Merge pull request #1353 from calumgrant/cs/diagnostic-queries3

C#: Add internal queries for extractor and compiler diagnostics
This commit is contained in:
Tom Hvitved
2019-05-29 10:26:41 +02:00
committed by GitHub
17 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This is an internal query that finds all compilation errors reported by the C# compiler used by the C# extractor.</p>
</overview>
</qhelp>

View File

@@ -0,0 +1,16 @@
/**
* @name Compilation error
* @description A compilation error can cause extraction problems, and could lead to inaccurate results.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/compilation-error
* @tags internal non-attributable
*/
import csharp
import semmle.code.csharp.commons.Diagnostics
from CompilerError diagnostic
select diagnostic,
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()

View File

@@ -0,0 +1,13 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
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
compiler warnings.
</p>
</overview>
</qhelp>

View File

@@ -0,0 +1,16 @@
/**
* @name Compilation message
* @description A message emitted by the compiler, including warnings and errors.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/compilation-message
* @tags internal non-attributable
*/
import csharp
import semmle.code.csharp.commons.Diagnostics
from Diagnostic diagnostic
select diagnostic,
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()

View File

@@ -0,0 +1,22 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This is an internal query that finds all errors reported by the C# extractor. It excludes results from files containing
compilation errors, because these errors are likely to be caused by the compilation error rather than due to an internal
error in the extractor.
</p>
<p>Extractor errors can lead to inaccurate results.</p>
</overview>
<recommendation>
<p>
Report extractor errors to Semmle.
</p>
</recommendation>
</qhelp>

View File

@@ -0,0 +1,20 @@
/**
* @name Extraction error
* @description An error message reported by the extractor, limited to those files where there are no
* compilation errors. This indicates a bug or limitation in the extractor, and could lead
* to inaccurate results.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/extraction-error
* @tags internal non-attributable
*/
import csharp
import semmle.code.csharp.commons.Diagnostics
from ExtractorError error
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
select error,
"Unexpected " + error.getOrigin() + " error in element '" + error.getElementText() +
"' at location " + error.getStackTrace()

View File

@@ -0,0 +1,16 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This is an internal query that finds all messages reported by the extractor. These results may include extraction errors
that are caused by compilation errors.
</p>
<p>
Extractor errors can lead to inaccurate results.
</p>
</overview>
</qhelp>

View File

@@ -0,0 +1,17 @@
/**
* @name Extraction message
* @description An error message reported by the extractor. This could lead to inaccurate results.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/extraction-message
* @tags internal non-attributable
*/
import csharp
import semmle.code.csharp.commons.Diagnostics
from ExtractorMessage message
select message,
message.getSeverityText() + " was generated by " + message.getOrigin() + " in element '" +
message.getElementText() + "' at location " + message.getStackTrace()

View File

@@ -29,6 +29,17 @@ class Diagnostic extends @diagnostic {
*/
int getSeverity() { result = severity }
/** Gets a string representation of the severity of this diagnostic. */
string getSeverityText() {
severity = 0 and result = "Hidden"
or
severity = 1 and result = "Info"
or
severity = 2 and result = "Warning"
or
severity = 3 and result = "Error"
}
/** Gets the identifier of this diagnostic, for example "CS8019". */
string getTag() { result = tag }

View File

@@ -0,0 +1 @@
Diagnostics/CompilerError.ql

View File

@@ -0,0 +1,3 @@
| Program.cs:7:13:7:13 | CS0219: The variable 'x' is assigned but its value is never used | Warning CS0219 The variable 'x' is assigned but its value is never used |
| Program.cs:9:9:9:11 | CS0162: Unreachable code detected | Warning CS0162 Unreachable code detected |
| Program.cs:9:13:9:13 | CS0219: The variable 'y' is assigned but its value is never used | Warning CS0219 The variable 'y' is assigned but its value is never used |

View File

@@ -0,0 +1 @@
Diagnostics/CompilerMessage.ql

View File

@@ -0,0 +1 @@
Diagnostics/ExtractorError.ql

View File

@@ -0,0 +1 @@
Diagnostics/ExtractorMessage.ql