mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Merge pull request #9953 from aibaars/update-grammar
Update tree-sitter-ruby
This commit is contained in:
BIN
ruby/Cargo.lock
generated
BIN
ruby/Cargo.lock
generated
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
class AstNode extends @ruby_ast_node_parent {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class Location extends @location {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class Wrapper = @ruby_body_statement or @ruby_block_body;
|
||||
|
||||
predicate astNodeInfo(AstNode child, AstNode parent, int primaryIndex, int secondaryIndex) {
|
||||
not parent instanceof Wrapper and
|
||||
exists(AstNode node, Location l |
|
||||
ruby_ast_node_info(node, parent, primaryIndex, _) and
|
||||
(
|
||||
not node instanceof Wrapper and secondaryIndex = 0 and child = node
|
||||
or
|
||||
node instanceof Wrapper and ruby_ast_node_info(child, node, secondaryIndex, _)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
from AstNode node, AstNode parent, int parent_index, Location loc
|
||||
where
|
||||
node =
|
||||
rank[parent_index + 1](AstNode n, int i, int j | astNodeInfo(n, parent, i, j) | n order by i, j) and
|
||||
ruby_ast_node_info(node, _, _, loc)
|
||||
select node, parent, parent_index, loc
|
||||
@@ -0,0 +1,7 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_block, AstNode body, int index, AstNode child
|
||||
where ruby_block_body(ruby_block, body) and ruby_block_body_child(body, index, child)
|
||||
select ruby_block, index, child
|
||||
@@ -0,0 +1,7 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_class, AstNode body, int index, AstNode child
|
||||
where ruby_class_body(ruby_class, body) and ruby_body_statement_child(body, index, child)
|
||||
select ruby_class, index, child
|
||||
@@ -0,0 +1,8 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_do_block, AstNode body, int index, AstNode child
|
||||
where ruby_do_block_body(ruby_do_block, body) and ruby_body_statement_child(body, index, child)
|
||||
select ruby_do_block, index, child
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_method, int index, AstNode child
|
||||
where
|
||||
exists(AstNode body |
|
||||
ruby_method_body(ruby_method, body) and ruby_body_statement_child(body, index, child)
|
||||
)
|
||||
or
|
||||
ruby_method_body(ruby_method, child) and
|
||||
not child instanceof @ruby_body_statement and
|
||||
index = 0
|
||||
select ruby_method, index, child
|
||||
@@ -0,0 +1,8 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_module, AstNode body, int index, AstNode child
|
||||
where ruby_module_body(ruby_module, body) and ruby_body_statement_child(body, index, child)
|
||||
select ruby_module, index, child
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_singleton_class, AstNode body, int index, AstNode child
|
||||
where ruby_singleton_class_body(ruby_singleton_class, body) and ruby_body_statement_child(body, index, child)
|
||||
select ruby_singleton_class, index, child
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_singleton_method, int index, AstNode child
|
||||
where
|
||||
exists(AstNode body |
|
||||
ruby_singleton_method_body(ruby_singleton_method, body) and
|
||||
ruby_body_statement_child(body, index, child)
|
||||
)
|
||||
or
|
||||
ruby_singleton_method_body(ruby_singleton_method, child) and
|
||||
not child instanceof @ruby_body_statement and
|
||||
index = 0
|
||||
select ruby_singleton_method, index, child
|
||||
@@ -0,0 +1,30 @@
|
||||
description: Wrap class, module, method, and block bodies in a named node
|
||||
compatibility: full
|
||||
|
||||
ruby_block_body.rel: delete
|
||||
ruby_block_body_def.rel: delete
|
||||
ruby_block_body_child.rel: delete
|
||||
ruby_block_child.rel: run ruby_block_child.qlo
|
||||
|
||||
ruby_body_statement_child.rel: delete
|
||||
ruby_body_statement_def.rel: delete
|
||||
|
||||
ruby_class_body.rel: delete
|
||||
ruby_class_child.rel: run ruby_class_child.qlo
|
||||
|
||||
ruby_do_block_body.rel: delete
|
||||
ruby_do_block_child.rel: run ruby_do_block_child.qlo
|
||||
|
||||
ruby_method_body.rel: delete
|
||||
ruby_method_child.rel: run ruby_method_child.qlo
|
||||
|
||||
ruby_module_body.rel: delete
|
||||
ruby_module_child.rel: run ruby_module_child.qlo
|
||||
|
||||
ruby_singleton_class_body.rel: delete
|
||||
ruby_singleton_class_child.rel: run ruby_singleton_class_child.qlo
|
||||
|
||||
ruby_singleton_method_body.rel: delete
|
||||
ruby_singleton_method_child.rel: run ruby_singleton_method_child.qlo
|
||||
|
||||
ruby_ast_node_info.rel: run ruby_ast_node_info.qlo
|
||||
@@ -11,7 +11,7 @@ flate2 = "1.0"
|
||||
node-types = { path = "../node-types" }
|
||||
tree-sitter = "0.19"
|
||||
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template.git", rev = "1a538da253d73f896b9f6c0c7d79cda58791ac5c" }
|
||||
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "e75d04404c9dd71ad68850d5c672b226d5e694f3" }
|
||||
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "ad1043283b1f9daf4aad381b6a81f18a5a27fe7e" }
|
||||
clap = "3.0"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
|
||||
|
||||
@@ -12,4 +12,4 @@ node-types = { path = "../node-types" }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
|
||||
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template.git", rev = "1a538da253d73f896b9f6c0c7d79cda58791ac5c" }
|
||||
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "e75d04404c9dd71ad68850d5c672b226d5e694f3" }
|
||||
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "ad1043283b1f9daf4aad381b6a81f18a5a27fe7e" }
|
||||
|
||||
@@ -51,25 +51,35 @@ class Ensure extends StmtSequence, TEnsure {
|
||||
|
||||
// Not defined by dispatch, as it should not be exposed
|
||||
Ruby::AstNode getBodyStmtChild(TBodyStmt b, int i) {
|
||||
result = any(Ruby::Method g | b = TMethod(g)).getChild(i)
|
||||
or
|
||||
result = any(Ruby::SingletonMethod g | b = TSingletonMethod(g)).getChild(i)
|
||||
or
|
||||
exists(Ruby::Lambda g | b = TLambda(g) |
|
||||
result = g.getBody().(Ruby::DoBlock).getChild(i) or
|
||||
result = g.getBody().(Ruby::Block).getChild(i)
|
||||
exists(Ruby::Method g, Ruby::AstNode body | b = TMethod(g) and body = g.getBody() |
|
||||
result = body.(Ruby::BodyStatement).getChild(i)
|
||||
or
|
||||
i = 0 and result = body and not body instanceof Ruby::BodyStatement
|
||||
)
|
||||
or
|
||||
result = any(Ruby::DoBlock g | b = TDoBlock(g)).getChild(i)
|
||||
exists(Ruby::SingletonMethod g, Ruby::AstNode body |
|
||||
b = TSingletonMethod(g) and body = g.getBody()
|
||||
|
|
||||
result = body.(Ruby::BodyStatement).getChild(i)
|
||||
or
|
||||
i = 0 and result = body and not body instanceof Ruby::BodyStatement
|
||||
)
|
||||
or
|
||||
exists(Ruby::Lambda g | b = TLambda(g) |
|
||||
result = g.getBody().(Ruby::DoBlock).getBody().getChild(i) or
|
||||
result = g.getBody().(Ruby::Block).getBody().getChild(i)
|
||||
)
|
||||
or
|
||||
result = any(Ruby::DoBlock g | b = TDoBlock(g)).getBody().getChild(i)
|
||||
or
|
||||
result = any(Ruby::Program g | b = TToplevel(g)).getChild(i) and
|
||||
not result instanceof Ruby::BeginBlock
|
||||
or
|
||||
result = any(Ruby::Class g | b = TClassDeclaration(g)).getChild(i)
|
||||
result = any(Ruby::Class g | b = TClassDeclaration(g)).getBody().getChild(i)
|
||||
or
|
||||
result = any(Ruby::SingletonClass g | b = TSingletonClass(g)).getChild(i)
|
||||
result = any(Ruby::SingletonClass g | b = TSingletonClass(g)).getBody().getChild(i)
|
||||
or
|
||||
result = any(Ruby::Module g | b = TModuleDeclaration(g)).getChild(i)
|
||||
result = any(Ruby::Module g | b = TModuleDeclaration(g)).getBody().getChild(i)
|
||||
or
|
||||
result = any(Ruby::Begin g | b = TBeginExpr(g)).getChild(i)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class BraceBlockReal extends BraceBlock, TBraceBlockReal {
|
||||
toGenerated(result) = g.getParameters().getChild(n)
|
||||
}
|
||||
|
||||
final override Stmt getStmt(int i) { toGenerated(result) = g.getChild(i) }
|
||||
final override Stmt getStmt(int i) { toGenerated(result) = g.getBody().getChild(i) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -311,15 +311,15 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Block" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final BlockBody getBody() { ruby_block_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `parameters`. */
|
||||
final BlockParameters getParameters() { ruby_block_parameters(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_block_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_block_parameters(this, result) or ruby_block_child(this, _, result)
|
||||
ruby_block_body(this, result) or ruby_block_parameters(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +335,18 @@ module Ruby {
|
||||
final override AstNode getAFieldOrChild() { ruby_block_argument_child(this, result) }
|
||||
}
|
||||
|
||||
/** A class representing `block_body` nodes. */
|
||||
class BlockBody extends @ruby_block_body, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "BlockBody" }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_block_body_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() { ruby_block_body_child(this, _, result) }
|
||||
}
|
||||
|
||||
/** A class representing `block_parameter` nodes. */
|
||||
class BlockParameter extends @ruby_block_parameter, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -364,6 +376,18 @@ module Ruby {
|
||||
}
|
||||
}
|
||||
|
||||
/** A class representing `body_statement` nodes. */
|
||||
class BodyStatement extends @ruby_body_statement, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "BodyStatement" }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_body_statement_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() { ruby_body_statement_child(this, _, result) }
|
||||
}
|
||||
|
||||
/** A class representing `break` nodes. */
|
||||
class Break extends @ruby_break, AstNode {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
@@ -468,20 +492,20 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Class" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final BodyStatement getBody() { ruby_class_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
final AstNode getName() { ruby_class_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `superclass`. */
|
||||
final Superclass getSuperclass() { ruby_class_superclass(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_class_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_class_body(this, result) or
|
||||
ruby_class_def(this, result) or
|
||||
ruby_class_superclass(this, result) or
|
||||
ruby_class_child(this, _, result)
|
||||
ruby_class_superclass(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,15 +616,15 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "DoBlock" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final BodyStatement getBody() { ruby_do_block_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `parameters`. */
|
||||
final BlockParameters getParameters() { ruby_do_block_parameters(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_do_block_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_do_block_parameters(this, result) or ruby_do_block_child(this, _, result)
|
||||
ruby_do_block_body(this, result) or ruby_do_block_parameters(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1106,20 +1130,20 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Method" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final AstNode getBody() { ruby_method_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
final UnderscoreMethodName getName() { ruby_method_def(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `parameters`. */
|
||||
final MethodParameters getParameters() { ruby_method_parameters(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_method_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_method_body(this, result) or
|
||||
ruby_method_def(this, result) or
|
||||
ruby_method_parameters(this, result) or
|
||||
ruby_method_child(this, _, result)
|
||||
ruby_method_parameters(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,15 +1164,15 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Module" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final BodyStatement getBody() { ruby_module_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
final AstNode getName() { ruby_module_def(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_module_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_module_def(this, result) or ruby_module_child(this, _, result)
|
||||
ruby_module_body(this, result) or ruby_module_def(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1504,15 +1528,15 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "SingletonClass" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final BodyStatement getBody() { ruby_singleton_class_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `value`. */
|
||||
final UnderscoreArg getValue() { ruby_singleton_class_def(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_singleton_class_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_singleton_class_def(this, result) or ruby_singleton_class_child(this, _, result)
|
||||
ruby_singleton_class_body(this, result) or ruby_singleton_class_def(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1521,6 +1545,9 @@ module Ruby {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "SingletonMethod" }
|
||||
|
||||
/** Gets the node corresponding to the field `body`. */
|
||||
final AstNode getBody() { ruby_singleton_method_body(this, result) }
|
||||
|
||||
/** Gets the node corresponding to the field `name`. */
|
||||
final UnderscoreMethodName getName() { ruby_singleton_method_def(this, result, _) }
|
||||
|
||||
@@ -1530,15 +1557,12 @@ module Ruby {
|
||||
/** Gets the node corresponding to the field `parameters`. */
|
||||
final MethodParameters getParameters() { ruby_singleton_method_parameters(this, result) }
|
||||
|
||||
/** Gets the `i`th child of this node. */
|
||||
final AstNode getChild(int i) { ruby_singleton_method_child(this, i, result) }
|
||||
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() {
|
||||
ruby_singleton_method_body(this, result) or
|
||||
ruby_singleton_method_def(this, result, _) or
|
||||
ruby_singleton_method_def(this, _, result) or
|
||||
ruby_singleton_method_parameters(this, result) or
|
||||
ruby_singleton_method_child(this, _, result)
|
||||
ruby_singleton_method_parameters(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,18 +200,18 @@ private module Cached {
|
||||
or
|
||||
i = any(Ruby::Binary x).getRight()
|
||||
or
|
||||
i = any(Ruby::Block x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::BlockArgument x).getChild()
|
||||
or
|
||||
i = any(Ruby::BlockBody x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::BodyStatement x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::Call x).getReceiver()
|
||||
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()
|
||||
or
|
||||
i = any(Ruby::Conditional x).getConsequence()
|
||||
@@ -220,8 +220,6 @@ private module Cached {
|
||||
or
|
||||
i = any(Ruby::Do x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::DoBlock x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::ElementReference x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::ElementReference x).getObject()
|
||||
@@ -250,9 +248,7 @@ private module Cached {
|
||||
or
|
||||
i = any(Ruby::KeywordParameter x).getValue()
|
||||
or
|
||||
i = any(Ruby::Method x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::Module x).getChild(_)
|
||||
i = any(Ruby::Method x).getBody()
|
||||
or
|
||||
i = any(Ruby::OperatorAssignment x).getRight()
|
||||
or
|
||||
@@ -282,9 +278,7 @@ private module Cached {
|
||||
or
|
||||
i = any(Ruby::SingletonClass x).getValue()
|
||||
or
|
||||
i = any(Ruby::SingletonClass x).getChild(_)
|
||||
or
|
||||
i = any(Ruby::SingletonMethod x).getChild(_)
|
||||
i = any(Ruby::SingletonMethod x).getBody()
|
||||
or
|
||||
i = any(Ruby::SingletonMethod x).getObject()
|
||||
or
|
||||
|
||||
@@ -247,20 +247,16 @@ ruby_binary_def(
|
||||
int right: @ruby_underscore_expression ref
|
||||
);
|
||||
|
||||
ruby_block_body(
|
||||
unique int ruby_block: @ruby_block ref,
|
||||
unique int body: @ruby_block_body ref
|
||||
);
|
||||
|
||||
ruby_block_parameters(
|
||||
unique int ruby_block: @ruby_block ref,
|
||||
unique int parameters: @ruby_block_parameters ref
|
||||
);
|
||||
|
||||
@ruby_block_child_type = @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_block, index]
|
||||
ruby_block_child(
|
||||
int ruby_block: @ruby_block ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_block_child_type ref
|
||||
);
|
||||
|
||||
ruby_block_def(
|
||||
unique int id: @ruby_block
|
||||
);
|
||||
@@ -274,6 +270,19 @@ ruby_block_argument_def(
|
||||
unique int id: @ruby_block_argument
|
||||
);
|
||||
|
||||
@ruby_block_body_child_type = @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_block_body, index]
|
||||
ruby_block_body_child(
|
||||
int ruby_block_body: @ruby_block_body ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_block_body_child_type ref
|
||||
);
|
||||
|
||||
ruby_block_body_def(
|
||||
unique int id: @ruby_block_body
|
||||
);
|
||||
|
||||
ruby_block_parameter_name(
|
||||
unique int ruby_block_parameter: @ruby_block_parameter ref,
|
||||
unique int name: @ruby_token_identifier ref
|
||||
@@ -303,6 +312,19 @@ ruby_block_parameters_def(
|
||||
unique int id: @ruby_block_parameters
|
||||
);
|
||||
|
||||
@ruby_body_statement_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_body_statement, index]
|
||||
ruby_body_statement_child(
|
||||
int ruby_body_statement: @ruby_body_statement ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_body_statement_child_type ref
|
||||
);
|
||||
|
||||
ruby_body_statement_def(
|
||||
unique int id: @ruby_body_statement
|
||||
);
|
||||
|
||||
ruby_break_child(
|
||||
unique int ruby_break: @ruby_break ref,
|
||||
unique int child: @ruby_argument_list ref
|
||||
@@ -391,6 +413,11 @@ ruby_chained_string_def(
|
||||
unique int id: @ruby_chained_string
|
||||
);
|
||||
|
||||
ruby_class_body(
|
||||
unique int ruby_class: @ruby_class ref,
|
||||
unique int body: @ruby_body_statement ref
|
||||
);
|
||||
|
||||
@ruby_class_name_type = @ruby_scope_resolution | @ruby_token_constant
|
||||
|
||||
ruby_class_superclass(
|
||||
@@ -398,15 +425,6 @@ ruby_class_superclass(
|
||||
unique int superclass: @ruby_superclass ref
|
||||
);
|
||||
|
||||
@ruby_class_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_class, index]
|
||||
ruby_class_child(
|
||||
int ruby_class: @ruby_class ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_class_child_type ref
|
||||
);
|
||||
|
||||
ruby_class_def(
|
||||
unique int id: @ruby_class,
|
||||
int name: @ruby_class_name_type ref
|
||||
@@ -478,20 +496,16 @@ ruby_do_def(
|
||||
unique int id: @ruby_do
|
||||
);
|
||||
|
||||
ruby_do_block_body(
|
||||
unique int ruby_do_block: @ruby_do_block ref,
|
||||
unique int body: @ruby_body_statement ref
|
||||
);
|
||||
|
||||
ruby_do_block_parameters(
|
||||
unique int ruby_do_block: @ruby_do_block ref,
|
||||
unique int parameters: @ruby_block_parameters ref
|
||||
);
|
||||
|
||||
@ruby_do_block_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_do_block, index]
|
||||
ruby_do_block_child(
|
||||
int ruby_do_block: @ruby_do_block ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_do_block_child_type ref
|
||||
);
|
||||
|
||||
ruby_do_block_def(
|
||||
unique int id: @ruby_do_block
|
||||
);
|
||||
@@ -724,7 +738,7 @@ ruby_in_clause_def(
|
||||
int pattern: @ruby_underscore_pattern_top_expr_body ref
|
||||
);
|
||||
|
||||
@ruby_interpolation_child_type = @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
@ruby_interpolation_child_type = @ruby_token_empty_statement | @ruby_underscore_nonlocal_variable | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_interpolation, index]
|
||||
ruby_interpolation_child(
|
||||
@@ -797,20 +811,18 @@ ruby_left_assignment_list_def(
|
||||
unique int id: @ruby_left_assignment_list
|
||||
);
|
||||
|
||||
@ruby_method_body_type = @ruby_body_statement | @ruby_rescue_modifier | @ruby_underscore_arg
|
||||
|
||||
ruby_method_body(
|
||||
unique int ruby_method: @ruby_method ref,
|
||||
unique int body: @ruby_method_body_type ref
|
||||
);
|
||||
|
||||
ruby_method_parameters(
|
||||
unique int ruby_method: @ruby_method ref,
|
||||
unique int parameters: @ruby_method_parameters ref
|
||||
);
|
||||
|
||||
@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(
|
||||
int ruby_method: @ruby_method ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_method_child_type ref
|
||||
);
|
||||
|
||||
ruby_method_def(
|
||||
unique int id: @ruby_method,
|
||||
int name: @ruby_underscore_method_name ref
|
||||
@@ -829,17 +841,13 @@ ruby_method_parameters_def(
|
||||
unique int id: @ruby_method_parameters
|
||||
);
|
||||
|
||||
@ruby_module_name_type = @ruby_scope_resolution | @ruby_token_constant
|
||||
|
||||
@ruby_module_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_module, index]
|
||||
ruby_module_child(
|
||||
int ruby_module: @ruby_module ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_module_child_type ref
|
||||
ruby_module_body(
|
||||
unique int ruby_module: @ruby_module ref,
|
||||
unique int body: @ruby_body_statement ref
|
||||
);
|
||||
|
||||
@ruby_module_name_type = @ruby_scope_resolution | @ruby_token_constant
|
||||
|
||||
ruby_module_def(
|
||||
unique int id: @ruby_module,
|
||||
int name: @ruby_module_name_type ref
|
||||
@@ -1074,13 +1082,9 @@ ruby_setter_def(
|
||||
int name: @ruby_token_identifier ref
|
||||
);
|
||||
|
||||
@ruby_singleton_class_child_type = @ruby_else | @ruby_ensure | @ruby_rescue | @ruby_token_empty_statement | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_singleton_class, index]
|
||||
ruby_singleton_class_child(
|
||||
int ruby_singleton_class: @ruby_singleton_class ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_singleton_class_child_type ref
|
||||
ruby_singleton_class_body(
|
||||
unique int ruby_singleton_class: @ruby_singleton_class ref,
|
||||
unique int body: @ruby_body_statement ref
|
||||
);
|
||||
|
||||
ruby_singleton_class_def(
|
||||
@@ -1088,6 +1092,13 @@ ruby_singleton_class_def(
|
||||
int value: @ruby_underscore_arg ref
|
||||
);
|
||||
|
||||
@ruby_singleton_method_body_type = @ruby_body_statement | @ruby_rescue_modifier | @ruby_underscore_arg
|
||||
|
||||
ruby_singleton_method_body(
|
||||
unique int ruby_singleton_method: @ruby_singleton_method ref,
|
||||
unique int body: @ruby_singleton_method_body_type ref
|
||||
);
|
||||
|
||||
@ruby_singleton_method_object_type = @ruby_underscore_arg | @ruby_underscore_variable
|
||||
|
||||
ruby_singleton_method_parameters(
|
||||
@@ -1095,15 +1106,6 @@ 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_arg | @ruby_underscore_statement
|
||||
|
||||
#keyset[ruby_singleton_method, index]
|
||||
ruby_singleton_method_child(
|
||||
int ruby_singleton_method: @ruby_singleton_method ref,
|
||||
int index: int ref,
|
||||
unique int child: @ruby_singleton_method_child_type ref
|
||||
);
|
||||
|
||||
ruby_singleton_method_def(
|
||||
unique int id: @ruby_singleton_method,
|
||||
int name: @ruby_underscore_method_name ref,
|
||||
@@ -1344,7 +1346,7 @@ case @ruby_token.kind of
|
||||
;
|
||||
|
||||
|
||||
@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_complex | @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_expression_reference_pattern | @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_pattern | @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 = @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_body | @ruby_block_parameter | @ruby_block_parameters | @ruby_body_statement | @ruby_break | @ruby_call | @ruby_case__ | @ruby_case_match | @ruby_chained_string | @ruby_class | @ruby_complex | @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_expression_reference_pattern | @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_pattern | @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
@@ -0,0 +1,68 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class Location extends @location {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class File extends @file {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
private predicate body_statement(AstNode body, int index, Location loc) {
|
||||
exists(AstNode node, AstNode child | ruby_ast_node_info(child, _, _, loc) |
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, index, child)
|
||||
or
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, index, child)
|
||||
or
|
||||
ruby_method_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, index, child)
|
||||
or
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, index, child)
|
||||
or
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, index, child)
|
||||
or
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, index, child)
|
||||
or
|
||||
ruby_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(node, index, child)
|
||||
)
|
||||
}
|
||||
|
||||
from Location loc, File file, int start_line, int start_column, int end_line, int end_column
|
||||
where
|
||||
locations_default(loc, file, start_line, start_column, end_line, end_column) and
|
||||
not exists(AstNode node | ruby_ast_node_info(node, _, _, loc) and body_statement(node, _, _))
|
||||
or
|
||||
exists(AstNode node |
|
||||
ruby_ast_node_info(node, _, _, loc) and
|
||||
exists(Location first |
|
||||
body_statement(node, 0, first) and
|
||||
locations_default(first, file, start_line, start_column, _, _)
|
||||
) and
|
||||
exists(Location last |
|
||||
last = max(Location l, int i | body_statement(node, i, l) | l order by i) and
|
||||
locations_default(last, file, _, _, end_line, end_column)
|
||||
)
|
||||
)
|
||||
select loc, file, start_line, start_column, end_line, end_column
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
class AstNode extends @ruby_ast_node_parent {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class Location extends @location {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
private predicate body_statement(AstNode body, AstNode firstChild) {
|
||||
exists(AstNode node |
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_method_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, 0, firstChild)
|
||||
or
|
||||
ruby_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(node, 0, firstChild)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate body_statement_child(AstNode body, int index, AstNode child) {
|
||||
exists(AstNode parent, AstNode firstChild, int firstChildIndex |
|
||||
body_statement(body, firstChild) and
|
||||
ruby_ast_node_info(firstChild, parent, firstChildIndex, _) and
|
||||
child =
|
||||
rank[index + 1](AstNode c, int i |
|
||||
ruby_ast_node_info(c, parent, i, _) and i >= firstChildIndex and c != body
|
||||
|
|
||||
c order by i
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate astNodeInfo(AstNode node, AstNode parent, int parent_index, Location loc) {
|
||||
ruby_ast_node_info(node, parent, parent_index, loc) and
|
||||
not body_statement(node, _) and
|
||||
not body_statement_child(_, _, node)
|
||||
}
|
||||
|
||||
from AstNode node, AstNode parent, int parent_index, Location loc
|
||||
where
|
||||
astNodeInfo(node, parent, parent_index, loc)
|
||||
or
|
||||
body_statement_child(parent, parent_index, node) and ruby_ast_node_info(node, _, _, loc)
|
||||
or
|
||||
body_statement(node, _) and
|
||||
ruby_ast_node_info(node, parent, _, loc) and
|
||||
parent_index = count(AstNode n | astNodeInfo(n, parent, _, _))
|
||||
select node, parent, parent_index, loc
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_block, AstNode body
|
||||
where
|
||||
ruby_block_def(ruby_block) and
|
||||
ruby_ast_node_info(body, ruby_block, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(ruby_block, _, _)
|
||||
select ruby_block, body
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode ruby_block, AstNode body, int index, AstNode child
|
||||
where
|
||||
ruby_block_def(ruby_block) and
|
||||
ruby_ast_node_info(body, ruby_block, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(ruby_block, index, child)
|
||||
select body, index, child
|
||||
@@ -0,0 +1,18 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
/*
|
||||
* It's not possible to generate fresh IDs for the new ruby_block_body nodes,
|
||||
* therefore we re-purpose the "}"-token that closes the block and use its ID instead.
|
||||
* As a result the AST will be missing the "}" tokens, but those are unlikely to be used
|
||||
* for anything.
|
||||
*/
|
||||
|
||||
from AstNode ruby_block, AstNode body
|
||||
where
|
||||
ruby_block_def(ruby_block) and
|
||||
ruby_ast_node_info(body, ruby_block, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(ruby_block, _, _)
|
||||
select body
|
||||
@@ -0,0 +1,36 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body, int index, AstNode child
|
||||
where
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, index, child)
|
||||
or
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, index, child)
|
||||
or
|
||||
ruby_method_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, index, child)
|
||||
or
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, index, child)
|
||||
or
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, index, child)
|
||||
or
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, index, child)
|
||||
select body, index, child
|
||||
@@ -0,0 +1,43 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
/*
|
||||
* It's not possible to generate fresh IDs for the new ruby_body_statement nodes,
|
||||
* therefore we re-purpose the "end"-token that closes the block and use its ID instead.
|
||||
* As a result the AST will be missing the "end" tokens, but those are unlikely to be used
|
||||
* for anything.
|
||||
*/
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, _, _)
|
||||
or
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, _, _)
|
||||
or
|
||||
ruby_method_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, _, _)
|
||||
or
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, _, _)
|
||||
or
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, _, _)
|
||||
or
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, _, _)
|
||||
select body
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, _, _)
|
||||
select node, body
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, _, _)
|
||||
select node, body
|
||||
@@ -0,0 +1,20 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_method_def(node, _) and
|
||||
(
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, _, _)
|
||||
or
|
||||
ruby_method_child(node, 0, body) and
|
||||
not exists(AstNode n |
|
||||
ruby_ast_node_info(n, node, _, _) and
|
||||
ruby_tokeninfo(n, _, "end")
|
||||
)
|
||||
)
|
||||
// TODO : handle end-less methods
|
||||
select node, body
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, _, _)
|
||||
select node, body
|
||||
@@ -0,0 +1,11 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, _, _)
|
||||
select node, body
|
||||
@@ -0,0 +1,17 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
from AstNode node, AstNode body
|
||||
where
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, _, _)
|
||||
or
|
||||
ruby_singleton_method_child(node, 0, body) and
|
||||
not exists(AstNode n |
|
||||
ruby_ast_node_info(n, node, _, _) and
|
||||
ruby_tokeninfo(n, _, "end")
|
||||
)
|
||||
select node, body
|
||||
@@ -0,0 +1,46 @@
|
||||
class AstNode extends @ruby_ast_node {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
private predicate body_statement(AstNode body) {
|
||||
exists(AstNode node |
|
||||
ruby_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_class_child(node, _, _)
|
||||
or
|
||||
ruby_do_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_do_block_child(node, _, _)
|
||||
or
|
||||
ruby_method_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_method_child(node, _, _)
|
||||
or
|
||||
ruby_module_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_module_child(node, _, _)
|
||||
or
|
||||
ruby_singleton_class_def(node, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_class_child(node, _, _)
|
||||
or
|
||||
ruby_singleton_method_def(node, _, _) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "end") and
|
||||
ruby_singleton_method_child(node, _, _)
|
||||
or
|
||||
ruby_block_def(node) and
|
||||
ruby_ast_node_info(body, node, _, _) and
|
||||
ruby_tokeninfo(body, _, "}") and
|
||||
ruby_block_child(node, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
from AstNode token, int kind, string value
|
||||
where ruby_tokeninfo(token, kind, value) and not body_statement(token)
|
||||
select token, kind, value
|
||||
@@ -0,0 +1,33 @@
|
||||
description: Wrap class, module, method, and block bodies in a named node
|
||||
compatibility: partial
|
||||
|
||||
ruby_block_body.rel: run ruby_block_body.qlo
|
||||
ruby_block_body_def.rel: run ruby_block_body_def.qlo
|
||||
ruby_block_body_child.rel: run ruby_block_body_child.qlo
|
||||
ruby_block_child.rel: delete
|
||||
|
||||
ruby_body_statement_child.rel: run ruby_body_statement_child.qlo
|
||||
ruby_body_statement_def.rel: run ruby_body_statement_def.qlo
|
||||
|
||||
ruby_class_body.rel: run ruby_class_body.qlo
|
||||
ruby_class_child.rel: delete
|
||||
|
||||
ruby_do_block_body.rel: run ruby_do_block_body.qlo
|
||||
ruby_do_block_child.rel: delete
|
||||
|
||||
ruby_method_body.rel: run ruby_method_body.qlo
|
||||
ruby_method_child.rel: delete
|
||||
|
||||
ruby_module_body.rel: run ruby_module_body.qlo
|
||||
ruby_module_child.rel: delete
|
||||
|
||||
ruby_singleton_class_body.rel: run ruby_singleton_class_body.qlo
|
||||
ruby_singleton_class_child.rel: delete
|
||||
|
||||
ruby_singleton_method_body.rel: run ruby_singleton_method_body.qlo
|
||||
ruby_singleton_method_child.rel: delete
|
||||
|
||||
ruby_ast_node_info.rel: run ruby_ast_node_info.qlo
|
||||
ruby_tokeninfo.rel: run ruby_tokeninfo.qlo
|
||||
|
||||
locations_default.rel: run locations_default.qlo
|
||||
@@ -2260,12 +2260,8 @@ literals/literals.rb:
|
||||
# 189| getAnOperand/getLeftOperand: [LocalVariableAccess] query
|
||||
# 189| getAnOperand/getRightOperand: [HereDoc] <<'DOC'
|
||||
# 189| getComponent: [StringTextComponent]
|
||||
# 189| text without
|
||||
# 190| getComponent: [StringInterpolationComponent] #{...}
|
||||
# 190| getStmt: [MethodCall] call to interpolation
|
||||
# 190| getReceiver: [SelfVariableAccess] self
|
||||
# 190| getComponent: [StringTextComponent] !
|
||||
# 190|
|
||||
# 189| text without #{ interpolation } !
|
||||
# 189|
|
||||
# 193| getStmt: [AssignExpr] ... = ...
|
||||
# 193| getAnOperand/getLeftOperand: [LocalVariableAccess] output
|
||||
# 193| getAnOperand/getRightOperand: [HereDoc] <<`SCRIPT`
|
||||
@@ -2293,6 +2289,17 @@ literals/literals.rb:
|
||||
# 199| getKey: [SymbolLiteral] :Z
|
||||
# 199| getComponent: [StringTextComponent] Z
|
||||
# 199| getValue: [ConstantReadAccess] Z
|
||||
# 201| getStmt: [StringLiteral] "@foo: #{...} @@bar: #{...} $_..."
|
||||
# 201| getComponent: [StringTextComponent] @foo:
|
||||
# 201| getComponent: [StringInterpolationComponent] #{...}
|
||||
# 201| getStmt: [InstanceVariableAccess] @foo
|
||||
# 201| getReceiver: [SelfVariableAccess] self
|
||||
# 201| getComponent: [StringTextComponent] @@bar:
|
||||
# 201| getComponent: [StringInterpolationComponent] #{...}
|
||||
# 201| getStmt: [ClassVariableAccess] @@bar
|
||||
# 201| getComponent: [StringTextComponent] $_:
|
||||
# 201| getComponent: [StringInterpolationComponent] #{...}
|
||||
# 201| getStmt: [GlobalVariableAccess] $_
|
||||
control/loops.rb:
|
||||
# 1| [Toplevel] loops.rb
|
||||
# 2| getStmt: [AssignExpr] ... = ...
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -709,6 +709,7 @@ exprValue
|
||||
| literals/literals.rb:168:9:168:13 | <<SQL | \nselect * from table\n | string |
|
||||
| literals/literals.rb:175:11:175:16 | <<-BLA | \nsome text\nand some more\n | string |
|
||||
| literals/literals.rb:180:9:180:19 | <<~SQUIGGLY | \n indented stuff\n | string |
|
||||
| literals/literals.rb:189:9:189:15 | <<'DOC' | \n text without #{ interpolation } !\n | string |
|
||||
| literals/literals.rb:193:10:193:19 | <<`SCRIPT` | \n cat file.txt\n | string |
|
||||
| literals/literals.rb:197:5:197:6 | 42 | 42 | int |
|
||||
| literals/literals.rb:198:2:198:2 | :x | :x | symbol |
|
||||
@@ -1585,6 +1586,7 @@ exprCfgNodeValue
|
||||
| literals/literals.rb:168:9:168:13 | <<SQL | \nselect * from table\n | string |
|
||||
| literals/literals.rb:175:11:175:16 | <<-BLA | \nsome text\nand some more\n | string |
|
||||
| literals/literals.rb:180:9:180:19 | <<~SQUIGGLY | \n indented stuff\n | string |
|
||||
| literals/literals.rb:189:9:189:15 | <<'DOC' | \n text without #{ interpolation } !\n | string |
|
||||
| literals/literals.rb:193:10:193:19 | <<`SCRIPT` | \n cat file.txt\n | string |
|
||||
| literals/literals.rb:197:5:197:6 | 42 | 42 | int |
|
||||
| literals/literals.rb:198:2:198:2 | :x | :x | symbol |
|
||||
|
||||
@@ -227,7 +227,7 @@ allLiterals
|
||||
| literals.rb:175:11:175:16 | <<-BLA | HereDoc | \nsome text\nand some more\n |
|
||||
| literals.rb:180:9:180:19 | <<~SQUIGGLY | HereDoc | \n indented stuff\n |
|
||||
| literals.rb:184:9:184:15 | <<"DOC" | HereDoc | <none> |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | <none> |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | \n text without #{ interpolation } !\n |
|
||||
| literals.rb:193:10:193:19 | <<`SCRIPT` | HereDoc | \n cat file.txt\n |
|
||||
| literals.rb:197:5:197:6 | 42 | IntegerLiteral | 42 |
|
||||
| literals.rb:198:1:198:9 | {...} | HashLiteral | <none> |
|
||||
@@ -237,6 +237,7 @@ allLiterals
|
||||
| literals.rb:199:1:199:9 | {...} | HashLiteral | <none> |
|
||||
| literals.rb:199:2:199:2 | :y | SymbolLiteral | :y |
|
||||
| literals.rb:199:7:199:7 | :Z | SymbolLiteral | :Z |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | <none> |
|
||||
stringlikeLiterals
|
||||
| literals.rb:59:1:59:2 | "" | |
|
||||
| literals.rb:60:1:60:2 | "" | |
|
||||
@@ -345,12 +346,13 @@ stringlikeLiterals
|
||||
| literals.rb:175:11:175:16 | <<-BLA | \nsome text\nand some more\n |
|
||||
| literals.rb:180:9:180:19 | <<~SQUIGGLY | \n indented stuff\n |
|
||||
| literals.rb:184:9:184:15 | <<"DOC" | <none> |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | <none> |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | \n text without #{ interpolation } !\n |
|
||||
| literals.rb:193:10:193:19 | <<`SCRIPT` | \n cat file.txt\n |
|
||||
| literals.rb:198:2:198:2 | :x | :x |
|
||||
| literals.rb:198:6:198:6 | :y | :y |
|
||||
| literals.rb:199:2:199:2 | :y | :y |
|
||||
| literals.rb:199:7:199:7 | :Z | :Z |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | <none> |
|
||||
stringLiterals
|
||||
| literals.rb:59:1:59:2 | "" | |
|
||||
| literals.rb:60:1:60:2 | "" | |
|
||||
@@ -405,6 +407,7 @@ stringLiterals
|
||||
| literals.rb:163:1:163:34 | "abcdefghijklmnopqrstuvwxyzabcdef" | abcdefghijklmnopqrstuvwxyzabcdef |
|
||||
| literals.rb:164:1:164:35 | "foobarfoobarfoobarfoobarfooba..." | foobarfoobarfoobarfoobarfoobarfoo |
|
||||
| literals.rb:165:1:165:40 | "foobar\\\\foobar\\\\foobar\\\\fooba..." | foobar\\foobar\\foobar\\foobar\\foobar |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | <none> |
|
||||
regExpLiterals
|
||||
| literals.rb:149:1:149:2 | // | | |
|
||||
| literals.rb:150:1:150:5 | /foo/ | foo | |
|
||||
@@ -626,14 +629,18 @@ stringComponents
|
||||
| literals.rb:184:9:184:15 | <<"DOC" | HereDoc | 0 | literals.rb:184:16:185:11 | \n text with | StringTextComponent |
|
||||
| literals.rb:184:9:184:15 | <<"DOC" | HereDoc | 1 | literals.rb:185:12:185:29 | #{...} | StringInterpolationComponent |
|
||||
| literals.rb:184:9:184:15 | <<"DOC" | HereDoc | 2 | literals.rb:185:30:185:32 | !\n | StringTextComponent |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | 0 | literals.rb:189:16:190:14 | \n text without | StringTextComponent |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | 1 | literals.rb:190:15:190:32 | #{...} | StringInterpolationComponent |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | 2 | literals.rb:190:33:190:35 | !\n | StringTextComponent |
|
||||
| literals.rb:189:9:189:15 | <<'DOC' | HereDoc | 0 | literals.rb:189:16:190:35 | \n text without #{ interpolation } !\n | StringTextComponent |
|
||||
| literals.rb:193:10:193:19 | <<`SCRIPT` | HereDoc | 0 | literals.rb:193:20:194:14 | \n cat file.txt\n | StringTextComponent |
|
||||
| literals.rb:198:2:198:2 | :x | SymbolLiteral | 0 | literals.rb:198:2:198:2 | x | StringTextComponent |
|
||||
| literals.rb:198:6:198:6 | :y | SymbolLiteral | 0 | literals.rb:198:6:198:6 | y | StringTextComponent |
|
||||
| literals.rb:199:2:199:2 | :y | SymbolLiteral | 0 | literals.rb:199:2:199:2 | y | StringTextComponent |
|
||||
| literals.rb:199:7:199:7 | :Z | SymbolLiteral | 0 | literals.rb:199:7:199:7 | Z | StringTextComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 0 | literals.rb:201:2:201:7 | @foo: | StringTextComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 1 | literals.rb:201:8:201:12 | #{...} | StringInterpolationComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 2 | literals.rb:201:13:201:20 | @@bar: | StringTextComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 3 | literals.rb:201:21:201:26 | #{...} | StringInterpolationComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 4 | literals.rb:201:27:201:31 | $_: | StringTextComponent |
|
||||
| literals.rb:201:1:201:35 | "@foo: #{...} @@bar: #{...} $_..." | StringLiteral | 5 | literals.rb:201:32:201:34 | #{...} | StringInterpolationComponent |
|
||||
stringInterpolations
|
||||
| literals.rb:71:10:71:19 | #{...} | 0 | literals.rb:71:13:71:17 | ... + ... | AddExpr |
|
||||
| literals.rb:72:12:72:21 | #{...} | 0 | literals.rb:72:15:72:19 | ... + ... | AddExpr |
|
||||
@@ -659,7 +666,9 @@ stringInterpolations
|
||||
| literals.rb:146:10:146:19 | #{...} | 0 | literals.rb:146:13:146:17 | ... - ... | SubExpr |
|
||||
| literals.rb:171:14:171:22 | #{...} | 0 | literals.rb:171:17:171:20 | call to name | MethodCall |
|
||||
| literals.rb:185:12:185:29 | #{...} | 0 | literals.rb:185:15:185:27 | call to interpolation | MethodCall |
|
||||
| literals.rb:190:15:190:32 | #{...} | 0 | literals.rb:190:18:190:30 | call to interpolation | MethodCall |
|
||||
| literals.rb:201:8:201:12 | #{...} | 0 | literals.rb:201:9:201:12 | @foo | InstanceVariableAccess |
|
||||
| literals.rb:201:21:201:26 | #{...} | 0 | literals.rb:201:22:201:26 | @@bar | ClassVariableAccess |
|
||||
| literals.rb:201:32:201:34 | #{...} | 0 | literals.rb:201:33:201:34 | $_ | GlobalVariableAccess |
|
||||
concatenatedStrings
|
||||
| literals.rb:75:1:75:17 | "..." "..." | foobarbaz | 0 | literals.rb:75:1:75:5 | "foo" |
|
||||
| literals.rb:75:1:75:17 | "..." "..." | foobarbaz | 1 | literals.rb:75:7:75:11 | "bar" |
|
||||
|
||||
@@ -196,4 +196,6 @@ SCRIPT
|
||||
|
||||
x = 42
|
||||
{x:, y:5}
|
||||
{y: , Z:}
|
||||
{y: , Z:}
|
||||
|
||||
"@foo: #@foo @@bar: #@@bar $_: #$_"
|
||||
Reference in New Issue
Block a user