diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs.tera')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index 1321f0def..131ee09ec 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera | |||
@@ -3,34 +3,27 @@ the below applies to the result of this template | |||
3 | #}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run | 3 | #}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run |
4 | // Do not edit manually | 4 | // Do not edit manually |
5 | 5 | ||
6 | //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes | ||
7 | //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode` | ||
8 | //! are Arc-based. You can switch between the two variants using `.owned` and | ||
9 | //! `.borrowed` functions. Most of the code works with borowed mode, and only | ||
10 | //! this mode has all AST accessors. | ||
11 | |||
6 | #![cfg_attr(rustfmt, rustfmt_skip)] | 12 | #![cfg_attr(rustfmt, rustfmt_skip)] |
7 | 13 | ||
14 | use std::hash::{Hash, Hasher}; | ||
15 | |||
8 | use crate::{ | 16 | use crate::{ |
9 | ast, | 17 | ast, |
10 | SyntaxNode, SyntaxNodeRef, AstNode, | 18 | SyntaxNode, SyntaxNodeRef, AstNode, |
19 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | ||
11 | SyntaxKind::*, | 20 | SyntaxKind::*, |
12 | }; | 21 | }; |
13 | {% for node, methods in ast %} | 22 | {% for node, methods in ast %} |
14 | // {{ node }} | 23 | // {{ node }} |
15 | 24 | ||
16 | #[derive(Debug, Clone)] | ||
17 | pub struct {{ node }}Node(SyntaxNode); | ||
18 | |||
19 | impl {{ node }}Node { | ||
20 | pub fn ast(&self) -> {{ node }} { | ||
21 | {{ node }}::cast(self.0.borrowed()).unwrap() | ||
22 | } | ||
23 | } | ||
24 | |||
25 | impl<'a> From<{{ node }}<'a>> for {{ node }}Node { | ||
26 | fn from(ast: {{ node}}<'a>) -> {{ node }}Node { | ||
27 | let syntax = ast.syntax().owned(); | ||
28 | {{ node }}Node(syntax) | ||
29 | } | ||
30 | } | ||
31 | |||
32 | {%- if methods.enum %} | 25 | {%- if methods.enum %} |
33 | #[derive(Debug, Clone, Copy)] | 26 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
34 | pub enum {{ node }}<'a> { | 27 | pub enum {{ node }}<'a> { |
35 | {%- for kind in methods.enum %} | 28 | {%- for kind in methods.enum %} |
36 | {{ kind }}({{ kind }}<'a>), | 29 | {{ kind }}({{ kind }}<'a>), |
@@ -55,9 +48,18 @@ impl<'a> AstNode<'a> for {{ node }}<'a> { | |||
55 | } | 48 | } |
56 | } | 49 | } |
57 | {% else %} | 50 | {% else %} |
58 | #[derive(Debug, Clone, Copy)] | 51 | #[derive(Debug, Clone, Copy,)] |
59 | pub struct {{ node }}<'a> { | 52 | pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> { |
60 | syntax: SyntaxNodeRef<'a>, | 53 | pub(crate) syntax: SyntaxNode<R>, |
54 | } | ||
55 | pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>; | ||
56 | |||
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) } | ||
61 | } | 63 | } |
62 | 64 | ||
63 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 65 | impl<'a> AstNode<'a> for {{ node }}<'a> { |
@@ -69,6 +71,16 @@ impl<'a> AstNode<'a> for {{ node }}<'a> { | |||
69 | } | 71 | } |
70 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 72 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
71 | } | 73 | } |
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 | |||
72 | {% endif %} | 84 | {% endif %} |
73 | {% if methods.traits -%} | 85 | {% if methods.traits -%} |
74 | {%- for t in methods.traits -%} | 86 | {%- for t in methods.traits -%} |