Skip to content

Commit e44064c

Browse files
committed
Add forward parameter/arguments to AST
1 parent 2a7f3fb commit e44064c

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,19 @@ class BlockArgument extends Expr, TBlockArgument {
197197
pred = "getValue" and result = this.getValue()
198198
}
199199
}
200+
201+
/**
202+
* A `...` expression that contains forwarded arguments.
203+
* ```rb
204+
* foo(...)
205+
* ```
206+
*/
207+
class ForwardedArguments extends Expr, TForwardArgument {
208+
private Ruby::ForwardArgument g;
209+
210+
ForwardedArguments() { this = TForwardArgument(g) }
211+
212+
final override string getAPrimaryQlClass() { result = "ForwardedArguments" }
213+
214+
final override string toString() { result = "..." }
215+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,16 @@ class SplatParameter extends NamedParameter, TSplatParameter {
233233

234234
final override string getName() { result = g.getName().getValue() }
235235
}
236+
237+
/**
238+
* A special `...` parameter that forwards positional/keyword/block arguments:
239+
* ```rb
240+
* def foo(...)
241+
* end
242+
* ```
243+
*/
244+
class ForwardParameter extends Parameter, TForwardParameter {
245+
final override string getAPrimaryQlClass() { result = "ForwardParameter" }
246+
247+
final override string toString() { result = "..." }
248+
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ private module Cached {
132132
TFloatLiteral(Ruby::Float g) { not any(Ruby::Rational r).getChild() = g } or
133133
TForExpr(Ruby::For g) or
134134
TForIn(Ruby::In g) or // TODO REMOVE
135+
TForwardParameter(Ruby::ForwardParameter g) or
136+
TForwardArgument(Ruby::ForwardArgument g) or
135137
TGEExpr(Ruby::Binary g) { g instanceof @ruby_binary_rangleequal } or
136138
TGTExpr(Ruby::Binary g) { g instanceof @ruby_binary_rangle } or
137139
TGlobalVariableAccessReal(Ruby::GlobalVariable g, AST::GlobalVariable v) {
@@ -340,6 +342,8 @@ private module Cached {
340342
n = TFloatLiteral(result) or
341343
n = TForExpr(result) or
342344
n = TForIn(result) or // TODO REMOVE
345+
n = TForwardArgument(result) or
346+
n = TForwardParameter(result) or
343347
n = TGEExpr(result) or
344348
n = TGTExpr(result) or
345349
n = TGlobalVariableAccessReal(result, _) or
@@ -550,7 +554,8 @@ class TSelf = TSelfReal or TSelfSynth;
550554
class TExpr =
551555
TSelf or TArgumentList or TRescueClause or TRescueModifierExpr or TPair or TStringConcatenation or
552556
TCall or TBlockArgument or TConstantAccess or TControlExpr or TWhenExpr or TLiteral or
553-
TCallable or TVariableAccess or TStmtSequence or TOperation or TSimpleParameter;
557+
TCallable or TVariableAccess or TStmtSequence or TOperation or TSimpleParameter or
558+
TForwardArgument;
554559

555560
class TSplatExpr = TSplatExprReal or TSplatExprSynth;
556561

@@ -677,7 +682,7 @@ class TReturningStmt = TReturnStmt or TBreakStmt or TNextStmt;
677682

678683
class TParameter =
679684
TPatternParameter or TBlockParameter or THashSplatParameter or TKeywordParameter or
680-
TOptionalParameter or TSplatParameter;
685+
TOptionalParameter or TSplatParameter or TForwardParameter;
681686

682687
class TPatternParameter = TSimpleParameter or TTuplePatternParameter;
683688

0 commit comments

Comments
 (0)