Skip to content

Commit 3b12ddf

Browse files
committed
Address comments
1 parent 052bc95 commit 3b12ddf

File tree

3 files changed

+64
-65
lines changed

3 files changed

+64
-65
lines changed

ruby/ql/lib/codeql/ruby/ast/Constant.qll

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -235,55 +235,6 @@ class ConstantAccess extends Expr, TConstantAccess {
235235
}
236236
}
237237

238-
private class TokenConstantAccess extends ConstantAccess, TTokenConstantAccess {
239-
private Ruby::Constant g;
240-
241-
TokenConstantAccess() { this = TTokenConstantAccess(g) }
242-
243-
final override string getName() { result = g.getValue() }
244-
}
245-
246-
private class ScopeResolutionConstantAccess extends ConstantAccess, TScopeResolutionConstantAccess {
247-
private Ruby::ScopeResolution g;
248-
private Ruby::Constant constant;
249-
250-
ScopeResolutionConstantAccess() { this = TScopeResolutionConstantAccess(g, constant) }
251-
252-
final override string getName() { result = constant.getValue() }
253-
254-
final override Expr getScopeExpr() { toGenerated(result) = g.getScope() }
255-
256-
final override predicate hasGlobalScope() { not exists(g.getScope()) }
257-
}
258-
259-
private class ConstantReadAccessSynth extends ConstantAccess, TConstantReadAccessSynth {
260-
private string value;
261-
262-
ConstantReadAccessSynth() { this = TConstantReadAccessSynth(_, _, value) }
263-
264-
final override string getName() {
265-
if this.hasGlobalScope() then result = value.suffix(2) else result = value
266-
}
267-
268-
final override Expr getScopeExpr() { synthChild(this, 0, result) }
269-
270-
final override predicate hasGlobalScope() { value.matches("::%") }
271-
}
272-
273-
private class ConstantWriteAccessSynth extends ConstantAccess, TConstantWriteAccessSynth {
274-
private string value;
275-
276-
ConstantWriteAccessSynth() { this = TConstantWriteAccessSynth(_, _, value) }
277-
278-
final override string getName() {
279-
if this.hasGlobalScope() then result = value.suffix(2) else result = value
280-
}
281-
282-
final override Expr getScopeExpr() { synthChild(this, 0, result) }
283-
284-
final override predicate hasGlobalScope() { value.matches("::%") }
285-
}
286-
287238
/**
288239
* A use (read) of a constant.
289240
*

ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
private import codeql.ruby.AST
2+
private import codeql.ruby.ast.internal.AST
23
private import codeql.ruby.ast.internal.Literal
34
private import codeql.ruby.ast.internal.Module
5+
private import codeql.ruby.ast.internal.TreeSitter
46
private import codeql.ruby.controlflow.CfgNodes
57
private import codeql.ruby.dataflow.SSA
68
private import ExprNodes
@@ -559,3 +561,60 @@ private predicate isArrayExpr(Expr e, ArrayLiteralCfgNode arr) {
559561
// results if the source is a phi node.
560562
forex(ExprCfgNode n | n = e.getAControlFlowNode() | isArrayConstant(n, arr))
561563
}
564+
565+
private class TokenConstantAccess extends ConstantAccess, TTokenConstantAccess {
566+
private Ruby::Constant g;
567+
568+
TokenConstantAccess() { this = TTokenConstantAccess(g) }
569+
570+
final override string getName() { result = g.getValue() }
571+
}
572+
573+
/**
574+
* A constant access that has a scope resolution qualifier.
575+
*/
576+
class ScopeResolutionConstantAccess extends ConstantAccess, TScopeResolutionConstantAccess {
577+
private Ruby::ScopeResolution g;
578+
private Ruby::Constant constant;
579+
580+
ScopeResolutionConstantAccess() { this = TScopeResolutionConstantAccess(g, constant) }
581+
582+
/**
583+
* Gets the name of the constant.
584+
*/
585+
final override string getName() { result = constant.getValue() }
586+
587+
/** Gets the scope resolution expression. */
588+
final override Expr getScopeExpr() { toGenerated(result) = g.getScope() }
589+
590+
/** Holds if this constant access has a global scope. */
591+
final override predicate hasGlobalScope() { not exists(g.getScope()) }
592+
}
593+
594+
private class ConstantReadAccessSynth extends ConstantAccess, TConstantReadAccessSynth {
595+
private string value;
596+
597+
ConstantReadAccessSynth() { this = TConstantReadAccessSynth(_, _, value) }
598+
599+
final override string getName() {
600+
if this.hasGlobalScope() then result = value.suffix(2) else result = value
601+
}
602+
603+
final override Expr getScopeExpr() { synthChild(this, 0, result) }
604+
605+
final override predicate hasGlobalScope() { value.matches("::%") }
606+
}
607+
608+
private class ConstantWriteAccessSynth extends ConstantAccess, TConstantWriteAccessSynth {
609+
private string value;
610+
611+
ConstantWriteAccessSynth() { this = TConstantWriteAccessSynth(_, _, value) }
612+
613+
final override string getName() {
614+
if this.hasGlobalScope() then result = value.suffix(2) else result = value
615+
}
616+
617+
final override Expr getScopeExpr() { synthChild(this, 0, result) }
618+
619+
final override predicate hasGlobalScope() { value.matches("::%") }
620+
}

ruby/ql/lib/codeql/ruby/ast/internal/Synthesis.qll

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
private import AST
44
private import TreeSitter
55
private import codeql.ruby.ast.internal.Call
6+
private import codeql.ruby.ast.internal.Constant
67
private import codeql.ruby.ast.internal.Expr
78
private import codeql.ruby.ast.internal.Variable
89
private import codeql.ruby.ast.internal.Pattern
@@ -964,24 +965,12 @@ private module DestructuredAssignDesugar {
964965
}
965966
}
966967

967-
private class LhsScopedConstant extends LhsWithReceiver, TScopeResolutionConstantAccess {
968-
private Ruby::AstNode receiver;
969-
private string name;
968+
private class LhsScopedConstant extends LhsWithReceiver, ScopeResolutionConstantAccess {
969+
LhsScopedConstant() { exists(this.getScopeExpr()) }
970970

971-
LhsScopedConstant() {
972-
exists(Ruby::ScopeResolution e, Ruby::Constant c |
973-
this = TScopeResolutionConstantAccess(e, c)
974-
|
975-
receiver = e.getScope() and
976-
name = c.getValue()
977-
)
978-
}
979-
980-
final string getName() { result = name }
981-
982-
final override Expr getReceiver() { toGenerated(result) = receiver }
971+
final override Expr getReceiver() { result = this.getScopeExpr() }
983972

984-
final override SynthKind getSynthKind() { result = ConstantWriteAccessKind(name) }
973+
final override SynthKind getSynthKind() { result = ConstantWriteAccessKind(this.getName()) }
985974
}
986975

987976
pragma[nomagic]

0 commit comments

Comments
 (0)