mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Merge pull request #7154 from aibaars/ruby-pattern-matching
Ruby: pattern matching
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
private import codeql.ruby.AST
|
||||
private import internal.AST
|
||||
private import internal.Control
|
||||
private import internal.TreeSitter
|
||||
|
||||
/**
|
||||
@@ -308,13 +309,36 @@ class TernaryIfExpr extends ConditionalExpr, TTernaryIfExpr {
|
||||
}
|
||||
}
|
||||
|
||||
class CaseExpr extends ControlExpr, TCaseExpr {
|
||||
private Ruby::Case g;
|
||||
|
||||
CaseExpr() { this = TCaseExpr(g) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "CaseExpr" }
|
||||
|
||||
/**
|
||||
* A `case` statement. There are three forms of `case` statements:
|
||||
* ```rb
|
||||
* # a value-less case expression acting like an if-elsif expression:
|
||||
* case
|
||||
* when x == 0 then puts "zero"
|
||||
* when x > 0 then puts "positive"
|
||||
* else puts "negative"
|
||||
* end
|
||||
*
|
||||
* # a case expression that matches a value using `when` clauses:
|
||||
* case value
|
||||
* when 1, 2 then puts "a is one or two"
|
||||
* when 3 then puts "a is three"
|
||||
* else puts "I don't know what a is"
|
||||
* end
|
||||
*
|
||||
* # a case expression that matches a value against patterns using `in` clauses:
|
||||
* config = {db: {user: 'admin', password: 'abc123'}}
|
||||
* case config
|
||||
* in db: {user:} # matches subhash and puts matched value in variable user
|
||||
* puts "Connect with user '#{user}'"
|
||||
* in connection: {username: } unless username == 'admin'
|
||||
* puts "Connect with user '#{username}'"
|
||||
* else
|
||||
* puts "Unrecognized structure of config"
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class CaseExpr extends ControlExpr instanceof CaseExprImpl {
|
||||
/**
|
||||
* Gets the expression being compared, if any. For example, `foo` in the following example.
|
||||
* ```rb
|
||||
@@ -334,22 +358,25 @@ class CaseExpr extends ControlExpr, TCaseExpr {
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
final Expr getValue() { toGenerated(result) = g.getValue() }
|
||||
final Expr getValue() { result = super.getValue() }
|
||||
|
||||
/**
|
||||
* Gets the `n`th branch of this case expression, either a `WhenExpr` or a
|
||||
* `StmtSequence`.
|
||||
* Gets the `n`th branch of this case expression, either a `WhenExpr`, an
|
||||
* `InClause`, or a `StmtSequence`.
|
||||
*/
|
||||
final Expr getBranch(int n) { toGenerated(result) = g.getChild(n) }
|
||||
final Expr getBranch(int n) { result = super.getBranch(n) }
|
||||
|
||||
/**
|
||||
* Gets a branch of this case expression, either a `WhenExpr` or an
|
||||
* `ElseExpr`.
|
||||
* Gets a branch of this case expression, either a `WhenExpr`, an
|
||||
* `InClause`, or a `StmtSequence`.
|
||||
*/
|
||||
final Expr getABranch() { result = this.getBranch(_) }
|
||||
|
||||
/** Gets the `n`th `when` branch of this case expression. */
|
||||
deprecated final WhenExpr getWhenBranch(int n) { result = this.getBranch(n) }
|
||||
|
||||
/** Gets a `when` branch of this case expression. */
|
||||
final WhenExpr getAWhenBranch() { result = this.getABranch() }
|
||||
deprecated final WhenExpr getAWhenBranch() { result = this.getABranch() }
|
||||
|
||||
/** Gets the `else` branch of this case expression, if any. */
|
||||
final StmtSequence getElseBranch() { result = this.getABranch() }
|
||||
@@ -359,14 +386,18 @@ class CaseExpr extends ControlExpr, TCaseExpr {
|
||||
*/
|
||||
final int getNumberOfBranches() { result = count(this.getBranch(_)) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "CaseExpr" }
|
||||
|
||||
final override string toString() { result = "case ..." }
|
||||
|
||||
override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
result = ControlExpr.super.getAChild(pred)
|
||||
or
|
||||
pred = "getValue" and result = this.getValue()
|
||||
or
|
||||
pred = "getBranch" and result = this.getBranch(_)
|
||||
or
|
||||
pred = "getElseBranch" and result = this.getElseBranch()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,6 +453,81 @@ class WhenExpr extends Expr, TWhenExpr {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An `in` clause of a `case` expression.
|
||||
* ```rb
|
||||
* case foo
|
||||
* in [ a ] then a
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class InClause extends Expr, TInClause {
|
||||
private Ruby::InClause g;
|
||||
|
||||
InClause() { this = TInClause(g) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "InClause" }
|
||||
|
||||
/** Gets the body of this case-in expression. */
|
||||
final Stmt getBody() { toGenerated(result) = g.getBody() }
|
||||
|
||||
/**
|
||||
* Gets the pattern in this case-in expression. In the
|
||||
* following example, the pattern is `Point{ x:, y: }`.
|
||||
* ```rb
|
||||
* case foo
|
||||
* in Point{ x:, y: }
|
||||
* x + y
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
final CasePattern getPattern() { toGenerated(result) = g.getPattern() }
|
||||
|
||||
/**
|
||||
* Gets the pattern guard condition in this case-in expression. In the
|
||||
* following example, there are two pattern guard conditions `x > 10` and `x < 0`.
|
||||
* ```rb
|
||||
* case foo
|
||||
* in [ x ] if x > 10 then ...
|
||||
* in [ x ] unless x < 0 then ...
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
final Expr getCondition() { toGenerated(result) = g.getGuard().getAFieldOrChild() }
|
||||
|
||||
/**
|
||||
* Holds if the pattern guard in this case-in expression is an `if` condition. For example:
|
||||
* ```rb
|
||||
* case foo
|
||||
* in [ x ] if x > 10 then ...
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
predicate hasIfCondition() { g.getGuard() instanceof Ruby::IfGuard }
|
||||
|
||||
/**
|
||||
* Holds if the pattern guard in this case-in expression is an `unless` condition. For example:
|
||||
* ```rb
|
||||
* case foo
|
||||
* in [ x ] unless x < 10 then ...
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
predicate hasUnlessCondition() { g.getGuard() instanceof Ruby::UnlessGuard }
|
||||
|
||||
final override string toString() { result = "in ... then ..." }
|
||||
|
||||
override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getBody" and result = this.getBody()
|
||||
or
|
||||
pred = "getPattern" and result = this.getPattern()
|
||||
or
|
||||
pred = "getCondition" and result = this.getCondition()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A loop. That is, a `for` loop, a `while` or `until` loop, or their
|
||||
* expression-modifier variants.
|
||||
|
||||
@@ -223,6 +223,40 @@ private class FalseLiteral extends BooleanLiteral, TFalseLiteral {
|
||||
final override predicate isFalse() { any() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An `__ENCODING__` literal.
|
||||
*/
|
||||
class EncodingLiteral extends Literal, TEncoding {
|
||||
final override string getAPrimaryQlClass() { result = "EncodingLiteral" }
|
||||
|
||||
final override string toString() { result = "__ENCODING__" }
|
||||
|
||||
// TODO: return the encoding defined by a magic encoding: comment, if any.
|
||||
override string getValueText() { result = "UTF-8" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `__LINE__` literal.
|
||||
*/
|
||||
class LineLiteral extends Literal, TLine {
|
||||
final override string getAPrimaryQlClass() { result = "LineLiteral" }
|
||||
|
||||
final override string toString() { result = "__LINE__" }
|
||||
|
||||
override string getValueText() { result = this.getLocation().getStartLine().toString() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `__FILE__` literal.
|
||||
*/
|
||||
class FileLiteral extends Literal, TFile {
|
||||
final override string getAPrimaryQlClass() { result = "FileLiteral" }
|
||||
|
||||
final override string toString() { result = "__FILE__" }
|
||||
|
||||
override string getValueText() { result = this.getLocation().getFile().getAbsolutePath() }
|
||||
}
|
||||
|
||||
/**
|
||||
* The base class for a component of a string: `StringTextComponent`,
|
||||
* `StringEscapeSequenceComponent`, or `StringInterpolationComponent`.
|
||||
|
||||
@@ -131,6 +131,23 @@ class HashSplatParameter extends NamedParameter, THashSplatParameter {
|
||||
final override string getName() { result = g.getName().getValue() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `nil` hash splat (`**nil`) indicating that there are no keyword parameters or keyword patterns.
|
||||
* For example:
|
||||
* ```rb
|
||||
* def foo(bar, **nil)
|
||||
* case bar
|
||||
* in { x:, **nil } then puts x
|
||||
* end
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class HashSplatNilParameter extends Parameter, THashSplatNilParameter {
|
||||
final override string getAPrimaryQlClass() { result = "HashSplatNilParameter" }
|
||||
|
||||
final override string toString() { result = "**nil" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A keyword parameter, including a default value if the parameter is optional.
|
||||
* For example, in the following example, `foo` is a keyword parameter with a
|
||||
|
||||
@@ -97,3 +97,322 @@ class TuplePattern extends Pattern, TTuplePattern {
|
||||
|
||||
override AstNode getAChild(string pred) { pred = "getElement" and result = this.getElement(_) }
|
||||
}
|
||||
|
||||
private class TPatternNode =
|
||||
TArrayPattern or TFindPattern or THashPattern or TAlternativePattern or TAsPattern or
|
||||
TVariableReferencePattern;
|
||||
|
||||
private class TPattern =
|
||||
TPatternNode or TLiteral or TLambda or TConstantAccess or TLocalVariableAccess or
|
||||
TUnaryArithmeticOperation;
|
||||
|
||||
/**
|
||||
* A pattern used in a `case-in` expression. For example
|
||||
* ```rb
|
||||
* case expr
|
||||
* in [ x ] then ...
|
||||
* in Point(a:, b:) then ...
|
||||
* in Integer => x then ...
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class CasePattern extends AstNode, TPattern {
|
||||
CasePattern() { casePattern(toGenerated(this)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* An array pattern, for example:
|
||||
* ```rb
|
||||
* in []
|
||||
* in ["first", Integer => x, "last"]
|
||||
* in ["a", Integer => x, *]
|
||||
* in ["a", Integer => x, ]
|
||||
* in [1, 2, *x, 7, 8]
|
||||
* in [*init, 7, 8]
|
||||
* in List["a", Integer => x, *tail]
|
||||
* ```
|
||||
*/
|
||||
class ArrayPattern extends CasePattern, TArrayPattern {
|
||||
private Ruby::ArrayPattern g;
|
||||
|
||||
ArrayPattern() { this = TArrayPattern(g) }
|
||||
|
||||
/** Gets the class this pattern matches objects against, if any. */
|
||||
ConstantReadAccess getClass() { toGenerated(result) = g.getClass() }
|
||||
|
||||
/**
|
||||
* Gets the `n`th element of this list pattern's prefix, i.e. the elements `1, ^two, 3`
|
||||
* in the following examples:
|
||||
* ```
|
||||
* in [ 1, ^two, 3 ]
|
||||
* in [ 1, ^two, 3, ]
|
||||
* in [ 1, ^two, 3, *, 4 , 5]
|
||||
* in [ 1, ^two, 3, *more]
|
||||
* ```
|
||||
*/
|
||||
CasePattern getPrefixElement(int n) {
|
||||
toGenerated(result) = g.getChild(n) and
|
||||
(
|
||||
n < this.restIndex()
|
||||
or
|
||||
not exists(restIndex())
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `n`th element of this list pattern's suffix, i.e. the elements `4, 5`
|
||||
* in the following examples:
|
||||
* ```
|
||||
* in [ *, 4, 5 ]
|
||||
* in [ 1, 2, 3, *middle, 4 , 5]
|
||||
* ```
|
||||
*/
|
||||
CasePattern getSuffixElement(int n) { toGenerated(result) = g.getChild(n + this.restIndex() + 1) }
|
||||
|
||||
/**
|
||||
* Gets the variable of the rest token, if any. For example `middle` in `the following array pattern.
|
||||
* ```rb
|
||||
* [ 1, 2, 3, *middle, 4 , 5]
|
||||
* ```
|
||||
*/
|
||||
LocalVariableWriteAccess getRestVariableAccess() {
|
||||
toGenerated(result) = g.getChild(restIndex()).(Ruby::SplatParameter).getName()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this pattern permits any unmatched remaining elements, i.e. the pattern does not have a trailing `,`
|
||||
* and does not contain a rest token (`*` or `*name`) either.
|
||||
*/
|
||||
predicate allowsUnmatchedElements() { not exists(this.restIndex()) }
|
||||
|
||||
private int restIndex() { g.getChild(result) instanceof Ruby::SplatParameter }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "ArrayPattern" }
|
||||
|
||||
final override string toString() { result = "[ ..., * ]" }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getClass" and result = this.getClass()
|
||||
or
|
||||
pred = "getPrefixElement" and result = this.getPrefixElement(_)
|
||||
or
|
||||
pred = "getSuffixElement" and result = this.getSuffixElement(_)
|
||||
or
|
||||
pred = "getRestVariableAccess" and result = this.getRestVariableAccess()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A find pattern, for example:
|
||||
* ```rb
|
||||
* in [*, "a", Integer => x, *]
|
||||
* in List[*init, "a", Integer => x, *tail]
|
||||
* in List[*, "a", Integer => x, *]
|
||||
* ```
|
||||
*/
|
||||
class FindPattern extends CasePattern, TFindPattern {
|
||||
private Ruby::FindPattern g;
|
||||
|
||||
FindPattern() { this = TFindPattern(g) }
|
||||
|
||||
/** Gets the class this pattern matches objects against, if any. */
|
||||
ConstantReadAccess getClass() { toGenerated(result) = g.getClass() }
|
||||
|
||||
/** Gets the `n`th element of this list pattern. */
|
||||
CasePattern getElement(int n) { toGenerated(result) = g.getChild(n + 1) }
|
||||
|
||||
/** Gets an element of this list pattern. */
|
||||
CasePattern getAnElement() { result = this.getElement(_) }
|
||||
|
||||
/**
|
||||
* Gets the variable for the prefix of this list pattern, if any. For example `init` in:
|
||||
* ```rb
|
||||
* in List[*init, "a", Integer => x, *tail]
|
||||
* ```
|
||||
*/
|
||||
LocalVariableWriteAccess getPrefixVariableAccess() {
|
||||
toGenerated(result) = g.getChild(0).(Ruby::SplatParameter).getName()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variable for the suffix of this list pattern, if any. For example `tail` in:
|
||||
* ```rb
|
||||
* in List[*init, "a", Integer => x, *tail]
|
||||
* ```
|
||||
*/
|
||||
LocalVariableWriteAccess getSuffixVariableAccess() {
|
||||
toGenerated(result) = max(int i | | g.getChild(i) order by i).(Ruby::SplatParameter).getName()
|
||||
}
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "FindPattern" }
|
||||
|
||||
final override string toString() { result = "[ *,...,* ]" }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getClass" and result = this.getClass()
|
||||
or
|
||||
pred = "getElement" and result = this.getElement(_)
|
||||
or
|
||||
pred = "getPrefixVariableAccess" and result = this.getPrefixVariableAccess()
|
||||
or
|
||||
pred = "getSuffixVariableAccess" and result = this.getSuffixVariableAccess()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash pattern, for example:
|
||||
* ```rb
|
||||
* in {}
|
||||
* in { a: 1 }
|
||||
* in { a: 1, **rest }
|
||||
* in { a: 1, **nil }
|
||||
* in Node{ label: , children: [] }
|
||||
* ```
|
||||
*/
|
||||
class HashPattern extends CasePattern, THashPattern {
|
||||
private Ruby::HashPattern g;
|
||||
|
||||
HashPattern() { this = THashPattern(g) }
|
||||
|
||||
/** Gets the class this pattern matches objects against, if any. */
|
||||
ConstantReadAccess getClass() { toGenerated(result) = g.getClass() }
|
||||
|
||||
private Ruby::KeywordPattern keyValuePair(int n) { result = g.getChild(n) }
|
||||
|
||||
/** Gets the key of the `n`th pair. */
|
||||
StringlikeLiteral getKey(int n) { toGenerated(result) = keyValuePair(n).getKey() }
|
||||
|
||||
/** Gets the value of the `n`th pair. */
|
||||
CasePattern getValue(int n) { toGenerated(result) = keyValuePair(n).getValue() }
|
||||
|
||||
/** Gets the value for a given key name. */
|
||||
CasePattern getValueByKey(string key) {
|
||||
exists(int i | key = this.getKey(i).getValueText() and result = this.getValue(i))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variable of the keyword rest token, if any. For example `rest` in:
|
||||
* ```rb
|
||||
* in { a: 1, **rest }
|
||||
* ```
|
||||
*/
|
||||
LocalVariableWriteAccess getRestVariableAccess() {
|
||||
toGenerated(result) =
|
||||
max(int i | | g.getChild(i) order by i).(Ruby::HashSplatParameter).getName()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this pattern is terminated by `**nil` indicating that the pattern does not permit
|
||||
* any unmatched remaining pairs.
|
||||
*/
|
||||
predicate allowsUnmatchedElements() { g.getChild(_) instanceof Ruby::HashSplatNil }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "HashPattern" }
|
||||
|
||||
final override string toString() { result = "{ ..., ** }" }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getClass" and result = this.getClass()
|
||||
or
|
||||
pred = "getKey" and result = this.getKey(_)
|
||||
or
|
||||
pred = "getValue" and result = this.getValue(_)
|
||||
or
|
||||
pred = "getRestVariableAccess" and result = this.getRestVariableAccess()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A composite pattern matching one of the given sub-patterns, for example:
|
||||
* ```rb
|
||||
* in 1 | 2 | 3
|
||||
* ```
|
||||
*/
|
||||
class AlternativePattern extends CasePattern, TAlternativePattern {
|
||||
private Ruby::AlternativePattern g;
|
||||
|
||||
AlternativePattern() { this = TAlternativePattern(g) }
|
||||
|
||||
/** Gets the `n`th alternative of this pattern. */
|
||||
CasePattern getAlternative(int n) { toGenerated(result) = g.getAlternatives(n) }
|
||||
|
||||
/** Gets an alternative of this pattern. */
|
||||
CasePattern getAnAlternative() { result = this.getAlternative(_) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "AlternativePattern" }
|
||||
|
||||
final override string toString() { result = "... | ..." }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getAlternative" and result = this.getAlternative(_)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A pattern match that binds to the specified local variable, for example `Integer => a`
|
||||
* in the following:
|
||||
* ```rb
|
||||
* case 1
|
||||
* in Integer => a then puts "#{a} is an integer value"
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class AsPattern extends CasePattern, TAsPattern {
|
||||
private Ruby::AsPattern g;
|
||||
|
||||
AsPattern() { this = TAsPattern(g) }
|
||||
|
||||
/** Gets the underlying pattern. */
|
||||
CasePattern getPattern() { toGenerated(result) = g.getValue() }
|
||||
|
||||
/** Gets the variable access for this pattern. */
|
||||
LocalVariableWriteAccess getVariableAccess() { toGenerated(result) = g.getName() }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "AsPattern" }
|
||||
|
||||
final override string toString() { result = "... => ..." }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getPattern" and result = this.getPattern()
|
||||
or
|
||||
pred = "getVariableAccess" and result = this.getVariableAccess()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A variable reference in a pattern, i.e. `^x` in the following example:
|
||||
* ```rb
|
||||
* x = 10
|
||||
* case expr
|
||||
* in ^x then puts "ok"
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class VariableReferencePattern extends CasePattern, TVariableReferencePattern {
|
||||
private Ruby::VariableReferencePattern g;
|
||||
|
||||
VariableReferencePattern() { this = TVariableReferencePattern(g) }
|
||||
|
||||
/** Gets the variable access corresponding to this variable reference pattern. */
|
||||
LocalVariableReadAccess getVariableAccess() { toGenerated(result) = g.getName() }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "VariableReferencePattern" }
|
||||
|
||||
final override string toString() { result = "^..." }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getVariableAccess" and result = this.getVariableAccess()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import codeql.Locations
|
||||
private import TreeSitter
|
||||
private import codeql.ruby.ast.internal.Call
|
||||
private import codeql.ruby.ast.internal.Parameter
|
||||
private import codeql.ruby.ast.internal.Pattern
|
||||
private import codeql.ruby.ast.internal.Variable
|
||||
private import codeql.ruby.AST as AST
|
||||
private import Synthesis
|
||||
@@ -30,6 +31,7 @@ private module Cached {
|
||||
TAddExprReal(Ruby::Binary g) { g instanceof @ruby_binary_plus } or
|
||||
TAddExprSynth(AST::AstNode parent, int i) { mkSynthChild(AddExprKind(), parent, i) } or
|
||||
TAliasStmt(Ruby::Alias g) or
|
||||
TAlternativePattern(Ruby::AlternativePattern g) or
|
||||
TArgumentList(Ruby::AstNode g) {
|
||||
(
|
||||
g.getParent() instanceof Ruby::Break or
|
||||
@@ -44,6 +46,7 @@ private module Cached {
|
||||
g instanceof Ruby::RightAssignmentList
|
||||
)
|
||||
} or
|
||||
TArrayPattern(Ruby::ArrayPattern g) or
|
||||
TAssignAddExpr(Ruby::OperatorAssignment g) { g instanceof @ruby_operator_assignment_plusequal } or
|
||||
TAssignBitwiseAndExpr(Ruby::OperatorAssignment g) {
|
||||
g instanceof @ruby_operator_assignment_ampersandequal
|
||||
@@ -77,6 +80,7 @@ private module Cached {
|
||||
g instanceof @ruby_operator_assignment_ranglerangleequal
|
||||
} or
|
||||
TAssignSubExpr(Ruby::OperatorAssignment g) { g instanceof @ruby_operator_assignment_minusequal } or
|
||||
TAsPattern(Ruby::AsPattern g) or
|
||||
TBareStringLiteral(Ruby::BareString g) or
|
||||
TBareSymbolLiteral(Ruby::BareSymbol g) or
|
||||
TBeginBlock(Ruby::BeginBlock g) or
|
||||
@@ -98,6 +102,7 @@ private module Cached {
|
||||
TBreakStmt(Ruby::Break g) or
|
||||
TCaseEqExpr(Ruby::Binary g) { g instanceof @ruby_binary_equalequalequal } or
|
||||
TCaseExpr(Ruby::Case g) or
|
||||
TCaseMatch(Ruby::CaseMatch g) or
|
||||
TCharacterLiteral(Ruby::Character g) or
|
||||
TClassDeclaration(Ruby::Class g) or
|
||||
TClassVariableAccessReal(Ruby::ClassVariable g, AST::ClassVariable v) {
|
||||
@@ -124,12 +129,15 @@ private module Cached {
|
||||
TElse(Ruby::Else g) or
|
||||
TElsif(Ruby::Elsif g) or
|
||||
TEmptyStmt(Ruby::EmptyStatement g) or
|
||||
TEncoding(Ruby::Encoding g) or
|
||||
TEndBlock(Ruby::EndBlock g) or
|
||||
TEnsure(Ruby::Ensure g) or
|
||||
TEqExpr(Ruby::Binary g) { g instanceof @ruby_binary_equalequal } or
|
||||
TExponentExprReal(Ruby::Binary g) { g instanceof @ruby_binary_starstar } or
|
||||
TExponentExprSynth(AST::AstNode parent, int i) { mkSynthChild(ExponentExprKind(), parent, i) } or
|
||||
TFalseLiteral(Ruby::False g) or
|
||||
TFile(Ruby::File g) or
|
||||
TFindPattern(Ruby::FindPattern g) or
|
||||
TFloatLiteral(Ruby::Float g) { not any(Ruby::Rational r).getChild() = g } or
|
||||
TForExpr(Ruby::For g) or
|
||||
TForwardParameter(Ruby::ForwardParameter g) or
|
||||
@@ -144,12 +152,17 @@ private module Cached {
|
||||
} or
|
||||
THashKeySymbolLiteral(Ruby::HashKeySymbol g) or
|
||||
THashLiteral(Ruby::Hash g) or
|
||||
THashPattern(Ruby::HashPattern g) or
|
||||
THashSplatExpr(Ruby::HashSplatArgument g) or
|
||||
THashSplatParameter(Ruby::HashSplatParameter g) or
|
||||
THashSplatNilParameter(Ruby::HashSplatNil g) { not g.getParent() instanceof Ruby::HashPattern } or
|
||||
THashSplatParameter(Ruby::HashSplatParameter g) {
|
||||
not g.getParent() instanceof Ruby::HashPattern
|
||||
} or
|
||||
THereDoc(Ruby::HeredocBeginning g) or
|
||||
TIdentifierMethodCall(Ruby::Identifier g) { isIdentifierMethodCall(g) } or
|
||||
TIf(Ruby::If g) or
|
||||
TIfModifierExpr(Ruby::IfModifier g) or
|
||||
TInClause(Ruby::InClause g) or
|
||||
TInstanceVariableAccessReal(Ruby::InstanceVariable g, AST::InstanceVariable v) {
|
||||
InstanceVariableAccess::range(g, v)
|
||||
} or
|
||||
@@ -166,6 +179,7 @@ private module Cached {
|
||||
TLShiftExprSynth(AST::AstNode parent, int i) { mkSynthChild(LShiftExprKind(), parent, i) } or
|
||||
TLTExpr(Ruby::Binary g) { g instanceof @ruby_binary_langle } or
|
||||
TLambda(Ruby::Lambda g) or
|
||||
TLine(Ruby::Line g) or
|
||||
TLeftAssignmentList(Ruby::LeftAssignmentList g) or
|
||||
TLocalVariableAccessReal(Ruby::Identifier g, TLocalVariableReal v) {
|
||||
LocalVariableAccess::range(g, v)
|
||||
@@ -229,6 +243,10 @@ private module Cached {
|
||||
vcall(g)
|
||||
or
|
||||
explicitAssignmentNode(g, _)
|
||||
or
|
||||
casePattern(g)
|
||||
or
|
||||
classReferencePattern(g)
|
||||
)
|
||||
} or
|
||||
TScopeResolutionMethodCall(Ruby::ScopeResolution g, Ruby::Identifier i) {
|
||||
@@ -248,7 +266,10 @@ private module Cached {
|
||||
TSpaceshipExpr(Ruby::Binary g) { g instanceof @ruby_binary_langleequalrangle } or
|
||||
TSplatExprReal(Ruby::SplatArgument g) or
|
||||
TSplatExprSynth(AST::AstNode parent, int i) { mkSynthChild(SplatExprKind(), parent, i) } or
|
||||
TSplatParameter(Ruby::SplatParameter g) or
|
||||
TSplatParameter(Ruby::SplatParameter g) {
|
||||
not g.getParent() instanceof Ruby::ArrayPattern and
|
||||
not g.getParent() instanceof Ruby::FindPattern
|
||||
} or
|
||||
TStmtSequenceSynth(AST::AstNode parent, int i) { mkSynthChild(StmtSequenceKind(), parent, i) } or
|
||||
TStringArrayLiteral(Ruby::StringArray g) or
|
||||
TStringConcatenation(Ruby::ChainedString g) or
|
||||
@@ -269,6 +290,10 @@ private module Cached {
|
||||
vcall(g)
|
||||
or
|
||||
explicitAssignmentNode(g, _)
|
||||
or
|
||||
casePattern(g)
|
||||
or
|
||||
classReferencePattern(g)
|
||||
} or
|
||||
TTokenMethodName(MethodName::Token g) { MethodName::range(g) } or
|
||||
TTokenSuperCall(Ruby::Super g) { vcall(g) } or
|
||||
@@ -282,34 +307,38 @@ private module Cached {
|
||||
TUnlessModifierExpr(Ruby::UnlessModifier g) or
|
||||
TUntilExpr(Ruby::Until g) or
|
||||
TUntilModifierExpr(Ruby::UntilModifier g) or
|
||||
TVariableReferencePattern(Ruby::VariableReferencePattern g) or
|
||||
TWhenExpr(Ruby::When g) or
|
||||
TWhileExpr(Ruby::While g) or
|
||||
TWhileModifierExpr(Ruby::WhileModifier g) or
|
||||
TYieldCall(Ruby::Yield g)
|
||||
|
||||
class TAstNodeReal =
|
||||
TAddExprReal or TAliasStmt or TArgumentList or TAssignAddExpr or TAssignBitwiseAndExpr or
|
||||
TAssignBitwiseOrExpr or TAssignBitwiseXorExpr or TAssignDivExpr or TAssignExponentExpr or
|
||||
TAssignExprReal or TAssignLShiftExpr or TAssignLogicalAndExpr or TAssignLogicalOrExpr or
|
||||
TAssignModuloExpr or TAssignMulExpr or TAssignRShiftExpr or TAssignSubExpr or
|
||||
TBareStringLiteral or TBareSymbolLiteral or TBeginBlock or TBeginExpr or
|
||||
TBitwiseAndExprReal or TBitwiseOrExprReal or TBitwiseXorExprReal or TBlockArgument or
|
||||
TBlockParameter or TBraceBlockReal or TBreakStmt or TCaseEqExpr or TCaseExpr or
|
||||
TAddExprReal or TAliasStmt or TAlternativePattern or TArgumentList or TArrayPattern or
|
||||
TAsPattern or TAssignAddExpr or TAssignBitwiseAndExpr or TAssignBitwiseOrExpr or
|
||||
TAssignBitwiseXorExpr or TAssignDivExpr or TAssignExponentExpr or TAssignExprReal or
|
||||
TAssignLShiftExpr or TAssignLogicalAndExpr or TAssignLogicalOrExpr or TAssignModuloExpr or
|
||||
TAssignMulExpr or TAssignRShiftExpr or TAssignSubExpr or TBareStringLiteral or
|
||||
TBareSymbolLiteral or TBeginBlock or TBeginExpr or TBitwiseAndExprReal or
|
||||
TBitwiseOrExprReal or TBitwiseXorExprReal or TBlockArgument or TBlockParameter or
|
||||
TBraceBlockReal or TBreakStmt or TCaseEqExpr or TCaseExpr or TCaseMatch or
|
||||
TCharacterLiteral or TClassDeclaration or TClassVariableAccessReal or TComplementExpr or
|
||||
TComplexLiteral or TDefinedExpr or TDelimitedSymbolLiteral or TDestructuredLeftAssignment or
|
||||
TDivExprReal or TDo or TDoBlock or TElementReference or TElse or TElsif or TEmptyStmt or
|
||||
TEndBlock or TEnsure or TEqExpr or TExponentExprReal or TFalseLiteral or TFloatLiteral or
|
||||
TForExpr or TForwardParameter or TForwardArgument or TGEExpr or TGTExpr or
|
||||
TGlobalVariableAccessReal or THashKeySymbolLiteral or THashLiteral or THashSplatExpr or
|
||||
THashSplatParameter or THereDoc or TIdentifierMethodCall or TIf or TIfModifierExpr or
|
||||
TInstanceVariableAccessReal or TIntegerLiteralReal or TKeywordParameter or TLEExpr or
|
||||
TLShiftExprReal or TLTExpr or TLambda or TLeftAssignmentList or TLocalVariableAccessReal or
|
||||
TLogicalAndExprReal or TLogicalOrExprReal or TMethod or TModuleDeclaration or
|
||||
TModuloExprReal or TMulExprReal or TNEExpr or TNextStmt or TNilLiteral or
|
||||
TNoRegExpMatchExpr or TNotExpr or TOptionalParameter or TPair or TParenthesizedExpr or
|
||||
TRShiftExprReal or TRangeLiteralReal or TRationalLiteral or TRedoStmt or TRegExpLiteral or
|
||||
TRegExpMatchExpr or TRegularArrayLiteral or TRegularMethodCall or TRegularStringLiteral or
|
||||
TRegularSuperCall or TRescueClause or TRescueModifierExpr or TRetryStmt or TReturnStmt or
|
||||
TEncoding or TEndBlock or TEnsure or TEqExpr or TExponentExprReal or TFalseLiteral or
|
||||
TFile or TFindPattern or TFloatLiteral or TForExpr or TForwardParameter or
|
||||
TForwardArgument or TGEExpr or TGTExpr or TGlobalVariableAccessReal or
|
||||
THashKeySymbolLiteral or THashLiteral or THashPattern or THashSplatExpr or
|
||||
THashSplatNilParameter or THashSplatParameter or THereDoc or TIdentifierMethodCall or TIf or
|
||||
TIfModifierExpr or TInClause or TInstanceVariableAccessReal or TIntegerLiteralReal or
|
||||
TKeywordParameter or TLEExpr or TLShiftExprReal or TLTExpr or TLambda or
|
||||
TLeftAssignmentList or TLine or TLocalVariableAccessReal or TLogicalAndExprReal or
|
||||
TLogicalOrExprReal or TMethod or TModuleDeclaration or TModuloExprReal or TMulExprReal or
|
||||
TNEExpr or TNextStmt or TNilLiteral or TNoRegExpMatchExpr or TNotExpr or
|
||||
TOptionalParameter or TPair or TParenthesizedExpr or TRShiftExprReal or TRangeLiteralReal or
|
||||
TRationalLiteral or TRedoStmt or TRegExpLiteral or TRegExpMatchExpr or
|
||||
TRegularArrayLiteral or TRegularMethodCall or TRegularStringLiteral or TRegularSuperCall or
|
||||
TRescueClause or TRescueModifierExpr or TRetryStmt or TReturnStmt or
|
||||
TScopeResolutionConstantAccess or TScopeResolutionMethodCall or TSelfReal or
|
||||
TSimpleParameterReal or TSimpleSymbolLiteral or TSingletonClass or TSingletonMethod or
|
||||
TSpaceshipExpr or TSplatExprReal or TSplatParameter or TStringArrayLiteral or
|
||||
@@ -318,7 +347,7 @@ private module Cached {
|
||||
TTernaryIfExpr or TThen or TTokenConstantAccess or TTokenMethodName or TTokenSuperCall or
|
||||
TToplevel or TTrueLiteral or TTuplePatternParameter or TUnaryMinusExpr or TUnaryPlusExpr or
|
||||
TUndefStmt or TUnlessExpr or TUnlessModifierExpr or TUntilExpr or TUntilModifierExpr or
|
||||
TWhenExpr or TWhileExpr or TWhileModifierExpr or TYieldCall;
|
||||
TVariableReferencePattern or TWhenExpr or TWhileExpr or TWhileModifierExpr or TYieldCall;
|
||||
|
||||
class TAstNodeSynth =
|
||||
TAddExprSynth or TAssignExprSynth or TBitwiseAndExprSynth or TBitwiseOrExprSynth or
|
||||
@@ -339,7 +368,10 @@ private module Cached {
|
||||
Ruby::AstNode toGenerated(TAstNodeReal n) {
|
||||
n = TAddExprReal(result) or
|
||||
n = TAliasStmt(result) or
|
||||
n = TAlternativePattern(result) or
|
||||
n = TArgumentList(result) or
|
||||
n = TArrayPattern(result) or
|
||||
n = TAsPattern(result) or
|
||||
n = TAssignAddExpr(result) or
|
||||
n = TAssignBitwiseAndExpr(result) or
|
||||
n = TAssignBitwiseOrExpr(result) or
|
||||
@@ -347,9 +379,9 @@ private module Cached {
|
||||
n = TAssignDivExpr(result) or
|
||||
n = TAssignExponentExpr(result) or
|
||||
n = TAssignExprReal(result) or
|
||||
n = TAssignLShiftExpr(result) or
|
||||
n = TAssignLogicalAndExpr(result) or
|
||||
n = TAssignLogicalOrExpr(result) or
|
||||
n = TAssignLShiftExpr(result) or
|
||||
n = TAssignModuloExpr(result) or
|
||||
n = TAssignMulExpr(result) or
|
||||
n = TAssignRShiftExpr(result) or
|
||||
@@ -367,6 +399,7 @@ private module Cached {
|
||||
n = TBreakStmt(result) or
|
||||
n = TCaseEqExpr(result) or
|
||||
n = TCaseExpr(result) or
|
||||
n = TCaseMatch(result) or
|
||||
n = TCharacterLiteral(result) or
|
||||
n = TClassDeclaration(result) or
|
||||
n = TClassVariableAccessReal(result, _) or
|
||||
@@ -376,43 +409,50 @@ private module Cached {
|
||||
n = TDelimitedSymbolLiteral(result) or
|
||||
n = TDestructuredLeftAssignment(result) or
|
||||
n = TDivExprReal(result) or
|
||||
n = TDo(result) or
|
||||
n = TDoBlock(result) or
|
||||
n = TDo(result) or
|
||||
n = TElementReference(result) or
|
||||
n = TElse(result) or
|
||||
n = TElsif(result) or
|
||||
n = TEmptyStmt(result) or
|
||||
n = TEncoding(result) or
|
||||
n = TEndBlock(result) or
|
||||
n = TEnsure(result) or
|
||||
n = TEqExpr(result) or
|
||||
n = TExponentExprReal(result) or
|
||||
n = TFalseLiteral(result) or
|
||||
n = TFile(result) or
|
||||
n = TFindPattern(result) or
|
||||
n = TFloatLiteral(result) or
|
||||
n = TForExpr(result) or
|
||||
n = TForwardArgument(result) or
|
||||
n = TForwardParameter(result) or
|
||||
n = TGEExpr(result) or
|
||||
n = TGTExpr(result) or
|
||||
n = TGlobalVariableAccessReal(result, _) or
|
||||
n = TGTExpr(result) or
|
||||
n = THashKeySymbolLiteral(result) or
|
||||
n = THashLiteral(result) or
|
||||
n = THashPattern(result) or
|
||||
n = THashSplatExpr(result) or
|
||||
n = THashSplatNilParameter(result) or
|
||||
n = THashSplatParameter(result) or
|
||||
n = THereDoc(result) or
|
||||
n = TIdentifierMethodCall(result) or
|
||||
n = TIf(result) or
|
||||
n = TIfModifierExpr(result) or
|
||||
n = TIf(result) or
|
||||
n = TInClause(result) or
|
||||
n = TInstanceVariableAccessReal(result, _) or
|
||||
n = TIntegerLiteralReal(result) or
|
||||
n = TKeywordParameter(result) or
|
||||
n = TLEExpr(result) or
|
||||
n = TLShiftExprReal(result) or
|
||||
n = TLTExpr(result) or
|
||||
n = TLambda(result) or
|
||||
n = TLEExpr(result) or
|
||||
n = TLeftAssignmentList(result) or
|
||||
n = TLine(result) or
|
||||
n = TLocalVariableAccessReal(result, _) or
|
||||
n = TLogicalAndExprReal(result) or
|
||||
n = TLogicalOrExprReal(result) or
|
||||
n = TLShiftExprReal(result) or
|
||||
n = TLTExpr(result) or
|
||||
n = TMethod(result) or
|
||||
n = TModuleDeclaration(result) or
|
||||
n = TModuloExprReal(result) or
|
||||
@@ -425,7 +465,6 @@ private module Cached {
|
||||
n = TOptionalParameter(result) or
|
||||
n = TPair(result) or
|
||||
n = TParenthesizedExpr(result) or
|
||||
n = TRShiftExprReal(result) or
|
||||
n = TRangeLiteralReal(result) or
|
||||
n = TRationalLiteral(result) or
|
||||
n = TRedoStmt(result) or
|
||||
@@ -439,6 +478,7 @@ private module Cached {
|
||||
n = TRescueModifierExpr(result) or
|
||||
n = TRetryStmt(result) or
|
||||
n = TReturnStmt(result) or
|
||||
n = TRShiftExprReal(result) or
|
||||
n = TScopeResolutionConstantAccess(result, _) or
|
||||
n = TScopeResolutionMethodCall(result, _) or
|
||||
n = TSelfReal(result) or
|
||||
@@ -472,6 +512,7 @@ private module Cached {
|
||||
n = TUnlessModifierExpr(result) or
|
||||
n = TUntilExpr(result) or
|
||||
n = TUntilModifierExpr(result) or
|
||||
n = TVariableReferencePattern(result) or
|
||||
n = TWhenExpr(result) or
|
||||
n = TWhileExpr(result) or
|
||||
n = TWhileModifierExpr(result) or
|
||||
@@ -582,6 +623,8 @@ TAstNodeReal fromGenerated(Ruby::AstNode n) { n = toGenerated(result) }
|
||||
|
||||
class TCall = TMethodCall or TYieldCall;
|
||||
|
||||
class TCase = TCaseExpr or TCaseMatch;
|
||||
|
||||
class TMethodCall =
|
||||
TMethodCallSynth or TIdentifierMethodCall or TScopeResolutionMethodCall or TRegularMethodCall or
|
||||
TElementReference or TSuperCall or TUnaryOperation or TBinaryOperation;
|
||||
@@ -591,7 +634,7 @@ class TSuperCall = TTokenSuperCall or TRegularSuperCall;
|
||||
class TConstantAccess =
|
||||
TTokenConstantAccess or TScopeResolutionConstantAccess or TNamespace or TConstantReadAccessSynth;
|
||||
|
||||
class TControlExpr = TConditionalExpr or TCaseExpr or TLoop;
|
||||
class TControlExpr = TConditionalExpr or TCaseExpr or TCaseMatch or TLoop;
|
||||
|
||||
class TConditionalExpr =
|
||||
TIfExpr or TUnlessExpr or TIfModifierExpr or TUnlessModifierExpr or TTernaryIfExpr;
|
||||
@@ -605,10 +648,10 @@ class TLoop = TConditionalLoop or TForExpr;
|
||||
class TSelf = TSelfReal or TSelfSynth;
|
||||
|
||||
class TExpr =
|
||||
TSelf or TArgumentList or TRescueClause or TRescueModifierExpr or TPair or TStringConcatenation or
|
||||
TCall or TBlockArgument or TConstantAccess or TControlExpr or TWhenExpr or TLiteral or
|
||||
TCallable or TVariableAccess or TStmtSequence or TOperation or TSimpleParameter or
|
||||
TForwardArgument;
|
||||
TSelf or TArgumentList or TInClause or TRescueClause or TRescueModifierExpr or TPair or
|
||||
TStringConcatenation or TCall or TBlockArgument or TConstantAccess or TControlExpr or
|
||||
TWhenExpr or TLiteral or TCallable or TVariableAccess or TStmtSequence or TOperation or
|
||||
TSimpleParameter or TForwardArgument;
|
||||
|
||||
class TSplatExpr = TSplatExprReal or TSplatExprSynth;
|
||||
|
||||
@@ -619,8 +662,9 @@ class TStmtSequence =
|
||||
class TBodyStmt = TBeginExpr or TModuleBase or TMethod or TLambda or TDoBlock or TSingletonMethod;
|
||||
|
||||
class TLiteral =
|
||||
TNumericLiteral or TNilLiteral or TBooleanLiteral or TStringlikeLiteral or TCharacterLiteral or
|
||||
TArrayLiteral or THashLiteral or TRangeLiteral or TTokenMethodName;
|
||||
TEncoding or TFile or TLine or TNumericLiteral or TNilLiteral or TBooleanLiteral or
|
||||
TStringlikeLiteral or TCharacterLiteral or TArrayLiteral or THashLiteral or TRangeLiteral or
|
||||
TTokenMethodName;
|
||||
|
||||
class TNumericLiteral = TIntegerLiteral or TFloatLiteral or TRationalLiteral or TComplexLiteral;
|
||||
|
||||
@@ -736,8 +780,8 @@ class TStmt =
|
||||
class TReturningStmt = TReturnStmt or TBreakStmt or TNextStmt;
|
||||
|
||||
class TParameter =
|
||||
TPatternParameter or TBlockParameter or THashSplatParameter or TKeywordParameter or
|
||||
TOptionalParameter or TSplatParameter or TForwardParameter;
|
||||
TPatternParameter or TBlockParameter or THashSplatParameter or THashSplatNilParameter or
|
||||
TKeywordParameter or TOptionalParameter or TSplatParameter or TForwardParameter;
|
||||
|
||||
class TSimpleParameter = TSimpleParameterReal or TSimpleParameterSynth;
|
||||
|
||||
|
||||
36
ruby/ql/lib/codeql/ruby/ast/internal/Control.qll
Normal file
36
ruby/ql/lib/codeql/ruby/ast/internal/Control.qll
Normal file
@@ -0,0 +1,36 @@
|
||||
private import TreeSitter
|
||||
private import codeql.ruby.AST
|
||||
private import codeql.ruby.ast.internal.AST
|
||||
|
||||
abstract class CaseExprImpl extends ControlExpr, TCase {
|
||||
abstract Expr getValue();
|
||||
|
||||
abstract Expr getBranch(int n);
|
||||
}
|
||||
|
||||
class CaseWhenExpr extends CaseExprImpl, TCaseExpr {
|
||||
private Ruby::Case g;
|
||||
|
||||
CaseWhenExpr() { this = TCaseExpr(g) }
|
||||
|
||||
final override Expr getValue() { toGenerated(result) = g.getValue() }
|
||||
|
||||
final override Expr getBranch(int n) {
|
||||
toGenerated(result) = g.getChild(n) or
|
||||
toGenerated(result) = g.getChild(n)
|
||||
}
|
||||
}
|
||||
|
||||
class CaseMatch extends CaseExprImpl, TCaseMatch {
|
||||
private Ruby::CaseMatch g;
|
||||
|
||||
CaseMatch() { this = TCaseMatch(g) }
|
||||
|
||||
final override Expr getValue() { toGenerated(result) = g.getValue() }
|
||||
|
||||
final override Expr getBranch(int n) {
|
||||
toGenerated(result) = g.getClauses(n)
|
||||
or
|
||||
n = count(g.getClauses(_)) and toGenerated(result) = g.getElse()
|
||||
}
|
||||
}
|
||||
@@ -30,3 +30,32 @@ class LeftAssignmentListImpl extends TuplePatternImpl, Ruby::LeftAssignmentList
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `node` is a case pattern.
|
||||
*/
|
||||
predicate casePattern(Ruby::AstNode node) {
|
||||
node = any(Ruby::InClause parent).getPattern()
|
||||
or
|
||||
node = any(Ruby::ArrayPattern parent).getChild(_).(Ruby::UnderscorePatternExpr)
|
||||
or
|
||||
node = any(Ruby::FindPattern parent).getChild(_).(Ruby::UnderscorePatternExpr)
|
||||
or
|
||||
node = any(Ruby::AlternativePattern parent).getAlternatives(_)
|
||||
or
|
||||
node = any(Ruby::AsPattern parent).getValue()
|
||||
or
|
||||
node = any(Ruby::KeywordPattern parent).getValue()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `node` is a class reference used in an
|
||||
* array, find, or hash pattern.
|
||||
*/
|
||||
predicate classReferencePattern(Ruby::AstNode node) {
|
||||
node = any(Ruby::ArrayPattern p).getClass()
|
||||
or
|
||||
node = any(Ruby::FindPattern p).getClass()
|
||||
or
|
||||
node = any(Ruby::HashPattern p).getClass()
|
||||
}
|
||||
|
||||
@@ -53,12 +53,26 @@ module Ruby {
|
||||
|
||||
class UnderscoreArg extends @ruby_underscore_arg, AstNode { }
|
||||
|
||||
class UnderscoreExpression extends @ruby_underscore_expression, AstNode { }
|
||||
|
||||
class UnderscoreLhs extends @ruby_underscore_lhs, AstNode { }
|
||||
|
||||
class UnderscoreMethodName extends @ruby_underscore_method_name, AstNode { }
|
||||
|
||||
class UnderscorePatternConstant extends @ruby_underscore_pattern_constant, AstNode { }
|
||||
|
||||
class UnderscorePatternExpr extends @ruby_underscore_pattern_expr, AstNode { }
|
||||
|
||||
class UnderscorePatternExprBasic extends @ruby_underscore_pattern_expr_basic, AstNode { }
|
||||
|
||||
class UnderscorePatternPrimitive extends @ruby_underscore_pattern_primitive, AstNode { }
|
||||
|
||||
class UnderscorePatternTopExprBody extends @ruby_underscore_pattern_top_expr_body, AstNode { }
|
||||
|
||||
class UnderscorePrimary extends @ruby_underscore_primary, AstNode { }
|
||||
|
||||
class UnderscoreSimpleNumeric extends @ruby_underscore_simple_numeric, AstNode { }
|
||||
|
||||
class UnderscoreStatement extends @ruby_underscore_statement, AstNode { }
|
||||
|
||||
class UnderscoreVariable extends @ruby_underscore_variable, AstNode { }
|
||||
@@ -83,6 +97,23 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `alternative_pattern` nodes. */
|
||||
class AlternativePattern extends @ruby_alternative_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "AlternativePattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_alternative_pattern_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `alternatives`. */
|
||||
UnderscorePatternExprBasic getAlternatives(int i) {
|
||||
ruby_alternative_pattern_alternatives(this, i, result)
|
||||
}
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() { ruby_alternative_pattern_alternatives(this, _, result) }
|
||||
}
|
||||
|
||||
/** A class representing `argument_list` nodes. */
|
||||
class ArgumentList extends @ruby_argument_list, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -113,6 +144,46 @@ module Ruby {
|
||||
override AstNode getAFieldOrChild() { ruby_array_child(this, _, result) }
|
||||
}
|
||||
|
||||
/** A class representing `array_pattern` nodes. */
|
||||
class ArrayPattern extends @ruby_array_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "ArrayPattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_array_pattern_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `class`. */
|
||||
UnderscorePatternConstant getClass() { ruby_array_pattern_class(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
AstNode getChild(int i) { ruby_array_pattern_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_array_pattern_class(this, result) or ruby_array_pattern_child(this, _, result)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `as_pattern` nodes. */
|
||||
class AsPattern extends @ruby_as_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "AsPattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_as_pattern_def(this, _, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
Identifier getName() { ruby_as_pattern_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `value`. */
|
||||
UnderscorePatternExpr getValue() { ruby_as_pattern_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_as_pattern_def(this, result, _, _) or ruby_as_pattern_def(this, _, result, _)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `assignment` nodes. */
|
||||
class Assignment extends @ruby_assignment, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -202,7 +273,7 @@ module Ruby {
|
||||
override L::Location getLocation() { ruby_binary_def(this, _, _, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `left`. */
|
||||
AstNode getLeft() { ruby_binary_def(this, result, _, _, _) }
|
||||
UnderscoreExpression getLeft() { ruby_binary_def(this, result, _, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `operator`. */
|
||||
string getOperator() {
|
||||
@@ -260,7 +331,7 @@ module Ruby {
|
||||
}
|
||||
|
||||
/** Gets the node corresponding to the field `right`. */
|
||||
AstNode getRight() { ruby_binary_def(this, _, _, result, _) }
|
||||
UnderscoreExpression getRight() { ruby_binary_def(this, _, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -397,6 +468,31 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `case_match` nodes. */
|
||||
class CaseMatch extends @ruby_case_match, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "CaseMatch" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_case_match_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `clauses`. */
|
||||
InClause getClauses(int i) { ruby_case_match_clauses(this, i, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `else`. */
|
||||
Else getElse() { ruby_case_match_else(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `value`. */
|
||||
UnderscoreStatement getValue() { ruby_case_match_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_case_match_clauses(this, _, result) or
|
||||
ruby_case_match_else(this, result) or
|
||||
ruby_case_match_def(this, result, _)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `chained_string` nodes. */
|
||||
class ChainedString extends @ruby_chained_string, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -638,6 +734,12 @@ module Ruby {
|
||||
override string getAPrimaryQlClass() { result = "EmptyStatement" }
|
||||
}
|
||||
|
||||
/** A class representing `encoding` tokens. */
|
||||
class Encoding extends @ruby_token_encoding, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "Encoding" }
|
||||
}
|
||||
|
||||
/** A class representing `end_block` nodes. */
|
||||
class EndBlock extends @ruby_end_block, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -710,6 +812,32 @@ module Ruby {
|
||||
override string getAPrimaryQlClass() { result = "False" }
|
||||
}
|
||||
|
||||
/** A class representing `file` tokens. */
|
||||
class File extends @ruby_token_file, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "File" }
|
||||
}
|
||||
|
||||
/** A class representing `find_pattern` nodes. */
|
||||
class FindPattern extends @ruby_find_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "FindPattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_find_pattern_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `class`. */
|
||||
UnderscorePatternConstant getClass() { ruby_find_pattern_class(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
AstNode getChild(int i) { ruby_find_pattern_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_find_pattern_class(this, result) or ruby_find_pattern_child(this, _, result)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `float` tokens. */
|
||||
class Float extends @ruby_token_float, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -780,6 +908,26 @@ module Ruby {
|
||||
override string getAPrimaryQlClass() { result = "HashKeySymbol" }
|
||||
}
|
||||
|
||||
/** A class representing `hash_pattern` nodes. */
|
||||
class HashPattern extends @ruby_hash_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "HashPattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_hash_pattern_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `class`. */
|
||||
UnderscorePatternConstant getClass() { ruby_hash_pattern_class(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
AstNode getChild(int i) { ruby_hash_pattern_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_hash_pattern_class(this, result) or ruby_hash_pattern_child(this, _, result)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `hash_splat_argument` nodes. */
|
||||
class HashSplatArgument extends @ruby_hash_splat_argument, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -795,6 +943,12 @@ module Ruby {
|
||||
override AstNode getAFieldOrChild() { ruby_hash_splat_argument_def(this, result, _) }
|
||||
}
|
||||
|
||||
/** A class representing `hash_splat_nil` tokens. */
|
||||
class HashSplatNil extends @ruby_token_hash_splat_nil, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "HashSplatNil" }
|
||||
}
|
||||
|
||||
/** A class representing `hash_splat_parameter` nodes. */
|
||||
class HashSplatParameter extends @ruby_hash_splat_parameter, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -874,6 +1028,21 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `if_guard` nodes. */
|
||||
class IfGuard extends @ruby_if_guard, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "IfGuard" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_if_guard_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
UnderscoreExpression getCondition() { ruby_if_guard_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() { ruby_if_guard_def(this, result, _) }
|
||||
}
|
||||
|
||||
/** A class representing `if_modifier` nodes. */
|
||||
class IfModifier extends @ruby_if_modifier, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -886,7 +1055,7 @@ module Ruby {
|
||||
UnderscoreStatement getBody() { ruby_if_modifier_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
AstNode getCondition() { ruby_if_modifier_def(this, _, result, _) }
|
||||
UnderscoreExpression getCondition() { ruby_if_modifier_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -909,6 +1078,31 @@ module Ruby {
|
||||
override AstNode getAFieldOrChild() { ruby_in_def(this, result, _) }
|
||||
}
|
||||
|
||||
/** A class representing `in_clause` nodes. */
|
||||
class InClause extends @ruby_in_clause, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "InClause" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_in_clause_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
Then getBody() { ruby_in_clause_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `guard`. */
|
||||
AstNode getGuard() { ruby_in_clause_guard(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `pattern`. */
|
||||
UnderscorePatternTopExprBody getPattern() { ruby_in_clause_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_in_clause_body(this, result) or
|
||||
ruby_in_clause_guard(this, result) or
|
||||
ruby_in_clause_def(this, result, _)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `instance_variable` tokens. */
|
||||
class InstanceVariable extends @ruby_token_instance_variable, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -956,6 +1150,26 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `keyword_pattern` nodes. */
|
||||
class KeywordPattern extends @ruby_keyword_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "KeywordPattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_keyword_pattern_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `key`. */
|
||||
AstNode getKey() { ruby_keyword_pattern_def(this, result, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `value`. */
|
||||
UnderscorePatternExpr getValue() { ruby_keyword_pattern_value(this, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
ruby_keyword_pattern_def(this, result, _) or ruby_keyword_pattern_value(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `lambda` nodes. */
|
||||
class Lambda extends @ruby_lambda, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -1006,6 +1220,12 @@ module Ruby {
|
||||
override AstNode getAFieldOrChild() { ruby_left_assignment_list_child(this, _, result) }
|
||||
}
|
||||
|
||||
/** A class representing `line` tokens. */
|
||||
class Line extends @ruby_token_line, Token {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "Line" }
|
||||
}
|
||||
|
||||
/** A class representing `method` nodes. */
|
||||
class Method extends @ruby_method, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -1136,7 +1356,7 @@ module Ruby {
|
||||
}
|
||||
|
||||
/** Gets the node corresponding to the field `right`. */
|
||||
AstNode getRight() { ruby_operator_assignment_def(this, _, _, result, _) }
|
||||
UnderscoreExpression getRight() { ruby_operator_assignment_def(this, _, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -1240,10 +1460,10 @@ module Ruby {
|
||||
override L::Location getLocation() { ruby_range_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `begin`. */
|
||||
UnderscoreArg getBegin() { ruby_range_begin(this, result) }
|
||||
AstNode getBegin() { ruby_range_begin(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `end`. */
|
||||
UnderscoreArg getEnd() { ruby_range_end(this, result) }
|
||||
AstNode getEnd() { ruby_range_end(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `operator`. */
|
||||
string getOperator() {
|
||||
@@ -1339,10 +1559,10 @@ module Ruby {
|
||||
override L::Location getLocation() { ruby_rescue_modifier_def(this, _, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
UnderscoreStatement getBody() { ruby_rescue_modifier_def(this, result, _, _) }
|
||||
AstNode getBody() { ruby_rescue_modifier_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `handler`. */
|
||||
AstNode getHandler() { ruby_rescue_modifier_def(this, _, result, _) }
|
||||
UnderscoreExpression getHandler() { ruby_rescue_modifier_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -1422,7 +1642,7 @@ module Ruby {
|
||||
AstNode getName() { ruby_scope_resolution_def(this, result, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `scope`. */
|
||||
UnderscorePrimary getScope() { ruby_scope_resolution_scope(this, result) }
|
||||
AstNode getScope() { ruby_scope_resolution_scope(this, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -1602,7 +1822,7 @@ module Ruby {
|
||||
override L::Location getLocation() { ruby_superclass_def(this, _, result) }
|
||||
|
||||
/** Gets the child of this node. */
|
||||
AstNode getChild() { ruby_superclass_def(this, result, _) }
|
||||
UnderscoreExpression getChild() { ruby_superclass_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() { ruby_superclass_def(this, result, _) }
|
||||
@@ -1722,6 +1942,21 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `unless_guard` nodes. */
|
||||
class UnlessGuard extends @ruby_unless_guard, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "UnlessGuard" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_unless_guard_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
UnderscoreExpression getCondition() { ruby_unless_guard_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() { ruby_unless_guard_def(this, result, _) }
|
||||
}
|
||||
|
||||
/** A class representing `unless_modifier` nodes. */
|
||||
class UnlessModifier extends @ruby_unless_modifier, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -1734,7 +1969,7 @@ module Ruby {
|
||||
UnderscoreStatement getBody() { ruby_unless_modifier_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
AstNode getCondition() { ruby_unless_modifier_def(this, _, result, _) }
|
||||
UnderscoreExpression getCondition() { ruby_unless_modifier_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -1774,7 +2009,7 @@ module Ruby {
|
||||
UnderscoreStatement getBody() { ruby_until_modifier_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
AstNode getCondition() { ruby_until_modifier_def(this, _, result, _) }
|
||||
UnderscoreExpression getCondition() { ruby_until_modifier_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
@@ -1782,6 +2017,21 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `variable_reference_pattern` nodes. */
|
||||
class VariableReferencePattern extends @ruby_variable_reference_pattern, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
override string getAPrimaryQlClass() { result = "VariableReferencePattern" }
|
||||
|
||||
/** Gets the location of this element. */
|
||||
override L::Location getLocation() { ruby_variable_reference_pattern_def(this, _, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
Identifier getName() { ruby_variable_reference_pattern_def(this, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() { ruby_variable_reference_pattern_def(this, result, _) }
|
||||
}
|
||||
|
||||
/** A class representing `when` nodes. */
|
||||
class When extends @ruby_when, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -1834,7 +2084,7 @@ module Ruby {
|
||||
UnderscoreStatement getBody() { ruby_while_modifier_def(this, result, _, _) }
|
||||
|
||||
/** Gets the node corresponding to the field `condition`. */
|
||||
AstNode getCondition() { ruby_while_modifier_def(this, _, result, _) }
|
||||
UnderscoreExpression getCondition() { ruby_while_modifier_def(this, _, result, _) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
override AstNode getAFieldOrChild() {
|
||||
|
||||
@@ -3,6 +3,7 @@ private import codeql.Locations
|
||||
private import codeql.ruby.AST
|
||||
private import codeql.ruby.ast.internal.AST
|
||||
private import codeql.ruby.ast.internal.Parameter
|
||||
private import codeql.ruby.ast.internal.Pattern
|
||||
private import codeql.ruby.ast.internal.Scope
|
||||
private import codeql.ruby.ast.internal.Synthesis
|
||||
|
||||
@@ -28,6 +29,16 @@ predicate explicitAssignmentNode(Ruby::AstNode n, Ruby::AstNode assignment) {
|
||||
|
||||
/** Holds if `n` is inside an implicit assignment. */
|
||||
predicate implicitAssignmentNode(Ruby::AstNode n) {
|
||||
casePattern(n) and n instanceof Ruby::Identifier
|
||||
or
|
||||
n = any(Ruby::AsPattern p).getName()
|
||||
or
|
||||
n = any(Ruby::ArrayPattern parent).getChild(_).(Ruby::SplatParameter).getName()
|
||||
or
|
||||
n = any(Ruby::FindPattern parent).getChild(_).(Ruby::SplatParameter).getName()
|
||||
or
|
||||
n = any(Ruby::HashPattern parent).getChild(_).(Ruby::HashSplatParameter).getName()
|
||||
or
|
||||
n = any(Ruby::ExceptionVariable ev).getChild()
|
||||
or
|
||||
n = any(Ruby::For for).getPattern()
|
||||
@@ -177,6 +188,8 @@ private module Cached {
|
||||
or
|
||||
i = any(Ruby::Case x).getValue()
|
||||
or
|
||||
i = any(Ruby::CaseMatch x).getValue()
|
||||
or
|
||||
i = any(Ruby::Class x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::Conditional x).getCondition()
|
||||
@@ -498,11 +511,10 @@ module LocalVariableAccess {
|
||||
predicate range(Ruby::Identifier id, TLocalVariableReal v) {
|
||||
access(id, v) and
|
||||
(
|
||||
explicitWriteAccess(id, _)
|
||||
or
|
||||
implicitWriteAccess(id)
|
||||
or
|
||||
vcall(id)
|
||||
explicitWriteAccess(id, _) or
|
||||
implicitWriteAccess(id) or
|
||||
vcall(id) or
|
||||
id = any(Ruby::VariableReferencePattern vr).getName()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ private predicate inBooleanContext(AstNode n) {
|
||||
or
|
||||
exists(CaseExpr c, WhenExpr w |
|
||||
not exists(c.getValue()) and
|
||||
c.getAWhenBranch() = w and
|
||||
c.getABranch() = w and
|
||||
w.getPattern(_) = n
|
||||
)
|
||||
}
|
||||
@@ -214,7 +214,7 @@ private predicate inMatchingContext(AstNode n) {
|
||||
or
|
||||
exists(CaseExpr c, WhenExpr w |
|
||||
exists(c.getValue()) and
|
||||
c.getAWhenBranch() = w and
|
||||
c.getABranch() = w and
|
||||
w.getPattern(_) = n
|
||||
)
|
||||
or
|
||||
|
||||
@@ -378,7 +378,7 @@ module Trees {
|
||||
override ControlFlowTree getChildElement(int i) { result = this.getArgument(i) }
|
||||
}
|
||||
|
||||
private class CaseTree extends PreOrderTree, CaseExpr {
|
||||
private class CaseTree extends PreOrderTree, CaseExpr, ASTInternal::TCaseExpr {
|
||||
final override predicate propagatesAbnormal(AstNode child) {
|
||||
child = this.getValue() or child = this.getABranch()
|
||||
}
|
||||
@@ -386,7 +386,7 @@ module Trees {
|
||||
final override predicate last(AstNode last, Completion c) {
|
||||
last(this.getValue(), last, c) and not exists(this.getABranch())
|
||||
or
|
||||
last(this.getAWhenBranch().getBody(), last, c)
|
||||
last(this.getABranch().(WhenExpr).getBody(), last, c)
|
||||
or
|
||||
exists(int i, ControlFlowTree lastBranch |
|
||||
lastBranch = this.getBranch(i) and
|
||||
@@ -603,6 +603,8 @@ module Trees {
|
||||
final override ControlFlowTree getChildElement(int i) { result = this.getElement(i) }
|
||||
}
|
||||
|
||||
private class HashSplatNilParameterTree extends LeafTree, HashSplatNilParameter { }
|
||||
|
||||
private class HashSplatParameterTree extends NonDefaultValueParameterTree, HashSplatParameter { }
|
||||
|
||||
private class HereDocTree extends StandardPreOrderTree, HereDoc {
|
||||
|
||||
@@ -52,13 +52,27 @@ case @diagnostic.severity of
|
||||
|
||||
@ruby_underscore_arg = @ruby_assignment | @ruby_binary | @ruby_conditional | @ruby_operator_assignment | @ruby_range | @ruby_unary | @ruby_underscore_primary
|
||||
|
||||
@ruby_underscore_expression = @ruby_assignment | @ruby_binary | @ruby_break | @ruby_call | @ruby_next | @ruby_operator_assignment | @ruby_return | @ruby_unary | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
@ruby_underscore_lhs = @ruby_call | @ruby_element_reference | @ruby_scope_resolution | @ruby_token_false | @ruby_token_nil | @ruby_token_true | @ruby_underscore_variable
|
||||
|
||||
@ruby_underscore_method_name = @ruby_delimited_symbol | @ruby_setter | @ruby_token_class_variable | @ruby_token_constant | @ruby_token_global_variable | @ruby_token_identifier | @ruby_token_instance_variable | @ruby_token_operator | @ruby_token_simple_symbol
|
||||
|
||||
@ruby_underscore_primary = @ruby_array | @ruby_begin | @ruby_break | @ruby_case__ | @ruby_chained_string | @ruby_class | @ruby_delimited_symbol | @ruby_for | @ruby_hash | @ruby_if | @ruby_lambda | @ruby_method | @ruby_module | @ruby_next | @ruby_parenthesized_statements | @ruby_rational | @ruby_redo | @ruby_regex | @ruby_retry | @ruby_return | @ruby_singleton_class | @ruby_singleton_method | @ruby_string__ | @ruby_string_array | @ruby_subshell | @ruby_symbol_array | @ruby_token_character | @ruby_token_complex | @ruby_token_float | @ruby_token_heredoc_beginning | @ruby_token_integer | @ruby_token_simple_symbol | @ruby_unary | @ruby_underscore_lhs | @ruby_unless | @ruby_until | @ruby_while | @ruby_yield
|
||||
@ruby_underscore_pattern_constant = @ruby_scope_resolution | @ruby_token_constant
|
||||
|
||||
@ruby_underscore_statement = @ruby_alias | @ruby_assignment | @ruby_begin_block | @ruby_binary | @ruby_break | @ruby_call | @ruby_end_block | @ruby_if_modifier | @ruby_next | @ruby_operator_assignment | @ruby_rescue_modifier | @ruby_return | @ruby_unary | @ruby_undef | @ruby_underscore_arg | @ruby_unless_modifier | @ruby_until_modifier | @ruby_while_modifier | @ruby_yield
|
||||
@ruby_underscore_pattern_expr = @ruby_alternative_pattern | @ruby_as_pattern | @ruby_underscore_pattern_expr_basic
|
||||
|
||||
@ruby_underscore_pattern_expr_basic = @ruby_array_pattern | @ruby_find_pattern | @ruby_hash_pattern | @ruby_range | @ruby_token_identifier | @ruby_underscore_pattern_constant | @ruby_underscore_pattern_primitive | @ruby_variable_reference_pattern
|
||||
|
||||
@ruby_underscore_pattern_primitive = @ruby_delimited_symbol | @ruby_lambda | @ruby_regex | @ruby_string__ | @ruby_string_array | @ruby_symbol_array | @ruby_token_encoding | @ruby_token_false | @ruby_token_file | @ruby_token_line | @ruby_token_nil | @ruby_token_self | @ruby_token_simple_symbol | @ruby_token_true | @ruby_unary | @ruby_underscore_simple_numeric
|
||||
|
||||
@ruby_underscore_pattern_top_expr_body = @ruby_array_pattern | @ruby_find_pattern | @ruby_hash_pattern | @ruby_underscore_pattern_expr
|
||||
|
||||
@ruby_underscore_primary = @ruby_array | @ruby_begin | @ruby_break | @ruby_case__ | @ruby_case_match | @ruby_chained_string | @ruby_class | @ruby_delimited_symbol | @ruby_for | @ruby_hash | @ruby_if | @ruby_lambda | @ruby_method | @ruby_module | @ruby_next | @ruby_parenthesized_statements | @ruby_redo | @ruby_regex | @ruby_retry | @ruby_return | @ruby_singleton_class | @ruby_singleton_method | @ruby_string__ | @ruby_string_array | @ruby_subshell | @ruby_symbol_array | @ruby_token_character | @ruby_token_heredoc_beginning | @ruby_token_simple_symbol | @ruby_unary | @ruby_underscore_lhs | @ruby_underscore_simple_numeric | @ruby_unless | @ruby_until | @ruby_while | @ruby_yield
|
||||
|
||||
@ruby_underscore_simple_numeric = @ruby_rational | @ruby_token_complex | @ruby_token_float | @ruby_token_integer
|
||||
|
||||
@ruby_underscore_statement = @ruby_alias | @ruby_begin_block | @ruby_end_block | @ruby_if_modifier | @ruby_rescue_modifier | @ruby_undef | @ruby_underscore_expression | @ruby_unless_modifier | @ruby_until_modifier | @ruby_while_modifier
|
||||
|
||||
@ruby_underscore_variable = @ruby_token_class_variable | @ruby_token_constant | @ruby_token_global_variable | @ruby_token_identifier | @ruby_token_instance_variable | @ruby_token_self | @ruby_token_super
|
||||
|
||||
@@ -69,7 +83,19 @@ ruby_alias_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_argument_list_child_type = @ruby_block_argument | @ruby_break | @ruby_call | @ruby_hash_splat_argument | @ruby_next | @ruby_pair | @ruby_return | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_arg | @ruby_yield
|
||||
#keyset[ruby_alternative_pattern, index]
|
||||
ruby_alternative_pattern_alternatives(
|
||||
int ruby_alternative_pattern: @ruby_alternative_pattern ref,
|
||||
int index: int ref,
|
||||
unique int alternatives: @ruby_underscore_pattern_expr_basic ref
|
||||
);
|
||||
|
||||
ruby_alternative_pattern_def(
|
||||
unique int id: @ruby_alternative_pattern,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_argument_list_child_type = @ruby_block_argument | @ruby_hash_splat_argument | @ruby_pair | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_expression
|
||||
|
||||
#keyset[ruby_argument_list, index]
|
||||
ruby_argument_list_child(
|
||||
@@ -83,7 +109,7 @@ ruby_argument_list_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_array_child_type = @ruby_block_argument | @ruby_break | @ruby_call | @ruby_hash_splat_argument | @ruby_next | @ruby_pair | @ruby_return | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_arg | @ruby_yield
|
||||
@ruby_array_child_type = @ruby_block_argument | @ruby_hash_splat_argument | @ruby_pair | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_expression
|
||||
|
||||
#keyset[ruby_array, index]
|
||||
ruby_array_child(
|
||||
@@ -97,9 +123,35 @@ ruby_array_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_array_pattern_class(
|
||||
unique int ruby_array_pattern: @ruby_array_pattern ref,
|
||||
unique int class: @ruby_underscore_pattern_constant ref
|
||||
);
|
||||
|
||||
@ruby_array_pattern_child_type = @ruby_splat_parameter | @ruby_underscore_pattern_expr
|
||||
|
||||
#keyset[ruby_array_pattern, index]
|
||||
ruby_array_pattern_child(
|
||||
int ruby_array_pattern: @ruby_array_pattern ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_array_pattern_child_type ref
|
||||
);
|
||||
|
||||
ruby_array_pattern_def(
|
||||
unique int id: @ruby_array_pattern,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_as_pattern_def(
|
||||
unique int id: @ruby_as_pattern,
|
||||
int name: @ruby_token_identifier ref,
|
||||
int value: @ruby_underscore_pattern_expr ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_assignment_left_type = @ruby_left_assignment_list | @ruby_underscore_lhs
|
||||
|
||||
@ruby_assignment_right_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_right_assignment_list | @ruby_splat_argument | @ruby_underscore_arg | @ruby_yield
|
||||
@ruby_assignment_right_type = @ruby_right_assignment_list | @ruby_splat_argument | @ruby_underscore_expression
|
||||
|
||||
ruby_assignment_def(
|
||||
unique int id: @ruby_assignment,
|
||||
@@ -164,8 +216,6 @@ ruby_begin_block_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_binary_left_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
case @ruby_binary.operator of
|
||||
0 = @ruby_binary_bangequal
|
||||
| 1 = @ruby_binary_bangtilde
|
||||
@@ -195,13 +245,11 @@ case @ruby_binary.operator of
|
||||
;
|
||||
|
||||
|
||||
@ruby_binary_right_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
ruby_binary_def(
|
||||
unique int id: @ruby_binary,
|
||||
int left: @ruby_binary_left_type ref,
|
||||
int left: @ruby_underscore_expression ref,
|
||||
int operator: int ref,
|
||||
int right: @ruby_binary_right_type ref,
|
||||
int right: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -236,7 +284,7 @@ ruby_block_parameter_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_block_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_identifier
|
||||
@ruby_block_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_hash_splat_nil | @ruby_token_identifier
|
||||
|
||||
#keyset[ruby_block_parameters, index]
|
||||
ruby_block_parameters_child(
|
||||
@@ -306,6 +354,24 @@ ruby_case_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
#keyset[ruby_case_match, index]
|
||||
ruby_case_match_clauses(
|
||||
int ruby_case_match: @ruby_case_match ref,
|
||||
int index: int ref,
|
||||
unique int clauses: @ruby_in_clause ref
|
||||
);
|
||||
|
||||
ruby_case_match_else(
|
||||
unique int ruby_case_match: @ruby_case_match ref,
|
||||
unique int else: @ruby_else ref
|
||||
);
|
||||
|
||||
ruby_case_match_def(
|
||||
unique int id: @ruby_case_match,
|
||||
int value: @ruby_underscore_statement ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
#keyset[ruby_chained_string, index]
|
||||
ruby_chained_string_child(
|
||||
int ruby_chained_string: @ruby_chained_string ref,
|
||||
@@ -376,7 +442,7 @@ ruby_destructured_left_assignment_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_destructured_parameter_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_identifier
|
||||
@ruby_destructured_parameter_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_hash_splat_nil | @ruby_token_identifier
|
||||
|
||||
#keyset[ruby_destructured_parameter, index]
|
||||
ruby_destructured_parameter_child(
|
||||
@@ -423,7 +489,7 @@ ruby_do_block_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_element_reference_child_type = @ruby_block_argument | @ruby_break | @ruby_call | @ruby_hash_splat_argument | @ruby_next | @ruby_pair | @ruby_return | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_arg | @ruby_yield
|
||||
@ruby_element_reference_child_type = @ruby_block_argument | @ruby_hash_splat_argument | @ruby_pair | @ruby_splat_argument | @ruby_token_forward_argument | @ruby_underscore_expression
|
||||
|
||||
#keyset[ruby_element_reference, index]
|
||||
ruby_element_reference_child(
|
||||
@@ -518,6 +584,25 @@ ruby_exceptions_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_find_pattern_class(
|
||||
unique int ruby_find_pattern: @ruby_find_pattern ref,
|
||||
unique int class: @ruby_underscore_pattern_constant ref
|
||||
);
|
||||
|
||||
@ruby_find_pattern_child_type = @ruby_splat_parameter | @ruby_underscore_pattern_expr
|
||||
|
||||
#keyset[ruby_find_pattern, index]
|
||||
ruby_find_pattern_child(
|
||||
int ruby_find_pattern: @ruby_find_pattern ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_find_pattern_child_type ref
|
||||
);
|
||||
|
||||
ruby_find_pattern_def(
|
||||
unique int id: @ruby_find_pattern,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_for_pattern_type = @ruby_left_assignment_list | @ruby_underscore_lhs
|
||||
|
||||
ruby_for_def(
|
||||
@@ -542,6 +627,25 @@ ruby_hash_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_hash_pattern_class(
|
||||
unique int ruby_hash_pattern: @ruby_hash_pattern ref,
|
||||
unique int class: @ruby_underscore_pattern_constant ref
|
||||
);
|
||||
|
||||
@ruby_hash_pattern_child_type = @ruby_hash_splat_parameter | @ruby_keyword_pattern | @ruby_token_hash_splat_nil
|
||||
|
||||
#keyset[ruby_hash_pattern, index]
|
||||
ruby_hash_pattern_child(
|
||||
int ruby_hash_pattern: @ruby_hash_pattern ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_hash_pattern_child_type ref
|
||||
);
|
||||
|
||||
ruby_hash_pattern_def(
|
||||
unique int id: @ruby_hash_pattern,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_hash_splat_argument_def(
|
||||
unique int id: @ruby_hash_splat_argument,
|
||||
int child: @ruby_underscore_arg ref,
|
||||
@@ -590,12 +694,16 @@ ruby_if_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_if_modifier_condition_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
ruby_if_guard_def(
|
||||
unique int id: @ruby_if_guard,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_if_modifier_def(
|
||||
unique int id: @ruby_if_modifier,
|
||||
int body: @ruby_underscore_statement ref,
|
||||
int condition: @ruby_if_modifier_condition_type ref,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -605,6 +713,24 @@ ruby_in_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_in_clause_body(
|
||||
unique int ruby_in_clause: @ruby_in_clause ref,
|
||||
unique int body: @ruby_then ref
|
||||
);
|
||||
|
||||
@ruby_in_clause_guard_type = @ruby_if_guard | @ruby_unless_guard
|
||||
|
||||
ruby_in_clause_guard(
|
||||
unique int ruby_in_clause: @ruby_in_clause ref,
|
||||
unique int guard: @ruby_in_clause_guard_type ref
|
||||
);
|
||||
|
||||
ruby_in_clause_def(
|
||||
unique int id: @ruby_in_clause,
|
||||
int pattern: @ruby_underscore_pattern_top_expr_body ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_interpolation_child_type = @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_interpolation, index]
|
||||
@@ -630,6 +756,19 @@ ruby_keyword_parameter_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_keyword_pattern_key_type = @ruby_string__ | @ruby_token_hash_key_symbol
|
||||
|
||||
ruby_keyword_pattern_value(
|
||||
unique int ruby_keyword_pattern: @ruby_keyword_pattern ref,
|
||||
unique int value: @ruby_underscore_pattern_expr ref
|
||||
);
|
||||
|
||||
ruby_keyword_pattern_def(
|
||||
unique int id: @ruby_keyword_pattern,
|
||||
int key__: @ruby_keyword_pattern_key_type ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_lambda_body_type = @ruby_block | @ruby_do_block
|
||||
|
||||
ruby_lambda_parameters(
|
||||
@@ -643,7 +782,7 @@ ruby_lambda_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_lambda_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_identifier
|
||||
@ruby_lambda_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_hash_splat_nil | @ruby_token_identifier
|
||||
|
||||
#keyset[ruby_lambda_parameters, index]
|
||||
ruby_lambda_parameters_child(
|
||||
@@ -676,7 +815,7 @@ ruby_method_parameters(
|
||||
unique int parameters: @ruby_method_parameters ref
|
||||
);
|
||||
|
||||
@ruby_method_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
@ruby_method_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_arg | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_method, index]
|
||||
ruby_method_child(
|
||||
@@ -691,7 +830,7 @@ ruby_method_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_method_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_identifier
|
||||
@ruby_method_parameters_child_type = @ruby_block_parameter | @ruby_destructured_parameter | @ruby_hash_splat_parameter | @ruby_keyword_parameter | @ruby_optional_parameter | @ruby_splat_parameter | @ruby_token_forward_parameter | @ruby_token_hash_splat_nil | @ruby_token_identifier
|
||||
|
||||
#keyset[ruby_method_parameters, index]
|
||||
ruby_method_parameters_child(
|
||||
@@ -749,13 +888,11 @@ case @ruby_operator_assignment.operator of
|
||||
;
|
||||
|
||||
|
||||
@ruby_operator_assignment_right_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
ruby_operator_assignment_def(
|
||||
unique int id: @ruby_operator_assignment,
|
||||
int left: @ruby_underscore_lhs ref,
|
||||
int operator: int ref,
|
||||
int right: @ruby_operator_assignment_right_type ref,
|
||||
int right: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -811,14 +948,18 @@ ruby_program_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_range_begin_type = @ruby_underscore_arg | @ruby_underscore_pattern_primitive
|
||||
|
||||
ruby_range_begin(
|
||||
unique int ruby_range: @ruby_range ref,
|
||||
unique int begin: @ruby_underscore_arg ref
|
||||
unique int begin: @ruby_range_begin_type ref
|
||||
);
|
||||
|
||||
@ruby_range_end_type = @ruby_underscore_arg | @ruby_underscore_pattern_primitive
|
||||
|
||||
ruby_range_end(
|
||||
unique int ruby_range: @ruby_range ref,
|
||||
unique int end: @ruby_underscore_arg ref
|
||||
unique int end: @ruby_range_end_type ref
|
||||
);
|
||||
|
||||
case @ruby_range.operator of
|
||||
@@ -885,12 +1026,12 @@ ruby_rescue_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_rescue_modifier_handler_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
@ruby_rescue_modifier_body_type = @ruby_underscore_arg | @ruby_underscore_statement
|
||||
|
||||
ruby_rescue_modifier_def(
|
||||
unique int id: @ruby_rescue_modifier,
|
||||
int body: @ruby_underscore_statement ref,
|
||||
int handler: @ruby_rescue_modifier_handler_type ref,
|
||||
int body: @ruby_rescue_modifier_body_type ref,
|
||||
int handler: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -940,9 +1081,11 @@ ruby_right_assignment_list_def(
|
||||
|
||||
@ruby_scope_resolution_name_type = @ruby_token_constant | @ruby_token_identifier
|
||||
|
||||
@ruby_scope_resolution_scope_type = @ruby_underscore_pattern_constant | @ruby_underscore_primary
|
||||
|
||||
ruby_scope_resolution_scope(
|
||||
unique int ruby_scope_resolution: @ruby_scope_resolution ref,
|
||||
unique int scope: @ruby_underscore_primary ref
|
||||
unique int scope: @ruby_scope_resolution_scope_type ref
|
||||
);
|
||||
|
||||
ruby_scope_resolution_def(
|
||||
@@ -979,7 +1122,7 @@ ruby_singleton_method_parameters(
|
||||
unique int parameters: @ruby_method_parameters ref
|
||||
);
|
||||
|
||||
@ruby_singleton_method_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
@ruby_singleton_method_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_arg | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_singleton_method, index]
|
||||
ruby_singleton_method_child(
|
||||
@@ -1051,11 +1194,9 @@ ruby_subshell_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_superclass_child_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
ruby_superclass_def(
|
||||
unique int id: @ruby_superclass,
|
||||
int child: @ruby_superclass_child_type ref,
|
||||
int child: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -1085,7 +1226,7 @@ ruby_then_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_unary_operand_type = @ruby_break | @ruby_call | @ruby_next | @ruby_parenthesized_statements | @ruby_return | @ruby_token_float | @ruby_token_integer | @ruby_underscore_arg | @ruby_yield
|
||||
@ruby_unary_operand_type = @ruby_parenthesized_statements | @ruby_underscore_expression | @ruby_underscore_simple_numeric
|
||||
|
||||
case @ruby_unary.operator of
|
||||
0 = @ruby_unary_bang
|
||||
@@ -1134,12 +1275,16 @@ ruby_unless_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_unless_modifier_condition_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
ruby_unless_guard_def(
|
||||
unique int id: @ruby_unless_guard,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_unless_modifier_def(
|
||||
unique int id: @ruby_unless_modifier,
|
||||
int body: @ruby_underscore_statement ref,
|
||||
int condition: @ruby_unless_modifier_condition_type ref,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -1150,12 +1295,16 @@ ruby_until_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_until_modifier_condition_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
ruby_until_modifier_def(
|
||||
unique int id: @ruby_until_modifier,
|
||||
int body: @ruby_underscore_statement ref,
|
||||
int condition: @ruby_until_modifier_condition_type ref,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
ruby_variable_reference_pattern_def(
|
||||
unique int id: @ruby_variable_reference_pattern,
|
||||
int name: @ruby_token_identifier ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -1183,12 +1332,10 @@ ruby_while_def(
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@ruby_while_modifier_condition_type = @ruby_break | @ruby_call | @ruby_next | @ruby_return | @ruby_underscore_arg | @ruby_yield
|
||||
|
||||
ruby_while_modifier_def(
|
||||
unique int id: @ruby_while_modifier,
|
||||
int body: @ruby_underscore_statement ref,
|
||||
int condition: @ruby_while_modifier_condition_type ref,
|
||||
int condition: @ruby_underscore_expression ref,
|
||||
int loc: @location ref
|
||||
);
|
||||
|
||||
@@ -1217,31 +1364,35 @@ case @ruby_token.kind of
|
||||
| 4 = @ruby_token_complex
|
||||
| 5 = @ruby_token_constant
|
||||
| 6 = @ruby_token_empty_statement
|
||||
| 7 = @ruby_token_escape_sequence
|
||||
| 8 = @ruby_token_false
|
||||
| 9 = @ruby_token_float
|
||||
| 10 = @ruby_token_forward_argument
|
||||
| 11 = @ruby_token_forward_parameter
|
||||
| 12 = @ruby_token_global_variable
|
||||
| 13 = @ruby_token_hash_key_symbol
|
||||
| 14 = @ruby_token_heredoc_beginning
|
||||
| 15 = @ruby_token_heredoc_content
|
||||
| 16 = @ruby_token_heredoc_end
|
||||
| 17 = @ruby_token_identifier
|
||||
| 18 = @ruby_token_instance_variable
|
||||
| 19 = @ruby_token_integer
|
||||
| 20 = @ruby_token_nil
|
||||
| 21 = @ruby_token_operator
|
||||
| 22 = @ruby_token_self
|
||||
| 23 = @ruby_token_simple_symbol
|
||||
| 24 = @ruby_token_string_content
|
||||
| 25 = @ruby_token_super
|
||||
| 26 = @ruby_token_true
|
||||
| 27 = @ruby_token_uninterpreted
|
||||
| 7 = @ruby_token_encoding
|
||||
| 8 = @ruby_token_escape_sequence
|
||||
| 9 = @ruby_token_false
|
||||
| 10 = @ruby_token_file
|
||||
| 11 = @ruby_token_float
|
||||
| 12 = @ruby_token_forward_argument
|
||||
| 13 = @ruby_token_forward_parameter
|
||||
| 14 = @ruby_token_global_variable
|
||||
| 15 = @ruby_token_hash_key_symbol
|
||||
| 16 = @ruby_token_hash_splat_nil
|
||||
| 17 = @ruby_token_heredoc_beginning
|
||||
| 18 = @ruby_token_heredoc_content
|
||||
| 19 = @ruby_token_heredoc_end
|
||||
| 20 = @ruby_token_identifier
|
||||
| 21 = @ruby_token_instance_variable
|
||||
| 22 = @ruby_token_integer
|
||||
| 23 = @ruby_token_line
|
||||
| 24 = @ruby_token_nil
|
||||
| 25 = @ruby_token_operator
|
||||
| 26 = @ruby_token_self
|
||||
| 27 = @ruby_token_simple_symbol
|
||||
| 28 = @ruby_token_string_content
|
||||
| 29 = @ruby_token_super
|
||||
| 30 = @ruby_token_true
|
||||
| 31 = @ruby_token_uninterpreted
|
||||
;
|
||||
|
||||
|
||||
@ruby_ast_node = @ruby_alias | @ruby_argument_list | @ruby_array | @ruby_assignment | @ruby_bare_string | @ruby_bare_symbol | @ruby_begin | @ruby_begin_block | @ruby_binary | @ruby_block | @ruby_block_argument | @ruby_block_parameter | @ruby_block_parameters | @ruby_break | @ruby_call | @ruby_case__ | @ruby_chained_string | @ruby_class | @ruby_conditional | @ruby_delimited_symbol | @ruby_destructured_left_assignment | @ruby_destructured_parameter | @ruby_do | @ruby_do_block | @ruby_element_reference | @ruby_else | @ruby_elsif | @ruby_end_block | @ruby_ensure | @ruby_exception_variable | @ruby_exceptions | @ruby_for | @ruby_hash | @ruby_hash_splat_argument | @ruby_hash_splat_parameter | @ruby_heredoc_body | @ruby_if | @ruby_if_modifier | @ruby_in | @ruby_interpolation | @ruby_keyword_parameter | @ruby_lambda | @ruby_lambda_parameters | @ruby_left_assignment_list | @ruby_method | @ruby_method_parameters | @ruby_module | @ruby_next | @ruby_operator_assignment | @ruby_optional_parameter | @ruby_pair | @ruby_parenthesized_statements | @ruby_pattern | @ruby_program | @ruby_range | @ruby_rational | @ruby_redo | @ruby_regex | @ruby_rescue | @ruby_rescue_modifier | @ruby_rest_assignment | @ruby_retry | @ruby_return | @ruby_right_assignment_list | @ruby_scope_resolution | @ruby_setter | @ruby_singleton_class | @ruby_singleton_method | @ruby_splat_argument | @ruby_splat_parameter | @ruby_string__ | @ruby_string_array | @ruby_subshell | @ruby_superclass | @ruby_symbol_array | @ruby_then | @ruby_token | @ruby_unary | @ruby_undef | @ruby_unless | @ruby_unless_modifier | @ruby_until | @ruby_until_modifier | @ruby_when | @ruby_while | @ruby_while_modifier | @ruby_yield
|
||||
@ruby_ast_node = @ruby_alias | @ruby_alternative_pattern | @ruby_argument_list | @ruby_array | @ruby_array_pattern | @ruby_as_pattern | @ruby_assignment | @ruby_bare_string | @ruby_bare_symbol | @ruby_begin | @ruby_begin_block | @ruby_binary | @ruby_block | @ruby_block_argument | @ruby_block_parameter | @ruby_block_parameters | @ruby_break | @ruby_call | @ruby_case__ | @ruby_case_match | @ruby_chained_string | @ruby_class | @ruby_conditional | @ruby_delimited_symbol | @ruby_destructured_left_assignment | @ruby_destructured_parameter | @ruby_do | @ruby_do_block | @ruby_element_reference | @ruby_else | @ruby_elsif | @ruby_end_block | @ruby_ensure | @ruby_exception_variable | @ruby_exceptions | @ruby_find_pattern | @ruby_for | @ruby_hash | @ruby_hash_pattern | @ruby_hash_splat_argument | @ruby_hash_splat_parameter | @ruby_heredoc_body | @ruby_if | @ruby_if_guard | @ruby_if_modifier | @ruby_in | @ruby_in_clause | @ruby_interpolation | @ruby_keyword_parameter | @ruby_keyword_pattern | @ruby_lambda | @ruby_lambda_parameters | @ruby_left_assignment_list | @ruby_method | @ruby_method_parameters | @ruby_module | @ruby_next | @ruby_operator_assignment | @ruby_optional_parameter | @ruby_pair | @ruby_parenthesized_statements | @ruby_pattern | @ruby_program | @ruby_range | @ruby_rational | @ruby_redo | @ruby_regex | @ruby_rescue | @ruby_rescue_modifier | @ruby_rest_assignment | @ruby_retry | @ruby_return | @ruby_right_assignment_list | @ruby_scope_resolution | @ruby_setter | @ruby_singleton_class | @ruby_singleton_method | @ruby_splat_argument | @ruby_splat_parameter | @ruby_string__ | @ruby_string_array | @ruby_subshell | @ruby_superclass | @ruby_symbol_array | @ruby_then | @ruby_token | @ruby_unary | @ruby_undef | @ruby_unless | @ruby_unless_guard | @ruby_unless_modifier | @ruby_until | @ruby_until_modifier | @ruby_variable_reference_pattern | @ruby_when | @ruby_while | @ruby_while_modifier | @ruby_yield
|
||||
|
||||
@ruby_ast_node_parent = @file | @ruby_ast_node
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
private class RubyToken extends @ruby_token {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
private class Location extends @location {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
bindingset[old]
|
||||
private int newKind(int old) {
|
||||
old in [0 .. 6] and result = old
|
||||
or
|
||||
// @ruby_token_escape_sequence
|
||||
old = 7 and result = 8
|
||||
or
|
||||
// @ruby_token_false
|
||||
old = 8 and result = 9
|
||||
or
|
||||
// @ruby_token_float
|
||||
old = 9 and result = 11
|
||||
or
|
||||
// @ruby_token_forward_argument
|
||||
old = 10 and result = 12
|
||||
or
|
||||
// @ruby_token_forward_parameter
|
||||
old = 11 and result = 13
|
||||
or
|
||||
// @ruby_token_global_variable
|
||||
old = 12 and result = 14
|
||||
or
|
||||
// @ruby_token_hash_key_symbol
|
||||
old = 13 and result = 15
|
||||
or
|
||||
// @ruby_token_heredoc_beginning
|
||||
old = 14 and result = 17
|
||||
or
|
||||
// @ruby_token_heredoc_content
|
||||
old = 15 and result = 18
|
||||
or
|
||||
// @ruby_token_heredoc_end
|
||||
old = 16 and result = 19
|
||||
or
|
||||
// @ruby_token_identifier
|
||||
old = 17 and result = 20
|
||||
or
|
||||
// @ruby_token_instance_variable
|
||||
old = 18 and result = 21
|
||||
or
|
||||
// @ruby_token_integer
|
||||
old = 19 and result = 22
|
||||
or
|
||||
// @ruby_token_nil
|
||||
old = 20 and result = 24
|
||||
or
|
||||
// @ruby_token_operator
|
||||
old = 21 and result = 25
|
||||
or
|
||||
// @ruby_token_self
|
||||
old = 22 and result = 26
|
||||
or
|
||||
// @ruby_token_simple_symbol
|
||||
old = 23 and result = 27
|
||||
or
|
||||
// @ruby_token_string_content
|
||||
old = 24 and result = 28
|
||||
or
|
||||
// @ruby_token_super
|
||||
old = 25 and result = 29
|
||||
or
|
||||
// @ruby_token_true
|
||||
old = 26 and result = 30
|
||||
or
|
||||
// @ruby_token_uninterpreted
|
||||
old = 27 and result = 31
|
||||
}
|
||||
|
||||
from RubyToken id, int kind, string value, Location loc
|
||||
where ruby_tokeninfo(id, kind, value, loc)
|
||||
select id, newKind(kind), value, loc
|
||||
@@ -0,0 +1,3 @@
|
||||
description: Re-number @ruby_token.kind
|
||||
compatibility: full
|
||||
ruby_tokeninfo.rel: run ruby_tokeninfo.qlo
|
||||
Reference in New Issue
Block a user