2
2
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
3
3
* given location.
4
4
*
5
- * Multiple instances of a statement at the same location can occur for two main reasons:
5
+ * Multiple instances of an element at the same location can occur for two main reasons:
6
6
* 1. Instantiations of a template
7
7
* 2. Re-compilation of a file under a different context
8
8
* This module helps ensure that a particular condition holds for all copies of a particular logical
9
- * statement . For example, this can be used to determine whether a line of code is dead in all copies
9
+ * element . For example, this can be used to determine whether a line of code is dead in all copies
10
10
* of a piece of code.
11
11
*
12
- * This module is parameterized by a set of _candidate_ statements in the program. For each candidate
13
- * statement , we determine whether all other statements that occur at the same location in the
14
- * program are also part of the same set, ignoring any results generated by macros.
12
+ * This module is parameterized by a set of _candidate_ elements in the program. For each candidate
13
+ * element , we determine whether all other elements in the same element set that occur at the same
14
+ * location in the program are also part of the same set, ignoring any results generated by macros.
15
15
*
16
- * We do so by reporting a new type of result, `LogicalResultStmt `, which represents a logical result
17
- * where all instances of a statement at a given location are considered to be part of the same set.
16
+ * We do so by reporting a new type of result, `LogicalResultElement `, which represents a logical result
17
+ * where all instances of a element at a given location are considered to be part of the same set.
18
18
*/
19
19
20
20
import cpp
21
21
22
22
/**
23
23
* Holds if the `Element` `e` is not within a macro expansion, i.e. generated by a macro, but not
24
- * the outermost `Stmt ` or `Expr` generated by the macro.
24
+ * the outermost `Element ` or `Expr` generated by the macro.
25
25
*/
26
26
predicate isNotWithinMacroExpansion ( Element e ) {
27
27
not e .isInMacroExpansion ( )
@@ -37,32 +37,35 @@ predicate isNotWithinMacroExpansion(Element e) {
37
37
)
38
38
}
39
39
40
- /** A candidate set of types. */
41
- signature class CandidateStmtSig extends Stmt ;
40
+ /** A candidate set of elements. */
41
+ signature class CandidateElementSig extends Element ;
42
+
43
+ /** The super set of relevant elements. */
44
+ signature class ElementSetSig extends Element ;
42
45
43
46
/**
44
47
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
45
48
* given location.
46
49
*/
47
- module HoldsForAllInstances< CandidateStmtSig CandidateStmt > {
50
+ module HoldsForAllInstances< CandidateElementSig CandidateElement , ElementSetSig ElementSet > {
48
51
private predicate hasLocation (
49
- Stmt s , string filepath , int startline , int startcolumn , int endline , int endcolumn
52
+ ElementSet s , string filepath , int startline , int startcolumn , int endline , int endcolumn
50
53
) {
51
54
s .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
52
55
}
53
56
54
- final private class MyStmt = Stmt ;
57
+ final private class MyElement = ElementSet ;
55
58
56
59
/**
57
- * A `Stmt ` that appears at the same location as a candidate statement .
60
+ * A `Element ` that appears at the same location as a candidate element .
58
61
*/
59
- private class RelevantStmt extends MyStmt {
60
- CandidateStmt s ;
62
+ private class RelevantElement extends MyElement {
63
+ CandidateElement e ;
61
64
62
- RelevantStmt ( ) {
65
+ RelevantElement ( ) {
63
66
exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
64
67
hasLocation ( this , filepath , startline , startcolumn , endline , endcolumn ) and
65
- hasLocation ( s , filepath , startline , startcolumn , endline , endcolumn )
68
+ hasLocation ( e , filepath , startline , startcolumn , endline , endcolumn )
66
69
) and
67
70
// Not within a macro expansion, as we cannot match up instances by location in that
68
71
// case
@@ -71,41 +74,43 @@ module HoldsForAllInstances<CandidateStmtSig CandidateStmt> {
71
74
not this instanceof Handler
72
75
}
73
76
74
- CandidateStmt getCandidateStmt ( ) { result = s }
77
+ CandidateElement getCandidateElement ( ) { result = e }
75
78
}
76
79
77
- newtype TResultStmts =
78
- TLogicalResultStmt ( string filepath , int startline , int startcolumn , int endline , int endcolumn ) {
79
- exists ( CandidateStmt s |
80
+ newtype TResultElements =
81
+ TLogicalResultElement (
82
+ string filepath , int startline , int startcolumn , int endline , int endcolumn
83
+ ) {
84
+ exists ( CandidateElement s |
80
85
// Only consider candidates where we can match up the location
81
86
isNotWithinMacroExpansion ( s ) and
82
87
hasLocation ( s , filepath , startline , startcolumn , endline , endcolumn ) and
83
- // All relevant statements that occur at the same location are candidates
84
- forex ( RelevantStmt relevantStmt | s = relevantStmt . getCandidateStmt ( ) |
85
- relevantStmt instanceof CandidateStmt
88
+ // All relevant elements that occur at the same location are candidates
89
+ forex ( RelevantElement relevantElement | s = relevantElement . getCandidateElement ( ) |
90
+ relevantElement instanceof CandidateElement
86
91
)
87
92
)
88
93
}
89
94
90
95
/**
91
- * A logical result statement , representing all instances of a statement that occur at the same
96
+ * A logical result element , representing all instances of a element that occur at the same
92
97
* location.
93
98
*/
94
- class LogicalResultStmt extends TLogicalResultStmt {
99
+ class LogicalResultElement extends TLogicalResultElement {
95
100
predicate hasLocationInfo (
96
101
string filepath , int startline , int startcolumn , int endline , int endcolumn
97
102
) {
98
- this = TLogicalResultStmt ( filepath , startline , startcolumn , endline , endcolumn )
103
+ this = TLogicalResultElement ( filepath , startline , startcolumn , endline , endcolumn )
99
104
}
100
105
101
- /** Gets an instance of this logical result statement . */
102
- CandidateStmt getAStmtInstance ( ) {
106
+ /** Gets an instance of this logical result element . */
107
+ CandidateElement getAnElementInstance ( ) {
103
108
exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
104
- this = TLogicalResultStmt ( filepath , startline , startcolumn , endline , endcolumn ) and
109
+ this = TLogicalResultElement ( filepath , startline , startcolumn , endline , endcolumn ) and
105
110
hasLocation ( result , filepath , startline , startcolumn , endline , endcolumn )
106
111
)
107
112
}
108
113
109
- string toString ( ) { result = getAStmtInstance ( ) .toString ( ) }
114
+ string toString ( ) { result = getAnElementInstance ( ) .toString ( ) }
110
115
}
111
116
}
0 commit comments