@@ -20,7 +20,7 @@ namespace codeql {
20
20
21
21
extern const std::string_view programName;
22
22
23
- struct SwiftDiagnosticsLocation {
23
+ struct DiagnosticsLocation {
24
24
std::string_view file;
25
25
unsigned startLine;
26
26
unsigned startColumn;
@@ -34,7 +34,8 @@ struct SwiftDiagnosticsLocation {
34
34
// Models a diagnostic source for Swift, holding static information that goes out into a diagnostic
35
35
// These are internally stored into a map on id's. A specific error log can use binlog's category
36
36
// as id, which will then be used to recover the diagnostic source while dumping.
37
- struct SwiftDiagnostic {
37
+ class Diagnostic {
38
+ public:
38
39
enum class Visibility : unsigned char {
39
40
none = 0b000 ,
40
41
statusPage = 0b001 ,
@@ -51,7 +52,14 @@ struct SwiftDiagnostic {
51
52
error,
52
53
};
53
54
54
- static constexpr std::string_view extractorName = " swift" ;
55
+ constexpr Diagnostic (std::string_view extractorName,
56
+ std::string_view id,
57
+ std::string_view name,
58
+ std::string_view action,
59
+ Severity severity)
60
+ : extractorName(extractorName), id(id), name(name), action(action), severity(severity) {}
61
+
62
+ std::string_view extractorName;
55
63
56
64
std::string_view id;
57
65
std::string_view name;
@@ -60,7 +68,7 @@ struct SwiftDiagnostic {
60
68
Visibility visibility{Visibility::all};
61
69
Severity severity{Severity::error};
62
70
63
- std::optional<SwiftDiagnosticsLocation > location{};
71
+ std::optional<DiagnosticsLocation > location{};
64
72
65
73
// create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
66
74
// A markdownMessage is emitted that includes both the message and the action to take. The id is
@@ -71,42 +79,46 @@ struct SwiftDiagnostic {
71
79
// returns <id> or <id>@<location> if a location is present
72
80
std::string abbreviation () const ;
73
81
74
- SwiftDiagnostic withLocation (std::string_view file,
75
- unsigned startLine = 0 ,
76
- unsigned startColumn = 0 ,
77
- unsigned endLine = 0 ,
78
- unsigned endColumn = 0 ) const {
82
+ Diagnostic withLocation (std::string_view file,
83
+ unsigned startLine = 0 ,
84
+ unsigned startColumn = 0 ,
85
+ unsigned endLine = 0 ,
86
+ unsigned endColumn = 0 ) const {
79
87
auto ret = *this ;
80
- ret.location = SwiftDiagnosticsLocation {file, startLine, startColumn, endLine, endColumn};
88
+ ret.location = DiagnosticsLocation {file, startLine, startColumn, endLine, endColumn};
81
89
return ret;
82
90
}
83
91
84
92
private:
85
93
bool has (Visibility v) const ;
86
94
};
87
95
88
- inline constexpr SwiftDiagnostic ::Visibility operator |(SwiftDiagnostic ::Visibility lhs,
89
- SwiftDiagnostic ::Visibility rhs) {
90
- return static_cast <SwiftDiagnostic ::Visibility>(static_cast <unsigned char >(lhs) |
91
- static_cast <unsigned char >(rhs));
96
+ inline constexpr Diagnostic ::Visibility operator |(Diagnostic ::Visibility lhs,
97
+ Diagnostic ::Visibility rhs) {
98
+ return static_cast <Diagnostic ::Visibility>(static_cast <unsigned char >(lhs) |
99
+ static_cast <unsigned char >(rhs));
92
100
}
93
101
94
- inline constexpr SwiftDiagnostic ::Visibility operator &(SwiftDiagnostic ::Visibility lhs,
95
- SwiftDiagnostic ::Visibility rhs) {
96
- return static_cast <SwiftDiagnostic ::Visibility>(static_cast <unsigned char >(lhs) &
97
- static_cast <unsigned char >(rhs));
102
+ inline constexpr Diagnostic ::Visibility operator &(Diagnostic ::Visibility lhs,
103
+ Diagnostic ::Visibility rhs) {
104
+ return static_cast <Diagnostic ::Visibility>(static_cast <unsigned char >(lhs) &
105
+ static_cast <unsigned char >(rhs));
98
106
}
99
107
100
- constexpr SwiftDiagnostic internalError{
101
- .id = " internal-error" ,
102
- .name = " Internal error" ,
103
- .action =
104
- " Some or all of the Swift analysis may have failed.\n "
105
- " \n "
106
- " If the error persists, contact support, quoting the error message and describing what "
107
- " happened, or [open an issue in our open source repository][1].\n "
108
- " \n "
109
- " [1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md" ,
110
- .severity = SwiftDiagnostic::Severity::warning,
111
- };
108
+ constexpr Diagnostic swiftDiagnostic (std::string_view id,
109
+ std::string_view name,
110
+ std::string_view action,
111
+ Diagnostic::Severity severity = Diagnostic::Severity::error) {
112
+ return Diagnostic (" swift" , id, name, action, severity);
113
+ }
114
+
115
+ constexpr Diagnostic internalError = swiftDiagnostic(
116
+ " internal-error" , " Internal error" ,
117
+ " Some or all of the Swift analysis may have failed.\n "
118
+ " \n "
119
+ " If the error persists, contact support, quoting the error message and describing what "
120
+ " happened, or [open an issue in our open source repository][1].\n "
121
+ " \n "
122
+ " [1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md" ,
123
+ Diagnostic::Severity::warning);
112
124
} // namespace codeql
0 commit comments