@@ -5,6 +5,8 @@ use core::fmt;
55use std:: fmt:: { Display , Formatter } ;
66use std:: { any:: Any , cmp:: Reverse } ;
77
8+ use crate :: node_kind:: NodeKind ;
9+
810#[ derive( Clone , PartialEq , Eq , Debug , Default , serde:: Serialize , serde:: Deserialize ) ]
911pub struct Location {
1012 pub offset_start : u32 ,
@@ -37,8 +39,8 @@ pub trait Node: Any + std::fmt::Debug {
3739 . unwrap_or_default ( )
3840 . to_string ( )
3941 }
40- fn children ( & self ) -> Vec < Box < dyn Node > > ;
41- fn sorted_children ( & self ) -> Vec < Box < dyn Node > > {
42+ fn children ( & self ) -> Vec < NodeKind > ;
43+ fn sorted_children ( & self ) -> Vec < NodeKind > {
4244 let mut children = self . children ( ) ;
4345 children. sort_by_key ( |c| Reverse ( c. id ( ) ) ) ;
4446 children
@@ -61,31 +63,6 @@ pub enum Mutability {
6163 Constant ,
6264}
6365
64- #[ macro_export]
65- macro_rules! location {
66- ( $item: expr) => { {
67- use syn:: spanned:: Spanned ;
68- #[ allow( clippy:: cast_possible_truncation) ]
69- $crate:: node:: Location {
70- offset_start: $item. span( ) . byte_range( ) . start as u32 ,
71- offset_end: $item. span( ) . byte_range( ) . end as u32 ,
72- source: $item. span( ) . source_text( ) . unwrap_or_default( ) ,
73- start_line: $item. span( ) . start( ) . line as u32 ,
74- start_column: $item. span( ) . start( ) . column as u32 ,
75- end_line: $item. span( ) . end( ) . line as u32 ,
76- end_column: $item. span( ) . end( ) . column as u32 ,
77- }
78- } } ;
79- }
80-
81- #[ macro_export]
82- macro_rules! source_code {
83- ( $item: expr) => { {
84- use syn:: spanned:: Spanned ;
85- $item. span( ) . source_text( ) . unwrap_or_default( )
86- } } ;
87- }
88-
8966#[ macro_export]
9067macro_rules! ast_enum {
9168 (
@@ -125,39 +102,39 @@ macro_rules! ast_enum {
125102 }
126103 }
127104
128- // #[must_use]
129- // pub fn children(&self) -> Vec<NodeKind> {
130- // match self {
131- // $(
132- // $name::$arm(_a) => {
133- // _a.children()
134- // }
135- // )*
136- // }
137- // }
105+ #[ must_use]
106+ pub fn children( & self ) -> Vec <$crate :: node_kind :: NodeKind > {
107+ match self {
108+ $(
109+ $name:: $arm( _a) => {
110+ _a. children( )
111+ }
112+ ) *
113+ }
114+ }
138115 }
139116
140- // impl From<&$name> for $crate::ast::node_type ::NodeKind {
141- // fn from(n: &$name) -> Self {
142- // match n {
143- // $(
144- // $name::$arm(a) => {
145- // $crate::ast::node_type ::NodeKind::$name($name::$arm(a.clone()))
146- // }
147- // )*
148- // }
149- // }
150- // }
117+ impl From <& $name> for $crate:: node_kind :: NodeKind {
118+ fn from( n: & $name) -> Self {
119+ match n {
120+ $(
121+ $name:: $arm( a) => {
122+ $crate:: node_kind :: NodeKind :: $name( $name:: $arm( a. clone( ) ) )
123+ }
124+ ) *
125+ }
126+ }
127+ }
151128
152- // impl From<$name> for $crate::ast::node_type ::NodeKind {
153- // fn from(n: $name) -> Self {
154- // match n {
155- // $(
156- // $name::$arm(inner) => $crate::ast::node_type ::NodeKind::$name($name::$arm(inner.clone())),
157- // )*
158- // }
159- // }
160- // }
129+ impl From <$name> for $crate:: node_kind :: NodeKind {
130+ fn from( n: $name) -> Self {
131+ match n {
132+ $(
133+ $name:: $arm( inner) => $crate:: node_kind :: NodeKind :: $name( $name:: $arm( inner. clone( ) ) ) ,
134+ ) *
135+ }
136+ }
137+ }
161138
162139 } ;
163140
0 commit comments