| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8179bff commit 717ff62
68 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -213,9 +213,11 @@ class ExprWithPointsTo extends Expr { | |||
| 213 | 213 | * Gets what this expression might "refer-to" in the given `context`. | |
| 214 | 214 | */ | |
| 215 | 215 | predicate refersTo(Context context, Object obj, ClassObject cls, AstNode origin) { | |
| 216 | - this.getAFlowNode() | ||
| 217 | - .(ControlFlowNodeWithPointsTo) | ||
| 218 | - .refersTo(context, obj, cls, origin.getAFlowNode()) | ||
| 216 | + exists(ControlFlowNode this_, ControlFlowNode origin_ | | ||
| 217 | + this_.getNode() = this and origin_.getNode() = origin | ||
| 218 | + | | ||
| 219 | + this_.(ControlFlowNodeWithPointsTo).refersTo(context, obj, cls, origin_) | ||
| 220 | + ) | ||
| 219 | 221 | } | |
| 220 | 222 | ||
| 221 | 223 | /** | |
@@ -226,7 +228,11 @@ class ExprWithPointsTo extends Expr { | |||
| 226 | 228 | */ | |
| 227 | 229 | pragma[nomagic] | |
| 228 | 230 | predicate refersTo(Object obj, AstNode origin) { | |
| 229 | - this.getAFlowNode().(ControlFlowNodeWithPointsTo).refersTo(obj, origin.getAFlowNode()) | ||
| 231 | + exists(ControlFlowNode this_, ControlFlowNode origin_ | | ||
| 232 | + this_.getNode() = this and origin_.getNode() = origin | ||
| 233 | + | | ||
| 234 | + this_.(ControlFlowNodeWithPointsTo).refersTo(obj, origin_) | ||
| 235 | + ) | ||
| 230 | 236 | } | |
| 231 | 237 | ||
| 232 | 238 | /** | |
@@ -240,16 +246,22 @@ class ExprWithPointsTo extends Expr { | |||
| 240 | 246 | * in the given `context`. | |
| 241 | 247 | */ | |
| 242 | 248 | predicate pointsTo(Context context, Value value, AstNode origin) { | |
| 243 | - this.getAFlowNode() | ||
| 244 | - .(ControlFlowNodeWithPointsTo) | ||
| 245 | - .pointsTo(context, value, origin.getAFlowNode()) | ||
| 249 | + exists(ControlFlowNode this_, ControlFlowNode origin_ | | ||
| 250 | + this_.getNode() = this and origin_.getNode() = origin | ||
| 251 | + | | ||
| 252 | + this_.(ControlFlowNodeWithPointsTo).pointsTo(context, value, origin_) | ||
| 253 | + ) | ||
| 246 | 254 | } | |
| 247 | 255 | ||
| 248 | 256 | /** | |
| 249 | 257 | * Holds if this expression might "point-to" to `value` which is from `origin`. | |
| 250 | 258 | */ | |
| 251 | 259 | predicate pointsTo(Value value, AstNode origin) { | |
| 252 | - this.getAFlowNode().(ControlFlowNodeWithPointsTo).pointsTo(value, origin.getAFlowNode()) | ||
| 260 | + exists(ControlFlowNode this_, ControlFlowNode origin_ | | ||
| 261 | + this_.getNode() = this and origin_.getNode() = origin | ||
| 262 | + | | ||
| 263 | + this_.(ControlFlowNodeWithPointsTo).pointsTo(value, origin_) | ||
| 264 | + ) | ||
| 253 | 265 | } | |
| 254 | 266 | ||
| 255 | 267 | /** | |
@@ -475,7 +487,10 @@ class FunctionMetricsWithPointsTo extends FunctionMetrics { | |||
| 475 | 487 | not non_coupling_method(result) and | |
| 476 | 488 | exists(Call call | call.getScope() = this | | |
| 477 | 489 | exists(FunctionObject callee | callee.getFunction() = result | | |
| 478 | - call.getAFlowNode().getFunction().(ControlFlowNodeWithPointsTo).refersTo(callee) | ||
| 490 | + exists(CallNode call_ | | ||
| 491 | + call_.getNode() = call and | ||
| 492 | + call_.getFunction().(ControlFlowNodeWithPointsTo).refersTo(callee) | ||
| 493 | + ) | ||
| 479 | 494 | ) | |
| 480 | 495 | or | |
| 481 | 496 | exists(Attribute a | call.getFunc() = a | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,7 +64,7 @@ private predicate jump_to_defn(ControlFlowNode use, Definition defn) { | |||
| 64 | 64 | private predicate preferred_jump_to_defn(Expr use, Definition def) { | |
| 65 | 65 | not use instanceof ClassExpr and | |
| 66 | 66 | not use instanceof FunctionExpr and | |
| 67 | - jump_to_defn(use.getAFlowNode(), def) | ||
| 67 | + exists(ControlFlowNode useNode | useNode.getNode() = use | jump_to_defn(useNode, def)) | ||
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | 70 | private predicate unique_jump_to_defn(Expr use, Definition def) { | |
@@ -452,7 +452,7 @@ private predicate self_parameter_jump_to_defn_attribute( | |||
| 452 | 452 | * This exists primarily for testing use `getPreferredDefinition()` instead. | |
| 453 | 453 | */ | |
| 454 | 454 | Definition getADefinition(Expr use) { | |
| 455 | - jump_to_defn(use.getAFlowNode(), result) and | ||
| 455 | + exists(ControlFlowNode useNode | useNode.getNode() = use | jump_to_defn(useNode, result)) and | ||
| 456 | 456 | not use instanceof Call and | |
| 457 | 457 | not use.isArtificial() and | |
| 458 | 458 | // Not the use itself | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + --- | ||
| 2 | + category: deprecated | ||
| 3 | + --- | ||
| 4 | + * The `AstNode.getAFlowNode()` predicate has been deprecated. Use `ControlFlowNode.getNode()` from the other direction instead: replace `e.getAFlowNode() = n` with `n.getNode() = e`. This is a preparatory step towards migrating the dataflow library off the legacy CFG; it has no semantic effect. | ||
| 5 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,12 +17,17 @@ abstract class AstNode extends AstNode_ { | |||
| 17 | 17 | abstract Scope getScope(); | |
| 18 | 18 | ||
| 19 | 19 | /** | |
| 20 | + * DEPRECATED: use `ControlFlowNode.getNode()` from the other direction instead; | ||
| 21 | + * that is, replace `e.getAFlowNode() = n` with `n.getNode() = e`. This API is | ||
| 22 | + * being removed to untangle the AST and CFG hierarchies in preparation for | ||
| 23 | + * migrating the dataflow library off the legacy CFG. | ||
| 24 | + * | ||
| 20 | 25 | * Gets a flow node corresponding directly to this node. | |
| 21 | 26 | * NOTE: For some statements and other purely syntactic elements, | |
| 22 | - * there may not be a `ControlFlowNode` | ||
| 27 | + * there may not be a `ControlFlowNode`. | ||
| 23 | 28 | */ | |
| 24 | 29 | cached | |
| 25 | - ControlFlowNode getAFlowNode() { | ||
| 30 | + deprecated ControlFlowNode getAFlowNode() { | ||
| 26 | 31 | Stages::AST::ref() and | |
| 27 | 32 | py_flow_bb_node(result, this, _, _) | |
| 28 | 33 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,9 @@ class Expr extends Expr_, AstNode { | |||
| 28 | 28 | /** Whether this expression may have a side effect (as determined purely from its syntax) */ | |
| 29 | 29 | predicate hasSideEffects() { | |
| 30 | 30 | /* If an exception raised by this expression handled, count that as a side effect */ | |
| 31 | - this.getAFlowNode().getASuccessor().getNode() instanceof ExceptStmt | ||
| 31 | + exists(ControlFlowNode n | n.getNode() = this | | ||
| 32 | + n.getASuccessor().getNode() instanceof ExceptStmt | ||
| 33 | + ) | ||
| 32 | 34 | or | |
| 33 | 35 | this.getASubExpression().hasSideEffects() | |
| 34 | 36 | } | |
@@ -68,7 +70,7 @@ class Attribute extends Attribute_ { | |||
| 68 | 70 | /* syntax: Expr.name */ | |
| 69 | 71 | override Expr getASubExpression() { result = this.getObject() } | |
| 70 | 72 | ||
| 71 | - override AttrNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 73 | + deprecated override AttrNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 72 | 74 | ||
| 73 | 75 | /** Gets the name of this attribute. That is the `name` in `obj.name` */ | |
| 74 | 76 | string getName() { result = Attribute_.super.getAttr() } | |
@@ -97,7 +99,7 @@ class Subscript extends Subscript_ { | |||
| 97 | 99 | ||
| 98 | 100 | Expr getObject() { result = Subscript_.super.getValue() } | |
| 99 | 101 | ||
| 100 | - override SubscriptNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 102 | + deprecated override SubscriptNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 101 | 103 | } | |
| 102 | 104 | ||
| 103 | 105 | /** A call expression, such as `func(...)` */ | |
@@ -113,7 +115,7 @@ class Call extends Call_ { | |||
| 113 | 115 | ||
| 114 | 116 | override string toString() { result = this.getFunc().toString() + "()" } | |
| 115 | 117 | ||
| 116 | - override CallNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 118 | + deprecated override CallNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 117 | 119 | ||
| 118 | 120 | /** Gets a tuple (*) argument of this call. */ | |
| 119 | 121 | Expr getStarargs() { result = this.getAPositionalArg().(Starred).getValue() } | |
@@ -201,7 +203,7 @@ class IfExp extends IfExp_ { | |||
| 201 | 203 | result = this.getTest() or result = this.getBody() or result = this.getOrelse() | |
| 202 | 204 | } | |
| 203 | 205 | ||
| 204 | - override IfExprNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 206 | + deprecated override IfExprNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 205 | 207 | } | |
| 206 | 208 | ||
| 207 | 209 | /** A starred expression, such as the `*rest` in the assignment `first, *rest = seq` */ | |
@@ -411,7 +413,7 @@ class PlaceHolder extends PlaceHolder_ { | |||
| 411 | 413 | ||
| 412 | 414 | override string toString() { result = "$" + this.getId() } | |
| 413 | 415 | ||
| 414 | - override NameNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 416 | + deprecated override NameNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 415 | 417 | } | |
| 416 | 418 | ||
| 417 | 419 | /** A tuple expression such as `( 1, 3, 5, 7, 9 )` */ | |
@@ -478,7 +480,7 @@ class Name extends Name_ { | |||
| 478 | 480 | ||
| 479 | 481 | override string toString() { result = this.getId() } | |
| 480 | 482 | ||
| 481 | - override NameNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 483 | + deprecated override NameNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 482 | 484 | ||
| 483 | 485 | override predicate isArtificial() { | |
| 484 | 486 | /* Artificial variable names in comprehensions all start with "." */ | |
@@ -585,7 +587,7 @@ abstract class NameConstant extends Name, ImmutableLiteral { | |||
| 585 | 587 | ||
| 586 | 588 | override predicate isConstant() { any() } | |
| 587 | 589 | ||
| 588 | - override NameConstantNode getAFlowNode() { result = Name.super.getAFlowNode() } | ||
| 590 | + deprecated override NameConstantNode getAFlowNode() { result = Name.super.getAFlowNode() } | ||
| 589 | 591 | ||
| 590 | 592 | override predicate isArtificial() { none() } | |
| 591 | 593 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,27 +555,27 @@ class DefinitionNode extends ControlFlowNode { | |||
| 555 | 555 | cached | |
| 556 | 556 | DefinitionNode() { | |
| 557 | 557 | Stages::AST::ref() and | |
| 558 | - exists(Assign a | a.getATarget().getAFlowNode() = this) | ||
| 558 | + exists(Assign a | this.getNode() = a.getATarget()) | ||
| 559 | 559 | or | |
| 560 | - exists(AssignExpr a | a.getTarget().getAFlowNode() = this) | ||
| 560 | + exists(AssignExpr a | this.getNode() = a.getTarget()) | ||
| 561 | 561 | or | |
| 562 | - exists(AnnAssign a | a.getTarget().getAFlowNode() = this and exists(a.getValue())) | ||
| 562 | + exists(AnnAssign a | this.getNode() = a.getTarget() and exists(a.getValue())) | ||
| 563 | 563 | or | |
| 564 | - exists(Alias a | a.getAsname().getAFlowNode() = this) | ||
| 564 | + exists(Alias a | this.getNode() = a.getAsname()) | ||
| 565 | 565 | or | |
| 566 | 566 | augstore(_, this) | |
| 567 | 567 | or | |
| 568 | 568 | // `x, y = 1, 2` where LHS is a combination of list or tuples | |
| 569 | - exists(Assign a | list_or_tuple_nested_element(a.getATarget()).getAFlowNode() = this) | ||
| 569 | + exists(Assign a | this.getNode() = list_or_tuple_nested_element(a.getATarget())) | ||
| 570 | 570 | or | |
| 571 | - exists(For for | for.getTarget().getAFlowNode() = this) | ||
| 571 | + exists(For for | this.getNode() = for.getTarget()) | ||
| 572 | 572 | or | |
| 573 | - exists(Parameter param | this = param.asName().getAFlowNode() and exists(param.getDefault())) | ||
| 573 | + exists(Parameter param | this.getNode() = param.asName() and exists(param.getDefault())) | ||
| 574 | 574 | } | |
| 575 | 575 | ||
| 576 | 576 | /** flow node corresponding to the value assigned for the definition corresponding to this flow node */ | |
| 577 | 577 | ControlFlowNode getValue() { | |
| 578 | - result = assigned_value(this.getNode()).getAFlowNode() and | ||
| 578 | + result.getNode() = assigned_value(this.getNode()) and | ||
| 579 | 579 | ( | |
| 580 | 580 | result.getBasicBlock().dominates(this.getBasicBlock()) | |
| 581 | 581 | or | |
@@ -584,7 +584,7 @@ class DefinitionNode extends ControlFlowNode { | |||
| 584 | 584 | // since the default value for a parameter is evaluated in the same basic block as | |
| 585 | 585 | // the function definition, but the parameter belongs to the basic block of the function, | |
| 586 | 586 | // there is no dominance relationship between the two. | |
| 587 | - exists(Parameter param | this = param.asName().getAFlowNode()) | ||
| 587 | + exists(Parameter param | this.getNode() = param.asName()) | ||
| 588 | 588 | ) | |
| 589 | 589 | } | |
| 590 | 590 | } | |
@@ -901,7 +901,7 @@ class ExceptFlowNode extends ControlFlowNode { | |||
| 901 | 901 | exists(ExceptStmt ex | | |
| 902 | 902 | this.getBasicBlock().dominates(result.getBasicBlock()) and | |
| 903 | 903 | ex = this.getNode() and | |
| 904 | - result = ex.getType().getAFlowNode() | ||
| 904 | + result.getNode() = ex.getType() | ||
| 905 | 905 | ) | |
| 906 | 906 | } | |
| 907 | 907 | ||
@@ -913,7 +913,7 @@ class ExceptFlowNode extends ControlFlowNode { | |||
| 913 | 913 | exists(ExceptStmt ex | | |
| 914 | 914 | this.getBasicBlock().dominates(result.getBasicBlock()) and | |
| 915 | 915 | ex = this.getNode() and | |
| 916 | - result = ex.getName().getAFlowNode() | ||
| 916 | + result.getNode() = ex.getName() | ||
| 917 | 917 | ) | |
| 918 | 918 | } | |
| 919 | 919 | } | |
@@ -928,7 +928,7 @@ class ExceptGroupFlowNode extends ControlFlowNode { | |||
| 928 | 928 | */ | |
| 929 | 929 | ControlFlowNode getType() { | |
| 930 | 930 | this.getBasicBlock().dominates(result.getBasicBlock()) and | |
| 931 | - result = this.getNode().(ExceptGroupStmt).getType().getAFlowNode() | ||
| 931 | + result.getNode() = this.getNode().(ExceptGroupStmt).getType() | ||
| 932 | 932 | } | |
| 933 | 933 | ||
| 934 | 934 | /** | |
@@ -937,7 +937,7 @@ class ExceptGroupFlowNode extends ControlFlowNode { | |||
| 937 | 937 | */ | |
| 938 | 938 | ControlFlowNode getName() { | |
| 939 | 939 | this.getBasicBlock().dominates(result.getBasicBlock()) and | |
| 940 | - result = this.getNode().(ExceptGroupStmt).getName().getAFlowNode() | ||
| 940 | + result.getNode() = this.getNode().(ExceptGroupStmt).getName() | ||
| 941 | 941 | } | |
| 942 | 942 | } | |
| 943 | 943 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,7 +163,7 @@ class ImportMember extends ImportMember_ { | |||
| 163 | 163 | result = this.getModule().(ImportExpr).getImportedModuleName() + "." + this.getName() | |
| 164 | 164 | } | |
| 165 | 165 | ||
| 166 | - override ImportMemberNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 166 | + deprecated override ImportMemberNode getAFlowNode() { result = super.getAFlowNode() } | ||
| 167 | 167 | } | |
| 168 | 168 | ||
| 169 | 169 | /** An import statement */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,20 +46,23 @@ class SelfAttributeRead extends SelfAttribute { | |||
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | 48 | predicate guardedByHasattr() { | |
| 49 | - exists(Variable var, ControlFlowNode n | | ||
| 50 | - var.getAUse() = this.getObject().getAFlowNode() and | ||
| 49 | + exists(Variable var, ControlFlowNode n, ControlFlowNode this_, ControlFlowNode obj_ | | ||
| 50 | + this_.getNode() = this and obj_.getNode() = this.getObject() | ||
| 51 | + | | ||
| 52 | + var.getAUse() = obj_ and | ||
| 51 | 53 | hasattr(n, var.getAUse(), this.getName()) and | |
| 52 | - n.strictlyDominates(this.getAFlowNode()) | ||
| 54 | + n.strictlyDominates(this_) | ||
| 53 | 55 | ) | |
| 54 | 56 | } | |
| 55 | 57 | ||
| 56 | 58 | pragma[noinline] | |
| 57 | 59 | predicate locallyDefined() { | |
| 58 | - exists(SelfAttributeStore store | | ||
| 59 | - this.getName() = store.getName() and | ||
| 60 | - this.getScope() = store.getScope() | ||
| 60 | + exists(SelfAttributeStore store, ControlFlowNode store_, ControlFlowNode this_ | | ||
| 61 | + store_.getNode() = store and this_.getNode() = this | ||
| 61 | 62 | | | |
| 62 | - store.getAFlowNode().strictlyDominates(this.getAFlowNode()) | ||
| 63 | + this.getName() = store.getName() and | ||
| 64 | + this.getScope() = store.getScope() and | ||
| 65 | + store_.strictlyDominates(this_) | ||
| 63 | 66 | ) | |
| 64 | 67 | } | |
| 65 | 68 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,24 +5,30 @@ private import semmle.python.dataflow.new.DataFlow | |||
| 5 | 5 | ||
| 6 | 6 | private predicate constCompare(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) { | |
| 7 | 7 | exists(CompareNode cn | cn = g | | |
| 8 | - exists(ImmutableLiteral const, Cmpop op | | ||
| 9 | - op = any(Eq eq) and branch = true | ||
| 10 | - or | ||
| 11 | - op = any(NotEq ne) and branch = false | ||
| 8 | + exists(ImmutableLiteral const, Cmpop op, ControlFlowNode c | | ||
| 9 | + c.getNode() = const and | ||
| 10 | + ( | ||
| 11 | + op = any(Eq eq) and branch = true | ||
| 12 | + or | ||
| 13 | + op = any(NotEq ne) and branch = false | ||
| 14 | + ) | ||
| 12 | 15 | | | |
| 13 | - cn.operands(const.getAFlowNode(), op, node) | ||
| 16 | + cn.operands(c, op, node) | ||
| 14 | 17 | or | |
| 15 | - cn.operands(node, op, const.getAFlowNode()) | ||
| 18 | + cn.operands(node, op, c) | ||
| 16 | 19 | ) | |
| 17 | 20 | or | |
| 18 | - exists(NameConstant const, Cmpop op | | ||
| 19 | - op = any(Is is_) and branch = true | ||
| 20 | - or | ||
| 21 | - op = any(IsNot isn) and branch = false | ||
| 21 | + exists(NameConstant const, Cmpop op, ControlFlowNode c | | ||
| 22 | + c.getNode() = const and | ||
| 23 | + ( | ||
| 24 | + op = any(Is is_) and branch = true | ||
| 25 | + or | ||
| 26 | + op = any(IsNot isn) and branch = false | ||
| 27 | + ) | ||
| 22 | 28 | | | |
| 23 | - cn.operands(const.getAFlowNode(), op, node) | ||
| 29 | + cn.operands(c, op, node) | ||
| 24 | 30 | or | |
| 25 | - cn.operands(node, op, const.getAFlowNode()) | ||
| 31 | + cn.operands(node, op, c) | ||
| 26 | 32 | ) | |
| 27 | 33 | or | |
| 28 | 34 | exists(IterableNode const_iterable, Cmpop op | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,7 +228,7 @@ private class ClassDefinitionAsAttrWrite extends AttrWrite, CfgNode { | |||
| 228 | 228 | ||
| 229 | 229 | override Node getValue() { result.asCfgNode() = node.getValue() } | |
| 230 | 230 | ||
| 231 | - override Node getObject() { result.asCfgNode() = cls.getAFlowNode() } | ||
| 231 | + override Node getObject() { result.asCfgNode().getNode() = cls } | ||
| 232 | 232 | ||
| 233 | 233 | override ExprNode getAttributeNameExpr() { none() } | |
| 234 | 234 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments