diff options
author | Aleksey Kladov <[email protected]> | 2019-01-07 13:15:47 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 08:20:15 +0000 |
commit | d91a98ec843ec8562c58ccb01a1e29d00cc744dc (patch) | |
tree | c628b6afbbe2e3a31ea88e6c16f556309dd0dde9 /crates/ra_syntax/src/ast/generated.rs.tera | |
parent | 55272f2023e69f3eff727ecbf77078e1b45e7f86 (diff) |
switch ra_syntax to new rowan API
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs.tera')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 93 |
1 files changed, 48 insertions, 45 deletions
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 -%} |