1
1
#pragma once
2
2
3
- #include < binlog/binlog.hpp>
4
- #include < string>
5
- #include < vector>
6
- #include < unordered_map>
7
- #include < optional>
8
- #include < cassert>
9
- #include < fstream>
10
- #include < filesystem>
11
- #include < sstream>
12
- #include < mutex>
13
- #include < fmt/format.h>
14
- #include < fmt/chrono.h>
15
- #include < nlohmann/json.hpp>
16
-
17
- #include " swift/logging/Formatters.h"
3
+ #include " shared/cpp/Diagnostics.h"
18
4
19
5
namespace codeql {
20
6
21
- extern const std::string_view programName;
22
- extern const std::string_view extractorName;
23
-
24
- struct DiagnosticsLocation {
25
- std::string_view file;
26
- unsigned startLine;
27
- unsigned startColumn;
28
- unsigned endLine;
29
- unsigned endColumn;
30
-
31
- nlohmann::json json () const ;
32
- std::string str () const ;
33
- };
34
-
35
- // Models a diagnostic source for Swift, holding static information that goes out into a diagnostic
36
- // These are internally stored into a map on id's. A specific error log can use binlog's category
37
- // as id, which will then be used to recover the diagnostic source while dumping.
38
- class Diagnostic {
39
- public:
40
- enum class Visibility : unsigned char {
41
- none = 0b000 ,
42
- statusPage = 0b001 ,
43
- cliSummaryTable = 0b010 ,
44
- telemetry = 0b100 ,
45
- all = 0b111 ,
46
- };
47
-
48
- // Notice that Tool Status Page severity is not necessarily the same as log severity, as the
49
- // scope is different: TSP's scope is the whole analysis, log's scope is a single run
50
- enum class Severity {
51
- note,
52
- warning,
53
- error,
54
- };
55
-
56
- std::string_view id;
57
- std::string_view name;
58
- std::string_view action;
59
-
60
- Visibility visibility{Visibility::all};
61
- Severity severity{Severity::error};
62
-
63
- std::optional<DiagnosticsLocation> location{};
64
-
65
- // create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
66
- // A markdownMessage is emitted that includes both the message and the action to take. The id is
67
- // used to construct the source id in the form `swift/<prog name>/<id>`
68
- nlohmann::json json (const std::chrono::system_clock::time_point& timestamp,
69
- std::string_view message) const ;
70
-
71
- // returns <id> or <id>@<location> if a location is present
72
- std::string abbreviation () const ;
73
-
74
- Diagnostic withLocation (std::string_view file,
75
- unsigned startLine = 0 ,
76
- unsigned startColumn = 0 ,
77
- unsigned endLine = 0 ,
78
- unsigned endColumn = 0 ) const {
79
- auto ret = *this ;
80
- ret.location = DiagnosticsLocation{file, startLine, startColumn, endLine, endColumn};
81
- return ret;
82
- }
83
-
84
- private:
85
- bool has (Visibility v) const ;
86
- };
87
-
88
- inline constexpr Diagnostic::Visibility operator |(Diagnostic::Visibility lhs,
89
- Diagnostic::Visibility rhs) {
90
- return static_cast <Diagnostic::Visibility>(static_cast <unsigned char >(lhs) |
91
- static_cast <unsigned char >(rhs));
92
- }
93
-
94
- inline constexpr Diagnostic::Visibility operator &(Diagnostic::Visibility lhs,
95
- Diagnostic::Visibility rhs) {
96
- return static_cast <Diagnostic::Visibility>(static_cast <unsigned char >(lhs) &
97
- static_cast <unsigned char >(rhs));
98
- }
99
-
100
7
constexpr Diagnostic internalError{
101
8
.id = " internal-error" ,
102
9
.name = " Internal error" ,
@@ -108,4 +15,5 @@ constexpr Diagnostic internalError{
108
15
" \n "
109
16
" [1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md" ,
110
17
.severity = Diagnostic::Severity::warning};
18
+
111
19
} // namespace codeql
0 commit comments