diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 16 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo/visit.rs | 30 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 328 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 4850 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 93 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 38 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 35 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 17 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte_string.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/string.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 148 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 6 |
17 files changed, 2221 insertions, 3412 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 4b3548ea9..13f50d2ef 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -1,19 +1,23 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | 2 | ||
3 | use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; | 3 | use rowan::TransparentNewType; |
4 | |||
5 | use crate::{SyntaxNode, TextRange, TextUnit}; | ||
4 | 6 | ||
5 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
6 | 8 | ||
7 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { | 9 | pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<&SyntaxNode> { |
8 | match node.0.leaf_at_offset(offset) { | 10 | match node.0.leaf_at_offset(offset) { |
9 | LeafAtOffset::None => LeafAtOffset::None, | 11 | LeafAtOffset::None => LeafAtOffset::None, |
10 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode(n)), | 12 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode::from_repr(n)), |
11 | LeafAtOffset::Between(l, r) => LeafAtOffset::Between(SyntaxNode(l), SyntaxNode(r)), | 13 | LeafAtOffset::Between(l, r) => { |
14 | LeafAtOffset::Between(SyntaxNode::from_repr(l), SyntaxNode::from_repr(r)) | ||
15 | } | ||
12 | } | 16 | } |
13 | } | 17 | } |
14 | 18 | ||
15 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { | 19 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { |
16 | SyntaxNode(root.0.covering_node(range)) | 20 | SyntaxNode::from_repr(root.0.covering_node(range)) |
17 | } | 21 | } |
18 | 22 | ||
19 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { | 23 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { |
diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index c021f464c..38f21594c 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{AstNode, SyntaxNodeRef}; | 1 | use crate::{AstNode, SyntaxNode}; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | 4 | ||
@@ -15,11 +15,11 @@ pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> | |||
15 | 15 | ||
16 | pub trait Visitor<'a>: Sized { | 16 | pub trait Visitor<'a>: Sized { |
17 | type Output; | 17 | type Output; |
18 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output>; | 18 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output>; |
19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> | 19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> |
20 | where | 20 | where |
21 | N: AstNode<'a>, | 21 | N: AstNode + 'a, |
22 | F: FnOnce(N) -> Self::Output, | 22 | F: FnOnce(&'a N) -> Self::Output, |
23 | { | 23 | { |
24 | Vis { | 24 | Vis { |
25 | inner: self, | 25 | inner: self, |
@@ -32,11 +32,11 @@ pub trait Visitor<'a>: Sized { | |||
32 | pub trait VisitorCtx<'a>: Sized { | 32 | pub trait VisitorCtx<'a>: Sized { |
33 | type Output; | 33 | type Output; |
34 | type Ctx; | 34 | type Ctx; |
35 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx>; | 35 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx>; |
36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> | 36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> |
37 | where | 37 | where |
38 | N: AstNode<'a>, | 38 | N: AstNode + 'a, |
39 | F: FnOnce(N, Self::Ctx) -> Self::Output, | 39 | F: FnOnce(&'a N, Self::Ctx) -> Self::Output, |
40 | { | 40 | { |
41 | VisCtx { | 41 | VisCtx { |
42 | inner: self, | 42 | inner: self, |
@@ -54,7 +54,7 @@ struct EmptyVisitor<T> { | |||
54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { | 54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { |
55 | type Output = T; | 55 | type Output = T; |
56 | 56 | ||
57 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Option<T> { | 57 | fn accept(self, _node: &'a SyntaxNode) -> Option<T> { |
58 | None | 58 | None |
59 | } | 59 | } |
60 | } | 60 | } |
@@ -69,7 +69,7 @@ impl<'a, T, C> VisitorCtx<'a> for EmptyVisitorCtx<T, C> { | |||
69 | type Output = T; | 69 | type Output = T; |
70 | type Ctx = C; | 70 | type Ctx = C; |
71 | 71 | ||
72 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Result<T, C> { | 72 | fn accept(self, _node: &'a SyntaxNode) -> Result<T, C> { |
73 | Err(self.ctx) | 73 | Err(self.ctx) |
74 | } | 74 | } |
75 | } | 75 | } |
@@ -84,12 +84,12 @@ pub struct Vis<V, N, F> { | |||
84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> | 84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> |
85 | where | 85 | where |
86 | V: Visitor<'a>, | 86 | V: Visitor<'a>, |
87 | N: AstNode<'a>, | 87 | N: AstNode + 'a, |
88 | F: FnOnce(N) -> <V as Visitor<'a>>::Output, | 88 | F: FnOnce(&'a N) -> <V as Visitor<'a>>::Output, |
89 | { | 89 | { |
90 | type Output = <V as Visitor<'a>>::Output; | 90 | type Output = <V as Visitor<'a>>::Output; |
91 | 91 | ||
92 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output> { | 92 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output> { |
93 | let Vis { inner, f, .. } = self; | 93 | let Vis { inner, f, .. } = self; |
94 | inner.accept(node).or_else(|| N::cast(node).map(f)) | 94 | inner.accept(node).or_else(|| N::cast(node).map(f)) |
95 | } | 95 | } |
@@ -105,13 +105,13 @@ pub struct VisCtx<V, N, F> { | |||
105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> | 105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> |
106 | where | 106 | where |
107 | V: VisitorCtx<'a>, | 107 | V: VisitorCtx<'a>, |
108 | N: AstNode<'a>, | 108 | N: AstNode + 'a, |
109 | F: FnOnce(N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, | 109 | F: FnOnce(&'a N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, |
110 | { | 110 | { |
111 | type Output = <V as VisitorCtx<'a>>::Output; | 111 | type Output = <V as VisitorCtx<'a>>::Output; |
112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; | 112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; |
113 | 113 | ||
114 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx> { | 114 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx> { |
115 | let VisCtx { inner, f, .. } = self; | 115 | let VisCtx { inner, f, .. } = self; |
116 | inner.accept(node).or_else(|ctx| match N::cast(node) { | 116 | inner.accept(node).or_else(|ctx| match N::cast(node) { |
117 | None => Err(ctx), | 117 | None => Err(ctx), |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9df8ec663..d25b5642b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -1,119 +1,121 @@ | |||
1 | mod generated; | 1 | mod generated; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | use std::string::String as RustString; | ||
5 | 4 | ||
6 | use itertools::Itertools; | 5 | use itertools::Itertools; |
7 | 6 | ||
8 | pub use self::generated::*; | 7 | pub use self::generated::*; |
9 | use crate::{ | 8 | use crate::{ |
10 | yellow::{RefRoot, SyntaxNodeChildren}, | 9 | yellow::{SyntaxNode, SyntaxNodeChildren, TreePtr, RaTypes}, |
11 | SmolStr, | 10 | SmolStr, |
12 | SyntaxKind::*, | 11 | SyntaxKind::*, |
13 | SyntaxNodeRef, | ||
14 | }; | 12 | }; |
15 | 13 | ||
16 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The | 14 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The |
17 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly | 15 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly |
18 | /// the same representation: a pointer to the tree root and a pointer to the | 16 | /// the same representation: a pointer to the tree root and a pointer to the |
19 | /// node itself. | 17 | /// node itself. |
20 | pub trait AstNode<'a>: Clone + Copy + 'a { | 18 | pub trait AstNode: rowan::TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>> { |
21 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> | 19 | fn cast(syntax: &SyntaxNode) -> Option<&Self> |
22 | where | 20 | where |
23 | Self: Sized; | 21 | Self: Sized; |
24 | fn syntax(self) -> SyntaxNodeRef<'a>; | 22 | fn syntax(&self) -> &SyntaxNode; |
23 | fn to_owned(&self) -> TreePtr<Self>; | ||
25 | } | 24 | } |
26 | 25 | ||
27 | pub trait NameOwner<'a>: AstNode<'a> { | 26 | pub trait AstToken: AstNode { |
28 | fn name(self) -> Option<Name<'a>> { | 27 | fn text(&self) -> &SmolStr { |
28 | self.syntax().leaf_text().unwrap() | ||
29 | } | ||
30 | } | ||
31 | |||
32 | pub trait NameOwner: AstNode { | ||
33 | fn name(&self) -> Option<&Name> { | ||
29 | child_opt(self) | 34 | child_opt(self) |
30 | } | 35 | } |
31 | } | 36 | } |
32 | 37 | ||
33 | pub trait VisibilityOwner<'a>: AstNode<'a> { | 38 | pub trait VisibilityOwner: AstNode { |
34 | fn visibility(self) -> Option<Visibility<'a>> { | 39 | fn visibility(&self) -> Option<&Visibility> { |
35 | child_opt(self) | 40 | child_opt(self) |
36 | } | 41 | } |
37 | } | 42 | } |
38 | 43 | ||
39 | pub trait LoopBodyOwner<'a>: AstNode<'a> { | 44 | pub trait LoopBodyOwner: AstNode { |
40 | fn loop_body(self) -> Option<Block<'a>> { | 45 | fn loop_body(&self) -> Option<&Block> { |
41 | child_opt(self) | 46 | child_opt(self) |
42 | } | 47 | } |
43 | } | 48 | } |
44 | 49 | ||
45 | pub trait ArgListOwner<'a>: AstNode<'a> { | 50 | pub trait ArgListOwner: AstNode { |
46 | fn arg_list(self) -> Option<ArgList<'a>> { | 51 | fn arg_list(&self) -> Option<&ArgList> { |
47 | child_opt(self) | 52 | child_opt(self) |
48 | } | 53 | } |
49 | } | 54 | } |
50 | 55 | ||
51 | pub trait FnDefOwner<'a>: AstNode<'a> { | 56 | pub trait FnDefOwner: AstNode { |
52 | fn functions(self) -> AstChildren<'a, FnDef<'a>> { | 57 | fn functions(&self) -> AstChildren<FnDef> { |
53 | children(self) | 58 | children(self) |
54 | } | 59 | } |
55 | } | 60 | } |
56 | 61 | ||
57 | // ModuleItem | ||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 62 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
59 | pub enum ItemOrMacro<'a> { | 63 | pub enum ItemOrMacro<'a> { |
60 | Item(ModuleItem<'a>), | 64 | Item(&'a ModuleItem), |
61 | Macro(MacroCall<'a>), | 65 | Macro(&'a MacroCall), |
62 | } | 66 | } |
63 | 67 | ||
64 | impl<'a> AstNode<'a> for ItemOrMacro<'a> { | 68 | pub trait ModuleItemOwner: AstNode { |
65 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 69 | fn items(&self) -> AstChildren<ModuleItem> { |
66 | let res = if let Some(item) = ModuleItem::cast(syntax) { | 70 | children(self) |
67 | ItemOrMacro::Item(item) | ||
68 | } else if let Some(macro_call) = MacroCall::cast(syntax) { | ||
69 | ItemOrMacro::Macro(macro_call) | ||
70 | } else { | ||
71 | return None; | ||
72 | }; | ||
73 | Some(res) | ||
74 | } | 71 | } |
75 | fn syntax(self) -> SyntaxNodeRef<'a> { | 72 | fn items_with_macros(&self) -> ItemOrMacroIter { |
76 | match self { | 73 | ItemOrMacroIter(self.syntax().children()) |
77 | ItemOrMacro::Item(it) => it.syntax(), | ||
78 | ItemOrMacro::Macro(it) => it.syntax(), | ||
79 | } | ||
80 | } | 74 | } |
81 | } | 75 | } |
82 | 76 | ||
83 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | 77 | #[derive(Debug)] |
84 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | 78 | pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); |
85 | children(self) | ||
86 | } | ||
87 | 79 | ||
88 | fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { | 80 | impl<'a> Iterator for ItemOrMacroIter<'a> { |
89 | children(self) | 81 | type Item = ItemOrMacro<'a>; |
82 | fn next(&mut self) -> Option<ItemOrMacro<'a>> { | ||
83 | loop { | ||
84 | let n = self.0.next()?; | ||
85 | if let Some(item) = ModuleItem::cast(n) { | ||
86 | return Some(ItemOrMacro::Item(item)); | ||
87 | } | ||
88 | if let Some(call) = MacroCall::cast(n) { | ||
89 | return Some(ItemOrMacro::Macro(call)); | ||
90 | } | ||
91 | } | ||
90 | } | 92 | } |
91 | } | 93 | } |
92 | 94 | ||
93 | pub trait TypeParamsOwner<'a>: AstNode<'a> { | 95 | pub trait TypeParamsOwner: AstNode { |
94 | fn type_param_list(self) -> Option<TypeParamList<'a>> { | 96 | fn type_param_list(&self) -> Option<&TypeParamList> { |
95 | child_opt(self) | 97 | child_opt(self) |
96 | } | 98 | } |
97 | 99 | ||
98 | fn where_clause(self) -> Option<WhereClause<'a>> { | 100 | fn where_clause(&self) -> Option<&WhereClause> { |
99 | child_opt(self) | 101 | child_opt(self) |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
103 | pub trait AttrsOwner<'a>: AstNode<'a> { | 105 | pub trait AttrsOwner: AstNode { |
104 | fn attrs(self) -> AstChildren<'a, Attr<'a>> { | 106 | fn attrs(&self) -> AstChildren<Attr> { |
105 | children(self) | 107 | children(self) |
106 | } | 108 | } |
107 | } | 109 | } |
108 | 110 | ||
109 | pub trait DocCommentsOwner<'a>: AstNode<'a> { | 111 | pub trait DocCommentsOwner: AstNode { |
110 | fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { | 112 | fn doc_comments(&self) -> AstChildren<Comment> { |
111 | children(self) | 113 | children(self) |
112 | } | 114 | } |
113 | 115 | ||
114 | /// Returns the textual content of a doc comment block as a single string. | 116 | /// Returns the textual content of a doc comment block as a single string. |
115 | /// That is, strips leading `///` and joins lines | 117 | /// That is, strips leading `///` and joins lines |
116 | fn doc_comment_text(self) -> RustString { | 118 | fn doc_comment_text(&self) -> std::string::String { |
117 | self.doc_comments() | 119 | self.doc_comments() |
118 | .filter(|comment| comment.is_doc_comment()) | 120 | .filter(|comment| comment.is_doc_comment()) |
119 | .map(|comment| { | 121 | .map(|comment| { |
@@ -130,13 +132,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
133 | impl<'a> FnDef<'a> { | 135 | impl FnDef { |
134 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 136 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
135 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | 137 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) |
136 | } | 138 | } |
137 | } | 139 | } |
138 | 140 | ||
139 | impl<'a> Attr<'a> { | 141 | impl Attr { |
140 | pub fn as_atom(&self) -> Option<SmolStr> { | 142 | pub fn as_atom(&self) -> Option<SmolStr> { |
141 | let tt = self.value()?; | 143 | let tt = self.value()?; |
142 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; | 144 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
@@ -147,7 +149,7 @@ impl<'a> Attr<'a> { | |||
147 | } | 149 | } |
148 | } | 150 | } |
149 | 151 | ||
150 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { | 152 | pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> { |
151 | let tt = self.value()?; | 153 | let tt = self.value()?; |
152 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | 154 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; |
153 | let args = TokenTree::cast(args)?; | 155 | let args = TokenTree::cast(args)?; |
@@ -159,41 +161,7 @@ impl<'a> Attr<'a> { | |||
159 | } | 161 | } |
160 | } | 162 | } |
161 | 163 | ||
162 | impl<'a> Lifetime<'a> { | 164 | impl Comment { |
163 | pub fn text(&self) -> SmolStr { | ||
164 | self.syntax().leaf_text().unwrap().clone() | ||
165 | } | ||
166 | } | ||
167 | |||
168 | impl<'a> Char<'a> { | ||
169 | pub fn text(&self) -> &SmolStr { | ||
170 | &self.syntax().leaf_text().unwrap() | ||
171 | } | ||
172 | } | ||
173 | |||
174 | impl<'a> Byte<'a> { | ||
175 | pub fn text(&self) -> &SmolStr { | ||
176 | &self.syntax().leaf_text().unwrap() | ||
177 | } | ||
178 | } | ||
179 | |||
180 | impl<'a> ByteString<'a> { | ||
181 | pub fn text(&self) -> &SmolStr { | ||
182 | &self.syntax().leaf_text().unwrap() | ||
183 | } | ||
184 | } | ||
185 | |||
186 | impl<'a> String<'a> { | ||
187 | pub fn text(&self) -> &SmolStr { | ||
188 | &self.syntax().leaf_text().unwrap() | ||
189 | } | ||
190 | } | ||
191 | |||
192 | impl<'a> Comment<'a> { | ||
193 | pub fn text(&self) -> &SmolStr { | ||
194 | self.syntax().leaf_text().unwrap() | ||
195 | } | ||
196 | |||
197 | pub fn flavor(&self) -> CommentFlavor { | 165 | pub fn flavor(&self) -> CommentFlavor { |
198 | let text = self.text(); | 166 | let text = self.text(); |
199 | if text.starts_with("///") { | 167 | if text.starts_with("///") { |
@@ -251,50 +219,46 @@ impl CommentFlavor { | |||
251 | } | 219 | } |
252 | } | 220 | } |
253 | 221 | ||
254 | impl<'a> Whitespace<'a> { | 222 | impl Whitespace { |
255 | pub fn text(&self) -> &SmolStr { | ||
256 | &self.syntax().leaf_text().unwrap() | ||
257 | } | ||
258 | |||
259 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { | 223 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { |
260 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) | 224 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) |
261 | } | 225 | } |
262 | 226 | ||
263 | pub fn has_newlines(&self) -> bool { | 227 | pub fn has_newlines(&self) -> bool { |
264 | self.count_newlines_lazy().count() > 0 | 228 | self.text().contains('\n') |
265 | } | 229 | } |
266 | } | 230 | } |
267 | 231 | ||
268 | impl<'a> Name<'a> { | 232 | impl Name { |
269 | pub fn text(&self) -> SmolStr { | 233 | pub fn text(&self) -> &SmolStr { |
270 | let ident = self.syntax().first_child().unwrap(); | 234 | let ident = self.syntax().first_child().unwrap(); |
271 | ident.leaf_text().unwrap().clone() | 235 | ident.leaf_text().unwrap() |
272 | } | 236 | } |
273 | } | 237 | } |
274 | 238 | ||
275 | impl<'a> NameRef<'a> { | 239 | impl NameRef { |
276 | pub fn text(&self) -> SmolStr { | 240 | pub fn text(&self) -> &SmolStr { |
277 | let ident = self.syntax().first_child().unwrap(); | 241 | let ident = self.syntax().first_child().unwrap(); |
278 | ident.leaf_text().unwrap().clone() | 242 | ident.leaf_text().unwrap() |
279 | } | 243 | } |
280 | } | 244 | } |
281 | 245 | ||
282 | impl<'a> ImplBlock<'a> { | 246 | impl ImplBlock { |
283 | pub fn target_type(self) -> Option<TypeRef<'a>> { | 247 | pub fn target_type(&self) -> Option<&TypeRef> { |
284 | match self.target() { | 248 | match self.target() { |
285 | (Some(t), None) | (_, Some(t)) => Some(t), | 249 | (Some(t), None) | (_, Some(t)) => Some(t), |
286 | _ => None, | 250 | _ => None, |
287 | } | 251 | } |
288 | } | 252 | } |
289 | 253 | ||
290 | pub fn target_trait(self) -> Option<TypeRef<'a>> { | 254 | pub fn target_trait(&self) -> Option<&TypeRef> { |
291 | match self.target() { | 255 | match self.target() { |
292 | (Some(t), Some(_)) => Some(t), | 256 | (Some(t), Some(_)) => Some(t), |
293 | _ => None, | 257 | _ => None, |
294 | } | 258 | } |
295 | } | 259 | } |
296 | 260 | ||
297 | fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { | 261 | fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) { |
298 | let mut types = children(self); | 262 | let mut types = children(self); |
299 | let first = types.next(); | 263 | let first = types.next(); |
300 | let second = types.next(); | 264 | let second = types.next(); |
@@ -302,8 +266,8 @@ impl<'a> ImplBlock<'a> { | |||
302 | } | 266 | } |
303 | } | 267 | } |
304 | 268 | ||
305 | impl<'a> Module<'a> { | 269 | impl Module { |
306 | pub fn has_semi(self) -> bool { | 270 | pub fn has_semi(&self) -> bool { |
307 | match self.syntax().last_child() { | 271 | match self.syntax().last_child() { |
308 | None => false, | 272 | None => false, |
309 | Some(node) => node.kind() == SEMI, | 273 | Some(node) => node.kind() == SEMI, |
@@ -311,8 +275,8 @@ impl<'a> Module<'a> { | |||
311 | } | 275 | } |
312 | } | 276 | } |
313 | 277 | ||
314 | impl<'a> LetStmt<'a> { | 278 | impl LetStmt { |
315 | pub fn has_semi(self) -> bool { | 279 | pub fn has_semi(&self) -> bool { |
316 | match self.syntax().last_child() { | 280 | match self.syntax().last_child() { |
317 | None => false, | 281 | None => false, |
318 | Some(node) => node.kind() == SEMI, | 282 | Some(node) => node.kind() == SEMI, |
@@ -320,35 +284,35 @@ impl<'a> LetStmt<'a> { | |||
320 | } | 284 | } |
321 | } | 285 | } |
322 | 286 | ||
323 | impl<'a> IfExpr<'a> { | 287 | impl IfExpr { |
324 | pub fn then_branch(self) -> Option<Block<'a>> { | 288 | pub fn then_branch(&self) -> Option<&Block> { |
325 | self.blocks().nth(0) | 289 | self.blocks().nth(0) |
326 | } | 290 | } |
327 | pub fn else_branch(self) -> Option<Block<'a>> { | 291 | pub fn else_branch(&self) -> Option<&Block> { |
328 | self.blocks().nth(1) | 292 | self.blocks().nth(1) |
329 | } | 293 | } |
330 | fn blocks(self) -> AstChildren<'a, Block<'a>> { | 294 | fn blocks(&self) -> AstChildren<Block> { |
331 | children(self) | 295 | children(self) |
332 | } | 296 | } |
333 | } | 297 | } |
334 | 298 | ||
335 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 299 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
336 | pub enum PathSegmentKind<'a> { | 300 | pub enum PathSegmentKind<'a> { |
337 | Name(NameRef<'a>), | 301 | Name(&'a NameRef), |
338 | SelfKw, | 302 | SelfKw, |
339 | SuperKw, | 303 | SuperKw, |
340 | CrateKw, | 304 | CrateKw, |
341 | } | 305 | } |
342 | 306 | ||
343 | impl<'a> PathSegment<'a> { | 307 | impl PathSegment { |
344 | pub fn parent_path(self) -> Path<'a> { | 308 | pub fn parent_path(&self) -> &Path { |
345 | self.syntax() | 309 | self.syntax() |
346 | .parent() | 310 | .parent() |
347 | .and_then(Path::cast) | 311 | .and_then(Path::cast) |
348 | .expect("segments are always nested in paths") | 312 | .expect("segments are always nested in paths") |
349 | } | 313 | } |
350 | 314 | ||
351 | pub fn kind(self) -> Option<PathSegmentKind<'a>> { | 315 | pub fn kind(&self) -> Option<PathSegmentKind> { |
352 | let res = if let Some(name_ref) = self.name_ref() { | 316 | let res = if let Some(name_ref) = self.name_ref() { |
353 | PathSegmentKind::Name(name_ref) | 317 | PathSegmentKind::Name(name_ref) |
354 | } else { | 318 | } else { |
@@ -363,20 +327,20 @@ impl<'a> PathSegment<'a> { | |||
363 | } | 327 | } |
364 | } | 328 | } |
365 | 329 | ||
366 | impl<'a> Path<'a> { | 330 | impl Path { |
367 | pub fn parent_path(self) -> Option<Path<'a>> { | 331 | pub fn parent_path(&self) -> Option<&Path> { |
368 | self.syntax().parent().and_then(Path::cast) | 332 | self.syntax().parent().and_then(Path::cast) |
369 | } | 333 | } |
370 | } | 334 | } |
371 | 335 | ||
372 | impl<'a> UseTree<'a> { | 336 | impl UseTree { |
373 | pub fn has_star(self) -> bool { | 337 | pub fn has_star(&self) -> bool { |
374 | self.syntax().children().any(|it| it.kind() == STAR) | 338 | self.syntax().children().any(|it| it.kind() == STAR) |
375 | } | 339 | } |
376 | } | 340 | } |
377 | 341 | ||
378 | impl<'a> UseTreeList<'a> { | 342 | impl UseTreeList { |
379 | pub fn parent_use_tree(self) -> UseTree<'a> { | 343 | pub fn parent_use_tree(&self) -> &UseTree { |
380 | self.syntax() | 344 | self.syntax() |
381 | .parent() | 345 | .parent() |
382 | .and_then(UseTree::cast) | 346 | .and_then(UseTree::cast) |
@@ -384,22 +348,22 @@ impl<'a> UseTreeList<'a> { | |||
384 | } | 348 | } |
385 | } | 349 | } |
386 | 350 | ||
387 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 351 | fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> { |
388 | children(parent).next() | 352 | children(parent).next() |
389 | } | 353 | } |
390 | 354 | ||
391 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { | 355 | fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> { |
392 | AstChildren::new(parent.syntax()) | 356 | AstChildren::new(parent.syntax()) |
393 | } | 357 | } |
394 | 358 | ||
395 | #[derive(Debug)] | 359 | #[derive(Debug)] |
396 | pub struct AstChildren<'a, N> { | 360 | pub struct AstChildren<'a, N> { |
397 | inner: SyntaxNodeChildren<RefRoot<'a>>, | 361 | inner: SyntaxNodeChildren<'a>, |
398 | ph: PhantomData<N>, | 362 | ph: PhantomData<N>, |
399 | } | 363 | } |
400 | 364 | ||
401 | impl<'a, N> AstChildren<'a, N> { | 365 | impl<'a, N> AstChildren<'a, N> { |
402 | fn new(parent: SyntaxNodeRef<'a>) -> Self { | 366 | fn new(parent: &'a SyntaxNode) -> Self { |
403 | AstChildren { | 367 | AstChildren { |
404 | inner: parent.children(), | 368 | inner: parent.children(), |
405 | ph: PhantomData, | 369 | ph: PhantomData, |
@@ -407,9 +371,9 @@ impl<'a, N> AstChildren<'a, N> { | |||
407 | } | 371 | } |
408 | } | 372 | } |
409 | 373 | ||
410 | impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | 374 | impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> { |
411 | type Item = N; | 375 | type Item = &'a N; |
412 | fn next(&mut self) -> Option<N> { | 376 | fn next(&mut self) -> Option<&'a N> { |
413 | loop { | 377 | loop { |
414 | if let Some(n) = N::cast(self.inner.next()?) { | 378 | if let Some(n) = N::cast(self.inner.next()?) { |
415 | return Some(n); | 379 | return Some(n); |
@@ -420,13 +384,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
420 | 384 | ||
421 | #[derive(Debug, Clone, PartialEq, Eq)] | 385 | #[derive(Debug, Clone, PartialEq, Eq)] |
422 | pub enum StructFlavor<'a> { | 386 | pub enum StructFlavor<'a> { |
423 | Tuple(PosFieldList<'a>), | 387 | Tuple(&'a PosFieldList), |
424 | Named(NamedFieldDefList<'a>), | 388 | Named(&'a NamedFieldDefList), |
425 | Unit, | 389 | Unit, |
426 | } | 390 | } |
427 | 391 | ||
428 | impl<'a> StructFlavor<'a> { | 392 | impl StructFlavor<'_> { |
429 | fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { | 393 | fn from_node<N: AstNode>(node: &N) -> StructFlavor { |
430 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { | 394 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { |
431 | StructFlavor::Named(nfdl) | 395 | StructFlavor::Named(nfdl) |
432 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { | 396 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { |
@@ -437,31 +401,31 @@ impl<'a> StructFlavor<'a> { | |||
437 | } | 401 | } |
438 | } | 402 | } |
439 | 403 | ||
440 | impl<'a> StructDef<'a> { | 404 | impl StructDef { |
441 | pub fn flavor(self) -> StructFlavor<'a> { | 405 | pub fn flavor(&self) -> StructFlavor { |
442 | StructFlavor::from_node(self) | 406 | StructFlavor::from_node(self) |
443 | } | 407 | } |
444 | } | 408 | } |
445 | 409 | ||
446 | impl<'a> EnumVariant<'a> { | 410 | impl EnumVariant { |
447 | pub fn flavor(self) -> StructFlavor<'a> { | 411 | pub fn flavor(&self) -> StructFlavor { |
448 | StructFlavor::from_node(self) | 412 | StructFlavor::from_node(self) |
449 | } | 413 | } |
450 | } | 414 | } |
451 | 415 | ||
452 | impl<'a> PointerType<'a> { | 416 | impl PointerType { |
453 | pub fn is_mut(&self) -> bool { | 417 | pub fn is_mut(&self) -> bool { |
454 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 418 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
455 | } | 419 | } |
456 | } | 420 | } |
457 | 421 | ||
458 | impl<'a> ReferenceType<'a> { | 422 | impl ReferenceType { |
459 | pub fn is_mut(&self) -> bool { | 423 | pub fn is_mut(&self) -> bool { |
460 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 424 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
461 | } | 425 | } |
462 | } | 426 | } |
463 | 427 | ||
464 | impl<'a> RefExpr<'a> { | 428 | impl RefExpr { |
465 | pub fn is_mut(&self) -> bool { | 429 | pub fn is_mut(&self) -> bool { |
466 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 430 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
467 | } | 431 | } |
@@ -477,7 +441,7 @@ pub enum PrefixOp { | |||
477 | Neg, | 441 | Neg, |
478 | } | 442 | } |
479 | 443 | ||
480 | impl<'a> PrefixExpr<'a> { | 444 | impl PrefixExpr { |
481 | pub fn op(&self) -> Option<PrefixOp> { | 445 | pub fn op(&self) -> Option<PrefixOp> { |
482 | match self.syntax().first_child()?.kind() { | 446 | match self.syntax().first_child()?.kind() { |
483 | STAR => Some(PrefixOp::Deref), | 447 | STAR => Some(PrefixOp::Deref), |
@@ -504,10 +468,55 @@ pub enum BinOp { | |||
504 | LesserTest, | 468 | LesserTest, |
505 | /// The `>` operator for comparison | 469 | /// The `>` operator for comparison |
506 | GreaterTest, | 470 | GreaterTest, |
507 | // TODO: lots of others | 471 | /// The `+` operator for addition |
508 | } | 472 | Addition, |
509 | 473 | /// The `*` operator for multiplication | |
510 | impl<'a> BinExpr<'a> { | 474 | Multiplication, |
475 | /// The `-` operator for subtraction | ||
476 | Subtraction, | ||
477 | /// The `/` operator for division | ||
478 | Division, | ||
479 | /// The `%` operator for remainder after division | ||
480 | Remainder, | ||
481 | /// The `<<` operator for left shift | ||
482 | LeftShift, | ||
483 | /// The `>>` operator for right shift | ||
484 | RightShift, | ||
485 | /// The `^` operator for bitwise XOR | ||
486 | BitwiseXor, | ||
487 | /// The `|` operator for bitwise OR | ||
488 | BitwiseOr, | ||
489 | /// The `&` operator for bitwise AND | ||
490 | BitwiseAnd, | ||
491 | /// The `..` operator for right-open ranges | ||
492 | RangeRightOpen, | ||
493 | /// The `..=` operator for right-closed ranges | ||
494 | RangeRightClosed, | ||
495 | /// The `=` operator for assignment | ||
496 | Assignment, | ||
497 | /// The `+=` operator for assignment after additon | ||
498 | AddAssign, | ||
499 | /// The `/=` operator for assignment after division | ||
500 | DivAssign, | ||
501 | /// The `*=` operator for assignment after multiplication | ||
502 | MulAssign, | ||
503 | /// The `%=` operator for assignment after remainders | ||
504 | RemAssign, | ||
505 | /// The `>>=` operator for assignment after shifting right | ||
506 | ShrAssign, | ||
507 | /// The `<<=` operator for assignment after shifting left | ||
508 | ShlAssign, | ||
509 | /// The `-=` operator for assignment after subtraction | ||
510 | SubAssign, | ||
511 | /// The `|=` operator for assignment after bitwise OR | ||
512 | BitOrAssign, | ||
513 | /// The `&=` operator for assignment after bitwise AND | ||
514 | BitAndAssign, | ||
515 | /// The `^=` operator for assignment after bitwise XOR | ||
516 | BitXorAssign, | ||
517 | } | ||
518 | |||
519 | impl BinExpr { | ||
511 | pub fn op(&self) -> Option<BinOp> { | 520 | pub fn op(&self) -> Option<BinOp> { |
512 | self.syntax() | 521 | self.syntax() |
513 | .children() | 522 | .children() |
@@ -519,20 +528,43 @@ impl<'a> BinExpr<'a> { | |||
519 | GTEQ => Some(BinOp::GreaterEqualTest), | 528 | GTEQ => Some(BinOp::GreaterEqualTest), |
520 | L_ANGLE => Some(BinOp::LesserTest), | 529 | L_ANGLE => Some(BinOp::LesserTest), |
521 | R_ANGLE => Some(BinOp::GreaterTest), | 530 | R_ANGLE => Some(BinOp::GreaterTest), |
531 | PLUS => Some(BinOp::Addition), | ||
532 | STAR => Some(BinOp::Multiplication), | ||
533 | MINUS => Some(BinOp::Subtraction), | ||
534 | SLASH => Some(BinOp::Division), | ||
535 | PERCENT => Some(BinOp::Remainder), | ||
536 | SHL => Some(BinOp::LeftShift), | ||
537 | SHR => Some(BinOp::RightShift), | ||
538 | CARET => Some(BinOp::BitwiseXor), | ||
539 | PIPE => Some(BinOp::BitwiseOr), | ||
540 | AMP => Some(BinOp::BitwiseAnd), | ||
541 | DOTDOT => Some(BinOp::RangeRightOpen), | ||
542 | DOTDOTEQ => Some(BinOp::RangeRightClosed), | ||
543 | EQ => Some(BinOp::Assignment), | ||
544 | PLUSEQ => Some(BinOp::AddAssign), | ||
545 | SLASHEQ => Some(BinOp::DivAssign), | ||
546 | STAREQ => Some(BinOp::MulAssign), | ||
547 | PERCENTEQ => Some(BinOp::RemAssign), | ||
548 | SHREQ => Some(BinOp::ShrAssign), | ||
549 | SHLEQ => Some(BinOp::ShlAssign), | ||
550 | MINUSEQ => Some(BinOp::SubAssign), | ||
551 | PIPEEQ => Some(BinOp::BitOrAssign), | ||
552 | AMPEQ => Some(BinOp::BitAndAssign), | ||
553 | CARETEQ => Some(BinOp::BitXorAssign), | ||
522 | _ => None, | 554 | _ => None, |
523 | }) | 555 | }) |
524 | .next() | 556 | .next() |
525 | } | 557 | } |
526 | 558 | ||
527 | pub fn lhs(self) -> Option<Expr<'a>> { | 559 | pub fn lhs(&self) -> Option<&Expr> { |
528 | children(self).nth(0) | 560 | children(self).nth(0) |
529 | } | 561 | } |
530 | 562 | ||
531 | pub fn rhs(self) -> Option<Expr<'a>> { | 563 | pub fn rhs(&self) -> Option<&Expr> { |
532 | children(self).nth(1) | 564 | children(self).nth(1) |
533 | } | 565 | } |
534 | 566 | ||
535 | pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { | 567 | pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) { |
536 | let mut children = children(self); | 568 | let mut children = children(self); |
537 | let first = children.next(); | 569 | let first = children.next(); |
538 | let second = children.next(); | 570 | let second = children.next(); |
@@ -550,7 +582,7 @@ pub enum SelfParamFlavor { | |||
550 | MutRef, | 582 | MutRef, |
551 | } | 583 | } |
552 | 584 | ||
553 | impl<'a> SelfParam<'a> { | 585 | impl SelfParam { |
554 | pub fn flavor(&self) -> SelfParamFlavor { | 586 | pub fn flavor(&self) -> SelfParamFlavor { |
555 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); | 587 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); |
556 | if borrowed { | 588 | if borrowed { |
@@ -573,7 +605,7 @@ impl<'a> SelfParam<'a> { | |||
573 | 605 | ||
574 | #[test] | 606 | #[test] |
575 | fn test_doc_comment_of_items() { | 607 | fn test_doc_comment_of_items() { |
576 | let file = SourceFileNode::parse( | 608 | let file = SourceFile::parse( |
577 | r#" | 609 | r#" |
578 | //! doc | 610 | //! doc |
579 | // non-doc | 611 | // non-doc |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 24f72393a..547e3c003 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -9,4648 +9,3394 @@ | |||
9 | 9 | ||
10 | #![cfg_attr(rustfmt, rustfmt_skip)] | 10 | #![cfg_attr(rustfmt, rustfmt_skip)] |
11 | 11 | ||
12 | use std::hash::{Hash, Hasher}; | 12 | use rowan::TransparentNewType; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | ast, | 15 | SyntaxNode, SyntaxKind::*, |
16 | SyntaxNode, SyntaxNodeRef, AstNode, | 16 | yellow::{RaTypes, TreePtr}, |
17 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | 17 | ast::{self, AstNode}, |
18 | SyntaxKind::*, | ||
19 | }; | 18 | }; |
20 | 19 | ||
21 | // ArgList | 20 | // ArgList |
22 | #[derive(Debug, Clone, Copy,)] | 21 | #[derive(Debug, PartialEq, Eq, Hash)] |
23 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 22 | #[repr(transparent)] |
24 | pub(crate) syntax: SyntaxNode<R>, | 23 | pub struct ArgList { |
24 | pub(crate) syntax: SyntaxNode, | ||
25 | } | 25 | } |
26 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; | 26 | unsafe impl TransparentNewType for ArgList { |
27 | 27 | type Repr = rowan::SyntaxNode<RaTypes>; | |
28 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArgListNode<R1>> for ArgListNode<R2> { | ||
29 | fn eq(&self, other: &ArgListNode<R1>) -> bool { self.syntax == other.syntax } | ||
30 | } | ||
31 | impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {} | ||
32 | impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> { | ||
33 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
34 | } | 28 | } |
35 | 29 | ||
36 | impl<'a> AstNode<'a> for ArgList<'a> { | 30 | impl AstNode for ArgList { |
37 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 31 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
38 | match syntax.kind() { | 32 | match syntax.kind() { |
39 | ARG_LIST => Some(ArgList { syntax }), | 33 | ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())), |
40 | _ => None, | 34 | _ => None, |
41 | } | 35 | } |
42 | } | 36 | } |
43 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 37 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
44 | } | 38 | fn to_owned(&self) -> TreePtr<ArgList> { TreePtr::cast(self.syntax.to_owned()) } |
45 | |||
46 | impl<R: TreeRoot<RaTypes>> ArgListNode<R> { | ||
47 | pub fn borrowed(&self) -> ArgList { | ||
48 | ArgListNode { syntax: self.syntax.borrowed() } | ||
49 | } | ||
50 | pub fn owned(&self) -> ArgListNode { | ||
51 | ArgListNode { syntax: self.syntax.owned() } | ||
52 | } | ||
53 | } | 39 | } |
54 | 40 | ||
55 | 41 | ||
56 | impl<'a> ArgList<'a> { | 42 | impl ArgList { |
57 | pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a { | 43 | pub fn args(&self) -> impl Iterator<Item = &Expr> { |
58 | super::children(self) | 44 | super::children(self) |
59 | } | 45 | } |
60 | } | 46 | } |
61 | 47 | ||
62 | // ArrayExpr | 48 | // ArrayExpr |
63 | #[derive(Debug, Clone, Copy,)] | 49 | #[derive(Debug, PartialEq, Eq, Hash)] |
64 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 50 | #[repr(transparent)] |
65 | pub(crate) syntax: SyntaxNode<R>, | 51 | pub struct ArrayExpr { |
52 | pub(crate) syntax: SyntaxNode, | ||
66 | } | 53 | } |
67 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; | 54 | unsafe impl TransparentNewType for ArrayExpr { |
68 | 55 | type Repr = rowan::SyntaxNode<RaTypes>; | |
69 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayExprNode<R1>> for ArrayExprNode<R2> { | ||
70 | fn eq(&self, other: &ArrayExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
71 | } | ||
72 | impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {} | ||
73 | impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> { | ||
74 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
75 | } | 56 | } |
76 | 57 | ||
77 | impl<'a> AstNode<'a> for ArrayExpr<'a> { | 58 | impl AstNode for ArrayExpr { |
78 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 59 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
79 | match syntax.kind() { | 60 | match syntax.kind() { |
80 | ARRAY_EXPR => Some(ArrayExpr { syntax }), | 61 | ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())), |
81 | _ => None, | 62 | _ => None, |
82 | } | 63 | } |
83 | } | 64 | } |
84 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 65 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
85 | } | 66 | fn to_owned(&self) -> TreePtr<ArrayExpr> { TreePtr::cast(self.syntax.to_owned()) } |
86 | |||
87 | impl<R: TreeRoot<RaTypes>> ArrayExprNode<R> { | ||
88 | pub fn borrowed(&self) -> ArrayExpr { | ||
89 | ArrayExprNode { syntax: self.syntax.borrowed() } | ||
90 | } | ||
91 | pub fn owned(&self) -> ArrayExprNode { | ||
92 | ArrayExprNode { syntax: self.syntax.owned() } | ||
93 | } | ||
94 | } | 67 | } |
95 | 68 | ||
96 | 69 | ||
97 | impl<'a> ArrayExpr<'a> {} | 70 | impl ArrayExpr {} |
98 | 71 | ||
99 | // ArrayType | 72 | // ArrayType |
100 | #[derive(Debug, Clone, Copy,)] | 73 | #[derive(Debug, PartialEq, Eq, Hash)] |
101 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 74 | #[repr(transparent)] |
102 | pub(crate) syntax: SyntaxNode<R>, | 75 | pub struct ArrayType { |
103 | } | 76 | pub(crate) syntax: SyntaxNode, |
104 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; | ||
105 | |||
106 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayTypeNode<R1>> for ArrayTypeNode<R2> { | ||
107 | fn eq(&self, other: &ArrayTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
108 | } | 77 | } |
109 | impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} | 78 | unsafe impl TransparentNewType for ArrayType { |
110 | impl<R: TreeRoot<RaTypes>> Hash for ArrayTypeNode<R> { | 79 | type Repr = rowan::SyntaxNode<RaTypes>; |
111 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
112 | } | 80 | } |
113 | 81 | ||
114 | impl<'a> AstNode<'a> for ArrayType<'a> { | 82 | impl AstNode for ArrayType { |
115 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 83 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
116 | match syntax.kind() { | 84 | match syntax.kind() { |
117 | ARRAY_TYPE => Some(ArrayType { syntax }), | 85 | ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())), |
118 | _ => None, | 86 | _ => None, |
119 | } | 87 | } |
120 | } | 88 | } |
121 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 89 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
90 | fn to_owned(&self) -> TreePtr<ArrayType> { TreePtr::cast(self.syntax.to_owned()) } | ||
122 | } | 91 | } |
123 | 92 | ||
124 | impl<R: TreeRoot<RaTypes>> ArrayTypeNode<R> { | ||
125 | pub fn borrowed(&self) -> ArrayType { | ||
126 | ArrayTypeNode { syntax: self.syntax.borrowed() } | ||
127 | } | ||
128 | pub fn owned(&self) -> ArrayTypeNode { | ||
129 | ArrayTypeNode { syntax: self.syntax.owned() } | ||
130 | } | ||
131 | } | ||
132 | 93 | ||
133 | 94 | impl ArrayType { | |
134 | impl<'a> ArrayType<'a> { | 95 | pub fn type_ref(&self) -> Option<&TypeRef> { |
135 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
136 | super::child_opt(self) | 96 | super::child_opt(self) |
137 | } | 97 | } |
138 | 98 | ||
139 | pub fn expr(self) -> Option<Expr<'a>> { | 99 | pub fn expr(&self) -> Option<&Expr> { |
140 | super::child_opt(self) | 100 | super::child_opt(self) |
141 | } | 101 | } |
142 | } | 102 | } |
143 | 103 | ||
144 | // Attr | 104 | // Attr |
145 | #[derive(Debug, Clone, Copy,)] | 105 | #[derive(Debug, PartialEq, Eq, Hash)] |
146 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 106 | #[repr(transparent)] |
147 | pub(crate) syntax: SyntaxNode<R>, | 107 | pub struct Attr { |
148 | } | 108 | pub(crate) syntax: SyntaxNode, |
149 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; | ||
150 | |||
151 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<AttrNode<R1>> for AttrNode<R2> { | ||
152 | fn eq(&self, other: &AttrNode<R1>) -> bool { self.syntax == other.syntax } | ||
153 | } | 109 | } |
154 | impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} | 110 | unsafe impl TransparentNewType for Attr { |
155 | impl<R: TreeRoot<RaTypes>> Hash for AttrNode<R> { | 111 | type Repr = rowan::SyntaxNode<RaTypes>; |
156 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
157 | } | 112 | } |
158 | 113 | ||
159 | impl<'a> AstNode<'a> for Attr<'a> { | 114 | impl AstNode for Attr { |
160 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 115 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
161 | match syntax.kind() { | 116 | match syntax.kind() { |
162 | ATTR => Some(Attr { syntax }), | 117 | ATTR => Some(Attr::from_repr(syntax.into_repr())), |
163 | _ => None, | 118 | _ => None, |
164 | } | 119 | } |
165 | } | 120 | } |
166 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 121 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
167 | } | 122 | fn to_owned(&self) -> TreePtr<Attr> { TreePtr::cast(self.syntax.to_owned()) } |
168 | |||
169 | impl<R: TreeRoot<RaTypes>> AttrNode<R> { | ||
170 | pub fn borrowed(&self) -> Attr { | ||
171 | AttrNode { syntax: self.syntax.borrowed() } | ||
172 | } | ||
173 | pub fn owned(&self) -> AttrNode { | ||
174 | AttrNode { syntax: self.syntax.owned() } | ||
175 | } | ||
176 | } | 123 | } |
177 | 124 | ||
178 | 125 | ||
179 | impl<'a> Attr<'a> { | 126 | impl Attr { |
180 | pub fn value(self) -> Option<TokenTree<'a>> { | 127 | pub fn value(&self) -> Option<&TokenTree> { |
181 | super::child_opt(self) | 128 | super::child_opt(self) |
182 | } | 129 | } |
183 | } | 130 | } |
184 | 131 | ||
185 | // BinExpr | 132 | // BinExpr |
186 | #[derive(Debug, Clone, Copy,)] | 133 | #[derive(Debug, PartialEq, Eq, Hash)] |
187 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 134 | #[repr(transparent)] |
188 | pub(crate) syntax: SyntaxNode<R>, | 135 | pub struct BinExpr { |
189 | } | 136 | pub(crate) syntax: SyntaxNode, |
190 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; | ||
191 | |||
192 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BinExprNode<R1>> for BinExprNode<R2> { | ||
193 | fn eq(&self, other: &BinExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
194 | } | 137 | } |
195 | impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} | 138 | unsafe impl TransparentNewType for BinExpr { |
196 | impl<R: TreeRoot<RaTypes>> Hash for BinExprNode<R> { | 139 | type Repr = rowan::SyntaxNode<RaTypes>; |
197 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
198 | } | 140 | } |
199 | 141 | ||
200 | impl<'a> AstNode<'a> for BinExpr<'a> { | 142 | impl AstNode for BinExpr { |
201 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 143 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
202 | match syntax.kind() { | 144 | match syntax.kind() { |
203 | BIN_EXPR => Some(BinExpr { syntax }), | 145 | BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())), |
204 | _ => None, | 146 | _ => None, |
205 | } | 147 | } |
206 | } | 148 | } |
207 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 149 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
208 | } | 150 | fn to_owned(&self) -> TreePtr<BinExpr> { TreePtr::cast(self.syntax.to_owned()) } |
209 | |||
210 | impl<R: TreeRoot<RaTypes>> BinExprNode<R> { | ||
211 | pub fn borrowed(&self) -> BinExpr { | ||
212 | BinExprNode { syntax: self.syntax.borrowed() } | ||
213 | } | ||
214 | pub fn owned(&self) -> BinExprNode { | ||
215 | BinExprNode { syntax: self.syntax.owned() } | ||
216 | } | ||
217 | } | 151 | } |
218 | 152 | ||
219 | 153 | ||
220 | impl<'a> BinExpr<'a> {} | 154 | impl BinExpr {} |
221 | 155 | ||
222 | // BindPat | 156 | // BindPat |
223 | #[derive(Debug, Clone, Copy,)] | 157 | #[derive(Debug, PartialEq, Eq, Hash)] |
224 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 158 | #[repr(transparent)] |
225 | pub(crate) syntax: SyntaxNode<R>, | 159 | pub struct BindPat { |
160 | pub(crate) syntax: SyntaxNode, | ||
226 | } | 161 | } |
227 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; | 162 | unsafe impl TransparentNewType for BindPat { |
228 | 163 | type Repr = rowan::SyntaxNode<RaTypes>; | |
229 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BindPatNode<R1>> for BindPatNode<R2> { | ||
230 | fn eq(&self, other: &BindPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
231 | } | ||
232 | impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {} | ||
233 | impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> { | ||
234 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
235 | } | 164 | } |
236 | 165 | ||
237 | impl<'a> AstNode<'a> for BindPat<'a> { | 166 | impl AstNode for BindPat { |
238 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 167 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
239 | match syntax.kind() { | 168 | match syntax.kind() { |
240 | BIND_PAT => Some(BindPat { syntax }), | 169 | BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())), |
241 | _ => None, | 170 | _ => None, |
242 | } | 171 | } |
243 | } | 172 | } |
244 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 173 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
245 | } | 174 | fn to_owned(&self) -> TreePtr<BindPat> { TreePtr::cast(self.syntax.to_owned()) } |
246 | |||
247 | impl<R: TreeRoot<RaTypes>> BindPatNode<R> { | ||
248 | pub fn borrowed(&self) -> BindPat { | ||
249 | BindPatNode { syntax: self.syntax.borrowed() } | ||
250 | } | ||
251 | pub fn owned(&self) -> BindPatNode { | ||
252 | BindPatNode { syntax: self.syntax.owned() } | ||
253 | } | ||
254 | } | 175 | } |
255 | 176 | ||
256 | 177 | ||
257 | impl<'a> ast::NameOwner<'a> for BindPat<'a> {} | 178 | impl ast::NameOwner for BindPat {} |
258 | impl<'a> BindPat<'a> {} | 179 | impl BindPat {} |
259 | 180 | ||
260 | // Block | 181 | // Block |
261 | #[derive(Debug, Clone, Copy,)] | 182 | #[derive(Debug, PartialEq, Eq, Hash)] |
262 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 183 | #[repr(transparent)] |
263 | pub(crate) syntax: SyntaxNode<R>, | 184 | pub struct Block { |
264 | } | 185 | pub(crate) syntax: SyntaxNode, |
265 | pub type Block<'a> = BlockNode<RefRoot<'a>>; | ||
266 | |||
267 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockNode<R1>> for BlockNode<R2> { | ||
268 | fn eq(&self, other: &BlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
269 | } | 186 | } |
270 | impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} | 187 | unsafe impl TransparentNewType for Block { |
271 | impl<R: TreeRoot<RaTypes>> Hash for BlockNode<R> { | 188 | type Repr = rowan::SyntaxNode<RaTypes>; |
272 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
273 | } | 189 | } |
274 | 190 | ||
275 | impl<'a> AstNode<'a> for Block<'a> { | 191 | impl AstNode for Block { |
276 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 192 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
277 | match syntax.kind() { | 193 | match syntax.kind() { |
278 | BLOCK => Some(Block { syntax }), | 194 | BLOCK => Some(Block::from_repr(syntax.into_repr())), |
279 | _ => None, | 195 | _ => None, |
280 | } | 196 | } |
281 | } | 197 | } |
282 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 198 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
199 | fn to_owned(&self) -> TreePtr<Block> { TreePtr::cast(self.syntax.to_owned()) } | ||
283 | } | 200 | } |
284 | 201 | ||
285 | impl<R: TreeRoot<RaTypes>> BlockNode<R> { | ||
286 | pub fn borrowed(&self) -> Block { | ||
287 | BlockNode { syntax: self.syntax.borrowed() } | ||
288 | } | ||
289 | pub fn owned(&self) -> BlockNode { | ||
290 | BlockNode { syntax: self.syntax.owned() } | ||
291 | } | ||
292 | } | ||
293 | 202 | ||
294 | 203 | impl Block { | |
295 | impl<'a> Block<'a> { | 204 | pub fn statements(&self) -> impl Iterator<Item = &Stmt> { |
296 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { | ||
297 | super::children(self) | 205 | super::children(self) |
298 | } | 206 | } |
299 | 207 | ||
300 | pub fn expr(self) -> Option<Expr<'a>> { | 208 | pub fn expr(&self) -> Option<&Expr> { |
301 | super::child_opt(self) | 209 | super::child_opt(self) |
302 | } | 210 | } |
303 | } | 211 | } |
304 | 212 | ||
305 | // BlockExpr | 213 | // BlockExpr |
306 | #[derive(Debug, Clone, Copy,)] | 214 | #[derive(Debug, PartialEq, Eq, Hash)] |
307 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 215 | #[repr(transparent)] |
308 | pub(crate) syntax: SyntaxNode<R>, | 216 | pub struct BlockExpr { |
217 | pub(crate) syntax: SyntaxNode, | ||
309 | } | 218 | } |
310 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; | 219 | unsafe impl TransparentNewType for BlockExpr { |
311 | 220 | type Repr = rowan::SyntaxNode<RaTypes>; | |
312 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockExprNode<R1>> for BlockExprNode<R2> { | ||
313 | fn eq(&self, other: &BlockExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
314 | } | ||
315 | impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {} | ||
316 | impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> { | ||
317 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
318 | } | 221 | } |
319 | 222 | ||
320 | impl<'a> AstNode<'a> for BlockExpr<'a> { | 223 | impl AstNode for BlockExpr { |
321 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 224 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
322 | match syntax.kind() { | 225 | match syntax.kind() { |
323 | BLOCK_EXPR => Some(BlockExpr { syntax }), | 226 | BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())), |
324 | _ => None, | 227 | _ => None, |
325 | } | 228 | } |
326 | } | 229 | } |
327 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 230 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
328 | } | 231 | fn to_owned(&self) -> TreePtr<BlockExpr> { TreePtr::cast(self.syntax.to_owned()) } |
329 | |||
330 | impl<R: TreeRoot<RaTypes>> BlockExprNode<R> { | ||
331 | pub fn borrowed(&self) -> BlockExpr { | ||
332 | BlockExprNode { syntax: self.syntax.borrowed() } | ||
333 | } | ||
334 | pub fn owned(&self) -> BlockExprNode { | ||
335 | BlockExprNode { syntax: self.syntax.owned() } | ||
336 | } | ||
337 | } | 232 | } |
338 | 233 | ||
339 | 234 | ||
340 | impl<'a> BlockExpr<'a> { | 235 | impl BlockExpr { |
341 | pub fn block(self) -> Option<Block<'a>> { | 236 | pub fn block(&self) -> Option<&Block> { |
342 | super::child_opt(self) | 237 | super::child_opt(self) |
343 | } | 238 | } |
344 | } | 239 | } |
345 | 240 | ||
346 | // BreakExpr | 241 | // BreakExpr |
347 | #[derive(Debug, Clone, Copy,)] | 242 | #[derive(Debug, PartialEq, Eq, Hash)] |
348 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 243 | #[repr(transparent)] |
349 | pub(crate) syntax: SyntaxNode<R>, | 244 | pub struct BreakExpr { |
245 | pub(crate) syntax: SyntaxNode, | ||
350 | } | 246 | } |
351 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; | 247 | unsafe impl TransparentNewType for BreakExpr { |
352 | 248 | type Repr = rowan::SyntaxNode<RaTypes>; | |
353 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BreakExprNode<R1>> for BreakExprNode<R2> { | ||
354 | fn eq(&self, other: &BreakExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
355 | } | ||
356 | impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {} | ||
357 | impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> { | ||
358 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
359 | } | 249 | } |
360 | 250 | ||
361 | impl<'a> AstNode<'a> for BreakExpr<'a> { | 251 | impl AstNode for BreakExpr { |
362 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 252 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
363 | match syntax.kind() { | 253 | match syntax.kind() { |
364 | BREAK_EXPR => Some(BreakExpr { syntax }), | 254 | BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())), |
365 | _ => None, | 255 | _ => None, |
366 | } | 256 | } |
367 | } | 257 | } |
368 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 258 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
369 | } | 259 | fn to_owned(&self) -> TreePtr<BreakExpr> { TreePtr::cast(self.syntax.to_owned()) } |
370 | |||
371 | impl<R: TreeRoot<RaTypes>> BreakExprNode<R> { | ||
372 | pub fn borrowed(&self) -> BreakExpr { | ||
373 | BreakExprNode { syntax: self.syntax.borrowed() } | ||
374 | } | ||
375 | pub fn owned(&self) -> BreakExprNode { | ||
376 | BreakExprNode { syntax: self.syntax.owned() } | ||
377 | } | ||
378 | } | 260 | } |
379 | 261 | ||
380 | 262 | ||
381 | impl<'a> BreakExpr<'a> { | 263 | impl BreakExpr { |
382 | pub fn expr(self) -> Option<Expr<'a>> { | 264 | pub fn expr(&self) -> Option<&Expr> { |
383 | super::child_opt(self) | 265 | super::child_opt(self) |
384 | } | 266 | } |
385 | } | 267 | } |
386 | 268 | ||
387 | // Byte | 269 | // Byte |
388 | #[derive(Debug, Clone, Copy,)] | 270 | #[derive(Debug, PartialEq, Eq, Hash)] |
389 | pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 271 | #[repr(transparent)] |
390 | pub(crate) syntax: SyntaxNode<R>, | 272 | pub struct Byte { |
273 | pub(crate) syntax: SyntaxNode, | ||
391 | } | 274 | } |
392 | pub type Byte<'a> = ByteNode<RefRoot<'a>>; | 275 | unsafe impl TransparentNewType for Byte { |
393 | 276 | type Repr = rowan::SyntaxNode<RaTypes>; | |
394 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> { | ||
395 | fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax } | ||
396 | } | ||
397 | impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {} | ||
398 | impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> { | ||
399 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
400 | } | 277 | } |
401 | 278 | ||
402 | impl<'a> AstNode<'a> for Byte<'a> { | 279 | impl AstNode for Byte { |
403 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 280 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
404 | match syntax.kind() { | 281 | match syntax.kind() { |
405 | BYTE => Some(Byte { syntax }), | 282 | BYTE => Some(Byte::from_repr(syntax.into_repr())), |
406 | _ => None, | 283 | _ => None, |
407 | } | 284 | } |
408 | } | 285 | } |
409 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 286 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
410 | } | 287 | fn to_owned(&self) -> TreePtr<Byte> { TreePtr::cast(self.syntax.to_owned()) } |
411 | |||
412 | impl<R: TreeRoot<RaTypes>> ByteNode<R> { | ||
413 | pub fn borrowed(&self) -> Byte { | ||
414 | ByteNode { syntax: self.syntax.borrowed() } | ||
415 | } | ||
416 | pub fn owned(&self) -> ByteNode { | ||
417 | ByteNode { syntax: self.syntax.owned() } | ||
418 | } | ||
419 | } | 288 | } |
420 | 289 | ||
421 | 290 | ||
422 | impl<'a> Byte<'a> {} | 291 | impl ast::AstToken for Byte {} |
292 | impl Byte {} | ||
423 | 293 | ||
424 | // ByteString | 294 | // ByteString |
425 | #[derive(Debug, Clone, Copy,)] | 295 | #[derive(Debug, PartialEq, Eq, Hash)] |
426 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 296 | #[repr(transparent)] |
427 | pub(crate) syntax: SyntaxNode<R>, | 297 | pub struct ByteString { |
428 | } | 298 | pub(crate) syntax: SyntaxNode, |
429 | pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>; | ||
430 | |||
431 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> { | ||
432 | fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax } | ||
433 | } | 299 | } |
434 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | 300 | unsafe impl TransparentNewType for ByteString { |
435 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | 301 | type Repr = rowan::SyntaxNode<RaTypes>; |
436 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
437 | } | 302 | } |
438 | 303 | ||
439 | impl<'a> AstNode<'a> for ByteString<'a> { | 304 | impl AstNode for ByteString { |
440 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 305 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
441 | match syntax.kind() { | 306 | match syntax.kind() { |
442 | BYTE_STRING => Some(ByteString { syntax }), | 307 | BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())), |
443 | _ => None, | 308 | _ => None, |
444 | } | 309 | } |
445 | } | 310 | } |
446 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 311 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
447 | } | 312 | fn to_owned(&self) -> TreePtr<ByteString> { TreePtr::cast(self.syntax.to_owned()) } |
448 | |||
449 | impl<R: TreeRoot<RaTypes>> ByteStringNode<R> { | ||
450 | pub fn borrowed(&self) -> ByteString { | ||
451 | ByteStringNode { syntax: self.syntax.borrowed() } | ||
452 | } | ||
453 | pub fn owned(&self) -> ByteStringNode { | ||
454 | ByteStringNode { syntax: self.syntax.owned() } | ||
455 | } | ||
456 | } | 313 | } |
457 | 314 | ||
458 | 315 | ||
459 | impl<'a> ByteString<'a> {} | 316 | impl ast::AstToken for ByteString {} |
317 | impl ByteString {} | ||
460 | 318 | ||
461 | // CallExpr | 319 | // CallExpr |
462 | #[derive(Debug, Clone, Copy,)] | 320 | #[derive(Debug, PartialEq, Eq, Hash)] |
463 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 321 | #[repr(transparent)] |
464 | pub(crate) syntax: SyntaxNode<R>, | 322 | pub struct CallExpr { |
465 | } | 323 | pub(crate) syntax: SyntaxNode, |
466 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; | ||
467 | |||
468 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> { | ||
469 | fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
470 | } | 324 | } |
471 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | 325 | unsafe impl TransparentNewType for CallExpr { |
472 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | 326 | type Repr = rowan::SyntaxNode<RaTypes>; |
473 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
474 | } | 327 | } |
475 | 328 | ||
476 | impl<'a> AstNode<'a> for CallExpr<'a> { | 329 | impl AstNode for CallExpr { |
477 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 330 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
478 | match syntax.kind() { | 331 | match syntax.kind() { |
479 | CALL_EXPR => Some(CallExpr { syntax }), | 332 | CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), |
480 | _ => None, | 333 | _ => None, |
481 | } | 334 | } |
482 | } | 335 | } |
483 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 336 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
484 | } | 337 | fn to_owned(&self) -> TreePtr<CallExpr> { TreePtr::cast(self.syntax.to_owned()) } |
485 | |||
486 | impl<R: TreeRoot<RaTypes>> CallExprNode<R> { | ||
487 | pub fn borrowed(&self) -> CallExpr { | ||
488 | CallExprNode { syntax: self.syntax.borrowed() } | ||
489 | } | ||
490 | pub fn owned(&self) -> CallExprNode { | ||
491 | CallExprNode { syntax: self.syntax.owned() } | ||
492 | } | ||
493 | } | 338 | } |
494 | 339 | ||
495 | 340 | ||
496 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 341 | impl ast::ArgListOwner for CallExpr {} |
497 | impl<'a> CallExpr<'a> { | 342 | impl CallExpr { |
498 | pub fn expr(self) -> Option<Expr<'a>> { | 343 | pub fn expr(&self) -> Option<&Expr> { |
499 | super::child_opt(self) | 344 | super::child_opt(self) |
500 | } | 345 | } |
501 | } | 346 | } |
502 | 347 | ||
503 | // CastExpr | 348 | // CastExpr |
504 | #[derive(Debug, Clone, Copy,)] | 349 | #[derive(Debug, PartialEq, Eq, Hash)] |
505 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 350 | #[repr(transparent)] |
506 | pub(crate) syntax: SyntaxNode<R>, | 351 | pub struct CastExpr { |
352 | pub(crate) syntax: SyntaxNode, | ||
507 | } | 353 | } |
508 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | 354 | unsafe impl TransparentNewType for CastExpr { |
509 | 355 | type Repr = rowan::SyntaxNode<RaTypes>; | |
510 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CastExprNode<R1>> for CastExprNode<R2> { | ||
511 | fn eq(&self, other: &CastExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
512 | } | ||
513 | impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {} | ||
514 | impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> { | ||
515 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
516 | } | 356 | } |
517 | 357 | ||
518 | impl<'a> AstNode<'a> for CastExpr<'a> { | 358 | impl AstNode for CastExpr { |
519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 359 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
520 | match syntax.kind() { | 360 | match syntax.kind() { |
521 | CAST_EXPR => Some(CastExpr { syntax }), | 361 | CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), |
522 | _ => None, | 362 | _ => None, |
523 | } | 363 | } |
524 | } | 364 | } |
525 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 365 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
526 | } | 366 | fn to_owned(&self) -> TreePtr<CastExpr> { TreePtr::cast(self.syntax.to_owned()) } |
527 | |||
528 | impl<R: TreeRoot<RaTypes>> CastExprNode<R> { | ||
529 | pub fn borrowed(&self) -> CastExpr { | ||
530 | CastExprNode { syntax: self.syntax.borrowed() } | ||
531 | } | ||
532 | pub fn owned(&self) -> CastExprNode { | ||
533 | CastExprNode { syntax: self.syntax.owned() } | ||
534 | } | ||
535 | } | 367 | } |
536 | 368 | ||
537 | 369 | ||
538 | impl<'a> CastExpr<'a> { | 370 | impl CastExpr { |
539 | pub fn expr(self) -> Option<Expr<'a>> { | 371 | pub fn expr(&self) -> Option<&Expr> { |
540 | super::child_opt(self) | 372 | super::child_opt(self) |
541 | } | 373 | } |
542 | 374 | ||
543 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 375 | pub fn type_ref(&self) -> Option<&TypeRef> { |
544 | super::child_opt(self) | 376 | super::child_opt(self) |
545 | } | 377 | } |
546 | } | 378 | } |
547 | 379 | ||
548 | // Char | 380 | // Char |
549 | #[derive(Debug, Clone, Copy,)] | 381 | #[derive(Debug, PartialEq, Eq, Hash)] |
550 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 382 | #[repr(transparent)] |
551 | pub(crate) syntax: SyntaxNode<R>, | 383 | pub struct Char { |
552 | } | 384 | pub(crate) syntax: SyntaxNode, |
553 | pub type Char<'a> = CharNode<RefRoot<'a>>; | ||
554 | |||
555 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CharNode<R1>> for CharNode<R2> { | ||
556 | fn eq(&self, other: &CharNode<R1>) -> bool { self.syntax == other.syntax } | ||
557 | } | 385 | } |
558 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} | 386 | unsafe impl TransparentNewType for Char { |
559 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { | 387 | type Repr = rowan::SyntaxNode<RaTypes>; |
560 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
561 | } | 388 | } |
562 | 389 | ||
563 | impl<'a> AstNode<'a> for Char<'a> { | 390 | impl AstNode for Char { |
564 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 391 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
565 | match syntax.kind() { | 392 | match syntax.kind() { |
566 | CHAR => Some(Char { syntax }), | 393 | CHAR => Some(Char::from_repr(syntax.into_repr())), |
567 | _ => None, | 394 | _ => None, |
568 | } | 395 | } |
569 | } | 396 | } |
570 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 397 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
398 | fn to_owned(&self) -> TreePtr<Char> { TreePtr::cast(self.syntax.to_owned()) } | ||
571 | } | 399 | } |
572 | 400 | ||
573 | impl<R: TreeRoot<RaTypes>> CharNode<R> { | ||
574 | pub fn borrowed(&self) -> Char { | ||
575 | CharNode { syntax: self.syntax.borrowed() } | ||
576 | } | ||
577 | pub fn owned(&self) -> CharNode { | ||
578 | CharNode { syntax: self.syntax.owned() } | ||
579 | } | ||
580 | } | ||
581 | 401 | ||
582 | 402 | impl ast::AstToken for Char {} | |
583 | impl<'a> Char<'a> {} | 403 | impl Char {} |
584 | 404 | ||
585 | // Comment | 405 | // Comment |
586 | #[derive(Debug, Clone, Copy,)] | 406 | #[derive(Debug, PartialEq, Eq, Hash)] |
587 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 407 | #[repr(transparent)] |
588 | pub(crate) syntax: SyntaxNode<R>, | 408 | pub struct Comment { |
589 | } | 409 | pub(crate) syntax: SyntaxNode, |
590 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; | ||
591 | |||
592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CommentNode<R1>> for CommentNode<R2> { | ||
593 | fn eq(&self, other: &CommentNode<R1>) -> bool { self.syntax == other.syntax } | ||
594 | } | 410 | } |
595 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} | 411 | unsafe impl TransparentNewType for Comment { |
596 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { | 412 | type Repr = rowan::SyntaxNode<RaTypes>; |
597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
598 | } | 413 | } |
599 | 414 | ||
600 | impl<'a> AstNode<'a> for Comment<'a> { | 415 | impl AstNode for Comment { |
601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 416 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
602 | match syntax.kind() { | 417 | match syntax.kind() { |
603 | COMMENT => Some(Comment { syntax }), | 418 | COMMENT => Some(Comment::from_repr(syntax.into_repr())), |
604 | _ => None, | 419 | _ => None, |
605 | } | 420 | } |
606 | } | 421 | } |
607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 422 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
608 | } | 423 | fn to_owned(&self) -> TreePtr<Comment> { TreePtr::cast(self.syntax.to_owned()) } |
609 | |||
610 | impl<R: TreeRoot<RaTypes>> CommentNode<R> { | ||
611 | pub fn borrowed(&self) -> Comment { | ||
612 | CommentNode { syntax: self.syntax.borrowed() } | ||
613 | } | ||
614 | pub fn owned(&self) -> CommentNode { | ||
615 | CommentNode { syntax: self.syntax.owned() } | ||
616 | } | ||
617 | } | 424 | } |
618 | 425 | ||
619 | 426 | ||
620 | impl<'a> Comment<'a> {} | 427 | impl ast::AstToken for Comment {} |
428 | impl Comment {} | ||
621 | 429 | ||
622 | // Condition | 430 | // Condition |
623 | #[derive(Debug, Clone, Copy,)] | 431 | #[derive(Debug, PartialEq, Eq, Hash)] |
624 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 432 | #[repr(transparent)] |
625 | pub(crate) syntax: SyntaxNode<R>, | 433 | pub struct Condition { |
434 | pub(crate) syntax: SyntaxNode, | ||
626 | } | 435 | } |
627 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | 436 | unsafe impl TransparentNewType for Condition { |
628 | 437 | type Repr = rowan::SyntaxNode<RaTypes>; | |
629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConditionNode<R1>> for ConditionNode<R2> { | ||
630 | fn eq(&self, other: &ConditionNode<R1>) -> bool { self.syntax == other.syntax } | ||
631 | } | ||
632 | impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {} | ||
633 | impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> { | ||
634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
635 | } | 438 | } |
636 | 439 | ||
637 | impl<'a> AstNode<'a> for Condition<'a> { | 440 | impl AstNode for Condition { |
638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 441 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
639 | match syntax.kind() { | 442 | match syntax.kind() { |
640 | CONDITION => Some(Condition { syntax }), | 443 | CONDITION => Some(Condition::from_repr(syntax.into_repr())), |
641 | _ => None, | 444 | _ => None, |
642 | } | 445 | } |
643 | } | 446 | } |
644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 447 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
645 | } | 448 | fn to_owned(&self) -> TreePtr<Condition> { TreePtr::cast(self.syntax.to_owned()) } |
646 | |||
647 | impl<R: TreeRoot<RaTypes>> ConditionNode<R> { | ||
648 | pub fn borrowed(&self) -> Condition { | ||
649 | ConditionNode { syntax: self.syntax.borrowed() } | ||
650 | } | ||
651 | pub fn owned(&self) -> ConditionNode { | ||
652 | ConditionNode { syntax: self.syntax.owned() } | ||
653 | } | ||
654 | } | 449 | } |
655 | 450 | ||
656 | 451 | ||
657 | impl<'a> Condition<'a> { | 452 | impl Condition { |
658 | pub fn pat(self) -> Option<Pat<'a>> { | 453 | pub fn pat(&self) -> Option<&Pat> { |
659 | super::child_opt(self) | 454 | super::child_opt(self) |
660 | } | 455 | } |
661 | 456 | ||
662 | pub fn expr(self) -> Option<Expr<'a>> { | 457 | pub fn expr(&self) -> Option<&Expr> { |
663 | super::child_opt(self) | 458 | super::child_opt(self) |
664 | } | 459 | } |
665 | } | 460 | } |
666 | 461 | ||
667 | // ConstDef | 462 | // ConstDef |
668 | #[derive(Debug, Clone, Copy,)] | 463 | #[derive(Debug, PartialEq, Eq, Hash)] |
669 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 464 | #[repr(transparent)] |
670 | pub(crate) syntax: SyntaxNode<R>, | 465 | pub struct ConstDef { |
466 | pub(crate) syntax: SyntaxNode, | ||
671 | } | 467 | } |
672 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | 468 | unsafe impl TransparentNewType for ConstDef { |
673 | 469 | type Repr = rowan::SyntaxNode<RaTypes>; | |
674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConstDefNode<R1>> for ConstDefNode<R2> { | ||
675 | fn eq(&self, other: &ConstDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
676 | } | ||
677 | impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {} | ||
678 | impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> { | ||
679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
680 | } | 470 | } |
681 | 471 | ||
682 | impl<'a> AstNode<'a> for ConstDef<'a> { | 472 | impl AstNode for ConstDef { |
683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 473 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
684 | match syntax.kind() { | 474 | match syntax.kind() { |
685 | CONST_DEF => Some(ConstDef { syntax }), | 475 | CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), |
686 | _ => None, | 476 | _ => None, |
687 | } | 477 | } |
688 | } | 478 | } |
689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 479 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
690 | } | 480 | fn to_owned(&self) -> TreePtr<ConstDef> { TreePtr::cast(self.syntax.to_owned()) } |
691 | |||
692 | impl<R: TreeRoot<RaTypes>> ConstDefNode<R> { | ||
693 | pub fn borrowed(&self) -> ConstDef { | ||
694 | ConstDefNode { syntax: self.syntax.borrowed() } | ||
695 | } | ||
696 | pub fn owned(&self) -> ConstDefNode { | ||
697 | ConstDefNode { syntax: self.syntax.owned() } | ||
698 | } | ||
699 | } | 481 | } |
700 | 482 | ||
701 | 483 | ||
702 | impl<'a> ast::VisibilityOwner<'a> for ConstDef<'a> {} | 484 | impl ast::VisibilityOwner for ConstDef {} |
703 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 485 | impl ast::NameOwner for ConstDef {} |
704 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 486 | impl ast::TypeParamsOwner for ConstDef {} |
705 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 487 | impl ast::AttrsOwner for ConstDef {} |
706 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | 488 | impl ast::DocCommentsOwner for ConstDef {} |
707 | impl<'a> ConstDef<'a> {} | 489 | impl ConstDef {} |
708 | 490 | ||
709 | // ContinueExpr | 491 | // ContinueExpr |
710 | #[derive(Debug, Clone, Copy,)] | 492 | #[derive(Debug, PartialEq, Eq, Hash)] |
711 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 493 | #[repr(transparent)] |
712 | pub(crate) syntax: SyntaxNode<R>, | 494 | pub struct ContinueExpr { |
495 | pub(crate) syntax: SyntaxNode, | ||
713 | } | 496 | } |
714 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | 497 | unsafe impl TransparentNewType for ContinueExpr { |
715 | 498 | type Repr = rowan::SyntaxNode<RaTypes>; | |
716 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ContinueExprNode<R1>> for ContinueExprNode<R2> { | ||
717 | fn eq(&self, other: &ContinueExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
718 | } | ||
719 | impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {} | ||
720 | impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> { | ||
721 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
722 | } | 499 | } |
723 | 500 | ||
724 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 501 | impl AstNode for ContinueExpr { |
725 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 502 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
726 | match syntax.kind() { | 503 | match syntax.kind() { |
727 | CONTINUE_EXPR => Some(ContinueExpr { syntax }), | 504 | CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), |
728 | _ => None, | 505 | _ => None, |
729 | } | 506 | } |
730 | } | 507 | } |
731 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 508 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
509 | fn to_owned(&self) -> TreePtr<ContinueExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
732 | } | 510 | } |
733 | 511 | ||
734 | impl<R: TreeRoot<RaTypes>> ContinueExprNode<R> { | ||
735 | pub fn borrowed(&self) -> ContinueExpr { | ||
736 | ContinueExprNode { syntax: self.syntax.borrowed() } | ||
737 | } | ||
738 | pub fn owned(&self) -> ContinueExprNode { | ||
739 | ContinueExprNode { syntax: self.syntax.owned() } | ||
740 | } | ||
741 | } | ||
742 | 512 | ||
743 | 513 | impl ContinueExpr {} | |
744 | impl<'a> ContinueExpr<'a> {} | ||
745 | 514 | ||
746 | // DynTraitType | 515 | // DynTraitType |
747 | #[derive(Debug, Clone, Copy,)] | 516 | #[derive(Debug, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 517 | #[repr(transparent)] |
749 | pub(crate) syntax: SyntaxNode<R>, | 518 | pub struct DynTraitType { |
750 | } | 519 | pub(crate) syntax: SyntaxNode, |
751 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; | ||
752 | |||
753 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<DynTraitTypeNode<R1>> for DynTraitTypeNode<R2> { | ||
754 | fn eq(&self, other: &DynTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
755 | } | 520 | } |
756 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} | 521 | unsafe impl TransparentNewType for DynTraitType { |
757 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { | 522 | type Repr = rowan::SyntaxNode<RaTypes>; |
758 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
759 | } | 523 | } |
760 | 524 | ||
761 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 525 | impl AstNode for DynTraitType { |
762 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 526 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
763 | match syntax.kind() { | 527 | match syntax.kind() { |
764 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), | 528 | DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), |
765 | _ => None, | 529 | _ => None, |
766 | } | 530 | } |
767 | } | 531 | } |
768 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 532 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
533 | fn to_owned(&self) -> TreePtr<DynTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
769 | } | 534 | } |
770 | 535 | ||
771 | impl<R: TreeRoot<RaTypes>> DynTraitTypeNode<R> { | ||
772 | pub fn borrowed(&self) -> DynTraitType { | ||
773 | DynTraitTypeNode { syntax: self.syntax.borrowed() } | ||
774 | } | ||
775 | pub fn owned(&self) -> DynTraitTypeNode { | ||
776 | DynTraitTypeNode { syntax: self.syntax.owned() } | ||
777 | } | ||
778 | } | ||
779 | 536 | ||
780 | 537 | impl DynTraitType {} | |
781 | impl<'a> DynTraitType<'a> {} | ||
782 | 538 | ||
783 | // EnumDef | 539 | // EnumDef |
784 | #[derive(Debug, Clone, Copy,)] | 540 | #[derive(Debug, PartialEq, Eq, Hash)] |
785 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 541 | #[repr(transparent)] |
786 | pub(crate) syntax: SyntaxNode<R>, | 542 | pub struct EnumDef { |
787 | } | 543 | pub(crate) syntax: SyntaxNode, |
788 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; | ||
789 | |||
790 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumDefNode<R1>> for EnumDefNode<R2> { | ||
791 | fn eq(&self, other: &EnumDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
792 | } | 544 | } |
793 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} | 545 | unsafe impl TransparentNewType for EnumDef { |
794 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { | 546 | type Repr = rowan::SyntaxNode<RaTypes>; |
795 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
796 | } | 547 | } |
797 | 548 | ||
798 | impl<'a> AstNode<'a> for EnumDef<'a> { | 549 | impl AstNode for EnumDef { |
799 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 550 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
800 | match syntax.kind() { | 551 | match syntax.kind() { |
801 | ENUM_DEF => Some(EnumDef { syntax }), | 552 | ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), |
802 | _ => None, | 553 | _ => None, |
803 | } | 554 | } |
804 | } | 555 | } |
805 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 556 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
806 | } | 557 | fn to_owned(&self) -> TreePtr<EnumDef> { TreePtr::cast(self.syntax.to_owned()) } |
807 | |||
808 | impl<R: TreeRoot<RaTypes>> EnumDefNode<R> { | ||
809 | pub fn borrowed(&self) -> EnumDef { | ||
810 | EnumDefNode { syntax: self.syntax.borrowed() } | ||
811 | } | ||
812 | pub fn owned(&self) -> EnumDefNode { | ||
813 | EnumDefNode { syntax: self.syntax.owned() } | ||
814 | } | ||
815 | } | 558 | } |
816 | 559 | ||
817 | 560 | ||
818 | impl<'a> ast::VisibilityOwner<'a> for EnumDef<'a> {} | 561 | impl ast::VisibilityOwner for EnumDef {} |
819 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 562 | impl ast::NameOwner for EnumDef {} |
820 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 563 | impl ast::TypeParamsOwner for EnumDef {} |
821 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 564 | impl ast::AttrsOwner for EnumDef {} |
822 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | 565 | impl ast::DocCommentsOwner for EnumDef {} |
823 | impl<'a> EnumDef<'a> { | 566 | impl EnumDef { |
824 | pub fn variant_list(self) -> Option<EnumVariantList<'a>> { | 567 | pub fn variant_list(&self) -> Option<&EnumVariantList> { |
825 | super::child_opt(self) | 568 | super::child_opt(self) |
826 | } | 569 | } |
827 | } | 570 | } |
828 | 571 | ||
829 | // EnumVariant | 572 | // EnumVariant |
830 | #[derive(Debug, Clone, Copy,)] | 573 | #[derive(Debug, PartialEq, Eq, Hash)] |
831 | pub struct EnumVariantNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 574 | #[repr(transparent)] |
832 | pub(crate) syntax: SyntaxNode<R>, | 575 | pub struct EnumVariant { |
576 | pub(crate) syntax: SyntaxNode, | ||
833 | } | 577 | } |
834 | pub type EnumVariant<'a> = EnumVariantNode<RefRoot<'a>>; | 578 | unsafe impl TransparentNewType for EnumVariant { |
835 | 579 | type Repr = rowan::SyntaxNode<RaTypes>; | |
836 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantNode<R1>> for EnumVariantNode<R2> { | ||
837 | fn eq(&self, other: &EnumVariantNode<R1>) -> bool { self.syntax == other.syntax } | ||
838 | } | ||
839 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantNode<R> {} | ||
840 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantNode<R> { | ||
841 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
842 | } | 580 | } |
843 | 581 | ||
844 | impl<'a> AstNode<'a> for EnumVariant<'a> { | 582 | impl AstNode for EnumVariant { |
845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 583 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
846 | match syntax.kind() { | 584 | match syntax.kind() { |
847 | ENUM_VARIANT => Some(EnumVariant { syntax }), | 585 | ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), |
848 | _ => None, | 586 | _ => None, |
849 | } | 587 | } |
850 | } | 588 | } |
851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 589 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
852 | } | 590 | fn to_owned(&self) -> TreePtr<EnumVariant> { TreePtr::cast(self.syntax.to_owned()) } |
853 | |||
854 | impl<R: TreeRoot<RaTypes>> EnumVariantNode<R> { | ||
855 | pub fn borrowed(&self) -> EnumVariant { | ||
856 | EnumVariantNode { syntax: self.syntax.borrowed() } | ||
857 | } | ||
858 | pub fn owned(&self) -> EnumVariantNode { | ||
859 | EnumVariantNode { syntax: self.syntax.owned() } | ||
860 | } | ||
861 | } | 591 | } |
862 | 592 | ||
863 | 593 | ||
864 | impl<'a> ast::NameOwner<'a> for EnumVariant<'a> {} | 594 | impl ast::NameOwner for EnumVariant {} |
865 | impl<'a> EnumVariant<'a> { | 595 | impl EnumVariant { |
866 | pub fn expr(self) -> Option<Expr<'a>> { | 596 | pub fn expr(&self) -> Option<&Expr> { |
867 | super::child_opt(self) | 597 | super::child_opt(self) |
868 | } | 598 | } |
869 | } | 599 | } |
870 | 600 | ||
871 | // EnumVariantList | 601 | // EnumVariantList |
872 | #[derive(Debug, Clone, Copy,)] | 602 | #[derive(Debug, PartialEq, Eq, Hash)] |
873 | pub struct EnumVariantListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 603 | #[repr(transparent)] |
874 | pub(crate) syntax: SyntaxNode<R>, | 604 | pub struct EnumVariantList { |
875 | } | 605 | pub(crate) syntax: SyntaxNode, |
876 | pub type EnumVariantList<'a> = EnumVariantListNode<RefRoot<'a>>; | ||
877 | |||
878 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantListNode<R1>> for EnumVariantListNode<R2> { | ||
879 | fn eq(&self, other: &EnumVariantListNode<R1>) -> bool { self.syntax == other.syntax } | ||
880 | } | 606 | } |
881 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantListNode<R> {} | 607 | unsafe impl TransparentNewType for EnumVariantList { |
882 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantListNode<R> { | 608 | type Repr = rowan::SyntaxNode<RaTypes>; |
883 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
884 | } | 609 | } |
885 | 610 | ||
886 | impl<'a> AstNode<'a> for EnumVariantList<'a> { | 611 | impl AstNode for EnumVariantList { |
887 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 612 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
888 | match syntax.kind() { | 613 | match syntax.kind() { |
889 | ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), | 614 | ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), |
890 | _ => None, | 615 | _ => None, |
891 | } | 616 | } |
892 | } | 617 | } |
893 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 618 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
619 | fn to_owned(&self) -> TreePtr<EnumVariantList> { TreePtr::cast(self.syntax.to_owned()) } | ||
894 | } | 620 | } |
895 | 621 | ||
896 | impl<R: TreeRoot<RaTypes>> EnumVariantListNode<R> { | ||
897 | pub fn borrowed(&self) -> EnumVariantList { | ||
898 | EnumVariantListNode { syntax: self.syntax.borrowed() } | ||
899 | } | ||
900 | pub fn owned(&self) -> EnumVariantListNode { | ||
901 | EnumVariantListNode { syntax: self.syntax.owned() } | ||
902 | } | ||
903 | } | ||
904 | 622 | ||
905 | 623 | impl EnumVariantList { | |
906 | impl<'a> EnumVariantList<'a> { | 624 | pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> { |
907 | pub fn variants(self) -> impl Iterator<Item = EnumVariant<'a>> + 'a { | ||
908 | super::children(self) | 625 | super::children(self) |
909 | } | 626 | } |
910 | } | 627 | } |
911 | 628 | ||
912 | // Expr | 629 | // Expr |
913 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 630 | #[derive(Debug, PartialEq, Eq, Hash)] |
914 | pub enum Expr<'a> { | 631 | #[repr(transparent)] |
915 | TupleExpr(TupleExpr<'a>), | 632 | pub struct Expr { |
916 | ArrayExpr(ArrayExpr<'a>), | 633 | pub(crate) syntax: SyntaxNode, |
917 | ParenExpr(ParenExpr<'a>), | 634 | } |
918 | PathExpr(PathExpr<'a>), | 635 | unsafe impl TransparentNewType for Expr { |
919 | LambdaExpr(LambdaExpr<'a>), | 636 | type Repr = rowan::SyntaxNode<RaTypes>; |
920 | IfExpr(IfExpr<'a>), | ||
921 | LoopExpr(LoopExpr<'a>), | ||
922 | ForExpr(ForExpr<'a>), | ||
923 | WhileExpr(WhileExpr<'a>), | ||
924 | ContinueExpr(ContinueExpr<'a>), | ||
925 | BreakExpr(BreakExpr<'a>), | ||
926 | Label(Label<'a>), | ||
927 | BlockExpr(BlockExpr<'a>), | ||
928 | ReturnExpr(ReturnExpr<'a>), | ||
929 | MatchExpr(MatchExpr<'a>), | ||
930 | StructLit(StructLit<'a>), | ||
931 | CallExpr(CallExpr<'a>), | ||
932 | IndexExpr(IndexExpr<'a>), | ||
933 | MethodCallExpr(MethodCallExpr<'a>), | ||
934 | FieldExpr(FieldExpr<'a>), | ||
935 | TryExpr(TryExpr<'a>), | ||
936 | CastExpr(CastExpr<'a>), | ||
937 | RefExpr(RefExpr<'a>), | ||
938 | PrefixExpr(PrefixExpr<'a>), | ||
939 | RangeExpr(RangeExpr<'a>), | ||
940 | BinExpr(BinExpr<'a>), | ||
941 | Literal(Literal<'a>), | ||
942 | } | ||
943 | |||
944 | impl<'a> AstNode<'a> for Expr<'a> { | ||
945 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
946 | match syntax.kind() { | ||
947 | TUPLE_EXPR => Some(Expr::TupleExpr(TupleExpr { syntax })), | ||
948 | ARRAY_EXPR => Some(Expr::ArrayExpr(ArrayExpr { syntax })), | ||
949 | PAREN_EXPR => Some(Expr::ParenExpr(ParenExpr { syntax })), | ||
950 | PATH_EXPR => Some(Expr::PathExpr(PathExpr { syntax })), | ||
951 | LAMBDA_EXPR => Some(Expr::LambdaExpr(LambdaExpr { syntax })), | ||
952 | IF_EXPR => Some(Expr::IfExpr(IfExpr { syntax })), | ||
953 | LOOP_EXPR => Some(Expr::LoopExpr(LoopExpr { syntax })), | ||
954 | FOR_EXPR => Some(Expr::ForExpr(ForExpr { syntax })), | ||
955 | WHILE_EXPR => Some(Expr::WhileExpr(WhileExpr { syntax })), | ||
956 | CONTINUE_EXPR => Some(Expr::ContinueExpr(ContinueExpr { syntax })), | ||
957 | BREAK_EXPR => Some(Expr::BreakExpr(BreakExpr { syntax })), | ||
958 | LABEL => Some(Expr::Label(Label { syntax })), | ||
959 | BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })), | ||
960 | RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })), | ||
961 | MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })), | ||
962 | STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })), | ||
963 | CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })), | ||
964 | INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })), | ||
965 | METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })), | ||
966 | FIELD_EXPR => Some(Expr::FieldExpr(FieldExpr { syntax })), | ||
967 | TRY_EXPR => Some(Expr::TryExpr(TryExpr { syntax })), | ||
968 | CAST_EXPR => Some(Expr::CastExpr(CastExpr { syntax })), | ||
969 | REF_EXPR => Some(Expr::RefExpr(RefExpr { syntax })), | ||
970 | PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })), | ||
971 | RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })), | ||
972 | BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })), | ||
973 | LITERAL => Some(Expr::Literal(Literal { syntax })), | ||
974 | _ => None, | ||
975 | } | ||
976 | } | ||
977 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
978 | match self { | ||
979 | Expr::TupleExpr(inner) => inner.syntax(), | ||
980 | Expr::ArrayExpr(inner) => inner.syntax(), | ||
981 | Expr::ParenExpr(inner) => inner.syntax(), | ||
982 | Expr::PathExpr(inner) => inner.syntax(), | ||
983 | Expr::LambdaExpr(inner) => inner.syntax(), | ||
984 | Expr::IfExpr(inner) => inner.syntax(), | ||
985 | Expr::LoopExpr(inner) => inner.syntax(), | ||
986 | Expr::ForExpr(inner) => inner.syntax(), | ||
987 | Expr::WhileExpr(inner) => inner.syntax(), | ||
988 | Expr::ContinueExpr(inner) => inner.syntax(), | ||
989 | Expr::BreakExpr(inner) => inner.syntax(), | ||
990 | Expr::Label(inner) => inner.syntax(), | ||
991 | Expr::BlockExpr(inner) => inner.syntax(), | ||
992 | Expr::ReturnExpr(inner) => inner.syntax(), | ||
993 | Expr::MatchExpr(inner) => inner.syntax(), | ||
994 | Expr::StructLit(inner) => inner.syntax(), | ||
995 | Expr::CallExpr(inner) => inner.syntax(), | ||
996 | Expr::IndexExpr(inner) => inner.syntax(), | ||
997 | Expr::MethodCallExpr(inner) => inner.syntax(), | ||
998 | Expr::FieldExpr(inner) => inner.syntax(), | ||
999 | Expr::TryExpr(inner) => inner.syntax(), | ||
1000 | Expr::CastExpr(inner) => inner.syntax(), | ||
1001 | Expr::RefExpr(inner) => inner.syntax(), | ||
1002 | Expr::PrefixExpr(inner) => inner.syntax(), | ||
1003 | Expr::RangeExpr(inner) => inner.syntax(), | ||
1004 | Expr::BinExpr(inner) => inner.syntax(), | ||
1005 | Expr::Literal(inner) => inner.syntax(), | ||
1006 | } | ||
1007 | } | ||
1008 | } | 637 | } |
1009 | 638 | ||
1010 | impl<'a> Expr<'a> {} | 639 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
640 | pub enum ExprKind<'a> { | ||
641 | TupleExpr(&'a TupleExpr), | ||
642 | ArrayExpr(&'a ArrayExpr), | ||
643 | ParenExpr(&'a ParenExpr), | ||
644 | PathExpr(&'a PathExpr), | ||
645 | LambdaExpr(&'a LambdaExpr), | ||
646 | IfExpr(&'a IfExpr), | ||
647 | LoopExpr(&'a LoopExpr), | ||
648 | ForExpr(&'a ForExpr), | ||
649 | WhileExpr(&'a WhileExpr), | ||
650 | ContinueExpr(&'a ContinueExpr), | ||
651 | BreakExpr(&'a BreakExpr), | ||
652 | Label(&'a Label), | ||
653 | BlockExpr(&'a BlockExpr), | ||
654 | ReturnExpr(&'a ReturnExpr), | ||
655 | MatchExpr(&'a MatchExpr), | ||
656 | StructLit(&'a StructLit), | ||
657 | CallExpr(&'a CallExpr), | ||
658 | IndexExpr(&'a IndexExpr), | ||
659 | MethodCallExpr(&'a MethodCallExpr), | ||
660 | FieldExpr(&'a FieldExpr), | ||
661 | TryExpr(&'a TryExpr), | ||
662 | CastExpr(&'a CastExpr), | ||
663 | RefExpr(&'a RefExpr), | ||
664 | PrefixExpr(&'a PrefixExpr), | ||
665 | RangeExpr(&'a RangeExpr), | ||
666 | BinExpr(&'a BinExpr), | ||
667 | Literal(&'a Literal), | ||
668 | } | ||
669 | |||
670 | impl AstNode for Expr { | ||
671 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
672 | match syntax.kind() { | ||
673 | | TUPLE_EXPR | ||
674 | | ARRAY_EXPR | ||
675 | | PAREN_EXPR | ||
676 | | PATH_EXPR | ||
677 | | LAMBDA_EXPR | ||
678 | | IF_EXPR | ||
679 | | LOOP_EXPR | ||
680 | | FOR_EXPR | ||
681 | | WHILE_EXPR | ||
682 | | CONTINUE_EXPR | ||
683 | | BREAK_EXPR | ||
684 | | LABEL | ||
685 | | BLOCK_EXPR | ||
686 | | RETURN_EXPR | ||
687 | | MATCH_EXPR | ||
688 | | STRUCT_LIT | ||
689 | | CALL_EXPR | ||
690 | | INDEX_EXPR | ||
691 | | METHOD_CALL_EXPR | ||
692 | | FIELD_EXPR | ||
693 | | TRY_EXPR | ||
694 | | CAST_EXPR | ||
695 | | REF_EXPR | ||
696 | | PREFIX_EXPR | ||
697 | | RANGE_EXPR | ||
698 | | BIN_EXPR | ||
699 | | LITERAL => Some(Expr::from_repr(syntax.into_repr())), | ||
700 | _ => None, | ||
701 | } | ||
702 | } | ||
703 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
704 | fn to_owned(&self) -> TreePtr<Expr> { TreePtr::cast(self.syntax.to_owned()) } | ||
705 | } | ||
706 | |||
707 | impl Expr { | ||
708 | pub fn kind(&self) -> ExprKind { | ||
709 | match self.syntax.kind() { | ||
710 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()), | ||
711 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()), | ||
712 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()), | ||
713 | PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()), | ||
714 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()), | ||
715 | IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
716 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()), | ||
717 | FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()), | ||
718 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()), | ||
719 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()), | ||
720 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()), | ||
721 | LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()), | ||
722 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()), | ||
723 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()), | ||
724 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()), | ||
725 | STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()), | ||
726 | CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()), | ||
727 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()), | ||
728 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), | ||
729 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), | ||
730 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), | ||
731 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), | ||
732 | REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), | ||
733 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), | ||
734 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), | ||
735 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), | ||
736 | LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), | ||
737 | _ => unreachable!(), | ||
738 | } | ||
739 | } | ||
740 | } | ||
741 | |||
742 | impl Expr {} | ||
1011 | 743 | ||
1012 | // ExprStmt | 744 | // ExprStmt |
1013 | #[derive(Debug, Clone, Copy,)] | 745 | #[derive(Debug, PartialEq, Eq, Hash)] |
1014 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 746 | #[repr(transparent)] |
1015 | pub(crate) syntax: SyntaxNode<R>, | 747 | pub struct ExprStmt { |
748 | pub(crate) syntax: SyntaxNode, | ||
1016 | } | 749 | } |
1017 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | 750 | unsafe impl TransparentNewType for ExprStmt { |
1018 | 751 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1019 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExprStmtNode<R1>> for ExprStmtNode<R2> { | ||
1020 | fn eq(&self, other: &ExprStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1021 | } | ||
1022 | impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {} | ||
1023 | impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> { | ||
1024 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1025 | } | 752 | } |
1026 | 753 | ||
1027 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 754 | impl AstNode for ExprStmt { |
1028 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 755 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1029 | match syntax.kind() { | 756 | match syntax.kind() { |
1030 | EXPR_STMT => Some(ExprStmt { syntax }), | 757 | EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())), |
1031 | _ => None, | 758 | _ => None, |
1032 | } | 759 | } |
1033 | } | 760 | } |
1034 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 761 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1035 | } | 762 | fn to_owned(&self) -> TreePtr<ExprStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1036 | |||
1037 | impl<R: TreeRoot<RaTypes>> ExprStmtNode<R> { | ||
1038 | pub fn borrowed(&self) -> ExprStmt { | ||
1039 | ExprStmtNode { syntax: self.syntax.borrowed() } | ||
1040 | } | ||
1041 | pub fn owned(&self) -> ExprStmtNode { | ||
1042 | ExprStmtNode { syntax: self.syntax.owned() } | ||
1043 | } | ||
1044 | } | 763 | } |
1045 | 764 | ||
1046 | 765 | ||
1047 | impl<'a> ExprStmt<'a> { | 766 | impl ExprStmt { |
1048 | pub fn expr(self) -> Option<Expr<'a>> { | 767 | pub fn expr(&self) -> Option<&Expr> { |
1049 | super::child_opt(self) | 768 | super::child_opt(self) |
1050 | } | 769 | } |
1051 | } | 770 | } |
1052 | 771 | ||
1053 | // ExternCrateItem | 772 | // ExternCrateItem |
1054 | #[derive(Debug, Clone, Copy,)] | 773 | #[derive(Debug, PartialEq, Eq, Hash)] |
1055 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 774 | #[repr(transparent)] |
1056 | pub(crate) syntax: SyntaxNode<R>, | 775 | pub struct ExternCrateItem { |
1057 | } | 776 | pub(crate) syntax: SyntaxNode, |
1058 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; | ||
1059 | |||
1060 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExternCrateItemNode<R1>> for ExternCrateItemNode<R2> { | ||
1061 | fn eq(&self, other: &ExternCrateItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
1062 | } | 777 | } |
1063 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} | 778 | unsafe impl TransparentNewType for ExternCrateItem { |
1064 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { | 779 | type Repr = rowan::SyntaxNode<RaTypes>; |
1065 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1066 | } | 780 | } |
1067 | 781 | ||
1068 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 782 | impl AstNode for ExternCrateItem { |
1069 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 783 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1070 | match syntax.kind() { | 784 | match syntax.kind() { |
1071 | EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), | 785 | EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())), |
1072 | _ => None, | 786 | _ => None, |
1073 | } | 787 | } |
1074 | } | 788 | } |
1075 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 789 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
790 | fn to_owned(&self) -> TreePtr<ExternCrateItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1076 | } | 791 | } |
1077 | 792 | ||
1078 | impl<R: TreeRoot<RaTypes>> ExternCrateItemNode<R> { | ||
1079 | pub fn borrowed(&self) -> ExternCrateItem { | ||
1080 | ExternCrateItemNode { syntax: self.syntax.borrowed() } | ||
1081 | } | ||
1082 | pub fn owned(&self) -> ExternCrateItemNode { | ||
1083 | ExternCrateItemNode { syntax: self.syntax.owned() } | ||
1084 | } | ||
1085 | } | ||
1086 | 793 | ||
1087 | 794 | impl ExternCrateItem {} | |
1088 | impl<'a> ExternCrateItem<'a> {} | ||
1089 | 795 | ||
1090 | // FieldExpr | 796 | // FieldExpr |
1091 | #[derive(Debug, Clone, Copy,)] | 797 | #[derive(Debug, PartialEq, Eq, Hash)] |
1092 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 798 | #[repr(transparent)] |
1093 | pub(crate) syntax: SyntaxNode<R>, | 799 | pub struct FieldExpr { |
1094 | } | 800 | pub(crate) syntax: SyntaxNode, |
1095 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; | ||
1096 | |||
1097 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldExprNode<R1>> for FieldExprNode<R2> { | ||
1098 | fn eq(&self, other: &FieldExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1099 | } | 801 | } |
1100 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} | 802 | unsafe impl TransparentNewType for FieldExpr { |
1101 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { | 803 | type Repr = rowan::SyntaxNode<RaTypes>; |
1102 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1103 | } | 804 | } |
1104 | 805 | ||
1105 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 806 | impl AstNode for FieldExpr { |
1106 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 807 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1107 | match syntax.kind() { | 808 | match syntax.kind() { |
1108 | FIELD_EXPR => Some(FieldExpr { syntax }), | 809 | FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())), |
1109 | _ => None, | 810 | _ => None, |
1110 | } | 811 | } |
1111 | } | 812 | } |
1112 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 813 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
814 | fn to_owned(&self) -> TreePtr<FieldExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
1113 | } | 815 | } |
1114 | 816 | ||
1115 | impl<R: TreeRoot<RaTypes>> FieldExprNode<R> { | ||
1116 | pub fn borrowed(&self) -> FieldExpr { | ||
1117 | FieldExprNode { syntax: self.syntax.borrowed() } | ||
1118 | } | ||
1119 | pub fn owned(&self) -> FieldExprNode { | ||
1120 | FieldExprNode { syntax: self.syntax.owned() } | ||
1121 | } | ||
1122 | } | ||
1123 | 817 | ||
1124 | 818 | impl FieldExpr { | |
1125 | impl<'a> FieldExpr<'a> { | 819 | pub fn expr(&self) -> Option<&Expr> { |
1126 | pub fn expr(self) -> Option<Expr<'a>> { | ||
1127 | super::child_opt(self) | 820 | super::child_opt(self) |
1128 | } | 821 | } |
1129 | 822 | ||
1130 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 823 | pub fn name_ref(&self) -> Option<&NameRef> { |
1131 | super::child_opt(self) | 824 | super::child_opt(self) |
1132 | } | 825 | } |
1133 | } | 826 | } |
1134 | 827 | ||
1135 | // FieldPatList | 828 | // FieldPatList |
1136 | #[derive(Debug, Clone, Copy,)] | 829 | #[derive(Debug, PartialEq, Eq, Hash)] |
1137 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 830 | #[repr(transparent)] |
1138 | pub(crate) syntax: SyntaxNode<R>, | 831 | pub struct FieldPatList { |
832 | pub(crate) syntax: SyntaxNode, | ||
1139 | } | 833 | } |
1140 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | 834 | unsafe impl TransparentNewType for FieldPatList { |
1141 | 835 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1142 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldPatListNode<R1>> for FieldPatListNode<R2> { | ||
1143 | fn eq(&self, other: &FieldPatListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1144 | } | ||
1145 | impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {} | ||
1146 | impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> { | ||
1147 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1148 | } | 836 | } |
1149 | 837 | ||
1150 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 838 | impl AstNode for FieldPatList { |
1151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 839 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1152 | match syntax.kind() { | 840 | match syntax.kind() { |
1153 | FIELD_PAT_LIST => Some(FieldPatList { syntax }), | 841 | FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())), |
1154 | _ => None, | 842 | _ => None, |
1155 | } | 843 | } |
1156 | } | 844 | } |
1157 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 845 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1158 | } | 846 | fn to_owned(&self) -> TreePtr<FieldPatList> { TreePtr::cast(self.syntax.to_owned()) } |
1159 | |||
1160 | impl<R: TreeRoot<RaTypes>> FieldPatListNode<R> { | ||
1161 | pub fn borrowed(&self) -> FieldPatList { | ||
1162 | FieldPatListNode { syntax: self.syntax.borrowed() } | ||
1163 | } | ||
1164 | pub fn owned(&self) -> FieldPatListNode { | ||
1165 | FieldPatListNode { syntax: self.syntax.owned() } | ||
1166 | } | ||
1167 | } | 847 | } |
1168 | 848 | ||
1169 | 849 | ||
1170 | impl<'a> FieldPatList<'a> {} | 850 | impl FieldPatList {} |
1171 | 851 | ||
1172 | // FnDef | 852 | // FnDef |
1173 | #[derive(Debug, Clone, Copy,)] | 853 | #[derive(Debug, PartialEq, Eq, Hash)] |
1174 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 854 | #[repr(transparent)] |
1175 | pub(crate) syntax: SyntaxNode<R>, | 855 | pub struct FnDef { |
856 | pub(crate) syntax: SyntaxNode, | ||
1176 | } | 857 | } |
1177 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | 858 | unsafe impl TransparentNewType for FnDef { |
1178 | 859 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1179 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnDefNode<R1>> for FnDefNode<R2> { | ||
1180 | fn eq(&self, other: &FnDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
1181 | } | ||
1182 | impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {} | ||
1183 | impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> { | ||
1184 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1185 | } | 860 | } |
1186 | 861 | ||
1187 | impl<'a> AstNode<'a> for FnDef<'a> { | 862 | impl AstNode for FnDef { |
1188 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 863 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1189 | match syntax.kind() { | 864 | match syntax.kind() { |
1190 | FN_DEF => Some(FnDef { syntax }), | 865 | FN_DEF => Some(FnDef::from_repr(syntax.into_repr())), |
1191 | _ => None, | 866 | _ => None, |
1192 | } | 867 | } |
1193 | } | 868 | } |
1194 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 869 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1195 | } | 870 | fn to_owned(&self) -> TreePtr<FnDef> { TreePtr::cast(self.syntax.to_owned()) } |
1196 | |||
1197 | impl<R: TreeRoot<RaTypes>> FnDefNode<R> { | ||
1198 | pub fn borrowed(&self) -> FnDef { | ||
1199 | FnDefNode { syntax: self.syntax.borrowed() } | ||
1200 | } | ||
1201 | pub fn owned(&self) -> FnDefNode { | ||
1202 | FnDefNode { syntax: self.syntax.owned() } | ||
1203 | } | ||
1204 | } | 871 | } |
1205 | 872 | ||
1206 | 873 | ||
1207 | impl<'a> ast::VisibilityOwner<'a> for FnDef<'a> {} | 874 | impl ast::VisibilityOwner for FnDef {} |
1208 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 875 | impl ast::NameOwner for FnDef {} |
1209 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 876 | impl ast::TypeParamsOwner for FnDef {} |
1210 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 877 | impl ast::AttrsOwner for FnDef {} |
1211 | impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {} | 878 | impl ast::DocCommentsOwner for FnDef {} |
1212 | impl<'a> FnDef<'a> { | 879 | impl FnDef { |
1213 | pub fn param_list(self) -> Option<ParamList<'a>> { | 880 | pub fn param_list(&self) -> Option<&ParamList> { |
1214 | super::child_opt(self) | 881 | super::child_opt(self) |
1215 | } | 882 | } |
1216 | 883 | ||
1217 | pub fn body(self) -> Option<Block<'a>> { | 884 | pub fn body(&self) -> Option<&Block> { |
1218 | super::child_opt(self) | 885 | super::child_opt(self) |
1219 | } | 886 | } |
1220 | 887 | ||
1221 | pub fn ret_type(self) -> Option<RetType<'a>> { | 888 | pub fn ret_type(&self) -> Option<&RetType> { |
1222 | super::child_opt(self) | 889 | super::child_opt(self) |
1223 | } | 890 | } |
1224 | } | 891 | } |
1225 | 892 | ||
1226 | // FnPointerType | 893 | // FnPointerType |
1227 | #[derive(Debug, Clone, Copy,)] | 894 | #[derive(Debug, PartialEq, Eq, Hash)] |
1228 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 895 | #[repr(transparent)] |
1229 | pub(crate) syntax: SyntaxNode<R>, | 896 | pub struct FnPointerType { |
1230 | } | 897 | pub(crate) syntax: SyntaxNode, |
1231 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; | ||
1232 | |||
1233 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnPointerTypeNode<R1>> for FnPointerTypeNode<R2> { | ||
1234 | fn eq(&self, other: &FnPointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1235 | } | 898 | } |
1236 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} | 899 | unsafe impl TransparentNewType for FnPointerType { |
1237 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { | 900 | type Repr = rowan::SyntaxNode<RaTypes>; |
1238 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1239 | } | 901 | } |
1240 | 902 | ||
1241 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 903 | impl AstNode for FnPointerType { |
1242 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 904 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1243 | match syntax.kind() { | 905 | match syntax.kind() { |
1244 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), | 906 | FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())), |
1245 | _ => None, | 907 | _ => None, |
1246 | } | 908 | } |
1247 | } | 909 | } |
1248 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 910 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
911 | fn to_owned(&self) -> TreePtr<FnPointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1249 | } | 912 | } |
1250 | 913 | ||
1251 | impl<R: TreeRoot<RaTypes>> FnPointerTypeNode<R> { | ||
1252 | pub fn borrowed(&self) -> FnPointerType { | ||
1253 | FnPointerTypeNode { syntax: self.syntax.borrowed() } | ||
1254 | } | ||
1255 | pub fn owned(&self) -> FnPointerTypeNode { | ||
1256 | FnPointerTypeNode { syntax: self.syntax.owned() } | ||
1257 | } | ||
1258 | } | ||
1259 | 914 | ||
1260 | 915 | impl FnPointerType { | |
1261 | impl<'a> FnPointerType<'a> { | 916 | pub fn param_list(&self) -> Option<&ParamList> { |
1262 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
1263 | super::child_opt(self) | 917 | super::child_opt(self) |
1264 | } | 918 | } |
1265 | 919 | ||
1266 | pub fn ret_type(self) -> Option<RetType<'a>> { | 920 | pub fn ret_type(&self) -> Option<&RetType> { |
1267 | super::child_opt(self) | 921 | super::child_opt(self) |
1268 | } | 922 | } |
1269 | } | 923 | } |
1270 | 924 | ||
1271 | // ForExpr | 925 | // ForExpr |
1272 | #[derive(Debug, Clone, Copy,)] | 926 | #[derive(Debug, PartialEq, Eq, Hash)] |
1273 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 927 | #[repr(transparent)] |
1274 | pub(crate) syntax: SyntaxNode<R>, | 928 | pub struct ForExpr { |
1275 | } | 929 | pub(crate) syntax: SyntaxNode, |
1276 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; | ||
1277 | |||
1278 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForExprNode<R1>> for ForExprNode<R2> { | ||
1279 | fn eq(&self, other: &ForExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1280 | } | 930 | } |
1281 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} | 931 | unsafe impl TransparentNewType for ForExpr { |
1282 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { | 932 | type Repr = rowan::SyntaxNode<RaTypes>; |
1283 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1284 | } | 933 | } |
1285 | 934 | ||
1286 | impl<'a> AstNode<'a> for ForExpr<'a> { | 935 | impl AstNode for ForExpr { |
1287 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 936 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1288 | match syntax.kind() { | 937 | match syntax.kind() { |
1289 | FOR_EXPR => Some(ForExpr { syntax }), | 938 | FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())), |
1290 | _ => None, | 939 | _ => None, |
1291 | } | 940 | } |
1292 | } | 941 | } |
1293 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 942 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1294 | } | 943 | fn to_owned(&self) -> TreePtr<ForExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1295 | |||
1296 | impl<R: TreeRoot<RaTypes>> ForExprNode<R> { | ||
1297 | pub fn borrowed(&self) -> ForExpr { | ||
1298 | ForExprNode { syntax: self.syntax.borrowed() } | ||
1299 | } | ||
1300 | pub fn owned(&self) -> ForExprNode { | ||
1301 | ForExprNode { syntax: self.syntax.owned() } | ||
1302 | } | ||
1303 | } | 944 | } |
1304 | 945 | ||
1305 | 946 | ||
1306 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 947 | impl ast::LoopBodyOwner for ForExpr {} |
1307 | impl<'a> ForExpr<'a> { | 948 | impl ForExpr { |
1308 | pub fn pat(self) -> Option<Pat<'a>> { | 949 | pub fn pat(&self) -> Option<&Pat> { |
1309 | super::child_opt(self) | 950 | super::child_opt(self) |
1310 | } | 951 | } |
1311 | 952 | ||
1312 | pub fn iterable(self) -> Option<Expr<'a>> { | 953 | pub fn iterable(&self) -> Option<&Expr> { |
1313 | super::child_opt(self) | 954 | super::child_opt(self) |
1314 | } | 955 | } |
1315 | } | 956 | } |
1316 | 957 | ||
1317 | // ForType | 958 | // ForType |
1318 | #[derive(Debug, Clone, Copy,)] | 959 | #[derive(Debug, PartialEq, Eq, Hash)] |
1319 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 960 | #[repr(transparent)] |
1320 | pub(crate) syntax: SyntaxNode<R>, | 961 | pub struct ForType { |
1321 | } | 962 | pub(crate) syntax: SyntaxNode, |
1322 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; | ||
1323 | |||
1324 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForTypeNode<R1>> for ForTypeNode<R2> { | ||
1325 | fn eq(&self, other: &ForTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1326 | } | 963 | } |
1327 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} | 964 | unsafe impl TransparentNewType for ForType { |
1328 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { | 965 | type Repr = rowan::SyntaxNode<RaTypes>; |
1329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1330 | } | 966 | } |
1331 | 967 | ||
1332 | impl<'a> AstNode<'a> for ForType<'a> { | 968 | impl AstNode for ForType { |
1333 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 969 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1334 | match syntax.kind() { | 970 | match syntax.kind() { |
1335 | FOR_TYPE => Some(ForType { syntax }), | 971 | FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())), |
1336 | _ => None, | 972 | _ => None, |
1337 | } | 973 | } |
1338 | } | 974 | } |
1339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 975 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1340 | } | 976 | fn to_owned(&self) -> TreePtr<ForType> { TreePtr::cast(self.syntax.to_owned()) } |
1341 | |||
1342 | impl<R: TreeRoot<RaTypes>> ForTypeNode<R> { | ||
1343 | pub fn borrowed(&self) -> ForType { | ||
1344 | ForTypeNode { syntax: self.syntax.borrowed() } | ||
1345 | } | ||
1346 | pub fn owned(&self) -> ForTypeNode { | ||
1347 | ForTypeNode { syntax: self.syntax.owned() } | ||
1348 | } | ||
1349 | } | 977 | } |
1350 | 978 | ||
1351 | 979 | ||
1352 | impl<'a> ForType<'a> { | 980 | impl ForType { |
1353 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 981 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1354 | super::child_opt(self) | 982 | super::child_opt(self) |
1355 | } | 983 | } |
1356 | } | 984 | } |
1357 | 985 | ||
1358 | // IfExpr | 986 | // IfExpr |
1359 | #[derive(Debug, Clone, Copy,)] | 987 | #[derive(Debug, PartialEq, Eq, Hash)] |
1360 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 988 | #[repr(transparent)] |
1361 | pub(crate) syntax: SyntaxNode<R>, | 989 | pub struct IfExpr { |
990 | pub(crate) syntax: SyntaxNode, | ||
1362 | } | 991 | } |
1363 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | 992 | unsafe impl TransparentNewType for IfExpr { |
1364 | 993 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1365 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IfExprNode<R1>> for IfExprNode<R2> { | ||
1366 | fn eq(&self, other: &IfExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1367 | } | ||
1368 | impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {} | ||
1369 | impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> { | ||
1370 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1371 | } | 994 | } |
1372 | 995 | ||
1373 | impl<'a> AstNode<'a> for IfExpr<'a> { | 996 | impl AstNode for IfExpr { |
1374 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 997 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1375 | match syntax.kind() { | 998 | match syntax.kind() { |
1376 | IF_EXPR => Some(IfExpr { syntax }), | 999 | IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())), |
1377 | _ => None, | 1000 | _ => None, |
1378 | } | 1001 | } |
1379 | } | 1002 | } |
1380 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1003 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1381 | } | 1004 | fn to_owned(&self) -> TreePtr<IfExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1382 | |||
1383 | impl<R: TreeRoot<RaTypes>> IfExprNode<R> { | ||
1384 | pub fn borrowed(&self) -> IfExpr { | ||
1385 | IfExprNode { syntax: self.syntax.borrowed() } | ||
1386 | } | ||
1387 | pub fn owned(&self) -> IfExprNode { | ||
1388 | IfExprNode { syntax: self.syntax.owned() } | ||
1389 | } | ||
1390 | } | 1005 | } |
1391 | 1006 | ||
1392 | 1007 | ||
1393 | impl<'a> IfExpr<'a> { | 1008 | impl IfExpr { |
1394 | pub fn condition(self) -> Option<Condition<'a>> { | 1009 | pub fn condition(&self) -> Option<&Condition> { |
1395 | super::child_opt(self) | 1010 | super::child_opt(self) |
1396 | } | 1011 | } |
1397 | } | 1012 | } |
1398 | 1013 | ||
1399 | // ImplBlock | 1014 | // ImplBlock |
1400 | #[derive(Debug, Clone, Copy,)] | 1015 | #[derive(Debug, PartialEq, Eq, Hash)] |
1401 | pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1016 | #[repr(transparent)] |
1402 | pub(crate) syntax: SyntaxNode<R>, | 1017 | pub struct ImplBlock { |
1018 | pub(crate) syntax: SyntaxNode, | ||
1403 | } | 1019 | } |
1404 | pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>; | 1020 | unsafe impl TransparentNewType for ImplBlock { |
1405 | 1021 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1406 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplBlockNode<R1>> for ImplBlockNode<R2> { | ||
1407 | fn eq(&self, other: &ImplBlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
1408 | } | ||
1409 | impl<R: TreeRoot<RaTypes>> Eq for ImplBlockNode<R> {} | ||
1410 | impl<R: TreeRoot<RaTypes>> Hash for ImplBlockNode<R> { | ||
1411 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1412 | } | 1022 | } |
1413 | 1023 | ||
1414 | impl<'a> AstNode<'a> for ImplBlock<'a> { | 1024 | impl AstNode for ImplBlock { |
1415 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1025 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1416 | match syntax.kind() { | 1026 | match syntax.kind() { |
1417 | IMPL_BLOCK => Some(ImplBlock { syntax }), | 1027 | IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())), |
1418 | _ => None, | 1028 | _ => None, |
1419 | } | 1029 | } |
1420 | } | 1030 | } |
1421 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1031 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1422 | } | 1032 | fn to_owned(&self) -> TreePtr<ImplBlock> { TreePtr::cast(self.syntax.to_owned()) } |
1423 | |||
1424 | impl<R: TreeRoot<RaTypes>> ImplBlockNode<R> { | ||
1425 | pub fn borrowed(&self) -> ImplBlock { | ||
1426 | ImplBlockNode { syntax: self.syntax.borrowed() } | ||
1427 | } | ||
1428 | pub fn owned(&self) -> ImplBlockNode { | ||
1429 | ImplBlockNode { syntax: self.syntax.owned() } | ||
1430 | } | ||
1431 | } | 1033 | } |
1432 | 1034 | ||
1433 | 1035 | ||
1434 | impl<'a> ImplBlock<'a> { | 1036 | impl ImplBlock { |
1435 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1037 | pub fn item_list(&self) -> Option<&ItemList> { |
1436 | super::child_opt(self) | 1038 | super::child_opt(self) |
1437 | } | 1039 | } |
1438 | } | 1040 | } |
1439 | 1041 | ||
1440 | // ImplItem | 1042 | // ImplItem |
1043 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1044 | #[repr(transparent)] | ||
1045 | pub struct ImplItem { | ||
1046 | pub(crate) syntax: SyntaxNode, | ||
1047 | } | ||
1048 | unsafe impl TransparentNewType for ImplItem { | ||
1049 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1050 | } | ||
1051 | |||
1441 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1052 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1442 | pub enum ImplItem<'a> { | 1053 | pub enum ImplItemKind<'a> { |
1443 | FnDef(FnDef<'a>), | 1054 | FnDef(&'a FnDef), |
1444 | TypeDef(TypeDef<'a>), | 1055 | TypeDef(&'a TypeDef), |
1445 | ConstDef(ConstDef<'a>), | 1056 | ConstDef(&'a ConstDef), |
1446 | } | 1057 | } |
1447 | 1058 | ||
1448 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1059 | impl AstNode for ImplItem { |
1449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1060 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1450 | match syntax.kind() { | 1061 | match syntax.kind() { |
1451 | FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })), | 1062 | | FN_DEF |
1452 | TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })), | 1063 | | TYPE_DEF |
1453 | CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })), | 1064 | | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())), |
1454 | _ => None, | 1065 | _ => None, |
1455 | } | 1066 | } |
1456 | } | 1067 | } |
1457 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1068 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1458 | match self { | 1069 | fn to_owned(&self) -> TreePtr<ImplItem> { TreePtr::cast(self.syntax.to_owned()) } |
1459 | ImplItem::FnDef(inner) => inner.syntax(), | 1070 | } |
1460 | ImplItem::TypeDef(inner) => inner.syntax(), | 1071 | |
1461 | ImplItem::ConstDef(inner) => inner.syntax(), | 1072 | impl ImplItem { |
1073 | pub fn kind(&self) -> ImplItemKind { | ||
1074 | match self.syntax.kind() { | ||
1075 | FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1076 | TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1077 | CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1078 | _ => unreachable!(), | ||
1462 | } | 1079 | } |
1463 | } | 1080 | } |
1464 | } | 1081 | } |
1465 | 1082 | ||
1466 | impl<'a> ImplItem<'a> {} | 1083 | impl ImplItem {} |
1467 | 1084 | ||
1468 | // ImplTraitType | 1085 | // ImplTraitType |
1469 | #[derive(Debug, Clone, Copy,)] | 1086 | #[derive(Debug, PartialEq, Eq, Hash)] |
1470 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1087 | #[repr(transparent)] |
1471 | pub(crate) syntax: SyntaxNode<R>, | 1088 | pub struct ImplTraitType { |
1472 | } | 1089 | pub(crate) syntax: SyntaxNode, |
1473 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; | ||
1474 | |||
1475 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplTraitTypeNode<R1>> for ImplTraitTypeNode<R2> { | ||
1476 | fn eq(&self, other: &ImplTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1477 | } | 1090 | } |
1478 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} | 1091 | unsafe impl TransparentNewType for ImplTraitType { |
1479 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { | 1092 | type Repr = rowan::SyntaxNode<RaTypes>; |
1480 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1481 | } | 1093 | } |
1482 | 1094 | ||
1483 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1095 | impl AstNode for ImplTraitType { |
1484 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1096 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1485 | match syntax.kind() { | 1097 | match syntax.kind() { |
1486 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), | 1098 | IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())), |
1487 | _ => None, | 1099 | _ => None, |
1488 | } | 1100 | } |
1489 | } | 1101 | } |
1490 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1102 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1103 | fn to_owned(&self) -> TreePtr<ImplTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1491 | } | 1104 | } |
1492 | 1105 | ||
1493 | impl<R: TreeRoot<RaTypes>> ImplTraitTypeNode<R> { | ||
1494 | pub fn borrowed(&self) -> ImplTraitType { | ||
1495 | ImplTraitTypeNode { syntax: self.syntax.borrowed() } | ||
1496 | } | ||
1497 | pub fn owned(&self) -> ImplTraitTypeNode { | ||
1498 | ImplTraitTypeNode { syntax: self.syntax.owned() } | ||
1499 | } | ||
1500 | } | ||
1501 | 1106 | ||
1502 | 1107 | impl ImplTraitType {} | |
1503 | impl<'a> ImplTraitType<'a> {} | ||
1504 | 1108 | ||
1505 | // IndexExpr | 1109 | // IndexExpr |
1506 | #[derive(Debug, Clone, Copy,)] | 1110 | #[derive(Debug, PartialEq, Eq, Hash)] |
1507 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1111 | #[repr(transparent)] |
1508 | pub(crate) syntax: SyntaxNode<R>, | 1112 | pub struct IndexExpr { |
1113 | pub(crate) syntax: SyntaxNode, | ||
1509 | } | 1114 | } |
1510 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | 1115 | unsafe impl TransparentNewType for IndexExpr { |
1511 | 1116 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1512 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IndexExprNode<R1>> for IndexExprNode<R2> { | ||
1513 | fn eq(&self, other: &IndexExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1514 | } | ||
1515 | impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {} | ||
1516 | impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> { | ||
1517 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1518 | } | 1117 | } |
1519 | 1118 | ||
1520 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1119 | impl AstNode for IndexExpr { |
1521 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1120 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1522 | match syntax.kind() { | 1121 | match syntax.kind() { |
1523 | INDEX_EXPR => Some(IndexExpr { syntax }), | 1122 | INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())), |
1524 | _ => None, | 1123 | _ => None, |
1525 | } | 1124 | } |
1526 | } | 1125 | } |
1527 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1126 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1528 | } | 1127 | fn to_owned(&self) -> TreePtr<IndexExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1529 | |||
1530 | impl<R: TreeRoot<RaTypes>> IndexExprNode<R> { | ||
1531 | pub fn borrowed(&self) -> IndexExpr { | ||
1532 | IndexExprNode { syntax: self.syntax.borrowed() } | ||
1533 | } | ||
1534 | pub fn owned(&self) -> IndexExprNode { | ||
1535 | IndexExprNode { syntax: self.syntax.owned() } | ||
1536 | } | ||
1537 | } | 1128 | } |
1538 | 1129 | ||
1539 | 1130 | ||
1540 | impl<'a> IndexExpr<'a> {} | 1131 | impl IndexExpr {} |
1541 | 1132 | ||
1542 | // ItemList | 1133 | // ItemList |
1543 | #[derive(Debug, Clone, Copy,)] | 1134 | #[derive(Debug, PartialEq, Eq, Hash)] |
1544 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1135 | #[repr(transparent)] |
1545 | pub(crate) syntax: SyntaxNode<R>, | 1136 | pub struct ItemList { |
1137 | pub(crate) syntax: SyntaxNode, | ||
1546 | } | 1138 | } |
1547 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | 1139 | unsafe impl TransparentNewType for ItemList { |
1548 | 1140 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1549 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ItemListNode<R1>> for ItemListNode<R2> { | ||
1550 | fn eq(&self, other: &ItemListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1551 | } | ||
1552 | impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {} | ||
1553 | impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> { | ||
1554 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1555 | } | 1141 | } |
1556 | 1142 | ||
1557 | impl<'a> AstNode<'a> for ItemList<'a> { | 1143 | impl AstNode for ItemList { |
1558 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1144 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1559 | match syntax.kind() { | 1145 | match syntax.kind() { |
1560 | ITEM_LIST => Some(ItemList { syntax }), | 1146 | ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())), |
1561 | _ => None, | 1147 | _ => None, |
1562 | } | 1148 | } |
1563 | } | 1149 | } |
1564 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1150 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1565 | } | 1151 | fn to_owned(&self) -> TreePtr<ItemList> { TreePtr::cast(self.syntax.to_owned()) } |
1566 | |||
1567 | impl<R: TreeRoot<RaTypes>> ItemListNode<R> { | ||
1568 | pub fn borrowed(&self) -> ItemList { | ||
1569 | ItemListNode { syntax: self.syntax.borrowed() } | ||
1570 | } | ||
1571 | pub fn owned(&self) -> ItemListNode { | ||
1572 | ItemListNode { syntax: self.syntax.owned() } | ||
1573 | } | ||
1574 | } | 1152 | } |
1575 | 1153 | ||
1576 | 1154 | ||
1577 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 1155 | impl ast::FnDefOwner for ItemList {} |
1578 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | 1156 | impl ast::ModuleItemOwner for ItemList {} |
1579 | impl<'a> ItemList<'a> { | 1157 | impl ItemList { |
1580 | pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a { | 1158 | pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> { |
1581 | super::children(self) | 1159 | super::children(self) |
1582 | } | 1160 | } |
1583 | } | 1161 | } |
1584 | 1162 | ||
1585 | // Label | 1163 | // Label |
1586 | #[derive(Debug, Clone, Copy,)] | 1164 | #[derive(Debug, PartialEq, Eq, Hash)] |
1587 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1165 | #[repr(transparent)] |
1588 | pub(crate) syntax: SyntaxNode<R>, | 1166 | pub struct Label { |
1167 | pub(crate) syntax: SyntaxNode, | ||
1589 | } | 1168 | } |
1590 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | 1169 | unsafe impl TransparentNewType for Label { |
1591 | 1170 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LabelNode<R1>> for LabelNode<R2> { | ||
1593 | fn eq(&self, other: &LabelNode<R1>) -> bool { self.syntax == other.syntax } | ||
1594 | } | ||
1595 | impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {} | ||
1596 | impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> { | ||
1597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1598 | } | 1171 | } |
1599 | 1172 | ||
1600 | impl<'a> AstNode<'a> for Label<'a> { | 1173 | impl AstNode for Label { |
1601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1174 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1602 | match syntax.kind() { | 1175 | match syntax.kind() { |
1603 | LABEL => Some(Label { syntax }), | 1176 | LABEL => Some(Label::from_repr(syntax.into_repr())), |
1604 | _ => None, | 1177 | _ => None, |
1605 | } | 1178 | } |
1606 | } | 1179 | } |
1607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1180 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1608 | } | 1181 | fn to_owned(&self) -> TreePtr<Label> { TreePtr::cast(self.syntax.to_owned()) } |
1609 | |||
1610 | impl<R: TreeRoot<RaTypes>> LabelNode<R> { | ||
1611 | pub fn borrowed(&self) -> Label { | ||
1612 | LabelNode { syntax: self.syntax.borrowed() } | ||
1613 | } | ||
1614 | pub fn owned(&self) -> LabelNode { | ||
1615 | LabelNode { syntax: self.syntax.owned() } | ||
1616 | } | ||
1617 | } | 1182 | } |
1618 | 1183 | ||
1619 | 1184 | ||
1620 | impl<'a> Label<'a> {} | 1185 | impl Label {} |
1621 | 1186 | ||
1622 | // LambdaExpr | 1187 | // LambdaExpr |
1623 | #[derive(Debug, Clone, Copy,)] | 1188 | #[derive(Debug, PartialEq, Eq, Hash)] |
1624 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1189 | #[repr(transparent)] |
1625 | pub(crate) syntax: SyntaxNode<R>, | 1190 | pub struct LambdaExpr { |
1626 | } | 1191 | pub(crate) syntax: SyntaxNode, |
1627 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; | ||
1628 | |||
1629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LambdaExprNode<R1>> for LambdaExprNode<R2> { | ||
1630 | fn eq(&self, other: &LambdaExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1631 | } | 1192 | } |
1632 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} | 1193 | unsafe impl TransparentNewType for LambdaExpr { |
1633 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { | 1194 | type Repr = rowan::SyntaxNode<RaTypes>; |
1634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1635 | } | 1195 | } |
1636 | 1196 | ||
1637 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1197 | impl AstNode for LambdaExpr { |
1638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1198 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1639 | match syntax.kind() { | 1199 | match syntax.kind() { |
1640 | LAMBDA_EXPR => Some(LambdaExpr { syntax }), | 1200 | LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())), |
1641 | _ => None, | 1201 | _ => None, |
1642 | } | 1202 | } |
1643 | } | 1203 | } |
1644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1204 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1645 | } | 1205 | fn to_owned(&self) -> TreePtr<LambdaExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1646 | |||
1647 | impl<R: TreeRoot<RaTypes>> LambdaExprNode<R> { | ||
1648 | pub fn borrowed(&self) -> LambdaExpr { | ||
1649 | LambdaExprNode { syntax: self.syntax.borrowed() } | ||
1650 | } | ||
1651 | pub fn owned(&self) -> LambdaExprNode { | ||
1652 | LambdaExprNode { syntax: self.syntax.owned() } | ||
1653 | } | ||
1654 | } | 1206 | } |
1655 | 1207 | ||
1656 | 1208 | ||
1657 | impl<'a> LambdaExpr<'a> { | 1209 | impl LambdaExpr { |
1658 | pub fn param_list(self) -> Option<ParamList<'a>> { | 1210 | pub fn param_list(&self) -> Option<&ParamList> { |
1659 | super::child_opt(self) | 1211 | super::child_opt(self) |
1660 | } | 1212 | } |
1661 | 1213 | ||
1662 | pub fn body(self) -> Option<Expr<'a>> { | 1214 | pub fn body(&self) -> Option<&Expr> { |
1663 | super::child_opt(self) | 1215 | super::child_opt(self) |
1664 | } | 1216 | } |
1665 | } | 1217 | } |
1666 | 1218 | ||
1667 | // LetStmt | 1219 | // LetStmt |
1668 | #[derive(Debug, Clone, Copy,)] | 1220 | #[derive(Debug, PartialEq, Eq, Hash)] |
1669 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1221 | #[repr(transparent)] |
1670 | pub(crate) syntax: SyntaxNode<R>, | 1222 | pub struct LetStmt { |
1671 | } | 1223 | pub(crate) syntax: SyntaxNode, |
1672 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; | ||
1673 | |||
1674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LetStmtNode<R1>> for LetStmtNode<R2> { | ||
1675 | fn eq(&self, other: &LetStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1676 | } | 1224 | } |
1677 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} | 1225 | unsafe impl TransparentNewType for LetStmt { |
1678 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { | 1226 | type Repr = rowan::SyntaxNode<RaTypes>; |
1679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1680 | } | 1227 | } |
1681 | 1228 | ||
1682 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1229 | impl AstNode for LetStmt { |
1683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1230 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1684 | match syntax.kind() { | 1231 | match syntax.kind() { |
1685 | LET_STMT => Some(LetStmt { syntax }), | 1232 | LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())), |
1686 | _ => None, | 1233 | _ => None, |
1687 | } | 1234 | } |
1688 | } | 1235 | } |
1689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1236 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1690 | } | 1237 | fn to_owned(&self) -> TreePtr<LetStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1691 | |||
1692 | impl<R: TreeRoot<RaTypes>> LetStmtNode<R> { | ||
1693 | pub fn borrowed(&self) -> LetStmt { | ||
1694 | LetStmtNode { syntax: self.syntax.borrowed() } | ||
1695 | } | ||
1696 | pub fn owned(&self) -> LetStmtNode { | ||
1697 | LetStmtNode { syntax: self.syntax.owned() } | ||
1698 | } | ||
1699 | } | 1238 | } |
1700 | 1239 | ||
1701 | 1240 | ||
1702 | impl<'a> LetStmt<'a> { | 1241 | impl LetStmt { |
1703 | pub fn pat(self) -> Option<Pat<'a>> { | 1242 | pub fn pat(&self) -> Option<&Pat> { |
1704 | super::child_opt(self) | 1243 | super::child_opt(self) |
1705 | } | 1244 | } |
1706 | 1245 | ||
1707 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1246 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1708 | super::child_opt(self) | 1247 | super::child_opt(self) |
1709 | } | 1248 | } |
1710 | 1249 | ||
1711 | pub fn initializer(self) -> Option<Expr<'a>> { | 1250 | pub fn initializer(&self) -> Option<&Expr> { |
1712 | super::child_opt(self) | 1251 | super::child_opt(self) |
1713 | } | 1252 | } |
1714 | } | 1253 | } |
1715 | 1254 | ||
1716 | // Lifetime | 1255 | // Lifetime |
1717 | #[derive(Debug, Clone, Copy,)] | 1256 | #[derive(Debug, PartialEq, Eq, Hash)] |
1718 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1257 | #[repr(transparent)] |
1719 | pub(crate) syntax: SyntaxNode<R>, | 1258 | pub struct Lifetime { |
1259 | pub(crate) syntax: SyntaxNode, | ||
1720 | } | 1260 | } |
1721 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | 1261 | unsafe impl TransparentNewType for Lifetime { |
1722 | 1262 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1723 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeNode<R1>> for LifetimeNode<R2> { | ||
1724 | fn eq(&self, other: &LifetimeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1725 | } | ||
1726 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {} | ||
1727 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> { | ||
1728 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1729 | } | 1263 | } |
1730 | 1264 | ||
1731 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1265 | impl AstNode for Lifetime { |
1732 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1266 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1733 | match syntax.kind() { | 1267 | match syntax.kind() { |
1734 | LIFETIME => Some(Lifetime { syntax }), | 1268 | LIFETIME => Some(Lifetime::from_repr(syntax.into_repr())), |
1735 | _ => None, | 1269 | _ => None, |
1736 | } | 1270 | } |
1737 | } | 1271 | } |
1738 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1272 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | } | 1273 | fn to_owned(&self) -> TreePtr<Lifetime> { TreePtr::cast(self.syntax.to_owned()) } |
1740 | |||
1741 | impl<R: TreeRoot<RaTypes>> LifetimeNode<R> { | ||
1742 | pub fn borrowed(&self) -> Lifetime { | ||
1743 | LifetimeNode { syntax: self.syntax.borrowed() } | ||
1744 | } | ||
1745 | pub fn owned(&self) -> LifetimeNode { | ||
1746 | LifetimeNode { syntax: self.syntax.owned() } | ||
1747 | } | ||
1748 | } | 1274 | } |
1749 | 1275 | ||
1750 | 1276 | ||
1751 | impl<'a> Lifetime<'a> {} | 1277 | impl ast::AstToken for Lifetime {} |
1278 | impl Lifetime {} | ||
1752 | 1279 | ||
1753 | // LifetimeParam | 1280 | // LifetimeParam |
1754 | #[derive(Debug, Clone, Copy,)] | 1281 | #[derive(Debug, PartialEq, Eq, Hash)] |
1755 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1282 | #[repr(transparent)] |
1756 | pub(crate) syntax: SyntaxNode<R>, | 1283 | pub struct LifetimeParam { |
1757 | } | 1284 | pub(crate) syntax: SyntaxNode, |
1758 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; | ||
1759 | |||
1760 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeParamNode<R1>> for LifetimeParamNode<R2> { | ||
1761 | fn eq(&self, other: &LifetimeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
1762 | } | 1285 | } |
1763 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} | 1286 | unsafe impl TransparentNewType for LifetimeParam { |
1764 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { | 1287 | type Repr = rowan::SyntaxNode<RaTypes>; |
1765 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1766 | } | 1288 | } |
1767 | 1289 | ||
1768 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1290 | impl AstNode for LifetimeParam { |
1769 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1291 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1770 | match syntax.kind() { | 1292 | match syntax.kind() { |
1771 | LIFETIME_PARAM => Some(LifetimeParam { syntax }), | 1293 | LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())), |
1772 | _ => None, | 1294 | _ => None, |
1773 | } | 1295 | } |
1774 | } | 1296 | } |
1775 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1297 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1298 | fn to_owned(&self) -> TreePtr<LifetimeParam> { TreePtr::cast(self.syntax.to_owned()) } | ||
1776 | } | 1299 | } |
1777 | 1300 | ||
1778 | impl<R: TreeRoot<RaTypes>> LifetimeParamNode<R> { | ||
1779 | pub fn borrowed(&self) -> LifetimeParam { | ||
1780 | LifetimeParamNode { syntax: self.syntax.borrowed() } | ||
1781 | } | ||
1782 | pub fn owned(&self) -> LifetimeParamNode { | ||
1783 | LifetimeParamNode { syntax: self.syntax.owned() } | ||
1784 | } | ||
1785 | } | ||
1786 | 1301 | ||
1787 | 1302 | impl LifetimeParam { | |
1788 | impl<'a> LifetimeParam<'a> { | 1303 | pub fn lifetime(&self) -> Option<&Lifetime> { |
1789 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | ||
1790 | super::child_opt(self) | 1304 | super::child_opt(self) |
1791 | } | 1305 | } |
1792 | } | 1306 | } |
1793 | 1307 | ||
1794 | // Literal | 1308 | // Literal |
1795 | #[derive(Debug, Clone, Copy,)] | 1309 | #[derive(Debug, PartialEq, Eq, Hash)] |
1796 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1310 | #[repr(transparent)] |
1797 | pub(crate) syntax: SyntaxNode<R>, | 1311 | pub struct Literal { |
1798 | } | 1312 | pub(crate) syntax: SyntaxNode, |
1799 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; | ||
1800 | |||
1801 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LiteralNode<R1>> for LiteralNode<R2> { | ||
1802 | fn eq(&self, other: &LiteralNode<R1>) -> bool { self.syntax == other.syntax } | ||
1803 | } | 1313 | } |
1804 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} | 1314 | unsafe impl TransparentNewType for Literal { |
1805 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { | 1315 | type Repr = rowan::SyntaxNode<RaTypes>; |
1806 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1807 | } | 1316 | } |
1808 | 1317 | ||
1809 | impl<'a> AstNode<'a> for Literal<'a> { | 1318 | impl AstNode for Literal { |
1810 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1319 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1811 | match syntax.kind() { | 1320 | match syntax.kind() { |
1812 | LITERAL => Some(Literal { syntax }), | 1321 | LITERAL => Some(Literal::from_repr(syntax.into_repr())), |
1813 | _ => None, | 1322 | _ => None, |
1814 | } | 1323 | } |
1815 | } | 1324 | } |
1816 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1325 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1817 | } | 1326 | fn to_owned(&self) -> TreePtr<Literal> { TreePtr::cast(self.syntax.to_owned()) } |
1818 | |||
1819 | impl<R: TreeRoot<RaTypes>> LiteralNode<R> { | ||
1820 | pub fn borrowed(&self) -> Literal { | ||
1821 | LiteralNode { syntax: self.syntax.borrowed() } | ||
1822 | } | ||
1823 | pub fn owned(&self) -> LiteralNode { | ||
1824 | LiteralNode { syntax: self.syntax.owned() } | ||
1825 | } | ||
1826 | } | 1327 | } |
1827 | 1328 | ||
1828 | 1329 | ||
1829 | impl<'a> Literal<'a> {} | 1330 | impl Literal {} |
1830 | 1331 | ||
1831 | // LoopExpr | 1332 | // LoopExpr |
1832 | #[derive(Debug, Clone, Copy,)] | 1333 | #[derive(Debug, PartialEq, Eq, Hash)] |
1833 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1334 | #[repr(transparent)] |
1834 | pub(crate) syntax: SyntaxNode<R>, | 1335 | pub struct LoopExpr { |
1336 | pub(crate) syntax: SyntaxNode, | ||
1835 | } | 1337 | } |
1836 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | 1338 | unsafe impl TransparentNewType for LoopExpr { |
1837 | 1339 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1838 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LoopExprNode<R1>> for LoopExprNode<R2> { | ||
1839 | fn eq(&self, other: &LoopExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1840 | } | ||
1841 | impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {} | ||
1842 | impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> { | ||
1843 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1844 | } | 1340 | } |
1845 | 1341 | ||
1846 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1342 | impl AstNode for LoopExpr { |
1847 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1343 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1848 | match syntax.kind() { | 1344 | match syntax.kind() { |
1849 | LOOP_EXPR => Some(LoopExpr { syntax }), | 1345 | LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())), |
1850 | _ => None, | 1346 | _ => None, |
1851 | } | 1347 | } |
1852 | } | 1348 | } |
1853 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1349 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1854 | } | 1350 | fn to_owned(&self) -> TreePtr<LoopExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1855 | |||
1856 | impl<R: TreeRoot<RaTypes>> LoopExprNode<R> { | ||
1857 | pub fn borrowed(&self) -> LoopExpr { | ||
1858 | LoopExprNode { syntax: self.syntax.borrowed() } | ||
1859 | } | ||
1860 | pub fn owned(&self) -> LoopExprNode { | ||
1861 | LoopExprNode { syntax: self.syntax.owned() } | ||
1862 | } | ||
1863 | } | 1351 | } |
1864 | 1352 | ||
1865 | 1353 | ||
1866 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | 1354 | impl ast::LoopBodyOwner for LoopExpr {} |
1867 | impl<'a> LoopExpr<'a> {} | 1355 | impl LoopExpr {} |
1868 | 1356 | ||
1869 | // MacroCall | 1357 | // MacroCall |
1870 | #[derive(Debug, Clone, Copy,)] | 1358 | #[derive(Debug, PartialEq, Eq, Hash)] |
1871 | pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1359 | #[repr(transparent)] |
1872 | pub(crate) syntax: SyntaxNode<R>, | 1360 | pub struct MacroCall { |
1361 | pub(crate) syntax: SyntaxNode, | ||
1873 | } | 1362 | } |
1874 | pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>; | 1363 | unsafe impl TransparentNewType for MacroCall { |
1875 | 1364 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1876 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MacroCallNode<R1>> for MacroCallNode<R2> { | ||
1877 | fn eq(&self, other: &MacroCallNode<R1>) -> bool { self.syntax == other.syntax } | ||
1878 | } | ||
1879 | impl<R: TreeRoot<RaTypes>> Eq for MacroCallNode<R> {} | ||
1880 | impl<R: TreeRoot<RaTypes>> Hash for MacroCallNode<R> { | ||
1881 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1882 | } | 1365 | } |
1883 | 1366 | ||
1884 | impl<'a> AstNode<'a> for MacroCall<'a> { | 1367 | impl AstNode for MacroCall { |
1885 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1368 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1886 | match syntax.kind() { | 1369 | match syntax.kind() { |
1887 | MACRO_CALL => Some(MacroCall { syntax }), | 1370 | MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())), |
1888 | _ => None, | 1371 | _ => None, |
1889 | } | 1372 | } |
1890 | } | 1373 | } |
1891 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1374 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1892 | } | 1375 | fn to_owned(&self) -> TreePtr<MacroCall> { TreePtr::cast(self.syntax.to_owned()) } |
1893 | |||
1894 | impl<R: TreeRoot<RaTypes>> MacroCallNode<R> { | ||
1895 | pub fn borrowed(&self) -> MacroCall { | ||
1896 | MacroCallNode { syntax: self.syntax.borrowed() } | ||
1897 | } | ||
1898 | pub fn owned(&self) -> MacroCallNode { | ||
1899 | MacroCallNode { syntax: self.syntax.owned() } | ||
1900 | } | ||
1901 | } | 1376 | } |
1902 | 1377 | ||
1903 | 1378 | ||
1904 | impl<'a> MacroCall<'a> { | 1379 | impl MacroCall { |
1905 | pub fn token_tree(self) -> Option<TokenTree<'a>> { | 1380 | pub fn token_tree(&self) -> Option<&TokenTree> { |
1906 | super::child_opt(self) | 1381 | super::child_opt(self) |
1907 | } | 1382 | } |
1908 | 1383 | ||
1909 | pub fn path(self) -> Option<Path<'a>> { | 1384 | pub fn path(&self) -> Option<&Path> { |
1910 | super::child_opt(self) | 1385 | super::child_opt(self) |
1911 | } | 1386 | } |
1912 | } | 1387 | } |
1913 | 1388 | ||
1914 | // MatchArm | 1389 | // MatchArm |
1915 | #[derive(Debug, Clone, Copy,)] | 1390 | #[derive(Debug, PartialEq, Eq, Hash)] |
1916 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1391 | #[repr(transparent)] |
1917 | pub(crate) syntax: SyntaxNode<R>, | 1392 | pub struct MatchArm { |
1393 | pub(crate) syntax: SyntaxNode, | ||
1918 | } | 1394 | } |
1919 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | 1395 | unsafe impl TransparentNewType for MatchArm { |
1920 | 1396 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1921 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmNode<R1>> for MatchArmNode<R2> { | ||
1922 | fn eq(&self, other: &MatchArmNode<R1>) -> bool { self.syntax == other.syntax } | ||
1923 | } | ||
1924 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {} | ||
1925 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> { | ||
1926 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1927 | } | 1397 | } |
1928 | 1398 | ||
1929 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1399 | impl AstNode for MatchArm { |
1930 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1400 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1931 | match syntax.kind() { | 1401 | match syntax.kind() { |
1932 | MATCH_ARM => Some(MatchArm { syntax }), | 1402 | MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())), |
1933 | _ => None, | 1403 | _ => None, |
1934 | } | 1404 | } |
1935 | } | 1405 | } |
1936 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1406 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1407 | fn to_owned(&self) -> TreePtr<MatchArm> { TreePtr::cast(self.syntax.to_owned()) } | ||
1937 | } | 1408 | } |
1938 | 1409 | ||
1939 | impl<R: TreeRoot<RaTypes>> MatchArmNode<R> { | ||
1940 | pub fn borrowed(&self) -> MatchArm { | ||
1941 | MatchArmNode { syntax: self.syntax.borrowed() } | ||
1942 | } | ||
1943 | pub fn owned(&self) -> MatchArmNode { | ||
1944 | MatchArmNode { syntax: self.syntax.owned() } | ||
1945 | } | ||
1946 | } | ||
1947 | 1410 | ||
1948 | 1411 | impl MatchArm { | |
1949 | impl<'a> MatchArm<'a> { | 1412 | pub fn pats(&self) -> impl Iterator<Item = &Pat> { |
1950 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | ||
1951 | super::children(self) | 1413 | super::children(self) |
1952 | } | 1414 | } |
1953 | 1415 | ||
1954 | pub fn guard(self) -> Option<MatchGuard<'a>> { | 1416 | pub fn guard(&self) -> Option<&MatchGuard> { |
1955 | super::child_opt(self) | 1417 | super::child_opt(self) |
1956 | } | 1418 | } |
1957 | 1419 | ||
1958 | pub fn expr(self) -> Option<Expr<'a>> { | 1420 | pub fn expr(&self) -> Option<&Expr> { |
1959 | super::child_opt(self) | 1421 | super::child_opt(self) |
1960 | } | 1422 | } |
1961 | } | 1423 | } |
1962 | 1424 | ||
1963 | // MatchArmList | 1425 | // MatchArmList |
1964 | #[derive(Debug, Clone, Copy,)] | 1426 | #[derive(Debug, PartialEq, Eq, Hash)] |
1965 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1427 | #[repr(transparent)] |
1966 | pub(crate) syntax: SyntaxNode<R>, | 1428 | pub struct MatchArmList { |
1967 | } | 1429 | pub(crate) syntax: SyntaxNode, |
1968 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; | ||
1969 | |||
1970 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmListNode<R1>> for MatchArmListNode<R2> { | ||
1971 | fn eq(&self, other: &MatchArmListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1972 | } | 1430 | } |
1973 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} | 1431 | unsafe impl TransparentNewType for MatchArmList { |
1974 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { | 1432 | type Repr = rowan::SyntaxNode<RaTypes>; |
1975 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1976 | } | 1433 | } |
1977 | 1434 | ||
1978 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1435 | impl AstNode for MatchArmList { |
1979 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1436 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1980 | match syntax.kind() { | 1437 | match syntax.kind() { |
1981 | MATCH_ARM_LIST => Some(MatchArmList { syntax }), | 1438 | MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())), |
1982 | _ => None, | 1439 | _ => None, |
1983 | } | 1440 | } |
1984 | } | 1441 | } |
1985 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1442 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1443 | fn to_owned(&self) -> TreePtr<MatchArmList> { TreePtr::cast(self.syntax.to_owned()) } | ||
1986 | } | 1444 | } |
1987 | 1445 | ||
1988 | impl<R: TreeRoot<RaTypes>> MatchArmListNode<R> { | ||
1989 | pub fn borrowed(&self) -> MatchArmList { | ||
1990 | MatchArmListNode { syntax: self.syntax.borrowed() } | ||
1991 | } | ||
1992 | pub fn owned(&self) -> MatchArmListNode { | ||
1993 | MatchArmListNode { syntax: self.syntax.owned() } | ||
1994 | } | ||
1995 | } | ||
1996 | 1446 | ||
1997 | 1447 | impl MatchArmList { | |
1998 | impl<'a> MatchArmList<'a> { | 1448 | pub fn arms(&self) -> impl Iterator<Item = &MatchArm> { |
1999 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | ||
2000 | super::children(self) | 1449 | super::children(self) |
2001 | } | 1450 | } |
2002 | } | 1451 | } |
2003 | 1452 | ||
2004 | // MatchExpr | 1453 | // MatchExpr |
2005 | #[derive(Debug, Clone, Copy,)] | 1454 | #[derive(Debug, PartialEq, Eq, Hash)] |
2006 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1455 | #[repr(transparent)] |
2007 | pub(crate) syntax: SyntaxNode<R>, | 1456 | pub struct MatchExpr { |
2008 | } | 1457 | pub(crate) syntax: SyntaxNode, |
2009 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; | ||
2010 | |||
2011 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchExprNode<R1>> for MatchExprNode<R2> { | ||
2012 | fn eq(&self, other: &MatchExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2013 | } | 1458 | } |
2014 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} | 1459 | unsafe impl TransparentNewType for MatchExpr { |
2015 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { | 1460 | type Repr = rowan::SyntaxNode<RaTypes>; |
2016 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2017 | } | 1461 | } |
2018 | 1462 | ||
2019 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1463 | impl AstNode for MatchExpr { |
2020 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1464 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2021 | match syntax.kind() { | 1465 | match syntax.kind() { |
2022 | MATCH_EXPR => Some(MatchExpr { syntax }), | 1466 | MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())), |
2023 | _ => None, | 1467 | _ => None, |
2024 | } | 1468 | } |
2025 | } | 1469 | } |
2026 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1470 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2027 | } | 1471 | fn to_owned(&self) -> TreePtr<MatchExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2028 | |||
2029 | impl<R: TreeRoot<RaTypes>> MatchExprNode<R> { | ||
2030 | pub fn borrowed(&self) -> MatchExpr { | ||
2031 | MatchExprNode { syntax: self.syntax.borrowed() } | ||
2032 | } | ||
2033 | pub fn owned(&self) -> MatchExprNode { | ||
2034 | MatchExprNode { syntax: self.syntax.owned() } | ||
2035 | } | ||
2036 | } | 1472 | } |
2037 | 1473 | ||
2038 | 1474 | ||
2039 | impl<'a> MatchExpr<'a> { | 1475 | impl MatchExpr { |
2040 | pub fn expr(self) -> Option<Expr<'a>> { | 1476 | pub fn expr(&self) -> Option<&Expr> { |
2041 | super::child_opt(self) | 1477 | super::child_opt(self) |
2042 | } | 1478 | } |
2043 | 1479 | ||
2044 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | 1480 | pub fn match_arm_list(&self) -> Option<&MatchArmList> { |
2045 | super::child_opt(self) | 1481 | super::child_opt(self) |
2046 | } | 1482 | } |
2047 | } | 1483 | } |
2048 | 1484 | ||
2049 | // MatchGuard | 1485 | // MatchGuard |
2050 | #[derive(Debug, Clone, Copy,)] | 1486 | #[derive(Debug, PartialEq, Eq, Hash)] |
2051 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1487 | #[repr(transparent)] |
2052 | pub(crate) syntax: SyntaxNode<R>, | 1488 | pub struct MatchGuard { |
1489 | pub(crate) syntax: SyntaxNode, | ||
2053 | } | 1490 | } |
2054 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | 1491 | unsafe impl TransparentNewType for MatchGuard { |
2055 | 1492 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2056 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchGuardNode<R1>> for MatchGuardNode<R2> { | ||
2057 | fn eq(&self, other: &MatchGuardNode<R1>) -> bool { self.syntax == other.syntax } | ||
2058 | } | ||
2059 | impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {} | ||
2060 | impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> { | ||
2061 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2062 | } | 1493 | } |
2063 | 1494 | ||
2064 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1495 | impl AstNode for MatchGuard { |
2065 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1496 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2066 | match syntax.kind() { | 1497 | match syntax.kind() { |
2067 | MATCH_GUARD => Some(MatchGuard { syntax }), | 1498 | MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())), |
2068 | _ => None, | 1499 | _ => None, |
2069 | } | 1500 | } |
2070 | } | 1501 | } |
2071 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1502 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2072 | } | 1503 | fn to_owned(&self) -> TreePtr<MatchGuard> { TreePtr::cast(self.syntax.to_owned()) } |
2073 | |||
2074 | impl<R: TreeRoot<RaTypes>> MatchGuardNode<R> { | ||
2075 | pub fn borrowed(&self) -> MatchGuard { | ||
2076 | MatchGuardNode { syntax: self.syntax.borrowed() } | ||
2077 | } | ||
2078 | pub fn owned(&self) -> MatchGuardNode { | ||
2079 | MatchGuardNode { syntax: self.syntax.owned() } | ||
2080 | } | ||
2081 | } | 1504 | } |
2082 | 1505 | ||
2083 | 1506 | ||
2084 | impl<'a> MatchGuard<'a> {} | 1507 | impl MatchGuard {} |
2085 | 1508 | ||
2086 | // MethodCallExpr | 1509 | // MethodCallExpr |
2087 | #[derive(Debug, Clone, Copy,)] | 1510 | #[derive(Debug, PartialEq, Eq, Hash)] |
2088 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1511 | #[repr(transparent)] |
2089 | pub(crate) syntax: SyntaxNode<R>, | 1512 | pub struct MethodCallExpr { |
2090 | } | 1513 | pub(crate) syntax: SyntaxNode, |
2091 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; | ||
2092 | |||
2093 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MethodCallExprNode<R1>> for MethodCallExprNode<R2> { | ||
2094 | fn eq(&self, other: &MethodCallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2095 | } | 1514 | } |
2096 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} | 1515 | unsafe impl TransparentNewType for MethodCallExpr { |
2097 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { | 1516 | type Repr = rowan::SyntaxNode<RaTypes>; |
2098 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2099 | } | 1517 | } |
2100 | 1518 | ||
2101 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1519 | impl AstNode for MethodCallExpr { |
2102 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1520 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2103 | match syntax.kind() { | 1521 | match syntax.kind() { |
2104 | METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), | 1522 | METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())), |
2105 | _ => None, | 1523 | _ => None, |
2106 | } | 1524 | } |
2107 | } | 1525 | } |
2108 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1526 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1527 | fn to_owned(&self) -> TreePtr<MethodCallExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2109 | } | 1528 | } |
2110 | 1529 | ||
2111 | impl<R: TreeRoot<RaTypes>> MethodCallExprNode<R> { | ||
2112 | pub fn borrowed(&self) -> MethodCallExpr { | ||
2113 | MethodCallExprNode { syntax: self.syntax.borrowed() } | ||
2114 | } | ||
2115 | pub fn owned(&self) -> MethodCallExprNode { | ||
2116 | MethodCallExprNode { syntax: self.syntax.owned() } | ||
2117 | } | ||
2118 | } | ||
2119 | 1530 | ||
2120 | 1531 | impl ast::ArgListOwner for MethodCallExpr {} | |
2121 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 1532 | impl MethodCallExpr { |
2122 | impl<'a> MethodCallExpr<'a> { | 1533 | pub fn expr(&self) -> Option<&Expr> { |
2123 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2124 | super::child_opt(self) | 1534 | super::child_opt(self) |
2125 | } | 1535 | } |
2126 | 1536 | ||
2127 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1537 | pub fn name_ref(&self) -> Option<&NameRef> { |
2128 | super::child_opt(self) | 1538 | super::child_opt(self) |
2129 | } | 1539 | } |
2130 | } | 1540 | } |
2131 | 1541 | ||
2132 | // Module | 1542 | // Module |
2133 | #[derive(Debug, Clone, Copy,)] | 1543 | #[derive(Debug, PartialEq, Eq, Hash)] |
2134 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1544 | #[repr(transparent)] |
2135 | pub(crate) syntax: SyntaxNode<R>, | 1545 | pub struct Module { |
2136 | } | 1546 | pub(crate) syntax: SyntaxNode, |
2137 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; | ||
2138 | |||
2139 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ModuleNode<R1>> for ModuleNode<R2> { | ||
2140 | fn eq(&self, other: &ModuleNode<R1>) -> bool { self.syntax == other.syntax } | ||
2141 | } | 1547 | } |
2142 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} | 1548 | unsafe impl TransparentNewType for Module { |
2143 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { | 1549 | type Repr = rowan::SyntaxNode<RaTypes>; |
2144 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2145 | } | 1550 | } |
2146 | 1551 | ||
2147 | impl<'a> AstNode<'a> for Module<'a> { | 1552 | impl AstNode for Module { |
2148 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1553 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2149 | match syntax.kind() { | 1554 | match syntax.kind() { |
2150 | MODULE => Some(Module { syntax }), | 1555 | MODULE => Some(Module::from_repr(syntax.into_repr())), |
2151 | _ => None, | 1556 | _ => None, |
2152 | } | 1557 | } |
2153 | } | 1558 | } |
2154 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1559 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1560 | fn to_owned(&self) -> TreePtr<Module> { TreePtr::cast(self.syntax.to_owned()) } | ||
2155 | } | 1561 | } |
2156 | 1562 | ||
2157 | impl<R: TreeRoot<RaTypes>> ModuleNode<R> { | ||
2158 | pub fn borrowed(&self) -> Module { | ||
2159 | ModuleNode { syntax: self.syntax.borrowed() } | ||
2160 | } | ||
2161 | pub fn owned(&self) -> ModuleNode { | ||
2162 | ModuleNode { syntax: self.syntax.owned() } | ||
2163 | } | ||
2164 | } | ||
2165 | 1563 | ||
2166 | 1564 | impl ast::VisibilityOwner for Module {} | |
2167 | impl<'a> ast::VisibilityOwner<'a> for Module<'a> {} | 1565 | impl ast::NameOwner for Module {} |
2168 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1566 | impl ast::AttrsOwner for Module {} |
2169 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1567 | impl ast::DocCommentsOwner for Module {} |
2170 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | 1568 | impl Module { |
2171 | impl<'a> Module<'a> { | 1569 | pub fn item_list(&self) -> Option<&ItemList> { |
2172 | pub fn item_list(self) -> Option<ItemList<'a>> { | ||
2173 | super::child_opt(self) | 1570 | super::child_opt(self) |
2174 | } | 1571 | } |
2175 | } | 1572 | } |
2176 | 1573 | ||
2177 | // ModuleItem | 1574 | // ModuleItem |
2178 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1575 | #[derive(Debug, PartialEq, Eq, Hash)] |
2179 | pub enum ModuleItem<'a> { | 1576 | #[repr(transparent)] |
2180 | StructDef(StructDef<'a>), | 1577 | pub struct ModuleItem { |
2181 | EnumDef(EnumDef<'a>), | 1578 | pub(crate) syntax: SyntaxNode, |
2182 | FnDef(FnDef<'a>), | 1579 | } |
2183 | TraitDef(TraitDef<'a>), | 1580 | unsafe impl TransparentNewType for ModuleItem { |
2184 | TypeDef(TypeDef<'a>), | 1581 | type Repr = rowan::SyntaxNode<RaTypes>; |
2185 | ImplBlock(ImplBlock<'a>), | ||
2186 | UseItem(UseItem<'a>), | ||
2187 | ExternCrateItem(ExternCrateItem<'a>), | ||
2188 | ConstDef(ConstDef<'a>), | ||
2189 | StaticDef(StaticDef<'a>), | ||
2190 | Module(Module<'a>), | ||
2191 | } | ||
2192 | |||
2193 | impl<'a> AstNode<'a> for ModuleItem<'a> { | ||
2194 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
2195 | match syntax.kind() { | ||
2196 | STRUCT_DEF => Some(ModuleItem::StructDef(StructDef { syntax })), | ||
2197 | ENUM_DEF => Some(ModuleItem::EnumDef(EnumDef { syntax })), | ||
2198 | FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })), | ||
2199 | TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })), | ||
2200 | TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })), | ||
2201 | IMPL_BLOCK => Some(ModuleItem::ImplBlock(ImplBlock { syntax })), | ||
2202 | USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })), | ||
2203 | EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })), | ||
2204 | CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })), | ||
2205 | STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })), | ||
2206 | MODULE => Some(ModuleItem::Module(Module { syntax })), | ||
2207 | _ => None, | ||
2208 | } | ||
2209 | } | ||
2210 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
2211 | match self { | ||
2212 | ModuleItem::StructDef(inner) => inner.syntax(), | ||
2213 | ModuleItem::EnumDef(inner) => inner.syntax(), | ||
2214 | ModuleItem::FnDef(inner) => inner.syntax(), | ||
2215 | ModuleItem::TraitDef(inner) => inner.syntax(), | ||
2216 | ModuleItem::TypeDef(inner) => inner.syntax(), | ||
2217 | ModuleItem::ImplBlock(inner) => inner.syntax(), | ||
2218 | ModuleItem::UseItem(inner) => inner.syntax(), | ||
2219 | ModuleItem::ExternCrateItem(inner) => inner.syntax(), | ||
2220 | ModuleItem::ConstDef(inner) => inner.syntax(), | ||
2221 | ModuleItem::StaticDef(inner) => inner.syntax(), | ||
2222 | ModuleItem::Module(inner) => inner.syntax(), | ||
2223 | } | ||
2224 | } | ||
2225 | } | 1582 | } |
2226 | 1583 | ||
2227 | impl<'a> ModuleItem<'a> {} | 1584 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1585 | pub enum ModuleItemKind<'a> { | ||
1586 | StructDef(&'a StructDef), | ||
1587 | EnumDef(&'a EnumDef), | ||
1588 | FnDef(&'a FnDef), | ||
1589 | TraitDef(&'a TraitDef), | ||
1590 | TypeDef(&'a TypeDef), | ||
1591 | ImplBlock(&'a ImplBlock), | ||
1592 | UseItem(&'a UseItem), | ||
1593 | ExternCrateItem(&'a ExternCrateItem), | ||
1594 | ConstDef(&'a ConstDef), | ||
1595 | StaticDef(&'a StaticDef), | ||
1596 | Module(&'a Module), | ||
1597 | } | ||
1598 | |||
1599 | impl AstNode for ModuleItem { | ||
1600 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1601 | match syntax.kind() { | ||
1602 | | STRUCT_DEF | ||
1603 | | ENUM_DEF | ||
1604 | | FN_DEF | ||
1605 | | TRAIT_DEF | ||
1606 | | TYPE_DEF | ||
1607 | | IMPL_BLOCK | ||
1608 | | USE_ITEM | ||
1609 | | EXTERN_CRATE_ITEM | ||
1610 | | CONST_DEF | ||
1611 | | STATIC_DEF | ||
1612 | | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())), | ||
1613 | _ => None, | ||
1614 | } | ||
1615 | } | ||
1616 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1617 | fn to_owned(&self) -> TreePtr<ModuleItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1618 | } | ||
1619 | |||
1620 | impl ModuleItem { | ||
1621 | pub fn kind(&self) -> ModuleItemKind { | ||
1622 | match self.syntax.kind() { | ||
1623 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1624 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1625 | FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1626 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()), | ||
1627 | TYPE_DEF => ModuleItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1628 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()), | ||
1629 | USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()), | ||
1630 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()), | ||
1631 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1632 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()), | ||
1633 | MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()), | ||
1634 | _ => unreachable!(), | ||
1635 | } | ||
1636 | } | ||
1637 | } | ||
1638 | |||
1639 | impl ModuleItem {} | ||
2228 | 1640 | ||
2229 | // Name | 1641 | // Name |
2230 | #[derive(Debug, Clone, Copy,)] | 1642 | #[derive(Debug, PartialEq, Eq, Hash)] |
2231 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1643 | #[repr(transparent)] |
2232 | pub(crate) syntax: SyntaxNode<R>, | 1644 | pub struct Name { |
2233 | } | 1645 | pub(crate) syntax: SyntaxNode, |
2234 | pub type Name<'a> = NameNode<RefRoot<'a>>; | ||
2235 | |||
2236 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> { | ||
2237 | fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax } | ||
2238 | } | 1646 | } |
2239 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} | 1647 | unsafe impl TransparentNewType for Name { |
2240 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { | 1648 | type Repr = rowan::SyntaxNode<RaTypes>; |
2241 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2242 | } | 1649 | } |
2243 | 1650 | ||
2244 | impl<'a> AstNode<'a> for Name<'a> { | 1651 | impl AstNode for Name { |
2245 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1652 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2246 | match syntax.kind() { | 1653 | match syntax.kind() { |
2247 | NAME => Some(Name { syntax }), | 1654 | NAME => Some(Name::from_repr(syntax.into_repr())), |
2248 | _ => None, | 1655 | _ => None, |
2249 | } | 1656 | } |
2250 | } | 1657 | } |
2251 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1658 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1659 | fn to_owned(&self) -> TreePtr<Name> { TreePtr::cast(self.syntax.to_owned()) } | ||
2252 | } | 1660 | } |
2253 | 1661 | ||
2254 | impl<R: TreeRoot<RaTypes>> NameNode<R> { | ||
2255 | pub fn borrowed(&self) -> Name { | ||
2256 | NameNode { syntax: self.syntax.borrowed() } | ||
2257 | } | ||
2258 | pub fn owned(&self) -> NameNode { | ||
2259 | NameNode { syntax: self.syntax.owned() } | ||
2260 | } | ||
2261 | } | ||
2262 | 1662 | ||
2263 | 1663 | impl Name {} | |
2264 | impl<'a> Name<'a> {} | ||
2265 | 1664 | ||
2266 | // NameRef | 1665 | // NameRef |
2267 | #[derive(Debug, Clone, Copy,)] | 1666 | #[derive(Debug, PartialEq, Eq, Hash)] |
2268 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1667 | #[repr(transparent)] |
2269 | pub(crate) syntax: SyntaxNode<R>, | 1668 | pub struct NameRef { |
2270 | } | 1669 | pub(crate) syntax: SyntaxNode, |
2271 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; | ||
2272 | |||
2273 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> { | ||
2274 | fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2275 | } | 1670 | } |
2276 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} | 1671 | unsafe impl TransparentNewType for NameRef { |
2277 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { | 1672 | type Repr = rowan::SyntaxNode<RaTypes>; |
2278 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2279 | } | 1673 | } |
2280 | 1674 | ||
2281 | impl<'a> AstNode<'a> for NameRef<'a> { | 1675 | impl AstNode for NameRef { |
2282 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1676 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2283 | match syntax.kind() { | 1677 | match syntax.kind() { |
2284 | NAME_REF => Some(NameRef { syntax }), | 1678 | NAME_REF => Some(NameRef::from_repr(syntax.into_repr())), |
2285 | _ => None, | 1679 | _ => None, |
2286 | } | 1680 | } |
2287 | } | 1681 | } |
2288 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1682 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1683 | fn to_owned(&self) -> TreePtr<NameRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2289 | } | 1684 | } |
2290 | 1685 | ||
2291 | impl<R: TreeRoot<RaTypes>> NameRefNode<R> { | ||
2292 | pub fn borrowed(&self) -> NameRef { | ||
2293 | NameRefNode { syntax: self.syntax.borrowed() } | ||
2294 | } | ||
2295 | pub fn owned(&self) -> NameRefNode { | ||
2296 | NameRefNode { syntax: self.syntax.owned() } | ||
2297 | } | ||
2298 | } | ||
2299 | 1686 | ||
2300 | 1687 | impl NameRef {} | |
2301 | impl<'a> NameRef<'a> {} | ||
2302 | 1688 | ||
2303 | // NamedField | 1689 | // NamedField |
2304 | #[derive(Debug, Clone, Copy,)] | 1690 | #[derive(Debug, PartialEq, Eq, Hash)] |
2305 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1691 | #[repr(transparent)] |
2306 | pub(crate) syntax: SyntaxNode<R>, | 1692 | pub struct NamedField { |
1693 | pub(crate) syntax: SyntaxNode, | ||
2307 | } | 1694 | } |
2308 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | 1695 | unsafe impl TransparentNewType for NamedField { |
2309 | 1696 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2310 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> { | ||
2311 | fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
2312 | } | ||
2313 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {} | ||
2314 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> { | ||
2315 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2316 | } | 1697 | } |
2317 | 1698 | ||
2318 | impl<'a> AstNode<'a> for NamedField<'a> { | 1699 | impl AstNode for NamedField { |
2319 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1700 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2320 | match syntax.kind() { | 1701 | match syntax.kind() { |
2321 | NAMED_FIELD => Some(NamedField { syntax }), | 1702 | NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())), |
2322 | _ => None, | 1703 | _ => None, |
2323 | } | 1704 | } |
2324 | } | 1705 | } |
2325 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1706 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2326 | } | 1707 | fn to_owned(&self) -> TreePtr<NamedField> { TreePtr::cast(self.syntax.to_owned()) } |
2327 | |||
2328 | impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> { | ||
2329 | pub fn borrowed(&self) -> NamedField { | ||
2330 | NamedFieldNode { syntax: self.syntax.borrowed() } | ||
2331 | } | ||
2332 | pub fn owned(&self) -> NamedFieldNode { | ||
2333 | NamedFieldNode { syntax: self.syntax.owned() } | ||
2334 | } | ||
2335 | } | 1708 | } |
2336 | 1709 | ||
2337 | 1710 | ||
2338 | impl<'a> NamedField<'a> { | 1711 | impl NamedField { |
2339 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1712 | pub fn name_ref(&self) -> Option<&NameRef> { |
2340 | super::child_opt(self) | 1713 | super::child_opt(self) |
2341 | } | 1714 | } |
2342 | 1715 | ||
2343 | pub fn expr(self) -> Option<Expr<'a>> { | 1716 | pub fn expr(&self) -> Option<&Expr> { |
2344 | super::child_opt(self) | 1717 | super::child_opt(self) |
2345 | } | 1718 | } |
2346 | } | 1719 | } |
2347 | 1720 | ||
2348 | // NamedFieldDef | 1721 | // NamedFieldDef |
2349 | #[derive(Debug, Clone, Copy,)] | 1722 | #[derive(Debug, PartialEq, Eq, Hash)] |
2350 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1723 | #[repr(transparent)] |
2351 | pub(crate) syntax: SyntaxNode<R>, | 1724 | pub struct NamedFieldDef { |
1725 | pub(crate) syntax: SyntaxNode, | ||
2352 | } | 1726 | } |
2353 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | 1727 | unsafe impl TransparentNewType for NamedFieldDef { |
2354 | 1728 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2355 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> { | ||
2356 | fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2357 | } | ||
2358 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {} | ||
2359 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> { | ||
2360 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2361 | } | 1729 | } |
2362 | 1730 | ||
2363 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 1731 | impl AstNode for NamedFieldDef { |
2364 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1732 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2365 | match syntax.kind() { | 1733 | match syntax.kind() { |
2366 | NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), | 1734 | NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())), |
2367 | _ => None, | 1735 | _ => None, |
2368 | } | 1736 | } |
2369 | } | 1737 | } |
2370 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | fn to_owned(&self) -> TreePtr<NamedFieldDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2371 | } | 1740 | } |
2372 | 1741 | ||
2373 | impl<R: TreeRoot<RaTypes>> NamedFieldDefNode<R> { | ||
2374 | pub fn borrowed(&self) -> NamedFieldDef { | ||
2375 | NamedFieldDefNode { syntax: self.syntax.borrowed() } | ||
2376 | } | ||
2377 | pub fn owned(&self) -> NamedFieldDefNode { | ||
2378 | NamedFieldDefNode { syntax: self.syntax.owned() } | ||
2379 | } | ||
2380 | } | ||
2381 | 1742 | ||
2382 | 1743 | impl ast::VisibilityOwner for NamedFieldDef {} | |
2383 | impl<'a> ast::VisibilityOwner<'a> for NamedFieldDef<'a> {} | 1744 | impl ast::NameOwner for NamedFieldDef {} |
2384 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} | 1745 | impl ast::AttrsOwner for NamedFieldDef {} |
2385 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | 1746 | impl NamedFieldDef { |
2386 | impl<'a> NamedFieldDef<'a> { | 1747 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2387 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
2388 | super::child_opt(self) | 1748 | super::child_opt(self) |
2389 | } | 1749 | } |
2390 | } | 1750 | } |
2391 | 1751 | ||
2392 | // NamedFieldDefList | 1752 | // NamedFieldDefList |
2393 | #[derive(Debug, Clone, Copy,)] | 1753 | #[derive(Debug, PartialEq, Eq, Hash)] |
2394 | pub struct NamedFieldDefListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1754 | #[repr(transparent)] |
2395 | pub(crate) syntax: SyntaxNode<R>, | 1755 | pub struct NamedFieldDefList { |
2396 | } | 1756 | pub(crate) syntax: SyntaxNode, |
2397 | pub type NamedFieldDefList<'a> = NamedFieldDefListNode<RefRoot<'a>>; | ||
2398 | |||
2399 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefListNode<R1>> for NamedFieldDefListNode<R2> { | ||
2400 | fn eq(&self, other: &NamedFieldDefListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2401 | } | 1757 | } |
2402 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefListNode<R> {} | 1758 | unsafe impl TransparentNewType for NamedFieldDefList { |
2403 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefListNode<R> { | 1759 | type Repr = rowan::SyntaxNode<RaTypes>; |
2404 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2405 | } | 1760 | } |
2406 | 1761 | ||
2407 | impl<'a> AstNode<'a> for NamedFieldDefList<'a> { | 1762 | impl AstNode for NamedFieldDefList { |
2408 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1763 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2409 | match syntax.kind() { | 1764 | match syntax.kind() { |
2410 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), | 1765 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())), |
2411 | _ => None, | 1766 | _ => None, |
2412 | } | 1767 | } |
2413 | } | 1768 | } |
2414 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1770 | fn to_owned(&self) -> TreePtr<NamedFieldDefList> { TreePtr::cast(self.syntax.to_owned()) } | ||
2415 | } | 1771 | } |
2416 | 1772 | ||
2417 | impl<R: TreeRoot<RaTypes>> NamedFieldDefListNode<R> { | ||
2418 | pub fn borrowed(&self) -> NamedFieldDefList { | ||
2419 | NamedFieldDefListNode { syntax: self.syntax.borrowed() } | ||
2420 | } | ||
2421 | pub fn owned(&self) -> NamedFieldDefListNode { | ||
2422 | NamedFieldDefListNode { syntax: self.syntax.owned() } | ||
2423 | } | ||
2424 | } | ||
2425 | 1773 | ||
2426 | 1774 | impl NamedFieldDefList { | |
2427 | impl<'a> NamedFieldDefList<'a> { | 1775 | pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> { |
2428 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { | ||
2429 | super::children(self) | 1776 | super::children(self) |
2430 | } | 1777 | } |
2431 | } | 1778 | } |
2432 | 1779 | ||
2433 | // NamedFieldList | 1780 | // NamedFieldList |
2434 | #[derive(Debug, Clone, Copy,)] | 1781 | #[derive(Debug, PartialEq, Eq, Hash)] |
2435 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1782 | #[repr(transparent)] |
2436 | pub(crate) syntax: SyntaxNode<R>, | 1783 | pub struct NamedFieldList { |
2437 | } | 1784 | pub(crate) syntax: SyntaxNode, |
2438 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; | ||
2439 | |||
2440 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> { | ||
2441 | fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2442 | } | 1785 | } |
2443 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} | 1786 | unsafe impl TransparentNewType for NamedFieldList { |
2444 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { | 1787 | type Repr = rowan::SyntaxNode<RaTypes>; |
2445 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2446 | } | 1788 | } |
2447 | 1789 | ||
2448 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 1790 | impl AstNode for NamedFieldList { |
2449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1791 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2450 | match syntax.kind() { | 1792 | match syntax.kind() { |
2451 | NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), | 1793 | NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())), |
2452 | _ => None, | 1794 | _ => None, |
2453 | } | 1795 | } |
2454 | } | 1796 | } |
2455 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1797 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2456 | } | 1798 | fn to_owned(&self) -> TreePtr<NamedFieldList> { TreePtr::cast(self.syntax.to_owned()) } |
2457 | |||
2458 | impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> { | ||
2459 | pub fn borrowed(&self) -> NamedFieldList { | ||
2460 | NamedFieldListNode { syntax: self.syntax.borrowed() } | ||
2461 | } | ||
2462 | pub fn owned(&self) -> NamedFieldListNode { | ||
2463 | NamedFieldListNode { syntax: self.syntax.owned() } | ||
2464 | } | ||
2465 | } | 1799 | } |
2466 | 1800 | ||
2467 | 1801 | ||
2468 | impl<'a> NamedFieldList<'a> { | 1802 | impl NamedFieldList { |
2469 | pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { | 1803 | pub fn fields(&self) -> impl Iterator<Item = &NamedField> { |
2470 | super::children(self) | 1804 | super::children(self) |
2471 | } | 1805 | } |
2472 | } | 1806 | } |
2473 | 1807 | ||
2474 | // NeverType | 1808 | // NeverType |
2475 | #[derive(Debug, Clone, Copy,)] | 1809 | #[derive(Debug, PartialEq, Eq, Hash)] |
2476 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1810 | #[repr(transparent)] |
2477 | pub(crate) syntax: SyntaxNode<R>, | 1811 | pub struct NeverType { |
2478 | } | 1812 | pub(crate) syntax: SyntaxNode, |
2479 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; | ||
2480 | |||
2481 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> { | ||
2482 | fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2483 | } | 1813 | } |
2484 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} | 1814 | unsafe impl TransparentNewType for NeverType { |
2485 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { | 1815 | type Repr = rowan::SyntaxNode<RaTypes>; |
2486 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2487 | } | 1816 | } |
2488 | 1817 | ||
2489 | impl<'a> AstNode<'a> for NeverType<'a> { | 1818 | impl AstNode for NeverType { |
2490 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1819 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2491 | match syntax.kind() { | 1820 | match syntax.kind() { |
2492 | NEVER_TYPE => Some(NeverType { syntax }), | 1821 | NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())), |
2493 | _ => None, | 1822 | _ => None, |
2494 | } | 1823 | } |
2495 | } | 1824 | } |
2496 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1825 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2497 | } | 1826 | fn to_owned(&self) -> TreePtr<NeverType> { TreePtr::cast(self.syntax.to_owned()) } |
2498 | |||
2499 | impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> { | ||
2500 | pub fn borrowed(&self) -> NeverType { | ||
2501 | NeverTypeNode { syntax: self.syntax.borrowed() } | ||
2502 | } | ||
2503 | pub fn owned(&self) -> NeverTypeNode { | ||
2504 | NeverTypeNode { syntax: self.syntax.owned() } | ||
2505 | } | ||
2506 | } | 1827 | } |
2507 | 1828 | ||
2508 | 1829 | ||
2509 | impl<'a> NeverType<'a> {} | 1830 | impl NeverType {} |
2510 | 1831 | ||
2511 | // NominalDef | 1832 | // NominalDef |
1833 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1834 | #[repr(transparent)] | ||
1835 | pub struct NominalDef { | ||
1836 | pub(crate) syntax: SyntaxNode, | ||
1837 | } | ||
1838 | unsafe impl TransparentNewType for NominalDef { | ||
1839 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1840 | } | ||
1841 | |||
2512 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1842 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2513 | pub enum NominalDef<'a> { | 1843 | pub enum NominalDefKind<'a> { |
2514 | StructDef(StructDef<'a>), | 1844 | StructDef(&'a StructDef), |
2515 | EnumDef(EnumDef<'a>), | 1845 | EnumDef(&'a EnumDef), |
2516 | } | 1846 | } |
2517 | 1847 | ||
2518 | impl<'a> AstNode<'a> for NominalDef<'a> { | 1848 | impl AstNode for NominalDef { |
2519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1849 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2520 | match syntax.kind() { | 1850 | match syntax.kind() { |
2521 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), | 1851 | | STRUCT_DEF |
2522 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), | 1852 | | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())), |
2523 | _ => None, | 1853 | _ => None, |
2524 | } | 1854 | } |
2525 | } | 1855 | } |
2526 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1856 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2527 | match self { | 1857 | fn to_owned(&self) -> TreePtr<NominalDef> { TreePtr::cast(self.syntax.to_owned()) } |
2528 | NominalDef::StructDef(inner) => inner.syntax(), | 1858 | } |
2529 | NominalDef::EnumDef(inner) => inner.syntax(), | 1859 | |
1860 | impl NominalDef { | ||
1861 | pub fn kind(&self) -> NominalDefKind { | ||
1862 | match self.syntax.kind() { | ||
1863 | STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1864 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1865 | _ => unreachable!(), | ||
2530 | } | 1866 | } |
2531 | } | 1867 | } |
2532 | } | 1868 | } |
2533 | 1869 | ||
2534 | impl<'a> ast::NameOwner<'a> for NominalDef<'a> {} | 1870 | impl ast::NameOwner for NominalDef {} |
2535 | impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} | 1871 | impl ast::TypeParamsOwner for NominalDef {} |
2536 | impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | 1872 | impl ast::AttrsOwner for NominalDef {} |
2537 | impl<'a> NominalDef<'a> {} | 1873 | impl NominalDef {} |
2538 | 1874 | ||
2539 | // Param | 1875 | // Param |
2540 | #[derive(Debug, Clone, Copy,)] | 1876 | #[derive(Debug, PartialEq, Eq, Hash)] |
2541 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1877 | #[repr(transparent)] |
2542 | pub(crate) syntax: SyntaxNode<R>, | 1878 | pub struct Param { |
2543 | } | 1879 | pub(crate) syntax: SyntaxNode, |
2544 | pub type Param<'a> = ParamNode<RefRoot<'a>>; | ||
2545 | |||
2546 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> { | ||
2547 | fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
2548 | } | 1880 | } |
2549 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} | 1881 | unsafe impl TransparentNewType for Param { |
2550 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { | 1882 | type Repr = rowan::SyntaxNode<RaTypes>; |
2551 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2552 | } | 1883 | } |
2553 | 1884 | ||
2554 | impl<'a> AstNode<'a> for Param<'a> { | 1885 | impl AstNode for Param { |
2555 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1886 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2556 | match syntax.kind() { | 1887 | match syntax.kind() { |
2557 | PARAM => Some(Param { syntax }), | 1888 | PARAM => Some(Param::from_repr(syntax.into_repr())), |
2558 | _ => None, | 1889 | _ => None, |
2559 | } | 1890 | } |
2560 | } | 1891 | } |
2561 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1892 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2562 | } | 1893 | fn to_owned(&self) -> TreePtr<Param> { TreePtr::cast(self.syntax.to_owned()) } |
2563 | |||
2564 | impl<R: TreeRoot<RaTypes>> ParamNode<R> { | ||
2565 | pub fn borrowed(&self) -> Param { | ||
2566 | ParamNode { syntax: self.syntax.borrowed() } | ||
2567 | } | ||
2568 | pub fn owned(&self) -> ParamNode { | ||
2569 | ParamNode { syntax: self.syntax.owned() } | ||
2570 | } | ||
2571 | } | 1894 | } |
2572 | 1895 | ||
2573 | 1896 | ||
2574 | impl<'a> Param<'a> { | 1897 | impl Param { |
2575 | pub fn pat(self) -> Option<Pat<'a>> { | 1898 | pub fn pat(&self) -> Option<&Pat> { |
2576 | super::child_opt(self) | 1899 | super::child_opt(self) |
2577 | } | 1900 | } |
2578 | 1901 | ||
2579 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1902 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2580 | super::child_opt(self) | 1903 | super::child_opt(self) |
2581 | } | 1904 | } |
2582 | } | 1905 | } |
2583 | 1906 | ||
2584 | // ParamList | 1907 | // ParamList |
2585 | #[derive(Debug, Clone, Copy,)] | 1908 | #[derive(Debug, PartialEq, Eq, Hash)] |
2586 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1909 | #[repr(transparent)] |
2587 | pub(crate) syntax: SyntaxNode<R>, | 1910 | pub struct ParamList { |
1911 | pub(crate) syntax: SyntaxNode, | ||
2588 | } | 1912 | } |
2589 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | 1913 | unsafe impl TransparentNewType for ParamList { |
2590 | 1914 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2591 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> { | ||
2592 | fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2593 | } | ||
2594 | impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {} | ||
2595 | impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> { | ||
2596 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2597 | } | 1915 | } |
2598 | 1916 | ||
2599 | impl<'a> AstNode<'a> for ParamList<'a> { | 1917 | impl AstNode for ParamList { |
2600 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1918 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2601 | match syntax.kind() { | 1919 | match syntax.kind() { |
2602 | PARAM_LIST => Some(ParamList { syntax }), | 1920 | PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())), |
2603 | _ => None, | 1921 | _ => None, |
2604 | } | 1922 | } |
2605 | } | 1923 | } |
2606 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1924 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2607 | } | 1925 | fn to_owned(&self) -> TreePtr<ParamList> { TreePtr::cast(self.syntax.to_owned()) } |
2608 | |||
2609 | impl<R: TreeRoot<RaTypes>> ParamListNode<R> { | ||
2610 | pub fn borrowed(&self) -> ParamList { | ||
2611 | ParamListNode { syntax: self.syntax.borrowed() } | ||
2612 | } | ||
2613 | pub fn owned(&self) -> ParamListNode { | ||
2614 | ParamListNode { syntax: self.syntax.owned() } | ||
2615 | } | ||
2616 | } | 1926 | } |
2617 | 1927 | ||
2618 | 1928 | ||
2619 | impl<'a> ParamList<'a> { | 1929 | impl ParamList { |
2620 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 1930 | pub fn params(&self) -> impl Iterator<Item = &Param> { |
2621 | super::children(self) | 1931 | super::children(self) |
2622 | } | 1932 | } |
2623 | 1933 | ||
2624 | pub fn self_param(self) -> Option<SelfParam<'a>> { | 1934 | pub fn self_param(&self) -> Option<&SelfParam> { |
2625 | super::child_opt(self) | 1935 | super::child_opt(self) |
2626 | } | 1936 | } |
2627 | } | 1937 | } |
2628 | 1938 | ||
2629 | // ParenExpr | 1939 | // ParenExpr |
2630 | #[derive(Debug, Clone, Copy,)] | 1940 | #[derive(Debug, PartialEq, Eq, Hash)] |
2631 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1941 | #[repr(transparent)] |
2632 | pub(crate) syntax: SyntaxNode<R>, | 1942 | pub struct ParenExpr { |
2633 | } | 1943 | pub(crate) syntax: SyntaxNode, |
2634 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; | ||
2635 | |||
2636 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> { | ||
2637 | fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2638 | } | 1944 | } |
2639 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} | 1945 | unsafe impl TransparentNewType for ParenExpr { |
2640 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { | 1946 | type Repr = rowan::SyntaxNode<RaTypes>; |
2641 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2642 | } | 1947 | } |
2643 | 1948 | ||
2644 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 1949 | impl AstNode for ParenExpr { |
2645 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1950 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2646 | match syntax.kind() { | 1951 | match syntax.kind() { |
2647 | PAREN_EXPR => Some(ParenExpr { syntax }), | 1952 | PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())), |
2648 | _ => None, | 1953 | _ => None, |
2649 | } | 1954 | } |
2650 | } | 1955 | } |
2651 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1956 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1957 | fn to_owned(&self) -> TreePtr<ParenExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2652 | } | 1958 | } |
2653 | 1959 | ||
2654 | impl<R: TreeRoot<RaTypes>> ParenExprNode<R> { | ||
2655 | pub fn borrowed(&self) -> ParenExpr { | ||
2656 | ParenExprNode { syntax: self.syntax.borrowed() } | ||
2657 | } | ||
2658 | pub fn owned(&self) -> ParenExprNode { | ||
2659 | ParenExprNode { syntax: self.syntax.owned() } | ||
2660 | } | ||
2661 | } | ||
2662 | 1960 | ||
2663 | 1961 | impl ParenExpr { | |
2664 | impl<'a> ParenExpr<'a> { | 1962 | pub fn expr(&self) -> Option<&Expr> { |
2665 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2666 | super::child_opt(self) | 1963 | super::child_opt(self) |
2667 | } | 1964 | } |
2668 | } | 1965 | } |
2669 | 1966 | ||
2670 | // ParenType | 1967 | // ParenType |
2671 | #[derive(Debug, Clone, Copy,)] | 1968 | #[derive(Debug, PartialEq, Eq, Hash)] |
2672 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1969 | #[repr(transparent)] |
2673 | pub(crate) syntax: SyntaxNode<R>, | 1970 | pub struct ParenType { |
1971 | pub(crate) syntax: SyntaxNode, | ||
2674 | } | 1972 | } |
2675 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | 1973 | unsafe impl TransparentNewType for ParenType { |
2676 | 1974 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2677 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> { | ||
2678 | fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2679 | } | ||
2680 | impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {} | ||
2681 | impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> { | ||
2682 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2683 | } | 1975 | } |
2684 | 1976 | ||
2685 | impl<'a> AstNode<'a> for ParenType<'a> { | 1977 | impl AstNode for ParenType { |
2686 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1978 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2687 | match syntax.kind() { | 1979 | match syntax.kind() { |
2688 | PAREN_TYPE => Some(ParenType { syntax }), | 1980 | PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())), |
2689 | _ => None, | 1981 | _ => None, |
2690 | } | 1982 | } |
2691 | } | 1983 | } |
2692 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1984 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2693 | } | 1985 | fn to_owned(&self) -> TreePtr<ParenType> { TreePtr::cast(self.syntax.to_owned()) } |
2694 | |||
2695 | impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> { | ||
2696 | pub fn borrowed(&self) -> ParenType { | ||
2697 | ParenTypeNode { syntax: self.syntax.borrowed() } | ||
2698 | } | ||
2699 | pub fn owned(&self) -> ParenTypeNode { | ||
2700 | ParenTypeNode { syntax: self.syntax.owned() } | ||
2701 | } | ||
2702 | } | 1986 | } |
2703 | 1987 | ||
2704 | 1988 | ||
2705 | impl<'a> ParenType<'a> { | 1989 | impl ParenType { |
2706 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1990 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2707 | super::child_opt(self) | 1991 | super::child_opt(self) |
2708 | } | 1992 | } |
2709 | } | 1993 | } |
2710 | 1994 | ||
2711 | // Pat | 1995 | // Pat |
1996 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1997 | #[repr(transparent)] | ||
1998 | pub struct Pat { | ||
1999 | pub(crate) syntax: SyntaxNode, | ||
2000 | } | ||
2001 | unsafe impl TransparentNewType for Pat { | ||
2002 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2003 | } | ||
2004 | |||
2712 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2005 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2713 | pub enum Pat<'a> { | 2006 | pub enum PatKind<'a> { |
2714 | RefPat(RefPat<'a>), | 2007 | RefPat(&'a RefPat), |
2715 | BindPat(BindPat<'a>), | 2008 | BindPat(&'a BindPat), |
2716 | PlaceholderPat(PlaceholderPat<'a>), | 2009 | PlaceholderPat(&'a PlaceholderPat), |
2717 | PathPat(PathPat<'a>), | 2010 | PathPat(&'a PathPat), |
2718 | StructPat(StructPat<'a>), | 2011 | StructPat(&'a StructPat), |
2719 | FieldPatList(FieldPatList<'a>), | 2012 | FieldPatList(&'a FieldPatList), |
2720 | TupleStructPat(TupleStructPat<'a>), | 2013 | TupleStructPat(&'a TupleStructPat), |
2721 | TuplePat(TuplePat<'a>), | 2014 | TuplePat(&'a TuplePat), |
2722 | SlicePat(SlicePat<'a>), | 2015 | SlicePat(&'a SlicePat), |
2723 | RangePat(RangePat<'a>), | 2016 | RangePat(&'a RangePat), |
2724 | } | 2017 | } |
2725 | 2018 | ||
2726 | impl<'a> AstNode<'a> for Pat<'a> { | 2019 | impl AstNode for Pat { |
2727 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2020 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2728 | match syntax.kind() { | 2021 | match syntax.kind() { |
2729 | REF_PAT => Some(Pat::RefPat(RefPat { syntax })), | 2022 | | REF_PAT |
2730 | BIND_PAT => Some(Pat::BindPat(BindPat { syntax })), | 2023 | | BIND_PAT |
2731 | PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })), | 2024 | | PLACEHOLDER_PAT |
2732 | PATH_PAT => Some(Pat::PathPat(PathPat { syntax })), | 2025 | | PATH_PAT |
2733 | STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })), | 2026 | | STRUCT_PAT |
2734 | FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })), | 2027 | | FIELD_PAT_LIST |
2735 | TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })), | 2028 | | TUPLE_STRUCT_PAT |
2736 | TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })), | 2029 | | TUPLE_PAT |
2737 | SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })), | 2030 | | SLICE_PAT |
2738 | RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })), | 2031 | | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())), |
2739 | _ => None, | 2032 | _ => None, |
2740 | } | 2033 | } |
2741 | } | 2034 | } |
2742 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2035 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2743 | match self { | 2036 | fn to_owned(&self) -> TreePtr<Pat> { TreePtr::cast(self.syntax.to_owned()) } |
2744 | Pat::RefPat(inner) => inner.syntax(), | 2037 | } |
2745 | Pat::BindPat(inner) => inner.syntax(), | 2038 | |
2746 | Pat::PlaceholderPat(inner) => inner.syntax(), | 2039 | impl Pat { |
2747 | Pat::PathPat(inner) => inner.syntax(), | 2040 | pub fn kind(&self) -> PatKind { |
2748 | Pat::StructPat(inner) => inner.syntax(), | 2041 | match self.syntax.kind() { |
2749 | Pat::FieldPatList(inner) => inner.syntax(), | 2042 | REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()), |
2750 | Pat::TupleStructPat(inner) => inner.syntax(), | 2043 | BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()), |
2751 | Pat::TuplePat(inner) => inner.syntax(), | 2044 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()), |
2752 | Pat::SlicePat(inner) => inner.syntax(), | 2045 | PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()), |
2753 | Pat::RangePat(inner) => inner.syntax(), | 2046 | STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()), |
2047 | FIELD_PAT_LIST => PatKind::FieldPatList(FieldPatList::cast(&self.syntax).unwrap()), | ||
2048 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()), | ||
2049 | TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()), | ||
2050 | SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()), | ||
2051 | RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()), | ||
2052 | _ => unreachable!(), | ||
2754 | } | 2053 | } |
2755 | } | 2054 | } |
2756 | } | 2055 | } |
2757 | 2056 | ||
2758 | impl<'a> Pat<'a> {} | 2057 | impl Pat {} |
2759 | 2058 | ||
2760 | // Path | 2059 | // Path |
2761 | #[derive(Debug, Clone, Copy,)] | 2060 | #[derive(Debug, PartialEq, Eq, Hash)] |
2762 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2061 | #[repr(transparent)] |
2763 | pub(crate) syntax: SyntaxNode<R>, | 2062 | pub struct Path { |
2764 | } | 2063 | pub(crate) syntax: SyntaxNode, |
2765 | pub type Path<'a> = PathNode<RefRoot<'a>>; | ||
2766 | |||
2767 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> { | ||
2768 | fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax } | ||
2769 | } | 2064 | } |
2770 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} | 2065 | unsafe impl TransparentNewType for Path { |
2771 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { | 2066 | type Repr = rowan::SyntaxNode<RaTypes>; |
2772 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2773 | } | 2067 | } |
2774 | 2068 | ||
2775 | impl<'a> AstNode<'a> for Path<'a> { | 2069 | impl AstNode for Path { |
2776 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2070 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2777 | match syntax.kind() { | 2071 | match syntax.kind() { |
2778 | PATH => Some(Path { syntax }), | 2072 | PATH => Some(Path::from_repr(syntax.into_repr())), |
2779 | _ => None, | 2073 | _ => None, |
2780 | } | 2074 | } |
2781 | } | 2075 | } |
2782 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2076 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2783 | } | 2077 | fn to_owned(&self) -> TreePtr<Path> { TreePtr::cast(self.syntax.to_owned()) } |
2784 | |||
2785 | impl<R: TreeRoot<RaTypes>> PathNode<R> { | ||
2786 | pub fn borrowed(&self) -> Path { | ||
2787 | PathNode { syntax: self.syntax.borrowed() } | ||
2788 | } | ||
2789 | pub fn owned(&self) -> PathNode { | ||
2790 | PathNode { syntax: self.syntax.owned() } | ||
2791 | } | ||
2792 | } | 2078 | } |
2793 | 2079 | ||
2794 | 2080 | ||
2795 | impl<'a> Path<'a> { | 2081 | impl Path { |
2796 | pub fn segment(self) -> Option<PathSegment<'a>> { | 2082 | pub fn segment(&self) -> Option<&PathSegment> { |
2797 | super::child_opt(self) | 2083 | super::child_opt(self) |
2798 | } | 2084 | } |
2799 | 2085 | ||
2800 | pub fn qualifier(self) -> Option<Path<'a>> { | 2086 | pub fn qualifier(&self) -> Option<&Path> { |
2801 | super::child_opt(self) | 2087 | super::child_opt(self) |
2802 | } | 2088 | } |
2803 | } | 2089 | } |
2804 | 2090 | ||
2805 | // PathExpr | 2091 | // PathExpr |
2806 | #[derive(Debug, Clone, Copy,)] | 2092 | #[derive(Debug, PartialEq, Eq, Hash)] |
2807 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2093 | #[repr(transparent)] |
2808 | pub(crate) syntax: SyntaxNode<R>, | 2094 | pub struct PathExpr { |
2095 | pub(crate) syntax: SyntaxNode, | ||
2809 | } | 2096 | } |
2810 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | 2097 | unsafe impl TransparentNewType for PathExpr { |
2811 | 2098 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2812 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> { | ||
2813 | fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2814 | } | ||
2815 | impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {} | ||
2816 | impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> { | ||
2817 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2818 | } | 2099 | } |
2819 | 2100 | ||
2820 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2101 | impl AstNode for PathExpr { |
2821 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2102 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2822 | match syntax.kind() { | 2103 | match syntax.kind() { |
2823 | PATH_EXPR => Some(PathExpr { syntax }), | 2104 | PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())), |
2824 | _ => None, | 2105 | _ => None, |
2825 | } | 2106 | } |
2826 | } | 2107 | } |
2827 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2108 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2828 | } | 2109 | fn to_owned(&self) -> TreePtr<PathExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2829 | |||
2830 | impl<R: TreeRoot<RaTypes>> PathExprNode<R> { | ||
2831 | pub fn borrowed(&self) -> PathExpr { | ||
2832 | PathExprNode { syntax: self.syntax.borrowed() } | ||
2833 | } | ||
2834 | pub fn owned(&self) -> PathExprNode { | ||
2835 | PathExprNode { syntax: self.syntax.owned() } | ||
2836 | } | ||
2837 | } | 2110 | } |
2838 | 2111 | ||
2839 | 2112 | ||
2840 | impl<'a> PathExpr<'a> { | 2113 | impl PathExpr { |
2841 | pub fn path(self) -> Option<Path<'a>> { | 2114 | pub fn path(&self) -> Option<&Path> { |
2842 | super::child_opt(self) | 2115 | super::child_opt(self) |
2843 | } | 2116 | } |
2844 | } | 2117 | } |
2845 | 2118 | ||
2846 | // PathPat | 2119 | // PathPat |
2847 | #[derive(Debug, Clone, Copy,)] | 2120 | #[derive(Debug, PartialEq, Eq, Hash)] |
2848 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2121 | #[repr(transparent)] |
2849 | pub(crate) syntax: SyntaxNode<R>, | 2122 | pub struct PathPat { |
2123 | pub(crate) syntax: SyntaxNode, | ||
2850 | } | 2124 | } |
2851 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | 2125 | unsafe impl TransparentNewType for PathPat { |
2852 | 2126 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2853 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> { | ||
2854 | fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2855 | } | ||
2856 | impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {} | ||
2857 | impl<R: TreeRoot<RaTypes>> Hash for PathPatNode<R> { | ||
2858 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2859 | } | 2127 | } |
2860 | 2128 | ||
2861 | impl<'a> AstNode<'a> for PathPat<'a> { | 2129 | impl AstNode for PathPat { |
2862 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2130 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2863 | match syntax.kind() { | 2131 | match syntax.kind() { |
2864 | PATH_PAT => Some(PathPat { syntax }), | 2132 | PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())), |
2865 | _ => None, | 2133 | _ => None, |
2866 | } | 2134 | } |
2867 | } | 2135 | } |
2868 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2136 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2869 | } | 2137 | fn to_owned(&self) -> TreePtr<PathPat> { TreePtr::cast(self.syntax.to_owned()) } |
2870 | |||
2871 | impl<R: TreeRoot<RaTypes>> PathPatNode<R> { | ||
2872 | pub fn borrowed(&self) -> PathPat { | ||
2873 | PathPatNode { syntax: self.syntax.borrowed() } | ||
2874 | } | ||
2875 | pub fn owned(&self) -> PathPatNode { | ||
2876 | PathPatNode { syntax: self.syntax.owned() } | ||
2877 | } | ||
2878 | } | 2138 | } |
2879 | 2139 | ||
2880 | 2140 | ||
2881 | impl<'a> PathPat<'a> {} | 2141 | impl PathPat {} |
2882 | 2142 | ||
2883 | // PathSegment | 2143 | // PathSegment |
2884 | #[derive(Debug, Clone, Copy,)] | 2144 | #[derive(Debug, PartialEq, Eq, Hash)] |
2885 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2145 | #[repr(transparent)] |
2886 | pub(crate) syntax: SyntaxNode<R>, | 2146 | pub struct PathSegment { |
2887 | } | 2147 | pub(crate) syntax: SyntaxNode, |
2888 | pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>; | ||
2889 | |||
2890 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathSegmentNode<R1>> for PathSegmentNode<R2> { | ||
2891 | fn eq(&self, other: &PathSegmentNode<R1>) -> bool { self.syntax == other.syntax } | ||
2892 | } | 2148 | } |
2893 | impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} | 2149 | unsafe impl TransparentNewType for PathSegment { |
2894 | impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { | 2150 | type Repr = rowan::SyntaxNode<RaTypes>; |
2895 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2896 | } | 2151 | } |
2897 | 2152 | ||
2898 | impl<'a> AstNode<'a> for PathSegment<'a> { | 2153 | impl AstNode for PathSegment { |
2899 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2154 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2900 | match syntax.kind() { | 2155 | match syntax.kind() { |
2901 | PATH_SEGMENT => Some(PathSegment { syntax }), | 2156 | PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())), |
2902 | _ => None, | 2157 | _ => None, |
2903 | } | 2158 | } |
2904 | } | 2159 | } |
2905 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2160 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2161 | fn to_owned(&self) -> TreePtr<PathSegment> { TreePtr::cast(self.syntax.to_owned()) } | ||
2906 | } | 2162 | } |
2907 | 2163 | ||
2908 | impl<R: TreeRoot<RaTypes>> PathSegmentNode<R> { | ||
2909 | pub fn borrowed(&self) -> PathSegment { | ||
2910 | PathSegmentNode { syntax: self.syntax.borrowed() } | ||
2911 | } | ||
2912 | pub fn owned(&self) -> PathSegmentNode { | ||
2913 | PathSegmentNode { syntax: self.syntax.owned() } | ||
2914 | } | ||
2915 | } | ||
2916 | 2164 | ||
2917 | 2165 | impl PathSegment { | |
2918 | impl<'a> PathSegment<'a> { | 2166 | pub fn name_ref(&self) -> Option<&NameRef> { |
2919 | pub fn name_ref(self) -> Option<NameRef<'a>> { | ||
2920 | super::child_opt(self) | 2167 | super::child_opt(self) |
2921 | } | 2168 | } |
2922 | } | 2169 | } |
2923 | 2170 | ||
2924 | // PathType | 2171 | // PathType |
2925 | #[derive(Debug, Clone, Copy,)] | 2172 | #[derive(Debug, PartialEq, Eq, Hash)] |
2926 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2173 | #[repr(transparent)] |
2927 | pub(crate) syntax: SyntaxNode<R>, | 2174 | pub struct PathType { |
2928 | } | 2175 | pub(crate) syntax: SyntaxNode, |
2929 | pub type PathType<'a> = PathTypeNode<RefRoot<'a>>; | ||
2930 | |||
2931 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathTypeNode<R1>> for PathTypeNode<R2> { | ||
2932 | fn eq(&self, other: &PathTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2933 | } | 2176 | } |
2934 | impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} | 2177 | unsafe impl TransparentNewType for PathType { |
2935 | impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { | 2178 | type Repr = rowan::SyntaxNode<RaTypes>; |
2936 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2937 | } | 2179 | } |
2938 | 2180 | ||
2939 | impl<'a> AstNode<'a> for PathType<'a> { | 2181 | impl AstNode for PathType { |
2940 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2182 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2941 | match syntax.kind() { | 2183 | match syntax.kind() { |
2942 | PATH_TYPE => Some(PathType { syntax }), | 2184 | PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())), |
2943 | _ => None, | 2185 | _ => None, |
2944 | } | 2186 | } |
2945 | } | 2187 | } |
2946 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2188 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2947 | } | 2189 | fn to_owned(&self) -> TreePtr<PathType> { TreePtr::cast(self.syntax.to_owned()) } |
2948 | |||
2949 | impl<R: TreeRoot<RaTypes>> PathTypeNode<R> { | ||
2950 | pub fn borrowed(&self) -> PathType { | ||
2951 | PathTypeNode { syntax: self.syntax.borrowed() } | ||
2952 | } | ||
2953 | pub fn owned(&self) -> PathTypeNode { | ||
2954 | PathTypeNode { syntax: self.syntax.owned() } | ||
2955 | } | ||
2956 | } | 2190 | } |
2957 | 2191 | ||
2958 | 2192 | ||
2959 | impl<'a> PathType<'a> { | 2193 | impl PathType { |
2960 | pub fn path(self) -> Option<Path<'a>> { | 2194 | pub fn path(&self) -> Option<&Path> { |
2961 | super::child_opt(self) | 2195 | super::child_opt(self) |
2962 | } | 2196 | } |
2963 | } | 2197 | } |
2964 | 2198 | ||
2965 | // PlaceholderPat | 2199 | // PlaceholderPat |
2966 | #[derive(Debug, Clone, Copy,)] | 2200 | #[derive(Debug, PartialEq, Eq, Hash)] |
2967 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2201 | #[repr(transparent)] |
2968 | pub(crate) syntax: SyntaxNode<R>, | 2202 | pub struct PlaceholderPat { |
2203 | pub(crate) syntax: SyntaxNode, | ||
2969 | } | 2204 | } |
2970 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; | 2205 | unsafe impl TransparentNewType for PlaceholderPat { |
2971 | 2206 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2972 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderPatNode<R1>> for PlaceholderPatNode<R2> { | ||
2973 | fn eq(&self, other: &PlaceholderPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2974 | } | ||
2975 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderPatNode<R> {} | ||
2976 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderPatNode<R> { | ||
2977 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2978 | } | 2207 | } |
2979 | 2208 | ||
2980 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { | 2209 | impl AstNode for PlaceholderPat { |
2981 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2210 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2982 | match syntax.kind() { | 2211 | match syntax.kind() { |
2983 | PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), | 2212 | PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())), |
2984 | _ => None, | 2213 | _ => None, |
2985 | } | 2214 | } |
2986 | } | 2215 | } |
2987 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2216 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2988 | } | 2217 | fn to_owned(&self) -> TreePtr<PlaceholderPat> { TreePtr::cast(self.syntax.to_owned()) } |
2989 | |||
2990 | impl<R: TreeRoot<RaTypes>> PlaceholderPatNode<R> { | ||
2991 | pub fn borrowed(&self) -> PlaceholderPat { | ||
2992 | PlaceholderPatNode { syntax: self.syntax.borrowed() } | ||
2993 | } | ||
2994 | pub fn owned(&self) -> PlaceholderPatNode { | ||
2995 | PlaceholderPatNode { syntax: self.syntax.owned() } | ||
2996 | } | ||
2997 | } | 2218 | } |
2998 | 2219 | ||
2999 | 2220 | ||
3000 | impl<'a> PlaceholderPat<'a> {} | 2221 | impl PlaceholderPat {} |
3001 | 2222 | ||
3002 | // PlaceholderType | 2223 | // PlaceholderType |
3003 | #[derive(Debug, Clone, Copy,)] | 2224 | #[derive(Debug, PartialEq, Eq, Hash)] |
3004 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2225 | #[repr(transparent)] |
3005 | pub(crate) syntax: SyntaxNode<R>, | 2226 | pub struct PlaceholderType { |
2227 | pub(crate) syntax: SyntaxNode, | ||
3006 | } | 2228 | } |
3007 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; | 2229 | unsafe impl TransparentNewType for PlaceholderType { |
3008 | 2230 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3009 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderTypeNode<R1>> for PlaceholderTypeNode<R2> { | ||
3010 | fn eq(&self, other: &PlaceholderTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3011 | } | ||
3012 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderTypeNode<R> {} | ||
3013 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderTypeNode<R> { | ||
3014 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3015 | } | 2231 | } |
3016 | 2232 | ||
3017 | impl<'a> AstNode<'a> for PlaceholderType<'a> { | 2233 | impl AstNode for PlaceholderType { |
3018 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2234 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3019 | match syntax.kind() { | 2235 | match syntax.kind() { |
3020 | PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), | 2236 | PLACEHOLDER_TYPE => Some(PlaceholderType::from_repr(syntax.into_repr())), |
3021 | _ => None, | 2237 | _ => None, |
3022 | } | 2238 | } |
3023 | } | 2239 | } |
3024 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2240 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3025 | } | 2241 | fn to_owned(&self) -> TreePtr<PlaceholderType> { TreePtr::cast(self.syntax.to_owned()) } |
3026 | |||
3027 | impl<R: TreeRoot<RaTypes>> PlaceholderTypeNode<R> { | ||
3028 | pub fn borrowed(&self) -> PlaceholderType { | ||
3029 | PlaceholderTypeNode { syntax: self.syntax.borrowed() } | ||
3030 | } | ||
3031 | pub fn owned(&self) -> PlaceholderTypeNode { | ||
3032 | PlaceholderTypeNode { syntax: self.syntax.owned() } | ||
3033 | } | ||
3034 | } | 2242 | } |
3035 | 2243 | ||
3036 | 2244 | ||
3037 | impl<'a> PlaceholderType<'a> {} | 2245 | impl PlaceholderType {} |
3038 | 2246 | ||
3039 | // PointerType | 2247 | // PointerType |
3040 | #[derive(Debug, Clone, Copy,)] | 2248 | #[derive(Debug, PartialEq, Eq, Hash)] |
3041 | pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2249 | #[repr(transparent)] |
3042 | pub(crate) syntax: SyntaxNode<R>, | 2250 | pub struct PointerType { |
3043 | } | 2251 | pub(crate) syntax: SyntaxNode, |
3044 | pub type PointerType<'a> = PointerTypeNode<RefRoot<'a>>; | ||
3045 | |||
3046 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PointerTypeNode<R1>> for PointerTypeNode<R2> { | ||
3047 | fn eq(&self, other: &PointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3048 | } | 2252 | } |
3049 | impl<R: TreeRoot<RaTypes>> Eq for PointerTypeNode<R> {} | 2253 | unsafe impl TransparentNewType for PointerType { |
3050 | impl<R: TreeRoot<RaTypes>> Hash for PointerTypeNode<R> { | 2254 | type Repr = rowan::SyntaxNode<RaTypes>; |
3051 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3052 | } | 2255 | } |
3053 | 2256 | ||
3054 | impl<'a> AstNode<'a> for PointerType<'a> { | 2257 | impl AstNode for PointerType { |
3055 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2258 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3056 | match syntax.kind() { | 2259 | match syntax.kind() { |
3057 | POINTER_TYPE => Some(PointerType { syntax }), | 2260 | POINTER_TYPE => Some(PointerType::from_repr(syntax.into_repr())), |
3058 | _ => None, | 2261 | _ => None, |
3059 | } | 2262 | } |
3060 | } | 2263 | } |
3061 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2264 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2265 | fn to_owned(&self) -> TreePtr<PointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
3062 | } | 2266 | } |
3063 | 2267 | ||
3064 | impl<R: TreeRoot<RaTypes>> PointerTypeNode<R> { | ||
3065 | pub fn borrowed(&self) -> PointerType { | ||
3066 | PointerTypeNode { syntax: self.syntax.borrowed() } | ||
3067 | } | ||
3068 | pub fn owned(&self) -> PointerTypeNode { | ||
3069 | PointerTypeNode { syntax: self.syntax.owned() } | ||
3070 | } | ||
3071 | } | ||
3072 | 2268 | ||
3073 | 2269 | impl PointerType { | |
3074 | impl<'a> PointerType<'a> { | 2270 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3075 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
3076 | super::child_opt(self) | 2271 | super::child_opt(self) |
3077 | } | 2272 | } |
3078 | } | 2273 | } |
3079 | 2274 | ||
3080 | // PosField | 2275 | // PosField |
3081 | #[derive(Debug, Clone, Copy,)] | 2276 | #[derive(Debug, PartialEq, Eq, Hash)] |
3082 | pub struct PosFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2277 | #[repr(transparent)] |
3083 | pub(crate) syntax: SyntaxNode<R>, | 2278 | pub struct PosField { |
3084 | } | 2279 | pub(crate) syntax: SyntaxNode, |
3085 | pub type PosField<'a> = PosFieldNode<RefRoot<'a>>; | ||
3086 | |||
3087 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldNode<R1>> for PosFieldNode<R2> { | ||
3088 | fn eq(&self, other: &PosFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
3089 | } | 2280 | } |
3090 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldNode<R> {} | 2281 | unsafe impl TransparentNewType for PosField { |
3091 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldNode<R> { | 2282 | type Repr = rowan::SyntaxNode<RaTypes>; |
3092 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3093 | } | 2283 | } |
3094 | 2284 | ||
3095 | impl<'a> AstNode<'a> for PosField<'a> { | 2285 | impl AstNode for PosField { |
3096 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2286 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3097 | match syntax.kind() { | 2287 | match syntax.kind() { |
3098 | POS_FIELD => Some(PosField { syntax }), | 2288 | POS_FIELD => Some(PosField::from_repr(syntax.into_repr())), |
3099 | _ => None, | 2289 | _ => None, |
3100 | } | 2290 | } |
3101 | } | 2291 | } |
3102 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2292 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3103 | } | 2293 | fn to_owned(&self) -> TreePtr<PosField> { TreePtr::cast(self.syntax.to_owned()) } |
3104 | |||
3105 | impl<R: TreeRoot<RaTypes>> PosFieldNode<R> { | ||
3106 | pub fn borrowed(&self) -> PosField { | ||
3107 | PosFieldNode { syntax: self.syntax.borrowed() } | ||
3108 | } | ||
3109 | pub fn owned(&self) -> PosFieldNode { | ||
3110 | PosFieldNode { syntax: self.syntax.owned() } | ||
3111 | } | ||
3112 | } | 2294 | } |
3113 | 2295 | ||
3114 | 2296 | ||
3115 | impl<'a> ast::VisibilityOwner<'a> for PosField<'a> {} | 2297 | impl ast::VisibilityOwner for PosField {} |
3116 | impl<'a> ast::AttrsOwner<'a> for PosField<'a> {} | 2298 | impl ast::AttrsOwner for PosField {} |
3117 | impl<'a> PosField<'a> { | 2299 | impl PosField { |
3118 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2300 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3119 | super::child_opt(self) | 2301 | super::child_opt(self) |
3120 | } | 2302 | } |
3121 | } | 2303 | } |
3122 | 2304 | ||
3123 | // PosFieldList | 2305 | // PosFieldList |
3124 | #[derive(Debug, Clone, Copy,)] | 2306 | #[derive(Debug, PartialEq, Eq, Hash)] |
3125 | pub struct PosFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2307 | #[repr(transparent)] |
3126 | pub(crate) syntax: SyntaxNode<R>, | 2308 | pub struct PosFieldList { |
3127 | } | 2309 | pub(crate) syntax: SyntaxNode, |
3128 | pub type PosFieldList<'a> = PosFieldListNode<RefRoot<'a>>; | ||
3129 | |||
3130 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldListNode<R1>> for PosFieldListNode<R2> { | ||
3131 | fn eq(&self, other: &PosFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
3132 | } | 2310 | } |
3133 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldListNode<R> {} | 2311 | unsafe impl TransparentNewType for PosFieldList { |
3134 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldListNode<R> { | 2312 | type Repr = rowan::SyntaxNode<RaTypes>; |
3135 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3136 | } | 2313 | } |
3137 | 2314 | ||
3138 | impl<'a> AstNode<'a> for PosFieldList<'a> { | 2315 | impl AstNode for PosFieldList { |
3139 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2316 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3140 | match syntax.kind() { | 2317 | match syntax.kind() { |
3141 | POS_FIELD_LIST => Some(PosFieldList { syntax }), | 2318 | POS_FIELD_LIST => Some(PosFieldList::from_repr(syntax.into_repr())), |
3142 | _ => None, | 2319 | _ => None, |
3143 | } | 2320 | } |
3144 | } | 2321 | } |
3145 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2322 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3146 | } | 2323 | fn to_owned(&self) -> TreePtr<PosFieldList> { TreePtr::cast(self.syntax.to_owned()) } |
3147 | |||
3148 | impl<R: TreeRoot<RaTypes>> PosFieldListNode<R> { | ||
3149 | pub fn borrowed(&self) -> PosFieldList { | ||
3150 | PosFieldListNode { syntax: self.syntax.borrowed() } | ||
3151 | } | ||
3152 | pub fn owned(&self) -> PosFieldListNode { | ||
3153 | PosFieldListNode { syntax: self.syntax.owned() } | ||
3154 | } | ||
3155 | } | 2324 | } |
3156 | 2325 | ||
3157 | 2326 | ||
3158 | impl<'a> PosFieldList<'a> { | 2327 | impl PosFieldList { |
3159 | pub fn fields(self) -> impl Iterator<Item = PosField<'a>> + 'a { | 2328 | pub fn fields(&self) -> impl Iterator<Item = &PosField> { |
3160 | super::children(self) | 2329 | super::children(self) |
3161 | } | 2330 | } |
3162 | } | 2331 | } |
3163 | 2332 | ||
3164 | // PrefixExpr | 2333 | // PrefixExpr |
3165 | #[derive(Debug, Clone, Copy,)] | 2334 | #[derive(Debug, PartialEq, Eq, Hash)] |
3166 | pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2335 | #[repr(transparent)] |
3167 | pub(crate) syntax: SyntaxNode<R>, | 2336 | pub struct PrefixExpr { |
2337 | pub(crate) syntax: SyntaxNode, | ||
3168 | } | 2338 | } |
3169 | pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; | 2339 | unsafe impl TransparentNewType for PrefixExpr { |
3170 | 2340 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3171 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PrefixExprNode<R1>> for PrefixExprNode<R2> { | ||
3172 | fn eq(&self, other: &PrefixExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3173 | } | ||
3174 | impl<R: TreeRoot<RaTypes>> Eq for PrefixExprNode<R> {} | ||
3175 | impl<R: TreeRoot<RaTypes>> Hash for PrefixExprNode<R> { | ||
3176 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3177 | } | 2341 | } |
3178 | 2342 | ||
3179 | impl<'a> AstNode<'a> for PrefixExpr<'a> { | 2343 | impl AstNode for PrefixExpr { |
3180 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2344 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3181 | match syntax.kind() { | 2345 | match syntax.kind() { |
3182 | PREFIX_EXPR => Some(PrefixExpr { syntax }), | 2346 | PREFIX_EXPR => Some(PrefixExpr::from_repr(syntax.into_repr())), |
3183 | _ => None, | 2347 | _ => None, |
3184 | } | 2348 | } |
3185 | } | 2349 | } |
3186 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2350 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3187 | } | 2351 | fn to_owned(&self) -> TreePtr<PrefixExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3188 | |||
3189 | impl<R: TreeRoot<RaTypes>> PrefixExprNode<R> { | ||
3190 | pub fn borrowed(&self) -> PrefixExpr { | ||
3191 | PrefixExprNode { syntax: self.syntax.borrowed() } | ||
3192 | } | ||
3193 | pub fn owned(&self) -> PrefixExprNode { | ||
3194 | PrefixExprNode { syntax: self.syntax.owned() } | ||
3195 | } | ||
3196 | } | 2352 | } |
3197 | 2353 | ||
3198 | 2354 | ||
3199 | impl<'a> PrefixExpr<'a> { | 2355 | impl PrefixExpr { |
3200 | pub fn expr(self) -> Option<Expr<'a>> { | 2356 | pub fn expr(&self) -> Option<&Expr> { |
3201 | super::child_opt(self) | 2357 | super::child_opt(self) |
3202 | } | 2358 | } |
3203 | } | 2359 | } |
3204 | 2360 | ||
3205 | // RangeExpr | 2361 | // RangeExpr |
3206 | #[derive(Debug, Clone, Copy,)] | 2362 | #[derive(Debug, PartialEq, Eq, Hash)] |
3207 | pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2363 | #[repr(transparent)] |
3208 | pub(crate) syntax: SyntaxNode<R>, | 2364 | pub struct RangeExpr { |
3209 | } | 2365 | pub(crate) syntax: SyntaxNode, |
3210 | pub type RangeExpr<'a> = RangeExprNode<RefRoot<'a>>; | ||
3211 | |||
3212 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangeExprNode<R1>> for RangeExprNode<R2> { | ||
3213 | fn eq(&self, other: &RangeExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3214 | } | 2366 | } |
3215 | impl<R: TreeRoot<RaTypes>> Eq for RangeExprNode<R> {} | 2367 | unsafe impl TransparentNewType for RangeExpr { |
3216 | impl<R: TreeRoot<RaTypes>> Hash for RangeExprNode<R> { | 2368 | type Repr = rowan::SyntaxNode<RaTypes>; |
3217 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3218 | } | 2369 | } |
3219 | 2370 | ||
3220 | impl<'a> AstNode<'a> for RangeExpr<'a> { | 2371 | impl AstNode for RangeExpr { |
3221 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2372 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3222 | match syntax.kind() { | 2373 | match syntax.kind() { |
3223 | RANGE_EXPR => Some(RangeExpr { syntax }), | 2374 | RANGE_EXPR => Some(RangeExpr::from_repr(syntax.into_repr())), |
3224 | _ => None, | 2375 | _ => None, |
3225 | } | 2376 | } |
3226 | } | 2377 | } |
3227 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2378 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2379 | fn to_owned(&self) -> TreePtr<RangeExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
3228 | } | 2380 | } |
3229 | 2381 | ||
3230 | impl<R: TreeRoot<RaTypes>> RangeExprNode<R> { | ||
3231 | pub fn borrowed(&self) -> RangeExpr { | ||
3232 | RangeExprNode { syntax: self.syntax.borrowed() } | ||
3233 | } | ||
3234 | pub fn owned(&self) -> RangeExprNode { | ||
3235 | RangeExprNode { syntax: self.syntax.owned() } | ||
3236 | } | ||
3237 | } | ||
3238 | 2382 | ||
3239 | 2383 | impl RangeExpr {} | |
3240 | impl<'a> RangeExpr<'a> {} | ||
3241 | 2384 | ||
3242 | // RangePat | 2385 | // RangePat |
3243 | #[derive(Debug, Clone, Copy,)] | 2386 | #[derive(Debug, PartialEq, Eq, Hash)] |
3244 | pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2387 | #[repr(transparent)] |
3245 | pub(crate) syntax: SyntaxNode<R>, | 2388 | pub struct RangePat { |
2389 | pub(crate) syntax: SyntaxNode, | ||
3246 | } | 2390 | } |
3247 | pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; | 2391 | unsafe impl TransparentNewType for RangePat { |
3248 | 2392 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3249 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangePatNode<R1>> for RangePatNode<R2> { | ||
3250 | fn eq(&self, other: &RangePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3251 | } | ||
3252 | impl<R: TreeRoot<RaTypes>> Eq for RangePatNode<R> {} | ||
3253 | impl<R: TreeRoot<RaTypes>> Hash for RangePatNode<R> { | ||
3254 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3255 | } | 2393 | } |
3256 | 2394 | ||
3257 | impl<'a> AstNode<'a> for RangePat<'a> { | 2395 | impl AstNode for RangePat { |
3258 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2396 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3259 | match syntax.kind() { | 2397 | match syntax.kind() { |
3260 | RANGE_PAT => Some(RangePat { syntax }), | 2398 | RANGE_PAT => Some(RangePat::from_repr(syntax.into_repr())), |
3261 | _ => None, | 2399 | _ => None, |
3262 | } | 2400 | } |
3263 | } | 2401 | } |
3264 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2402 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3265 | } | 2403 | fn to_owned(&self) -> TreePtr<RangePat> { TreePtr::cast(self.syntax.to_owned()) } |
3266 | |||
3267 | impl<R: TreeRoot<RaTypes>> RangePatNode<R> { | ||
3268 | pub fn borrowed(&self) -> RangePat { | ||
3269 | RangePatNode { syntax: self.syntax.borrowed() } | ||
3270 | } | ||
3271 | pub fn owned(&self) -> RangePatNode { | ||
3272 | RangePatNode { syntax: self.syntax.owned() } | ||
3273 | } | ||
3274 | } | 2404 | } |
3275 | 2405 | ||
3276 | 2406 | ||
3277 | impl<'a> RangePat<'a> {} | 2407 | impl RangePat {} |
3278 | 2408 | ||
3279 | // RefExpr | 2409 | // RefExpr |
3280 | #[derive(Debug, Clone, Copy,)] | 2410 | #[derive(Debug, PartialEq, Eq, Hash)] |
3281 | pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2411 | #[repr(transparent)] |
3282 | pub(crate) syntax: SyntaxNode<R>, | 2412 | pub struct RefExpr { |
2413 | pub(crate) syntax: SyntaxNode, | ||
3283 | } | 2414 | } |
3284 | pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; | 2415 | unsafe impl TransparentNewType for RefExpr { |
3285 | 2416 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3286 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefExprNode<R1>> for RefExprNode<R2> { | ||
3287 | fn eq(&self, other: &RefExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3288 | } | ||
3289 | impl<R: TreeRoot<RaTypes>> Eq for RefExprNode<R> {} | ||
3290 | impl<R: TreeRoot<RaTypes>> Hash for RefExprNode<R> { | ||
3291 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3292 | } | 2417 | } |
3293 | 2418 | ||
3294 | impl<'a> AstNode<'a> for RefExpr<'a> { | 2419 | impl AstNode for RefExpr { |
3295 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2420 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3296 | match syntax.kind() { | 2421 | match syntax.kind() { |
3297 | REF_EXPR => Some(RefExpr { syntax }), | 2422 | REF_EXPR => Some(RefExpr::from_repr(syntax.into_repr())), |
3298 | _ => None, | 2423 | _ => None, |
3299 | } | 2424 | } |
3300 | } | 2425 | } |
3301 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2426 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3302 | } | 2427 | fn to_owned(&self) -> TreePtr<RefExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3303 | |||
3304 | impl<R: TreeRoot<RaTypes>> RefExprNode<R> { | ||
3305 | pub fn borrowed(&self) -> RefExpr { | ||
3306 | RefExprNode { syntax: self.syntax.borrowed() } | ||
3307 | } | ||
3308 | pub fn owned(&self) -> RefExprNode { | ||
3309 | RefExprNode { syntax: self.syntax.owned() } | ||
3310 | } | ||
3311 | } | 2428 | } |
3312 | 2429 | ||
3313 | 2430 | ||
3314 | impl<'a> RefExpr<'a> { | 2431 | impl RefExpr { |
3315 | pub fn expr(self) -> Option<Expr<'a>> { | 2432 | pub fn expr(&self) -> Option<&Expr> { |
3316 | super::child_opt(self) | 2433 | super::child_opt(self) |
3317 | } | 2434 | } |
3318 | } | 2435 | } |
3319 | 2436 | ||
3320 | // RefPat | 2437 | // RefPat |
3321 | #[derive(Debug, Clone, Copy,)] | 2438 | #[derive(Debug, PartialEq, Eq, Hash)] |
3322 | pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2439 | #[repr(transparent)] |
3323 | pub(crate) syntax: SyntaxNode<R>, | 2440 | pub struct RefPat { |
2441 | pub(crate) syntax: SyntaxNode, | ||
3324 | } | 2442 | } |
3325 | pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; | 2443 | unsafe impl TransparentNewType for RefPat { |
3326 | 2444 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3327 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefPatNode<R1>> for RefPatNode<R2> { | ||
3328 | fn eq(&self, other: &RefPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3329 | } | ||
3330 | impl<R: TreeRoot<RaTypes>> Eq for RefPatNode<R> {} | ||
3331 | impl<R: TreeRoot<RaTypes>> Hash for RefPatNode<R> { | ||
3332 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3333 | } | 2445 | } |
3334 | 2446 | ||
3335 | impl<'a> AstNode<'a> for RefPat<'a> { | 2447 | impl AstNode for RefPat { |
3336 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2448 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3337 | match syntax.kind() { | 2449 | match syntax.kind() { |
3338 | REF_PAT => Some(RefPat { syntax }), | 2450 | REF_PAT => Some(RefPat::from_repr(syntax.into_repr())), |
3339 | _ => None, | 2451 | _ => None, |
3340 | } | 2452 | } |
3341 | } | 2453 | } |
3342 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2454 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3343 | } | 2455 | fn to_owned(&self) -> TreePtr<RefPat> { TreePtr::cast(self.syntax.to_owned()) } |
3344 | |||
3345 | impl<R: TreeRoot<RaTypes>> RefPatNode<R> { | ||
3346 | pub fn borrowed(&self) -> RefPat { | ||
3347 | RefPatNode { syntax: self.syntax.borrowed() } | ||
3348 | } | ||
3349 | pub fn owned(&self) -> RefPatNode { | ||
3350 | RefPatNode { syntax: self.syntax.owned() } | ||
3351 | } | ||
3352 | } | 2456 | } |
3353 | 2457 | ||
3354 | 2458 | ||
3355 | impl<'a> RefPat<'a> {} | 2459 | impl RefPat {} |
3356 | 2460 | ||
3357 | // ReferenceType | 2461 | // ReferenceType |
3358 | #[derive(Debug, Clone, Copy,)] | 2462 | #[derive(Debug, PartialEq, Eq, Hash)] |
3359 | pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2463 | #[repr(transparent)] |
3360 | pub(crate) syntax: SyntaxNode<R>, | 2464 | pub struct ReferenceType { |
3361 | } | 2465 | pub(crate) syntax: SyntaxNode, |
3362 | pub type ReferenceType<'a> = ReferenceTypeNode<RefRoot<'a>>; | ||
3363 | |||
3364 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReferenceTypeNode<R1>> for ReferenceTypeNode<R2> { | ||
3365 | fn eq(&self, other: &ReferenceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3366 | } | 2466 | } |
3367 | impl<R: TreeRoot<RaTypes>> Eq for ReferenceTypeNode<R> {} | 2467 | unsafe impl TransparentNewType for ReferenceType { |
3368 | impl<R: TreeRoot<RaTypes>> Hash for ReferenceTypeNode<R> { | 2468 | type Repr = rowan::SyntaxNode<RaTypes>; |
3369 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3370 | } | 2469 | } |
3371 | 2470 | ||
3372 | impl<'a> AstNode<'a> for ReferenceType<'a> { | 2471 | impl AstNode for ReferenceType { |
3373 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2472 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3374 | match syntax.kind() { | 2473 | match syntax.kind() { |
3375 | REFERENCE_TYPE => Some(ReferenceType { syntax }), | 2474 | REFERENCE_TYPE => Some(ReferenceType::from_repr(syntax.into_repr())), |
3376 | _ => None, | 2475 | _ => None, |
3377 | } | 2476 | } |
3378 | } | 2477 | } |
3379 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2478 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3380 | } | 2479 | fn to_owned(&self) -> TreePtr<ReferenceType> { TreePtr::cast(self.syntax.to_owned()) } |
3381 | |||
3382 | impl<R: TreeRoot<RaTypes>> ReferenceTypeNode<R> { | ||
3383 | pub fn borrowed(&self) -> ReferenceType { | ||
3384 | ReferenceTypeNode { syntax: self.syntax.borrowed() } | ||
3385 | } | ||
3386 | pub fn owned(&self) -> ReferenceTypeNode { | ||
3387 | ReferenceTypeNode { syntax: self.syntax.owned() } | ||
3388 | } | ||
3389 | } | 2480 | } |
3390 | 2481 | ||
3391 | 2482 | ||
3392 | impl<'a> ReferenceType<'a> { | 2483 | impl ReferenceType { |
3393 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2484 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3394 | super::child_opt(self) | 2485 | super::child_opt(self) |
3395 | } | 2486 | } |
3396 | } | 2487 | } |
3397 | 2488 | ||
3398 | // RetType | 2489 | // RetType |
3399 | #[derive(Debug, Clone, Copy,)] | 2490 | #[derive(Debug, PartialEq, Eq, Hash)] |
3400 | pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2491 | #[repr(transparent)] |
3401 | pub(crate) syntax: SyntaxNode<R>, | 2492 | pub struct RetType { |
3402 | } | 2493 | pub(crate) syntax: SyntaxNode, |
3403 | pub type RetType<'a> = RetTypeNode<RefRoot<'a>>; | ||
3404 | |||
3405 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RetTypeNode<R1>> for RetTypeNode<R2> { | ||
3406 | fn eq(&self, other: &RetTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3407 | } | 2494 | } |
3408 | impl<R: TreeRoot<RaTypes>> Eq for RetTypeNode<R> {} | 2495 | unsafe impl TransparentNewType for RetType { |
3409 | impl<R: TreeRoot<RaTypes>> Hash for RetTypeNode<R> { | 2496 | type Repr = rowan::SyntaxNode<RaTypes>; |
3410 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3411 | } | 2497 | } |
3412 | 2498 | ||
3413 | impl<'a> AstNode<'a> for RetType<'a> { | 2499 | impl AstNode for RetType { |
3414 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2500 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3415 | match syntax.kind() { | 2501 | match syntax.kind() { |
3416 | RET_TYPE => Some(RetType { syntax }), | 2502 | RET_TYPE => Some(RetType::from_repr(syntax.into_repr())), |
3417 | _ => None, | 2503 | _ => None, |
3418 | } | 2504 | } |
3419 | } | 2505 | } |
3420 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2506 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3421 | } | 2507 | fn to_owned(&self) -> TreePtr<RetType> { TreePtr::cast(self.syntax.to_owned()) } |
3422 | |||
3423 | impl<R: TreeRoot<RaTypes>> RetTypeNode<R> { | ||
3424 | pub fn borrowed(&self) -> RetType { | ||
3425 | RetTypeNode { syntax: self.syntax.borrowed() } | ||
3426 | } | ||
3427 | pub fn owned(&self) -> RetTypeNode { | ||
3428 | RetTypeNode { syntax: self.syntax.owned() } | ||
3429 | } | ||
3430 | } | 2508 | } |
3431 | 2509 | ||
3432 | 2510 | ||
3433 | impl<'a> RetType<'a> { | 2511 | impl RetType { |
3434 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2512 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3435 | super::child_opt(self) | 2513 | super::child_opt(self) |
3436 | } | 2514 | } |
3437 | } | 2515 | } |
3438 | 2516 | ||
3439 | // ReturnExpr | 2517 | // ReturnExpr |
3440 | #[derive(Debug, Clone, Copy,)] | 2518 | #[derive(Debug, PartialEq, Eq, Hash)] |
3441 | pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2519 | #[repr(transparent)] |
3442 | pub(crate) syntax: SyntaxNode<R>, | 2520 | pub struct ReturnExpr { |
2521 | pub(crate) syntax: SyntaxNode, | ||
3443 | } | 2522 | } |
3444 | pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; | 2523 | unsafe impl TransparentNewType for ReturnExpr { |
3445 | 2524 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3446 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReturnExprNode<R1>> for ReturnExprNode<R2> { | ||
3447 | fn eq(&self, other: &ReturnExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3448 | } | ||
3449 | impl<R: TreeRoot<RaTypes>> Eq for ReturnExprNode<R> {} | ||
3450 | impl<R: TreeRoot<RaTypes>> Hash for ReturnExprNode<R> { | ||
3451 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3452 | } | 2525 | } |
3453 | 2526 | ||
3454 | impl<'a> AstNode<'a> for ReturnExpr<'a> { | 2527 | impl AstNode for ReturnExpr { |
3455 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2528 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3456 | match syntax.kind() { | 2529 | match syntax.kind() { |
3457 | RETURN_EXPR => Some(ReturnExpr { syntax }), | 2530 | RETURN_EXPR => Some(ReturnExpr::from_repr(syntax.into_repr())), |
3458 | _ => None, | 2531 | _ => None, |
3459 | } | 2532 | } |
3460 | } | 2533 | } |
3461 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2534 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3462 | } | 2535 | fn to_owned(&self) -> TreePtr<ReturnExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3463 | |||
3464 | impl<R: TreeRoot<RaTypes>> ReturnExprNode<R> { | ||
3465 | pub fn borrowed(&self) -> ReturnExpr { | ||
3466 | ReturnExprNode { syntax: self.syntax.borrowed() } | ||
3467 | } | ||
3468 | pub fn owned(&self) -> ReturnExprNode { | ||
3469 | ReturnExprNode { syntax: self.syntax.owned() } | ||
3470 | } | ||
3471 | } | 2536 | } |
3472 | 2537 | ||
3473 | 2538 | ||
3474 | impl<'a> ReturnExpr<'a> { | 2539 | impl ReturnExpr { |
3475 | pub fn expr(self) -> Option<Expr<'a>> { | 2540 | pub fn expr(&self) -> Option<&Expr> { |
3476 | super::child_opt(self) | 2541 | super::child_opt(self) |
3477 | } | 2542 | } |
3478 | } | 2543 | } |
3479 | 2544 | ||
3480 | // SelfKw | 2545 | // SelfKw |
3481 | #[derive(Debug, Clone, Copy,)] | 2546 | #[derive(Debug, PartialEq, Eq, Hash)] |
3482 | pub struct SelfKwNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2547 | #[repr(transparent)] |
3483 | pub(crate) syntax: SyntaxNode<R>, | 2548 | pub struct SelfKw { |
3484 | } | 2549 | pub(crate) syntax: SyntaxNode, |
3485 | pub type SelfKw<'a> = SelfKwNode<RefRoot<'a>>; | ||
3486 | |||
3487 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfKwNode<R1>> for SelfKwNode<R2> { | ||
3488 | fn eq(&self, other: &SelfKwNode<R1>) -> bool { self.syntax == other.syntax } | ||
3489 | } | 2550 | } |
3490 | impl<R: TreeRoot<RaTypes>> Eq for SelfKwNode<R> {} | 2551 | unsafe impl TransparentNewType for SelfKw { |
3491 | impl<R: TreeRoot<RaTypes>> Hash for SelfKwNode<R> { | 2552 | type Repr = rowan::SyntaxNode<RaTypes>; |
3492 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3493 | } | 2553 | } |
3494 | 2554 | ||
3495 | impl<'a> AstNode<'a> for SelfKw<'a> { | 2555 | impl AstNode for SelfKw { |
3496 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2556 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3497 | match syntax.kind() { | 2557 | match syntax.kind() { |
3498 | SELF_KW => Some(SelfKw { syntax }), | 2558 | SELF_KW => Some(SelfKw::from_repr(syntax.into_repr())), |
3499 | _ => None, | 2559 | _ => None, |
3500 | } | 2560 | } |
3501 | } | 2561 | } |
3502 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2562 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2563 | fn to_owned(&self) -> TreePtr<SelfKw> { TreePtr::cast(self.syntax.to_owned()) } | ||
3503 | } | 2564 | } |
3504 | 2565 | ||
3505 | impl<R: TreeRoot<RaTypes>> SelfKwNode<R> { | ||
3506 | pub fn borrowed(&self) -> SelfKw { | ||
3507 | SelfKwNode { syntax: self.syntax.borrowed() } | ||
3508 | } | ||
3509 | pub fn owned(&self) -> SelfKwNode { | ||
3510 | SelfKwNode { syntax: self.syntax.owned() } | ||
3511 | } | ||
3512 | } | ||
3513 | 2566 | ||
3514 | 2567 | impl SelfKw {} | |
3515 | impl<'a> SelfKw<'a> {} | ||
3516 | 2568 | ||
3517 | // SelfParam | 2569 | // SelfParam |
3518 | #[derive(Debug, Clone, Copy,)] | 2570 | #[derive(Debug, PartialEq, Eq, Hash)] |
3519 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2571 | #[repr(transparent)] |
3520 | pub(crate) syntax: SyntaxNode<R>, | 2572 | pub struct SelfParam { |
2573 | pub(crate) syntax: SyntaxNode, | ||
3521 | } | 2574 | } |
3522 | pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; | 2575 | unsafe impl TransparentNewType for SelfParam { |
3523 | 2576 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3524 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfParamNode<R1>> for SelfParamNode<R2> { | ||
3525 | fn eq(&self, other: &SelfParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
3526 | } | ||
3527 | impl<R: TreeRoot<RaTypes>> Eq for SelfParamNode<R> {} | ||
3528 | impl<R: TreeRoot<RaTypes>> Hash for SelfParamNode<R> { | ||
3529 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3530 | } | 2577 | } |
3531 | 2578 | ||
3532 | impl<'a> AstNode<'a> for SelfParam<'a> { | 2579 | impl AstNode for SelfParam { |
3533 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2580 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3534 | match syntax.kind() { | 2581 | match syntax.kind() { |
3535 | SELF_PARAM => Some(SelfParam { syntax }), | 2582 | SELF_PARAM => Some(SelfParam::from_repr(syntax.into_repr())), |
3536 | _ => None, | 2583 | _ => None, |
3537 | } | 2584 | } |
3538 | } | 2585 | } |
3539 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2586 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3540 | } | 2587 | fn to_owned(&self) -> TreePtr<SelfParam> { TreePtr::cast(self.syntax.to_owned()) } |
3541 | |||
3542 | impl<R: TreeRoot<RaTypes>> SelfParamNode<R> { | ||
3543 | pub fn borrowed(&self) -> SelfParam { | ||
3544 | SelfParamNode { syntax: self.syntax.borrowed() } | ||
3545 | } | ||
3546 | pub fn owned(&self) -> SelfParamNode { | ||
3547 | SelfParamNode { syntax: self.syntax.owned() } | ||
3548 | } | ||
3549 | } | 2588 | } |
3550 | 2589 | ||
3551 | 2590 | ||
3552 | impl<'a> SelfParam<'a> { | 2591 | impl SelfParam { |
3553 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2592 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3554 | super::child_opt(self) | 2593 | super::child_opt(self) |
3555 | } | 2594 | } |
3556 | 2595 | ||
3557 | pub fn self_kw(self) -> Option<SelfKw<'a>> { | 2596 | pub fn self_kw(&self) -> Option<&SelfKw> { |
3558 | super::child_opt(self) | 2597 | super::child_opt(self) |
3559 | } | 2598 | } |
3560 | } | 2599 | } |
3561 | 2600 | ||
3562 | // SlicePat | 2601 | // SlicePat |
3563 | #[derive(Debug, Clone, Copy,)] | 2602 | #[derive(Debug, PartialEq, Eq, Hash)] |
3564 | pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2603 | #[repr(transparent)] |
3565 | pub(crate) syntax: SyntaxNode<R>, | 2604 | pub struct SlicePat { |
2605 | pub(crate) syntax: SyntaxNode, | ||
3566 | } | 2606 | } |
3567 | pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; | 2607 | unsafe impl TransparentNewType for SlicePat { |
3568 | 2608 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3569 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SlicePatNode<R1>> for SlicePatNode<R2> { | ||
3570 | fn eq(&self, other: &SlicePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3571 | } | ||
3572 | impl<R: TreeRoot<RaTypes>> Eq for SlicePatNode<R> {} | ||
3573 | impl<R: TreeRoot<RaTypes>> Hash for SlicePatNode<R> { | ||
3574 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3575 | } | 2609 | } |
3576 | 2610 | ||
3577 | impl<'a> AstNode<'a> for SlicePat<'a> { | 2611 | impl AstNode for SlicePat { |
3578 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2612 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3579 | match syntax.kind() { | 2613 | match syntax.kind() { |
3580 | SLICE_PAT => Some(SlicePat { syntax }), | 2614 | SLICE_PAT => Some(SlicePat::from_repr(syntax.into_repr())), |
3581 | _ => None, | 2615 | _ => None, |
3582 | } | 2616 | } |
3583 | } | 2617 | } |
3584 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2618 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3585 | } | 2619 | fn to_owned(&self) -> TreePtr<SlicePat> { TreePtr::cast(self.syntax.to_owned()) } |
3586 | |||
3587 | impl<R: TreeRoot<RaTypes>> SlicePatNode<R> { | ||
3588 | pub fn borrowed(&self) -> SlicePat { | ||
3589 | SlicePatNode { syntax: self.syntax.borrowed() } | ||
3590 | } | ||
3591 | pub fn owned(&self) -> SlicePatNode { | ||
3592 | SlicePatNode { syntax: self.syntax.owned() } | ||
3593 | } | ||
3594 | } | 2620 | } |
3595 | 2621 | ||
3596 | 2622 | ||
3597 | impl<'a> SlicePat<'a> {} | 2623 | impl SlicePat {} |
3598 | 2624 | ||
3599 | // SliceType | 2625 | // SliceType |
3600 | #[derive(Debug, Clone, Copy,)] | 2626 | #[derive(Debug, PartialEq, Eq, Hash)] |
3601 | pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2627 | #[repr(transparent)] |
3602 | pub(crate) syntax: SyntaxNode<R>, | 2628 | pub struct SliceType { |
2629 | pub(crate) syntax: SyntaxNode, | ||
3603 | } | 2630 | } |
3604 | pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; | 2631 | unsafe impl TransparentNewType for SliceType { |
3605 | 2632 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3606 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SliceTypeNode<R1>> for SliceTypeNode<R2> { | ||
3607 | fn eq(&self, other: &SliceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3608 | } | ||
3609 | impl<R: TreeRoot<RaTypes>> Eq for SliceTypeNode<R> {} | ||
3610 | impl<R: TreeRoot<RaTypes>> Hash for SliceTypeNode<R> { | ||
3611 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3612 | } | 2633 | } |
3613 | 2634 | ||
3614 | impl<'a> AstNode<'a> for SliceType<'a> { | 2635 | impl AstNode for SliceType { |
3615 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2636 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3616 | match syntax.kind() { | 2637 | match syntax.kind() { |
3617 | SLICE_TYPE => Some(SliceType { syntax }), | 2638 | SLICE_TYPE => Some(SliceType::from_repr(syntax.into_repr())), |
3618 | _ => None, | 2639 | _ => None, |
3619 | } | 2640 | } |
3620 | } | 2641 | } |
3621 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2642 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3622 | } | 2643 | fn to_owned(&self) -> TreePtr<SliceType> { TreePtr::cast(self.syntax.to_owned()) } |
3623 | |||
3624 | impl<R: TreeRoot<RaTypes>> SliceTypeNode<R> { | ||
3625 | pub fn borrowed(&self) -> SliceType { | ||
3626 | SliceTypeNode { syntax: self.syntax.borrowed() } | ||
3627 | } | ||
3628 | pub fn owned(&self) -> SliceTypeNode { | ||
3629 | SliceTypeNode { syntax: self.syntax.owned() } | ||
3630 | } | ||
3631 | } | 2644 | } |
3632 | 2645 | ||
3633 | 2646 | ||
3634 | impl<'a> SliceType<'a> { | 2647 | impl SliceType { |
3635 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2648 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3636 | super::child_opt(self) | 2649 | super::child_opt(self) |
3637 | } | 2650 | } |
3638 | } | 2651 | } |
3639 | 2652 | ||
3640 | // SourceFile | 2653 | // SourceFile |
3641 | #[derive(Debug, Clone, Copy,)] | 2654 | #[derive(Debug, PartialEq, Eq, Hash)] |
3642 | pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2655 | #[repr(transparent)] |
3643 | pub(crate) syntax: SyntaxNode<R>, | 2656 | pub struct SourceFile { |
2657 | pub(crate) syntax: SyntaxNode, | ||
3644 | } | 2658 | } |
3645 | pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; | 2659 | unsafe impl TransparentNewType for SourceFile { |
3646 | 2660 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3647 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SourceFileNode<R1>> for SourceFileNode<R2> { | ||
3648 | fn eq(&self, other: &SourceFileNode<R1>) -> bool { self.syntax == other.syntax } | ||
3649 | } | ||
3650 | impl<R: TreeRoot<RaTypes>> Eq for SourceFileNode<R> {} | ||
3651 | impl<R: TreeRoot<RaTypes>> Hash for SourceFileNode<R> { | ||
3652 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3653 | } | 2661 | } |
3654 | 2662 | ||
3655 | impl<'a> AstNode<'a> for SourceFile<'a> { | 2663 | impl AstNode for SourceFile { |
3656 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2664 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3657 | match syntax.kind() { | 2665 | match syntax.kind() { |
3658 | SOURCE_FILE => Some(SourceFile { syntax }), | 2666 | SOURCE_FILE => Some(SourceFile::from_repr(syntax.into_repr())), |
3659 | _ => None, | 2667 | _ => None, |
3660 | } | 2668 | } |
3661 | } | 2669 | } |
3662 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2670 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2671 | fn to_owned(&self) -> TreePtr<SourceFile> { TreePtr::cast(self.syntax.to_owned()) } | ||
3663 | } | 2672 | } |
3664 | 2673 | ||
3665 | impl<R: TreeRoot<RaTypes>> SourceFileNode<R> { | ||
3666 | pub fn borrowed(&self) -> SourceFile { | ||
3667 | SourceFileNode { syntax: self.syntax.borrowed() } | ||
3668 | } | ||
3669 | pub fn owned(&self) -> SourceFileNode { | ||
3670 | SourceFileNode { syntax: self.syntax.owned() } | ||
3671 | } | ||
3672 | } | ||
3673 | 2674 | ||
3674 | 2675 | impl ast::ModuleItemOwner for SourceFile {} | |
3675 | impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} | 2676 | impl ast::FnDefOwner for SourceFile {} |
3676 | impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} | 2677 | impl SourceFile { |
3677 | impl<'a> SourceFile<'a> { | 2678 | pub fn modules(&self) -> impl Iterator<Item = &Module> { |
3678 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3679 | super::children(self) | 2679 | super::children(self) |
3680 | } | 2680 | } |
3681 | } | 2681 | } |
3682 | 2682 | ||
3683 | // StaticDef | 2683 | // StaticDef |
3684 | #[derive(Debug, Clone, Copy,)] | 2684 | #[derive(Debug, PartialEq, Eq, Hash)] |
3685 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2685 | #[repr(transparent)] |
3686 | pub(crate) syntax: SyntaxNode<R>, | 2686 | pub struct StaticDef { |
3687 | } | 2687 | pub(crate) syntax: SyntaxNode, |
3688 | pub type StaticDef<'a> = StaticDefNode<RefRoot<'a>>; | ||
3689 | |||
3690 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StaticDefNode<R1>> for StaticDefNode<R2> { | ||
3691 | fn eq(&self, other: &StaticDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3692 | } | 2688 | } |
3693 | impl<R: TreeRoot<RaTypes>> Eq for StaticDefNode<R> {} | 2689 | unsafe impl TransparentNewType for StaticDef { |
3694 | impl<R: TreeRoot<RaTypes>> Hash for StaticDefNode<R> { | 2690 | type Repr = rowan::SyntaxNode<RaTypes>; |
3695 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3696 | } | 2691 | } |
3697 | 2692 | ||
3698 | impl<'a> AstNode<'a> for StaticDef<'a> { | 2693 | impl AstNode for StaticDef { |
3699 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2694 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3700 | match syntax.kind() { | 2695 | match syntax.kind() { |
3701 | STATIC_DEF => Some(StaticDef { syntax }), | 2696 | STATIC_DEF => Some(StaticDef::from_repr(syntax.into_repr())), |
3702 | _ => None, | 2697 | _ => None, |
3703 | } | 2698 | } |
3704 | } | 2699 | } |
3705 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2700 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2701 | fn to_owned(&self) -> TreePtr<StaticDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3706 | } | 2702 | } |
3707 | 2703 | ||
3708 | impl<R: TreeRoot<RaTypes>> StaticDefNode<R> { | ||
3709 | pub fn borrowed(&self) -> StaticDef { | ||
3710 | StaticDefNode { syntax: self.syntax.borrowed() } | ||
3711 | } | ||
3712 | pub fn owned(&self) -> StaticDefNode { | ||
3713 | StaticDefNode { syntax: self.syntax.owned() } | ||
3714 | } | ||
3715 | } | ||
3716 | 2704 | ||
3717 | 2705 | impl ast::VisibilityOwner for StaticDef {} | |
3718 | impl<'a> ast::VisibilityOwner<'a> for StaticDef<'a> {} | 2706 | impl ast::NameOwner for StaticDef {} |
3719 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} | 2707 | impl ast::TypeParamsOwner for StaticDef {} |
3720 | impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} | 2708 | impl ast::AttrsOwner for StaticDef {} |
3721 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} | 2709 | impl ast::DocCommentsOwner for StaticDef {} |
3722 | impl<'a> ast::DocCommentsOwner<'a> for StaticDef<'a> {} | 2710 | impl StaticDef {} |
3723 | impl<'a> StaticDef<'a> {} | ||
3724 | 2711 | ||
3725 | // Stmt | 2712 | // Stmt |
2713 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
2714 | #[repr(transparent)] | ||
2715 | pub struct Stmt { | ||
2716 | pub(crate) syntax: SyntaxNode, | ||
2717 | } | ||
2718 | unsafe impl TransparentNewType for Stmt { | ||
2719 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2720 | } | ||
2721 | |||
3726 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2722 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3727 | pub enum Stmt<'a> { | 2723 | pub enum StmtKind<'a> { |
3728 | ExprStmt(ExprStmt<'a>), | 2724 | ExprStmt(&'a ExprStmt), |
3729 | LetStmt(LetStmt<'a>), | 2725 | LetStmt(&'a LetStmt), |
3730 | } | 2726 | } |
3731 | 2727 | ||
3732 | impl<'a> AstNode<'a> for Stmt<'a> { | 2728 | impl AstNode for Stmt { |
3733 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2729 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3734 | match syntax.kind() { | 2730 | match syntax.kind() { |
3735 | EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })), | 2731 | | EXPR_STMT |
3736 | LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })), | 2732 | | LET_STMT => Some(Stmt::from_repr(syntax.into_repr())), |
3737 | _ => None, | 2733 | _ => None, |
3738 | } | 2734 | } |
3739 | } | 2735 | } |
3740 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2736 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3741 | match self { | 2737 | fn to_owned(&self) -> TreePtr<Stmt> { TreePtr::cast(self.syntax.to_owned()) } |
3742 | Stmt::ExprStmt(inner) => inner.syntax(), | 2738 | } |
3743 | Stmt::LetStmt(inner) => inner.syntax(), | 2739 | |
2740 | impl Stmt { | ||
2741 | pub fn kind(&self) -> StmtKind { | ||
2742 | match self.syntax.kind() { | ||
2743 | EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(&self.syntax).unwrap()), | ||
2744 | LET_STMT => StmtKind::LetStmt(LetStmt::cast(&self.syntax).unwrap()), | ||
2745 | _ => unreachable!(), | ||
3744 | } | 2746 | } |
3745 | } | 2747 | } |
3746 | } | 2748 | } |
3747 | 2749 | ||
3748 | impl<'a> Stmt<'a> {} | 2750 | impl Stmt {} |
3749 | 2751 | ||
3750 | // String | 2752 | // String |
3751 | #[derive(Debug, Clone, Copy,)] | 2753 | #[derive(Debug, PartialEq, Eq, Hash)] |
3752 | pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2754 | #[repr(transparent)] |
3753 | pub(crate) syntax: SyntaxNode<R>, | 2755 | pub struct String { |
3754 | } | 2756 | pub(crate) syntax: SyntaxNode, |
3755 | pub type String<'a> = StringNode<RefRoot<'a>>; | ||
3756 | |||
3757 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> { | ||
3758 | fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax } | ||
3759 | } | 2757 | } |
3760 | impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {} | 2758 | unsafe impl TransparentNewType for String { |
3761 | impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> { | 2759 | type Repr = rowan::SyntaxNode<RaTypes>; |
3762 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3763 | } | 2760 | } |
3764 | 2761 | ||
3765 | impl<'a> AstNode<'a> for String<'a> { | 2762 | impl AstNode for String { |
3766 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2763 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3767 | match syntax.kind() { | 2764 | match syntax.kind() { |
3768 | STRING => Some(String { syntax }), | 2765 | STRING => Some(String::from_repr(syntax.into_repr())), |
3769 | _ => None, | 2766 | _ => None, |
3770 | } | 2767 | } |
3771 | } | 2768 | } |
3772 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3773 | } | 2770 | fn to_owned(&self) -> TreePtr<String> { TreePtr::cast(self.syntax.to_owned()) } |
3774 | |||
3775 | impl<R: TreeRoot<RaTypes>> StringNode<R> { | ||
3776 | pub fn borrowed(&self) -> String { | ||
3777 | StringNode { syntax: self.syntax.borrowed() } | ||
3778 | } | ||
3779 | pub fn owned(&self) -> StringNode { | ||
3780 | StringNode { syntax: self.syntax.owned() } | ||
3781 | } | ||
3782 | } | 2771 | } |
3783 | 2772 | ||
3784 | 2773 | ||
3785 | impl<'a> String<'a> {} | 2774 | impl ast::AstToken for String {} |
2775 | impl String {} | ||
3786 | 2776 | ||
3787 | // StructDef | 2777 | // StructDef |
3788 | #[derive(Debug, Clone, Copy,)] | 2778 | #[derive(Debug, PartialEq, Eq, Hash)] |
3789 | pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2779 | #[repr(transparent)] |
3790 | pub(crate) syntax: SyntaxNode<R>, | 2780 | pub struct StructDef { |
2781 | pub(crate) syntax: SyntaxNode, | ||
3791 | } | 2782 | } |
3792 | pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; | 2783 | unsafe impl TransparentNewType for StructDef { |
3793 | 2784 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3794 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructDefNode<R1>> for StructDefNode<R2> { | ||
3795 | fn eq(&self, other: &StructDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3796 | } | ||
3797 | impl<R: TreeRoot<RaTypes>> Eq for StructDefNode<R> {} | ||
3798 | impl<R: TreeRoot<RaTypes>> Hash for StructDefNode<R> { | ||
3799 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3800 | } | 2785 | } |
3801 | 2786 | ||
3802 | impl<'a> AstNode<'a> for StructDef<'a> { | 2787 | impl AstNode for StructDef { |
3803 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2788 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3804 | match syntax.kind() { | 2789 | match syntax.kind() { |
3805 | STRUCT_DEF => Some(StructDef { syntax }), | 2790 | STRUCT_DEF => Some(StructDef::from_repr(syntax.into_repr())), |
3806 | _ => None, | 2791 | _ => None, |
3807 | } | 2792 | } |
3808 | } | 2793 | } |
3809 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2794 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3810 | } | 2795 | fn to_owned(&self) -> TreePtr<StructDef> { TreePtr::cast(self.syntax.to_owned()) } |
3811 | |||
3812 | impl<R: TreeRoot<RaTypes>> StructDefNode<R> { | ||
3813 | pub fn borrowed(&self) -> StructDef { | ||
3814 | StructDefNode { syntax: self.syntax.borrowed() } | ||
3815 | } | ||
3816 | pub fn owned(&self) -> StructDefNode { | ||
3817 | StructDefNode { syntax: self.syntax.owned() } | ||
3818 | } | ||
3819 | } | 2796 | } |
3820 | 2797 | ||
3821 | 2798 | ||
3822 | impl<'a> ast::VisibilityOwner<'a> for StructDef<'a> {} | 2799 | impl ast::VisibilityOwner for StructDef {} |
3823 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} | 2800 | impl ast::NameOwner for StructDef {} |
3824 | impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} | 2801 | impl ast::TypeParamsOwner for StructDef {} |
3825 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} | 2802 | impl ast::AttrsOwner for StructDef {} |
3826 | impl<'a> ast::DocCommentsOwner<'a> for StructDef<'a> {} | 2803 | impl ast::DocCommentsOwner for StructDef {} |
3827 | impl<'a> StructDef<'a> {} | 2804 | impl StructDef {} |
3828 | 2805 | ||
3829 | // StructLit | 2806 | // StructLit |
3830 | #[derive(Debug, Clone, Copy,)] | 2807 | #[derive(Debug, PartialEq, Eq, Hash)] |
3831 | pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2808 | #[repr(transparent)] |
3832 | pub(crate) syntax: SyntaxNode<R>, | 2809 | pub struct StructLit { |
2810 | pub(crate) syntax: SyntaxNode, | ||
3833 | } | 2811 | } |
3834 | pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; | 2812 | unsafe impl TransparentNewType for StructLit { |
3835 | 2813 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3836 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructLitNode<R1>> for StructLitNode<R2> { | ||
3837 | fn eq(&self, other: &StructLitNode<R1>) -> bool { self.syntax == other.syntax } | ||
3838 | } | ||
3839 | impl<R: TreeRoot<RaTypes>> Eq for StructLitNode<R> {} | ||
3840 | impl<R: TreeRoot<RaTypes>> Hash for StructLitNode<R> { | ||
3841 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3842 | } | 2814 | } |
3843 | 2815 | ||
3844 | impl<'a> AstNode<'a> for StructLit<'a> { | 2816 | impl AstNode for StructLit { |
3845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2817 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3846 | match syntax.kind() { | 2818 | match syntax.kind() { |
3847 | STRUCT_LIT => Some(StructLit { syntax }), | 2819 | STRUCT_LIT => Some(StructLit::from_repr(syntax.into_repr())), |
3848 | _ => None, | 2820 | _ => None, |
3849 | } | 2821 | } |
3850 | } | 2822 | } |
3851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2823 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3852 | } | 2824 | fn to_owned(&self) -> TreePtr<StructLit> { TreePtr::cast(self.syntax.to_owned()) } |
3853 | |||
3854 | impl<R: TreeRoot<RaTypes>> StructLitNode<R> { | ||
3855 | pub fn borrowed(&self) -> StructLit { | ||
3856 | StructLitNode { syntax: self.syntax.borrowed() } | ||
3857 | } | ||
3858 | pub fn owned(&self) -> StructLitNode { | ||
3859 | StructLitNode { syntax: self.syntax.owned() } | ||
3860 | } | ||
3861 | } | 2825 | } |
3862 | 2826 | ||
3863 | 2827 | ||
3864 | impl<'a> StructLit<'a> { | 2828 | impl StructLit { |
3865 | pub fn path(self) -> Option<Path<'a>> { | 2829 | pub fn path(&self) -> Option<&Path> { |
3866 | super::child_opt(self) | 2830 | super::child_opt(self) |
3867 | } | 2831 | } |
3868 | 2832 | ||
3869 | pub fn named_field_list(self) -> Option<NamedFieldList<'a>> { | 2833 | pub fn named_field_list(&self) -> Option<&NamedFieldList> { |
3870 | super::child_opt(self) | 2834 | super::child_opt(self) |
3871 | } | 2835 | } |
3872 | 2836 | ||
3873 | pub fn spread(self) -> Option<Expr<'a>> { | 2837 | pub fn spread(&self) -> Option<&Expr> { |
3874 | super::child_opt(self) | 2838 | super::child_opt(self) |
3875 | } | 2839 | } |
3876 | } | 2840 | } |
3877 | 2841 | ||
3878 | // StructPat | 2842 | // StructPat |
3879 | #[derive(Debug, Clone, Copy,)] | 2843 | #[derive(Debug, PartialEq, Eq, Hash)] |
3880 | pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2844 | #[repr(transparent)] |
3881 | pub(crate) syntax: SyntaxNode<R>, | 2845 | pub struct StructPat { |
3882 | } | 2846 | pub(crate) syntax: SyntaxNode, |
3883 | pub type StructPat<'a> = StructPatNode<RefRoot<'a>>; | ||
3884 | |||
3885 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructPatNode<R1>> for StructPatNode<R2> { | ||
3886 | fn eq(&self, other: &StructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3887 | } | 2847 | } |
3888 | impl<R: TreeRoot<RaTypes>> Eq for StructPatNode<R> {} | 2848 | unsafe impl TransparentNewType for StructPat { |
3889 | impl<R: TreeRoot<RaTypes>> Hash for StructPatNode<R> { | 2849 | type Repr = rowan::SyntaxNode<RaTypes>; |
3890 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3891 | } | 2850 | } |
3892 | 2851 | ||
3893 | impl<'a> AstNode<'a> for StructPat<'a> { | 2852 | impl AstNode for StructPat { |
3894 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2853 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3895 | match syntax.kind() { | 2854 | match syntax.kind() { |
3896 | STRUCT_PAT => Some(StructPat { syntax }), | 2855 | STRUCT_PAT => Some(StructPat::from_repr(syntax.into_repr())), |
3897 | _ => None, | 2856 | _ => None, |
3898 | } | 2857 | } |
3899 | } | 2858 | } |
3900 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2859 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2860 | fn to_owned(&self) -> TreePtr<StructPat> { TreePtr::cast(self.syntax.to_owned()) } | ||
3901 | } | 2861 | } |
3902 | 2862 | ||
3903 | impl<R: TreeRoot<RaTypes>> StructPatNode<R> { | ||
3904 | pub fn borrowed(&self) -> StructPat { | ||
3905 | StructPatNode { syntax: self.syntax.borrowed() } | ||
3906 | } | ||
3907 | pub fn owned(&self) -> StructPatNode { | ||
3908 | StructPatNode { syntax: self.syntax.owned() } | ||
3909 | } | ||
3910 | } | ||
3911 | 2863 | ||
3912 | 2864 | impl StructPat {} | |
3913 | impl<'a> StructPat<'a> {} | ||
3914 | 2865 | ||
3915 | // TokenTree | 2866 | // TokenTree |
3916 | #[derive(Debug, Clone, Copy,)] | 2867 | #[derive(Debug, PartialEq, Eq, Hash)] |
3917 | pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2868 | #[repr(transparent)] |
3918 | pub(crate) syntax: SyntaxNode<R>, | 2869 | pub struct TokenTree { |
3919 | } | 2870 | pub(crate) syntax: SyntaxNode, |
3920 | pub type TokenTree<'a> = TokenTreeNode<RefRoot<'a>>; | ||
3921 | |||
3922 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TokenTreeNode<R1>> for TokenTreeNode<R2> { | ||
3923 | fn eq(&self, other: &TokenTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3924 | } | 2871 | } |
3925 | impl<R: TreeRoot<RaTypes>> Eq for TokenTreeNode<R> {} | 2872 | unsafe impl TransparentNewType for TokenTree { |
3926 | impl<R: TreeRoot<RaTypes>> Hash for TokenTreeNode<R> { | 2873 | type Repr = rowan::SyntaxNode<RaTypes>; |
3927 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3928 | } | 2874 | } |
3929 | 2875 | ||
3930 | impl<'a> AstNode<'a> for TokenTree<'a> { | 2876 | impl AstNode for TokenTree { |
3931 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2877 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3932 | match syntax.kind() { | 2878 | match syntax.kind() { |
3933 | TOKEN_TREE => Some(TokenTree { syntax }), | 2879 | TOKEN_TREE => Some(TokenTree::from_repr(syntax.into_repr())), |
3934 | _ => None, | 2880 | _ => None, |
3935 | } | 2881 | } |
3936 | } | 2882 | } |
3937 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2883 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3938 | } | 2884 | fn to_owned(&self) -> TreePtr<TokenTree> { TreePtr::cast(self.syntax.to_owned()) } |
3939 | |||
3940 | impl<R: TreeRoot<RaTypes>> TokenTreeNode<R> { | ||
3941 | pub fn borrowed(&self) -> TokenTree { | ||
3942 | TokenTreeNode { syntax: self.syntax.borrowed() } | ||
3943 | } | ||
3944 | pub fn owned(&self) -> TokenTreeNode { | ||
3945 | TokenTreeNode { syntax: self.syntax.owned() } | ||
3946 | } | ||
3947 | } | 2885 | } |
3948 | 2886 | ||
3949 | 2887 | ||
3950 | impl<'a> TokenTree<'a> {} | 2888 | impl TokenTree {} |
3951 | 2889 | ||
3952 | // TraitDef | 2890 | // TraitDef |
3953 | #[derive(Debug, Clone, Copy,)] | 2891 | #[derive(Debug, PartialEq, Eq, Hash)] |
3954 | pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2892 | #[repr(transparent)] |
3955 | pub(crate) syntax: SyntaxNode<R>, | 2893 | pub struct TraitDef { |
2894 | pub(crate) syntax: SyntaxNode, | ||
3956 | } | 2895 | } |
3957 | pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; | 2896 | unsafe impl TransparentNewType for TraitDef { |
3958 | 2897 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3959 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TraitDefNode<R1>> for TraitDefNode<R2> { | ||
3960 | fn eq(&self, other: &TraitDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3961 | } | ||
3962 | impl<R: TreeRoot<RaTypes>> Eq for TraitDefNode<R> {} | ||
3963 | impl<R: TreeRoot<RaTypes>> Hash for TraitDefNode<R> { | ||
3964 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3965 | } | 2898 | } |
3966 | 2899 | ||
3967 | impl<'a> AstNode<'a> for TraitDef<'a> { | 2900 | impl AstNode for TraitDef { |
3968 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2901 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3969 | match syntax.kind() { | 2902 | match syntax.kind() { |
3970 | TRAIT_DEF => Some(TraitDef { syntax }), | 2903 | TRAIT_DEF => Some(TraitDef::from_repr(syntax.into_repr())), |
3971 | _ => None, | 2904 | _ => None, |
3972 | } | 2905 | } |
3973 | } | 2906 | } |
3974 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2907 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3975 | } | 2908 | fn to_owned(&self) -> TreePtr<TraitDef> { TreePtr::cast(self.syntax.to_owned()) } |
3976 | |||
3977 | impl<R: TreeRoot<RaTypes>> TraitDefNode<R> { | ||
3978 | pub fn borrowed(&self) -> TraitDef { | ||
3979 | TraitDefNode { syntax: self.syntax.borrowed() } | ||
3980 | } | ||
3981 | pub fn owned(&self) -> TraitDefNode { | ||
3982 | TraitDefNode { syntax: self.syntax.owned() } | ||
3983 | } | ||
3984 | } | 2909 | } |
3985 | 2910 | ||
3986 | 2911 | ||
3987 | impl<'a> ast::VisibilityOwner<'a> for TraitDef<'a> {} | 2912 | impl ast::VisibilityOwner for TraitDef {} |
3988 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} | 2913 | impl ast::NameOwner for TraitDef {} |
3989 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} | 2914 | impl ast::AttrsOwner for TraitDef {} |
3990 | impl<'a> ast::DocCommentsOwner<'a> for TraitDef<'a> {} | 2915 | impl ast::DocCommentsOwner for TraitDef {} |
3991 | impl<'a> TraitDef<'a> {} | 2916 | impl TraitDef {} |
3992 | 2917 | ||
3993 | // TryExpr | 2918 | // TryExpr |
3994 | #[derive(Debug, Clone, Copy,)] | 2919 | #[derive(Debug, PartialEq, Eq, Hash)] |
3995 | pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2920 | #[repr(transparent)] |
3996 | pub(crate) syntax: SyntaxNode<R>, | 2921 | pub struct TryExpr { |
2922 | pub(crate) syntax: SyntaxNode, | ||
3997 | } | 2923 | } |
3998 | pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; | 2924 | unsafe impl TransparentNewType for TryExpr { |
3999 | 2925 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4000 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TryExprNode<R1>> for TryExprNode<R2> { | ||
4001 | fn eq(&self, other: &TryExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4002 | } | ||
4003 | impl<R: TreeRoot<RaTypes>> Eq for TryExprNode<R> {} | ||
4004 | impl<R: TreeRoot<RaTypes>> Hash for TryExprNode<R> { | ||
4005 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4006 | } | 2926 | } |
4007 | 2927 | ||
4008 | impl<'a> AstNode<'a> for TryExpr<'a> { | 2928 | impl AstNode for TryExpr { |
4009 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2929 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4010 | match syntax.kind() { | 2930 | match syntax.kind() { |
4011 | TRY_EXPR => Some(TryExpr { syntax }), | 2931 | TRY_EXPR => Some(TryExpr::from_repr(syntax.into_repr())), |
4012 | _ => None, | 2932 | _ => None, |
4013 | } | 2933 | } |
4014 | } | 2934 | } |
4015 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2935 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2936 | fn to_owned(&self) -> TreePtr<TryExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4016 | } | 2937 | } |
4017 | 2938 | ||
4018 | impl<R: TreeRoot<RaTypes>> TryExprNode<R> { | ||
4019 | pub fn borrowed(&self) -> TryExpr { | ||
4020 | TryExprNode { syntax: self.syntax.borrowed() } | ||
4021 | } | ||
4022 | pub fn owned(&self) -> TryExprNode { | ||
4023 | TryExprNode { syntax: self.syntax.owned() } | ||
4024 | } | ||
4025 | } | ||
4026 | 2939 | ||
4027 | 2940 | impl TryExpr { | |
4028 | impl<'a> TryExpr<'a> { | 2941 | pub fn expr(&self) -> Option<&Expr> { |
4029 | pub fn expr(self) -> Option<Expr<'a>> { | ||
4030 | super::child_opt(self) | 2942 | super::child_opt(self) |
4031 | } | 2943 | } |
4032 | } | 2944 | } |
4033 | 2945 | ||
4034 | // TupleExpr | 2946 | // TupleExpr |
4035 | #[derive(Debug, Clone, Copy,)] | 2947 | #[derive(Debug, PartialEq, Eq, Hash)] |
4036 | pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2948 | #[repr(transparent)] |
4037 | pub(crate) syntax: SyntaxNode<R>, | 2949 | pub struct TupleExpr { |
4038 | } | 2950 | pub(crate) syntax: SyntaxNode, |
4039 | pub type TupleExpr<'a> = TupleExprNode<RefRoot<'a>>; | ||
4040 | |||
4041 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleExprNode<R1>> for TupleExprNode<R2> { | ||
4042 | fn eq(&self, other: &TupleExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4043 | } | 2951 | } |
4044 | impl<R: TreeRoot<RaTypes>> Eq for TupleExprNode<R> {} | 2952 | unsafe impl TransparentNewType for TupleExpr { |
4045 | impl<R: TreeRoot<RaTypes>> Hash for TupleExprNode<R> { | 2953 | type Repr = rowan::SyntaxNode<RaTypes>; |
4046 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4047 | } | 2954 | } |
4048 | 2955 | ||
4049 | impl<'a> AstNode<'a> for TupleExpr<'a> { | 2956 | impl AstNode for TupleExpr { |
4050 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2957 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4051 | match syntax.kind() { | 2958 | match syntax.kind() { |
4052 | TUPLE_EXPR => Some(TupleExpr { syntax }), | 2959 | TUPLE_EXPR => Some(TupleExpr::from_repr(syntax.into_repr())), |
4053 | _ => None, | 2960 | _ => None, |
4054 | } | 2961 | } |
4055 | } | 2962 | } |
4056 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2963 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4057 | } | 2964 | fn to_owned(&self) -> TreePtr<TupleExpr> { TreePtr::cast(self.syntax.to_owned()) } |
4058 | |||
4059 | impl<R: TreeRoot<RaTypes>> TupleExprNode<R> { | ||
4060 | pub fn borrowed(&self) -> TupleExpr { | ||
4061 | TupleExprNode { syntax: self.syntax.borrowed() } | ||
4062 | } | ||
4063 | pub fn owned(&self) -> TupleExprNode { | ||
4064 | TupleExprNode { syntax: self.syntax.owned() } | ||
4065 | } | ||
4066 | } | 2965 | } |
4067 | 2966 | ||
4068 | 2967 | ||
4069 | impl<'a> TupleExpr<'a> {} | 2968 | impl TupleExpr {} |
4070 | 2969 | ||
4071 | // TuplePat | 2970 | // TuplePat |
4072 | #[derive(Debug, Clone, Copy,)] | 2971 | #[derive(Debug, PartialEq, Eq, Hash)] |
4073 | pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2972 | #[repr(transparent)] |
4074 | pub(crate) syntax: SyntaxNode<R>, | 2973 | pub struct TuplePat { |
2974 | pub(crate) syntax: SyntaxNode, | ||
4075 | } | 2975 | } |
4076 | pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; | 2976 | unsafe impl TransparentNewType for TuplePat { |
4077 | 2977 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4078 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TuplePatNode<R1>> for TuplePatNode<R2> { | ||
4079 | fn eq(&self, other: &TuplePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
4080 | } | ||
4081 | impl<R: TreeRoot<RaTypes>> Eq for TuplePatNode<R> {} | ||
4082 | impl<R: TreeRoot<RaTypes>> Hash for TuplePatNode<R> { | ||
4083 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4084 | } | 2978 | } |
4085 | 2979 | ||
4086 | impl<'a> AstNode<'a> for TuplePat<'a> { | 2980 | impl AstNode for TuplePat { |
4087 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2981 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4088 | match syntax.kind() { | 2982 | match syntax.kind() { |
4089 | TUPLE_PAT => Some(TuplePat { syntax }), | 2983 | TUPLE_PAT => Some(TuplePat::from_repr(syntax.into_repr())), |
4090 | _ => None, | 2984 | _ => None, |
4091 | } | 2985 | } |
4092 | } | 2986 | } |
4093 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2987 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4094 | } | 2988 | fn to_owned(&self) -> TreePtr<TuplePat> { TreePtr::cast(self.syntax.to_owned()) } |
4095 | |||
4096 | impl<R: TreeRoot<RaTypes>> TuplePatNode<R> { | ||
4097 | pub fn borrowed(&self) -> TuplePat { | ||
4098 | TuplePatNode { syntax: self.syntax.borrowed() } | ||
4099 | } | ||
4100 | pub fn owned(&self) -> TuplePatNode { | ||
4101 | TuplePatNode { syntax: self.syntax.owned() } | ||
4102 | } | ||
4103 | } | 2989 | } |
4104 | 2990 | ||
4105 | 2991 | ||
4106 | impl<'a> TuplePat<'a> {} | 2992 | impl TuplePat {} |
4107 | 2993 | ||
4108 | // TupleStructPat | 2994 | // TupleStructPat |
4109 | #[derive(Debug, Clone, Copy,)] | 2995 | #[derive(Debug, PartialEq, Eq, Hash)] |
4110 | pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2996 | #[repr(transparent)] |
4111 | pub(crate) syntax: SyntaxNode<R>, | 2997 | pub struct TupleStructPat { |
2998 | pub(crate) syntax: SyntaxNode, | ||
4112 | } | 2999 | } |
4113 | pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; | 3000 | unsafe impl TransparentNewType for TupleStructPat { |
4114 | 3001 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4115 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleStructPatNode<R1>> for TupleStructPatNode<R2> { | ||
4116 | fn eq(&self, other: &TupleStructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
4117 | } | ||
4118 | impl<R: TreeRoot<RaTypes>> Eq for TupleStructPatNode<R> {} | ||
4119 | impl<R: TreeRoot<RaTypes>> Hash for TupleStructPatNode<R> { | ||
4120 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4121 | } | 3002 | } |
4122 | 3003 | ||
4123 | impl<'a> AstNode<'a> for TupleStructPat<'a> { | 3004 | impl AstNode for TupleStructPat { |
4124 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3005 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4125 | match syntax.kind() { | 3006 | match syntax.kind() { |
4126 | TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }), | 3007 | TUPLE_STRUCT_PAT => Some(TupleStructPat::from_repr(syntax.into_repr())), |
4127 | _ => None, | 3008 | _ => None, |
4128 | } | 3009 | } |
4129 | } | 3010 | } |
4130 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3011 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4131 | } | 3012 | fn to_owned(&self) -> TreePtr<TupleStructPat> { TreePtr::cast(self.syntax.to_owned()) } |
4132 | |||
4133 | impl<R: TreeRoot<RaTypes>> TupleStructPatNode<R> { | ||
4134 | pub fn borrowed(&self) -> TupleStructPat { | ||
4135 | TupleStructPatNode { syntax: self.syntax.borrowed() } | ||
4136 | } | ||
4137 | pub fn owned(&self) -> TupleStructPatNode { | ||
4138 | TupleStructPatNode { syntax: self.syntax.owned() } | ||
4139 | } | ||
4140 | } | 3013 | } |
4141 | 3014 | ||
4142 | 3015 | ||
4143 | impl<'a> TupleStructPat<'a> { | 3016 | impl TupleStructPat { |
4144 | pub fn args(self) -> impl Iterator<Item = Pat<'a>> + 'a { | 3017 | pub fn args(&self) -> impl Iterator<Item = &Pat> { |
4145 | super::children(self) | 3018 | super::children(self) |
4146 | } | 3019 | } |
4147 | 3020 | ||
4148 | pub fn path(self) -> Option<Path<'a>> { | 3021 | pub fn path(&self) -> Option<&Path> { |
4149 | super::child_opt(self) | 3022 | super::child_opt(self) |
4150 | } | 3023 | } |
4151 | } | 3024 | } |
4152 | 3025 | ||
4153 | // TupleType | 3026 | // TupleType |
4154 | #[derive(Debug, Clone, Copy,)] | 3027 | #[derive(Debug, PartialEq, Eq, Hash)] |
4155 | pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3028 | #[repr(transparent)] |
4156 | pub(crate) syntax: SyntaxNode<R>, | 3029 | pub struct TupleType { |
4157 | } | 3030 | pub(crate) syntax: SyntaxNode, |
4158 | pub type TupleType<'a> = TupleTypeNode<RefRoot<'a>>; | ||
4159 | |||
4160 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleTypeNode<R1>> for TupleTypeNode<R2> { | ||
4161 | fn eq(&self, other: &TupleTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
4162 | } | 3031 | } |
4163 | impl<R: TreeRoot<RaTypes>> Eq for TupleTypeNode<R> {} | 3032 | unsafe impl TransparentNewType for TupleType { |
4164 | impl<R: TreeRoot<RaTypes>> Hash for TupleTypeNode<R> { | 3033 | type Repr = rowan::SyntaxNode<RaTypes>; |
4165 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4166 | } | 3034 | } |
4167 | 3035 | ||
4168 | impl<'a> AstNode<'a> for TupleType<'a> { | 3036 | impl AstNode for TupleType { |
4169 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3037 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4170 | match syntax.kind() { | 3038 | match syntax.kind() { |
4171 | TUPLE_TYPE => Some(TupleType { syntax }), | 3039 | TUPLE_TYPE => Some(TupleType::from_repr(syntax.into_repr())), |
4172 | _ => None, | 3040 | _ => None, |
4173 | } | 3041 | } |
4174 | } | 3042 | } |
4175 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3043 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3044 | fn to_owned(&self) -> TreePtr<TupleType> { TreePtr::cast(self.syntax.to_owned()) } | ||
4176 | } | 3045 | } |
4177 | 3046 | ||
4178 | impl<R: TreeRoot<RaTypes>> TupleTypeNode<R> { | ||
4179 | pub fn borrowed(&self) -> TupleType { | ||
4180 | TupleTypeNode { syntax: self.syntax.borrowed() } | ||
4181 | } | ||
4182 | pub fn owned(&self) -> TupleTypeNode { | ||
4183 | TupleTypeNode { syntax: self.syntax.owned() } | ||
4184 | } | ||
4185 | } | ||
4186 | 3047 | ||
4187 | 3048 | impl TupleType { | |
4188 | impl<'a> TupleType<'a> { | 3049 | pub fn fields(&self) -> impl Iterator<Item = &TypeRef> { |
4189 | pub fn fields(self) -> impl Iterator<Item = TypeRef<'a>> + 'a { | ||
4190 | super::children(self) | 3050 | super::children(self) |
4191 | } | 3051 | } |
4192 | } | 3052 | } |
4193 | 3053 | ||
4194 | // TypeDef | 3054 | // TypeDef |
4195 | #[derive(Debug, Clone, Copy,)] | 3055 | #[derive(Debug, PartialEq, Eq, Hash)] |
4196 | pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3056 | #[repr(transparent)] |
4197 | pub(crate) syntax: SyntaxNode<R>, | 3057 | pub struct TypeDef { |
4198 | } | 3058 | pub(crate) syntax: SyntaxNode, |
4199 | pub type TypeDef<'a> = TypeDefNode<RefRoot<'a>>; | ||
4200 | |||
4201 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeDefNode<R1>> for TypeDefNode<R2> { | ||
4202 | fn eq(&self, other: &TypeDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
4203 | } | 3059 | } |
4204 | impl<R: TreeRoot<RaTypes>> Eq for TypeDefNode<R> {} | 3060 | unsafe impl TransparentNewType for TypeDef { |
4205 | impl<R: TreeRoot<RaTypes>> Hash for TypeDefNode<R> { | 3061 | type Repr = rowan::SyntaxNode<RaTypes>; |
4206 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4207 | } | 3062 | } |
4208 | 3063 | ||
4209 | impl<'a> AstNode<'a> for TypeDef<'a> { | 3064 | impl AstNode for TypeDef { |
4210 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3065 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4211 | match syntax.kind() { | 3066 | match syntax.kind() { |
4212 | TYPE_DEF => Some(TypeDef { syntax }), | 3067 | TYPE_DEF => Some(TypeDef::from_repr(syntax.into_repr())), |
4213 | _ => None, | 3068 | _ => None, |
4214 | } | 3069 | } |
4215 | } | 3070 | } |
4216 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3071 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4217 | } | 3072 | fn to_owned(&self) -> TreePtr<TypeDef> { TreePtr::cast(self.syntax.to_owned()) } |
4218 | |||
4219 | impl<R: TreeRoot<RaTypes>> TypeDefNode<R> { | ||
4220 | pub fn borrowed(&self) -> TypeDef { | ||
4221 | TypeDefNode { syntax: self.syntax.borrowed() } | ||
4222 | } | ||
4223 | pub fn owned(&self) -> TypeDefNode { | ||
4224 | TypeDefNode { syntax: self.syntax.owned() } | ||
4225 | } | ||
4226 | } | 3073 | } |
4227 | 3074 | ||
4228 | 3075 | ||
4229 | impl<'a> ast::VisibilityOwner<'a> for TypeDef<'a> {} | 3076 | impl ast::VisibilityOwner for TypeDef {} |
4230 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} | 3077 | impl ast::NameOwner for TypeDef {} |
4231 | impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} | 3078 | impl ast::TypeParamsOwner for TypeDef {} |
4232 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} | 3079 | impl ast::AttrsOwner for TypeDef {} |
4233 | impl<'a> ast::DocCommentsOwner<'a> for TypeDef<'a> {} | 3080 | impl ast::DocCommentsOwner for TypeDef {} |
4234 | impl<'a> TypeDef<'a> {} | 3081 | impl TypeDef {} |
4235 | 3082 | ||
4236 | // TypeParam | 3083 | // TypeParam |
4237 | #[derive(Debug, Clone, Copy,)] | 3084 | #[derive(Debug, PartialEq, Eq, Hash)] |
4238 | pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3085 | #[repr(transparent)] |
4239 | pub(crate) syntax: SyntaxNode<R>, | 3086 | pub struct TypeParam { |
3087 | pub(crate) syntax: SyntaxNode, | ||
4240 | } | 3088 | } |
4241 | pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; | 3089 | unsafe impl TransparentNewType for TypeParam { |
4242 | 3090 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4243 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamNode<R1>> for TypeParamNode<R2> { | ||
4244 | fn eq(&self, other: &TypeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
4245 | } | ||
4246 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamNode<R> {} | ||
4247 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamNode<R> { | ||
4248 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4249 | } | 3091 | } |
4250 | 3092 | ||
4251 | impl<'a> AstNode<'a> for TypeParam<'a> { | 3093 | impl AstNode for TypeParam { |
4252 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3094 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4253 | match syntax.kind() { | 3095 | match syntax.kind() { |
4254 | TYPE_PARAM => Some(TypeParam { syntax }), | 3096 | TYPE_PARAM => Some(TypeParam::from_repr(syntax.into_repr())), |
4255 | _ => None, | 3097 | _ => None, |
4256 | } | 3098 | } |
4257 | } | 3099 | } |
4258 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3100 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4259 | } | 3101 | fn to_owned(&self) -> TreePtr<TypeParam> { TreePtr::cast(self.syntax.to_owned()) } |
4260 | |||
4261 | impl<R: TreeRoot<RaTypes>> TypeParamNode<R> { | ||
4262 | pub fn borrowed(&self) -> TypeParam { | ||
4263 | TypeParamNode { syntax: self.syntax.borrowed() } | ||
4264 | } | ||
4265 | pub fn owned(&self) -> TypeParamNode { | ||
4266 | TypeParamNode { syntax: self.syntax.owned() } | ||
4267 | } | ||
4268 | } | 3102 | } |
4269 | 3103 | ||
4270 | 3104 | ||
4271 | impl<'a> ast::NameOwner<'a> for TypeParam<'a> {} | 3105 | impl ast::NameOwner for TypeParam {} |
4272 | impl<'a> TypeParam<'a> {} | 3106 | impl TypeParam {} |
4273 | 3107 | ||
4274 | // TypeParamList | 3108 | // TypeParamList |
4275 | #[derive(Debug, Clone, Copy,)] | 3109 | #[derive(Debug, PartialEq, Eq, Hash)] |
4276 | pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3110 | #[repr(transparent)] |
4277 | pub(crate) syntax: SyntaxNode<R>, | 3111 | pub struct TypeParamList { |
3112 | pub(crate) syntax: SyntaxNode, | ||
4278 | } | 3113 | } |
4279 | pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; | 3114 | unsafe impl TransparentNewType for TypeParamList { |
4280 | 3115 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4281 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamListNode<R1>> for TypeParamListNode<R2> { | ||
4282 | fn eq(&self, other: &TypeParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
4283 | } | ||
4284 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamListNode<R> {} | ||
4285 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamListNode<R> { | ||
4286 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4287 | } | 3116 | } |
4288 | 3117 | ||
4289 | impl<'a> AstNode<'a> for TypeParamList<'a> { | 3118 | impl AstNode for TypeParamList { |
4290 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3119 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4291 | match syntax.kind() { | 3120 | match syntax.kind() { |
4292 | TYPE_PARAM_LIST => Some(TypeParamList { syntax }), | 3121 | TYPE_PARAM_LIST => Some(TypeParamList::from_repr(syntax.into_repr())), |
4293 | _ => None, | 3122 | _ => None, |
4294 | } | 3123 | } |
4295 | } | 3124 | } |
4296 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3125 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3126 | fn to_owned(&self) -> TreePtr<TypeParamList> { TreePtr::cast(self.syntax.to_owned()) } | ||
4297 | } | 3127 | } |
4298 | 3128 | ||
4299 | impl<R: TreeRoot<RaTypes>> TypeParamListNode<R> { | ||
4300 | pub fn borrowed(&self) -> TypeParamList { | ||
4301 | TypeParamListNode { syntax: self.syntax.borrowed() } | ||
4302 | } | ||
4303 | pub fn owned(&self) -> TypeParamListNode { | ||
4304 | TypeParamListNode { syntax: self.syntax.owned() } | ||
4305 | } | ||
4306 | } | ||
4307 | 3129 | ||
4308 | 3130 | impl TypeParamList { | |
4309 | impl<'a> TypeParamList<'a> { | 3131 | pub fn type_params(&self) -> impl Iterator<Item = &TypeParam> { |
4310 | pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a { | ||
4311 | super::children(self) | 3132 | super::children(self) |
4312 | } | 3133 | } |
4313 | 3134 | ||
4314 | pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a { | 3135 | pub fn lifetime_params(&self) -> impl Iterator<Item = &LifetimeParam> { |
4315 | super::children(self) | 3136 | super::children(self) |
4316 | } | 3137 | } |
4317 | } | 3138 | } |
4318 | 3139 | ||
4319 | // TypeRef | 3140 | // TypeRef |
4320 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 3141 | #[derive(Debug, PartialEq, Eq, Hash)] |
4321 | pub enum TypeRef<'a> { | 3142 | #[repr(transparent)] |
4322 | ParenType(ParenType<'a>), | 3143 | pub struct TypeRef { |
4323 | TupleType(TupleType<'a>), | 3144 | pub(crate) syntax: SyntaxNode, |
4324 | NeverType(NeverType<'a>), | 3145 | } |
4325 | PathType(PathType<'a>), | 3146 | unsafe impl TransparentNewType for TypeRef { |
4326 | PointerType(PointerType<'a>), | 3147 | type Repr = rowan::SyntaxNode<RaTypes>; |
4327 | ArrayType(ArrayType<'a>), | ||
4328 | SliceType(SliceType<'a>), | ||
4329 | ReferenceType(ReferenceType<'a>), | ||
4330 | PlaceholderType(PlaceholderType<'a>), | ||
4331 | FnPointerType(FnPointerType<'a>), | ||
4332 | ForType(ForType<'a>), | ||
4333 | ImplTraitType(ImplTraitType<'a>), | ||
4334 | DynTraitType(DynTraitType<'a>), | ||
4335 | } | ||
4336 | |||
4337 | impl<'a> AstNode<'a> for TypeRef<'a> { | ||
4338 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
4339 | match syntax.kind() { | ||
4340 | PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })), | ||
4341 | TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })), | ||
4342 | NEVER_TYPE => Some(TypeRef::NeverType(NeverType { syntax })), | ||
4343 | PATH_TYPE => Some(TypeRef::PathType(PathType { syntax })), | ||
4344 | POINTER_TYPE => Some(TypeRef::PointerType(PointerType { syntax })), | ||
4345 | ARRAY_TYPE => Some(TypeRef::ArrayType(ArrayType { syntax })), | ||
4346 | SLICE_TYPE => Some(TypeRef::SliceType(SliceType { syntax })), | ||
4347 | REFERENCE_TYPE => Some(TypeRef::ReferenceType(ReferenceType { syntax })), | ||
4348 | PLACEHOLDER_TYPE => Some(TypeRef::PlaceholderType(PlaceholderType { syntax })), | ||
4349 | FN_POINTER_TYPE => Some(TypeRef::FnPointerType(FnPointerType { syntax })), | ||
4350 | FOR_TYPE => Some(TypeRef::ForType(ForType { syntax })), | ||
4351 | IMPL_TRAIT_TYPE => Some(TypeRef::ImplTraitType(ImplTraitType { syntax })), | ||
4352 | DYN_TRAIT_TYPE => Some(TypeRef::DynTraitType(DynTraitType { syntax })), | ||
4353 | _ => None, | ||
4354 | } | ||
4355 | } | ||
4356 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
4357 | match self { | ||
4358 | TypeRef::ParenType(inner) => inner.syntax(), | ||
4359 | TypeRef::TupleType(inner) => inner.syntax(), | ||
4360 | TypeRef::NeverType(inner) => inner.syntax(), | ||
4361 | TypeRef::PathType(inner) => inner.syntax(), | ||
4362 | TypeRef::PointerType(inner) => inner.syntax(), | ||
4363 | TypeRef::ArrayType(inner) => inner.syntax(), | ||
4364 | TypeRef::SliceType(inner) => inner.syntax(), | ||
4365 | TypeRef::ReferenceType(inner) => inner.syntax(), | ||
4366 | TypeRef::PlaceholderType(inner) => inner.syntax(), | ||
4367 | TypeRef::FnPointerType(inner) => inner.syntax(), | ||
4368 | TypeRef::ForType(inner) => inner.syntax(), | ||
4369 | TypeRef::ImplTraitType(inner) => inner.syntax(), | ||
4370 | TypeRef::DynTraitType(inner) => inner.syntax(), | ||
4371 | } | ||
4372 | } | ||
4373 | } | 3148 | } |
4374 | 3149 | ||
4375 | impl<'a> TypeRef<'a> {} | 3150 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3151 | pub enum TypeRefKind<'a> { | ||
3152 | ParenType(&'a ParenType), | ||
3153 | TupleType(&'a TupleType), | ||
3154 | NeverType(&'a NeverType), | ||
3155 | PathType(&'a PathType), | ||
3156 | PointerType(&'a PointerType), | ||
3157 | ArrayType(&'a ArrayType), | ||
3158 | SliceType(&'a SliceType), | ||
3159 | ReferenceType(&'a ReferenceType), | ||
3160 | PlaceholderType(&'a PlaceholderType), | ||
3161 | FnPointerType(&'a FnPointerType), | ||
3162 | ForType(&'a ForType), | ||
3163 | ImplTraitType(&'a ImplTraitType), | ||
3164 | DynTraitType(&'a DynTraitType), | ||
3165 | } | ||
3166 | |||
3167 | impl AstNode for TypeRef { | ||
3168 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
3169 | match syntax.kind() { | ||
3170 | | PAREN_TYPE | ||
3171 | | TUPLE_TYPE | ||
3172 | | NEVER_TYPE | ||
3173 | | PATH_TYPE | ||
3174 | | POINTER_TYPE | ||
3175 | | ARRAY_TYPE | ||
3176 | | SLICE_TYPE | ||
3177 | | REFERENCE_TYPE | ||
3178 | | PLACEHOLDER_TYPE | ||
3179 | | FN_POINTER_TYPE | ||
3180 | | FOR_TYPE | ||
3181 | | IMPL_TRAIT_TYPE | ||
3182 | | DYN_TRAIT_TYPE => Some(TypeRef::from_repr(syntax.into_repr())), | ||
3183 | _ => None, | ||
3184 | } | ||
3185 | } | ||
3186 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3187 | fn to_owned(&self) -> TreePtr<TypeRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3188 | } | ||
3189 | |||
3190 | impl TypeRef { | ||
3191 | pub fn kind(&self) -> TypeRefKind { | ||
3192 | match self.syntax.kind() { | ||
3193 | PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(&self.syntax).unwrap()), | ||
3194 | TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(&self.syntax).unwrap()), | ||
3195 | NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(&self.syntax).unwrap()), | ||
3196 | PATH_TYPE => TypeRefKind::PathType(PathType::cast(&self.syntax).unwrap()), | ||
3197 | POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(&self.syntax).unwrap()), | ||
3198 | ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(&self.syntax).unwrap()), | ||
3199 | SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(&self.syntax).unwrap()), | ||
3200 | REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(&self.syntax).unwrap()), | ||
3201 | PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(&self.syntax).unwrap()), | ||
3202 | FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(&self.syntax).unwrap()), | ||
3203 | FOR_TYPE => TypeRefKind::ForType(ForType::cast(&self.syntax).unwrap()), | ||
3204 | IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(&self.syntax).unwrap()), | ||
3205 | DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(&self.syntax).unwrap()), | ||
3206 | _ => unreachable!(), | ||
3207 | } | ||
3208 | } | ||
3209 | } | ||
3210 | |||
3211 | impl TypeRef {} | ||
4376 | 3212 | ||
4377 | // UseItem | 3213 | // UseItem |
4378 | #[derive(Debug, Clone, Copy,)] | 3214 | #[derive(Debug, PartialEq, Eq, Hash)] |
4379 | pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3215 | #[repr(transparent)] |
4380 | pub(crate) syntax: SyntaxNode<R>, | 3216 | pub struct UseItem { |
3217 | pub(crate) syntax: SyntaxNode, | ||
4381 | } | 3218 | } |
4382 | pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; | 3219 | unsafe impl TransparentNewType for UseItem { |
4383 | 3220 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4384 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseItemNode<R1>> for UseItemNode<R2> { | ||
4385 | fn eq(&self, other: &UseItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
4386 | } | ||
4387 | impl<R: TreeRoot<RaTypes>> Eq for UseItemNode<R> {} | ||
4388 | impl<R: TreeRoot<RaTypes>> Hash for UseItemNode<R> { | ||
4389 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4390 | } | 3221 | } |
4391 | 3222 | ||
4392 | impl<'a> AstNode<'a> for UseItem<'a> { | 3223 | impl AstNode for UseItem { |
4393 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3224 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4394 | match syntax.kind() { | 3225 | match syntax.kind() { |
4395 | USE_ITEM => Some(UseItem { syntax }), | 3226 | USE_ITEM => Some(UseItem::from_repr(syntax.into_repr())), |
4396 | _ => None, | 3227 | _ => None, |
4397 | } | 3228 | } |
4398 | } | 3229 | } |
4399 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3230 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4400 | } | 3231 | fn to_owned(&self) -> TreePtr<UseItem> { TreePtr::cast(self.syntax.to_owned()) } |
4401 | |||
4402 | impl<R: TreeRoot<RaTypes>> UseItemNode<R> { | ||
4403 | pub fn borrowed(&self) -> UseItem { | ||
4404 | UseItemNode { syntax: self.syntax.borrowed() } | ||
4405 | } | ||
4406 | pub fn owned(&self) -> UseItemNode { | ||
4407 | UseItemNode { syntax: self.syntax.owned() } | ||
4408 | } | ||
4409 | } | 3232 | } |
4410 | 3233 | ||
4411 | 3234 | ||
4412 | impl<'a> UseItem<'a> { | 3235 | impl UseItem { |
4413 | pub fn use_tree(self) -> Option<UseTree<'a>> { | 3236 | pub fn use_tree(&self) -> Option<&UseTree> { |
4414 | super::child_opt(self) | 3237 | super::child_opt(self) |
4415 | } | 3238 | } |
4416 | } | 3239 | } |
4417 | 3240 | ||
4418 | // UseTree | 3241 | // UseTree |
4419 | #[derive(Debug, Clone, Copy,)] | 3242 | #[derive(Debug, PartialEq, Eq, Hash)] |
4420 | pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3243 | #[repr(transparent)] |
4421 | pub(crate) syntax: SyntaxNode<R>, | 3244 | pub struct UseTree { |
3245 | pub(crate) syntax: SyntaxNode, | ||
4422 | } | 3246 | } |
4423 | pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; | 3247 | unsafe impl TransparentNewType for UseTree { |
4424 | 3248 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4425 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeNode<R1>> for UseTreeNode<R2> { | ||
4426 | fn eq(&self, other: &UseTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
4427 | } | ||
4428 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeNode<R> {} | ||
4429 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeNode<R> { | ||
4430 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4431 | } | 3249 | } |
4432 | 3250 | ||
4433 | impl<'a> AstNode<'a> for UseTree<'a> { | 3251 | impl AstNode for UseTree { |
4434 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3252 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4435 | match syntax.kind() { | 3253 | match syntax.kind() { |
4436 | USE_TREE => Some(UseTree { syntax }), | 3254 | USE_TREE => Some(UseTree::from_repr(syntax.into_repr())), |
4437 | _ => None, | 3255 | _ => None, |
4438 | } | 3256 | } |
4439 | } | 3257 | } |
4440 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3258 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3259 | fn to_owned(&self) -> TreePtr<UseTree> { TreePtr::cast(self.syntax.to_owned()) } | ||
4441 | } | 3260 | } |
4442 | 3261 | ||
4443 | impl<R: TreeRoot<RaTypes>> UseTreeNode<R> { | ||
4444 | pub fn borrowed(&self) -> UseTree { | ||
4445 | UseTreeNode { syntax: self.syntax.borrowed() } | ||
4446 | } | ||
4447 | pub fn owned(&self) -> UseTreeNode { | ||
4448 | UseTreeNode { syntax: self.syntax.owned() } | ||
4449 | } | ||
4450 | } | ||
4451 | 3262 | ||
4452 | 3263 | impl UseTree { | |
4453 | impl<'a> UseTree<'a> { | 3264 | pub fn path(&self) -> Option<&Path> { |
4454 | pub fn path(self) -> Option<Path<'a>> { | ||
4455 | super::child_opt(self) | 3265 | super::child_opt(self) |
4456 | } | 3266 | } |
4457 | 3267 | ||
4458 | pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { | 3268 | pub fn use_tree_list(&self) -> Option<&UseTreeList> { |
4459 | super::child_opt(self) | 3269 | super::child_opt(self) |
4460 | } | 3270 | } |
4461 | } | 3271 | } |
4462 | 3272 | ||
4463 | // UseTreeList | 3273 | // UseTreeList |
4464 | #[derive(Debug, Clone, Copy,)] | 3274 | #[derive(Debug, PartialEq, Eq, Hash)] |
4465 | pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3275 | #[repr(transparent)] |
4466 | pub(crate) syntax: SyntaxNode<R>, | 3276 | pub struct UseTreeList { |
4467 | } | 3277 | pub(crate) syntax: SyntaxNode, |
4468 | pub type UseTreeList<'a> = UseTreeListNode<RefRoot<'a>>; | ||
4469 | |||
4470 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeListNode<R1>> for UseTreeListNode<R2> { | ||
4471 | fn eq(&self, other: &UseTreeListNode<R1>) -> bool { self.syntax == other.syntax } | ||
4472 | } | 3278 | } |
4473 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeListNode<R> {} | 3279 | unsafe impl TransparentNewType for UseTreeList { |
4474 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeListNode<R> { | 3280 | type Repr = rowan::SyntaxNode<RaTypes>; |
4475 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4476 | } | 3281 | } |
4477 | 3282 | ||
4478 | impl<'a> AstNode<'a> for UseTreeList<'a> { | 3283 | impl AstNode for UseTreeList { |
4479 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3284 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4480 | match syntax.kind() { | 3285 | match syntax.kind() { |
4481 | USE_TREE_LIST => Some(UseTreeList { syntax }), | 3286 | USE_TREE_LIST => Some(UseTreeList::from_repr(syntax.into_repr())), |
4482 | _ => None, | 3287 | _ => None, |
4483 | } | 3288 | } |
4484 | } | 3289 | } |
4485 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3290 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4486 | } | 3291 | fn to_owned(&self) -> TreePtr<UseTreeList> { TreePtr::cast(self.syntax.to_owned()) } |
4487 | |||
4488 | impl<R: TreeRoot<RaTypes>> UseTreeListNode<R> { | ||
4489 | pub fn borrowed(&self) -> UseTreeList { | ||
4490 | UseTreeListNode { syntax: self.syntax.borrowed() } | ||
4491 | } | ||
4492 | pub fn owned(&self) -> UseTreeListNode { | ||
4493 | UseTreeListNode { syntax: self.syntax.owned() } | ||
4494 | } | ||
4495 | } | 3292 | } |
4496 | 3293 | ||
4497 | 3294 | ||
4498 | impl<'a> UseTreeList<'a> { | 3295 | impl UseTreeList { |
4499 | pub fn use_trees(self) -> impl Iterator<Item = UseTree<'a>> + 'a { | 3296 | pub fn use_trees(&self) -> impl Iterator<Item = &UseTree> { |
4500 | super::children(self) | 3297 | super::children(self) |
4501 | } | 3298 | } |
4502 | } | 3299 | } |
4503 | 3300 | ||
4504 | // Visibility | 3301 | // Visibility |
4505 | #[derive(Debug, Clone, Copy,)] | 3302 | #[derive(Debug, PartialEq, Eq, Hash)] |
4506 | pub struct VisibilityNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3303 | #[repr(transparent)] |
4507 | pub(crate) syntax: SyntaxNode<R>, | 3304 | pub struct Visibility { |
3305 | pub(crate) syntax: SyntaxNode, | ||
4508 | } | 3306 | } |
4509 | pub type Visibility<'a> = VisibilityNode<RefRoot<'a>>; | 3307 | unsafe impl TransparentNewType for Visibility { |
4510 | 3308 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4511 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<VisibilityNode<R1>> for VisibilityNode<R2> { | ||
4512 | fn eq(&self, other: &VisibilityNode<R1>) -> bool { self.syntax == other.syntax } | ||
4513 | } | ||
4514 | impl<R: TreeRoot<RaTypes>> Eq for VisibilityNode<R> {} | ||
4515 | impl<R: TreeRoot<RaTypes>> Hash for VisibilityNode<R> { | ||
4516 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4517 | } | 3309 | } |
4518 | 3310 | ||
4519 | impl<'a> AstNode<'a> for Visibility<'a> { | 3311 | impl AstNode for Visibility { |
4520 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3312 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4521 | match syntax.kind() { | 3313 | match syntax.kind() { |
4522 | VISIBILITY => Some(Visibility { syntax }), | 3314 | VISIBILITY => Some(Visibility::from_repr(syntax.into_repr())), |
4523 | _ => None, | 3315 | _ => None, |
4524 | } | 3316 | } |
4525 | } | 3317 | } |
4526 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3318 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4527 | } | 3319 | fn to_owned(&self) -> TreePtr<Visibility> { TreePtr::cast(self.syntax.to_owned()) } |
4528 | |||
4529 | impl<R: TreeRoot<RaTypes>> VisibilityNode<R> { | ||
4530 | pub fn borrowed(&self) -> Visibility { | ||
4531 | VisibilityNode { syntax: self.syntax.borrowed() } | ||
4532 | } | ||
4533 | pub fn owned(&self) -> VisibilityNode { | ||
4534 | VisibilityNode { syntax: self.syntax.owned() } | ||
4535 | } | ||
4536 | } | 3320 | } |
4537 | 3321 | ||
4538 | 3322 | ||
4539 | impl<'a> Visibility<'a> {} | 3323 | impl Visibility {} |
4540 | 3324 | ||
4541 | // WhereClause | 3325 | // WhereClause |
4542 | #[derive(Debug, Clone, Copy,)] | 3326 | #[derive(Debug, PartialEq, Eq, Hash)] |
4543 | pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3327 | #[repr(transparent)] |
4544 | pub(crate) syntax: SyntaxNode<R>, | 3328 | pub struct WhereClause { |
3329 | pub(crate) syntax: SyntaxNode, | ||
4545 | } | 3330 | } |
4546 | pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; | 3331 | unsafe impl TransparentNewType for WhereClause { |
4547 | 3332 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4548 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhereClauseNode<R1>> for WhereClauseNode<R2> { | ||
4549 | fn eq(&self, other: &WhereClauseNode<R1>) -> bool { self.syntax == other.syntax } | ||
4550 | } | ||
4551 | impl<R: TreeRoot<RaTypes>> Eq for WhereClauseNode<R> {} | ||
4552 | impl<R: TreeRoot<RaTypes>> Hash for WhereClauseNode<R> { | ||
4553 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4554 | } | 3333 | } |
4555 | 3334 | ||
4556 | impl<'a> AstNode<'a> for WhereClause<'a> { | 3335 | impl AstNode for WhereClause { |
4557 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3336 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4558 | match syntax.kind() { | 3337 | match syntax.kind() { |
4559 | WHERE_CLAUSE => Some(WhereClause { syntax }), | 3338 | WHERE_CLAUSE => Some(WhereClause::from_repr(syntax.into_repr())), |
4560 | _ => None, | 3339 | _ => None, |
4561 | } | 3340 | } |
4562 | } | 3341 | } |
4563 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3342 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4564 | } | 3343 | fn to_owned(&self) -> TreePtr<WhereClause> { TreePtr::cast(self.syntax.to_owned()) } |
4565 | |||
4566 | impl<R: TreeRoot<RaTypes>> WhereClauseNode<R> { | ||
4567 | pub fn borrowed(&self) -> WhereClause { | ||
4568 | WhereClauseNode { syntax: self.syntax.borrowed() } | ||
4569 | } | ||
4570 | pub fn owned(&self) -> WhereClauseNode { | ||
4571 | WhereClauseNode { syntax: self.syntax.owned() } | ||
4572 | } | ||
4573 | } | 3344 | } |
4574 | 3345 | ||
4575 | 3346 | ||
4576 | impl<'a> WhereClause<'a> {} | 3347 | impl WhereClause {} |
4577 | 3348 | ||
4578 | // WhileExpr | 3349 | // WhileExpr |
4579 | #[derive(Debug, Clone, Copy,)] | 3350 | #[derive(Debug, PartialEq, Eq, Hash)] |
4580 | pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3351 | #[repr(transparent)] |
4581 | pub(crate) syntax: SyntaxNode<R>, | 3352 | pub struct WhileExpr { |
4582 | } | 3353 | pub(crate) syntax: SyntaxNode, |
4583 | pub type WhileExpr<'a> = WhileExprNode<RefRoot<'a>>; | ||
4584 | |||
4585 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhileExprNode<R1>> for WhileExprNode<R2> { | ||
4586 | fn eq(&self, other: &WhileExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4587 | } | 3354 | } |
4588 | impl<R: TreeRoot<RaTypes>> Eq for WhileExprNode<R> {} | 3355 | unsafe impl TransparentNewType for WhileExpr { |
4589 | impl<R: TreeRoot<RaTypes>> Hash for WhileExprNode<R> { | 3356 | type Repr = rowan::SyntaxNode<RaTypes>; |
4590 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4591 | } | 3357 | } |
4592 | 3358 | ||
4593 | impl<'a> AstNode<'a> for WhileExpr<'a> { | 3359 | impl AstNode for WhileExpr { |
4594 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3360 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4595 | match syntax.kind() { | 3361 | match syntax.kind() { |
4596 | WHILE_EXPR => Some(WhileExpr { syntax }), | 3362 | WHILE_EXPR => Some(WhileExpr::from_repr(syntax.into_repr())), |
4597 | _ => None, | 3363 | _ => None, |
4598 | } | 3364 | } |
4599 | } | 3365 | } |
4600 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3366 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3367 | fn to_owned(&self) -> TreePtr<WhileExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4601 | } | 3368 | } |
4602 | 3369 | ||
4603 | impl<R: TreeRoot<RaTypes>> WhileExprNode<R> { | ||
4604 | pub fn borrowed(&self) -> WhileExpr { | ||
4605 | WhileExprNode { syntax: self.syntax.borrowed() } | ||
4606 | } | ||
4607 | pub fn owned(&self) -> WhileExprNode { | ||
4608 | WhileExprNode { syntax: self.syntax.owned() } | ||
4609 | } | ||
4610 | } | ||
4611 | 3370 | ||
4612 | 3371 | impl ast::LoopBodyOwner for WhileExpr {} | |
4613 | impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} | 3372 | impl WhileExpr { |
4614 | impl<'a> WhileExpr<'a> { | 3373 | pub fn condition(&self) -> Option<&Condition> { |
4615 | pub fn condition(self) -> Option<Condition<'a>> { | ||
4616 | super::child_opt(self) | 3374 | super::child_opt(self) |
4617 | } | 3375 | } |
4618 | } | 3376 | } |
4619 | 3377 | ||
4620 | // Whitespace | 3378 | // Whitespace |
4621 | #[derive(Debug, Clone, Copy,)] | 3379 | #[derive(Debug, PartialEq, Eq, Hash)] |
4622 | pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3380 | #[repr(transparent)] |
4623 | pub(crate) syntax: SyntaxNode<R>, | 3381 | pub struct Whitespace { |
4624 | } | 3382 | pub(crate) syntax: SyntaxNode, |
4625 | pub type Whitespace<'a> = WhitespaceNode<RefRoot<'a>>; | ||
4626 | |||
4627 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhitespaceNode<R1>> for WhitespaceNode<R2> { | ||
4628 | fn eq(&self, other: &WhitespaceNode<R1>) -> bool { self.syntax == other.syntax } | ||
4629 | } | 3383 | } |
4630 | impl<R: TreeRoot<RaTypes>> Eq for WhitespaceNode<R> {} | 3384 | unsafe impl TransparentNewType for Whitespace { |
4631 | impl<R: TreeRoot<RaTypes>> Hash for WhitespaceNode<R> { | 3385 | type Repr = rowan::SyntaxNode<RaTypes>; |
4632 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4633 | } | 3386 | } |
4634 | 3387 | ||
4635 | impl<'a> AstNode<'a> for Whitespace<'a> { | 3388 | impl AstNode for Whitespace { |
4636 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3389 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4637 | match syntax.kind() { | 3390 | match syntax.kind() { |
4638 | WHITESPACE => Some(Whitespace { syntax }), | 3391 | WHITESPACE => Some(Whitespace::from_repr(syntax.into_repr())), |
4639 | _ => None, | 3392 | _ => None, |
4640 | } | 3393 | } |
4641 | } | 3394 | } |
4642 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3395 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4643 | } | 3396 | fn to_owned(&self) -> TreePtr<Whitespace> { TreePtr::cast(self.syntax.to_owned()) } |
4644 | |||
4645 | impl<R: TreeRoot<RaTypes>> WhitespaceNode<R> { | ||
4646 | pub fn borrowed(&self) -> Whitespace { | ||
4647 | WhitespaceNode { syntax: self.syntax.borrowed() } | ||
4648 | } | ||
4649 | pub fn owned(&self) -> WhitespaceNode { | ||
4650 | WhitespaceNode { syntax: self.syntax.owned() } | ||
4651 | } | ||
4652 | } | 3397 | } |
4653 | 3398 | ||
4654 | 3399 | ||
4655 | impl<'a> Whitespace<'a> {} | 3400 | impl ast::AstToken for Whitespace {} |
3401 | impl Whitespace {} | ||
4656 | 3402 | ||
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index 131ee09ec..0a20fc78e 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera | |||
@@ -11,89 +11,92 @@ the below applies to the result of this template | |||
11 | 11 | ||
12 | #![cfg_attr(rustfmt, rustfmt_skip)] | 12 | #![cfg_attr(rustfmt, rustfmt_skip)] |
13 | 13 | ||
14 | use std::hash::{Hash, Hasher}; | 14 | use rowan::TransparentNewType; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | ast, | 17 | SyntaxNode, SyntaxKind::*, |
18 | SyntaxNode, SyntaxNodeRef, AstNode, | 18 | yellow::{RaTypes, TreePtr}, |
19 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | 19 | ast::{self, AstNode}, |
20 | SyntaxKind::*, | ||
21 | }; | 20 | }; |
22 | {% for node, methods in ast %} | 21 | {% for node, methods in ast %} |
23 | // {{ node }} | 22 | // {{ node }} |
24 | 23 | ||
25 | {%- if methods.enum %} | 24 | {%- if methods.enum %} |
25 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
26 | #[repr(transparent)] | ||
27 | pub struct {{ node }} { | ||
28 | pub(crate) syntax: SyntaxNode, | ||
29 | } | ||
30 | unsafe impl TransparentNewType for {{ node }} { | ||
31 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
32 | } | ||
33 | |||
26 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 34 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
27 | pub enum {{ node }}<'a> { | 35 | pub enum {{ node }}Kind<'a> { |
28 | {%- for kind in methods.enum %} | 36 | {%- for kind in methods.enum %} |
29 | {{ kind }}({{ kind }}<'a>), | 37 | {{ kind }}(&'a {{ kind }}), |
30 | {%- endfor %} | 38 | {%- endfor %} |
31 | } | 39 | } |
32 | 40 | ||
33 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 41 | impl AstNode for {{ node }} { |
34 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 42 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
35 | match syntax.kind() { | 43 | match syntax.kind() { |
36 | {%- for kind in methods.enum %} | 44 | {%- for kind in methods.enum %} |
37 | {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), | 45 | | {{ kind | SCREAM }} |
38 | {%- endfor %} | 46 | {%- endfor %} => Some({{ node }}::from_repr(syntax.into_repr())), |
39 | _ => None, | 47 | _ => None, |
40 | } | 48 | } |
41 | } | 49 | } |
42 | fn syntax(self) -> SyntaxNodeRef<'a> { | 50 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
43 | match self { | 51 | fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) } |
44 | {%- for kind in methods.enum %} | 52 | } |
45 | {{ node }}::{{ kind }}(inner) => inner.syntax(), | 53 | |
46 | {%- endfor %} | 54 | impl {{ node }} { |
55 | pub fn kind(&self) -> {{ node }}Kind { | ||
56 | match self.syntax.kind() { | ||
57 | {%- for kind in methods.enum %} | ||
58 | {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(&self.syntax).unwrap()), | ||
59 | {%- endfor %} | ||
60 | _ => unreachable!(), | ||
47 | } | 61 | } |
48 | } | 62 | } |
49 | } | 63 | } |
50 | {% else %} | 64 | {% else %} |
51 | #[derive(Debug, Clone, Copy,)] | 65 | #[derive(Debug, PartialEq, Eq, Hash)] |
52 | pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> { | 66 | #[repr(transparent)] |
53 | pub(crate) syntax: SyntaxNode<R>, | 67 | pub struct {{ node }} { |
68 | pub(crate) syntax: SyntaxNode, | ||
54 | } | 69 | } |
55 | pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>; | 70 | unsafe impl TransparentNewType for {{ node }} { |
56 | 71 | type Repr = rowan::SyntaxNode<RaTypes>; | |
57 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<{{node}}Node<R1>> for {{node}}Node<R2> { | ||
58 | fn eq(&self, other: &{{node}}Node<R1>) -> bool { self.syntax == other.syntax } | ||
59 | } | ||
60 | impl<R: TreeRoot<RaTypes>> Eq for {{node}}Node<R> {} | ||
61 | impl<R: TreeRoot<RaTypes>> Hash for {{node}}Node<R> { | ||
62 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
63 | } | 72 | } |
64 | 73 | ||
65 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 74 | impl AstNode for {{ node }} { |
66 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 75 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
67 | match syntax.kind() { | 76 | match syntax.kind() { |
68 | {{ node | SCREAM }} => Some({{ node }} { syntax }), | 77 | {{ node | SCREAM }} => Some({{ node }}::from_repr(syntax.into_repr())), |
69 | _ => None, | 78 | _ => None, |
70 | } | 79 | } |
71 | } | 80 | } |
72 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 81 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
73 | } | 82 | fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) } |
74 | |||
75 | impl<R: TreeRoot<RaTypes>> {{ node }}Node<R> { | ||
76 | pub fn borrowed(&self) -> {{ node }} { | ||
77 | {{ node }}Node { syntax: self.syntax.borrowed() } | ||
78 | } | ||
79 | pub fn owned(&self) -> {{ node }}Node { | ||
80 | {{ node }}Node { syntax: self.syntax.owned() } | ||
81 | } | ||
82 | } | 83 | } |
83 | 84 | ||
84 | {% endif %} | 85 | {% endif %} |
85 | {% if methods.traits -%} | 86 | {% if methods.traits -%} |
87 | |||
86 | {%- for t in methods.traits -%} | 88 | {%- for t in methods.traits -%} |
87 | impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {} | 89 | impl ast::{{ t }} for {{ node }} {} |
88 | {% endfor -%} | 90 | {% endfor -%} |
91 | |||
89 | {%- endif -%} | 92 | {%- endif -%} |
90 | 93 | ||
91 | impl<'a> {{ node }}<'a> { | 94 | impl {{ node }} { |
92 | {%- if methods.collections -%} | 95 | {%- if methods.collections -%} |
93 | {%- for m in methods.collections -%} | 96 | {%- for m in methods.collections -%} |
94 | {%- set method_name = m.0 -%} | 97 | {%- set method_name = m.0 -%} |
95 | {%- set ChildName = m.1 %} | 98 | {%- set ChildName = m.1 %} |
96 | pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a { | 99 | pub fn {{ method_name }}(&self) -> impl Iterator<Item = &{{ ChildName }}> { |
97 | super::children(self) | 100 | super::children(self) |
98 | } | 101 | } |
99 | {% endfor -%} | 102 | {% endfor -%} |
@@ -109,7 +112,7 @@ impl<'a> {{ node }}<'a> { | |||
109 | {%- set method_name = m.0 -%} | 112 | {%- set method_name = m.0 -%} |
110 | {%- set ChildName = m.1 %} | 113 | {%- set ChildName = m.1 %} |
111 | {%- endif %} | 114 | {%- endif %} |
112 | pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { | 115 | pub fn {{ method_name }}(&self) -> Option<&{{ ChildName }}> { |
113 | super::child_opt(self) | 116 | super::child_opt(self) |
114 | } | 117 | } |
115 | {% endfor -%} | 118 | {% endfor -%} |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 3c640ed47..bddd96a5c 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -49,6 +49,7 @@ Grammar( | |||
49 | ["^=", "CARETEQ"], | 49 | ["^=", "CARETEQ"], |
50 | ["/=", "SLASHEQ"], | 50 | ["/=", "SLASHEQ"], |
51 | ["*=", "STAREQ"], | 51 | ["*=", "STAREQ"], |
52 | ["%=", "PERCENTEQ"], | ||
52 | ["&&", "AMPAMP"], | 53 | ["&&", "AMPAMP"], |
53 | ["||", "PIPEPIPE"], | 54 | ["||", "PIPEPIPE"], |
54 | ["<<", "SHL"], | 55 | ["<<", "SHL"], |
@@ -423,10 +424,10 @@ Grammar( | |||
423 | "PrefixExpr": (options: ["Expr"]), | 424 | "PrefixExpr": (options: ["Expr"]), |
424 | "RangeExpr": (), | 425 | "RangeExpr": (), |
425 | "BinExpr": (), | 426 | "BinExpr": (), |
426 | "String": (), | 427 | "String": ( traits: ["AstToken"] ), |
427 | "Byte": (), | 428 | "Byte": ( traits: ["AstToken"] ), |
428 | "ByteString": (), | 429 | "ByteString": ( traits: ["AstToken"] ), |
429 | "Char": (), | 430 | "Char": ( traits: ["AstToken"] ), |
430 | "Literal": (), | 431 | "Literal": (), |
431 | 432 | ||
432 | "Expr": ( | 433 | "Expr": ( |
@@ -504,7 +505,7 @@ Grammar( | |||
504 | ), | 505 | ), |
505 | "TypeParam": ( traits: ["NameOwner"] ), | 506 | "TypeParam": ( traits: ["NameOwner"] ), |
506 | "LifetimeParam": ( options: [ "Lifetime" ] ), | 507 | "LifetimeParam": ( options: [ "Lifetime" ] ), |
507 | "Lifetime": (), | 508 | "Lifetime": ( traits: ["AstToken"] ), |
508 | "WhereClause": (), | 509 | "WhereClause": (), |
509 | "ExprStmt": ( | 510 | "ExprStmt": ( |
510 | options: [ ["expr", "Expr"] ] | 511 | options: [ ["expr", "Expr"] ] |
@@ -561,7 +562,7 @@ Grammar( | |||
561 | "PathSegment": ( | 562 | "PathSegment": ( |
562 | options: [ "NameRef" ] | 563 | options: [ "NameRef" ] |
563 | ), | 564 | ), |
564 | "Comment": (), | 565 | "Comment": ( traits: ["AstToken"] ), |
565 | "Whitespace": (), | 566 | "Whitespace": ( traits: ["AstToken"] ), |
566 | }, | 567 | }, |
567 | ) | 568 | ) |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 6753c513f..a75e641ea 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -42,52 +42,42 @@ pub use crate::{ | |||
42 | ast::AstNode, | 42 | ast::AstNode, |
43 | lexer::{tokenize, Token}, | 43 | lexer::{tokenize, Token}, |
44 | syntax_kinds::SyntaxKind, | 44 | syntax_kinds::SyntaxKind, |
45 | yellow::{ | 45 | yellow::{Direction, SyntaxError, SyntaxNode, WalkEvent, Location, TreePtr}, |
46 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, | ||
47 | }, | ||
48 | }; | 46 | }; |
49 | 47 | ||
50 | use ra_text_edit::AtomTextEdit; | 48 | use ra_text_edit::AtomTextEdit; |
51 | use crate::yellow::GreenNode; | 49 | use crate::yellow::GreenNode; |
52 | 50 | ||
53 | /// `SourceFileNode` represents a parse tree for a single Rust file. | 51 | /// `SourceFile` represents a parse tree for a single Rust file. |
54 | pub use crate::ast::{SourceFile, SourceFileNode}; | 52 | pub use crate::ast::SourceFile; |
55 | 53 | ||
56 | impl SourceFileNode { | 54 | impl SourceFile { |
57 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { | 55 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SourceFile> { |
58 | let root = SyntaxNode::new(green, errors); | 56 | let root = SyntaxNode::new(green, errors); |
59 | if cfg!(debug_assertions) { | 57 | if cfg!(debug_assertions) { |
60 | utils::validate_block_structure(root.borrowed()); | 58 | utils::validate_block_structure(&root); |
61 | } | 59 | } |
62 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); | 60 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); |
63 | ast::SourceFileNode { syntax: root } | 61 | TreePtr::cast(root) |
64 | } | 62 | } |
65 | pub fn parse(text: &str) -> SourceFileNode { | 63 | pub fn parse(text: &str) -> TreePtr<SourceFile> { |
66 | let tokens = tokenize(&text); | 64 | let tokens = tokenize(&text); |
67 | let (green, errors) = | 65 | let (green, errors) = |
68 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); | 66 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); |
69 | SourceFileNode::new(green, errors) | 67 | SourceFile::new(green, errors) |
70 | } | 68 | } |
71 | pub fn reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { | 69 | pub fn reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { |
72 | self.incremental_reparse(edit) | 70 | self.incremental_reparse(edit) |
73 | .unwrap_or_else(|| self.full_reparse(edit)) | 71 | .unwrap_or_else(|| self.full_reparse(edit)) |
74 | } | 72 | } |
75 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<SourceFileNode> { | 73 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<TreePtr<SourceFile>> { |
76 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) | 74 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) |
77 | .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) | 75 | .map(|(green_node, errors)| SourceFile::new(green_node, errors)) |
78 | } | 76 | } |
79 | fn full_reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { | 77 | fn full_reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { |
80 | let text = | 78 | let text = |
81 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | 79 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); |
82 | SourceFileNode::parse(&text) | 80 | SourceFile::parse(&text) |
83 | } | ||
84 | /// Typed AST representation of the parse tree. | ||
85 | pub fn ast(&self) -> ast::SourceFile { | ||
86 | self.borrowed() | ||
87 | } | ||
88 | /// Untyped homogeneous representation of the parse tree. | ||
89 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
90 | self.syntax.borrowed() | ||
91 | } | 81 | } |
92 | pub fn errors(&self) -> Vec<SyntaxError> { | 82 | pub fn errors(&self) -> Vec<SyntaxError> { |
93 | let mut errors = self.syntax.root_data().clone(); | 83 | let mut errors = self.syntax.root_data().clone(); |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 7ee71a1b6..d5d72e1f8 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -4,12 +4,12 @@ use crate::lexer::{tokenize, Token}; | |||
4 | use crate::parser_api::Parser; | 4 | use crate::parser_api::Parser; |
5 | use crate::parser_impl; | 5 | use crate::parser_impl; |
6 | use crate::text_utils::replace_range; | 6 | use crate::text_utils::replace_range; |
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; | 7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNode}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | use ra_text_edit::AtomTextEdit; | 9 | use ra_text_edit::AtomTextEdit; |
10 | 10 | ||
11 | pub(crate) fn incremental_reparse( | 11 | pub(crate) fn incremental_reparse( |
12 | node: SyntaxNodeRef, | 12 | node: &SyntaxNode, |
13 | edit: &AtomTextEdit, | 13 | edit: &AtomTextEdit, |
14 | errors: Vec<SyntaxError>, | 14 | errors: Vec<SyntaxError>, |
15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { | 15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { |
@@ -21,9 +21,9 @@ pub(crate) fn incremental_reparse( | |||
21 | } | 21 | } |
22 | 22 | ||
23 | fn reparse_leaf<'node>( | 23 | fn reparse_leaf<'node>( |
24 | node: SyntaxNodeRef<'node>, | 24 | node: &'node SyntaxNode, |
25 | edit: &AtomTextEdit, | 25 | edit: &AtomTextEdit, |
26 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 26 | ) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> { |
27 | let node = algo::find_covering_node(node, edit.delete); | 27 | let node = algo::find_covering_node(node, edit.delete); |
28 | match node.kind() { | 28 | match node.kind() { |
29 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { | 29 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { |
@@ -47,9 +47,9 @@ fn reparse_leaf<'node>( | |||
47 | } | 47 | } |
48 | 48 | ||
49 | fn reparse_block<'node>( | 49 | fn reparse_block<'node>( |
50 | node: SyntaxNodeRef<'node>, | 50 | node: &'node SyntaxNode, |
51 | edit: &AtomTextEdit, | 51 | edit: &AtomTextEdit, |
52 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 52 | ) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> { |
53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; | 53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; |
54 | let text = get_text_after_edit(node, &edit); | 54 | let text = get_text_after_edit(node, &edit); |
55 | let tokens = tokenize(&text); | 55 | let tokens = tokenize(&text); |
@@ -61,7 +61,7 @@ fn reparse_block<'node>( | |||
61 | Some((node, green, new_errors)) | 61 | Some((node, green, new_errors)) |
62 | } | 62 | } |
63 | 63 | ||
64 | fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomTextEdit) -> String { | 64 | fn get_text_after_edit(node: &SyntaxNode, edit: &AtomTextEdit) -> String { |
65 | replace_range( | 65 | replace_range( |
66 | node.text().to_string(), | 66 | node.text().to_string(), |
67 | edit.delete - node.range().start(), | 67 | edit.delete - node.range().start(), |
@@ -77,17 +77,14 @@ fn is_contextual_kw(text: &str) -> bool { | |||
77 | } | 77 | } |
78 | 78 | ||
79 | type ParseFn = fn(&mut Parser); | 79 | type ParseFn = fn(&mut Parser); |
80 | fn find_reparsable_node( | 80 | fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> { |
81 | node: SyntaxNodeRef<'_>, | ||
82 | range: TextRange, | ||
83 | ) -> Option<(SyntaxNodeRef<'_>, ParseFn)> { | ||
84 | let node = algo::find_covering_node(node, range); | 81 | let node = algo::find_covering_node(node, range); |
85 | return node | 82 | return node |
86 | .ancestors() | 83 | .ancestors() |
87 | .filter_map(|node| reparser(node).map(|r| (node, r))) | 84 | .filter_map(|node| reparser(node).map(|r| (node, r))) |
88 | .next(); | 85 | .next(); |
89 | 86 | ||
90 | fn reparser(node: SyntaxNodeRef) -> Option<ParseFn> { | 87 | fn reparser(node: &SyntaxNode) -> Option<ParseFn> { |
91 | let res = match node.kind() { | 88 | let res = match node.kind() { |
92 | BLOCK => grammar::block, | 89 | BLOCK => grammar::block, |
93 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, | 90 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, |
@@ -138,7 +135,7 @@ fn is_balanced(tokens: &[Token]) -> bool { | |||
138 | fn merge_errors( | 135 | fn merge_errors( |
139 | old_errors: Vec<SyntaxError>, | 136 | old_errors: Vec<SyntaxError>, |
140 | new_errors: Vec<SyntaxError>, | 137 | new_errors: Vec<SyntaxError>, |
141 | old_node: SyntaxNodeRef, | 138 | old_node: &SyntaxNode, |
142 | edit: &AtomTextEdit, | 139 | edit: &AtomTextEdit, |
143 | ) -> Vec<SyntaxError> { | 140 | ) -> Vec<SyntaxError> { |
144 | let mut res = Vec::new(); | 141 | let mut res = Vec::new(); |
@@ -159,22 +156,22 @@ fn merge_errors( | |||
159 | mod tests { | 156 | mod tests { |
160 | use test_utils::{extract_range, assert_eq_text}; | 157 | use test_utils::{extract_range, assert_eq_text}; |
161 | 158 | ||
162 | use crate::{SourceFileNode, text_utils::replace_range, utils::dump_tree }; | 159 | use crate::{SourceFile, AstNode, text_utils::replace_range, utils::dump_tree}; |
163 | use super::*; | 160 | use super::*; |
164 | 161 | ||
165 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) | 162 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) |
166 | where | 163 | where |
167 | for<'a> F: Fn( | 164 | for<'a> F: Fn( |
168 | SyntaxNodeRef<'a>, | 165 | &'a SyntaxNode, |
169 | &AtomTextEdit, | 166 | &AtomTextEdit, |
170 | ) -> Option<(SyntaxNodeRef<'a>, GreenNode, Vec<SyntaxError>)>, | 167 | ) -> Option<(&'a SyntaxNode, GreenNode, Vec<SyntaxError>)>, |
171 | { | 168 | { |
172 | let (range, before) = extract_range(before); | 169 | let (range, before) = extract_range(before); |
173 | let after = replace_range(before.clone(), range, replace_with); | 170 | let after = replace_range(before.clone(), range, replace_with); |
174 | 171 | ||
175 | let fully_reparsed = SourceFileNode::parse(&after); | 172 | let fully_reparsed = SourceFile::parse(&after); |
176 | let incrementally_reparsed = { | 173 | let incrementally_reparsed = { |
177 | let f = SourceFileNode::parse(&before); | 174 | let f = SourceFile::parse(&before); |
178 | let edit = AtomTextEdit { | 175 | let edit = AtomTextEdit { |
179 | delete: range, | 176 | delete: range, |
180 | insert: replace_with.to_string(), | 177 | insert: replace_with.to_string(), |
@@ -183,7 +180,7 @@ mod tests { | |||
183 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); | 180 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); |
184 | let green_root = node.replace_with(green); | 181 | let green_root = node.replace_with(green); |
185 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); | 182 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); |
186 | SourceFileNode::new(green_root, errors) | 183 | SourceFile::new(green_root, errors) |
187 | }; | 184 | }; |
188 | 185 | ||
189 | assert_eq_text!( | 186 | assert_eq_text!( |
diff --git a/crates/ra_syntax/src/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs index ef4588d93..830fac9f4 100644 --- a/crates/ra_syntax/src/syntax_kinds/generated.rs +++ b/crates/ra_syntax/src/syntax_kinds/generated.rs | |||
@@ -58,6 +58,7 @@ pub enum SyntaxKind { | |||
58 | CARETEQ, | 58 | CARETEQ, |
59 | SLASHEQ, | 59 | SLASHEQ, |
60 | STAREQ, | 60 | STAREQ, |
61 | PERCENTEQ, | ||
61 | AMPAMP, | 62 | AMPAMP, |
62 | PIPEPIPE, | 63 | PIPEPIPE, |
63 | SHL, | 64 | SHL, |
@@ -319,6 +320,7 @@ impl SyntaxKind { | |||
319 | CARETEQ => &SyntaxInfo { name: "CARETEQ" }, | 320 | CARETEQ => &SyntaxInfo { name: "CARETEQ" }, |
320 | SLASHEQ => &SyntaxInfo { name: "SLASHEQ" }, | 321 | SLASHEQ => &SyntaxInfo { name: "SLASHEQ" }, |
321 | STAREQ => &SyntaxInfo { name: "STAREQ" }, | 322 | STAREQ => &SyntaxInfo { name: "STAREQ" }, |
323 | PERCENTEQ => &SyntaxInfo { name: "PERCENTEQ" }, | ||
322 | AMPAMP => &SyntaxInfo { name: "AMPAMP" }, | 324 | AMPAMP => &SyntaxInfo { name: "AMPAMP" }, |
323 | PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, | 325 | PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, |
324 | SHL => &SyntaxInfo { name: "SHL" }, | 326 | SHL => &SyntaxInfo { name: "SHL" }, |
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 0a2b6afbc..2e1b42da0 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent, AstNode}; | 1 | use std::{str, fmt::Write}; |
2 | use std::fmt::Write; | 2 | |
3 | use std::str; | 3 | use crate::{SourceFile, SyntaxKind, WalkEvent, AstNode, SyntaxNode}; |
4 | 4 | ||
5 | /// Parse a file and create a string representation of the resulting parse tree. | 5 | /// Parse a file and create a string representation of the resulting parse tree. |
6 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | 6 | pub fn dump_tree(syntax: &SyntaxNode) -> String { |
7 | let mut errors: Vec<_> = match syntax.ancestors().find_map(SourceFileNode::cast) { | 7 | let mut errors: Vec<_> = match syntax.ancestors().find_map(SourceFile::cast) { |
8 | Some(file) => file.owned().errors(), | 8 | Some(file) => file.errors(), |
9 | None => syntax.root_data().to_vec(), | 9 | None => syntax.root_data().to_vec(), |
10 | }; | 10 | }; |
11 | errors.sort_by_key(|e| e.offset()); | 11 | errors.sort_by_key(|e| e.offset()); |
@@ -48,14 +48,13 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | pub fn check_fuzz_invariants(text: &str) { | 50 | pub fn check_fuzz_invariants(text: &str) { |
51 | let file = SourceFileNode::parse(text); | 51 | let file = SourceFile::parse(text); |
52 | let root = file.syntax(); | 52 | let root = file.syntax(); |
53 | validate_block_structure(root); | 53 | validate_block_structure(root); |
54 | let _ = file.ast(); | ||
55 | let _ = file.errors(); | 54 | let _ = file.errors(); |
56 | } | 55 | } |
57 | 56 | ||
58 | pub(crate) fn validate_block_structure(root: SyntaxNodeRef) { | 57 | pub(crate) fn validate_block_structure(root: &SyntaxNode) { |
59 | let mut stack = Vec::new(); | 58 | let mut stack = Vec::new(); |
60 | for node in root.descendants() { | 59 | for node in root.descendants() { |
61 | match node.kind() { | 60 | match node.kind() { |
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index bdee8120c..73e1d20b9 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs | |||
@@ -1,16 +1,15 @@ | |||
1 | use crate::{ | ||
2 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
3 | ast, | ||
4 | SourceFileNode, | ||
5 | yellow::SyntaxError, | ||
6 | }; | ||
7 | |||
8 | mod byte; | 1 | mod byte; |
9 | mod byte_string; | 2 | mod byte_string; |
10 | mod char; | 3 | mod char; |
11 | mod string; | 4 | mod string; |
12 | 5 | ||
13 | pub(crate) fn validate(file: &SourceFileNode) -> Vec<SyntaxError> { | 6 | use crate::{ |
7 | SourceFile, yellow::SyntaxError, AstNode, | ||
8 | ast, | ||
9 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
10 | }; | ||
11 | |||
12 | pub(crate) fn validate(file: &SourceFile) -> Vec<SyntaxError> { | ||
14 | let mut errors = Vec::new(); | 13 | let mut errors = Vec::new(); |
15 | for node in file.syntax().descendants() { | 14 | for node in file.syntax().descendants() { |
16 | let _ = visitor_ctx(&mut errors) | 15 | let _ = visitor_ctx(&mut errors) |
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 714224b09..9ab4b18a3 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Validation of byte literals | 1 | //! Validation of byte literals |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | ast::{self, AstNode}, | 4 | ast::{self, AstNode, AstToken}, |
5 | string_lexing::{self, StringComponentKind}, | 5 | string_lexing::{self, StringComponentKind}, |
6 | TextRange, | 6 | TextRange, |
7 | validation::char, | 7 | validation::char, |
@@ -11,7 +11,7 @@ use crate::{ | |||
11 | }, | 11 | }, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub(super) fn validate_byte_node(node: ast::Byte, errors: &mut Vec<SyntaxError>) { | 14 | pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError>) { |
15 | let literal_text = node.text(); | 15 | let literal_text = node.text(); |
16 | let literal_range = node.syntax().range(); | 16 | let literal_range = node.syntax().range(); |
17 | let mut components = string_lexing::parse_byte_literal(literal_text); | 17 | let mut components = string_lexing::parse_byte_literal(literal_text); |
@@ -106,11 +106,11 @@ fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec<Synt | |||
106 | 106 | ||
107 | #[cfg(test)] | 107 | #[cfg(test)] |
108 | mod test { | 108 | mod test { |
109 | use crate::SourceFileNode; | 109 | use crate::{SourceFile, TreePtr}; |
110 | 110 | ||
111 | fn build_file(literal: &str) -> SourceFileNode { | 111 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
112 | let src = format!("const C: u8 = b'{}';", literal); | 112 | let src = format!("const C: u8 = b'{}';", literal); |
113 | SourceFileNode::parse(&src) | 113 | SourceFile::parse(&src) |
114 | } | 114 | } |
115 | 115 | ||
116 | fn assert_valid_byte(literal: &str) { | 116 | fn assert_valid_byte(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs index f7a4fb156..cd41a0a68 100644 --- a/crates/ra_syntax/src/validation/byte_string.rs +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode, AstToken}, |
3 | string_lexing::{self, StringComponentKind}, | 3 | string_lexing::{self, StringComponentKind}, |
4 | yellow::{ | 4 | yellow::{ |
5 | SyntaxError, | 5 | SyntaxError, |
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | 9 | ||
10 | use super::byte; | 10 | use super::byte; |
11 | 11 | ||
12 | pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec<SyntaxError>) { | 12 | pub(crate) fn validate_byte_string_node(node: &ast::ByteString, errors: &mut Vec<SyntaxError>) { |
13 | let literal_text = node.text(); | 13 | let literal_text = node.text(); |
14 | let literal_range = node.syntax().range(); | 14 | let literal_range = node.syntax().range(); |
15 | let mut components = string_lexing::parse_byte_string_literal(literal_text); | 15 | let mut components = string_lexing::parse_byte_string_literal(literal_text); |
@@ -43,12 +43,12 @@ pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec< | |||
43 | 43 | ||
44 | #[cfg(test)] | 44 | #[cfg(test)] |
45 | mod test { | 45 | mod test { |
46 | use crate::SourceFileNode; | 46 | use crate::{SourceFile, TreePtr}; |
47 | 47 | ||
48 | fn build_file(literal: &str) -> SourceFileNode { | 48 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
49 | let src = format!(r#"const S: &'static [u8] = b"{}";"#, literal); | 49 | let src = format!(r#"const S: &'static [u8] = b"{}";"#, literal); |
50 | println!("Source: {}", src); | 50 | println!("Source: {}", src); |
51 | SourceFileNode::parse(&src) | 51 | SourceFile::parse(&src) |
52 | } | 52 | } |
53 | 53 | ||
54 | fn assert_valid_str(literal: &str) { | 54 | fn assert_valid_str(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 1d6fe8837..169c88f56 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -5,7 +5,7 @@ use std::u32; | |||
5 | use arrayvec::ArrayString; | 5 | use arrayvec::ArrayString; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast::{self, AstNode}, | 8 | ast::{self, AstNode, AstToken}, |
9 | string_lexing::{self, StringComponentKind}, | 9 | string_lexing::{self, StringComponentKind}, |
10 | TextRange, | 10 | TextRange, |
11 | yellow::{ | 11 | yellow::{ |
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | }, | 14 | }, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec<SyntaxError>) { | 17 | pub(super) fn validate_char_node(node: &ast::Char, errors: &mut Vec<SyntaxError>) { |
18 | let literal_text = node.text(); | 18 | let literal_text = node.text(); |
19 | let literal_range = node.syntax().range(); | 19 | let literal_range = node.syntax().range(); |
20 | let mut components = string_lexing::parse_char_literal(literal_text); | 20 | let mut components = string_lexing::parse_char_literal(literal_text); |
@@ -175,11 +175,11 @@ fn validate_unicode_escape(text: &str, range: TextRange, errors: &mut Vec<Syntax | |||
175 | 175 | ||
176 | #[cfg(test)] | 176 | #[cfg(test)] |
177 | mod test { | 177 | mod test { |
178 | use crate::SourceFileNode; | 178 | use crate::{SourceFile, TreePtr}; |
179 | 179 | ||
180 | fn build_file(literal: &str) -> SourceFileNode { | 180 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
181 | let src = format!("const C: char = '{}';", literal); | 181 | let src = format!("const C: char = '{}';", literal); |
182 | SourceFileNode::parse(&src) | 182 | SourceFile::parse(&src) |
183 | } | 183 | } |
184 | 184 | ||
185 | fn assert_valid_char(literal: &str) { | 185 | fn assert_valid_char(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs index 1371bb1f0..cb86b765f 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode, AstToken}, |
3 | string_lexing, | 3 | string_lexing, |
4 | yellow::{ | 4 | yellow::{ |
5 | SyntaxError, | 5 | SyntaxError, |
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | 9 | ||
10 | use super::char; | 10 | use super::char; |
11 | 11 | ||
12 | pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxError>) { | 12 | pub(crate) fn validate_string_node(node: &ast::String, errors: &mut Vec<SyntaxError>) { |
13 | let literal_text = node.text(); | 13 | let literal_text = node.text(); |
14 | let literal_range = node.syntax().range(); | 14 | let literal_range = node.syntax().range(); |
15 | let mut components = string_lexing::parse_string_literal(literal_text); | 15 | let mut components = string_lexing::parse_string_literal(literal_text); |
@@ -38,12 +38,12 @@ pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxErr | |||
38 | 38 | ||
39 | #[cfg(test)] | 39 | #[cfg(test)] |
40 | mod test { | 40 | mod test { |
41 | use crate::SourceFileNode; | 41 | use crate::{SourceFile, TreePtr}; |
42 | 42 | ||
43 | fn build_file(literal: &str) -> SourceFileNode { | 43 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
44 | let src = format!(r#"const S: &'static str = "{}";"#, literal); | 44 | let src = format!(r#"const S: &'static str = "{}";"#, literal); |
45 | println!("Source: {}", src); | 45 | println!("Source: {}", src); |
46 | SourceFileNode::parse(&src) | 46 | SourceFile::parse(&src) |
47 | } | 47 | } |
48 | 48 | ||
49 | fn assert_valid_str(literal: &str) { | 49 | fn assert_valid_str(literal: &str) { |
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index cacd89dc8..1bf1806b9 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -4,15 +4,12 @@ mod syntax_text; | |||
4 | 4 | ||
5 | use self::syntax_text::SyntaxText; | 5 | use self::syntax_text::SyntaxText; |
6 | use crate::{SmolStr, SyntaxKind, TextRange}; | 6 | use crate::{SmolStr, SyntaxKind, TextRange}; |
7 | use rowan::Types; | 7 | use rowan::{Types, TransparentNewType}; |
8 | use std::{ | 8 | use std::fmt; |
9 | fmt, | ||
10 | hash::{Hash, Hasher}, | ||
11 | }; | ||
12 | 9 | ||
13 | pub(crate) use self::builder::GreenBuilder; | 10 | pub(crate) use self::builder::GreenBuilder; |
14 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; | 11 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; |
15 | pub use rowan::{TreeRoot, WalkEvent}; | 12 | pub use rowan::WalkEvent; |
16 | 13 | ||
17 | #[derive(Debug, Clone, Copy)] | 14 | #[derive(Debug, Clone, Copy)] |
18 | pub enum RaTypes {} | 15 | pub enum RaTypes {} |
@@ -21,35 +18,76 @@ impl Types for RaTypes { | |||
21 | type RootData = Vec<SyntaxError>; | 18 | type RootData = Vec<SyntaxError>; |
22 | } | 19 | } |
23 | 20 | ||
24 | pub type OwnedRoot = ::rowan::OwnedRoot<RaTypes>; | 21 | pub type GreenNode = rowan::GreenNode<RaTypes>; |
25 | pub type RefRoot<'a> = ::rowan::RefRoot<'a, RaTypes>; | ||
26 | 22 | ||
27 | pub type GreenNode = ::rowan::GreenNode<RaTypes>; | 23 | #[derive(PartialEq, Eq, Hash)] |
24 | pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | ||
25 | pub(crate) rowan::TreePtr<RaTypes, T>, | ||
26 | ); | ||
28 | 27 | ||
29 | #[derive(Clone, Copy)] | 28 | impl<T> TreePtr<T> |
30 | pub struct SyntaxNode<R: TreeRoot<RaTypes> = OwnedRoot>(pub(crate) ::rowan::SyntaxNode<RaTypes, R>); | 29 | where |
31 | pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; | 30 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
31 | { | ||
32 | pub(crate) fn cast<U>(this: TreePtr<T>) -> TreePtr<U> | ||
33 | where | ||
34 | U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
35 | { | ||
36 | TreePtr(rowan::TreePtr::cast(this.0)) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | impl<T> std::ops::Deref for TreePtr<T> | ||
41 | where | ||
42 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
43 | { | ||
44 | type Target = T; | ||
45 | fn deref(&self) -> &T { | ||
46 | self.0.deref() | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl<T> PartialEq<T> for TreePtr<T> | ||
51 | where | ||
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
53 | T: PartialEq<T>, | ||
54 | { | ||
55 | fn eq(&self, other: &T) -> bool { | ||
56 | let t: &T = self; | ||
57 | t == other | ||
58 | } | ||
59 | } | ||
32 | 60 | ||
33 | impl<R1, R2> PartialEq<SyntaxNode<R1>> for SyntaxNode<R2> | 61 | impl<T> Clone for TreePtr<T> |
34 | where | 62 | where |
35 | R1: TreeRoot<RaTypes>, | 63 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
36 | R2: TreeRoot<RaTypes>, | ||
37 | { | 64 | { |
38 | fn eq(&self, other: &SyntaxNode<R1>) -> bool { | 65 | fn clone(&self) -> TreePtr<T> { |
39 | self.0 == other.0 | 66 | TreePtr(self.0.clone()) |
40 | } | 67 | } |
41 | } | 68 | } |
42 | 69 | ||
43 | impl<R: TreeRoot<RaTypes>> Eq for SyntaxNode<R> {} | 70 | impl<T> fmt::Debug for TreePtr<T> |
44 | impl<R: TreeRoot<RaTypes>> Hash for SyntaxNode<R> { | 71 | where |
45 | fn hash<H: Hasher>(&self, state: &mut H) { | 72 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
46 | self.0.hash(state) | 73 | T: fmt::Debug, |
74 | { | ||
75 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
76 | fmt::Debug::fmt(&self.0, fmt) | ||
47 | } | 77 | } |
48 | } | 78 | } |
49 | 79 | ||
80 | #[derive(PartialEq, Eq, Hash)] | ||
81 | #[repr(transparent)] | ||
82 | pub struct SyntaxNode(pub(crate) rowan::SyntaxNode<RaTypes>); | ||
83 | unsafe impl TransparentNewType for SyntaxNode { | ||
84 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
85 | } | ||
86 | |||
50 | impl SyntaxNode { | 87 | impl SyntaxNode { |
51 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxNode { | 88 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> { |
52 | SyntaxNode(::rowan::SyntaxNode::new(green, errors)) | 89 | let ptr = TreePtr(rowan::SyntaxNode::new(green, errors)); |
90 | TreePtr::cast(ptr) | ||
53 | } | 91 | } |
54 | } | 92 | } |
55 | 93 | ||
@@ -59,45 +97,43 @@ pub enum Direction { | |||
59 | Prev, | 97 | Prev, |
60 | } | 98 | } |
61 | 99 | ||
62 | impl<'a> SyntaxNodeRef<'a> { | 100 | impl SyntaxNode { |
63 | pub fn leaf_text(self) -> Option<&'a SmolStr> { | 101 | pub fn leaf_text(&self) -> Option<&SmolStr> { |
64 | self.0.leaf_text() | 102 | self.0.leaf_text() |
65 | } | 103 | } |
66 | pub fn ancestors(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 104 | pub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode> { |
67 | crate::algo::generate(Some(self), |&node| node.parent()) | 105 | crate::algo::generate(Some(self), |&node| node.parent()) |
68 | } | 106 | } |
69 | pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 107 | pub fn descendants(&self) -> impl Iterator<Item = &SyntaxNode> { |
70 | self.preorder().filter_map(|event| match event { | 108 | self.preorder().filter_map(|event| match event { |
71 | WalkEvent::Enter(node) => Some(node), | 109 | WalkEvent::Enter(node) => Some(node), |
72 | WalkEvent::Leave(_) => None, | 110 | WalkEvent::Leave(_) => None, |
73 | }) | 111 | }) |
74 | } | 112 | } |
75 | pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 113 | pub fn siblings(&self, direction: Direction) -> impl Iterator<Item = &SyntaxNode> { |
76 | crate::algo::generate(Some(self), move |&node| match direction { | 114 | crate::algo::generate(Some(self), move |&node| match direction { |
77 | Direction::Next => node.next_sibling(), | 115 | Direction::Next => node.next_sibling(), |
78 | Direction::Prev => node.prev_sibling(), | 116 | Direction::Prev => node.prev_sibling(), |
79 | }) | 117 | }) |
80 | } | 118 | } |
81 | pub fn preorder(self) -> impl Iterator<Item = WalkEvent<SyntaxNodeRef<'a>>> { | 119 | pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode>> { |
82 | self.0.preorder().map(|event| match event { | 120 | self.0.preorder().map(|event| match event { |
83 | WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)), | 121 | WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode::from_repr(n)), |
84 | WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)), | 122 | WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode::from_repr(n)), |
85 | }) | 123 | }) |
86 | } | 124 | } |
87 | } | 125 | } |
88 | 126 | ||
89 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 127 | impl SyntaxNode { |
90 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { | 128 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { |
91 | self.0.root_data() | 129 | self.0.root_data() |
92 | } | 130 | } |
93 | pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { | 131 | pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { |
94 | self.0.replace_with(replacement) | 132 | self.0.replace_self(replacement) |
95 | } | ||
96 | pub fn borrowed<'a>(&'a self) -> SyntaxNode<RefRoot<'a>> { | ||
97 | SyntaxNode(self.0.borrowed()) | ||
98 | } | 133 | } |
99 | pub fn owned(&self) -> SyntaxNode<OwnedRoot> { | 134 | pub fn to_owned(&self) -> TreePtr<SyntaxNode> { |
100 | SyntaxNode(self.0.owned()) | 135 | let ptr = TreePtr(self.0.to_owned()); |
136 | TreePtr::cast(ptr) | ||
101 | } | 137 | } |
102 | pub fn kind(&self) -> SyntaxKind { | 138 | pub fn kind(&self) -> SyntaxKind { |
103 | self.0.kind() | 139 | self.0.kind() |
@@ -106,32 +142,32 @@ impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | |||
106 | self.0.range() | 142 | self.0.range() |
107 | } | 143 | } |
108 | pub fn text(&self) -> SyntaxText { | 144 | pub fn text(&self) -> SyntaxText { |
109 | SyntaxText::new(self.borrowed()) | 145 | SyntaxText::new(self) |
110 | } | 146 | } |
111 | pub fn is_leaf(&self) -> bool { | 147 | pub fn is_leaf(&self) -> bool { |
112 | self.0.is_leaf() | 148 | self.0.is_leaf() |
113 | } | 149 | } |
114 | pub fn parent(&self) -> Option<SyntaxNode<R>> { | 150 | pub fn parent(&self) -> Option<&SyntaxNode> { |
115 | self.0.parent().map(SyntaxNode) | 151 | self.0.parent().map(SyntaxNode::from_repr) |
116 | } | 152 | } |
117 | pub fn first_child(&self) -> Option<SyntaxNode<R>> { | 153 | pub fn first_child(&self) -> Option<&SyntaxNode> { |
118 | self.0.first_child().map(SyntaxNode) | 154 | self.0.first_child().map(SyntaxNode::from_repr) |
119 | } | 155 | } |
120 | pub fn last_child(&self) -> Option<SyntaxNode<R>> { | 156 | pub fn last_child(&self) -> Option<&SyntaxNode> { |
121 | self.0.last_child().map(SyntaxNode) | 157 | self.0.last_child().map(SyntaxNode::from_repr) |
122 | } | 158 | } |
123 | pub fn next_sibling(&self) -> Option<SyntaxNode<R>> { | 159 | pub fn next_sibling(&self) -> Option<&SyntaxNode> { |
124 | self.0.next_sibling().map(SyntaxNode) | 160 | self.0.next_sibling().map(SyntaxNode::from_repr) |
125 | } | 161 | } |
126 | pub fn prev_sibling(&self) -> Option<SyntaxNode<R>> { | 162 | pub fn prev_sibling(&self) -> Option<&SyntaxNode> { |
127 | self.0.prev_sibling().map(SyntaxNode) | 163 | self.0.prev_sibling().map(SyntaxNode::from_repr) |
128 | } | 164 | } |
129 | pub fn children(&self) -> SyntaxNodeChildren<R> { | 165 | pub fn children(&self) -> SyntaxNodeChildren { |
130 | SyntaxNodeChildren(self.0.children()) | 166 | SyntaxNodeChildren(self.0.children()) |
131 | } | 167 | } |
132 | } | 168 | } |
133 | 169 | ||
134 | impl<R: TreeRoot<RaTypes>> fmt::Debug for SyntaxNode<R> { | 170 | impl fmt::Debug for SyntaxNode { |
135 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 171 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
136 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; | 172 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; |
137 | if has_short_text(self.kind()) { | 173 | if has_short_text(self.kind()) { |
@@ -142,13 +178,13 @@ impl<R: TreeRoot<RaTypes>> fmt::Debug for SyntaxNode<R> { | |||
142 | } | 178 | } |
143 | 179 | ||
144 | #[derive(Debug)] | 180 | #[derive(Debug)] |
145 | pub struct SyntaxNodeChildren<R: TreeRoot<RaTypes>>(::rowan::SyntaxNodeChildren<RaTypes, R>); | 181 | pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>); |
146 | 182 | ||
147 | impl<R: TreeRoot<RaTypes>> Iterator for SyntaxNodeChildren<R> { | 183 | impl<'a> Iterator for SyntaxNodeChildren<'a> { |
148 | type Item = SyntaxNode<R>; | 184 | type Item = &'a SyntaxNode; |
149 | 185 | ||
150 | fn next(&mut self) -> Option<SyntaxNode<R>> { | 186 | fn next(&mut self) -> Option<&'a SyntaxNode> { |
151 | self.0.next().map(SyntaxNode) | 187 | self.0.next().map(SyntaxNode::from_repr) |
152 | } | 188 | } |
153 | } | 189 | } |
154 | 190 | ||
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 279a83b61..31db0fdab 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -3,17 +3,17 @@ use std::{fmt, ops}; | |||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 3 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
4 | use crate::{ | 4 | use crate::{ |
5 | text_utils::intersect, | 5 | text_utils::intersect, |
6 | SyntaxNodeRef, TextRange, TextUnit, | 6 | SyntaxNode, TextRange, TextUnit, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | #[derive(Clone)] | 9 | #[derive(Clone)] |
10 | pub struct SyntaxText<'a> { | 10 | pub struct SyntaxText<'a> { |
11 | node: SyntaxNodeRef<'a>, | 11 | node: &'a SyntaxNode, |
12 | range: TextRange, | 12 | range: TextRange, |
13 | } | 13 | } |
14 | 14 | ||
15 | impl<'a> SyntaxText<'a> { | 15 | impl<'a> SyntaxText<'a> { |
16 | pub(crate) fn new(node: SyntaxNodeRef<'a>) -> SyntaxText<'a> { | 16 | pub(crate) fn new(node: &'a SyntaxNode) -> SyntaxText<'a> { |
17 | SyntaxText { | 17 | SyntaxText { |
18 | node, | 18 | node, |
19 | range: node.range(), | 19 | range: node.range(), |