Merge pull request #7509 from hvitved/csharp/stubs-from-source

C#: Treat QL test stubs as not from source
This commit is contained in:
Michael Nebel
2022-01-05 16:40:19 +01:00
committed by GitHub
6 changed files with 50 additions and 59 deletions

View File

@@ -2,5 +2,40 @@
* The default C# QL library.
*/
// Do not add other imports here; add to `semmle.code.csharp.internal.csharp` instead
import semmle.code.csharp.internal.csharp
import Customizations
import semmle.code.csharp.Attribute
import semmle.code.csharp.Callable
import semmle.code.csharp.Comments
import semmle.code.csharp.Element
import semmle.code.csharp.Event
import semmle.code.csharp.File
import semmle.code.csharp.Generics
import semmle.code.csharp.Location
import semmle.code.csharp.Member
import semmle.code.csharp.Namespace
import semmle.code.csharp.AnnotatedType
import semmle.code.csharp.Property
import semmle.code.csharp.Stmt
import semmle.code.csharp.Type
import semmle.code.csharp.Using
import semmle.code.csharp.Variable
import semmle.code.csharp.XML
import semmle.code.csharp.Preprocessor
import semmle.code.csharp.exprs.Access
import semmle.code.csharp.exprs.ArithmeticOperation
import semmle.code.csharp.exprs.Assignment
import semmle.code.csharp.exprs.BitwiseOperation
import semmle.code.csharp.exprs.Call
import semmle.code.csharp.exprs.ComparisonOperation
import semmle.code.csharp.exprs.Creation
import semmle.code.csharp.exprs.Dynamic
import semmle.code.csharp.exprs.Expr
import semmle.code.csharp.exprs.Literal
import semmle.code.csharp.exprs.LogicalOperation
import semmle.code.csharp.controlflow.ControlFlowGraph
import semmle.code.csharp.dataflow.DataFlow
import semmle.code.csharp.dataflow.TaintTracking
import semmle.code.csharp.dataflow.SSA
/** Whether the source was extracted without a build command. */
predicate extractionIsStandalone() { exists(SourceFile f | f.extractedStandalone()) }

View File

@@ -2,6 +2,8 @@
* Provides classes representing filesystem files and folders.
*/
private import Comments
/** A file or folder. */
class Container extends @container {
/**
@@ -195,11 +197,18 @@ class File extends Container, @file {
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
/** Holds if this file is a QL test stub file. */
pragma[noinline]
private predicate isStub() { this.getAbsolutePath().matches("%resources/stubs/%") }
/** Holds if this file contains source code. */
predicate fromSource() { this.getExtension() = "cs" }
final predicate fromSource() {
this.getExtension() = "cs" and
not this.isStub()
}
/** Holds if this file is a library. */
predicate fromLibrary() {
final predicate fromLibrary() {
not this.getBaseName() = "" and
not this.fromSource()
}

View File

@@ -71,7 +71,7 @@ newtype CompilationExt =
TBuildless() { extractionIsStandalone() }
/** Gets the compilation that source file `f` belongs to. */
CompilationExt getCompilation(SourceFile f) {
CompilationExt getCompilation(File f) {
exists(Compilation c |
f = c.getAFileCompiled() and
result = TCompilation(c)

View File

@@ -1,41 +0,0 @@
/**
* The default C# QL library.
*/
import Customizations
import semmle.code.csharp.Attribute
import semmle.code.csharp.Callable
import semmle.code.csharp.Comments
import semmle.code.csharp.Element
import semmle.code.csharp.Event
import semmle.code.csharp.File
import semmle.code.csharp.Generics
import semmle.code.csharp.Location
import semmle.code.csharp.Member
import semmle.code.csharp.Namespace
import semmle.code.csharp.AnnotatedType
import semmle.code.csharp.Property
import semmle.code.csharp.Stmt
import semmle.code.csharp.Type
import semmle.code.csharp.Using
import semmle.code.csharp.Variable
import semmle.code.csharp.XML
import semmle.code.csharp.Preprocessor
import semmle.code.csharp.exprs.Access
import semmle.code.csharp.exprs.ArithmeticOperation
import semmle.code.csharp.exprs.Assignment
import semmle.code.csharp.exprs.BitwiseOperation
import semmle.code.csharp.exprs.Call
import semmle.code.csharp.exprs.ComparisonOperation
import semmle.code.csharp.exprs.Creation
import semmle.code.csharp.exprs.Dynamic
import semmle.code.csharp.exprs.Expr
import semmle.code.csharp.exprs.Literal
import semmle.code.csharp.exprs.LogicalOperation
import semmle.code.csharp.controlflow.ControlFlowGraph
import semmle.code.csharp.dataflow.DataFlow
import semmle.code.csharp.dataflow.TaintTracking
import semmle.code.csharp.dataflow.SSA
/** Whether the source was extracted without a build command. */
predicate extractionIsStandalone() { exists(SourceFile f | f.extractedStandalone()) }

View File

@@ -1,12 +0,0 @@
/**
* The default C# QL library.
*/
import semmle.code.csharp.internal.csharp
private class FileAdjusted extends File {
override predicate fromSource() {
super.fromSource() and
not this.getAbsolutePath().matches("%resources/stubs/%")
}
}

File diff suppressed because one or more lines are too long