aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-22 14:46:42 +0100
committerAleksey Kladov <[email protected]>2018-08-22 14:46:42 +0100
commit8e3bec11ebd1fce78701670cf9189b5a9d0d68f8 (patch)
tree16066a9bed666d0176bfa656a310fe9a264af53c /crates/libsyntax2/src/ast
parent55896aedb16e9eae6309bf129d04a75e6d26530d (diff)
TypeParamList Owner
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs35
-rw-r--r--crates/libsyntax2/src/ast/mod.rs16
2 files changed, 46 insertions, 5 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 0651da26d..d0e07fddc 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -64,6 +64,7 @@ impl<'a> AstNode<'a> for ConstDef<'a> {
64} 64}
65 65
66impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} 66impl<'a> ast::NameOwner<'a> for ConstDef<'a> {}
67impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {}
67impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} 68impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {}
68impl<'a> ConstDef<'a> {} 69impl<'a> ConstDef<'a> {}
69 70
@@ -102,6 +103,7 @@ impl<'a> AstNode<'a> for EnumDef<'a> {
102} 103}
103 104
104impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} 105impl<'a> ast::NameOwner<'a> for EnumDef<'a> {}
106impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {}
105impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} 107impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
106impl<'a> EnumDef<'a> {} 108impl<'a> EnumDef<'a> {}
107 109
@@ -152,6 +154,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
152} 154}
153 155
154impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 156impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
157impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
155impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 158impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
156impl<'a> FnDef<'a> {} 159impl<'a> FnDef<'a> {}
157 160
@@ -351,6 +354,7 @@ impl<'a> AstNode<'a> for NominalDef<'a> {
351} 354}
352 355
353impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} 356impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {}
357impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {}
354impl<'a> NominalDef<'a> {} 358impl<'a> NominalDef<'a> {}
355 359
356// ParenType 360// ParenType
@@ -478,6 +482,7 @@ impl<'a> AstNode<'a> for StaticDef<'a> {
478} 482}
479 483
480impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} 484impl<'a> ast::NameOwner<'a> for StaticDef<'a> {}
485impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
481impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} 486impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
482impl<'a> StaticDef<'a> {} 487impl<'a> StaticDef<'a> {}
483 488
@@ -498,6 +503,7 @@ impl<'a> AstNode<'a> for StructDef<'a> {
498} 503}
499 504
500impl<'a> ast::NameOwner<'a> for StructDef<'a> {} 505impl<'a> ast::NameOwner<'a> for StructDef<'a> {}
506impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {}
501impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} 507impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {}
502impl<'a> StructDef<'a> { 508impl<'a> StructDef<'a> {
503 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { 509 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a {
@@ -580,9 +586,28 @@ impl<'a> AstNode<'a> for TypeDef<'a> {
580} 586}
581 587
582impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} 588impl<'a> ast::NameOwner<'a> for TypeDef<'a> {}
589impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {}
583impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} 590impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {}
584impl<'a> TypeDef<'a> {} 591impl<'a> TypeDef<'a> {}
585 592
593// TypeParamList
594#[derive(Debug, Clone, Copy)]
595pub struct TypeParamList<'a> {
596 syntax: SyntaxNodeRef<'a>,
597}
598
599impl<'a> AstNode<'a> for TypeParamList<'a> {
600 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
601 match syntax.kind() {
602 TYPE_PARAM_LIST => Some(TypeParamList { syntax }),
603 _ => None,
604 }
605 }
606 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
607}
608
609impl<'a> TypeParamList<'a> {}
610
586// TypeRef 611// TypeRef
587#[derive(Debug, Clone, Copy)] 612#[derive(Debug, Clone, Copy)]
588pub enum TypeRef<'a> { 613pub enum TypeRef<'a> {
@@ -641,21 +666,21 @@ impl<'a> AstNode<'a> for TypeRef<'a> {
641 666
642impl<'a> TypeRef<'a> {} 667impl<'a> TypeRef<'a> {}
643 668
644// Whitespace 669// WhereClause
645#[derive(Debug, Clone, Copy)] 670#[derive(Debug, Clone, Copy)]
646pub struct Whitespace<'a> { 671pub struct WhereClause<'a> {
647 syntax: SyntaxNodeRef<'a>, 672 syntax: SyntaxNodeRef<'a>,
648} 673}
649 674
650impl<'a> AstNode<'a> for Whitespace<'a> { 675impl<'a> AstNode<'a> for WhereClause<'a> {
651 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 676 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
652 match syntax.kind() { 677 match syntax.kind() {
653 WHITESPACE => Some(Whitespace { syntax }), 678 WHERE_CLAUSE => Some(WhereClause { syntax }),
654 _ => None, 679 _ => None,
655 } 680 }
656 } 681 }
657 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 682 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
658} 683}
659 684
660impl<'a> Whitespace<'a> {} 685impl<'a> WhereClause<'a> {}
661 686
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index 5b9a07db4..1784b871e 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -24,6 +24,22 @@ pub trait NameOwner<'a>: AstNode<'a> {
24 } 24 }
25} 25}
26 26
27pub trait TypeParamsOwner<'a>: AstNode<'a> {
28 fn type_param_list(self) -> Option<TypeParamList<'a>> {
29 self.syntax()
30 .children()
31 .filter_map(TypeParamList::cast)
32 .next()
33 }
34
35 fn where_clause(self) -> Option<WhereClause<'a>> {
36 self.syntax()
37 .children()
38 .filter_map(WhereClause::cast)
39 .next()
40 }
41}
42
27pub trait AttrsOwner<'a>: AstNode<'a> { 43pub trait AttrsOwner<'a>: AstNode<'a> {
28 fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> { 44 fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> {
29 let it = self.syntax().children() 45 let it = self.syntax().children()