-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathAlertReporting.qll
More file actions
76 lines (64 loc) · 2.52 KB
/
AlertReporting.qll
File metadata and controls
76 lines (64 loc) · 2.52 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
/**
* Provides a library for managing how alerts are reported.
*/
import cpp
signature class ResultType extends Element;
/**
* A module for unwrapping results that occur in macro expansions.
*/
module MacroUnwrapper<ResultType ResultElement> {
/**
* Gets a macro invocation that applies to the result element.
*/
private MacroInvocation getAMacroInvocation(ResultElement re) {
result.getAnAffectedElement() = re
}
private MacroInvocation getASubsumedMacroInvocation(ResultElement re) {
result = getAMacroInvocation(re) and
// Only report cases where the element is not located at the macro expansion site
// This means we'll report results in macro arguments in the macro argument
// location, not within the macro itself.
//
// Do not join start column values.
pragma[only_bind_out](result.getLocation().getStartColumn()) =
pragma[only_bind_out](re.getLocation().getStartColumn())
}
/**
* Gets the primary macro invocation that generated the result element.
*
* Does not hold for cases where the result element is located at a macro argument site.
*/
MacroInvocation getPrimaryMacroInvocation(ResultElement re) {
exists(MacroInvocation mi |
mi = getASubsumedMacroInvocation(re) and
// No other more specific macro that expands to element
not exists(MacroInvocation otherMi |
otherMi = getAMacroInvocation(re) and otherMi.getParentInvocation() = mi
) and
result = mi
)
}
/**
* Gets the primary macro that generated the result element.
*/
Macro getPrimaryMacro(ResultElement re) { result = getPrimaryMacroInvocation(re).getMacro() }
/**
* If a result element is expanded from a macro invocation, then return the "primary" macro that
* generated the element, otherwise return the element itself.
*/
Element unwrapElement(ResultElement re) {
if exists(getPrimaryMacro(re)) then result = getPrimaryMacro(re) else result = re
}
/* Final class so we can extend it */
final private class FinalMacroInvocation = MacroInvocation;
/* A macro invocation that expands to create a `ResultElement` */
class ResultMacroExpansion extends FinalMacroInvocation {
ResultElement re;
ResultMacroExpansion() { re = getAnExpandedElement() }
ResultElement getResultElement() { result = re }
}
/* The most specific macro invocation that expands to create this `ResultElement`. */
class PrimaryMacroExpansion extends ResultMacroExpansion {
PrimaryMacroExpansion() { this = getPrimaryMacroInvocation(re) }
}
}