-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathancestors.ql
More file actions
63 lines (56 loc) · 1.6 KB
/
ancestors.ql
File metadata and controls
63 lines (56 loc) · 1.6 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
/**
* @kind graph
* @id rb/test/ancestors
*/
import codeql.ruby.AST
int locationModuleRank(Module node) {
node =
rank[result](Module m, Location l |
l = m.getLocation()
|
m
order by
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
)
}
int stringModuleRank(Module node) {
node = rank[result](Module m | not exists(locationModuleRank(m)) | m order by m.toString())
}
int moduleRank(Module node) {
result = locationModuleRank(node) + max(stringModuleRank(_))
or
result = stringModuleRank(node)
}
query predicate nodes(Module node, string key, string value) {
key = "semmle.label" and value = node.toString()
or
key = "semmle.order" and
value = moduleRank(node).toString()
}
Module getATarget(Module source, string value) {
result = source.getSuperClass() and value = "super"
or
result = source.getAPrependedModule() and value = "prepend"
or
result = source.getAnIncludedModule() and value = "include"
}
query predicate edges(Module source, Module target, string key, string value) {
key = "semmle.label" and
target = getATarget(source, value)
or
key = "semmle.order" and
value =
any(int i |
target =
rank[i](Module t, Location l |
t = getATarget(source, _) and
l = t.getLocation()
|
t
order by
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), t.toString()
)
).toString()
}