mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Add parent_index field to @astnode
This commit is contained in:
@@ -260,12 +260,12 @@ struct Visitor<'a> {
|
||||
/// A lookup table from type name to node types
|
||||
schema: &'a NodeTypeMap,
|
||||
/// A stack for gathering information from child nodes. Whenever a node is entered
|
||||
/// the parent's [Label] and an empty list is pushed. All children append their data
|
||||
/// the parent's [Label], child counter, and an empty list is pushed. All children append their data
|
||||
/// (field name, label, type) to the the list. When the visitor leaves a node the list
|
||||
/// containing the child data is popped from the stack and matched against the dbscheme
|
||||
/// for the node. If the expectations are met the corresponding row definitions are
|
||||
/// added to the trap_output.
|
||||
stack: Vec<(Label, Vec<(Option<&'static str>, Label, TypeName)>)>,
|
||||
stack: Vec<(Label, usize, Vec<(Option<&'static str>, Label, TypeName)>)>,
|
||||
}
|
||||
|
||||
impl Visitor<'_> {
|
||||
@@ -290,7 +290,7 @@ impl Visitor<'_> {
|
||||
|
||||
let id = self.trap_writer.fresh_id();
|
||||
|
||||
self.stack.push((id, Vec::new()));
|
||||
self.stack.push((id, 0, Vec::new()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ impl Visitor<'_> {
|
||||
if node.is_error() || node.is_missing() {
|
||||
return;
|
||||
}
|
||||
let (id, child_nodes) = self.stack.pop().expect("Vistor: empty stack");
|
||||
let (id, _, child_nodes) = self.stack.pop().expect("Vistor: empty stack");
|
||||
let (start_line, start_column, end_line, end_column) = location_for(&self.source, node);
|
||||
let loc = self.trap_writer.location(
|
||||
self.file_label,
|
||||
@@ -315,9 +315,12 @@ impl Visitor<'_> {
|
||||
})
|
||||
.unwrap();
|
||||
let mut valid = true;
|
||||
let parent_id = match self.stack.last_mut() {
|
||||
Some(p) if !node.is_extra() => p.0,
|
||||
_ => self.file_label,
|
||||
let (parent_id, parent_index) = match self.stack.last_mut() {
|
||||
Some(p) if !node.is_extra() => {
|
||||
p.1 += 1;
|
||||
(p.0, p.1 - 1)
|
||||
}
|
||||
_ => (self.file_label, 0),
|
||||
};
|
||||
match &table.kind {
|
||||
EntryKind::Token { kind_id, .. } => {
|
||||
@@ -326,6 +329,7 @@ impl Visitor<'_> {
|
||||
vec![
|
||||
Arg::Label(id),
|
||||
Arg::Label(parent_id),
|
||||
Arg::Int(parent_index),
|
||||
Arg::Int(*kind_id),
|
||||
Arg::Label(self.file_label),
|
||||
Arg::Int(self.token_counter),
|
||||
@@ -343,6 +347,7 @@ impl Visitor<'_> {
|
||||
let mut all_args = Vec::new();
|
||||
all_args.push(Arg::Label(id));
|
||||
all_args.push(Arg::Label(parent_id));
|
||||
all_args.push(Arg::Int(parent_index));
|
||||
all_args.extend(args);
|
||||
all_args.push(Arg::Label(loc));
|
||||
self.trap_writer.add_tuple(&table_name, all_args);
|
||||
@@ -362,7 +367,7 @@ impl Visitor<'_> {
|
||||
// Extra nodes are independent root nodes and do not belong to the parent node
|
||||
// Therefore we should not register them in the parent vector
|
||||
if let Some(parent) = self.stack.last_mut() {
|
||||
parent.1.push((
|
||||
parent.2.push((
|
||||
field_name,
|
||||
id,
|
||||
TypeName {
|
||||
|
||||
Reference in New Issue
Block a user