1
1
#include " swift/extractor/invocation/SwiftDiagnosticsConsumer.h"
2
- #include " swift/extractor/trap/generated/TrapEntries .h"
2
+ #include " swift/extractor/trap/generated/TrapClasses .h"
3
3
#include " swift/extractor/trap/TrapDomain.h"
4
4
#include " swift/extractor/infra/SwiftDiagnosticKind.h"
5
5
@@ -13,13 +13,17 @@ using namespace codeql;
13
13
14
14
void SwiftDiagnosticsConsumer::handleDiagnostic (swift::SourceManager& sourceManager,
15
15
const swift::DiagnosticInfo& diagInfo) {
16
- auto message = getDiagMessage (sourceManager, diagInfo);
17
- DiagnosticsTrap diag{};
18
- diag.id = trap.createTypedLabel <DiagnosticsTag>();
16
+ if (diagInfo.IsChildNote ) return ;
17
+ Diagnostics diag{trap.createTypedLabel <DiagnosticsTag>()};
19
18
diag.kind = translateDiagnosticsKind (diagInfo.Kind );
20
- diag.text = message ;
19
+ diag.text = getDiagMessage (sourceManager, diagInfo) ;
21
20
trap.emit (diag);
22
21
locationExtractor.attachLocation (sourceManager, diagInfo, diag.id );
22
+
23
+ forwardToLog (sourceManager, diagInfo, diag.text );
24
+ for (const auto & child : diagInfo.ChildDiagnosticInfo ) {
25
+ forwardToLog (sourceManager, *child);
26
+ }
23
27
}
24
28
25
29
std::string SwiftDiagnosticsConsumer::getDiagMessage (swift::SourceManager& sourceManager,
@@ -29,3 +33,29 @@ std::string SwiftDiagnosticsConsumer::getDiagMessage(swift::SourceManager& sourc
29
33
swift::DiagnosticEngine::formatDiagnosticText (out, diagInfo.FormatString , diagInfo.FormatArgs );
30
34
return text.str ().str ();
31
35
}
36
+
37
+ void SwiftDiagnosticsConsumer::forwardToLog (swift::SourceManager& sourceManager,
38
+ const swift::DiagnosticInfo& diagInfo,
39
+ const std::string& message) {
40
+ auto file = sourceManager.getDisplayNameForLoc (diagInfo.Loc );
41
+ auto [line, column] = sourceManager.getLineAndColumnInBuffer (diagInfo.Loc );
42
+ using Kind = swift::DiagnosticKind;
43
+ switch (diagInfo.Kind ) {
44
+ case Kind::Error:
45
+ LOG_ERROR (" {}:{}:{} {}" , file, line, column, message);
46
+ break ;
47
+ case Kind::Warning:
48
+ LOG_WARNING (" {}:{}:{} {}" , file, line, column, message);
49
+ break ;
50
+ case Kind::Remark:
51
+ LOG_INFO (" {}:{}:{} {}" , file, line, column, message);
52
+ break ;
53
+ case Kind::Note:
54
+ LOG_DEBUG (" {}:{}:{} {}" , file, line, column, message);
55
+ break ;
56
+ default :
57
+ LOG_ERROR (" unknown diagnostic kind {}, {}:{}:{} {}" , diagInfo.Kind , file, line, column,
58
+ message);
59
+ break ;
60
+ }
61
+ }
0 commit comments