wrap TreePtr

This commit is contained in:
Aleksey Kladov 2019-01-07 16:42:10 +03:00
parent 5618c8ade1
commit b73c51ff9b
2 changed files with 54 additions and 16 deletions

18
Cargo.lock generated
View file

@ -221,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -501,7 +501,7 @@ dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -585,7 +585,7 @@ dependencies = [
"pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -970,7 +970,7 @@ dependencies = [
[[package]]
name = "rowan"
version = "0.2.0"
source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#688693ceec26b7be82918832c427b4bcb230fe24"
source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#6b50db0f68a989c512e3bbebfbc8ede70ca7f221"
dependencies = [
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1075,7 +1075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1140,7 +1140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.15.23"
version = "0.15.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1155,7 +1155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1593,7 +1593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc"
"checksum syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)" = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2"
"checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3"

View file

@ -18,19 +18,56 @@ impl Types for RaTypes {
type RootData = Vec<SyntaxError>;
}
pub type GreenNode = ::rowan::GreenNode<RaTypes>;
pub type TreePtr<T> = ::rowan::TreePtr<RaTypes, T>;
pub type GreenNode = rowan::GreenNode<RaTypes>;
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>(
pub(crate) rowan::TreePtr<RaTypes, T>,
);
impl<T> TreePtr<T>
where
T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
{
pub(crate) fn cast<U>(this: TreePtr<T>) -> TreePtr<U>
where
U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
{
TreePtr(rowan::TreePtr::cast(this.0))
}
}
impl<T> std::ops::Deref for TreePtr<T>
where
T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
{
type Target = T;
fn deref(&self) -> &T {
self.0.deref()
}
}
impl<T> fmt::Debug for TreePtr<T>
where
T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
T: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.0, fmt)
}
}
#[derive(PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct SyntaxNode(pub(crate) ::rowan::SyntaxNode<RaTypes>);
pub struct SyntaxNode(pub(crate) rowan::SyntaxNode<RaTypes>);
unsafe impl TransparentNewType for SyntaxNode {
type Repr = ::rowan::SyntaxNode<RaTypes>;
type Repr = rowan::SyntaxNode<RaTypes>;
}
impl SyntaxNode {
pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> {
TreePtr::cast(::rowan::SyntaxNode::new(green, errors))
let ptr = TreePtr(rowan::SyntaxNode::new(green, errors));
TreePtr::cast(ptr)
}
}
@ -75,7 +112,8 @@ impl SyntaxNode {
self.0.replace_self(replacement)
}
pub fn to_owned(&self) -> TreePtr<SyntaxNode> {
TreePtr::cast(self.0.to_owned())
let ptr = TreePtr(self.0.to_owned());
TreePtr::cast(ptr)
}
pub fn kind(&self) -> SyntaxKind {
self.0.kind()
@ -120,7 +158,7 @@ impl fmt::Debug for SyntaxNode {
}
#[derive(Debug)]
pub struct SyntaxNodeChildren<'a>(::rowan::SyntaxNodeChildren<'a, RaTypes>);
pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>);
impl<'a> Iterator for SyntaxNodeChildren<'a> {
type Item = &'a SyntaxNode;