Skip to content

Commit 964915e

Browse files
committed
C#: Treat QL test stubs as not from source
1 parent bfb573c commit 964915e

File tree

4 files changed

+68
-57
lines changed

4 files changed

+68
-57
lines changed

csharp/ql/lib/csharp.qll

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,40 @@
22
* The default C# QL library.
33
*/
44

5-
// Do not add other imports here; add to `semmle.code.csharp.internal.csharp` instead
6-
import semmle.code.csharp.internal.csharp
5+
import Customizations
6+
import semmle.code.csharp.Attribute
7+
import semmle.code.csharp.Callable
8+
import semmle.code.csharp.Comments
9+
import semmle.code.csharp.Element
10+
import semmle.code.csharp.Event
11+
import semmle.code.csharp.File
12+
import semmle.code.csharp.Generics
13+
import semmle.code.csharp.Location
14+
import semmle.code.csharp.Member
15+
import semmle.code.csharp.Namespace
16+
import semmle.code.csharp.AnnotatedType
17+
import semmle.code.csharp.Property
18+
import semmle.code.csharp.Stmt
19+
import semmle.code.csharp.Type
20+
import semmle.code.csharp.Using
21+
import semmle.code.csharp.Variable
22+
import semmle.code.csharp.XML
23+
import semmle.code.csharp.Preprocessor
24+
import semmle.code.csharp.exprs.Access
25+
import semmle.code.csharp.exprs.ArithmeticOperation
26+
import semmle.code.csharp.exprs.Assignment
27+
import semmle.code.csharp.exprs.BitwiseOperation
28+
import semmle.code.csharp.exprs.Call
29+
import semmle.code.csharp.exprs.ComparisonOperation
30+
import semmle.code.csharp.exprs.Creation
31+
import semmle.code.csharp.exprs.Dynamic
32+
import semmle.code.csharp.exprs.Expr
33+
import semmle.code.csharp.exprs.Literal
34+
import semmle.code.csharp.exprs.LogicalOperation
35+
import semmle.code.csharp.controlflow.ControlFlowGraph
36+
import semmle.code.csharp.dataflow.DataFlow
37+
import semmle.code.csharp.dataflow.TaintTracking
38+
import semmle.code.csharp.dataflow.SSA
39+
40+
/** Whether the source was extracted without a build command. */
41+
predicate extractionIsStandalone() { exists(SourceFile f | f.extractedStandalone()) }

csharp/ql/lib/semmle/code/csharp/File.qll

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Provides classes representing filesystem files and folders.
33
*/
44

5+
private import Comments
6+
57
/** A file or folder. */
68
class Container extends @container {
79
/**
@@ -195,11 +197,38 @@ class File extends Container, @file {
195197

196198
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
197199

200+
pragma[noinline]
201+
private predicate hasStubHeaderComment() {
202+
exists(CommentLine c |
203+
c.getText() = "This file contains auto-generated code." and
204+
c.getLocation().getFile() = this
205+
)
206+
}
207+
208+
pragma[noinline]
209+
private predicate hasStubComment() {
210+
exists(CommentLine c |
211+
c.getText().regexpMatch("Generated from `.*` in `.*`") and
212+
c.getLocation().getFile() = this
213+
)
214+
}
215+
216+
/** Holds if this file is a QL test stub file. */
217+
pragma[noinline]
218+
private predicate isStub() {
219+
this.hasStubHeaderComment() and
220+
this.hasStubComment() and
221+
this.getAbsolutePath().matches("%resources/stubs/%")
222+
}
223+
198224
/** Holds if this file contains source code. */
199-
predicate fromSource() { this.getExtension() = "cs" }
225+
final predicate fromSource() {
226+
this.getExtension() = "cs" and
227+
not this.isStub()
228+
}
200229

201230
/** Holds if this file is a library. */
202-
predicate fromLibrary() {
231+
final predicate fromLibrary() {
203232
not this.getBaseName() = "" and
204233
not this.fromSource()
205234
}

csharp/ql/lib/semmle/code/csharp/internal/csharp.qll

Lines changed: 0 additions & 41 deletions
This file was deleted.

csharp/ql/test/csharp.qll

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)