Skip to content

Commit 22b3dc8

Browse files
committed
Ruby: Remove getDefinitionExt references.
1 parent 7499df4 commit 22b3dc8

File tree

4 files changed

+41
-58
lines changed

4 files changed

+41
-58
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ private module TrackInstanceInput implements CallGraphConstruction::InputSig {
641641
// type being checked against
642642
localFlowStep(nodeFrom, nodeTo, summary) and
643643
not hasAdjacentTypeCheckedRead(nodeTo) and
644-
not TypeInference::asModulePattern(nodeTo.(SsaDefinitionExtNode).getDefinitionExt(), _)
644+
not TypeInference::asModulePattern(nodeTo.(SsaDefinitionNodeImpl).getDefinition(), _)
645645
}
646646

647647
predicate stepCall(DataFlow::Node nodeFrom, DataFlow::Node nodeTo, StepSummary summary) {

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ module SsaFlow {
9393
result = TSelfToplevelParameterNode(p.asToplevelSelf())
9494
}
9595

96-
ParameterNodeImpl toParameterNodeImpl(SsaDefinitionExtNode node) {
96+
ParameterNodeImpl toParameterNodeImpl(SsaDefinitionNodeImpl node) {
9797
exists(SsaImpl::WriteDefinition def, SsaImpl::ParameterExt p |
98-
def = node.getDefinitionExt() and
98+
def = node.getDefinition() and
9999
result = toParameterNode(p) and
100100
p.isInitializedBy(def)
101101
)
@@ -392,10 +392,10 @@ module VariableCapture {
392392

393393
// From an assignment or implicit initialization of a captured variable to its flow-insensitive node
394394
private predicate flowInsensitiveWriteStep(
395-
SsaDefinitionExtNode node1, CapturedVariableNode node2, CapturedVariable v
395+
SsaDefinitionNodeImpl node1, CapturedVariableNode node2, CapturedVariable v
396396
) {
397397
exists(CapturedSsaDefinitionExt def |
398-
def = node1.getDefinitionExt() and
398+
def = node1.getDefinition() and
399399
def.getSourceVariable() = v and
400400
(
401401
def instanceof Ssa::WriteDefinition
@@ -408,11 +408,11 @@ module VariableCapture {
408408

409409
// From a captured variable node to its flow-sensitive capture nodes
410410
private predicate flowInsensitiveReadStep(
411-
CapturedVariableNode node1, SsaDefinitionExtNode node2, CapturedVariable v
411+
CapturedVariableNode node1, SsaDefinitionNodeImpl node2, CapturedVariable v
412412
) {
413413
exists(CapturedSsaDefinitionExt def |
414414
node1.getVariable() = v and
415-
def = node2.getDefinitionExt() and
415+
def = node2.getDefinition() and
416416
def.getSourceVariable() = v and
417417
(
418418
def instanceof Ssa::CapturedCallDefinition
@@ -571,8 +571,8 @@ private module Cached {
571571
}
572572

573573
/** Holds if `n` wraps an SSA definition without ingoing flow. */
574-
private predicate entrySsaDefinition(SsaDefinitionExtNode n) {
575-
n.getDefinitionExt() =
574+
private predicate entrySsaDefinition(SsaDefinitionNodeImpl n) {
575+
n.getDefinition() =
576576
any(SsaImpl::WriteDefinition def | not def.(Ssa::WriteDefinition).assigns(_))
577577
}
578578

@@ -614,7 +614,7 @@ private module Cached {
614614
// to parameters (which are themselves local sources)
615615
entrySsaDefinition(n) and
616616
not exists(SsaImpl::ParameterExt p |
617-
p.isInitializedBy(n.(SsaDefinitionExtNode).getDefinitionExt())
617+
p.isInitializedBy(n.(SsaDefinitionNodeImpl).getDefinition())
618618
)
619619
or
620620
isStoreTargetNode(n)
@@ -749,51 +749,38 @@ predicate nodeIsHidden(Node n) {
749749
}
750750

751751
/** An SSA node. */
752-
abstract class SsaNode extends NodeImpl, TSsaNode {
752+
class SsaNode extends NodeImpl, TSsaNode {
753753
SsaImpl::DataFlowIntegration::SsaNode node;
754-
SsaImpl::DefinitionExt def;
755754

756-
SsaNode() {
757-
this = TSsaNode(node) and
758-
def = node.getDefinitionExt()
759-
}
755+
SsaNode() { this = TSsaNode(node) }
760756

761-
SsaImpl::DefinitionExt getDefinitionExt() { result = def }
757+
/** Gets the underlying variable. */
758+
Variable getVariable() { result = node.getSourceVariable() }
762759

763760
/** Holds if this node should be hidden from path explanations. */
764-
abstract predicate isHidden();
761+
predicate isHidden() { any() }
762+
763+
override CfgScope getCfgScope() { result = node.getBasicBlock().getScope() }
765764

766765
override Location getLocationImpl() { result = node.getLocation() }
767766

768767
override string toStringImpl() { result = node.toString() }
769768
}
770769

771-
/** An (extended) SSA definition, viewed as a node in a data flow graph. */
772-
class SsaDefinitionExtNode extends SsaNode {
773-
override SsaImpl::DataFlowIntegration::SsaDefinitionExtNode node;
770+
class SsaDefinitionNodeImpl extends SsaNode {
771+
override SsaImpl::DataFlowIntegration::SsaDefinitionNode node;
774772

775-
/** Gets the underlying variable. */
776-
Variable getVariable() { result = def.getSourceVariable() }
773+
SsaImpl::Definition getDefinition() { result = node.getDefinition() }
777774

778775
override predicate isHidden() {
779-
not def instanceof Ssa::WriteDefinition
780-
or
781-
isDesugarNode(def.(Ssa::WriteDefinition).getWriteAccess().getExpr())
782-
or
783-
def = getParameterDef(_)
776+
exists(SsaImpl::Definition def | def = this.getDefinition() |
777+
not def instanceof Ssa::WriteDefinition
778+
or
779+
isDesugarNode(def.(Ssa::WriteDefinition).getWriteAccess().getExpr())
780+
or
781+
def = getParameterDef(_)
782+
)
784783
}
785-
786-
override CfgScope getCfgScope() { result = def.getBasicBlock().getScope() }
787-
}
788-
789-
class SsaDefinitionNodeImpl extends SsaDefinitionExtNode {
790-
Ssa::Definition ssaDef;
791-
792-
SsaDefinitionNodeImpl() { ssaDef = def }
793-
794-
override Location getLocationImpl() { result = ssaDef.getLocation() }
795-
796-
override string toStringImpl() { result = ssaDef.toString() }
797784
}
798785

799786
/**
@@ -833,17 +820,13 @@ class SsaDefinitionNodeImpl extends SsaDefinitionExtNode {
833820
*/
834821
class SsaInputNode extends SsaNode {
835822
override SsaImpl::DataFlowIntegration::SsaInputNode node;
836-
837-
override predicate isHidden() { any() }
838-
839-
override CfgScope getCfgScope() { result = node.getDefinitionExt().getBasicBlock().getScope() }
840823
}
841824

842825
/** An SSA definition for a `self` variable. */
843-
class SsaSelfDefinitionNode extends SsaDefinitionExtNode {
826+
class SsaSelfDefinitionNode extends SsaDefinitionNodeImpl {
844827
private SelfVariable self;
845828

846-
SsaSelfDefinitionNode() { self = def.getSourceVariable() }
829+
SsaSelfDefinitionNode() { self = super.getVariable() }
847830

848831
/** Gets the scope in which the `self` variable is declared. */
849832
Scope getSelfScope() { result = self.getDeclaringScope() }
@@ -1976,9 +1959,9 @@ predicate localMustFlowStep(Node node1, Node node2) {
19761959
or
19771960
exists(SsaImpl::Definition def |
19781961
def.(Ssa::WriteDefinition).assigns(node1.asExpr()) and
1979-
node2.(SsaDefinitionExtNode).getDefinitionExt() = def
1962+
node2.(SsaDefinitionNodeImpl).getDefinition() = def
19801963
or
1981-
def = node1.(SsaDefinitionExtNode).getDefinitionExt() and
1964+
def = node1.(SsaDefinitionNodeImpl).getDefinition() and
19821965
node2.asExpr() = SsaImpl::getARead(def)
19831966
)
19841967
or
@@ -2122,8 +2105,8 @@ class CastNode extends Node {
21222105
predicate neverSkipInPathGraph(Node n) {
21232106
// ensure that all variable assignments are included in the path graph
21242107
n =
2125-
any(SsaDefinitionExtNode def |
2126-
def.getDefinitionExt() instanceof Ssa::WriteDefinition and
2108+
any(SsaDefinitionNodeImpl def |
2109+
def.getDefinition() instanceof Ssa::WriteDefinition and
21272110
not def.isHidden()
21282111
)
21292112
}
@@ -2446,15 +2429,15 @@ module TypeInference {
24462429
}
24472430

24482431
pragma[nomagic]
2449-
private predicate ssaDefHasType(SsaDefinitionExtNode def, Module tp, boolean exact) {
2432+
private predicate ssaDefHasType(SsaDefinitionNodeImpl def, Module tp, boolean exact) {
24502433
exists(ParameterNodeImpl p |
24512434
parameterNodeHasType(p, tp, exact) and
24522435
p = SsaFlow::toParameterNodeImpl(def)
24532436
)
24542437
or
24552438
selfInMethodOrToplevelHasType(def.getVariable(), tp, exact)
24562439
or
2457-
asModulePattern(def.getDefinitionExt(), tp) and
2440+
asModulePattern(def.getDefinition(), tp) and
24582441
exact = false
24592442
}
24602443

@@ -2523,11 +2506,11 @@ module TypeInference {
25232506
or
25242507
parameterNodeHasType(n, tp, exact)
25252508
or
2526-
exists(SsaDefinitionExtNode def | ssaDefHasType(def, tp, exact) |
2509+
exists(SsaDefinitionNodeImpl def | ssaDefHasType(def, tp, exact) |
25272510
n = def or
25282511
n.asExpr() =
25292512
any(CfgNodes::ExprCfgNode read |
2530-
read = def.getDefinitionExt().getARead() and
2513+
read = def.getDefinition().(SsaImpl::DefinitionExt).getARead() and
25312514
not isTypeCheckedRead(read, _) // could in principle be checked against a new type
25322515
)
25332516
)

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class PostUpdateNode extends Node {
363363
/** An SSA definition, viewed as a node in a data flow graph. */
364364
class SsaDefinitionNode extends Node instanceof SsaDefinitionNodeImpl {
365365
/** Gets the underlying SSA definition. */
366-
Ssa::Definition getDefinition() { result = super.getDefinitionExt() }
366+
Ssa::Definition getDefinition() { result = super.getDefinition() }
367367

368368
/** Gets the underlying variable. */
369369
Variable getVariable() { result = this.getDefinition().getSourceVariable() }
@@ -434,7 +434,7 @@ private module Cached {
434434
LocalSourceNode getConstantAccessNode(ConstantAccess access) {
435435
// Namespaces don't evaluate to the constant being accessed, they return the value of their last statement.
436436
// Use the definition of 'self' in the namespace as the representative in this case.
437-
result.(SsaDefinitionExtNode).getDefinitionExt().(Ssa::SelfDefinition).getSourceVariable() =
437+
result.(SsaDefinitionNode).getDefinition().(Ssa::SelfDefinition).getSourceVariable() =
438438
access.(Namespace).getModuleSelfVariable()
439439
or
440440
not access instanceof Namespace and
@@ -1002,7 +1002,7 @@ class ModuleNode instanceof Module {
10021002
* This only gets `self` at the module level, not inside any (singleton) method.
10031003
*/
10041004
LocalSourceNode getModuleLevelSelf() {
1005-
result.(SsaDefinitionExtNode).getVariable() = super.getADeclaration().getModuleSelfVariable()
1005+
result.(SsaDefinitionNode).getVariable() = super.getADeclaration().getModuleSelfVariable()
10061006
}
10071007

10081008
/**

ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private module Cached {
8888
nodeFrom.asExpr() = value and
8989
value = case.getValue() and
9090
clause = case.getBranch(_) and
91-
def = nodeTo.(SsaDefinitionExtNode).getDefinitionExt() and
91+
def = nodeTo.(SsaDefinitionNodeImpl).getDefinition() and
9292
def.getControlFlowNode() = variablesInPattern(clause.getPattern()) and
9393
not def.(Ssa::WriteDefinition).assigns(value)
9494
)

0 commit comments

Comments
 (0)