@@ -20,7 +20,7 @@ namespace codeql {
2020
2121extern const std::string_view programName;
2222
23- struct SwiftDiagnosticsLocation {
23+ struct DiagnosticsLocation {
2424 std::string_view file;
2525 unsigned startLine;
2626 unsigned startColumn;
@@ -34,7 +34,8 @@ struct SwiftDiagnosticsLocation {
3434// Models a diagnostic source for Swift, holding static information that goes out into a diagnostic
3535// These are internally stored into a map on id's. A specific error log can use binlog's category
3636// as id, which will then be used to recover the diagnostic source while dumping.
37- struct SwiftDiagnostic {
37+ class Diagnostic {
38+ public:
3839 enum class Visibility : unsigned char {
3940 none = 0b000 ,
4041 statusPage = 0b001 ,
@@ -51,7 +52,14 @@ struct SwiftDiagnostic {
5152 error,
5253 };
5354
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;
5563
5664 std::string_view id;
5765 std::string_view name;
@@ -60,7 +68,7 @@ struct SwiftDiagnostic {
6068 Visibility visibility{Visibility::all};
6169 Severity severity{Severity::error};
6270
63- std::optional<SwiftDiagnosticsLocation > location{};
71+ std::optional<DiagnosticsLocation > location{};
6472
6573 // create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
6674 // A markdownMessage is emitted that includes both the message and the action to take. The id is
@@ -71,42 +79,46 @@ struct SwiftDiagnostic {
7179 // returns <id> or <id>@<location> if a location is present
7280 std::string abbreviation () const ;
7381
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 {
7987 auto ret = *this ;
80- ret.location = SwiftDiagnosticsLocation {file, startLine, startColumn, endLine, endColumn};
88+ ret.location = DiagnosticsLocation {file, startLine, startColumn, endLine, endColumn};
8189 return ret;
8290 }
8391
8492 private:
8593 bool has (Visibility v) const ;
8694};
8795
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));
92100}
93101
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));
98106}
99107
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);
112124} // namespace codeql
0 commit comments