Merge pull request #15966 from hvitved/treesitter-split-up-node-info-table

Tree-sitter: Split up `ast_node_info` table into two tables
This commit is contained in:
Tom Hvitved
2024-03-20 20:38:18 +01:00
committed by GitHub
25 changed files with 15100 additions and 9245 deletions

View File

@@ -0,0 +1,44 @@
class TAstNodeParent = @file or @erb_ast_node;
abstract class AstNodeParent extends TAstNodeParent {
string toString() { none() }
}
class AstNode extends AstNodeParent, @erb_ast_node { }
class File extends AstNodeParent, @file { }
class Location extends @location_default {
string toString() { none() }
}
pragma[nomagic]
predicate hasFileParent(
AstNode n, File f, int startline, int startcolumn, int endline, int endcolumn
) {
exists(Location loc |
not erb_ast_node_parent(n, _, _) and
erb_ast_node_location(n, loc) and
locations_default(loc, f, startline, startcolumn, endline, endcolumn)
)
}
pragma[nomagic]
predicate hasFileParent(AstNode n, File f, int i) {
n =
rank[i + 1](AstNode n0, int startline, int startcolumn, int endline, int endcolumn |
hasFileParent(n0, f, startline, startcolumn, endline, endcolumn)
|
n0 order by startline, startcolumn, endline, endcolumn
)
}
from AstNode n, AstNodeParent parent, int i, Location location
where
erb_ast_node_location(n, location) and
(
erb_ast_node_parent(n, parent, i)
or
hasFileParent(n, parent, i)
)
select n, parent, i, location

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
class TAstNodeParent = @file or @ruby_ast_node;
abstract class AstNodeParent extends TAstNodeParent {
string toString() { none() }
}
class AstNode extends AstNodeParent, @ruby_ast_node { }
class File extends AstNodeParent, @file { }
class Location extends @location_default {
string toString() { none() }
}
pragma[nomagic]
predicate hasFileParent(
AstNode n, File f, int startline, int startcolumn, int endline, int endcolumn
) {
exists(Location loc |
not ruby_ast_node_parent(n, _, _) and
ruby_ast_node_location(n, loc) and
locations_default(loc, f, startline, startcolumn, endline, endcolumn)
)
}
pragma[nomagic]
predicate hasFileParent(AstNode n, File f, int i) {
n =
rank[i + 1](AstNode n0, int startline, int startcolumn, int endline, int endcolumn |
hasFileParent(n0, f, startline, startcolumn, endline, endcolumn)
|
n0 order by startline, startcolumn, endline, endcolumn
)
}
from AstNode n, AstNodeParent parent, int i, Location location
where
ruby_ast_node_location(n, location) and
(
ruby_ast_node_parent(n, parent, i)
or
hasFileParent(n, parent, i)
)
select n, parent, i, location

View File

@@ -0,0 +1,8 @@
description: Merge `ruby_ast_node_location` and `ruby_ast_node_parent` into `ruby_ast_node_info` (and same for `erb`)
compatibility: backwards
erb_ast_node_info.rel: run erb_ast_node_info.qlo
erb_ast_node_location.rel: delete
erb_ast_node_parent.rel: delete
ruby_ast_node_info.rel: run ruby_ast_node_info.qlo
ruby_ast_node_location.rel: delete
ruby_ast_node_parent.rel: delete

Binary file not shown.

View File

@@ -34,4 +34,4 @@ lazy_static = "1.4.0"
# of lock-file update time, but `rules_rust` pins generates a bazel rule that unconditionally downloads `main`, which
# breaks build hermeticity. So, rev-pinning it is.
# See also https://github.com/bazelbuild/rules_rust/issues/2502.
codeql-extractor = { git = "https://github.com/github/codeql.git", rev = "514a92d5bd1e24e4b7367d64430762ffd1ffbe7f" }
codeql-extractor = { git = "https://github.com/github/codeql.git", rev = "cee6f003fd58c64916c629f7d8b27b870d6f78c5" }

File diff suppressed because it is too large Load Diff

View File

@@ -137,7 +137,12 @@ class AstNode extends TAstNode {
/** A Ruby source file */
class RubyFile extends File {
RubyFile() { ruby_ast_node_info(_, this, _, _) }
RubyFile() {
exists(Location loc |
ruby_ast_node_location(_, loc) and
this = loc.getFile()
)
}
/** Gets a token in this file. */
private Ruby::Token getAToken() { result.getLocation().getFile() = this }

View File

@@ -12,13 +12,13 @@ module Ruby {
string toString() { result = this.getAPrimaryQlClass() }
/** Gets the location of this element. */
final L::Location getLocation() { ruby_ast_node_info(this, _, _, result) }
final L::Location getLocation() { ruby_ast_node_location(this, result) }
/** Gets the parent of this element. */
final AstNode getParent() { ruby_ast_node_info(this, result, _, _) }
final AstNode getParent() { ruby_ast_node_parent(this, result, _) }
/** Gets the index of this node among the children of its parent. */
final int getParentIndex() { ruby_ast_node_info(this, _, result, _) }
final int getParentIndex() { ruby_ast_node_parent(this, _, result) }
/** Gets a field or child node of this node. */
AstNode getAFieldOrChild() { none() }
@@ -1929,13 +1929,13 @@ module Erb {
string toString() { result = this.getAPrimaryQlClass() }
/** Gets the location of this element. */
final L::Location getLocation() { erb_ast_node_info(this, _, _, result) }
final L::Location getLocation() { erb_ast_node_location(this, result) }
/** Gets the parent of this element. */
final AstNode getParent() { erb_ast_node_info(this, result, _, _) }
final AstNode getParent() { erb_ast_node_parent(this, result, _) }
/** Gets the index of this node among the children of its parent. */
final int getParentIndex() { erb_ast_node_info(this, _, result, _) }
final int getParentIndex() { erb_ast_node_parent(this, _, result) }
/** Gets a field or child node of this node. */
AstNode getAFieldOrChild() { none() }

View File

@@ -1421,14 +1421,16 @@ 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_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_match_pattern | @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_test_pattern | @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
ruby_ast_node_location(
unique int node: @ruby_ast_node ref,
int loc: @location_default ref
);
#keyset[parent, parent_index]
ruby_ast_node_info(
ruby_ast_node_parent(
unique int node: @ruby_ast_node ref,
int parent: @ruby_ast_node_parent ref,
int parent_index: int ref,
int loc: @location_default ref
int parent: @ruby_ast_node ref,
int parent_index: int ref
);
/*- Erb dbscheme -*/
@@ -1497,13 +1499,15 @@ case @erb_token.kind of
@erb_ast_node = @erb_comment_directive | @erb_directive | @erb_graphql_directive | @erb_output_directive | @erb_template | @erb_token
@erb_ast_node_parent = @erb_ast_node | @file
#keyset[parent, parent_index]
erb_ast_node_info(
erb_ast_node_location(
unique int node: @erb_ast_node ref,
int parent: @erb_ast_node_parent ref,
int parent_index: int ref,
int loc: @location_default ref
);
#keyset[parent, parent_index]
erb_ast_node_parent(
unique int node: @erb_ast_node ref,
int parent: @erb_ast_node ref,
int parent_index: int ref
);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
class AstNode extends @erb_ast_node {
string toString() { none() }
}
class Location extends @location_default {
string toString() { none() }
}
from AstNode n, Location location
where erb_ast_node_info(n, _, _, location)
select n, location

View File

@@ -0,0 +1,7 @@
class AstNode extends @erb_ast_node {
string toString() { none() }
}
from AstNode n, int i, AstNode parent
where erb_ast_node_info(n, parent, i, _)
select n, parent, i

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
class AstNode extends @ruby_ast_node {
string toString() { none() }
}
class Location extends @location_default {
string toString() { none() }
}
from AstNode n, Location location
where ruby_ast_node_info(n, _, _, location)
select n, location

View File

@@ -0,0 +1,7 @@
class AstNode extends @ruby_ast_node {
string toString() { none() }
}
from AstNode n, int i, AstNode parent
where ruby_ast_node_info(n, parent, i, _)
select n, parent, i

View File

@@ -0,0 +1,8 @@
description: Split up `ruby_ast_node_info` into `ruby_ast_node_location` and `ruby_ast_node_parent` (and same for `erb`)
compatibility: backwards
erb_ast_node_location.rel: run erb_ast_node_location.qlo
erb_ast_node_parent.rel: run erb_ast_node_parent.qlo
erb_ast_node_info.rel: delete
ruby_ast_node_location.rel: run ruby_ast_node_location.qlo
ruby_ast_node_parent.rel: run ruby_ast_node_parent.qlo
ruby_ast_node_info.rel: delete