Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
 * Rename HoldsForAllInstances to HoldsForAllCopies
 * Improve documentation
  • Loading branch information
lcartey committed Oct 15, 2024
1 parent f66e7c5 commit 2a17ba7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions c/misra/src/rules/RULE-2-2/DeadCode.ql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import cpp
import codingstandards.c.misra
import codingstandards.cpp.alertreporting.HoldsForAllInstances
import codingstandards.cpp.alertreporting.HoldsForAllCopies
import codingstandards.cpp.deadcode.UselessAssignments

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ class DeadOperationInstance extends Expr {
string getDescription() { result = description }
}

class DeadOperation = HoldsForAllInstances<DeadOperationInstance, Expr>::LogicalResultElement;
class DeadOperation = HoldsForAllCopies<DeadOperationInstance, Expr>::LogicalResultElement;

from
DeadOperation deadOperation, DeadOperationInstance instance, string message, Element explainer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
* given location.
* A module for considering whether a result occurs in all copies of the code at a given location.
*
* Multiple instances of an element at the same location can occur for two main reasons:
* Multiple copies of an element at the same location can occur for two main reasons:
* 1. Instantiations of a template
* 2. Re-compilation of a file under a different context
* This module helps ensure that a particular condition holds for all copies of a particular logical
Expand Down Expand Up @@ -37,17 +36,21 @@ predicate isNotWithinMacroExpansion(Element e) {
)
}

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

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

/**
* A module for considering whether a result occurs in all instances (e.g. copies) of the code at a
* given location.
* A module for considering whether a result occurs in all copies of the code at a given location.
*/
module HoldsForAllInstances<CandidateElementSig CandidateElement, ElementSetSig ElementSet> {
module HoldsForAllCopies<CandidateElementSig CandidateElement, ElementSetSig ElementSet> {
private predicate hasLocation(
ElementSet s, string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
Expand Down Expand Up @@ -93,8 +96,8 @@ module HoldsForAllInstances<CandidateElementSig CandidateElement, ElementSetSig
}

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

/** Gets an instance of this logical result element. */
/** Gets a copy instance of this logical result element. */
CandidateElement getAnElementInstance() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
this = TLogicalResultElement(filepath, startline, startcolumn, endline, endcolumn) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import cpp
import codingstandards.cpp.alertreporting.HoldsForAllInstances
import codingstandards.cpp.alertreporting.HoldsForAllCopies
import codingstandards.cpp.Customizations
import codingstandards.cpp.Exclusions
import codingstandards.cpp.deadcode.UselessAssignments
Expand Down Expand Up @@ -122,7 +122,7 @@ class DeadStmtInstance extends Stmt {
}
}

class DeadStmt = HoldsForAllInstances<DeadStmtInstance, Stmt>::LogicalResultElement;
class DeadStmt = HoldsForAllCopies<DeadStmtInstance, Stmt>::LogicalResultElement;

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

0 comments on commit 2a17ba7

Please sign in to comment.