Skip to content

Commit 353d5f8

Browse files
authored
Merge pull request github#12984 from aschackmull/dataflow/instanceof-node
Dataflow: Replace "extends Node" with "instanceof Node".
2 parents 0ce27d1 + ca09649 commit 353d5f8

File tree

12 files changed

+364
-44
lines changed

12 files changed

+364
-44
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,16 @@ predicate recordDataFlowCallSite(DataFlowCall call, DataFlowCallable callable) {
961961
/**
962962
* A `Node` at which a cast can occur such that the type should be checked.
963963
*/
964-
class CastingNode extends Node {
964+
class CastingNode instanceof Node {
965965
CastingNode() { castingNode(this) }
966+
967+
string toString() { result = super.toString() }
968+
969+
predicate hasLocationInfo(
970+
string filepath, int startline, int startcolumn, int endline, int endcolumn
971+
) {
972+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
973+
}
966974
}
967975

968976
private predicate readStepWithTypes(
@@ -1110,9 +1118,17 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
11101118
* The value of a parameter at function entry, viewed as a node in a data
11111119
* flow graph.
11121120
*/
1113-
class ParamNode extends Node {
1121+
class ParamNode instanceof Node {
11141122
ParamNode() { parameterNode(this, _, _) }
11151123

1124+
string toString() { result = super.toString() }
1125+
1126+
predicate hasLocationInfo(
1127+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1128+
) {
1129+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1130+
}
1131+
11161132
/**
11171133
* Holds if this node is the parameter of callable `c` at the specified
11181134
* position.
@@ -1121,9 +1137,17 @@ class ParamNode extends Node {
11211137
}
11221138

11231139
/** A data-flow node that represents a call argument. */
1124-
class ArgNode extends Node {
1140+
class ArgNode instanceof Node {
11251141
ArgNode() { argumentNode(this, _, _) }
11261142

1143+
string toString() { result = super.toString() }
1144+
1145+
predicate hasLocationInfo(
1146+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1147+
) {
1148+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1149+
}
1150+
11271151
/** Holds if this argument occurs at the given position in the given call. */
11281152
final predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
11291153
argumentNode(this, call, pos)
@@ -1134,9 +1158,17 @@ class ArgNode extends Node {
11341158
* A node from which flow can return to the caller. This is either a regular
11351159
* `ReturnNode` or a `PostUpdateNode` corresponding to the value of a parameter.
11361160
*/
1137-
class ReturnNodeExt extends Node {
1161+
class ReturnNodeExt instanceof Node {
11381162
ReturnNodeExt() { returnNodeExt(this, _) }
11391163

1164+
string toString() { result = super.toString() }
1165+
1166+
predicate hasLocationInfo(
1167+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1168+
) {
1169+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1170+
}
1171+
11401172
/** Gets the kind of this returned value. */
11411173
ReturnKindExt getKind() { returnNodeExt(this, result) }
11421174
}
@@ -1145,8 +1177,16 @@ class ReturnNodeExt extends Node {
11451177
* A node to which data can flow from a call. Either an ordinary out node
11461178
* or a post-update node associated with a call argument.
11471179
*/
1148-
class OutNodeExt extends Node {
1180+
class OutNodeExt instanceof Node {
11491181
OutNodeExt() { outNodeExt(this) }
1182+
1183+
string toString() { result = super.toString() }
1184+
1185+
predicate hasLocationInfo(
1186+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1187+
) {
1188+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1189+
}
11501190
}
11511191

11521192
/**

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

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,16 @@ predicate recordDataFlowCallSite(DataFlowCall call, DataFlowCallable callable) {
961961
/**
962962
* A `Node` at which a cast can occur such that the type should be checked.
963963
*/
964-
class CastingNode extends Node {
964+
class CastingNode instanceof Node {
965965
CastingNode() { castingNode(this) }
966+
967+
string toString() { result = super.toString() }
968+
969+
predicate hasLocationInfo(
970+
string filepath, int startline, int startcolumn, int endline, int endcolumn
971+
) {
972+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
973+
}
966974
}
967975

968976
private predicate readStepWithTypes(
@@ -1110,9 +1118,17 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
11101118
* The value of a parameter at function entry, viewed as a node in a data
11111119
* flow graph.
11121120
*/
1113-
class ParamNode extends Node {
1121+
class ParamNode instanceof Node {
11141122
ParamNode() { parameterNode(this, _, _) }
11151123

1124+
string toString() { result = super.toString() }
1125+
1126+
predicate hasLocationInfo(
1127+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1128+
) {
1129+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1130+
}
1131+
11161132
/**
11171133
* Holds if this node is the parameter of callable `c` at the specified
11181134
* position.
@@ -1121,9 +1137,17 @@ class ParamNode extends Node {
11211137
}
11221138

11231139
/** A data-flow node that represents a call argument. */
1124-
class ArgNode extends Node {
1140+
class ArgNode instanceof Node {
11251141
ArgNode() { argumentNode(this, _, _) }
11261142

1143+
string toString() { result = super.toString() }
1144+
1145+
predicate hasLocationInfo(
1146+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1147+
) {
1148+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1149+
}
1150+
11271151
/** Holds if this argument occurs at the given position in the given call. */
11281152
final predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
11291153
argumentNode(this, call, pos)
@@ -1134,9 +1158,17 @@ class ArgNode extends Node {
11341158
* A node from which flow can return to the caller. This is either a regular
11351159
* `ReturnNode` or a `PostUpdateNode` corresponding to the value of a parameter.
11361160
*/
1137-
class ReturnNodeExt extends Node {
1161+
class ReturnNodeExt instanceof Node {
11381162
ReturnNodeExt() { returnNodeExt(this, _) }
11391163

1164+
string toString() { result = super.toString() }
1165+
1166+
predicate hasLocationInfo(
1167+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1168+
) {
1169+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1170+
}
1171+
11401172
/** Gets the kind of this returned value. */
11411173
ReturnKindExt getKind() { returnNodeExt(this, result) }
11421174
}
@@ -1145,8 +1177,16 @@ class ReturnNodeExt extends Node {
11451177
* A node to which data can flow from a call. Either an ordinary out node
11461178
* or a post-update node associated with a call argument.
11471179
*/
1148-
class OutNodeExt extends Node {
1180+
class OutNodeExt instanceof Node {
11491181
OutNodeExt() { outNodeExt(this) }
1182+
1183+
string toString() { result = super.toString() }
1184+
1185+
predicate hasLocationInfo(
1186+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1187+
) {
1188+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1189+
}
11501190
}
11511191

11521192
/**

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,16 @@ predicate recordDataFlowCallSite(DataFlowCall call, DataFlowCallable callable) {
961961
/**
962962
* A `Node` at which a cast can occur such that the type should be checked.
963963
*/
964-
class CastingNode extends Node {
964+
class CastingNode instanceof Node {
965965
CastingNode() { castingNode(this) }
966+
967+
string toString() { result = super.toString() }
968+
969+
predicate hasLocationInfo(
970+
string filepath, int startline, int startcolumn, int endline, int endcolumn
971+
) {
972+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
973+
}
966974
}
967975

968976
private predicate readStepWithTypes(
@@ -1110,9 +1118,17 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
11101118
* The value of a parameter at function entry, viewed as a node in a data
11111119
* flow graph.
11121120
*/
1113-
class ParamNode extends Node {
1121+
class ParamNode instanceof Node {
11141122
ParamNode() { parameterNode(this, _, _) }
11151123

1124+
string toString() { result = super.toString() }
1125+
1126+
predicate hasLocationInfo(
1127+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1128+
) {
1129+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1130+
}
1131+
11161132
/**
11171133
* Holds if this node is the parameter of callable `c` at the specified
11181134
* position.
@@ -1121,9 +1137,17 @@ class ParamNode extends Node {
11211137
}
11221138

11231139
/** A data-flow node that represents a call argument. */
1124-
class ArgNode extends Node {
1140+
class ArgNode instanceof Node {
11251141
ArgNode() { argumentNode(this, _, _) }
11261142

1143+
string toString() { result = super.toString() }
1144+
1145+
predicate hasLocationInfo(
1146+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1147+
) {
1148+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1149+
}
1150+
11271151
/** Holds if this argument occurs at the given position in the given call. */
11281152
final predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
11291153
argumentNode(this, call, pos)
@@ -1134,9 +1158,17 @@ class ArgNode extends Node {
11341158
* A node from which flow can return to the caller. This is either a regular
11351159
* `ReturnNode` or a `PostUpdateNode` corresponding to the value of a parameter.
11361160
*/
1137-
class ReturnNodeExt extends Node {
1161+
class ReturnNodeExt instanceof Node {
11381162
ReturnNodeExt() { returnNodeExt(this, _) }
11391163

1164+
string toString() { result = super.toString() }
1165+
1166+
predicate hasLocationInfo(
1167+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1168+
) {
1169+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1170+
}
1171+
11401172
/** Gets the kind of this returned value. */
11411173
ReturnKindExt getKind() { returnNodeExt(this, result) }
11421174
}
@@ -1145,8 +1177,16 @@ class ReturnNodeExt extends Node {
11451177
* A node to which data can flow from a call. Either an ordinary out node
11461178
* or a post-update node associated with a call argument.
11471179
*/
1148-
class OutNodeExt extends Node {
1180+
class OutNodeExt instanceof Node {
11491181
OutNodeExt() { outNodeExt(this) }
1182+
1183+
string toString() { result = super.toString() }
1184+
1185+
predicate hasLocationInfo(
1186+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1187+
) {
1188+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1189+
}
11501190
}
11511191

11521192
/**

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ string captureThroughFlow(DataFlowTargetApi api) {
178178
string output
179179
|
180180
ThroughFlow::flow(p, returnNodeExt) and
181-
returnNodeExt.getEnclosingCallable() = api and
181+
returnNodeExt.(DataFlow::Node).getEnclosingCallable() = api and
182182
input = parameterNodeAsInput(p) and
183183
output = returnNodeAsOutput(returnNodeExt) and
184184
input != output and

csharp/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class InstanceParameterNode = DataFlowPrivate::InstanceParameterNode;
121121

122122
pragma[nomagic]
123123
private CS::Parameter getParameter(DataFlowImplCommon::ReturnNodeExt node, ParameterPosition pos) {
124-
result = node.getEnclosingCallable().getParameter(pos.getPosition())
124+
result = node.(DataFlow::Node).getEnclosingCallable().getParameter(pos.getPosition())
125125
}
126126

127127
/**

go/ql/lib/semmle/go/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,16 @@ predicate recordDataFlowCallSite(DataFlowCall call, DataFlowCallable callable) {
961961
/**
962962
* A `Node` at which a cast can occur such that the type should be checked.
963963
*/
964-
class CastingNode extends Node {
964+
class CastingNode instanceof Node {
965965
CastingNode() { castingNode(this) }
966+
967+
string toString() { result = super.toString() }
968+
969+
predicate hasLocationInfo(
970+
string filepath, int startline, int startcolumn, int endline, int endcolumn
971+
) {
972+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
973+
}
966974
}
967975

968976
private predicate readStepWithTypes(
@@ -1110,9 +1118,17 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
11101118
* The value of a parameter at function entry, viewed as a node in a data
11111119
* flow graph.
11121120
*/
1113-
class ParamNode extends Node {
1121+
class ParamNode instanceof Node {
11141122
ParamNode() { parameterNode(this, _, _) }
11151123

1124+
string toString() { result = super.toString() }
1125+
1126+
predicate hasLocationInfo(
1127+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1128+
) {
1129+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1130+
}
1131+
11161132
/**
11171133
* Holds if this node is the parameter of callable `c` at the specified
11181134
* position.
@@ -1121,9 +1137,17 @@ class ParamNode extends Node {
11211137
}
11221138

11231139
/** A data-flow node that represents a call argument. */
1124-
class ArgNode extends Node {
1140+
class ArgNode instanceof Node {
11251141
ArgNode() { argumentNode(this, _, _) }
11261142

1143+
string toString() { result = super.toString() }
1144+
1145+
predicate hasLocationInfo(
1146+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1147+
) {
1148+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1149+
}
1150+
11271151
/** Holds if this argument occurs at the given position in the given call. */
11281152
final predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
11291153
argumentNode(this, call, pos)
@@ -1134,9 +1158,17 @@ class ArgNode extends Node {
11341158
* A node from which flow can return to the caller. This is either a regular
11351159
* `ReturnNode` or a `PostUpdateNode` corresponding to the value of a parameter.
11361160
*/
1137-
class ReturnNodeExt extends Node {
1161+
class ReturnNodeExt instanceof Node {
11381162
ReturnNodeExt() { returnNodeExt(this, _) }
11391163

1164+
string toString() { result = super.toString() }
1165+
1166+
predicate hasLocationInfo(
1167+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1168+
) {
1169+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1170+
}
1171+
11401172
/** Gets the kind of this returned value. */
11411173
ReturnKindExt getKind() { returnNodeExt(this, result) }
11421174
}
@@ -1145,8 +1177,16 @@ class ReturnNodeExt extends Node {
11451177
* A node to which data can flow from a call. Either an ordinary out node
11461178
* or a post-update node associated with a call argument.
11471179
*/
1148-
class OutNodeExt extends Node {
1180+
class OutNodeExt instanceof Node {
11491181
OutNodeExt() { outNodeExt(this) }
1182+
1183+
string toString() { result = super.toString() }
1184+
1185+
predicate hasLocationInfo(
1186+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1187+
) {
1188+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1189+
}
11501190
}
11511191

11521192
/**

0 commit comments

Comments
 (0)