|
1 | 1 | /**
|
2 | 2 | * @name Extraction errors
|
3 |
| - * @description List all errors reported by the extractor. The returned issues are |
4 |
| - * limited to those files where there are no compilation errors. This |
5 |
| - * indicates a bug or limitation in the extractor, and could lead to |
6 |
| - * inaccurate results. |
| 3 | + * @description List all errors reported by the extractor or the compiler. Extractor errors are |
| 4 | + * limited to those files where there are no compilation errors. |
7 | 5 | * @kind diagnostic
|
8 | 6 | * @id cs/diagnostics/extraction-errors
|
9 | 7 | */
|
10 | 8 |
|
11 | 9 | import csharp
|
12 | 10 | import semmle.code.csharp.commons.Diagnostics
|
13 | 11 |
|
14 |
| -private string getLocation(ExtractorError error) { |
15 |
| - if error.getLocation().getFile().fromSource() |
16 |
| - then result = " in " + error.getLocation().getFile() |
17 |
| - else result = "" |
| 12 | +private newtype TDiagnosticError = |
| 13 | + TCompilerError(CompilerError c) or |
| 14 | + TExtractorError(ExtractorError e) |
| 15 | + |
| 16 | +abstract private class DiagnosticError extends TDiagnosticError { |
| 17 | + string getMessage() { none() } |
| 18 | + |
| 19 | + string toString() { none() } |
| 20 | + |
| 21 | + string getLocation(Location l) { |
| 22 | + if l.getFile().fromSource() then result = " in " + l.getFile() else result = "" |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +private class DiagnosticCompilerError extends DiagnosticError { |
| 27 | + CompilerError c; |
| 28 | + |
| 29 | + DiagnosticCompilerError() { this = TCompilerError(c) } |
| 30 | + |
| 31 | + override string getMessage() { |
| 32 | + result = "Compiler error" + getLocation(c.getLocation()) + ": " + c.getMessage() |
| 33 | + } |
| 34 | + |
| 35 | + override string toString() { result = c.toString() } |
| 36 | +} |
| 37 | + |
| 38 | +private class DiagnosticExtractorError extends DiagnosticError { |
| 39 | + ExtractorError e; |
| 40 | + |
| 41 | + DiagnosticExtractorError() { |
| 42 | + this = TExtractorError(e) and |
| 43 | + not exists(CompilerError ce | ce.getLocation().getFile() = e.getLocation().getFile()) |
| 44 | + } |
| 45 | + |
| 46 | + override string getMessage() { |
| 47 | + result = |
| 48 | + "Unexpected " + e.getOrigin() + " error" + getLocation(e.getLocation()) + ": " + e.getText() |
| 49 | + } |
| 50 | + |
| 51 | + override string toString() { result = e.toString() } |
18 | 52 | }
|
19 | 53 |
|
20 |
| -from ExtractorError error |
21 |
| -where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile()) |
22 |
| -select error, |
23 |
| - "Unexpected " + error.getOrigin() + " error" + getLocation(error) + ": " + error.getText(), 3 |
| 54 | +from DiagnosticError error |
| 55 | +select error.getMessage(), 3 |
0 commit comments