Skip to content

Commit e604756

Browse files
authored
Merge pull request github#8728 from asgerf/ql/library-coverage
QL: Add facilities for data flow
2 parents cb898ae + a5ad4c8 commit e604756

File tree

17 files changed

+1564
-4
lines changed

17 files changed

+1564
-4
lines changed

config/identical-files.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@
383383
"csharp/ql/test/TestUtilities/InlineExpectationsTest.qll",
384384
"java/ql/test/TestUtilities/InlineExpectationsTest.qll",
385385
"python/ql/test/TestUtilities/InlineExpectationsTest.qll",
386-
"ruby/ql/test/TestUtilities/InlineExpectationsTest.qll"
386+
"ruby/ql/test/TestUtilities/InlineExpectationsTest.qll",
387+
"ql/ql/test/TestUtilities/InlineExpectationsTest.qll"
387388
],
388389
"C++ ExternalAPIs": [
389390
"cpp/ql/src/Security/CWE/CWE-020/ExternalAPIs.qll",

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class AstNode extends TAstNode {
7979

8080
/** Gets an annotation of this AST node. */
8181
Annotation getAnAnnotation() {
82+
not this instanceof Annotation and // avoid cyclic parent-child relationship
8283
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
8384
}
8485

@@ -125,6 +126,9 @@ class TopLevel extends TTopLevel, AstNode {
125126
/** Gets a `newtype` defined at the top-level of this module. */
126127
NewType getANewType() { result = this.getAMember() }
127128

129+
/** Gets a `select` clause in the top-level of this module. */
130+
Select getASelect() { result = this.getAMember() }
131+
128132
override ModuleMember getAChild(string pred) {
129133
pred = directMember("getAnImport") and result = this.getAnImport()
130134
or
@@ -137,6 +141,8 @@ class TopLevel extends TTopLevel, AstNode {
137141
pred = directMember("getANewType") and result = this.getANewType()
138142
or
139143
pred = directMember("getQLDoc") and result = this.getQLDoc()
144+
or
145+
pred = directMember("getASelect") and result = this.getASelect()
140146
}
141147

142148
QLDoc getQLDocFor(ModuleMember m) {
@@ -547,6 +553,9 @@ class VarDef extends TVarDef, AstNode {
547553

548554
Type getType() { none() }
549555

556+
/** Gets a variable access to this `VarDef` */
557+
VarAccess getAnAccess() { result.getDeclaration() = this }
558+
550559
override string getAPrimaryQlClass() { result = "VarDef" }
551560

552561
override string toString() { result = this.getName() }
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
private import codeql_ql.ast.Ast
2+
3+
pragma[inline]
4+
private predicate isNumberedNode(AstNode node) {
5+
// these are not nested in the location of the parent node, so we can't use their location to order them
6+
not node instanceof Annotation and
7+
not node instanceof QLDoc
8+
}
9+
10+
private int getNodeDepth(AstNode node) {
11+
node instanceof TopLevel and
12+
result = 0
13+
or
14+
isNumberedNode(node) and
15+
result = 1 + getNodeDepth(node.getParent())
16+
}
17+
18+
/**
19+
* Gets the pre-order ID for the given `node`, that is, its visit position
20+
* in a pre-order traversal of all nodes.
21+
*
22+
* The children of a node are ordered left-to-right as they appear in the source code.
23+
*
24+
* The ID is globally unique for this AST node, also across files.
25+
*
26+
* At the moment this predicate is only defined for node which are:
27+
* - reachable via `getAChild` edges from a `TopLevel`, and
28+
* - is not a comment or annotation
29+
*/
30+
cached
31+
int getPreOrderId(AstNode node) {
32+
node =
33+
rank[result](AstNode n, Location loc, int depth |
34+
depth = getNodeDepth(n) and loc = n.getLocation()
35+
|
36+
n order by loc.getFile().getAbsolutePath(), loc.getStartLine(), loc.getStartColumn(), depth
37+
)
38+
}

ql/ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ QL::AstNode toQL(AST::AstNode n) {
204204
class TPredicate =
205205
TCharPred or TClasslessPredicate or TClassPredicate or TDBRelation or TNewTypeBranch;
206206

207-
class TPredOrBuiltin = TPredicate or TNewTypeBranch or TBuiltin;
207+
class TPredOrBuiltin = TPredicate or TBuiltin;
208208

209209
class TBuiltin = TBuiltinClassless or TBuiltinMember;
210210

0 commit comments

Comments
 (0)