aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-17 19:10:55 +0100
committerAleksey Kladov <[email protected]>2018-08-17 19:10:55 +0100
commit70097504f78c4c41368a0b864a94df95fb9c27f7 (patch)
treec4034cab3c0d0b9488c0be538ae1d4c286570de9 /crates/libsyntax2/src/yellow/mod.rs
parented7ae78c6fd9e508f6e959c6a164cf8481f6b377 (diff)
hide root
Diffstat (limited to 'crates/libsyntax2/src/yellow/mod.rs')
-rw-r--r--crates/libsyntax2/src/yellow/mod.rs40
1 files changed, 35 insertions, 5 deletions
diff --git a/crates/libsyntax2/src/yellow/mod.rs b/crates/libsyntax2/src/yellow/mod.rs
index ff3bb221b..3c4510fe7 100644
--- a/crates/libsyntax2/src/yellow/mod.rs
+++ b/crates/libsyntax2/src/yellow/mod.rs
@@ -4,7 +4,6 @@ mod red;
4mod syntax; 4mod syntax;
5 5
6use std::{ 6use std::{
7 ops::Deref,
8 sync::Arc, 7 sync::Arc,
9 ptr, 8 ptr,
10}; 9};
@@ -15,17 +14,48 @@ pub(crate) use self::{
15 red::RedNode, 14 red::RedNode,
16}; 15};
17 16
18pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone + Send + Sync {}
19
20#[derive(Debug)] 17#[derive(Debug)]
21pub struct SyntaxRoot { 18pub struct SyntaxRoot {
22 red: RedNode, 19 red: RedNode,
23 pub(crate) errors: Vec<SyntaxError>, 20 pub(crate) errors: Vec<SyntaxError>,
24} 21}
25 22
26impl TreeRoot for Arc<SyntaxRoot> {} 23pub trait TreeRoot: Clone + Send + Sync {
24 fn borrowed(&self) -> RefRoot;
25 fn owned(&self) -> OwnedRoot;
26
27 #[doc(hidden)]
28 fn syntax_root(&self) -> &SyntaxRoot;
29}
30#[derive(Clone, Debug)]
31pub struct OwnedRoot(Arc<SyntaxRoot>);
32#[derive(Clone, Copy, Debug)]
33pub struct RefRoot<'a>(&'a OwnedRoot); // TODO: shared_from_this instead of double indirection
27 34
28impl<'a> TreeRoot for &'a SyntaxRoot {} 35impl TreeRoot for OwnedRoot {
36 fn borrowed(&self) -> RefRoot {
37 RefRoot(&self)
38 }
39 fn owned(&self) -> OwnedRoot {
40 self.clone()
41 }
42
43 fn syntax_root(&self) -> &SyntaxRoot {
44 &*self.0
45 }
46}
47
48impl<'a> TreeRoot for RefRoot<'a> {
49 fn borrowed(&self) -> RefRoot {
50 *self
51 }
52 fn owned(&self) -> OwnedRoot {
53 self.0.clone()
54 }
55 fn syntax_root(&self) -> &SyntaxRoot {
56 self.0.syntax_root()
57 }
58}
29 59
30impl SyntaxRoot { 60impl SyntaxRoot {
31 pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxRoot { 61 pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxRoot {