From a89df0b928dab042fcf60dd7678224e1f6c93e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Fri, 24 Oct 2025 10:58:26 -0400 Subject: [PATCH 01/27] Create `SyntaxNode` which should act as a red node to the existing (green) nodes --- crates/metaslang/cst/Cargo.toml | 3 + crates/metaslang/cst/src/lib.rs | 4 + crates/metaslang/cst/src/syntax.rs | 159 +++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 crates/metaslang/cst/src/syntax.rs 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..1c2fdcd832 100644 --- a/crates/metaslang/cst/src/lib.rs +++ b/crates/metaslang/cst/src/lib.rs @@ -7,3 +7,7 @@ pub mod kinds; pub mod nodes; pub mod query; pub mod text_index; + +#[cfg(feature = "syntax")] +#[allow(missing_docs)] +pub mod syntax; diff --git a/crates/metaslang/cst/src/syntax.rs b/crates/metaslang/cst/src/syntax.rs new file mode 100644 index 0000000000..ccf8a200eb --- /dev/null +++ b/crates/metaslang/cst/src/syntax.rs @@ -0,0 +1,159 @@ +use std::rc::Rc; + +use crate::{ + kinds::{KindTypes, NodeKind}, + nodes::{Node, NodeId, NonterminalNode, TerminalNode}, + text_index::TextIndex, +}; + +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, + }) + } + + /// 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) + } + + /// 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) -> impl Iterator> + use<'_, T> { + self.green.children().iter().map(|edge| { + Rc::new(SyntaxNode { + parent: Some(Rc::clone(self)), + label: edge.label, + green: edge.node.clone(), + }) + }) + } + + /// 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() + } +} From b8356f2028cfb2b4019f0baa41393ec9f3579aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Tue, 28 Oct 2025 22:10:44 -0400 Subject: [PATCH 02/27] Reifiy `SyntaxNode` children into a vector and port a `SyntaxCursor` --- crates/metaslang/cst/src/lib.rs | 6 +- crates/metaslang/cst/src/syntax_cursor.rs | 400 ++++++++++++++++++ .../cst/src/{syntax.rs => syntax_node.rs} | 17 +- 3 files changed, 420 insertions(+), 3 deletions(-) create mode 100644 crates/metaslang/cst/src/syntax_cursor.rs rename crates/metaslang/cst/src/{syntax.rs => syntax_node.rs} (93%) diff --git a/crates/metaslang/cst/src/lib.rs b/crates/metaslang/cst/src/lib.rs index 1c2fdcd832..4b9e7c3d9c 100644 --- a/crates/metaslang/cst/src/lib.rs +++ b/crates/metaslang/cst/src/lib.rs @@ -10,4 +10,8 @@ pub mod text_index; #[cfg(feature = "syntax")] #[allow(missing_docs)] -pub mod syntax; +pub mod syntax_node; + +#[cfg(feature = "syntax")] +#[allow(missing_docs)] +pub mod syntax_cursor; diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs new file mode 100644 index 0000000000..087e5b05c1 --- /dev/null +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -0,0 +1,400 @@ +//! 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; +use crate::text_index::{TextIndex, TextRange}; + +/// 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, + /// Text offset that corresponds to the beginning of the currently pointed to node. + text_offset: TextIndex, + /// 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(node: Rc>, text_offset: TextIndex) -> Self { + Self { + node, + child_index: 0, + text_offset, + 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, + text_offset: self.text_offset, + } + } + + /// Whether the cursor can be moved. + pub fn is_completed(&self) -> bool { + self.is_completed + } + + /// Returns the currently pointed to [`Node`]. + pub fn node(&self) -> Rc> { + self.node.clone() + } + + /// Returns the text offset that corresponds to the beginning of the currently pointed to node. + pub fn text_offset(&self) -> TextIndex { + self.text_offset + } + + /// Returns the text range that corresponds to the currently pointed to node. + pub fn text_range(&self) -> TextRange { + let start = self.text_offset; + let end = start + self.node.text_len(); + start..end + } + + /// 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) -> CursorIterator { + let mut cursor = self.spawn(); + + // skip the current node: + cursor.go_to_next(); + + CursorIterator { 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) -> CursorIterator { + CursorIterator { + 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) -> AncestorsIterator { + let current = self.node.clone(); + + AncestorsIterator { 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; + + 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 + let mut children = self.node.children(); + if !children.is_empty() { + self.node = children.remove(0); + self.child_index = 0; + + return true; + } + + false + } + + /// 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 mut children = self.node.children(); + if children.is_empty() { + return false; + } + + self.child_index = children.len() - 1; + self.node = children.remove(self.child_index); + for child in &children { + self.text_offset += child.text_len(); + } + + 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; + } + + let mut children = self.node.children(); + if child_index + 1 > children.len() { + return false; + } + + for i in 0..child_index { + self.text_offset += children[i].text_len(); + } + self.node = children.remove(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; + }; + + let mut siblings = parent.children(); + let index = siblings + .iter() + .position(|parent_child| *parent_child == self.node) + .expect("did not find node in parent's children"); + if index + 1 >= siblings.len() { + return false; + } + self.text_offset += self.node.text_len(); + self.child_index = index + 1; + self.node = siblings.remove(index + 1); + + 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; + }; + + let mut siblings = parent.children(); + let index = siblings + .iter() + .position(|parent_child| *parent_child == self.node) + .expect("did not find node in parent's children"); + if index == 0 { + return false; + } + // FIXME: recalculating the text_offset is more complicated here + //self.text_offset -= self.node.text_len(); + self.child_index = index - 1; + self.node = siblings.remove(index - 1); + + 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 CursorIterator { + cursor: SyntaxCursor, +} + +impl Iterator for CursorIterator { + 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 AncestorsIterator { + current: Rc>, +} + +impl Iterator for AncestorsIterator { + 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.rs b/crates/metaslang/cst/src/syntax_node.rs similarity index 93% rename from crates/metaslang/cst/src/syntax.rs rename to crates/metaslang/cst/src/syntax_node.rs index ccf8a200eb..6da8fa3858 100644 --- a/crates/metaslang/cst/src/syntax.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -6,6 +6,7 @@ use crate::{ text_index::TextIndex, }; +#[derive(Clone, Debug, Eq, PartialEq)] pub struct SyntaxNode { parent: Option>>, label: T::EdgeLabel, @@ -21,6 +22,14 @@ impl SyntaxNode { }) } + pub(crate) fn erase_root(&self) -> Rc { + Rc::new(Self { + parent: None, + label: self.label, + green: self.green.clone(), + }) + } + /// 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 { @@ -31,6 +40,10 @@ impl SyntaxNode { 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() @@ -46,14 +59,14 @@ impl SyntaxNode { } /// Returns the list of child edges directly connected to this node. - pub fn children(self: &Rc) -> impl Iterator> + use<'_, T> { + pub fn children(self: &Rc) -> Vec> { self.green.children().iter().map(|edge| { Rc::new(SyntaxNode { parent: Some(Rc::clone(self)), label: edge.label, green: edge.node.clone(), }) - }) + }).collect() } /// Reconstructs the original source code from the node and its sub-tree. From 3c1edce4d051568b49f3d6e053fe4e50daf4d947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 29 Oct 2025 16:48:48 -0400 Subject: [PATCH 03/27] Move `text_offset` into `SyntaxNode` --- crates/metaslang/cst/src/syntax_cursor.rs | 19 +++---------------- crates/metaslang/cst/src/syntax_node.rs | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs index 087e5b05c1..63082d31bf 100644 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -16,19 +16,16 @@ pub struct SyntaxCursor { /// The index of the current child node in the parent's children. // Required to go to the next/previous sibling. child_index: usize, - /// Text offset that corresponds to the beginning of the currently pointed to node. - text_offset: TextIndex, /// 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(node: Rc>, text_offset: TextIndex) -> Self { + pub fn create(node: Rc>) -> Self { Self { node, child_index: 0, - text_offset, is_completed: false, } } @@ -57,7 +54,6 @@ impl SyntaxCursor { is_completed: false, node: self.node.erase_root(), child_index: 0, - text_offset: self.text_offset, } } @@ -73,12 +69,12 @@ impl SyntaxCursor { /// Returns the text offset that corresponds to the beginning of the currently pointed to node. pub fn text_offset(&self) -> TextIndex { - self.text_offset + self.node.text_offset() } /// Returns the text range that corresponds to the currently pointed to node. pub fn text_range(&self) -> TextRange { - let start = self.text_offset; + let start = self.text_offset(); let end = start + self.node.text_len(); start..end } @@ -221,9 +217,6 @@ impl SyntaxCursor { self.child_index = children.len() - 1; self.node = children.remove(self.child_index); - for child in &children { - self.text_offset += child.text_len(); - } true } @@ -241,9 +234,6 @@ impl SyntaxCursor { return false; } - for i in 0..child_index { - self.text_offset += children[i].text_len(); - } self.node = children.remove(child_index); self.child_index = child_index; @@ -270,7 +260,6 @@ impl SyntaxCursor { if index + 1 >= siblings.len() { return false; } - self.text_offset += self.node.text_len(); self.child_index = index + 1; self.node = siblings.remove(index + 1); @@ -297,8 +286,6 @@ impl SyntaxCursor { if index == 0 { return false; } - // FIXME: recalculating the text_offset is more complicated here - //self.text_offset -= self.node.text_len(); self.child_index = index - 1; self.node = siblings.remove(index - 1); diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs index 6da8fa3858..4752f6bc1c 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -10,6 +10,7 @@ use crate::{ pub struct SyntaxNode { parent: Option>>, label: T::EdgeLabel, + text_offset: TextIndex, green: Node, } @@ -18,6 +19,7 @@ impl SyntaxNode { Rc::new(Self { parent: None, label: T::EdgeLabel::default(), + text_offset: TextIndex::ZERO, green: node, }) } @@ -26,6 +28,7 @@ impl SyntaxNode { Rc::new(Self { parent: None, label: self.label, + text_offset: self.text_offset, green: self.green.clone(), }) } @@ -58,15 +61,24 @@ impl SyntaxNode { self.green.text_len() } + pub fn text_offset(&self) -> TextIndex { + self.text_offset + } + /// Returns the list of child edges directly connected to this node. pub fn children(self: &Rc) -> Vec> { - self.green.children().iter().map(|edge| { - Rc::new(SyntaxNode { + let mut children = Vec::with_capacity(self.green.children().len()); + let mut text_offset = self.text_offset; + for edge in self.green.children() { + children.push(Rc::new(SyntaxNode { parent: Some(Rc::clone(self)), label: edge.label, + text_offset, green: edge.node.clone(), - }) - }).collect() + })); + text_offset += edge.node.text_len(); + } + children } /// Reconstructs the original source code from the node and its sub-tree. From 3fe1075e0d94c0af4652064a053aa973f571d586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 29 Oct 2025 16:58:32 -0400 Subject: [PATCH 04/27] Add a version of queries for `SyntaxCursor` --- crates/metaslang/cst/src/query/mod.rs | 2 + .../metaslang/cst/src/query/syntax_engine.rs | 818 ++++++++++++++++++ 2 files changed, 820 insertions(+) create mode 100644 crates/metaslang/cst/src/query/syntax_engine.rs diff --git a/crates/metaslang/cst/src/query/mod.rs b/crates/metaslang/cst/src/query/mod.rs index d4edcd304c..654654c399 100644 --- a/crates/metaslang/cst/src/query/mod.rs +++ b/crates/metaslang/cst/src/query/mod.rs @@ -3,7 +3,9 @@ mod engine; mod model; mod parser; +mod syntax_engine; pub use engine::{Capture, QueryMatch, QueryMatchIterator}; pub use model::Query; pub use parser::{CaptureQuantifier, QueryError}; +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..6dfb824b64 --- /dev/null +++ b/crates/metaslang/cst/src/query/syntax_engine.rs @@ -0,0 +1,818 @@ +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 [`Capture`] contains the capture name, + /// and a list of [`Cursor`]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 [`Capture`] containing the capture name, + /// and a list of [`Cursor`]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 [`Cursor`]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>>) {} +} From a832e555f47043e0b30d215fd1d57ae7aaf72be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 29 Oct 2025 16:59:53 -0400 Subject: [PATCH 05/27] Fix clippy warnings and formatting --- crates/metaslang/cst/src/query/syntax_engine.rs | 16 ++++++++++++---- crates/metaslang/cst/src/syntax_cursor.rs | 4 ++-- crates/metaslang/cst/src/syntax_node.rs | 8 +++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/metaslang/cst/src/query/syntax_engine.rs b/crates/metaslang/cst/src/query/syntax_engine.rs index 6dfb824b64..58bbb8d0cd 100644 --- a/crates/metaslang/cst/src/query/syntax_engine.rs +++ b/crates/metaslang/cst/src/query/syntax_engine.rs @@ -79,7 +79,9 @@ impl ASTNode { 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::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, @@ -112,7 +114,11 @@ impl ASTNode { // 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 { + fn create_syntax_matcher( + &self, + cursor: SyntaxCursor, + require_explicit_match: bool, + ) -> MatcherRef { match self { Self::Capture(matcher) => Box::new(CaptureMatcher::::new( Rc::clone(matcher), @@ -584,8 +590,10 @@ impl Matcher for AlternativesMatcher { // `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); + let child = child.create_syntax_matcher( + self.cursor.clone(), + self.require_explicit_match, + ); self.child = Some(child); self.next_child_number += 1; } diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs index 63082d31bf..c7608e4ce6 100644 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -64,7 +64,7 @@ impl SyntaxCursor { /// Returns the currently pointed to [`Node`]. pub fn node(&self) -> Rc> { - self.node.clone() + Rc::clone(&self.node) } /// Returns the text offset that corresponds to the beginning of the currently pointed to node. @@ -115,7 +115,7 @@ impl SyntaxCursor { /// 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) -> AncestorsIterator { - let current = self.node.clone(); + let current = Rc::clone(&self.node); AncestorsIterator { current } } diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs index 4752f6bc1c..46616f727d 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -1,10 +1,8 @@ use std::rc::Rc; -use crate::{ - kinds::{KindTypes, NodeKind}, - nodes::{Node, NodeId, NonterminalNode, TerminalNode}, - text_index::TextIndex, -}; +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 { From 30e8155e629d4a388ea1fdf34cfd32359c364c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 29 Oct 2025 18:48:15 -0400 Subject: [PATCH 06/27] Use `SyntaxNode` in IR nodes --- .../solidity/outputs/cargo/crate/Cargo.toml | 2 +- .../src/backend/ir/common/_builder.rs.jinja2 | 52 +- .../src/backend/ir/common/_nodes.rs.jinja2 | 9 +- .../src/backend/ir/common/_rewriter.rs.jinja2 | 2 +- .../backend/ir/common/_transformer.rs.jinja2 | 2 +- .../ir1_structured_ast/builder.generated.rs | 2258 +++++++---------- .../ir/ir1_structured_ast/nodes.generated.rs | 1042 +++++++- .../ir1_structured_ast/rewriter.generated.rs | 260 +- .../ir/ir2_flat_contracts/nodes.generated.rs | 850 ++++++- .../transformer.generated.rs | 194 +- .../crate/src/backend/passes/p0_build_ast.rs | 2 +- .../backend/passes/p1_flatten_contracts.rs | 64 +- .../backend/passes/p2_collect_definitions.rs | 129 +- .../passes/p3_linearise_contracts/mod.rs | 14 +- .../backend/passes/p4_type_definitions/mod.rs | 4 +- .../passes/p4_type_definitions/resolution.rs | 2 +- .../passes/p4_type_definitions/typing.rs | 4 +- .../passes/p4_type_definitions/visitor.rs | 90 +- .../passes/p5_resolve_references/typing.rs | 42 +- .../passes/p5_resolve_references/visitor.rs | 86 +- .../cargo/crate/src/compilation/file.rs | 7 +- .../outputs/cargo/crate/src/cst/mod.rs | 3 + .../cargo/crate/src/parser/parse_output.rs | 7 +- .../backend/ir/ir1_structured_ast/builder.rs | 6 +- .../backend/ir/ir1_structured_ast/rewriter.rs | 8 +- .../backend/ir/ir1_structured_ast/visitor.rs | 2 +- 26 files changed, 3134 insertions(+), 2007 deletions(-) diff --git a/crates/solidity/outputs/cargo/crate/Cargo.toml b/crates/solidity/outputs/cargo/crate/Cargo.toml index 3f90df0e8b..eff59d4ed7 100644 --- a/crates/solidity/outputs/cargo/crate/Cargo.toml +++ b/crates/solidity/outputs/cargo/crate/Cargo.toml @@ -35,7 +35,7 @@ __private_testing_utils = ["metaslang_bindings/__private_testing_utils"] ariadne = { workspace = true, optional = true } indexmap = { workspace = true, optional = true } metaslang_bindings = { workspace = true } -metaslang_cst = { workspace = true } +metaslang_cst = { workspace = true, features = ["syntax"] } semver = { workspace = true } serde = { workspace = true } strum = { workspace = true } 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..8de0ed1e50 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, TerminalNode, }; // @@ -16,10 +16,10 @@ {% 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); + let mut helper = ChildrenHelper::new(node.children()); {% for field in sequence.fields %} {%- if field.is_removed -%} _ = helper.accept_label(EdgeLabel::{{ field.label | pascal_case }})?; @@ -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: Rc::clone(node), {%- for field in sequence.fields -%} {%- if not field.is_removed -%} {{ field.label }}, @@ -67,13 +67,13 @@ // {% for parent_type, choice in builder.choices %} - 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); + let mut helper = ChildrenHelper::new(node.children()); 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,15 +105,15 @@ // {% for parent_type, collection in builder.collections %} - 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 items = {{ parent_type }}::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 -%} @@ -132,29 +132,23 @@ #[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 { + fn terminal_node_cloned(node: &Rc) -> 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") - } - - struct ChildrenHelper<'a> { - children: &'a Vec, + struct ChildrenHelper { + children: Vec>, index: usize, } - impl<'a> ChildrenHelper<'a> { - fn new(children: &'a Vec) -> Self { + impl ChildrenHelper { + fn new(children: Vec>) -> Self { let mut index = 0; while index < children.len() { if !children[index].is_trivia() && children[index].is_valid() { @@ -165,12 +159,12 @@ 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 accept_label(&mut self, label: EdgeLabel) -> Option<&Rc> { + if self.index >= self.children.len() || self.children[self.index].label() != label { return None; } - let node = &self.children[self.index].node; + let node = &self.children[self.index]; loop { self.index += 1; if self.index >= self.children.len() || 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..ab181da667 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,6 +2,7 @@ {%- set target = model.ir_languages[language].target -%} use std::rc::Rc; use std::vec::Vec; + use crate::cst::SyntaxNode; use crate::cst::TerminalNode; use metaslang_cst::nodes::NodeId; @@ -14,7 +15,7 @@ #[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" -%} @@ -39,6 +40,12 @@ {% endfor -%} } + impl {{ parent_type }}Struct { + pub fn id(&self) -> NodeId { + self.node.id() + } + } + {% endfor %} // 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..1c3b416ef6 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 @@ -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 }}, 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..43418d3008 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,225 +6,216 @@ 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, TerminalNode}; // // Sequences: // -pub fn build_source_unit(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let members = build_source_unit_members(helper.accept_label(EdgeLabel::Members)?)?; if !helper.finalize() { return None; } Some(Rc::new(SourceUnitStruct { - node_id: node.id(), + node: Rc::clone(node), members, })) } -pub fn build_pragma_directive(node: &Rc) -> Option { +pub fn build_pragma_directive(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::PragmaDirective); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::PragmaKeyword)?; - let pragma = build_pragma(nonterminal_node(helper.accept_label(EdgeLabel::Pragma)?))?; + let pragma = build_pragma(helper.accept_label(EdgeLabel::Pragma)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(PragmaDirectiveStruct { - node_id: node.id(), + node: Rc::clone(node), pragma, })) } -pub fn build_abicoder_pragma(node: &Rc) -> Option { +pub fn build_abicoder_pragma(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::AbicoderPragma); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::AbicoderKeyword)?; - let version = - build_abicoder_version(nonterminal_node(helper.accept_label(EdgeLabel::Version)?))?; + let version = build_abicoder_version(helper.accept_label(EdgeLabel::Version)?)?; if !helper.finalize() { return None; } Some(Rc::new(AbicoderPragmaStruct { - node_id: node.id(), + node: Rc::clone(node), version, })) } -pub fn build_experimental_pragma(node: &Rc) -> Option { +pub fn build_experimental_pragma(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ExperimentalPragma); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ExperimentalKeyword)?; - let feature = - build_experimental_feature(nonterminal_node(helper.accept_label(EdgeLabel::Feature)?))?; + let feature = build_experimental_feature(helper.accept_label(EdgeLabel::Feature)?)?; if !helper.finalize() { return None; } Some(Rc::new(ExperimentalPragmaStruct { - node_id: node.id(), + node: Rc::clone(node), feature, })) } -pub fn build_version_pragma(node: &Rc) -> Option { +pub fn build_version_pragma(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VersionPragma); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let sets = build_version_expression_sets(helper.accept_label(EdgeLabel::Sets)?)?; if !helper.finalize() { return None; } Some(Rc::new(VersionPragmaStruct { - node_id: node.id(), + node: Rc::clone(node), sets, })) } -pub fn build_version_range(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let start = build_version_literal(helper.accept_label(EdgeLabel::Start)?)?; _ = helper.accept_label(EdgeLabel::Minus)?; - let end = build_version_literal(nonterminal_node(helper.accept_label(EdgeLabel::End)?))?; + let end = build_version_literal(helper.accept_label(EdgeLabel::End)?)?; if !helper.finalize() { return None; } Some(Rc::new(VersionRangeStruct { - node_id: node.id(), + node: Rc::clone(node), start, end, })) } -pub fn build_version_term(node: &Rc) -> Option { +pub fn build_version_term(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VersionTerm); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), operator, literal, })) } -pub fn build_import_directive(node: &Rc) -> Option { +pub fn build_import_directive(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ImportDirective); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ImportKeyword)?; - let clause = build_import_clause(nonterminal_node(helper.accept_label(EdgeLabel::Clause)?))?; + let clause = build_import_clause(helper.accept_label(EdgeLabel::Clause)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ImportDirectiveStruct { - node_id: node.id(), + node: Rc::clone(node), clause, })) } -pub fn build_path_import(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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(), + node: Rc::clone(node), path, alias, })) } -pub fn build_named_import(node: &Rc) -> Option { +pub fn build_named_import(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::NamedImport); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::Asterisk)?; - let alias = build_import_alias(nonterminal_node(helper.accept_label(EdgeLabel::Alias)?))?; + let alias = build_import_alias(helper.accept_label(EdgeLabel::Alias)?)?; _ = helper.accept_label(EdgeLabel::FromKeyword)?; - let path = build_string_literal(nonterminal_node(helper.accept_label(EdgeLabel::Path)?))?; + let path = build_string_literal(helper.accept_label(EdgeLabel::Path)?)?; if !helper.finalize() { return None; } Some(Rc::new(NamedImportStruct { - node_id: node.id(), + node: Rc::clone(node), alias, path, })) } -pub fn build_import_deconstruction(node: &Rc) -> Option { +pub fn build_import_deconstruction(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ImportDeconstruction); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + let symbols = build_import_deconstruction_symbols(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)?))?; + let path = build_string_literal(helper.accept_label(EdgeLabel::Path)?)?; if !helper.finalize() { return None; } Some(Rc::new(ImportDeconstructionStruct { - node_id: node.id(), + node: Rc::clone(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); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), name, alias, })) } -pub fn build_import_alias(node: &Rc) -> Option { +pub fn build_import_alias(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ImportAlias); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::AsKeyword)?; let identifier = terminal_node_cloned(helper.accept_label(EdgeLabel::Identifier)?); if !helper.finalize() { @@ -232,18 +223,18 @@ pub fn build_import_alias(node: &Rc) -> Option { } Some(Rc::new(ImportAliasStruct { - node_id: node.id(), + node: Rc::clone(node), identifier, })) } -pub fn build_using_directive(node: &Rc) -> Option { +pub fn build_using_directive(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingDirective); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::UsingKeyword)?; - let clause = build_using_clause(nonterminal_node(helper.accept_label(EdgeLabel::Clause)?))?; + let clause = build_using_clause(helper.accept_label(EdgeLabel::Clause)?)?; _ = helper.accept_label(EdgeLabel::ForKeyword)?; - let target = build_using_target(nonterminal_node(helper.accept_label(EdgeLabel::Target)?))?; + 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)?; if !helper.finalize() { @@ -251,86 +242,80 @@ pub fn build_using_directive(node: &Rc) -> Option) -> Option { +pub fn build_using_deconstruction(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingDeconstruction); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + let symbols = build_using_deconstruction_symbols(helper.accept_label(EdgeLabel::Symbols)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(UsingDeconstructionStruct { - node_id: node.id(), + node: Rc::clone(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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), name, alias, })) } -pub fn build_using_alias(node: &Rc) -> Option { +pub fn build_using_alias(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingAlias); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::AsKeyword)?; - let operator = - build_using_operator(nonterminal_node(helper.accept_label(EdgeLabel::Operator)?))?; + let operator = build_using_operator(helper.accept_label(EdgeLabel::Operator)?)?; if !helper.finalize() { return None; } Some(Rc::new(UsingAliasStruct { - node_id: node.id(), + node: Rc::clone(node), operator, })) } -pub fn build_contract_definition(node: &Rc) -> Option { +pub fn build_contract_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ContractDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let abstract_keyword = helper.accept_label(EdgeLabel::AbstractKeyword).is_some(); _ = helper.accept_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)?, - ))?; + let specifiers = build_contract_specifiers(helper.accept_label(EdgeLabel::Specifiers)?)?; _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = - build_contract_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; + let members = build_contract_members(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(ContractDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), abstract_keyword, name, specifiers, @@ -338,127 +323,120 @@ pub fn build_contract_definition(node: &Rc) -> Option) -> Option { +pub fn build_inheritance_specifier(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::InheritanceSpecifier); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::IsKeyword)?; - let types = build_inheritance_types(nonterminal_node(helper.accept_label(EdgeLabel::Types)?))?; + let types = build_inheritance_types(helper.accept_label(EdgeLabel::Types)?)?; if !helper.finalize() { return None; } Some(Rc::new(InheritanceSpecifierStruct { - node_id: node.id(), + node: Rc::clone(node), types, })) } -pub fn build_inheritance_type(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), type_name, arguments, })) } -pub fn build_storage_layout_specifier( - node: &Rc, -) -> Option { +pub fn build_storage_layout_specifier(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StorageLayoutSpecifier); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } Some(Rc::new(StorageLayoutSpecifierStruct { - node_id: node.id(), + node: Rc::clone(node), expression, })) } -pub fn build_interface_definition(node: &Rc) -> Option { +pub fn build_interface_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::InterfaceDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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))); + .and_then(build_inheritance_specifier); _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let members = - build_interface_members(nonterminal_node(helper.accept_label(EdgeLabel::Members)?))?; + let members = build_interface_members(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(InterfaceDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), name, inheritance, members, })) } -pub fn build_library_definition(node: &Rc) -> Option { +pub fn build_library_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::LibraryDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?))?; + let members = build_library_members(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(LibraryDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), name, members, })) } -pub fn build_struct_definition(node: &Rc) -> Option { +pub fn build_struct_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StructDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?))?; + let members = build_struct_members(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(StructDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), name, members, })) } -pub fn build_struct_member(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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)?; if !helper.finalize() { @@ -466,72 +444,68 @@ pub fn build_struct_member(node: &Rc) -> Option { } Some(Rc::new(StructMemberStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, name, })) } -pub fn build_enum_definition(node: &Rc) -> Option { +pub fn build_enum_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::EnumDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?))?; + let members = build_enum_members(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(EnumDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), name, members, })) } -pub fn build_constant_definition(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; _ = helper.accept_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)?))?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ConstantDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, name, value, })) } -pub fn build_state_variable_definition( - node: &Rc, -) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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))); + .and_then(build_state_variable_definition_value); _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(StateVariableDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, attributes, name, @@ -540,43 +514,39 @@ 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); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::Equal)?; - let value = build_expression(nonterminal_node(helper.accept_label(EdgeLabel::Value)?))?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; if !helper.finalize() { return None; } Some(Rc::new(StateVariableDefinitionValueStruct { - node_id: node.id(), + node: Rc::clone(node), value, })) } -pub fn build_function_definition(node: &Rc) -> Option { +pub fn build_function_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + 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: Rc::clone(node), name, parameters, attributes, @@ -585,31 +555,29 @@ pub fn build_function_definition(node: &Rc) -> Option) -> Option { +pub fn build_parameters_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(ParametersDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), parameters, })) } -pub fn build_parameter(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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 +586,74 @@ pub fn build_parameter(node: &Rc) -> Option { } Some(Rc::new(ParameterStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, storage_location, name, })) } -pub fn build_override_specifier(node: &Rc) -> Option { +pub fn build_override_specifier(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::OverrideSpecifier); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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(), + node: Rc::clone(node), overridden, })) } -pub fn build_override_paths_declaration( - node: &Rc, -) -> Option { +pub fn build_override_paths_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::OverridePathsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let paths = build_override_paths(nonterminal_node(helper.accept_label(EdgeLabel::Paths)?))?; + let paths = build_override_paths(helper.accept_label(EdgeLabel::Paths)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(OverridePathsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), paths, })) } -pub fn build_returns_declaration(node: &Rc) -> Option { +pub fn build_returns_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ReturnsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ReturnsKeyword)?; - let variables = - build_parameters_declaration(nonterminal_node(helper.accept_label(EdgeLabel::Variables)?))?; + let variables = build_parameters_declaration(helper.accept_label(EdgeLabel::Variables)?)?; if !helper.finalize() { return None; } Some(Rc::new(ReturnsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), variables, })) } -pub fn build_constructor_definition(node: &Rc) -> Option { +pub fn build_constructor_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ConstructorDefinition); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + 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: Rc::clone(node), parameters, attributes, body, @@ -700,24 +661,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); + 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)?))?; + 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: Rc::clone(node), parameters, attributes, body, @@ -725,27 +683,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); + 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)?, - ))?; + 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: Rc::clone(node), parameters, attributes, returns, @@ -754,48 +709,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); + 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)?))?; + 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: Rc::clone(node), parameters, attributes, body, })) } -pub fn build_modifier_definition(node: &Rc) -> Option { +pub fn build_modifier_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ModifierDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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: Rc::clone(node), name, parameters, attributes, @@ -803,32 +753,31 @@ pub fn build_modifier_definition(node: &Rc) -> Option) -> Option { +pub fn build_modifier_invocation(node: &Rc) -> 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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), name, arguments, })) } -pub fn build_event_definition(node: &Rc) -> Option { +pub fn build_event_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::EventDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?; if !helper.finalize() { @@ -836,7 +785,7 @@ pub fn build_event_definition(node: &Rc) -> Option) -> Option, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::EventParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_event_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_event_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(EventParametersDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), parameters, })) } -pub fn build_event_parameter(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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 +823,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); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?))?; + let value_type = build_elementary_type(helper.accept_label(EdgeLabel::ValueType)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(UserDefinedValueTypeDefinitionStruct { - node_id: node.id(), + node: Rc::clone(node), name, value_type, })) } -pub fn build_error_definition(node: &Rc) -> Option { +pub fn build_error_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ErrorDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?, - ))?; + let members = build_error_parameters_declaration(helper.accept_label(EdgeLabel::Members)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorDefinitionStruct { - node_id: node.id(), + node: Rc::clone(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); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_error_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_error_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorParametersDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), parameters, })) } -pub fn build_error_parameter(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -957,83 +899,77 @@ pub fn build_error_parameter(node: &Rc) -> Option) -> Option { +pub fn build_array_type_name(node: &Rc) -> 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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_type_name(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_label(EdgeLabel::OpenBracket)?; let index = helper .accept_label(EdgeLabel::Index) - .and_then(|node| build_expression(nonterminal_node(node))); + .and_then(build_expression); _ = helper.accept_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(ArrayTypeNameStruct { - node_id: node.id(), + node: Rc::clone(node), operand, index, })) } -pub fn build_function_type(node: &Rc) -> Option { +pub fn build_function_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionType); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + 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: Rc::clone(node), parameters, attributes, returns, })) } -pub fn build_mapping_type(node: &Rc) -> Option { +pub fn build_mapping_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::MappingType); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let key_type = build_mapping_key(helper.accept_label(EdgeLabel::KeyType)?)?; _ = helper.accept_label(EdgeLabel::EqualGreaterThan)?; - let value_type = - build_mapping_value(nonterminal_node(helper.accept_label(EdgeLabel::ValueType)?))?; + let value_type = build_mapping_value(helper.accept_label(EdgeLabel::ValueType)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(MappingTypeStruct { - node_id: node.id(), + node: Rc::clone(node), key_type, value_type, })) } -pub fn build_mapping_key(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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 +978,16 @@ pub fn build_mapping_key(node: &Rc) -> Option { } Some(Rc::new(MappingKeyStruct { - node_id: node.id(), + node: Rc::clone(node), key_type, name, })) } -pub fn build_mapping_value(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; let name = helper .accept_label(EdgeLabel::Name) .map(terminal_node_cloned); @@ -1060,15 +996,15 @@ pub fn build_mapping_value(node: &Rc) -> Option { } Some(Rc::new(MappingValueStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, name, })) } -pub fn build_address_type(node: &Rc) -> Option { +pub fn build_address_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::AddressType); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::AddressKeyword)?; let payable_keyword = helper.accept_label(EdgeLabel::PayableKeyword).is_some(); if !helper.finalize() { @@ -1076,124 +1012,114 @@ pub fn build_address_type(node: &Rc) -> Option { } Some(Rc::new(AddressTypeStruct { - node_id: node.id(), + node: Rc::clone(node), payable_keyword, })) } -pub fn build_block(node: &Rc) -> Option { +pub fn build_block(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::Block); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let statements = build_statements(nonterminal_node( - helper.accept_label(EdgeLabel::Statements)?, - ))?; + let statements = build_statements(helper.accept_label(EdgeLabel::Statements)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(BlockStruct { - node_id: node.id(), + node: Rc::clone(node), statements, })) } -pub fn build_unchecked_block(node: &Rc) -> Option { +pub fn build_unchecked_block(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UncheckedBlock); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::UncheckedKeyword)?; - let block = build_block(nonterminal_node(helper.accept_label(EdgeLabel::Block)?))?; + let block = build_block(helper.accept_label(EdgeLabel::Block)?)?; if !helper.finalize() { return None; } Some(Rc::new(UncheckedBlockStruct { - node_id: node.id(), + node: Rc::clone(node), block, })) } -pub fn build_expression_statement(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ExpressionStatementStruct { - node_id: node.id(), + node: Rc::clone(node), expression, })) } -pub fn build_assembly_statement(node: &Rc) -> Option { +pub fn build_assembly_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::AssemblyStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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: Rc::clone(node), label, flags, body, })) } -pub fn build_assembly_flags_declaration( - node: &Rc, -) -> Option { +pub fn build_assembly_flags_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::AssemblyFlagsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let flags = build_assembly_flags(nonterminal_node(helper.accept_label(EdgeLabel::Flags)?))?; + let flags = build_assembly_flags(helper.accept_label(EdgeLabel::Flags)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(AssemblyFlagsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(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); + let mut helper = ChildrenHelper::new(node.children()); 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)?, - ))?; + let elements = build_tuple_deconstruction_elements(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)?, - ))?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(TupleDeconstructionStatementStruct { - node_id: node.id(), + node: Rc::clone(node), var_keyword, elements, expression, @@ -1201,83 +1127,82 @@ 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); + let mut helper = ChildrenHelper::new(node.children()); 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(), + node: Rc::clone(node), member, })) } -pub fn build_typed_tuple_member(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), type_name, storage_location, name, })) } -pub fn build_untyped_tuple_member(node: &Rc) -> Option { +pub fn build_untyped_tuple_member(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UntypedTupleMember); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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))); + .and_then(build_variable_declaration_value); _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(VariableDeclarationStatementStruct { - node_id: node.id(), + node: Rc::clone(node), variable_type, storage_location, name, @@ -1285,85 +1210,78 @@ pub fn build_variable_declaration_statement( })) } -pub fn build_variable_declaration_value( - node: &Rc, -) -> Option { +pub fn build_variable_declaration_value(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationValue); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::Equal)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; + let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; if !helper.finalize() { return None; } Some(Rc::new(VariableDeclarationValueStruct { - node_id: node.id(), + node: Rc::clone(node), expression, })) } -pub fn build_if_statement(node: &Rc) -> Option { +pub fn build_if_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::IfStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + 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: Rc::clone(node), condition, body, else_branch, })) } -pub fn build_else_branch(node: &Rc) -> Option { +pub fn build_else_branch(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ElseBranch); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ElseKeyword)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ElseBranchStruct { - node_id: node.id(), + node: Rc::clone(node), body, })) } -pub fn build_for_statement(node: &Rc) -> Option { +pub fn build_for_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ForStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?, - ))?; + 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))); + .and_then(build_expression); _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ForStatementStruct { - node_id: node.id(), + node: Rc::clone(node), initialization, condition, iterator, @@ -1371,33 +1289,33 @@ pub fn build_for_statement(node: &Rc) -> Option { })) } -pub fn build_while_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); + 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)?))?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(WhileStatementStruct { - node_id: node.id(), + node: Rc::clone(node), condition, body, })) } -pub fn build_do_while_statement(node: &Rc) -> Option { +pub fn build_do_while_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::DoWhileStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::DoKeyword)?; - let body = build_statement(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + let body = build_statement(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)?))?; + let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { @@ -1405,93 +1323,92 @@ pub fn build_do_while_statement(node: &Rc) -> Option) -> Option { +pub fn build_continue_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ContinueStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ContinueKeyword)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ContinueStatementStruct { node_id: node.id() })) + Some(Rc::new(ContinueStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_break_statement(node: &Rc) -> Option { +pub fn build_break_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::BreakStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::BreakKeyword)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(BreakStatementStruct { node_id: node.id() })) + Some(Rc::new(BreakStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_return_statement(node: &Rc) -> Option { +pub fn build_return_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ReturnStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ReturnKeyword)?; let expression = helper .accept_label(EdgeLabel::Expression) - .and_then(|node| build_expression(nonterminal_node(node))); + .and_then(build_expression); _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ReturnStatementStruct { - node_id: node.id(), + node: Rc::clone(node), expression, })) } -pub fn build_emit_statement(node: &Rc) -> Option { +pub fn build_emit_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::EmitStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let event = build_identifier_path(helper.accept_label(EdgeLabel::Event)?)?; + let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(EmitStatementStruct { - node_id: node.id(), + node: Rc::clone(node), event, arguments, })) } -pub fn build_try_statement(node: &Rc) -> Option { +pub fn build_try_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TryStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::TryKeyword)?; - let expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::Expression)?, - ))?; + 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: Rc::clone(node), expression, returns, body, @@ -1499,440 +1416,378 @@ pub fn build_try_statement(node: &Rc) -> Option { })) } -pub fn build_catch_clause(node: &Rc) -> Option { +pub fn build_catch_clause(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::CatchClause); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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(), + node: Rc::clone(node), error, body, })) } -pub fn build_catch_clause_error(node: &Rc) -> Option { +pub fn build_catch_clause_error(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::CatchClauseError); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), name, parameters, })) } -pub fn build_revert_statement(node: &Rc) -> Option { +pub fn build_revert_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::RevertStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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)?))?; + .and_then(build_identifier_path); + let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(RevertStatementStruct { - node_id: node.id(), + node: Rc::clone(node), error, arguments, })) } -pub fn build_throw_statement(node: &Rc) -> Option { +pub fn build_throw_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ThrowStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ThrowKeyword)?; _ = helper.accept_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ThrowStatementStruct { node_id: node.id() })) + Some(Rc::new(ThrowStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_assignment_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_conditional_expression(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_label(EdgeLabel::QuestionMark)?; - let true_expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::TrueExpression)?, - ))?; + let true_expression = build_expression(helper.accept_label(EdgeLabel::TrueExpression)?)?; _ = helper.accept_label(EdgeLabel::Colon)?; - let false_expression = build_expression(nonterminal_node( - helper.accept_label(EdgeLabel::FalseExpression)?, - ))?; + let false_expression = build_expression(helper.accept_label(EdgeLabel::FalseExpression)?)?; if !helper.finalize() { return None; } Some(Rc::new(ConditionalExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), operand, true_expression, false_expression, })) } -pub fn build_or_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; _ = 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(OrExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), left_operand, right_operand, })) } -pub fn build_and_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; _ = 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(AndExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), left_operand, right_operand, })) } -pub fn build_equality_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_inequality_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_bitwise_or_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; _ = 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(BitwiseOrExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), left_operand, right_operand, })) } -pub fn build_bitwise_xor_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; _ = 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(BitwiseXorExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), left_operand, right_operand, })) } -pub fn build_bitwise_and_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + let left_operand = build_expression(helper.accept_label(EdgeLabel::LeftOperand)?)?; _ = 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(BitwiseAndExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), left_operand, right_operand, })) } -pub fn build_shift_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_additive_expression(node: &Rc) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_multiplicative_expression( - node: &Rc, -) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_exponentiation_expression( - node: &Rc, -) -> Option { +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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), left_operand, operator, right_operand, })) } -pub fn build_postfix_expression(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), operand, operator, })) } -pub fn build_prefix_expression(node: &Rc) -> Option { +pub fn build_prefix_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::PrefixExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), operator, operand, })) } -pub fn build_function_call_expression( - node: &Rc, -) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), operand, arguments, })) } -pub fn build_call_options_expression(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let options = build_call_options(nonterminal_node(helper.accept_label(EdgeLabel::Options)?))?; + let options = build_call_options(helper.accept_label(EdgeLabel::Options)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(CallOptionsExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), operand, options, })) } -pub fn build_member_access_expression( - node: &Rc, -) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_label(EdgeLabel::Period)?; let member = terminal_node_cloned(helper.accept_label(EdgeLabel::Member)?); if !helper.finalize() { @@ -1940,280 +1795,272 @@ pub fn build_member_access_expression( } Some(Rc::new(MemberAccessExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), operand, member, })) } -pub fn build_index_access_expression(node: &Rc) -> Option { +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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_expression(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_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))); + .and_then(build_index_access_end); _ = helper.accept_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(IndexAccessExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), operand, start, end, })) } -pub fn build_index_access_end(node: &Rc) -> Option { +pub fn build_index_access_end(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::IndexAccessEnd); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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(), + node: Rc::clone(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); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let arguments = - build_positional_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; + let arguments = build_positional_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(PositionalArgumentsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(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); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; let arguments = helper .accept_label(EdgeLabel::Arguments) - .and_then(|node| build_named_argument_group(nonterminal_node(node))); + .and_then(build_named_argument_group); _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(NamedArgumentsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), arguments, })) } -pub fn build_named_argument_group(node: &Rc) -> Option { +pub fn build_named_argument_group(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::NamedArgumentGroup); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let arguments = - build_named_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; + let arguments = build_named_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(NamedArgumentGroupStruct { - node_id: node.id(), + node: Rc::clone(node), arguments, })) } -pub fn build_named_argument(node: &Rc) -> Option { +pub fn build_named_argument(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::NamedArgument); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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)?))?; + let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; if !helper.finalize() { return None; } Some(Rc::new(NamedArgumentStruct { - node_id: node.id(), + node: Rc::clone(node), name, value, })) } -pub fn build_type_expression(node: &Rc) -> Option { +pub fn build_type_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TypeExpression); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(TypeExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, })) } -pub fn build_new_expression(node: &Rc) -> Option { +pub fn build_new_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::NewExpression); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let type_name = build_type_name(helper.accept_label(EdgeLabel::TypeName)?)?; if !helper.finalize() { return None; } Some(Rc::new(NewExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), type_name, })) } -pub fn build_tuple_expression(node: &Rc) -> Option { +pub fn build_tuple_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TupleExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let items = build_tuple_values(nonterminal_node(helper.accept_label(EdgeLabel::Items)?))?; + let items = build_tuple_values(helper.accept_label(EdgeLabel::Items)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(TupleExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), items, })) } -pub fn build_tuple_value(node: &Rc) -> Option { +pub fn build_tuple_value(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TupleValue); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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(), + node: Rc::clone(node), expression, })) } -pub fn build_array_expression(node: &Rc) -> Option { +pub fn build_array_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ArrayExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenBracket)?; - let items = build_array_values(nonterminal_node(helper.accept_label(EdgeLabel::Items)?))?; + let items = build_array_values(helper.accept_label(EdgeLabel::Items)?)?; _ = helper.accept_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(ArrayExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), items, })) } -pub fn build_hex_number_expression(node: &Rc) -> Option { +pub fn build_hex_number_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::HexNumberExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), literal, unit, })) } -pub fn build_decimal_number_expression( - node: &Rc, -) -> Option { +pub fn build_decimal_number_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::DecimalNumberExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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: Rc::clone(node), literal, unit, })) } -pub fn build_yul_block(node: &Rc) -> Option { +pub fn build_yul_block(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulBlock); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenBrace)?; - let statements = build_yul_statements(nonterminal_node( - helper.accept_label(EdgeLabel::Statements)?, - ))?; + let statements = build_yul_statements(helper.accept_label(EdgeLabel::Statements)?)?; _ = helper.accept_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(YulBlockStruct { - node_id: node.id(), + node: Rc::clone(node), statements, })) } -pub fn build_yul_function_definition(node: &Rc) -> Option { +pub fn build_yul_function_definition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulFunctionDefinition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_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: Rc::clone(node), name, parameters, returns, @@ -2221,189 +2068,174 @@ pub fn build_yul_function_definition(node: &Rc) -> Option, -) -> Option { +pub fn build_yul_parameters_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulParametersDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::OpenParen)?; - let parameters = build_yul_parameters(nonterminal_node( - helper.accept_label(EdgeLabel::Parameters)?, - ))?; + let parameters = build_yul_parameters(helper.accept_label(EdgeLabel::Parameters)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(YulParametersDeclarationStruct { - node_id: node.id(), + node: Rc::clone(node), parameters, })) } -pub fn build_yul_returns_declaration(node: &Rc) -> Option { +pub fn build_yul_returns_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulReturnsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + let variables = build_yul_variable_names(helper.accept_label(EdgeLabel::Variables)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulReturnsDeclarationStruct { - node_id: node.id(), + node: Rc::clone(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); + 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)?))?; + 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: Rc::clone(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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), variables, assignment, expression, })) } -pub fn build_yul_colon_and_equal(node: &Rc) -> Option { +pub fn build_yul_colon_and_equal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulColonAndEqual); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::Colon)?; _ = helper.accept_label(EdgeLabel::Equal)?; if !helper.finalize() { return None; } - Some(Rc::new(YulColonAndEqualStruct { node_id: node.id() })) + Some(Rc::new(YulColonAndEqualStruct { + node: Rc::clone(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)?, - ))?; + let mut helper = ChildrenHelper::new(node.children()); + 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: Rc::clone(node), assignment, variable, })) } -pub fn build_yul_equal_and_colon(node: &Rc) -> Option { +pub fn build_yul_equal_and_colon(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulEqualAndColon); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::Equal)?; _ = helper.accept_label(EdgeLabel::Colon)?; if !helper.finalize() { return None; } - Some(Rc::new(YulEqualAndColonStruct { node_id: node.id() })) + Some(Rc::new(YulEqualAndColonStruct { + node: Rc::clone(node), + })) } -pub fn build_yul_if_statement(node: &Rc) -> Option { +pub fn build_yul_if_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulIfStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + 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: Rc::clone(node), condition, body, })) } -pub fn build_yul_for_statement(node: &Rc) -> Option { +pub fn build_yul_for_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulForStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + 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: Rc::clone(node), initialization, condition, iterator, @@ -2411,93 +2243,97 @@ pub fn build_yul_for_statement(node: &Rc) -> Option) -> Option { +pub fn build_yul_switch_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulSwitchStatement); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + 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: Rc::clone(node), expression, cases, })) } -pub fn build_yul_default_case(node: &Rc) -> Option { +pub fn build_yul_default_case(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulDefaultCase); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::DefaultKeyword)?; - let body = build_yul_block(nonterminal_node(helper.accept_label(EdgeLabel::Body)?))?; + let body = build_yul_block(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(YulDefaultCaseStruct { - node_id: node.id(), + node: Rc::clone(node), body, })) } -pub fn build_yul_value_case(node: &Rc) -> Option { +pub fn build_yul_value_case(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulValueCase); - let mut helper = ChildrenHelper::new(&node.children); + 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)?))?; + 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(), + node: Rc::clone(node), value, body, })) } -pub fn build_yul_leave_statement(node: &Rc) -> Option { +pub fn build_yul_leave_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulLeaveStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::LeaveKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulLeaveStatementStruct { node_id: node.id() })) + Some(Rc::new(YulLeaveStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_yul_break_statement(node: &Rc) -> Option { +pub fn build_yul_break_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulBreakStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::BreakKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulBreakStatementStruct { node_id: node.id() })) + Some(Rc::new(YulBreakStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_yul_continue_statement(node: &Rc) -> Option { +pub fn build_yul_continue_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulContinueStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); _ = helper.accept_label(EdgeLabel::ContinueKeyword)?; if !helper.finalize() { return None; } - Some(Rc::new(YulContinueStatementStruct { node_id: node.id() })) + Some(Rc::new(YulContinueStatementStruct { + node: Rc::clone(node), + })) } -pub fn build_yul_label(node: &Rc) -> Option { +pub fn build_yul_label(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulLabel); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let label = terminal_node_cloned(helper.accept_label(EdgeLabel::Label)?); _ = helper.accept_label(EdgeLabel::Colon)?; if !helper.finalize() { @@ -2505,27 +2341,26 @@ pub fn build_yul_label(node: &Rc) -> Option { } Some(Rc::new(YulLabelStruct { - node_id: node.id(), + node: Rc::clone(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)?))?; + let mut helper = ChildrenHelper::new(node.children()); + let operand = build_yul_expression(helper.accept_label(EdgeLabel::Operand)?)?; _ = helper.accept_label(EdgeLabel::OpenParen)?; - let arguments = - build_yul_arguments(nonterminal_node(helper.accept_label(EdgeLabel::Arguments)?))?; + let arguments = build_yul_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; _ = helper.accept_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(YulFunctionCallExpressionStruct { - node_id: node.id(), + node: Rc::clone(node), operand, arguments, })) @@ -2535,61 +2370,51 @@ pub fn build_yul_function_call_expression( // Choices: // -pub fn build_source_unit_member(node: &Rc) -> Option { +pub fn build_source_unit_member(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::SourceUnitMember); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2429,19 @@ pub fn build_source_unit_member(node: &Rc) -> Option) -> Option { +pub fn build_pragma(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::Pragma); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2456,9 @@ pub fn build_pragma(node: &Rc) -> Option { Some(item) } -pub fn build_abicoder_version(node: &Rc) -> Option { +pub fn build_abicoder_version(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::AbicoderVersion); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::AbicoderV1Keyword) => AbicoderVersion::AbicoderV1Keyword, @@ -2651,13 +2476,13 @@ pub fn build_abicoder_version(node: &Rc) -> Option) -> Option { +pub fn build_experimental_feature(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ExperimentalFeature); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2503,16 @@ pub fn build_experimental_feature(node: &Rc) -> Option) -> Option { +pub fn build_version_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VersionExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2527,9 @@ pub fn build_version_expression(node: &Rc) -> Option) -> Option { +pub fn build_version_operator(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VersionOperator); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Caret) => VersionOperator::Caret, @@ -2727,15 +2552,13 @@ pub fn build_version_operator(node: &Rc) -> Option) -> Option { +pub fn build_version_literal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VersionLiteral); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2579,19 @@ pub fn build_version_literal(node: &Rc) -> Option) -> Option { +pub fn build_import_clause(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ImportClause); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2606,16 @@ pub fn build_import_clause(node: &Rc) -> Option { Some(item) } -pub fn build_using_clause(node: &Rc) -> Option { +pub fn build_using_clause(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingClause); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2630,9 @@ pub fn build_using_clause(node: &Rc) -> Option { Some(item) } -pub fn build_using_operator(node: &Rc) -> Option { +pub fn build_using_operator(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingOperator); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Ampersand) => UsingOperator::Ampersand, @@ -2842,13 +2663,13 @@ pub fn build_using_operator(node: &Rc) -> Option Some(item) } -pub fn build_using_target(node: &Rc) -> Option { +pub fn build_using_target(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingTarget); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2685,16 @@ pub fn build_using_target(node: &Rc) -> Option { Some(item) } -pub fn build_contract_specifier(node: &Rc) -> Option { +pub fn build_contract_specifier(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ContractSpecifier); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2709,51 @@ pub fn build_contract_specifier(node: &Rc) -> Option) -> Option { +pub fn build_contract_member(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ContractMember); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2768,13 @@ pub fn build_contract_member(node: &Rc) -> Option, -) -> Option { +pub fn build_state_variable_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StateVariableAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2803,9 @@ pub fn build_state_variable_attribute( Some(item) } -pub fn build_function_name(node: &Rc) -> Option { +pub fn build_function_name(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionName); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::Identifier) => { @@ -3027,20 +2826,16 @@ pub fn build_function_name(node: &Rc) -> Option { Some(item) } -pub fn build_function_attribute(node: &Rc) -> Option { +pub fn build_function_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2859,12 @@ pub fn build_function_attribute(node: &Rc) -> Option) -> Option { +pub fn build_function_body(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionBody); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2879,13 @@ pub fn build_function_body(node: &Rc) -> Option { Some(item) } -pub fn build_constructor_attribute(node: &Rc) -> Option { +pub fn build_constructor_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ConstructorAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2905,13 @@ pub fn build_constructor_attribute(node: &Rc) -> Option, -) -> Option { +pub fn build_unnamed_function_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 @@ -3158,21 +2945,17 @@ pub fn build_unnamed_function_attribute( } pub fn build_fallback_function_attribute( - node: &Rc, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::FallbackFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +2981,16 @@ pub fn build_fallback_function_attribute( Some(item) } -pub fn build_receive_function_attribute( - node: &Rc, -) -> Option { +pub fn build_receive_function_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ReceiveFunctionAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3014,13 @@ pub fn build_receive_function_attribute( Some(item) } -pub fn build_modifier_attribute(node: &Rc) -> Option { +pub fn build_modifier_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ModifierAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3036,25 @@ pub fn build_modifier_attribute(node: &Rc) -> Option) -> Option { +pub fn build_type_name(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TypeName); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3069,9 @@ pub fn build_type_name(node: &Rc) -> Option { Some(item) } -pub fn build_function_type_attribute(node: &Rc) -> Option { +pub fn build_function_type_attribute(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::FunctionTypeAttribute); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::InternalKeyword) => FunctionTypeAttribute::InternalKeyword, @@ -3320,16 +3095,16 @@ pub fn build_function_type_attribute(node: &Rc) -> Option) -> Option { +pub fn build_mapping_key_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::MappingKeyType); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3119,13 @@ pub fn build_mapping_key_type(node: &Rc) -> Option) -> Option { +pub fn build_elementary_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ElementaryType); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3158,59 @@ pub fn build_elementary_type(node: &Rc) -> Option) -> Option { +pub fn build_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::Statement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3225,16 @@ pub fn build_statement(node: &Rc) -> Option { Some(item) } -pub fn build_tuple_member(node: &Rc) -> Option { +pub fn build_tuple_member(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::TupleMember); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3249,13 @@ pub fn build_tuple_member(node: &Rc) -> Option { Some(item) } -pub fn build_variable_declaration_type( - node: &Rc, -) -> Option { +pub fn build_variable_declaration_type(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationType); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3271,9 @@ pub fn build_variable_declaration_type( Some(item) } -pub fn build_storage_location(node: &Rc) -> Option { +pub fn build_storage_location(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StorageLocation); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::MemoryKeyword) => StorageLocation::MemoryKeyword, @@ -3526,26 +3293,24 @@ pub fn build_storage_location(node: &Rc) -> Option, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::ForStatementInitialization); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3326,13 @@ pub fn build_for_statement_initialization( Some(item) } -pub fn build_for_statement_condition(node: &Rc) -> Option { +pub fn build_for_statement_condition(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ForStatementCondition); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3348,91 @@ pub fn build_for_statement_condition(node: &Rc) -> Option) -> Option { +pub fn build_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::Expression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3455,19 @@ pub fn build_expression(node: &Rc) -> Option { Some(item) } -pub fn build_arguments_declaration(node: &Rc) -> Option { +pub fn build_arguments_declaration(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::ArgumentsDeclaration); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3483,9 @@ pub fn build_arguments_declaration(node: &Rc) -> Option) -> Option { +pub fn build_number_unit(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::NumberUnit); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::WeiKeyword) => NumberUnit::WeiKeyword, @@ -3773,29 +3512,25 @@ pub fn build_number_unit(node: &Rc) -> Option { Some(item) } -pub fn build_string_expression(node: &Rc) -> Option { +pub fn build_string_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StringExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3545,9 @@ pub fn build_string_expression(node: &Rc) -> Option) -> Option { +pub fn build_string_literal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::StringLiteral); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedStringLiteral) => { @@ -3834,9 +3569,9 @@ pub fn build_string_literal(node: &Rc) -> Option Some(item) } -pub fn build_hex_string_literal(node: &Rc) -> Option { +pub fn build_hex_string_literal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::HexStringLiteral); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedHexStringLiteral) => { @@ -3858,9 +3593,9 @@ pub fn build_hex_string_literal(node: &Rc) -> Option) -> Option { +pub fn build_unicode_string_literal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::UnicodeStringLiteral); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); let variant = helper.accept_label(EdgeLabel::Variant)?; let item = match variant.kind() { NodeKind::Terminal(TerminalKind::SingleQuotedUnicodeStringLiteral) => { @@ -3882,59 +3617,55 @@ pub fn build_unicode_string_literal(node: &Rc) -> Option) -> Option { +pub fn build_yul_statement(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulStatement); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3680,13 @@ pub fn build_yul_statement(node: &Rc) -> Option { Some(item) } -pub fn build_yul_assignment_operator(node: &Rc) -> Option { +pub fn build_yul_assignment_operator(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulAssignmentOperator); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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(_) => { @@ -3974,16 +3703,14 @@ 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); + let mut helper = ChildrenHelper::new(node.children()); 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 +3726,16 @@ pub fn build_yul_stack_assignment_operator( Some(item) } -pub fn build_yul_switch_case(node: &Rc) -> Option { +pub fn build_yul_switch_case(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulSwitchCase); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3750,19 @@ pub fn build_yul_switch_case(node: &Rc) -> Option) -> Option { +pub fn build_yul_expression(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulExpression); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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 +3777,16 @@ pub fn build_yul_expression(node: &Rc) -> Option Some(item) } -pub fn build_yul_literal(node: &Rc) -> Option { +pub fn build_yul_literal(node: &Rc) -> Option { assert_nonterminal_kind(node, NonterminalKind::YulLiteral); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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,12 +3813,12 @@ pub fn build_yul_literal(node: &Rc) -> Option { // Repeated & Separated // -pub fn build_source_unit_members(node: &Rc) -> Option { +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.children()); 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); @@ -4104,12 +3829,12 @@ pub fn build_source_unit_members(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4120,12 +3845,12 @@ pub fn build_version_expression_sets(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4136,10 +3861,10 @@ pub fn build_version_expression_set(node: &Rc) -> Option) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4151,13 +3876,13 @@ pub fn build_simple_version_literal(node: &Rc) -> Option, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::ImportDeconstructionSymbols); let mut items = ImportDeconstructionSymbols::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4169,13 +3894,13 @@ pub fn build_import_deconstruction_symbols( } pub fn build_using_deconstruction_symbols( - node: &Rc, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::UsingDeconstructionSymbols); let mut items = UsingDeconstructionSymbols::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4186,12 +3911,12 @@ pub fn build_using_deconstruction_symbols( Some(items) } -pub fn build_contract_specifiers(node: &Rc) -> Option { +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.children()); 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); @@ -4202,12 +3927,12 @@ pub fn build_contract_specifiers(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4218,12 +3943,12 @@ pub fn build_inheritance_types(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4234,12 +3959,12 @@ pub fn build_contract_members(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4250,12 +3975,12 @@ pub fn build_interface_members(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4266,12 +3991,12 @@ pub fn build_library_members(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4282,10 +4007,10 @@ pub fn build_struct_members(node: &Rc) -> Option Some(items) } -pub fn build_enum_members(node: &Rc) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4296,14 +4021,12 @@ pub fn build_enum_members(node: &Rc) -> Option { Some(items) } -pub fn build_state_variable_attributes( - node: &Rc, -) -> Option { +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.children()); 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); @@ -4314,12 +4037,12 @@ pub fn build_state_variable_attributes( Some(items) } -pub fn build_parameters(node: &Rc) -> Option { +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.children()); 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); @@ -4330,12 +4053,12 @@ pub fn build_parameters(node: &Rc) -> Option { Some(items) } -pub fn build_function_attributes(node: &Rc) -> Option { +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.children()); 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); @@ -4346,12 +4069,12 @@ pub fn build_function_attributes(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4362,12 +4085,12 @@ pub fn build_override_paths(node: &Rc) -> Option Some(items) } -pub fn build_constructor_attributes(node: &Rc) -> Option { +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.children()); 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); @@ -4379,13 +4102,13 @@ pub fn build_constructor_attributes(node: &Rc) -> Option, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionAttributes); let mut items = UnnamedFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4397,13 +4120,13 @@ pub fn build_unnamed_function_attributes( } pub fn build_fallback_function_attributes( - node: &Rc, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::FallbackFunctionAttributes); let mut items = FallbackFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4415,13 +4138,13 @@ pub fn build_fallback_function_attributes( } pub fn build_receive_function_attributes( - node: &Rc, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::ReceiveFunctionAttributes); let mut items = ReceiveFunctionAttributes::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4432,12 +4155,12 @@ pub fn build_receive_function_attributes( Some(items) } -pub fn build_modifier_attributes(node: &Rc) -> Option { +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.children()); 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); @@ -4448,12 +4171,12 @@ pub fn build_modifier_attributes(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4464,12 +4187,12 @@ pub fn build_event_parameters(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4480,14 +4203,12 @@ pub fn build_error_parameters(node: &Rc) -> Option, -) -> Option { +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.children()); 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); @@ -4498,12 +4219,12 @@ pub fn build_function_type_attributes( Some(items) } -pub fn build_statements(node: &Rc) -> Option { +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.children()); 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); @@ -4514,12 +4235,12 @@ pub fn build_statements(node: &Rc) -> Option { Some(items) } -pub fn build_assembly_flags(node: &Rc) -> Option { +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.children()); 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); @@ -4531,13 +4252,13 @@ pub fn build_assembly_flags(node: &Rc) -> Option } pub fn build_tuple_deconstruction_elements( - node: &Rc, + node: &Rc, ) -> Option { assert_nonterminal_kind(node, NonterminalKind::TupleDeconstructionElements); let mut items = TupleDeconstructionElements::new(); - let mut helper = ChildrenHelper::new(&node.children); + let mut helper = ChildrenHelper::new(node.children()); 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); @@ -4548,12 +4269,12 @@ pub fn build_tuple_deconstruction_elements( Some(items) } -pub fn build_catch_clauses(node: &Rc) -> Option { +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.children()); 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); @@ -4564,12 +4285,12 @@ pub fn build_catch_clauses(node: &Rc) -> Option { Some(items) } -pub fn build_positional_arguments(node: &Rc) -> Option { +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.children()); 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); @@ -4580,12 +4301,12 @@ pub fn build_positional_arguments(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4596,12 +4317,12 @@ pub fn build_named_arguments(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4612,12 +4333,12 @@ pub fn build_call_options(node: &Rc) -> Option { Some(items) } -pub fn build_tuple_values(node: &Rc) -> Option { +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.children()); 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); @@ -4628,12 +4349,12 @@ pub fn build_tuple_values(node: &Rc) -> Option { Some(items) } -pub fn build_array_values(node: &Rc) -> Option { +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.children()); 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); @@ -4644,12 +4365,12 @@ pub fn build_array_values(node: &Rc) -> Option { Some(items) } -pub fn build_string_literals(node: &Rc) -> Option { +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.children()); 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); @@ -4660,12 +4381,12 @@ pub fn build_string_literals(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4676,12 +4397,12 @@ pub fn build_hex_string_literals(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4692,10 +4413,10 @@ pub fn build_unicode_string_literals(node: &Rc) -> Option) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4706,12 +4427,12 @@ pub fn build_identifier_path(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4722,10 +4443,10 @@ pub fn build_yul_statements(node: &Rc) -> Option Some(items) } -pub fn build_yul_parameters(node: &Rc) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4736,10 +4457,10 @@ pub fn build_yul_parameters(node: &Rc) -> Option Some(items) } -pub fn build_yul_variable_names(node: &Rc) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4750,12 +4471,12 @@ pub fn build_yul_variable_names(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4766,12 +4487,12 @@ pub fn build_yul_switch_cases(node: &Rc) -> Option) -> Option { +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.children()); 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); @@ -4782,12 +4503,12 @@ pub fn build_yul_arguments(node: &Rc) -> Option { Some(items) } -pub fn build_yul_paths(node: &Rc) -> Option { +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.children()); 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); @@ -4798,10 +4519,10 @@ pub fn build_yul_paths(node: &Rc) -> Option { Some(items) } -pub fn build_yul_path(node: &Rc) -> Option { +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.children()); while let Some(child) = helper.accept_label(EdgeLabel::Item) { items.push(terminal_node_cloned(child)); _ = helper.accept_label(EdgeLabel::Separator); @@ -4818,34 +4539,29 @@ 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 { +fn terminal_node_cloned(node: &Rc) -> 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") -} - -struct ChildrenHelper<'a> { - children: &'a Vec, +struct ChildrenHelper { + children: Vec>, index: usize, } -impl<'a> ChildrenHelper<'a> { - fn new(children: &'a Vec) -> Self { +impl ChildrenHelper { + fn new(children: Vec>) -> Self { let mut index = 0; while index < children.len() { if !children[index].is_trivia() && children[index].is_valid() { @@ -4856,12 +4572,12 @@ 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 accept_label(&mut self, label: EdgeLabel) -> Option<&Rc> { + if self.index >= self.children.len() || self.children[self.index].label() != label { return None; } - let node = &self.children[self.index].node; + let node = &self.children[self.index]; loop { self.index += 1; if self.index >= self.children.len() 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..4ef5d54399 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, TerminalNode}; // // 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 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 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 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 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 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 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, } +impl StructMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { - pub node_id: NodeId, + 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 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 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>, } +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 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 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>, } +impl EventParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UserDefinedValueTypeDefinition = Rc; #[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { - pub node_id: NodeId, + 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 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>, } +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>, } +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>, } +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, } +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, } +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 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 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 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 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 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 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 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 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 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, } +impl PostfixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { - pub node_id: NodeId, + 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, } +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 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 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 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 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, } +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 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: // 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/ir2_flat_contracts/nodes.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs index 328829373a..4af8f2c2ad 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, TerminalNode}; // // Sequences: @@ -15,136 +15,226 @@ 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 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 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, } +impl ImportDeconstructionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type ImportDeconstructionSymbol = Rc; #[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { - pub node_id: NodeId, + 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 members: ContractMembers, @@ -152,76 +242,124 @@ pub struct ContractDefinitionStruct { 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 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 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 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, } +impl StructMemberStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { - pub node_id: NodeId, + 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 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 value: Option, @@ -230,11 +368,17 @@ pub struct StateVariableDefinitionStruct { 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, @@ -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>, } +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 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>, } +impl EventParameterStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type UserDefinedValueTypeDefinition = Rc; #[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { - pub node_id: NodeId, + 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 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>, } +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>, } +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>, } +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>, } +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, } +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, } +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 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 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 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 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 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 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 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 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 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, } +impl PostfixExpressionStruct { + pub fn id(&self) -> NodeId { + self.node.id() + } +} + pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { - pub node_id: NodeId, + 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, } +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 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 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 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 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, } +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 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: // 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..4127e41330 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 @@ -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, }) 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..81a385cd0d 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..bd4dcac059 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 @@ -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, 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..ada5daaed0 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 @@ -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(parameter.id(), 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(parameter.id(), 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(parameter.id(), 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(parameter.id(), 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.id(), &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.id(), &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.id(), &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.id(), 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.id(), &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.id(), 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.id(), 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.id(), 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,14 +410,14 @@ 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.id(), &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); @@ -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.id(), &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.id(), &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.id(), &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.id(), &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.id(), &node.name) } else { let visibility = (&node.visibility).into(); - Definition::new_state_variable(node.node_id, &node.name, visibility) + Definition::new_state_variable(node.id(), &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.id(), &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.id(), &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.id(), &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.id(), &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.id(), &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.id(), 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.id(), 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(parameter.id(), 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(parameter.id(), name); self.binder.insert_definition_no_scope(definition); } } @@ -637,21 +630,21 @@ 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.id(), &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 { @@ -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.id(), &node.label); self.insert_definition_in_current_scope(definition); false @@ -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..bb709f3ab9 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); } @@ -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..336f3efa46 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 @@ -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..f9ef5c9380 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 @@ -12,10 +12,10 @@ 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 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..9f27d32e96 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 @@ -10,21 +10,21 @@ 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,13 +261,13 @@ 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) { @@ -287,7 +287,7 @@ impl Visitor for Pass { 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 +313,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 +350,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 +418,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 +441,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 +453,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 +471,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 +550,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 +662,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 +678,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 +690,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 +718,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/compilation/file.rs b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs index f49e6e118a..692b2021bc 100644 --- a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs +++ b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use metaslang_cst::nodes::NodeId; use metaslang_cst::text_index::TextIndex; -use crate::cst::{Cursor, NonterminalNode}; +use crate::cst::{Cursor, Node, NonterminalNode, SyntaxNode}; use crate::parser::{ParseError, ParseOutput}; /// A single source file in the compilation unit. @@ -40,6 +40,11 @@ impl File { &self.tree } + /// Returns the root syntax node of the parse tree. + pub fn syntax_tree(&self) -> Rc { + SyntaxNode::create_root(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..8d516daa69 100644 --- a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs @@ -59,6 +59,9 @@ pub type TerminalNode = metaslang_cst::nodes::TerminalNode; /// Represents a connection between nodes in the syntax tree. pub type Edge = metaslang_cst::nodes::Edge; +/// A node reference that can be navigated to the parent or its children +pub type SyntaxNode = metaslang_cst::syntax_node::SyntaxNode; + /// A cursor that can traverse a CST. /// /// Nodes are visited in a DFS pre-order traversal. 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..77964c5ddf 100644 --- a/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs +++ b/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use crate::cst::{Cursor, NonterminalNode, TextIndex}; +use crate::cst::{Cursor, Node, NonterminalNode, SyntaxNode, TextIndex}; use crate::parser::ParseError; /// The result of parsing source code using [`Parser`][`crate::parser::Parser`]. @@ -48,4 +48,9 @@ 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. + pub fn syntax_tree(&self) -> Rc { + SyntaxNode::create_root(Node::Nonterminal(Rc::clone(&self.tree))) + } } 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..a4b83c976f 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..ceba049996 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 @@ -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); @@ -130,7 +130,7 @@ impl Rewriter for ConstantFolder { let result = left_decimal.literal.unparse().parse::().unwrap() * right_decimal.literal.unparse().parse::().unwrap(); let number = Rc::new(ir1_structured_ast::DecimalNumberExpressionStruct { - node_id: multiplicative_expression.node_id, + node: Rc::clone(&multiplicative_expression.node), literal: Rc::new(TerminalNode { kind: TerminalKind::DecimalLiteral, text: format!("{result}"), @@ -141,7 +141,7 @@ impl Rewriter for ConstantFolder { } 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 +166,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..df5034a624 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); From dbd24b0de11e7129701b66ff4e8fd9e9c30cf7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Thu, 30 Oct 2025 12:50:39 -0400 Subject: [PATCH 07/27] Use `SyntaxNode` to store terminals in the IR trees --- .../crate/src/backend/binder/definitions.rs | 96 ++++++------ .../crate/src/backend/binder/references.rs | 6 +- .../cargo/crate/src/backend/binder/scopes.rs | 4 +- .../src/backend/ir/common/_builder.rs.jinja2 | 7 +- .../src/backend/ir/common/_nodes.rs.jinja2 | 11 +- .../backend/ir/common/_transformer.rs.jinja2 | 4 +- .../src/backend/ir/common/_visitor.rs.jinja2 | 4 +- .../ir1_structured_ast/builder.generated.rs | 9 +- .../ir/ir1_structured_ast/nodes.generated.rs | 126 ++++++++-------- .../ir1_structured_ast/visitor.generated.rs | 14 +- .../ir/ir2_flat_contracts/nodes.generated.rs | 138 +++++++++--------- .../transformer.generated.rs | 4 +- .../ir2_flat_contracts/visitor.generated.rs | 22 +-- .../backend/passes/p1_flatten_contracts.rs | 10 +- .../backend/passes/p2_collect_definitions.rs | 4 +- .../passes/p5_resolve_references/typing.rs | 4 +- .../passes/p5_resolve_references/visitor.rs | 20 +-- .../backend/ir/ir1_structured_ast/rewriter.rs | 13 +- .../sourcify/src/run/binder_v2_check.rs | 4 +- 19 files changed, 251 insertions(+), 249 deletions(-) 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..d8e3c48e71 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 @@ -37,13 +37,13 @@ pub enum Definition { #[derive(Debug)] pub struct ConstantDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ContractDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub bases: Option>, pub constructor_parameters_scope_id: Option, } @@ -51,26 +51,26 @@ pub struct ContractDefinition { #[derive(Debug)] pub struct EnumDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct EnumMemberDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ErrorDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, } #[derive(Debug)] pub struct EventDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, } @@ -85,7 +85,7 @@ pub enum FunctionVisibility { #[derive(Debug)] pub struct FunctionDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub parameters_scope_id: ScopeId, pub visibility: FunctionVisibility, } @@ -93,14 +93,14 @@ pub struct FunctionDefinition { #[derive(Debug)] pub struct ImportDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub resolved_file_id: Option, } #[derive(Debug)] pub struct ImportedSymbolDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub symbol: String, pub resolved_file_id: Option, } @@ -108,26 +108,26 @@ pub struct ImportedSymbolDefinition { #[derive(Debug)] pub struct InterfaceDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub bases: Option>, } #[derive(Debug)] pub struct LibraryDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ModifierDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct ParameterDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug, Eq, PartialEq)] @@ -140,7 +140,7 @@ pub enum StateVariableVisibility { #[derive(Debug)] pub struct StateVariableDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub getter_type_id: Option, pub visibility: StateVariableVisibility, } @@ -148,56 +148,56 @@ pub struct StateVariableDefinition { #[derive(Debug)] pub struct StructDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct StructMemberDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct TypeParameterDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct UserDefinedValueTypeDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, pub target_type_id: Option, } #[derive(Debug)] pub struct VariableDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulLabelDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulFunctionDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulParameterDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } #[derive(Debug)] pub struct YulVariableDefinition { pub node_id: NodeId, - pub identifier: Rc, + pub identifier: Rc, } impl Definition { @@ -229,7 +229,7 @@ impl Definition { } } - 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, @@ -291,14 +291,14 @@ impl Definition { } } - pub(crate) fn new_constant(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_constant(node_id: NodeId, identifier: &Rc) -> Self { Self::Constant(ConstantDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_contract(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_contract(node_id: NodeId, identifier: &Rc) -> Self { Self::Contract(ContractDefinition { node_id, identifier: Rc::clone(identifier), @@ -307,14 +307,14 @@ impl Definition { }) } - pub(crate) fn new_enum(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_enum(node_id: NodeId, identifier: &Rc) -> Self { Self::Enum(EnumDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_enum_member(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_enum_member(node_id: NodeId, identifier: &Rc) -> Self { Self::EnumMember(EnumMemberDefinition { node_id, identifier: Rc::clone(identifier), @@ -323,7 +323,7 @@ impl Definition { pub(crate) fn new_error( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, ) -> Self { Self::Error(ErrorDefinition { @@ -335,7 +335,7 @@ impl Definition { pub(crate) fn new_event( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, ) -> Self { Self::Event(EventDefinition { @@ -347,7 +347,7 @@ impl Definition { pub(crate) fn new_function( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, parameters_scope_id: ScopeId, visibility: FunctionVisibility, ) -> Self { @@ -361,7 +361,7 @@ impl Definition { pub(crate) fn new_import( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, resolved_file_id: Option, ) -> Self { Self::Import(ImportDefinition { @@ -373,7 +373,7 @@ impl Definition { pub(crate) fn new_imported_symbol( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, symbol: String, resolved_file_id: Option, ) -> Self { @@ -385,7 +385,7 @@ impl Definition { }) } - pub(crate) fn new_interface(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_interface(node_id: NodeId, identifier: &Rc) -> Self { Self::Interface(InterfaceDefinition { node_id, identifier: Rc::clone(identifier), @@ -393,21 +393,21 @@ impl Definition { }) } - pub(crate) fn new_library(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_library(node_id: NodeId, identifier: &Rc) -> Self { Self::Library(LibraryDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_modifier(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_modifier(node_id: NodeId, identifier: &Rc) -> Self { Self::Modifier(ModifierDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_parameter(node_id: NodeId, identifier: &Rc) -> Self { Self::Parameter(ParameterDefinition { node_id, identifier: Rc::clone(identifier), @@ -416,7 +416,7 @@ impl Definition { pub(crate) fn new_state_variable( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, visibility: StateVariableVisibility, ) -> Self { Self::StateVariable(StateVariableDefinition { @@ -427,21 +427,21 @@ impl Definition { }) } - pub(crate) fn new_struct(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_struct(node_id: NodeId, identifier: &Rc) -> Self { Self::Struct(StructDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_struct_member(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_struct_member(node_id: NodeId, identifier: &Rc) -> Self { Self::StructMember(StructMemberDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_type_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_type_parameter(node_id: NodeId, identifier: &Rc) -> Self { Self::TypeParameter(TypeParameterDefinition { node_id, identifier: Rc::clone(identifier), @@ -450,7 +450,7 @@ impl Definition { pub(crate) fn new_user_defined_value_type( node_id: NodeId, - identifier: &Rc, + identifier: &Rc, ) -> Self { Self::UserDefinedValueType(UserDefinedValueTypeDefinition { node_id, @@ -459,35 +459,35 @@ impl Definition { }) } - pub(crate) fn new_variable(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_variable(node_id: NodeId, identifier: &Rc) -> Self { Self::Variable(VariableDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_function(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_function(node_id: NodeId, identifier: &Rc) -> Self { Self::YulFunction(YulFunctionDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_label(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_label(node_id: NodeId, identifier: &Rc) -> Self { Self::YulLabel(YulLabelDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_parameter(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_parameter(node_id: NodeId, identifier: &Rc) -> Self { Self::YulParameter(YulParameterDefinition { node_id, identifier: Rc::clone(identifier), }) } - pub(crate) fn new_yul_variable(node_id: NodeId, identifier: &Rc) -> Self { + pub(crate) fn new_yul_variable(node_id: NodeId, identifier: &Rc) -> Self { Self::YulVariable(YulVariableDefinition { node_id, identifier: Rc::clone(identifier), 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/ir/common/_builder.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_builder.rs.jinja2 index 8de0ed1e50..0102b67b5b 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::{ - EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind, TerminalNode, + EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind, }; // @@ -138,8 +138,9 @@ #[allow(dead_code)] #[inline] - fn terminal_node_cloned(node: &Rc) -> Rc { - node.as_terminal().map(Rc::clone).expect("expected terminal node") + fn terminal_node_cloned(node: &Rc) -> Rc { + assert!(node.is_terminal(), "expected terminal node"); + Rc::clone(node) } struct ChildrenHelper { 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 ab181da667..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 @@ -3,7 +3,6 @@ use std::rc::Rc; use std::vec::Vec; use crate::cst::SyntaxNode; - use crate::cst::TerminalNode; use metaslang_cst::nodes::NodeId; // @@ -20,15 +19,15 @@ 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 -%} @@ -59,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 }}, @@ -74,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/_transformer.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_transformer.rs.jinja2 index 1c3b416ef6..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 { // @@ -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 43418d3008..3778ef3097 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,7 +6,7 @@ use std::rc::Rc; #[allow(clippy::wildcard_imports)] use super::nodes::*; -use crate::cst::{EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind, TerminalNode}; +use crate::cst::{EdgeLabel, NodeKind, NonterminalKind, SyntaxNode, TerminalKind}; // // Sequences: @@ -4549,10 +4549,9 @@ fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { #[allow(dead_code)] #[inline] -fn terminal_node_cloned(node: &Rc) -> Rc { - node.as_terminal() - .map(Rc::clone) - .expect("expected terminal node") +fn terminal_node_cloned(node: &Rc) -> Rc { + assert!(node.is_terminal(), "expected terminal node"); + Rc::clone(node) } struct ChildrenHelper { 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 4ef5d54399..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::{SyntaxNode, TerminalNode}; +use crate::cst::SyntaxNode; // // Sequences: @@ -175,7 +175,7 @@ pub type ImportDeconstructionSymbol = Rc; #[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub alias: Option, } @@ -190,7 +190,7 @@ pub type ImportAlias = Rc; #[derive(Debug)] pub struct ImportAliasStruct { pub node: Rc, - pub identifier: Rc, + pub identifier: Rc, } impl ImportAliasStruct { @@ -264,7 +264,7 @@ pub type ContractDefinition = Rc; pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, - pub name: Rc, + pub name: Rc, pub specifiers: ContractSpecifiers, pub members: ContractMembers, } @@ -323,7 +323,7 @@ pub type InterfaceDefinition = Rc; #[derive(Debug)] pub struct InterfaceDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub inheritance: Option, pub members: InterfaceMembers, } @@ -339,7 +339,7 @@ pub type LibraryDefinition = Rc; #[derive(Debug)] pub struct LibraryDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: LibraryMembers, } @@ -354,7 +354,7 @@ pub type StructDefinition = Rc; #[derive(Debug)] pub struct StructDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: StructMembers, } @@ -370,7 +370,7 @@ pub type StructMember = Rc; pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, } impl StructMemberStruct { @@ -384,7 +384,7 @@ pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: EnumMembers, } @@ -400,7 +400,7 @@ pub type ConstantDefinition = Rc; pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Expression, } @@ -417,7 +417,7 @@ pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, pub attributes: StateVariableAttributes, - pub name: Rc, + pub name: Rc, pub value: Option, } @@ -480,7 +480,7 @@ pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Option>, + pub name: Option>, } impl ParameterStruct { @@ -601,7 +601,7 @@ pub type ModifierDefinition = Rc; #[derive(Debug)] pub struct ModifierDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub parameters: Option, pub attributes: ModifierAttributes, pub body: FunctionBody, @@ -633,7 +633,7 @@ pub type EventDefinition = Rc; #[derive(Debug)] pub struct EventDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub parameters: EventParametersDeclaration, pub anonymous_keyword: bool, } @@ -665,7 +665,7 @@ pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, pub indexed_keyword: bool, - pub name: Option>, + pub name: Option>, } impl EventParameterStruct { @@ -679,7 +679,7 @@ pub type UserDefinedValueTypeDefinition = Rc, - pub name: Rc, + pub name: Rc, pub value_type: ElementaryType, } @@ -694,7 +694,7 @@ pub type ErrorDefinition = Rc; #[derive(Debug)] pub struct ErrorDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: ErrorParametersDeclaration, } @@ -724,7 +724,7 @@ pub type ErrorParameter = Rc; pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, } impl ErrorParameterStruct { @@ -785,7 +785,7 @@ pub type MappingKey = Rc; pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, - pub name: Option>, + pub name: Option>, } impl MappingKeyStruct { @@ -800,7 +800,7 @@ pub type MappingValue = Rc; pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, } impl MappingValueStruct { @@ -932,7 +932,7 @@ pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Rc, + pub name: Rc, } impl TypedTupleMemberStruct { @@ -947,7 +947,7 @@ pub type UntypedTupleMember = Rc; pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, - pub name: Rc, + pub name: Rc, } impl UntypedTupleMemberStruct { @@ -963,7 +963,7 @@ pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, pub storage_location: Option, - pub name: Rc, + pub name: Rc, pub value: Option, } @@ -1156,7 +1156,7 @@ pub type CatchClauseError = Rc; #[derive(Debug)] pub struct CatchClauseErrorStruct { pub node: Rc, - pub name: Option>, + pub name: Option>, pub parameters: ParametersDeclaration, } @@ -1200,7 +1200,7 @@ pub type AssignmentExpression = Rc; pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1262,7 +1262,7 @@ pub type EqualityExpression = Rc; pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1278,7 +1278,7 @@ pub type InequalityExpression = Rc; pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1339,7 +1339,7 @@ pub type ShiftExpression = Rc; pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1355,7 +1355,7 @@ pub type AdditiveExpression = Rc; pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1371,7 +1371,7 @@ pub type MultiplicativeExpression = Rc; pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1387,7 +1387,7 @@ pub type ExponentiationExpression = Rc; pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1403,7 +1403,7 @@ pub type PostfixExpression = Rc; pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, - pub operator: Rc, + pub operator: Rc, } impl PostfixExpressionStruct { @@ -1417,7 +1417,7 @@ pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { pub node: Rc, - pub operator: Rc, + pub operator: Rc, pub operand: Expression, } @@ -1463,7 +1463,7 @@ pub type MemberAccessExpression = Rc; pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, - pub member: Rc, + pub member: Rc, } impl MemberAccessExpressionStruct { @@ -1549,7 +1549,7 @@ pub type NamedArgument = Rc; #[derive(Debug)] pub struct NamedArgumentStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub value: Expression, } @@ -1634,7 +1634,7 @@ pub type HexNumberExpression = Rc; #[derive(Debug)] pub struct HexNumberExpressionStruct { pub node: Rc, - pub literal: Rc, + pub literal: Rc, pub unit: Option, } @@ -1649,7 +1649,7 @@ pub type DecimalNumberExpression = Rc; #[derive(Debug)] pub struct DecimalNumberExpressionStruct { pub node: Rc, - pub literal: Rc, + pub literal: Rc, pub unit: Option, } @@ -1678,7 +1678,7 @@ pub type YulFunctionDefinition = Rc; #[derive(Debug)] pub struct YulFunctionDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub parameters: YulParametersDeclaration, pub returns: Option, pub body: YulBlock, @@ -1783,7 +1783,7 @@ pub type YulStackAssignmentStatement = Rc; pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, - pub variable: Rc, + pub variable: Rc, } impl YulStackAssignmentStatementStruct { @@ -1925,7 +1925,7 @@ pub type YulLabel = Rc; #[derive(Debug)] pub struct YulLabelStruct { pub node: Rc, - pub label: Rc, + pub label: Rc, } impl YulLabelStruct { @@ -2010,8 +2010,8 @@ pub enum VersionOperator { #[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), - SingleQuotedVersionLiteral(Rc), - DoubleQuotedVersionLiteral(Rc), + SingleQuotedVersionLiteral(Rc), + DoubleQuotedVersionLiteral(Rc), } #[derive(Debug)] @@ -2088,7 +2088,7 @@ pub enum StateVariableAttribute { #[derive(Debug)] pub enum FunctionName { - Identifier(Rc), + Identifier(Rc), FallbackKeyword, ReceiveKeyword, } @@ -2193,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, @@ -2286,7 +2286,7 @@ pub enum Expression { DecimalNumberExpression(DecimalNumberExpression), StringExpression(StringExpression), ElementaryType(ElementaryType), - Identifier(Rc), + Identifier(Rc), PayableKeyword, ThisKeyword, SuperKeyword, @@ -2326,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)] @@ -2388,8 +2388,8 @@ pub enum YulExpression { pub enum YulLiteral { HexStringLiteral(HexStringLiteral), StringLiteral(StringLiteral), - YulDecimalLiteral(Rc), - YulHexLiteral(Rc), + YulDecimalLiteral(Rc), + YulHexLiteral(Rc), YulTrueKeyword, YulFalseKeyword, } @@ -2404,7 +2404,7 @@ pub type VersionExpressionSets = Vec; pub type VersionExpressionSet = Vec; -pub type SimpleVersionLiteral = Vec>; +pub type SimpleVersionLiteral = Vec>; pub type ImportDeconstructionSymbols = Vec; @@ -2422,7 +2422,7 @@ pub type LibraryMembers = Vec; pub type StructMembers = Vec; -pub type EnumMembers = Vec>; +pub type EnumMembers = Vec>; pub type StateVariableAttributes = Vec; @@ -2472,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; @@ -2486,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/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/nodes.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/nodes.generated.rs index 4af8f2c2ad..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::{SyntaxNode, TerminalNode}; +use crate::cst::SyntaxNode; // // Sequences: @@ -130,8 +130,8 @@ pub type PathImport = Rc; #[derive(Debug)] pub struct PathImportStruct { pub node: Rc, - pub alias: Option>, - pub path: Rc, + pub alias: Option>, + pub path: Rc, } impl PathImportStruct { @@ -145,8 +145,8 @@ pub type NamedImport = Rc; #[derive(Debug)] pub struct NamedImportStruct { pub node: Rc, - pub alias: Rc, - pub path: Rc, + pub alias: Rc, + pub path: Rc, } impl NamedImportStruct { @@ -161,7 +161,7 @@ pub type ImportDeconstruction = Rc; pub struct ImportDeconstructionStruct { pub node: Rc, pub symbols: ImportDeconstructionSymbols, - pub path: Rc, + pub path: Rc, } impl ImportDeconstructionStruct { @@ -175,8 +175,8 @@ pub type ImportDeconstructionSymbol = Rc; #[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, - pub name: Rc, - pub alias: Option>, + pub name: Rc, + pub alias: Option>, } impl ImportDeconstructionSymbolStruct { @@ -236,7 +236,7 @@ pub type ContractDefinition = Rc; pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, - pub name: Rc, + pub name: Rc, pub members: ContractMembers, pub inheritance_types: InheritanceTypes, pub storage_layout: Option, @@ -268,7 +268,7 @@ pub type InterfaceDefinition = Rc; #[derive(Debug)] pub struct InterfaceDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub inheritance: Option, pub members: InterfaceMembers, } @@ -284,7 +284,7 @@ pub type LibraryDefinition = Rc; #[derive(Debug)] pub struct LibraryDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: LibraryMembers, } @@ -299,7 +299,7 @@ pub type StructDefinition = Rc; #[derive(Debug)] pub struct StructDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: StructMembers, } @@ -315,7 +315,7 @@ pub type StructMember = Rc; pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, } impl StructMemberStruct { @@ -329,7 +329,7 @@ pub type EnumDefinition = Rc; #[derive(Debug)] pub struct EnumDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: EnumMembers, } @@ -345,7 +345,7 @@ pub type ConstantDefinition = Rc; pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Expression, } @@ -361,7 +361,7 @@ pub type StateVariableDefinition = Rc; pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, - pub name: Rc, + pub name: Rc, pub value: Option, pub visibility: StateVariableVisibility, pub mutability: StateVariableMutability, @@ -382,7 +382,7 @@ pub struct FunctionDefinitionStruct { pub parameters: Parameters, pub returns: Option, pub kind: FunctionKind, - pub name: Option>, + pub name: Option>, pub body: Option, pub visibility: FunctionVisibility, pub mutability: FunctionMutability, @@ -404,7 +404,7 @@ pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Option>, + pub name: Option>, } impl ParameterStruct { @@ -447,7 +447,7 @@ pub type EventDefinition = Rc; #[derive(Debug)] pub struct EventDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub parameters: EventParameters, pub anonymous_keyword: bool, } @@ -465,7 +465,7 @@ pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, pub indexed_keyword: bool, - pub name: Option>, + pub name: Option>, } impl EventParameterStruct { @@ -479,7 +479,7 @@ pub type UserDefinedValueTypeDefinition = Rc, - pub name: Rc, + pub name: Rc, pub value_type: ElementaryType, } @@ -494,7 +494,7 @@ pub type ErrorDefinition = Rc; #[derive(Debug)] pub struct ErrorDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub members: ErrorParameters, } @@ -510,7 +510,7 @@ pub type ErrorParameter = Rc; pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, } impl ErrorParameterStruct { @@ -572,7 +572,7 @@ pub type MappingKey = Rc; pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, - pub name: Option>, + pub name: Option>, } impl MappingKeyStruct { @@ -587,7 +587,7 @@ pub type MappingValue = Rc; pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, - pub name: Option>, + pub name: Option>, } impl MappingValueStruct { @@ -659,7 +659,7 @@ pub struct AssemblyStatementStruct { pub node: Rc, pub body: YulBlock, pub flags: AssemblyFlags, - pub label: Option>, + pub label: Option>, } impl AssemblyStatementStruct { @@ -705,7 +705,7 @@ pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, pub storage_location: Option, - pub name: Rc, + pub name: Rc, } impl TypedTupleMemberStruct { @@ -720,7 +720,7 @@ pub type UntypedTupleMember = Rc; pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, - pub name: Rc, + pub name: Rc, } impl UntypedTupleMemberStruct { @@ -736,7 +736,7 @@ pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, pub storage_location: Option, - pub name: Rc, + pub name: Rc, pub value: Option, } @@ -901,7 +901,7 @@ pub type CatchClauseError = Rc; #[derive(Debug)] pub struct CatchClauseErrorStruct { pub node: Rc, - pub name: Option>, + pub name: Option>, pub parameters: Parameters, } @@ -945,7 +945,7 @@ pub type AssignmentExpression = Rc; pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1007,7 +1007,7 @@ pub type EqualityExpression = Rc; pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1023,7 +1023,7 @@ pub type InequalityExpression = Rc; pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1084,7 +1084,7 @@ pub type ShiftExpression = Rc; pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1100,7 +1100,7 @@ pub type AdditiveExpression = Rc; pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1116,7 +1116,7 @@ pub type MultiplicativeExpression = Rc; pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1132,7 +1132,7 @@ pub type ExponentiationExpression = Rc; pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, - pub operator: Rc, + pub operator: Rc, pub right_operand: Expression, } @@ -1148,7 +1148,7 @@ pub type PostfixExpression = Rc; pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, - pub operator: Rc, + pub operator: Rc, } impl PostfixExpressionStruct { @@ -1162,7 +1162,7 @@ pub type PrefixExpression = Rc; #[derive(Debug)] pub struct PrefixExpressionStruct { pub node: Rc, - pub operator: Rc, + pub operator: Rc, pub operand: Expression, } @@ -1208,7 +1208,7 @@ pub type MemberAccessExpression = Rc; pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, - pub member: Rc, + pub member: Rc, } impl MemberAccessExpressionStruct { @@ -1238,7 +1238,7 @@ pub type NamedArgument = Rc; #[derive(Debug)] pub struct NamedArgumentStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub value: Expression, } @@ -1323,7 +1323,7 @@ pub type HexNumberExpression = Rc; #[derive(Debug)] pub struct HexNumberExpressionStruct { pub node: Rc, - pub literal: Rc, + pub literal: Rc, pub unit: Option, } @@ -1338,7 +1338,7 @@ pub type DecimalNumberExpression = Rc; #[derive(Debug)] pub struct DecimalNumberExpressionStruct { pub node: Rc, - pub literal: Rc, + pub literal: Rc, pub unit: Option, } @@ -1367,7 +1367,7 @@ pub type YulFunctionDefinition = Rc; #[derive(Debug)] pub struct YulFunctionDefinitionStruct { pub node: Rc, - pub name: Rc, + pub name: Rc, pub parameters: YulParameters, pub returns: Option, pub body: YulBlock, @@ -1444,7 +1444,7 @@ pub type YulStackAssignmentStatement = Rc; pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, - pub variable: Rc, + pub variable: Rc, } impl YulStackAssignmentStatementStruct { @@ -1586,7 +1586,7 @@ pub type YulLabel = Rc; #[derive(Debug)] pub struct YulLabelStruct { pub node: Rc, - pub label: Rc, + pub label: Rc, } impl YulLabelStruct { @@ -1646,7 +1646,7 @@ pub enum AbicoderVersion { #[derive(Debug)] pub enum ExperimentalFeature { - StringLiteral(Rc), + StringLiteral(Rc), ABIEncoderV2Keyword, SMTCheckerKeyword, } @@ -1671,8 +1671,8 @@ pub enum VersionOperator { #[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), - SingleQuotedVersionLiteral(Rc), - DoubleQuotedVersionLiteral(Rc), + SingleQuotedVersionLiteral(Rc), + DoubleQuotedVersionLiteral(Rc), } #[derive(Debug)] @@ -1743,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, @@ -1836,7 +1836,7 @@ pub enum Expression { DecimalNumberExpression(DecimalNumberExpression), StringExpression(StringExpression), ElementaryType(ElementaryType), - Identifier(Rc), + Identifier(Rc), PayableKeyword, ThisKeyword, SuperKeyword, @@ -1916,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, } @@ -1975,7 +1975,7 @@ pub type VersionExpressionSets = Vec; pub type VersionExpressionSet = Vec; -pub type SimpleVersionLiteral = Vec>; +pub type SimpleVersionLiteral = Vec>; pub type ImportDeconstructionSymbols = Vec; @@ -1991,7 +1991,7 @@ pub type LibraryMembers = Vec; pub type StructMembers = Vec; -pub type EnumMembers = Vec>; +pub type EnumMembers = Vec>; pub type Parameters = Vec; @@ -2017,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; @@ -2031,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 4127e41330..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 { // @@ -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/passes/p1_flatten_contracts.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs index bd4dcac059..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 { @@ -924,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) => { @@ -933,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) => { @@ -942,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 ada5daaed0..7b621e1644 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 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 f9ef5c9380..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,7 +5,7 @@ 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 { @@ -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 9f27d32e96..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,7 +5,7 @@ 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 { @@ -271,20 +271,22 @@ impl Visitor for Pass { } 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.id(), type_id); 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 ceba049996..4e9d8bd9ad 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; @@ -129,12 +129,15 @@ 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: Rc::clone(&multiplicative_expression.node), - literal: Rc::new(TerminalNode { - kind: TerminalKind::DecimalLiteral, - text: format!("{result}"), - }), + literal, unit: None, }); ir1_structured_ast::Expression::DecimalNumberExpression(number) 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() { From a1f28b2540a3da0164336661178aad9b2399bb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Thu, 30 Oct 2025 13:19:56 -0400 Subject: [PATCH 08/27] Use `SyntaxNode` to link definitions back to the CST --- .../crate/src/backend/binder/definitions.rs | 198 +++++++++--------- .../cargo/crate/src/backend/built_ins.rs | 4 +- .../backend/passes/p2_collect_definitions.rs | 68 +++--- .../passes/p3_linearise_contracts/mod.rs | 8 +- .../passes/p4_type_definitions/resolution.rs | 8 +- 5 files changed, 141 insertions(+), 145 deletions(-) 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 d8e3c48e71..e29cfe2c88 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs @@ -36,13 +36,13 @@ pub enum Definition { #[derive(Debug)] pub struct ConstantDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct ContractDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub bases: Option>, pub constructor_parameters_scope_id: Option, @@ -50,26 +50,25 @@ pub struct ContractDefinition { #[derive(Debug)] pub struct EnumDefinition { - pub node_id: NodeId, + 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 node: Rc, pub identifier: Rc, pub parameters_scope_id: ScopeId, } #[derive(Debug)] pub struct EventDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub parameters_scope_id: ScopeId, } @@ -84,7 +83,7 @@ pub enum FunctionVisibility { #[derive(Debug)] pub struct FunctionDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub parameters_scope_id: ScopeId, pub visibility: FunctionVisibility, @@ -92,14 +91,14 @@ pub struct FunctionDefinition { #[derive(Debug)] pub struct ImportDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub resolved_file_id: Option, } #[derive(Debug)] pub struct ImportedSymbolDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub symbol: String, pub resolved_file_id: Option, @@ -107,26 +106,26 @@ pub struct ImportedSymbolDefinition { #[derive(Debug)] pub struct InterfaceDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub bases: Option>, } #[derive(Debug)] pub struct LibraryDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct ModifierDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct ParameterDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } @@ -139,7 +138,7 @@ pub enum StateVariableVisibility { #[derive(Debug)] pub struct StateVariableDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub getter_type_id: Option, pub visibility: StateVariableVisibility, @@ -147,85 +146,85 @@ pub struct StateVariableDefinition { #[derive(Debug)] pub struct StructDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct StructMemberDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct TypeParameterDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct UserDefinedValueTypeDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, pub target_type_id: Option, } #[derive(Debug)] pub struct VariableDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct YulLabelDefinition { - pub node_id: NodeId, + pub node: Rc, pub identifier: Rc, } #[derive(Debug)] pub struct YulFunctionDefinition { - pub node_id: NodeId, + 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_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(), } } @@ -234,7 +233,7 @@ impl Definition { 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 +251,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 +290,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, + 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, + 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, + 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 +358,135 @@ impl Definition { } pub(crate) fn new_import( - node_id: NodeId, + 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, + 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, + 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, + 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/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/passes/p2_collect_definitions.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p2_collect_definitions.rs index 7b621e1644..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 @@ -171,7 +171,7 @@ impl Pass { for parameter in parameters { scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.id(), name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -184,7 +184,7 @@ impl Pass { for parameter in parameters { scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.id(), name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -197,7 +197,7 @@ impl Pass { for parameter in parameters { scope.add_parameter(parameter.name.as_ref(), parameter.id()); if let Some(name) = ¶meter.name { - let definition = Definition::new_parameter(parameter.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.id(), name); + let definition = Definition::new_parameter(¶meter.node, name); self.binder.insert_definition_in_scope(definition, scope_id); } } @@ -249,7 +249,7 @@ impl Visitor for Pass { } fn enter_contract_definition(&mut self, node: &input_ir::ContractDefinition) -> bool { - let definition = Definition::new_contract(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.id(), self.current_scope_id()); @@ -263,7 +263,7 @@ impl Visitor for Pass { } fn enter_library_definition(&mut self, node: &input_ir::LibraryDefinition) -> bool { - let definition = Definition::new_library(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.id(), self.current_scope_id()); @@ -277,7 +277,7 @@ impl Visitor for Pass { } fn enter_interface_definition(&mut self, node: &input_ir::InterfaceDefinition) -> bool { - let definition = Definition::new_interface(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.id(), self.current_scope_id()); @@ -294,7 +294,7 @@ impl Visitor for Pass { let imported_file_id = self.resolve_import_path(&node.path); if let Some(alias) = &node.alias { - let definition = Definition::new_import(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.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.id(), + &symbol.node, identifier, symbol.name.unparse(), imported_file_id.clone(), @@ -346,7 +346,7 @@ impl Visitor for Pass { if let Some(name) = &node.name { let visibility = (&node.visibility).into(); let definition = - Definition::new_function(node.id(), name, parameters_scope_id, visibility); + Definition::new_function(&node.node, name, parameters_scope_id, visibility); let current_scope_node_id = self.current_scope().node_id(); let enclosing_definition = @@ -398,7 +398,7 @@ impl Visitor for Pass { unreachable!("expected a name for the modifier"); }; - let definition = Definition::new_modifier(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.id(), self.current_scope_id()); @@ -414,13 +414,13 @@ impl Visitor for Pass { } fn enter_enum_definition(&mut self, node: &input_ir::EnumDefinition) -> bool { - let definition = Definition::new_enum(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.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); } @@ -429,13 +429,13 @@ impl Visitor for Pass { } fn enter_struct_definition(&mut self, node: &input_ir::StructDefinition) -> bool { - let definition = Definition::new_struct(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.id()); let struct_scope_id = self.binder.insert_scope(struct_scope); for member in &node.members { - let definition = Definition::new_struct_member(member.id(), &member.name); + let definition = Definition::new_struct_member(&member.node, &member.name); self.binder .insert_definition_in_scope(definition, struct_scope_id); } @@ -445,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.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 @@ -453,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.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 @@ -468,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.id(), &node.name) + Definition::new_constant(&node.node, &node.name) } else { let visibility = (&node.visibility).into(); - Definition::new_state_variable(node.id(), &node.name, visibility) + Definition::new_state_variable(&node.node, &node.name, visibility) }; self.insert_definition_in_current_scope(definition); @@ -481,7 +481,7 @@ impl Visitor for Pass { } fn enter_constant_definition(&mut self, node: &input_ir::ConstantDefinition) -> bool { - let definition = Definition::new_constant(node.id(), &node.name); + let definition = Definition::new_constant(&node.node, &node.name); self.insert_definition_in_current_scope(definition); false @@ -491,7 +491,7 @@ impl Visitor for Pass { &mut self, node: &input_ir::UserDefinedValueTypeDefinition, ) -> bool { - let definition = Definition::new_user_defined_value_type(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,7 +509,7 @@ impl Visitor for Pass { self.replace_scope(scope); } - let definition = Definition::new_variable(node.id(), &node.name); + let definition = Definition::new_variable(&node.node, &node.name); self.insert_definition_in_current_scope(definition); } @@ -532,13 +532,13 @@ impl Visitor for Pass { }; let definition = match tuple_member { input_ir::TupleMember::TypedTupleMember(typed_tuple_member) => { - Definition::new_variable(typed_tuple_member.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.id(), &untyped_tuple_member.name) + Definition::new_variable(&untyped_tuple_member.node, &untyped_tuple_member.name) } }; self.insert_definition_in_current_scope(definition); @@ -599,11 +599,11 @@ impl Visitor for Pass { 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.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.id(), name); + let definition = Definition::new_type_parameter(&node.value_type.node, name); self.binder.insert_definition_no_scope(definition); } @@ -613,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.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.id(), name); + let definition = Definition::new_type_parameter(¶meter.node, name); self.binder.insert_definition_no_scope(definition); } } @@ -641,19 +641,19 @@ impl Visitor for Pass { } fn enter_yul_function_definition(&mut self, node: &input_ir::YulFunctionDefinition) -> bool { - let definition = Definition::new_yul_function(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.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); } } @@ -666,7 +666,7 @@ impl Visitor for Pass { } fn enter_yul_label(&mut self, node: &input_ir::YulLabel) -> bool { - let definition = Definition::new_yul_label(node.id(), &node.label); + let definition = Definition::new_yul_label(&node.node, &node.label); self.insert_definition_in_current_scope(definition); false @@ -677,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 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 bb709f3ab9..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 @@ -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, }); 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 336f3efa46..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, }); From bcefe85e65465c7afa9aa9006f7dc6983703dfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Fri, 31 Oct 2025 18:59:21 -0400 Subject: [PATCH 09/27] Remove `text_offset` from `SyntaxNode` and all `SyntaxCursor` code --- crates/metaslang/cst/src/lib.rs | 4 - crates/metaslang/cst/src/query/mod.rs | 2 - .../metaslang/cst/src/query/syntax_engine.rs | 826 ------------------ crates/metaslang/cst/src/syntax_cursor.rs | 387 -------- crates/metaslang/cst/src/syntax_node.rs | 18 - 5 files changed, 1237 deletions(-) delete mode 100644 crates/metaslang/cst/src/query/syntax_engine.rs delete mode 100644 crates/metaslang/cst/src/syntax_cursor.rs diff --git a/crates/metaslang/cst/src/lib.rs b/crates/metaslang/cst/src/lib.rs index 4b9e7c3d9c..d5ba7e51c6 100644 --- a/crates/metaslang/cst/src/lib.rs +++ b/crates/metaslang/cst/src/lib.rs @@ -11,7 +11,3 @@ 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 654654c399..d4edcd304c 100644 --- a/crates/metaslang/cst/src/query/mod.rs +++ b/crates/metaslang/cst/src/query/mod.rs @@ -3,9 +3,7 @@ mod engine; mod model; mod parser; -mod syntax_engine; pub use engine::{Capture, QueryMatch, QueryMatchIterator}; pub use model::Query; pub use parser::{CaptureQuantifier, QueryError}; -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 deleted file mode 100644 index 58bbb8d0cd..0000000000 --- a/crates/metaslang/cst/src/query/syntax_engine.rs +++ /dev/null @@ -1,826 +0,0 @@ -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 [`Capture`] contains the capture name, - /// and a list of [`Cursor`]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 [`Capture`] containing the capture name, - /// and a list of [`Cursor`]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 [`Cursor`]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 deleted file mode 100644 index c7608e4ce6..0000000000 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ /dev/null @@ -1,387 +0,0 @@ -//! 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; -use crate::text_index::{TextIndex, TextRange}; - -/// 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(node: Rc>) -> Self { - Self { - node, - child_index: 0, - 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 [`Node`]. - pub fn node(&self) -> Rc> { - Rc::clone(&self.node) - } - - /// Returns the text offset that corresponds to the beginning of the currently pointed to node. - pub fn text_offset(&self) -> TextIndex { - self.node.text_offset() - } - - /// Returns the text range that corresponds to the currently pointed to node. - pub fn text_range(&self) -> TextRange { - let start = self.text_offset(); - let end = start + self.node.text_len(); - start..end - } - - /// 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) -> CursorIterator { - let mut cursor = self.spawn(); - - // skip the current node: - cursor.go_to_next(); - - CursorIterator { 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) -> CursorIterator { - CursorIterator { - 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) -> AncestorsIterator { - let current = Rc::clone(&self.node); - - AncestorsIterator { 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; - - 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 - let mut children = self.node.children(); - if !children.is_empty() { - self.node = children.remove(0); - self.child_index = 0; - - return true; - } - - false - } - - /// 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 mut children = self.node.children(); - if children.is_empty() { - return false; - } - - self.child_index = children.len() - 1; - self.node = children.remove(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; - } - - let mut children = self.node.children(); - if child_index + 1 > children.len() { - return false; - } - - self.node = children.remove(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; - }; - - let mut siblings = parent.children(); - let index = siblings - .iter() - .position(|parent_child| *parent_child == self.node) - .expect("did not find node in parent's children"); - if index + 1 >= siblings.len() { - return false; - } - self.child_index = index + 1; - self.node = siblings.remove(index + 1); - - 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; - }; - - let mut siblings = parent.children(); - let index = siblings - .iter() - .position(|parent_child| *parent_child == self.node) - .expect("did not find node in parent's children"); - if index == 0 { - return false; - } - self.child_index = index - 1; - self.node = siblings.remove(index - 1); - - 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 CursorIterator { - cursor: SyntaxCursor, -} - -impl Iterator for CursorIterator { - 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 AncestorsIterator { - current: Rc>, -} - -impl Iterator for AncestorsIterator { - 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 index 46616f727d..0ab62427c3 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -8,7 +8,6 @@ use crate::text_index::TextIndex; pub struct SyntaxNode { parent: Option>>, label: T::EdgeLabel, - text_offset: TextIndex, green: Node, } @@ -17,20 +16,10 @@ impl SyntaxNode { Rc::new(Self { parent: None, label: T::EdgeLabel::default(), - text_offset: TextIndex::ZERO, green: node, }) } - pub(crate) fn erase_root(&self) -> Rc { - Rc::new(Self { - parent: None, - label: self.label, - text_offset: self.text_offset, - green: self.green.clone(), - }) - } - /// 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 { @@ -59,22 +48,15 @@ impl SyntaxNode { self.green.text_len() } - pub fn text_offset(&self) -> TextIndex { - self.text_offset - } - /// 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()); - let mut text_offset = self.text_offset; for edge in self.green.children() { children.push(Rc::new(SyntaxNode { parent: Some(Rc::clone(self)), label: edge.label, - text_offset, green: edge.node.clone(), })); - text_offset += edge.node.text_len(); } children } From 8cd0dd5aa3880fd668f7f646620de0f9a02e870e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 3 Nov 2025 12:30:05 -0500 Subject: [PATCH 10/27] Avoid instantiating `SyntaxNode`s that will be dropped immediately --- crates/metaslang/cst/src/syntax_node.rs | 30 + .../src/backend/ir/common/_builder.rs.jinja2 | 63 +- .../ir1_structured_ast/builder.generated.rs | 2284 ++++++++--------- .../crate/src/backend/passes/p0_build_ast.rs | 2 +- .../backend/ir/ir1_structured_ast/builder.rs | 6 +- .../backend/ir/ir1_structured_ast/rewriter.rs | 4 +- .../backend/ir/ir1_structured_ast/visitor.rs | 2 +- 7 files changed, 1187 insertions(+), 1204 deletions(-) diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs index 0ab62427c3..154a39a799 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -61,6 +61,36 @@ impl SyntaxNode { 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(), + }) + } + /// Reconstructs the original source code from the node and its sub-tree. pub fn unparse(&self) -> String { self.green.unparse() 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 0102b67b5b..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 @@ -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" -%} @@ -51,7 +51,7 @@ } Some(Rc::new({{ parent_type }}Struct { - node: Rc::clone(node), + node, {%- for field in sequence.fields -%} {%- if not field.is_removed -%} {{ field.label }}, @@ -67,9 +67,10 @@ // {% 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") -%} @@ -105,10 +106,11 @@ // {% 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)); @@ -117,7 +119,7 @@ items.push(item); } {%- endif -%} - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -138,21 +140,21 @@ #[allow(dead_code)] #[inline] - fn terminal_node_cloned(node: &Rc) -> Rc { + fn terminal_node_cloned(node: Rc) -> Rc { assert!(node.is_terminal(), "expected terminal node"); - Rc::clone(node) + node } - struct ChildrenHelper { - children: Vec>, + struct ChildrenHelper<'a> { + children: &'a Rc, index: usize, } - impl ChildrenHelper { - fn new(children: Vec>) -> Self { + impl<'a> ChildrenHelper<'a> { + 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; @@ -160,26 +162,31 @@ Self { children, index } } - fn accept_label(&mut self, label: EdgeLabel) -> Option<&Rc> { - 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]; + 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/builder.generated.rs b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir1_structured_ast/builder.generated.rs index 3778ef3097..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 @@ -12,101 +12,82 @@ 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()); +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: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(PragmaDirectiveStruct { - node: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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()); +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.accept_label(EdgeLabel::Minus)?; + 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: Rc::clone(node), - 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(build_version_operator); @@ -116,31 +97,28 @@ pub fn build_version_term(node: &Rc) -> Option { } Some(Rc::new(VersionTermStruct { - node: Rc::clone(node), + 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)?; +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.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ImportDirectiveStruct { - node: Rc::clone(node), - 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()); +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) @@ -149,55 +127,47 @@ pub fn build_path_import(node: &Rc) -> Option { return None; } - Some(Rc::new(PathImportStruct { - node: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::FromKeyword)?; + 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: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseBrace)?; - _ = helper.accept_label(EdgeLabel::FromKeyword)?; + 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: Rc::clone(node), + 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) @@ -207,69 +177,63 @@ pub fn build_import_deconstruction_symbol( } Some(Rc::new(ImportDeconstructionSymbolStruct { - node: Rc::clone(node), + 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: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::ForKeyword)?; + 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: Rc::clone(node), + 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)?; +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.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(UsingDeconstructionStruct { - node: Rc::clone(node), - 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()); + 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) @@ -279,43 +243,40 @@ pub fn build_using_deconstruction_symbol( } Some(Rc::new(UsingDeconstructionSymbolStruct { - node: Rc::clone(node), + 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)?; +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: Rc::clone(node), - 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(helper.accept_label(EdgeLabel::Specifiers)?)?; - _ = helper.accept_label(EdgeLabel::OpenBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let members = build_contract_members(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(ContractDefinitionStruct { - node: Rc::clone(node), + node, abstract_keyword, name, specifiers, @@ -323,24 +284,21 @@ 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)?; +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: Rc::clone(node), - 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()); +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) @@ -350,162 +308,159 @@ pub fn build_inheritance_type(node: &Rc) -> Option } Some(Rc::new(InheritanceTypeStruct { - node: Rc::clone(node), + 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)?; +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: Rc::clone(node), - 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(build_inheritance_specifier); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let members = build_interface_members(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(InterfaceDefinitionStruct { - node: Rc::clone(node), + 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)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let members = build_library_members(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(LibraryDefinitionStruct { - node: Rc::clone(node), + 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)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let members = build_struct_members(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(StructDefinitionStruct { - node: Rc::clone(node), + node, name, members, })) } -pub fn build_struct_member(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StructMember); - let mut helper = ChildrenHelper::new(node.children()); +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: Rc::clone(node), + 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)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let members = build_enum_members(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(EnumDefinitionStruct { - node: Rc::clone(node), + node, name, members, })) } -pub fn build_constant_definition(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConstantDefinition); - let mut helper = ChildrenHelper::new(node.children()); +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.accept_label(EdgeLabel::ConstantKeyword)?; + helper.skip_label(EdgeLabel::ConstantKeyword)?; let name = terminal_node_cloned(helper.accept_label(EdgeLabel::Name)?); - _ = helper.accept_label(EdgeLabel::Equal)?; + helper.skip_label(EdgeLabel::Equal)?; let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ConstantDefinitionStruct { - node: Rc::clone(node), + 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()); +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(build_state_variable_definition_value); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(StateVariableDefinitionStruct { - node: Rc::clone(node), + node, type_name, attributes, name, @@ -514,26 +469,23 @@ pub fn build_state_variable_definition(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::StateVariableDefinitionValue); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::Equal)?; + 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: Rc::clone(node), - 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)?; +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)?)?; @@ -546,7 +498,7 @@ pub fn build_function_definition(node: &Rc) -> Option) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ParametersDeclaration); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenParen)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(ParametersDeclarationStruct { - node: Rc::clone(node), - 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()); +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) @@ -586,17 +535,17 @@ pub fn build_parameter(node: &Rc) -> Option { } Some(Rc::new(ParameterStruct { - node: Rc::clone(node), + 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(build_override_paths_declaration); @@ -604,47 +553,38 @@ pub fn build_override_specifier(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::OverridePathsDeclaration); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenParen)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(OverridePathsDeclarationStruct { - node: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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)?; +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)?)?; @@ -653,7 +593,7 @@ pub fn build_constructor_definition(node: &Rc) -> Option) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::UnnamedFunctionDefinition); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::FunctionKeyword)?; + 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)?)?; @@ -675,7 +615,7 @@ pub fn build_unnamed_function_definition( } Some(Rc::new(UnnamedFunctionDefinitionStruct { - node: Rc::clone(node), + node, parameters, attributes, body, @@ -683,11 +623,11 @@ 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)?; + 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)?)?; @@ -700,7 +640,7 @@ pub fn build_fallback_function_definition( } Some(Rc::new(FallbackFunctionDefinitionStruct { - node: Rc::clone(node), + node, parameters, attributes, returns, @@ -709,11 +649,11 @@ 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)?; + 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)?)?; @@ -723,17 +663,17 @@ pub fn build_receive_function_definition( } Some(Rc::new(ReceiveFunctionDefinitionStruct { - node: Rc::clone(node), + 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) @@ -745,7 +685,7 @@ pub fn build_modifier_definition(node: &Rc) -> Option) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ModifierInvocation); - let mut helper = ChildrenHelper::new(node.children()); +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) @@ -765,27 +705,27 @@ pub fn build_modifier_invocation(node: &Rc) -> Option) -> 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(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: Rc::clone(node), + node, name, parameters, anonymous_keyword, @@ -793,26 +733,26 @@ pub fn build_event_definition(node: &Rc) -> Option } pub fn build_event_parameters_declaration( - node: &Rc, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventParametersDeclaration); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenParen)?; + 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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(EventParametersDeclarationStruct { - node: Rc::clone(node), + node, parameters, })) } -pub fn build_event_parameter(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::EventParameter); - let mut helper = ChildrenHelper::new(node.children()); +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 @@ -823,7 +763,7 @@ pub fn build_event_parameter(node: &Rc) -> Option { } Some(Rc::new(EventParameterStruct { - node: Rc::clone(node), + node, type_name, indexed_keyword, name, @@ -831,65 +771,65 @@ pub fn build_event_parameter(node: &Rc) -> Option { } pub fn build_user_defined_value_type_definition( - node: &Rc, + 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)?; + helper.skip_label(EdgeLabel::IsKeyword)?; let value_type = build_elementary_type(helper.accept_label(EdgeLabel::ValueType)?)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(UserDefinedValueTypeDefinitionStruct { - node: Rc::clone(node), + 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(helper.accept_label(EdgeLabel::Members)?)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorDefinitionStruct { - node: Rc::clone(node), + 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)?; + 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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(ErrorParametersDeclarationStruct { - node: Rc::clone(node), + node, parameters, })) } -pub fn build_error_parameter(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ErrorParameter); - let mut helper = ChildrenHelper::new(node.children()); +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) @@ -899,36 +839,36 @@ pub fn build_error_parameter(node: &Rc) -> Option { } Some(Rc::new(ErrorParameterStruct { - node: Rc::clone(node), + node, type_name, name, })) } -pub fn build_array_type_name(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ArrayTypeName); - let mut helper = ChildrenHelper::new(node.children()); +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.accept_label(EdgeLabel::OpenBracket)?; + helper.skip_label(EdgeLabel::OpenBracket)?; let index = helper .accept_label(EdgeLabel::Index) .and_then(build_expression); - _ = helper.accept_label(EdgeLabel::CloseBracket)?; + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(ArrayTypeNameStruct { - node: Rc::clone(node), + 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)?; +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 @@ -939,36 +879,36 @@ pub fn build_function_type(node: &Rc) -> Option { } Some(Rc::new(FunctionTypeStruct { - node: Rc::clone(node), + 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)?; +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.accept_label(EdgeLabel::EqualGreaterThan)?; + helper.skip_label(EdgeLabel::EqualGreaterThan)?; let value_type = build_mapping_value(helper.accept_label(EdgeLabel::ValueType)?)?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(MappingTypeStruct { - node: Rc::clone(node), + 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()); +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) @@ -978,15 +918,15 @@ pub fn build_mapping_key(node: &Rc) -> Option { } Some(Rc::new(MappingKeyStruct { - node: Rc::clone(node), + 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()); +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) @@ -996,77 +936,68 @@ pub fn build_mapping_value(node: &Rc) -> Option { } Some(Rc::new(MappingValueStruct { - node: Rc::clone(node), + 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: Rc::clone(node), + 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)?; +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.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(BlockStruct { - node: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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()); +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.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ExpressionStatementStruct { - node: Rc::clone(node), - 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(build_string_literal); @@ -1079,47 +1010,44 @@ pub fn build_assembly_statement(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::AssemblyFlagsDeclaration); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenParen)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(AssemblyFlagsDeclarationStruct { - node: Rc::clone(node), - 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)?; + helper.skip_label(EdgeLabel::OpenParen)?; let elements = build_tuple_deconstruction_elements(helper.accept_label(EdgeLabel::Elements)?)?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - _ = helper.accept_label(EdgeLabel::Equal)?; + helper.skip_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::Equal)?; let expression = build_expression(helper.accept_label(EdgeLabel::Expression)?)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(TupleDeconstructionStatementStruct { - node: Rc::clone(node), + node, var_keyword, elements, expression, @@ -1127,10 +1055,10 @@ 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(build_tuple_member); @@ -1138,15 +1066,12 @@ pub fn build_tuple_deconstruction_element( return None; } - Some(Rc::new(TupleDeconstructionElementStruct { - node: Rc::clone(node), - 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()); +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) @@ -1157,16 +1082,16 @@ pub fn build_typed_tuple_member(node: &Rc) -> Option) -> 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(build_storage_location); @@ -1176,17 +1101,17 @@ pub fn build_untyped_tuple_member(node: &Rc) -> Option, + node: Rc, ) -> Option { - assert_nonterminal_kind(node, NonterminalKind::VariableDeclarationStatement); - let mut helper = ChildrenHelper::new(node.children()); + 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 @@ -1196,13 +1121,13 @@ pub fn build_variable_declaration_statement( let value = helper .accept_label(EdgeLabel::Value) .and_then(build_variable_declaration_value); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(VariableDeclarationStatementStruct { - node: Rc::clone(node), + node, variable_type, storage_location, name, @@ -1210,28 +1135,25 @@ 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)?; +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: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; let else_branch = helper .accept_label(EdgeLabel::ElseBranch) @@ -1241,47 +1163,44 @@ pub fn build_if_statement(node: &Rc) -> Option { } Some(Rc::new(IfStatementStruct { - node: Rc::clone(node), + 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)?; +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: Rc::clone(node), - 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)?; +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(build_expression); - _ = helper.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(ForStatementStruct { - node: Rc::clone(node), + node, initialization, condition, iterator, @@ -1289,114 +1208,107 @@ 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)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; let body = build_statement(helper.accept_label(EdgeLabel::Body)?)?; if !helper.finalize() { return None; } Some(Rc::new(WhileStatementStruct { - node: Rc::clone(node), + 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)?; +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.accept_label(EdgeLabel::WhileKeyword)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; + helper.skip_label(EdgeLabel::WhileKeyword)?; + helper.skip_label(EdgeLabel::OpenParen)?; let condition = build_expression(helper.accept_label(EdgeLabel::Condition)?)?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(DoWhileStatementStruct { - node: Rc::clone(node), + 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: Rc::clone(node), - })) + 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: Rc::clone(node), - })) + 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(build_expression); - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } - Some(Rc::new(ReturnStatementStruct { - node: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(EmitStatementStruct { - node: Rc::clone(node), + 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)?; +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) @@ -1408,7 +1320,7 @@ pub fn build_try_statement(node: &Rc) -> Option { } Some(Rc::new(TryStatementStruct { - node: Rc::clone(node), + node, expression, returns, body, @@ -1416,10 +1328,10 @@ 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(build_catch_clause_error); @@ -1428,16 +1340,12 @@ pub fn build_catch_clause(node: &Rc) -> Option { return None; } - Some(Rc::new(CatchClauseStruct { - node: Rc::clone(node), - 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); @@ -1447,49 +1355,47 @@ pub fn build_catch_clause_error(node: &Rc) -> Option) -> 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(build_identifier_path); let arguments = build_arguments_declaration(helper.accept_label(EdgeLabel::Arguments)?)?; - _ = helper.accept_label(EdgeLabel::Semicolon)?; + helper.skip_label(EdgeLabel::Semicolon)?; if !helper.finalize() { return None; } Some(Rc::new(RevertStatementStruct { - node: Rc::clone(node), + 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: Rc::clone(node), - })) + 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()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1498,70 +1404,70 @@ pub fn build_assignment_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ConditionalExpression); - let mut helper = ChildrenHelper::new(node.children()); +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.accept_label(EdgeLabel::QuestionMark)?; + helper.skip_label(EdgeLabel::QuestionMark)?; let true_expression = build_expression(helper.accept_label(EdgeLabel::TrueExpression)?)?; - _ = helper.accept_label(EdgeLabel::Colon)?; + 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: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::Operator)?; + 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: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::Operator)?; + 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: Rc::clone(node), + 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()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1570,16 +1476,16 @@ pub fn build_equality_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::InequalityExpression); - let mut helper = ChildrenHelper::new(node.children()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1588,67 +1494,67 @@ pub fn build_inequality_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::BitwiseOrExpression); - let mut helper = ChildrenHelper::new(node.children()); +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.accept_label(EdgeLabel::Operator)?; + 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: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::Operator)?; + 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: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::Operator)?; + 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: Rc::clone(node), + 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()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1657,16 +1563,16 @@ pub fn build_shift_expression(node: &Rc) -> Option } Some(Rc::new(ShiftExpressionStruct { - node: Rc::clone(node), + 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()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1675,16 +1581,16 @@ pub fn build_additive_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::MultiplicativeExpression); - let mut helper = ChildrenHelper::new(node.children()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1693,16 +1599,16 @@ pub fn build_multiplicative_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::ExponentiationExpression); - let mut helper = ChildrenHelper::new(node.children()); +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(helper.accept_label(EdgeLabel::RightOperand)?)?; @@ -1711,16 +1617,16 @@ pub fn build_exponentiation_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::PostfixExpression); - let mut helper = ChildrenHelper::new(node.children()); +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() { @@ -1728,15 +1634,15 @@ pub fn build_postfix_expression(node: &Rc) -> Option) -> 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(helper.accept_label(EdgeLabel::Operand)?)?; if !helper.finalize() { @@ -1744,15 +1650,15 @@ pub fn build_prefix_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::FunctionCallExpression); - let mut helper = ChildrenHelper::new(node.children()); +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() { @@ -1760,75 +1666,75 @@ pub fn build_function_call_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::CallOptionsExpression); - let mut helper = ChildrenHelper::new(node.children()); +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.accept_label(EdgeLabel::OpenBrace)?; + helper.skip_label(EdgeLabel::OpenBrace)?; let options = build_call_options(helper.accept_label(EdgeLabel::Options)?)?; - _ = helper.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } Some(Rc::new(CallOptionsExpressionStruct { - node: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::Period)?; + 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: Rc::clone(node), + 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()); +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.accept_label(EdgeLabel::OpenBracket)?; + helper.skip_label(EdgeLabel::OpenBracket)?; let start = helper .accept_label(EdgeLabel::Start) .and_then(build_expression); let end = helper .accept_label(EdgeLabel::End) .and_then(build_index_access_end); - _ = helper.accept_label(EdgeLabel::CloseBracket)?; + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } Some(Rc::new(IndexAccessExpressionStruct { - node: Rc::clone(node), + 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(build_expression); @@ -1836,134 +1742,112 @@ pub fn build_index_access_end(node: &Rc) -> Option { return None; } - Some(Rc::new(IndexAccessEndStruct { - node: Rc::clone(node), - 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)?; + 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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(PositionalArgumentsDeclarationStruct { - node: Rc::clone(node), + 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(build_named_argument_group); - _ = helper.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentsDeclarationStruct { - node: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentGroupStruct { - node: Rc::clone(node), - 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)?; + helper.skip_label(EdgeLabel::Colon)?; let value = build_expression(helper.accept_label(EdgeLabel::Value)?)?; if !helper.finalize() { return None; } - Some(Rc::new(NamedArgumentStruct { - node: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(TypeExpressionStruct { - node: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(TupleExpressionStruct { - node: Rc::clone(node), - 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(build_expression); @@ -1971,31 +1855,25 @@ pub fn build_tuple_value(node: &Rc) -> Option { return None; } - Some(Rc::new(TupleValueStruct { - node: Rc::clone(node), - 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)?; +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.accept_label(EdgeLabel::CloseBracket)?; + helper.skip_label(EdgeLabel::CloseBracket)?; if !helper.finalize() { return None; } - Some(Rc::new(ArrayExpressionStruct { - node: Rc::clone(node), - 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) @@ -2005,15 +1883,15 @@ pub fn build_hex_number_expression(node: &Rc) -> Option) -> 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) @@ -2023,32 +1901,29 @@ pub fn build_decimal_number_expression(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulBlock); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenBrace)?; +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.accept_label(EdgeLabel::CloseBrace)?; + helper.skip_label(EdgeLabel::CloseBrace)?; if !helper.finalize() { return None; } - Some(Rc::new(YulBlockStruct { - node: Rc::clone(node), - 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(helper.accept_label(EdgeLabel::Parameters)?)?; let returns = helper @@ -2060,7 +1935,7 @@ pub fn build_yul_function_definition(node: &Rc) -> Option) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulParametersDeclaration); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::OpenParen)?; +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.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } - Some(Rc::new(YulParametersDeclarationStruct { - node: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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)?; + 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) @@ -2114,17 +1983,17 @@ pub fn build_yul_variable_declaration_statement( } Some(Rc::new(YulVariableDeclarationStatementStruct { - node: Rc::clone(node), + 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()); + 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() { @@ -2132,17 +2001,17 @@ pub fn build_yul_variable_declaration_value( } Some(Rc::new(YulVariableDeclarationValueStruct { - node: Rc::clone(node), + 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()); + 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)?)?; @@ -2151,32 +2020,30 @@ pub fn build_yul_variable_assignment_statement( } Some(Rc::new(YulVariableAssignmentStatementStruct { - node: Rc::clone(node), + 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: Rc::clone(node), - })) + 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()); + 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)?); @@ -2185,30 +2052,28 @@ pub fn build_yul_stack_assignment_statement( } Some(Rc::new(YulStackAssignmentStatementStruct { - node: Rc::clone(node), + 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: Rc::clone(node), - })) + 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)?; +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() { @@ -2216,16 +2081,16 @@ pub fn build_yul_if_statement(node: &Rc) -> Option { } Some(Rc::new(YulIfStatementStruct { - node: Rc::clone(node), + 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)?; +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)?)?; @@ -2235,7 +2100,7 @@ pub fn build_yul_for_statement(node: &Rc) -> Option } Some(Rc::new(YulForStatementStruct { - node: Rc::clone(node), + node, initialization, condition, iterator, @@ -2243,10 +2108,10 @@ pub fn build_yul_for_statement(node: &Rc) -> Option })) } -pub fn build_yul_switch_statement(node: &Rc) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulSwitchStatement); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::SwitchKeyword)?; +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() { @@ -2254,113 +2119,97 @@ pub fn build_yul_switch_statement(node: &Rc) -> Option) -> Option { - assert_nonterminal_kind(node, NonterminalKind::YulDefaultCase); - let mut helper = ChildrenHelper::new(node.children()); - _ = helper.accept_label(EdgeLabel::DefaultKeyword)?; +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: Rc::clone(node), - 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)?; +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: Rc::clone(node), - 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: Rc::clone(node), - })) + 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: Rc::clone(node), - })) + 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: Rc::clone(node), - })) + 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: Rc::clone(node), - 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()); + assert_nonterminal_kind(&node, NonterminalKind::YulFunctionCallExpression); + let mut helper = ChildrenHelper::new(&node); let operand = build_yul_expression(helper.accept_label(EdgeLabel::Operand)?)?; - _ = helper.accept_label(EdgeLabel::OpenParen)?; + helper.skip_label(EdgeLabel::OpenParen)?; let arguments = build_yul_arguments(helper.accept_label(EdgeLabel::Arguments)?)?; - _ = helper.accept_label(EdgeLabel::CloseParen)?; + helper.skip_label(EdgeLabel::CloseParen)?; if !helper.finalize() { return None; } Some(Rc::new(YulFunctionCallExpressionStruct { - node: Rc::clone(node), + node, operand, arguments, })) @@ -2370,9 +2219,10 @@ 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) => { @@ -2429,9 +2279,10 @@ 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) => { @@ -2456,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, @@ -2476,9 +2328,10 @@ pub fn build_abicoder_version(node: &Rc) -> Option Some(item) } -pub fn build_experimental_feature(node: &Rc) -> 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) => { @@ -2503,9 +2356,10 @@ 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) => { @@ -2527,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, @@ -2552,9 +2407,10 @@ pub fn build_version_operator(node: &Rc) -> Option Some(item) } -pub fn build_version_literal(node: &Rc) -> 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) => { @@ -2579,9 +2435,10 @@ pub fn build_version_literal(node: &Rc) -> Option { Some(item) } -pub fn build_import_clause(node: &Rc) -> 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) => { @@ -2606,9 +2463,10 @@ 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) => { @@ -2630,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, @@ -2663,9 +2522,10 @@ 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) => { @@ -2685,9 +2545,10 @@ 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) => { @@ -2709,9 +2570,10 @@ 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) => { @@ -2768,9 +2630,10 @@ pub fn build_contract_member(node: &Rc) -> Option { Some(item) } -pub fn build_state_variable_attribute(node: &Rc) -> 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) => { @@ -2803,9 +2666,10 @@ pub fn build_state_variable_attribute(node: &Rc) -> Option) -> 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) => { @@ -2826,9 +2690,10 @@ 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) => { @@ -2859,9 +2724,10 @@ 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(variant)?), @@ -2879,9 +2745,10 @@ 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) => { @@ -2905,9 +2772,10 @@ 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) => { @@ -2944,11 +2812,12 @@ pub fn build_unnamed_function_attribute(node: &Rc) -> Option, + 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) => { @@ -2981,9 +2850,10 @@ 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) => { @@ -3014,9 +2884,10 @@ pub fn build_receive_function_attribute(node: &Rc) -> Option) -> 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) => { @@ -3036,9 +2907,10 @@ 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) => { @@ -3069,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, @@ -3095,9 +2968,10 @@ 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) => { @@ -3119,9 +2993,10 @@ pub fn build_mapping_key_type(node: &Rc) -> Option { Some(item) } -pub fn build_elementary_type(node: &Rc) -> 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) => { @@ -3158,9 +3033,10 @@ pub fn build_elementary_type(node: &Rc) -> Option { Some(item) } -pub fn build_statement(node: &Rc) -> 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) => { @@ -3225,9 +3101,10 @@ 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) => { @@ -3249,9 +3126,10 @@ 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) => { @@ -3271,9 +3149,10 @@ pub fn build_variable_declaration_type(node: &Rc) -> Option) -> 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, @@ -3292,11 +3171,12 @@ pub fn build_storage_location(node: &Rc) -> Option Some(item) } +#[allow(clippy::needless_pass_by_value)] pub fn build_for_statement_initialization( - node: &Rc, + 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) => { @@ -3326,9 +3206,10 @@ 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) => { @@ -3348,9 +3229,10 @@ 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) => { @@ -3455,9 +3337,10 @@ 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) => { @@ -3483,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, @@ -3512,9 +3396,10 @@ 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) => { @@ -3545,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) => { @@ -3569,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) => { @@ -3593,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) => { @@ -3617,9 +3505,10 @@ 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) => { @@ -3680,9 +3569,10 @@ 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) => { @@ -3702,11 +3592,12 @@ 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) => { @@ -3726,9 +3617,10 @@ 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) => { @@ -3750,9 +3642,10 @@ pub fn build_yul_switch_case(node: &Rc) -> Option { Some(item) } -pub fn build_yul_expression(node: &Rc) -> 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) => { @@ -3777,9 +3670,10 @@ 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) => { @@ -3813,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3829,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3845,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3861,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; @@ -3875,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3893,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3911,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3927,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3943,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3959,15 +3862,16 @@ pub fn build_contract_members(node: &Rc) -> Option Some(items) } -pub fn build_interface_members(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3975,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -3991,15 +3896,16 @@ pub fn build_library_members(node: &Rc) -> Option { Some(items) } -pub fn build_struct_members(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4007,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; @@ -4021,15 +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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4037,15 +3945,16 @@ pub fn build_state_variable_attributes(node: &Rc) -> Option) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4053,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4069,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4085,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4101,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4119,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4137,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4155,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4171,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4187,15 +4104,16 @@ pub fn build_event_parameters(node: &Rc) -> Option Some(items) } -pub fn build_error_parameters(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4203,15 +4121,16 @@ pub fn build_error_parameters(node: &Rc) -> Option Some(items) } -pub fn build_function_type_attributes(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4219,15 +4138,16 @@ pub fn build_function_type_attributes(node: &Rc) -> Option) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4235,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4251,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4269,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4285,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4301,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4317,15 +4242,16 @@ pub fn build_named_arguments(node: &Rc) -> Option { Some(items) } -pub fn build_call_options(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4333,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4349,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4365,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4381,15 +4310,16 @@ pub fn build_string_literals(node: &Rc) -> Option { Some(items) } -pub fn build_hex_string_literals(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4397,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4413,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; @@ -4427,15 +4359,16 @@ pub fn build_identifier_path(node: &Rc) -> Option { Some(items) } -pub fn build_yul_statements(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4443,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; @@ -4457,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; @@ -4471,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4487,15 +4423,16 @@ pub fn build_yul_switch_cases(node: &Rc) -> Option { Some(items) } -pub fn build_yul_arguments(node: &Rc) -> 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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4503,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(child) { items.push(item); } - _ = helper.accept_label(EdgeLabel::Separator); + helper.skip_label(EdgeLabel::Separator); } if !helper.finalize() { return None; @@ -4519,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; @@ -4549,21 +4488,21 @@ fn assert_nonterminal_kind(node: &Rc, kind: NonterminalKind) { #[allow(dead_code)] #[inline] -fn terminal_node_cloned(node: &Rc) -> Rc { +fn terminal_node_cloned(node: Rc) -> Rc { assert!(node.is_terminal(), "expected terminal node"); - Rc::clone(node) + node } -struct ChildrenHelper { - children: Vec>, +struct ChildrenHelper<'a> { + children: &'a Rc, index: usize, } -impl ChildrenHelper { - fn new(children: Vec>) -> Self { +impl<'a> ChildrenHelper<'a> { + 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; @@ -4571,27 +4510,34 @@ impl ChildrenHelper { Self { children, index } } - fn accept_label(&mut self, label: EdgeLabel) -> Option<&Rc> { - 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]; + 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/passes/p0_build_ast.rs b/crates/solidity/outputs/cargo/crate/src/backend/passes/p0_build_ast.rs index 81a385cd0d..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.syntax_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/tests/src/backend/ir/ir1_structured_ast/builder.rs b/crates/solidity/outputs/cargo/tests/src/backend/ir/ir1_structured_ast/builder.rs index a4b83c976f..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.syntax_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.syntax_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.syntax_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 4e9d8bd9ad..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 @@ -32,7 +32,7 @@ contract MyContract { ); assert!(output.is_valid()); - let source = ir1_structured_ast::builder::build_source_unit(&output.syntax_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); @@ -169,7 +169,7 @@ function weeksToSeconds(uint _weeks) returns (uint) { ); assert!(output.is_valid()); - let source = ir1_structured_ast::builder::build_source_unit(&output.syntax_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 df5034a624..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.syntax_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); From b129a18f3c183480eae8f4f991ad355a14591bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 3 Nov 2025 18:28:21 -0500 Subject: [PATCH 11/27] Add module to IR language to index the nodes in a tree --- .../src/backend/ir/common/_index.rs.jinja2 | 95 + .../ir/ir2_flat_contracts/index.generated.rs | 1625 +++++++++++++++++ .../ir/ir2_flat_contracts/index.rs.jinja2 | 2 + .../src/backend/ir/ir2_flat_contracts/mod.rs | 2 + 4 files changed, 1724 insertions(+) create mode 100644 crates/solidity/outputs/cargo/crate/src/backend/ir/common/_index.rs.jinja2 create mode 100644 crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.generated.rs create mode 100644 crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.rs.jinja2 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..f839f4728f --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_index.rs.jinja2 @@ -0,0 +1,95 @@ +{% 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; + + // + // 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/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..96e8660929 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/backend/ir/ir2_flat_contracts/index.generated.rs @@ -0,0 +1,1625 @@ +// 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; + +// +// 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"] From 40cb165849cdc66723f0441abf32a705bf980975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 3 Nov 2025 18:41:11 -0500 Subject: [PATCH 12/27] Add backend pass to index output IR tree nodes --- .../outputs/cargo/crate/src/backend/mod.rs | 5 ++- .../cargo/crate/src/backend/passes/mod.rs | 1 + .../crate/src/backend/passes/p6_index_tree.rs | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 crates/solidity/outputs/cargo/crate/src/backend/passes/p6_index_tree.rs diff --git a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs index 3b1b1f6b21..5ce3b0d7c3 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs @@ -8,7 +8,7 @@ pub mod ir; pub mod passes; pub mod types; -pub type BinderOutput = passes::p5_resolve_references::Output; +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 +16,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/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, + } +} From 422423f4c2c1cf3e07bcf52719616b5298e6a955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Tue, 4 Nov 2025 17:13:11 -0500 Subject: [PATCH 13/27] Update public_api.txt to appease CI --- crates/solidity/outputs/cargo/crate/generated/public_api.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/solidity/outputs/cargo/crate/generated/public_api.txt b/crates/solidity/outputs/cargo/crate/generated/public_api.txt index aa3feb773c..901eb2449f 100644 --- a/crates/solidity/outputs/cargo/crate/generated/public_api.txt +++ b/crates/solidity/outputs/cargo/crate/generated/public_api.txt @@ -33,6 +33,7 @@ impl slang_solidity::compilation::File pub fn slang_solidity::compilation::File::create_tree_cursor(&self) -> slang_solidity::cst::Cursor pub fn slang_solidity::compilation::File::errors(&self) -> &alloc::vec::Vec pub fn slang_solidity::compilation::File::id(&self) -> &str +pub fn slang_solidity::compilation::File::syntax_tree(&self) -> alloc::rc::Rc pub fn slang_solidity::compilation::File::tree(&self) -> &alloc::rc::Rc impl core::clone::Clone for slang_solidity::compilation::File pub fn slang_solidity::compilation::File::clone(&self) -> slang_solidity::compilation::File @@ -1358,6 +1359,7 @@ pub type slang_solidity::cst::NonterminalNode = metaslang_cst::nodes::Nontermina pub type slang_solidity::cst::Query = metaslang_cst::query::model::Query pub type slang_solidity::cst::QueryMatch = metaslang_cst::query::engine::QueryMatch pub type slang_solidity::cst::QueryMatchIterator = metaslang_cst::query::engine::QueryMatchIterator +pub type slang_solidity::cst::SyntaxNode = metaslang_cst::syntax_node::SyntaxNode pub type slang_solidity::cst::TerminalNode = metaslang_cst::nodes::TerminalNode pub type slang_solidity::cst::TextIndex = metaslang_cst::text_index::TextIndex pub type slang_solidity::cst::TextRange = metaslang_cst::text_index::TextRange @@ -1388,6 +1390,7 @@ impl slang_solidity::parser::ParseOutput pub fn slang_solidity::parser::ParseOutput::create_tree_cursor(&self) -> slang_solidity::cst::Cursor pub fn slang_solidity::parser::ParseOutput::errors(&self) -> &alloc::vec::Vec pub fn slang_solidity::parser::ParseOutput::is_valid(&self) -> bool +pub fn slang_solidity::parser::ParseOutput::syntax_tree(&self) -> alloc::rc::Rc pub fn slang_solidity::parser::ParseOutput::tree(&self) -> &alloc::rc::Rc impl core::clone::Clone for slang_solidity::parser::ParseOutput pub fn slang_solidity::parser::ParseOutput::clone(&self) -> slang_solidity::parser::ParseOutput From 0ba7a95d0416d4ece45421e0545f7ba416eb61b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Tue, 4 Nov 2025 17:24:47 -0500 Subject: [PATCH 14/27] Restore `SyntaxCursor` implementation --- crates/metaslang/cst/src/lib.rs | 4 + crates/metaslang/cst/src/query/mod.rs | 2 + .../metaslang/cst/src/query/syntax_engine.rs | 826 ++++++++++++++++++ crates/metaslang/cst/src/syntax_cursor.rs | 374 ++++++++ crates/metaslang/cst/src/syntax_node.rs | 8 + .../outputs/cargo/crate/src/cst/mod.rs | 9 + 6 files changed, 1223 insertions(+) create mode 100644 crates/metaslang/cst/src/query/syntax_engine.rs create mode 100644 crates/metaslang/cst/src/syntax_cursor.rs diff --git a/crates/metaslang/cst/src/lib.rs b/crates/metaslang/cst/src/lib.rs index d5ba7e51c6..4b9e7c3d9c 100644 --- a/crates/metaslang/cst/src/lib.rs +++ b/crates/metaslang/cst/src/lib.rs @@ -11,3 +11,7 @@ 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..654654c399 100644 --- a/crates/metaslang/cst/src/query/mod.rs +++ b/crates/metaslang/cst/src/query/mod.rs @@ -3,7 +3,9 @@ mod engine; mod model; mod parser; +mod syntax_engine; pub use engine::{Capture, QueryMatch, QueryMatchIterator}; pub use model::Query; pub use parser::{CaptureQuantifier, QueryError}; +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..58bbb8d0cd --- /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 [`Capture`] contains the capture name, + /// and a list of [`Cursor`]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 [`Capture`] containing the capture name, + /// and a list of [`Cursor`]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 [`Cursor`]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..9dc33984a3 --- /dev/null +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -0,0 +1,374 @@ +//! 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(node: Rc>) -> Self { + Self { + node, + child_index: 0, + 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 [`Node`]. + 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; + + 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 + let mut children = self.node.children(); + if !children.is_empty() { + self.node = children.remove(0); + self.child_index = 0; + + return true; + } + + false + } + + /// 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 mut children = self.node.children(); + if children.is_empty() { + return false; + } + + self.child_index = children.len() - 1; + self.node = children.remove(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; + } + + let mut children = self.node.children(); + if child_index + 1 > children.len() { + return false; + } + + self.node = children.remove(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; + }; + + let mut siblings = parent.children(); + let index = siblings + .iter() + .position(|parent_child| *parent_child == self.node) + .expect("did not find node in parent's children"); + if index + 1 >= siblings.len() { + return false; + } + self.child_index = index + 1; + self.node = siblings.remove(index + 1); + + 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; + }; + + let mut siblings = parent.children(); + let index = siblings + .iter() + .position(|parent_child| *parent_child == self.node) + .expect("did not find node in parent's children"); + if index == 0 { + return false; + } + self.child_index = index - 1; + self.node = siblings.remove(index - 1); + + 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 index 154a39a799..44ce46fdc2 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -20,6 +20,14 @@ impl SyntaxNode { }) } + pub(crate) fn erase_root(&self) -> Rc { + Rc::new(Self { + parent: None, + label: self.label, + green: self.green.clone(), + }) + } + /// 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 { diff --git a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs index 8d516daa69..eb8e6a17f8 100644 --- a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs @@ -71,6 +71,15 @@ 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 cursor that can traverse a CST using `SyntaxNodes`. +/// +/// Nodes are visited in a DFS pre-order traversal. +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. +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. +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. /// From 3bf0720bc9cc946a7126b8917dbbfb762ae7332a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 10:51:01 -0500 Subject: [PATCH 15/27] Implement an `IntoIr` for IR types to map them from `SyntaxNode`s --- .../src/backend/ir/common/_index.rs.jinja2 | 18 + .../ir/ir2_flat_contracts/index.generated.rs | 1276 +++++++++++++++++ 2 files changed, 1294 insertions(+) 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 index f839f4728f..1c109f6ce9 100644 --- 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 @@ -15,6 +15,24 @@ 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: // 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 index 96e8660929..57607f4d78 100644 --- 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 @@ -118,6 +118,1282 @@ pub enum NodeType { 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: // From 14e63990f9ad824ca58adde201a9e557f176d41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 11:22:55 -0500 Subject: [PATCH 16/27] Improve `SyntaxCursor` implementation --- crates/metaslang/cst/src/syntax_cursor.rs | 54 +++++++++-------------- crates/metaslang/cst/src/syntax_node.rs | 29 +++++++++--- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs index 9dc33984a3..a1579b37bb 100644 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -21,10 +21,11 @@ pub struct SyntaxCursor { } impl SyntaxCursor { - pub fn create(node: Rc>) -> Self { + pub fn create_from(node: Rc>) -> Self { + let child_index = node.index_in_parent().unwrap_or(0usize); Self { node, - child_index: 0, + child_index, is_completed: false, } } @@ -178,15 +179,13 @@ impl SyntaxCursor { } // If the current cursor is a node and it has children, go to first children - let mut children = self.node.children(); - if !children.is_empty() { - self.node = children.remove(0); - self.child_index = 0; - - return true; + if self.node.children_count() == 0 { + return false; } - false + self.node = self.node.nth_child(0); + self.child_index = 0; + true } /// Attempts to go to current node's last child. @@ -197,13 +196,13 @@ impl SyntaxCursor { return false; } - let mut children = self.node.children(); - if children.is_empty() { + let children_count = self.node.children_count(); + if children_count == 0 { return false; } - self.child_index = children.len() - 1; - self.node = children.remove(self.child_index); + self.child_index = children_count - 1; + self.node = self.node.nth_child(self.child_index); true } @@ -216,12 +215,11 @@ impl SyntaxCursor { return false; } - let mut children = self.node.children(); - if child_index + 1 > children.len() { + if child_index + 1 > self.node.children_count() { return false; } - self.node = children.remove(child_index); + self.node = self.node.nth_child(child_index); self.child_index = child_index; false @@ -239,16 +237,12 @@ impl SyntaxCursor { return false; }; - let mut siblings = parent.children(); - let index = siblings - .iter() - .position(|parent_child| *parent_child == self.node) - .expect("did not find node in parent's children"); - if index + 1 >= siblings.len() { + if self.child_index + 1 >= parent.children_count() { return false; } - self.child_index = index + 1; - self.node = siblings.remove(index + 1); + + self.child_index += 1; + self.node = parent.nth_child(self.child_index); true } @@ -265,16 +259,12 @@ impl SyntaxCursor { return false; }; - let mut siblings = parent.children(); - let index = siblings - .iter() - .position(|parent_child| *parent_child == self.node) - .expect("did not find node in parent's children"); - if index == 0 { + if self.child_index == 0 { return false; } - self.child_index = index - 1; - self.node = siblings.remove(index - 1); + + self.child_index -= 1; + self.node = parent.nth_child(self.child_index); true } diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs index 44ce46fdc2..604577e01d 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -20,12 +20,16 @@ impl SyntaxNode { }) } - pub(crate) fn erase_root(&self) -> Rc { - Rc::new(Self { - parent: None, - label: self.label, - green: self.green.clone(), - }) + 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 @@ -99,6 +103,19 @@ impl SyntaxNode { }) } + 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() From a5739aea2bd0117ef3322ae56e773fe8816bbb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 11:25:19 -0500 Subject: [PATCH 17/27] Update public_api.txt --- crates/metaslang/cst/src/query/mod.rs | 6 +++++- .../solidity/outputs/cargo/crate/generated/public_api.txt | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/metaslang/cst/src/query/mod.rs b/crates/metaslang/cst/src/query/mod.rs index 654654c399..43f113bd45 100644 --- a/crates/metaslang/cst/src/query/mod.rs +++ b/crates/metaslang/cst/src/query/mod.rs @@ -3,9 +3,13 @@ mod engine; mod model; mod parser; -mod syntax_engine; 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/solidity/outputs/cargo/crate/generated/public_api.txt b/crates/solidity/outputs/cargo/crate/generated/public_api.txt index 901eb2449f..6ff1b6e484 100644 --- a/crates/solidity/outputs/cargo/crate/generated/public_api.txt +++ b/crates/solidity/outputs/cargo/crate/generated/public_api.txt @@ -1359,6 +1359,9 @@ pub type slang_solidity::cst::NonterminalNode = metaslang_cst::nodes::Nontermina pub type slang_solidity::cst::Query = metaslang_cst::query::model::Query pub type slang_solidity::cst::QueryMatch = metaslang_cst::query::engine::QueryMatch pub type slang_solidity::cst::QueryMatchIterator = metaslang_cst::query::engine::QueryMatchIterator +pub type slang_solidity::cst::SyntaxAncestorsIterator = metaslang_cst::syntax_cursor::SyntaxAncestorsIterator +pub type slang_solidity::cst::SyntaxCursor = metaslang_cst::syntax_cursor::SyntaxCursor +pub type slang_solidity::cst::SyntaxCursorIterator = metaslang_cst::syntax_cursor::SyntaxCursorIterator pub type slang_solidity::cst::SyntaxNode = metaslang_cst::syntax_node::SyntaxNode pub type slang_solidity::cst::TerminalNode = metaslang_cst::nodes::TerminalNode pub type slang_solidity::cst::TextIndex = metaslang_cst::text_index::TextIndex From ba7d957cf5b95e3aba2ea44fb1e8e797172d2ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 12:02:32 -0500 Subject: [PATCH 18/27] Fix `rustdoc` errors --- crates/metaslang/cst/src/query/syntax_engine.rs | 10 +++++----- crates/metaslang/cst/src/syntax_cursor.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/metaslang/cst/src/query/syntax_engine.rs b/crates/metaslang/cst/src/query/syntax_engine.rs index 58bbb8d0cd..8d0210b7ca 100644 --- a/crates/metaslang/cst/src/query/syntax_engine.rs +++ b/crates/metaslang/cst/src/query/syntax_engine.rs @@ -183,8 +183,8 @@ impl SyntaxQueryMatch { self.query().capture_quantifiers().keys() } - /// Returns an iterator over all of the captures matched by this query. Each [`Capture`] contains the capture name, - /// and a list of [`Cursor`]s to the location of each captured node in the parse tree. + /// 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) { @@ -198,8 +198,8 @@ impl SyntaxQueryMatch { /// 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 [`Capture`] containing the capture name, - /// and a list of [`Cursor`]s to the location of each captured node in the parse tree. + /// 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() @@ -217,7 +217,7 @@ impl SyntaxQueryMatch { } /// A single capture matched by a query, containing the capture name, -/// and a list of [`Cursor`]s to the location of each captured node in the parse tree. +/// 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], diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs index a1579b37bb..25e14ff861 100644 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -62,7 +62,7 @@ impl SyntaxCursor { self.is_completed } - /// Returns the currently pointed to [`Node`]. + /// Returns the currently pointed to [`SyntaxNode`]. pub fn node(&self) -> Rc> { Rc::clone(&self.node) } From 02469b572a3de915b337bcaa1554fd5400617795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 13:26:00 -0500 Subject: [PATCH 19/27] Fix `SyntaxCursor::go_to_parent()` --- crates/metaslang/cst/src/syntax_cursor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/metaslang/cst/src/syntax_cursor.rs b/crates/metaslang/cst/src/syntax_cursor.rs index 25e14ff861..13c3b90f64 100644 --- a/crates/metaslang/cst/src/syntax_cursor.rs +++ b/crates/metaslang/cst/src/syntax_cursor.rs @@ -161,6 +161,7 @@ impl SyntaxCursor { 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 { From 54e8ddfd7ef239dc4788727da6b92ae060b1d6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 5 Nov 2025 15:45:02 -0500 Subject: [PATCH 20/27] Tidy up feature flag for using `SyntaxNode` and put them under `__private_backend_api` --- crates/solidity/outputs/cargo/crate/Cargo.toml | 4 ++-- .../outputs/cargo/crate/generated/public_api.txt | 6 ------ .../outputs/cargo/crate/src/compilation/file.rs | 6 +++++- crates/solidity/outputs/cargo/crate/src/cst/mod.rs | 11 ++++++----- .../outputs/cargo/crate/src/parser/parse_output.rs | 6 +++++- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/solidity/outputs/cargo/crate/Cargo.toml b/crates/solidity/outputs/cargo/crate/Cargo.toml index eff59d4ed7..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"] @@ -35,7 +35,7 @@ __private_testing_utils = ["metaslang_bindings/__private_testing_utils"] ariadne = { workspace = true, optional = true } indexmap = { workspace = true, optional = true } metaslang_bindings = { workspace = true } -metaslang_cst = { workspace = true, features = ["syntax"] } +metaslang_cst = { workspace = true } semver = { workspace = true } serde = { workspace = true } strum = { workspace = true } diff --git a/crates/solidity/outputs/cargo/crate/generated/public_api.txt b/crates/solidity/outputs/cargo/crate/generated/public_api.txt index 6ff1b6e484..aa3feb773c 100644 --- a/crates/solidity/outputs/cargo/crate/generated/public_api.txt +++ b/crates/solidity/outputs/cargo/crate/generated/public_api.txt @@ -33,7 +33,6 @@ impl slang_solidity::compilation::File pub fn slang_solidity::compilation::File::create_tree_cursor(&self) -> slang_solidity::cst::Cursor pub fn slang_solidity::compilation::File::errors(&self) -> &alloc::vec::Vec pub fn slang_solidity::compilation::File::id(&self) -> &str -pub fn slang_solidity::compilation::File::syntax_tree(&self) -> alloc::rc::Rc pub fn slang_solidity::compilation::File::tree(&self) -> &alloc::rc::Rc impl core::clone::Clone for slang_solidity::compilation::File pub fn slang_solidity::compilation::File::clone(&self) -> slang_solidity::compilation::File @@ -1359,10 +1358,6 @@ pub type slang_solidity::cst::NonterminalNode = metaslang_cst::nodes::Nontermina pub type slang_solidity::cst::Query = metaslang_cst::query::model::Query pub type slang_solidity::cst::QueryMatch = metaslang_cst::query::engine::QueryMatch pub type slang_solidity::cst::QueryMatchIterator = metaslang_cst::query::engine::QueryMatchIterator -pub type slang_solidity::cst::SyntaxAncestorsIterator = metaslang_cst::syntax_cursor::SyntaxAncestorsIterator -pub type slang_solidity::cst::SyntaxCursor = metaslang_cst::syntax_cursor::SyntaxCursor -pub type slang_solidity::cst::SyntaxCursorIterator = metaslang_cst::syntax_cursor::SyntaxCursorIterator -pub type slang_solidity::cst::SyntaxNode = metaslang_cst::syntax_node::SyntaxNode pub type slang_solidity::cst::TerminalNode = metaslang_cst::nodes::TerminalNode pub type slang_solidity::cst::TextIndex = metaslang_cst::text_index::TextIndex pub type slang_solidity::cst::TextRange = metaslang_cst::text_index::TextRange @@ -1393,7 +1388,6 @@ impl slang_solidity::parser::ParseOutput pub fn slang_solidity::parser::ParseOutput::create_tree_cursor(&self) -> slang_solidity::cst::Cursor pub fn slang_solidity::parser::ParseOutput::errors(&self) -> &alloc::vec::Vec pub fn slang_solidity::parser::ParseOutput::is_valid(&self) -> bool -pub fn slang_solidity::parser::ParseOutput::syntax_tree(&self) -> alloc::rc::Rc pub fn slang_solidity::parser::ParseOutput::tree(&self) -> &alloc::rc::Rc impl core::clone::Clone for slang_solidity::parser::ParseOutput pub fn slang_solidity::parser::ParseOutput::clone(&self) -> slang_solidity::parser::ParseOutput diff --git a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs index 692b2021bc..4edd8b573d 100644 --- a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs +++ b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs @@ -4,9 +4,12 @@ use std::rc::Rc; use metaslang_cst::nodes::NodeId; use metaslang_cst::text_index::TextIndex; -use crate::cst::{Cursor, Node, NonterminalNode, SyntaxNode}; +use crate::cst::{Cursor, Node, NonterminalNode}; use crate::parser::{ParseError, ParseOutput}; +#[cfg(feature = "__private_backend_api")] +use crate::cst::SyntaxNode; + /// A single source file in the compilation unit. #[derive(Clone)] pub struct File { @@ -41,6 +44,7 @@ impl File { } /// Returns the root syntax node of the parse tree. + #[cfg(feature = "__private_backend_api")] pub fn syntax_tree(&self) -> Rc { SyntaxNode::create_root(Node::Nonterminal(Rc::clone(&self.tree))) } diff --git a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs index eb8e6a17f8..37245cf080 100644 --- a/crates/solidity/outputs/cargo/crate/src/cst/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/cst/mod.rs @@ -59,9 +59,6 @@ pub type TerminalNode = metaslang_cst::nodes::TerminalNode; /// Represents a connection between nodes in the syntax tree. pub type Edge = metaslang_cst::nodes::Edge; -/// A node reference that can be navigated to the parent or its children -pub type SyntaxNode = metaslang_cst::syntax_node::SyntaxNode; - /// A cursor that can traverse a CST. /// /// Nodes are visited in a DFS pre-order traversal. @@ -71,13 +68,17 @@ 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`. -/// -/// Nodes are visited in a DFS pre-order traversal. +#[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`] 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 77964c5ddf..8779a571d3 100644 --- a/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs +++ b/crates/solidity/outputs/cargo/crate/src/parser/parse_output.rs @@ -1,8 +1,11 @@ use std::rc::Rc; -use crate::cst::{Cursor, Node, NonterminalNode, SyntaxNode, TextIndex}; +use crate::cst::{Cursor, Node, NonterminalNode, TextIndex}; use crate::parser::ParseError; +#[cfg(feature = "__private_backend_api")] +use crate::cst::SyntaxNode; + /// The result of parsing source code using [`Parser`][`crate::parser::Parser`]. /// /// ``` @@ -50,6 +53,7 @@ impl ParseOutput { } /// Returns the root syntax node of the parse tree. + #[cfg(feature = "__private_backend_api")] pub fn syntax_tree(&self) -> Rc { SyntaxNode::create_root(Node::Nonterminal(Rc::clone(&self.tree))) } From e2aa5ad9912bd0bcf0240600f7b12f1aede9f32c Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Tue, 11 Nov 2025 13:46:48 -0300 Subject: [PATCH 21/27] Partial commit --- crates/metaslang/cst/src/syntax_node.rs | 11 + .../tests/src/ast_api/collect_definitions.rs | 53 + .../cargo/tests/src/ast_api/collect_nodes.rs | 1138 +++++++++++++++++ .../src/ast_api/find_unused_definitions.rs | 146 +++ .../src/ast_api/follow_all_references.rs | 21 + .../outputs/cargo/tests/src/ast_api/mod.rs | 54 + .../cargo/tests/src/ast_api/pipeline.rs | 59 + .../ast_api/test_find_unused_definitions.rs | 49 + .../tests/src/ast_api/visit_definition.rs | 169 +++ 9 files changed, 1700 insertions(+) create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/find_unused_definitions.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/follow_all_references.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/test_find_unused_definitions.rs create mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs diff --git a/crates/metaslang/cst/src/syntax_node.rs b/crates/metaslang/cst/src/syntax_node.rs index 604577e01d..a2dc7953b6 100644 --- a/crates/metaslang/cst/src/syntax_node.rs +++ b/crates/metaslang/cst/src/syntax_node.rs @@ -1,5 +1,6 @@ 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; @@ -216,4 +217,14 @@ impl SyntaxNode { 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/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..b536e477b9 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs @@ -0,0 +1,53 @@ +use std::collections::{HashMap, HashSet}; + +use slang_solidity::backend::binder::{Binder, Definition}; +use slang_solidity::compilation::CompilationUnit; +use slang_solidity::cst::{Cursor, Node, NodeId, TerminalKindExtensions}; + +pub(crate) fn collect_all_definitions<'a>( + compilation_unit: &'a CompilationUnit, + binder: &'a Binder, +) -> Vec<&'a Definition> { + let mut all_definitions = vec![]; + for file in compilation_unit.files() { + let cursor = file.create_tree_cursor(); + all_definitions.append(&mut collect_definitions(binder, &cursor)); + } + all_definitions +} + +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 +} + +pub(crate) fn map_definitions_ids<'a>( + compilation_unit: &'a CompilationUnit, + binder: &'a Binder, +) -> HashMap { + let mut result = HashMap::new(); + + let definitions = collect_all_definitions(compilation_unit, binder); + let definitions_ids: HashSet<_> = definitions.iter().map(|def| def.node_id()).collect(); + + for file in compilation_unit.files() { + let mut cursor = file.create_tree_cursor(); + while cursor.go_to_next() { + let node = cursor.node(); + if definitions_ids.contains(&node.id()) { + result.insert(node.id(), node); + } + } + } + result +} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs new file mode 100644 index 0000000000..f2e0ba16ef --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs @@ -0,0 +1,1138 @@ +use std::collections::HashMap; +use std::rc::Rc; + +use slang_solidity::backend::l2_flat_contracts::visitor::Visitor; +use slang_solidity::backend::l2_flat_contracts::*; +use slang_solidity::cst::NodeId; + +#[derive(Default, Debug)] +pub(crate) struct NodesMap { + pub(crate) map: HashMap, +} + +impl Visitor for NodesMap { + fn enter_source_unit(&mut self, node: &SourceUnit) -> bool { + self.map + .insert(node.node_id, Node::SourceUnit(Rc::clone(node))); + true + } + + fn enter_pragma_directive(&mut self, node: &PragmaDirective) -> bool { + self.map + .insert(node.node_id, Node::PragmaDirective(Rc::clone(node))); + true + } + + fn enter_abicoder_pragma(&mut self, node: &AbicoderPragma) -> bool { + self.map + .insert(node.node_id, Node::AbicoderPragma(Rc::clone(node))); + true + } + + fn enter_experimental_pragma(&mut self, node: &ExperimentalPragma) -> bool { + self.map + .insert(node.node_id, Node::ExperimentalPragma(Rc::clone(node))); + true + } + + fn enter_version_pragma(&mut self, node: &VersionPragma) -> bool { + self.map + .insert(node.node_id, Node::VersionPragma(Rc::clone(node))); + true + } + + fn enter_version_range(&mut self, node: &VersionRange) -> bool { + self.map + .insert(node.node_id, Node::VersionRange(Rc::clone(node))); + true + } + + fn enter_version_term(&mut self, node: &VersionTerm) -> bool { + self.map + .insert(node.node_id, Node::VersionTerm(Rc::clone(node))); + true + } + + fn enter_import_directive(&mut self, node: &ImportDirective) -> bool { + self.map + .insert(node.node_id, Node::ImportDirective(Rc::clone(node))); + true + } + + fn enter_path_import(&mut self, node: &PathImport) -> bool { + self.map + .insert(node.node_id, Node::PathImport(Rc::clone(node))); + true + } + + fn enter_named_import(&mut self, node: &NamedImport) -> bool { + self.map + .insert(node.node_id, Node::NamedImport(Rc::clone(node))); + true + } + + fn enter_import_deconstruction(&mut self, node: &ImportDeconstruction) -> bool { + self.map + .insert(node.node_id, Node::ImportDeconstruction(Rc::clone(node))); + true + } + + fn enter_import_deconstruction_symbol(&mut self, node: &ImportDeconstructionSymbol) -> bool { + self.map.insert( + node.node_id, + Node::ImportDeconstructionSymbol(Rc::clone(node)), + ); + true + } + + fn enter_import_alias(&mut self, node: &ImportAlias) -> bool { + self.map + .insert(node.node_id, Node::ImportAlias(Rc::clone(node))); + true + } + + fn enter_using_directive(&mut self, node: &UsingDirective) -> bool { + self.map + .insert(node.node_id, Node::UsingDirective(Rc::clone(node))); + true + } + + fn enter_using_deconstruction(&mut self, node: &UsingDeconstruction) -> bool { + self.map + .insert(node.node_id, Node::UsingDeconstruction(Rc::clone(node))); + true + } + + fn enter_using_deconstruction_symbol(&mut self, node: &UsingDeconstructionSymbol) -> bool { + self.map.insert( + node.node_id, + Node::UsingDeconstructionSymbol(Rc::clone(node)), + ); + true + } + + fn enter_using_alias(&mut self, node: &UsingAlias) -> bool { + self.map + .insert(node.node_id, Node::UsingAlias(Rc::clone(node))); + true + } + + fn enter_contract_definition(&mut self, node: &ContractDefinition) -> bool { + self.map + .insert(node.node_id, Node::ContractDefinition(Rc::clone(node))); + true + } + + fn enter_inheritance_specifier(&mut self, node: &InheritanceSpecifier) -> bool { + self.map + .insert(node.node_id, Node::InheritanceSpecifier(Rc::clone(node))); + true + } + + fn enter_inheritance_type(&mut self, node: &InheritanceType) -> bool { + self.map + .insert(node.node_id, Node::InheritanceType(Rc::clone(node))); + true + } + + fn enter_storage_layout_specifier(&mut self, node: &StorageLayoutSpecifier) -> bool { + self.map + .insert(node.node_id, Node::StorageLayoutSpecifier(Rc::clone(node))); + true + } + + fn enter_interface_definition(&mut self, node: &InterfaceDefinition) -> bool { + self.map + .insert(node.node_id, Node::InterfaceDefinition(Rc::clone(node))); + true + } + + fn enter_library_definition(&mut self, node: &LibraryDefinition) -> bool { + self.map + .insert(node.node_id, Node::LibraryDefinition(Rc::clone(node))); + true + } + + fn enter_struct_definition(&mut self, node: &StructDefinition) -> bool { + self.map + .insert(node.node_id, Node::StructDefinition(Rc::clone(node))); + true + } + + fn enter_struct_member(&mut self, node: &StructMember) -> bool { + self.map + .insert(node.node_id, Node::StructMember(Rc::clone(node))); + true + } + + fn enter_enum_definition(&mut self, node: &EnumDefinition) -> bool { + self.map + .insert(node.node_id, Node::EnumDefinition(Rc::clone(node))); + true + } + + fn enter_constant_definition(&mut self, node: &ConstantDefinition) -> bool { + self.map + .insert(node.node_id, Node::ConstantDefinition(Rc::clone(node))); + true + } + + fn enter_state_variable_definition(&mut self, node: &StateVariableDefinition) -> bool { + self.map + .insert(node.node_id, Node::StateVariableDefinition(Rc::clone(node))); + true + } + + fn enter_state_variable_definition_value( + &mut self, + node: &StateVariableDefinitionValue, + ) -> bool { + self.map.insert( + node.node_id, + Node::StateVariableDefinitionValue(Rc::clone(node)), + ); + true + } + + fn enter_function_definition(&mut self, node: &FunctionDefinition) -> bool { + self.map + .insert(node.node_id, Node::FunctionDefinition(Rc::clone(node))); + true + } + + fn enter_parameters_declaration(&mut self, node: &ParametersDeclaration) -> bool { + self.map + .insert(node.node_id, Node::ParametersDeclaration(Rc::clone(node))); + true + } + + fn enter_parameter(&mut self, node: &Parameter) -> bool { + self.map + .insert(node.node_id, Node::Parameter(Rc::clone(node))); + true + } + + fn enter_override_specifier(&mut self, node: &OverrideSpecifier) -> bool { + self.map + .insert(node.node_id, Node::OverrideSpecifier(Rc::clone(node))); + true + } + + fn enter_override_paths_declaration(&mut self, node: &OverridePathsDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::OverridePathsDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_returns_declaration(&mut self, node: &ReturnsDeclaration) -> bool { + self.map + .insert(node.node_id, Node::ReturnsDeclaration(Rc::clone(node))); + true + } + + fn enter_constructor_definition(&mut self, node: &ConstructorDefinition) -> bool { + self.map + .insert(node.node_id, Node::ConstructorDefinition(Rc::clone(node))); + true + } + + fn enter_unnamed_function_definition(&mut self, node: &UnnamedFunctionDefinition) -> bool { + self.map.insert( + node.node_id, + Node::UnnamedFunctionDefinition(Rc::clone(node)), + ); + true + } + + fn enter_fallback_function_definition(&mut self, node: &FallbackFunctionDefinition) -> bool { + self.map.insert( + node.node_id, + Node::FallbackFunctionDefinition(Rc::clone(node)), + ); + true + } + + fn enter_receive_function_definition(&mut self, node: &ReceiveFunctionDefinition) -> bool { + self.map.insert( + node.node_id, + Node::ReceiveFunctionDefinition(Rc::clone(node)), + ); + true + } + + fn enter_modifier_definition(&mut self, node: &ModifierDefinition) -> bool { + self.map + .insert(node.node_id, Node::ModifierDefinition(Rc::clone(node))); + true + } + + fn enter_modifier_invocation(&mut self, node: &ModifierInvocation) -> bool { + self.map + .insert(node.node_id, Node::ModifierInvocation(Rc::clone(node))); + true + } + + fn enter_event_definition(&mut self, node: &EventDefinition) -> bool { + self.map + .insert(node.node_id, Node::EventDefinition(Rc::clone(node))); + true + } + + fn enter_event_parameters_declaration(&mut self, node: &EventParametersDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::EventParametersDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_event_parameter(&mut self, node: &EventParameter) -> bool { + self.map + .insert(node.node_id, Node::EventParameter(Rc::clone(node))); + true + } + + fn enter_user_defined_value_type_definition( + &mut self, + node: &UserDefinedValueTypeDefinition, + ) -> bool { + self.map.insert( + node.node_id, + Node::UserDefinedValueTypeDefinition(Rc::clone(node)), + ); + true + } + + fn enter_error_definition(&mut self, node: &ErrorDefinition) -> bool { + self.map + .insert(node.node_id, Node::ErrorDefinition(Rc::clone(node))); + true + } + + fn enter_error_parameters_declaration(&mut self, node: &ErrorParametersDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::ErrorParametersDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_error_parameter(&mut self, node: &ErrorParameter) -> bool { + self.map + .insert(node.node_id, Node::ErrorParameter(Rc::clone(node))); + true + } + + fn enter_array_type_name(&mut self, node: &ArrayTypeName) -> bool { + self.map + .insert(node.node_id, Node::ArrayTypeName(Rc::clone(node))); + true + } + + fn enter_function_type(&mut self, node: &FunctionType) -> bool { + self.map + .insert(node.node_id, Node::FunctionType(Rc::clone(node))); + true + } + + fn enter_mapping_type(&mut self, node: &MappingType) -> bool { + self.map + .insert(node.node_id, Node::MappingType(Rc::clone(node))); + true + } + + fn enter_mapping_key(&mut self, node: &MappingKey) -> bool { + self.map + .insert(node.node_id, Node::MappingKey(Rc::clone(node))); + true + } + + fn enter_mapping_value(&mut self, node: &MappingValue) -> bool { + self.map + .insert(node.node_id, Node::MappingValue(Rc::clone(node))); + true + } + + fn enter_address_type(&mut self, node: &AddressType) -> bool { + self.map + .insert(node.node_id, Node::AddressType(Rc::clone(node))); + true + } + + fn enter_block(&mut self, node: &Block) -> bool { + self.map.insert(node.node_id, Node::Block(Rc::clone(node))); + true + } + + fn enter_unchecked_block(&mut self, node: &UncheckedBlock) -> bool { + self.map + .insert(node.node_id, Node::UncheckedBlock(Rc::clone(node))); + true + } + + fn enter_expression_statement(&mut self, node: &ExpressionStatement) -> bool { + self.map + .insert(node.node_id, Node::ExpressionStatement(Rc::clone(node))); + true + } + + fn enter_assembly_statement(&mut self, node: &AssemblyStatement) -> bool { + self.map + .insert(node.node_id, Node::AssemblyStatement(Rc::clone(node))); + true + } + + fn enter_assembly_flags_declaration(&mut self, node: &AssemblyFlagsDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::AssemblyFlagsDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_tuple_deconstruction_statement( + &mut self, + node: &TupleDeconstructionStatement, + ) -> bool { + self.map.insert( + node.node_id, + Node::TupleDeconstructionStatement(Rc::clone(node)), + ); + true + } + + fn enter_tuple_deconstruction_element(&mut self, node: &TupleDeconstructionElement) -> bool { + self.map.insert( + node.node_id, + Node::TupleDeconstructionElement(Rc::clone(node)), + ); + true + } + + fn enter_typed_tuple_member(&mut self, node: &TypedTupleMember) -> bool { + self.map + .insert(node.node_id, Node::TypedTupleMember(Rc::clone(node))); + true + } + + fn enter_untyped_tuple_member(&mut self, node: &UntypedTupleMember) -> bool { + self.map + .insert(node.node_id, Node::UntypedTupleMember(Rc::clone(node))); + true + } + + fn enter_variable_declaration_statement( + &mut self, + node: &VariableDeclarationStatement, + ) -> bool { + self.map.insert( + node.node_id, + Node::VariableDeclarationStatement(Rc::clone(node)), + ); + true + } + + fn enter_variable_declaration_value(&mut self, node: &VariableDeclarationValue) -> bool { + self.map.insert( + node.node_id, + Node::VariableDeclarationValue(Rc::clone(node)), + ); + true + } + + fn enter_if_statement(&mut self, node: &IfStatement) -> bool { + self.map + .insert(node.node_id, Node::IfStatement(Rc::clone(node))); + true + } + + fn enter_else_branch(&mut self, node: &ElseBranch) -> bool { + self.map + .insert(node.node_id, Node::ElseBranch(Rc::clone(node))); + true + } + + fn enter_for_statement(&mut self, node: &ForStatement) -> bool { + self.map + .insert(node.node_id, Node::ForStatement(Rc::clone(node))); + true + } + + fn enter_while_statement(&mut self, node: &WhileStatement) -> bool { + self.map + .insert(node.node_id, Node::WhileStatement(Rc::clone(node))); + true + } + + fn enter_do_while_statement(&mut self, node: &DoWhileStatement) -> bool { + self.map + .insert(node.node_id, Node::DoWhileStatement(Rc::clone(node))); + true + } + + fn enter_continue_statement(&mut self, node: &ContinueStatement) -> bool { + self.map + .insert(node.node_id, Node::ContinueStatement(Rc::clone(node))); + true + } + + fn enter_break_statement(&mut self, node: &BreakStatement) -> bool { + self.map + .insert(node.node_id, Node::BreakStatement(Rc::clone(node))); + true + } + + fn enter_return_statement(&mut self, node: &ReturnStatement) -> bool { + self.map + .insert(node.node_id, Node::ReturnStatement(Rc::clone(node))); + true + } + + fn enter_emit_statement(&mut self, node: &EmitStatement) -> bool { + self.map + .insert(node.node_id, Node::EmitStatement(Rc::clone(node))); + true + } + + fn enter_try_statement(&mut self, node: &TryStatement) -> bool { + self.map + .insert(node.node_id, Node::TryStatement(Rc::clone(node))); + true + } + + fn enter_catch_clause(&mut self, node: &CatchClause) -> bool { + self.map + .insert(node.node_id, Node::CatchClause(Rc::clone(node))); + true + } + + fn enter_catch_clause_error(&mut self, node: &CatchClauseError) -> bool { + self.map + .insert(node.node_id, Node::CatchClauseError(Rc::clone(node))); + true + } + + fn enter_revert_statement(&mut self, node: &RevertStatement) -> bool { + self.map + .insert(node.node_id, Node::RevertStatement(Rc::clone(node))); + true + } + + fn enter_throw_statement(&mut self, node: &ThrowStatement) -> bool { + self.map + .insert(node.node_id, Node::ThrowStatement(Rc::clone(node))); + true + } + + fn enter_assignment_expression(&mut self, node: &AssignmentExpression) -> bool { + self.map + .insert(node.node_id, Node::AssignmentExpression(Rc::clone(node))); + true + } + + fn enter_conditional_expression(&mut self, node: &ConditionalExpression) -> bool { + self.map + .insert(node.node_id, Node::ConditionalExpression(Rc::clone(node))); + true + } + + fn enter_or_expression(&mut self, node: &OrExpression) -> bool { + self.map + .insert(node.node_id, Node::OrExpression(Rc::clone(node))); + true + } + + fn enter_and_expression(&mut self, node: &AndExpression) -> bool { + self.map + .insert(node.node_id, Node::AndExpression(Rc::clone(node))); + true + } + + fn enter_equality_expression(&mut self, node: &EqualityExpression) -> bool { + self.map + .insert(node.node_id, Node::EqualityExpression(Rc::clone(node))); + true + } + + fn enter_inequality_expression(&mut self, node: &InequalityExpression) -> bool { + self.map + .insert(node.node_id, Node::InequalityExpression(Rc::clone(node))); + true + } + + fn enter_bitwise_or_expression(&mut self, node: &BitwiseOrExpression) -> bool { + self.map + .insert(node.node_id, Node::BitwiseOrExpression(Rc::clone(node))); + true + } + + fn enter_bitwise_xor_expression(&mut self, node: &BitwiseXorExpression) -> bool { + self.map + .insert(node.node_id, Node::BitwiseXorExpression(Rc::clone(node))); + true + } + + fn enter_bitwise_and_expression(&mut self, node: &BitwiseAndExpression) -> bool { + self.map + .insert(node.node_id, Node::BitwiseAndExpression(Rc::clone(node))); + true + } + + fn enter_shift_expression(&mut self, node: &ShiftExpression) -> bool { + self.map + .insert(node.node_id, Node::ShiftExpression(Rc::clone(node))); + true + } + + fn enter_additive_expression(&mut self, node: &AdditiveExpression) -> bool { + self.map + .insert(node.node_id, Node::AdditiveExpression(Rc::clone(node))); + true + } + + fn enter_multiplicative_expression(&mut self, node: &MultiplicativeExpression) -> bool { + self.map.insert( + node.node_id, + Node::MultiplicativeExpression(Rc::clone(node)), + ); + true + } + + fn enter_exponentiation_expression(&mut self, node: &ExponentiationExpression) -> bool { + self.map.insert( + node.node_id, + Node::ExponentiationExpression(Rc::clone(node)), + ); + true + } + + fn enter_postfix_expression(&mut self, node: &PostfixExpression) -> bool { + self.map + .insert(node.node_id, Node::PostfixExpression(Rc::clone(node))); + true + } + + fn enter_prefix_expression(&mut self, node: &PrefixExpression) -> bool { + self.map + .insert(node.node_id, Node::PrefixExpression(Rc::clone(node))); + true + } + + fn enter_function_call_expression(&mut self, node: &FunctionCallExpression) -> bool { + self.map + .insert(node.node_id, Node::FunctionCallExpression(Rc::clone(node))); + true + } + + fn enter_call_options_expression(&mut self, node: &CallOptionsExpression) -> bool { + self.map + .insert(node.node_id, Node::CallOptionsExpression(Rc::clone(node))); + true + } + + fn enter_member_access_expression(&mut self, node: &MemberAccessExpression) -> bool { + self.map + .insert(node.node_id, Node::MemberAccessExpression(Rc::clone(node))); + true + } + + fn enter_index_access_expression(&mut self, node: &IndexAccessExpression) -> bool { + self.map + .insert(node.node_id, Node::IndexAccessExpression(Rc::clone(node))); + true + } + + fn enter_index_access_end(&mut self, node: &IndexAccessEnd) -> bool { + self.map + .insert(node.node_id, Node::IndexAccessEnd(Rc::clone(node))); + true + } + + fn enter_positional_arguments_declaration( + &mut self, + node: &PositionalArgumentsDeclaration, + ) -> bool { + self.map.insert( + node.node_id, + Node::PositionalArgumentsDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_named_arguments_declaration(&mut self, node: &NamedArgumentsDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::NamedArgumentsDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_named_argument_group(&mut self, node: &NamedArgumentGroup) -> bool { + self.map + .insert(node.node_id, Node::NamedArgumentGroup(Rc::clone(node))); + true + } + + fn enter_named_argument(&mut self, node: &NamedArgument) -> bool { + self.map + .insert(node.node_id, Node::NamedArgument(Rc::clone(node))); + true + } + + fn enter_type_expression(&mut self, node: &TypeExpression) -> bool { + self.map + .insert(node.node_id, Node::TypeExpression(Rc::clone(node))); + true + } + + fn enter_new_expression(&mut self, node: &NewExpression) -> bool { + self.map + .insert(node.node_id, Node::NewExpression(Rc::clone(node))); + true + } + + fn enter_tuple_expression(&mut self, node: &TupleExpression) -> bool { + self.map + .insert(node.node_id, Node::TupleExpression(Rc::clone(node))); + true + } + + fn enter_tuple_value(&mut self, node: &TupleValue) -> bool { + self.map + .insert(node.node_id, Node::TupleValue(Rc::clone(node))); + true + } + + fn enter_array_expression(&mut self, node: &ArrayExpression) -> bool { + self.map + .insert(node.node_id, Node::ArrayExpression(Rc::clone(node))); + true + } + + fn enter_hex_number_expression(&mut self, node: &HexNumberExpression) -> bool { + self.map + .insert(node.node_id, Node::HexNumberExpression(Rc::clone(node))); + true + } + + fn enter_decimal_number_expression(&mut self, node: &DecimalNumberExpression) -> bool { + self.map + .insert(node.node_id, Node::DecimalNumberExpression(Rc::clone(node))); + true + } + + fn enter_yul_block(&mut self, node: &YulBlock) -> bool { + self.map + .insert(node.node_id, Node::YulBlock(Rc::clone(node))); + true + } + + fn enter_yul_function_definition(&mut self, node: &YulFunctionDefinition) -> bool { + self.map + .insert(node.node_id, Node::YulFunctionDefinition(Rc::clone(node))); + true + } + + fn enter_yul_parameters_declaration(&mut self, node: &YulParametersDeclaration) -> bool { + self.map.insert( + node.node_id, + Node::YulParametersDeclaration(Rc::clone(node)), + ); + true + } + + fn enter_yul_returns_declaration(&mut self, node: &YulReturnsDeclaration) -> bool { + self.map + .insert(node.node_id, Node::YulReturnsDeclaration(Rc::clone(node))); + true + } + + fn enter_yul_variable_declaration_statement( + &mut self, + node: &YulVariableDeclarationStatement, + ) -> bool { + self.map.insert( + node.node_id, + Node::YulVariableDeclarationStatement(Rc::clone(node)), + ); + true + } + + fn enter_yul_variable_declaration_value(&mut self, node: &YulVariableDeclarationValue) -> bool { + self.map.insert( + node.node_id, + Node::YulVariableDeclarationValue(Rc::clone(node)), + ); + true + } + + fn enter_yul_variable_assignment_statement( + &mut self, + node: &YulVariableAssignmentStatement, + ) -> bool { + self.map.insert( + node.node_id, + Node::YulVariableAssignmentStatement(Rc::clone(node)), + ); + true + } + + fn enter_yul_colon_and_equal(&mut self, node: &YulColonAndEqual) -> bool { + self.map + .insert(node.node_id, Node::YulColonAndEqual(Rc::clone(node))); + true + } + + fn enter_yul_stack_assignment_statement(&mut self, node: &YulStackAssignmentStatement) -> bool { + self.map.insert( + node.node_id, + Node::YulStackAssignmentStatement(Rc::clone(node)), + ); + true + } + + fn enter_yul_equal_and_colon(&mut self, node: &YulEqualAndColon) -> bool { + self.map + .insert(node.node_id, Node::YulEqualAndColon(Rc::clone(node))); + true + } + + fn enter_yul_if_statement(&mut self, node: &YulIfStatement) -> bool { + self.map + .insert(node.node_id, Node::YulIfStatement(Rc::clone(node))); + true + } + + fn enter_yul_for_statement(&mut self, node: &YulForStatement) -> bool { + self.map + .insert(node.node_id, Node::YulForStatement(Rc::clone(node))); + true + } + + fn enter_yul_switch_statement(&mut self, node: &YulSwitchStatement) -> bool { + self.map + .insert(node.node_id, Node::YulSwitchStatement(Rc::clone(node))); + true + } + + fn enter_yul_default_case(&mut self, node: &YulDefaultCase) -> bool { + self.map + .insert(node.node_id, Node::YulDefaultCase(Rc::clone(node))); + true + } + + fn enter_yul_value_case(&mut self, node: &YulValueCase) -> bool { + self.map + .insert(node.node_id, Node::YulValueCase(Rc::clone(node))); + true + } + + fn enter_yul_leave_statement(&mut self, node: &YulLeaveStatement) -> bool { + self.map + .insert(node.node_id, Node::YulLeaveStatement(Rc::clone(node))); + true + } + + fn enter_yul_break_statement(&mut self, node: &YulBreakStatement) -> bool { + self.map + .insert(node.node_id, Node::YulBreakStatement(Rc::clone(node))); + true + } + + fn enter_yul_continue_statement(&mut self, node: &YulContinueStatement) -> bool { + self.map + .insert(node.node_id, Node::YulContinueStatement(Rc::clone(node))); + true + } + + fn enter_yul_label(&mut self, node: &YulLabel) -> bool { + self.map + .insert(node.node_id, Node::YulLabel(Rc::clone(node))); + true + } + + fn enter_yul_function_call_expression(&mut self, node: &YulFunctionCallExpression) -> bool { + self.map.insert( + node.node_id, + Node::YulFunctionCallExpression(Rc::clone(node)), + ); + true + } + + fn enter_source_unit_member(&mut self, _node: &SourceUnitMember) -> bool { + true + } + fn enter_pragma(&mut self, _node: &Pragma) -> bool { + true + } + fn enter_abicoder_version(&mut self, _node: &AbicoderVersion) -> bool { + true + } + fn enter_experimental_feature(&mut self, _node: &ExperimentalFeature) -> bool { + true + } + fn enter_version_expression(&mut self, _node: &VersionExpression) -> bool { + true + } + fn enter_version_operator(&mut self, _node: &VersionOperator) -> bool { + true + } + fn enter_version_literal(&mut self, _node: &VersionLiteral) -> bool { + true + } + fn enter_import_clause(&mut self, _node: &ImportClause) -> bool { + true + } + fn enter_using_clause(&mut self, _node: &UsingClause) -> bool { + true + } + fn enter_using_operator(&mut self, _node: &UsingOperator) -> bool { + true + } + fn enter_using_target(&mut self, _node: &UsingTarget) -> bool { + true + } + fn enter_contract_specifier(&mut self, _node: &ContractSpecifier) -> bool { + true + } + fn enter_contract_member(&mut self, _node: &ContractMember) -> bool { + true + } + fn enter_state_variable_attribute(&mut self, _node: &StateVariableAttribute) -> bool { + true + } + + fn enter_function_name(&mut self, _node: &FunctionName) -> bool { + true + } + fn enter_function_attribute(&mut self, _node: &FunctionAttribute) -> bool { + true + } + fn enter_function_body(&mut self, _node: &FunctionBody) -> bool { + true + } + fn enter_constructor_attribute(&mut self, _node: &ConstructorAttribute) -> bool { + true + } + fn enter_unnamed_function_attribute(&mut self, _node: &UnnamedFunctionAttribute) -> bool { + true + } + fn enter_fallback_function_attribute(&mut self, _node: &FallbackFunctionAttribute) -> bool { + true + } + fn enter_receive_function_attribute(&mut self, _node: &ReceiveFunctionAttribute) -> bool { + true + } + fn enter_modifier_attribute(&mut self, _node: &ModifierAttribute) -> bool { + true + } + fn enter_type_name(&mut self, _node: &TypeName) -> bool { + true + } + fn enter_function_type_attribute(&mut self, _node: &FunctionTypeAttribute) -> bool { + true + } + fn enter_mapping_key_type(&mut self, _node: &MappingKeyType) -> bool { + true + } + fn enter_elementary_type(&mut self, _node: &ElementaryType) -> bool { + true + } + fn enter_statement(&mut self, _node: &Statement) -> bool { + true + } + fn enter_tuple_member(&mut self, _node: &TupleMember) -> bool { + true + } + fn enter_variable_declaration_type(&mut self, _node: &VariableDeclarationType) -> bool { + true + } + fn enter_storage_location(&mut self, _node: &StorageLocation) -> bool { + true + } + fn enter_for_statement_initialization(&mut self, _node: &ForStatementInitialization) -> bool { + true + } + fn enter_for_statement_condition(&mut self, _node: &ForStatementCondition) -> bool { + true + } + fn enter_expression(&mut self, _node: &Expression) -> bool { + true + } + fn enter_arguments_declaration(&mut self, _node: &ArgumentsDeclaration) -> bool { + true + } + fn enter_number_unit(&mut self, _node: &NumberUnit) -> bool { + true + } + fn enter_string_expression(&mut self, _node: &StringExpression) -> bool { + true + } + fn enter_string_literal(&mut self, _node: &StringLiteral) -> bool { + true + } + fn enter_hex_string_literal(&mut self, _node: &HexStringLiteral) -> bool { + true + } + fn enter_unicode_string_literal(&mut self, _node: &UnicodeStringLiteral) -> bool { + true + } + fn enter_yul_statement(&mut self, _node: &YulStatement) -> bool { + true + } + fn enter_yul_assignment_operator(&mut self, _node: &YulAssignmentOperator) -> bool { + true + } + fn enter_yul_stack_assignment_operator(&mut self, _node: &YulStackAssignmentOperator) -> bool { + true + } + fn enter_yul_switch_case(&mut self, _node: &YulSwitchCase) -> bool { + true + } + fn enter_yul_expression(&mut self, _node: &YulExpression) -> bool { + true + } + fn enter_yul_literal(&mut self, _node: &YulLiteral) -> bool { + true + } + fn enter_source_unit_members(&mut self, _items: &SourceUnitMembers) -> bool { + true + } + fn enter_version_expression_sets(&mut self, _items: &VersionExpressionSets) -> bool { + true + } + fn enter_version_expression_set(&mut self, _items: &VersionExpressionSet) -> bool { + true + } + fn enter_simple_version_literal(&mut self, _items: &SimpleVersionLiteral) -> bool { + true + } + fn enter_import_deconstruction_symbols( + &mut self, + _items: &ImportDeconstructionSymbols, + ) -> bool { + true + } + fn enter_using_deconstruction_symbols(&mut self, _items: &UsingDeconstructionSymbols) -> bool { + true + } + fn enter_inheritance_types(&mut self, _items: &InheritanceTypes) -> bool { + true + } + fn enter_contract_members(&mut self, _items: &ContractMembers) -> bool { + true + } + fn enter_interface_members(&mut self, _items: &InterfaceMembers) -> bool { + true + } + fn enter_library_members(&mut self, _items: &LibraryMembers) -> bool { + true + } + fn enter_struct_members(&mut self, _items: &StructMembers) -> bool { + true + } + fn enter_enum_members(&mut self, _items: &EnumMembers) -> bool { + true + } + fn enter_state_variable_attributes(&mut self, _items: &StateVariableAttributes) -> bool { + true + } + fn enter_parameters(&mut self, _items: &Parameters) -> bool { + true + } + fn enter_function_attributes(&mut self, _items: &FunctionAttributes) -> bool { + true + } + fn enter_override_paths(&mut self, _items: &OverridePaths) -> bool { + true + } + fn enter_constructor_attributes(&mut self, _items: &ConstructorAttributes) -> bool { + true + } + fn enter_unnamed_function_attributes(&mut self, _items: &UnnamedFunctionAttributes) -> bool { + true + } + fn enter_fallback_function_attributes(&mut self, _items: &FallbackFunctionAttributes) -> bool { + true + } + fn enter_receive_function_attributes(&mut self, _items: &ReceiveFunctionAttributes) -> bool { + true + } + fn enter_modifier_attributes(&mut self, _items: &ModifierAttributes) -> bool { + true + } + fn enter_event_parameters(&mut self, _items: &EventParameters) -> bool { + true + } + fn enter_error_parameters(&mut self, _items: &ErrorParameters) -> bool { + true + } + fn enter_function_type_attributes(&mut self, _items: &FunctionTypeAttributes) -> bool { + true + } + fn enter_statements(&mut self, _items: &Statements) -> bool { + true + } + fn enter_assembly_flags(&mut self, _items: &AssemblyFlags) -> bool { + true + } + fn enter_tuple_deconstruction_elements( + &mut self, + _items: &TupleDeconstructionElements, + ) -> bool { + true + } + fn enter_catch_clauses(&mut self, _items: &CatchClauses) -> bool { + true + } + fn enter_positional_arguments(&mut self, _items: &PositionalArguments) -> bool { + true + } + fn enter_named_arguments(&mut self, _items: &NamedArguments) -> bool { + true + } + fn enter_call_options(&mut self, _items: &CallOptions) -> bool { + true + } + fn enter_tuple_values(&mut self, _items: &TupleValues) -> bool { + true + } + fn enter_array_values(&mut self, _items: &ArrayValues) -> bool { + true + } + fn enter_string_literals(&mut self, _items: &StringLiterals) -> bool { + true + } + fn enter_hex_string_literals(&mut self, _items: &HexStringLiterals) -> bool { + true + } + fn enter_unicode_string_literals(&mut self, _items: &UnicodeStringLiterals) -> bool { + true + } + fn enter_identifier_path(&mut self, _items: &IdentifierPath) -> bool { + true + } + fn enter_yul_statements(&mut self, _items: &YulStatements) -> bool { + true + } + fn enter_yul_parameters(&mut self, _items: &YulParameters) -> bool { + true + } + fn enter_yul_variable_names(&mut self, _items: &YulVariableNames) -> bool { + true + } + fn enter_yul_switch_cases(&mut self, _items: &YulSwitchCases) -> bool { + true + } + fn enter_yul_arguments(&mut self, _items: &YulArguments) -> bool { + true + } + fn enter_yul_paths(&mut self, _items: &YulPaths) -> bool { + true + } + fn enter_yul_path(&mut self, _items: &YulPath) -> bool { + true + } +} 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..26af0243e4 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/find_unused_definitions.rs @@ -0,0 +1,146 @@ +use std::collections::{HashMap, VecDeque}; + +use anyhow::{bail, Result}; +use slang_solidity::backend::binder::definitions::FunctionVisibility; +use slang_solidity::backend::binder::Definition::{self, Function}; +use slang_solidity::cst::TextIndex; + +use crate::ast_api::collect_definitions::{collect_all_definitions, collect_definitions}; +use crate::ast_api::visit_definition::visit_definition_from_cursor; +use crate::ast_api::CompilationOutput; + +pub fn find_unused_definitions<'a>( + compilation_output: &'a CompilationOutput, + starting_contract_name: &str, +) -> Vec<&'a Definition> { + fn is_private_function(def: &Definition) -> bool { + !matches!(def, Function(_)) + || matches!(def, Function(fundef) if matches!(fundef.visibility, FunctionVisibility::Private) || matches!(fundef.visibility, FunctionVisibility::Internal)) + } + + let all_definitions = collect_all_definitions( + &compilation_output.compilation_unit, + &compilation_output.binder, + ); + + // Only consider functions with private visibility as unused candidates + let mut unused_definitions: HashMap<_, _> = all_definitions + .iter() + .map(|def| (def.node_id(), *def)) + .filter(|(_, def)| is_private_function(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 definiens_definition = compilation_output + .binder + .find_definition_by_id(node_id) + .unwrap(); + + // TODO: missing way to obtain location from definition + // assert_user_file_location(definiens_location); + + let node = compilation_output + .cst_map + .get(&definiens_definition.node_id()) + .expect("The definiens_location to be in the nodes map"); + let followed = visit_definition_from_cursor( + &compilation_output.binder, + &node.clone().create_cursor(TextIndex::ZERO), + ); + for def in followed { + 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; + } + + // assert_user_file_location(definiens_location); + let node = compilation_output + .cst_map + .get(&to_visit.node_id()) + .expect("to_visit to be in the nodes map"); + let inner_definitions = collect_definitions( + &compilation_output.binder, + &node.clone().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: &Vec<&'a Definition>, + name: &'a str, +) -> Result<&'a Definition> { + let matching_name: Vec<_> = definitions + .iter() + .filter(|def| { + if matches!(def, Definition::Contract(_)) { + def.identifier().text == name + } else { + false + } + }) + .collect(); + match matching_name.len() { + 0 => bail!("No contract matches name {name}"), + 1 => Ok(matching_name.first().unwrap()), + _ => bail!("{name} is ambiguous"), + } +} + +#[test] +fn test_one_function() { + const FILE_CONTENT: &str = r#" +contract Test { + function test() private { + } +} + "#; + let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let result = find_unused_definitions(&output, "Test"); + assert_eq!(result.len(), 1); + assert_eq!(result[0].identifier().text, "test".to_owned()); +} + +#[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::one_file_backend_pipeline(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..a78a9e748a --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/follow_all_references.rs @@ -0,0 +1,21 @@ +use slang_solidity::backend::binder::{Binder, Definition}; +use slang_solidity::cst::{Cursor, TerminalKindExtensions}; + +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_terminal() { + continue; + } + if !node.as_terminal().unwrap().kind.is_identifier() { + continue; + } + + if let Some(definition) = binder.naviagate_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..3b108c873e --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs @@ -0,0 +1,54 @@ +use std::collections::HashMap; + +use slang_solidity::backend::binder::Binder; +use slang_solidity::backend::l2_flat_contracts::visitor::Visitor; +use slang_solidity::backend::passes; +use slang_solidity::compilation::CompilationUnit; +use slang_solidity::cst::{Node, NodeId}; + +use crate::ast_api::collect_definitions::map_definitions_ids; + +pub(crate) struct CompilationOutput { + pub(crate) binder: Binder, + pub(crate) compilation_unit: CompilationUnit, + pub(crate) cst_map: HashMap, + pub(crate) ast_map: HashMap, +} + +impl CompilationOutput { + pub(crate) fn from_passes(output: passes::p5_resolve_references::Output) -> CompilationOutput { + let map = map_definitions_ids(&output.compilation_unit, &output.binder); + let mut ast_visitor = collect_nodes::NodesMap::default(); + + for (_, file) in output.files { + ast_visitor.enter_source_unit(&file); + } + + CompilationOutput { + binder: output.binder, + compilation_unit: output.compilation_unit, + cst_map: map, + ast_map: ast_visitor.map, + } + } +} + +macro_rules! assert_eq_defs { + ($xs:expr, $ys:expr) => { + assert_eq!( + $xs.iter() + .map(|def| def.identifier().text.as_str()) + .collect::>(), + $ys + ); + }; +} + +mod collect_definitions; +mod collect_nodes; +mod find_unused_definitions; +mod follow_all_references; +// mod map_nodes; +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..f70e5d1c5d --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs @@ -0,0 +1,59 @@ +use anyhow::{bail, Result}; +use slang_solidity::backend::passes; +use slang_solidity::compilation::{CompilationBuilder, CompilationBuilderConfig, CompilationUnit}; +use slang_solidity::utils::LanguageFacts; + +use crate::ast_api::CompilationOutput; + +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 one_file_backend_pipeline(content: &str) -> Result { + let unit = build_one_file_compilation_unit(content)?; + let data = passes::p0_build_ast::run(unit); + let data = passes::p1_flatten_contracts::run(data); + let data = passes::p2_collect_definitions::run(data); + let data = passes::p3_linearise_contracts::run(data); + let data = passes::p4_type_definitions::run(data); + let data = passes::p5_resolve_references::run(data); + assert_eq!(1, data.files.len()); + let data = CompilationOutput::from_passes(data); + 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..22a09a66de --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/test_find_unused_definitions.rs @@ -0,0 +1,49 @@ +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::one_file_backend_pipeline(MAIN_SOL_CONTENTS).unwrap(); + + let unused = find_unused_definitions(&unit, "Counter"); + assert_eq_defs!( + unused, + vec!["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..7a122eaa9c --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -0,0 +1,169 @@ +use slang_solidity::backend::binder::definitions::ContractDefinition; +use slang_solidity::backend::binder::{Binder, Definition}; +use slang_solidity::backend::l2_flat_contracts::{ + ContractMember, StateVariableAttribute, TypeName, +}; +use slang_solidity::cst::{Cursor, NodeId, NonterminalKind, TerminalKindExtensions}; + +use crate::ast_api::CompilationOutput; +use crate::binder; + +pub fn visit_definition<'a>( + compilation_output: &'a CompilationOutput, + definition: &'a Definition, +) -> Vec<&'a Definition> { + match definition { + Definition::Contract(contract_definition) => { + visit_contract(compilation_output, contract_definition) + } + Definition::Function(function_definition) => todo!(), + Definition::Modifier(modifier_definition) => todo!(), + _ => todo!(), + } +} + +fn type_name_node_id(type_name: &TypeName) -> Option { + match type_name { + TypeName::ArrayTypeName(array_type_name_struct) => Some(array_type_name_struct.node_id), + TypeName::FunctionType(function_type_struct) => Some(function_type_struct.node_id), + TypeName::MappingType(mapping_type_struct) => Some(mapping_type_struct.node_id), + TypeName::ElementaryType(_elementary_type) => None, + TypeName::IdentifierPath(terminal_nodes) => terminal_nodes.last().map(|last| last.id()), + } +} + +fn visit_contract<'a>( + compilation_output: &'a CompilationOutput, + 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 = compilation_output + .ast_map + .get(&contract_definition.node_id) + .expect("Node to be defined") + .as_contract_definition(); + + let inheritance_definitions = + contract + .inheritance_types + .iter() + .map(|f| f.node_id) + .map(|node_id| { + compilation_output + .binder + .naviagate_to(node_id) + .expect("reference to be defined") + }); + + let state_vars_definitions = contract + .members + .iter() + .filter_map(|member| match member { + ContractMember::StateVariableDefinition(sv_def) + if sv_def + .attributes + .contains(&StateVariableAttribute::PublicKeyword) => + { + let type_node_id = type_name_node_id(&sv_def.type_name); + if let Some(type_node_id) = type_node_id { + Some(vec![sv_def.node_id, type_node_id]) + } else { + Some(vec![sv_def.node_id]) + } + } + _ => None, + }) + .flatten() + .filter_map(|node_id| compilation_output.binder.naviagate_to(node_id)); + + // contract_definition.bases + todo!() +} + +/// Visits a definition and returns all definitions that are referenced from its body. +/// This is a translation of the TypeScript logic from visit-definition.mts. +pub fn visit_definition_from_cursor<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a Definition> { + let mut referenced_definitions = Vec::new(); + let mut cursor = root.spawn(); + while cursor.go_to_next_terminal() { + let node = cursor.node(); + if !node.is_terminal() { + continue; + } + if !node.as_terminal().unwrap().kind.is_identifier() { + continue; + } + + if let Some(def) = binder + .find_reference_by_identifier_node_id(node.id()) + .and_then(|reference| reference.resolution.as_definition_id()) + .and_then(|def_id| binder.find_definition_by_id(def_id)) + { + referenced_definitions.push(def); + } + } + referenced_definitions +} + +#[test] +fn test_no_references() { + const FILE_CONTENT: &str = r#" +abstract contract Ownable { +}"#; + let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let cursor = output.compilation_unit.files()[0].create_tree_cursor(); + let result = visit_definition_from_cursor(&output.binder, &cursor); + assert!(result.is_empty()); +} + +#[test] +fn test_one_reference() { + const FILE_CONTENT: &str = r#" +function test() { + test(); +}"#; + let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let cursor = output.compilation_unit.files()[0].create_tree_cursor(); + let result = visit_definition_from_cursor(&output.binder, &cursor); + assert_eq_defs!(result, ["test"]); +} + +#[test] +fn test_function_reference() { + const FILE_CONTENT: &str = r#" +function test() { + test2(); +} + +function test2() { + test(); +} + "#; + let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let mut cursor = output.compilation_unit.files()[0].create_tree_cursor(); + assert!(cursor.go_to_next_nonterminal_with_kind(NonterminalKind::FunctionDefinition)); + let result = visit_definition_from_cursor(&output.binder, &cursor); + assert_eq_defs!(result, ["test2"]); +} + +#[test] +fn test_contract() { + const FILE_CONTENT: &str = r#" +contract Test { + function test() { + test2(); + } + + function test2() { + test(); + } +} + "#; + let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let mut cursor = output.compilation_unit.files()[0].create_tree_cursor(); + assert!(cursor.go_to_next_nonterminal_with_kind(NonterminalKind::ContractDefinition)); + let result = visit_definition_from_cursor(&output.binder, &cursor); + assert_eq_defs!(result, vec!["test2", "test"]); +} From 0b4eb3e02f5f63f1af0fbaf044b06623cc94f545 Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Tue, 11 Nov 2025 14:06:51 -0300 Subject: [PATCH 22/27] Collecting unused definitions --- .../crate/src/backend/binder/definitions.rs | 34 + .../cargo/crate/src/backend/binder/mod.rs | 11 +- .../src/backend/ir/common/_nodes.rs.jinja2 | 4 +- .../ir/ir1_structured_ast/nodes.generated.rs | 350 ++--- .../ir/ir2_flat_contracts/nodes.generated.rs | 284 ++-- .../cargo/crate/src/compilation/file.rs | 7 +- .../cargo/crate/src/parser/parse_output.rs | 7 +- .../tests/src/ast_api/collect_definitions.rs | 38 +- .../cargo/tests/src/ast_api/collect_nodes.rs | 1138 ----------------- .../src/ast_api/find_unused_definitions.rs | 89 +- .../src/ast_api/follow_all_references.rs | 2 +- .../outputs/cargo/tests/src/ast_api/mod.rs | 43 +- .../cargo/tests/src/ast_api/pipeline.rs | 3 +- .../ast_api/test_find_unused_definitions.rs | 3 +- .../tests/src/ast_api/visit_definition.rs | 222 ++-- .../solidity/outputs/cargo/tests/src/lib.rs | 1 + 16 files changed, 502 insertions(+), 1734 deletions(-) delete mode 100644 crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs 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 e29cfe2c88..4fe22f932f 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/definitions.rs @@ -198,6 +198,40 @@ pub struct YulVariableDefinition { } 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(), 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..1c0918b2dd 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,10 @@ impl Binder { _ => None, } } + + 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/ir/common/_nodes.rs.jinja2 b/crates/solidity/outputs/cargo/crate/src/backend/ir/common/_nodes.rs.jinja2 index 5495ffd936..81d1fe97f2 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 @@ -12,7 +12,7 @@ {% for parent_type, sequence in target.sequences %} pub type {{ parent_type }} = Rc<{{ parent_type }}Struct>; - #[derive(Debug)] + #[derive(Debug, PartialEq)] pub struct {{ parent_type }}Struct { pub node: Rc, {%- for field in sequence.fields %} @@ -52,7 +52,7 @@ // {% for parent_type, choice in target.choices %} - #[derive(Debug)] + #[derive(Debug, PartialEq)] pub enum {{ parent_type }} { {% for nonterminal in choice.variants | filter(attribute="kind", value="Nonterminal") -%} {{ nonterminal.name }}({{ nonterminal.name }}), 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 b0d41e40be..af92f0b1f4 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 @@ -13,7 +13,7 @@ use crate::cst::SyntaxNode; pub type SourceUnit = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct SourceUnitStruct { pub node: Rc, pub members: SourceUnitMembers, @@ -27,7 +27,7 @@ impl SourceUnitStruct { pub type PragmaDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PragmaDirectiveStruct { pub node: Rc, pub pragma: Pragma, @@ -41,7 +41,7 @@ impl PragmaDirectiveStruct { pub type AbicoderPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AbicoderPragmaStruct { pub node: Rc, pub version: AbicoderVersion, @@ -55,7 +55,7 @@ impl AbicoderPragmaStruct { pub type ExperimentalPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExperimentalPragmaStruct { pub node: Rc, pub feature: ExperimentalFeature, @@ -69,7 +69,7 @@ impl ExperimentalPragmaStruct { pub type VersionPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionPragmaStruct { pub node: Rc, pub sets: VersionExpressionSets, @@ -83,7 +83,7 @@ impl VersionPragmaStruct { pub type VersionRange = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionRangeStruct { pub node: Rc, pub start: VersionLiteral, @@ -98,7 +98,7 @@ impl VersionRangeStruct { pub type VersionTerm = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionTermStruct { pub node: Rc, pub operator: Option, @@ -113,7 +113,7 @@ impl VersionTermStruct { pub type ImportDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDirectiveStruct { pub node: Rc, pub clause: ImportClause, @@ -127,7 +127,7 @@ impl ImportDirectiveStruct { pub type PathImport = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PathImportStruct { pub node: Rc, pub path: StringLiteral, @@ -142,7 +142,7 @@ impl PathImportStruct { pub type NamedImport = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedImportStruct { pub node: Rc, pub alias: ImportAlias, @@ -157,7 +157,7 @@ impl NamedImportStruct { pub type ImportDeconstruction = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDeconstructionStruct { pub node: Rc, pub symbols: ImportDeconstructionSymbols, @@ -172,7 +172,7 @@ impl ImportDeconstructionStruct { pub type ImportDeconstructionSymbol = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, pub name: Rc, @@ -187,7 +187,7 @@ impl ImportDeconstructionSymbolStruct { pub type ImportAlias = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportAliasStruct { pub node: Rc, pub identifier: Rc, @@ -201,7 +201,7 @@ impl ImportAliasStruct { pub type UsingDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDirectiveStruct { pub node: Rc, pub clause: UsingClause, @@ -217,7 +217,7 @@ impl UsingDirectiveStruct { pub type UsingDeconstruction = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDeconstructionStruct { pub node: Rc, pub symbols: UsingDeconstructionSymbols, @@ -231,7 +231,7 @@ impl UsingDeconstructionStruct { pub type UsingDeconstructionSymbol = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDeconstructionSymbolStruct { pub node: Rc, pub name: IdentifierPath, @@ -246,7 +246,7 @@ impl UsingDeconstructionSymbolStruct { pub type UsingAlias = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingAliasStruct { pub node: Rc, pub operator: UsingOperator, @@ -260,7 +260,7 @@ impl UsingAliasStruct { pub type ContractDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, @@ -277,7 +277,7 @@ impl ContractDefinitionStruct { pub type InheritanceSpecifier = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InheritanceSpecifierStruct { pub node: Rc, pub types: InheritanceTypes, @@ -291,7 +291,7 @@ impl InheritanceSpecifierStruct { pub type InheritanceType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InheritanceTypeStruct { pub node: Rc, pub type_name: IdentifierPath, @@ -306,7 +306,7 @@ impl InheritanceTypeStruct { pub type StorageLayoutSpecifier = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StorageLayoutSpecifierStruct { pub node: Rc, pub expression: Expression, @@ -320,7 +320,7 @@ impl StorageLayoutSpecifierStruct { pub type InterfaceDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InterfaceDefinitionStruct { pub node: Rc, pub name: Rc, @@ -336,7 +336,7 @@ impl InterfaceDefinitionStruct { pub type LibraryDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct LibraryDefinitionStruct { pub node: Rc, pub name: Rc, @@ -351,7 +351,7 @@ impl LibraryDefinitionStruct { pub type StructDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StructDefinitionStruct { pub node: Rc, pub name: Rc, @@ -366,7 +366,7 @@ impl StructDefinitionStruct { pub type StructMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -381,7 +381,7 @@ impl StructMemberStruct { pub type EnumDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EnumDefinitionStruct { pub node: Rc, pub name: Rc, @@ -396,7 +396,7 @@ impl EnumDefinitionStruct { pub type ConstantDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -412,7 +412,7 @@ impl ConstantDefinitionStruct { pub type StateVariableDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -429,7 +429,7 @@ impl StateVariableDefinitionStruct { pub type StateVariableDefinitionValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StateVariableDefinitionValueStruct { pub node: Rc, pub value: Expression, @@ -443,7 +443,7 @@ impl StateVariableDefinitionValueStruct { pub type FunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionDefinitionStruct { pub node: Rc, pub name: FunctionName, @@ -461,7 +461,7 @@ impl FunctionDefinitionStruct { pub type ParametersDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ParametersDeclarationStruct { pub node: Rc, pub parameters: Parameters, @@ -475,7 +475,7 @@ impl ParametersDeclarationStruct { pub type Parameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -491,7 +491,7 @@ impl ParameterStruct { pub type OverrideSpecifier = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct OverrideSpecifierStruct { pub node: Rc, pub overridden: Option, @@ -505,7 +505,7 @@ impl OverrideSpecifierStruct { pub type OverridePathsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct OverridePathsDeclarationStruct { pub node: Rc, pub paths: OverridePaths, @@ -519,7 +519,7 @@ impl OverridePathsDeclarationStruct { pub type ReturnsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ReturnsDeclarationStruct { pub node: Rc, pub variables: ParametersDeclaration, @@ -533,7 +533,7 @@ impl ReturnsDeclarationStruct { pub type ConstructorDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ConstructorDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -549,7 +549,7 @@ impl ConstructorDefinitionStruct { pub type UnnamedFunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UnnamedFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -565,7 +565,7 @@ impl UnnamedFunctionDefinitionStruct { pub type FallbackFunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FallbackFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -582,7 +582,7 @@ impl FallbackFunctionDefinitionStruct { pub type ReceiveFunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ReceiveFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -598,7 +598,7 @@ impl ReceiveFunctionDefinitionStruct { pub type ModifierDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ModifierDefinitionStruct { pub node: Rc, pub name: Rc, @@ -615,7 +615,7 @@ impl ModifierDefinitionStruct { pub type ModifierInvocation = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ModifierInvocationStruct { pub node: Rc, pub name: IdentifierPath, @@ -630,7 +630,7 @@ impl ModifierInvocationStruct { pub type EventDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EventDefinitionStruct { pub node: Rc, pub name: Rc, @@ -646,7 +646,7 @@ impl EventDefinitionStruct { pub type EventParametersDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EventParametersDeclarationStruct { pub node: Rc, pub parameters: EventParameters, @@ -660,7 +660,7 @@ impl EventParametersDeclarationStruct { pub type EventParameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -676,7 +676,7 @@ impl EventParameterStruct { pub type UserDefinedValueTypeDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UserDefinedValueTypeDefinitionStruct { pub node: Rc, pub name: Rc, @@ -691,7 +691,7 @@ impl UserDefinedValueTypeDefinitionStruct { pub type ErrorDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ErrorDefinitionStruct { pub node: Rc, pub name: Rc, @@ -706,7 +706,7 @@ impl ErrorDefinitionStruct { pub type ErrorParametersDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ErrorParametersDeclarationStruct { pub node: Rc, pub parameters: ErrorParameters, @@ -720,7 +720,7 @@ impl ErrorParametersDeclarationStruct { pub type ErrorParameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -735,7 +735,7 @@ impl ErrorParameterStruct { pub type ArrayTypeName = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ArrayTypeNameStruct { pub node: Rc, pub operand: TypeName, @@ -750,7 +750,7 @@ impl ArrayTypeNameStruct { pub type FunctionType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionTypeStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -766,7 +766,7 @@ impl FunctionTypeStruct { pub type MappingType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingTypeStruct { pub node: Rc, pub key_type: MappingKey, @@ -781,7 +781,7 @@ impl MappingTypeStruct { pub type MappingKey = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, @@ -796,7 +796,7 @@ impl MappingKeyStruct { pub type MappingValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, @@ -811,7 +811,7 @@ impl MappingValueStruct { pub type AddressType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AddressTypeStruct { pub node: Rc, pub payable_keyword: bool, @@ -825,7 +825,7 @@ impl AddressTypeStruct { pub type Block = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BlockStruct { pub node: Rc, pub statements: Statements, @@ -839,7 +839,7 @@ impl BlockStruct { pub type UncheckedBlock = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UncheckedBlockStruct { pub node: Rc, pub block: Block, @@ -853,7 +853,7 @@ impl UncheckedBlockStruct { pub type ExpressionStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExpressionStatementStruct { pub node: Rc, pub expression: Expression, @@ -867,7 +867,7 @@ impl ExpressionStatementStruct { pub type AssemblyStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AssemblyStatementStruct { pub node: Rc, pub label: Option, @@ -883,7 +883,7 @@ impl AssemblyStatementStruct { pub type AssemblyFlagsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AssemblyFlagsDeclarationStruct { pub node: Rc, pub flags: AssemblyFlags, @@ -897,7 +897,7 @@ impl AssemblyFlagsDeclarationStruct { pub type TupleDeconstructionStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleDeconstructionStatementStruct { pub node: Rc, pub var_keyword: bool, @@ -913,7 +913,7 @@ impl TupleDeconstructionStatementStruct { pub type TupleDeconstructionElement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleDeconstructionElementStruct { pub node: Rc, pub member: Option, @@ -927,7 +927,7 @@ impl TupleDeconstructionElementStruct { pub type TypedTupleMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -943,7 +943,7 @@ impl TypedTupleMemberStruct { pub type UntypedTupleMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, @@ -958,7 +958,7 @@ impl UntypedTupleMemberStruct { pub type VariableDeclarationStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, @@ -975,7 +975,7 @@ impl VariableDeclarationStatementStruct { pub type VariableDeclarationValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VariableDeclarationValueStruct { pub node: Rc, pub expression: Expression, @@ -989,7 +989,7 @@ impl VariableDeclarationValueStruct { pub type IfStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct IfStatementStruct { pub node: Rc, pub condition: Expression, @@ -1005,7 +1005,7 @@ impl IfStatementStruct { pub type ElseBranch = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ElseBranchStruct { pub node: Rc, pub body: Statement, @@ -1019,7 +1019,7 @@ impl ElseBranchStruct { pub type ForStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ForStatementStruct { pub node: Rc, pub initialization: ForStatementInitialization, @@ -1036,7 +1036,7 @@ impl ForStatementStruct { pub type WhileStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct WhileStatementStruct { pub node: Rc, pub condition: Expression, @@ -1051,7 +1051,7 @@ impl WhileStatementStruct { pub type DoWhileStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct DoWhileStatementStruct { pub node: Rc, pub body: Statement, @@ -1066,7 +1066,7 @@ impl DoWhileStatementStruct { pub type ContinueStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ContinueStatementStruct { pub node: Rc, } @@ -1079,7 +1079,7 @@ impl ContinueStatementStruct { pub type BreakStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BreakStatementStruct { pub node: Rc, } @@ -1092,7 +1092,7 @@ impl BreakStatementStruct { pub type ReturnStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ReturnStatementStruct { pub node: Rc, pub expression: Option, @@ -1106,7 +1106,7 @@ impl ReturnStatementStruct { pub type EmitStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EmitStatementStruct { pub node: Rc, pub event: IdentifierPath, @@ -1121,7 +1121,7 @@ impl EmitStatementStruct { pub type TryStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TryStatementStruct { pub node: Rc, pub expression: Expression, @@ -1138,7 +1138,7 @@ impl TryStatementStruct { pub type CatchClause = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CatchClauseStruct { pub node: Rc, pub error: Option, @@ -1153,7 +1153,7 @@ impl CatchClauseStruct { pub type CatchClauseError = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CatchClauseErrorStruct { pub node: Rc, pub name: Option>, @@ -1168,7 +1168,7 @@ impl CatchClauseErrorStruct { pub type RevertStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct RevertStatementStruct { pub node: Rc, pub error: Option, @@ -1183,7 +1183,7 @@ impl RevertStatementStruct { pub type ThrowStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ThrowStatementStruct { pub node: Rc, } @@ -1196,7 +1196,7 @@ impl ThrowStatementStruct { pub type AssignmentExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1212,7 +1212,7 @@ impl AssignmentExpressionStruct { pub type ConditionalExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ConditionalExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1228,7 +1228,7 @@ impl ConditionalExpressionStruct { pub type OrExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct OrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1243,7 +1243,7 @@ impl OrExpressionStruct { pub type AndExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1258,7 +1258,7 @@ impl AndExpressionStruct { pub type EqualityExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1274,7 +1274,7 @@ impl EqualityExpressionStruct { pub type InequalityExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1290,7 +1290,7 @@ impl InequalityExpressionStruct { pub type BitwiseOrExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseOrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1305,7 +1305,7 @@ impl BitwiseOrExpressionStruct { pub type BitwiseXorExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseXorExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1320,7 +1320,7 @@ impl BitwiseXorExpressionStruct { pub type BitwiseAndExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseAndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1335,7 +1335,7 @@ impl BitwiseAndExpressionStruct { pub type ShiftExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1351,7 +1351,7 @@ impl ShiftExpressionStruct { pub type AdditiveExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1367,7 +1367,7 @@ impl AdditiveExpressionStruct { pub type MultiplicativeExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1383,7 +1383,7 @@ impl MultiplicativeExpressionStruct { pub type ExponentiationExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1399,7 +1399,7 @@ impl ExponentiationExpressionStruct { pub type PostfixExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1414,7 +1414,7 @@ impl PostfixExpressionStruct { pub type PrefixExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PrefixExpressionStruct { pub node: Rc, pub operator: Rc, @@ -1429,7 +1429,7 @@ impl PrefixExpressionStruct { pub type FunctionCallExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionCallExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1444,7 +1444,7 @@ impl FunctionCallExpressionStruct { pub type CallOptionsExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CallOptionsExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1459,7 +1459,7 @@ impl CallOptionsExpressionStruct { pub type MemberAccessExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1474,7 +1474,7 @@ impl MemberAccessExpressionStruct { pub type IndexAccessExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct IndexAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1490,7 +1490,7 @@ impl IndexAccessExpressionStruct { pub type IndexAccessEnd = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct IndexAccessEndStruct { pub node: Rc, pub end: Option, @@ -1504,7 +1504,7 @@ impl IndexAccessEndStruct { pub type PositionalArgumentsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PositionalArgumentsDeclarationStruct { pub node: Rc, pub arguments: PositionalArguments, @@ -1518,7 +1518,7 @@ impl PositionalArgumentsDeclarationStruct { pub type NamedArgumentsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedArgumentsDeclarationStruct { pub node: Rc, pub arguments: Option, @@ -1532,7 +1532,7 @@ impl NamedArgumentsDeclarationStruct { pub type NamedArgumentGroup = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedArgumentGroupStruct { pub node: Rc, pub arguments: NamedArguments, @@ -1546,7 +1546,7 @@ impl NamedArgumentGroupStruct { pub type NamedArgument = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedArgumentStruct { pub node: Rc, pub name: Rc, @@ -1561,7 +1561,7 @@ impl NamedArgumentStruct { pub type TypeExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TypeExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1575,7 +1575,7 @@ impl TypeExpressionStruct { pub type NewExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NewExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1589,7 +1589,7 @@ impl NewExpressionStruct { pub type TupleExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleExpressionStruct { pub node: Rc, pub items: TupleValues, @@ -1603,7 +1603,7 @@ impl TupleExpressionStruct { pub type TupleValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleValueStruct { pub node: Rc, pub expression: Option, @@ -1617,7 +1617,7 @@ impl TupleValueStruct { pub type ArrayExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ArrayExpressionStruct { pub node: Rc, pub items: ArrayValues, @@ -1631,7 +1631,7 @@ impl ArrayExpressionStruct { pub type HexNumberExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct HexNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1646,7 +1646,7 @@ impl HexNumberExpressionStruct { pub type DecimalNumberExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct DecimalNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1661,7 +1661,7 @@ impl DecimalNumberExpressionStruct { pub type YulBlock = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulBlockStruct { pub node: Rc, pub statements: YulStatements, @@ -1675,7 +1675,7 @@ impl YulBlockStruct { pub type YulFunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulFunctionDefinitionStruct { pub node: Rc, pub name: Rc, @@ -1692,7 +1692,7 @@ impl YulFunctionDefinitionStruct { pub type YulParametersDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulParametersDeclarationStruct { pub node: Rc, pub parameters: YulParameters, @@ -1706,7 +1706,7 @@ impl YulParametersDeclarationStruct { pub type YulReturnsDeclaration = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulReturnsDeclarationStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1720,7 +1720,7 @@ impl YulReturnsDeclarationStruct { pub type YulVariableDeclarationStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableDeclarationStatementStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1735,7 +1735,7 @@ impl YulVariableDeclarationStatementStruct { pub type YulVariableDeclarationValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableDeclarationValueStruct { pub node: Rc, pub assignment: YulAssignmentOperator, @@ -1750,7 +1750,7 @@ impl YulVariableDeclarationValueStruct { pub type YulVariableAssignmentStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableAssignmentStatementStruct { pub node: Rc, pub variables: YulPaths, @@ -1766,7 +1766,7 @@ impl YulVariableAssignmentStatementStruct { pub type YulColonAndEqual = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulColonAndEqualStruct { pub node: Rc, } @@ -1779,7 +1779,7 @@ impl YulColonAndEqualStruct { pub type YulStackAssignmentStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, @@ -1794,7 +1794,7 @@ impl YulStackAssignmentStatementStruct { pub type YulEqualAndColon = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulEqualAndColonStruct { pub node: Rc, } @@ -1807,7 +1807,7 @@ impl YulEqualAndColonStruct { pub type YulIfStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulIfStatementStruct { pub node: Rc, pub condition: YulExpression, @@ -1822,7 +1822,7 @@ impl YulIfStatementStruct { pub type YulForStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulForStatementStruct { pub node: Rc, pub initialization: YulBlock, @@ -1839,7 +1839,7 @@ impl YulForStatementStruct { pub type YulSwitchStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulSwitchStatementStruct { pub node: Rc, pub expression: YulExpression, @@ -1854,7 +1854,7 @@ impl YulSwitchStatementStruct { pub type YulDefaultCase = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulDefaultCaseStruct { pub node: Rc, pub body: YulBlock, @@ -1868,7 +1868,7 @@ impl YulDefaultCaseStruct { pub type YulValueCase = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulValueCaseStruct { pub node: Rc, pub value: YulLiteral, @@ -1883,7 +1883,7 @@ impl YulValueCaseStruct { pub type YulLeaveStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulLeaveStatementStruct { pub node: Rc, } @@ -1896,7 +1896,7 @@ impl YulLeaveStatementStruct { pub type YulBreakStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulBreakStatementStruct { pub node: Rc, } @@ -1909,7 +1909,7 @@ impl YulBreakStatementStruct { pub type YulContinueStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulContinueStatementStruct { pub node: Rc, } @@ -1922,7 +1922,7 @@ impl YulContinueStatementStruct { pub type YulLabel = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulLabelStruct { pub node: Rc, pub label: Rc, @@ -1936,7 +1936,7 @@ impl YulLabelStruct { pub type YulFunctionCallExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulFunctionCallExpressionStruct { pub node: Rc, pub operand: YulExpression, @@ -1953,7 +1953,7 @@ impl YulFunctionCallExpressionStruct { // Choices: // -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum SourceUnitMember { PragmaDirective(PragmaDirective), ImportDirective(ImportDirective), @@ -1970,33 +1970,33 @@ pub enum SourceUnitMember { ConstantDefinition(ConstantDefinition), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Pragma { VersionPragma(VersionPragma), AbicoderPragma(AbicoderPragma), ExperimentalPragma(ExperimentalPragma), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum AbicoderVersion { AbicoderV1Keyword, AbicoderV2Keyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ExperimentalFeature { StringLiteral(StringLiteral), ABIEncoderV2Keyword, SMTCheckerKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionExpression { VersionRange(VersionRange), VersionTerm(VersionTerm), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionOperator { Caret, Tilde, @@ -2007,27 +2007,27 @@ pub enum VersionOperator { GreaterThanEqual, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), SingleQuotedVersionLiteral(Rc), DoubleQuotedVersionLiteral(Rc), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ImportClause { PathImport(PathImport), NamedImport(NamedImport), ImportDeconstruction(ImportDeconstruction), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingClause { IdentifierPath(IdentifierPath), UsingDeconstruction(UsingDeconstruction), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingOperator { Ampersand, Asterisk, @@ -2046,19 +2046,19 @@ pub enum UsingOperator { Tilde, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingTarget { TypeName(TypeName), Asterisk, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ContractSpecifier { InheritanceSpecifier(InheritanceSpecifier), StorageLayoutSpecifier(StorageLayoutSpecifier), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ContractMember { UsingDirective(UsingDirective), FunctionDefinition(FunctionDefinition), @@ -2075,7 +2075,7 @@ pub enum ContractMember { StateVariableDefinition(StateVariableDefinition), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StateVariableAttribute { OverrideSpecifier(OverrideSpecifier), ConstantKeyword, @@ -2086,14 +2086,14 @@ pub enum StateVariableAttribute { TransientKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionName { Identifier(Rc), FallbackKeyword, ReceiveKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2108,13 +2108,13 @@ pub enum FunctionAttribute { VirtualKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionBody { Block(Block), Semicolon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ConstructorAttribute { ModifierInvocation(ModifierInvocation), InternalKeyword, @@ -2124,7 +2124,7 @@ pub enum ConstructorAttribute { VirtualKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UnnamedFunctionAttribute { ModifierInvocation(ModifierInvocation), ConstantKeyword, @@ -2137,7 +2137,7 @@ pub enum UnnamedFunctionAttribute { ViewKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FallbackFunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2148,7 +2148,7 @@ pub enum FallbackFunctionAttribute { VirtualKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ReceiveFunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2157,13 +2157,13 @@ pub enum ReceiveFunctionAttribute { VirtualKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ModifierAttribute { OverrideSpecifier(OverrideSpecifier), VirtualKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum TypeName { ArrayTypeName(ArrayTypeName), FunctionType(FunctionType), @@ -2172,7 +2172,7 @@ pub enum TypeName { IdentifierPath(IdentifierPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionTypeAttribute { InternalKeyword, ExternalKeyword, @@ -2184,13 +2184,13 @@ pub enum FunctionTypeAttribute { PayableKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum MappingKeyType { ElementaryType(ElementaryType), IdentifierPath(IdentifierPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ElementaryType { AddressType(AddressType), BytesKeyword(Rc), @@ -2203,7 +2203,7 @@ pub enum ElementaryType { StringKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Statement { IfStatement(IfStatement), ForStatement(ForStatement), @@ -2224,26 +2224,26 @@ pub enum Statement { ExpressionStatement(ExpressionStatement), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum TupleMember { TypedTupleMember(TypedTupleMember), UntypedTupleMember(UntypedTupleMember), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VariableDeclarationType { TypeName(TypeName), VarKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StorageLocation { MemoryKeyword, StorageKeyword, CallDataKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ForStatementInitialization { TupleDeconstructionStatement(TupleDeconstructionStatement), VariableDeclarationStatement(VariableDeclarationStatement), @@ -2251,13 +2251,13 @@ pub enum ForStatementInitialization { Semicolon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ForStatementCondition { ExpressionStatement(ExpressionStatement), Semicolon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Expression { AssignmentExpression(AssignmentExpression), ConditionalExpression(ConditionalExpression), @@ -2294,13 +2294,13 @@ pub enum Expression { FalseKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ArgumentsDeclaration { PositionalArgumentsDeclaration(PositionalArgumentsDeclaration), NamedArgumentsDeclaration(NamedArgumentsDeclaration), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum NumberUnit { WeiKeyword, GweiKeyword, @@ -2315,7 +2315,7 @@ pub enum NumberUnit { YearsKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StringExpression { StringLiteral(StringLiteral), StringLiterals(StringLiterals), @@ -2324,25 +2324,25 @@ pub enum StringExpression { UnicodeStringLiterals(UnicodeStringLiterals), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StringLiteral { SingleQuotedStringLiteral(Rc), DoubleQuotedStringLiteral(Rc), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum HexStringLiteral { SingleQuotedHexStringLiteral(Rc), DoubleQuotedHexStringLiteral(Rc), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UnicodeStringLiteral { SingleQuotedUnicodeStringLiteral(Rc), DoubleQuotedUnicodeStringLiteral(Rc), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulStatement { YulBlock(YulBlock), YulFunctionDefinition(YulFunctionDefinition), @@ -2359,32 +2359,32 @@ pub enum YulStatement { YulExpression(YulExpression), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulAssignmentOperator { YulColonAndEqual(YulColonAndEqual), ColonEqual, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulStackAssignmentOperator { YulEqualAndColon(YulEqualAndColon), EqualColon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulSwitchCase { YulDefaultCase(YulDefaultCase), YulValueCase(YulValueCase), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulExpression { YulFunctionCallExpression(YulFunctionCallExpression), YulLiteral(YulLiteral), YulPath(YulPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulLiteral { HexStringLiteral(HexStringLiteral), StringLiteral(StringLiteral), 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 93ce1009ff..42bcdc6bd3 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 @@ -13,7 +13,7 @@ use crate::cst::SyntaxNode; pub type SourceUnit = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct SourceUnitStruct { pub node: Rc, pub members: SourceUnitMembers, @@ -27,7 +27,7 @@ impl SourceUnitStruct { pub type PragmaDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PragmaDirectiveStruct { pub node: Rc, pub pragma: Pragma, @@ -41,7 +41,7 @@ impl PragmaDirectiveStruct { pub type AbicoderPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AbicoderPragmaStruct { pub node: Rc, pub version: AbicoderVersion, @@ -55,7 +55,7 @@ impl AbicoderPragmaStruct { pub type ExperimentalPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExperimentalPragmaStruct { pub node: Rc, pub feature: ExperimentalFeature, @@ -69,7 +69,7 @@ impl ExperimentalPragmaStruct { pub type VersionPragma = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionPragmaStruct { pub node: Rc, pub sets: VersionExpressionSets, @@ -83,7 +83,7 @@ impl VersionPragmaStruct { pub type VersionRange = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionRangeStruct { pub node: Rc, pub start: VersionLiteral, @@ -98,7 +98,7 @@ impl VersionRangeStruct { pub type VersionTerm = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VersionTermStruct { pub node: Rc, pub operator: Option, @@ -113,7 +113,7 @@ impl VersionTermStruct { pub type ImportDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDirectiveStruct { pub node: Rc, pub clause: ImportClause, @@ -127,7 +127,7 @@ impl ImportDirectiveStruct { pub type PathImport = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PathImportStruct { pub node: Rc, pub alias: Option>, @@ -142,7 +142,7 @@ impl PathImportStruct { pub type NamedImport = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedImportStruct { pub node: Rc, pub alias: Rc, @@ -157,7 +157,7 @@ impl NamedImportStruct { pub type ImportDeconstruction = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDeconstructionStruct { pub node: Rc, pub symbols: ImportDeconstructionSymbols, @@ -172,7 +172,7 @@ impl ImportDeconstructionStruct { pub type ImportDeconstructionSymbol = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, pub name: Rc, @@ -187,7 +187,7 @@ impl ImportDeconstructionSymbolStruct { pub type UsingDirective = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDirectiveStruct { pub node: Rc, pub clause: UsingClause, @@ -203,7 +203,7 @@ impl UsingDirectiveStruct { pub type UsingDeconstruction = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDeconstructionStruct { pub node: Rc, pub symbols: UsingDeconstructionSymbols, @@ -217,7 +217,7 @@ impl UsingDeconstructionStruct { pub type UsingDeconstructionSymbol = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UsingDeconstructionSymbolStruct { pub node: Rc, pub name: IdentifierPath, @@ -232,7 +232,7 @@ impl UsingDeconstructionSymbolStruct { pub type ContractDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, @@ -250,7 +250,7 @@ impl ContractDefinitionStruct { pub type InheritanceType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InheritanceTypeStruct { pub node: Rc, pub type_name: IdentifierPath, @@ -265,7 +265,7 @@ impl InheritanceTypeStruct { pub type InterfaceDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InterfaceDefinitionStruct { pub node: Rc, pub name: Rc, @@ -281,7 +281,7 @@ impl InterfaceDefinitionStruct { pub type LibraryDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct LibraryDefinitionStruct { pub node: Rc, pub name: Rc, @@ -296,7 +296,7 @@ impl LibraryDefinitionStruct { pub type StructDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StructDefinitionStruct { pub node: Rc, pub name: Rc, @@ -311,7 +311,7 @@ impl StructDefinitionStruct { pub type StructMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -326,7 +326,7 @@ impl StructMemberStruct { pub type EnumDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EnumDefinitionStruct { pub node: Rc, pub name: Rc, @@ -341,7 +341,7 @@ impl EnumDefinitionStruct { pub type ConstantDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -357,7 +357,7 @@ impl ConstantDefinitionStruct { pub type StateVariableDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -376,7 +376,7 @@ impl StateVariableDefinitionStruct { pub type FunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionDefinitionStruct { pub node: Rc, pub parameters: Parameters, @@ -399,7 +399,7 @@ impl FunctionDefinitionStruct { pub type Parameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -415,7 +415,7 @@ impl ParameterStruct { pub type OverrideSpecifier = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct OverrideSpecifierStruct { pub node: Rc, pub overridden: Option, @@ -429,7 +429,7 @@ impl OverrideSpecifierStruct { pub type ModifierInvocation = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ModifierInvocationStruct { pub node: Rc, pub name: IdentifierPath, @@ -444,7 +444,7 @@ impl ModifierInvocationStruct { pub type EventDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EventDefinitionStruct { pub node: Rc, pub name: Rc, @@ -460,7 +460,7 @@ impl EventDefinitionStruct { pub type EventParameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -476,7 +476,7 @@ impl EventParameterStruct { pub type UserDefinedValueTypeDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UserDefinedValueTypeDefinitionStruct { pub node: Rc, pub name: Rc, @@ -491,7 +491,7 @@ impl UserDefinedValueTypeDefinitionStruct { pub type ErrorDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ErrorDefinitionStruct { pub node: Rc, pub name: Rc, @@ -506,7 +506,7 @@ impl ErrorDefinitionStruct { pub type ErrorParameter = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -521,7 +521,7 @@ impl ErrorParameterStruct { pub type ArrayTypeName = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ArrayTypeNameStruct { pub node: Rc, pub operand: TypeName, @@ -536,7 +536,7 @@ impl ArrayTypeNameStruct { pub type FunctionType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionTypeStruct { pub node: Rc, pub parameters: Parameters, @@ -553,7 +553,7 @@ impl FunctionTypeStruct { pub type MappingType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingTypeStruct { pub node: Rc, pub key_type: MappingKey, @@ -568,7 +568,7 @@ impl MappingTypeStruct { pub type MappingKey = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, @@ -583,7 +583,7 @@ impl MappingKeyStruct { pub type MappingValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, @@ -598,7 +598,7 @@ impl MappingValueStruct { pub type AddressType = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AddressTypeStruct { pub node: Rc, pub payable_keyword: bool, @@ -612,7 +612,7 @@ impl AddressTypeStruct { pub type Block = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BlockStruct { pub node: Rc, pub statements: Statements, @@ -626,7 +626,7 @@ impl BlockStruct { pub type UncheckedBlock = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UncheckedBlockStruct { pub node: Rc, pub block: Block, @@ -640,7 +640,7 @@ impl UncheckedBlockStruct { pub type ExpressionStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExpressionStatementStruct { pub node: Rc, pub expression: Expression, @@ -654,7 +654,7 @@ impl ExpressionStatementStruct { pub type AssemblyStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AssemblyStatementStruct { pub node: Rc, pub body: YulBlock, @@ -670,7 +670,7 @@ impl AssemblyStatementStruct { pub type TupleDeconstructionStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleDeconstructionStatementStruct { pub node: Rc, pub var_keyword: bool, @@ -686,7 +686,7 @@ impl TupleDeconstructionStatementStruct { pub type TupleDeconstructionElement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleDeconstructionElementStruct { pub node: Rc, pub member: Option, @@ -700,7 +700,7 @@ impl TupleDeconstructionElementStruct { pub type TypedTupleMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -716,7 +716,7 @@ impl TypedTupleMemberStruct { pub type UntypedTupleMember = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, @@ -731,7 +731,7 @@ impl UntypedTupleMemberStruct { pub type VariableDeclarationStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, @@ -748,7 +748,7 @@ impl VariableDeclarationStatementStruct { pub type IfStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct IfStatementStruct { pub node: Rc, pub condition: Expression, @@ -764,7 +764,7 @@ impl IfStatementStruct { pub type ForStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ForStatementStruct { pub node: Rc, pub initialization: ForStatementInitialization, @@ -781,7 +781,7 @@ impl ForStatementStruct { pub type WhileStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct WhileStatementStruct { pub node: Rc, pub condition: Expression, @@ -796,7 +796,7 @@ impl WhileStatementStruct { pub type DoWhileStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct DoWhileStatementStruct { pub node: Rc, pub body: Statement, @@ -811,7 +811,7 @@ impl DoWhileStatementStruct { pub type ContinueStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ContinueStatementStruct { pub node: Rc, } @@ -824,7 +824,7 @@ impl ContinueStatementStruct { pub type BreakStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BreakStatementStruct { pub node: Rc, } @@ -837,7 +837,7 @@ impl BreakStatementStruct { pub type ReturnStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ReturnStatementStruct { pub node: Rc, pub expression: Option, @@ -851,7 +851,7 @@ impl ReturnStatementStruct { pub type EmitStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EmitStatementStruct { pub node: Rc, pub event: IdentifierPath, @@ -866,7 +866,7 @@ impl EmitStatementStruct { pub type TryStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TryStatementStruct { pub node: Rc, pub expression: Expression, @@ -883,7 +883,7 @@ impl TryStatementStruct { pub type CatchClause = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CatchClauseStruct { pub node: Rc, pub error: Option, @@ -898,7 +898,7 @@ impl CatchClauseStruct { pub type CatchClauseError = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CatchClauseErrorStruct { pub node: Rc, pub name: Option>, @@ -913,7 +913,7 @@ impl CatchClauseErrorStruct { pub type RevertStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct RevertStatementStruct { pub node: Rc, pub error: Option, @@ -928,7 +928,7 @@ impl RevertStatementStruct { pub type ThrowStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ThrowStatementStruct { pub node: Rc, } @@ -941,7 +941,7 @@ impl ThrowStatementStruct { pub type AssignmentExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -957,7 +957,7 @@ impl AssignmentExpressionStruct { pub type ConditionalExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ConditionalExpressionStruct { pub node: Rc, pub operand: Expression, @@ -973,7 +973,7 @@ impl ConditionalExpressionStruct { pub type OrExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct OrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -988,7 +988,7 @@ impl OrExpressionStruct { pub type AndExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1003,7 +1003,7 @@ impl AndExpressionStruct { pub type EqualityExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1019,7 +1019,7 @@ impl EqualityExpressionStruct { pub type InequalityExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1035,7 +1035,7 @@ impl InequalityExpressionStruct { pub type BitwiseOrExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseOrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1050,7 +1050,7 @@ impl BitwiseOrExpressionStruct { pub type BitwiseXorExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseXorExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1065,7 +1065,7 @@ impl BitwiseXorExpressionStruct { pub type BitwiseAndExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct BitwiseAndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1080,7 +1080,7 @@ impl BitwiseAndExpressionStruct { pub type ShiftExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1096,7 +1096,7 @@ impl ShiftExpressionStruct { pub type AdditiveExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1112,7 +1112,7 @@ impl AdditiveExpressionStruct { pub type MultiplicativeExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1128,7 +1128,7 @@ impl MultiplicativeExpressionStruct { pub type ExponentiationExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1144,7 +1144,7 @@ impl ExponentiationExpressionStruct { pub type PostfixExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1159,7 +1159,7 @@ impl PostfixExpressionStruct { pub type PrefixExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct PrefixExpressionStruct { pub node: Rc, pub operator: Rc, @@ -1174,7 +1174,7 @@ impl PrefixExpressionStruct { pub type FunctionCallExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct FunctionCallExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1189,7 +1189,7 @@ impl FunctionCallExpressionStruct { pub type CallOptionsExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct CallOptionsExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1204,7 +1204,7 @@ impl CallOptionsExpressionStruct { pub type MemberAccessExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1219,7 +1219,7 @@ impl MemberAccessExpressionStruct { pub type IndexAccessExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct IndexAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1235,7 +1235,7 @@ impl IndexAccessExpressionStruct { pub type NamedArgument = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NamedArgumentStruct { pub node: Rc, pub name: Rc, @@ -1250,7 +1250,7 @@ impl NamedArgumentStruct { pub type TypeExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TypeExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1264,7 +1264,7 @@ impl TypeExpressionStruct { pub type NewExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct NewExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1278,7 +1278,7 @@ impl NewExpressionStruct { pub type TupleExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleExpressionStruct { pub node: Rc, pub items: TupleValues, @@ -1292,7 +1292,7 @@ impl TupleExpressionStruct { pub type TupleValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct TupleValueStruct { pub node: Rc, pub expression: Option, @@ -1306,7 +1306,7 @@ impl TupleValueStruct { pub type ArrayExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ArrayExpressionStruct { pub node: Rc, pub items: ArrayValues, @@ -1320,7 +1320,7 @@ impl ArrayExpressionStruct { pub type HexNumberExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct HexNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1335,7 +1335,7 @@ impl HexNumberExpressionStruct { pub type DecimalNumberExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct DecimalNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1350,7 +1350,7 @@ impl DecimalNumberExpressionStruct { pub type YulBlock = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulBlockStruct { pub node: Rc, pub statements: YulStatements, @@ -1364,7 +1364,7 @@ impl YulBlockStruct { pub type YulFunctionDefinition = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulFunctionDefinitionStruct { pub node: Rc, pub name: Rc, @@ -1381,7 +1381,7 @@ impl YulFunctionDefinitionStruct { pub type YulVariableDeclarationStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableDeclarationStatementStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1396,7 +1396,7 @@ impl YulVariableDeclarationStatementStruct { pub type YulVariableDeclarationValue = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableDeclarationValueStruct { pub node: Rc, pub assignment: YulAssignmentOperator, @@ -1411,7 +1411,7 @@ impl YulVariableDeclarationValueStruct { pub type YulVariableAssignmentStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulVariableAssignmentStatementStruct { pub node: Rc, pub variables: YulPaths, @@ -1427,7 +1427,7 @@ impl YulVariableAssignmentStatementStruct { pub type YulColonAndEqual = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulColonAndEqualStruct { pub node: Rc, } @@ -1440,7 +1440,7 @@ impl YulColonAndEqualStruct { pub type YulStackAssignmentStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, @@ -1455,7 +1455,7 @@ impl YulStackAssignmentStatementStruct { pub type YulEqualAndColon = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulEqualAndColonStruct { pub node: Rc, } @@ -1468,7 +1468,7 @@ impl YulEqualAndColonStruct { pub type YulIfStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulIfStatementStruct { pub node: Rc, pub condition: YulExpression, @@ -1483,7 +1483,7 @@ impl YulIfStatementStruct { pub type YulForStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulForStatementStruct { pub node: Rc, pub initialization: YulBlock, @@ -1500,7 +1500,7 @@ impl YulForStatementStruct { pub type YulSwitchStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulSwitchStatementStruct { pub node: Rc, pub expression: YulExpression, @@ -1515,7 +1515,7 @@ impl YulSwitchStatementStruct { pub type YulDefaultCase = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulDefaultCaseStruct { pub node: Rc, pub body: YulBlock, @@ -1529,7 +1529,7 @@ impl YulDefaultCaseStruct { pub type YulValueCase = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulValueCaseStruct { pub node: Rc, pub value: YulLiteral, @@ -1544,7 +1544,7 @@ impl YulValueCaseStruct { pub type YulLeaveStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulLeaveStatementStruct { pub node: Rc, } @@ -1557,7 +1557,7 @@ impl YulLeaveStatementStruct { pub type YulBreakStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulBreakStatementStruct { pub node: Rc, } @@ -1570,7 +1570,7 @@ impl YulBreakStatementStruct { pub type YulContinueStatement = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulContinueStatementStruct { pub node: Rc, } @@ -1583,7 +1583,7 @@ impl YulContinueStatementStruct { pub type YulLabel = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulLabelStruct { pub node: Rc, pub label: Rc, @@ -1597,7 +1597,7 @@ impl YulLabelStruct { pub type YulFunctionCallExpression = Rc; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct YulFunctionCallExpressionStruct { pub node: Rc, pub operand: YulExpression, @@ -1614,7 +1614,7 @@ impl YulFunctionCallExpressionStruct { // Choices: // -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum SourceUnitMember { PragmaDirective(PragmaDirective), ImportDirective(ImportDirective), @@ -1631,33 +1631,33 @@ pub enum SourceUnitMember { ConstantDefinition(ConstantDefinition), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Pragma { VersionPragma(VersionPragma), AbicoderPragma(AbicoderPragma), ExperimentalPragma(ExperimentalPragma), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum AbicoderVersion { AbicoderV1Keyword, AbicoderV2Keyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ExperimentalFeature { StringLiteral(Rc), ABIEncoderV2Keyword, SMTCheckerKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionExpression { VersionRange(VersionRange), VersionTerm(VersionTerm), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionOperator { Caret, Tilde, @@ -1668,27 +1668,27 @@ pub enum VersionOperator { GreaterThanEqual, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), SingleQuotedVersionLiteral(Rc), DoubleQuotedVersionLiteral(Rc), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ImportClause { PathImport(PathImport), NamedImport(NamedImport), ImportDeconstruction(ImportDeconstruction), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingClause { IdentifierPath(IdentifierPath), UsingDeconstruction(UsingDeconstruction), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingOperator { Ampersand, Asterisk, @@ -1707,13 +1707,13 @@ pub enum UsingOperator { Tilde, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum UsingTarget { TypeName(TypeName), Asterisk, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ContractMember { UsingDirective(UsingDirective), FunctionDefinition(FunctionDefinition), @@ -1725,7 +1725,7 @@ pub enum ContractMember { StateVariableDefinition(StateVariableDefinition), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum TypeName { ArrayTypeName(ArrayTypeName), FunctionType(FunctionType), @@ -1734,13 +1734,13 @@ pub enum TypeName { IdentifierPath(IdentifierPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum MappingKeyType { ElementaryType(ElementaryType), IdentifierPath(IdentifierPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ElementaryType { AddressType(AddressType), BytesKeyword(Rc), @@ -1753,7 +1753,7 @@ pub enum ElementaryType { StringKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Statement { IfStatement(IfStatement), ForStatement(ForStatement), @@ -1774,26 +1774,26 @@ pub enum Statement { ExpressionStatement(ExpressionStatement), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum TupleMember { TypedTupleMember(TypedTupleMember), UntypedTupleMember(UntypedTupleMember), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum VariableDeclarationType { TypeName(TypeName), VarKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StorageLocation { MemoryKeyword, StorageKeyword, CallDataKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ForStatementInitialization { TupleDeconstructionStatement(TupleDeconstructionStatement), VariableDeclarationStatement(VariableDeclarationStatement), @@ -1801,13 +1801,13 @@ pub enum ForStatementInitialization { Semicolon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ForStatementCondition { ExpressionStatement(ExpressionStatement), Semicolon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Expression { AssignmentExpression(AssignmentExpression), ConditionalExpression(ConditionalExpression), @@ -1844,13 +1844,13 @@ pub enum Expression { FalseKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ArgumentsDeclaration { PositionalArguments(PositionalArguments), NamedArguments(NamedArguments), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum NumberUnit { WeiKeyword, GweiKeyword, @@ -1865,14 +1865,14 @@ pub enum NumberUnit { YearsKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StringExpression { Strings(Strings), HexStrings(HexStrings), UnicodeStrings(UnicodeStrings), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulStatement { YulBlock(YulBlock), YulFunctionDefinition(YulFunctionDefinition), @@ -1889,32 +1889,32 @@ pub enum YulStatement { YulExpression(YulExpression), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulAssignmentOperator { YulColonAndEqual(YulColonAndEqual), ColonEqual, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulStackAssignmentOperator { YulEqualAndColon(YulEqualAndColon), EqualColon, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulSwitchCase { YulDefaultCase(YulDefaultCase), YulValueCase(YulValueCase), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulExpression { YulFunctionCallExpression(YulFunctionCallExpression), YulLiteral(YulLiteral), YulPath(YulPath), } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum YulLiteral { YulDecimalLiteral(Rc), YulHexLiteral(Rc), @@ -1924,7 +1924,7 @@ pub enum YulLiteral { YulFalseKeyword, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionKind { Regular, Constructor, @@ -1934,7 +1934,7 @@ pub enum FunctionKind { Modifier, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionVisibility { Public, Private, @@ -1942,7 +1942,7 @@ pub enum FunctionVisibility { External, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum FunctionMutability { Pure, View, @@ -1950,14 +1950,14 @@ pub enum FunctionMutability { Payable, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StateVariableVisibility { Public, Private, Internal, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum StateVariableMutability { Mutable, Constant, diff --git a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs index 4edd8b573d..366b61cce2 100644 --- a/crates/solidity/outputs/cargo/crate/src/compilation/file.rs +++ b/crates/solidity/outputs/cargo/crate/src/compilation/file.rs @@ -4,11 +4,10 @@ use std::rc::Rc; use metaslang_cst::nodes::NodeId; use metaslang_cst::text_index::TextIndex; -use crate::cst::{Cursor, Node, NonterminalNode}; -use crate::parser::{ParseError, ParseOutput}; - #[cfg(feature = "__private_backend_api")] use crate::cst::SyntaxNode; +use crate::cst::{Cursor, NonterminalNode}; +use crate::parser::{ParseError, ParseOutput}; /// A single source file in the compilation unit. #[derive(Clone)] @@ -46,7 +45,7 @@ impl File { /// Returns the root syntax node of the parse tree. #[cfg(feature = "__private_backend_api")] pub fn syntax_tree(&self) -> Rc { - SyntaxNode::create_root(Node::Nonterminal(Rc::clone(&self.tree))) + SyntaxNode::create_root(crate::cst::Node::Nonterminal(Rc::clone(&self.tree))) } /// Returns a list of all errors encountered during parsing this file. 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 8779a571d3..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,10 +1,9 @@ use std::rc::Rc; -use crate::cst::{Cursor, Node, NonterminalNode, TextIndex}; -use crate::parser::ParseError; - #[cfg(feature = "__private_backend_api")] use crate::cst::SyntaxNode; +use crate::cst::{Cursor, NonterminalNode, TextIndex}; +use crate::parser::ParseError; /// The result of parsing source code using [`Parser`][`crate::parser::Parser`]. /// @@ -55,6 +54,6 @@ impl ParseOutput { /// Returns the root syntax node of the parse tree. #[cfg(feature = "__private_backend_api")] pub fn syntax_tree(&self) -> Rc { - SyntaxNode::create_root(Node::Nonterminal(Rc::clone(&self.tree))) + 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 index b536e477b9..6f577b4676 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs @@ -1,20 +1,5 @@ -use std::collections::{HashMap, HashSet}; - use slang_solidity::backend::binder::{Binder, Definition}; -use slang_solidity::compilation::CompilationUnit; -use slang_solidity::cst::{Cursor, Node, NodeId, TerminalKindExtensions}; - -pub(crate) fn collect_all_definitions<'a>( - compilation_unit: &'a CompilationUnit, - binder: &'a Binder, -) -> Vec<&'a Definition> { - let mut all_definitions = vec![]; - for file in compilation_unit.files() { - let cursor = file.create_tree_cursor(); - all_definitions.append(&mut collect_definitions(binder, &cursor)); - } - all_definitions -} +use slang_solidity::cst::{Cursor, TerminalKindExtensions}; pub(crate) fn collect_definitions<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a Definition> { let mut cursor = root.spawn(); @@ -30,24 +15,3 @@ pub(crate) fn collect_definitions<'a>(binder: &'a Binder, root: &Cursor) -> Vec< } definitions } - -pub(crate) fn map_definitions_ids<'a>( - compilation_unit: &'a CompilationUnit, - binder: &'a Binder, -) -> HashMap { - let mut result = HashMap::new(); - - let definitions = collect_all_definitions(compilation_unit, binder); - let definitions_ids: HashSet<_> = definitions.iter().map(|def| def.node_id()).collect(); - - for file in compilation_unit.files() { - let mut cursor = file.create_tree_cursor(); - while cursor.go_to_next() { - let node = cursor.node(); - if definitions_ids.contains(&node.id()) { - result.insert(node.id(), node); - } - } - } - result -} diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs deleted file mode 100644 index f2e0ba16ef..0000000000 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_nodes.rs +++ /dev/null @@ -1,1138 +0,0 @@ -use std::collections::HashMap; -use std::rc::Rc; - -use slang_solidity::backend::l2_flat_contracts::visitor::Visitor; -use slang_solidity::backend::l2_flat_contracts::*; -use slang_solidity::cst::NodeId; - -#[derive(Default, Debug)] -pub(crate) struct NodesMap { - pub(crate) map: HashMap, -} - -impl Visitor for NodesMap { - fn enter_source_unit(&mut self, node: &SourceUnit) -> bool { - self.map - .insert(node.node_id, Node::SourceUnit(Rc::clone(node))); - true - } - - fn enter_pragma_directive(&mut self, node: &PragmaDirective) -> bool { - self.map - .insert(node.node_id, Node::PragmaDirective(Rc::clone(node))); - true - } - - fn enter_abicoder_pragma(&mut self, node: &AbicoderPragma) -> bool { - self.map - .insert(node.node_id, Node::AbicoderPragma(Rc::clone(node))); - true - } - - fn enter_experimental_pragma(&mut self, node: &ExperimentalPragma) -> bool { - self.map - .insert(node.node_id, Node::ExperimentalPragma(Rc::clone(node))); - true - } - - fn enter_version_pragma(&mut self, node: &VersionPragma) -> bool { - self.map - .insert(node.node_id, Node::VersionPragma(Rc::clone(node))); - true - } - - fn enter_version_range(&mut self, node: &VersionRange) -> bool { - self.map - .insert(node.node_id, Node::VersionRange(Rc::clone(node))); - true - } - - fn enter_version_term(&mut self, node: &VersionTerm) -> bool { - self.map - .insert(node.node_id, Node::VersionTerm(Rc::clone(node))); - true - } - - fn enter_import_directive(&mut self, node: &ImportDirective) -> bool { - self.map - .insert(node.node_id, Node::ImportDirective(Rc::clone(node))); - true - } - - fn enter_path_import(&mut self, node: &PathImport) -> bool { - self.map - .insert(node.node_id, Node::PathImport(Rc::clone(node))); - true - } - - fn enter_named_import(&mut self, node: &NamedImport) -> bool { - self.map - .insert(node.node_id, Node::NamedImport(Rc::clone(node))); - true - } - - fn enter_import_deconstruction(&mut self, node: &ImportDeconstruction) -> bool { - self.map - .insert(node.node_id, Node::ImportDeconstruction(Rc::clone(node))); - true - } - - fn enter_import_deconstruction_symbol(&mut self, node: &ImportDeconstructionSymbol) -> bool { - self.map.insert( - node.node_id, - Node::ImportDeconstructionSymbol(Rc::clone(node)), - ); - true - } - - fn enter_import_alias(&mut self, node: &ImportAlias) -> bool { - self.map - .insert(node.node_id, Node::ImportAlias(Rc::clone(node))); - true - } - - fn enter_using_directive(&mut self, node: &UsingDirective) -> bool { - self.map - .insert(node.node_id, Node::UsingDirective(Rc::clone(node))); - true - } - - fn enter_using_deconstruction(&mut self, node: &UsingDeconstruction) -> bool { - self.map - .insert(node.node_id, Node::UsingDeconstruction(Rc::clone(node))); - true - } - - fn enter_using_deconstruction_symbol(&mut self, node: &UsingDeconstructionSymbol) -> bool { - self.map.insert( - node.node_id, - Node::UsingDeconstructionSymbol(Rc::clone(node)), - ); - true - } - - fn enter_using_alias(&mut self, node: &UsingAlias) -> bool { - self.map - .insert(node.node_id, Node::UsingAlias(Rc::clone(node))); - true - } - - fn enter_contract_definition(&mut self, node: &ContractDefinition) -> bool { - self.map - .insert(node.node_id, Node::ContractDefinition(Rc::clone(node))); - true - } - - fn enter_inheritance_specifier(&mut self, node: &InheritanceSpecifier) -> bool { - self.map - .insert(node.node_id, Node::InheritanceSpecifier(Rc::clone(node))); - true - } - - fn enter_inheritance_type(&mut self, node: &InheritanceType) -> bool { - self.map - .insert(node.node_id, Node::InheritanceType(Rc::clone(node))); - true - } - - fn enter_storage_layout_specifier(&mut self, node: &StorageLayoutSpecifier) -> bool { - self.map - .insert(node.node_id, Node::StorageLayoutSpecifier(Rc::clone(node))); - true - } - - fn enter_interface_definition(&mut self, node: &InterfaceDefinition) -> bool { - self.map - .insert(node.node_id, Node::InterfaceDefinition(Rc::clone(node))); - true - } - - fn enter_library_definition(&mut self, node: &LibraryDefinition) -> bool { - self.map - .insert(node.node_id, Node::LibraryDefinition(Rc::clone(node))); - true - } - - fn enter_struct_definition(&mut self, node: &StructDefinition) -> bool { - self.map - .insert(node.node_id, Node::StructDefinition(Rc::clone(node))); - true - } - - fn enter_struct_member(&mut self, node: &StructMember) -> bool { - self.map - .insert(node.node_id, Node::StructMember(Rc::clone(node))); - true - } - - fn enter_enum_definition(&mut self, node: &EnumDefinition) -> bool { - self.map - .insert(node.node_id, Node::EnumDefinition(Rc::clone(node))); - true - } - - fn enter_constant_definition(&mut self, node: &ConstantDefinition) -> bool { - self.map - .insert(node.node_id, Node::ConstantDefinition(Rc::clone(node))); - true - } - - fn enter_state_variable_definition(&mut self, node: &StateVariableDefinition) -> bool { - self.map - .insert(node.node_id, Node::StateVariableDefinition(Rc::clone(node))); - true - } - - fn enter_state_variable_definition_value( - &mut self, - node: &StateVariableDefinitionValue, - ) -> bool { - self.map.insert( - node.node_id, - Node::StateVariableDefinitionValue(Rc::clone(node)), - ); - true - } - - fn enter_function_definition(&mut self, node: &FunctionDefinition) -> bool { - self.map - .insert(node.node_id, Node::FunctionDefinition(Rc::clone(node))); - true - } - - fn enter_parameters_declaration(&mut self, node: &ParametersDeclaration) -> bool { - self.map - .insert(node.node_id, Node::ParametersDeclaration(Rc::clone(node))); - true - } - - fn enter_parameter(&mut self, node: &Parameter) -> bool { - self.map - .insert(node.node_id, Node::Parameter(Rc::clone(node))); - true - } - - fn enter_override_specifier(&mut self, node: &OverrideSpecifier) -> bool { - self.map - .insert(node.node_id, Node::OverrideSpecifier(Rc::clone(node))); - true - } - - fn enter_override_paths_declaration(&mut self, node: &OverridePathsDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::OverridePathsDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_returns_declaration(&mut self, node: &ReturnsDeclaration) -> bool { - self.map - .insert(node.node_id, Node::ReturnsDeclaration(Rc::clone(node))); - true - } - - fn enter_constructor_definition(&mut self, node: &ConstructorDefinition) -> bool { - self.map - .insert(node.node_id, Node::ConstructorDefinition(Rc::clone(node))); - true - } - - fn enter_unnamed_function_definition(&mut self, node: &UnnamedFunctionDefinition) -> bool { - self.map.insert( - node.node_id, - Node::UnnamedFunctionDefinition(Rc::clone(node)), - ); - true - } - - fn enter_fallback_function_definition(&mut self, node: &FallbackFunctionDefinition) -> bool { - self.map.insert( - node.node_id, - Node::FallbackFunctionDefinition(Rc::clone(node)), - ); - true - } - - fn enter_receive_function_definition(&mut self, node: &ReceiveFunctionDefinition) -> bool { - self.map.insert( - node.node_id, - Node::ReceiveFunctionDefinition(Rc::clone(node)), - ); - true - } - - fn enter_modifier_definition(&mut self, node: &ModifierDefinition) -> bool { - self.map - .insert(node.node_id, Node::ModifierDefinition(Rc::clone(node))); - true - } - - fn enter_modifier_invocation(&mut self, node: &ModifierInvocation) -> bool { - self.map - .insert(node.node_id, Node::ModifierInvocation(Rc::clone(node))); - true - } - - fn enter_event_definition(&mut self, node: &EventDefinition) -> bool { - self.map - .insert(node.node_id, Node::EventDefinition(Rc::clone(node))); - true - } - - fn enter_event_parameters_declaration(&mut self, node: &EventParametersDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::EventParametersDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_event_parameter(&mut self, node: &EventParameter) -> bool { - self.map - .insert(node.node_id, Node::EventParameter(Rc::clone(node))); - true - } - - fn enter_user_defined_value_type_definition( - &mut self, - node: &UserDefinedValueTypeDefinition, - ) -> bool { - self.map.insert( - node.node_id, - Node::UserDefinedValueTypeDefinition(Rc::clone(node)), - ); - true - } - - fn enter_error_definition(&mut self, node: &ErrorDefinition) -> bool { - self.map - .insert(node.node_id, Node::ErrorDefinition(Rc::clone(node))); - true - } - - fn enter_error_parameters_declaration(&mut self, node: &ErrorParametersDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::ErrorParametersDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_error_parameter(&mut self, node: &ErrorParameter) -> bool { - self.map - .insert(node.node_id, Node::ErrorParameter(Rc::clone(node))); - true - } - - fn enter_array_type_name(&mut self, node: &ArrayTypeName) -> bool { - self.map - .insert(node.node_id, Node::ArrayTypeName(Rc::clone(node))); - true - } - - fn enter_function_type(&mut self, node: &FunctionType) -> bool { - self.map - .insert(node.node_id, Node::FunctionType(Rc::clone(node))); - true - } - - fn enter_mapping_type(&mut self, node: &MappingType) -> bool { - self.map - .insert(node.node_id, Node::MappingType(Rc::clone(node))); - true - } - - fn enter_mapping_key(&mut self, node: &MappingKey) -> bool { - self.map - .insert(node.node_id, Node::MappingKey(Rc::clone(node))); - true - } - - fn enter_mapping_value(&mut self, node: &MappingValue) -> bool { - self.map - .insert(node.node_id, Node::MappingValue(Rc::clone(node))); - true - } - - fn enter_address_type(&mut self, node: &AddressType) -> bool { - self.map - .insert(node.node_id, Node::AddressType(Rc::clone(node))); - true - } - - fn enter_block(&mut self, node: &Block) -> bool { - self.map.insert(node.node_id, Node::Block(Rc::clone(node))); - true - } - - fn enter_unchecked_block(&mut self, node: &UncheckedBlock) -> bool { - self.map - .insert(node.node_id, Node::UncheckedBlock(Rc::clone(node))); - true - } - - fn enter_expression_statement(&mut self, node: &ExpressionStatement) -> bool { - self.map - .insert(node.node_id, Node::ExpressionStatement(Rc::clone(node))); - true - } - - fn enter_assembly_statement(&mut self, node: &AssemblyStatement) -> bool { - self.map - .insert(node.node_id, Node::AssemblyStatement(Rc::clone(node))); - true - } - - fn enter_assembly_flags_declaration(&mut self, node: &AssemblyFlagsDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::AssemblyFlagsDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_tuple_deconstruction_statement( - &mut self, - node: &TupleDeconstructionStatement, - ) -> bool { - self.map.insert( - node.node_id, - Node::TupleDeconstructionStatement(Rc::clone(node)), - ); - true - } - - fn enter_tuple_deconstruction_element(&mut self, node: &TupleDeconstructionElement) -> bool { - self.map.insert( - node.node_id, - Node::TupleDeconstructionElement(Rc::clone(node)), - ); - true - } - - fn enter_typed_tuple_member(&mut self, node: &TypedTupleMember) -> bool { - self.map - .insert(node.node_id, Node::TypedTupleMember(Rc::clone(node))); - true - } - - fn enter_untyped_tuple_member(&mut self, node: &UntypedTupleMember) -> bool { - self.map - .insert(node.node_id, Node::UntypedTupleMember(Rc::clone(node))); - true - } - - fn enter_variable_declaration_statement( - &mut self, - node: &VariableDeclarationStatement, - ) -> bool { - self.map.insert( - node.node_id, - Node::VariableDeclarationStatement(Rc::clone(node)), - ); - true - } - - fn enter_variable_declaration_value(&mut self, node: &VariableDeclarationValue) -> bool { - self.map.insert( - node.node_id, - Node::VariableDeclarationValue(Rc::clone(node)), - ); - true - } - - fn enter_if_statement(&mut self, node: &IfStatement) -> bool { - self.map - .insert(node.node_id, Node::IfStatement(Rc::clone(node))); - true - } - - fn enter_else_branch(&mut self, node: &ElseBranch) -> bool { - self.map - .insert(node.node_id, Node::ElseBranch(Rc::clone(node))); - true - } - - fn enter_for_statement(&mut self, node: &ForStatement) -> bool { - self.map - .insert(node.node_id, Node::ForStatement(Rc::clone(node))); - true - } - - fn enter_while_statement(&mut self, node: &WhileStatement) -> bool { - self.map - .insert(node.node_id, Node::WhileStatement(Rc::clone(node))); - true - } - - fn enter_do_while_statement(&mut self, node: &DoWhileStatement) -> bool { - self.map - .insert(node.node_id, Node::DoWhileStatement(Rc::clone(node))); - true - } - - fn enter_continue_statement(&mut self, node: &ContinueStatement) -> bool { - self.map - .insert(node.node_id, Node::ContinueStatement(Rc::clone(node))); - true - } - - fn enter_break_statement(&mut self, node: &BreakStatement) -> bool { - self.map - .insert(node.node_id, Node::BreakStatement(Rc::clone(node))); - true - } - - fn enter_return_statement(&mut self, node: &ReturnStatement) -> bool { - self.map - .insert(node.node_id, Node::ReturnStatement(Rc::clone(node))); - true - } - - fn enter_emit_statement(&mut self, node: &EmitStatement) -> bool { - self.map - .insert(node.node_id, Node::EmitStatement(Rc::clone(node))); - true - } - - fn enter_try_statement(&mut self, node: &TryStatement) -> bool { - self.map - .insert(node.node_id, Node::TryStatement(Rc::clone(node))); - true - } - - fn enter_catch_clause(&mut self, node: &CatchClause) -> bool { - self.map - .insert(node.node_id, Node::CatchClause(Rc::clone(node))); - true - } - - fn enter_catch_clause_error(&mut self, node: &CatchClauseError) -> bool { - self.map - .insert(node.node_id, Node::CatchClauseError(Rc::clone(node))); - true - } - - fn enter_revert_statement(&mut self, node: &RevertStatement) -> bool { - self.map - .insert(node.node_id, Node::RevertStatement(Rc::clone(node))); - true - } - - fn enter_throw_statement(&mut self, node: &ThrowStatement) -> bool { - self.map - .insert(node.node_id, Node::ThrowStatement(Rc::clone(node))); - true - } - - fn enter_assignment_expression(&mut self, node: &AssignmentExpression) -> bool { - self.map - .insert(node.node_id, Node::AssignmentExpression(Rc::clone(node))); - true - } - - fn enter_conditional_expression(&mut self, node: &ConditionalExpression) -> bool { - self.map - .insert(node.node_id, Node::ConditionalExpression(Rc::clone(node))); - true - } - - fn enter_or_expression(&mut self, node: &OrExpression) -> bool { - self.map - .insert(node.node_id, Node::OrExpression(Rc::clone(node))); - true - } - - fn enter_and_expression(&mut self, node: &AndExpression) -> bool { - self.map - .insert(node.node_id, Node::AndExpression(Rc::clone(node))); - true - } - - fn enter_equality_expression(&mut self, node: &EqualityExpression) -> bool { - self.map - .insert(node.node_id, Node::EqualityExpression(Rc::clone(node))); - true - } - - fn enter_inequality_expression(&mut self, node: &InequalityExpression) -> bool { - self.map - .insert(node.node_id, Node::InequalityExpression(Rc::clone(node))); - true - } - - fn enter_bitwise_or_expression(&mut self, node: &BitwiseOrExpression) -> bool { - self.map - .insert(node.node_id, Node::BitwiseOrExpression(Rc::clone(node))); - true - } - - fn enter_bitwise_xor_expression(&mut self, node: &BitwiseXorExpression) -> bool { - self.map - .insert(node.node_id, Node::BitwiseXorExpression(Rc::clone(node))); - true - } - - fn enter_bitwise_and_expression(&mut self, node: &BitwiseAndExpression) -> bool { - self.map - .insert(node.node_id, Node::BitwiseAndExpression(Rc::clone(node))); - true - } - - fn enter_shift_expression(&mut self, node: &ShiftExpression) -> bool { - self.map - .insert(node.node_id, Node::ShiftExpression(Rc::clone(node))); - true - } - - fn enter_additive_expression(&mut self, node: &AdditiveExpression) -> bool { - self.map - .insert(node.node_id, Node::AdditiveExpression(Rc::clone(node))); - true - } - - fn enter_multiplicative_expression(&mut self, node: &MultiplicativeExpression) -> bool { - self.map.insert( - node.node_id, - Node::MultiplicativeExpression(Rc::clone(node)), - ); - true - } - - fn enter_exponentiation_expression(&mut self, node: &ExponentiationExpression) -> bool { - self.map.insert( - node.node_id, - Node::ExponentiationExpression(Rc::clone(node)), - ); - true - } - - fn enter_postfix_expression(&mut self, node: &PostfixExpression) -> bool { - self.map - .insert(node.node_id, Node::PostfixExpression(Rc::clone(node))); - true - } - - fn enter_prefix_expression(&mut self, node: &PrefixExpression) -> bool { - self.map - .insert(node.node_id, Node::PrefixExpression(Rc::clone(node))); - true - } - - fn enter_function_call_expression(&mut self, node: &FunctionCallExpression) -> bool { - self.map - .insert(node.node_id, Node::FunctionCallExpression(Rc::clone(node))); - true - } - - fn enter_call_options_expression(&mut self, node: &CallOptionsExpression) -> bool { - self.map - .insert(node.node_id, Node::CallOptionsExpression(Rc::clone(node))); - true - } - - fn enter_member_access_expression(&mut self, node: &MemberAccessExpression) -> bool { - self.map - .insert(node.node_id, Node::MemberAccessExpression(Rc::clone(node))); - true - } - - fn enter_index_access_expression(&mut self, node: &IndexAccessExpression) -> bool { - self.map - .insert(node.node_id, Node::IndexAccessExpression(Rc::clone(node))); - true - } - - fn enter_index_access_end(&mut self, node: &IndexAccessEnd) -> bool { - self.map - .insert(node.node_id, Node::IndexAccessEnd(Rc::clone(node))); - true - } - - fn enter_positional_arguments_declaration( - &mut self, - node: &PositionalArgumentsDeclaration, - ) -> bool { - self.map.insert( - node.node_id, - Node::PositionalArgumentsDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_named_arguments_declaration(&mut self, node: &NamedArgumentsDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::NamedArgumentsDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_named_argument_group(&mut self, node: &NamedArgumentGroup) -> bool { - self.map - .insert(node.node_id, Node::NamedArgumentGroup(Rc::clone(node))); - true - } - - fn enter_named_argument(&mut self, node: &NamedArgument) -> bool { - self.map - .insert(node.node_id, Node::NamedArgument(Rc::clone(node))); - true - } - - fn enter_type_expression(&mut self, node: &TypeExpression) -> bool { - self.map - .insert(node.node_id, Node::TypeExpression(Rc::clone(node))); - true - } - - fn enter_new_expression(&mut self, node: &NewExpression) -> bool { - self.map - .insert(node.node_id, Node::NewExpression(Rc::clone(node))); - true - } - - fn enter_tuple_expression(&mut self, node: &TupleExpression) -> bool { - self.map - .insert(node.node_id, Node::TupleExpression(Rc::clone(node))); - true - } - - fn enter_tuple_value(&mut self, node: &TupleValue) -> bool { - self.map - .insert(node.node_id, Node::TupleValue(Rc::clone(node))); - true - } - - fn enter_array_expression(&mut self, node: &ArrayExpression) -> bool { - self.map - .insert(node.node_id, Node::ArrayExpression(Rc::clone(node))); - true - } - - fn enter_hex_number_expression(&mut self, node: &HexNumberExpression) -> bool { - self.map - .insert(node.node_id, Node::HexNumberExpression(Rc::clone(node))); - true - } - - fn enter_decimal_number_expression(&mut self, node: &DecimalNumberExpression) -> bool { - self.map - .insert(node.node_id, Node::DecimalNumberExpression(Rc::clone(node))); - true - } - - fn enter_yul_block(&mut self, node: &YulBlock) -> bool { - self.map - .insert(node.node_id, Node::YulBlock(Rc::clone(node))); - true - } - - fn enter_yul_function_definition(&mut self, node: &YulFunctionDefinition) -> bool { - self.map - .insert(node.node_id, Node::YulFunctionDefinition(Rc::clone(node))); - true - } - - fn enter_yul_parameters_declaration(&mut self, node: &YulParametersDeclaration) -> bool { - self.map.insert( - node.node_id, - Node::YulParametersDeclaration(Rc::clone(node)), - ); - true - } - - fn enter_yul_returns_declaration(&mut self, node: &YulReturnsDeclaration) -> bool { - self.map - .insert(node.node_id, Node::YulReturnsDeclaration(Rc::clone(node))); - true - } - - fn enter_yul_variable_declaration_statement( - &mut self, - node: &YulVariableDeclarationStatement, - ) -> bool { - self.map.insert( - node.node_id, - Node::YulVariableDeclarationStatement(Rc::clone(node)), - ); - true - } - - fn enter_yul_variable_declaration_value(&mut self, node: &YulVariableDeclarationValue) -> bool { - self.map.insert( - node.node_id, - Node::YulVariableDeclarationValue(Rc::clone(node)), - ); - true - } - - fn enter_yul_variable_assignment_statement( - &mut self, - node: &YulVariableAssignmentStatement, - ) -> bool { - self.map.insert( - node.node_id, - Node::YulVariableAssignmentStatement(Rc::clone(node)), - ); - true - } - - fn enter_yul_colon_and_equal(&mut self, node: &YulColonAndEqual) -> bool { - self.map - .insert(node.node_id, Node::YulColonAndEqual(Rc::clone(node))); - true - } - - fn enter_yul_stack_assignment_statement(&mut self, node: &YulStackAssignmentStatement) -> bool { - self.map.insert( - node.node_id, - Node::YulStackAssignmentStatement(Rc::clone(node)), - ); - true - } - - fn enter_yul_equal_and_colon(&mut self, node: &YulEqualAndColon) -> bool { - self.map - .insert(node.node_id, Node::YulEqualAndColon(Rc::clone(node))); - true - } - - fn enter_yul_if_statement(&mut self, node: &YulIfStatement) -> bool { - self.map - .insert(node.node_id, Node::YulIfStatement(Rc::clone(node))); - true - } - - fn enter_yul_for_statement(&mut self, node: &YulForStatement) -> bool { - self.map - .insert(node.node_id, Node::YulForStatement(Rc::clone(node))); - true - } - - fn enter_yul_switch_statement(&mut self, node: &YulSwitchStatement) -> bool { - self.map - .insert(node.node_id, Node::YulSwitchStatement(Rc::clone(node))); - true - } - - fn enter_yul_default_case(&mut self, node: &YulDefaultCase) -> bool { - self.map - .insert(node.node_id, Node::YulDefaultCase(Rc::clone(node))); - true - } - - fn enter_yul_value_case(&mut self, node: &YulValueCase) -> bool { - self.map - .insert(node.node_id, Node::YulValueCase(Rc::clone(node))); - true - } - - fn enter_yul_leave_statement(&mut self, node: &YulLeaveStatement) -> bool { - self.map - .insert(node.node_id, Node::YulLeaveStatement(Rc::clone(node))); - true - } - - fn enter_yul_break_statement(&mut self, node: &YulBreakStatement) -> bool { - self.map - .insert(node.node_id, Node::YulBreakStatement(Rc::clone(node))); - true - } - - fn enter_yul_continue_statement(&mut self, node: &YulContinueStatement) -> bool { - self.map - .insert(node.node_id, Node::YulContinueStatement(Rc::clone(node))); - true - } - - fn enter_yul_label(&mut self, node: &YulLabel) -> bool { - self.map - .insert(node.node_id, Node::YulLabel(Rc::clone(node))); - true - } - - fn enter_yul_function_call_expression(&mut self, node: &YulFunctionCallExpression) -> bool { - self.map.insert( - node.node_id, - Node::YulFunctionCallExpression(Rc::clone(node)), - ); - true - } - - fn enter_source_unit_member(&mut self, _node: &SourceUnitMember) -> bool { - true - } - fn enter_pragma(&mut self, _node: &Pragma) -> bool { - true - } - fn enter_abicoder_version(&mut self, _node: &AbicoderVersion) -> bool { - true - } - fn enter_experimental_feature(&mut self, _node: &ExperimentalFeature) -> bool { - true - } - fn enter_version_expression(&mut self, _node: &VersionExpression) -> bool { - true - } - fn enter_version_operator(&mut self, _node: &VersionOperator) -> bool { - true - } - fn enter_version_literal(&mut self, _node: &VersionLiteral) -> bool { - true - } - fn enter_import_clause(&mut self, _node: &ImportClause) -> bool { - true - } - fn enter_using_clause(&mut self, _node: &UsingClause) -> bool { - true - } - fn enter_using_operator(&mut self, _node: &UsingOperator) -> bool { - true - } - fn enter_using_target(&mut self, _node: &UsingTarget) -> bool { - true - } - fn enter_contract_specifier(&mut self, _node: &ContractSpecifier) -> bool { - true - } - fn enter_contract_member(&mut self, _node: &ContractMember) -> bool { - true - } - fn enter_state_variable_attribute(&mut self, _node: &StateVariableAttribute) -> bool { - true - } - - fn enter_function_name(&mut self, _node: &FunctionName) -> bool { - true - } - fn enter_function_attribute(&mut self, _node: &FunctionAttribute) -> bool { - true - } - fn enter_function_body(&mut self, _node: &FunctionBody) -> bool { - true - } - fn enter_constructor_attribute(&mut self, _node: &ConstructorAttribute) -> bool { - true - } - fn enter_unnamed_function_attribute(&mut self, _node: &UnnamedFunctionAttribute) -> bool { - true - } - fn enter_fallback_function_attribute(&mut self, _node: &FallbackFunctionAttribute) -> bool { - true - } - fn enter_receive_function_attribute(&mut self, _node: &ReceiveFunctionAttribute) -> bool { - true - } - fn enter_modifier_attribute(&mut self, _node: &ModifierAttribute) -> bool { - true - } - fn enter_type_name(&mut self, _node: &TypeName) -> bool { - true - } - fn enter_function_type_attribute(&mut self, _node: &FunctionTypeAttribute) -> bool { - true - } - fn enter_mapping_key_type(&mut self, _node: &MappingKeyType) -> bool { - true - } - fn enter_elementary_type(&mut self, _node: &ElementaryType) -> bool { - true - } - fn enter_statement(&mut self, _node: &Statement) -> bool { - true - } - fn enter_tuple_member(&mut self, _node: &TupleMember) -> bool { - true - } - fn enter_variable_declaration_type(&mut self, _node: &VariableDeclarationType) -> bool { - true - } - fn enter_storage_location(&mut self, _node: &StorageLocation) -> bool { - true - } - fn enter_for_statement_initialization(&mut self, _node: &ForStatementInitialization) -> bool { - true - } - fn enter_for_statement_condition(&mut self, _node: &ForStatementCondition) -> bool { - true - } - fn enter_expression(&mut self, _node: &Expression) -> bool { - true - } - fn enter_arguments_declaration(&mut self, _node: &ArgumentsDeclaration) -> bool { - true - } - fn enter_number_unit(&mut self, _node: &NumberUnit) -> bool { - true - } - fn enter_string_expression(&mut self, _node: &StringExpression) -> bool { - true - } - fn enter_string_literal(&mut self, _node: &StringLiteral) -> bool { - true - } - fn enter_hex_string_literal(&mut self, _node: &HexStringLiteral) -> bool { - true - } - fn enter_unicode_string_literal(&mut self, _node: &UnicodeStringLiteral) -> bool { - true - } - fn enter_yul_statement(&mut self, _node: &YulStatement) -> bool { - true - } - fn enter_yul_assignment_operator(&mut self, _node: &YulAssignmentOperator) -> bool { - true - } - fn enter_yul_stack_assignment_operator(&mut self, _node: &YulStackAssignmentOperator) -> bool { - true - } - fn enter_yul_switch_case(&mut self, _node: &YulSwitchCase) -> bool { - true - } - fn enter_yul_expression(&mut self, _node: &YulExpression) -> bool { - true - } - fn enter_yul_literal(&mut self, _node: &YulLiteral) -> bool { - true - } - fn enter_source_unit_members(&mut self, _items: &SourceUnitMembers) -> bool { - true - } - fn enter_version_expression_sets(&mut self, _items: &VersionExpressionSets) -> bool { - true - } - fn enter_version_expression_set(&mut self, _items: &VersionExpressionSet) -> bool { - true - } - fn enter_simple_version_literal(&mut self, _items: &SimpleVersionLiteral) -> bool { - true - } - fn enter_import_deconstruction_symbols( - &mut self, - _items: &ImportDeconstructionSymbols, - ) -> bool { - true - } - fn enter_using_deconstruction_symbols(&mut self, _items: &UsingDeconstructionSymbols) -> bool { - true - } - fn enter_inheritance_types(&mut self, _items: &InheritanceTypes) -> bool { - true - } - fn enter_contract_members(&mut self, _items: &ContractMembers) -> bool { - true - } - fn enter_interface_members(&mut self, _items: &InterfaceMembers) -> bool { - true - } - fn enter_library_members(&mut self, _items: &LibraryMembers) -> bool { - true - } - fn enter_struct_members(&mut self, _items: &StructMembers) -> bool { - true - } - fn enter_enum_members(&mut self, _items: &EnumMembers) -> bool { - true - } - fn enter_state_variable_attributes(&mut self, _items: &StateVariableAttributes) -> bool { - true - } - fn enter_parameters(&mut self, _items: &Parameters) -> bool { - true - } - fn enter_function_attributes(&mut self, _items: &FunctionAttributes) -> bool { - true - } - fn enter_override_paths(&mut self, _items: &OverridePaths) -> bool { - true - } - fn enter_constructor_attributes(&mut self, _items: &ConstructorAttributes) -> bool { - true - } - fn enter_unnamed_function_attributes(&mut self, _items: &UnnamedFunctionAttributes) -> bool { - true - } - fn enter_fallback_function_attributes(&mut self, _items: &FallbackFunctionAttributes) -> bool { - true - } - fn enter_receive_function_attributes(&mut self, _items: &ReceiveFunctionAttributes) -> bool { - true - } - fn enter_modifier_attributes(&mut self, _items: &ModifierAttributes) -> bool { - true - } - fn enter_event_parameters(&mut self, _items: &EventParameters) -> bool { - true - } - fn enter_error_parameters(&mut self, _items: &ErrorParameters) -> bool { - true - } - fn enter_function_type_attributes(&mut self, _items: &FunctionTypeAttributes) -> bool { - true - } - fn enter_statements(&mut self, _items: &Statements) -> bool { - true - } - fn enter_assembly_flags(&mut self, _items: &AssemblyFlags) -> bool { - true - } - fn enter_tuple_deconstruction_elements( - &mut self, - _items: &TupleDeconstructionElements, - ) -> bool { - true - } - fn enter_catch_clauses(&mut self, _items: &CatchClauses) -> bool { - true - } - fn enter_positional_arguments(&mut self, _items: &PositionalArguments) -> bool { - true - } - fn enter_named_arguments(&mut self, _items: &NamedArguments) -> bool { - true - } - fn enter_call_options(&mut self, _items: &CallOptions) -> bool { - true - } - fn enter_tuple_values(&mut self, _items: &TupleValues) -> bool { - true - } - fn enter_array_values(&mut self, _items: &ArrayValues) -> bool { - true - } - fn enter_string_literals(&mut self, _items: &StringLiterals) -> bool { - true - } - fn enter_hex_string_literals(&mut self, _items: &HexStringLiterals) -> bool { - true - } - fn enter_unicode_string_literals(&mut self, _items: &UnicodeStringLiterals) -> bool { - true - } - fn enter_identifier_path(&mut self, _items: &IdentifierPath) -> bool { - true - } - fn enter_yul_statements(&mut self, _items: &YulStatements) -> bool { - true - } - fn enter_yul_parameters(&mut self, _items: &YulParameters) -> bool { - true - } - fn enter_yul_variable_names(&mut self, _items: &YulVariableNames) -> bool { - true - } - fn enter_yul_switch_cases(&mut self, _items: &YulSwitchCases) -> bool { - true - } - fn enter_yul_arguments(&mut self, _items: &YulArguments) -> bool { - true - } - fn enter_yul_paths(&mut self, _items: &YulPaths) -> bool { - true - } - fn enter_yul_path(&mut self, _items: &YulPath) -> bool { - true - } -} 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 index 26af0243e4..68d5719b88 100644 --- 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 @@ -1,37 +1,23 @@ use std::collections::{HashMap, VecDeque}; -use anyhow::{bail, Result}; -use slang_solidity::backend::binder::definitions::FunctionVisibility; -use slang_solidity::backend::binder::Definition::{self, Function}; -use slang_solidity::cst::TextIndex; +use anyhow::{anyhow, Result}; +use slang_solidity::backend::binder::Definition; +use slang_solidity::cst::{NodeId, TextIndex}; -use crate::ast_api::collect_definitions::{collect_all_definitions, collect_definitions}; -use crate::ast_api::visit_definition::visit_definition_from_cursor; +use crate::ast_api::collect_definitions::collect_definitions; +use crate::ast_api::visit_definition::visit_definition; use crate::ast_api::CompilationOutput; pub fn find_unused_definitions<'a>( compilation_output: &'a CompilationOutput, starting_contract_name: &str, ) -> Vec<&'a Definition> { - fn is_private_function(def: &Definition) -> bool { - !matches!(def, Function(_)) - || matches!(def, Function(fundef) if matches!(fundef.visibility, FunctionVisibility::Private) || matches!(fundef.visibility, FunctionVisibility::Internal)) - } - - let all_definitions = collect_all_definitions( - &compilation_output.compilation_unit, - &compilation_output.binder, - ); - - // Only consider functions with private visibility as unused candidates - let mut unused_definitions: HashMap<_, _> = all_definitions - .iter() - .map(|def| (def.node_id(), *def)) - .filter(|(_, def)| is_private_function(def)) - .collect(); + 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) { + if let Ok(contract) = find_contract_by_name(all_definitions, starting_contract_name) { visit_queue.push_back(contract); } @@ -42,23 +28,8 @@ pub fn find_unused_definitions<'a>( } unused_definitions.remove(&node_id); - let definiens_definition = compilation_output - .binder - .find_definition_by_id(node_id) - .unwrap(); - - // TODO: missing way to obtain location from definition - // assert_user_file_location(definiens_location); - - let node = compilation_output - .cst_map - .get(&definiens_definition.node_id()) - .expect("The definiens_location to be in the nodes map"); - let followed = visit_definition_from_cursor( - &compilation_output.binder, - &node.clone().create_cursor(TextIndex::ZERO), - ); - for def in followed { + let definitions = visit_definition(compilation_output, to_visit); + for def in definitions { visit_queue.push_back(def); } } @@ -66,21 +37,16 @@ pub fn find_unused_definitions<'a>( // 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); + visit_queue.push_back(def); } while let Some(to_visit) = visit_queue.pop_front() { if !unused_definitions.contains_key(&to_visit.node_id()) { continue; } - // assert_user_file_location(definiens_location); - let node = compilation_output - .cst_map - .get(&to_visit.node_id()) - .expect("to_visit to be in the nodes map"); let inner_definitions = collect_definitions( &compilation_output.binder, - &node.clone().create_cursor(TextIndex::ZERO), + &to_visit.node().create_cursor(TextIndex::ZERO), ); for inner in inner_definitions { if inner.node_id() == to_visit.node_id() { @@ -90,28 +56,18 @@ pub fn find_unused_definitions<'a>( } } - unused_definitions.values().copied().collect() + unused_definitions.values().map(|def| *def).collect() } pub(crate) fn find_contract_by_name<'a>( - definitions: &Vec<&'a Definition>, - name: &'a str, + definitions: &'a HashMap, + name: &str, ) -> Result<&'a Definition> { - let matching_name: Vec<_> = definitions - .iter() - .filter(|def| { - if matches!(def, Definition::Contract(_)) { - def.identifier().text == name - } else { - false - } - }) - .collect(); - match matching_name.len() { - 0 => bail!("No contract matches name {name}"), - 1 => Ok(matching_name.first().unwrap()), - _ => bail!("{name} is ambiguous"), - } + 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] @@ -124,8 +80,7 @@ contract Test { "#; let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); let result = find_unused_definitions(&output, "Test"); - assert_eq!(result.len(), 1); - assert_eq!(result[0].identifier().text, "test".to_owned()); + assert_eq_defs!(result, ["test"]); } #[test] 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 index a78a9e748a..47cd5e7643 100644 --- 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 @@ -13,7 +13,7 @@ pub fn follow_all_references<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a D continue; } - if let Some(definition) = binder.naviagate_to(node.id()) { + if let Some(definition) = binder.navigate_to(node.id()) { referenced_definitions.push(definition); } } diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs index 3b108c873e..84c395e7b8 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs @@ -1,54 +1,19 @@ -use std::collections::HashMap; - -use slang_solidity::backend::binder::Binder; -use slang_solidity::backend::l2_flat_contracts::visitor::Visitor; -use slang_solidity::backend::passes; -use slang_solidity::compilation::CompilationUnit; -use slang_solidity::cst::{Node, NodeId}; - -use crate::ast_api::collect_definitions::map_definitions_ids; - -pub(crate) struct CompilationOutput { - pub(crate) binder: Binder, - pub(crate) compilation_unit: CompilationUnit, - pub(crate) cst_map: HashMap, - pub(crate) ast_map: HashMap, -} - -impl CompilationOutput { - pub(crate) fn from_passes(output: passes::p5_resolve_references::Output) -> CompilationOutput { - let map = map_definitions_ids(&output.compilation_unit, &output.binder); - let mut ast_visitor = collect_nodes::NodesMap::default(); - - for (_, file) in output.files { - ast_visitor.enter_source_unit(&file); - } - - CompilationOutput { - binder: output.binder, - compilation_unit: output.compilation_unit, - cst_map: map, - ast_map: ast_visitor.map, - } - } -} +type CompilationOutput = slang_solidity::backend::passes::p6_index_tree::Output; macro_rules! assert_eq_defs { ($xs:expr, $ys:expr) => { assert_eq!( $xs.iter() - .map(|def| def.identifier().text.as_str()) - .collect::>(), - $ys + .map(|def| def.identifier().unparse()) + .collect::>(), + $ys.iter().map(|s| (*s).to_string()).collect() ); }; } mod collect_definitions; -mod collect_nodes; mod find_unused_definitions; mod follow_all_references; -// mod map_nodes; 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 index f70e5d1c5d..22a191ffae 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs @@ -53,7 +53,8 @@ pub(crate) fn one_file_backend_pipeline(content: &str) -> Result( compilation_output: &'a CompilationOutput, @@ -16,19 +17,19 @@ pub fn visit_definition<'a>( Definition::Contract(contract_definition) => { visit_contract(compilation_output, contract_definition) } - Definition::Function(function_definition) => todo!(), - Definition::Modifier(modifier_definition) => todo!(), - _ => todo!(), - } -} - -fn type_name_node_id(type_name: &TypeName) -> Option { - match type_name { - TypeName::ArrayTypeName(array_type_name_struct) => Some(array_type_name_struct.node_id), - TypeName::FunctionType(function_type_struct) => Some(function_type_struct.node_id), - TypeName::MappingType(mapping_type_struct) => Some(mapping_type_struct.node_id), - TypeName::ElementaryType(_elementary_type) => None, - TypeName::IdentifierPath(terminal_nodes) => terminal_nodes.last().map(|last| last.id()), + Definition::Struct(_) | Definition::Library(_) | Definition::Enum(_) => vec![], + Definition::Function(definition) => follow_all_references( + &compilation_output.binder, + &definition.node.create_cursor(TextIndex::ZERO), + ), + Definition::Modifier(definition) => follow_all_references( + &compilation_output.binder, + &definition.node.create_cursor(TextIndex::ZERO), + ), + _ => collect_definitions( + &compilation_output.binder, + &definition.node().create_cursor(TextIndex::ZERO), + ), } } @@ -39,131 +40,112 @@ fn visit_contract<'a>( // for a contract, we need to explicitly follow inheritance specifiers and constructors, // and visit state variables and public functions - let contract = compilation_output - .ast_map - .get(&contract_definition.node_id) - .expect("Node to be defined") - .as_contract_definition(); - - let inheritance_definitions = - contract - .inheritance_types - .iter() - .map(|f| f.node_id) - .map(|node_id| { - compilation_output - .binder - .naviagate_to(node_id) - .expect("reference to be defined") - }); - - let state_vars_definitions = contract - .members + let contract = ir2_flat_contracts::ContractDefinition::into_ir( + &contract_definition.node, + &compilation_output.index, + ) + .expect("Contract to be defined"); + + let inheritance_nodes = contract + .inheritance_types .iter() - .filter_map(|member| match member { - ContractMember::StateVariableDefinition(sv_def) - if sv_def - .attributes - .contains(&StateVariableAttribute::PublicKeyword) => - { - let type_node_id = type_name_node_id(&sv_def.type_name); - if let Some(type_node_id) = type_node_id { - Some(vec![sv_def.node_id, type_node_id]) - } else { - Some(vec![sv_def.node_id]) - } - } - _ => None, - }) - .flatten() - .filter_map(|node_id| compilation_output.binder.naviagate_to(node_id)); - - // contract_definition.bases - todo!() -} + .map(|f| Rc::clone(&f.node)); -/// Visits a definition and returns all definitions that are referenced from its body. -/// This is a translation of the TypeScript logic from visit-definition.mts. -pub fn visit_definition_from_cursor<'a>(binder: &'a Binder, root: &Cursor) -> Vec<&'a Definition> { - let mut referenced_definitions = Vec::new(); - let mut cursor = root.spawn(); - while cursor.go_to_next_terminal() { - let node = cursor.node(); - if !node.is_terminal() { - continue; + let function_nodes = contract.members.iter().filter_map(|member| match member { + ir2_flat_contracts::ContractMember::FunctionDefinition(f) + if f.kind != ir2_flat_contracts::FunctionKind::Regular => + { + Some(Rc::clone(&f.node)) } - if !node.as_terminal().unwrap().kind.is_identifier() { - continue; + + _ => None, + }); + + 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 sv_def.visibility == ir2_flat_contracts::StateVariableVisibility::Public => + { + Some(sv_def.name.id()) } - if let Some(def) = binder - .find_reference_by_identifier_node_id(node.id()) - .and_then(|reference| reference.resolution.as_definition_id()) - .and_then(|def_id| binder.find_definition_by_id(def_id)) + _ => None, + }); + + let public_functions_ids = contract.members.iter().filter_map(|member| match member { + ir2_flat_contracts::ContractMember::FunctionDefinition(f) + if f.kind == ir2_flat_contracts::FunctionKind::Regular + && f.visibility == ir2_flat_contracts::FunctionVisibility::Public => { - referenced_definitions.push(def); + f.name.as_ref().map(|node| node.id()) } - } - referenced_definitions + + _ => None, + }); + + 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#" -abstract contract Ownable { +contract Ownable { }"#; let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); - let cursor = output.compilation_unit.files()[0].create_tree_cursor(); - let result = visit_definition_from_cursor(&output.binder, &cursor); + 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_one_reference() { +fn test_no_public_reference() { const FILE_CONTENT: &str = r#" -function test() { - test(); +contract Ownable { + function test() { + } }"#; let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); - let cursor = output.compilation_unit.files()[0].create_tree_cursor(); - let result = visit_definition_from_cursor(&output.binder, &cursor); - assert_eq_defs!(result, ["test"]); -} - -#[test] -fn test_function_reference() { - const FILE_CONTENT: &str = r#" -function test() { - test2(); -} - -function test2() { - test(); -} - "#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); - let mut cursor = output.compilation_unit.files()[0].create_tree_cursor(); - assert!(cursor.go_to_next_nonterminal_with_kind(NonterminalKind::FunctionDefinition)); - let result = visit_definition_from_cursor(&output.binder, &cursor); - assert_eq_defs!(result, ["test2"]); + 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_contract() { +fn test_public_function_reference() { const FILE_CONTENT: &str = r#" -contract Test { - function test() { - test2(); - } - - function test2() { - test(); +contract Ownable { + function test() public { } -} - "#; +}"#; let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); - let mut cursor = output.compilation_unit.files()[0].create_tree_cursor(); - assert!(cursor.go_to_next_nonterminal_with_kind(NonterminalKind::ContractDefinition)); - let result = visit_definition_from_cursor(&output.binder, &cursor); - assert_eq_defs!(result, vec!["test2", "test"]); + 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/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; From b6e0a610027d311a79f468b4b9183f05975a6acc Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Tue, 11 Nov 2025 14:18:14 -0300 Subject: [PATCH 23/27] little fixes --- crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs | 2 ++ .../outputs/cargo/tests/src/ast_api/find_unused_definitions.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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 1c0918b2dd..f5400e7f21 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/binder/mod.rs @@ -649,6 +649,8 @@ impl Binder { } } + // 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()) 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 index 68d5719b88..464d5b9ba9 100644 --- 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 @@ -56,7 +56,7 @@ pub fn find_unused_definitions<'a>( } } - unused_definitions.values().map(|def| *def).collect() + unused_definitions.values().copied().collect() } pub(crate) fn find_contract_by_name<'a>( From 430a6c636deb8886fea1c5cf35aaebbbec82160e Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Wed, 12 Nov 2025 11:40:40 -0300 Subject: [PATCH 24/27] comments and refactoring --- .../cargo/crate/src/backend/passes/mod.rs | 17 ++++ .../tests/src/ast_api/collect_definitions.rs | 1 + .../src/ast_api/find_unused_definitions.rs | 6 +- .../src/ast_api/follow_all_references.rs | 7 +- .../outputs/cargo/tests/src/ast_api/mod.rs | 4 +- .../cargo/tests/src/ast_api/pipeline.rs | 16 ++-- .../ast_api/test_find_unused_definitions.rs | 2 +- .../tests/src/ast_api/visit_definition.rs | 78 +++++++++++-------- 8 files changed, 79 insertions(+), 52 deletions(-) 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 df2ad51055..d67fc5a8fe 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs @@ -1,3 +1,5 @@ +use crate::compilation::CompilationUnit; + pub mod p0_build_ast; pub mod p1_flatten_contracts; pub mod p2_collect_definitions; @@ -5,3 +7,18 @@ pub mod p3_linearise_contracts; pub mod p4_type_definitions; pub mod p5_resolve_references; pub mod p6_index_tree; + +pub use crate::backend::ir::ir2_flat_contracts as ast; + +// TODO: likely we want to be more specific here +pub type CompilationOutput = p6_index_tree::Output; + +pub fn compile(unit: CompilationUnit) -> CompilationOutput { + let data = p0_build_ast::run(unit); + let data = p1_flatten_contracts::run(data); + let data = p2_collect_definitions::run(data); + let data = p3_linearise_contracts::run(data); + let data = p4_type_definitions::run(data); + let data = p5_resolve_references::run(data); + p6_index_tree::run(data) +} 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 index 6f577b4676..8563d95ca9 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/collect_definitions.rs @@ -1,6 +1,7 @@ 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(); 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 index 464d5b9ba9..8fc6751d41 100644 --- 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 @@ -2,11 +2,11 @@ use std::collections::{HashMap, VecDeque}; use anyhow::{anyhow, Result}; use slang_solidity::backend::binder::Definition; +use slang_solidity::backend::passes::CompilationOutput; use slang_solidity::cst::{NodeId, TextIndex}; use crate::ast_api::collect_definitions::collect_definitions; use crate::ast_api::visit_definition::visit_definition; -use crate::ast_api::CompilationOutput; pub fn find_unused_definitions<'a>( compilation_output: &'a CompilationOutput, @@ -78,7 +78,7 @@ contract Test { } } "#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); let result = find_unused_definitions(&output, "Test"); assert_eq_defs!(result, ["test"]); } @@ -95,7 +95,7 @@ contract Test { } } "#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + 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 index 47cd5e7643..a7f26cdcb6 100644 --- 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 @@ -1,15 +1,14 @@ 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_terminal() { - continue; - } - if !node.as_terminal().unwrap().kind.is_identifier() { + if node.is_nonterminal() && !node.as_terminal().unwrap().kind.is_identifier() { continue; } diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs index 84c395e7b8..333f9d7253 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/mod.rs @@ -1,5 +1,5 @@ -type CompilationOutput = slang_solidity::backend::passes::p6_index_tree::Output; - +// 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!( diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs index 22a191ffae..c02a04091e 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs @@ -1,9 +1,10 @@ use anyhow::{bail, Result}; -use slang_solidity::backend::passes; +use slang_solidity::backend::passes::{compile, CompilationOutput}; use slang_solidity::compilation::{CompilationBuilder, CompilationBuilderConfig, CompilationUnit}; use slang_solidity::utils::LanguageFacts; -use crate::ast_api::CompilationOutput; +// 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"; @@ -45,16 +46,9 @@ pub(crate) fn build_one_file_compilation_unit(content: &str) -> Result Result { +pub(crate) fn compile_one_file(content: &str) -> Result { let unit = build_one_file_compilation_unit(content)?; - let data = passes::p0_build_ast::run(unit); - let data = passes::p1_flatten_contracts::run(data); - let data = passes::p2_collect_definitions::run(data); - let data = passes::p3_linearise_contracts::run(data); - let data = passes::p4_type_definitions::run(data); - let data = passes::p5_resolve_references::run(data); - let data = passes::p6_index_tree::run(data); - + let data = compile(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 index d7bea44031..1c43f786fe 100644 --- 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 @@ -39,7 +39,7 @@ contract Counter is Ownable { #[test] fn test_find_unused_definitions() { - let unit = pipeline::one_file_backend_pipeline(MAIN_SOL_CONTENTS).unwrap(); + let unit = pipeline::compile_one_file(MAIN_SOL_CONTENTS).unwrap(); let unused = find_unused_definitions(&unit, "Counter"); 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 index a915f6f60f..67a9c59a37 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -1,13 +1,13 @@ use std::rc::Rc; use slang_solidity::backend::binder::{ContractDefinition, Definition}; -use slang_solidity::backend::ir::ir2_flat_contracts::index::IntoIr; -use slang_solidity::backend::ir::ir2_flat_contracts::{self, ContractMember}; +use slang_solidity::backend::passes::ast::index::IntoIr; +use slang_solidity::backend::passes::ast::{self, ContractMember}; +use slang_solidity::backend::passes::CompilationOutput; use slang_solidity::cst::TextIndex; use crate::ast_api::collect_definitions::collect_definitions; use crate::ast_api::follow_all_references::follow_all_references; -use crate::ast_api::CompilationOutput; pub fn visit_definition<'a>( compilation_output: &'a CompilationOutput, @@ -15,21 +15,37 @@ pub fn visit_definition<'a>( ) -> 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(_) => vec![], - Definition::Function(definition) => follow_all_references( - &compilation_output.binder, - &definition.node.create_cursor(TextIndex::ZERO), - ), - Definition::Modifier(definition) => follow_all_references( - &compilation_output.binder, - &definition.node.create_cursor(TextIndex::ZERO), - ), - _ => collect_definitions( - &compilation_output.binder, - &definition.node().create_cursor(TextIndex::ZERO), - ), + 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), + ) + } } } @@ -40,27 +56,25 @@ fn visit_contract<'a>( // for a contract, we need to explicitly follow inheritance specifiers and constructors, // and visit state variables and public functions - let contract = ir2_flat_contracts::ContractDefinition::into_ir( - &contract_definition.node, - &compilation_output.index, - ) - .expect("Contract to be defined"); + 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 { - ir2_flat_contracts::ContractMember::FunctionDefinition(f) - if f.kind != ir2_flat_contracts::FunctionKind::Regular => - { + ast::ContractMember::FunctionDefinition(f) if 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)) @@ -68,7 +82,7 @@ fn visit_contract<'a>( let public_state_vars_ids = contract.members.iter().filter_map(|member| match member { ContractMember::StateVariableDefinition(sv_def) - if sv_def.visibility == ir2_flat_contracts::StateVariableVisibility::Public => + if sv_def.visibility == ast::StateVariableVisibility::Public => { Some(sv_def.name.id()) } @@ -77,9 +91,9 @@ fn visit_contract<'a>( }); let public_functions_ids = contract.members.iter().filter_map(|member| match member { - ir2_flat_contracts::ContractMember::FunctionDefinition(f) - if f.kind == ir2_flat_contracts::FunctionKind::Regular - && f.visibility == ir2_flat_contracts::FunctionVisibility::Public => + ast::ContractMember::FunctionDefinition(f) + if f.kind == ast::FunctionKind::Regular + && f.visibility == ast::FunctionVisibility::Public => { f.name.as_ref().map(|node| node.id()) } @@ -87,6 +101,8 @@ fn visit_contract<'a>( _ => 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| { @@ -103,7 +119,7 @@ fn test_no_references() { const FILE_CONTENT: &str = r#" contract Ownable { }"#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); let defs = output.binder.definitions(); assert_eq!(defs.len(), 1); assert_eq!( @@ -123,7 +139,7 @@ contract Ownable { function test() { } }"#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); let defs = output.binder.definitions(); let (_, contract) = defs .iter() @@ -140,7 +156,7 @@ contract Ownable { function test() public { } }"#; - let output = crate::ast_api::pipeline::one_file_backend_pipeline(FILE_CONTENT).unwrap(); + let output = crate::ast_api::pipeline::compile_one_file(FILE_CONTENT).unwrap(); let defs = output.binder.definitions(); let (_, contract) = defs .iter() From a8ad0c34a86bc6b6a7568c07cb7458d96f187069 Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Thu, 13 Nov 2025 11:39:09 -0300 Subject: [PATCH 25/27] Remove duplicated code --- .../outputs/cargo/crate/src/backend/passes/mod.rs | 15 --------------- .../tests/src/ast_api/find_unused_definitions.rs | 4 ++-- .../outputs/cargo/tests/src/ast_api/pipeline.rs | 6 +++--- .../cargo/tests/src/ast_api/visit_definition.rs | 6 +++--- 4 files changed, 8 insertions(+), 23 deletions(-) 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 d67fc5a8fe..dd14684d2f 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs @@ -1,5 +1,3 @@ -use crate::compilation::CompilationUnit; - pub mod p0_build_ast; pub mod p1_flatten_contracts; pub mod p2_collect_definitions; @@ -9,16 +7,3 @@ pub mod p5_resolve_references; pub mod p6_index_tree; pub use crate::backend::ir::ir2_flat_contracts as ast; - -// TODO: likely we want to be more specific here -pub type CompilationOutput = p6_index_tree::Output; - -pub fn compile(unit: CompilationUnit) -> CompilationOutput { - let data = p0_build_ast::run(unit); - let data = p1_flatten_contracts::run(data); - let data = p2_collect_definitions::run(data); - let data = p3_linearise_contracts::run(data); - let data = p4_type_definitions::run(data); - let data = p5_resolve_references::run(data); - p6_index_tree::run(data) -} 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 index 8fc6751d41..fadc5e4d5c 100644 --- 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 @@ -2,14 +2,14 @@ use std::collections::{HashMap, VecDeque}; use anyhow::{anyhow, Result}; use slang_solidity::backend::binder::Definition; -use slang_solidity::backend::passes::CompilationOutput; +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 CompilationOutput, + compilation_output: &'a BinderOutput, starting_contract_name: &str, ) -> Vec<&'a Definition> { let all_definitions = compilation_output.binder.definitions(); diff --git a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs index c02a04091e..08bf01186b 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/pipeline.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Result}; -use slang_solidity::backend::passes::{compile, CompilationOutput}; +use slang_solidity::backend::{build_binder_output, BinderOutput}; use slang_solidity::compilation::{CompilationBuilder, CompilationBuilderConfig, CompilationUnit}; use slang_solidity::utils::LanguageFacts; @@ -46,9 +46,9 @@ pub(crate) fn build_one_file_compilation_unit(content: &str) -> Result Result { +pub(crate) fn compile_one_file(content: &str) -> Result { let unit = build_one_file_compilation_unit(content)?; - let data = compile(unit); + 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/visit_definition.rs b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs index 67a9c59a37..3021ca2611 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -3,14 +3,14 @@ use std::rc::Rc; use slang_solidity::backend::binder::{ContractDefinition, Definition}; use slang_solidity::backend::passes::ast::index::IntoIr; use slang_solidity::backend::passes::ast::{self, ContractMember}; -use slang_solidity::backend::passes::CompilationOutput; +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 CompilationOutput, + compilation_output: &'a BinderOutput, definition: &'a Definition, ) -> Vec<&'a Definition> { match definition { @@ -50,7 +50,7 @@ pub fn visit_definition<'a>( } fn visit_contract<'a>( - compilation_output: &'a CompilationOutput, + compilation_output: &'a BinderOutput, contract_definition: &ContractDefinition, ) -> Vec<&'a Definition> { // for a contract, we need to explicitly follow inheritance specifiers and constructors, From 4270da26e58250fc3aaa349d78c5655d888813dd Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Thu, 13 Nov 2025 11:42:12 -0300 Subject: [PATCH 26/27] moved type ast to binder mod --- crates/solidity/outputs/cargo/crate/src/backend/mod.rs | 2 ++ crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs | 2 -- .../outputs/cargo/tests/src/ast_api/visit_definition.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs index 5ce3b0d7c3..b6db4db865 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/mod.rs @@ -8,6 +8,8 @@ pub mod ir; pub mod passes; pub mod types; +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 { 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 dd14684d2f..df2ad51055 100644 --- a/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/backend/passes/mod.rs @@ -5,5 +5,3 @@ pub mod p3_linearise_contracts; pub mod p4_type_definitions; pub mod p5_resolve_references; pub mod p6_index_tree; - -pub use crate::backend::ir::ir2_flat_contracts as ast; 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 index 3021ca2611..a2d82a9aed 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -1,8 +1,8 @@ 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::passes::ast::index::IntoIr; -use slang_solidity::backend::passes::ast::{self, ContractMember}; use slang_solidity::backend::BinderOutput; use slang_solidity::cst::TextIndex; From 106cc61a6392e8c2a18461b9f0612a16455d8cf9 Mon Sep 17 00:00:00 2001 From: Beta Ziliani Date: Thu, 13 Nov 2025 11:47:13 -0300 Subject: [PATCH 27/27] Revert inclusion of PartialEq --- .../src/backend/ir/common/_nodes.rs.jinja2 | 4 +- .../ir/ir1_structured_ast/nodes.generated.rs | 350 +++++++++--------- .../ir/ir2_flat_contracts/nodes.generated.rs | 284 +++++++------- .../tests/src/ast_api/visit_definition.rs | 10 +- 4 files changed, 325 insertions(+), 323 deletions(-) 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 81d1fe97f2..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 @@ -12,7 +12,7 @@ {% for parent_type, sequence in target.sequences %} pub type {{ parent_type }} = Rc<{{ parent_type }}Struct>; - #[derive(Debug, PartialEq)] + #[derive(Debug)] pub struct {{ parent_type }}Struct { pub node: Rc, {%- for field in sequence.fields %} @@ -52,7 +52,7 @@ // {% for parent_type, choice in target.choices %} - #[derive(Debug, PartialEq)] + #[derive(Debug)] pub enum {{ parent_type }} { {% for nonterminal in choice.variants | filter(attribute="kind", value="Nonterminal") -%} {{ nonterminal.name }}({{ nonterminal.name }}), 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 af92f0b1f4..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 @@ -13,7 +13,7 @@ use crate::cst::SyntaxNode; pub type SourceUnit = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct SourceUnitStruct { pub node: Rc, pub members: SourceUnitMembers, @@ -27,7 +27,7 @@ impl SourceUnitStruct { pub type PragmaDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PragmaDirectiveStruct { pub node: Rc, pub pragma: Pragma, @@ -41,7 +41,7 @@ impl PragmaDirectiveStruct { pub type AbicoderPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AbicoderPragmaStruct { pub node: Rc, pub version: AbicoderVersion, @@ -55,7 +55,7 @@ impl AbicoderPragmaStruct { pub type ExperimentalPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExperimentalPragmaStruct { pub node: Rc, pub feature: ExperimentalFeature, @@ -69,7 +69,7 @@ impl ExperimentalPragmaStruct { pub type VersionPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionPragmaStruct { pub node: Rc, pub sets: VersionExpressionSets, @@ -83,7 +83,7 @@ impl VersionPragmaStruct { pub type VersionRange = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionRangeStruct { pub node: Rc, pub start: VersionLiteral, @@ -98,7 +98,7 @@ impl VersionRangeStruct { pub type VersionTerm = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionTermStruct { pub node: Rc, pub operator: Option, @@ -113,7 +113,7 @@ impl VersionTermStruct { pub type ImportDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDirectiveStruct { pub node: Rc, pub clause: ImportClause, @@ -127,7 +127,7 @@ impl ImportDirectiveStruct { pub type PathImport = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PathImportStruct { pub node: Rc, pub path: StringLiteral, @@ -142,7 +142,7 @@ impl PathImportStruct { pub type NamedImport = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedImportStruct { pub node: Rc, pub alias: ImportAlias, @@ -157,7 +157,7 @@ impl NamedImportStruct { pub type ImportDeconstruction = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDeconstructionStruct { pub node: Rc, pub symbols: ImportDeconstructionSymbols, @@ -172,7 +172,7 @@ impl ImportDeconstructionStruct { pub type ImportDeconstructionSymbol = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, pub name: Rc, @@ -187,7 +187,7 @@ impl ImportDeconstructionSymbolStruct { pub type ImportAlias = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportAliasStruct { pub node: Rc, pub identifier: Rc, @@ -201,7 +201,7 @@ impl ImportAliasStruct { pub type UsingDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDirectiveStruct { pub node: Rc, pub clause: UsingClause, @@ -217,7 +217,7 @@ impl UsingDirectiveStruct { pub type UsingDeconstruction = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDeconstructionStruct { pub node: Rc, pub symbols: UsingDeconstructionSymbols, @@ -231,7 +231,7 @@ impl UsingDeconstructionStruct { pub type UsingDeconstructionSymbol = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDeconstructionSymbolStruct { pub node: Rc, pub name: IdentifierPath, @@ -246,7 +246,7 @@ impl UsingDeconstructionSymbolStruct { pub type UsingAlias = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingAliasStruct { pub node: Rc, pub operator: UsingOperator, @@ -260,7 +260,7 @@ impl UsingAliasStruct { pub type ContractDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, @@ -277,7 +277,7 @@ impl ContractDefinitionStruct { pub type InheritanceSpecifier = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InheritanceSpecifierStruct { pub node: Rc, pub types: InheritanceTypes, @@ -291,7 +291,7 @@ impl InheritanceSpecifierStruct { pub type InheritanceType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InheritanceTypeStruct { pub node: Rc, pub type_name: IdentifierPath, @@ -306,7 +306,7 @@ impl InheritanceTypeStruct { pub type StorageLayoutSpecifier = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StorageLayoutSpecifierStruct { pub node: Rc, pub expression: Expression, @@ -320,7 +320,7 @@ impl StorageLayoutSpecifierStruct { pub type InterfaceDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InterfaceDefinitionStruct { pub node: Rc, pub name: Rc, @@ -336,7 +336,7 @@ impl InterfaceDefinitionStruct { pub type LibraryDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct LibraryDefinitionStruct { pub node: Rc, pub name: Rc, @@ -351,7 +351,7 @@ impl LibraryDefinitionStruct { pub type StructDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StructDefinitionStruct { pub node: Rc, pub name: Rc, @@ -366,7 +366,7 @@ impl StructDefinitionStruct { pub type StructMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -381,7 +381,7 @@ impl StructMemberStruct { pub type EnumDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EnumDefinitionStruct { pub node: Rc, pub name: Rc, @@ -396,7 +396,7 @@ impl EnumDefinitionStruct { pub type ConstantDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -412,7 +412,7 @@ impl ConstantDefinitionStruct { pub type StateVariableDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -429,7 +429,7 @@ impl StateVariableDefinitionStruct { pub type StateVariableDefinitionValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StateVariableDefinitionValueStruct { pub node: Rc, pub value: Expression, @@ -443,7 +443,7 @@ impl StateVariableDefinitionValueStruct { pub type FunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionDefinitionStruct { pub node: Rc, pub name: FunctionName, @@ -461,7 +461,7 @@ impl FunctionDefinitionStruct { pub type ParametersDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ParametersDeclarationStruct { pub node: Rc, pub parameters: Parameters, @@ -475,7 +475,7 @@ impl ParametersDeclarationStruct { pub type Parameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -491,7 +491,7 @@ impl ParameterStruct { pub type OverrideSpecifier = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct OverrideSpecifierStruct { pub node: Rc, pub overridden: Option, @@ -505,7 +505,7 @@ impl OverrideSpecifierStruct { pub type OverridePathsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct OverridePathsDeclarationStruct { pub node: Rc, pub paths: OverridePaths, @@ -519,7 +519,7 @@ impl OverridePathsDeclarationStruct { pub type ReturnsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ReturnsDeclarationStruct { pub node: Rc, pub variables: ParametersDeclaration, @@ -533,7 +533,7 @@ impl ReturnsDeclarationStruct { pub type ConstructorDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ConstructorDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -549,7 +549,7 @@ impl ConstructorDefinitionStruct { pub type UnnamedFunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UnnamedFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -565,7 +565,7 @@ impl UnnamedFunctionDefinitionStruct { pub type FallbackFunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FallbackFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -582,7 +582,7 @@ impl FallbackFunctionDefinitionStruct { pub type ReceiveFunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ReceiveFunctionDefinitionStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -598,7 +598,7 @@ impl ReceiveFunctionDefinitionStruct { pub type ModifierDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ModifierDefinitionStruct { pub node: Rc, pub name: Rc, @@ -615,7 +615,7 @@ impl ModifierDefinitionStruct { pub type ModifierInvocation = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ModifierInvocationStruct { pub node: Rc, pub name: IdentifierPath, @@ -630,7 +630,7 @@ impl ModifierInvocationStruct { pub type EventDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EventDefinitionStruct { pub node: Rc, pub name: Rc, @@ -646,7 +646,7 @@ impl EventDefinitionStruct { pub type EventParametersDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EventParametersDeclarationStruct { pub node: Rc, pub parameters: EventParameters, @@ -660,7 +660,7 @@ impl EventParametersDeclarationStruct { pub type EventParameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -676,7 +676,7 @@ impl EventParameterStruct { pub type UserDefinedValueTypeDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { pub node: Rc, pub name: Rc, @@ -691,7 +691,7 @@ impl UserDefinedValueTypeDefinitionStruct { pub type ErrorDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ErrorDefinitionStruct { pub node: Rc, pub name: Rc, @@ -706,7 +706,7 @@ impl ErrorDefinitionStruct { pub type ErrorParametersDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ErrorParametersDeclarationStruct { pub node: Rc, pub parameters: ErrorParameters, @@ -720,7 +720,7 @@ impl ErrorParametersDeclarationStruct { pub type ErrorParameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -735,7 +735,7 @@ impl ErrorParameterStruct { pub type ArrayTypeName = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ArrayTypeNameStruct { pub node: Rc, pub operand: TypeName, @@ -750,7 +750,7 @@ impl ArrayTypeNameStruct { pub type FunctionType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionTypeStruct { pub node: Rc, pub parameters: ParametersDeclaration, @@ -766,7 +766,7 @@ impl FunctionTypeStruct { pub type MappingType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingTypeStruct { pub node: Rc, pub key_type: MappingKey, @@ -781,7 +781,7 @@ impl MappingTypeStruct { pub type MappingKey = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, @@ -796,7 +796,7 @@ impl MappingKeyStruct { pub type MappingValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, @@ -811,7 +811,7 @@ impl MappingValueStruct { pub type AddressType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AddressTypeStruct { pub node: Rc, pub payable_keyword: bool, @@ -825,7 +825,7 @@ impl AddressTypeStruct { pub type Block = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BlockStruct { pub node: Rc, pub statements: Statements, @@ -839,7 +839,7 @@ impl BlockStruct { pub type UncheckedBlock = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UncheckedBlockStruct { pub node: Rc, pub block: Block, @@ -853,7 +853,7 @@ impl UncheckedBlockStruct { pub type ExpressionStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExpressionStatementStruct { pub node: Rc, pub expression: Expression, @@ -867,7 +867,7 @@ impl ExpressionStatementStruct { pub type AssemblyStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AssemblyStatementStruct { pub node: Rc, pub label: Option, @@ -883,7 +883,7 @@ impl AssemblyStatementStruct { pub type AssemblyFlagsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AssemblyFlagsDeclarationStruct { pub node: Rc, pub flags: AssemblyFlags, @@ -897,7 +897,7 @@ impl AssemblyFlagsDeclarationStruct { pub type TupleDeconstructionStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleDeconstructionStatementStruct { pub node: Rc, pub var_keyword: bool, @@ -913,7 +913,7 @@ impl TupleDeconstructionStatementStruct { pub type TupleDeconstructionElement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleDeconstructionElementStruct { pub node: Rc, pub member: Option, @@ -927,7 +927,7 @@ impl TupleDeconstructionElementStruct { pub type TypedTupleMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -943,7 +943,7 @@ impl TypedTupleMemberStruct { pub type UntypedTupleMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, @@ -958,7 +958,7 @@ impl UntypedTupleMemberStruct { pub type VariableDeclarationStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, @@ -975,7 +975,7 @@ impl VariableDeclarationStatementStruct { pub type VariableDeclarationValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VariableDeclarationValueStruct { pub node: Rc, pub expression: Expression, @@ -989,7 +989,7 @@ impl VariableDeclarationValueStruct { pub type IfStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IfStatementStruct { pub node: Rc, pub condition: Expression, @@ -1005,7 +1005,7 @@ impl IfStatementStruct { pub type ElseBranch = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ElseBranchStruct { pub node: Rc, pub body: Statement, @@ -1019,7 +1019,7 @@ impl ElseBranchStruct { pub type ForStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ForStatementStruct { pub node: Rc, pub initialization: ForStatementInitialization, @@ -1036,7 +1036,7 @@ impl ForStatementStruct { pub type WhileStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct WhileStatementStruct { pub node: Rc, pub condition: Expression, @@ -1051,7 +1051,7 @@ impl WhileStatementStruct { pub type DoWhileStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct DoWhileStatementStruct { pub node: Rc, pub body: Statement, @@ -1066,7 +1066,7 @@ impl DoWhileStatementStruct { pub type ContinueStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ContinueStatementStruct { pub node: Rc, } @@ -1079,7 +1079,7 @@ impl ContinueStatementStruct { pub type BreakStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BreakStatementStruct { pub node: Rc, } @@ -1092,7 +1092,7 @@ impl BreakStatementStruct { pub type ReturnStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ReturnStatementStruct { pub node: Rc, pub expression: Option, @@ -1106,7 +1106,7 @@ impl ReturnStatementStruct { pub type EmitStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EmitStatementStruct { pub node: Rc, pub event: IdentifierPath, @@ -1121,7 +1121,7 @@ impl EmitStatementStruct { pub type TryStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TryStatementStruct { pub node: Rc, pub expression: Expression, @@ -1138,7 +1138,7 @@ impl TryStatementStruct { pub type CatchClause = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CatchClauseStruct { pub node: Rc, pub error: Option, @@ -1153,7 +1153,7 @@ impl CatchClauseStruct { pub type CatchClauseError = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CatchClauseErrorStruct { pub node: Rc, pub name: Option>, @@ -1168,7 +1168,7 @@ impl CatchClauseErrorStruct { pub type RevertStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct RevertStatementStruct { pub node: Rc, pub error: Option, @@ -1183,7 +1183,7 @@ impl RevertStatementStruct { pub type ThrowStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ThrowStatementStruct { pub node: Rc, } @@ -1196,7 +1196,7 @@ impl ThrowStatementStruct { pub type AssignmentExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1212,7 +1212,7 @@ impl AssignmentExpressionStruct { pub type ConditionalExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ConditionalExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1228,7 +1228,7 @@ impl ConditionalExpressionStruct { pub type OrExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct OrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1243,7 +1243,7 @@ impl OrExpressionStruct { pub type AndExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1258,7 +1258,7 @@ impl AndExpressionStruct { pub type EqualityExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1274,7 +1274,7 @@ impl EqualityExpressionStruct { pub type InequalityExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1290,7 +1290,7 @@ impl InequalityExpressionStruct { pub type BitwiseOrExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseOrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1305,7 +1305,7 @@ impl BitwiseOrExpressionStruct { pub type BitwiseXorExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseXorExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1320,7 +1320,7 @@ impl BitwiseXorExpressionStruct { pub type BitwiseAndExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseAndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1335,7 +1335,7 @@ impl BitwiseAndExpressionStruct { pub type ShiftExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1351,7 +1351,7 @@ impl ShiftExpressionStruct { pub type AdditiveExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1367,7 +1367,7 @@ impl AdditiveExpressionStruct { pub type MultiplicativeExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1383,7 +1383,7 @@ impl MultiplicativeExpressionStruct { pub type ExponentiationExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1399,7 +1399,7 @@ impl ExponentiationExpressionStruct { pub type PostfixExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1414,7 +1414,7 @@ impl PostfixExpressionStruct { pub type PrefixExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PrefixExpressionStruct { pub node: Rc, pub operator: Rc, @@ -1429,7 +1429,7 @@ impl PrefixExpressionStruct { pub type FunctionCallExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionCallExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1444,7 +1444,7 @@ impl FunctionCallExpressionStruct { pub type CallOptionsExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CallOptionsExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1459,7 +1459,7 @@ impl CallOptionsExpressionStruct { pub type MemberAccessExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1474,7 +1474,7 @@ impl MemberAccessExpressionStruct { pub type IndexAccessExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IndexAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1490,7 +1490,7 @@ impl IndexAccessExpressionStruct { pub type IndexAccessEnd = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IndexAccessEndStruct { pub node: Rc, pub end: Option, @@ -1504,7 +1504,7 @@ impl IndexAccessEndStruct { pub type PositionalArgumentsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PositionalArgumentsDeclarationStruct { pub node: Rc, pub arguments: PositionalArguments, @@ -1518,7 +1518,7 @@ impl PositionalArgumentsDeclarationStruct { pub type NamedArgumentsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedArgumentsDeclarationStruct { pub node: Rc, pub arguments: Option, @@ -1532,7 +1532,7 @@ impl NamedArgumentsDeclarationStruct { pub type NamedArgumentGroup = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedArgumentGroupStruct { pub node: Rc, pub arguments: NamedArguments, @@ -1546,7 +1546,7 @@ impl NamedArgumentGroupStruct { pub type NamedArgument = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedArgumentStruct { pub node: Rc, pub name: Rc, @@ -1561,7 +1561,7 @@ impl NamedArgumentStruct { pub type TypeExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TypeExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1575,7 +1575,7 @@ impl TypeExpressionStruct { pub type NewExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NewExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1589,7 +1589,7 @@ impl NewExpressionStruct { pub type TupleExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleExpressionStruct { pub node: Rc, pub items: TupleValues, @@ -1603,7 +1603,7 @@ impl TupleExpressionStruct { pub type TupleValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleValueStruct { pub node: Rc, pub expression: Option, @@ -1617,7 +1617,7 @@ impl TupleValueStruct { pub type ArrayExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ArrayExpressionStruct { pub node: Rc, pub items: ArrayValues, @@ -1631,7 +1631,7 @@ impl ArrayExpressionStruct { pub type HexNumberExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct HexNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1646,7 +1646,7 @@ impl HexNumberExpressionStruct { pub type DecimalNumberExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct DecimalNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1661,7 +1661,7 @@ impl DecimalNumberExpressionStruct { pub type YulBlock = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulBlockStruct { pub node: Rc, pub statements: YulStatements, @@ -1675,7 +1675,7 @@ impl YulBlockStruct { pub type YulFunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulFunctionDefinitionStruct { pub node: Rc, pub name: Rc, @@ -1692,7 +1692,7 @@ impl YulFunctionDefinitionStruct { pub type YulParametersDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulParametersDeclarationStruct { pub node: Rc, pub parameters: YulParameters, @@ -1706,7 +1706,7 @@ impl YulParametersDeclarationStruct { pub type YulReturnsDeclaration = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulReturnsDeclarationStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1720,7 +1720,7 @@ impl YulReturnsDeclarationStruct { pub type YulVariableDeclarationStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableDeclarationStatementStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1735,7 +1735,7 @@ impl YulVariableDeclarationStatementStruct { pub type YulVariableDeclarationValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableDeclarationValueStruct { pub node: Rc, pub assignment: YulAssignmentOperator, @@ -1750,7 +1750,7 @@ impl YulVariableDeclarationValueStruct { pub type YulVariableAssignmentStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableAssignmentStatementStruct { pub node: Rc, pub variables: YulPaths, @@ -1766,7 +1766,7 @@ impl YulVariableAssignmentStatementStruct { pub type YulColonAndEqual = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulColonAndEqualStruct { pub node: Rc, } @@ -1779,7 +1779,7 @@ impl YulColonAndEqualStruct { pub type YulStackAssignmentStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, @@ -1794,7 +1794,7 @@ impl YulStackAssignmentStatementStruct { pub type YulEqualAndColon = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulEqualAndColonStruct { pub node: Rc, } @@ -1807,7 +1807,7 @@ impl YulEqualAndColonStruct { pub type YulIfStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulIfStatementStruct { pub node: Rc, pub condition: YulExpression, @@ -1822,7 +1822,7 @@ impl YulIfStatementStruct { pub type YulForStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulForStatementStruct { pub node: Rc, pub initialization: YulBlock, @@ -1839,7 +1839,7 @@ impl YulForStatementStruct { pub type YulSwitchStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulSwitchStatementStruct { pub node: Rc, pub expression: YulExpression, @@ -1854,7 +1854,7 @@ impl YulSwitchStatementStruct { pub type YulDefaultCase = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulDefaultCaseStruct { pub node: Rc, pub body: YulBlock, @@ -1868,7 +1868,7 @@ impl YulDefaultCaseStruct { pub type YulValueCase = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulValueCaseStruct { pub node: Rc, pub value: YulLiteral, @@ -1883,7 +1883,7 @@ impl YulValueCaseStruct { pub type YulLeaveStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulLeaveStatementStruct { pub node: Rc, } @@ -1896,7 +1896,7 @@ impl YulLeaveStatementStruct { pub type YulBreakStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulBreakStatementStruct { pub node: Rc, } @@ -1909,7 +1909,7 @@ impl YulBreakStatementStruct { pub type YulContinueStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulContinueStatementStruct { pub node: Rc, } @@ -1922,7 +1922,7 @@ impl YulContinueStatementStruct { pub type YulLabel = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulLabelStruct { pub node: Rc, pub label: Rc, @@ -1936,7 +1936,7 @@ impl YulLabelStruct { pub type YulFunctionCallExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulFunctionCallExpressionStruct { pub node: Rc, pub operand: YulExpression, @@ -1953,7 +1953,7 @@ impl YulFunctionCallExpressionStruct { // Choices: // -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum SourceUnitMember { PragmaDirective(PragmaDirective), ImportDirective(ImportDirective), @@ -1970,33 +1970,33 @@ pub enum SourceUnitMember { ConstantDefinition(ConstantDefinition), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Pragma { VersionPragma(VersionPragma), AbicoderPragma(AbicoderPragma), ExperimentalPragma(ExperimentalPragma), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum AbicoderVersion { AbicoderV1Keyword, AbicoderV2Keyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ExperimentalFeature { StringLiteral(StringLiteral), ABIEncoderV2Keyword, SMTCheckerKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionExpression { VersionRange(VersionRange), VersionTerm(VersionTerm), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionOperator { Caret, Tilde, @@ -2007,27 +2007,27 @@ pub enum VersionOperator { GreaterThanEqual, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), SingleQuotedVersionLiteral(Rc), DoubleQuotedVersionLiteral(Rc), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ImportClause { PathImport(PathImport), NamedImport(NamedImport), ImportDeconstruction(ImportDeconstruction), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingClause { IdentifierPath(IdentifierPath), UsingDeconstruction(UsingDeconstruction), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingOperator { Ampersand, Asterisk, @@ -2046,19 +2046,19 @@ pub enum UsingOperator { Tilde, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingTarget { TypeName(TypeName), Asterisk, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ContractSpecifier { InheritanceSpecifier(InheritanceSpecifier), StorageLayoutSpecifier(StorageLayoutSpecifier), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ContractMember { UsingDirective(UsingDirective), FunctionDefinition(FunctionDefinition), @@ -2075,7 +2075,7 @@ pub enum ContractMember { StateVariableDefinition(StateVariableDefinition), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StateVariableAttribute { OverrideSpecifier(OverrideSpecifier), ConstantKeyword, @@ -2086,14 +2086,14 @@ pub enum StateVariableAttribute { TransientKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionName { Identifier(Rc), FallbackKeyword, ReceiveKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2108,13 +2108,13 @@ pub enum FunctionAttribute { VirtualKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionBody { Block(Block), Semicolon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ConstructorAttribute { ModifierInvocation(ModifierInvocation), InternalKeyword, @@ -2124,7 +2124,7 @@ pub enum ConstructorAttribute { VirtualKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UnnamedFunctionAttribute { ModifierInvocation(ModifierInvocation), ConstantKeyword, @@ -2137,7 +2137,7 @@ pub enum UnnamedFunctionAttribute { ViewKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FallbackFunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2148,7 +2148,7 @@ pub enum FallbackFunctionAttribute { VirtualKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ReceiveFunctionAttribute { ModifierInvocation(ModifierInvocation), OverrideSpecifier(OverrideSpecifier), @@ -2157,13 +2157,13 @@ pub enum ReceiveFunctionAttribute { VirtualKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ModifierAttribute { OverrideSpecifier(OverrideSpecifier), VirtualKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum TypeName { ArrayTypeName(ArrayTypeName), FunctionType(FunctionType), @@ -2172,7 +2172,7 @@ pub enum TypeName { IdentifierPath(IdentifierPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionTypeAttribute { InternalKeyword, ExternalKeyword, @@ -2184,13 +2184,13 @@ pub enum FunctionTypeAttribute { PayableKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum MappingKeyType { ElementaryType(ElementaryType), IdentifierPath(IdentifierPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ElementaryType { AddressType(AddressType), BytesKeyword(Rc), @@ -2203,7 +2203,7 @@ pub enum ElementaryType { StringKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Statement { IfStatement(IfStatement), ForStatement(ForStatement), @@ -2224,26 +2224,26 @@ pub enum Statement { ExpressionStatement(ExpressionStatement), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum TupleMember { TypedTupleMember(TypedTupleMember), UntypedTupleMember(UntypedTupleMember), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VariableDeclarationType { TypeName(TypeName), VarKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StorageLocation { MemoryKeyword, StorageKeyword, CallDataKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ForStatementInitialization { TupleDeconstructionStatement(TupleDeconstructionStatement), VariableDeclarationStatement(VariableDeclarationStatement), @@ -2251,13 +2251,13 @@ pub enum ForStatementInitialization { Semicolon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ForStatementCondition { ExpressionStatement(ExpressionStatement), Semicolon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Expression { AssignmentExpression(AssignmentExpression), ConditionalExpression(ConditionalExpression), @@ -2294,13 +2294,13 @@ pub enum Expression { FalseKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ArgumentsDeclaration { PositionalArgumentsDeclaration(PositionalArgumentsDeclaration), NamedArgumentsDeclaration(NamedArgumentsDeclaration), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum NumberUnit { WeiKeyword, GweiKeyword, @@ -2315,7 +2315,7 @@ pub enum NumberUnit { YearsKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StringExpression { StringLiteral(StringLiteral), StringLiterals(StringLiterals), @@ -2324,25 +2324,25 @@ pub enum StringExpression { UnicodeStringLiterals(UnicodeStringLiterals), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StringLiteral { SingleQuotedStringLiteral(Rc), DoubleQuotedStringLiteral(Rc), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum HexStringLiteral { SingleQuotedHexStringLiteral(Rc), DoubleQuotedHexStringLiteral(Rc), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UnicodeStringLiteral { SingleQuotedUnicodeStringLiteral(Rc), DoubleQuotedUnicodeStringLiteral(Rc), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulStatement { YulBlock(YulBlock), YulFunctionDefinition(YulFunctionDefinition), @@ -2359,32 +2359,32 @@ pub enum YulStatement { YulExpression(YulExpression), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulAssignmentOperator { YulColonAndEqual(YulColonAndEqual), ColonEqual, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulStackAssignmentOperator { YulEqualAndColon(YulEqualAndColon), EqualColon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulSwitchCase { YulDefaultCase(YulDefaultCase), YulValueCase(YulValueCase), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulExpression { YulFunctionCallExpression(YulFunctionCallExpression), YulLiteral(YulLiteral), YulPath(YulPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulLiteral { HexStringLiteral(HexStringLiteral), StringLiteral(StringLiteral), 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 42bcdc6bd3..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 @@ -13,7 +13,7 @@ use crate::cst::SyntaxNode; pub type SourceUnit = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct SourceUnitStruct { pub node: Rc, pub members: SourceUnitMembers, @@ -27,7 +27,7 @@ impl SourceUnitStruct { pub type PragmaDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PragmaDirectiveStruct { pub node: Rc, pub pragma: Pragma, @@ -41,7 +41,7 @@ impl PragmaDirectiveStruct { pub type AbicoderPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AbicoderPragmaStruct { pub node: Rc, pub version: AbicoderVersion, @@ -55,7 +55,7 @@ impl AbicoderPragmaStruct { pub type ExperimentalPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExperimentalPragmaStruct { pub node: Rc, pub feature: ExperimentalFeature, @@ -69,7 +69,7 @@ impl ExperimentalPragmaStruct { pub type VersionPragma = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionPragmaStruct { pub node: Rc, pub sets: VersionExpressionSets, @@ -83,7 +83,7 @@ impl VersionPragmaStruct { pub type VersionRange = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionRangeStruct { pub node: Rc, pub start: VersionLiteral, @@ -98,7 +98,7 @@ impl VersionRangeStruct { pub type VersionTerm = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VersionTermStruct { pub node: Rc, pub operator: Option, @@ -113,7 +113,7 @@ impl VersionTermStruct { pub type ImportDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDirectiveStruct { pub node: Rc, pub clause: ImportClause, @@ -127,7 +127,7 @@ impl ImportDirectiveStruct { pub type PathImport = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PathImportStruct { pub node: Rc, pub alias: Option>, @@ -142,7 +142,7 @@ impl PathImportStruct { pub type NamedImport = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedImportStruct { pub node: Rc, pub alias: Rc, @@ -157,7 +157,7 @@ impl NamedImportStruct { pub type ImportDeconstruction = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDeconstructionStruct { pub node: Rc, pub symbols: ImportDeconstructionSymbols, @@ -172,7 +172,7 @@ impl ImportDeconstructionStruct { pub type ImportDeconstructionSymbol = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ImportDeconstructionSymbolStruct { pub node: Rc, pub name: Rc, @@ -187,7 +187,7 @@ impl ImportDeconstructionSymbolStruct { pub type UsingDirective = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDirectiveStruct { pub node: Rc, pub clause: UsingClause, @@ -203,7 +203,7 @@ impl UsingDirectiveStruct { pub type UsingDeconstruction = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDeconstructionStruct { pub node: Rc, pub symbols: UsingDeconstructionSymbols, @@ -217,7 +217,7 @@ impl UsingDeconstructionStruct { pub type UsingDeconstructionSymbol = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UsingDeconstructionSymbolStruct { pub node: Rc, pub name: IdentifierPath, @@ -232,7 +232,7 @@ impl UsingDeconstructionSymbolStruct { pub type ContractDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ContractDefinitionStruct { pub node: Rc, pub abstract_keyword: bool, @@ -250,7 +250,7 @@ impl ContractDefinitionStruct { pub type InheritanceType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InheritanceTypeStruct { pub node: Rc, pub type_name: IdentifierPath, @@ -265,7 +265,7 @@ impl InheritanceTypeStruct { pub type InterfaceDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InterfaceDefinitionStruct { pub node: Rc, pub name: Rc, @@ -281,7 +281,7 @@ impl InterfaceDefinitionStruct { pub type LibraryDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct LibraryDefinitionStruct { pub node: Rc, pub name: Rc, @@ -296,7 +296,7 @@ impl LibraryDefinitionStruct { pub type StructDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StructDefinitionStruct { pub node: Rc, pub name: Rc, @@ -311,7 +311,7 @@ impl StructDefinitionStruct { pub type StructMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StructMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -326,7 +326,7 @@ impl StructMemberStruct { pub type EnumDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EnumDefinitionStruct { pub node: Rc, pub name: Rc, @@ -341,7 +341,7 @@ impl EnumDefinitionStruct { pub type ConstantDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ConstantDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -357,7 +357,7 @@ impl ConstantDefinitionStruct { pub type StateVariableDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct StateVariableDefinitionStruct { pub node: Rc, pub type_name: TypeName, @@ -376,7 +376,7 @@ impl StateVariableDefinitionStruct { pub type FunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionDefinitionStruct { pub node: Rc, pub parameters: Parameters, @@ -399,7 +399,7 @@ impl FunctionDefinitionStruct { pub type Parameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -415,7 +415,7 @@ impl ParameterStruct { pub type OverrideSpecifier = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct OverrideSpecifierStruct { pub node: Rc, pub overridden: Option, @@ -429,7 +429,7 @@ impl OverrideSpecifierStruct { pub type ModifierInvocation = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ModifierInvocationStruct { pub node: Rc, pub name: IdentifierPath, @@ -444,7 +444,7 @@ impl ModifierInvocationStruct { pub type EventDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EventDefinitionStruct { pub node: Rc, pub name: Rc, @@ -460,7 +460,7 @@ impl EventDefinitionStruct { pub type EventParameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EventParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -476,7 +476,7 @@ impl EventParameterStruct { pub type UserDefinedValueTypeDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UserDefinedValueTypeDefinitionStruct { pub node: Rc, pub name: Rc, @@ -491,7 +491,7 @@ impl UserDefinedValueTypeDefinitionStruct { pub type ErrorDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ErrorDefinitionStruct { pub node: Rc, pub name: Rc, @@ -506,7 +506,7 @@ impl ErrorDefinitionStruct { pub type ErrorParameter = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ErrorParameterStruct { pub node: Rc, pub type_name: TypeName, @@ -521,7 +521,7 @@ impl ErrorParameterStruct { pub type ArrayTypeName = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ArrayTypeNameStruct { pub node: Rc, pub operand: TypeName, @@ -536,7 +536,7 @@ impl ArrayTypeNameStruct { pub type FunctionType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionTypeStruct { pub node: Rc, pub parameters: Parameters, @@ -553,7 +553,7 @@ impl FunctionTypeStruct { pub type MappingType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingTypeStruct { pub node: Rc, pub key_type: MappingKey, @@ -568,7 +568,7 @@ impl MappingTypeStruct { pub type MappingKey = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingKeyStruct { pub node: Rc, pub key_type: MappingKeyType, @@ -583,7 +583,7 @@ impl MappingKeyStruct { pub type MappingValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MappingValueStruct { pub node: Rc, pub type_name: TypeName, @@ -598,7 +598,7 @@ impl MappingValueStruct { pub type AddressType = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AddressTypeStruct { pub node: Rc, pub payable_keyword: bool, @@ -612,7 +612,7 @@ impl AddressTypeStruct { pub type Block = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BlockStruct { pub node: Rc, pub statements: Statements, @@ -626,7 +626,7 @@ impl BlockStruct { pub type UncheckedBlock = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UncheckedBlockStruct { pub node: Rc, pub block: Block, @@ -640,7 +640,7 @@ impl UncheckedBlockStruct { pub type ExpressionStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExpressionStatementStruct { pub node: Rc, pub expression: Expression, @@ -654,7 +654,7 @@ impl ExpressionStatementStruct { pub type AssemblyStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AssemblyStatementStruct { pub node: Rc, pub body: YulBlock, @@ -670,7 +670,7 @@ impl AssemblyStatementStruct { pub type TupleDeconstructionStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleDeconstructionStatementStruct { pub node: Rc, pub var_keyword: bool, @@ -686,7 +686,7 @@ impl TupleDeconstructionStatementStruct { pub type TupleDeconstructionElement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleDeconstructionElementStruct { pub node: Rc, pub member: Option, @@ -700,7 +700,7 @@ impl TupleDeconstructionElementStruct { pub type TypedTupleMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TypedTupleMemberStruct { pub node: Rc, pub type_name: TypeName, @@ -716,7 +716,7 @@ impl TypedTupleMemberStruct { pub type UntypedTupleMember = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct UntypedTupleMemberStruct { pub node: Rc, pub storage_location: Option, @@ -731,7 +731,7 @@ impl UntypedTupleMemberStruct { pub type VariableDeclarationStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct VariableDeclarationStatementStruct { pub node: Rc, pub variable_type: VariableDeclarationType, @@ -748,7 +748,7 @@ impl VariableDeclarationStatementStruct { pub type IfStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IfStatementStruct { pub node: Rc, pub condition: Expression, @@ -764,7 +764,7 @@ impl IfStatementStruct { pub type ForStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ForStatementStruct { pub node: Rc, pub initialization: ForStatementInitialization, @@ -781,7 +781,7 @@ impl ForStatementStruct { pub type WhileStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct WhileStatementStruct { pub node: Rc, pub condition: Expression, @@ -796,7 +796,7 @@ impl WhileStatementStruct { pub type DoWhileStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct DoWhileStatementStruct { pub node: Rc, pub body: Statement, @@ -811,7 +811,7 @@ impl DoWhileStatementStruct { pub type ContinueStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ContinueStatementStruct { pub node: Rc, } @@ -824,7 +824,7 @@ impl ContinueStatementStruct { pub type BreakStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BreakStatementStruct { pub node: Rc, } @@ -837,7 +837,7 @@ impl BreakStatementStruct { pub type ReturnStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ReturnStatementStruct { pub node: Rc, pub expression: Option, @@ -851,7 +851,7 @@ impl ReturnStatementStruct { pub type EmitStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EmitStatementStruct { pub node: Rc, pub event: IdentifierPath, @@ -866,7 +866,7 @@ impl EmitStatementStruct { pub type TryStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TryStatementStruct { pub node: Rc, pub expression: Expression, @@ -883,7 +883,7 @@ impl TryStatementStruct { pub type CatchClause = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CatchClauseStruct { pub node: Rc, pub error: Option, @@ -898,7 +898,7 @@ impl CatchClauseStruct { pub type CatchClauseError = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CatchClauseErrorStruct { pub node: Rc, pub name: Option>, @@ -913,7 +913,7 @@ impl CatchClauseErrorStruct { pub type RevertStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct RevertStatementStruct { pub node: Rc, pub error: Option, @@ -928,7 +928,7 @@ impl RevertStatementStruct { pub type ThrowStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ThrowStatementStruct { pub node: Rc, } @@ -941,7 +941,7 @@ impl ThrowStatementStruct { pub type AssignmentExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AssignmentExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -957,7 +957,7 @@ impl AssignmentExpressionStruct { pub type ConditionalExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ConditionalExpressionStruct { pub node: Rc, pub operand: Expression, @@ -973,7 +973,7 @@ impl ConditionalExpressionStruct { pub type OrExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct OrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -988,7 +988,7 @@ impl OrExpressionStruct { pub type AndExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1003,7 +1003,7 @@ impl AndExpressionStruct { pub type EqualityExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct EqualityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1019,7 +1019,7 @@ impl EqualityExpressionStruct { pub type InequalityExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct InequalityExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1035,7 +1035,7 @@ impl InequalityExpressionStruct { pub type BitwiseOrExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseOrExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1050,7 +1050,7 @@ impl BitwiseOrExpressionStruct { pub type BitwiseXorExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseXorExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1065,7 +1065,7 @@ impl BitwiseXorExpressionStruct { pub type BitwiseAndExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct BitwiseAndExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1080,7 +1080,7 @@ impl BitwiseAndExpressionStruct { pub type ShiftExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ShiftExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1096,7 +1096,7 @@ impl ShiftExpressionStruct { pub type AdditiveExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct AdditiveExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1112,7 +1112,7 @@ impl AdditiveExpressionStruct { pub type MultiplicativeExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MultiplicativeExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1128,7 +1128,7 @@ impl MultiplicativeExpressionStruct { pub type ExponentiationExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ExponentiationExpressionStruct { pub node: Rc, pub left_operand: Expression, @@ -1144,7 +1144,7 @@ impl ExponentiationExpressionStruct { pub type PostfixExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PostfixExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1159,7 +1159,7 @@ impl PostfixExpressionStruct { pub type PrefixExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct PrefixExpressionStruct { pub node: Rc, pub operator: Rc, @@ -1174,7 +1174,7 @@ impl PrefixExpressionStruct { pub type FunctionCallExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct FunctionCallExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1189,7 +1189,7 @@ impl FunctionCallExpressionStruct { pub type CallOptionsExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct CallOptionsExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1204,7 +1204,7 @@ impl CallOptionsExpressionStruct { pub type MemberAccessExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MemberAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1219,7 +1219,7 @@ impl MemberAccessExpressionStruct { pub type IndexAccessExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IndexAccessExpressionStruct { pub node: Rc, pub operand: Expression, @@ -1235,7 +1235,7 @@ impl IndexAccessExpressionStruct { pub type NamedArgument = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NamedArgumentStruct { pub node: Rc, pub name: Rc, @@ -1250,7 +1250,7 @@ impl NamedArgumentStruct { pub type TypeExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TypeExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1264,7 +1264,7 @@ impl TypeExpressionStruct { pub type NewExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct NewExpressionStruct { pub node: Rc, pub type_name: TypeName, @@ -1278,7 +1278,7 @@ impl NewExpressionStruct { pub type TupleExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleExpressionStruct { pub node: Rc, pub items: TupleValues, @@ -1292,7 +1292,7 @@ impl TupleExpressionStruct { pub type TupleValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct TupleValueStruct { pub node: Rc, pub expression: Option, @@ -1306,7 +1306,7 @@ impl TupleValueStruct { pub type ArrayExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ArrayExpressionStruct { pub node: Rc, pub items: ArrayValues, @@ -1320,7 +1320,7 @@ impl ArrayExpressionStruct { pub type HexNumberExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct HexNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1335,7 +1335,7 @@ impl HexNumberExpressionStruct { pub type DecimalNumberExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct DecimalNumberExpressionStruct { pub node: Rc, pub literal: Rc, @@ -1350,7 +1350,7 @@ impl DecimalNumberExpressionStruct { pub type YulBlock = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulBlockStruct { pub node: Rc, pub statements: YulStatements, @@ -1364,7 +1364,7 @@ impl YulBlockStruct { pub type YulFunctionDefinition = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulFunctionDefinitionStruct { pub node: Rc, pub name: Rc, @@ -1381,7 +1381,7 @@ impl YulFunctionDefinitionStruct { pub type YulVariableDeclarationStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableDeclarationStatementStruct { pub node: Rc, pub variables: YulVariableNames, @@ -1396,7 +1396,7 @@ impl YulVariableDeclarationStatementStruct { pub type YulVariableDeclarationValue = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableDeclarationValueStruct { pub node: Rc, pub assignment: YulAssignmentOperator, @@ -1411,7 +1411,7 @@ impl YulVariableDeclarationValueStruct { pub type YulVariableAssignmentStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulVariableAssignmentStatementStruct { pub node: Rc, pub variables: YulPaths, @@ -1427,7 +1427,7 @@ impl YulVariableAssignmentStatementStruct { pub type YulColonAndEqual = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulColonAndEqualStruct { pub node: Rc, } @@ -1440,7 +1440,7 @@ impl YulColonAndEqualStruct { pub type YulStackAssignmentStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulStackAssignmentStatementStruct { pub node: Rc, pub assignment: YulStackAssignmentOperator, @@ -1455,7 +1455,7 @@ impl YulStackAssignmentStatementStruct { pub type YulEqualAndColon = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulEqualAndColonStruct { pub node: Rc, } @@ -1468,7 +1468,7 @@ impl YulEqualAndColonStruct { pub type YulIfStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulIfStatementStruct { pub node: Rc, pub condition: YulExpression, @@ -1483,7 +1483,7 @@ impl YulIfStatementStruct { pub type YulForStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulForStatementStruct { pub node: Rc, pub initialization: YulBlock, @@ -1500,7 +1500,7 @@ impl YulForStatementStruct { pub type YulSwitchStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulSwitchStatementStruct { pub node: Rc, pub expression: YulExpression, @@ -1515,7 +1515,7 @@ impl YulSwitchStatementStruct { pub type YulDefaultCase = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulDefaultCaseStruct { pub node: Rc, pub body: YulBlock, @@ -1529,7 +1529,7 @@ impl YulDefaultCaseStruct { pub type YulValueCase = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulValueCaseStruct { pub node: Rc, pub value: YulLiteral, @@ -1544,7 +1544,7 @@ impl YulValueCaseStruct { pub type YulLeaveStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulLeaveStatementStruct { pub node: Rc, } @@ -1557,7 +1557,7 @@ impl YulLeaveStatementStruct { pub type YulBreakStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulBreakStatementStruct { pub node: Rc, } @@ -1570,7 +1570,7 @@ impl YulBreakStatementStruct { pub type YulContinueStatement = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulContinueStatementStruct { pub node: Rc, } @@ -1583,7 +1583,7 @@ impl YulContinueStatementStruct { pub type YulLabel = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulLabelStruct { pub node: Rc, pub label: Rc, @@ -1597,7 +1597,7 @@ impl YulLabelStruct { pub type YulFunctionCallExpression = Rc; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct YulFunctionCallExpressionStruct { pub node: Rc, pub operand: YulExpression, @@ -1614,7 +1614,7 @@ impl YulFunctionCallExpressionStruct { // Choices: // -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum SourceUnitMember { PragmaDirective(PragmaDirective), ImportDirective(ImportDirective), @@ -1631,33 +1631,33 @@ pub enum SourceUnitMember { ConstantDefinition(ConstantDefinition), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Pragma { VersionPragma(VersionPragma), AbicoderPragma(AbicoderPragma), ExperimentalPragma(ExperimentalPragma), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum AbicoderVersion { AbicoderV1Keyword, AbicoderV2Keyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ExperimentalFeature { StringLiteral(Rc), ABIEncoderV2Keyword, SMTCheckerKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionExpression { VersionRange(VersionRange), VersionTerm(VersionTerm), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionOperator { Caret, Tilde, @@ -1668,27 +1668,27 @@ pub enum VersionOperator { GreaterThanEqual, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VersionLiteral { SimpleVersionLiteral(SimpleVersionLiteral), SingleQuotedVersionLiteral(Rc), DoubleQuotedVersionLiteral(Rc), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ImportClause { PathImport(PathImport), NamedImport(NamedImport), ImportDeconstruction(ImportDeconstruction), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingClause { IdentifierPath(IdentifierPath), UsingDeconstruction(UsingDeconstruction), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingOperator { Ampersand, Asterisk, @@ -1707,13 +1707,13 @@ pub enum UsingOperator { Tilde, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum UsingTarget { TypeName(TypeName), Asterisk, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ContractMember { UsingDirective(UsingDirective), FunctionDefinition(FunctionDefinition), @@ -1725,7 +1725,7 @@ pub enum ContractMember { StateVariableDefinition(StateVariableDefinition), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum TypeName { ArrayTypeName(ArrayTypeName), FunctionType(FunctionType), @@ -1734,13 +1734,13 @@ pub enum TypeName { IdentifierPath(IdentifierPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum MappingKeyType { ElementaryType(ElementaryType), IdentifierPath(IdentifierPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ElementaryType { AddressType(AddressType), BytesKeyword(Rc), @@ -1753,7 +1753,7 @@ pub enum ElementaryType { StringKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Statement { IfStatement(IfStatement), ForStatement(ForStatement), @@ -1774,26 +1774,26 @@ pub enum Statement { ExpressionStatement(ExpressionStatement), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum TupleMember { TypedTupleMember(TypedTupleMember), UntypedTupleMember(UntypedTupleMember), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum VariableDeclarationType { TypeName(TypeName), VarKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StorageLocation { MemoryKeyword, StorageKeyword, CallDataKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ForStatementInitialization { TupleDeconstructionStatement(TupleDeconstructionStatement), VariableDeclarationStatement(VariableDeclarationStatement), @@ -1801,13 +1801,13 @@ pub enum ForStatementInitialization { Semicolon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ForStatementCondition { ExpressionStatement(ExpressionStatement), Semicolon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Expression { AssignmentExpression(AssignmentExpression), ConditionalExpression(ConditionalExpression), @@ -1844,13 +1844,13 @@ pub enum Expression { FalseKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum ArgumentsDeclaration { PositionalArguments(PositionalArguments), NamedArguments(NamedArguments), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum NumberUnit { WeiKeyword, GweiKeyword, @@ -1865,14 +1865,14 @@ pub enum NumberUnit { YearsKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StringExpression { Strings(Strings), HexStrings(HexStrings), UnicodeStrings(UnicodeStrings), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulStatement { YulBlock(YulBlock), YulFunctionDefinition(YulFunctionDefinition), @@ -1889,32 +1889,32 @@ pub enum YulStatement { YulExpression(YulExpression), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulAssignmentOperator { YulColonAndEqual(YulColonAndEqual), ColonEqual, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulStackAssignmentOperator { YulEqualAndColon(YulEqualAndColon), EqualColon, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulSwitchCase { YulDefaultCase(YulDefaultCase), YulValueCase(YulValueCase), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulExpression { YulFunctionCallExpression(YulFunctionCallExpression), YulLiteral(YulLiteral), YulPath(YulPath), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum YulLiteral { YulDecimalLiteral(Rc), YulHexLiteral(Rc), @@ -1924,7 +1924,7 @@ pub enum YulLiteral { YulFalseKeyword, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionKind { Regular, Constructor, @@ -1934,7 +1934,7 @@ pub enum FunctionKind { Modifier, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionVisibility { Public, Private, @@ -1942,7 +1942,7 @@ pub enum FunctionVisibility { External, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum FunctionMutability { Pure, View, @@ -1950,14 +1950,14 @@ pub enum FunctionMutability { Payable, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StateVariableVisibility { Public, Private, Internal, } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum StateVariableMutability { Mutable, Constant, 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 index a2d82a9aed..ac27eb6c8d 100644 --- a/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs +++ b/crates/solidity/outputs/cargo/tests/src/ast_api/visit_definition.rs @@ -67,7 +67,9 @@ fn visit_contract<'a>( // Special functions (receiver, fallback, unnamed, constructors) let function_nodes = contract.members.iter().filter_map(|member| match member { - ast::ContractMember::FunctionDefinition(f) if f.kind != ast::FunctionKind::Regular => { + ast::ContractMember::FunctionDefinition(f) + if !matches!(f.kind, ast::FunctionKind::Regular) => + { Some(Rc::clone(&f.node)) } @@ -82,7 +84,7 @@ fn visit_contract<'a>( let public_state_vars_ids = contract.members.iter().filter_map(|member| match member { ContractMember::StateVariableDefinition(sv_def) - if sv_def.visibility == ast::StateVariableVisibility::Public => + if matches!(sv_def.visibility, ast::StateVariableVisibility::Public) => { Some(sv_def.name.id()) } @@ -92,8 +94,8 @@ fn visit_contract<'a>( let public_functions_ids = contract.members.iter().filter_map(|member| match member { ast::ContractMember::FunctionDefinition(f) - if f.kind == ast::FunctionKind::Regular - && f.visibility == ast::FunctionVisibility::Public => + if matches!(f.kind, ast::FunctionKind::Regular) + && matches!(f.visibility, ast::FunctionVisibility::Public) => { f.name.as_ref().map(|node| node.id()) }