-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathAlertReporting.qll
More file actions
63 lines (52 loc) · 1.92 KB
/
AlertReporting.qll
File metadata and controls
63 lines (52 loc) · 1.92 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
/**
* 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.getAnExpandedElement() = re
}
/**
* Gets the primary macro invocation that generated the result element.
*/
MacroInvocation getPrimaryMacroInvocation(ResultElement re) {
exists(MacroInvocation mi |
mi = getAMacroInvocation(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) }
}
}