-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFile.qll
More file actions
95 lines (73 loc) · 2.53 KB
/
File.qll
File metadata and controls
95 lines (73 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Provides classes representing filesystem files and folders.
*/
private import Comments
private import codeql.util.FileSystem
private module Input implements InputSig {
abstract class ContainerBase extends @container {
abstract string getAbsolutePath();
ContainerBase getParentContainer() { containerparent(result, this) }
string toString() { result = this.getAbsolutePath() }
}
class FolderBase extends ContainerBase, @folder {
override string getAbsolutePath() { folders(this, result) }
}
class FileBase extends ContainerBase, @file {
override string getAbsolutePath() { files(this, result) }
}
predicate hasSourceLocationPrefix = sourceLocationPrefix/1;
}
private module Impl = Make<Input>;
class Container = Impl::Container;
class Folder = Impl::Folder;
bindingset[flag]
private predicate fileHasExtractionFlag(File f, int flag) {
exists(int i |
file_extraction_mode(f, i) and
i.bitAnd(flag) = flag
)
}
/** A file. */
class File extends Container, Impl::File {
/** Gets the number of lines in this file. */
int getNumberOfLines() { numlines(this, result, _, _) }
/** Gets the number of lines containing code in this file. */
int getNumberOfLinesOfCode() { numlines(this, _, result, _) }
/** Gets the number of lines containing comments in this file. */
int getNumberOfLinesOfComments() { numlines(this, _, _, result) }
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
/** Holds if this file is a QL test stub file. */
pragma[noinline]
predicate isStub() {
this.extractedQlTest() and
this.getAbsolutePath().matches("%resources/stubs/%")
}
/** Holds if this file contains source code. */
final predicate fromSource() {
this.getExtension() = ["cs", "cshtml", "razor"] and
not this.isStub()
}
/** Holds if this file is a library. */
final predicate fromLibrary() {
not this.getBaseName() = "" and
not this.fromSource()
}
/**
* Holds if this source file came from a PDB.
* A source file can come from a PDB and from regular extraction
* in the same snapshot.
*/
predicate isPdbSourceFile() { fileHasExtractionFlag(this, 2) }
/**
* Holds if this file was extracted using `codeql test run`.
*/
predicate extractedQlTest() { fileHasExtractionFlag(this, 4) }
}
/**
* A source file.
*/
class SourceFile extends File {
SourceFile() { this.fromSource() }
/** Holds if the file was extracted without building the source code. */
predicate extractedStandalone() { fileHasExtractionFlag(this, 1) }
}