Skip to content

Commit

Permalink
Rename getNode to getAstNode
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Jun 22, 2023
1 parent 4e26261 commit 6c3cf4e
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ruby/ql/lib/codeql/ruby/ast/Statement.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl as CfgImpl
*/
class Stmt extends AstNode, TStmt {
/** Gets a control-flow node for this statement, if any. */
CfgNodes::AstCfgNode getAControlFlowNode() { result.getNode() = this }
CfgNodes::AstCfgNode getAControlFlowNode() { result.getAstNode() = this }

/** Gets a control-flow entry node for this statement, if any */
AstNode getAControlFlowEntryNode() { result = CfgImpl::getAControlFlowEntryNode(this) }
Expand Down
2 changes: 1 addition & 1 deletion ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private module Propagation {
any(StringComponentCfgNode c |
isString(c, result)
or
result = c.getNode().(StringComponentImpl).getValue()
result = c.getAstNode().(StringComponentImpl).getValue()
)
}

Expand Down
2 changes: 1 addition & 1 deletion ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private module JoinBlockPredecessors {
private predicate idOf(Ruby::AstNode x, int y) = equivalenceRelation(id/2)(x, y)

int getId(JoinBlockPredecessor jbp) {
idOf(toGeneratedInclSynth(jbp.getFirstNode().(AstCfgNode).getNode()), result)
idOf(toGeneratedInclSynth(jbp.getFirstNode().(AstCfgNode).getAstNode()), result)
or
idOf(toGeneratedInclSynth(jbp.(EntryBasicBlock).getScope()), result)
}
Expand Down
54 changes: 31 additions & 23 deletions ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExprCfgNode extends AstCfgNode {

Expr e;

ExprCfgNode() { e = this.getNode() }
ExprCfgNode() { e = this.getAstNode() }

/** Gets the underlying expression. */
Expr getExpr() { result = e }
Expand All @@ -61,30 +61,32 @@ class ReturningCfgNode extends AstCfgNode {

ReturningStmt s;

ReturningCfgNode() { s = this.getNode() }
ReturningCfgNode() { s = this.getAstNode() }

/** Gets the node of the returned value, if any. */
ExprCfgNode getReturnedValueNode() {
result = this.getAPredecessor() and
result.getNode() = s.getValue()
result.getAstNode() = s.getValue()
}
}

/** A control-flow node that wraps a `StringComponent` AST expression. */
class StringComponentCfgNode extends AstCfgNode {
override string getAPrimaryQlClass() { result = "StringComponentCfgNode" }

StringComponentCfgNode() { this.getNode() instanceof StringComponent }
StringComponentCfgNode() { this.getAstNode() instanceof StringComponent }

/** Gets the constant value of this string component. */
ConstantValue getConstantValue() { result = this.getNode().(StringComponent).getConstantValue() }
ConstantValue getConstantValue() {
result = this.getAstNode().(StringComponent).getConstantValue()
}
}

/** A control-flow node that wraps a `RegExpComponent` AST expression. */
class RegExpComponentCfgNode extends StringComponentCfgNode {
override string getAPrimaryQlClass() { result = "RegExpComponentCfgNode" }

RegExpComponentCfgNode() { this.getNode() instanceof RegExpComponent }
RegExpComponentCfgNode() { this.getAstNode() instanceof RegExpComponent }
}

private AstNode desugar(AstNode n) {
Expand Down Expand Up @@ -117,7 +119,7 @@ abstract private class ChildMapping extends AstNode {
cached
predicate hasCfgChild(AstNode child, CfgNode cfn, CfgNode cfnChild) {
this.reachesBasicBlock(child, cfn, cfnChild.getBasicBlock()) and
cfnChild.getNode() = desugar(child)
cfnChild.getAstNode() = desugar(child)
}
}

Expand All @@ -134,7 +136,7 @@ abstract private class ExprChildMapping extends Expr, ChildMapping {
exists(BasicBlock mid |
this.reachesBasicBlock(child, cfn, mid) and
bb = mid.getAPredecessor() and
not mid.getANode().getNode() = child
not mid.getANode().getAstNode() = child
)
}
}
Expand All @@ -148,13 +150,13 @@ abstract private class NonExprChildMapping extends ChildMapping {
pragma[nomagic]
override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) {
this.relevantChild(child) and
cfn.getNode() = this and
cfn.getAstNode() = this and
bb.getANode() = cfn
or
exists(BasicBlock mid |
this.reachesBasicBlock(child, cfn, mid) and
bb = mid.getASuccessor() and
not mid.getANode().getNode() = child
not mid.getANode().getAstNode() = child
)
}
}
Expand Down Expand Up @@ -380,7 +382,7 @@ module ExprNodes {
class InClauseCfgNode extends AstCfgNode {
private InClauseChildMapping e;

InClauseCfgNode() { e = this.getNode() }
InClauseCfgNode() { e = this.getAstNode() }

override string getAPrimaryQlClass() { result = "InClauseCfgNode" }

Expand All @@ -400,28 +402,28 @@ module ExprNodes {
predicate patternReachesBasicBlock(int i, CfgNode cfnPattern, BasicBlock bb) {
exists(Expr pattern |
pattern = this.getPattern(i) and
cfnPattern.getNode() = pattern and
cfnPattern.getAstNode() = pattern and
bb.getANode() = cfnPattern
)
or
exists(BasicBlock mid |
this.patternReachesBasicBlock(i, cfnPattern, mid) and
bb = mid.getASuccessor() and
not mid.getANode().getNode() = this
not mid.getANode().getAstNode() = this
)
}

predicate bodyReachesBasicBlock(CfgNode cfnBody, BasicBlock bb) {
exists(Stmt body |
body = this.getBody() and
cfnBody.getNode() = body and
cfnBody.getAstNode() = body and
bb.getANode() = cfnBody
)
or
exists(BasicBlock mid |
this.bodyReachesBasicBlock(cfnBody, mid) and
bb = mid.getAPredecessor() and
not mid.getANode().getNode() = this
not mid.getANode().getAstNode() = this
)
}
}
Expand All @@ -430,19 +432,19 @@ module ExprNodes {
class WhenClauseCfgNode extends AstCfgNode {
private WhenClauseChildMapping e;

WhenClauseCfgNode() { e = this.getNode() }
WhenClauseCfgNode() { e = this.getAstNode() }

override string getAPrimaryQlClass() { result = "WhenClauseCfgNode" }

/** Gets the body of this `when`-clause. */
final ExprCfgNode getBody() {
result.getNode() = desugar(e.getBody()) and
result.getAstNode() = desugar(e.getBody()) and
e.bodyReachesBasicBlock(result, this.getBasicBlock())
}

/** Gets the `i`th pattern this `when`-clause. */
final ExprCfgNode getPattern(int i) {
result.getNode() = desugar(e.getPattern(i)) and
result.getAstNode() = desugar(e.getPattern(i)) and
e.patternReachesBasicBlock(i, result, this.getBasicBlock())
}
}
Expand All @@ -451,7 +453,7 @@ module ExprNodes {
class CasePatternCfgNode extends AstCfgNode {
CasePattern e;

CasePatternCfgNode() { e = this.getNode() }
CasePatternCfgNode() { e = this.getAstNode() }

override string getAPrimaryQlClass() { result = "CasePatternCfgNode" }
}
Expand Down Expand Up @@ -815,7 +817,7 @@ module ExprNodes {

/** A control-flow node that wraps an `InstanceVariableReadAccess` AST expression. */
class InstanceVariableReadAccessCfgNode extends InstanceVariableAccessCfgNode {
InstanceVariableReadAccessCfgNode() { this.getNode() instanceof InstanceVariableReadAccess }
InstanceVariableReadAccessCfgNode() { this.getAstNode() instanceof InstanceVariableReadAccess }

override string getAPrimaryQlClass() { result = "InstanceVariableReadAccessCfgNode" }

Expand All @@ -824,7 +826,9 @@ module ExprNodes {

/** A control-flow node that wraps an `InstanceVariableWriteAccess` AST expression. */
class InstanceVariableWriteAccessCfgNode extends InstanceVariableAccessCfgNode {
InstanceVariableWriteAccessCfgNode() { this.getNode() instanceof InstanceVariableWriteAccess }
InstanceVariableWriteAccessCfgNode() {
this.getAstNode() instanceof InstanceVariableWriteAccess
}

override string getAPrimaryQlClass() { result = "InstanceVariableWriteAccessCfgNode" }

Expand All @@ -835,7 +839,9 @@ module ExprNodes {
class StringInterpolationComponentCfgNode extends StringComponentCfgNode, StmtSequenceCfgNode {
override string getAPrimaryQlClass() { result = "StringInterpolationComponentCfgNode" }

StringInterpolationComponentCfgNode() { this.getNode() instanceof StringInterpolationComponent }
StringInterpolationComponentCfgNode() {
this.getAstNode() instanceof StringInterpolationComponent
}

final override ConstantValue getConstantValue() {
result = StmtSequenceCfgNode.super.getConstantValue()
Expand All @@ -846,7 +852,9 @@ module ExprNodes {
class RegExpInterpolationComponentCfgNode extends RegExpComponentCfgNode, StmtSequenceCfgNode {
override string getAPrimaryQlClass() { result = "RegExpInterpolationComponentCfgNode" }

RegExpInterpolationComponentCfgNode() { this.getNode() instanceof RegExpInterpolationComponent }
RegExpInterpolationComponentCfgNode() {
this.getAstNode() instanceof RegExpInterpolationComponent
}

final override ConstantValue getConstantValue() {
result = StmtSequenceCfgNode.super.getConstantValue()
Expand Down
3 changes: 3 additions & 0 deletions ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class CfgNode extends CfgImpl::Node {
/** Gets the file of this control flow node. */
final File getFile() { result = this.getLocation().getFile() }

/** DEPRECATED: Use `getAstNode` instead. */
deprecated AstNode getNode() { result = this.getAstNode() }

/** Gets a successor node of a given type, if any. */
final CfgNode getASuccessor(SuccessorType t) { result = super.getASuccessor(t) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private predicate selfInToplevel(SelfVariable self, Module m) {
private predicate asModulePattern(SsaDefinitionExtNode def, Module m) {
exists(AsPattern ap |
m = resolveConstantReadAccess(ap.getPattern()) and
def.getDefinitionExt().(Ssa::WriteDefinition).getWriteAccess().getNode() =
def.getDefinitionExt().(Ssa::WriteDefinition).getWriteAccess().getAstNode() =
ap.getVariableAccess()
)
}
Expand Down
10 changes: 5 additions & 5 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module LocalFlow {
/** Gets the SSA definition node corresponding to parameter `p`. */
SsaDefinitionExtNode getParameterDefNode(NamedParameter p) {
exists(BasicBlock bb, int i |
bb.getNode(i).getNode() = p.getDefiningAccess() and
bb.getNode(i).getAstNode() = p.getDefiningAccess() and
result.getDefinitionExt().definesAt(_, bb, i, _)
)
}
Expand Down Expand Up @@ -203,8 +203,8 @@ module LocalFlow {
exists(CfgNodes::ExprCfgNode exprTo, ReturningStatementNode n |
nodeFrom = n and
exprTo = nodeTo.asExpr() and
n.getReturningNode().getNode() instanceof BreakStmt and
exprTo.getNode() instanceof Loop and
n.getReturningNode().getAstNode() instanceof BreakStmt and
exprTo.getAstNode() instanceof Loop and
nodeTo.asExpr().getAPredecessor(any(SuccessorTypes::BreakSuccessor s)) = n.getReturningNode()
)
or
Expand Down Expand Up @@ -926,7 +926,7 @@ abstract class SourceReturnNode extends ReturnNode {
private module ReturnNodes {
private predicate isValid(CfgNodes::ReturningCfgNode node) {
exists(ReturningStmt stmt, Callable scope |
stmt = node.getNode() and
stmt = node.getAstNode() and
scope = node.getScope()
|
stmt instanceof ReturnStmt and
Expand All @@ -952,7 +952,7 @@ private module ReturnNodes {
}

override ReturnKind getKindSource() {
if n.getNode() instanceof BreakStmt
if n.getAstNode() instanceof BreakStmt
then result instanceof BreakReturnKind
else
exists(CfgScope scope | scope = this.getCfgScope() |
Expand Down
8 changes: 4 additions & 4 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private module SsaInput implements SsaImplCommon::InputSig {
i = 0
or
// ...or a class or module block.
bb.getNode(i).getNode() = scope.(ModuleBase).getAControlFlowEntryNode() and
bb.getNode(i).getAstNode() = scope.(ModuleBase).getAControlFlowEntryNode() and
not scope instanceof Toplevel // handled by case above
)
or
Expand Down Expand Up @@ -126,8 +126,8 @@ private predicate namespaceSelfExitRead(Cfg::AnnotatedExitBasicBlock bb, int i,
v.getDeclaringScope() = ns and
last = ControlFlowGraphImpl::getAControlFlowExitNode(ns) and
if last = ns
then bb.getNode(i).getAPredecessor().getNode() = last
else bb.getNode(i).getNode() = last
then bb.getNode(i).getAPredecessor().getAstNode() = last
else bb.getNode(i).getAstNode() = last
)
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private predicate capturedCallRead(CallCfgNode call, Cfg::BasicBlock bb, int i,
private predicate variableReadActual(Cfg::BasicBlock bb, int i, LocalVariable v) {
exists(VariableReadAccess read |
read.getVariable() = v and
read = bb.getNode(i).getNode()
read = bb.getNode(i).getAstNode()
)
}

Expand Down
2 changes: 1 addition & 1 deletion ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class PotentiallyUnsafeSqlExecutingMethodCall extends ActiveRecordModelClassMeth
class ActiveRecordSqlExecutionRange extends SqlExecution::Range {
ActiveRecordSqlExecutionRange() {
exists(PotentiallyUnsafeSqlExecutingMethodCall mc |
this.asExpr().getNode() = mc.getSqlFragmentSinkArgument()
this.asExpr().getAstNode() = mc.getSqlFragmentSinkArgument()
)
or
this = activeRecordConnectionInstance().getAMethodCall("execute").getArgument(0) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ predicate returnStep(Node nodeFrom, Node nodeTo) {
// deliberately do not include `getInitializeTarget`, since calls to `new` should not
// get the return value from `initialize`. Any fields being set in the initializer
// will reach all reads via `callStep` and `localFieldStep`.
nodeTo.asExpr().getNode() = call.getNode()
nodeTo.asExpr().getAstNode() = call.getAstNode()
)
}

Expand Down
4 changes: 2 additions & 2 deletions ruby/ql/src/experimental/performance/UseDetect.ql
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class EndCall extends MethodCall {
}

Expr getUniqueRead(Expr e) {
forex(CfgNode eNode | eNode.getNode() = e |
forex(CfgNode eNode | eNode.getAstNode() = e |
exists(Ssa::WriteDefinition def |
def.assigns(eNode) and
strictcount(def.getARead()) = 1 and
not def = any(Ssa::PhiNode phi).getAnInput() and
def.getARead().getNode() = result
def.getARead().getAstNode() = result
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion ruby/ql/src/queries/analysis/Definitions.ql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ newtype DefLoc =
/** A local variable. */
LocalVariableLoc(VariableReadAccess read, VariableWriteAccess write) {
exists(Ssa::WriteDefinition w |
write = w.getWriteAccess().getNode() and
write = w.getWriteAccess().getAstNode() and
read = w.getARead().getExpr() and
not read.isSynthesized()
)
Expand Down
10 changes: 5 additions & 5 deletions shared/controlflow/codeql/controlflow/Cfg.qll
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
abstract string toString();

/** Gets the AST node that this node corresponds to, if any. */
abstract AstNode getNode();
abstract AstNode getAstNode();

/** Gets the location of this control flow node. */
abstract Location getLocation();
Expand Down Expand Up @@ -1011,7 +1011,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {

EntryNodeImpl() { this = TEntryNode(scope) }

final override AstNode getNode() { none() }
final override AstNode getAstNode() { none() }

final override Location getLocation() { result = scope.getLocation() }

Expand All @@ -1030,7 +1030,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
/** Holds if this node represent a normal exit. */
final predicate isNormal() { normal = true }

final override AstNode getNode() { none() }
final override AstNode getAstNode() { none() }

final override Location getLocation() { result = scope.getLocation() }

Expand All @@ -1053,7 +1053,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {

ExitNodeImpl() { this = TExitNode(scope) }

final override AstNode getNode() { none() }
final override AstNode getAstNode() { none() }

final override Location getLocation() { result = scope.getLocation() }

Expand All @@ -1075,7 +1075,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {

AstCfgNodeImpl() { this = TAstNode(_, n, splits) }

final override AstNode getNode() { result = n }
final override AstNode getAstNode() { result = n }

override Location getLocation() { result = n.getLocation() }

Expand Down

0 comments on commit 6c3cf4e

Please sign in to comment.