diff --git a/crates/metaslang/cst/Cargo.toml b/crates/metaslang/cst/Cargo.toml index 8d8f12b536..48e860a550 100644 --- a/crates/metaslang/cst/Cargo.toml +++ b/crates/metaslang/cst/Cargo.toml @@ -18,6 +18,9 @@ license = "MIT" keywords = ["parser"] categories = ["compilers", "parsing", "parser-implementations"] +[features] +syntax = [] + [dependencies] nom = { workspace = true } serde = { workspace = true } diff --git a/crates/metaslang/cst/src/lib.rs b/crates/metaslang/cst/src/lib.rs index e151477bec..4b9e7c3d9c 100644 --- a/crates/metaslang/cst/src/lib.rs +++ b/crates/metaslang/cst/src/lib.rs @@ -7,3 +7,11 @@ pub mod kinds; pub mod nodes; pub mod query; pub mod text_index; + +#[cfg(feature = "syntax")] +#[allow(missing_docs)] +pub mod syntax_node; + +#[cfg(feature = "syntax")] +#[allow(missing_docs)] +pub mod syntax_cursor; diff --git a/crates/metaslang/cst/src/query/mod.rs b/crates/metaslang/cst/src/query/mod.rs index d4edcd304c..43f113bd45 100644 --- a/crates/metaslang/cst/src/query/mod.rs +++ b/crates/metaslang/cst/src/query/mod.rs @@ -7,3 +7,9 @@ mod parser; pub use engine::{Capture, QueryMatch, QueryMatchIterator}; pub use model::Query; pub use parser::{CaptureQuantifier, QueryError}; + +#[cfg(feature = "syntax")] +mod syntax_engine; + +#[cfg(feature = "syntax")] +pub use syntax_engine::{SyntaxCapture, SyntaxQueryMatch, SyntaxQueryMatchIterator}; diff --git a/crates/metaslang/cst/src/query/syntax_engine.rs b/crates/metaslang/cst/src/query/syntax_engine.rs new file mode 100644 index 0000000000..8d0210b7ca --- /dev/null +++ b/crates/metaslang/cst/src/query/syntax_engine.rs @@ -0,0 +1,826 @@ +use std::collections::BTreeMap; +use std::rc::Rc; + +use super::model::{ + ASTNode, AlternativesASTNode, CaptureASTNode, NodeMatchASTNode, NodeSelector, OneOrMoreASTNode, + OptionalASTNode, Query, SequenceASTNode, +}; +use crate::kinds::{KindTypes, NodeKind, TerminalKindExtensions}; +use crate::syntax_cursor::SyntaxCursor; + +impl SyntaxCursor { + /// Returns an iterator over all matches of the given queries in the syntax tree. + pub fn query(self, queries: Vec>) -> SyntaxQueryMatchIterator { + SyntaxQueryMatchIterator::new(self, queries) + } + + fn irrevocably_go_to_next_sibling(&mut self) -> bool { + if self.is_completed() { + false + } else { + if !self.go_to_next_sibling() { + self.complete(); + } + true + } + } + + fn matches_node_selector(&self, node_selector: &NodeSelector) -> bool { + if let Some(nonterminal) = self.node().as_nonterminal() { + match node_selector { + NodeSelector::Anonymous => true, + NodeSelector::NodeKind { node_kind } => { + NodeKind::Nonterminal(nonterminal.kind) == *node_kind + } + NodeSelector::NodeText { .. } => false, + NodeSelector::EdgeLabel { edge_label } => *edge_label == self.node().label(), + NodeSelector::EdgeLabelAndNodeKind { + edge_label, + node_kind, + } => { + *edge_label == self.node().label() + && NodeKind::Nonterminal(nonterminal.kind) == *node_kind + } + NodeSelector::EdgeLabelAndNodeText { .. } => false, + } + } else if let Some(terminal) = self.node().as_terminal() { + if terminal.kind.is_trivia() { + false + } else { + match node_selector { + NodeSelector::Anonymous => true, + NodeSelector::NodeKind { node_kind } => { + NodeKind::Terminal(terminal.kind) == *node_kind + } + NodeSelector::NodeText { node_text } => terminal.text == *node_text, + NodeSelector::EdgeLabel { edge_label } => *edge_label == self.node().label(), + NodeSelector::EdgeLabelAndNodeKind { + edge_label, + node_kind, + } => { + *edge_label == self.node().label() + && NodeKind::Terminal(terminal.kind) == *node_kind + } + NodeSelector::EdgeLabelAndNodeText { + edge_label, + node_text, + } => *edge_label == self.node().label() && terminal.text == *node_text, + } + } + } else { + unreachable!("node is neither terminal nor non-terminal"); + } + } +} + +impl ASTNode { + // This allows for queries to pre-flight against a cursor without allocating + fn can_match_syntax(&self, cursor: &SyntaxCursor) -> bool { + match self { + Self::Capture(matcher) => matcher.child.can_match_syntax(cursor), + Self::NodeMatch(matcher) => cursor.matches_node_selector(&matcher.node_selector), + Self::Alternatives(matcher) => { + matcher.children.iter().any(|c| c.can_match_syntax(cursor)) + } + Self::Sequence(matcher) => matcher.children[0].can_match_syntax(cursor), + Self::OneOrMore(matcher) => matcher.child.can_match_syntax(cursor), + Self::Optional(_) => true, + Self::Adjacency => true, + } + } + + // The `require_explicit_match` parameter modifies the behaviour of this and + // later matchers. If this value is true, this and later matchers should not + // match sibling nodes implicitly. + // Currently this only modifies the behaviour of the ellipsis matcher, which + // otherwise will attempt to consume any number of sibling nodes. + // In a sequence of matchers, this value is set to true by the ellipsis + // operator itself, to consume all available sibling nodes and prevent later + // ellipsis matchers from doing so. + // Conversely, it's set to false by the `NodeMatcher`, both when recursing + // into its children and for later matchers after itself, as it handles an + // explicit match requested by the user. + // All other matchers should propagate the received value forward. + // + // The whole point of propagating this flag is to prevent a weird + // interaction between ellipsis operators working on the same set of sibling + // nodes. While two consecutive ellipsis operators should never happen, we + // have the `OptionalMatcher` which will not consume any nodes in the nil + // case. This means that `... [_]? ...` will effectively work (in one case) + // as `... ...`. If we allow both ellipsis operators to consume any number + // of nodes, for a sequence of N nodes we get N+1 identical query results + // when the operators take turns matching each prefix and complementary + // suffix of the list of nodes. By only allowing the first ellipsis operator + // to consume an arbitrary number of nodes, we reduce the returned matches + // to a single one. + // + fn create_syntax_matcher( + &self, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> MatcherRef { + match self { + Self::Capture(matcher) => Box::new(CaptureMatcher::::new( + Rc::clone(matcher), + cursor, + require_explicit_match, + )), + Self::NodeMatch(matcher) => { + // By definition this matcher matches nodes explicitly + Box::new(NodeMatchMatcher::::new(Rc::clone(matcher), cursor)) + } + Self::Sequence(matcher) => Box::new(SequenceMatcher::::new( + Rc::clone(matcher), + cursor, + require_explicit_match, + )), + Self::Alternatives(matcher) => Box::new(AlternativesMatcher::::new( + Rc::clone(matcher), + cursor, + require_explicit_match, + )), + Self::Optional(matcher) => Box::new(OptionalMatcher::::new( + Rc::clone(matcher), + cursor, + require_explicit_match, + )), + Self::OneOrMore(matcher) => Box::new(OneOrMoreMatcher::::new( + Rc::clone(matcher), + cursor, + require_explicit_match, + )), + Self::Adjacency => Box::new(AdjacencyMatcher::::new(cursor, require_explicit_match)), + } + } +} + +/// Represents a match found by executing queries on a cursor. +pub struct SyntaxQueryMatch { + queries: Rc>>, + query_index: usize, + root_cursor: SyntaxCursor, + captures: BTreeMap>>, +} + +impl SyntaxQueryMatch { + /// Returns the query that was matched. + pub fn query(&self) -> &Query { + &self.queries[self.query_index] + } + + /// The index of the matched query within the list of queries. + pub fn query_index(&self) -> usize { + self.query_index + } + + /// The cursor that was used to find the match. + pub fn root_cursor(&self) -> &SyntaxCursor { + &self.root_cursor + } + + /// Returns an iterator over all of the capture names matched by this query. + pub fn capture_names(&self) -> impl Iterator { + self.query().capture_quantifiers().keys() + } + + /// Returns an iterator over all of the captures matched by this query. Each [`SyntaxCapture`] contains the capture name, + /// and a list of [`SyntaxCursor`]s to the location of each captured node in the parse tree. + pub fn captures(&self) -> impl Iterator> { + self.query().capture_quantifiers().keys().map(|name| { + let cursors = match self.captures.get(name) { + Some(cursors) => &cursors[..], + None => &[], + }; + + SyntaxCapture { name, cursors } + }) + } + + /// Try to find a single capture matched by this query. + /// If no captures exist with the name `name`, this will return `None`. + /// If a capture does exist, then this will return a [`SyntaxCapture`] containing the capture name, + /// and a list of [`SyntaxCursor`]s to the location of each captured node in the parse tree. + pub fn capture(&self, name: &str) -> Option> { + let name = self + .query() + .capture_quantifiers() + .keys() + .find(|key| key == &name)?; + + let cursors = match self.captures.get(name) { + Some(cursors) => &cursors[..], + None => &[], + }; + + Some(SyntaxCapture { name, cursors }) + } +} + +/// A single capture matched by a query, containing the capture name, +/// and a list of [`SyntaxCursor`]s to the location of each captured node in the parse tree. +pub struct SyntaxCapture<'a, T: KindTypes> { + name: &'a str, + cursors: &'a [SyntaxCursor], +} + +impl SyntaxCapture<'_, T> { + /// The name of the capture. + pub fn name(&self) -> &str { + self.name + } + + /// A list of cursors to the location of each captured node in the parse tree. + pub fn cursors(&self) -> &[SyntaxCursor] { + self.cursors + } +} + +/// Iterator over query matches in the syntax tree. +pub struct SyntaxQueryMatchIterator { + queries: Rc>>, + cursor: SyntaxCursor, + query_index: usize, + matcher: Option>, +} + +impl SyntaxQueryMatchIterator { + fn new(cursor: SyntaxCursor, queries: Vec>) -> Self { + Self { + queries: Rc::new(queries), + cursor, + query_index: 0, + matcher: None, + } + } + + fn advance_to_next_possible_matching_query(&mut self) { + while !self.cursor.is_completed() { + while self.query_index < self.queries.len() { + let ast_node = &self.queries[self.query_index].ast_node(); + if ast_node.can_match_syntax(&self.cursor) { + // The first matcher in the query should allow implicit matches + self.matcher = Some(ast_node.create_syntax_matcher(self.cursor.clone(), false)); + return; + } + self.query_index += 1; + } + self.cursor.go_to_next(); + self.query_index = 0; + } + } +} + +impl Iterator for SyntaxQueryMatchIterator { + type Item = SyntaxQueryMatch; + + /// Returns the next match or `None` if there are no more matches. + fn next(&mut self) -> Option { + while !self.cursor.is_completed() { + if let Some(matcher) = self.matcher.as_mut() { + if matcher.next().is_some() { + let mut captures = BTreeMap::new(); + matcher.record_captures(&mut captures); + return Some(SyntaxQueryMatch { + queries: Rc::clone(&self.queries), + root_cursor: self.cursor.clone(), + query_index: self.query_index, + captures, + }); + } + self.query_index += 1; + } + + self.advance_to_next_possible_matching_query(); + } + + None + } +} + +#[derive(Clone)] +struct MatcherResult { + // if cursor.is_completed() -> end of input + // if !cursor.is_completed() -> there is more input to go + cursor: SyntaxCursor, + + // Controls whether next matchers can match nodes implicitly. For matchers + // applied on a sequence of sibling nodes, this will be: + // - initially false, allowing the first found ellipsis matcher to consume + // an arbitrary number of nodes + // - true after the execution of an ellipsis, thus preventing later ellipsis + // from consuming nodes + // - propagated forward by other matchers, until + // - an actual `NodeMatcher` successfully matches a node, which then flips + // this value back to false + require_explicit_match: bool, +} + +trait Matcher { + // None -> failed to match, you must backtrack. DO NOT call again + // Some(result) -> matched, check result.cursor and pass require_explicit_match forward + fn next(&mut self) -> Option>; + fn record_captures(&self, captures: &mut BTreeMap>>); +} +type MatcherRef = Box>; + +struct CaptureMatcher { + matcher: Rc>, + cursor: SyntaxCursor, + child: MatcherRef, +} + +impl CaptureMatcher { + fn new( + matcher: Rc>, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> Self { + let child = matcher + .child + .create_syntax_matcher(cursor.clone(), require_explicit_match); + Self { + matcher, + cursor, + child, + } + } +} + +impl Matcher for CaptureMatcher { + fn next(&mut self) -> Option> { + self.child.next() + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + captures + .entry(self.matcher.name.clone()) + .or_default() + .push(self.cursor.clone()); + self.child.record_captures(captures); + } +} + +struct NodeMatchMatcher { + matcher: Rc>, + child: Option>, + cursor: SyntaxCursor, + is_initialised: bool, +} + +impl NodeMatchMatcher { + fn new(matcher: Rc>, cursor: SyntaxCursor) -> Self { + Self { + matcher, + child: None, + cursor, + is_initialised: false, + } + } +} + +impl Matcher for NodeMatchMatcher { + fn next(&mut self) -> Option> { + if self.cursor.is_completed() { + return None; + } + + if !self.is_initialised { + self.is_initialised = true; + + if !self + .cursor + .matches_node_selector(&self.matcher.node_selector) + { + return None; + } + + if let Some(child) = self.matcher.child.as_ref() { + let mut child_cursor = self.cursor.clone(); + if !child_cursor.go_to_first_child() { + // We have child matchers, but no children. + return None; + } + + // Start traversing the children nodes allowing an ellipsis + // operator to match implicitly. + self.child = Some(child.create_syntax_matcher(child_cursor, false)); + } else { + // We have no child matchers, we can return the result now. + let mut return_cursor = self.cursor.clone(); + return_cursor.irrevocably_go_to_next_sibling(); + return Some(MatcherResult { + cursor: return_cursor, + require_explicit_match: false, + }); + } + } + + if let Some(child) = self.child.as_mut() { + // Match our children with the child matcher repeatedly. + while let Some(MatcherResult { cursor, .. }) = child.as_mut().next() { + if cursor.is_completed() { + // If match found and exhausted our children list, return + // the match *from our own cursor* + let mut return_cursor = self.cursor.clone(); + return_cursor.irrevocably_go_to_next_sibling(); + return Some(MatcherResult { + cursor: return_cursor, + require_explicit_match: false, + }); + } + } + // No more matches from the child matcher, we will backtrack at this point. + self.child = None; + } + + None + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + if let Some(child) = self.child.as_ref() { + child.record_captures(captures); + } + } +} + +enum SequenceItem { + ChildMatcher(usize), + Ellipsis, +} + +struct SequenceMatcher { + matcher: Rc>, + children: Vec>, + cursor: SyntaxCursor, + is_initialised: bool, + template: Vec, + require_explicit_match: bool, +} + +impl SequenceMatcher { + fn new( + matcher: Rc>, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> Self { + // Produce a template of instructions to create the matchers for the + // sequence by inserting ellipsis matchers at the start, end, and in + // between each of the child matchers, unless we find an adjacency + // operator. If the sequence is adjacent (eg. option in alt or + // quantified group sequence) then we should not add matchers at the + // edges. + let (mut template, last_adjacent) = matcher.children.iter().enumerate().fold( + (Vec::new(), matcher.adjacent), + |(mut acc, last_adjacent), (index, child)| { + if matches!(child, ASTNode::Adjacency) { + if last_adjacent { + unreachable!("Found two consecutive adjacency operators") + } + acc.push(SequenceItem::ChildMatcher(index)); + (acc, true) + } else { + if !last_adjacent { + acc.push(SequenceItem::Ellipsis); + } + acc.push(SequenceItem::ChildMatcher(index)); + (acc, false) + } + }, + ); + if !last_adjacent && !matcher.adjacent { + template.push(SequenceItem::Ellipsis); + } + Self { + matcher, + children: vec![], + cursor, + is_initialised: false, + template, + require_explicit_match, + } + } + + fn create_syntax_matcher( + &self, + index: usize, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> MatcherRef { + let item = &self.template[index]; + match item { + SequenceItem::Ellipsis => { + Box::new(EllipsisMatcher::new(cursor, require_explicit_match)) + } + SequenceItem::ChildMatcher(index) => { + self.matcher.children[*index].create_syntax_matcher(cursor, require_explicit_match) + } + } + } +} + +impl Matcher for SequenceMatcher { + fn next(&mut self) -> Option> { + if !self.is_initialised { + self.is_initialised = true; + + let child_cursor = self.cursor.clone(); + let child = self.create_syntax_matcher(0, child_cursor, self.require_explicit_match); + self.children.push(child); + } + + while !self.children.is_empty() { + if let Some(child_matcher_result) = self.children.last_mut().unwrap().next() { + if self.children.len() == self.template.len() { + // Last child, return its result as our own + return Some(child_matcher_result); + } + // Create the next child matcher propagating the + // `require_explicit_match` flag forward. + let child = self.create_syntax_matcher( + self.children.len(), + child_matcher_result.cursor, + child_matcher_result.require_explicit_match, + ); + self.children.push(child); + } else { + // Backtrack + self.children.pop(); + } + } + + None + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + for child in &self.children { + child.record_captures(captures); + } + } +} + +struct AlternativesMatcher { + matcher: Rc>, + next_child_number: usize, + child: Option>, + cursor: SyntaxCursor, + require_explicit_match: bool, +} + +impl AlternativesMatcher { + fn new( + matcher: Rc>, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> Self { + Self { + matcher, + next_child_number: 0, + child: None, + cursor, + require_explicit_match, + } + } +} + +impl Matcher for AlternativesMatcher { + fn next(&mut self) -> Option> { + loop { + if self.child.is_none() { + // Create the next available child matcher forwarding the + // `require_explicit_match` flag, or give up if we have no more + match self.matcher.children.get(self.next_child_number) { + Some(child) => { + let child = child.create_syntax_matcher( + self.cursor.clone(), + self.require_explicit_match, + ); + self.child = Some(child); + self.next_child_number += 1; + } + None => return None, + } + } + + match self.child.as_mut().unwrap().next() { + Some(child_matcher_result) => return Some(child_matcher_result), + None => self.child = None, + } + } + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + self.child.as_ref().unwrap().record_captures(captures); + } +} + +struct OptionalMatcher { + matcher: Rc>, + child: Option>, + cursor: SyntaxCursor, + have_nonempty_match: bool, + require_explicit_match: bool, +} + +impl OptionalMatcher { + fn new( + matcher: Rc>, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> Self { + Self { + matcher, + child: None, + cursor, + have_nonempty_match: false, + require_explicit_match, + } + } +} + +impl Matcher for OptionalMatcher { + fn next(&mut self) -> Option> { + if let Some(child) = self.child.as_mut() { + // Second visit, we have a child matcher created + if let Some(child_matcher_result) = child.next() { + self.have_nonempty_match = true; + Some(child_matcher_result) + } else { + self.child = None; + None + } + } else { + // First visit, we don't have a child matcher yet, so create it + // forwarding our `require_explicit_match` flag + let child_cursor = self.cursor.clone(); + let child = self + .matcher + .child + .create_syntax_matcher(child_cursor, self.require_explicit_match); + self.child = Some(child); + + // Return a match result for the empty case, forwarding the + // `require_explicit_match` flag. + Some(MatcherResult { + cursor: self.cursor.clone(), + require_explicit_match: self.require_explicit_match, + }) + } + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + if self.have_nonempty_match { + if let Some(child) = self.child.as_ref() { + child.record_captures(captures); + } + } + } +} + +struct OneOrMoreMatcher { + matcher: Rc>, + children: Vec>, + result_for_next_repetition: Option>, +} + +impl OneOrMoreMatcher { + fn new( + matcher: Rc>, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> Self { + let result_for_next_repetition = Some(MatcherResult { + cursor, + require_explicit_match, + }); + Self { + matcher, + children: vec![], + result_for_next_repetition, + } + } +} + +impl Matcher for OneOrMoreMatcher { + fn next(&mut self) -> Option> { + loop { + if let Some(last_result) = self.result_for_next_repetition.take() { + let next_child = self + .matcher + .child + .create_syntax_matcher(last_result.cursor, last_result.require_explicit_match); + self.children.push(next_child); + } else { + let tail = self.children.last_mut().unwrap(); + if let Some(child_matcher_result) = tail.next() { + // Skip over trivia before saving the result for next repetition + let mut cursor = child_matcher_result.cursor.clone(); + while !cursor.is_completed() && cursor.node().is_trivia() { + cursor.irrevocably_go_to_next_sibling(); + } + if !cursor.is_completed() { + self.result_for_next_repetition = Some(MatcherResult { + cursor, + ..child_matcher_result + }); + } + return Some(child_matcher_result); + } + self.children.pop(); + if self.children.is_empty() { + return None; + } + } + } + } + + fn record_captures(&self, captures: &mut BTreeMap>>) { + for child in &self.children { + child.record_captures(captures); + } + } +} + +/// Matches any number of sibling nodes and is used in between other matchers +/// when matching sequences, unless an explicit adjacency operator is found. +/// If `require_explicit_match` is true, then this matcher can only return a +/// result for the empty case. This usually means that in the same sequence of +/// siblings we found a previous ellipsis matcher which will be able to consume +/// an arbitrary number of nodes. Then, the value is false if this is the first +/// `EllipsisMatcher` in a sibling list, or there was an explicit match (by a +/// `NodeMatcher`) in a previous matcher of the sequence. +struct EllipsisMatcher { + cursor: SyntaxCursor, + has_returned_initial_empty_value: bool, + require_explicit_match: bool, +} + +impl EllipsisMatcher { + fn new(cursor: SyntaxCursor, require_explicit_match: bool) -> Self { + Self { + cursor, + has_returned_initial_empty_value: false, + require_explicit_match, + } + } +} + +impl Matcher for EllipsisMatcher { + fn next(&mut self) -> Option> { + // First visit, we always return a match for empty case + if !self.has_returned_initial_empty_value { + self.has_returned_initial_empty_value = true; + // We need later matchers to avoid consuming nodes + return Some(MatcherResult { + cursor: self.cursor.clone(), + require_explicit_match: true, + }); + } + + // Subsequent visits: we only consume nodes if an explicit match is not + // required, ie. if this is the *first* ellipsis operator in a sibling + // sequence or there was an explicit match before us. + if !self.require_explicit_match && self.cursor.irrevocably_go_to_next_sibling() { + return Some(MatcherResult { + cursor: self.cursor.clone(), + require_explicit_match: true, + }); + } + + None + } + + fn record_captures(&self, _: &mut BTreeMap>>) {} +} + +/// Greedily consumes available trivia nodes only +struct AdjacencyMatcher { + cursor: Option>, + require_explicit_match: bool, +} + +impl AdjacencyMatcher { + fn new(cursor: SyntaxCursor, require_explicit_match: bool) -> Self { + Self { + cursor: Some(cursor), + require_explicit_match, + } + } +} + +impl Matcher for AdjacencyMatcher { + fn next(&mut self) -> Option> { + if let Some(mut cursor) = self.cursor.take() { + while !cursor.is_completed() && cursor.node().is_trivia() { + cursor.irrevocably_go_to_next_sibling(); + } + Some(MatcherResult { + cursor, + require_explicit_match: self.require_explicit_match, + }) + } else { + None + } + } + + fn record_captures(&self, _: &mut BTreeMap>>) {} +} diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs new file mode 100644 index 0000000000..13c3b90f64 --- /dev/null +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -0,0 +1,365 @@ +//! A cursor that can traverse a CST in a DFS pre-order fashion. + +use std::rc::Rc; + +use crate::kinds::KindTypes; +use crate::syntax_node::SyntaxNode; + +/// A cursor that can traverse a CST. +/// +/// Nodes are visited in a DFS pre-order traversal. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct SyntaxCursor { + /// The node the cursor is currently pointing to. + node: Rc>, + /// The index of the current child node in the parent's children. + // Required to go to the next/previous sibling. + child_index: usize, + /// Whether the cursor is completed, i.e. at the root node as a result of traversal (or when `complete`d). + /// If `true`, the cursor cannot be moved. + is_completed: bool, +} + +impl SyntaxCursor { + pub fn create_from(node: Rc>) -> Self { + let child_index = node.index_in_parent().unwrap_or(0usize); + Self { + node, + child_index, + is_completed: false, + } + } + + /// Resets the cursor to the root node. + pub fn reset(&mut self) { + self.complete(); + self.is_completed = false; + } + + /// Completes the cursor, setting it to the root node. + pub fn complete(&mut self) { + let mut parent = Rc::clone(&self.node); + while let Some(next_parent) = parent.parent() { + parent = next_parent; + } + self.node = parent; + self.is_completed = true; + } + + /// Unlike [`clone`][`Self::clone`] this re-roots at the current node; however, + /// it does preserve the correct text offset even though the path is reset. + #[must_use] + pub fn spawn(&self) -> Self { + Self { + is_completed: false, + node: self.node.erase_root(), + child_index: 0, + } + } + + /// Whether the cursor can be moved. + pub fn is_completed(&self) -> bool { + self.is_completed + } + + /// Returns the currently pointed to [`SyntaxNode`]. + pub fn node(&self) -> Rc> { + Rc::clone(&self.node) + } + + /// Returns the depth of the current node in the CST, i.e. the number of ancestors. + pub fn depth(&self) -> usize { + let mut depth = 0; + let mut parent = &self.node; + while let Some(next_parent) = parent.parent_ref() { + depth += 1; + parent = next_parent; + } + + depth + } + + /// Returns the list of child edges directly connected to this node. + pub fn children(&self) -> Vec>> { + self.node.children() + } + + /// Returns an iterator over all descendants of the current node in pre-order traversal. + pub fn descendants(&self) -> SyntaxCursorIterator { + let mut cursor = self.spawn(); + + // skip the current node: + cursor.go_to_next(); + + SyntaxCursorIterator { cursor } + } + + /// Returns an iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. + pub fn remaining_nodes(&self) -> SyntaxCursorIterator { + SyntaxCursorIterator { + cursor: self.clone(), + } + } + + /// Returns an iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. + pub fn ancestors(&self) -> SyntaxAncestorsIterator { + let current = Rc::clone(&self.node); + + SyntaxAncestorsIterator { current } + } + + /// Attempts to go to current node's next one, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next(&mut self) -> bool { + if self.is_completed { + return false; + } + + self.go_to_first_child() || self.go_to_next_non_descendant() + } + + /// Attempts to go to current node's next non-descendant. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_non_descendant(&mut self) -> bool { + if self.is_completed { + return false; + } + + while !self.go_to_next_sibling() { + if !self.go_to_parent() { + return false; + } + } + + true + } + + /// Attempts to go to current node's previous one, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_previous(&mut self) -> bool { + if self.is_completed { + return false; + } + + while !self.go_to_previous_sibling() { + if !self.go_to_parent() { + return false; + } + } + + while self.go_to_last_child() {} + + true + } + + /// Attempts to go to current node's parent. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_parent(&mut self) -> bool { + if let Some(parent) = self.node.parent() { + self.node = parent; + self.child_index = self.node.index_in_parent().unwrap_or(0); + + true + } else { + self.is_completed = true; + + false + } + } + + /// Attempts to go to current node's first child. + /// + /// Returns `false` if the cursor is finished or there's no child to go to. + pub fn go_to_first_child(&mut self) -> bool { + if self.is_completed { + return false; + } + + // If the current cursor is a node and it has children, go to first children + if self.node.children_count() == 0 { + return false; + } + + self.node = self.node.nth_child(0); + self.child_index = 0; + true + } + + /// Attempts to go to current node's last child. + /// + /// Returns `false` if the cursor is finished or there's no child to go to. + pub fn go_to_last_child(&mut self) -> bool { + if self.is_completed { + return false; + } + + let children_count = self.node.children_count(); + if children_count == 0 { + return false; + } + + self.child_index = children_count - 1; + self.node = self.node.nth_child(self.child_index); + + true + } + + /// Attempts to go to current node's nth child. + /// + /// Returns `false` if the cursor is finished or there's no child to go to. + pub fn go_to_nth_child(&mut self, child_index: usize) -> bool { + if self.is_completed { + return false; + } + + if child_index + 1 > self.node.children_count() { + return false; + } + + self.node = self.node.nth_child(child_index); + self.child_index = child_index; + + false + } + + /// Attempts to go to current node's next sibling. + /// + /// Returns `false` if the cursor is finished or there's no sibling to go to. + pub fn go_to_next_sibling(&mut self) -> bool { + if self.is_completed { + return false; + } + + let Some(parent) = self.node.parent() else { + return false; + }; + + if self.child_index + 1 >= parent.children_count() { + return false; + } + + self.child_index += 1; + self.node = parent.nth_child(self.child_index); + + true + } + + /// Attempts to go to current node's previous sibling. + /// + /// Returns `false` if the cursor is finished or there's no sibling to go to. + pub fn go_to_previous_sibling(&mut self) -> bool { + if self.is_completed { + return false; + } + + let Some(parent) = self.node.parent() else { + return false; + }; + + if self.child_index == 0 { + return false; + } + + self.child_index -= 1; + self.node = parent.nth_child(self.child_index); + + true + } + + /// Attempts to go to the next terminal node, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_terminal(&mut self) -> bool { + self.go_to_next_matching(|node| node.is_terminal()) + } + + /// Attempts to go to the next terminal node with the given kind, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_terminal_with_kind(&mut self, kind: T::TerminalKind) -> bool { + self.go_to_next_matching(|node| node.is_terminal_with_kind(kind)) + } + + /// Attempts to go to the next terminal node with any of the given kinds, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_terminal_with_kinds(&mut self, kinds: &[T::TerminalKind]) -> bool { + self.go_to_next_matching(|node| node.is_terminal_with_kinds(kinds)) + } + + /// Attempts to go to the next nonterminal node, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_nonterminal(&mut self) -> bool { + self.go_to_next_matching(|node| node.is_nonterminal()) + } + + /// Attempts to go to the next nonterminal node with the given kind, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_nonterminal_with_kind(&mut self, kind: T::NonterminalKind) -> bool { + self.go_to_next_matching(|node| node.is_nonterminal_with_kind(kind)) + } + + /// Attempts to go to the next nonterminal node with any of the given kinds, according to the DFS pre-order traversal. + /// + /// Returns `false` if the cursor is finished and at the root. + pub fn go_to_next_nonterminal_with_kinds(&mut self, kinds: &[T::NonterminalKind]) -> bool { + self.go_to_next_matching(|node| node.is_nonterminal_with_kinds(kinds)) + } + + fn go_to_next_matching(&mut self, pred: impl Fn(&SyntaxNode) -> bool) -> bool { + while self.go_to_next() { + if pred(&self.node) { + return true; + } + } + + false + } +} + +/// Iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. +pub struct SyntaxCursorIterator { + cursor: SyntaxCursor, +} + +impl Iterator for SyntaxCursorIterator { + type Item = Rc>; + + /// Returns the next edge in the iteration, or `None` if there are no more edges. + fn next(&mut self) -> Option { + if self.cursor.is_completed() { + return None; + } + + let current = Rc::clone(&self.cursor.node); + + self.cursor.go_to_next(); + + Some(current) + } +} + +/// Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. +pub struct SyntaxAncestorsIterator { + current: Rc>, +} + +impl Iterator for SyntaxAncestorsIterator { + type Item = Rc>; + + /// Returns the next nonterminal node in the iteration, or `None` if there are no more nodes. + fn next(&mut self) -> Option { + if let Some(parent) = self.current.parent() { + self.current = Rc::clone(&parent); + Some(parent) + } else { + None + } + } +} diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs new file mode 100644 index 0000000000..a2dc7953b6 --- /dev/null +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -0,0 +1,230 @@ +use std::rc::Rc; + +use crate::cursor::Cursor; +use crate::kinds::{KindTypes, NodeKind}; +use crate::nodes::{Node, NodeId, NonterminalNode, TerminalNode}; +use crate::text_index::TextIndex; + +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct SyntaxNode { + parent: Option>>, + label: T::EdgeLabel, + green: Node, +} + +impl SyntaxNode { + pub fn create_root(node: Node) -> Rc { + Rc::new(Self { + parent: None, + label: T::EdgeLabel::default(), + green: node, + }) + } + + pub(crate) fn erase_root(self: &Rc) -> Rc { + if self.parent.is_some() { + Rc::new(Self { + parent: None, + label: self.label, + green: self.green.clone(), + }) + } else { + Rc::clone(self) + } + } + + /// Returns a unique identifier of the node. It is not reproducible over parses + /// and cannot be used in a persistent/serialised sense. + pub fn id(&self) -> NodeId { + self.green.id() + } + + pub fn parent(&self) -> Option>> { + self.parent.as_ref().map(Rc::clone) + } + + pub fn parent_ref(&self) -> Option<&Rc>> { + self.parent.as_ref() + } + + /// The kind of the node. + pub fn kind(&self) -> NodeKind { + self.green.kind() + } + + pub fn label(&self) -> T::EdgeLabel { + self.label + } + + /// The length of the node, as a `TextIndex`. + pub fn text_len(&self) -> TextIndex { + self.green.text_len() + } + + /// Returns the list of child edges directly connected to this node. + pub fn children(self: &Rc) -> Vec> { + let mut children = Vec::with_capacity(self.green.children().len()); + for edge in self.green.children() { + children.push(Rc::new(SyntaxNode { + parent: Some(Rc::clone(self)), + label: edge.label, + green: edge.node.clone(), + })); + } + children + } + + /// Returns the number of child nodes + #[inline] + pub fn children_count(&self) -> usize { + self.green.children().len() + } + + /// Returns the label of the nth child. Panics if the given index is out of bounds. + #[inline] + pub fn child_label(&self, index: usize) -> T::EdgeLabel { + self.green.children()[index].label + } + + /// Check that the nth child is a valid node and is not trivia + #[inline] + pub fn child_is_valid_and_not_trivia(&self, index: usize) -> bool { + let node = &self.green.children()[index].node; + node.is_valid() && !node.is_trivia() + } + + /// Returns the `SyntaxNode` for the nth-child + #[inline] + pub fn nth_child(self: &Rc, index: usize) -> Rc { + let edge = &self.green.children()[index]; + Rc::new(SyntaxNode { + parent: Some(Rc::clone(self)), + label: edge.label, + green: edge.node.clone(), + }) + } + + pub fn child_index(&self, node_id: NodeId) -> Option { + self.green + .children() + .iter() + .position(|edge| edge.node.id() == node_id) + } + + pub fn index_in_parent(&self) -> Option { + self.parent + .as_ref() + .and_then(|parent| parent.child_index(self.id())) + } + + /// Reconstructs the original source code from the node and its sub-tree. + pub fn unparse(&self) -> String { + self.green.unparse() + } + + /// Converts the node into a `NonterminalNode`, if possible. + pub fn into_nonterminal(self) -> Option>> { + self.green.into_nonterminal() + } + + /// Returns if the node is a nonterminal. + pub fn is_nonterminal(&self) -> bool { + self.as_nonterminal().is_some() + } + + /// Converts the node into a `NonterminalNode`, if possible. + pub fn as_nonterminal(&self) -> Option<&Rc>> { + self.green.as_nonterminal() + } + + /// Returns if this node is a nonterminal with the given nonterminal kind. + pub fn is_nonterminal_with_kind(&self, kind: T::NonterminalKind) -> bool { + self.as_nonterminal_with_kind(kind).is_some() + } + + /// Returns the `NonterminalNode` with the specific `kind`, or `None` if it is not a nonterminal or it doesn't have + /// the specific kind. + pub fn as_nonterminal_with_kind( + &self, + kind: T::NonterminalKind, + ) -> Option<&Rc>> { + self.as_nonterminal().filter(|node| node.kind == kind) + } + + /// Returns if this node is a nonterminal with the given nonterminal kinds. + pub fn is_nonterminal_with_kinds(&self, kinds: &[T::NonterminalKind]) -> bool { + self.as_nonterminal_with_kinds(kinds).is_some() + } + + /// Returns the `NonterminalNode` with the specific `kinds`, or `None` if it is not a nonterminal or it doesn't + /// have any of the specific kinds. + pub fn as_nonterminal_with_kinds( + &self, + kinds: &[T::NonterminalKind], + ) -> Option<&Rc>> { + self.as_nonterminal() + .filter(|nonterminal| kinds.contains(&nonterminal.kind)) + } + + /// Returns the node as a `TerminalNode`, if it's a terminal node. + pub fn into_terminal(self) -> Option>> { + self.green.into_terminal() + } + + /// Returns if the node is a terminal node. + pub fn is_terminal(&self) -> bool { + self.as_terminal().is_some() + } + + /// Returns the node as a `TerminalNode`, if it's a terminal node. + pub fn as_terminal(&self) -> Option<&Rc>> { + self.green.as_terminal() + } + + /// Returns if this node is a terminal node with the given terminal kind. + pub fn is_terminal_with_kind(&self, kind: T::TerminalKind) -> bool { + self.as_terminal_with_kind(kind).is_some() + } + + /// Returns the `TerminalNode` with the specific `kind`, or `None` if it is a nonterminal node or it doesn't + /// have the specific kind. + pub fn as_terminal_with_kind(&self, kind: T::TerminalKind) -> Option<&Rc>> { + self.as_terminal().filter(|terminal| terminal.kind == kind) + } + + /// Returns if this node is a terminal node with the given terminal kinds. + pub fn is_terminal_with_kinds(&self, kinds: &[T::TerminalKind]) -> bool { + self.as_terminal_with_kinds(kinds).is_some() + } + + /// Returns the `TerminalNode` with the specific `kinds`, or `None` if it is a nonterminal node or it doesn't + /// have any of the specific kinds. + pub fn as_terminal_with_kinds( + &self, + kinds: &[T::TerminalKind], + ) -> Option<&Rc>> { + self.as_terminal() + .filter(|terminal| kinds.contains(&terminal.kind)) + } + + /// Returns if this node is a terminal node with the trivia kind. + pub fn is_trivia(&self) -> bool { + self.green.is_trivia() + } + + /// Returns true if this node is a nonterminal, or if it's a temrinal with a valid kind (that is, any valid token of + /// the language). + pub fn is_valid(&self) -> bool { + self.green.is_valid() + } + + /// Creates a [`Cursor`] that starts at the current node as the root and a given initial `text_offset`. + pub fn create_cursor(&self, text_offset: TextIndex) -> Cursor { + match &self.green { + Node::Nonterminal(nonterminal_node) => { + Rc::clone(nonterminal_node).create_cursor(text_offset) + } + Node::Terminal(terminal_node) => Rc::clone(terminal_node).create_cursor(text_offset), + } + } +} diff --git a/crates/solidity/outputs/cargo/crate/Cargo.toml b/crates/solidity/outputs/cargo/crate/Cargo.toml index 3f90df0e8b..19687d0819 100644 --- a/crates/solidity/outputs/cargo/crate/Cargo.toml +++ b/crates/solidity/outputs/cargo/crate/Cargo.toml @@ -27,7 +27,7 @@ categories = [ [features] default = [] __private_ariadne_errors = ["dep:ariadne"] -__private_backend_api = ["dep:indexmap"] +__private_backend_api = ["dep:indexmap", "metaslang_cst/syntax"] __private_wasm_apis = [] __private_testing_utils = ["metaslang_bindings/__private_testing_utils"] diff --git a/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs b/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs index 3e597c4cc2..4fe22f932f 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use super::ScopeId; use crate::backend::types::TypeId; -use crate::cst::{NodeId, TerminalNode}; +use crate::cst::{NodeId, SyntaxNode}; ////////////////////////////////////////////////////////////////////////////// // Definitions @@ -36,41 +36,40 @@ pub enum Definition { #[derive(Debug)] pub struct ConstantDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ContractDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub bases: Option>, pub constructor_parameters_scope_id: Option, } #[derive(Debug)] pub struct EnumDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct EnumMemberDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, } #[derive(Debug)] pub struct ErrorDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, } #[derive(Debug)] pub struct EventDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, } @@ -84,50 +83,50 @@ pub enum FunctionVisibility { #[derive(Debug)] pub struct FunctionDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, pub visibility: FunctionVisibility, } #[derive(Debug)] pub struct ImportDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub resolved_file_id: Option, } #[derive(Debug)] pub struct ImportedSymbolDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub symbol: String, pub resolved_file_id: Option, } #[derive(Debug)] pub struct InterfaceDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub bases: Option>, } #[derive(Debug)] pub struct LibraryDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ModifierDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ParameterDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug, Eq, PartialEq)] @@ -139,102 +138,136 @@ pub enum StateVariableVisibility { #[derive(Debug)] pub struct StateVariableDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub getter_type_id: Option, pub visibility: StateVariableVisibility, } #[derive(Debug)] pub struct StructDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct StructMemberDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct TypeParameterDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct UserDefinedValueTypeDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, pub target_type_id: Option, } #[derive(Debug)] pub struct VariableDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulLabelDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulFunctionDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulParameterDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, } #[derive(Debug)] pub struct YulVariableDefinition { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, } impl Definition { + pub fn node(&self) -> Rc { + match self { + Self::Constant(constant_definition) => Rc::clone(&constant_definition.node), + Self::Contract(contract_definition) => Rc::clone(&contract_definition.node), + Self::Enum(enum_definition) => Rc::clone(&enum_definition.node), + Self::EnumMember(enum_member_definition) => Rc::clone(&enum_member_definition.node), + Self::Error(error_definition) => Rc::clone(&error_definition.node), + Self::Event(event_definition) => Rc::clone(&event_definition.node), + Self::Function(function_definition) => Rc::clone(&function_definition.node), + Self::Import(import_definition) => Rc::clone(&import_definition.node), + Self::ImportedSymbol(imported_symbol_definition) => { + Rc::clone(&imported_symbol_definition.node) + } + Self::Interface(interface_definition) => Rc::clone(&interface_definition.node), + Self::Library(library_definition) => Rc::clone(&library_definition.node), + Self::Modifier(modifier_definition) => Rc::clone(&modifier_definition.node), + Self::Parameter(parameter_definition) => Rc::clone(¶meter_definition.node), + Self::StateVariable(state_variable_definition) => { + Rc::clone(&state_variable_definition.node) + } + Self::Struct(struct_definition) => Rc::clone(&struct_definition.node), + Self::StructMember(struct_member_definition) => { + Rc::clone(&struct_member_definition.node) + } + Self::TypeParameter(parameter_definition) => Rc::clone(¶meter_definition.node), + Self::UserDefinedValueType(udvt_definition) => Rc::clone(&udvt_definition.node), + Self::Variable(variable_definition) => Rc::clone(&variable_definition.node), + Self::YulFunction(function_definition) => Rc::clone(&function_definition.node), + Self::YulLabel(label_definition) => Rc::clone(&label_definition.node), + Self::YulParameter(parameter_definition) => Rc::clone(¶meter_definition.node), + Self::YulVariable(variable_definition) => Rc::clone(&variable_definition.node), + } + } + pub fn node_id(&self) -> NodeId { match self { - Self::Constant(constant_definition) => constant_definition.node_id, - Self::Contract(contract_definition) => contract_definition.node_id, - Self::Enum(enum_definition) => enum_definition.node_id, - Self::EnumMember(enum_member_definition) => enum_member_definition.node_id, - Self::Error(error_definition) => error_definition.node_id, - Self::Event(event_definition) => event_definition.node_id, - Self::Function(function_definition) => function_definition.node_id, - Self::Import(import_definition) => import_definition.node_id, - Self::ImportedSymbol(imported_symbol_definition) => imported_symbol_definition.node_id, - Self::Interface(interface_definition) => interface_definition.node_id, - Self::Library(library_definition) => library_definition.node_id, - Self::Modifier(modifier_definition) => modifier_definition.node_id, - Self::Parameter(parameter_definition) => parameter_definition.node_id, - Self::StateVariable(state_variable_definition) => state_variable_definition.node_id, - Self::Struct(struct_definition) => struct_definition.node_id, - Self::StructMember(struct_member_definition) => struct_member_definition.node_id, - Self::TypeParameter(parameter_definition) => parameter_definition.node_id, - Self::UserDefinedValueType(udvt_definition) => udvt_definition.node_id, - Self::Variable(variable_definition) => variable_definition.node_id, - Self::YulFunction(function_definition) => function_definition.node_id, - Self::YulLabel(label_definition) => label_definition.node_id, - Self::YulParameter(parameter_definition) => parameter_definition.node_id, - Self::YulVariable(variable_definition) => variable_definition.node_id, + Self::Constant(constant_definition) => constant_definition.node.id(), + Self::Contract(contract_definition) => contract_definition.node.id(), + Self::Enum(enum_definition) => enum_definition.node.id(), + Self::EnumMember(enum_member_definition) => enum_member_definition.node.id(), + Self::Error(error_definition) => error_definition.node.id(), + Self::Event(event_definition) => event_definition.node.id(), + Self::Function(function_definition) => function_definition.node.id(), + Self::Import(import_definition) => import_definition.node.id(), + Self::ImportedSymbol(imported_symbol_definition) => { + imported_symbol_definition.node.id() + } + Self::Interface(interface_definition) => interface_definition.node.id(), + Self::Library(library_definition) => library_definition.node.id(), + Self::Modifier(modifier_definition) => modifier_definition.node.id(), + Self::Parameter(parameter_definition) => parameter_definition.node.id(), + Self::StateVariable(state_variable_definition) => state_variable_definition.node.id(), + Self::Struct(struct_definition) => struct_definition.node.id(), + Self::StructMember(struct_member_definition) => struct_member_definition.node.id(), + Self::TypeParameter(parameter_definition) => parameter_definition.node.id(), + Self::UserDefinedValueType(udvt_definition) => udvt_definition.node.id(), + Self::Variable(variable_definition) => variable_definition.node.id(), + Self::YulFunction(function_definition) => function_definition.node.id(), + Self::YulLabel(label_definition) => label_definition.node.id(), + Self::YulParameter(parameter_definition) => parameter_definition.node.id(), + Self::YulVariable(variable_definition) => variable_definition.node.id(), } } - pub fn identifier(&self) -> &Rc { + pub fn identifier(&self) -> &Rc { match self { Self::Constant(constant_definition) => &constant_definition.identifier, Self::Contract(contract_definition) => &contract_definition.identifier, Self::Enum(enum_definition) => &enum_definition.identifier, - Self::EnumMember(enum_member_definition) => &enum_member_definition.identifier, + Self::EnumMember(enum_member_definition) => &enum_member_definition.node, Self::Error(error_definition) => &error_definition.identifier, Self::Event(event_definition) => &event_definition.identifier, Self::Function(function_definition) => &function_definition.identifier, @@ -252,8 +285,8 @@ impl Definition { Self::Variable(variable_definition) => &variable_definition.identifier, Self::YulFunction(function_definition) => &function_definition.identifier, Self::YulLabel(label_definition) => &label_definition.identifier, - Self::YulParameter(parameter_definition) => ¶meter_definition.identifier, - Self::YulVariable(variable_definition) => &variable_definition.identifier, + Self::YulParameter(parameter_definition) => ¶meter_definition.node, + Self::YulVariable(variable_definition) => &variable_definition.node, } } @@ -291,68 +324,67 @@ impl Definition { } } - pub(crate) fn new_constant(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_constant(node: &Rc, identifier: &Rc) -> Self { Self::Constant(ConstantDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_contract(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_contract(node: &Rc, identifier: &Rc) -> Self { Self::Contract(ContractDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), bases: None, constructor_parameters_scope_id: None, }) } - pub(crate) fn new_enum(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_enum(node: &Rc, identifier: &Rc) -> Self { Self::Enum(EnumDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_enum_member(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_enum_member(node: &Rc) -> Self { Self::EnumMember(EnumMemberDefinition { - node_id, - identifier: Rc::clone(identifier), + node: Rc::clone(node), }) } pub(crate) fn new_error( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, ) -> Self { Self::Error(ErrorDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), parameters_scope_id, }) } pub(crate) fn new_event( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, ) -> Self { Self::Event(EventDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), parameters_scope_id, }) } pub(crate) fn new_function( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, visibility: FunctionVisibility, ) -> Self { Self::Function(FunctionDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), parameters_scope_id, visibility, @@ -360,137 +392,135 @@ impl Definition { } pub(crate) fn new_import( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, resolved_file_id: Option, ) -> Self { Self::Import(ImportDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), resolved_file_id, }) } pub(crate) fn new_imported_symbol( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, symbol: String, resolved_file_id: Option, ) -> Self { Self::ImportedSymbol(ImportedSymbolDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), symbol, resolved_file_id, }) } - pub(crate) fn new_interface(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_interface(node: &Rc, identifier: &Rc) -> Self { Self::Interface(InterfaceDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), bases: None, }) } - pub(crate) fn new_library(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_library(node: &Rc, identifier: &Rc) -> Self { Self::Library(LibraryDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_modifier(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_modifier(node: &Rc, identifier: &Rc) -> Self { Self::Modifier(ModifierDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_parameter(node: &Rc, identifier: &Rc) -> Self { Self::Parameter(ParameterDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } pub(crate) fn new_state_variable( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, visibility: StateVariableVisibility, ) -> Self { Self::StateVariable(StateVariableDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), getter_type_id: None, visibility, }) } - pub(crate) fn new_struct(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_struct(node: &Rc, identifier: &Rc) -> Self { Self::Struct(StructDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_struct_member(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_struct_member(node: &Rc, identifier: &Rc) -> Self { Self::StructMember(StructMemberDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_type_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_type_parameter(node: &Rc, identifier: &Rc) -> Self { Self::TypeParameter(TypeParameterDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } pub(crate) fn new_user_defined_value_type( - node_id: NodeId, - identifier: &Rc, + node: &Rc, + identifier: &Rc, ) -> Self { Self::UserDefinedValueType(UserDefinedValueTypeDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), target_type_id: None, }) } - pub(crate) fn new_variable(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_variable(node: &Rc, identifier: &Rc) -> Self { Self::Variable(VariableDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_function(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_function(node: &Rc, identifier: &Rc) -> Self { Self::YulFunction(YulFunctionDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_label(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_label(node: &Rc, identifier: &Rc) -> Self { Self::YulLabel(YulLabelDefinition { - node_id, + node: Rc::clone(node), identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_parameter(node: &Rc) -> Self { Self::YulParameter(YulParameterDefinition { - node_id, - identifier: Rc::clone(identifier), + node: Rc::clone(node), }) } - pub(crate) fn new_yul_variable(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_variable(node: &Rc) -> Self { Self::YulVariable(YulVariableDefinition { - node_id, - identifier: Rc::clone(identifier), + node: Rc::clone(node), }) } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs index 0ccf76c1eb..f5400e7f21 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs @@ -8,9 +8,8 @@ mod definitions; mod references; mod scopes; -pub use definitions::Definition; -pub(crate) use definitions::{ - ContractDefinition, FunctionVisibility, ImportDefinition, InterfaceDefinition, +pub use definitions::{ + ContractDefinition, Definition, FunctionVisibility, ImportDefinition, InterfaceDefinition, LibraryDefinition, StateVariableVisibility, }; pub use references::{Reference, Resolution}; @@ -649,4 +648,12 @@ impl Binder { _ => None, } } + + // Given the node id of an identifier, it tries to find the unique definition it references. + // Returns `None` if it's not a reference, or it's not to a unique definition. + pub fn navigate_to(&self, node_id: NodeId) -> Option<&Definition> { + self.find_reference_by_identifier_node_id(node_id) + .and_then(|reference| reference.resolution.as_definition_id()) + .and_then(|def_node_id| self.find_definition_by_id(def_node_id)) + } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/binder/references.rs b/crates/solidity/outputs/cargo/crate/src/backend/binder/references.rs index f657bb9457..2f2b00867d 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/references.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/references.rs @@ -1,14 +1,14 @@ use std::rc::Rc; use crate::backend::built_ins::BuiltIn; -use crate::cst::{NodeId, TerminalNode}; +use crate::cst::{NodeId, SyntaxNode}; ////////////////////////////////////////////////////////////////////////////// // References #[derive(Debug)] pub struct Reference { - pub identifier: Rc, + pub identifier: Rc, pub resolution: Resolution, } @@ -38,7 +38,7 @@ impl Reference { self.identifier.id() } - pub(crate) fn new(identifier: Rc, resolution: Resolution) -> Self { + pub(crate) fn new(identifier: Rc, resolution: Resolution) -> Self { Self { identifier, resolution, diff --git a/crates/solidity/outputs/cargo/crate/src/backend/binder/scopes.rs b/crates/solidity/outputs/cargo/crate/src/backend/binder/scopes.rs index 2be23b7a30..65a2838b8d 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/scopes.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/scopes.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use super::definitions::Definition; use super::ScopeId; use crate::backend::types::TypeId; -use crate::cst::{NodeId, TerminalKind, TerminalNode}; +use crate::cst::{NodeId, SyntaxNode, TerminalKind}; ////////////////////////////////////////////////////////////////////////////// // Scopes - types @@ -328,7 +328,7 @@ impl ParametersScope { } } - pub(crate) fn add_parameter(&mut self, identifier: Option<&Rc>, node_id: NodeId) { + pub(crate) fn add_parameter(&mut self, identifier: Option<&Rc>, node_id: NodeId) { self.parameters.push(ParameterDefinition { name: identifier.map(|name| name.unparse()), node_id, diff --git a/crates/solidity/outputs/cargo/crate/src/backend/built_ins.rs b/crates/solidity/outputs/cargo/crate/src/backend/built_ins.rs index 1950aee5a6..afda7ac98a 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/built_ins.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/built_ins.rs @@ -462,8 +462,8 @@ impl<'a> BuiltInsResolver<'a> { }, Definition::UserDefinedValueType(udvt) if self.language_version >= VERSION_0_8_8 => { match symbol { - "wrap" => Some(BuiltIn::Wrap(udvt.node_id)), - "unwrap" => Some(BuiltIn::Unwrap(udvt.node_id)), + "wrap" => Some(BuiltIn::Wrap(udvt.node.id())), + "unwrap" => Some(BuiltIn::Unwrap(udvt.node.id())), _ => None, } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_builder.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_builder.rs.jinja2 index fce781339e..b230b4a621 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_builder.rs.jinja2 +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_builder.rs.jinja2 @@ -7,7 +7,7 @@ #[allow(clippy::wildcard_imports)] use super::nodes::*; use crate::cst::{ - Edge, EdgeLabel, Node, NodeKind, NonterminalKind, NonterminalNode, TerminalKind, TerminalNode, + EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind, }; // @@ -16,13 +16,13 @@ {% for parent_type, sequence in builder.sequences %} {% if not sequence.has_added_fields %} - pub fn build_{{ parent_type | snake_case }}(node: &Rc) -> Option<{{ parent_type }}> + pub fn build_{{ parent_type | snake_case }}(node: Rc) -> Option<{{ parent_type }}> { - assert_nonterminal_kind(node, NonterminalKind::{{ parent_type }}); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::{{ parent_type }}); + let mut helper = ChildrenHelper::new(&node); {% for field in sequence.fields %} {%- if field.is_removed -%} - _ = helper.accept_label(EdgeLabel::{{ field.label | pascal_case }})?; + helper.skip_label(EdgeLabel::{{ field.label | pascal_case }})?; {%- elif field.is_optional -%} let {{ field.label }} = {%- if field.type.kind == "Terminal" -%} @@ -30,8 +30,8 @@ {%- elif field.type.kind == "UniqueTerminal" -%} helper.accept_label(EdgeLabel::{{ field.label | pascal_case }}).is_some() {%- else -%} - helper.accept_label(EdgeLabel::{{ field.label | pascal_case }}).and_then(|node| - build_{{ field.type.name | snake_case }}(nonterminal_node(node)) + helper.accept_label(EdgeLabel::{{ field.label | pascal_case }}).and_then( + build_{{ field.type.name | snake_case }} ) {%- endif -%} ; @@ -41,7 +41,7 @@ terminal_node_cloned(helper.accept_label(EdgeLabel::{{ field.label | pascal_case }})?); {%- else -%} build_{{ field.type.name | snake_case }}( - nonterminal_node(helper.accept_label(EdgeLabel::{{ field.label | pascal_case }})?), + helper.accept_label(EdgeLabel::{{ field.label | pascal_case }})?, )?; {%- endif -%} {%- endif -%} @@ -51,7 +51,7 @@ } Some(Rc::new({{ parent_type }}Struct { - node_id: node.id(), + node, {%- for field in sequence.fields -%} {%- if not field.is_removed -%} {{ field.label }}, @@ -67,13 +67,14 @@ // {% for parent_type, choice in builder.choices %} - pub fn build_{{ parent_type | snake_case }}(node: &Rc) -> Option<{{ parent_type }}> { - assert_nonterminal_kind(node, NonterminalKind::{{ parent_type }}); - let mut helper = ChildrenHelper::new(&node.children); + #[allow(clippy::needless_pass_by_value)] + pub fn build_{{ parent_type | snake_case }}(node: Rc) -> Option<{{ parent_type }}> { + assert_nonterminal_kind(&node, NonterminalKind::{{ parent_type }}); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { {% for type in choice.variants | filter(attribute="kind", value="Nonterminal") -%} - NodeKind::Nonterminal(NonterminalKind::{{ type.name }}) => {{ parent_type }}::{{ type.name }}(build_{{ type.name | snake_case }}(nonterminal_node(variant))?), + NodeKind::Nonterminal(NonterminalKind::{{ type.name }}) => {{ parent_type }}::{{ type.name }}(build_{{ type.name | snake_case }}(variant)?), {%- endfor -%} {% for type in choice.variants | filter(attribute="kind", value="Terminal") -%} @@ -105,19 +106,20 @@ // {% for parent_type, collection in builder.collections %} - pub fn build_{{ parent_type | snake_case }}(node: &Rc) -> Option<{{ parent_type }}> { - assert_nonterminal_kind(node, NonterminalKind::{{ parent_type }}); + #[allow(clippy::needless_pass_by_value)] + pub fn build_{{ parent_type | snake_case }}(node: Rc) -> Option<{{ parent_type }}> { + assert_nonterminal_kind(&node, NonterminalKind::{{ parent_type }}); let mut items = {{ parent_type }}::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { {%- if collection.item_type.is_terminal -%} items.push(terminal_node_cloned(child)); {%- else -%} - if let Some(item) = build_{{ collection.item_type.name | snake_case }}(nonterminal_node(child)) { + if let Some(item) = build_{{ collection.item_type.name | snake_case }}(child) { items.push(item); } {%- endif -%} - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -132,32 +134,27 @@ #[allow(dead_code)] #[inline] - fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { - assert_eq!(node.kind, kind, "expected non-terminal of kind {kind}, got {node:?}"); + fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { + assert_eq!(node.kind(), NodeKind::Nonterminal(kind), "expected non-terminal of kind {kind}, got {node:?}"); } #[allow(dead_code)] #[inline] - fn terminal_node_cloned(node: &Node) -> Rc { - node.as_terminal().map(Rc::clone).expect("expected terminal node") - } - - #[allow(dead_code)] - #[inline] - fn nonterminal_node(node: &Node) -> &Rc { - node.as_nonterminal().expect("expected non-terminal node") + fn terminal_node_cloned(node: Rc) -> Rc { + assert!(node.is_terminal(), "expected terminal node"); + node } struct ChildrenHelper<'a> { - children: &'a Vec, + children: &'a Rc, index: usize, } impl<'a> ChildrenHelper<'a> { - fn new(children: &'a Vec) -> Self { + fn new(children: &'a Rc) -> Self { let mut index = 0; - while index < children.len() { - if !children[index].is_trivia() && children[index].is_valid() { + while index < children.children_count() { + if children.child_is_valid_and_not_trivia(index) { break; } index += 1; @@ -165,26 +162,31 @@ Self { children, index } } - fn accept_label(&mut self, label: EdgeLabel) -> Option<&Node> { - if self.index >= self.children.len() || self.children[self.index].label != label { + fn skip_label(&mut self, label: EdgeLabel) -> Option { + if self.index >= self.children.children_count() || self.children.child_label(self.index) != label { return None; } - let node = &self.children[self.index].node; + let result = self.index; loop { self.index += 1; - if self.index >= self.children.len() || - (!self.children[self.index].is_trivia() && self.children[self.index].is_valid()) { + if self.index >= self.children.children_count() || + self.children.child_is_valid_and_not_trivia(self.index) { break; } } - Some(node) + Some(result) + } + + fn accept_label(&mut self, label: EdgeLabel) -> Option> { + let index = self.skip_label(label)?; + Some(self.children.nth_child(index)) } fn finalize(mut self) -> bool { // skip over trailing trivia and unrecognized nodes - while self.index < self.children.len() { - if !self.children[self.index].is_trivia() && self.children[self.index].is_valid() { + while self.index < self.children.children_count() { + if self.children.child_is_valid_and_not_trivia(self.index) { return false; } self.index += 1; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_index.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_index.rs.jinja2 new file mode 100644 index 0000000000..1c109f6ce9 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_index.rs.jinja2 @@ -0,0 +1,113 @@ +{% macro render_index(language) -%} + {%- set target = model.ir_languages[language].target -%} + use std::rc::Rc; + use std::collections::HashMap; + use crate::cst::SyntaxNode; + use crate::cst::NodeId; + #[allow(clippy::wildcard_imports)] + use super::nodes::*; + + pub enum NodeType { + {%- for parent_type, sequence in target.sequences -%} + {{ parent_type }}({{ parent_type }}), + {% endfor -%} + } + + pub type TreeIndex = HashMap; + + pub trait IntoIr { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option; + } + + {% for parent_type, sequence in target.sequences %} + impl IntoIr<{{ parent_type }}> for {{ parent_type }} { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::{{ parent_type }}(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } + } + {% endfor %} + + // + // Sequences: + // + + {% for parent_type, sequence in target.sequences %} + pub fn register_{{ parent_type | snake_case }}(node: &{{ parent_type }}, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::{{ parent_type }}(Rc::clone(node))); + {% for field in sequence.fields -%} + {%- if not field.type.is_terminal -%} + {%- if field.is_optional -%} + if let Some(ref {{ field.label | snake_case }}) = node.{{ field.label | snake_case }} { + register_{{ field.type.name | snake_case }}({{ field.label }}, tree); + } + {% else -%} + register_{{ field.type.name | snake_case }}(&node.{{ field.label }}, tree); + {%- endif -%} + {%- endif -%} + {%- endfor -%} + } + + {% endfor %} + + // + // Choices: + // + + {% for parent_type, choice in target.choices %} + {%- set nonterminals = choice.variants | filter(attribute="kind", value="Nonterminal") -%} + {%- set unique_terminals = choice.variants | filter(attribute="kind", value="UniqueTerminal") -%} + {%- set non_unique_terminals = choice.variants | filter(attribute="kind", value="Terminal") -%} + {% if nonterminals | length == 0 %} + pub fn register_{{ parent_type | snake_case }}(_node: &{{ parent_type }}, _tree: &mut TreeIndex) {} + {% else %} + pub fn register_{{ parent_type | snake_case }}(node: &{{ parent_type }}, tree: &mut TreeIndex) { + match node { + {% for nonterminal in nonterminals -%} + {{ parent_type }}::{{ nonterminal.name }}(ref {{ nonterminal.name | snake_case }}) => { + register_{{ nonterminal.name | snake_case }}({{ nonterminal.name | snake_case }}, tree); + } + {%- endfor %} + {%- if non_unique_terminals | length > 0 %} + {%- for terminal in non_unique_terminals -%} + {%- if not loop.first -%} | {%- endif -%} + {{ parent_type }}::{{ terminal.name }}(_) + {%- endfor -%} + => {} + {% endif -%} + {%- if unique_terminals | length > 0 %} + {%- for terminal in unique_terminals -%} + {%- if not loop.first -%} | {%- endif -%} + {{ parent_type }}::{{ terminal.name }} + {%- endfor -%} + => {} + {% endif -%} + } + } + {% endif %} + {% endfor %} + + // + // Repeated & Separated + // + + {% for parent_type, collection in target.collections -%} + {%- if collection.item_type.is_terminal %} + #[inline] + fn register_{{ parent_type | snake_case }}(_items: &[Rc], _tree: &mut TreeIndex) {} + {% else %} + #[inline] + fn register_{{ parent_type | snake_case }}(items: &[{{ collection.item_type.name }}], tree: &mut TreeIndex) { + for item in items { + register_{{ collection.item_type.name | snake_case }}(item, tree); + } + } + {% endif -%} + {% endfor %} + +{% endmacro render_index %} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_nodes.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_nodes.rs.jinja2 index dfa8752871..5495ffd936 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_nodes.rs.jinja2 +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_nodes.rs.jinja2 @@ -2,7 +2,7 @@ {%- set target = model.ir_languages[language].target -%} use std::rc::Rc; use std::vec::Vec; - use crate::cst::TerminalNode; + use crate::cst::SyntaxNode; use metaslang_cst::nodes::NodeId; // @@ -14,20 +14,20 @@ #[derive(Debug)] pub struct {{ parent_type }}Struct { - pub node_id: NodeId, + pub node: Rc, {%- for field in sequence.fields %} pub {{ field.label | snake_case }}: {%- if field.type.kind == "Terminal" -%} {%- if field.is_optional -%} - Option>, + Option>, {%- else -%} - Rc, + Rc, {%- endif -%} {%- elif field.type.kind == "UniqueTerminal" -%} {%- if field.is_optional -%} bool, {%- else -%} - Rc, + Rc, {%- endif -%} {%- else -%} {%- if field.is_optional -%} @@ -39,6 +39,12 @@ {% endfor -%} } + impl {{ parent_type }}Struct { + pub fn id(&self) -> NodeId { + self.node.id() + } + } + {% endfor %} // @@ -52,7 +58,7 @@ {{ nonterminal.name }}({{ nonterminal.name }}), {%- endfor -%} {% for terminal in choice.variants | filter(attribute="kind", value="Terminal") -%} - {{ terminal.name }}(Rc), + {{ terminal.name }}(Rc), {%- endfor -%} {% for terminal in choice.variants | filter(attribute="kind", value="UniqueTerminal") -%} {{ terminal.name }}, @@ -67,7 +73,7 @@ {% for parent_type, collection in target.collections %} pub type {{ parent_type }} = Vec< {%- if collection.item_type.is_terminal -%} - Rc + Rc {%- else -%} {{ collection.item_type.name }} {%- endif -%} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_rewriter.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_rewriter.rs.jinja2 index ca1ed72e4c..ef9ba54cc4 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_rewriter.rs.jinja2 +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_rewriter.rs.jinja2 @@ -34,7 +34,7 @@ {%- endfor %} Rc::new({{ parent_type }}Struct { - node_id: source.node_id, + node: Rc::clone(&source.node), {%- for field in sequence.fields -%} {{ field.label }}, {%- endfor %} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_transformer.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_transformer.rs.jinja2 index 9b19d48d18..0140f46ea8 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_transformer.rs.jinja2 +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_transformer.rs.jinja2 @@ -7,7 +7,7 @@ use std::rc::Rc; use super::{input, nodes as output}; #[allow(unused)] - use crate::cst::TerminalNode; + use crate::cst::SyntaxNode; pub trait Transformer { // @@ -41,7 +41,7 @@ {%- endfor %} Rc::new(output::{{ parent_type }}Struct { - node_id: source.node_id, + node: Rc::clone(&source.node), {%- for field in sequence.fields -%} {%- if not field.is_removed -%} {{ field.label }}, @@ -60,7 +60,7 @@ {% for parent_type, collapsed in transformer.collapsed_sequences %} fn transform_{{ parent_type | snake_case }}(&mut self, source: &input::{{ parent_type }}) -> {%- if collapsed.target_type.is_terminal -%} - Rc + Rc {%- else -%} output::{{ collapsed.target_type.name }} {%- endif -%} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_visitor.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_visitor.rs.jinja2 index 5a7fe27203..25c9225859 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_visitor.rs.jinja2 +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_visitor.rs.jinja2 @@ -1,7 +1,7 @@ {% macro render_visitor(language) -%} {%- set target = model.ir_languages[language].target -%} use std::rc::Rc; - use crate::cst::TerminalNode; + use crate::cst::SyntaxNode; #[allow(clippy::wildcard_imports)] use super::nodes::*; @@ -93,7 +93,7 @@ {% for parent_type, collection in target.collections -%} {%- if collection.item_type.is_terminal %} #[inline] - fn accept_{{ parent_type | snake_case }}(items: &Vec>, visitor: &mut impl Visitor) { + fn accept_{{ parent_type | snake_case }}(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_{{ parent_type | snake_case }}(items) { visitor.leave_{{ parent_type | snake_case }}(items); } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/builder.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/builder.generated.rs index b0391ab7b4..42d1393602 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/builder.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/builder.generated.rs @@ -6,331 +6,277 @@ use std::rc::Rc; #[allow(clippy::wildcard_imports)] use super::nodes::*; -use crate::cst::{ - Edge, EdgeLabel, Node, NodeKind, NonterminalKind, NonterminalNode, TerminalKind, TerminalNode, -}; +use crate::cst::{EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind}; // // Sequences: // -pub fn build_source_unit(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::SourceUnit); - let mut helper = ChildrenHelper::new(&node.children); - let members = - build_source_unit_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; +pub fn build_source_unit(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::SourceUnit); + let mut helper = ChildrenHelper::new(&node); + let members = build_source_unit_members(helper.accept_label(EdgeLabel::Members)?)?; if !helper.finalize() { return None; } - Some(Rc::new(SourceUnitStruct { - node_id: node.id(), - members, - })) + Some(Rc::new(SourceUnitStruct { node, members })) } -pub fn build_pragma_directive(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PragmaDirective); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::PragmaKeyword)?; - let pragma = build_pragma(nonterminal_node(helper.accept_label(EdgeLabel::Pragma)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_pragma_directive(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::PragmaDirective); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::PragmaKeyword)?; + let pragma = build_pragma(helper.accept_label(EdgeLabel::Pragma)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(PragmaDirectiveStruct { - node_id: node.id(), - pragma, - })) + Some(Rc::new(PragmaDirectiveStruct { node, pragma })) } -pub fn build_abicoder_pragma(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AbicoderPragma); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::AbicoderKeyword)?; - let version = - build_abicoder_version(nonterminal_node(helper.accept_label(EdgeLabel::Version)?))?; +pub fn build_abicoder_pragma(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AbicoderPragma); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::AbicoderKeyword)?; + let version = build_abicoder_version(helper.accept_label(EdgeLabel::Version)?)?; if !helper.finalize() { return None; } - Some(Rc::new(AbicoderPragmaStruct { - node_id: node.id(), - version, - })) + Some(Rc::new(AbicoderPragmaStruct { node, version })) } -pub fn build_experimental_pragma(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ExperimentalPragma); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ExperimentalKeyword)?; - let feature = - build_experimental_feature(nonterminal_node(helper.accept_label(EdgeLabel::Feature)?))?; +pub fn build_experimental_pragma(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ExperimentalPragma); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ExperimentalKeyword)?; + let feature = build_experimental_feature(helper.accept_label(EdgeLabel::Feature)?)?; if !helper.finalize() { return None; } - Some(Rc::new(ExperimentalPragmaStruct { - node_id: node.id(), - feature, - })) + Some(Rc::new(ExperimentalPragmaStruct { node, feature })) } -pub fn build_version_pragma(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionPragma); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::SolidityKeyword)?; - let sets = - build_version_expression_sets(nonterminal_node(helper.accept_label(EdgeLabel::Sets)?))?; +pub fn build_version_pragma(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionPragma); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::SolidityKeyword)?; + let sets = build_version_expression_sets(helper.accept_label(EdgeLabel::Sets)?)?; if !helper.finalize() { return None; } - Some(Rc::new(VersionPragmaStruct { - node_id: node.id(), - sets, - })) + Some(Rc::new(VersionPragmaStruct { node, sets })) } -pub fn build_version_range(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionRange); - let mut helper = ChildrenHelper::new(&node.children); - let start = build_version_literal(nonterminal_node(helper.accept_label(EdgeLabel::Start)?))?; - _ = helper.accept_label(EdgeLabel::Minus)?; - let end = build_version_literal(nonterminal_node(helper.accept_label(EdgeLabel::End)?))?; +pub fn build_version_range(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionRange); + let mut helper = ChildrenHelper::new(&node); + let start = build_version_literal(helper.accept_label(EdgeLabel::Start)?)?; + helper.skip_label(EdgeLabel::Minus)?; + let end = build_version_literal(helper.accept_label(EdgeLabel::End)?)?; if !helper.finalize() { return None; } - Some(Rc::new(VersionRangeStruct { - node_id: node.id(), - start, - end, - })) + Some(Rc::new(VersionRangeStruct { node, start, end })) } -pub fn build_version_term(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionTerm); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_version_term(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionTerm); + let mut helper = ChildrenHelper::new(&node); let operator = helper .accept_label(EdgeLabel::Operator) - .and_then(|node| build_version_operator(nonterminal_node(node))); - let literal = - build_version_literal(nonterminal_node(helper.accept_label(EdgeLabel::Literal)?))?; + .and_then(build_version_operator); + let literal = build_version_literal(helper.accept_label(EdgeLabel::Literal)?)?; if !helper.finalize() { return None; } Some(Rc::new(VersionTermStruct { - node_id: node.id(), + node, operator, literal, })) } -pub fn build_import_directive(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportDirective); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ImportKeyword)?; - let clause = build_import_clause(nonterminal_node(helper.accept_label(EdgeLabel::Clause)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_import_directive(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ImportDirective); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ImportKeyword)?; + let clause = build_import_clause(helper.accept_label(EdgeLabel::Clause)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ImportDirectiveStruct { - node_id: node.id(), - clause, - })) + Some(Rc::new(ImportDirectiveStruct { node, clause })) } -pub fn build_path_import(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PathImport); - let mut helper = ChildrenHelper::new(&node.children); - let path = build_string_literal(nonterminal_node(helper.accept_label(EdgeLabel::Path)?))?; +pub fn build_path_import(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::PathImport); + let mut helper = ChildrenHelper::new(&node); + let path = build_string_literal(helper.accept_label(EdgeLabel::Path)?)?; let alias = helper .accept_label(EdgeLabel::Alias) - .and_then(|node| build_import_alias(nonterminal_node(node))); + .and_then(build_import_alias); if !helper.finalize() { return None; } - Some(Rc::new(PathImportStruct { - node_id: node.id(), - path, - alias, - })) + Some(Rc::new(PathImportStruct { node, path, alias })) } -pub fn build_named_import(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NamedImport); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Asterisk)?; - let alias = build_import_alias(nonterminal_node(helper.accept_label(EdgeLabel::Alias)?))?; - _ = helper.accept_label(EdgeLabel::FromKeyword)?; - let path = build_string_literal(nonterminal_node(helper.accept_label(EdgeLabel::Path)?))?; +pub fn build_named_import(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NamedImport); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Asterisk)?; + let alias = build_import_alias(helper.accept_label(EdgeLabel::Alias)?)?; + helper.skip_label(EdgeLabel::FromKeyword)?; + let path = build_string_literal(helper.accept_label(EdgeLabel::Path)?)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedImportStruct { - node_id: node.id(), - alias, - path, - })) + Some(Rc::new(NamedImportStruct { node, alias, path })) } -pub fn build_import_deconstruction(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportDeconstruction); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let symbols = build_import_deconstruction_symbols(nonterminal_node( - helper.accept_label(EdgeLabel::Symbols)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; - _ = helper.accept_label(EdgeLabel::FromKeyword)?; - let path = build_string_literal(nonterminal_node(helper.accept_label(EdgeLabel::Path)?))?; +pub fn build_import_deconstruction(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ImportDeconstruction); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBrace)?; + let symbols = build_import_deconstruction_symbols(helper.accept_label(EdgeLabel::Symbols)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::FromKeyword)?; + let path = build_string_literal(helper.accept_label(EdgeLabel::Path)?)?; if !helper.finalize() { return None; } Some(Rc::new(ImportDeconstructionStruct { - node_id: node.id(), + node, symbols, path, })) } pub fn build_import_deconstruction_symbol( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportDeconstructionSymbol); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::ImportDeconstructionSymbol); + let mut helper = ChildrenHelper::new(&node); let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); let alias = helper .accept_label(EdgeLabel::Alias) - .and_then(|node| build_import_alias(nonterminal_node(node))); + .and_then(build_import_alias); if !helper.finalize() { return None; } Some(Rc::new(ImportDeconstructionSymbolStruct { - node_id: node.id(), + node, name, alias, })) } -pub fn build_import_alias(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportAlias); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::AsKeyword)?; +pub fn build_import_alias(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ImportAlias); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::AsKeyword)?; let identifier = terminal_node_cloned(helper.accept_label(EdgeLabel::Identifier)?); if !helper.finalize() { return None; } - Some(Rc::new(ImportAliasStruct { - node_id: node.id(), - identifier, - })) + Some(Rc::new(ImportAliasStruct { node, identifier })) } -pub fn build_using_directive(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingDirective); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::UsingKeyword)?; - let clause = build_using_clause(nonterminal_node(helper.accept_label(EdgeLabel::Clause)?))?; - _ = helper.accept_label(EdgeLabel::ForKeyword)?; - let target = build_using_target(nonterminal_node(helper.accept_label(EdgeLabel::Target)?))?; +pub fn build_using_directive(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingDirective); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::UsingKeyword)?; + let clause = build_using_clause(helper.accept_label(EdgeLabel::Clause)?)?; + helper.skip_label(EdgeLabel::ForKeyword)?; + let target = build_using_target(helper.accept_label(EdgeLabel::Target)?)?; let global_keyword = helper.accept_label(EdgeLabel::GlobalKeyword).is_some(); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(UsingDirectiveStruct { - node_id: node.id(), + node, clause, target, global_keyword, })) } -pub fn build_using_deconstruction(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingDeconstruction); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let symbols = build_using_deconstruction_symbols(nonterminal_node( - helper.accept_label(EdgeLabel::Symbols)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; +pub fn build_using_deconstruction(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingDeconstruction); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBrace)?; + let symbols = build_using_deconstruction_symbols(helper.accept_label(EdgeLabel::Symbols)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(UsingDeconstructionStruct { - node_id: node.id(), - symbols, - })) + Some(Rc::new(UsingDeconstructionStruct { node, symbols })) } pub fn build_using_deconstruction_symbol( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingDeconstructionSymbol); - let mut helper = ChildrenHelper::new(&node.children); - let name = build_identifier_path(nonterminal_node(helper.accept_label(EdgeLabel::Name)?))?; + assert_nonterminal_kind(&node, NonterminalKind::UsingDeconstructionSymbol); + let mut helper = ChildrenHelper::new(&node); + let name = build_identifier_path(helper.accept_label(EdgeLabel::Name)?)?; let alias = helper .accept_label(EdgeLabel::Alias) - .and_then(|node| build_using_alias(nonterminal_node(node))); + .and_then(build_using_alias); if !helper.finalize() { return None; } Some(Rc::new(UsingDeconstructionSymbolStruct { - node_id: node.id(), + node, name, alias, })) } -pub fn build_using_alias(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingAlias); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::AsKeyword)?; - let operator = - build_using_operator(nonterminal_node(helper.accept_label(EdgeLabel::Operator)?))?; +pub fn build_using_alias(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingAlias); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::AsKeyword)?; + let operator = build_using_operator(helper.accept_label(EdgeLabel::Operator)?)?; if !helper.finalize() { return None; } - Some(Rc::new(UsingAliasStruct { - node_id: node.id(), - operator, - })) + Some(Rc::new(UsingAliasStruct { node, operator })) } -pub fn build_contract_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContractDefinition); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_contract_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContractDefinition); + let mut helper = ChildrenHelper::new(&node); let abstract_keyword = helper.accept_label(EdgeLabel::AbstractKeyword).is_some(); - _ = helper.accept_label(EdgeLabel::ContractKeyword)?; + helper.skip_label(EdgeLabel::ContractKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - let specifiers = build_contract_specifiers(nonterminal_node( - helper.accept_label(EdgeLabel::Specifiers)?, - ))?; - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = - build_contract_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + let specifiers = build_contract_specifiers(helper.accept_label(EdgeLabel::Specifiers)?)?; + helper.skip_label(EdgeLabel::OpenBrace)?; + let members = build_contract_members(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(ContractDefinitionStruct { - node_id: node.id(), + node, abstract_keyword, name, specifiers, @@ -338,200 +284,183 @@ pub fn build_contract_definition(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InheritanceSpecifier); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::IsKeyword)?; - let types = build_inheritance_types(nonterminal_node(helper.accept_label(EdgeLabel::Types)?))?; +pub fn build_inheritance_specifier(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InheritanceSpecifier); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::IsKeyword)?; + let types = build_inheritance_types(helper.accept_label(EdgeLabel::Types)?)?; if !helper.finalize() { return None; } - Some(Rc::new(InheritanceSpecifierStruct { - node_id: node.id(), - types, - })) + Some(Rc::new(InheritanceSpecifierStruct { node, types })) } -pub fn build_inheritance_type(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InheritanceType); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = - build_identifier_path(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_inheritance_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InheritanceType); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_identifier_path(helper.accept_label(EdgeLabel::TypeName)?)?; let arguments = helper .accept_label(EdgeLabel::Arguments) - .and_then(|node| build_arguments_declaration(nonterminal_node(node))); + .and_then(build_arguments_declaration); if !helper.finalize() { return None; } Some(Rc::new(InheritanceTypeStruct { - node_id: node.id(), + node, type_name, arguments, })) } -pub fn build_storage_layout_specifier( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StorageLayoutSpecifier); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::LayoutKeyword)?; - _ = helper.accept_label(EdgeLabel::AtKeyword)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; +pub fn build_storage_layout_specifier(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StorageLayoutSpecifier); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::LayoutKeyword)?; + helper.skip_label(EdgeLabel::AtKeyword)?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } - Some(Rc::new(StorageLayoutSpecifierStruct { - node_id: node.id(), - expression, - })) + Some(Rc::new(StorageLayoutSpecifierStruct { node, expression })) } -pub fn build_interface_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InterfaceDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::InterfaceKeyword)?; +pub fn build_interface_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InterfaceDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::InterfaceKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); let inheritance = helper .accept_label(EdgeLabel::Inheritance) - .and_then(|node| build_inheritance_specifier(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = - build_interface_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + .and_then(build_inheritance_specifier); + helper.skip_label(EdgeLabel::OpenBrace)?; + let members = build_interface_members(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(InterfaceDefinitionStruct { - node_id: node.id(), + node, name, inheritance, members, })) } -pub fn build_library_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::LibraryDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::LibraryKeyword)?; +pub fn build_library_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::LibraryDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::LibraryKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = - build_library_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; + let members = build_library_members(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(LibraryDefinitionStruct { - node_id: node.id(), + node, name, members, })) } -pub fn build_struct_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StructDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::StructKeyword)?; +pub fn build_struct_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StructDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::StructKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = build_struct_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; + let members = build_struct_members(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(StructDefinitionStruct { - node_id: node.id(), + node, name, members, })) } -pub fn build_struct_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StructMember); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_struct_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StructMember); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(StructMemberStruct { - node_id: node.id(), + node, type_name, name, })) } -pub fn build_enum_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EnumDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::EnumKeyword)?; +pub fn build_enum_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EnumDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::EnumKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = build_enum_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; + let members = build_enum_members(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(EnumDefinitionStruct { - node_id: node.id(), + node, name, members, })) } -pub fn build_constant_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConstantDefinition); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; - _ = helper.accept_label(EdgeLabel::ConstantKeyword)?; +pub fn build_constant_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ConstantDefinition); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; + helper.skip_label(EdgeLabel::ConstantKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::Equal)?; - let value = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Value)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Equal)?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ConstantDefinitionStruct { - node_id: node.id(), + node, type_name, name, value, })) } -pub fn build_state_variable_definition( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StateVariableDefinition); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; - let attributes = build_state_variable_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; +pub fn build_state_variable_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StateVariableDefinition); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; + let attributes = build_state_variable_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); let value = helper .accept_label(EdgeLabel::Value) - .and_then(|node| build_state_variable_definition_value(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + .and_then(build_state_variable_definition_value); + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(StateVariableDefinitionStruct { - node_id: node.id(), + node, type_name, attributes, name, @@ -540,43 +469,36 @@ pub fn build_state_variable_definition( } pub fn build_state_variable_definition_value( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StateVariableDefinitionValue); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Equal)?; - let value = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Value)?))?; + assert_nonterminal_kind(&node, NonterminalKind::StateVariableDefinitionValue); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Equal)?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; if !helper.finalize() { return None; } - Some(Rc::new(StateVariableDefinitionValueStruct { - node_id: node.id(), - value, - })) + Some(Rc::new(StateVariableDefinitionValueStruct { node, value })) } -pub fn build_function_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::FunctionKeyword)?; - let name = build_function_name(nonterminal_node(helper.accept_label(EdgeLabel::Name)?))?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_function_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; +pub fn build_function_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::FunctionKeyword)?; + let name = build_function_name(helper.accept_label(EdgeLabel::Name)?)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = build_function_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; let returns = helper .accept_label(EdgeLabel::Returns) - .and_then(|node| build_returns_declaration(nonterminal_node(node))); - let body = build_function_body(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_returns_declaration); + let body = build_function_body(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(FunctionDefinitionStruct { - node_id: node.id(), + node, name, parameters, attributes, @@ -585,31 +507,26 @@ pub fn build_function_definition(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_parameters_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ParametersDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let parameters = build_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(ParametersDeclarationStruct { - node_id: node.id(), - parameters, - })) + Some(Rc::new(ParametersDeclarationStruct { node, parameters })) } -pub fn build_parameter(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Parameter); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_parameter(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Parameter); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let storage_location = helper .accept_label(EdgeLabel::StorageLocation) - .and_then(|node| build_storage_location(nonterminal_node(node))); + .and_then(build_storage_location); let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -618,81 +535,65 @@ pub fn build_parameter(node: &Rc) -> Option { } Some(Rc::new(ParameterStruct { - node_id: node.id(), + node, type_name, storage_location, name, })) } -pub fn build_override_specifier(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::OverrideSpecifier); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OverrideKeyword)?; +pub fn build_override_specifier(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::OverrideSpecifier); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OverrideKeyword)?; let overridden = helper .accept_label(EdgeLabel::Overridden) - .and_then(|node| build_override_paths_declaration(nonterminal_node(node))); + .and_then(build_override_paths_declaration); if !helper.finalize() { return None; } - Some(Rc::new(OverrideSpecifierStruct { - node_id: node.id(), - overridden, - })) + Some(Rc::new(OverrideSpecifierStruct { node, overridden })) } -pub fn build_override_paths_declaration( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::OverridePathsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let paths = build_override_paths(nonterminal_node(helper.accept_label(EdgeLabel::Paths)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_override_paths_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::OverridePathsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let paths = build_override_paths(helper.accept_label(EdgeLabel::Paths)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(OverridePathsDeclarationStruct { - node_id: node.id(), - paths, - })) + Some(Rc::new(OverridePathsDeclarationStruct { node, paths })) } -pub fn build_returns_declaration(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ReturnsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ReturnsKeyword)?; - let variables = - build_parameters_declaration(nonterminal_node(helper.accept_label(EdgeLabel::Variables)?))?; +pub fn build_returns_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ReturnsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ReturnsKeyword)?; + let variables = build_parameters_declaration(helper.accept_label(EdgeLabel::Variables)?)?; if !helper.finalize() { return None; } - Some(Rc::new(ReturnsDeclarationStruct { - node_id: node.id(), - variables, - })) + Some(Rc::new(ReturnsDeclarationStruct { node, variables })) } -pub fn build_constructor_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConstructorDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ConstructorKeyword)?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_constructor_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; - let body = build_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_constructor_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ConstructorDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ConstructorKeyword)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = build_constructor_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; + let body = build_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ConstructorDefinitionStruct { - node_id: node.id(), + node, parameters, attributes, body, @@ -700,24 +601,21 @@ pub fn build_constructor_definition(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::FunctionKeyword)?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_unnamed_function_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; - let body = build_function_body(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + assert_nonterminal_kind(&node, NonterminalKind::UnnamedFunctionDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::FunctionKeyword)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = + build_unnamed_function_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; + let body = build_function_body(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(UnnamedFunctionDefinitionStruct { - node_id: node.id(), + node, parameters, attributes, body, @@ -725,27 +623,24 @@ pub fn build_unnamed_function_definition( } pub fn build_fallback_function_definition( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FallbackFunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::FallbackKeyword)?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_fallback_function_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; + assert_nonterminal_kind(&node, NonterminalKind::FallbackFunctionDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::FallbackKeyword)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = + build_fallback_function_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; let returns = helper .accept_label(EdgeLabel::Returns) - .and_then(|node| build_returns_declaration(nonterminal_node(node))); - let body = build_function_body(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_returns_declaration); + let body = build_function_body(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(FallbackFunctionDefinitionStruct { - node_id: node.id(), + node, parameters, attributes, returns, @@ -754,48 +649,43 @@ pub fn build_fallback_function_definition( } pub fn build_receive_function_definition( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ReceiveFunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ReceiveKeyword)?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_receive_function_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; - let body = build_function_body(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + assert_nonterminal_kind(&node, NonterminalKind::ReceiveFunctionDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ReceiveKeyword)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = + build_receive_function_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; + let body = build_function_body(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ReceiveFunctionDefinitionStruct { - node_id: node.id(), + node, parameters, attributes, body, })) } -pub fn build_modifier_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ModifierDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ModifierKeyword)?; +pub fn build_modifier_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ModifierDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ModifierKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); let parameters = helper .accept_label(EdgeLabel::Parameters) - .and_then(|node| build_parameters_declaration(nonterminal_node(node))); - let attributes = build_modifier_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; - let body = build_function_body(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_parameters_declaration); + let attributes = build_modifier_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; + let body = build_function_body(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ModifierDefinitionStruct { - node_id: node.id(), + node, name, parameters, attributes, @@ -803,40 +693,39 @@ pub fn build_modifier_definition(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ModifierInvocation); - let mut helper = ChildrenHelper::new(&node.children); - let name = build_identifier_path(nonterminal_node(helper.accept_label(EdgeLabel::Name)?))?; +pub fn build_modifier_invocation(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ModifierInvocation); + let mut helper = ChildrenHelper::new(&node); + let name = build_identifier_path(helper.accept_label(EdgeLabel::Name)?)?; let arguments = helper .accept_label(EdgeLabel::Arguments) - .and_then(|node| build_arguments_declaration(nonterminal_node(node))); + .and_then(build_arguments_declaration); if !helper.finalize() { return None; } Some(Rc::new(ModifierInvocationStruct { - node_id: node.id(), + node, name, arguments, })) } -pub fn build_event_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::EventKeyword)?; +pub fn build_event_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EventDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::EventKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - let parameters = build_event_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = + build_event_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; let anonymous_keyword = helper.accept_label(EdgeLabel::AnonymousKeyword).is_some(); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(EventDefinitionStruct { - node_id: node.id(), + node, name, parameters, anonymous_keyword, @@ -844,29 +733,27 @@ pub fn build_event_definition(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_event_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + assert_nonterminal_kind(&node, NonterminalKind::EventParametersDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let parameters = build_event_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(EventParametersDeclarationStruct { - node_id: node.id(), + node, parameters, })) } -pub fn build_event_parameter(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventParameter); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_event_parameter(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EventParameter); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let indexed_keyword = helper.accept_label(EdgeLabel::IndexedKeyword).is_some(); let name = helper .accept_label(EdgeLabel::Name) @@ -876,7 +763,7 @@ pub fn build_event_parameter(node: &Rc) -> Option) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UserDefinedValueTypeDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::TypeKeyword)?; + assert_nonterminal_kind(&node, NonterminalKind::UserDefinedValueTypeDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::TypeKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::IsKeyword)?; - let value_type = - build_elementary_type(nonterminal_node(helper.accept_label(EdgeLabel::ValueType)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::IsKeyword)?; + let value_type = build_elementary_type(helper.accept_label(EdgeLabel::ValueType)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(UserDefinedValueTypeDefinitionStruct { - node_id: node.id(), + node, name, value_type, })) } -pub fn build_error_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ErrorDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ErrorKeyword)?; +pub fn build_error_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ErrorDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ErrorKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - let members = build_error_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Members)?, - ))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + let members = build_error_parameters_declaration(helper.accept_label(EdgeLabel::Members)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorDefinitionStruct { - node_id: node.id(), + node, name, members, })) } pub fn build_error_parameters_declaration( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ErrorParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_error_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + assert_nonterminal_kind(&node, NonterminalKind::ErrorParametersDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let parameters = build_error_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorParametersDeclarationStruct { - node_id: node.id(), + node, parameters, })) } -pub fn build_error_parameter(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ErrorParameter); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_error_parameter(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ErrorParameter); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -957,83 +839,77 @@ pub fn build_error_parameter(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ArrayTypeName); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::OpenBracket)?; +pub fn build_array_type_name(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ArrayTypeName); + let mut helper = ChildrenHelper::new(&node); + let operand = build_type_name(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::OpenBracket)?; let index = helper .accept_label(EdgeLabel::Index) - .and_then(|node| build_expression(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::CloseBracket)?; + .and_then(build_expression); + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(ArrayTypeNameStruct { - node_id: node.id(), + node, operand, index, })) } -pub fn build_function_type(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionType); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::FunctionKeyword)?; - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - let attributes = build_function_type_attributes(nonterminal_node( - helper.accept_label(EdgeLabel::Attributes)?, - ))?; +pub fn build_function_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionType); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::FunctionKeyword)?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; + let attributes = build_function_type_attributes(helper.accept_label(EdgeLabel::Attributes)?)?; let returns = helper .accept_label(EdgeLabel::Returns) - .and_then(|node| build_returns_declaration(nonterminal_node(node))); + .and_then(build_returns_declaration); if !helper.finalize() { return None; } Some(Rc::new(FunctionTypeStruct { - node_id: node.id(), + node, parameters, attributes, returns, })) } -pub fn build_mapping_type(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MappingType); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::MappingKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let key_type = build_mapping_key(nonterminal_node(helper.accept_label(EdgeLabel::KeyType)?))?; - _ = helper.accept_label(EdgeLabel::EqualGreaterThan)?; - let value_type = - build_mapping_value(nonterminal_node(helper.accept_label(EdgeLabel::ValueType)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_mapping_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MappingType); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::MappingKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let key_type = build_mapping_key(helper.accept_label(EdgeLabel::KeyType)?)?; + helper.skip_label(EdgeLabel::EqualGreaterThan)?; + let value_type = build_mapping_value(helper.accept_label(EdgeLabel::ValueType)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(MappingTypeStruct { - node_id: node.id(), + node, key_type, value_type, })) } -pub fn build_mapping_key(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MappingKey); - let mut helper = ChildrenHelper::new(&node.children); - let key_type = - build_mapping_key_type(nonterminal_node(helper.accept_label(EdgeLabel::KeyType)?))?; +pub fn build_mapping_key(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MappingKey); + let mut helper = ChildrenHelper::new(&node); + let key_type = build_mapping_key_type(helper.accept_label(EdgeLabel::KeyType)?)?; let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -1042,16 +918,16 @@ pub fn build_mapping_key(node: &Rc) -> Option { } Some(Rc::new(MappingKeyStruct { - node_id: node.id(), + node, key_type, name, })) } -pub fn build_mapping_value(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MappingValue); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_mapping_value(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MappingValue); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -1060,140 +936,118 @@ pub fn build_mapping_value(node: &Rc) -> Option { } Some(Rc::new(MappingValueStruct { - node_id: node.id(), + node, type_name, name, })) } -pub fn build_address_type(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AddressType); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::AddressKeyword)?; +pub fn build_address_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AddressType); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::AddressKeyword)?; let payable_keyword = helper.accept_label(EdgeLabel::PayableKeyword).is_some(); if !helper.finalize() { return None; } Some(Rc::new(AddressTypeStruct { - node_id: node.id(), + node, payable_keyword, })) } -pub fn build_block(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Block); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let statements = build_statements(nonterminal_node( - helper.accept_label(EdgeLabel::Statements)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; +pub fn build_block(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Block); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBrace)?; + let statements = build_statements(helper.accept_label(EdgeLabel::Statements)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(BlockStruct { - node_id: node.id(), - statements, - })) + Some(Rc::new(BlockStruct { node, statements })) } -pub fn build_unchecked_block(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UncheckedBlock); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::UncheckedKeyword)?; - let block = build_block(nonterminal_node(helper.accept_label(EdgeLabel::Block)?))?; +pub fn build_unchecked_block(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UncheckedBlock); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::UncheckedKeyword)?; + let block = build_block(helper.accept_label(EdgeLabel::Block)?)?; if !helper.finalize() { return None; } - Some(Rc::new(UncheckedBlockStruct { - node_id: node.id(), - block, - })) + Some(Rc::new(UncheckedBlockStruct { node, block })) } -pub fn build_expression_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ExpressionStatement); - let mut helper = ChildrenHelper::new(&node.children); - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_expression_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ExpressionStatement); + let mut helper = ChildrenHelper::new(&node); + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ExpressionStatementStruct { - node_id: node.id(), - expression, - })) + Some(Rc::new(ExpressionStatementStruct { node, expression })) } -pub fn build_assembly_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AssemblyStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::AssemblyKeyword)?; +pub fn build_assembly_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AssemblyStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::AssemblyKeyword)?; let label = helper .accept_label(EdgeLabel::Label) - .and_then(|node| build_string_literal(nonterminal_node(node))); + .and_then(build_string_literal); let flags = helper .accept_label(EdgeLabel::Flags) - .and_then(|node| build_assembly_flags_declaration(nonterminal_node(node))); - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_assembly_flags_declaration); + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(AssemblyStatementStruct { - node_id: node.id(), + node, label, flags, body, })) } -pub fn build_assembly_flags_declaration( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AssemblyFlagsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let flags = build_assembly_flags(nonterminal_node(helper.accept_label(EdgeLabel::Flags)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_assembly_flags_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AssemblyFlagsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let flags = build_assembly_flags(helper.accept_label(EdgeLabel::Flags)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(AssemblyFlagsDeclarationStruct { - node_id: node.id(), - flags, - })) + Some(Rc::new(AssemblyFlagsDeclarationStruct { node, flags })) } pub fn build_tuple_deconstruction_statement( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleDeconstructionStatement); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::TupleDeconstructionStatement); + let mut helper = ChildrenHelper::new(&node); let var_keyword = helper.accept_label(EdgeLabel::VarKeyword).is_some(); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let elements = build_tuple_deconstruction_elements(nonterminal_node( - helper.accept_label(EdgeLabel::Elements)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - _ = helper.accept_label(EdgeLabel::Equal)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let elements = build_tuple_deconstruction_elements(helper.accept_label(EdgeLabel::Elements)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::Equal)?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(TupleDeconstructionStatementStruct { - node_id: node.id(), + node, var_keyword, elements, expression, @@ -1201,83 +1055,79 @@ pub fn build_tuple_deconstruction_statement( } pub fn build_tuple_deconstruction_element( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleDeconstructionElement); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::TupleDeconstructionElement); + let mut helper = ChildrenHelper::new(&node); let member = helper .accept_label(EdgeLabel::Member) - .and_then(|node| build_tuple_member(nonterminal_node(node))); + .and_then(build_tuple_member); if !helper.finalize() { return None; } - Some(Rc::new(TupleDeconstructionElementStruct { - node_id: node.id(), - member, - })) + Some(Rc::new(TupleDeconstructionElementStruct { node, member })) } -pub fn build_typed_tuple_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TypedTupleMember); - let mut helper = ChildrenHelper::new(&node.children); - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_typed_tuple_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TypedTupleMember); + let mut helper = ChildrenHelper::new(&node); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let storage_location = helper .accept_label(EdgeLabel::StorageLocation) - .and_then(|node| build_storage_location(nonterminal_node(node))); + .and_then(build_storage_location); let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); if !helper.finalize() { return None; } Some(Rc::new(TypedTupleMemberStruct { - node_id: node.id(), + node, type_name, storage_location, name, })) } -pub fn build_untyped_tuple_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UntypedTupleMember); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_untyped_tuple_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UntypedTupleMember); + let mut helper = ChildrenHelper::new(&node); let storage_location = helper .accept_label(EdgeLabel::StorageLocation) - .and_then(|node| build_storage_location(nonterminal_node(node))); + .and_then(build_storage_location); let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); if !helper.finalize() { return None; } Some(Rc::new(UntypedTupleMemberStruct { - node_id: node.id(), + node, storage_location, name, })) } pub fn build_variable_declaration_statement( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationStatement); - let mut helper = ChildrenHelper::new(&node.children); - let variable_type = build_variable_declaration_type(nonterminal_node( - helper.accept_label(EdgeLabel::VariableType)?, - ))?; + assert_nonterminal_kind(&node, NonterminalKind::VariableDeclarationStatement); + let mut helper = ChildrenHelper::new(&node); + let variable_type = + build_variable_declaration_type(helper.accept_label(EdgeLabel::VariableType)?)?; let storage_location = helper .accept_label(EdgeLabel::StorageLocation) - .and_then(|node| build_storage_location(nonterminal_node(node))); + .and_then(build_storage_location); let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); let value = helper .accept_label(EdgeLabel::Value) - .and_then(|node| build_variable_declaration_value(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + .and_then(build_variable_declaration_value); + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(VariableDeclarationStatementStruct { - node_id: node.id(), + node, variable_type, storage_location, name, @@ -1285,85 +1135,72 @@ pub fn build_variable_declaration_statement( })) } -pub fn build_variable_declaration_value( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationValue); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Equal)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; +pub fn build_variable_declaration_value(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VariableDeclarationValue); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Equal)?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } - Some(Rc::new(VariableDeclarationValueStruct { - node_id: node.id(), - expression, - })) + Some(Rc::new(VariableDeclarationValueStruct { node, expression })) } -pub fn build_if_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::IfStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::IfKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let condition = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Condition)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_if_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::IfStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::IfKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; let else_branch = helper .accept_label(EdgeLabel::ElseBranch) - .and_then(|node| build_else_branch(nonterminal_node(node))); + .and_then(build_else_branch); if !helper.finalize() { return None; } Some(Rc::new(IfStatementStruct { - node_id: node.id(), + node, condition, body, else_branch, })) } -pub fn build_else_branch(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ElseBranch); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ElseKeyword)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_else_branch(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ElseBranch); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ElseKeyword)?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } - Some(Rc::new(ElseBranchStruct { - node_id: node.id(), - body, - })) + Some(Rc::new(ElseBranchStruct { node, body })) } -pub fn build_for_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ForStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ForKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let initialization = build_for_statement_initialization(nonterminal_node( - helper.accept_label(EdgeLabel::Initialization)?, - ))?; - let condition = build_for_statement_condition(nonterminal_node( - helper.accept_label(EdgeLabel::Condition)?, - ))?; +pub fn build_for_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ForStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ForKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let initialization = + build_for_statement_initialization(helper.accept_label(EdgeLabel::Initialization)?)?; + let condition = build_for_statement_condition(helper.accept_label(EdgeLabel::Condition)?)?; let iterator = helper .accept_label(EdgeLabel::Iterator) - .and_then(|node| build_expression(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_expression); + helper.skip_label(EdgeLabel::CloseParen)?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ForStatementStruct { - node_id: node.id(), + node, initialization, condition, iterator, @@ -1371,127 +1208,119 @@ pub fn build_for_statement(node: &Rc) -> Option { })) } -pub fn build_while_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::WhileStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::WhileKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let condition = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Condition)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_while_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::WhileStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::WhileKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(WhileStatementStruct { - node_id: node.id(), + node, condition, body, })) } -pub fn build_do_while_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::DoWhileStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::DoKeyword)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; - _ = helper.accept_label(EdgeLabel::WhileKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let condition = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Condition)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_do_while_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::DoWhileStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::DoKeyword)?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; + helper.skip_label(EdgeLabel::WhileKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(DoWhileStatementStruct { - node_id: node.id(), + node, body, condition, })) } -pub fn build_continue_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContinueStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ContinueKeyword)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_continue_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContinueStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ContinueKeyword)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ContinueStatementStruct { node_id: node.id() })) + Some(Rc::new(ContinueStatementStruct { node })) } -pub fn build_break_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::BreakStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::BreakKeyword)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_break_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::BreakStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::BreakKeyword)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(BreakStatementStruct { node_id: node.id() })) + Some(Rc::new(BreakStatementStruct { node })) } -pub fn build_return_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ReturnStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ReturnKeyword)?; +pub fn build_return_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ReturnStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ReturnKeyword)?; let expression = helper .accept_label(EdgeLabel::Expression) - .and_then(|node| build_expression(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + .and_then(build_expression); + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ReturnStatementStruct { - node_id: node.id(), - expression, - })) + Some(Rc::new(ReturnStatementStruct { node, expression })) } -pub fn build_emit_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EmitStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::EmitKeyword)?; - let event = build_identifier_path(nonterminal_node(helper.accept_label(EdgeLabel::Event)?))?; - let arguments = - build_arguments_declaration(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_emit_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EmitStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::EmitKeyword)?; + let event = build_identifier_path(helper.accept_label(EdgeLabel::Event)?)?; + let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(EmitStatementStruct { - node_id: node.id(), + node, event, arguments, })) } -pub fn build_try_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TryStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::TryKeyword)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; +pub fn build_try_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TryStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::TryKeyword)?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; let returns = helper .accept_label(EdgeLabel::Returns) - .and_then(|node| build_returns_declaration(nonterminal_node(node))); - let body = build_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; - let catch_clauses = build_catch_clauses(nonterminal_node( - helper.accept_label(EdgeLabel::CatchClauses)?, - ))?; + .and_then(build_returns_declaration); + let body = build_block(helper.accept_label(EdgeLabel::Body)?)?; + let catch_clauses = build_catch_clauses(helper.accept_label(EdgeLabel::CatchClauses)?)?; if !helper.finalize() { return None; } Some(Rc::new(TryStatementStruct { - node_id: node.id(), + node, expression, returns, body, @@ -1499,721 +1328,614 @@ pub fn build_try_statement(node: &Rc) -> Option { })) } -pub fn build_catch_clause(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CatchClause); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::CatchKeyword)?; +pub fn build_catch_clause(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::CatchClause); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::CatchKeyword)?; let error = helper .accept_label(EdgeLabel::Error) - .and_then(|node| build_catch_clause_error(nonterminal_node(node))); - let body = build_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_catch_clause_error); + let body = build_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } - Some(Rc::new(CatchClauseStruct { - node_id: node.id(), - error, - body, - })) + Some(Rc::new(CatchClauseStruct { node, error, body })) } -pub fn build_catch_clause_error(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CatchClauseError); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_catch_clause_error(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::CatchClauseError); + let mut helper = ChildrenHelper::new(&node); let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); - let parameters = build_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; if !helper.finalize() { return None; } Some(Rc::new(CatchClauseErrorStruct { - node_id: node.id(), + node, name, parameters, })) } -pub fn build_revert_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::RevertStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::RevertKeyword)?; +pub fn build_revert_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::RevertStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::RevertKeyword)?; let error = helper .accept_label(EdgeLabel::Error) - .and_then(|node| build_identifier_path(nonterminal_node(node))); - let arguments = - build_arguments_declaration(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + .and_then(build_identifier_path); + let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(RevertStatementStruct { - node_id: node.id(), + node, error, arguments, })) } -pub fn build_throw_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ThrowStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ThrowKeyword)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; +pub fn build_throw_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ThrowStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ThrowKeyword)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ThrowStatementStruct { node_id: node.id() })) + Some(Rc::new(ThrowStatementStruct { node })) } -pub fn build_assignment_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AssignmentExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_assignment_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AssignmentExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(AssignmentExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_conditional_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConditionalExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::QuestionMark)?; - let true_expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::TrueExpression)?, - ))?; - _ = helper.accept_label(EdgeLabel::Colon)?; - let false_expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::FalseExpression)?, - ))?; +pub fn build_conditional_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ConditionalExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::QuestionMark)?; + let true_expression = build_expression(helper.accept_label(EdgeLabel::TrueExpression)?)?; + helper.skip_label(EdgeLabel::Colon)?; + let false_expression = build_expression(helper.accept_label(EdgeLabel::FalseExpression)?)?; if !helper.finalize() { return None; } Some(Rc::new(ConditionalExpressionStruct { - node_id: node.id(), + node, operand, true_expression, false_expression, })) } -pub fn build_or_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::OrExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; - _ = helper.accept_label(EdgeLabel::Operator)?; - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; +pub fn build_or_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::OrExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; + helper.skip_label(EdgeLabel::Operator)?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(OrExpressionStruct { - node_id: node.id(), + node, left_operand, right_operand, })) } -pub fn build_and_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AndExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; - _ = helper.accept_label(EdgeLabel::Operator)?; - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; +pub fn build_and_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AndExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; + helper.skip_label(EdgeLabel::Operator)?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(AndExpressionStruct { - node_id: node.id(), + node, left_operand, right_operand, })) } -pub fn build_equality_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EqualityExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_equality_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EqualityExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(EqualityExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_inequality_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InequalityExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_inequality_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InequalityExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(InequalityExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_bitwise_or_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::BitwiseOrExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; - _ = helper.accept_label(EdgeLabel::Operator)?; - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; +pub fn build_bitwise_or_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::BitwiseOrExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; + helper.skip_label(EdgeLabel::Operator)?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(BitwiseOrExpressionStruct { - node_id: node.id(), + node, left_operand, right_operand, })) } -pub fn build_bitwise_xor_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::BitwiseXorExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; - _ = helper.accept_label(EdgeLabel::Operator)?; - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; +pub fn build_bitwise_xor_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::BitwiseXorExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; + helper.skip_label(EdgeLabel::Operator)?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(BitwiseXorExpressionStruct { - node_id: node.id(), + node, left_operand, right_operand, })) } -pub fn build_bitwise_and_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::BitwiseAndExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; - _ = helper.accept_label(EdgeLabel::Operator)?; - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; +pub fn build_bitwise_and_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::BitwiseAndExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; + helper.skip_label(EdgeLabel::Operator)?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(BitwiseAndExpressionStruct { - node_id: node.id(), + node, left_operand, right_operand, })) } -pub fn build_shift_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ShiftExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_shift_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ShiftExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(ShiftExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_additive_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AdditiveExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_additive_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AdditiveExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(AdditiveExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_multiplicative_expression( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MultiplicativeExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_multiplicative_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MultiplicativeExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(MultiplicativeExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_exponentiation_expression( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ExponentiationExpression); - let mut helper = ChildrenHelper::new(&node.children); - let left_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::LeftOperand)?, - ))?; +pub fn build_exponentiation_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ExponentiationExpression); + let mut helper = ChildrenHelper::new(&node); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let right_operand = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::RightOperand)?, - ))?; + let right_operand = build_expression(helper.accept_label(EdgeLabel::RightOperand)?)?; if !helper.finalize() { return None; } Some(Rc::new(ExponentiationExpressionStruct { - node_id: node.id(), + node, left_operand, operator, right_operand, })) } -pub fn build_postfix_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PostfixExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; +pub fn build_postfix_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::PostfixExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); if !helper.finalize() { return None; } Some(Rc::new(PostfixExpressionStruct { - node_id: node.id(), + node, operand, operator, })) } -pub fn build_prefix_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PrefixExpression); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_prefix_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::PrefixExpression); + let mut helper = ChildrenHelper::new(&node); let operator = terminal_node_cloned(helper.accept_label(EdgeLabel::Operator)?); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; if !helper.finalize() { return None; } Some(Rc::new(PrefixExpressionStruct { - node_id: node.id(), + node, operator, operand, })) } -pub fn build_function_call_expression( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionCallExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - let arguments = - build_arguments_declaration(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; +pub fn build_function_call_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionCallExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; + let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; if !helper.finalize() { return None; } Some(Rc::new(FunctionCallExpressionStruct { - node_id: node.id(), + node, operand, arguments, })) } -pub fn build_call_options_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CallOptionsExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let options = build_call_options(nonterminal_node(helper.accept_label(EdgeLabel::Options)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; +pub fn build_call_options_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::CallOptionsExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::OpenBrace)?; + let options = build_call_options(helper.accept_label(EdgeLabel::Options)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(CallOptionsExpressionStruct { - node_id: node.id(), + node, operand, options, })) } -pub fn build_member_access_expression( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MemberAccessExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::Period)?; +pub fn build_member_access_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MemberAccessExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::Period)?; let member = terminal_node_cloned(helper.accept_label(EdgeLabel::Member)?); if !helper.finalize() { return None; } Some(Rc::new(MemberAccessExpressionStruct { - node_id: node.id(), + node, operand, member, })) } -pub fn build_index_access_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::IndexAccessExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::OpenBracket)?; +pub fn build_index_access_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::IndexAccessExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::OpenBracket)?; let start = helper .accept_label(EdgeLabel::Start) - .and_then(|node| build_expression(nonterminal_node(node))); + .and_then(build_expression); let end = helper .accept_label(EdgeLabel::End) - .and_then(|node| build_index_access_end(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::CloseBracket)?; + .and_then(build_index_access_end); + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(IndexAccessExpressionStruct { - node_id: node.id(), + node, operand, start, end, })) } -pub fn build_index_access_end(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::IndexAccessEnd); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Colon)?; +pub fn build_index_access_end(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::IndexAccessEnd); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Colon)?; let end = helper .accept_label(EdgeLabel::End) - .and_then(|node| build_expression(nonterminal_node(node))); + .and_then(build_expression); if !helper.finalize() { return None; } - Some(Rc::new(IndexAccessEndStruct { - node_id: node.id(), - end, - })) + Some(Rc::new(IndexAccessEndStruct { node, end })) } pub fn build_positional_arguments_declaration( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PositionalArgumentsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let arguments = - build_positional_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + assert_nonterminal_kind(&node, NonterminalKind::PositionalArgumentsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let arguments = build_positional_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(PositionalArgumentsDeclarationStruct { - node_id: node.id(), + node, arguments, })) } pub fn build_named_arguments_declaration( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NamedArgumentsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; + assert_nonterminal_kind(&node, NonterminalKind::NamedArgumentsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; let arguments = helper .accept_label(EdgeLabel::Arguments) - .and_then(|node| build_named_argument_group(nonterminal_node(node))); - _ = helper.accept_label(EdgeLabel::CloseParen)?; + .and_then(build_named_argument_group); + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentsDeclarationStruct { - node_id: node.id(), - arguments, - })) + Some(Rc::new(NamedArgumentsDeclarationStruct { node, arguments })) } -pub fn build_named_argument_group(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NamedArgumentGroup); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let arguments = - build_named_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; +pub fn build_named_argument_group(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NamedArgumentGroup); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBrace)?; + let arguments = build_named_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentGroupStruct { - node_id: node.id(), - arguments, - })) + Some(Rc::new(NamedArgumentGroupStruct { node, arguments })) } -pub fn build_named_argument(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NamedArgument); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_named_argument(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NamedArgument); + let mut helper = ChildrenHelper::new(&node); let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::Colon)?; - let value = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Value)?))?; + helper.skip_label(EdgeLabel::Colon)?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentStruct { - node_id: node.id(), - name, - value, - })) + Some(Rc::new(NamedArgumentStruct { node, name, value })) } -pub fn build_type_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TypeExpression); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::TypeKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_type_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TypeExpression); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::TypeKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(TypeExpressionStruct { - node_id: node.id(), - type_name, - })) + Some(Rc::new(TypeExpressionStruct { node, type_name })) } -pub fn build_new_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NewExpression); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::NewKeyword)?; - let type_name = build_type_name(nonterminal_node(helper.accept_label(EdgeLabel::TypeName)?))?; +pub fn build_new_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NewExpression); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::NewKeyword)?; + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; if !helper.finalize() { return None; } - Some(Rc::new(NewExpressionStruct { - node_id: node.id(), - type_name, - })) + Some(Rc::new(NewExpressionStruct { node, type_name })) } -pub fn build_tuple_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleExpression); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let items = build_tuple_values(nonterminal_node(helper.accept_label(EdgeLabel::Items)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_tuple_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TupleExpression); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let items = build_tuple_values(helper.accept_label(EdgeLabel::Items)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(TupleExpressionStruct { - node_id: node.id(), - items, - })) + Some(Rc::new(TupleExpressionStruct { node, items })) } -pub fn build_tuple_value(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleValue); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_tuple_value(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TupleValue); + let mut helper = ChildrenHelper::new(&node); let expression = helper .accept_label(EdgeLabel::Expression) - .and_then(|node| build_expression(nonterminal_node(node))); + .and_then(build_expression); if !helper.finalize() { return None; } - Some(Rc::new(TupleValueStruct { - node_id: node.id(), - expression, - })) + Some(Rc::new(TupleValueStruct { node, expression })) } -pub fn build_array_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ArrayExpression); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBracket)?; - let items = build_array_values(nonterminal_node(helper.accept_label(EdgeLabel::Items)?))?; - _ = helper.accept_label(EdgeLabel::CloseBracket)?; +pub fn build_array_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ArrayExpression); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBracket)?; + let items = build_array_values(helper.accept_label(EdgeLabel::Items)?)?; + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } - Some(Rc::new(ArrayExpressionStruct { - node_id: node.id(), - items, - })) + Some(Rc::new(ArrayExpressionStruct { node, items })) } -pub fn build_hex_number_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::HexNumberExpression); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_hex_number_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::HexNumberExpression); + let mut helper = ChildrenHelper::new(&node); let literal = terminal_node_cloned(helper.accept_label(EdgeLabel::Literal)?); let unit = helper .accept_label(EdgeLabel::Unit) - .and_then(|node| build_number_unit(nonterminal_node(node))); + .and_then(build_number_unit); if !helper.finalize() { return None; } Some(Rc::new(HexNumberExpressionStruct { - node_id: node.id(), + node, literal, unit, })) } -pub fn build_decimal_number_expression( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::DecimalNumberExpression); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_decimal_number_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::DecimalNumberExpression); + let mut helper = ChildrenHelper::new(&node); let literal = terminal_node_cloned(helper.accept_label(EdgeLabel::Literal)?); let unit = helper .accept_label(EdgeLabel::Unit) - .and_then(|node| build_number_unit(nonterminal_node(node))); + .and_then(build_number_unit); if !helper.finalize() { return None; } Some(Rc::new(DecimalNumberExpressionStruct { - node_id: node.id(), + node, literal, unit, })) } -pub fn build_yul_block(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulBlock); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let statements = build_yul_statements(nonterminal_node( - helper.accept_label(EdgeLabel::Statements)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; +pub fn build_yul_block(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulBlock); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenBrace)?; + let statements = build_yul_statements(helper.accept_label(EdgeLabel::Statements)?)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(YulBlockStruct { - node_id: node.id(), - statements, - })) + Some(Rc::new(YulBlockStruct { node, statements })) } -pub fn build_yul_function_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulFunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::FunctionKeyword)?; +pub fn build_yul_function_definition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulFunctionDefinition); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::FunctionKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - let parameters = build_yul_parameters_declaration(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_yul_parameters_declaration(helper.accept_label(EdgeLabel::Parameters)?)?; let returns = helper .accept_label(EdgeLabel::Returns) - .and_then(|node| build_yul_returns_declaration(nonterminal_node(node))); - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + .and_then(build_yul_returns_declaration); + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulFunctionDefinitionStruct { - node_id: node.id(), + node, name, parameters, returns, @@ -2221,189 +1943,164 @@ pub fn build_yul_function_definition(node: &Rc) -> Option, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_yul_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; +pub fn build_yul_parameters_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulParametersDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::OpenParen)?; + let parameters = build_yul_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(YulParametersDeclarationStruct { - node_id: node.id(), - parameters, - })) + Some(Rc::new(YulParametersDeclarationStruct { node, parameters })) } -pub fn build_yul_returns_declaration(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulReturnsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::MinusGreaterThan)?; - let variables = - build_yul_variable_names(nonterminal_node(helper.accept_label(EdgeLabel::Variables)?))?; +pub fn build_yul_returns_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulReturnsDeclaration); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::MinusGreaterThan)?; + let variables = build_yul_variable_names(helper.accept_label(EdgeLabel::Variables)?)?; if !helper.finalize() { return None; } - Some(Rc::new(YulReturnsDeclarationStruct { - node_id: node.id(), - variables, - })) + Some(Rc::new(YulReturnsDeclarationStruct { node, variables })) } pub fn build_yul_variable_declaration_statement( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulVariableDeclarationStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::LetKeyword)?; - let variables = - build_yul_variable_names(nonterminal_node(helper.accept_label(EdgeLabel::Variables)?))?; + assert_nonterminal_kind(&node, NonterminalKind::YulVariableDeclarationStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::LetKeyword)?; + let variables = build_yul_variable_names(helper.accept_label(EdgeLabel::Variables)?)?; let value = helper .accept_label(EdgeLabel::Value) - .and_then(|node| build_yul_variable_declaration_value(nonterminal_node(node))); + .and_then(build_yul_variable_declaration_value); if !helper.finalize() { return None; } Some(Rc::new(YulVariableDeclarationStatementStruct { - node_id: node.id(), + node, variables, value, })) } pub fn build_yul_variable_declaration_value( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulVariableDeclarationValue); - let mut helper = ChildrenHelper::new(&node.children); - let assignment = build_yul_assignment_operator(nonterminal_node( - helper.accept_label(EdgeLabel::Assignment)?, - ))?; - let expression = build_yul_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; + assert_nonterminal_kind(&node, NonterminalKind::YulVariableDeclarationValue); + let mut helper = ChildrenHelper::new(&node); + let assignment = build_yul_assignment_operator(helper.accept_label(EdgeLabel::Assignment)?)?; + let expression = build_yul_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulVariableDeclarationValueStruct { - node_id: node.id(), + node, assignment, expression, })) } pub fn build_yul_variable_assignment_statement( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulVariableAssignmentStatement); - let mut helper = ChildrenHelper::new(&node.children); - let variables = build_yul_paths(nonterminal_node(helper.accept_label(EdgeLabel::Variables)?))?; - let assignment = build_yul_assignment_operator(nonterminal_node( - helper.accept_label(EdgeLabel::Assignment)?, - ))?; - let expression = build_yul_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; + assert_nonterminal_kind(&node, NonterminalKind::YulVariableAssignmentStatement); + let mut helper = ChildrenHelper::new(&node); + let variables = build_yul_paths(helper.accept_label(EdgeLabel::Variables)?)?; + let assignment = build_yul_assignment_operator(helper.accept_label(EdgeLabel::Assignment)?)?; + let expression = build_yul_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulVariableAssignmentStatementStruct { - node_id: node.id(), + node, variables, assignment, expression, })) } -pub fn build_yul_colon_and_equal(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulColonAndEqual); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Colon)?; - _ = helper.accept_label(EdgeLabel::Equal)?; +pub fn build_yul_colon_and_equal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulColonAndEqual); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Colon)?; + helper.skip_label(EdgeLabel::Equal)?; if !helper.finalize() { return None; } - Some(Rc::new(YulColonAndEqualStruct { node_id: node.id() })) + Some(Rc::new(YulColonAndEqualStruct { node })) } pub fn build_yul_stack_assignment_statement( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulStackAssignmentStatement); - let mut helper = ChildrenHelper::new(&node.children); - let assignment = build_yul_stack_assignment_operator(nonterminal_node( - helper.accept_label(EdgeLabel::Assignment)?, - ))?; + assert_nonterminal_kind(&node, NonterminalKind::YulStackAssignmentStatement); + let mut helper = ChildrenHelper::new(&node); + let assignment = + build_yul_stack_assignment_operator(helper.accept_label(EdgeLabel::Assignment)?)?; let variable = terminal_node_cloned(helper.accept_label(EdgeLabel::Variable)?); if !helper.finalize() { return None; } Some(Rc::new(YulStackAssignmentStatementStruct { - node_id: node.id(), + node, assignment, variable, })) } -pub fn build_yul_equal_and_colon(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulEqualAndColon); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::Equal)?; - _ = helper.accept_label(EdgeLabel::Colon)?; +pub fn build_yul_equal_and_colon(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulEqualAndColon); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::Equal)?; + helper.skip_label(EdgeLabel::Colon)?; if !helper.finalize() { return None; } - Some(Rc::new(YulEqualAndColonStruct { node_id: node.id() })) + Some(Rc::new(YulEqualAndColonStruct { node })) } -pub fn build_yul_if_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulIfStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::IfKeyword)?; - let condition = - build_yul_expression(nonterminal_node(helper.accept_label(EdgeLabel::Condition)?))?; - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_yul_if_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulIfStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::IfKeyword)?; + let condition = build_yul_expression(helper.accept_label(EdgeLabel::Condition)?)?; + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulIfStatementStruct { - node_id: node.id(), + node, condition, body, })) } -pub fn build_yul_for_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulForStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ForKeyword)?; - let initialization = build_yul_block(nonterminal_node( - helper.accept_label(EdgeLabel::Initialization)?, - ))?; - let condition = - build_yul_expression(nonterminal_node(helper.accept_label(EdgeLabel::Condition)?))?; - let iterator = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Iterator)?))?; - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_yul_for_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulForStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ForKeyword)?; + let initialization = build_yul_block(helper.accept_label(EdgeLabel::Initialization)?)?; + let condition = build_yul_expression(helper.accept_label(EdgeLabel::Condition)?)?; + let iterator = build_yul_block(helper.accept_label(EdgeLabel::Iterator)?)?; + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulForStatementStruct { - node_id: node.id(), + node, initialization, condition, iterator, @@ -2411,121 +2108,108 @@ pub fn build_yul_for_statement(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulSwitchStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::SwitchKeyword)?; - let expression = build_yul_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; - let cases = build_yul_switch_cases(nonterminal_node(helper.accept_label(EdgeLabel::Cases)?))?; +pub fn build_yul_switch_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulSwitchStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::SwitchKeyword)?; + let expression = build_yul_expression(helper.accept_label(EdgeLabel::Expression)?)?; + let cases = build_yul_switch_cases(helper.accept_label(EdgeLabel::Cases)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulSwitchStatementStruct { - node_id: node.id(), + node, expression, cases, })) } -pub fn build_yul_default_case(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulDefaultCase); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::DefaultKeyword)?; - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_yul_default_case(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulDefaultCase); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::DefaultKeyword)?; + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } - Some(Rc::new(YulDefaultCaseStruct { - node_id: node.id(), - body, - })) + Some(Rc::new(YulDefaultCaseStruct { node, body })) } -pub fn build_yul_value_case(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulValueCase); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::CaseKeyword)?; - let value = build_yul_literal(nonterminal_node(helper.accept_label(EdgeLabel::Value)?))?; - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; +pub fn build_yul_value_case(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulValueCase); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::CaseKeyword)?; + let value = build_yul_literal(helper.accept_label(EdgeLabel::Value)?)?; + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } - Some(Rc::new(YulValueCaseStruct { - node_id: node.id(), - value, - body, - })) + Some(Rc::new(YulValueCaseStruct { node, value, body })) } -pub fn build_yul_leave_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulLeaveStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::LeaveKeyword)?; +pub fn build_yul_leave_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulLeaveStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::LeaveKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulLeaveStatementStruct { node_id: node.id() })) + Some(Rc::new(YulLeaveStatementStruct { node })) } -pub fn build_yul_break_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulBreakStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::BreakKeyword)?; +pub fn build_yul_break_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulBreakStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::BreakKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulBreakStatementStruct { node_id: node.id() })) + Some(Rc::new(YulBreakStatementStruct { node })) } -pub fn build_yul_continue_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulContinueStatement); - let mut helper = ChildrenHelper::new(&node.children); - _ = helper.accept_label(EdgeLabel::ContinueKeyword)?; +pub fn build_yul_continue_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulContinueStatement); + let mut helper = ChildrenHelper::new(&node); + helper.skip_label(EdgeLabel::ContinueKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulContinueStatementStruct { node_id: node.id() })) + Some(Rc::new(YulContinueStatementStruct { node })) } -pub fn build_yul_label(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulLabel); - let mut helper = ChildrenHelper::new(&node.children); +pub fn build_yul_label(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulLabel); + let mut helper = ChildrenHelper::new(&node); let label = terminal_node_cloned(helper.accept_label(EdgeLabel::Label)?); - _ = helper.accept_label(EdgeLabel::Colon)?; + helper.skip_label(EdgeLabel::Colon)?; if !helper.finalize() { return None; } - Some(Rc::new(YulLabelStruct { - node_id: node.id(), - label, - })) + Some(Rc::new(YulLabelStruct { node, label })) } pub fn build_yul_function_call_expression( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulFunctionCallExpression); - let mut helper = ChildrenHelper::new(&node.children); - let operand = build_yul_expression(nonterminal_node(helper.accept_label(EdgeLabel::Operand)?))?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; - let arguments = - build_yul_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + assert_nonterminal_kind(&node, NonterminalKind::YulFunctionCallExpression); + let mut helper = ChildrenHelper::new(&node); + let operand = build_yul_expression(helper.accept_label(EdgeLabel::Operand)?)?; + helper.skip_label(EdgeLabel::OpenParen)?; + let arguments = build_yul_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(YulFunctionCallExpressionStruct { - node_id: node.id(), + node, operand, arguments, })) @@ -2535,61 +2219,52 @@ pub fn build_yul_function_call_expression( // Choices: // -pub fn build_source_unit_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::SourceUnitMember); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_source_unit_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::SourceUnitMember); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::PragmaDirective) => { - SourceUnitMember::PragmaDirective(build_pragma_directive(nonterminal_node(variant))?) + SourceUnitMember::PragmaDirective(build_pragma_directive(variant)?) } NodeKind::Nonterminal(NonterminalKind::ImportDirective) => { - SourceUnitMember::ImportDirective(build_import_directive(nonterminal_node(variant))?) + SourceUnitMember::ImportDirective(build_import_directive(variant)?) } NodeKind::Nonterminal(NonterminalKind::ContractDefinition) => { - SourceUnitMember::ContractDefinition(build_contract_definition(nonterminal_node( - variant, - ))?) + SourceUnitMember::ContractDefinition(build_contract_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::InterfaceDefinition) => { - SourceUnitMember::InterfaceDefinition(build_interface_definition(nonterminal_node( - variant, - ))?) + SourceUnitMember::InterfaceDefinition(build_interface_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::LibraryDefinition) => { - SourceUnitMember::LibraryDefinition(build_library_definition(nonterminal_node( - variant, - ))?) + SourceUnitMember::LibraryDefinition(build_library_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::StructDefinition) => { - SourceUnitMember::StructDefinition(build_struct_definition(nonterminal_node(variant))?) + SourceUnitMember::StructDefinition(build_struct_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::EnumDefinition) => { - SourceUnitMember::EnumDefinition(build_enum_definition(nonterminal_node(variant))?) + SourceUnitMember::EnumDefinition(build_enum_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::FunctionDefinition) => { - SourceUnitMember::FunctionDefinition(build_function_definition(nonterminal_node( - variant, - ))?) + SourceUnitMember::FunctionDefinition(build_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ErrorDefinition) => { - SourceUnitMember::ErrorDefinition(build_error_definition(nonterminal_node(variant))?) + SourceUnitMember::ErrorDefinition(build_error_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::UserDefinedValueTypeDefinition) => { SourceUnitMember::UserDefinedValueTypeDefinition( - build_user_defined_value_type_definition(nonterminal_node(variant))?, + build_user_defined_value_type_definition(variant)?, ) } NodeKind::Nonterminal(NonterminalKind::UsingDirective) => { - SourceUnitMember::UsingDirective(build_using_directive(nonterminal_node(variant))?) + SourceUnitMember::UsingDirective(build_using_directive(variant)?) } NodeKind::Nonterminal(NonterminalKind::EventDefinition) => { - SourceUnitMember::EventDefinition(build_event_definition(nonterminal_node(variant))?) + SourceUnitMember::EventDefinition(build_event_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ConstantDefinition) => { - SourceUnitMember::ConstantDefinition(build_constant_definition(nonterminal_node( - variant, - ))?) + SourceUnitMember::ConstantDefinition(build_constant_definition(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2604,19 +2279,20 @@ pub fn build_source_unit_member(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Pragma); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_pragma(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Pragma); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::VersionPragma) => { - Pragma::VersionPragma(build_version_pragma(nonterminal_node(variant))?) + Pragma::VersionPragma(build_version_pragma(variant)?) } NodeKind::Nonterminal(NonterminalKind::AbicoderPragma) => { - Pragma::AbicoderPragma(build_abicoder_pragma(nonterminal_node(variant))?) + Pragma::AbicoderPragma(build_abicoder_pragma(variant)?) } NodeKind::Nonterminal(NonterminalKind::ExperimentalPragma) => { - Pragma::ExperimentalPragma(build_experimental_pragma(nonterminal_node(variant))?) + Pragma::ExperimentalPragma(build_experimental_pragma(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2631,9 +2307,10 @@ pub fn build_pragma(node: &Rc) -> Option { Some(item) } -pub fn build_abicoder_version(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AbicoderVersion); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_abicoder_version(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AbicoderVersion); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::AbicoderV1Keyword) => AbicoderVersion::AbicoderV1Keyword, @@ -2651,13 +2328,14 @@ pub fn build_abicoder_version(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ExperimentalFeature); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_experimental_feature(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ExperimentalFeature); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::StringLiteral) => { - ExperimentalFeature::StringLiteral(build_string_literal(nonterminal_node(variant))?) + ExperimentalFeature::StringLiteral(build_string_literal(variant)?) } NodeKind::Terminal(TerminalKind::ABIEncoderV2Keyword) => { ExperimentalFeature::ABIEncoderV2Keyword @@ -2678,16 +2356,17 @@ pub fn build_experimental_feature(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionExpression); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_version_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionExpression); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::VersionRange) => { - VersionExpression::VersionRange(build_version_range(nonterminal_node(variant))?) + VersionExpression::VersionRange(build_version_range(variant)?) } NodeKind::Nonterminal(NonterminalKind::VersionTerm) => { - VersionExpression::VersionTerm(build_version_term(nonterminal_node(variant))?) + VersionExpression::VersionTerm(build_version_term(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2702,9 +2381,10 @@ pub fn build_version_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionOperator); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_version_operator(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionOperator); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Caret) => VersionOperator::Caret, @@ -2727,15 +2407,14 @@ pub fn build_version_operator(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionLiteral); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_version_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionLiteral); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::SimpleVersionLiteral) => { - VersionLiteral::SimpleVersionLiteral(build_simple_version_literal(nonterminal_node( - variant, - ))?) + VersionLiteral::SimpleVersionLiteral(build_simple_version_literal(variant)?) } NodeKind::Terminal(TerminalKind::SingleQuotedVersionLiteral) => { VersionLiteral::SingleQuotedVersionLiteral(terminal_node_cloned(variant)) @@ -2756,21 +2435,20 @@ pub fn build_version_literal(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportClause); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_import_clause(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ImportClause); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::PathImport) => { - ImportClause::PathImport(build_path_import(nonterminal_node(variant))?) + ImportClause::PathImport(build_path_import(variant)?) } NodeKind::Nonterminal(NonterminalKind::NamedImport) => { - ImportClause::NamedImport(build_named_import(nonterminal_node(variant))?) + ImportClause::NamedImport(build_named_import(variant)?) } NodeKind::Nonterminal(NonterminalKind::ImportDeconstruction) => { - ImportClause::ImportDeconstruction(build_import_deconstruction(nonterminal_node( - variant, - ))?) + ImportClause::ImportDeconstruction(build_import_deconstruction(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2785,16 +2463,17 @@ pub fn build_import_clause(node: &Rc) -> Option { Some(item) } -pub fn build_using_clause(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingClause); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_using_clause(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingClause); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::IdentifierPath) => { - UsingClause::IdentifierPath(build_identifier_path(nonterminal_node(variant))?) + UsingClause::IdentifierPath(build_identifier_path(variant)?) } NodeKind::Nonterminal(NonterminalKind::UsingDeconstruction) => { - UsingClause::UsingDeconstruction(build_using_deconstruction(nonterminal_node(variant))?) + UsingClause::UsingDeconstruction(build_using_deconstruction(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2809,9 +2488,10 @@ pub fn build_using_clause(node: &Rc) -> Option { Some(item) } -pub fn build_using_operator(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingOperator); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_using_operator(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingOperator); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Ampersand) => UsingOperator::Ampersand, @@ -2842,13 +2522,14 @@ pub fn build_using_operator(node: &Rc) -> Option Some(item) } -pub fn build_using_target(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingTarget); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_using_target(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UsingTarget); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::TypeName) => { - UsingTarget::TypeName(build_type_name(nonterminal_node(variant))?) + UsingTarget::TypeName(build_type_name(variant)?) } NodeKind::Terminal(TerminalKind::Asterisk) => UsingTarget::Asterisk, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -2864,20 +2545,17 @@ pub fn build_using_target(node: &Rc) -> Option { Some(item) } -pub fn build_contract_specifier(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContractSpecifier); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_contract_specifier(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContractSpecifier); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::InheritanceSpecifier) => { - ContractSpecifier::InheritanceSpecifier(build_inheritance_specifier(nonterminal_node( - variant, - ))?) + ContractSpecifier::InheritanceSpecifier(build_inheritance_specifier(variant)?) } NodeKind::Nonterminal(NonterminalKind::StorageLayoutSpecifier) => { - ContractSpecifier::StorageLayoutSpecifier(build_storage_layout_specifier( - nonterminal_node(variant), - )?) + ContractSpecifier::StorageLayoutSpecifier(build_storage_layout_specifier(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2892,65 +2570,52 @@ pub fn build_contract_specifier(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContractMember); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_contract_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContractMember); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::UsingDirective) => { - ContractMember::UsingDirective(build_using_directive(nonterminal_node(variant))?) + ContractMember::UsingDirective(build_using_directive(variant)?) } NodeKind::Nonterminal(NonterminalKind::FunctionDefinition) => { - ContractMember::FunctionDefinition(build_function_definition(nonterminal_node( - variant, - ))?) + ContractMember::FunctionDefinition(build_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ConstructorDefinition) => { - ContractMember::ConstructorDefinition(build_constructor_definition(nonterminal_node( - variant, - ))?) + ContractMember::ConstructorDefinition(build_constructor_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ReceiveFunctionDefinition) => { - ContractMember::ReceiveFunctionDefinition(build_receive_function_definition( - nonterminal_node(variant), - )?) + ContractMember::ReceiveFunctionDefinition(build_receive_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::FallbackFunctionDefinition) => { - ContractMember::FallbackFunctionDefinition(build_fallback_function_definition( - nonterminal_node(variant), - )?) + ContractMember::FallbackFunctionDefinition(build_fallback_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::UnnamedFunctionDefinition) => { - ContractMember::UnnamedFunctionDefinition(build_unnamed_function_definition( - nonterminal_node(variant), - )?) + ContractMember::UnnamedFunctionDefinition(build_unnamed_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ModifierDefinition) => { - ContractMember::ModifierDefinition(build_modifier_definition(nonterminal_node( - variant, - ))?) + ContractMember::ModifierDefinition(build_modifier_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::StructDefinition) => { - ContractMember::StructDefinition(build_struct_definition(nonterminal_node(variant))?) + ContractMember::StructDefinition(build_struct_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::EnumDefinition) => { - ContractMember::EnumDefinition(build_enum_definition(nonterminal_node(variant))?) + ContractMember::EnumDefinition(build_enum_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::EventDefinition) => { - ContractMember::EventDefinition(build_event_definition(nonterminal_node(variant))?) + ContractMember::EventDefinition(build_event_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::ErrorDefinition) => { - ContractMember::ErrorDefinition(build_error_definition(nonterminal_node(variant))?) + ContractMember::ErrorDefinition(build_error_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::UserDefinedValueTypeDefinition) => { ContractMember::UserDefinedValueTypeDefinition( - build_user_defined_value_type_definition(nonterminal_node(variant))?, + build_user_defined_value_type_definition(variant)?, ) } NodeKind::Nonterminal(NonterminalKind::StateVariableDefinition) => { - ContractMember::StateVariableDefinition(build_state_variable_definition( - nonterminal_node(variant), - )?) + ContractMember::StateVariableDefinition(build_state_variable_definition(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -2965,17 +2630,14 @@ pub fn build_contract_member(node: &Rc) -> Option, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StateVariableAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_state_variable_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StateVariableAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::OverrideSpecifier) => { - StateVariableAttribute::OverrideSpecifier(build_override_specifier(nonterminal_node( - variant, - ))?) + StateVariableAttribute::OverrideSpecifier(build_override_specifier(variant)?) } NodeKind::Terminal(TerminalKind::ConstantKeyword) => { StateVariableAttribute::ConstantKeyword @@ -3004,9 +2666,10 @@ pub fn build_state_variable_attribute( Some(item) } -pub fn build_function_name(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionName); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_name(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionName); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Identifier) => { @@ -3027,20 +2690,17 @@ pub fn build_function_name(node: &Rc) -> Option { Some(item) } -pub fn build_function_attribute(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ModifierInvocation) => { - FunctionAttribute::ModifierInvocation(build_modifier_invocation(nonterminal_node( - variant, - ))?) + FunctionAttribute::ModifierInvocation(build_modifier_invocation(variant)?) } NodeKind::Nonterminal(NonterminalKind::OverrideSpecifier) => { - FunctionAttribute::OverrideSpecifier(build_override_specifier(nonterminal_node( - variant, - ))?) + FunctionAttribute::OverrideSpecifier(build_override_specifier(variant)?) } NodeKind::Terminal(TerminalKind::ConstantKeyword) => FunctionAttribute::ConstantKeyword, NodeKind::Terminal(TerminalKind::ExternalKeyword) => FunctionAttribute::ExternalKeyword, @@ -3064,14 +2724,13 @@ pub fn build_function_attribute(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionBody); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_body(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionBody); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { - NodeKind::Nonterminal(NonterminalKind::Block) => { - FunctionBody::Block(build_block(nonterminal_node(variant))?) - } + NodeKind::Nonterminal(NonterminalKind::Block) => FunctionBody::Block(build_block(variant)?), NodeKind::Terminal(TerminalKind::Semicolon) => FunctionBody::Semicolon, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3086,15 +2745,14 @@ pub fn build_function_body(node: &Rc) -> Option { Some(item) } -pub fn build_constructor_attribute(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConstructorAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_constructor_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ConstructorAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ModifierInvocation) => { - ConstructorAttribute::ModifierInvocation(build_modifier_invocation(nonterminal_node( - variant, - ))?) + ConstructorAttribute::ModifierInvocation(build_modifier_invocation(variant)?) } NodeKind::Terminal(TerminalKind::InternalKeyword) => ConstructorAttribute::InternalKeyword, NodeKind::Terminal(TerminalKind::OverrideKeyword) => ConstructorAttribute::OverrideKeyword, @@ -3114,17 +2772,14 @@ pub fn build_constructor_attribute(node: &Rc) -> Option, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_unnamed_function_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UnnamedFunctionAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ModifierInvocation) => { - UnnamedFunctionAttribute::ModifierInvocation(build_modifier_invocation( - nonterminal_node(variant), - )?) + UnnamedFunctionAttribute::ModifierInvocation(build_modifier_invocation(variant)?) } NodeKind::Terminal(TerminalKind::ConstantKeyword) => { UnnamedFunctionAttribute::ConstantKeyword @@ -3157,22 +2812,19 @@ pub fn build_unnamed_function_attribute( Some(item) } +#[allow(clippy::needless_pass_by_value)] pub fn build_fallback_function_attribute( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FallbackFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::FallbackFunctionAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ModifierInvocation) => { - FallbackFunctionAttribute::ModifierInvocation(build_modifier_invocation( - nonterminal_node(variant), - )?) + FallbackFunctionAttribute::ModifierInvocation(build_modifier_invocation(variant)?) } NodeKind::Nonterminal(NonterminalKind::OverrideSpecifier) => { - FallbackFunctionAttribute::OverrideSpecifier(build_override_specifier( - nonterminal_node(variant), - )?) + FallbackFunctionAttribute::OverrideSpecifier(build_override_specifier(variant)?) } NodeKind::Terminal(TerminalKind::ExternalKeyword) => { FallbackFunctionAttribute::ExternalKeyword @@ -3198,22 +2850,17 @@ pub fn build_fallback_function_attribute( Some(item) } -pub fn build_receive_function_attribute( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ReceiveFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_receive_function_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ReceiveFunctionAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ModifierInvocation) => { - ReceiveFunctionAttribute::ModifierInvocation(build_modifier_invocation( - nonterminal_node(variant), - )?) + ReceiveFunctionAttribute::ModifierInvocation(build_modifier_invocation(variant)?) } NodeKind::Nonterminal(NonterminalKind::OverrideSpecifier) => { - ReceiveFunctionAttribute::OverrideSpecifier(build_override_specifier( - nonterminal_node(variant), - )?) + ReceiveFunctionAttribute::OverrideSpecifier(build_override_specifier(variant)?) } NodeKind::Terminal(TerminalKind::ExternalKeyword) => { ReceiveFunctionAttribute::ExternalKeyword @@ -3237,15 +2884,14 @@ pub fn build_receive_function_attribute( Some(item) } -pub fn build_modifier_attribute(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ModifierAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_modifier_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ModifierAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::OverrideSpecifier) => { - ModifierAttribute::OverrideSpecifier(build_override_specifier(nonterminal_node( - variant, - ))?) + ModifierAttribute::OverrideSpecifier(build_override_specifier(variant)?) } NodeKind::Terminal(TerminalKind::VirtualKeyword) => ModifierAttribute::VirtualKeyword, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3261,25 +2907,26 @@ pub fn build_modifier_attribute(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TypeName); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_type_name(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TypeName); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ArrayTypeName) => { - TypeName::ArrayTypeName(build_array_type_name(nonterminal_node(variant))?) + TypeName::ArrayTypeName(build_array_type_name(variant)?) } NodeKind::Nonterminal(NonterminalKind::FunctionType) => { - TypeName::FunctionType(build_function_type(nonterminal_node(variant))?) + TypeName::FunctionType(build_function_type(variant)?) } NodeKind::Nonterminal(NonterminalKind::MappingType) => { - TypeName::MappingType(build_mapping_type(nonterminal_node(variant))?) + TypeName::MappingType(build_mapping_type(variant)?) } NodeKind::Nonterminal(NonterminalKind::ElementaryType) => { - TypeName::ElementaryType(build_elementary_type(nonterminal_node(variant))?) + TypeName::ElementaryType(build_elementary_type(variant)?) } NodeKind::Nonterminal(NonterminalKind::IdentifierPath) => { - TypeName::IdentifierPath(build_identifier_path(nonterminal_node(variant))?) + TypeName::IdentifierPath(build_identifier_path(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3294,9 +2941,10 @@ pub fn build_type_name(node: &Rc) -> Option { Some(item) } -pub fn build_function_type_attribute(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionTypeAttribute); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_type_attribute(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionTypeAttribute); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::InternalKeyword) => FunctionTypeAttribute::InternalKeyword, @@ -3320,16 +2968,17 @@ pub fn build_function_type_attribute(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MappingKeyType); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_mapping_key_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::MappingKeyType); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ElementaryType) => { - MappingKeyType::ElementaryType(build_elementary_type(nonterminal_node(variant))?) + MappingKeyType::ElementaryType(build_elementary_type(variant)?) } NodeKind::Nonterminal(NonterminalKind::IdentifierPath) => { - MappingKeyType::IdentifierPath(build_identifier_path(nonterminal_node(variant))?) + MappingKeyType::IdentifierPath(build_identifier_path(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3344,13 +2993,14 @@ pub fn build_mapping_key_type(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ElementaryType); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_elementary_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ElementaryType); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::AddressType) => { - ElementaryType::AddressType(build_address_type(nonterminal_node(variant))?) + ElementaryType::AddressType(build_address_type(variant)?) } NodeKind::Terminal(TerminalKind::BytesKeyword) => { ElementaryType::BytesKeyword(terminal_node_cloned(variant)) @@ -3383,65 +3033,60 @@ pub fn build_elementary_type(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Statement); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Statement); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::IfStatement) => { - Statement::IfStatement(build_if_statement(nonterminal_node(variant))?) + Statement::IfStatement(build_if_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::ForStatement) => { - Statement::ForStatement(build_for_statement(nonterminal_node(variant))?) + Statement::ForStatement(build_for_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::WhileStatement) => { - Statement::WhileStatement(build_while_statement(nonterminal_node(variant))?) + Statement::WhileStatement(build_while_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::DoWhileStatement) => { - Statement::DoWhileStatement(build_do_while_statement(nonterminal_node(variant))?) + Statement::DoWhileStatement(build_do_while_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::ContinueStatement) => { - Statement::ContinueStatement(build_continue_statement(nonterminal_node(variant))?) + Statement::ContinueStatement(build_continue_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::BreakStatement) => { - Statement::BreakStatement(build_break_statement(nonterminal_node(variant))?) + Statement::BreakStatement(build_break_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::ReturnStatement) => { - Statement::ReturnStatement(build_return_statement(nonterminal_node(variant))?) + Statement::ReturnStatement(build_return_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::ThrowStatement) => { - Statement::ThrowStatement(build_throw_statement(nonterminal_node(variant))?) + Statement::ThrowStatement(build_throw_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::EmitStatement) => { - Statement::EmitStatement(build_emit_statement(nonterminal_node(variant))?) + Statement::EmitStatement(build_emit_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::TryStatement) => { - Statement::TryStatement(build_try_statement(nonterminal_node(variant))?) + Statement::TryStatement(build_try_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::RevertStatement) => { - Statement::RevertStatement(build_revert_statement(nonterminal_node(variant))?) + Statement::RevertStatement(build_revert_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::AssemblyStatement) => { - Statement::AssemblyStatement(build_assembly_statement(nonterminal_node(variant))?) - } - NodeKind::Nonterminal(NonterminalKind::Block) => { - Statement::Block(build_block(nonterminal_node(variant))?) + Statement::AssemblyStatement(build_assembly_statement(variant)?) } + NodeKind::Nonterminal(NonterminalKind::Block) => Statement::Block(build_block(variant)?), NodeKind::Nonterminal(NonterminalKind::UncheckedBlock) => { - Statement::UncheckedBlock(build_unchecked_block(nonterminal_node(variant))?) + Statement::UncheckedBlock(build_unchecked_block(variant)?) } NodeKind::Nonterminal(NonterminalKind::TupleDeconstructionStatement) => { - Statement::TupleDeconstructionStatement(build_tuple_deconstruction_statement( - nonterminal_node(variant), - )?) + Statement::TupleDeconstructionStatement(build_tuple_deconstruction_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::VariableDeclarationStatement) => { - Statement::VariableDeclarationStatement(build_variable_declaration_statement( - nonterminal_node(variant), - )?) + Statement::VariableDeclarationStatement(build_variable_declaration_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::ExpressionStatement) => { - Statement::ExpressionStatement(build_expression_statement(nonterminal_node(variant))?) + Statement::ExpressionStatement(build_expression_statement(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3456,16 +3101,17 @@ pub fn build_statement(node: &Rc) -> Option { Some(item) } -pub fn build_tuple_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleMember); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_tuple_member(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TupleMember); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::TypedTupleMember) => { - TupleMember::TypedTupleMember(build_typed_tuple_member(nonterminal_node(variant))?) + TupleMember::TypedTupleMember(build_typed_tuple_member(variant)?) } NodeKind::Nonterminal(NonterminalKind::UntypedTupleMember) => { - TupleMember::UntypedTupleMember(build_untyped_tuple_member(nonterminal_node(variant))?) + TupleMember::UntypedTupleMember(build_untyped_tuple_member(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3480,15 +3126,14 @@ pub fn build_tuple_member(node: &Rc) -> Option { Some(item) } -pub fn build_variable_declaration_type( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationType); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_variable_declaration_type(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VariableDeclarationType); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::TypeName) => { - VariableDeclarationType::TypeName(build_type_name(nonterminal_node(variant))?) + VariableDeclarationType::TypeName(build_type_name(variant)?) } NodeKind::Terminal(TerminalKind::VarKeyword) => VariableDeclarationType::VarKeyword, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3504,9 +3149,10 @@ pub fn build_variable_declaration_type( Some(item) } -pub fn build_storage_location(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StorageLocation); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_storage_location(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StorageLocation); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::MemoryKeyword) => StorageLocation::MemoryKeyword, @@ -3525,27 +3171,26 @@ pub fn build_storage_location(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ForStatementInitialization); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::ForStatementInitialization); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::TupleDeconstructionStatement) => { ForStatementInitialization::TupleDeconstructionStatement( - build_tuple_deconstruction_statement(nonterminal_node(variant))?, + build_tuple_deconstruction_statement(variant)?, ) } NodeKind::Nonterminal(NonterminalKind::VariableDeclarationStatement) => { ForStatementInitialization::VariableDeclarationStatement( - build_variable_declaration_statement(nonterminal_node(variant))?, + build_variable_declaration_statement(variant)?, ) } NodeKind::Nonterminal(NonterminalKind::ExpressionStatement) => { - ForStatementInitialization::ExpressionStatement(build_expression_statement( - nonterminal_node(variant), - )?) + ForStatementInitialization::ExpressionStatement(build_expression_statement(variant)?) } NodeKind::Terminal(TerminalKind::Semicolon) => ForStatementInitialization::Semicolon, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3561,15 +3206,14 @@ pub fn build_for_statement_initialization( Some(item) } -pub fn build_for_statement_condition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ForStatementCondition); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_for_statement_condition(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ForStatementCondition); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::ExpressionStatement) => { - ForStatementCondition::ExpressionStatement(build_expression_statement( - nonterminal_node(variant), - )?) + ForStatementCondition::ExpressionStatement(build_expression_statement(variant)?) } NodeKind::Terminal(TerminalKind::Semicolon) => ForStatementCondition::Semicolon, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3585,115 +3229,92 @@ pub fn build_for_statement_condition(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Expression); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Expression); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::AssignmentExpression) => { - Expression::AssignmentExpression(build_assignment_expression(nonterminal_node( - variant, - ))?) + Expression::AssignmentExpression(build_assignment_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::ConditionalExpression) => { - Expression::ConditionalExpression(build_conditional_expression(nonterminal_node( - variant, - ))?) + Expression::ConditionalExpression(build_conditional_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::OrExpression) => { - Expression::OrExpression(build_or_expression(nonterminal_node(variant))?) + Expression::OrExpression(build_or_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::AndExpression) => { - Expression::AndExpression(build_and_expression(nonterminal_node(variant))?) + Expression::AndExpression(build_and_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::EqualityExpression) => { - Expression::EqualityExpression(build_equality_expression(nonterminal_node(variant))?) + Expression::EqualityExpression(build_equality_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::InequalityExpression) => { - Expression::InequalityExpression(build_inequality_expression(nonterminal_node( - variant, - ))?) + Expression::InequalityExpression(build_inequality_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::BitwiseOrExpression) => { - Expression::BitwiseOrExpression(build_bitwise_or_expression(nonterminal_node(variant))?) + Expression::BitwiseOrExpression(build_bitwise_or_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::BitwiseXorExpression) => { - Expression::BitwiseXorExpression(build_bitwise_xor_expression(nonterminal_node( - variant, - ))?) + Expression::BitwiseXorExpression(build_bitwise_xor_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::BitwiseAndExpression) => { - Expression::BitwiseAndExpression(build_bitwise_and_expression(nonterminal_node( - variant, - ))?) + Expression::BitwiseAndExpression(build_bitwise_and_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::ShiftExpression) => { - Expression::ShiftExpression(build_shift_expression(nonterminal_node(variant))?) + Expression::ShiftExpression(build_shift_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::AdditiveExpression) => { - Expression::AdditiveExpression(build_additive_expression(nonterminal_node(variant))?) + Expression::AdditiveExpression(build_additive_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::MultiplicativeExpression) => { - Expression::MultiplicativeExpression(build_multiplicative_expression( - nonterminal_node(variant), - )?) + Expression::MultiplicativeExpression(build_multiplicative_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::ExponentiationExpression) => { - Expression::ExponentiationExpression(build_exponentiation_expression( - nonterminal_node(variant), - )?) + Expression::ExponentiationExpression(build_exponentiation_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::PostfixExpression) => { - Expression::PostfixExpression(build_postfix_expression(nonterminal_node(variant))?) + Expression::PostfixExpression(build_postfix_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::PrefixExpression) => { - Expression::PrefixExpression(build_prefix_expression(nonterminal_node(variant))?) + Expression::PrefixExpression(build_prefix_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::FunctionCallExpression) => { - Expression::FunctionCallExpression(build_function_call_expression(nonterminal_node( - variant, - ))?) + Expression::FunctionCallExpression(build_function_call_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::CallOptionsExpression) => { - Expression::CallOptionsExpression(build_call_options_expression(nonterminal_node( - variant, - ))?) + Expression::CallOptionsExpression(build_call_options_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::MemberAccessExpression) => { - Expression::MemberAccessExpression(build_member_access_expression(nonterminal_node( - variant, - ))?) + Expression::MemberAccessExpression(build_member_access_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::IndexAccessExpression) => { - Expression::IndexAccessExpression(build_index_access_expression(nonterminal_node( - variant, - ))?) + Expression::IndexAccessExpression(build_index_access_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::NewExpression) => { - Expression::NewExpression(build_new_expression(nonterminal_node(variant))?) + Expression::NewExpression(build_new_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::TupleExpression) => { - Expression::TupleExpression(build_tuple_expression(nonterminal_node(variant))?) + Expression::TupleExpression(build_tuple_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::TypeExpression) => { - Expression::TypeExpression(build_type_expression(nonterminal_node(variant))?) + Expression::TypeExpression(build_type_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::ArrayExpression) => { - Expression::ArrayExpression(build_array_expression(nonterminal_node(variant))?) + Expression::ArrayExpression(build_array_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::HexNumberExpression) => { - Expression::HexNumberExpression(build_hex_number_expression(nonterminal_node(variant))?) + Expression::HexNumberExpression(build_hex_number_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::DecimalNumberExpression) => { - Expression::DecimalNumberExpression(build_decimal_number_expression(nonterminal_node( - variant, - ))?) + Expression::DecimalNumberExpression(build_decimal_number_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::StringExpression) => { - Expression::StringExpression(build_string_expression(nonterminal_node(variant))?) + Expression::StringExpression(build_string_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::ElementaryType) => { - Expression::ElementaryType(build_elementary_type(nonterminal_node(variant))?) + Expression::ElementaryType(build_elementary_type(variant)?) } NodeKind::Terminal(TerminalKind::Identifier) => { Expression::Identifier(terminal_node_cloned(variant)) @@ -3716,19 +3337,20 @@ pub fn build_expression(node: &Rc) -> Option { Some(item) } -pub fn build_arguments_declaration(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ArgumentsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_arguments_declaration(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ArgumentsDeclaration); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::PositionalArgumentsDeclaration) => { ArgumentsDeclaration::PositionalArgumentsDeclaration( - build_positional_arguments_declaration(nonterminal_node(variant))?, + build_positional_arguments_declaration(variant)?, ) } NodeKind::Nonterminal(NonterminalKind::NamedArgumentsDeclaration) => { ArgumentsDeclaration::NamedArgumentsDeclaration(build_named_arguments_declaration( - nonterminal_node(variant), + variant, )?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3744,9 +3366,10 @@ pub fn build_arguments_declaration(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NumberUnit); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_number_unit(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NumberUnit); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::WeiKeyword) => NumberUnit::WeiKeyword, @@ -3773,29 +3396,26 @@ pub fn build_number_unit(node: &Rc) -> Option { Some(item) } -pub fn build_string_expression(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StringExpression); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_string_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StringExpression); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::StringLiteral) => { - StringExpression::StringLiteral(build_string_literal(nonterminal_node(variant))?) + StringExpression::StringLiteral(build_string_literal(variant)?) } NodeKind::Nonterminal(NonterminalKind::StringLiterals) => { - StringExpression::StringLiterals(build_string_literals(nonterminal_node(variant))?) + StringExpression::StringLiterals(build_string_literals(variant)?) } NodeKind::Nonterminal(NonterminalKind::HexStringLiteral) => { - StringExpression::HexStringLiteral(build_hex_string_literal(nonterminal_node(variant))?) + StringExpression::HexStringLiteral(build_hex_string_literal(variant)?) } NodeKind::Nonterminal(NonterminalKind::HexStringLiterals) => { - StringExpression::HexStringLiterals(build_hex_string_literals(nonterminal_node( - variant, - ))?) + StringExpression::HexStringLiterals(build_hex_string_literals(variant)?) } NodeKind::Nonterminal(NonterminalKind::UnicodeStringLiterals) => { - StringExpression::UnicodeStringLiterals(build_unicode_string_literals( - nonterminal_node(variant), - )?) + StringExpression::UnicodeStringLiterals(build_unicode_string_literals(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3810,9 +3430,10 @@ pub fn build_string_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StringLiteral); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_string_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StringLiteral); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedStringLiteral) => { @@ -3834,9 +3455,10 @@ pub fn build_string_literal(node: &Rc) -> Option Some(item) } -pub fn build_hex_string_literal(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::HexStringLiteral); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_hex_string_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::HexStringLiteral); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedHexStringLiteral) => { @@ -3858,9 +3480,10 @@ pub fn build_hex_string_literal(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnicodeStringLiteral); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_unicode_string_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UnicodeStringLiteral); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedUnicodeStringLiteral) => { @@ -3882,59 +3505,56 @@ pub fn build_unicode_string_literal(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulStatement); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_statement(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulStatement); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::YulBlock) => { - YulStatement::YulBlock(build_yul_block(nonterminal_node(variant))?) + YulStatement::YulBlock(build_yul_block(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulFunctionDefinition) => { - YulStatement::YulFunctionDefinition(build_yul_function_definition(nonterminal_node( - variant, - ))?) + YulStatement::YulFunctionDefinition(build_yul_function_definition(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulStackAssignmentStatement) => { YulStatement::YulStackAssignmentStatement(build_yul_stack_assignment_statement( - nonterminal_node(variant), + variant, )?) } NodeKind::Nonterminal(NonterminalKind::YulIfStatement) => { - YulStatement::YulIfStatement(build_yul_if_statement(nonterminal_node(variant))?) + YulStatement::YulIfStatement(build_yul_if_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulForStatement) => { - YulStatement::YulForStatement(build_yul_for_statement(nonterminal_node(variant))?) + YulStatement::YulForStatement(build_yul_for_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulSwitchStatement) => { - YulStatement::YulSwitchStatement(build_yul_switch_statement(nonterminal_node(variant))?) + YulStatement::YulSwitchStatement(build_yul_switch_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulLeaveStatement) => { - YulStatement::YulLeaveStatement(build_yul_leave_statement(nonterminal_node(variant))?) + YulStatement::YulLeaveStatement(build_yul_leave_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulBreakStatement) => { - YulStatement::YulBreakStatement(build_yul_break_statement(nonterminal_node(variant))?) + YulStatement::YulBreakStatement(build_yul_break_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulContinueStatement) => { - YulStatement::YulContinueStatement(build_yul_continue_statement(nonterminal_node( - variant, - ))?) + YulStatement::YulContinueStatement(build_yul_continue_statement(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulVariableAssignmentStatement) => { YulStatement::YulVariableAssignmentStatement(build_yul_variable_assignment_statement( - nonterminal_node(variant), + variant, )?) } NodeKind::Nonterminal(NonterminalKind::YulLabel) => { - YulStatement::YulLabel(build_yul_label(nonterminal_node(variant))?) + YulStatement::YulLabel(build_yul_label(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulVariableDeclarationStatement) => { YulStatement::YulVariableDeclarationStatement(build_yul_variable_declaration_statement( - nonterminal_node(variant), + variant, )?) } NodeKind::Nonterminal(NonterminalKind::YulExpression) => { - YulStatement::YulExpression(build_yul_expression(nonterminal_node(variant))?) + YulStatement::YulExpression(build_yul_expression(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -3949,15 +3569,14 @@ pub fn build_yul_statement(node: &Rc) -> Option { Some(item) } -pub fn build_yul_assignment_operator(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulAssignmentOperator); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_assignment_operator(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulAssignmentOperator); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::YulColonAndEqual) => { - YulAssignmentOperator::YulColonAndEqual(build_yul_colon_and_equal(nonterminal_node( - variant, - ))?) + YulAssignmentOperator::YulColonAndEqual(build_yul_colon_and_equal(variant)?) } NodeKind::Terminal(TerminalKind::ColonEqual) => YulAssignmentOperator::ColonEqual, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3973,17 +3592,16 @@ pub fn build_yul_assignment_operator(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulStackAssignmentOperator); - let mut helper = ChildrenHelper::new(&node.children); + assert_nonterminal_kind(&node, NonterminalKind::YulStackAssignmentOperator); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::YulEqualAndColon) => { - YulStackAssignmentOperator::YulEqualAndColon(build_yul_equal_and_colon( - nonterminal_node(variant), - )?) + YulStackAssignmentOperator::YulEqualAndColon(build_yul_equal_and_colon(variant)?) } NodeKind::Terminal(TerminalKind::EqualColon) => YulStackAssignmentOperator::EqualColon, NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { @@ -3999,16 +3617,17 @@ pub fn build_yul_stack_assignment_operator( Some(item) } -pub fn build_yul_switch_case(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulSwitchCase); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_switch_case(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulSwitchCase); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::YulDefaultCase) => { - YulSwitchCase::YulDefaultCase(build_yul_default_case(nonterminal_node(variant))?) + YulSwitchCase::YulDefaultCase(build_yul_default_case(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulValueCase) => { - YulSwitchCase::YulValueCase(build_yul_value_case(nonterminal_node(variant))?) + YulSwitchCase::YulValueCase(build_yul_value_case(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -4023,21 +3642,20 @@ pub fn build_yul_switch_case(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulExpression); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_expression(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulExpression); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::YulFunctionCallExpression) => { - YulExpression::YulFunctionCallExpression(build_yul_function_call_expression( - nonterminal_node(variant), - )?) + YulExpression::YulFunctionCallExpression(build_yul_function_call_expression(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulLiteral) => { - YulExpression::YulLiteral(build_yul_literal(nonterminal_node(variant))?) + YulExpression::YulLiteral(build_yul_literal(variant)?) } NodeKind::Nonterminal(NonterminalKind::YulPath) => { - YulExpression::YulPath(build_yul_path(nonterminal_node(variant))?) + YulExpression::YulPath(build_yul_path(variant)?) } NodeKind::Nonterminal(_) | NodeKind::Terminal(_) => { unreachable!( @@ -4052,16 +3670,17 @@ pub fn build_yul_expression(node: &Rc) -> Option Some(item) } -pub fn build_yul_literal(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulLiteral); - let mut helper = ChildrenHelper::new(&node.children); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulLiteral); + let mut helper = ChildrenHelper::new(&node); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Nonterminal(NonterminalKind::HexStringLiteral) => { - YulLiteral::HexStringLiteral(build_hex_string_literal(nonterminal_node(variant))?) + YulLiteral::HexStringLiteral(build_hex_string_literal(variant)?) } NodeKind::Nonterminal(NonterminalKind::StringLiteral) => { - YulLiteral::StringLiteral(build_string_literal(nonterminal_node(variant))?) + YulLiteral::StringLiteral(build_string_literal(variant)?) } NodeKind::Terminal(TerminalKind::YulDecimalLiteral) => { YulLiteral::YulDecimalLiteral(terminal_node_cloned(variant)) @@ -4088,15 +3707,16 @@ pub fn build_yul_literal(node: &Rc) -> Option { // Repeated & Separated // -pub fn build_source_unit_members(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::SourceUnitMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_source_unit_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::SourceUnitMembers); let mut items = SourceUnitMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_source_unit_member(nonterminal_node(child)) { + if let Some(item) = build_source_unit_member(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4104,15 +3724,16 @@ pub fn build_source_unit_members(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionExpressionSets); +#[allow(clippy::needless_pass_by_value)] +pub fn build_version_expression_sets(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionExpressionSets); let mut items = VersionExpressionSets::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_version_expression_set(nonterminal_node(child)) { + if let Some(item) = build_version_expression_set(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4120,15 +3741,16 @@ pub fn build_version_expression_sets(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VersionExpressionSet); +#[allow(clippy::needless_pass_by_value)] +pub fn build_version_expression_set(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::VersionExpressionSet); let mut items = VersionExpressionSet::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_version_expression(nonterminal_node(child)) { + if let Some(item) = build_version_expression(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4136,13 +3758,14 @@ pub fn build_version_expression_set(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::SimpleVersionLiteral); +#[allow(clippy::needless_pass_by_value)] +pub fn build_simple_version_literal(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::SimpleVersionLiteral); let mut items = SimpleVersionLiteral::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4150,17 +3773,18 @@ pub fn build_simple_version_literal(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ImportDeconstructionSymbols); + assert_nonterminal_kind(&node, NonterminalKind::ImportDeconstructionSymbols); let mut items = ImportDeconstructionSymbols::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_import_deconstruction_symbol(nonterminal_node(child)) { + if let Some(item) = build_import_deconstruction_symbol(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4168,17 +3792,18 @@ pub fn build_import_deconstruction_symbols( Some(items) } +#[allow(clippy::needless_pass_by_value)] pub fn build_using_deconstruction_symbols( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UsingDeconstructionSymbols); + assert_nonterminal_kind(&node, NonterminalKind::UsingDeconstructionSymbols); let mut items = UsingDeconstructionSymbols::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_using_deconstruction_symbol(nonterminal_node(child)) { + if let Some(item) = build_using_deconstruction_symbol(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4186,15 +3811,16 @@ pub fn build_using_deconstruction_symbols( Some(items) } -pub fn build_contract_specifiers(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContractSpecifiers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_contract_specifiers(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContractSpecifiers); let mut items = ContractSpecifiers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_contract_specifier(nonterminal_node(child)) { + if let Some(item) = build_contract_specifier(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4202,15 +3828,16 @@ pub fn build_contract_specifiers(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InheritanceTypes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_inheritance_types(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InheritanceTypes); let mut items = InheritanceTypes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_inheritance_type(nonterminal_node(child)) { + if let Some(item) = build_inheritance_type(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4218,15 +3845,16 @@ pub fn build_inheritance_types(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ContractMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_contract_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ContractMembers); let mut items = ContractMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_contract_member(nonterminal_node(child)) { + if let Some(item) = build_contract_member(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4234,15 +3862,16 @@ pub fn build_contract_members(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InterfaceMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_interface_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::InterfaceMembers); let mut items = InterfaceMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_contract_member(nonterminal_node(child)) { + if let Some(item) = build_contract_member(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4250,15 +3879,16 @@ pub fn build_interface_members(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::LibraryMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_library_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::LibraryMembers); let mut items = LibraryMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_contract_member(nonterminal_node(child)) { + if let Some(item) = build_contract_member(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4266,15 +3896,16 @@ pub fn build_library_members(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StructMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_struct_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StructMembers); let mut items = StructMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_struct_member(nonterminal_node(child)) { + if let Some(item) = build_struct_member(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4282,13 +3913,14 @@ pub fn build_struct_members(node: &Rc) -> Option Some(items) } -pub fn build_enum_members(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EnumMembers); +#[allow(clippy::needless_pass_by_value)] +pub fn build_enum_members(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EnumMembers); let mut items = EnumMembers::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4296,17 +3928,16 @@ pub fn build_enum_members(node: &Rc) -> Option { Some(items) } -pub fn build_state_variable_attributes( - node: &Rc, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StateVariableAttributes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_state_variable_attributes(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StateVariableAttributes); let mut items = StateVariableAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_state_variable_attribute(nonterminal_node(child)) { + if let Some(item) = build_state_variable_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4314,15 +3945,16 @@ pub fn build_state_variable_attributes( Some(items) } -pub fn build_parameters(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Parameters); +#[allow(clippy::needless_pass_by_value)] +pub fn build_parameters(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Parameters); let mut items = Parameters::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_parameter(nonterminal_node(child)) { + if let Some(item) = build_parameter(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4330,15 +3962,16 @@ pub fn build_parameters(node: &Rc) -> Option { Some(items) } -pub fn build_function_attributes(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionAttributes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_attributes(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionAttributes); let mut items = FunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_function_attribute(nonterminal_node(child)) { + if let Some(item) = build_function_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4346,15 +3979,16 @@ pub fn build_function_attributes(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::OverridePaths); +#[allow(clippy::needless_pass_by_value)] +pub fn build_override_paths(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::OverridePaths); let mut items = OverridePaths::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_identifier_path(nonterminal_node(child)) { + if let Some(item) = build_identifier_path(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4362,15 +3996,16 @@ pub fn build_override_paths(node: &Rc) -> Option Some(items) } -pub fn build_constructor_attributes(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConstructorAttributes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_constructor_attributes(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ConstructorAttributes); let mut items = ConstructorAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_constructor_attribute(nonterminal_node(child)) { + if let Some(item) = build_constructor_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4378,17 +4013,18 @@ pub fn build_constructor_attributes(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionAttributes); + assert_nonterminal_kind(&node, NonterminalKind::UnnamedFunctionAttributes); let mut items = UnnamedFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_unnamed_function_attribute(nonterminal_node(child)) { + if let Some(item) = build_unnamed_function_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4396,17 +4032,18 @@ pub fn build_unnamed_function_attributes( Some(items) } +#[allow(clippy::needless_pass_by_value)] pub fn build_fallback_function_attributes( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FallbackFunctionAttributes); + assert_nonterminal_kind(&node, NonterminalKind::FallbackFunctionAttributes); let mut items = FallbackFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_fallback_function_attribute(nonterminal_node(child)) { + if let Some(item) = build_fallback_function_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4414,17 +4051,18 @@ pub fn build_fallback_function_attributes( Some(items) } +#[allow(clippy::needless_pass_by_value)] pub fn build_receive_function_attributes( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ReceiveFunctionAttributes); + assert_nonterminal_kind(&node, NonterminalKind::ReceiveFunctionAttributes); let mut items = ReceiveFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_receive_function_attribute(nonterminal_node(child)) { + if let Some(item) = build_receive_function_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4432,15 +4070,16 @@ pub fn build_receive_function_attributes( Some(items) } -pub fn build_modifier_attributes(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ModifierAttributes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_modifier_attributes(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ModifierAttributes); let mut items = ModifierAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_modifier_attribute(nonterminal_node(child)) { + if let Some(item) = build_modifier_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4448,15 +4087,16 @@ pub fn build_modifier_attributes(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventParameters); +#[allow(clippy::needless_pass_by_value)] +pub fn build_event_parameters(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::EventParameters); let mut items = EventParameters::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_event_parameter(nonterminal_node(child)) { + if let Some(item) = build_event_parameter(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4464,15 +4104,16 @@ pub fn build_event_parameters(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ErrorParameters); +#[allow(clippy::needless_pass_by_value)] +pub fn build_error_parameters(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ErrorParameters); let mut items = ErrorParameters::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_error_parameter(nonterminal_node(child)) { + if let Some(item) = build_error_parameter(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4480,17 +4121,16 @@ pub fn build_error_parameters(node: &Rc) -> Option, -) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionTypeAttributes); +#[allow(clippy::needless_pass_by_value)] +pub fn build_function_type_attributes(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::FunctionTypeAttributes); let mut items = FunctionTypeAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_function_type_attribute(nonterminal_node(child)) { + if let Some(item) = build_function_type_attribute(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4498,15 +4138,16 @@ pub fn build_function_type_attributes( Some(items) } -pub fn build_statements(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::Statements); +#[allow(clippy::needless_pass_by_value)] +pub fn build_statements(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::Statements); let mut items = Statements::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_statement(nonterminal_node(child)) { + if let Some(item) = build_statement(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4514,15 +4155,16 @@ pub fn build_statements(node: &Rc) -> Option { Some(items) } -pub fn build_assembly_flags(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AssemblyFlags); +#[allow(clippy::needless_pass_by_value)] +pub fn build_assembly_flags(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::AssemblyFlags); let mut items = AssemblyFlags::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_string_literal(nonterminal_node(child)) { + if let Some(item) = build_string_literal(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4530,17 +4172,18 @@ pub fn build_assembly_flags(node: &Rc) -> Option Some(items) } +#[allow(clippy::needless_pass_by_value)] pub fn build_tuple_deconstruction_elements( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleDeconstructionElements); + assert_nonterminal_kind(&node, NonterminalKind::TupleDeconstructionElements); let mut items = TupleDeconstructionElements::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_tuple_deconstruction_element(nonterminal_node(child)) { + if let Some(item) = build_tuple_deconstruction_element(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4548,15 +4191,16 @@ pub fn build_tuple_deconstruction_elements( Some(items) } -pub fn build_catch_clauses(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CatchClauses); +#[allow(clippy::needless_pass_by_value)] +pub fn build_catch_clauses(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::CatchClauses); let mut items = CatchClauses::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_catch_clause(nonterminal_node(child)) { + if let Some(item) = build_catch_clause(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4564,15 +4208,16 @@ pub fn build_catch_clauses(node: &Rc) -> Option { Some(items) } -pub fn build_positional_arguments(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PositionalArguments); +#[allow(clippy::needless_pass_by_value)] +pub fn build_positional_arguments(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::PositionalArguments); let mut items = PositionalArguments::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_expression(nonterminal_node(child)) { + if let Some(item) = build_expression(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4580,15 +4225,16 @@ pub fn build_positional_arguments(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::NamedArguments); +#[allow(clippy::needless_pass_by_value)] +pub fn build_named_arguments(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::NamedArguments); let mut items = NamedArguments::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_named_argument(nonterminal_node(child)) { + if let Some(item) = build_named_argument(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4596,15 +4242,16 @@ pub fn build_named_arguments(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CallOptions); +#[allow(clippy::needless_pass_by_value)] +pub fn build_call_options(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::CallOptions); let mut items = CallOptions::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_named_argument(nonterminal_node(child)) { + if let Some(item) = build_named_argument(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4612,15 +4259,16 @@ pub fn build_call_options(node: &Rc) -> Option { Some(items) } -pub fn build_tuple_values(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::TupleValues); +#[allow(clippy::needless_pass_by_value)] +pub fn build_tuple_values(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::TupleValues); let mut items = TupleValues::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_tuple_value(nonterminal_node(child)) { + if let Some(item) = build_tuple_value(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4628,15 +4276,16 @@ pub fn build_tuple_values(node: &Rc) -> Option { Some(items) } -pub fn build_array_values(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ArrayValues); +#[allow(clippy::needless_pass_by_value)] +pub fn build_array_values(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::ArrayValues); let mut items = ArrayValues::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_expression(nonterminal_node(child)) { + if let Some(item) = build_expression(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4644,15 +4293,16 @@ pub fn build_array_values(node: &Rc) -> Option { Some(items) } -pub fn build_string_literals(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StringLiterals); +#[allow(clippy::needless_pass_by_value)] +pub fn build_string_literals(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::StringLiterals); let mut items = StringLiterals::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_string_literal(nonterminal_node(child)) { + if let Some(item) = build_string_literal(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4660,15 +4310,16 @@ pub fn build_string_literals(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::HexStringLiterals); +#[allow(clippy::needless_pass_by_value)] +pub fn build_hex_string_literals(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::HexStringLiterals); let mut items = HexStringLiterals::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_hex_string_literal(nonterminal_node(child)) { + if let Some(item) = build_hex_string_literal(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4676,15 +4327,16 @@ pub fn build_hex_string_literals(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnicodeStringLiterals); +#[allow(clippy::needless_pass_by_value)] +pub fn build_unicode_string_literals(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::UnicodeStringLiterals); let mut items = UnicodeStringLiterals::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_unicode_string_literal(nonterminal_node(child)) { + if let Some(item) = build_unicode_string_literal(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4692,13 +4344,14 @@ pub fn build_unicode_string_literals(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::IdentifierPath); +#[allow(clippy::needless_pass_by_value)] +pub fn build_identifier_path(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::IdentifierPath); let mut items = IdentifierPath::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4706,15 +4359,16 @@ pub fn build_identifier_path(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulStatements); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_statements(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulStatements); let mut items = YulStatements::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_yul_statement(nonterminal_node(child)) { + if let Some(item) = build_yul_statement(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4722,13 +4376,14 @@ pub fn build_yul_statements(node: &Rc) -> Option Some(items) } -pub fn build_yul_parameters(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulParameters); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_parameters(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulParameters); let mut items = YulParameters::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4736,13 +4391,14 @@ pub fn build_yul_parameters(node: &Rc) -> Option Some(items) } -pub fn build_yul_variable_names(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulVariableNames); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_variable_names(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulVariableNames); let mut items = YulVariableNames::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4750,15 +4406,16 @@ pub fn build_yul_variable_names(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulSwitchCases); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_switch_cases(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulSwitchCases); let mut items = YulSwitchCases::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_yul_switch_case(nonterminal_node(child)) { + if let Some(item) = build_yul_switch_case(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4766,15 +4423,16 @@ pub fn build_yul_switch_cases(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulArguments); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_arguments(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulArguments); let mut items = YulArguments::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_yul_expression(nonterminal_node(child)) { + if let Some(item) = build_yul_expression(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4782,15 +4440,16 @@ pub fn build_yul_arguments(node: &Rc) -> Option { Some(items) } -pub fn build_yul_paths(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulPaths); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_paths(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulPaths); let mut items = YulPaths::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { - if let Some(item) = build_yul_path(nonterminal_node(child)) { + if let Some(item) = build_yul_path(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4798,13 +4457,14 @@ pub fn build_yul_paths(node: &Rc) -> Option { Some(items) } -pub fn build_yul_path(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulPath); +#[allow(clippy::needless_pass_by_value)] +pub fn build_yul_path(node: Rc) -> Option { + assert_nonterminal_kind(&node, NonterminalKind::YulPath); let mut items = YulPath::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(&node); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4818,37 +4478,31 @@ pub fn build_yul_path(node: &Rc) -> Option { #[allow(dead_code)] #[inline] -fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { +fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { assert_eq!( - node.kind, kind, + node.kind(), + NodeKind::Nonterminal(kind), "expected non-terminal of kind {kind}, got {node:?}" ); } #[allow(dead_code)] #[inline] -fn terminal_node_cloned(node: &Node) -> Rc { - node.as_terminal() - .map(Rc::clone) - .expect("expected terminal node") -} - -#[allow(dead_code)] -#[inline] -fn nonterminal_node(node: &Node) -> &Rc { - node.as_nonterminal().expect("expected non-terminal node") +fn terminal_node_cloned(node: Rc) -> Rc { + assert!(node.is_terminal(), "expected terminal node"); + node } struct ChildrenHelper<'a> { - children: &'a Vec, + children: &'a Rc, index: usize, } impl<'a> ChildrenHelper<'a> { - fn new(children: &'a Vec) -> Self { + fn new(children: &'a Rc) -> Self { let mut index = 0; - while index < children.len() { - if !children[index].is_trivia() && children[index].is_valid() { + while index < children.children_count() { + if children.child_is_valid_and_not_trivia(index) { break; } index += 1; @@ -4856,27 +4510,34 @@ impl<'a> ChildrenHelper<'a> { Self { children, index } } - fn accept_label(&mut self, label: EdgeLabel) -> Option<&Node> { - if self.index >= self.children.len() || self.children[self.index].label != label { + fn skip_label(&mut self, label: EdgeLabel) -> Option { + if self.index >= self.children.children_count() + || self.children.child_label(self.index) != label + { return None; } - let node = &self.children[self.index].node; + let result = self.index; loop { self.index += 1; - if self.index >= self.children.len() - || (!self.children[self.index].is_trivia() && self.children[self.index].is_valid()) + if self.index >= self.children.children_count() + || self.children.child_is_valid_and_not_trivia(self.index) { break; } } - Some(node) + Some(result) + } + + fn accept_label(&mut self, label: EdgeLabel) -> Option> { + let index = self.skip_label(label)?; + Some(self.children.nth_child(index)) } fn finalize(mut self) -> bool { // skip over trailing trivia and unrecognized nodes - while self.index < self.children.len() { - if !self.children[self.index].is_trivia() && self.children[self.index].is_valid() { + while self.index < self.children.children_count() { + if self.children.child_is_valid_and_not_trivia(self.index) { return false; } self.index += 1; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/nodes.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/nodes.generated.rs index 186fc81738..b0d41e40be 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/nodes.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/nodes.generated.rs @@ -5,7 +5,7 @@ use std::vec::Vec; use metaslang_cst::nodes::NodeId; -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; // // Sequences: @@ -15,263 +15,437 @@ pub type SourceUnit = Rc; #[derive(Debug)] pub struct SourceUnitStruct { - pub node_id: NodeId, + pub node: Rc, pub members: SourceUnitMembers, } +impl SourceUnitStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PragmaDirective = Rc; #[derive(Debug)] pub struct PragmaDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub pragma: Pragma, } +impl PragmaDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AbicoderPragma = Rc; #[derive(Debug)] pub struct AbicoderPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub version: AbicoderVersion, } +impl AbicoderPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExperimentalPragma = Rc; #[derive(Debug)] pub struct ExperimentalPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub feature: ExperimentalFeature, } +impl ExperimentalPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionPragma = Rc; #[derive(Debug)] pub struct VersionPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub sets: VersionExpressionSets, } +impl VersionPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionRange = Rc; #[derive(Debug)] pub struct VersionRangeStruct { - pub node_id: NodeId, + pub node: Rc, pub start: VersionLiteral, pub end: VersionLiteral, } +impl VersionRangeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionTerm = Rc; #[derive(Debug)] pub struct VersionTermStruct { - pub node_id: NodeId, + pub node: Rc, pub operator: Option, pub literal: VersionLiteral, } +impl VersionTermStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportDirective = Rc; #[derive(Debug)] pub struct ImportDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub clause: ImportClause, } +impl ImportDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PathImport = Rc; #[derive(Debug)] pub struct PathImportStruct { - pub node_id: NodeId, + pub node: Rc, pub path: StringLiteral, pub alias: Option, } +impl PathImportStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NamedImport = Rc; #[derive(Debug)] pub struct NamedImportStruct { - pub node_id: NodeId, + pub node: Rc, pub alias: ImportAlias, pub path: StringLiteral, } +impl NamedImportStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportDeconstruction = Rc; #[derive(Debug)] pub struct ImportDeconstructionStruct { - pub node_id: NodeId, + pub node: Rc, pub symbols: ImportDeconstructionSymbols, pub path: StringLiteral, } +impl ImportDeconstructionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportDeconstructionSymbol = Rc; #[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub alias: Option, } +impl ImportDeconstructionSymbolStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportAlias = Rc; #[derive(Debug)] pub struct ImportAliasStruct { - pub node_id: NodeId, - pub identifier: Rc, + pub node: Rc, + pub identifier: Rc, +} + +impl ImportAliasStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UsingDirective = Rc; #[derive(Debug)] pub struct UsingDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub clause: UsingClause, pub target: UsingTarget, pub global_keyword: bool, } +impl UsingDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UsingDeconstruction = Rc; #[derive(Debug)] pub struct UsingDeconstructionStruct { - pub node_id: NodeId, + pub node: Rc, pub symbols: UsingDeconstructionSymbols, } +impl UsingDeconstructionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UsingDeconstructionSymbol = Rc; #[derive(Debug)] pub struct UsingDeconstructionSymbolStruct { - pub node_id: NodeId, + pub node: Rc, pub name: IdentifierPath, pub alias: Option, } +impl UsingDeconstructionSymbolStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UsingAlias = Rc; #[derive(Debug)] pub struct UsingAliasStruct { - pub node_id: NodeId, + pub node: Rc, pub operator: UsingOperator, } +impl UsingAliasStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ContractDefinition = Rc; #[derive(Debug)] pub struct ContractDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub abstract_keyword: bool, - pub name: Rc, + pub name: Rc, pub specifiers: ContractSpecifiers, pub members: ContractMembers, } +impl ContractDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InheritanceSpecifier = Rc; #[derive(Debug)] pub struct InheritanceSpecifierStruct { - pub node_id: NodeId, + pub node: Rc, pub types: InheritanceTypes, } +impl InheritanceSpecifierStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InheritanceType = Rc; #[derive(Debug)] pub struct InheritanceTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: IdentifierPath, pub arguments: Option, } +impl InheritanceTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StorageLayoutSpecifier = Rc; #[derive(Debug)] pub struct StorageLayoutSpecifierStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, } +impl StorageLayoutSpecifierStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InterfaceDefinition = Rc; #[derive(Debug)] pub struct InterfaceDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub inheritance: Option, pub members: InterfaceMembers, } +impl InterfaceDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type LibraryDefinition = Rc; #[derive(Debug)] pub struct LibraryDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: LibraryMembers, } +impl LibraryDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StructDefinition = Rc; #[derive(Debug)] pub struct StructDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: StructMembers, } +impl StructDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StructMember = Rc; #[derive(Debug)] pub struct StructMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, +} + +impl StructMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: EnumMembers, } +impl EnumDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ConstantDefinition = Rc; #[derive(Debug)] pub struct ConstantDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Expression, } +impl ConstantDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StateVariableDefinition = Rc; #[derive(Debug)] pub struct StateVariableDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub attributes: StateVariableAttributes, - pub name: Rc, + pub name: Rc, pub value: Option, } +impl StateVariableDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StateVariableDefinitionValue = Rc; #[derive(Debug)] pub struct StateVariableDefinitionValueStruct { - pub node_id: NodeId, + pub node: Rc, pub value: Expression, } +impl StateVariableDefinitionValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionDefinition = Rc; #[derive(Debug)] pub struct FunctionDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub name: FunctionName, pub parameters: ParametersDeclaration, pub attributes: FunctionAttributes, @@ -279,896 +453,1502 @@ pub struct FunctionDefinitionStruct { pub body: FunctionBody, } +impl FunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ParametersDeclaration = Rc; #[derive(Debug)] pub struct ParametersDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: Parameters, } +impl ParametersDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type Parameter = Rc; #[derive(Debug)] pub struct ParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Option>, + pub name: Option>, +} + +impl ParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type OverrideSpecifier = Rc; #[derive(Debug)] pub struct OverrideSpecifierStruct { - pub node_id: NodeId, + pub node: Rc, pub overridden: Option, } +impl OverrideSpecifierStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type OverridePathsDeclaration = Rc; #[derive(Debug)] pub struct OverridePathsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub paths: OverridePaths, } +impl OverridePathsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ReturnsDeclaration = Rc; #[derive(Debug)] pub struct ReturnsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: ParametersDeclaration, } +impl ReturnsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ConstructorDefinition = Rc; #[derive(Debug)] pub struct ConstructorDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ParametersDeclaration, pub attributes: ConstructorAttributes, pub body: Block, } +impl ConstructorDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UnnamedFunctionDefinition = Rc; #[derive(Debug)] pub struct UnnamedFunctionDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ParametersDeclaration, pub attributes: UnnamedFunctionAttributes, pub body: FunctionBody, } +impl UnnamedFunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FallbackFunctionDefinition = Rc; #[derive(Debug)] pub struct FallbackFunctionDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ParametersDeclaration, pub attributes: FallbackFunctionAttributes, pub returns: Option, pub body: FunctionBody, } +impl FallbackFunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ReceiveFunctionDefinition = Rc; #[derive(Debug)] pub struct ReceiveFunctionDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ParametersDeclaration, pub attributes: ReceiveFunctionAttributes, pub body: FunctionBody, } +impl ReceiveFunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ModifierDefinition = Rc; #[derive(Debug)] pub struct ModifierDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub parameters: Option, pub attributes: ModifierAttributes, pub body: FunctionBody, } +impl ModifierDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ModifierInvocation = Rc; #[derive(Debug)] pub struct ModifierInvocationStruct { - pub node_id: NodeId, + pub node: Rc, pub name: IdentifierPath, pub arguments: Option, } +impl ModifierInvocationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EventDefinition = Rc; #[derive(Debug)] pub struct EventDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub parameters: EventParametersDeclaration, pub anonymous_keyword: bool, } +impl EventDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EventParametersDeclaration = Rc; #[derive(Debug)] pub struct EventParametersDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: EventParameters, } +impl EventParametersDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EventParameter = Rc; #[derive(Debug)] pub struct EventParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub indexed_keyword: bool, - pub name: Option>, + pub name: Option>, +} + +impl EventParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UserDefinedValueTypeDefinition = Rc; #[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub value_type: ElementaryType, } +impl UserDefinedValueTypeDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ErrorDefinition = Rc; #[derive(Debug)] pub struct ErrorDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: ErrorParametersDeclaration, } +impl ErrorDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ErrorParametersDeclaration = Rc; #[derive(Debug)] pub struct ErrorParametersDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ErrorParameters, } +impl ErrorParametersDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ErrorParameter = Rc; #[derive(Debug)] pub struct ErrorParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, +} + +impl ErrorParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ArrayTypeName = Rc; #[derive(Debug)] pub struct ArrayTypeNameStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: TypeName, pub index: Option, } +impl ArrayTypeNameStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionType = Rc; #[derive(Debug)] pub struct FunctionTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: ParametersDeclaration, pub attributes: FunctionTypeAttributes, pub returns: Option, } +impl FunctionTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MappingType = Rc; #[derive(Debug)] pub struct MappingTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub key_type: MappingKey, pub value_type: MappingValue, } +impl MappingTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MappingKey = Rc; #[derive(Debug)] pub struct MappingKeyStruct { - pub node_id: NodeId, + pub node: Rc, pub key_type: MappingKeyType, - pub name: Option>, + pub name: Option>, +} + +impl MappingKeyStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type MappingValue = Rc; #[derive(Debug)] pub struct MappingValueStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, +} + +impl MappingValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type AddressType = Rc; #[derive(Debug)] pub struct AddressTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub payable_keyword: bool, } +impl AddressTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type Block = Rc; #[derive(Debug)] pub struct BlockStruct { - pub node_id: NodeId, + pub node: Rc, pub statements: Statements, } +impl BlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UncheckedBlock = Rc; #[derive(Debug)] pub struct UncheckedBlockStruct { - pub node_id: NodeId, + pub node: Rc, pub block: Block, } +impl UncheckedBlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExpressionStatement = Rc; #[derive(Debug)] pub struct ExpressionStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, } +impl ExpressionStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AssemblyStatement = Rc; #[derive(Debug)] pub struct AssemblyStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub label: Option, pub flags: Option, pub body: YulBlock, } +impl AssemblyStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AssemblyFlagsDeclaration = Rc; #[derive(Debug)] pub struct AssemblyFlagsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub flags: AssemblyFlags, } +impl AssemblyFlagsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleDeconstructionStatement = Rc; #[derive(Debug)] pub struct TupleDeconstructionStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub var_keyword: bool, pub elements: TupleDeconstructionElements, pub expression: Expression, } +impl TupleDeconstructionStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleDeconstructionElement = Rc; #[derive(Debug)] pub struct TupleDeconstructionElementStruct { - pub node_id: NodeId, + pub node: Rc, pub member: Option, } +impl TupleDeconstructionElementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TypedTupleMember = Rc; #[derive(Debug)] pub struct TypedTupleMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Rc, + pub name: Rc, +} + +impl TypedTupleMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UntypedTupleMember = Rc; #[derive(Debug)] pub struct UntypedTupleMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub storage_location: Option, - pub name: Rc, + pub name: Rc, +} + +impl UntypedTupleMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type VariableDeclarationStatement = Rc; #[derive(Debug)] pub struct VariableDeclarationStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variable_type: VariableDeclarationType, pub storage_location: Option, - pub name: Rc, + pub name: Rc, pub value: Option, } +impl VariableDeclarationStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VariableDeclarationValue = Rc; #[derive(Debug)] pub struct VariableDeclarationValueStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, } +impl VariableDeclarationValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type IfStatement = Rc; #[derive(Debug)] pub struct IfStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: Expression, pub body: Statement, pub else_branch: Option, } +impl IfStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ElseBranch = Rc; #[derive(Debug)] pub struct ElseBranchStruct { - pub node_id: NodeId, + pub node: Rc, pub body: Statement, } +impl ElseBranchStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ForStatement = Rc; #[derive(Debug)] pub struct ForStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub initialization: ForStatementInitialization, pub condition: ForStatementCondition, pub iterator: Option, pub body: Statement, } +impl ForStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type WhileStatement = Rc; #[derive(Debug)] pub struct WhileStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: Expression, pub body: Statement, } +impl WhileStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type DoWhileStatement = Rc; #[derive(Debug)] pub struct DoWhileStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub body: Statement, pub condition: Expression, } +impl DoWhileStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ContinueStatement = Rc; #[derive(Debug)] pub struct ContinueStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl ContinueStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type BreakStatement = Rc; #[derive(Debug)] pub struct BreakStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl BreakStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ReturnStatement = Rc; #[derive(Debug)] pub struct ReturnStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Option, } +impl ReturnStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EmitStatement = Rc; #[derive(Debug)] pub struct EmitStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub event: IdentifierPath, pub arguments: ArgumentsDeclaration, } +impl EmitStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TryStatement = Rc; #[derive(Debug)] pub struct TryStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, pub returns: Option, pub body: Block, pub catch_clauses: CatchClauses, } +impl TryStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CatchClause = Rc; #[derive(Debug)] pub struct CatchClauseStruct { - pub node_id: NodeId, + pub node: Rc, pub error: Option, pub body: Block, } +impl CatchClauseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CatchClauseError = Rc; #[derive(Debug)] pub struct CatchClauseErrorStruct { - pub node_id: NodeId, - pub name: Option>, + pub node: Rc, + pub name: Option>, pub parameters: ParametersDeclaration, } +impl CatchClauseErrorStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type RevertStatement = Rc; #[derive(Debug)] pub struct RevertStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub error: Option, pub arguments: ArgumentsDeclaration, } +impl RevertStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ThrowStatement = Rc; #[derive(Debug)] pub struct ThrowStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl ThrowStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type AssignmentExpression = Rc; #[derive(Debug)] pub struct AssignmentExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl AssignmentExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ConditionalExpression = Rc; #[derive(Debug)] pub struct ConditionalExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub true_expression: Expression, pub false_expression: Expression, } +impl ConditionalExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type OrExpression = Rc; #[derive(Debug)] pub struct OrExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl OrExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AndExpression = Rc; #[derive(Debug)] pub struct AndExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl AndExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EqualityExpression = Rc; #[derive(Debug)] pub struct EqualityExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl EqualityExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InequalityExpression = Rc; #[derive(Debug)] pub struct InequalityExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl InequalityExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseOrExpression = Rc; #[derive(Debug)] pub struct BitwiseOrExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseOrExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseXorExpression = Rc; #[derive(Debug)] pub struct BitwiseXorExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseXorExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseAndExpression = Rc; #[derive(Debug)] pub struct BitwiseAndExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseAndExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ShiftExpression = Rc; #[derive(Debug)] pub struct ShiftExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl ShiftExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AdditiveExpression = Rc; #[derive(Debug)] pub struct AdditiveExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl AdditiveExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MultiplicativeExpression = Rc; #[derive(Debug)] pub struct MultiplicativeExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl MultiplicativeExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExponentiationExpression = Rc; #[derive(Debug)] pub struct ExponentiationExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl ExponentiationExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PostfixExpression = Rc; #[derive(Debug)] pub struct PostfixExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, - pub operator: Rc, + pub operator: Rc, +} + +impl PostfixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { - pub node_id: NodeId, - pub operator: Rc, + pub node: Rc, + pub operator: Rc, pub operand: Expression, } +impl PrefixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionCallExpression = Rc; #[derive(Debug)] pub struct FunctionCallExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub arguments: ArgumentsDeclaration, } +impl FunctionCallExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CallOptionsExpression = Rc; #[derive(Debug)] pub struct CallOptionsExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub options: CallOptions, } +impl CallOptionsExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MemberAccessExpression = Rc; #[derive(Debug)] pub struct MemberAccessExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, - pub member: Rc, + pub member: Rc, +} + +impl MemberAccessExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type IndexAccessExpression = Rc; #[derive(Debug)] pub struct IndexAccessExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub start: Option, pub end: Option, } +impl IndexAccessExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type IndexAccessEnd = Rc; #[derive(Debug)] pub struct IndexAccessEndStruct { - pub node_id: NodeId, + pub node: Rc, pub end: Option, } +impl IndexAccessEndStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PositionalArgumentsDeclaration = Rc; #[derive(Debug)] pub struct PositionalArgumentsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub arguments: PositionalArguments, } +impl PositionalArgumentsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NamedArgumentsDeclaration = Rc; #[derive(Debug)] pub struct NamedArgumentsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub arguments: Option, } +impl NamedArgumentsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NamedArgumentGroup = Rc; #[derive(Debug)] pub struct NamedArgumentGroupStruct { - pub node_id: NodeId, + pub node: Rc, pub arguments: NamedArguments, } +impl NamedArgumentGroupStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NamedArgument = Rc; #[derive(Debug)] pub struct NamedArgumentStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub value: Expression, } +impl NamedArgumentStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TypeExpression = Rc; #[derive(Debug)] pub struct TypeExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, } +impl TypeExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NewExpression = Rc; #[derive(Debug)] pub struct NewExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, } +impl NewExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleExpression = Rc; #[derive(Debug)] pub struct TupleExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub items: TupleValues, } +impl TupleExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleValue = Rc; #[derive(Debug)] pub struct TupleValueStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Option, } +impl TupleValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ArrayExpression = Rc; #[derive(Debug)] pub struct ArrayExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub items: ArrayValues, } +impl ArrayExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type HexNumberExpression = Rc; #[derive(Debug)] pub struct HexNumberExpressionStruct { - pub node_id: NodeId, - pub literal: Rc, + pub node: Rc, + pub literal: Rc, pub unit: Option, } +impl HexNumberExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type DecimalNumberExpression = Rc; #[derive(Debug)] pub struct DecimalNumberExpressionStruct { - pub node_id: NodeId, - pub literal: Rc, + pub node: Rc, + pub literal: Rc, pub unit: Option, } +impl DecimalNumberExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulBlock = Rc; #[derive(Debug)] pub struct YulBlockStruct { - pub node_id: NodeId, + pub node: Rc, pub statements: YulStatements, } +impl YulBlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulFunctionDefinition = Rc; #[derive(Debug)] pub struct YulFunctionDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub parameters: YulParametersDeclaration, pub returns: Option, pub body: YulBlock, } +impl YulFunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulParametersDeclaration = Rc; #[derive(Debug)] pub struct YulParametersDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: YulParameters, } +impl YulParametersDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulReturnsDeclaration = Rc; #[derive(Debug)] pub struct YulReturnsDeclarationStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: YulVariableNames, } +impl YulReturnsDeclarationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableDeclarationStatement = Rc; #[derive(Debug)] pub struct YulVariableDeclarationStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: YulVariableNames, pub value: Option, } +impl YulVariableDeclarationStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableDeclarationValue = Rc; #[derive(Debug)] pub struct YulVariableDeclarationValueStruct { - pub node_id: NodeId, + pub node: Rc, pub assignment: YulAssignmentOperator, pub expression: YulExpression, } +impl YulVariableDeclarationValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableAssignmentStatement = Rc; #[derive(Debug)] pub struct YulVariableAssignmentStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: YulPaths, pub assignment: YulAssignmentOperator, pub expression: YulExpression, } +impl YulVariableAssignmentStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulColonAndEqual = Rc; #[derive(Debug)] pub struct YulColonAndEqualStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulColonAndEqualStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulStackAssignmentStatement = Rc; #[derive(Debug)] pub struct YulStackAssignmentStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub assignment: YulStackAssignmentOperator, - pub variable: Rc, + pub variable: Rc, +} + +impl YulStackAssignmentStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulEqualAndColon = Rc; #[derive(Debug)] pub struct YulEqualAndColonStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulEqualAndColonStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulIfStatement = Rc; #[derive(Debug)] pub struct YulIfStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: YulExpression, pub body: YulBlock, } +impl YulIfStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulForStatement = Rc; #[derive(Debug)] pub struct YulForStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub initialization: YulBlock, pub condition: YulExpression, pub iterator: YulBlock, pub body: YulBlock, } +impl YulForStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulSwitchStatement = Rc; #[derive(Debug)] pub struct YulSwitchStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: YulExpression, pub cases: YulSwitchCases, } +impl YulSwitchStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulDefaultCase = Rc; #[derive(Debug)] pub struct YulDefaultCaseStruct { - pub node_id: NodeId, + pub node: Rc, pub body: YulBlock, } +impl YulDefaultCaseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulValueCase = Rc; #[derive(Debug)] pub struct YulValueCaseStruct { - pub node_id: NodeId, + pub node: Rc, pub value: YulLiteral, pub body: YulBlock, } +impl YulValueCaseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulLeaveStatement = Rc; #[derive(Debug)] pub struct YulLeaveStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulLeaveStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulBreakStatement = Rc; #[derive(Debug)] pub struct YulBreakStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulBreakStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulContinueStatement = Rc; #[derive(Debug)] pub struct YulContinueStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulContinueStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulLabel = Rc; #[derive(Debug)] pub struct YulLabelStruct { - pub node_id: NodeId, - pub label: Rc, + pub node: Rc, + pub label: Rc, +} + +impl YulLabelStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulFunctionCallExpression = Rc; #[derive(Debug)] pub struct YulFunctionCallExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: YulExpression, pub arguments: YulArguments, } +impl YulFunctionCallExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + // // Choices: // @@ -1230,8 +2010,8 @@ pub enum VersionOperator { #[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), - SingleQuotedVersionLiteral(Rc), - DoubleQuotedVersionLiteral(Rc), + SingleQuotedVersionLiteral(Rc), + DoubleQuotedVersionLiteral(Rc), } #[derive(Debug)] @@ -1308,7 +2088,7 @@ pub enum StateVariableAttribute { #[derive(Debug)] pub enum FunctionName { - Identifier(Rc), + Identifier(Rc), FallbackKeyword, ReceiveKeyword, } @@ -1413,11 +2193,11 @@ pub enum MappingKeyType { #[derive(Debug)] pub enum ElementaryType { AddressType(AddressType), - BytesKeyword(Rc), - IntKeyword(Rc), - UintKeyword(Rc), - FixedKeyword(Rc), - UfixedKeyword(Rc), + BytesKeyword(Rc), + IntKeyword(Rc), + UintKeyword(Rc), + FixedKeyword(Rc), + UfixedKeyword(Rc), BoolKeyword, ByteKeyword, StringKeyword, @@ -1506,7 +2286,7 @@ pub enum Expression { DecimalNumberExpression(DecimalNumberExpression), StringExpression(StringExpression), ElementaryType(ElementaryType), - Identifier(Rc), + Identifier(Rc), PayableKeyword, ThisKeyword, SuperKeyword, @@ -1546,20 +2326,20 @@ pub enum StringExpression { #[derive(Debug)] pub enum StringLiteral { - SingleQuotedStringLiteral(Rc), - DoubleQuotedStringLiteral(Rc), + SingleQuotedStringLiteral(Rc), + DoubleQuotedStringLiteral(Rc), } #[derive(Debug)] pub enum HexStringLiteral { - SingleQuotedHexStringLiteral(Rc), - DoubleQuotedHexStringLiteral(Rc), + SingleQuotedHexStringLiteral(Rc), + DoubleQuotedHexStringLiteral(Rc), } #[derive(Debug)] pub enum UnicodeStringLiteral { - SingleQuotedUnicodeStringLiteral(Rc), - DoubleQuotedUnicodeStringLiteral(Rc), + SingleQuotedUnicodeStringLiteral(Rc), + DoubleQuotedUnicodeStringLiteral(Rc), } #[derive(Debug)] @@ -1608,8 +2388,8 @@ pub enum YulExpression { pub enum YulLiteral { HexStringLiteral(HexStringLiteral), StringLiteral(StringLiteral), - YulDecimalLiteral(Rc), - YulHexLiteral(Rc), + YulDecimalLiteral(Rc), + YulHexLiteral(Rc), YulTrueKeyword, YulFalseKeyword, } @@ -1624,7 +2404,7 @@ pub type VersionExpressionSets = Vec; pub type VersionExpressionSet = Vec; -pub type SimpleVersionLiteral = Vec>; +pub type SimpleVersionLiteral = Vec>; pub type ImportDeconstructionSymbols = Vec; @@ -1642,7 +2422,7 @@ pub type LibraryMembers = Vec; pub type StructMembers = Vec; -pub type EnumMembers = Vec>; +pub type EnumMembers = Vec>; pub type StateVariableAttributes = Vec; @@ -1692,13 +2472,13 @@ pub type HexStringLiterals = Vec; pub type UnicodeStringLiterals = Vec; -pub type IdentifierPath = Vec>; +pub type IdentifierPath = Vec>; pub type YulStatements = Vec; -pub type YulParameters = Vec>; +pub type YulParameters = Vec>; -pub type YulVariableNames = Vec>; +pub type YulVariableNames = Vec>; pub type YulSwitchCases = Vec; @@ -1706,4 +2486,4 @@ pub type YulArguments = Vec; pub type YulPaths = Vec; -pub type YulPath = Vec>; +pub type YulPath = Vec>; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/rewriter.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/rewriter.generated.rs index 9d6b52a1ca..f5ffb63f75 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/rewriter.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/rewriter.generated.rs @@ -16,7 +16,7 @@ pub trait Rewriter { let members = self.rewrite_source_unit_members(&source.members); Rc::new(SourceUnitStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), members, }) } @@ -25,7 +25,7 @@ pub trait Rewriter { let pragma = self.rewrite_pragma(&source.pragma); Rc::new(PragmaDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), pragma, }) } @@ -34,7 +34,7 @@ pub trait Rewriter { let version = self.rewrite_abicoder_version(&source.version); Rc::new(AbicoderPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), version, }) } @@ -43,7 +43,7 @@ pub trait Rewriter { let feature = self.rewrite_experimental_feature(&source.feature); Rc::new(ExperimentalPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), feature, }) } @@ -52,7 +52,7 @@ pub trait Rewriter { let sets = self.rewrite_version_expression_sets(&source.sets); Rc::new(VersionPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), sets, }) } @@ -62,7 +62,7 @@ pub trait Rewriter { let end = self.rewrite_version_literal(&source.end); Rc::new(VersionRangeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), start, end, }) @@ -76,7 +76,7 @@ pub trait Rewriter { let literal = self.rewrite_version_literal(&source.literal); Rc::new(VersionTermStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operator, literal, }) @@ -86,7 +86,7 @@ pub trait Rewriter { let clause = self.rewrite_import_clause(&source.clause); Rc::new(ImportDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), clause, }) } @@ -99,7 +99,7 @@ pub trait Rewriter { .map(|value| self.rewrite_import_alias(value)); Rc::new(PathImportStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), path, alias, }) @@ -110,7 +110,7 @@ pub trait Rewriter { let path = self.rewrite_string_literal(&source.path); Rc::new(NamedImportStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), alias, path, }) @@ -124,7 +124,7 @@ pub trait Rewriter { let path = self.rewrite_string_literal(&source.path); Rc::new(ImportDeconstructionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), symbols, path, }) @@ -141,7 +141,7 @@ pub trait Rewriter { .map(|value| self.rewrite_import_alias(value)); Rc::new(ImportDeconstructionSymbolStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, alias, }) @@ -151,7 +151,7 @@ pub trait Rewriter { let identifier = Rc::clone(&source.identifier); Rc::new(ImportAliasStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), identifier, }) } @@ -162,7 +162,7 @@ pub trait Rewriter { let global_keyword = source.global_keyword; Rc::new(UsingDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), clause, target, global_keyword, @@ -176,7 +176,7 @@ pub trait Rewriter { let symbols = self.rewrite_using_deconstruction_symbols(&source.symbols); Rc::new(UsingDeconstructionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), symbols, }) } @@ -192,7 +192,7 @@ pub trait Rewriter { .map(|value| self.rewrite_using_alias(value)); Rc::new(UsingDeconstructionSymbolStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, alias, }) @@ -202,7 +202,7 @@ pub trait Rewriter { let operator = self.rewrite_using_operator(&source.operator); Rc::new(UsingAliasStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operator, }) } @@ -214,7 +214,7 @@ pub trait Rewriter { let members = self.rewrite_contract_members(&source.members); Rc::new(ContractDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), abstract_keyword, name, specifiers, @@ -229,7 +229,7 @@ pub trait Rewriter { let types = self.rewrite_inheritance_types(&source.types); Rc::new(InheritanceSpecifierStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), types, }) } @@ -242,7 +242,7 @@ pub trait Rewriter { .map(|value| self.rewrite_arguments_declaration(value)); Rc::new(InheritanceTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, arguments, }) @@ -255,7 +255,7 @@ pub trait Rewriter { let expression = self.rewrite_expression(&source.expression); Rc::new(StorageLayoutSpecifierStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -272,7 +272,7 @@ pub trait Rewriter { let members = self.rewrite_interface_members(&source.members); Rc::new(InterfaceDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, inheritance, members, @@ -284,7 +284,7 @@ pub trait Rewriter { let members = self.rewrite_library_members(&source.members); Rc::new(LibraryDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -295,7 +295,7 @@ pub trait Rewriter { let members = self.rewrite_struct_members(&source.members); Rc::new(StructDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -306,7 +306,7 @@ pub trait Rewriter { let name = Rc::clone(&source.name); Rc::new(StructMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -317,7 +317,7 @@ pub trait Rewriter { let members = self.rewrite_enum_members(&source.members); Rc::new(EnumDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -329,7 +329,7 @@ pub trait Rewriter { let value = self.rewrite_expression(&source.value); Rc::new(ConstantDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, value, @@ -349,7 +349,7 @@ pub trait Rewriter { .map(|value| self.rewrite_state_variable_definition_value(value)); Rc::new(StateVariableDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, attributes, name, @@ -364,7 +364,7 @@ pub trait Rewriter { let value = self.rewrite_expression(&source.value); Rc::new(StateVariableDefinitionValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), value, }) } @@ -380,7 +380,7 @@ pub trait Rewriter { let body = self.rewrite_function_body(&source.body); Rc::new(FunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, attributes, @@ -396,7 +396,7 @@ pub trait Rewriter { let parameters = self.rewrite_parameters(&source.parameters); Rc::new(ParametersDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, }) } @@ -410,7 +410,7 @@ pub trait Rewriter { let name = source.name.as_ref().map(Rc::clone); Rc::new(ParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, storage_location, name, @@ -424,7 +424,7 @@ pub trait Rewriter { .map(|value| self.rewrite_override_paths_declaration(value)); Rc::new(OverrideSpecifierStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), overridden, }) } @@ -436,7 +436,7 @@ pub trait Rewriter { let paths = self.rewrite_override_paths(&source.paths); Rc::new(OverridePathsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), paths, }) } @@ -445,7 +445,7 @@ pub trait Rewriter { let variables = self.rewrite_parameters_declaration(&source.variables); Rc::new(ReturnsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, }) } @@ -459,7 +459,7 @@ pub trait Rewriter { let body = self.rewrite_block(&source.body); Rc::new(ConstructorDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, attributes, body, @@ -475,7 +475,7 @@ pub trait Rewriter { let body = self.rewrite_function_body(&source.body); Rc::new(UnnamedFunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, attributes, body, @@ -495,7 +495,7 @@ pub trait Rewriter { let body = self.rewrite_function_body(&source.body); Rc::new(FallbackFunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, attributes, returns, @@ -512,7 +512,7 @@ pub trait Rewriter { let body = self.rewrite_function_body(&source.body); Rc::new(ReceiveFunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, attributes, body, @@ -529,7 +529,7 @@ pub trait Rewriter { let body = self.rewrite_function_body(&source.body); Rc::new(ModifierDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, attributes, @@ -545,7 +545,7 @@ pub trait Rewriter { .map(|value| self.rewrite_arguments_declaration(value)); Rc::new(ModifierInvocationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, arguments, }) @@ -557,7 +557,7 @@ pub trait Rewriter { let anonymous_keyword = source.anonymous_keyword; Rc::new(EventDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, anonymous_keyword, @@ -571,7 +571,7 @@ pub trait Rewriter { let parameters = self.rewrite_event_parameters(&source.parameters); Rc::new(EventParametersDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, }) } @@ -582,7 +582,7 @@ pub trait Rewriter { let name = source.name.as_ref().map(Rc::clone); Rc::new(EventParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, indexed_keyword, name, @@ -597,7 +597,7 @@ pub trait Rewriter { let value_type = self.rewrite_elementary_type(&source.value_type); Rc::new(UserDefinedValueTypeDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, value_type, }) @@ -608,7 +608,7 @@ pub trait Rewriter { let members = self.rewrite_error_parameters_declaration(&source.members); Rc::new(ErrorDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -621,7 +621,7 @@ pub trait Rewriter { let parameters = self.rewrite_error_parameters(&source.parameters); Rc::new(ErrorParametersDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, }) } @@ -631,7 +631,7 @@ pub trait Rewriter { let name = source.name.as_ref().map(Rc::clone); Rc::new(ErrorParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -645,7 +645,7 @@ pub trait Rewriter { .map(|value| self.rewrite_expression(value)); Rc::new(ArrayTypeNameStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, index, }) @@ -660,7 +660,7 @@ pub trait Rewriter { .map(|value| self.rewrite_returns_declaration(value)); Rc::new(FunctionTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, attributes, returns, @@ -672,7 +672,7 @@ pub trait Rewriter { let value_type = self.rewrite_mapping_value(&source.value_type); Rc::new(MappingTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), key_type, value_type, }) @@ -683,7 +683,7 @@ pub trait Rewriter { let name = source.name.as_ref().map(Rc::clone); Rc::new(MappingKeyStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), key_type, name, }) @@ -694,7 +694,7 @@ pub trait Rewriter { let name = source.name.as_ref().map(Rc::clone); Rc::new(MappingValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -704,7 +704,7 @@ pub trait Rewriter { let payable_keyword = source.payable_keyword; Rc::new(AddressTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), payable_keyword, }) } @@ -713,7 +713,7 @@ pub trait Rewriter { let statements = self.rewrite_statements(&source.statements); Rc::new(BlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), statements, }) } @@ -722,7 +722,7 @@ pub trait Rewriter { let block = self.rewrite_block(&source.block); Rc::new(UncheckedBlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), block, }) } @@ -734,7 +734,7 @@ pub trait Rewriter { let expression = self.rewrite_expression(&source.expression); Rc::new(ExpressionStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -751,7 +751,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(AssemblyStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), label, flags, body, @@ -765,7 +765,7 @@ pub trait Rewriter { let flags = self.rewrite_assembly_flags(&source.flags); Rc::new(AssemblyFlagsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), flags, }) } @@ -779,7 +779,7 @@ pub trait Rewriter { let expression = self.rewrite_expression(&source.expression); Rc::new(TupleDeconstructionStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), var_keyword, elements, expression, @@ -796,7 +796,7 @@ pub trait Rewriter { .map(|value| self.rewrite_tuple_member(value)); Rc::new(TupleDeconstructionElementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), member, }) } @@ -810,7 +810,7 @@ pub trait Rewriter { let name = Rc::clone(&source.name); Rc::new(TypedTupleMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, storage_location, name, @@ -825,7 +825,7 @@ pub trait Rewriter { let name = Rc::clone(&source.name); Rc::new(UntypedTupleMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), storage_location, name, }) @@ -847,7 +847,7 @@ pub trait Rewriter { .map(|value| self.rewrite_variable_declaration_value(value)); Rc::new(VariableDeclarationStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variable_type, storage_location, name, @@ -862,7 +862,7 @@ pub trait Rewriter { let expression = self.rewrite_expression(&source.expression); Rc::new(VariableDeclarationValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -876,7 +876,7 @@ pub trait Rewriter { .map(|value| self.rewrite_else_branch(value)); Rc::new(IfStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, else_branch, @@ -887,7 +887,7 @@ pub trait Rewriter { let body = self.rewrite_statement(&source.body); Rc::new(ElseBranchStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), body, }) } @@ -902,7 +902,7 @@ pub trait Rewriter { let body = self.rewrite_statement(&source.body); Rc::new(ForStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), initialization, condition, iterator, @@ -915,7 +915,7 @@ pub trait Rewriter { let body = self.rewrite_statement(&source.body); Rc::new(WhileStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, }) @@ -926,7 +926,7 @@ pub trait Rewriter { let condition = self.rewrite_expression(&source.condition); Rc::new(DoWhileStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), body, condition, }) @@ -934,13 +934,13 @@ pub trait Rewriter { fn rewrite_continue_statement(&mut self, source: &ContinueStatement) -> ContinueStatement { Rc::new(ContinueStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } fn rewrite_break_statement(&mut self, source: &BreakStatement) -> BreakStatement { Rc::new(BreakStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -951,7 +951,7 @@ pub trait Rewriter { .map(|value| self.rewrite_expression(value)); Rc::new(ReturnStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -961,7 +961,7 @@ pub trait Rewriter { let arguments = self.rewrite_arguments_declaration(&source.arguments); Rc::new(EmitStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), event, arguments, }) @@ -977,7 +977,7 @@ pub trait Rewriter { let catch_clauses = self.rewrite_catch_clauses(&source.catch_clauses); Rc::new(TryStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, returns, body, @@ -993,7 +993,7 @@ pub trait Rewriter { let body = self.rewrite_block(&source.body); Rc::new(CatchClauseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), error, body, }) @@ -1004,7 +1004,7 @@ pub trait Rewriter { let parameters = self.rewrite_parameters_declaration(&source.parameters); Rc::new(CatchClauseErrorStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, }) @@ -1018,7 +1018,7 @@ pub trait Rewriter { let arguments = self.rewrite_arguments_declaration(&source.arguments); Rc::new(RevertStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), error, arguments, }) @@ -1026,7 +1026,7 @@ pub trait Rewriter { fn rewrite_throw_statement(&mut self, source: &ThrowStatement) -> ThrowStatement { Rc::new(ThrowStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1039,7 +1039,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(AssignmentExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1055,7 +1055,7 @@ pub trait Rewriter { let false_expression = self.rewrite_expression(&source.false_expression); Rc::new(ConditionalExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, true_expression, false_expression, @@ -1067,7 +1067,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(OrExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -1078,7 +1078,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(AndExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -1090,7 +1090,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(EqualityExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1106,7 +1106,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(InequalityExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1121,7 +1121,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(BitwiseOrExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -1135,7 +1135,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(BitwiseXorExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -1149,7 +1149,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(BitwiseAndExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -1161,7 +1161,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(ShiftExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1174,7 +1174,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(AdditiveExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1190,7 +1190,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(MultiplicativeExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1206,7 +1206,7 @@ pub trait Rewriter { let right_operand = self.rewrite_expression(&source.right_operand); Rc::new(ExponentiationExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -1218,7 +1218,7 @@ pub trait Rewriter { let operator = Rc::clone(&source.operator); Rc::new(PostfixExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, operator, }) @@ -1229,7 +1229,7 @@ pub trait Rewriter { let operand = self.rewrite_expression(&source.operand); Rc::new(PrefixExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operator, operand, }) @@ -1243,7 +1243,7 @@ pub trait Rewriter { let arguments = self.rewrite_arguments_declaration(&source.arguments); Rc::new(FunctionCallExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, arguments, }) @@ -1257,7 +1257,7 @@ pub trait Rewriter { let options = self.rewrite_call_options(&source.options); Rc::new(CallOptionsExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, options, }) @@ -1271,7 +1271,7 @@ pub trait Rewriter { let member = Rc::clone(&source.member); Rc::new(MemberAccessExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, member, }) @@ -1292,7 +1292,7 @@ pub trait Rewriter { .map(|value| self.rewrite_index_access_end(value)); Rc::new(IndexAccessExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, start, end, @@ -1306,7 +1306,7 @@ pub trait Rewriter { .map(|value| self.rewrite_expression(value)); Rc::new(IndexAccessEndStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), end, }) } @@ -1318,7 +1318,7 @@ pub trait Rewriter { let arguments = self.rewrite_positional_arguments(&source.arguments); Rc::new(PositionalArgumentsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), arguments, }) } @@ -1333,7 +1333,7 @@ pub trait Rewriter { .map(|value| self.rewrite_named_argument_group(value)); Rc::new(NamedArgumentsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), arguments, }) } @@ -1342,7 +1342,7 @@ pub trait Rewriter { let arguments = self.rewrite_named_arguments(&source.arguments); Rc::new(NamedArgumentGroupStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), arguments, }) } @@ -1352,7 +1352,7 @@ pub trait Rewriter { let value = self.rewrite_expression(&source.value); Rc::new(NamedArgumentStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, value, }) @@ -1362,7 +1362,7 @@ pub trait Rewriter { let type_name = self.rewrite_type_name(&source.type_name); Rc::new(TypeExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, }) } @@ -1371,7 +1371,7 @@ pub trait Rewriter { let type_name = self.rewrite_type_name(&source.type_name); Rc::new(NewExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, }) } @@ -1380,7 +1380,7 @@ pub trait Rewriter { let items = self.rewrite_tuple_values(&source.items); Rc::new(TupleExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), items, }) } @@ -1392,7 +1392,7 @@ pub trait Rewriter { .map(|value| self.rewrite_expression(value)); Rc::new(TupleValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -1401,7 +1401,7 @@ pub trait Rewriter { let items = self.rewrite_array_values(&source.items); Rc::new(ArrayExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), items, }) } @@ -1417,7 +1417,7 @@ pub trait Rewriter { .map(|value| self.rewrite_number_unit(value)); Rc::new(HexNumberExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), literal, unit, }) @@ -1434,7 +1434,7 @@ pub trait Rewriter { .map(|value| self.rewrite_number_unit(value)); Rc::new(DecimalNumberExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), literal, unit, }) @@ -1444,7 +1444,7 @@ pub trait Rewriter { let statements = self.rewrite_yul_statements(&source.statements); Rc::new(YulBlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), statements, }) } @@ -1462,7 +1462,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(YulFunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, returns, @@ -1477,7 +1477,7 @@ pub trait Rewriter { let parameters = self.rewrite_yul_parameters(&source.parameters); Rc::new(YulParametersDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), parameters, }) } @@ -1489,7 +1489,7 @@ pub trait Rewriter { let variables = self.rewrite_yul_variable_names(&source.variables); Rc::new(YulReturnsDeclarationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, }) } @@ -1505,7 +1505,7 @@ pub trait Rewriter { .map(|value| self.rewrite_yul_variable_declaration_value(value)); Rc::new(YulVariableDeclarationStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, value, }) @@ -1519,7 +1519,7 @@ pub trait Rewriter { let expression = self.rewrite_yul_expression(&source.expression); Rc::new(YulVariableDeclarationValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), assignment, expression, }) @@ -1534,7 +1534,7 @@ pub trait Rewriter { let expression = self.rewrite_yul_expression(&source.expression); Rc::new(YulVariableAssignmentStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, assignment, expression, @@ -1543,7 +1543,7 @@ pub trait Rewriter { fn rewrite_yul_colon_and_equal(&mut self, source: &YulColonAndEqual) -> YulColonAndEqual { Rc::new(YulColonAndEqualStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1555,7 +1555,7 @@ pub trait Rewriter { let variable = Rc::clone(&source.variable); Rc::new(YulStackAssignmentStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), assignment, variable, }) @@ -1563,7 +1563,7 @@ pub trait Rewriter { fn rewrite_yul_equal_and_colon(&mut self, source: &YulEqualAndColon) -> YulEqualAndColon { Rc::new(YulEqualAndColonStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1572,7 +1572,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(YulIfStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, }) @@ -1585,7 +1585,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(YulForStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), initialization, condition, iterator, @@ -1598,7 +1598,7 @@ pub trait Rewriter { let cases = self.rewrite_yul_switch_cases(&source.cases); Rc::new(YulSwitchStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, cases, }) @@ -1608,7 +1608,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(YulDefaultCaseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), body, }) } @@ -1618,7 +1618,7 @@ pub trait Rewriter { let body = self.rewrite_yul_block(&source.body); Rc::new(YulValueCaseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), value, body, }) @@ -1626,13 +1626,13 @@ pub trait Rewriter { fn rewrite_yul_leave_statement(&mut self, source: &YulLeaveStatement) -> YulLeaveStatement { Rc::new(YulLeaveStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } fn rewrite_yul_break_statement(&mut self, source: &YulBreakStatement) -> YulBreakStatement { Rc::new(YulBreakStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1641,7 +1641,7 @@ pub trait Rewriter { source: &YulContinueStatement, ) -> YulContinueStatement { Rc::new(YulContinueStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1649,7 +1649,7 @@ pub trait Rewriter { let label = Rc::clone(&source.label); Rc::new(YulLabelStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), label, }) } @@ -1662,7 +1662,7 @@ pub trait Rewriter { let arguments = self.rewrite_yul_arguments(&source.arguments); Rc::new(YulFunctionCallExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, arguments, }) diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/visitor.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/visitor.generated.rs index 85f490988d..9c1aa37484 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/visitor.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/visitor.generated.rs @@ -4,7 +4,7 @@ use std::rc::Rc; #[allow(clippy::wildcard_imports)] use super::nodes::*; -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; pub trait Visitor { fn enter_source_unit(&mut self, _node: &SourceUnit) -> bool { @@ -3304,7 +3304,7 @@ fn accept_version_expression_set(items: &Vec, visitor: &mut i } #[inline] -fn accept_simple_version_literal(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_simple_version_literal(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_simple_version_literal(items) { visitor.leave_simple_version_literal(items); } @@ -3405,7 +3405,7 @@ fn accept_struct_members(items: &Vec, visitor: &mut impl Visitor) } #[inline] -fn accept_enum_members(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_enum_members(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_enum_members(items) { visitor.leave_enum_members(items); } @@ -3691,7 +3691,7 @@ fn accept_unicode_string_literals(items: &Vec, visitor: &m } #[inline] -fn accept_identifier_path(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_identifier_path(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_identifier_path(items) { visitor.leave_identifier_path(items); } @@ -3709,14 +3709,14 @@ fn accept_yul_statements(items: &Vec, visitor: &mut impl Visitor) } #[inline] -fn accept_yul_parameters(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_parameters(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_parameters(items) { visitor.leave_yul_parameters(items); } } #[inline] -fn accept_yul_variable_names(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_variable_names(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_variable_names(items) { visitor.leave_yul_variable_names(items); } @@ -3756,7 +3756,7 @@ fn accept_yul_paths(items: &Vec, visitor: &mut impl Visitor) { } #[inline] -fn accept_yul_path(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_path(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_path(items) { visitor.leave_yul_path(items); } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.generated.rs new file mode 100644 index 0000000000..57607f4d78 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.generated.rs @@ -0,0 +1,2901 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +use std::collections::HashMap; +use std::rc::Rc; + +#[allow(clippy::wildcard_imports)] +use super::nodes::*; +use crate::cst::{NodeId, SyntaxNode}; + +pub enum NodeType { + SourceUnit(SourceUnit), + PragmaDirective(PragmaDirective), + AbicoderPragma(AbicoderPragma), + ExperimentalPragma(ExperimentalPragma), + VersionPragma(VersionPragma), + VersionRange(VersionRange), + VersionTerm(VersionTerm), + ImportDirective(ImportDirective), + PathImport(PathImport), + NamedImport(NamedImport), + ImportDeconstruction(ImportDeconstruction), + ImportDeconstructionSymbol(ImportDeconstructionSymbol), + UsingDirective(UsingDirective), + UsingDeconstruction(UsingDeconstruction), + UsingDeconstructionSymbol(UsingDeconstructionSymbol), + ContractDefinition(ContractDefinition), + InheritanceType(InheritanceType), + InterfaceDefinition(InterfaceDefinition), + LibraryDefinition(LibraryDefinition), + StructDefinition(StructDefinition), + StructMember(StructMember), + EnumDefinition(EnumDefinition), + ConstantDefinition(ConstantDefinition), + StateVariableDefinition(StateVariableDefinition), + FunctionDefinition(FunctionDefinition), + Parameter(Parameter), + OverrideSpecifier(OverrideSpecifier), + ModifierInvocation(ModifierInvocation), + EventDefinition(EventDefinition), + EventParameter(EventParameter), + UserDefinedValueTypeDefinition(UserDefinedValueTypeDefinition), + ErrorDefinition(ErrorDefinition), + ErrorParameter(ErrorParameter), + ArrayTypeName(ArrayTypeName), + FunctionType(FunctionType), + MappingType(MappingType), + MappingKey(MappingKey), + MappingValue(MappingValue), + AddressType(AddressType), + Block(Block), + UncheckedBlock(UncheckedBlock), + ExpressionStatement(ExpressionStatement), + AssemblyStatement(AssemblyStatement), + TupleDeconstructionStatement(TupleDeconstructionStatement), + TupleDeconstructionElement(TupleDeconstructionElement), + TypedTupleMember(TypedTupleMember), + UntypedTupleMember(UntypedTupleMember), + VariableDeclarationStatement(VariableDeclarationStatement), + IfStatement(IfStatement), + ForStatement(ForStatement), + WhileStatement(WhileStatement), + DoWhileStatement(DoWhileStatement), + ContinueStatement(ContinueStatement), + BreakStatement(BreakStatement), + ReturnStatement(ReturnStatement), + EmitStatement(EmitStatement), + TryStatement(TryStatement), + CatchClause(CatchClause), + CatchClauseError(CatchClauseError), + RevertStatement(RevertStatement), + ThrowStatement(ThrowStatement), + AssignmentExpression(AssignmentExpression), + ConditionalExpression(ConditionalExpression), + OrExpression(OrExpression), + AndExpression(AndExpression), + EqualityExpression(EqualityExpression), + InequalityExpression(InequalityExpression), + BitwiseOrExpression(BitwiseOrExpression), + BitwiseXorExpression(BitwiseXorExpression), + BitwiseAndExpression(BitwiseAndExpression), + ShiftExpression(ShiftExpression), + AdditiveExpression(AdditiveExpression), + MultiplicativeExpression(MultiplicativeExpression), + ExponentiationExpression(ExponentiationExpression), + PostfixExpression(PostfixExpression), + PrefixExpression(PrefixExpression), + FunctionCallExpression(FunctionCallExpression), + CallOptionsExpression(CallOptionsExpression), + MemberAccessExpression(MemberAccessExpression), + IndexAccessExpression(IndexAccessExpression), + NamedArgument(NamedArgument), + TypeExpression(TypeExpression), + NewExpression(NewExpression), + TupleExpression(TupleExpression), + TupleValue(TupleValue), + ArrayExpression(ArrayExpression), + HexNumberExpression(HexNumberExpression), + DecimalNumberExpression(DecimalNumberExpression), + YulBlock(YulBlock), + YulFunctionDefinition(YulFunctionDefinition), + YulVariableDeclarationStatement(YulVariableDeclarationStatement), + YulVariableDeclarationValue(YulVariableDeclarationValue), + YulVariableAssignmentStatement(YulVariableAssignmentStatement), + YulColonAndEqual(YulColonAndEqual), + YulStackAssignmentStatement(YulStackAssignmentStatement), + YulEqualAndColon(YulEqualAndColon), + YulIfStatement(YulIfStatement), + YulForStatement(YulForStatement), + YulSwitchStatement(YulSwitchStatement), + YulDefaultCase(YulDefaultCase), + YulValueCase(YulValueCase), + YulLeaveStatement(YulLeaveStatement), + YulBreakStatement(YulBreakStatement), + YulContinueStatement(YulContinueStatement), + YulLabel(YulLabel), + YulFunctionCallExpression(YulFunctionCallExpression), +} + +pub type TreeIndex = HashMap; + +pub trait IntoIr { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option; +} + +impl IntoIr for SourceUnit { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::SourceUnit(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for PragmaDirective { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::PragmaDirective(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AbicoderPragma { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AbicoderPragma(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ExperimentalPragma { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ExperimentalPragma(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for VersionPragma { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::VersionPragma(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for VersionRange { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::VersionRange(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for VersionTerm { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::VersionTerm(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ImportDirective { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ImportDirective(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for PathImport { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::PathImport(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for NamedImport { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::NamedImport(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ImportDeconstruction { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ImportDeconstruction(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ImportDeconstructionSymbol { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ImportDeconstructionSymbol(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UsingDirective { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UsingDirective(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UsingDeconstruction { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UsingDeconstruction(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UsingDeconstructionSymbol { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UsingDeconstructionSymbol(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ContractDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ContractDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for InheritanceType { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::InheritanceType(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for InterfaceDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::InterfaceDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for LibraryDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::LibraryDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for StructDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::StructDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for StructMember { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::StructMember(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for EnumDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::EnumDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ConstantDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ConstantDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for StateVariableDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::StateVariableDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for FunctionDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::FunctionDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for Parameter { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::Parameter(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for OverrideSpecifier { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::OverrideSpecifier(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ModifierInvocation { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ModifierInvocation(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for EventDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::EventDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for EventParameter { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::EventParameter(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UserDefinedValueTypeDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UserDefinedValueTypeDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ErrorDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ErrorDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ErrorParameter { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ErrorParameter(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ArrayTypeName { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ArrayTypeName(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for FunctionType { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::FunctionType(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for MappingType { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::MappingType(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for MappingKey { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::MappingKey(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for MappingValue { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::MappingValue(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AddressType { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AddressType(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for Block { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::Block(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UncheckedBlock { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UncheckedBlock(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ExpressionStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ExpressionStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AssemblyStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AssemblyStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TupleDeconstructionStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TupleDeconstructionStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TupleDeconstructionElement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TupleDeconstructionElement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TypedTupleMember { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TypedTupleMember(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for UntypedTupleMember { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::UntypedTupleMember(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for VariableDeclarationStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::VariableDeclarationStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for IfStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::IfStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ForStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ForStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for WhileStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::WhileStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for DoWhileStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::DoWhileStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ContinueStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ContinueStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for BreakStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::BreakStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ReturnStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ReturnStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for EmitStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::EmitStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TryStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TryStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for CatchClause { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::CatchClause(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for CatchClauseError { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::CatchClauseError(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for RevertStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::RevertStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ThrowStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ThrowStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AssignmentExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AssignmentExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ConditionalExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ConditionalExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for OrExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::OrExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AndExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AndExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for EqualityExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::EqualityExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for InequalityExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::InequalityExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for BitwiseOrExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::BitwiseOrExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for BitwiseXorExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::BitwiseXorExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for BitwiseAndExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::BitwiseAndExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ShiftExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ShiftExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for AdditiveExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::AdditiveExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for MultiplicativeExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::MultiplicativeExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ExponentiationExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ExponentiationExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for PostfixExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::PostfixExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for PrefixExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::PrefixExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for FunctionCallExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::FunctionCallExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for CallOptionsExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::CallOptionsExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for MemberAccessExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::MemberAccessExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for IndexAccessExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::IndexAccessExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for NamedArgument { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::NamedArgument(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TypeExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TypeExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for NewExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::NewExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TupleExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TupleExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for TupleValue { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::TupleValue(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for ArrayExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::ArrayExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for HexNumberExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::HexNumberExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for DecimalNumberExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::DecimalNumberExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulBlock { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulBlock(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulFunctionDefinition { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulFunctionDefinition(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulVariableDeclarationStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulVariableDeclarationStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulVariableDeclarationValue { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulVariableDeclarationValue(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulVariableAssignmentStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulVariableAssignmentStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulColonAndEqual { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulColonAndEqual(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulStackAssignmentStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulStackAssignmentStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulEqualAndColon { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulEqualAndColon(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulIfStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulIfStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulForStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulForStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulSwitchStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulSwitchStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulDefaultCase { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulDefaultCase(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulValueCase { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulValueCase(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulLeaveStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulLeaveStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulBreakStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulBreakStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulContinueStatement { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulContinueStatement(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulLabel { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulLabel(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +impl IntoIr for YulFunctionCallExpression { + fn into_ir(node: &Rc, index: &TreeIndex) -> Option { + index.get(&node.id()).and_then(|ir_node| { + if let NodeType::YulFunctionCallExpression(ir_node) = ir_node { + Some(Rc::clone(ir_node)) + } else { + None + } + }) + } +} + +// +// Sequences: +// + +pub fn register_source_unit(node: &SourceUnit, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::SourceUnit(Rc::clone(node))); + register_source_unit_members(&node.members, tree); +} + +pub fn register_pragma_directive(node: &PragmaDirective, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::PragmaDirective(Rc::clone(node))); + register_pragma(&node.pragma, tree); +} + +pub fn register_abicoder_pragma(node: &AbicoderPragma, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AbicoderPragma(Rc::clone(node))); + register_abicoder_version(&node.version, tree); +} + +pub fn register_experimental_pragma(node: &ExperimentalPragma, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ExperimentalPragma(Rc::clone(node))); + register_experimental_feature(&node.feature, tree); +} + +pub fn register_version_pragma(node: &VersionPragma, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::VersionPragma(Rc::clone(node))); + register_version_expression_sets(&node.sets, tree); +} + +pub fn register_version_range(node: &VersionRange, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::VersionRange(Rc::clone(node))); + register_version_literal(&node.start, tree); + register_version_literal(&node.end, tree); +} + +pub fn register_version_term(node: &VersionTerm, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::VersionTerm(Rc::clone(node))); + if let Some(ref operator) = node.operator { + register_version_operator(operator, tree); + } + register_version_literal(&node.literal, tree); +} + +pub fn register_import_directive(node: &ImportDirective, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ImportDirective(Rc::clone(node))); + register_import_clause(&node.clause, tree); +} + +pub fn register_path_import(node: &PathImport, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::PathImport(Rc::clone(node))); +} + +pub fn register_named_import(node: &NamedImport, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::NamedImport(Rc::clone(node))); +} + +pub fn register_import_deconstruction(node: &ImportDeconstruction, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ImportDeconstruction(Rc::clone(node))); + register_import_deconstruction_symbols(&node.symbols, tree); +} + +pub fn register_import_deconstruction_symbol( + node: &ImportDeconstructionSymbol, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::ImportDeconstructionSymbol(Rc::clone(node)), + ); +} + +pub fn register_using_directive(node: &UsingDirective, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::UsingDirective(Rc::clone(node))); + register_using_clause(&node.clause, tree); + register_using_target(&node.target, tree); +} + +pub fn register_using_deconstruction(node: &UsingDeconstruction, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::UsingDeconstruction(Rc::clone(node))); + register_using_deconstruction_symbols(&node.symbols, tree); +} + +pub fn register_using_deconstruction_symbol( + node: &UsingDeconstructionSymbol, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::UsingDeconstructionSymbol(Rc::clone(node)), + ); + register_identifier_path(&node.name, tree); + if let Some(ref alias) = node.alias { + register_using_operator(alias, tree); + } +} + +pub fn register_contract_definition(node: &ContractDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ContractDefinition(Rc::clone(node))); + register_contract_members(&node.members, tree); + register_inheritance_types(&node.inheritance_types, tree); + if let Some(ref storage_layout) = node.storage_layout { + register_expression(storage_layout, tree); + } +} + +pub fn register_inheritance_type(node: &InheritanceType, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::InheritanceType(Rc::clone(node))); + register_identifier_path(&node.type_name, tree); + if let Some(ref arguments) = node.arguments { + register_arguments_declaration(arguments, tree); + } +} + +pub fn register_interface_definition(node: &InterfaceDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::InterfaceDefinition(Rc::clone(node))); + if let Some(ref inheritance) = node.inheritance { + register_inheritance_types(inheritance, tree); + } + register_interface_members(&node.members, tree); +} + +pub fn register_library_definition(node: &LibraryDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::LibraryDefinition(Rc::clone(node))); + register_library_members(&node.members, tree); +} + +pub fn register_struct_definition(node: &StructDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::StructDefinition(Rc::clone(node))); + register_struct_members(&node.members, tree); +} + +pub fn register_struct_member(node: &StructMember, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::StructMember(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_enum_definition(node: &EnumDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::EnumDefinition(Rc::clone(node))); + register_enum_members(&node.members, tree); +} + +pub fn register_constant_definition(node: &ConstantDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ConstantDefinition(Rc::clone(node))); + register_type_name(&node.type_name, tree); + register_expression(&node.value, tree); +} + +pub fn register_state_variable_definition(node: &StateVariableDefinition, tree: &mut TreeIndex) { + tree.insert( + node.id(), + NodeType::StateVariableDefinition(Rc::clone(node)), + ); + register_type_name(&node.type_name, tree); + if let Some(ref value) = node.value { + register_expression(value, tree); + } + register_state_variable_visibility(&node.visibility, tree); + register_state_variable_mutability(&node.mutability, tree); + if let Some(ref override_specifier) = node.override_specifier { + register_override_paths(override_specifier, tree); + } +} + +pub fn register_function_definition(node: &FunctionDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::FunctionDefinition(Rc::clone(node))); + register_parameters(&node.parameters, tree); + if let Some(ref returns) = node.returns { + register_parameters(returns, tree); + } + register_function_kind(&node.kind, tree); + if let Some(ref body) = node.body { + register_block(body, tree); + } + register_function_visibility(&node.visibility, tree); + register_function_mutability(&node.mutability, tree); + if let Some(ref override_specifier) = node.override_specifier { + register_override_paths(override_specifier, tree); + } + register_modifier_invocations(&node.modifier_invocations, tree); +} + +pub fn register_parameter(node: &Parameter, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::Parameter(Rc::clone(node))); + register_type_name(&node.type_name, tree); + if let Some(ref storage_location) = node.storage_location { + register_storage_location(storage_location, tree); + } +} + +pub fn register_override_specifier(node: &OverrideSpecifier, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::OverrideSpecifier(Rc::clone(node))); + if let Some(ref overridden) = node.overridden { + register_override_paths(overridden, tree); + } +} + +pub fn register_modifier_invocation(node: &ModifierInvocation, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ModifierInvocation(Rc::clone(node))); + register_identifier_path(&node.name, tree); + if let Some(ref arguments) = node.arguments { + register_arguments_declaration(arguments, tree); + } +} + +pub fn register_event_definition(node: &EventDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::EventDefinition(Rc::clone(node))); + register_event_parameters(&node.parameters, tree); +} + +pub fn register_event_parameter(node: &EventParameter, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::EventParameter(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_user_defined_value_type_definition( + node: &UserDefinedValueTypeDefinition, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::UserDefinedValueTypeDefinition(Rc::clone(node)), + ); + register_elementary_type(&node.value_type, tree); +} + +pub fn register_error_definition(node: &ErrorDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ErrorDefinition(Rc::clone(node))); + register_error_parameters(&node.members, tree); +} + +pub fn register_error_parameter(node: &ErrorParameter, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ErrorParameter(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_array_type_name(node: &ArrayTypeName, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ArrayTypeName(Rc::clone(node))); + register_type_name(&node.operand, tree); + if let Some(ref index) = node.index { + register_expression(index, tree); + } +} + +pub fn register_function_type(node: &FunctionType, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::FunctionType(Rc::clone(node))); + register_parameters(&node.parameters, tree); + if let Some(ref returns) = node.returns { + register_parameters(returns, tree); + } + register_function_visibility(&node.visibility, tree); + register_function_mutability(&node.mutability, tree); +} + +pub fn register_mapping_type(node: &MappingType, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::MappingType(Rc::clone(node))); + register_mapping_key(&node.key_type, tree); + register_mapping_value(&node.value_type, tree); +} + +pub fn register_mapping_key(node: &MappingKey, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::MappingKey(Rc::clone(node))); + register_mapping_key_type(&node.key_type, tree); +} + +pub fn register_mapping_value(node: &MappingValue, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::MappingValue(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_address_type(node: &AddressType, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AddressType(Rc::clone(node))); +} + +pub fn register_block(node: &Block, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::Block(Rc::clone(node))); + register_statements(&node.statements, tree); +} + +pub fn register_unchecked_block(node: &UncheckedBlock, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::UncheckedBlock(Rc::clone(node))); + register_block(&node.block, tree); +} + +pub fn register_expression_statement(node: &ExpressionStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ExpressionStatement(Rc::clone(node))); + register_expression(&node.expression, tree); +} + +pub fn register_assembly_statement(node: &AssemblyStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AssemblyStatement(Rc::clone(node))); + register_yul_block(&node.body, tree); + register_assembly_flags(&node.flags, tree); +} + +pub fn register_tuple_deconstruction_statement( + node: &TupleDeconstructionStatement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::TupleDeconstructionStatement(Rc::clone(node)), + ); + register_tuple_deconstruction_elements(&node.elements, tree); + register_expression(&node.expression, tree); +} + +pub fn register_tuple_deconstruction_element( + node: &TupleDeconstructionElement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::TupleDeconstructionElement(Rc::clone(node)), + ); + if let Some(ref member) = node.member { + register_tuple_member(member, tree); + } +} + +pub fn register_typed_tuple_member(node: &TypedTupleMember, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::TypedTupleMember(Rc::clone(node))); + register_type_name(&node.type_name, tree); + if let Some(ref storage_location) = node.storage_location { + register_storage_location(storage_location, tree); + } +} + +pub fn register_untyped_tuple_member(node: &UntypedTupleMember, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::UntypedTupleMember(Rc::clone(node))); + if let Some(ref storage_location) = node.storage_location { + register_storage_location(storage_location, tree); + } +} + +pub fn register_variable_declaration_statement( + node: &VariableDeclarationStatement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::VariableDeclarationStatement(Rc::clone(node)), + ); + register_variable_declaration_type(&node.variable_type, tree); + if let Some(ref storage_location) = node.storage_location { + register_storage_location(storage_location, tree); + } + if let Some(ref value) = node.value { + register_expression(value, tree); + } +} + +pub fn register_if_statement(node: &IfStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::IfStatement(Rc::clone(node))); + register_expression(&node.condition, tree); + register_statement(&node.body, tree); + if let Some(ref else_branch) = node.else_branch { + register_statement(else_branch, tree); + } +} + +pub fn register_for_statement(node: &ForStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ForStatement(Rc::clone(node))); + register_for_statement_initialization(&node.initialization, tree); + register_for_statement_condition(&node.condition, tree); + if let Some(ref iterator) = node.iterator { + register_expression(iterator, tree); + } + register_statement(&node.body, tree); +} + +pub fn register_while_statement(node: &WhileStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::WhileStatement(Rc::clone(node))); + register_expression(&node.condition, tree); + register_statement(&node.body, tree); +} + +pub fn register_do_while_statement(node: &DoWhileStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::DoWhileStatement(Rc::clone(node))); + register_statement(&node.body, tree); + register_expression(&node.condition, tree); +} + +pub fn register_continue_statement(node: &ContinueStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ContinueStatement(Rc::clone(node))); +} + +pub fn register_break_statement(node: &BreakStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::BreakStatement(Rc::clone(node))); +} + +pub fn register_return_statement(node: &ReturnStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ReturnStatement(Rc::clone(node))); + if let Some(ref expression) = node.expression { + register_expression(expression, tree); + } +} + +pub fn register_emit_statement(node: &EmitStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::EmitStatement(Rc::clone(node))); + register_identifier_path(&node.event, tree); + register_arguments_declaration(&node.arguments, tree); +} + +pub fn register_try_statement(node: &TryStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::TryStatement(Rc::clone(node))); + register_expression(&node.expression, tree); + if let Some(ref returns) = node.returns { + register_parameters(returns, tree); + } + register_block(&node.body, tree); + register_catch_clauses(&node.catch_clauses, tree); +} + +pub fn register_catch_clause(node: &CatchClause, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::CatchClause(Rc::clone(node))); + if let Some(ref error) = node.error { + register_catch_clause_error(error, tree); + } + register_block(&node.body, tree); +} + +pub fn register_catch_clause_error(node: &CatchClauseError, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::CatchClauseError(Rc::clone(node))); + register_parameters(&node.parameters, tree); +} + +pub fn register_revert_statement(node: &RevertStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::RevertStatement(Rc::clone(node))); + if let Some(ref error) = node.error { + register_identifier_path(error, tree); + } + register_arguments_declaration(&node.arguments, tree); +} + +pub fn register_throw_statement(node: &ThrowStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ThrowStatement(Rc::clone(node))); +} + +pub fn register_assignment_expression(node: &AssignmentExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AssignmentExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_conditional_expression(node: &ConditionalExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ConditionalExpression(Rc::clone(node))); + register_expression(&node.operand, tree); + register_expression(&node.true_expression, tree); + register_expression(&node.false_expression, tree); +} + +pub fn register_or_expression(node: &OrExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::OrExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_and_expression(node: &AndExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AndExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_equality_expression(node: &EqualityExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::EqualityExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_inequality_expression(node: &InequalityExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::InequalityExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_bitwise_or_expression(node: &BitwiseOrExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::BitwiseOrExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_bitwise_xor_expression(node: &BitwiseXorExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::BitwiseXorExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_bitwise_and_expression(node: &BitwiseAndExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::BitwiseAndExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_shift_expression(node: &ShiftExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ShiftExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_additive_expression(node: &AdditiveExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::AdditiveExpression(Rc::clone(node))); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_multiplicative_expression(node: &MultiplicativeExpression, tree: &mut TreeIndex) { + tree.insert( + node.id(), + NodeType::MultiplicativeExpression(Rc::clone(node)), + ); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_exponentiation_expression(node: &ExponentiationExpression, tree: &mut TreeIndex) { + tree.insert( + node.id(), + NodeType::ExponentiationExpression(Rc::clone(node)), + ); + register_expression(&node.left_operand, tree); + register_expression(&node.right_operand, tree); +} + +pub fn register_postfix_expression(node: &PostfixExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::PostfixExpression(Rc::clone(node))); + register_expression(&node.operand, tree); +} + +pub fn register_prefix_expression(node: &PrefixExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::PrefixExpression(Rc::clone(node))); + register_expression(&node.operand, tree); +} + +pub fn register_function_call_expression(node: &FunctionCallExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::FunctionCallExpression(Rc::clone(node))); + register_expression(&node.operand, tree); + register_arguments_declaration(&node.arguments, tree); +} + +pub fn register_call_options_expression(node: &CallOptionsExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::CallOptionsExpression(Rc::clone(node))); + register_expression(&node.operand, tree); + register_call_options(&node.options, tree); +} + +pub fn register_member_access_expression(node: &MemberAccessExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::MemberAccessExpression(Rc::clone(node))); + register_expression(&node.operand, tree); +} + +pub fn register_index_access_expression(node: &IndexAccessExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::IndexAccessExpression(Rc::clone(node))); + register_expression(&node.operand, tree); + if let Some(ref start) = node.start { + register_expression(start, tree); + } + if let Some(ref end) = node.end { + register_expression(end, tree); + } +} + +pub fn register_named_argument(node: &NamedArgument, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::NamedArgument(Rc::clone(node))); + register_expression(&node.value, tree); +} + +pub fn register_type_expression(node: &TypeExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::TypeExpression(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_new_expression(node: &NewExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::NewExpression(Rc::clone(node))); + register_type_name(&node.type_name, tree); +} + +pub fn register_tuple_expression(node: &TupleExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::TupleExpression(Rc::clone(node))); + register_tuple_values(&node.items, tree); +} + +pub fn register_tuple_value(node: &TupleValue, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::TupleValue(Rc::clone(node))); + if let Some(ref expression) = node.expression { + register_expression(expression, tree); + } +} + +pub fn register_array_expression(node: &ArrayExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::ArrayExpression(Rc::clone(node))); + register_array_values(&node.items, tree); +} + +pub fn register_hex_number_expression(node: &HexNumberExpression, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::HexNumberExpression(Rc::clone(node))); + if let Some(ref unit) = node.unit { + register_number_unit(unit, tree); + } +} + +pub fn register_decimal_number_expression(node: &DecimalNumberExpression, tree: &mut TreeIndex) { + tree.insert( + node.id(), + NodeType::DecimalNumberExpression(Rc::clone(node)), + ); + if let Some(ref unit) = node.unit { + register_number_unit(unit, tree); + } +} + +pub fn register_yul_block(node: &YulBlock, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulBlock(Rc::clone(node))); + register_yul_statements(&node.statements, tree); +} + +pub fn register_yul_function_definition(node: &YulFunctionDefinition, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulFunctionDefinition(Rc::clone(node))); + register_yul_parameters(&node.parameters, tree); + if let Some(ref returns) = node.returns { + register_yul_variable_names(returns, tree); + } + register_yul_block(&node.body, tree); +} + +pub fn register_yul_variable_declaration_statement( + node: &YulVariableDeclarationStatement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::YulVariableDeclarationStatement(Rc::clone(node)), + ); + register_yul_variable_names(&node.variables, tree); + if let Some(ref value) = node.value { + register_yul_variable_declaration_value(value, tree); + } +} + +pub fn register_yul_variable_declaration_value( + node: &YulVariableDeclarationValue, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::YulVariableDeclarationValue(Rc::clone(node)), + ); + register_yul_assignment_operator(&node.assignment, tree); + register_yul_expression(&node.expression, tree); +} + +pub fn register_yul_variable_assignment_statement( + node: &YulVariableAssignmentStatement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::YulVariableAssignmentStatement(Rc::clone(node)), + ); + register_yul_paths(&node.variables, tree); + register_yul_assignment_operator(&node.assignment, tree); + register_yul_expression(&node.expression, tree); +} + +pub fn register_yul_colon_and_equal(node: &YulColonAndEqual, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulColonAndEqual(Rc::clone(node))); +} + +pub fn register_yul_stack_assignment_statement( + node: &YulStackAssignmentStatement, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::YulStackAssignmentStatement(Rc::clone(node)), + ); + register_yul_stack_assignment_operator(&node.assignment, tree); +} + +pub fn register_yul_equal_and_colon(node: &YulEqualAndColon, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulEqualAndColon(Rc::clone(node))); +} + +pub fn register_yul_if_statement(node: &YulIfStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulIfStatement(Rc::clone(node))); + register_yul_expression(&node.condition, tree); + register_yul_block(&node.body, tree); +} + +pub fn register_yul_for_statement(node: &YulForStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulForStatement(Rc::clone(node))); + register_yul_block(&node.initialization, tree); + register_yul_expression(&node.condition, tree); + register_yul_block(&node.iterator, tree); + register_yul_block(&node.body, tree); +} + +pub fn register_yul_switch_statement(node: &YulSwitchStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulSwitchStatement(Rc::clone(node))); + register_yul_expression(&node.expression, tree); + register_yul_switch_cases(&node.cases, tree); +} + +pub fn register_yul_default_case(node: &YulDefaultCase, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulDefaultCase(Rc::clone(node))); + register_yul_block(&node.body, tree); +} + +pub fn register_yul_value_case(node: &YulValueCase, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulValueCase(Rc::clone(node))); + register_yul_literal(&node.value, tree); + register_yul_block(&node.body, tree); +} + +pub fn register_yul_leave_statement(node: &YulLeaveStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulLeaveStatement(Rc::clone(node))); +} + +pub fn register_yul_break_statement(node: &YulBreakStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulBreakStatement(Rc::clone(node))); +} + +pub fn register_yul_continue_statement(node: &YulContinueStatement, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulContinueStatement(Rc::clone(node))); +} + +pub fn register_yul_label(node: &YulLabel, tree: &mut TreeIndex) { + tree.insert(node.id(), NodeType::YulLabel(Rc::clone(node))); +} + +pub fn register_yul_function_call_expression( + node: &YulFunctionCallExpression, + tree: &mut TreeIndex, +) { + tree.insert( + node.id(), + NodeType::YulFunctionCallExpression(Rc::clone(node)), + ); + register_yul_expression(&node.operand, tree); + register_yul_arguments(&node.arguments, tree); +} + +// +// Choices: +// + +pub fn register_source_unit_member(node: &SourceUnitMember, tree: &mut TreeIndex) { + match node { + SourceUnitMember::PragmaDirective(ref pragma_directive) => { + register_pragma_directive(pragma_directive, tree); + } + SourceUnitMember::ImportDirective(ref import_directive) => { + register_import_directive(import_directive, tree); + } + SourceUnitMember::ContractDefinition(ref contract_definition) => { + register_contract_definition(contract_definition, tree); + } + SourceUnitMember::InterfaceDefinition(ref interface_definition) => { + register_interface_definition(interface_definition, tree); + } + SourceUnitMember::LibraryDefinition(ref library_definition) => { + register_library_definition(library_definition, tree); + } + SourceUnitMember::StructDefinition(ref struct_definition) => { + register_struct_definition(struct_definition, tree); + } + SourceUnitMember::EnumDefinition(ref enum_definition) => { + register_enum_definition(enum_definition, tree); + } + SourceUnitMember::FunctionDefinition(ref function_definition) => { + register_function_definition(function_definition, tree); + } + SourceUnitMember::ErrorDefinition(ref error_definition) => { + register_error_definition(error_definition, tree); + } + SourceUnitMember::UserDefinedValueTypeDefinition( + ref user_defined_value_type_definition, + ) => { + register_user_defined_value_type_definition(user_defined_value_type_definition, tree); + } + SourceUnitMember::UsingDirective(ref using_directive) => { + register_using_directive(using_directive, tree); + } + SourceUnitMember::EventDefinition(ref event_definition) => { + register_event_definition(event_definition, tree); + } + SourceUnitMember::ConstantDefinition(ref constant_definition) => { + register_constant_definition(constant_definition, tree); + } + } +} + +pub fn register_pragma(node: &Pragma, tree: &mut TreeIndex) { + match node { + Pragma::VersionPragma(ref version_pragma) => { + register_version_pragma(version_pragma, tree); + } + Pragma::AbicoderPragma(ref abicoder_pragma) => { + register_abicoder_pragma(abicoder_pragma, tree); + } + Pragma::ExperimentalPragma(ref experimental_pragma) => { + register_experimental_pragma(experimental_pragma, tree); + } + } +} + +pub fn register_abicoder_version(_node: &AbicoderVersion, _tree: &mut TreeIndex) {} + +pub fn register_experimental_feature(_node: &ExperimentalFeature, _tree: &mut TreeIndex) {} + +pub fn register_version_expression(node: &VersionExpression, tree: &mut TreeIndex) { + match node { + VersionExpression::VersionRange(ref version_range) => { + register_version_range(version_range, tree); + } + VersionExpression::VersionTerm(ref version_term) => { + register_version_term(version_term, tree); + } + } +} + +pub fn register_version_operator(_node: &VersionOperator, _tree: &mut TreeIndex) {} + +pub fn register_version_literal(node: &VersionLiteral, tree: &mut TreeIndex) { + match node { + VersionLiteral::SimpleVersionLiteral(ref simple_version_literal) => { + register_simple_version_literal(simple_version_literal, tree); + } + VersionLiteral::SingleQuotedVersionLiteral(_) + | VersionLiteral::DoubleQuotedVersionLiteral(_) => {} + } +} + +pub fn register_import_clause(node: &ImportClause, tree: &mut TreeIndex) { + match node { + ImportClause::PathImport(ref path_import) => { + register_path_import(path_import, tree); + } + ImportClause::NamedImport(ref named_import) => { + register_named_import(named_import, tree); + } + ImportClause::ImportDeconstruction(ref import_deconstruction) => { + register_import_deconstruction(import_deconstruction, tree); + } + } +} + +pub fn register_using_clause(node: &UsingClause, tree: &mut TreeIndex) { + match node { + UsingClause::IdentifierPath(ref identifier_path) => { + register_identifier_path(identifier_path, tree); + } + UsingClause::UsingDeconstruction(ref using_deconstruction) => { + register_using_deconstruction(using_deconstruction, tree); + } + } +} + +pub fn register_using_operator(_node: &UsingOperator, _tree: &mut TreeIndex) {} + +pub fn register_using_target(node: &UsingTarget, tree: &mut TreeIndex) { + match node { + UsingTarget::TypeName(ref type_name) => { + register_type_name(type_name, tree); + } + UsingTarget::Asterisk => {} + } +} + +pub fn register_contract_member(node: &ContractMember, tree: &mut TreeIndex) { + match node { + ContractMember::UsingDirective(ref using_directive) => { + register_using_directive(using_directive, tree); + } + ContractMember::FunctionDefinition(ref function_definition) => { + register_function_definition(function_definition, tree); + } + ContractMember::StructDefinition(ref struct_definition) => { + register_struct_definition(struct_definition, tree); + } + ContractMember::EnumDefinition(ref enum_definition) => { + register_enum_definition(enum_definition, tree); + } + ContractMember::EventDefinition(ref event_definition) => { + register_event_definition(event_definition, tree); + } + ContractMember::ErrorDefinition(ref error_definition) => { + register_error_definition(error_definition, tree); + } + ContractMember::UserDefinedValueTypeDefinition(ref user_defined_value_type_definition) => { + register_user_defined_value_type_definition(user_defined_value_type_definition, tree); + } + ContractMember::StateVariableDefinition(ref state_variable_definition) => { + register_state_variable_definition(state_variable_definition, tree); + } + } +} + +pub fn register_type_name(node: &TypeName, tree: &mut TreeIndex) { + match node { + TypeName::ArrayTypeName(ref array_type_name) => { + register_array_type_name(array_type_name, tree); + } + TypeName::FunctionType(ref function_type) => { + register_function_type(function_type, tree); + } + TypeName::MappingType(ref mapping_type) => { + register_mapping_type(mapping_type, tree); + } + TypeName::ElementaryType(ref elementary_type) => { + register_elementary_type(elementary_type, tree); + } + TypeName::IdentifierPath(ref identifier_path) => { + register_identifier_path(identifier_path, tree); + } + } +} + +pub fn register_mapping_key_type(node: &MappingKeyType, tree: &mut TreeIndex) { + match node { + MappingKeyType::ElementaryType(ref elementary_type) => { + register_elementary_type(elementary_type, tree); + } + MappingKeyType::IdentifierPath(ref identifier_path) => { + register_identifier_path(identifier_path, tree); + } + } +} + +pub fn register_elementary_type(node: &ElementaryType, tree: &mut TreeIndex) { + match node { + ElementaryType::AddressType(ref address_type) => { + register_address_type(address_type, tree); + } + ElementaryType::BytesKeyword(_) + | ElementaryType::IntKeyword(_) + | ElementaryType::UintKeyword(_) + | ElementaryType::FixedKeyword(_) + | ElementaryType::UfixedKeyword(_) => {} + ElementaryType::BoolKeyword + | ElementaryType::ByteKeyword + | ElementaryType::StringKeyword => {} + } +} + +pub fn register_statement(node: &Statement, tree: &mut TreeIndex) { + match node { + Statement::IfStatement(ref if_statement) => { + register_if_statement(if_statement, tree); + } + Statement::ForStatement(ref for_statement) => { + register_for_statement(for_statement, tree); + } + Statement::WhileStatement(ref while_statement) => { + register_while_statement(while_statement, tree); + } + Statement::DoWhileStatement(ref do_while_statement) => { + register_do_while_statement(do_while_statement, tree); + } + Statement::ContinueStatement(ref continue_statement) => { + register_continue_statement(continue_statement, tree); + } + Statement::BreakStatement(ref break_statement) => { + register_break_statement(break_statement, tree); + } + Statement::ReturnStatement(ref return_statement) => { + register_return_statement(return_statement, tree); + } + Statement::ThrowStatement(ref throw_statement) => { + register_throw_statement(throw_statement, tree); + } + Statement::EmitStatement(ref emit_statement) => { + register_emit_statement(emit_statement, tree); + } + Statement::TryStatement(ref try_statement) => { + register_try_statement(try_statement, tree); + } + Statement::RevertStatement(ref revert_statement) => { + register_revert_statement(revert_statement, tree); + } + Statement::AssemblyStatement(ref assembly_statement) => { + register_assembly_statement(assembly_statement, tree); + } + Statement::Block(ref block) => { + register_block(block, tree); + } + Statement::UncheckedBlock(ref unchecked_block) => { + register_unchecked_block(unchecked_block, tree); + } + Statement::TupleDeconstructionStatement(ref tuple_deconstruction_statement) => { + register_tuple_deconstruction_statement(tuple_deconstruction_statement, tree); + } + Statement::VariableDeclarationStatement(ref variable_declaration_statement) => { + register_variable_declaration_statement(variable_declaration_statement, tree); + } + Statement::ExpressionStatement(ref expression_statement) => { + register_expression_statement(expression_statement, tree); + } + } +} + +pub fn register_tuple_member(node: &TupleMember, tree: &mut TreeIndex) { + match node { + TupleMember::TypedTupleMember(ref typed_tuple_member) => { + register_typed_tuple_member(typed_tuple_member, tree); + } + TupleMember::UntypedTupleMember(ref untyped_tuple_member) => { + register_untyped_tuple_member(untyped_tuple_member, tree); + } + } +} + +pub fn register_variable_declaration_type(node: &VariableDeclarationType, tree: &mut TreeIndex) { + match node { + VariableDeclarationType::TypeName(ref type_name) => { + register_type_name(type_name, tree); + } + VariableDeclarationType::VarKeyword => {} + } +} + +pub fn register_storage_location(_node: &StorageLocation, _tree: &mut TreeIndex) {} + +pub fn register_for_statement_initialization( + node: &ForStatementInitialization, + tree: &mut TreeIndex, +) { + match node { + ForStatementInitialization::TupleDeconstructionStatement( + ref tuple_deconstruction_statement, + ) => { + register_tuple_deconstruction_statement(tuple_deconstruction_statement, tree); + } + ForStatementInitialization::VariableDeclarationStatement( + ref variable_declaration_statement, + ) => { + register_variable_declaration_statement(variable_declaration_statement, tree); + } + ForStatementInitialization::ExpressionStatement(ref expression_statement) => { + register_expression_statement(expression_statement, tree); + } + ForStatementInitialization::Semicolon => {} + } +} + +pub fn register_for_statement_condition(node: &ForStatementCondition, tree: &mut TreeIndex) { + match node { + ForStatementCondition::ExpressionStatement(ref expression_statement) => { + register_expression_statement(expression_statement, tree); + } + ForStatementCondition::Semicolon => {} + } +} + +pub fn register_expression(node: &Expression, tree: &mut TreeIndex) { + match node { + Expression::AssignmentExpression(ref assignment_expression) => { + register_assignment_expression(assignment_expression, tree); + } + Expression::ConditionalExpression(ref conditional_expression) => { + register_conditional_expression(conditional_expression, tree); + } + Expression::OrExpression(ref or_expression) => { + register_or_expression(or_expression, tree); + } + Expression::AndExpression(ref and_expression) => { + register_and_expression(and_expression, tree); + } + Expression::EqualityExpression(ref equality_expression) => { + register_equality_expression(equality_expression, tree); + } + Expression::InequalityExpression(ref inequality_expression) => { + register_inequality_expression(inequality_expression, tree); + } + Expression::BitwiseOrExpression(ref bitwise_or_expression) => { + register_bitwise_or_expression(bitwise_or_expression, tree); + } + Expression::BitwiseXorExpression(ref bitwise_xor_expression) => { + register_bitwise_xor_expression(bitwise_xor_expression, tree); + } + Expression::BitwiseAndExpression(ref bitwise_and_expression) => { + register_bitwise_and_expression(bitwise_and_expression, tree); + } + Expression::ShiftExpression(ref shift_expression) => { + register_shift_expression(shift_expression, tree); + } + Expression::AdditiveExpression(ref additive_expression) => { + register_additive_expression(additive_expression, tree); + } + Expression::MultiplicativeExpression(ref multiplicative_expression) => { + register_multiplicative_expression(multiplicative_expression, tree); + } + Expression::ExponentiationExpression(ref exponentiation_expression) => { + register_exponentiation_expression(exponentiation_expression, tree); + } + Expression::PostfixExpression(ref postfix_expression) => { + register_postfix_expression(postfix_expression, tree); + } + Expression::PrefixExpression(ref prefix_expression) => { + register_prefix_expression(prefix_expression, tree); + } + Expression::FunctionCallExpression(ref function_call_expression) => { + register_function_call_expression(function_call_expression, tree); + } + Expression::CallOptionsExpression(ref call_options_expression) => { + register_call_options_expression(call_options_expression, tree); + } + Expression::MemberAccessExpression(ref member_access_expression) => { + register_member_access_expression(member_access_expression, tree); + } + Expression::IndexAccessExpression(ref index_access_expression) => { + register_index_access_expression(index_access_expression, tree); + } + Expression::NewExpression(ref new_expression) => { + register_new_expression(new_expression, tree); + } + Expression::TupleExpression(ref tuple_expression) => { + register_tuple_expression(tuple_expression, tree); + } + Expression::TypeExpression(ref type_expression) => { + register_type_expression(type_expression, tree); + } + Expression::ArrayExpression(ref array_expression) => { + register_array_expression(array_expression, tree); + } + Expression::HexNumberExpression(ref hex_number_expression) => { + register_hex_number_expression(hex_number_expression, tree); + } + Expression::DecimalNumberExpression(ref decimal_number_expression) => { + register_decimal_number_expression(decimal_number_expression, tree); + } + Expression::StringExpression(ref string_expression) => { + register_string_expression(string_expression, tree); + } + Expression::ElementaryType(ref elementary_type) => { + register_elementary_type(elementary_type, tree); + } + Expression::Identifier(_) => {} + Expression::PayableKeyword + | Expression::ThisKeyword + | Expression::SuperKeyword + | Expression::TrueKeyword + | Expression::FalseKeyword => {} + } +} + +pub fn register_arguments_declaration(node: &ArgumentsDeclaration, tree: &mut TreeIndex) { + match node { + ArgumentsDeclaration::PositionalArguments(ref positional_arguments) => { + register_positional_arguments(positional_arguments, tree); + } + ArgumentsDeclaration::NamedArguments(ref named_arguments) => { + register_named_arguments(named_arguments, tree); + } + } +} + +pub fn register_number_unit(_node: &NumberUnit, _tree: &mut TreeIndex) {} + +pub fn register_string_expression(node: &StringExpression, tree: &mut TreeIndex) { + match node { + StringExpression::Strings(ref strings) => { + register_strings(strings, tree); + } + StringExpression::HexStrings(ref hex_strings) => { + register_hex_strings(hex_strings, tree); + } + StringExpression::UnicodeStrings(ref unicode_strings) => { + register_unicode_strings(unicode_strings, tree); + } + } +} + +pub fn register_yul_statement(node: &YulStatement, tree: &mut TreeIndex) { + match node { + YulStatement::YulBlock(ref yul_block) => { + register_yul_block(yul_block, tree); + } + YulStatement::YulFunctionDefinition(ref yul_function_definition) => { + register_yul_function_definition(yul_function_definition, tree); + } + YulStatement::YulStackAssignmentStatement(ref yul_stack_assignment_statement) => { + register_yul_stack_assignment_statement(yul_stack_assignment_statement, tree); + } + YulStatement::YulIfStatement(ref yul_if_statement) => { + register_yul_if_statement(yul_if_statement, tree); + } + YulStatement::YulForStatement(ref yul_for_statement) => { + register_yul_for_statement(yul_for_statement, tree); + } + YulStatement::YulSwitchStatement(ref yul_switch_statement) => { + register_yul_switch_statement(yul_switch_statement, tree); + } + YulStatement::YulLeaveStatement(ref yul_leave_statement) => { + register_yul_leave_statement(yul_leave_statement, tree); + } + YulStatement::YulBreakStatement(ref yul_break_statement) => { + register_yul_break_statement(yul_break_statement, tree); + } + YulStatement::YulContinueStatement(ref yul_continue_statement) => { + register_yul_continue_statement(yul_continue_statement, tree); + } + YulStatement::YulVariableAssignmentStatement(ref yul_variable_assignment_statement) => { + register_yul_variable_assignment_statement(yul_variable_assignment_statement, tree); + } + YulStatement::YulLabel(ref yul_label) => { + register_yul_label(yul_label, tree); + } + YulStatement::YulVariableDeclarationStatement(ref yul_variable_declaration_statement) => { + register_yul_variable_declaration_statement(yul_variable_declaration_statement, tree); + } + YulStatement::YulExpression(ref yul_expression) => { + register_yul_expression(yul_expression, tree); + } + } +} + +pub fn register_yul_assignment_operator(node: &YulAssignmentOperator, tree: &mut TreeIndex) { + match node { + YulAssignmentOperator::YulColonAndEqual(ref yul_colon_and_equal) => { + register_yul_colon_and_equal(yul_colon_and_equal, tree); + } + YulAssignmentOperator::ColonEqual => {} + } +} + +pub fn register_yul_stack_assignment_operator( + node: &YulStackAssignmentOperator, + tree: &mut TreeIndex, +) { + match node { + YulStackAssignmentOperator::YulEqualAndColon(ref yul_equal_and_colon) => { + register_yul_equal_and_colon(yul_equal_and_colon, tree); + } + YulStackAssignmentOperator::EqualColon => {} + } +} + +pub fn register_yul_switch_case(node: &YulSwitchCase, tree: &mut TreeIndex) { + match node { + YulSwitchCase::YulDefaultCase(ref yul_default_case) => { + register_yul_default_case(yul_default_case, tree); + } + YulSwitchCase::YulValueCase(ref yul_value_case) => { + register_yul_value_case(yul_value_case, tree); + } + } +} + +pub fn register_yul_expression(node: &YulExpression, tree: &mut TreeIndex) { + match node { + YulExpression::YulFunctionCallExpression(ref yul_function_call_expression) => { + register_yul_function_call_expression(yul_function_call_expression, tree); + } + YulExpression::YulLiteral(ref yul_literal) => { + register_yul_literal(yul_literal, tree); + } + YulExpression::YulPath(ref yul_path) => { + register_yul_path(yul_path, tree); + } + } +} + +pub fn register_yul_literal(_node: &YulLiteral, _tree: &mut TreeIndex) {} + +pub fn register_function_kind(_node: &FunctionKind, _tree: &mut TreeIndex) {} + +pub fn register_function_visibility(_node: &FunctionVisibility, _tree: &mut TreeIndex) {} + +pub fn register_function_mutability(_node: &FunctionMutability, _tree: &mut TreeIndex) {} + +pub fn register_state_variable_visibility(_node: &StateVariableVisibility, _tree: &mut TreeIndex) {} + +pub fn register_state_variable_mutability(_node: &StateVariableMutability, _tree: &mut TreeIndex) {} + +// +// Repeated & Separated +// + +#[inline] +fn register_source_unit_members(items: &[SourceUnitMember], tree: &mut TreeIndex) { + for item in items { + register_source_unit_member(item, tree); + } +} + +#[inline] +fn register_version_expression_sets(items: &[VersionExpressionSet], tree: &mut TreeIndex) { + for item in items { + register_version_expression_set(item, tree); + } +} + +#[inline] +fn register_version_expression_set(items: &[VersionExpression], tree: &mut TreeIndex) { + for item in items { + register_version_expression(item, tree); + } +} + +#[inline] +fn register_simple_version_literal(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_import_deconstruction_symbols( + items: &[ImportDeconstructionSymbol], + tree: &mut TreeIndex, +) { + for item in items { + register_import_deconstruction_symbol(item, tree); + } +} + +#[inline] +fn register_using_deconstruction_symbols( + items: &[UsingDeconstructionSymbol], + tree: &mut TreeIndex, +) { + for item in items { + register_using_deconstruction_symbol(item, tree); + } +} + +#[inline] +fn register_inheritance_types(items: &[InheritanceType], tree: &mut TreeIndex) { + for item in items { + register_inheritance_type(item, tree); + } +} + +#[inline] +fn register_contract_members(items: &[ContractMember], tree: &mut TreeIndex) { + for item in items { + register_contract_member(item, tree); + } +} + +#[inline] +fn register_interface_members(items: &[ContractMember], tree: &mut TreeIndex) { + for item in items { + register_contract_member(item, tree); + } +} + +#[inline] +fn register_library_members(items: &[ContractMember], tree: &mut TreeIndex) { + for item in items { + register_contract_member(item, tree); + } +} + +#[inline] +fn register_struct_members(items: &[StructMember], tree: &mut TreeIndex) { + for item in items { + register_struct_member(item, tree); + } +} + +#[inline] +fn register_enum_members(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_parameters(items: &[Parameter], tree: &mut TreeIndex) { + for item in items { + register_parameter(item, tree); + } +} + +#[inline] +fn register_override_paths(items: &[IdentifierPath], tree: &mut TreeIndex) { + for item in items { + register_identifier_path(item, tree); + } +} + +#[inline] +fn register_event_parameters(items: &[EventParameter], tree: &mut TreeIndex) { + for item in items { + register_event_parameter(item, tree); + } +} + +#[inline] +fn register_error_parameters(items: &[ErrorParameter], tree: &mut TreeIndex) { + for item in items { + register_error_parameter(item, tree); + } +} + +#[inline] +fn register_statements(items: &[Statement], tree: &mut TreeIndex) { + for item in items { + register_statement(item, tree); + } +} + +#[inline] +fn register_tuple_deconstruction_elements( + items: &[TupleDeconstructionElement], + tree: &mut TreeIndex, +) { + for item in items { + register_tuple_deconstruction_element(item, tree); + } +} + +#[inline] +fn register_catch_clauses(items: &[CatchClause], tree: &mut TreeIndex) { + for item in items { + register_catch_clause(item, tree); + } +} + +#[inline] +fn register_positional_arguments(items: &[Expression], tree: &mut TreeIndex) { + for item in items { + register_expression(item, tree); + } +} + +#[inline] +fn register_named_arguments(items: &[NamedArgument], tree: &mut TreeIndex) { + for item in items { + register_named_argument(item, tree); + } +} + +#[inline] +fn register_call_options(items: &[NamedArgument], tree: &mut TreeIndex) { + for item in items { + register_named_argument(item, tree); + } +} + +#[inline] +fn register_tuple_values(items: &[TupleValue], tree: &mut TreeIndex) { + for item in items { + register_tuple_value(item, tree); + } +} + +#[inline] +fn register_array_values(items: &[Expression], tree: &mut TreeIndex) { + for item in items { + register_expression(item, tree); + } +} + +#[inline] +fn register_identifier_path(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_yul_statements(items: &[YulStatement], tree: &mut TreeIndex) { + for item in items { + register_yul_statement(item, tree); + } +} + +#[inline] +fn register_yul_parameters(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_yul_variable_names(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_yul_switch_cases(items: &[YulSwitchCase], tree: &mut TreeIndex) { + for item in items { + register_yul_switch_case(item, tree); + } +} + +#[inline] +fn register_yul_arguments(items: &[YulExpression], tree: &mut TreeIndex) { + for item in items { + register_yul_expression(item, tree); + } +} + +#[inline] +fn register_yul_paths(items: &[YulPath], tree: &mut TreeIndex) { + for item in items { + register_yul_path(item, tree); + } +} + +#[inline] +fn register_yul_path(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_modifier_invocations(items: &[ModifierInvocation], tree: &mut TreeIndex) { + for item in items { + register_modifier_invocation(item, tree); + } +} + +#[inline] +fn register_strings(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_hex_strings(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_unicode_strings(_items: &[Rc], _tree: &mut TreeIndex) {} + +#[inline] +fn register_assembly_flags(_items: &[Rc], _tree: &mut TreeIndex) {} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.rs.jinja2 new file mode 100644 index 0000000000..e7d57459a9 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.rs.jinja2 @@ -0,0 +1,2 @@ +{%- import "src/backend/ir/common/_index.rs.jinja2" as index -%} +{{ index::render_index(language='ir2_flat_contracts') }} diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/mod.rs index 80f104bd45..7f361ca30a 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/mod.rs @@ -2,6 +2,8 @@ mod nodes; pub use nodes::*; +#[path = "index.generated.rs"] +pub mod index; #[path = "transformer.generated.rs"] pub mod transformer; #[path = "visitor.generated.rs"] diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs index 328829373a..93ce1009ff 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs @@ -5,7 +5,7 @@ use std::vec::Vec; use metaslang_cst::nodes::NodeId; -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; // // Sequences: @@ -15,230 +15,374 @@ pub type SourceUnit = Rc; #[derive(Debug)] pub struct SourceUnitStruct { - pub node_id: NodeId, + pub node: Rc, pub members: SourceUnitMembers, } +impl SourceUnitStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PragmaDirective = Rc; #[derive(Debug)] pub struct PragmaDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub pragma: Pragma, } +impl PragmaDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AbicoderPragma = Rc; #[derive(Debug)] pub struct AbicoderPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub version: AbicoderVersion, } +impl AbicoderPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExperimentalPragma = Rc; #[derive(Debug)] pub struct ExperimentalPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub feature: ExperimentalFeature, } +impl ExperimentalPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionPragma = Rc; #[derive(Debug)] pub struct VersionPragmaStruct { - pub node_id: NodeId, + pub node: Rc, pub sets: VersionExpressionSets, } +impl VersionPragmaStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionRange = Rc; #[derive(Debug)] pub struct VersionRangeStruct { - pub node_id: NodeId, + pub node: Rc, pub start: VersionLiteral, pub end: VersionLiteral, } +impl VersionRangeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type VersionTerm = Rc; #[derive(Debug)] pub struct VersionTermStruct { - pub node_id: NodeId, + pub node: Rc, pub operator: Option, pub literal: VersionLiteral, } +impl VersionTermStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportDirective = Rc; #[derive(Debug)] pub struct ImportDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub clause: ImportClause, } +impl ImportDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PathImport = Rc; #[derive(Debug)] pub struct PathImportStruct { - pub node_id: NodeId, - pub alias: Option>, - pub path: Rc, + pub node: Rc, + pub alias: Option>, + pub path: Rc, +} + +impl PathImportStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type NamedImport = Rc; #[derive(Debug)] pub struct NamedImportStruct { - pub node_id: NodeId, - pub alias: Rc, - pub path: Rc, + pub node: Rc, + pub alias: Rc, + pub path: Rc, +} + +impl NamedImportStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ImportDeconstruction = Rc; #[derive(Debug)] pub struct ImportDeconstructionStruct { - pub node_id: NodeId, + pub node: Rc, pub symbols: ImportDeconstructionSymbols, - pub path: Rc, + pub path: Rc, +} + +impl ImportDeconstructionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ImportDeconstructionSymbol = Rc; #[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { - pub node_id: NodeId, - pub name: Rc, - pub alias: Option>, + pub node: Rc, + pub name: Rc, + pub alias: Option>, +} + +impl ImportDeconstructionSymbolStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UsingDirective = Rc; #[derive(Debug)] pub struct UsingDirectiveStruct { - pub node_id: NodeId, + pub node: Rc, pub clause: UsingClause, pub target: UsingTarget, pub global_keyword: bool, } +impl UsingDirectiveStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UsingDeconstruction = Rc; #[derive(Debug)] pub struct UsingDeconstructionStruct { - pub node_id: NodeId, + pub node: Rc, pub symbols: UsingDeconstructionSymbols, } +impl UsingDeconstructionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UsingDeconstructionSymbol = Rc; #[derive(Debug)] pub struct UsingDeconstructionSymbolStruct { - pub node_id: NodeId, + pub node: Rc, pub name: IdentifierPath, pub alias: Option, } +impl UsingDeconstructionSymbolStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ContractDefinition = Rc; #[derive(Debug)] pub struct ContractDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub abstract_keyword: bool, - pub name: Rc, + pub name: Rc, pub members: ContractMembers, pub inheritance_types: InheritanceTypes, pub storage_layout: Option, } +impl ContractDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InheritanceType = Rc; #[derive(Debug)] pub struct InheritanceTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: IdentifierPath, pub arguments: Option, } +impl InheritanceTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InterfaceDefinition = Rc; #[derive(Debug)] pub struct InterfaceDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub inheritance: Option, pub members: InterfaceMembers, } +impl InterfaceDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type LibraryDefinition = Rc; #[derive(Debug)] pub struct LibraryDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: LibraryMembers, } +impl LibraryDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StructDefinition = Rc; #[derive(Debug)] pub struct StructDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: StructMembers, } +impl StructDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StructMember = Rc; #[derive(Debug)] pub struct StructMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, +} + +impl StructMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: EnumMembers, } +impl EnumDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ConstantDefinition = Rc; #[derive(Debug)] pub struct ConstantDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Expression, } +impl ConstantDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type StateVariableDefinition = Rc; #[derive(Debug)] pub struct StateVariableDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Option, pub visibility: StateVariableVisibility, pub mutability: StateVariableMutability, pub override_specifier: Option, } +impl StateVariableDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionDefinition = Rc; #[derive(Debug)] pub struct FunctionDefinitionStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: Parameters, pub returns: Option, pub kind: FunctionKind, - pub name: Option>, + pub name: Option>, pub body: Option, pub visibility: FunctionVisibility, pub mutability: FunctionMutability, @@ -247,733 +391,1225 @@ pub struct FunctionDefinitionStruct { pub modifier_invocations: ModifierInvocations, } +impl FunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type Parameter = Rc; #[derive(Debug)] pub struct ParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Option>, + pub name: Option>, +} + +impl ParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type OverrideSpecifier = Rc; #[derive(Debug)] pub struct OverrideSpecifierStruct { - pub node_id: NodeId, + pub node: Rc, pub overridden: Option, } +impl OverrideSpecifierStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ModifierInvocation = Rc; #[derive(Debug)] pub struct ModifierInvocationStruct { - pub node_id: NodeId, + pub node: Rc, pub name: IdentifierPath, pub arguments: Option, } +impl ModifierInvocationStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EventDefinition = Rc; #[derive(Debug)] pub struct EventDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub parameters: EventParameters, pub anonymous_keyword: bool, } +impl EventDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EventParameter = Rc; #[derive(Debug)] pub struct EventParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub indexed_keyword: bool, - pub name: Option>, + pub name: Option>, +} + +impl EventParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UserDefinedValueTypeDefinition = Rc; #[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub value_type: ElementaryType, } +impl UserDefinedValueTypeDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ErrorDefinition = Rc; #[derive(Debug)] pub struct ErrorDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub members: ErrorParameters, } +impl ErrorDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ErrorParameter = Rc; #[derive(Debug)] pub struct ErrorParameterStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, +} + +impl ErrorParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ArrayTypeName = Rc; #[derive(Debug)] pub struct ArrayTypeNameStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: TypeName, pub index: Option, } +impl ArrayTypeNameStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionType = Rc; #[derive(Debug)] pub struct FunctionTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub parameters: Parameters, pub returns: Option, pub visibility: FunctionVisibility, pub mutability: FunctionMutability, } +impl FunctionTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MappingType = Rc; #[derive(Debug)] pub struct MappingTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub key_type: MappingKey, pub value_type: MappingValue, } +impl MappingTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MappingKey = Rc; #[derive(Debug)] pub struct MappingKeyStruct { - pub node_id: NodeId, + pub node: Rc, pub key_type: MappingKeyType, - pub name: Option>, + pub name: Option>, +} + +impl MappingKeyStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type MappingValue = Rc; #[derive(Debug)] pub struct MappingValueStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, +} + +impl MappingValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type AddressType = Rc; #[derive(Debug)] pub struct AddressTypeStruct { - pub node_id: NodeId, + pub node: Rc, pub payable_keyword: bool, } +impl AddressTypeStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type Block = Rc; #[derive(Debug)] pub struct BlockStruct { - pub node_id: NodeId, + pub node: Rc, pub statements: Statements, } +impl BlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UncheckedBlock = Rc; #[derive(Debug)] pub struct UncheckedBlockStruct { - pub node_id: NodeId, + pub node: Rc, pub block: Block, } +impl UncheckedBlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExpressionStatement = Rc; #[derive(Debug)] pub struct ExpressionStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, } +impl ExpressionStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AssemblyStatement = Rc; #[derive(Debug)] pub struct AssemblyStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub body: YulBlock, pub flags: AssemblyFlags, - pub label: Option>, + pub label: Option>, +} + +impl AssemblyStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type TupleDeconstructionStatement = Rc; #[derive(Debug)] pub struct TupleDeconstructionStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub var_keyword: bool, pub elements: TupleDeconstructionElements, pub expression: Expression, } +impl TupleDeconstructionStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleDeconstructionElement = Rc; #[derive(Debug)] pub struct TupleDeconstructionElementStruct { - pub node_id: NodeId, + pub node: Rc, pub member: Option, } +impl TupleDeconstructionElementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TypedTupleMember = Rc; #[derive(Debug)] pub struct TypedTupleMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Rc, + pub name: Rc, +} + +impl TypedTupleMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type UntypedTupleMember = Rc; #[derive(Debug)] pub struct UntypedTupleMemberStruct { - pub node_id: NodeId, + pub node: Rc, pub storage_location: Option, - pub name: Rc, + pub name: Rc, +} + +impl UntypedTupleMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type VariableDeclarationStatement = Rc; #[derive(Debug)] pub struct VariableDeclarationStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variable_type: VariableDeclarationType, pub storage_location: Option, - pub name: Rc, + pub name: Rc, pub value: Option, } +impl VariableDeclarationStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type IfStatement = Rc; #[derive(Debug)] pub struct IfStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: Expression, pub body: Statement, pub else_branch: Option, } +impl IfStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ForStatement = Rc; #[derive(Debug)] pub struct ForStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub initialization: ForStatementInitialization, pub condition: ForStatementCondition, pub iterator: Option, pub body: Statement, } +impl ForStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type WhileStatement = Rc; #[derive(Debug)] pub struct WhileStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: Expression, pub body: Statement, } +impl WhileStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type DoWhileStatement = Rc; #[derive(Debug)] pub struct DoWhileStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub body: Statement, pub condition: Expression, } +impl DoWhileStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ContinueStatement = Rc; #[derive(Debug)] pub struct ContinueStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl ContinueStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type BreakStatement = Rc; #[derive(Debug)] pub struct BreakStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl BreakStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type ReturnStatement = Rc; #[derive(Debug)] pub struct ReturnStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Option, } +impl ReturnStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EmitStatement = Rc; #[derive(Debug)] pub struct EmitStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub event: IdentifierPath, pub arguments: ArgumentsDeclaration, } +impl EmitStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TryStatement = Rc; #[derive(Debug)] pub struct TryStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Expression, pub returns: Option, pub body: Block, pub catch_clauses: CatchClauses, } +impl TryStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CatchClause = Rc; #[derive(Debug)] pub struct CatchClauseStruct { - pub node_id: NodeId, + pub node: Rc, pub error: Option, pub body: Block, } +impl CatchClauseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CatchClauseError = Rc; #[derive(Debug)] pub struct CatchClauseErrorStruct { - pub node_id: NodeId, - pub name: Option>, + pub node: Rc, + pub name: Option>, pub parameters: Parameters, } +impl CatchClauseErrorStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type RevertStatement = Rc; #[derive(Debug)] pub struct RevertStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub error: Option, pub arguments: ArgumentsDeclaration, } +impl RevertStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ThrowStatement = Rc; #[derive(Debug)] pub struct ThrowStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl ThrowStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type AssignmentExpression = Rc; #[derive(Debug)] pub struct AssignmentExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl AssignmentExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ConditionalExpression = Rc; #[derive(Debug)] pub struct ConditionalExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub true_expression: Expression, pub false_expression: Expression, } +impl ConditionalExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type OrExpression = Rc; #[derive(Debug)] pub struct OrExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl OrExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AndExpression = Rc; #[derive(Debug)] pub struct AndExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl AndExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EqualityExpression = Rc; #[derive(Debug)] pub struct EqualityExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl EqualityExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type InequalityExpression = Rc; #[derive(Debug)] pub struct InequalityExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl InequalityExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseOrExpression = Rc; #[derive(Debug)] pub struct BitwiseOrExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseOrExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseXorExpression = Rc; #[derive(Debug)] pub struct BitwiseXorExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseXorExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type BitwiseAndExpression = Rc; #[derive(Debug)] pub struct BitwiseAndExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, pub right_operand: Expression, } +impl BitwiseAndExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ShiftExpression = Rc; #[derive(Debug)] pub struct ShiftExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl ShiftExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type AdditiveExpression = Rc; #[derive(Debug)] pub struct AdditiveExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl AdditiveExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MultiplicativeExpression = Rc; #[derive(Debug)] pub struct MultiplicativeExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl MultiplicativeExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ExponentiationExpression = Rc; #[derive(Debug)] pub struct ExponentiationExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } +impl ExponentiationExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PostfixExpression = Rc; #[derive(Debug)] pub struct PostfixExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, - pub operator: Rc, + pub operator: Rc, +} + +impl PostfixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { - pub node_id: NodeId, - pub operator: Rc, + pub node: Rc, + pub operator: Rc, pub operand: Expression, } +impl PrefixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type FunctionCallExpression = Rc; #[derive(Debug)] pub struct FunctionCallExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub arguments: ArgumentsDeclaration, } +impl FunctionCallExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type CallOptionsExpression = Rc; #[derive(Debug)] pub struct CallOptionsExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub options: CallOptions, } +impl CallOptionsExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type MemberAccessExpression = Rc; #[derive(Debug)] pub struct MemberAccessExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, - pub member: Rc, + pub member: Rc, +} + +impl MemberAccessExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type IndexAccessExpression = Rc; #[derive(Debug)] pub struct IndexAccessExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: Expression, pub start: Option, pub end: Option, } +impl IndexAccessExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NamedArgument = Rc; #[derive(Debug)] pub struct NamedArgumentStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub value: Expression, } +impl NamedArgumentStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TypeExpression = Rc; #[derive(Debug)] pub struct TypeExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, } +impl TypeExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type NewExpression = Rc; #[derive(Debug)] pub struct NewExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub type_name: TypeName, } +impl NewExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleExpression = Rc; #[derive(Debug)] pub struct TupleExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub items: TupleValues, } +impl TupleExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type TupleValue = Rc; #[derive(Debug)] pub struct TupleValueStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: Option, } +impl TupleValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ArrayExpression = Rc; #[derive(Debug)] pub struct ArrayExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub items: ArrayValues, } +impl ArrayExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type HexNumberExpression = Rc; #[derive(Debug)] pub struct HexNumberExpressionStruct { - pub node_id: NodeId, - pub literal: Rc, + pub node: Rc, + pub literal: Rc, pub unit: Option, } +impl HexNumberExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type DecimalNumberExpression = Rc; #[derive(Debug)] pub struct DecimalNumberExpressionStruct { - pub node_id: NodeId, - pub literal: Rc, + pub node: Rc, + pub literal: Rc, pub unit: Option, } +impl DecimalNumberExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulBlock = Rc; #[derive(Debug)] pub struct YulBlockStruct { - pub node_id: NodeId, + pub node: Rc, pub statements: YulStatements, } +impl YulBlockStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulFunctionDefinition = Rc; #[derive(Debug)] pub struct YulFunctionDefinitionStruct { - pub node_id: NodeId, - pub name: Rc, + pub node: Rc, + pub name: Rc, pub parameters: YulParameters, pub returns: Option, pub body: YulBlock, } +impl YulFunctionDefinitionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableDeclarationStatement = Rc; #[derive(Debug)] pub struct YulVariableDeclarationStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: YulVariableNames, pub value: Option, } +impl YulVariableDeclarationStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableDeclarationValue = Rc; #[derive(Debug)] pub struct YulVariableDeclarationValueStruct { - pub node_id: NodeId, + pub node: Rc, pub assignment: YulAssignmentOperator, pub expression: YulExpression, } +impl YulVariableDeclarationValueStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulVariableAssignmentStatement = Rc; #[derive(Debug)] pub struct YulVariableAssignmentStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub variables: YulPaths, pub assignment: YulAssignmentOperator, pub expression: YulExpression, } +impl YulVariableAssignmentStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulColonAndEqual = Rc; #[derive(Debug)] pub struct YulColonAndEqualStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulColonAndEqualStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulStackAssignmentStatement = Rc; #[derive(Debug)] pub struct YulStackAssignmentStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub assignment: YulStackAssignmentOperator, - pub variable: Rc, + pub variable: Rc, +} + +impl YulStackAssignmentStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulEqualAndColon = Rc; #[derive(Debug)] pub struct YulEqualAndColonStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulEqualAndColonStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulIfStatement = Rc; #[derive(Debug)] pub struct YulIfStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub condition: YulExpression, pub body: YulBlock, } +impl YulIfStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulForStatement = Rc; #[derive(Debug)] pub struct YulForStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub initialization: YulBlock, pub condition: YulExpression, pub iterator: YulBlock, pub body: YulBlock, } +impl YulForStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulSwitchStatement = Rc; #[derive(Debug)] pub struct YulSwitchStatementStruct { - pub node_id: NodeId, + pub node: Rc, pub expression: YulExpression, pub cases: YulSwitchCases, } +impl YulSwitchStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulDefaultCase = Rc; #[derive(Debug)] pub struct YulDefaultCaseStruct { - pub node_id: NodeId, + pub node: Rc, pub body: YulBlock, } +impl YulDefaultCaseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulValueCase = Rc; #[derive(Debug)] pub struct YulValueCaseStruct { - pub node_id: NodeId, + pub node: Rc, pub value: YulLiteral, pub body: YulBlock, } +impl YulValueCaseStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type YulLeaveStatement = Rc; #[derive(Debug)] pub struct YulLeaveStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulLeaveStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulBreakStatement = Rc; #[derive(Debug)] pub struct YulBreakStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulBreakStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulContinueStatement = Rc; #[derive(Debug)] pub struct YulContinueStatementStruct { - pub node_id: NodeId, + pub node: Rc, +} + +impl YulContinueStatementStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulLabel = Rc; #[derive(Debug)] pub struct YulLabelStruct { - pub node_id: NodeId, - pub label: Rc, + pub node: Rc, + pub label: Rc, +} + +impl YulLabelStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } } pub type YulFunctionCallExpression = Rc; #[derive(Debug)] pub struct YulFunctionCallExpressionStruct { - pub node_id: NodeId, + pub node: Rc, pub operand: YulExpression, pub arguments: YulArguments, } +impl YulFunctionCallExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + // // Choices: // @@ -1010,7 +1646,7 @@ pub enum AbicoderVersion { #[derive(Debug)] pub enum ExperimentalFeature { - StringLiteral(Rc), + StringLiteral(Rc), ABIEncoderV2Keyword, SMTCheckerKeyword, } @@ -1035,8 +1671,8 @@ pub enum VersionOperator { #[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), - SingleQuotedVersionLiteral(Rc), - DoubleQuotedVersionLiteral(Rc), + SingleQuotedVersionLiteral(Rc), + DoubleQuotedVersionLiteral(Rc), } #[derive(Debug)] @@ -1107,11 +1743,11 @@ pub enum MappingKeyType { #[derive(Debug)] pub enum ElementaryType { AddressType(AddressType), - BytesKeyword(Rc), - IntKeyword(Rc), - UintKeyword(Rc), - FixedKeyword(Rc), - UfixedKeyword(Rc), + BytesKeyword(Rc), + IntKeyword(Rc), + UintKeyword(Rc), + FixedKeyword(Rc), + UfixedKeyword(Rc), BoolKeyword, ByteKeyword, StringKeyword, @@ -1200,7 +1836,7 @@ pub enum Expression { DecimalNumberExpression(DecimalNumberExpression), StringExpression(StringExpression), ElementaryType(ElementaryType), - Identifier(Rc), + Identifier(Rc), PayableKeyword, ThisKeyword, SuperKeyword, @@ -1280,10 +1916,10 @@ pub enum YulExpression { #[derive(Debug)] pub enum YulLiteral { - YulDecimalLiteral(Rc), - YulHexLiteral(Rc), - StringLiteral(Rc), - HexStringLiteral(Rc), + YulDecimalLiteral(Rc), + YulHexLiteral(Rc), + StringLiteral(Rc), + HexStringLiteral(Rc), YulTrueKeyword, YulFalseKeyword, } @@ -1339,7 +1975,7 @@ pub type VersionExpressionSets = Vec; pub type VersionExpressionSet = Vec; -pub type SimpleVersionLiteral = Vec>; +pub type SimpleVersionLiteral = Vec>; pub type ImportDeconstructionSymbols = Vec; @@ -1355,7 +1991,7 @@ pub type LibraryMembers = Vec; pub type StructMembers = Vec; -pub type EnumMembers = Vec>; +pub type EnumMembers = Vec>; pub type Parameters = Vec; @@ -1381,13 +2017,13 @@ pub type TupleValues = Vec; pub type ArrayValues = Vec; -pub type IdentifierPath = Vec>; +pub type IdentifierPath = Vec>; pub type YulStatements = Vec; -pub type YulParameters = Vec>; +pub type YulParameters = Vec>; -pub type YulVariableNames = Vec>; +pub type YulVariableNames = Vec>; pub type YulSwitchCases = Vec; @@ -1395,14 +2031,14 @@ pub type YulArguments = Vec; pub type YulPaths = Vec; -pub type YulPath = Vec>; +pub type YulPath = Vec>; pub type ModifierInvocations = Vec; -pub type Strings = Vec>; +pub type Strings = Vec>; -pub type HexStrings = Vec>; +pub type HexStrings = Vec>; -pub type UnicodeStrings = Vec>; +pub type UnicodeStrings = Vec>; -pub type AssemblyFlags = Vec>; +pub type AssemblyFlags = Vec>; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/transformer.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/transformer.generated.rs index 98f2009937..7c8f9ea82f 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/transformer.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/transformer.generated.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use super::{input, nodes as output}; #[allow(unused)] -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; pub trait Transformer { // @@ -18,7 +18,7 @@ pub trait Transformer { let members = self.transform_source_unit_members(&source.members); Rc::new(output::SourceUnitStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), members, }) } @@ -30,7 +30,7 @@ pub trait Transformer { let pragma = self.transform_pragma(&source.pragma); Rc::new(output::PragmaDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), pragma, }) } @@ -42,7 +42,7 @@ pub trait Transformer { let version = self.transform_abicoder_version(&source.version); Rc::new(output::AbicoderPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), version, }) } @@ -54,7 +54,7 @@ pub trait Transformer { let feature = self.transform_experimental_feature(&source.feature); Rc::new(output::ExperimentalPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), feature, }) } @@ -63,7 +63,7 @@ pub trait Transformer { let sets = self.transform_version_expression_sets(&source.sets); Rc::new(output::VersionPragmaStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), sets, }) } @@ -73,7 +73,7 @@ pub trait Transformer { let end = self.transform_version_literal(&source.end); Rc::new(output::VersionRangeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), start, end, }) @@ -87,7 +87,7 @@ pub trait Transformer { let literal = self.transform_version_literal(&source.literal); Rc::new(output::VersionTermStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operator, literal, }) @@ -100,7 +100,7 @@ pub trait Transformer { let clause = self.transform_import_clause(&source.clause); Rc::new(output::ImportDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), clause, }) } @@ -125,7 +125,7 @@ pub trait Transformer { .map(|value| self.transform_import_alias(value)); Rc::new(output::ImportDeconstructionSymbolStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, alias, }) @@ -140,7 +140,7 @@ pub trait Transformer { let global_keyword = source.global_keyword; Rc::new(output::UsingDirectiveStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), clause, target, global_keyword, @@ -154,7 +154,7 @@ pub trait Transformer { let symbols = self.transform_using_deconstruction_symbols(&source.symbols); Rc::new(output::UsingDeconstructionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), symbols, }) } @@ -170,7 +170,7 @@ pub trait Transformer { .map(|value| self.transform_using_alias(value)); Rc::new(output::UsingDeconstructionSymbolStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, alias, }) @@ -192,7 +192,7 @@ pub trait Transformer { .map(|value| self.transform_arguments_declaration(value)); Rc::new(output::InheritanceTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, arguments, }) @@ -210,7 +210,7 @@ pub trait Transformer { let members = self.transform_interface_members(&source.members); Rc::new(output::InterfaceDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, inheritance, members, @@ -225,7 +225,7 @@ pub trait Transformer { let members = self.transform_library_members(&source.members); Rc::new(output::LibraryDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -239,7 +239,7 @@ pub trait Transformer { let members = self.transform_struct_members(&source.members); Rc::new(output::StructDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -250,7 +250,7 @@ pub trait Transformer { let name = Rc::clone(&source.name); Rc::new(output::StructMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -264,7 +264,7 @@ pub trait Transformer { let members = self.transform_enum_members(&source.members); Rc::new(output::EnumDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -279,7 +279,7 @@ pub trait Transformer { let value = self.transform_expression(&source.value); Rc::new(output::ConstantDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, value, @@ -305,7 +305,7 @@ pub trait Transformer { let name = source.name.as_ref().map(Rc::clone); Rc::new(output::ParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, storage_location, name, @@ -322,7 +322,7 @@ pub trait Transformer { .map(|value| self.transform_override_paths_declaration(value)); Rc::new(output::OverrideSpecifierStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), overridden, }) } @@ -338,7 +338,7 @@ pub trait Transformer { .map(|value| self.transform_arguments_declaration(value)); Rc::new(output::ModifierInvocationStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, arguments, }) @@ -353,7 +353,7 @@ pub trait Transformer { let anonymous_keyword = source.anonymous_keyword; Rc::new(output::EventDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, anonymous_keyword, @@ -369,7 +369,7 @@ pub trait Transformer { let name = source.name.as_ref().map(Rc::clone); Rc::new(output::EventParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, indexed_keyword, name, @@ -384,7 +384,7 @@ pub trait Transformer { let value_type = self.transform_elementary_type(&source.value_type); Rc::new(output::UserDefinedValueTypeDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, value_type, }) @@ -398,7 +398,7 @@ pub trait Transformer { let members = self.transform_error_parameters_declaration(&source.members); Rc::new(output::ErrorDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, members, }) @@ -412,7 +412,7 @@ pub trait Transformer { let name = source.name.as_ref().map(Rc::clone); Rc::new(output::ErrorParameterStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -429,7 +429,7 @@ pub trait Transformer { .map(|value| self.transform_expression(value)); Rc::new(output::ArrayTypeNameStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, index, }) @@ -442,7 +442,7 @@ pub trait Transformer { let value_type = self.transform_mapping_value(&source.value_type); Rc::new(output::MappingTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), key_type, value_type, }) @@ -453,7 +453,7 @@ pub trait Transformer { let name = source.name.as_ref().map(Rc::clone); Rc::new(output::MappingKeyStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), key_type, name, }) @@ -464,7 +464,7 @@ pub trait Transformer { let name = source.name.as_ref().map(Rc::clone); Rc::new(output::MappingValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, name, }) @@ -474,7 +474,7 @@ pub trait Transformer { let payable_keyword = source.payable_keyword; Rc::new(output::AddressTypeStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), payable_keyword, }) } @@ -483,7 +483,7 @@ pub trait Transformer { let statements = self.transform_statements(&source.statements); Rc::new(output::BlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), statements, }) } @@ -495,7 +495,7 @@ pub trait Transformer { let block = self.transform_block(&source.block); Rc::new(output::UncheckedBlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), block, }) } @@ -507,7 +507,7 @@ pub trait Transformer { let expression = self.transform_expression(&source.expression); Rc::new(output::ExpressionStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -526,7 +526,7 @@ pub trait Transformer { let expression = self.transform_expression(&source.expression); Rc::new(output::TupleDeconstructionStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), var_keyword, elements, expression, @@ -543,7 +543,7 @@ pub trait Transformer { .map(|value| self.transform_tuple_member(value)); Rc::new(output::TupleDeconstructionElementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), member, }) } @@ -560,7 +560,7 @@ pub trait Transformer { let name = Rc::clone(&source.name); Rc::new(output::TypedTupleMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, storage_location, name, @@ -578,7 +578,7 @@ pub trait Transformer { let name = Rc::clone(&source.name); Rc::new(output::UntypedTupleMemberStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), storage_location, name, }) @@ -600,7 +600,7 @@ pub trait Transformer { .map(|value| self.transform_variable_declaration_value(value)); Rc::new(output::VariableDeclarationStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variable_type, storage_location, name, @@ -617,7 +617,7 @@ pub trait Transformer { .map(|value| self.transform_else_branch(value)); Rc::new(output::IfStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, else_branch, @@ -634,7 +634,7 @@ pub trait Transformer { let body = self.transform_statement(&source.body); Rc::new(output::ForStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), initialization, condition, iterator, @@ -650,7 +650,7 @@ pub trait Transformer { let body = self.transform_statement(&source.body); Rc::new(output::WhileStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, }) @@ -664,7 +664,7 @@ pub trait Transformer { let condition = self.transform_expression(&source.condition); Rc::new(output::DoWhileStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), body, condition, }) @@ -675,7 +675,7 @@ pub trait Transformer { source: &input::ContinueStatement, ) -> output::ContinueStatement { Rc::new(output::ContinueStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -684,7 +684,7 @@ pub trait Transformer { source: &input::BreakStatement, ) -> output::BreakStatement { Rc::new(output::BreakStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -698,7 +698,7 @@ pub trait Transformer { .map(|value| self.transform_expression(value)); Rc::new(output::ReturnStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -708,7 +708,7 @@ pub trait Transformer { let arguments = self.transform_arguments_declaration(&source.arguments); Rc::new(output::EmitStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), event, arguments, }) @@ -724,7 +724,7 @@ pub trait Transformer { let catch_clauses = self.transform_catch_clauses(&source.catch_clauses); Rc::new(output::TryStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, returns, body, @@ -740,7 +740,7 @@ pub trait Transformer { let body = self.transform_block(&source.body); Rc::new(output::CatchClauseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), error, body, }) @@ -754,7 +754,7 @@ pub trait Transformer { let parameters = self.transform_parameters_declaration(&source.parameters); Rc::new(output::CatchClauseErrorStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, }) @@ -771,7 +771,7 @@ pub trait Transformer { let arguments = self.transform_arguments_declaration(&source.arguments); Rc::new(output::RevertStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), error, arguments, }) @@ -782,7 +782,7 @@ pub trait Transformer { source: &input::ThrowStatement, ) -> output::ThrowStatement { Rc::new(output::ThrowStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -795,7 +795,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::AssignmentExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -811,7 +811,7 @@ pub trait Transformer { let false_expression = self.transform_expression(&source.false_expression); Rc::new(output::ConditionalExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, true_expression, false_expression, @@ -823,7 +823,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::OrExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -834,7 +834,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::AndExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -849,7 +849,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::EqualityExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -865,7 +865,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::InequalityExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -880,7 +880,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::BitwiseOrExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -894,7 +894,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::BitwiseXorExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -908,7 +908,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::BitwiseAndExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, right_operand, }) @@ -923,7 +923,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::ShiftExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -939,7 +939,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::AdditiveExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -955,7 +955,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::MultiplicativeExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -971,7 +971,7 @@ pub trait Transformer { let right_operand = self.transform_expression(&source.right_operand); Rc::new(output::ExponentiationExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), left_operand, operator, right_operand, @@ -986,7 +986,7 @@ pub trait Transformer { let operator = Rc::clone(&source.operator); Rc::new(output::PostfixExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, operator, }) @@ -1000,7 +1000,7 @@ pub trait Transformer { let operand = self.transform_expression(&source.operand); Rc::new(output::PrefixExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operator, operand, }) @@ -1014,7 +1014,7 @@ pub trait Transformer { let arguments = self.transform_arguments_declaration(&source.arguments); Rc::new(output::FunctionCallExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, arguments, }) @@ -1028,7 +1028,7 @@ pub trait Transformer { let options = self.transform_call_options(&source.options); Rc::new(output::CallOptionsExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, options, }) @@ -1042,7 +1042,7 @@ pub trait Transformer { let member = Rc::clone(&source.member); Rc::new(output::MemberAccessExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, member, }) @@ -1058,7 +1058,7 @@ pub trait Transformer { let value = self.transform_expression(&source.value); Rc::new(output::NamedArgumentStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, value, }) @@ -1071,7 +1071,7 @@ pub trait Transformer { let type_name = self.transform_type_name(&source.type_name); Rc::new(output::TypeExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, }) } @@ -1080,7 +1080,7 @@ pub trait Transformer { let type_name = self.transform_type_name(&source.type_name); Rc::new(output::NewExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), type_name, }) } @@ -1092,7 +1092,7 @@ pub trait Transformer { let items = self.transform_tuple_values(&source.items); Rc::new(output::TupleExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), items, }) } @@ -1104,7 +1104,7 @@ pub trait Transformer { .map(|value| self.transform_expression(value)); Rc::new(output::TupleValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, }) } @@ -1116,7 +1116,7 @@ pub trait Transformer { let items = self.transform_array_values(&source.items); Rc::new(output::ArrayExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), items, }) } @@ -1132,7 +1132,7 @@ pub trait Transformer { .map(|value| self.transform_number_unit(value)); Rc::new(output::HexNumberExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), literal, unit, }) @@ -1149,7 +1149,7 @@ pub trait Transformer { .map(|value| self.transform_number_unit(value)); Rc::new(output::DecimalNumberExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), literal, unit, }) @@ -1159,7 +1159,7 @@ pub trait Transformer { let statements = self.transform_yul_statements(&source.statements); Rc::new(output::YulBlockStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), statements, }) } @@ -1177,7 +1177,7 @@ pub trait Transformer { let body = self.transform_yul_block(&source.body); Rc::new(output::YulFunctionDefinitionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), name, parameters, returns, @@ -1196,7 +1196,7 @@ pub trait Transformer { .map(|value| self.transform_yul_variable_declaration_value(value)); Rc::new(output::YulVariableDeclarationStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, value, }) @@ -1210,7 +1210,7 @@ pub trait Transformer { let expression = self.transform_yul_expression(&source.expression); Rc::new(output::YulVariableDeclarationValueStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), assignment, expression, }) @@ -1225,7 +1225,7 @@ pub trait Transformer { let expression = self.transform_yul_expression(&source.expression); Rc::new(output::YulVariableAssignmentStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), variables, assignment, expression, @@ -1237,7 +1237,7 @@ pub trait Transformer { source: &input::YulColonAndEqual, ) -> output::YulColonAndEqual { Rc::new(output::YulColonAndEqualStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1249,7 +1249,7 @@ pub trait Transformer { let variable = Rc::clone(&source.variable); Rc::new(output::YulStackAssignmentStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), assignment, variable, }) @@ -1260,7 +1260,7 @@ pub trait Transformer { source: &input::YulEqualAndColon, ) -> output::YulEqualAndColon { Rc::new(output::YulEqualAndColonStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1272,7 +1272,7 @@ pub trait Transformer { let body = self.transform_yul_block(&source.body); Rc::new(output::YulIfStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), condition, body, }) @@ -1288,7 +1288,7 @@ pub trait Transformer { let body = self.transform_yul_block(&source.body); Rc::new(output::YulForStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), initialization, condition, iterator, @@ -1304,7 +1304,7 @@ pub trait Transformer { let cases = self.transform_yul_switch_cases(&source.cases); Rc::new(output::YulSwitchStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), expression, cases, }) @@ -1317,7 +1317,7 @@ pub trait Transformer { let body = self.transform_yul_block(&source.body); Rc::new(output::YulDefaultCaseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), body, }) } @@ -1327,7 +1327,7 @@ pub trait Transformer { let body = self.transform_yul_block(&source.body); Rc::new(output::YulValueCaseStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), value, body, }) @@ -1338,7 +1338,7 @@ pub trait Transformer { source: &input::YulLeaveStatement, ) -> output::YulLeaveStatement { Rc::new(output::YulLeaveStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1347,7 +1347,7 @@ pub trait Transformer { source: &input::YulBreakStatement, ) -> output::YulBreakStatement { Rc::new(output::YulBreakStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1356,7 +1356,7 @@ pub trait Transformer { source: &input::YulContinueStatement, ) -> output::YulContinueStatement { Rc::new(output::YulContinueStatementStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), }) } @@ -1364,7 +1364,7 @@ pub trait Transformer { let label = Rc::clone(&source.label); Rc::new(output::YulLabelStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), label, }) } @@ -1377,7 +1377,7 @@ pub trait Transformer { let arguments = self.transform_yul_arguments(&source.arguments); Rc::new(output::YulFunctionCallExpressionStruct { - node_id: source.node_id, + node: Rc::clone(&source.node), operand, arguments, }) @@ -1443,7 +1443,7 @@ pub trait Transformer { self.transform_error_parameters(&source.parameters) } - fn transform_import_alias(&mut self, source: &input::ImportAlias) -> Rc { + fn transform_import_alias(&mut self, source: &input::ImportAlias) -> Rc { Rc::clone(&source.identifier) } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/visitor.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/visitor.generated.rs index 400421c96f..a470836c7a 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/visitor.generated.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/visitor.generated.rs @@ -4,7 +4,7 @@ use std::rc::Rc; #[allow(clippy::wildcard_imports)] use super::nodes::*; -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; pub trait Visitor { fn enter_source_unit(&mut self, _node: &SourceUnit) -> bool { @@ -2639,7 +2639,7 @@ fn accept_version_expression_set(items: &Vec, visitor: &mut i } #[inline] -fn accept_simple_version_literal(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_simple_version_literal(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_simple_version_literal(items) { visitor.leave_simple_version_literal(items); } @@ -2729,7 +2729,7 @@ fn accept_struct_members(items: &Vec, visitor: &mut impl Visitor) } #[inline] -fn accept_enum_members(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_enum_members(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_enum_members(items) { visitor.leave_enum_members(items); } @@ -2871,7 +2871,7 @@ fn accept_array_values(items: &Vec, visitor: &mut impl Visitor) { } #[inline] -fn accept_identifier_path(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_identifier_path(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_identifier_path(items) { visitor.leave_identifier_path(items); } @@ -2889,14 +2889,14 @@ fn accept_yul_statements(items: &Vec, visitor: &mut impl Visitor) } #[inline] -fn accept_yul_parameters(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_parameters(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_parameters(items) { visitor.leave_yul_parameters(items); } } #[inline] -fn accept_yul_variable_names(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_variable_names(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_variable_names(items) { visitor.leave_yul_variable_names(items); } @@ -2936,7 +2936,7 @@ fn accept_yul_paths(items: &Vec, visitor: &mut impl Visitor) { } #[inline] -fn accept_yul_path(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_yul_path(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_yul_path(items) { visitor.leave_yul_path(items); } @@ -2954,28 +2954,28 @@ fn accept_modifier_invocations(items: &Vec, visitor: &mut im } #[inline] -fn accept_strings(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_strings(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_strings(items) { visitor.leave_strings(items); } } #[inline] -fn accept_hex_strings(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_hex_strings(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_hex_strings(items) { visitor.leave_hex_strings(items); } } #[inline] -fn accept_unicode_strings(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_unicode_strings(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_unicode_strings(items) { visitor.leave_unicode_strings(items); } } #[inline] -fn accept_assembly_flags(items: &Vec>, visitor: &mut impl Visitor) { +fn accept_assembly_flags(items: &Vec>, visitor: &mut impl Visitor) { if visitor.enter_assembly_flags(items) { visitor.leave_assembly_flags(items); } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs index 3b1b1f6b21..b6db4db865 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs @@ -8,7 +8,9 @@ pub mod ir; pub mod passes; pub mod types; -pub type BinderOutput = passes::p5_resolve_references::Output; +pub use crate::backend::ir::ir2_flat_contracts as ast; + +pub type BinderOutput = passes::p6_index_tree::Output; pub fn build_binder_output(compilation_unit: CompilationUnit) -> BinderOutput { let data = passes::p0_build_ast::run(compilation_unit); @@ -16,5 +18,6 @@ pub fn build_binder_output(compilation_unit: CompilationUnit) -> BinderOutput { let data = passes::p2_collect_definitions::run(data); let data = passes::p3_linearise_contracts::run(data); let data = passes::p4_type_definitions::run(data); - passes::p5_resolve_references::run(data) + let data = passes::p5_resolve_references::run(data); + passes::p6_index_tree::run(data) } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs index b54e9e061f..df2ad51055 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs @@ -4,3 +4,4 @@ pub mod p2_collect_definitions; pub mod p3_linearise_contracts; pub mod p4_type_definitions; pub mod p5_resolve_references; +pub mod p6_index_tree; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p0_build_ast.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p0_build_ast.rs index a53b4a9598..5f118aa22c 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p0_build_ast.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p0_build_ast.rs @@ -11,7 +11,7 @@ pub struct Output { pub fn run(input: CompilationUnit) -> Output { let mut files = HashMap::new(); for file in &input.files() { - if let Some(source_unit) = builder::build_source_unit(file.tree()) { + if let Some(source_unit) = builder::build_source_unit(file.syntax_tree()) { files.insert(file.id().into(), source_unit); } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs index 0bf076a921..5dfdfd4c3c 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs @@ -7,7 +7,7 @@ use super::p0_build_ast::Output as Input; use crate::backend::ir::ir2_flat_contracts::transformer::Transformer; use crate::backend::ir::ir2_flat_contracts::{self as output, input, SourceUnit}; use crate::compilation::CompilationUnit; -use crate::cst::TerminalNode; +use crate::cst::SyntaxNode; use crate::utils::versions::VERSION_0_5_0; pub struct Output { @@ -44,7 +44,7 @@ impl Transformer for Pass { &mut self, source: &input::ContractDefinition, ) -> output::ContractDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let abstract_keyword = source.abstract_keyword; let name = Rc::clone(&source.name); let members = self.transform_contract_members(&source.members); @@ -68,7 +68,7 @@ impl Transformer for Pass { }); Rc::new(output::ContractDefinitionStruct { - node_id, + node, abstract_keyword, name, members, @@ -81,7 +81,7 @@ impl Transformer for Pass { &mut self, source: &input::FunctionDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let (name, kind) = match &source.name { input::FunctionName::Identifier(identifier) => { (Some(Rc::clone(identifier)), output::FunctionKind::Regular) @@ -106,7 +106,7 @@ impl Transformer for Pass { .map(|returns| self.transform_returns_declaration(returns)); Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -155,7 +155,7 @@ impl Transformer for Pass { } fn transform_function_type(&mut self, source: &input::FunctionType) -> output::FunctionType { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let parameters = self.transform_parameters_declaration(&source.parameters); let returns = source .returns @@ -165,7 +165,7 @@ impl Transformer for Pass { let mutability = Self::function_type_mutability(&source.attributes); Rc::new(output::FunctionTypeStruct { - node_id, + node, parameters, returns, visibility, @@ -177,7 +177,7 @@ impl Transformer for Pass { &mut self, source: &input::IndexAccessExpression, ) -> output::IndexAccessExpression { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let operand = self.transform_expression(&source.operand); let start = source .start @@ -189,7 +189,7 @@ impl Transformer for Pass { .and_then(|end| end.end.as_ref().map(|end| self.transform_expression(end))); Rc::new(output::IndexAccessExpressionStruct { - node_id, + node, operand, start, end, @@ -223,7 +223,7 @@ impl Transformer for Pass { &mut self, source: &input::StateVariableDefinition, ) -> output::StateVariableDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let type_name = self.transform_type_name(&source.type_name); let name = Rc::clone(&source.name); let value = source @@ -235,7 +235,7 @@ impl Transformer for Pass { let override_specifier = self.state_variable_override_specifier(&source.attributes); Rc::new(output::StateVariableDefinitionStruct { - node_id, + node, type_name, name, value, @@ -288,42 +288,34 @@ impl Transformer for Pass { } fn transform_path_import(&mut self, source: &input::PathImport) -> output::PathImport { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let alias = source .alias .as_ref() .map(|alias| self.transform_import_alias(alias)); let path = Self::string_literal_terminal_node(&source.path); - Rc::new(output::PathImportStruct { - node_id, - alias, - path, - }) + Rc::new(output::PathImportStruct { node, alias, path }) } fn transform_named_import(&mut self, source: &input::NamedImport) -> output::NamedImport { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let alias = self.transform_import_alias(&source.alias); let path = Self::string_literal_terminal_node(&source.path); - Rc::new(output::NamedImportStruct { - node_id, - alias, - path, - }) + Rc::new(output::NamedImportStruct { node, alias, path }) } fn transform_import_deconstruction( &mut self, source: &input::ImportDeconstruction, ) -> output::ImportDeconstruction { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let symbols = self.transform_import_deconstruction_symbols(&source.symbols); let path = Self::string_literal_terminal_node(&source.path); Rc::new(output::ImportDeconstructionStruct { - node_id, + node, symbols, path, }) @@ -333,7 +325,7 @@ impl Transformer for Pass { &mut self, source: &input::AssemblyStatement, ) -> output::AssemblyStatement { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let flags = source.flags.as_ref().map_or(Vec::new(), |flags| { flags .flags @@ -348,7 +340,7 @@ impl Transformer for Pass { .map(Self::string_literal_terminal_node); Rc::new(output::AssemblyStatementStruct { - node_id, + node, body, flags, label, @@ -515,7 +507,7 @@ impl Pass { &mut self, source: &input::ConstructorDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let kind = output::FunctionKind::Constructor; let name = None; let visibility = Self::constructor_visibility(&source.attributes); @@ -531,7 +523,7 @@ impl Pass { let returns = None; Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -606,7 +598,7 @@ impl Pass { &mut self, source: &input::UnnamedFunctionDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let kind = output::FunctionKind::Unnamed; let name = None; // TODO(validation): unnamed (aka fallback) functions *must* have external visibility @@ -620,7 +612,7 @@ impl Pass { let returns = None; Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -673,7 +665,7 @@ impl Pass { &mut self, source: &input::FallbackFunctionDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let kind = output::FunctionKind::Fallback; let name = None; // TODO(validation): fallback functions *must* have external visibility @@ -693,7 +685,7 @@ impl Pass { .map(|returns| self.transform_returns_declaration(returns)); Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -760,7 +752,7 @@ impl Pass { &mut self, source: &input::ReceiveFunctionDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let kind = output::FunctionKind::Receive; let name = None; // TODO(validation): receive functions *must* have an external visibility @@ -778,7 +770,7 @@ impl Pass { let returns = None; Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -829,7 +821,7 @@ impl Pass { &mut self, source: &input::ModifierDefinition, ) -> output::FunctionDefinition { - let node_id = source.node_id; + let node = Rc::clone(&source.node); let kind = output::FunctionKind::Modifier; let name = Some(Rc::clone(&source.name)); let visibility = output::FunctionVisibility::Internal; @@ -848,7 +840,7 @@ impl Pass { let returns = None; Rc::new(output::FunctionDefinitionStruct { - node_id, + node, parameters, returns, kind, @@ -932,7 +924,7 @@ impl Pass { }) } - fn string_literal_terminal_node(value: &input::StringLiteral) -> Rc { + fn string_literal_terminal_node(value: &input::StringLiteral) -> Rc { match value { input::StringLiteral::SingleQuotedStringLiteral(terminal_node) | input::StringLiteral::DoubleQuotedStringLiteral(terminal_node) => { @@ -941,7 +933,7 @@ impl Pass { } } - fn hex_string_literal_terminal_node(value: &input::HexStringLiteral) -> Rc { + fn hex_string_literal_terminal_node(value: &input::HexStringLiteral) -> Rc { match value { input::HexStringLiteral::SingleQuotedHexStringLiteral(terminal_node) | input::HexStringLiteral::DoubleQuotedHexStringLiteral(terminal_node) => { @@ -950,9 +942,7 @@ impl Pass { } } - fn unicode_string_literal_terminal_node( - value: &input::UnicodeStringLiteral, - ) -> Rc { + fn unicode_string_literal_terminal_node(value: &input::UnicodeStringLiteral) -> Rc { match value { input::UnicodeStringLiteral::SingleQuotedUnicodeStringLiteral(terminal_node) | input::UnicodeStringLiteral::DoubleQuotedUnicodeStringLiteral(terminal_node) => { diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p2_collect_definitions.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p2_collect_definitions.rs index 24889ae1a6..925bc0cc37 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p2_collect_definitions.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p2_collect_definitions.rs @@ -8,7 +8,7 @@ use crate::backend::binder::{Binder, Definition, FileScope, ParametersScope, Sco use crate::backend::ir::ir2_flat_contracts::visitor::Visitor; use crate::backend::ir::ir2_flat_contracts::{self as input_ir}; use crate::compilation::{CompilationUnit, File}; -use crate::cst::{NodeId, TerminalNode}; +use crate::cst::{NodeId, SyntaxNode}; use crate::utils::versions::VERSION_0_5_0; pub struct Output { @@ -150,7 +150,7 @@ impl Pass { .insert_definition_in_scope(definition, self.current_scope_id()); } - fn resolve_import_path(&self, import_path: &Rc) -> Option { + fn resolve_import_path(&self, import_path: &Rc) -> Option { let import_path_node_id = import_path.id(); let current_file = self .current_file @@ -169,9 +169,9 @@ impl Pass { fn collect_parameters(&mut self, parameters: &input_ir::Parameters) -> ScopeId { let mut scope = ParametersScope::new(); for parameter in parameters { - scope.add_parameter(parameter.name.as_ref(), parameter.node_id); + scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.node_id, name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -182,9 +182,9 @@ impl Pass { fn collect_error_parameters(&mut self, parameters: &input_ir::ErrorParameters) -> ScopeId { let mut scope = ParametersScope::new(); for parameter in parameters { - scope.add_parameter(parameter.name.as_ref(), parameter.node_id); + scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.node_id, name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -195,9 +195,9 @@ impl Pass { fn collect_event_parameters(&mut self, parameters: &input_ir::EventParameters) -> ScopeId { let mut scope = ParametersScope::new(); for parameter in parameters { - scope.add_parameter(parameter.name.as_ref(), parameter.node_id); + scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.node_id, name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -214,7 +214,7 @@ impl Pass { ) { for parameter in parameters { if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.node_id, name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_in_scope(definition, scope_id); } } @@ -238,63 +238,63 @@ impl Visitor for Pass { let Some(current_file) = &self.current_file else { unreachable!("visiting SourceUnit without a current file being set"); }; - let scope = Scope::new_file(node.node_id, current_file.id()); + let scope = Scope::new_file(node.id(), current_file.id()); self.enter_scope(scope); true } fn leave_source_unit(&mut self, node: &input_ir::SourceUnit) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_contract_definition(&mut self, node: &input_ir::ContractDefinition) -> bool { - let definition = Definition::new_contract(node.node_id, &node.name); + let definition = Definition::new_contract(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let scope = Scope::new_contract(node.node_id, self.current_scope_id()); + let scope = Scope::new_contract(node.id(), self.current_scope_id()); self.enter_scope(scope); true } fn leave_contract_definition(&mut self, node: &input_ir::ContractDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_library_definition(&mut self, node: &input_ir::LibraryDefinition) -> bool { - let definition = Definition::new_library(node.node_id, &node.name); + let definition = Definition::new_library(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let scope = Scope::new_contract(node.node_id, self.current_scope_id()); + let scope = Scope::new_contract(node.id(), self.current_scope_id()); self.enter_scope(scope); true } fn leave_library_definition(&mut self, node: &input_ir::LibraryDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) -> bool { - let definition = Definition::new_interface(node.node_id, &node.name); + let definition = Definition::new_interface(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let scope = Scope::new_contract(node.node_id, self.current_scope_id()); + let scope = Scope::new_contract(node.id(), self.current_scope_id()); self.enter_scope(scope); true } fn leave_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_path_import(&mut self, node: &input_ir::PathImport) -> bool { let imported_file_id = self.resolve_import_path(&node.path); if let Some(alias) = &node.alias { - let definition = Definition::new_import(node.node_id, alias, imported_file_id); + let definition = Definition::new_import(&node.node, alias, imported_file_id); self.insert_definition_in_current_scope(definition); } else if let Some(imported_file_id) = imported_file_id { self.current_file_scope() @@ -307,7 +307,7 @@ impl Visitor for Pass { fn enter_named_import(&mut self, node: &input_ir::NamedImport) -> bool { let imported_file_id = self.resolve_import_path(&node.path); - let definition = Definition::new_import(node.node_id, &node.alias, imported_file_id); + let definition = Definition::new_import(&node.node, &node.alias, imported_file_id); self.insert_definition_in_current_scope(definition); false @@ -323,7 +323,7 @@ impl Visitor for Pass { &symbol.name }; let definition = Definition::new_imported_symbol( - symbol.node_id, + &symbol.node, identifier, symbol.name.unparse(), imported_file_id.clone(), @@ -345,12 +345,8 @@ impl Visitor for Pass { if let Some(name) = &node.name { let visibility = (&node.visibility).into(); - let definition = Definition::new_function( - node.node_id, - name, - parameters_scope_id, - visibility, - ); + let definition = + Definition::new_function(&node.node, name, parameters_scope_id, visibility); let current_scope_node_id = self.current_scope().node_id(); let enclosing_definition = @@ -389,7 +385,7 @@ impl Visitor for Pass { } let function_scope = - Scope::new_function(node.node_id, self.current_scope_id(), parameters_scope_id); + Scope::new_function(node.id(), self.current_scope_id(), parameters_scope_id); let function_scope_id = self.enter_scope(function_scope); if let Some(returns) = &node.returns { @@ -402,10 +398,10 @@ impl Visitor for Pass { unreachable!("expected a name for the modifier"); }; - let definition = Definition::new_modifier(node.node_id, name); + let definition = Definition::new_modifier(&node.node, name); self.insert_definition_in_current_scope(definition); - let modifier_scope = Scope::new_modifier(node.node_id, self.current_scope_id()); + let modifier_scope = Scope::new_modifier(node.id(), self.current_scope_id()); let modifier_scope_id = self.enter_scope(modifier_scope); self.collect_named_parameters_into_scope(&node.parameters, modifier_scope_id); } @@ -414,17 +410,17 @@ impl Visitor for Pass { } fn leave_function_definition(&mut self, node: &input_ir::FunctionDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_enum_definition(&mut self, node: &input_ir::EnumDefinition) -> bool { - let definition = Definition::new_enum(node.node_id, &node.name); + let definition = Definition::new_enum(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let enum_scope = Scope::new_enum(node.node_id); + let enum_scope = Scope::new_enum(node.id()); let enum_scope_id = self.binder.insert_scope(enum_scope); for member in &node.members { - let definition = Definition::new_enum_member(member.id(), member); + let definition = Definition::new_enum_member(member); self.binder .insert_definition_in_scope(definition, enum_scope_id); } @@ -433,13 +429,13 @@ impl Visitor for Pass { } fn enter_struct_definition(&mut self, node: &input_ir::StructDefinition) -> bool { - let definition = Definition::new_struct(node.node_id, &node.name); + let definition = Definition::new_struct(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let struct_scope = Scope::new_struct(node.node_id); + let struct_scope = Scope::new_struct(node.id()); let struct_scope_id = self.binder.insert_scope(struct_scope); for member in &node.members { - let definition = Definition::new_struct_member(member.node_id, &member.name); + let definition = Definition::new_struct_member(&member.node, &member.name); self.binder .insert_definition_in_scope(definition, struct_scope_id); } @@ -449,7 +445,7 @@ impl Visitor for Pass { fn enter_error_definition(&mut self, node: &input_ir::ErrorDefinition) -> bool { let parameters_scope_id = self.collect_error_parameters(&node.members); - let definition = Definition::new_error(node.node_id, &node.name, parameters_scope_id); + let definition = Definition::new_error(&node.node, &node.name, parameters_scope_id); self.insert_definition_in_current_scope(definition); false @@ -457,7 +453,7 @@ impl Visitor for Pass { fn enter_event_definition(&mut self, node: &input_ir::EventDefinition) -> bool { let parameters_scope_id = self.collect_event_parameters(&node.parameters); - let definition = Definition::new_event(node.node_id, &node.name, parameters_scope_id); + let definition = Definition::new_event(&node.node, &node.name, parameters_scope_id); self.insert_definition_in_current_scope(definition); false @@ -472,10 +468,10 @@ impl Visitor for Pass { // Public state variables define a getter, so we don't register them as // constants here let definition = if is_constant && !is_public { - Definition::new_constant(node.node_id, &node.name) + Definition::new_constant(&node.node, &node.name) } else { let visibility = (&node.visibility).into(); - Definition::new_state_variable(node.node_id, &node.name, visibility) + Definition::new_state_variable(&node.node, &node.name, visibility) }; self.insert_definition_in_current_scope(definition); @@ -485,7 +481,7 @@ impl Visitor for Pass { } fn enter_constant_definition(&mut self, node: &input_ir::ConstantDefinition) -> bool { - let definition = Definition::new_constant(node.node_id, &node.name); + let definition = Definition::new_constant(&node.node, &node.name); self.insert_definition_in_current_scope(definition); false @@ -495,7 +491,7 @@ impl Visitor for Pass { &mut self, node: &input_ir::UserDefinedValueTypeDefinition, ) -> bool { - let definition = Definition::new_user_defined_value_type(node.node_id, &node.name); + let definition = Definition::new_user_defined_value_type(&node.node, &node.name); self.insert_definition_in_current_scope(definition); false @@ -509,11 +505,11 @@ impl Visitor for Pass { // In Solidity >= 0.5.0 this definition should only be available for // statements after this one. So we open a new scope that replaces // but is linked to the current one - let scope = Scope::new_block(node.node_id, self.current_scope_id()); + let scope = Scope::new_block(node.id(), self.current_scope_id()); self.replace_scope(scope); } - let definition = Definition::new_variable(node.node_id, &node.name); + let definition = Definition::new_variable(&node.node, &node.name); self.insert_definition_in_current_scope(definition); } @@ -525,7 +521,7 @@ impl Visitor for Pass { // In Solidity >= 0.5.0 the definitions should only be available for // statements after this one. So we open a new scope that replaces // but is linked to the current one - let scope = Scope::new_block(node.node_id, self.current_scope_id()); + let scope = Scope::new_block(node.id(), self.current_scope_id()); self.replace_scope(scope); } @@ -536,16 +532,13 @@ impl Visitor for Pass { }; let definition = match tuple_member { input_ir::TupleMember::TypedTupleMember(typed_tuple_member) => { - Definition::new_variable(typed_tuple_member.node_id, &typed_tuple_member.name) + Definition::new_variable(&typed_tuple_member.node, &typed_tuple_member.name) } input_ir::TupleMember::UntypedTupleMember(untyped_tuple_member) => { if !is_untyped_declaration { continue; } - Definition::new_variable( - untyped_tuple_member.node_id, - &untyped_tuple_member.name, - ) + Definition::new_variable(&untyped_tuple_member.node, &untyped_tuple_member.name) } }; self.insert_definition_in_current_scope(definition); @@ -554,7 +547,7 @@ impl Visitor for Pass { fn enter_block(&mut self, node: &input_ir::Block) -> bool { if self.language_version >= VERSION_0_5_0 { - let scope = Scope::new_block(node.node_id, self.current_scope_id()); + let scope = Scope::new_block(node.id(), self.current_scope_id()); self.enter_scope(scope); } true @@ -562,7 +555,7 @@ impl Visitor for Pass { fn leave_block(&mut self, node: &input_ir::Block) { if self.language_version >= VERSION_0_5_0 { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } } @@ -570,7 +563,7 @@ impl Visitor for Pass { if self.language_version >= VERSION_0_5_0 { // For Solidity >= 0.5.0 open a new block here to hold declarations // in the initialization clause. - let scope = Scope::new_block(node.node_id, self.current_scope_id()); + let scope = Scope::new_block(node.id(), self.current_scope_id()); self.enter_scope(scope); } true @@ -578,7 +571,7 @@ impl Visitor for Pass { fn leave_for_statement(&mut self, node: &input_ir::ForStatement) { if self.language_version >= VERSION_0_5_0 { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } } @@ -590,7 +583,7 @@ impl Visitor for Pass { // For Solidity >= 0.5.0, collect the parameters in the returns // declaration of the try statement and make them available in the // body block. - let body_scope_id = self.binder.scope_id_for_node_id(node.body.node_id).unwrap(); + let body_scope_id = self.binder.scope_id_for_node_id(node.body.id()).unwrap(); self.collect_named_parameters_into_scope(returns, body_scope_id); } } @@ -599,18 +592,18 @@ impl Visitor for Pass { if let Some(error) = &node.error { // For Solidity >= 0.5.0, collect the parameters in the catch // declaration and make them available in the body block. - let body_scope_id = self.binder.scope_id_for_node_id(node.body.node_id).unwrap(); + let body_scope_id = self.binder.scope_id_for_node_id(node.body.id()).unwrap(); self.collect_named_parameters_into_scope(&error.parameters, body_scope_id); } } fn enter_mapping_type(&mut self, node: &input_ir::MappingType) -> bool { if let Some(name) = &node.key_type.name { - let definition = Definition::new_type_parameter(node.key_type.node_id, name); + let definition = Definition::new_type_parameter(&node.key_type.node, name); self.binder.insert_definition_no_scope(definition); } if let Some(name) = &node.value_type.name { - let definition = Definition::new_type_parameter(node.value_type.node_id, name); + let definition = Definition::new_type_parameter(&node.value_type.node, name); self.binder.insert_definition_no_scope(definition); } @@ -620,14 +613,14 @@ impl Visitor for Pass { fn enter_function_type(&mut self, node: &input_ir::FunctionType) -> bool { for parameter in &node.parameters { if let Some(name) = ¶meter.name { - let definition = Definition::new_type_parameter(parameter.node_id, name); + let definition = Definition::new_type_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } if let Some(returns) = &node.returns { for parameter in returns { if let Some(name) = ¶meter.name { - let definition = Definition::new_type_parameter(parameter.node_id, name); + let definition = Definition::new_type_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -637,30 +630,30 @@ impl Visitor for Pass { } fn enter_yul_block(&mut self, node: &input_ir::YulBlock) -> bool { - let scope = Scope::new_yul_block(node.node_id, self.current_scope_id()); + let scope = Scope::new_yul_block(node.id(), self.current_scope_id()); self.enter_scope(scope); true } fn leave_yul_block(&mut self, node: &input_ir::YulBlock) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_yul_function_definition(&mut self, node: &input_ir::YulFunctionDefinition) -> bool { - let definition = Definition::new_yul_function(node.node_id, &node.name); + let definition = Definition::new_yul_function(&node.node, &node.name); self.insert_definition_in_current_scope(definition); - let scope = Scope::new_yul_function(node.node_id, self.current_scope_id()); + let scope = Scope::new_yul_function(node.id(), self.current_scope_id()); let scope_id = self.enter_scope(scope); for parameter in &node.parameters { - let definition = Definition::new_yul_parameter(parameter.id(), parameter); + let definition = Definition::new_yul_parameter(parameter); self.binder.insert_definition_in_scope(definition, scope_id); } if let Some(returns) = &node.returns { for parameter in returns { - let definition = Definition::new_yul_variable(parameter.id(), parameter); + let definition = Definition::new_yul_variable(parameter); self.binder.insert_definition_in_scope(definition, scope_id); } } @@ -669,11 +662,11 @@ impl Visitor for Pass { } fn leave_yul_function_definition(&mut self, node: &input_ir::YulFunctionDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_yul_label(&mut self, node: &input_ir::YulLabel) -> bool { - let definition = Definition::new_yul_label(node.node_id, &node.label); + let definition = Definition::new_yul_label(&node.node, &node.label); self.insert_definition_in_current_scope(definition); false @@ -684,7 +677,7 @@ impl Visitor for Pass { node: &input_ir::YulVariableDeclarationStatement, ) -> bool { for variable in &node.variables { - let definition = Definition::new_yul_variable(variable.id(), variable); + let definition = Definition::new_yul_variable(variable); self.insert_definition_in_current_scope(definition); } // TODO: we maybe want to enter a new scope here, but that should be @@ -702,11 +695,11 @@ impl Visitor for Pass { // Visit the rest of the children, but in the scope of the // initialization block such that iterator and body blocks link to it - self.enter_scope_for_node_id(node.initialization.node_id); + self.enter_scope_for_node_id(node.initialization.id()); input_ir::visitor::accept_yul_expression(&node.condition, self); input_ir::visitor::accept_yul_block(&node.iterator, self); input_ir::visitor::accept_yul_block(&node.body, self); - self.leave_scope_for_node_id(node.initialization.node_id); + self.leave_scope_for_node_id(node.initialization.id()); // We already visited our children false diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p3_linearise_contracts/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p3_linearise_contracts/mod.rs index 926392cad5..6e42aac6ea 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p3_linearise_contracts/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p3_linearise_contracts/mod.rs @@ -55,7 +55,7 @@ impl Pass { fn visit_file_collect_bases(&mut self, source_unit: &input_ir::SourceUnit) { let scope_id = self .binder - .scope_id_for_node_id(source_unit.node_id) + .scope_id_for_node_id(source_unit.id()) .expect("source unit should have a defined scope"); for member in &source_unit.members { match member { @@ -77,8 +77,8 @@ impl Pass { ) { let resolved_bases = self.resolve_inheritance_types(&node.inheritance_types, scope_id); - let Definition::Contract(definition) = self.binder.get_definition_mut(node.node_id) else { - unreachable!("{node_id:?} should be a contract", node_id = node.node_id); + let Definition::Contract(definition) = self.binder.get_definition_mut(node.id()) else { + unreachable!("{node_id:?} should be a contract", node_id = node.id()); }; definition.bases = Some(resolved_bases); } @@ -93,8 +93,8 @@ impl Pass { resolved_bases = self.resolve_inheritance_types(inheritance_types, scope_id); } - let Definition::Interface(definition) = self.binder.get_definition_mut(node.node_id) else { - unreachable!("{node_id:?} should be an interface", node_id = node.node_id); + let Definition::Interface(definition) = self.binder.get_definition_mut(node.id()) else { + unreachable!("{node_id:?} should be an interface", node_id = node.id()); }; definition.bases = Some(resolved_bases); } @@ -157,11 +157,11 @@ impl Pass { }) => resolved_file_id.as_ref().and_then(|resolved_file_id| { self.binder.scope_id_for_file_id(resolved_file_id) }), - Definition::Contract(ContractDefinition { node_id, .. }) - | Definition::Interface(InterfaceDefinition { node_id, .. }) - | Definition::Library(LibraryDefinition { node_id, .. }) => { + Definition::Contract(ContractDefinition { node, .. }) + | Definition::Interface(InterfaceDefinition { node, .. }) + | Definition::Library(LibraryDefinition { node, .. }) => { use_lexical_resolution = false; - self.binder.scope_id_for_node_id(*node_id) + self.binder.scope_id_for_node_id(node.id()) } _ => None, }); @@ -175,10 +175,10 @@ impl Pass { for member in &source_unit.members { let node_id = match member { input_ir::SourceUnitMember::ContractDefinition(contract_definition) => { - contract_definition.node_id + contract_definition.id() } input_ir::SourceUnitMember::InterfaceDefinition(interface_definition) => { - interface_definition.node_id + interface_definition.id() } _ => continue, }; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/mod.rs index a7221bb52a..4c61789301 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/mod.rs @@ -90,7 +90,7 @@ impl Pass { continue; }; let receiver_type_id = self.types.register_type(Type::Contract { - definition_id: contract_definition.node_id, + definition_id: contract_definition.id(), }); for contract_member in &contract_definition.members { let input_ir::ContractMember::StateVariableDefinition(state_var_definition) = @@ -105,7 +105,7 @@ impl Pass { continue; } - let node_id = state_var_definition.node_id; + let node_id = state_var_definition.id(); let Some(type_id) = self.binder.node_typing(node_id).as_type_id() else { continue; }; diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/resolution.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/resolution.rs index 8b81381373..7afcd5cd6b 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/resolution.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/resolution.rs @@ -50,11 +50,11 @@ impl Pass { }) => resolved_file_id.as_ref().and_then(|resolved_file_id| { self.binder.scope_id_for_file_id(resolved_file_id) }), - Definition::Contract(ContractDefinition { node_id, .. }) - | Definition::Interface(InterfaceDefinition { node_id, .. }) - | Definition::Library(LibraryDefinition { node_id, .. }) => { + Definition::Contract(ContractDefinition { node, .. }) + | Definition::Interface(InterfaceDefinition { node, .. }) + | Definition::Library(LibraryDefinition { node, .. }) => { use_lexical_resolution = false; - self.binder.scope_id_for_node_id(*node_id) + self.binder.scope_id_for_node_id(node.id()) } _ => None, }); @@ -70,7 +70,7 @@ impl Pass { ) -> Option> { let mut parameter_types = Vec::new(); for parameter in parameters { - let parameter_type_id = self.binder.node_typing(parameter.node_id).as_type_id()?; + let parameter_type_id = self.binder.node_typing(parameter.id()).as_type_id()?; parameter_types.push(parameter_type_id); } Some(parameter_types) diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/typing.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/typing.rs index ebc764834a..b1dba87215 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/typing.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/typing.rs @@ -142,7 +142,7 @@ impl Pass { input_ir::FunctionVisibility::External | input_ir::FunctionVisibility::Public ); Some(self.types.register_type(Type::Function(FunctionType { - definition_id: Some(function_definition.node_id), + definition_id: Some(function_definition.id()), implicit_receiver_type, parameter_types, return_type, @@ -258,7 +258,7 @@ impl Pass { .map(Into::into) .or(default_location), ); - self.binder.set_node_type(parameter.node_id, type_id); + self.binder.set_node_type(parameter.id(), type_id); } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/visitor.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/visitor.rs index cfefd42c89..9dfbe85915 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/visitor.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p4_type_definitions/visitor.rs @@ -12,23 +12,23 @@ use crate::utils::versions::VERSION_0_5_0; impl Visitor for Pass { fn enter_source_unit(&mut self, node: &input_ir::SourceUnit) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_source_unit(&mut self, node: &input_ir::SourceUnit) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_contract_definition(&mut self, node: &input_ir::ContractDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); let type_id = self.types.register_type(Type::Contract { - definition_id: node.node_id, + definition_id: node.id(), }); self.current_receiver_type = Some(type_id); - if let Some(bases) = self.binder.get_linearised_bases(node.node_id) { + if let Some(bases) = self.binder.get_linearised_bases(node.id()) { if !bases.is_empty() { self.register_super_types(type_id, &bases.clone()); } @@ -38,21 +38,21 @@ impl Visitor for Pass { } fn leave_contract_definition(&mut self, node: &input_ir::ContractDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); self.current_receiver_type = None; - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn enter_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); let type_id = self.types.register_type(Type::Interface { - definition_id: node.node_id, + definition_id: node.id(), }); self.current_receiver_type = Some(type_id); - if let Some(bases) = self.binder.get_linearised_bases(node.node_id) { + if let Some(bases) = self.binder.get_linearised_bases(node.id()) { if !bases.is_empty() { self.register_super_types(type_id, &bases.clone()); } @@ -62,31 +62,31 @@ impl Visitor for Pass { } fn leave_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); self.current_receiver_type = None; - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn enter_library_definition(&mut self, node: &input_ir::LibraryDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_library_definition(&mut self, node: &input_ir::LibraryDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn leave_path_import(&mut self, node: &input_ir::PathImport) { if node.alias.is_some() { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } } fn leave_named_import(&mut self, node: &input_ir::NamedImport) { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn enter_import_deconstruction(&mut self, node: &input_ir::ImportDeconstruction) -> bool { @@ -129,7 +129,7 @@ impl Visitor for Pass { // now we can compute the function type let type_id = self.type_of_function_definition(node, self.current_receiver_type); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); if !matches!(node.kind, input_ir::FunctionKind::Modifier) && node.name.is_some() { // for non-modifier *named* functions, fill-in parameter types in @@ -137,12 +137,11 @@ impl Visitor for Pass { let parameter_types: Vec<_> = node .parameters .iter() - .map(|parameter| self.binder.node_typing(parameter.node_id).as_type_id()) + .map(|parameter| self.binder.node_typing(parameter.id()).as_type_id()) .collect(); - let Some(parameters_scope_id) = self - .binder - .get_parameters_scope_for_definition(node.node_id) + let Some(parameters_scope_id) = + self.binder.get_parameters_scope_for_definition(node.id()) else { unreachable!("FunctionDefinition does not have associated parameters scope"); }; @@ -198,17 +197,15 @@ impl Visitor for Pass { } fn leave_event_definition(&mut self, node: &input_ir::EventDefinition) { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); let parameter_types: Vec<_> = node .parameters .iter() - .map(|parameter| self.binder.node_typing(parameter.node_id).as_type_id()) + .map(|parameter| self.binder.node_typing(parameter.id()).as_type_id()) .collect(); - let Some(parameters_scope_id) = self - .binder - .get_parameters_scope_for_definition(node.node_id) + let Some(parameters_scope_id) = self.binder.get_parameters_scope_for_definition(node.id()) else { unreachable!("EventDefinition does not have associated parameters scope"); }; @@ -225,11 +222,11 @@ impl Visitor for Pass { // and structs are allowed as event parameters and they won't type if we // pass None here let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Memory)); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_error_definition(&mut self, node: &input_ir::ErrorDefinition) { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn leave_error_parameter(&mut self, node: &input_ir::ErrorParameter) { @@ -237,19 +234,19 @@ impl Visitor for Pass { // and structs are allowed as error parameters and they won't type if we // pass None here let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Memory)); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_state_variable_definition(&mut self, node: &input_ir::StateVariableDefinition) { let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Storage)); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); // if required, we will compute the type of the getter after all // definitions have been typed } fn leave_constant_definition(&mut self, node: &input_ir::ConstantDefinition) { let type_id = self.resolve_type_name(&node.type_name, None); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_variable_declaration_statement( @@ -274,7 +271,7 @@ impl Visitor for Pass { // resolve the type at this point (will fixup in p5) None }; - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_typed_tuple_member(&mut self, node: &input_ir::TypedTupleMember) { @@ -289,7 +286,7 @@ impl Visitor for Pass { } }), ); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_tuple_deconstruction_statement( @@ -308,40 +305,39 @@ impl Visitor for Pass { // the variable types cannot be typed at this point, but we // should be able to infer it after typing the initialization // value - self.binder - .set_node_type(untyped_tuple_member.node_id, None); + self.binder.set_node_type(untyped_tuple_member.id(), None); } } } fn leave_struct_definition(&mut self, node: &input_ir::StructDefinition) { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn leave_struct_member(&mut self, node: &input_ir::StructMember) { let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Inherited)); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_enum_definition(&mut self, node: &input_ir::EnumDefinition) { let type_id = self.types.register_type(Type::Enum { - definition_id: node.node_id, + definition_id: node.id(), }); for member in &node.members { self.binder.set_node_type(member.id(), Some(type_id)); } - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); } fn leave_user_defined_value_type_definition( &mut self, node: &input_ir::UserDefinedValueTypeDefinition, ) { - self.binder.mark_user_meta_type_node(node.node_id); + self.binder.mark_user_meta_type_node(node.id()); let target_type_id = self.type_of_elementary_type(&node.value_type, None); - let Definition::UserDefinedValueType(udvt) = self.binder.get_definition_mut(node.node_id) + let Definition::UserDefinedValueType(udvt) = self.binder.get_definition_mut(node.id()) else { unreachable!("definition in UDVT node is not a UDVT"); }; @@ -427,7 +423,7 @@ impl Visitor for Pass { } } - let scope = Scope::new_using(node.node_id, symbols); + let scope = Scope::new_using(node.id(), symbols); let scope_id = self.binder.insert_scope(scope); if operators.is_empty() { @@ -475,7 +471,7 @@ impl Visitor for Pass { fn leave_revert_statement(&mut self, node: &input_ir::RevertStatement) { if let Some(identifier_path) = &node.error { let type_id = self.type_of_identifier_path(identifier_path, None); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } } @@ -486,7 +482,7 @@ impl Visitor for Pass { fn leave_emit_statement(&mut self, node: &input_ir::EmitStatement) { let type_id = self.type_of_identifier_path(&node.event, None); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn enter_catch_clause_error(&mut self, node: &input_ir::CatchClauseError) -> bool { @@ -504,7 +500,7 @@ impl Visitor for Pass { fn leave_new_expression(&mut self, node: &input_ir::NewExpression) { let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Memory)); let typing = type_id.map_or(Typing::Unresolved, Typing::NewExpression); - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn leave_type_expression(&mut self, node: &input_ir::TypeExpression) { @@ -512,6 +508,6 @@ impl Visitor for Pass { let typing = type_id.map_or(Typing::Unresolved, |type_id| { Typing::BuiltIn(BuiltIn::Type(type_id)) }); - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/typing.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/typing.rs index 91c0001505..b150406eb1 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/typing.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/typing.rs @@ -5,17 +5,17 @@ use crate::backend::binder::{Definition, Resolution, Typing}; use crate::backend::built_ins::BuiltIn; use crate::backend::ir::ir2_flat_contracts::{self as input_ir}; use crate::backend::types::{DataLocation, FunctionType, LiteralKind, Type, TypeId}; -use crate::cst::{NodeId, TerminalNode}; +use crate::cst::{NodeId, SyntaxNode}; use crate::utils::versions::{VERSION_0_5_0, VERSION_0_8_0}; impl Pass { pub(super) fn typing_of_expression(&self, node: &input_ir::Expression) -> Typing { match node { input_ir::Expression::AssignmentExpression(assignment_expression) => { - self.binder.node_typing(assignment_expression.node_id) + self.binder.node_typing(assignment_expression.id()) } input_ir::Expression::ConditionalExpression(conditional_expression) => { - self.binder.node_typing(conditional_expression.node_id) + self.binder.node_typing(conditional_expression.id()) } input_ir::Expression::OrExpression(_) | input_ir::Expression::AndExpression(_) @@ -24,61 +24,61 @@ impl Pass { | input_ir::Expression::TrueKeyword | input_ir::Expression::FalseKeyword => Typing::Resolved(self.types.boolean()), input_ir::Expression::BitwiseOrExpression(bitwise_or_expression) => { - self.binder.node_typing(bitwise_or_expression.node_id) + self.binder.node_typing(bitwise_or_expression.id()) } input_ir::Expression::BitwiseXorExpression(bitwise_xor_expression) => { - self.binder.node_typing(bitwise_xor_expression.node_id) + self.binder.node_typing(bitwise_xor_expression.id()) } input_ir::Expression::BitwiseAndExpression(bitwise_and_expression) => { - self.binder.node_typing(bitwise_and_expression.node_id) + self.binder.node_typing(bitwise_and_expression.id()) } input_ir::Expression::ShiftExpression(shift_expression) => { - self.binder.node_typing(shift_expression.node_id) + self.binder.node_typing(shift_expression.id()) } input_ir::Expression::AdditiveExpression(additive_expression) => { - self.binder.node_typing(additive_expression.node_id) + self.binder.node_typing(additive_expression.id()) } input_ir::Expression::MultiplicativeExpression(multiplicative_expression) => { - self.binder.node_typing(multiplicative_expression.node_id) + self.binder.node_typing(multiplicative_expression.id()) } input_ir::Expression::ExponentiationExpression(exponentiation_expression) => { - self.binder.node_typing(exponentiation_expression.node_id) + self.binder.node_typing(exponentiation_expression.id()) } input_ir::Expression::PostfixExpression(postfix_expression) => { - self.binder.node_typing(postfix_expression.node_id) + self.binder.node_typing(postfix_expression.id()) } input_ir::Expression::PrefixExpression(prefix_expression) => { - self.binder.node_typing(prefix_expression.node_id) + self.binder.node_typing(prefix_expression.id()) } input_ir::Expression::FunctionCallExpression(function_call_expression) => { - self.binder.node_typing(function_call_expression.node_id) + self.binder.node_typing(function_call_expression.id()) } input_ir::Expression::CallOptionsExpression(call_options_expression) => { - self.binder.node_typing(call_options_expression.node_id) + self.binder.node_typing(call_options_expression.id()) } input_ir::Expression::MemberAccessExpression(member_access_expression) => { - self.binder.node_typing(member_access_expression.node_id) + self.binder.node_typing(member_access_expression.id()) } input_ir::Expression::IndexAccessExpression(index_access_expression) => { - self.binder.node_typing(index_access_expression.node_id) + self.binder.node_typing(index_access_expression.id()) } input_ir::Expression::NewExpression(new_expression) => { - self.binder.node_typing(new_expression.node_id) + self.binder.node_typing(new_expression.id()) } input_ir::Expression::TupleExpression(tuple_expression) => { - self.binder.node_typing(tuple_expression.node_id) + self.binder.node_typing(tuple_expression.id()) } input_ir::Expression::TypeExpression(type_expression) => { - self.binder.node_typing(type_expression.node_id) + self.binder.node_typing(type_expression.id()) } input_ir::Expression::ArrayExpression(array_expression) => { - self.binder.node_typing(array_expression.node_id) + self.binder.node_typing(array_expression.id()) } input_ir::Expression::HexNumberExpression(hex_number_expression) => { - self.binder.node_typing(hex_number_expression.node_id) + self.binder.node_typing(hex_number_expression.id()) } input_ir::Expression::DecimalNumberExpression(decimal_number_expression) => { - self.binder.node_typing(decimal_number_expression.node_id) + self.binder.node_typing(decimal_number_expression.id()) } input_ir::Expression::StringExpression(string_expression) => self .binder @@ -138,7 +138,7 @@ impl Pass { } } - fn typing_of_identifier(&self, identifier: &Rc) -> Typing { + fn typing_of_identifier(&self, identifier: &Rc) -> Typing { let resolution = self .binder .find_reference_by_identifier_node_id(identifier.id()) diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/visitor.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/visitor.rs index a04b9b6300..ca8beb055a 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/visitor.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/visitor.rs @@ -5,26 +5,26 @@ use crate::backend::binder::{Reference, Resolution, Typing}; use crate::backend::ir::ir2_flat_contracts::visitor::Visitor; use crate::backend::ir::ir2_flat_contracts::{self as input_ir}; use crate::backend::types::{DataLocation, LiteralKind, Type}; -use crate::cst::TerminalKind; +use crate::cst::{NodeKind, TerminalKind}; use crate::utils::versions::{VERSION_0_5_0, VERSION_0_7_0}; impl Visitor for Pass { fn enter_source_unit(&mut self, node: &input_ir::SourceUnit) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_source_unit(&mut self, node: &input_ir::SourceUnit) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_contract_definition(&mut self, node: &input_ir::ContractDefinition) -> bool { // Push the contract scope to visit the contract members - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); for member in &node.members { input_ir::visitor::accept_contract_member(member, self); } - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); // But any reference in the inheritance types and the storage layout // specifier should resolve in the parent scope @@ -41,21 +41,21 @@ impl Visitor for Pass { } fn enter_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_library_definition(&mut self, node: &input_ir::LibraryDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_library_definition(&mut self, node: &input_ir::LibraryDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_function_definition(&mut self, node: &input_ir::FunctionDefinition) -> bool { @@ -66,56 +66,56 @@ impl Visitor for Pass { self.resolve_modifier_invocation(modifier_invocation); } - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_function_definition(&mut self, node: &input_ir::FunctionDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_block(&mut self, node: &input_ir::Block) -> bool { if self.language_version >= VERSION_0_5_0 { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); } true } fn leave_block(&mut self, node: &input_ir::Block) { if self.language_version >= VERSION_0_5_0 { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } } fn enter_for_statement(&mut self, node: &input_ir::ForStatement) -> bool { if self.language_version >= VERSION_0_5_0 { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); } true } fn leave_for_statement(&mut self, node: &input_ir::ForStatement) { if self.language_version >= VERSION_0_5_0 { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } } fn enter_yul_block(&mut self, node: &input_ir::YulBlock) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_yul_block(&mut self, node: &input_ir::YulBlock) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_yul_function_definition(&mut self, node: &input_ir::YulFunctionDefinition) -> bool { - self.enter_scope_for_node_id(node.node_id); + self.enter_scope_for_node_id(node.id()); true } fn leave_yul_function_definition(&mut self, node: &input_ir::YulFunctionDefinition) { - self.leave_scope_for_node_id(node.node_id); + self.leave_scope_for_node_id(node.id()); } fn enter_expression(&mut self, node: &input_ir::Expression) -> bool { @@ -133,7 +133,7 @@ impl Visitor for Pass { fn leave_hex_number_expression(&mut self, node: &input_ir::HexNumberExpression) { let kind = Self::hex_number_literal_kind(node); let type_id = self.types.register_type(Type::Literal(kind)); - self.binder.set_node_type(node.node_id, Some(type_id)); + self.binder.set_node_type(node.id(), Some(type_id)); } fn leave_decimal_number_expression(&mut self, node: &input_ir::DecimalNumberExpression) { @@ -143,7 +143,7 @@ impl Visitor for Pass { Type::Literal(LiteralKind::DecimalInteger) }; let type_id = self.types.register_type(type_); - self.binder.set_node_type(node.node_id, Some(type_id)); + self.binder.set_node_type(node.id(), Some(type_id)); } fn leave_string_expression(&mut self, node: &input_ir::StringExpression) { @@ -158,7 +158,7 @@ impl Visitor for Pass { let type_id = self.typing_of_expression(&node.left_operand).as_type_id(); // TODO(validation): check that the type of right_operand can be applied // to the left by means of the operator - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_conditional_expression(&mut self, node: &input_ir::ConditionalExpression) { @@ -189,7 +189,7 @@ impl Visitor for Pass { } _ => None, }; - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_or_expression(&mut self, _node: &input_ir::OrExpression) { @@ -211,38 +211,38 @@ impl Visitor for Pass { fn leave_bitwise_or_expression(&mut self, node: &input_ir::BitwiseOrExpression) { let type_id = self.type_of_integer_binary_expression(&node.left_operand, &node.right_operand); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_bitwise_xor_expression(&mut self, node: &input_ir::BitwiseXorExpression) { let type_id = self.type_of_integer_binary_expression(&node.left_operand, &node.right_operand); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_bitwise_and_expression(&mut self, node: &input_ir::BitwiseAndExpression) { let type_id = self.type_of_integer_binary_expression(&node.left_operand, &node.right_operand); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_shift_expression(&mut self, node: &input_ir::ShiftExpression) { let type_id = self.typing_of_expression(&node.left_operand).as_type_id(); // TODO(validation): check that the left operand is an integer and the // right operand is an _unsigned_ integer - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_additive_expression(&mut self, node: &input_ir::AdditiveExpression) { let type_id = self.type_of_integer_binary_expression(&node.left_operand, &node.right_operand); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_multiplicative_expression(&mut self, node: &input_ir::MultiplicativeExpression) { let type_id = self.type_of_integer_binary_expression(&node.left_operand, &node.right_operand); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_exponentiation_expression(&mut self, node: &input_ir::ExponentiationExpression) { @@ -261,33 +261,35 @@ impl Visitor for Pass { type_id = Some(self.types.uint256()); } } - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_postfix_expression(&mut self, node: &input_ir::PostfixExpression) { // TODO(validation): check that the operand is an integer let type_id = self.typing_of_expression(&node.operand).as_type_id(); - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_prefix_expression(&mut self, node: &input_ir::PrefixExpression) { - let type_id = match node.operator.kind { - TerminalKind::PlusPlus - | TerminalKind::Plus - | TerminalKind::MinusMinus - | TerminalKind::Minus - | TerminalKind::Tilde => { + let type_id = match node.operator.kind() { + NodeKind::Terminal( + TerminalKind::PlusPlus + | TerminalKind::Plus + | TerminalKind::MinusMinus + | TerminalKind::Minus + | TerminalKind::Tilde, + ) => { // TODO(validation): check that the operand is integer self.typing_of_expression(&node.operand).as_type_id() } - TerminalKind::Bang => { + NodeKind::Terminal(TerminalKind::Bang) => { // TODO(validation): check that the operand is boolean Some(self.types.boolean()) } - TerminalKind::DeleteKeyword => Some(self.types.void()), + NodeKind::Terminal(TerminalKind::DeleteKeyword) => Some(self.types.void()), _ => None, }; - self.binder.set_node_type(node.node_id, type_id); + self.binder.set_node_type(node.id(), type_id); } fn leave_tuple_expression(&mut self, node: &input_ir::TupleExpression) { @@ -313,7 +315,7 @@ impl Visitor for Pass { let type_id = self.types.register_type(Type::Tuple { types }); Typing::Resolved(type_id) }; - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn leave_member_access_expression(&mut self, node: &input_ir::MemberAccessExpression) { @@ -350,7 +352,7 @@ impl Visitor for Pass { } // store the typing - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); let reference = Reference::new(Rc::clone(&node.member), resolution); self.binder.insert_reference(reference); @@ -418,7 +420,7 @@ impl Visitor for Pass { } _ => Typing::Unresolved, }; - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn leave_array_expression(&mut self, node: &input_ir::ArrayExpression) { @@ -441,7 +443,7 @@ impl Visitor for Pass { Typing::Unresolved } }; - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn leave_function_call_expression(&mut self, node: &input_ir::FunctionCallExpression) { @@ -453,7 +455,7 @@ impl Visitor for Pass { self.typing_of_function_call_with_named_arguments(node, named_arguments) } }; - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn enter_call_options_expression(&mut self, node: &input_ir::CallOptionsExpression) -> bool { @@ -471,7 +473,7 @@ impl Visitor for Pass { fn leave_call_options_expression(&mut self, node: &input_ir::CallOptionsExpression) { let typing = self.typing_of_expression(&node.operand); - self.binder.set_node_typing(node.node_id, typing); + self.binder.set_node_typing(node.id(), typing); } fn enter_yul_path(&mut self, items: &input_ir::YulPath) -> bool { @@ -550,11 +552,11 @@ impl Visitor for Pass { // initialization block. This is mainly so references in the condition // can resolve against the initialization block. The iterator and body // should be already properly linked from construction. - self.enter_scope_for_node_id(node.initialization.node_id); + self.enter_scope_for_node_id(node.initialization.id()); input_ir::visitor::accept_yul_expression(&node.condition, self); input_ir::visitor::accept_yul_block(&node.iterator, self); input_ir::visitor::accept_yul_block(&node.body, self); - self.leave_scope_for_node_id(node.initialization.node_id); + self.leave_scope_for_node_id(node.initialization.id()); // We already visited our children false @@ -662,7 +664,7 @@ impl Visitor for Pass { if self.language_version >= VERSION_0_5_0 { // in Solidity >= 0.5.0 we need to update the scope so further // resolutions can access this variable definition - self.replace_scope_for_node_id(node.node_id); + self.replace_scope_for_node_id(node.id()); // NOTE: ensure following code does not need to perform resolution } @@ -678,7 +680,7 @@ impl Visitor for Pass { .map_or(Typing::Unresolved, |type_id| { Typing::Resolved(self.types.reified_type(type_id)) }); - self.binder.fixup_node_typing(node.node_id, typing); + self.binder.fixup_node_typing(node.id(), typing); } } } @@ -690,7 +692,7 @@ impl Visitor for Pass { if self.language_version >= VERSION_0_5_0 { // in Solidity >= 0.5.0 we need to update the scope so further // resolutions can access these variable definitions - self.replace_scope_for_node_id(node.node_id); + self.replace_scope_for_node_id(node.id()); // NOTE: ensure following code does not need to perform resolution } @@ -718,7 +720,7 @@ impl Visitor for Pass { if let input_ir::TupleMember::UntypedTupleMember(untyped_tuple_member) = member { let typing = Typing::Resolved(self.types.reified_type(element_type_id)); self.binder - .fixup_node_typing(untyped_tuple_member.node_id, typing); + .fixup_node_typing(untyped_tuple_member.id(), typing); } } } diff --git a/crates/solidity/outputs/cargo/crate/src/backend/passes/p6_index_tree.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p6_index_tree.rs new file mode 100644 index 0000000000..53da80ce54 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/p6_index_tree.rs @@ -0,0 +1,37 @@ +use std::collections::HashMap; + +use super::p5_resolve_references::Output as Input; +use crate::backend::binder::Binder; +use crate::backend::ir::ir2_flat_contracts as input_ir; +use crate::backend::ir::ir2_flat_contracts::index::{self, TreeIndex}; +use crate::backend::types::TypeRegistry; +use crate::backend::CompilationUnit; + +pub struct Output { + pub compilation_unit: CompilationUnit, + pub files: HashMap, + pub binder: Binder, + pub types: TypeRegistry, + pub index: TreeIndex, +} + +#[inline(never)] +pub fn run(input: Input) -> Output { + let files = input.files; + let compilation_unit = input.compilation_unit; + let binder = input.binder; + let types = input.types; + + let mut index = TreeIndex::new(); + for source_unit in files.values() { + index::register_source_unit(source_unit, &mut index); + } + + Output { + compilation_unit, + files, + binder, + types, + index, + } +} diff --git a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs index f49e6e118a..366b61cce2 100644 --- a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs +++ b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs @@ -4,6 +4,8 @@ use std::rc::Rc; use metaslang_cst::nodes::NodeId; use metaslang_cst::text_index::TextIndex; +#[cfg(feature = "__private_backend_api")] +use crate::cst::SyntaxNode; use crate::cst::{Cursor, NonterminalNode}; use crate::parser::{ParseError, ParseOutput}; @@ -40,6 +42,12 @@ impl File { &self.tree } + /// Returns the root syntax node of the parse tree. + #[cfg(feature = "__private_backend_api")] + pub fn syntax_tree(&self) -> Rc { + SyntaxNode::create_root(crate::cst::Node::Nonterminal(Rc::clone(&self.tree))) + } + /// Returns a list of all errors encountered during parsing this file. pub fn errors(&self) -> &Vec { &self.errors diff --git a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs index 73c5b04839..37245cf080 100644 --- a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs @@ -68,6 +68,19 @@ pub type CursorIterator = metaslang_cst::cursor::CursorIterator; /// Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. pub type AncestorsIterator = metaslang_cst::cursor::AncestorsIterator; +/// A node reference that can be navigated to the parent or its children +#[cfg(feature = "__private_backend_api")] +pub type SyntaxNode = metaslang_cst::syntax_node::SyntaxNode; +/// A cursor that can traverse a CST using `SyntaxNodes`. +#[cfg(feature = "__private_backend_api")] +pub type SyntaxCursor = metaslang_cst::syntax_cursor::SyntaxCursor; +/// Iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. +#[cfg(feature = "__private_backend_api")] +pub type SyntaxCursorIterator = metaslang_cst::syntax_cursor::SyntaxCursorIterator; +/// Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. +#[cfg(feature = "__private_backend_api")] +pub type SyntaxAncestorsIterator = metaslang_cst::syntax_cursor::SyntaxAncestorsIterator; + /// The declarative `Query` API is a convenient alternative to the [`Cursor`][`metaslang_cst::cursor::Cursor`] /// API for navigating the CST. /// diff --git a/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs b/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs index 0ec5b9177d..5e6e5be9b2 100644 --- a/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs +++ b/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs @@ -1,5 +1,7 @@ use std::rc::Rc; +#[cfg(feature = "__private_backend_api")] +use crate::cst::SyntaxNode; use crate::cst::{Cursor, NonterminalNode, TextIndex}; use crate::parser::ParseError; @@ -48,4 +50,10 @@ impl ParseOutput { pub fn create_tree_cursor(&self) -> Cursor { Rc::clone(&self.tree).create_cursor(TextIndex::ZERO) } + + /// Returns the root syntax node of the parse tree. + #[cfg(feature = "__private_backend_api")] + pub fn syntax_tree(&self) -> Rc { + SyntaxNode::create_root(crate::cst::Node::Nonterminal(Rc::clone(&self.tree))) + } } diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs new file mode 100644 index 0000000000..8563d95ca9 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs @@ -0,0 +1,18 @@ +use slang_solidity::backend::binder::{Binder, Definition}; +use slang_solidity::cst::{Cursor, TerminalKindExtensions}; + +// Collects all the definitions from a given cursor, by navigating the identifiers that appear. +pub(crate) fn collect_definitions<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a Definition> { + let mut cursor = root.spawn(); + let mut definitions = Vec::new(); + while cursor.go_to_next_terminal() { + let node = cursor.node(); + if node.is_nonterminal() || !node.as_terminal().unwrap().kind.is_identifier() { + continue; + } + if let Some(definition) = binder.find_definition_by_identifier_node_id(node.id()) { + definitions.push(definition); + } + } + definitions +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/find_unused_definitions.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/find_unused_definitions.rs new file mode 100644 index 0000000000..fadc5e4d5c --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/find_unused_definitions.rs @@ -0,0 +1,101 @@ +use std::collections::{HashMap, VecDeque}; + +use anyhow::{anyhow, Result}; +use slang_solidity::backend::binder::Definition; +use slang_solidity::backend::BinderOutput; +use slang_solidity::cst::{NodeId, TextIndex}; + +use crate::ast_api::collect_definitions::collect_definitions; +use crate::ast_api::visit_definition::visit_definition; + +pub fn find_unused_definitions<'a>( + compilation_output: &'a BinderOutput, + starting_contract_name: &str, +) -> Vec<&'a Definition> { + let all_definitions = compilation_output.binder.definitions(); + let mut unused_definitions: HashMap = + all_definitions.iter().map(|(id, def)| (*id, def)).collect(); + + let mut visit_queue = VecDeque::new(); + if let Ok(contract) = find_contract_by_name(all_definitions, starting_contract_name) { + visit_queue.push_back(contract); + } + + while let Some(to_visit) = visit_queue.pop_front() { + let node_id = to_visit.node_id(); + if !unused_definitions.contains_key(&node_id) { + continue; + } + unused_definitions.remove(&node_id); + + let definitions = visit_definition(compilation_output, to_visit); + for def in definitions { + visit_queue.push_back(def); + } + } + + // For remaining unused definitions, remove any nested definitions inside them + // to prevent reporting eg. a function and all its parameters + for def in unused_definitions.values() { + visit_queue.push_back(def); + } + while let Some(to_visit) = visit_queue.pop_front() { + if !unused_definitions.contains_key(&to_visit.node_id()) { + continue; + } + + let inner_definitions = collect_definitions( + &compilation_output.binder, + &to_visit.node().create_cursor(TextIndex::ZERO), + ); + for inner in inner_definitions { + if inner.node_id() == to_visit.node_id() { + continue; + } + unused_definitions.remove(&inner.node_id()); + } + } + + unused_definitions.values().copied().collect() +} + +pub(crate) fn find_contract_by_name<'a>( + definitions: &'a HashMap, + name: &str, +) -> Result<&'a Definition> { + definitions + .values() + .find( + |def| matches!(def, Definition::Contract(contract) if contract.identifier.unparse() == name), + ).ok_or_else(|| anyhow!("Can't find a contract {name}")) +} + +#[test] +fn test_one_function() { + const FILE_CONTENT: &str = r#" +contract Test { + function test() private { + } +} + "#; + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); + let result = find_unused_definitions(&output, "Test"); + assert_eq_defs!(result, ["test"]); +} + +#[test] +fn test_a_field_unused() { + const FILE_CONTENT: &str = r#" +contract Test { + uint _count; + uint _unused; + + function count() public view returns (uint) { + return _count; + } +} + "#; + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); + let result = find_unused_definitions(&output, "Test"); + assert_eq_defs!(result, ["_unused"]); +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/follow_all_references.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/follow_all_references.rs new file mode 100644 index 0000000000..a7f26cdcb6 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/follow_all_references.rs @@ -0,0 +1,20 @@ +use slang_solidity::backend::binder::{Binder, Definition}; +use slang_solidity::cst::{Cursor, TerminalKindExtensions}; + +// It takes all the identifiers listed from the cursor position, and returns all the +// definitions they refer to (if they are indeed references) +pub fn follow_all_references<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a Definition> { + let mut referenced_definitions = vec![]; + let mut cursor = root.spawn(); + while cursor.go_to_next_terminal() { + let node = cursor.node(); + if node.is_nonterminal() && !node.as_terminal().unwrap().kind.is_identifier() { + continue; + } + + if let Some(definition) = binder.navigate_to(node.id()) { + referenced_definitions.push(definition); + } + } + referenced_definitions +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs new file mode 100644 index 0000000000..333f9d7253 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs @@ -0,0 +1,19 @@ +// Takes a vec of strings and a slice of str and checks they are permutations one another. +// Used in tests. +macro_rules! assert_eq_defs { + ($xs:expr, $ys:expr) => { + assert_eq!( + $xs.iter() + .map(|def| def.identifier().unparse()) + .collect::>(), + $ys.iter().map(|s| (*s).to_string()).collect() + ); + }; +} + +mod collect_definitions; +mod find_unused_definitions; +mod follow_all_references; +mod pipeline; +mod test_find_unused_definitions; +mod visit_definition; diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs new file mode 100644 index 0000000000..08bf01186b --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs @@ -0,0 +1,54 @@ +use anyhow::{bail, Result}; +use slang_solidity::backend::{build_binder_output, BinderOutput}; +use slang_solidity::compilation::{CompilationBuilder, CompilationBuilderConfig, CompilationUnit}; +use slang_solidity::utils::LanguageFacts; + +// This module allows to easily build a one-file compilation unit from a str, +// and generates the compilation output from the backend pipeline. + +const MAIN_ID: &str = "MAIN-ID"; + +pub(crate) struct OneFileConfig { + file_content: String, +} + +impl OneFileConfig { + pub(crate) fn new(content: &str) -> OneFileConfig { + OneFileConfig { + file_content: content.to_owned(), + } + } +} + +impl CompilationBuilderConfig for OneFileConfig { + type Error = anyhow::Error; + + fn read_file(&mut self, file_id: &str) -> Result> { + assert_eq!(file_id, MAIN_ID); + Ok(Some(self.file_content.clone())) + } + + fn resolve_import( + &mut self, + _source_file_id: &str, + _import_path_cursor: &slang_solidity::cst::Cursor, + ) -> Result> { + bail!("Not expecting an import") + } +} + +pub(crate) fn build_one_file_compilation_unit(content: &str) -> Result { + let config = OneFileConfig::new(content); + let mut builder = CompilationBuilder::create(LanguageFacts::LATEST_VERSION, config)?; + + builder.add_file(MAIN_ID)?; + + Ok(builder.build()) +} + +pub(crate) fn compile_one_file(content: &str) -> Result { + let unit = build_one_file_compilation_unit(content)?; + let data = build_binder_output(unit); + assert_eq!(1, data.files.len()); + Ok(data) +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/test_find_unused_definitions.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/test_find_unused_definitions.rs new file mode 100644 index 0000000000..1c43f786fe --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/test_find_unused_definitions.rs @@ -0,0 +1,50 @@ +use crate::ast_api::find_unused_definitions::find_unused_definitions; +use crate::ast_api::pipeline; + +pub(crate) const MAIN_SOL_CONTENTS: &str = r#" +abstract contract Ownable { + address _owner; + constructor() { + _owner = msg.sender; + } + modifier onlyOwner() { + require(_owner == msg.sender); + _; + } + function checkOwner(address addr) internal returns (bool) { + return _owner == addr; + } +} + +contract Counter is Ownable { + uint _count; + uint _unused; + constructor(uint initialCount) { + _count = initialCount; + } + function count() public view returns (uint) { + return _count; + } + function increment(uint delta, uint multiplier) public onlyOwner returns (uint) { + require(delta > 0, "Delta must be positive"); + _count += delta; + return _count; + } + function unusedDecrement() private { + require(checkOwner(msg.sender)); + _count -= 1; + } +} +"#; + +#[test] +fn test_find_unused_definitions() { + let unit = pipeline::compile_one_file(MAIN_SOL_CONTENTS).unwrap(); + + let unused = find_unused_definitions(&unit, "Counter"); + + assert_eq_defs!( + unused, + ["checkOwner", "_unused", "multiplier", "unusedDecrement",] + ); +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs new file mode 100644 index 0000000000..ac27eb6c8d --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -0,0 +1,169 @@ +use std::rc::Rc; + +use slang_solidity::backend::ast::index::IntoIr; +use slang_solidity::backend::ast::{self, ContractMember}; +use slang_solidity::backend::binder::{ContractDefinition, Definition}; +use slang_solidity::backend::BinderOutput; +use slang_solidity::cst::TextIndex; + +use crate::ast_api::collect_definitions::collect_definitions; +use crate::ast_api::follow_all_references::follow_all_references; + +pub fn visit_definition<'a>( + compilation_output: &'a BinderOutput, + definition: &'a Definition, +) -> Vec<&'a Definition> { + match definition { + Definition::Contract(contract_definition) => { + // special case contracts; see below + visit_contract(compilation_output, contract_definition) + } + Definition::Struct(_) | Definition::Library(_) | Definition::Enum(_) => { + // members must be explicitly referenced + vec![] + } + Definition::Function(definition) => { + // follow any references inside, but don't automatically reference any new + // definitions (eg. a parameter) + follow_all_references( + &compilation_output.binder, + &definition.node.create_cursor(TextIndex::ZERO), + ) + } + Definition::Modifier(definition) => { + // ditto + follow_all_references( + &compilation_output.binder, + &definition.node.create_cursor(TextIndex::ZERO), + ) + } + _ => { + // anything else (events, errors, interfaces) should be considered fully + // referenced (including inner definitions) and we need to follow any + // references inside them + collect_definitions( + &compilation_output.binder, + &definition.node().create_cursor(TextIndex::ZERO), + ) + } + } +} + +fn visit_contract<'a>( + compilation_output: &'a BinderOutput, + contract_definition: &ContractDefinition, +) -> Vec<&'a Definition> { + // for a contract, we need to explicitly follow inheritance specifiers and constructors, + // and visit state variables and public functions + + let contract = + ast::ContractDefinition::into_ir(&contract_definition.node, &compilation_output.index) + .expect("Contract to be defined"); + + let inheritance_nodes = contract + .inheritance_types + .iter() + .map(|f| Rc::clone(&f.node)); + + // Special functions (receiver, fallback, unnamed, constructors) + let function_nodes = contract.members.iter().filter_map(|member| match member { + ast::ContractMember::FunctionDefinition(f) + if !matches!(f.kind, ast::FunctionKind::Regular) => + { + Some(Rc::clone(&f.node)) + } + + _ => None, + }); + + // For special functions and bases, we follow each reference + let follow_all_references = inheritance_nodes + .chain(function_nodes) + .map(|node| node.create_cursor(TextIndex::ZERO)) + .flat_map(|cursor| follow_all_references(&compilation_output.binder, &cursor)); + + let public_state_vars_ids = contract.members.iter().filter_map(|member| match member { + ContractMember::StateVariableDefinition(sv_def) + if matches!(sv_def.visibility, ast::StateVariableVisibility::Public) => + { + Some(sv_def.name.id()) + } + + _ => None, + }); + + let public_functions_ids = contract.members.iter().filter_map(|member| match member { + ast::ContractMember::FunctionDefinition(f) + if matches!(f.kind, ast::FunctionKind::Regular) + && matches!(f.visibility, ast::FunctionVisibility::Public) => + { + f.name.as_ref().map(|node| node.id()) + } + + _ => None, + }); + + // For public functions and state vars we add their definition to the list, to recursively + // consider them + let public_definitions = public_state_vars_ids + .chain(public_functions_ids) + .filter_map(|id| { + compilation_output + .binder + .find_definition_by_identifier_node_id(id) + }); + + follow_all_references.chain(public_definitions).collect() +} + +#[test] +fn test_no_references() { + const FILE_CONTENT: &str = r#" +contract Ownable { +}"#; + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); + let defs = output.binder.definitions(); + assert_eq!(defs.len(), 1); + assert_eq!( + defs.values() + .map(|v| v.identifier().unparse()) + .collect::>(), + vec!["Ownable".to_string()] + ); + let result = visit_definition(&output, defs.values().next().unwrap()); + assert!(result.is_empty()); +} + +#[test] +fn test_no_public_reference() { + const FILE_CONTENT: &str = r#" +contract Ownable { + function test() { + } +}"#; + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); + let defs = output.binder.definitions(); + let (_, contract) = defs + .iter() + .find(|(_, def)| def.identifier().unparse() == "Ownable") + .unwrap(); + let result = visit_definition(&output, contract); + assert!(result.is_empty()); +} + +#[test] +fn test_public_function_reference() { + const FILE_CONTENT: &str = r#" +contract Ownable { + function test() public { + } +}"#; + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); + let defs = output.binder.definitions(); + let (_, contract) = defs + .iter() + .find(|(_, def)| def.identifier().unparse() == "Ownable") + .unwrap(); + let result = visit_definition(&output, contract); + assert_eq_defs!(result, ["test"]); +} diff --git a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/builder.rs b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/builder.rs index eecaaac6fd..d34c08a54d 100644 --- a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/builder.rs +++ b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/builder.rs @@ -25,7 +25,7 @@ contract MyContract { ); assert!(output.is_valid()); - let ast = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let ast = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); assert_eq!(2, ast.members.len()); assert!(matches!( ast.members[0], @@ -106,7 +106,7 @@ contract Test { assert!(!output.is_valid()); assert_eq!(output.errors().len(), 1); - let ast = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let ast = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); assert_eq!(1, ast.members.len()); assert!(matches!( ast.members[0], @@ -157,7 +157,7 @@ contract Test { assert!(!output.is_valid()); assert_eq!(output.errors().len(), 1); - let ast = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let ast = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); // the contract definition cannot be parsed fully assert_eq!(0, ast.members.len()); diff --git a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/rewriter.rs b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/rewriter.rs index f865d2bf85..f329191c63 100644 --- a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/rewriter.rs +++ b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/rewriter.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use anyhow::Result; use slang_solidity::backend::ir::ir1_structured_ast; use slang_solidity::backend::ir::ir1_structured_ast::rewriter::Rewriter; -use slang_solidity::cst::{TerminalKind, TerminalNode}; +use slang_solidity::cst::{Node, SyntaxNode, TerminalKind, TerminalNode}; use slang_solidity::parser::Parser; use slang_solidity::utils::LanguageFacts; @@ -32,7 +32,7 @@ contract MyContract { ); assert!(output.is_valid()); - let source = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let source = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); let mut cloner = Cloner {}; let ast = cloner.rewrite_source_unit(&source); @@ -129,19 +129,22 @@ impl Rewriter for ConstantFolder { // also, any decimal number should be parseable as a 64-bit floating point let result = left_decimal.literal.unparse().parse::().unwrap() * right_decimal.literal.unparse().parse::().unwrap(); + let literal_terminal = Rc::new(TerminalNode { + kind: TerminalKind::DecimalLiteral, + text: format!("{result}"), + }); + // FIXME: this creates an isolated tree, not connected to the expression node + let literal = SyntaxNode::create_root(Node::Terminal(literal_terminal)); let number = Rc::new(ir1_structured_ast::DecimalNumberExpressionStruct { - node_id: multiplicative_expression.node_id, - literal: Rc::new(TerminalNode { - kind: TerminalKind::DecimalLiteral, - text: format!("{result}"), - }), + node: Rc::clone(&multiplicative_expression.node), + literal, unit: None, }); ir1_structured_ast::Expression::DecimalNumberExpression(number) } else { ir1_structured_ast::Expression::MultiplicativeExpression(Rc::new( ir1_structured_ast::MultiplicativeExpressionStruct { - node_id: multiplicative_expression.node_id, + node: Rc::clone(&multiplicative_expression.node), operator: Rc::clone(&multiplicative_expression.operator), left_operand, right_operand, @@ -166,7 +169,7 @@ function weeksToSeconds(uint _weeks) returns (uint) { ); assert!(output.is_valid()); - let source = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let source = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); let mut constant_folder = ConstantFolder {}; let ast = constant_folder.rewrite_source_unit(&source); diff --git a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/visitor.rs b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/visitor.rs index efbe5b0d99..3ef6ff1261 100644 --- a/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/visitor.rs +++ b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/visitor.rs @@ -89,7 +89,7 @@ contract Counter is Ownable { ); assert!(output.is_valid()); - let ast = ir1_structured_ast::builder::build_source_unit(output.tree()).unwrap(); + let ast = ir1_structured_ast::builder::build_source_unit(output.syntax_tree()).unwrap(); let mut visitor = CounterVisitor::new(true); ir1_structured_ast::visitor::accept_source_unit(&ast, &mut visitor); diff --git a/crates/solidity/outputs/cargo/tests/src/lib.rs b/crates/solidity/outputs/cargo/tests/src/lib.rs index 7757c4bca7..f0ba4f2bd8 100644 --- a/crates/solidity/outputs/cargo/tests/src/lib.rs +++ b/crates/solidity/outputs/cargo/tests/src/lib.rs @@ -2,6 +2,7 @@ use metaslang_bindings as _; +mod ast_api; mod backend; mod binder; mod bindings; diff --git a/crates/solidity/testing/sourcify/src/run/binder_v2_check.rs b/crates/solidity/testing/sourcify/src/run/binder_v2_check.rs index 0d419ce15e..e15fcf71db 100644 --- a/crates/solidity/testing/sourcify/src/run/binder_v2_check.rs +++ b/crates/solidity/testing/sourcify/src/run/binder_v2_check.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use slang_solidity::backend::binder::Resolution; use slang_solidity::backend::build_binder_output; use slang_solidity::compilation::CompilationUnit; -use slang_solidity::cst::{Cursor, NodeId, TerminalKind, TerminalNode}; +use slang_solidity::cst::{Cursor, NodeId, SyntaxNode, TerminalKind}; use super::BindingError; use crate::events::{Events, TestOutcome}; @@ -62,7 +62,7 @@ pub(super) fn run( fn find_cursor_for_identifier( cursor_cache: &mut HashMap, compilation_unit: &CompilationUnit, - identifier: &Rc, + identifier: &Rc, ) -> Option<(Cursor, String)> { if cursor_cache.is_empty() { for file in &compilation_unit.files() {