C++: Introduce operand dataflow node

This commit is contained in:
Mathias Vorreiter Pedersen
2020-06-24 18:26:17 +02:00
parent 791f31fa65
commit d7a9d3d8bc

View File

@@ -13,6 +13,7 @@ private import semmle.code.cpp.models.interfaces.DataFlow
private newtype TIRDataFlowNode =
TInstructionNode(Instruction i) or
TOperandNode(Operand op) or
TVariableNode(Variable var)
/**
@@ -37,6 +38,9 @@ class Node extends TIRDataFlowNode {
/** Gets the instruction corresponding to this node, if any. */
Instruction asInstruction() { result = this.(InstructionNode).getInstruction() }
/** Gets the operands corresponding to this node, if any. */
Operand asOperand() { result = this.(OperandNode).getOperand() }
/**
* Gets the non-conversion expression corresponding to this node, if any. If
* this node strictly (in the sense of `asConvertedExpr`) corresponds to a
@@ -132,6 +136,28 @@ class InstructionNode extends Node, TInstructionNode {
}
}
/**
* An operand, viewed as a node in a data flow graph.
*/
class OperandNode extends Node, TOperandNode {
Operand op;
OperandNode() { this = TOperandNode(op) }
/** Gets the operand corresponding to this node. */
Operand getOperand() { result = op }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Function getFunction() { result = op.getUse().getEnclosingFunction() }
override Type getType() { result = op.getType() }
override Location getLocation() { result = op.getLocation() }
override string toString() { result = this.getOperand().toString() }
}
/**
* An expression, viewed as a node in a data flow graph.
*/