From 5862542dedd5aca9bbdcba19c5f8cd895591005d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 13 Jan 2019 00:19:20 +0100 Subject: Add AST/HIR for type args in path segments --- crates/ra_syntax/src/ast/generated.rs | 128 ++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 271040bf4..9fe946172 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -105,6 +105,38 @@ impl ArrayType { } } +// AssocTypeArg +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct AssocTypeArg { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for AssocTypeArg { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for AssocTypeArg { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + ASSOC_TYPE_ARG => Some(AssocTypeArg::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl AssocTypeArg { + pub fn name_ref(&self) -> Option<&NameRef> { + super::child_opt(self) + } + + pub fn type_ref(&self) -> Option<&TypeRef> { + super::child_opt(self) + } +} + // Attr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] @@ -1397,6 +1429,34 @@ impl AstNode for Lifetime { impl ast::AstToken for Lifetime {} impl Lifetime {} +// LifetimeArg +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct LifetimeArg { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for LifetimeArg { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for LifetimeArg { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + LIFETIME_ARG => Some(LifetimeArg::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl LifetimeArg { + pub fn lifetime(&self) -> Option<&Lifetime> { + super::child_opt(self) + } +} + // LifetimeParam #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] @@ -2355,6 +2415,10 @@ impl PathSegment { pub fn name_ref(&self) -> Option<&NameRef> { super::child_opt(self) } + + pub fn type_arg_list(&self) -> Option<&TypeArgList> { + super::child_opt(self) + } } // PathType @@ -3335,6 +3399,70 @@ impl TupleType { } } +// TypeArg +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct TypeArg { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for TypeArg { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for TypeArg { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + TYPE_ARG => Some(TypeArg::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl TypeArg { + pub fn type_ref(&self) -> Option<&TypeRef> { + super::child_opt(self) + } +} + +// TypeArgList +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct TypeArgList { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for TypeArgList { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for TypeArgList { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + TYPE_ARG_LIST => Some(TypeArgList::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl TypeArgList { + pub fn type_args(&self) -> impl Iterator { + super::children(self) + } + + pub fn lifetime_args(&self) -> impl Iterator { + super::children(self) + } + + pub fn assoc_type_args(&self) -> impl Iterator { + super::children(self) + } +} + // TypeDef #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] -- cgit v1.2.3