Skip to content

Commit e4c211d

Browse files
committed
C++: Address review comments
1 parent 20ce4cd commit e4c211d

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ class Node0Impl extends TIRDataFlowNode0 {
4949
DataFlowType getType() { none() } // overridden in subclasses
5050

5151
/** Gets the instruction corresponding to this node, if any. */
52-
Instruction asInstruction() {
53-
result = this.(InstructionNode0).getInstruction()
54-
or
55-
result = Ssa::getIRRepresentationOfOperand(this.(SingleUseOperandNode0).getOperand())
56-
}
52+
Instruction asInstruction() { result = this.(InstructionNode0).getInstruction() }
5753

5854
/** Gets the operands corresponding to this node, if any. */
5955
Operand asOperand() { result = this.(OperandNode0).getOperand() }
@@ -78,11 +74,9 @@ class Node0Impl extends TIRDataFlowNode0 {
7874
/**
7975
* An instruction, viewed as a node in a data flow graph.
8076
*/
81-
class InstructionNode0 extends Node0Impl, TInstructionNode0 {
77+
abstract class InstructionNode0 extends Node0Impl {
8278
Instruction instr;
8379

84-
InstructionNode0() { this = TInstructionNode0(instr) }
85-
8680
/** Gets the instruction corresponding to this node. */
8781
Instruction getInstruction() { result = instr }
8882

@@ -101,6 +95,25 @@ class InstructionNode0 extends Node0Impl, TInstructionNode0 {
10195
}
10296
}
10397

98+
/**
99+
* An instruction without an operand that is used only once, viewed as a node in a data flow graph.
100+
*/
101+
private class InstructionInstructionNode0 extends InstructionNode0, TInstructionNode0 {
102+
InstructionInstructionNode0() { this = TInstructionNode0(instr) }
103+
}
104+
105+
/**
106+
* An instruction with an operand that is used only once, viewed as a node in a data flow graph.
107+
*/
108+
private class SingleUseOperandInstructionNode0 extends InstructionNode0, TSingleUseOperandNode0 {
109+
SingleUseOperandInstructionNode0() {
110+
exists(Operand op |
111+
this = TSingleUseOperandNode0(op) and
112+
instr = Ssa::getIRRepresentationOfOperand(op)
113+
)
114+
}
115+
}
116+
104117
/**
105118
* An operand, viewed as a node in a data flow graph.
106119
*/
@@ -124,14 +137,14 @@ abstract class OperandNode0 extends Node0Impl {
124137
/**
125138
* An operand that is used multiple times, viewed as a node in a data flow graph.
126139
*/
127-
class MultipleUseOperandNode0 extends OperandNode0, TMultipleUseOperandNode0 {
140+
private class MultipleUseOperandNode0 extends OperandNode0, TMultipleUseOperandNode0 {
128141
MultipleUseOperandNode0() { this = TMultipleUseOperandNode0(op) }
129142
}
130143

131144
/**
132145
* An operand that is used only once, viewed as a node in a data flow graph.
133146
*/
134-
class SingleUseOperandNode0 extends OperandNode0, TSingleUseOperandNode0 {
147+
private class SingleUseOperandNode0 extends OperandNode0, TSingleUseOperandNode0 {
135148
SingleUseOperandNode0() { this = TSingleUseOperandNode0(op) }
136149
}
137150

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,10 @@ private class Node0 extends Node, TNode0 {
383383
* An instruction, viewed as a node in a data flow graph.
384384
*/
385385
class InstructionNode extends Node0 {
386+
override InstructionNode0 node;
386387
Instruction instr;
387388

388-
InstructionNode() {
389-
node.(InstructionNode0).getInstruction() = instr
390-
or
391-
Ssa::getIRRepresentationOfOperand(node.(SingleUseOperandNode0).getOperand()) = instr
392-
}
389+
InstructionNode() { instr = node.getInstruction() }
393390

394391
/** Gets the instruction corresponding to this node. */
395392
Instruction getInstruction() { result = instr }

0 commit comments

Comments
 (0)