Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94e6fd9

Browse files
committed
Python: Convenience methods
asVar, asCfgNode, and asExpr
1 parent 5a73473 commit 94e6fd9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

python/ql/src/experimental/dataflow/internal/DataFlowPublic.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class Node extends TNode {
5151
) {
5252
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
5353
}
54+
55+
/** Convenience method for casting to EssaNode and calling getVar. */
56+
EssaVariable asVar() { none() }
57+
58+
/** Convenience method for casting to CfgNode and calling getNode. */
59+
DataFlowCfgNode asCfgNode() { none() }
60+
61+
/** Convenience method for casting to ExprNode and calling getNode and getNode again. */
62+
Expr asExpr() { none() }
5463
}
5564

5665
class EssaNode extends Node, TEssaNode {
@@ -60,6 +69,8 @@ class EssaNode extends Node, TEssaNode {
6069

6170
EssaVariable getVar() { result = var }
6271

72+
override EssaVariable asVar() { result = var }
73+
6374
/** Gets a textual representation of this element. */
6475
override string toString() { result = var.toString() }
6576

@@ -75,6 +86,8 @@ class CfgNode extends Node, TCfgNode {
7586

7687
DataFlowCfgNode getNode() { result = node }
7788

89+
override DataFlowCfgNode asCfgNode() { result = node }
90+
7891
/** Gets a textual representation of this element. */
7992
override string toString() { result = node.toString() }
8093

@@ -92,6 +105,8 @@ class CfgNode extends Node, TCfgNode {
92105
*/
93106
class ExprNode extends CfgNode {
94107
ExprNode() { isExpressionNode(node) }
108+
109+
override Expr asExpr() { result = node.getNode() }
95110
}
96111

97112
/** Gets a node corresponding to expression `e`. */

0 commit comments

Comments
 (0)