Skip to content

Commit 2a17ba7

Browse files
committed
Address review comments
* Rename HoldsForAllInstances to HoldsForAllCopies * Improve documentation
1 parent f66e7c5 commit 2a17ba7

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

c/misra/src/rules/RULE-2-2/DeadCode.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import cpp
1717
import codingstandards.c.misra
18-
import codingstandards.cpp.alertreporting.HoldsForAllInstances
18+
import codingstandards.cpp.alertreporting.HoldsForAllCopies
1919
import codingstandards.cpp.deadcode.UselessAssignments
2020

2121
/**
@@ -75,7 +75,7 @@ class DeadOperationInstance extends Expr {
7575
string getDescription() { result = description }
7676
}
7777

78-
class DeadOperation = HoldsForAllInstances<DeadOperationInstance, Expr>::LogicalResultElement;
78+
class DeadOperation = HoldsForAllCopies<DeadOperationInstance, Expr>::LogicalResultElement;
7979

8080
from
8181
DeadOperation deadOperation, DeadOperationInstance instance, string message, Element explainer,

cpp/common/src/codingstandards/cpp/alertreporting/HoldsForAllInstances.qll renamed to cpp/common/src/codingstandards/cpp/alertreporting/HoldsForAllCopies.qll

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
2-
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
3-
* given location.
2+
* A module for considering whether a result occurs in all copies of the code at a given location.
43
*
5-
* Multiple instances of an element at the same location can occur for two main reasons:
4+
* Multiple copies of an element at the same location can occur for two main reasons:
65
* 1. Instantiations of a template
76
* 2. Re-compilation of a file under a different context
87
* This module helps ensure that a particular condition holds for all copies of a particular logical
@@ -37,17 +36,21 @@ predicate isNotWithinMacroExpansion(Element e) {
3736
)
3837
}
3938

40-
/** A candidate set of elements. */
39+
/**
40+
* A type representing a set of Element's in the program that satisfy some condition.
41+
*
42+
* `HoldsForAllCopies<T>::LogicalResultElement` will represent an element in this set
43+
* iff all copies of that element satisfy the condition.
44+
*/
4145
signature class CandidateElementSig extends Element;
4246

4347
/** The super set of relevant elements. */
4448
signature class ElementSetSig extends Element;
4549

4650
/**
47-
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
48-
* given location.
51+
* A module for considering whether a result occurs in all copies of the code at a given location.
4952
*/
50-
module HoldsForAllInstances<CandidateElementSig CandidateElement, ElementSetSig ElementSet> {
53+
module HoldsForAllCopies<CandidateElementSig CandidateElement, ElementSetSig ElementSet> {
5154
private predicate hasLocation(
5255
ElementSet s, string filepath, int startline, int startcolumn, int endline, int endcolumn
5356
) {
@@ -93,8 +96,8 @@ module HoldsForAllInstances<CandidateElementSig CandidateElement, ElementSetSig
9396
}
9497

9598
/**
96-
* A logical result element, representing all instances of a element that occur at the same
97-
* location.
99+
* A logical result element representing all copies of an element that occur at the same
100+
* location, iff they all belong to the `CandidateElement` set.
98101
*/
99102
class LogicalResultElement extends TLogicalResultElement {
100103
predicate hasLocationInfo(
@@ -103,7 +106,7 @@ module HoldsForAllInstances<CandidateElementSig CandidateElement, ElementSetSig
103106
this = TLogicalResultElement(filepath, startline, startcolumn, endline, endcolumn)
104107
}
105108

106-
/** Gets an instance of this logical result element. */
109+
/** Gets a copy instance of this logical result element. */
107110
CandidateElement getAnElementInstance() {
108111
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
109112
this = TLogicalResultElement(filepath, startline, startcolumn, endline, endcolumn) and

cpp/common/src/codingstandards/cpp/rules/deadcode/DeadCode.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
import cpp
15-
import codingstandards.cpp.alertreporting.HoldsForAllInstances
15+
import codingstandards.cpp.alertreporting.HoldsForAllCopies
1616
import codingstandards.cpp.Customizations
1717
import codingstandards.cpp.Exclusions
1818
import codingstandards.cpp.deadcode.UselessAssignments
@@ -122,7 +122,7 @@ class DeadStmtInstance extends Stmt {
122122
}
123123
}
124124

125-
class DeadStmt = HoldsForAllInstances<DeadStmtInstance, Stmt>::LogicalResultElement;
125+
class DeadStmt = HoldsForAllCopies<DeadStmtInstance, Stmt>::LogicalResultElement;
126126

127127
query predicate problems(DeadStmt s, string message) {
128128
not isExcluded(s.getAnElementInstance(), getQuery()) and

0 commit comments

Comments
 (0)