Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23ce5bc

Browse files
authored
Merge pull request #1353 from calumgrant/cs/diagnostic-queries3
C#: Add internal queries for extractor and compiler diagnostics
2 parents 5bbbd26 + ae8ecc8 commit 23ce5bc

17 files changed

Lines changed: 149 additions & 0 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
This is an internal query that finds all compilation errors reported by the C# compiler used by the C# extractor.</p>
9+
</overview>
10+
11+
</qhelp>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name Compilation error
3+
* @description A compilation error can cause extraction problems, and could lead to inaccurate results.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @precision high
7+
* @id cs/compilation-error
8+
* @tags internal non-attributable
9+
*/
10+
11+
import csharp
12+
import semmle.code.csharp.commons.Diagnostics
13+
14+
from CompilerError diagnostic
15+
select diagnostic,
16+
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
This is an internal query that finds all messages reported by the C# compiler used by the C# extractor. This may include both compiler errors and
9+
compiler warnings.
10+
</p>
11+
</overview>
12+
13+
</qhelp>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name Compilation message
3+
* @description A message emitted by the compiler, including warnings and errors.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @precision high
7+
* @id cs/compilation-message
8+
* @tags internal non-attributable
9+
*/
10+
11+
import csharp
12+
import semmle.code.csharp.commons.Diagnostics
13+
14+
from Diagnostic diagnostic
15+
select diagnostic,
16+
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
This is an internal query that finds all errors reported by the C# extractor. It excludes results from files containing
9+
compilation errors, because these errors are likely to be caused by the compilation error rather than due to an internal
10+
error in the extractor.
11+
</p>
12+
13+
<p>Extractor errors can lead to inaccurate results.</p>
14+
</overview>
15+
16+
<recommendation>
17+
<p>
18+
Report extractor errors to Semmle.
19+
</p>
20+
</recommendation>
21+
22+
</qhelp>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Extraction error
3+
* @description An error message reported by the extractor, limited to those files where there are no
4+
* compilation errors. This indicates a bug or limitation in the extractor, and could lead
5+
* to inaccurate results.
6+
* @kind problem
7+
* @problem.severity recommendation
8+
* @precision high
9+
* @id cs/extraction-error
10+
* @tags internal non-attributable
11+
*/
12+
13+
import csharp
14+
import semmle.code.csharp.commons.Diagnostics
15+
16+
from ExtractorError error
17+
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
18+
select error,
19+
"Unexpected " + error.getOrigin() + " error in element '" + error.getElementText() +
20+
"' at location " + error.getStackTrace()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
This is an internal query that finds all messages reported by the extractor. These results may include extraction errors
9+
that are caused by compilation errors.
10+
</p>
11+
<p>
12+
Extractor errors can lead to inaccurate results.
13+
</p>
14+
</overview>
15+
16+
</qhelp>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Extraction message
3+
* @description An error message reported by the extractor. This could lead to inaccurate results.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @precision high
7+
* @id cs/extraction-message
8+
* @tags internal non-attributable
9+
*/
10+
11+
import csharp
12+
import semmle.code.csharp.commons.Diagnostics
13+
14+
from ExtractorMessage message
15+
select message,
16+
message.getSeverityText() + " was generated by " + message.getOrigin() + " in element '" +
17+
message.getElementText() + "' at location " + message.getStackTrace()

csharp/ql/src/semmle/code/csharp/commons/Diagnostics.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ class Diagnostic extends @diagnostic {
2929
*/
3030
int getSeverity() { result = severity }
3131

32+
/** Gets a string representation of the severity of this diagnostic. */
33+
string getSeverityText() {
34+
severity = 0 and result = "Hidden"
35+
or
36+
severity = 1 and result = "Info"
37+
or
38+
severity = 2 and result = "Warning"
39+
or
40+
severity = 3 and result = "Error"
41+
}
42+
3243
/** Gets the identifier of this diagnostic, for example "CS8019". */
3344
string getTag() { result = tag }
3445

csharp/ql/test/library-tests/compilations/CompilerError.expected

Whitespace-only changes.

0 commit comments

Comments
 (0)