Repository navigation
Expand file tree
/
Copy pathInlineExpectationsTestImpl.qll
More file actions
51 lines (41 loc) · 1.89 KB
/
Copy pathInlineExpectationsTestImpl.qll
File metadata and controls
51 lines (41 loc) · 1.89 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
import cpp as C
private import codeql.util.test.InlineExpectationsTest
module Impl implements InlineExpectationsTestSig {
private newtype TExpectationComment = MkExpectationComment(C::CppStyleComment c)
/**
* A class representing a line comment in the CPP style.
* Unlike the `CppStyleComment` class, however, the string returned by `getContents` does _not_
* include the preceding comment marker (`//`).
*/
class ExpectationComment extends TExpectationComment {
C::CppStyleComment comment;
ExpectationComment() { this = MkExpectationComment(comment) }
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = comment.getContents().suffix(2) }
/** C++ expectation comments use line-comment syntax. */
predicate isLineComment() { any() }
/** Gets a textual representation of this element. */
string toString() { result = comment.toString() }
/** Gets the location of this comment. */
Location getLocation() { result = comment.getLocation() }
}
class Location = C::Location;
string getRelativeUrl(Location location) {
exists(C::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// C/C++ databases can also contain XML (e.g. `.xml`, `.props`), whose block-comment
// syntax is not yet supported, so we only render for C/C++ sources.
relativePath
.toLowerCase()
.regexpMatch(".*\\.(c|i|cc|cp|cpp|cxx|c\\+\\+|icc|ipp|ixx|i\\+\\+|ii|h|r|hh|hp|hpp|hxx|h\\+\\+|tcc|tpp|txx|t\\+\\+|inl|cu|cuh)") and
result = "//"
}
}