11/*
22 * MIT License
33 *
4+ * Copyright (c) 2024 light-tech
45 * Copyright (c) 2026 Kyle-Ye
6+ * Copyright (c) 2026 cr4zyengineer
57 *
68 * Permission is hereby granted, free of charge, to any person obtaining a copy
79 * of this software and associated documentation files (the "Software"), to deal
3840#include < unistd.h>
3941
4042struct CapturedDiag {
41- swift::DiagID id;
43+ swift::DiagID id;
4244 swift::DiagnosticKind kind;
43- std::string message; // already formatted
44- std::string file;
45- unsigned line = 0 , column = 0 ;
46- // add ranges / fixits / category / educationalNotes if you need them
45+ std::string message;
46+ std::string file;
47+ unsigned line = 0 , column = 0 ;
48+ /* add ranges / fixits / category / educationalNotes if you need them */
4749};
4850
4951class CapturingConsumer : public swift ::DiagnosticConsumer {
5052public:
5153 std::vector<CapturedDiag> diags;
5254
5355 void handleDiagnostic (swift::SourceManager &SM ,
54- const swift::DiagnosticInfo &Info) override {
56+ const swift::DiagnosticInfo &Info) override
57+ {
5558 CapturedDiag d;
56- d.id = Info.ID ;
59+ d.id = Info.ID ;
5760 d.kind = Info.Kind ;
5861
59- // Render FormatString + FormatArgs into a real string.
62+ /* render FormatString + FormatArgs into a real string. */
6063 llvm::SmallString<256 > buf;
6164 {
6265 llvm::raw_svector_ostream os (buf);
63- swift::DiagnosticEngine::formatDiagnosticText (
64- os, Info.FormatString , Info.FormatArgs );
66+ swift::DiagnosticEngine::formatDiagnosticText (os, Info.FormatString , Info.FormatArgs );
6567 }
6668 d.message = std::string (buf);
6769
68- if (Info.Loc .isValid ()) {
70+ if (Info.Loc .isValid ())
71+ {
6972 auto lc = SM .getPresumedLineAndColumnForLoc (Info.Loc );
70- d.line = lc.first ;
73+ d.line = lc.first ;
7174 d.column = lc.second ;
72- d.file = SM .getDisplayNameForLoc (Info.Loc ).str ();
75+ d.file = SM .getDisplayNameForLoc (Info.Loc ).str ();
7376 }
7477 diags.push_back (std::move (d));
7578 }
@@ -78,7 +81,8 @@ class CapturingConsumer : public swift::DiagnosticConsumer {
7881class MyObserver : public swift ::FrontendObserver {
7982public:
8083 CapturingConsumer consumer;
81- void configuredCompiler (swift::CompilerInstance &CI ) override {
84+ void configuredCompiler (swift::CompilerInstance &CI ) override
85+ {
8286 CI .addDiagnosticConsumer (&consumer);
8387 }
8488};
@@ -118,7 +122,8 @@ static CFStringRef CCStringCreateWithFileDescriptor(CFAllocatorRef allocator, in
118122 return string;
119123}
120124
121- Boolean CCSwiftCompilerExecute (CFArrayRef arguments, CFArrayRef *outDiagnostic)
125+ Boolean CCSwiftCompilerExecute (CFArrayRef arguments,
126+ CFArrayRef *outDiagnostic)
122127{
123128 assert (arguments != nullptr );
124129
0 commit comments