Skip to content

Commit 586fddb

Browse files
authored
Merge pull request #7509 from hvitved/csharp/stubs-from-source
C#: Treat QL test stubs as not from source
2 parents f935df9 + 83c05f7 commit 586fddb

File tree

6 files changed

+50
-59
lines changed

6 files changed

+50
-59
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: 11 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,18 @@ class File extends Container, @file {
195197

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

200+
/** Holds if this file is a QL test stub file. */
201+
pragma[noinline]
202+
private predicate isStub() { this.getAbsolutePath().matches("%resources/stubs/%") }
203+
198204
/** Holds if this file contains source code. */
199-
predicate fromSource() { this.getExtension() = "cs" }
205+
final predicate fromSource() {
206+
this.getExtension() = "cs" and
207+
not this.isStub()
208+
}
200209

201210
/** Holds if this file is a library. */
202-
predicate fromLibrary() {
211+
final predicate fromLibrary() {
203212
not this.getBaseName() = "" and
204213
not this.fromSource()
205214
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ newtype CompilationExt =
7171
TBuildless() { extractionIsStandalone() }
7272

7373
/** Gets the compilation that source file `f` belongs to. */
74-
CompilationExt getCompilation(SourceFile f) {
74+
CompilationExt getCompilation(File f) {
7575
exists(Compilation c |
7676
f = c.getAFileCompiled() and
7777
result = TCompilation(c)

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.

csharp/ql/test/query-tests/Stubs/Minimal/MinimalStubsFromSource.expected

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)