1
1
/**
2
- * Provides a common hierarchy of all types of errors that can occur during extraction.
2
+ * Provides a common hierarchy of all types of problems that can occur during extraction.
3
3
*/
4
4
5
5
import cpp
6
6
7
7
/*
8
8
* A note about how the C/C++ extractor emits diagnostics:
9
- * When the extractor frontend encounters an error , it emits a diagnostic message,
9
+ * When the extractor frontend encounters a problem , it emits a diagnostic message,
10
10
* that includes a message, location and severity.
11
11
* However, that process is best-effort and may fail (e.g. due to lack of memory).
12
12
* Thus, if the extractor emitted at least one diagnostic of severity discretionary
@@ -15,17 +15,17 @@ import cpp
15
15
* In the common case, this means that a compilation during which one or more errors happened also gets
16
16
* the catch-all diagnostic.
17
17
* This diagnostic has the empty string as file path.
18
- * We filter out these useless diagnostics if there is at least one error -level diagnostic
18
+ * We filter out these useless diagnostics if there is at least one warning -level diagnostic
19
19
* for the affected compilation in the database.
20
20
* Otherwise, we show it to indicate that something went wrong and that we
21
21
* don't know what exactly happened.
22
22
*/
23
23
24
24
/**
25
- * An error that, if present, leads to a file being marked as non-successfully extracted.
25
+ * A problem with a file that, if present, leads to a file being marked as non-successfully extracted.
26
26
*/
27
- class ReportableError extends Diagnostic {
28
- ReportableError ( ) {
27
+ class ReportableWarning extends Diagnostic {
28
+ ReportableWarning ( ) {
29
29
(
30
30
this instanceof CompilerDiscretionaryError or
31
31
this instanceof CompilerError or
@@ -36,39 +36,35 @@ class ReportableError extends Diagnostic {
36
36
}
37
37
}
38
38
39
- private newtype TExtractionError =
40
- TReportableError ( ReportableError err ) or
39
+ private newtype TExtractionProblem =
40
+ TReportableWarning ( ReportableWarning err ) or
41
41
TCompilationFailed ( Compilation c , File f ) {
42
42
f = c .getAFileCompiled ( ) and not c .normalTermination ( )
43
43
} or
44
44
// Show the catch-all diagnostic (see note above) only if we haven't seen any other error-level diagnostic
45
45
// for that compilation
46
- TUnknownError ( CompilerError err ) {
47
- not exists ( ReportableError e | e .getCompilation ( ) = err .getCompilation ( ) )
46
+ TUnknownProblem ( CompilerError err ) {
47
+ not exists ( ReportableWarning e | e .getCompilation ( ) = err .getCompilation ( ) )
48
48
}
49
49
50
50
/**
51
- * Superclass for the extraction error hierarchy.
51
+ * Superclass for the extraction problem hierarchy.
52
52
*/
53
- class ExtractionError extends TExtractionError {
54
- /** Gets the string representation of the error . */
53
+ class ExtractionProblem extends TExtractionProblem {
54
+ /** Gets the string representation of the problem . */
55
55
string toString ( ) { none ( ) }
56
56
57
- /** Gets the error message for this error . */
58
- string getErrorMessage ( ) { none ( ) }
57
+ /** Gets the problem message for this problem . */
58
+ string getProblemMessage ( ) { none ( ) }
59
59
60
- /** Gets the file this error occured in. */
60
+ /** Gets the file this problem occured in. */
61
61
File getFile ( ) { none ( ) }
62
62
63
- /** Gets the location this error occured in. */
63
+ /** Gets the location this problem occured in. */
64
64
Location getLocation ( ) { none ( ) }
65
65
66
- /** Gets the SARIF severity of this error. */
67
- int getSeverity ( ) {
68
- // Unfortunately, we can't distinguish between errors and fatal errors in SARIF,
69
- // so all errors have severity 2.
70
- result = 2
71
- }
66
+ /** Gets the SARIF severity of this problem. */
67
+ int getSeverity ( ) { none ( ) }
72
68
}
73
69
74
70
/**
@@ -79,7 +75,7 @@ class ExtractionError extends TExtractionError {
79
75
* - stack overflow
80
76
* - out of memory
81
77
*/
82
- class ExtractionUnrecoverableError extends ExtractionError , TCompilationFailed {
78
+ class ExtractionUnrecoverableError extends ExtractionProblem , TCompilationFailed {
83
79
Compilation c ;
84
80
File f ;
85
81
@@ -89,49 +85,67 @@ class ExtractionUnrecoverableError extends ExtractionError, TCompilationFailed {
89
85
result = "Unrecoverable extraction error while compiling " + f .toString ( )
90
86
}
91
87
92
- override string getErrorMessage ( ) { result = "unrecoverable compilation failure." }
88
+ override string getProblemMessage ( ) { result = "unrecoverable compilation failure." }
93
89
94
90
override File getFile ( ) { result = f }
95
91
96
92
override Location getLocation ( ) { result = f .getLocation ( ) }
93
+
94
+ override int getSeverity ( ) {
95
+ // These extractor errors break the analysis, so we mark them in SARIF as
96
+ // [errors](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541338).
97
+ result = 2
98
+ }
97
99
}
98
100
99
101
/**
100
- * A recoverable extraction error .
102
+ * A recoverable extraction warning .
101
103
* These are compiler errors from the frontend.
102
104
* Upon encountering one of these, we still continue extraction, but the
103
105
* database will be incomplete for that file.
104
106
*/
105
- class ExtractionRecoverableError extends ExtractionError , TReportableError {
106
- ReportableError err ;
107
+ class ExtractionRecoverableWarning extends ExtractionProblem , TReportableWarning {
108
+ ReportableWarning err ;
107
109
108
- ExtractionRecoverableError ( ) { this = TReportableError ( err ) }
110
+ ExtractionRecoverableWarning ( ) { this = TReportableWarning ( err ) }
109
111
110
112
override string toString ( ) { result = "Recoverable extraction error: " + err }
111
113
112
- override string getErrorMessage ( ) { result = err .getFullMessage ( ) }
114
+ override string getProblemMessage ( ) { result = err .getFullMessage ( ) }
113
115
114
116
override File getFile ( ) { result = err .getFile ( ) }
115
117
116
118
override Location getLocation ( ) { result = err .getLocation ( ) }
119
+
120
+ override int getSeverity ( ) {
121
+ // Recoverable extraction problems don't tend to break the analysis, so we mark them in SARIF as
122
+ // [warnings](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541338).
123
+ result = 1
124
+ }
117
125
}
118
126
119
127
/**
120
- * An unknown error happened during extraction.
121
- * These are only displayed if we know that we encountered an error during extraction,
128
+ * An unknown problem happened during extraction.
129
+ * These are only displayed if we know that we encountered an problem during extraction,
122
130
* but, for some reason, failed to emit a proper diagnostic with location information
123
- * and error message.
131
+ * and problem message.
124
132
*/
125
- class ExtractionUnknownError extends ExtractionError , TUnknownError {
133
+ class ExtractionUnknownProblem extends ExtractionProblem , TUnknownProblem {
126
134
CompilerError err ;
127
135
128
- ExtractionUnknownError ( ) { this = TUnknownError ( err ) }
136
+ ExtractionUnknownProblem ( ) { this = TUnknownProblem ( err ) }
129
137
130
- override string toString ( ) { result = "Unknown extraction error : " + err }
138
+ override string toString ( ) { result = "Unknown extraction problem : " + err }
131
139
132
- override string getErrorMessage ( ) { result = err .getFullMessage ( ) }
140
+ override string getProblemMessage ( ) { result = err .getFullMessage ( ) }
133
141
134
142
override File getFile ( ) { result = err .getFile ( ) }
135
143
136
144
override Location getLocation ( ) { result = err .getLocation ( ) }
145
+
146
+ override int getSeverity ( ) {
147
+ // Unknown extraction problems don't tend to break the analysis, so we mark them in SARIF as
148
+ // [warnings](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541338).
149
+ result = 1
150
+ }
137
151
}
0 commit comments