2018-07-30 11:08:06 +00:00
|
|
|
mod builder;
|
2018-07-29 10:51:55 +00:00
|
|
|
mod green;
|
|
|
|
mod red;
|
|
|
|
mod syntax;
|
|
|
|
|
2018-08-10 14:49:45 +00:00
|
|
|
use std::{
|
|
|
|
ops::Deref,
|
|
|
|
sync::Arc,
|
|
|
|
ptr,
|
|
|
|
};
|
|
|
|
pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxError};
|
2018-07-29 10:51:55 +00:00
|
|
|
pub(crate) use self::{
|
2018-07-30 11:08:06 +00:00
|
|
|
builder::GreenBuilder,
|
2018-08-08 18:14:18 +00:00
|
|
|
green::GreenNode,
|
2018-07-29 10:51:55 +00:00
|
|
|
red::RedNode,
|
|
|
|
};
|
2018-08-10 14:49:45 +00:00
|
|
|
|
|
|
|
pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone + Send + Sync {}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SyntaxRoot {
|
|
|
|
red: RedNode,
|
|
|
|
pub(crate) errors: Vec<SyntaxError>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TreeRoot for Arc<SyntaxRoot> {}
|
|
|
|
|
|
|
|
impl<'a> TreeRoot for &'a SyntaxRoot {}
|
|
|
|
|
|
|
|
impl SyntaxRoot {
|
|
|
|
pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxRoot {
|
|
|
|
SyntaxRoot {
|
|
|
|
red: RedNode::new_root(green),
|
|
|
|
errors,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
pub(crate) struct RedPtr(ptr::NonNull<RedNode>);
|
|
|
|
|
|
|
|
unsafe impl Send for RedPtr {}
|
|
|
|
|
|
|
|
unsafe impl Sync for RedPtr {}
|
|
|
|
|
|
|
|
impl RedPtr {
|
|
|
|
fn new(red: &RedNode) -> RedPtr {
|
|
|
|
RedPtr(red.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn get<'a>(self, _root: &'a impl TreeRoot) -> &'a RedNode {
|
|
|
|
&*self.0.as_ptr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn assert_send_sync() {
|
|
|
|
fn f<T: Send + Sync>() {}
|
|
|
|
f::<GreenNode>();
|
|
|
|
f::<RedNode>();
|
|
|
|
f::<SyntaxNode>();
|
|
|
|
}
|