Skip to content

Commit 08c53d4

Browse files
committed
C++: Clean up the ParameterNode class tree
The new names are chosen to align with Java's `DataFlowUtil.qll`.
1 parent b622d62 commit 08c53d4

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Node extends TIRDataFlowNode {
5555
Expr asDefiningArgument() { result = this.(DefinitionByReferenceNode).getArgument() }
5656

5757
/** Gets the positional parameter corresponding to this node, if any. */
58-
Parameter asParameter() { result = this.(PositionalParameterNode).getParameter() }
58+
Parameter asParameter() { result = this.(ExplicitParameterNode).getParameter() }
5959

6060
/**
6161
* Gets the variable corresponding to this node, if any. This can be used for
@@ -157,18 +157,32 @@ int getArgumentPosOfSideEffect(int index) {
157157

158158
/**
159159
* The value of a parameter at function entry, viewed as a node in a data
160-
* flow graph.
160+
* flow graph. This type includes implicit parameters.
161+
*
162+
* To match a specific kind of parameter, consider using one of the subclasses
163+
* `ExplicitParameterNode`, `InstanceParameterNode`, or
164+
* `ParameterIndirectionNode`.
161165
*/
162-
abstract class ParameterNode extends InstructionNode {
166+
class ParameterNode extends InstructionNode {
167+
ParameterNode() {
168+
// To avoid making this class abstract, we enumerate its values here
169+
instr instanceof InitializeThisInstruction
170+
or
171+
instr instanceof InitializeParameterInstruction
172+
or
173+
instr instanceof InitializeIndirectionInstruction
174+
}
175+
163176
/**
164177
* Holds if this node is the parameter of `f` at the specified position. The
165178
* implicit `this` parameter is considered to have position `-1`, and
166179
* pointer-indirection parameters are at further negative positions.
167180
*/
168-
abstract predicate isParameterOf(Function f, int pos);
181+
predicate isParameterOf(Function f, int pos) { none() } // overridden in subclasses
169182
}
170183

171-
private class ThisParameterNode extends ParameterNode {
184+
/** An implicit `this` parameter. */
185+
class InstanceParameterNode extends ParameterNode {
172186
override InitializeThisInstruction instr;
173187

174188
override predicate isParameterOf(Function f, int pos) {
@@ -179,7 +193,8 @@ private class ThisParameterNode extends ParameterNode {
179193
override string toString() { result = "this" }
180194
}
181195

182-
class PositionalParameterNode extends ParameterNode {
196+
/** An explicit positional parameter, not including `this` or `...`. */
197+
class ExplicitParameterNode extends ParameterNode {
183198
override InitializeParameterInstruction instr;
184199

185200
override predicate isParameterOf(Function f, int pos) {
@@ -192,7 +207,8 @@ class PositionalParameterNode extends ParameterNode {
192207
override string toString() { result = this.getParameter().toString() }
193208
}
194209

195-
private class ParameterIndirectionNode extends ParameterNode {
210+
/** A virtual parameter to model the pointed-to object of a pointer parameter. */
211+
class ParameterIndirectionNode extends ParameterNode {
196212
override InitializeIndirectionInstruction instr;
197213

198214
override predicate isParameterOf(Function f, int pos) {
@@ -336,7 +352,7 @@ ExprNode convertedExprNode(Expr e) { result.getExpr() = e }
336352
/**
337353
* Gets the `Node` corresponding to the value of `p` at function entry.
338354
*/
339-
PositionalParameterNode parameterNode(Parameter p) { result.getParameter() = p }
355+
ExplicitParameterNode parameterNode(Parameter p) { result.getParameter() = p }
340356

341357
/** Gets the `VariableNode` corresponding to the variable `v`. */
342358
VariableNode variableNode(Variable v) { result.getVariable() = v }

0 commit comments

Comments
 (0)