-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathInlineMadTest.qll
34 lines (29 loc) · 1012 Bytes
/
InlineMadTest.qll
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
private import cpp
private import codeql.mad.test.InlineMadTest
class MadRelevantFunction extends Function {
MadRelevantFunction() { not this.isFromUninstantiatedTemplate(_) }
}
private module InlineMadTestLang implements InlineMadTestLangSig {
class Callable = MadRelevantFunction;
/**
* Holds if `c` is the closest `Callable` that succeeds `comment` in the file.
*/
private predicate hasClosestCallable(CppStyleComment comment, Callable c) {
c =
min(Callable cand, int dist |
// This has no good join order, but should hopefully be good enough for tests.
cand.getFile() = comment.getFile() and
dist = cand.getLocation().getStartLine() - comment.getLocation().getStartLine() and
dist > 0
|
cand order by dist
)
}
string getComment(Callable c) {
exists(CppStyleComment comment |
hasClosestCallable(comment, c) and
result = comment.getContents().suffix(2)
)
}
}
import InlineMadTestImpl<InlineMadTestLang>