aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/yellow/mod.rs')
-rw-r--r--crates/libsyntax2/src/yellow/mod.rs100
1 files changed, 0 insertions, 100 deletions
diff --git a/crates/libsyntax2/src/yellow/mod.rs b/crates/libsyntax2/src/yellow/mod.rs
deleted file mode 100644
index 0596e702f..000000000
--- a/crates/libsyntax2/src/yellow/mod.rs
+++ /dev/null
@@ -1,100 +0,0 @@
1mod builder;
2mod green;
3mod red;
4mod syntax;
5mod syntax_text;
6
7use std::{
8 sync::Arc,
9 ptr,
10};
11pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxError, SyntaxNodeChildren};
12pub(crate) use self::{
13 builder::GreenBuilder,
14 green::GreenNode,
15 red::RedNode,
16 syntax_text::SyntaxText,
17};
18
19#[derive(Debug)]
20pub struct SyntaxRoot {
21 red: RedNode,
22 pub(crate) errors: Vec<SyntaxError>,
23}
24
25pub trait TreeRoot: Clone + Send + Sync {
26 fn borrowed(&self) -> RefRoot;
27 fn owned(&self) -> OwnedRoot;
28
29 #[doc(hidden)]
30 fn syntax_root(&self) -> &SyntaxRoot;
31}
32#[derive(Clone, Debug)]
33pub struct OwnedRoot(Arc<SyntaxRoot>);
34#[derive(Clone, Copy, Debug)]
35pub struct RefRoot<'a>(&'a OwnedRoot); // TODO: shared_from_this instead of double indirection
36
37impl<'a> RefRoot<'a> {
38 fn syntax_root(&self) -> &'a SyntaxRoot {
39 self.0.syntax_root()
40 }
41}
42
43impl TreeRoot for OwnedRoot {
44 fn borrowed(&self) -> RefRoot {
45 RefRoot(&self)
46 }
47 fn owned(&self) -> OwnedRoot {
48 self.clone()
49 }
50
51 fn syntax_root(&self) -> &SyntaxRoot {
52 &*self.0
53 }
54}
55
56impl<'a> TreeRoot for RefRoot<'a> {
57 fn borrowed(&self) -> RefRoot {
58 *self
59 }
60 fn owned(&self) -> OwnedRoot {
61 self.0.clone()
62 }
63 fn syntax_root(&self) -> &SyntaxRoot {
64 self.0.syntax_root()
65 }
66}
67
68impl SyntaxRoot {
69 pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxRoot {
70 SyntaxRoot {
71 red: RedNode::new_root(green),
72 errors,
73 }
74 }
75}
76
77#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
78pub(crate) struct RedPtr(ptr::NonNull<RedNode>);
79
80unsafe impl Send for RedPtr {}
81
82unsafe impl Sync for RedPtr {}
83
84impl RedPtr {
85 fn new(red: &RedNode) -> RedPtr {
86 RedPtr(red.into())
87 }
88
89 unsafe fn get<'a>(self, _root: &'a SyntaxRoot) -> &'a RedNode {
90 &*self.0.as_ptr()
91 }
92}
93
94#[test]
95fn assert_send_sync() {
96 fn f<T: Send + Sync>() {}
97 f::<GreenNode>();
98 f::<RedNode>();
99 f::<SyntaxNode>();
100}