-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathidentity_string.ql
More file actions
83 lines (66 loc) · 2.43 KB
/
Copy pathidentity_string.ql
File metadata and controls
83 lines (66 loc) · 2.43 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
import cpp
import semmle.code.cpp.Print
abstract class CheckCall extends FunctionCall {
abstract string getActualString();
final string getExpectedString() {
exists(int lastArgIndex |
lastArgIndex = this.getNumberOfArguments() - 1 and
(
result = this.getArgument(lastArgIndex).getValue()
or
not exists(this.getArgument(lastArgIndex).getValue()) and result = "<missing>"
)
)
}
abstract string explain();
}
class CheckTypeCall extends CheckCall {
CheckTypeCall() {
this.getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_type")
}
override string getActualString() {
result = getTypeIdentityString(this.getSpecifiedType())
or
not exists(getTypeIdentityString(this.getSpecifiedType())) and result = "<missing>"
}
override string explain() { result = this.getSpecifiedType().explain() }
final Type getSpecifiedType() { result = this.getTarget().getTemplateArgument(0) }
}
class CheckFuncCall extends CheckCall {
CheckFuncCall() {
this.getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_func")
}
override string getActualString() {
result = getIdentityString(this.getSpecifiedFunction())
or
not exists(getIdentityString(this.getSpecifiedFunction())) and result = "<missing>"
}
override string explain() { result = this.getSpecifiedFunction().toString() }
final Function getSpecifiedFunction() {
result = this.getArgument(0).(FunctionAccess).getTarget()
}
}
class CheckVarCall extends CheckCall {
CheckVarCall() {
this.getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_var")
}
override string getActualString() {
result = getIdentityString(this.getSpecifiedVariable())
or
not exists(getIdentityString(this.getSpecifiedVariable())) and result = "<missing>"
}
override string explain() { result = this.getSpecifiedVariable().toString() }
final Variable getSpecifiedVariable() {
result = this.getArgument(0).(VariableAccess).getTarget()
}
}
bindingset[s]
private string normalizeLambdas(string s) {
result = s.regexpReplaceAll("line \\d+, col\\. \\d+", "line ?, col. ?")
}
from CheckCall call, string expected, string actual
where
expected = call.getExpectedString() and
actual = normalizeLambdas(call.getActualString()) and
expected != actual
select call, "Expected: '" + expected + "'", "Actual: '" + actual + "'", call.explain()