11/**
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.
33 */
44
55import cpp
66
77/*
88 * 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,
1010 * that includes a message, location and severity.
1111 * However, that process is best-effort and may fail (e.g. due to lack of memory).
1212 * Thus, if the extractor emitted at least one diagnostic of severity discretionary
@@ -15,17 +15,17 @@ import cpp
1515 * In the common case, this means that a compilation during which one or more errors happened also gets
1616 * the catch-all diagnostic.
1717 * 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
1919 * for the affected compilation in the database.
2020 * Otherwise, we show it to indicate that something went wrong and that we
2121 * don't know what exactly happened.
2222 */
2323
2424/**
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.
2626 */
27- class ReportableError extends Diagnostic {
28- ReportableError ( ) {
27+ class ReportableWarning extends Diagnostic {
28+ ReportableWarning ( ) {
2929 (
3030 this instanceof CompilerDiscretionaryError or
3131 this instanceof CompilerError or
@@ -36,39 +36,35 @@ class ReportableError extends Diagnostic {
3636 }
3737}
3838
39- private newtype TExtractionError =
40- TReportableError ( ReportableError err ) or
39+ private newtype TExtractionProblem =
40+ TReportableWarning ( ReportableWarning err ) or
4141 TCompilationFailed ( Compilation c , File f ) {
4242 f = c .getAFileCompiled ( ) and not c .normalTermination ( )
4343 } or
4444 // Show the catch-all diagnostic (see note above) only if we haven't seen any other error-level diagnostic
4545 // 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 ( ) )
4848 }
4949
5050/**
51- * Superclass for the extraction error hierarchy.
51+ * Superclass for the extraction problem hierarchy.
5252 */
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 . */
5555 string toString ( ) { none ( ) }
5656
57- /** Gets the error message for this error . */
58- string getErrorMessage ( ) { none ( ) }
57+ /** Gets the problem message for this problem . */
58+ string getProblemMessage ( ) { none ( ) }
5959
60- /** Gets the file this error occured in. */
60+ /** Gets the file this problem occured in. */
6161 File getFile ( ) { none ( ) }
6262
63- /** Gets the location this error occured in. */
63+ /** Gets the location this problem occured in. */
6464 Location getLocation ( ) { none ( ) }
6565
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 ( ) }
7268}
7369
7470/**
@@ -79,7 +75,7 @@ class ExtractionError extends TExtractionError {
7975 * - stack overflow
8076 * - out of memory
8177 */
82- class ExtractionUnrecoverableError extends ExtractionError , TCompilationFailed {
78+ class ExtractionUnrecoverableError extends ExtractionProblem , TCompilationFailed {
8379 Compilation c ;
8480 File f ;
8581
@@ -89,49 +85,67 @@ class ExtractionUnrecoverableError extends ExtractionError, TCompilationFailed {
8985 result = "Unrecoverable extraction error while compiling " + f .toString ( )
9086 }
9187
92- override string getErrorMessage ( ) { result = "unrecoverable compilation failure." }
88+ override string getProblemMessage ( ) { result = "unrecoverable compilation failure." }
9389
9490 override File getFile ( ) { result = f }
9591
9692 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+ }
9799}
98100
99101/**
100- * A recoverable extraction error .
102+ * A recoverable extraction warning .
101103 * These are compiler errors from the frontend.
102104 * Upon encountering one of these, we still continue extraction, but the
103105 * database will be incomplete for that file.
104106 */
105- class ExtractionRecoverableError extends ExtractionError , TReportableError {
106- ReportableError err ;
107+ class ExtractionRecoverableWarning extends ExtractionProblem , TReportableWarning {
108+ ReportableWarning err ;
107109
108- ExtractionRecoverableError ( ) { this = TReportableError ( err ) }
110+ ExtractionRecoverableWarning ( ) { this = TReportableWarning ( err ) }
109111
110112 override string toString ( ) { result = "Recoverable extraction error: " + err }
111113
112- override string getErrorMessage ( ) { result = err .getFullMessage ( ) }
114+ override string getProblemMessage ( ) { result = err .getFullMessage ( ) }
113115
114116 override File getFile ( ) { result = err .getFile ( ) }
115117
116118 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+ }
117125}
118126
119127/**
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,
122130 * but, for some reason, failed to emit a proper diagnostic with location information
123- * and error message.
131+ * and problem message.
124132 */
125- class ExtractionUnknownError extends ExtractionError , TUnknownError {
133+ class ExtractionUnknownProblem extends ExtractionProblem , TUnknownProblem {
126134 CompilerError err ;
127135
128- ExtractionUnknownError ( ) { this = TUnknownError ( err ) }
136+ ExtractionUnknownProblem ( ) { this = TUnknownProblem ( err ) }
129137
130- override string toString ( ) { result = "Unknown extraction error : " + err }
138+ override string toString ( ) { result = "Unknown extraction problem : " + err }
131139
132- override string getErrorMessage ( ) { result = err .getFullMessage ( ) }
140+ override string getProblemMessage ( ) { result = err .getFullMessage ( ) }
133141
134142 override File getFile ( ) { result = err .getFile ( ) }
135143
136144 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+ }
137151}
0 commit comments