diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-19 18:03:36 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-19 18:03:36 +0000 |
commit | 1c296d54e3dcc36c1a778873f26035000a352ba2 (patch) | |
tree | 0a6ce660ee32080287284c93bffaaaada91f3584 /crates/ra_syntax/src | |
parent | bade91db081a3465dea3547ab8ab669f78fde9dc (diff) | |
parent | 5f3509e140d19b989db418a00ac6778c622cde5d (diff) |
Merge #576
576: Beginnings of generics r=matklad a=flodiebold
This implements the beginnings of the generics infrastructure; generic parameters for structs work and are correctly substituted in fields. Functions and methods aren't handled at all yet (as the tests show).
The name resolution in `ty` really needs refactoring now, I hope to do that next ;)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 128 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 10 |
2 files changed, 137 insertions, 1 deletions
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 { | |||
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | // AssocTypeArg | ||
109 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
110 | #[repr(transparent)] | ||
111 | pub struct AssocTypeArg { | ||
112 | pub(crate) syntax: SyntaxNode, | ||
113 | } | ||
114 | unsafe impl TransparentNewType for AssocTypeArg { | ||
115 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
116 | } | ||
117 | |||
118 | impl AstNode for AssocTypeArg { | ||
119 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
120 | match syntax.kind() { | ||
121 | ASSOC_TYPE_ARG => Some(AssocTypeArg::from_repr(syntax.into_repr())), | ||
122 | _ => None, | ||
123 | } | ||
124 | } | ||
125 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
126 | fn to_owned(&self) -> TreeArc<AssocTypeArg> { TreeArc::cast(self.syntax.to_owned()) } | ||
127 | } | ||
128 | |||
129 | |||
130 | impl AssocTypeArg { | ||
131 | pub fn name_ref(&self) -> Option<&NameRef> { | ||
132 | super::child_opt(self) | ||
133 | } | ||
134 | |||
135 | pub fn type_ref(&self) -> Option<&TypeRef> { | ||
136 | super::child_opt(self) | ||
137 | } | ||
138 | } | ||
139 | |||
108 | // Attr | 140 | // Attr |
109 | #[derive(Debug, PartialEq, Eq, Hash)] | 141 | #[derive(Debug, PartialEq, Eq, Hash)] |
110 | #[repr(transparent)] | 142 | #[repr(transparent)] |
@@ -1397,6 +1429,34 @@ impl AstNode for Lifetime { | |||
1397 | impl ast::AstToken for Lifetime {} | 1429 | impl ast::AstToken for Lifetime {} |
1398 | impl Lifetime {} | 1430 | impl Lifetime {} |
1399 | 1431 | ||
1432 | // LifetimeArg | ||
1433 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1434 | #[repr(transparent)] | ||
1435 | pub struct LifetimeArg { | ||
1436 | pub(crate) syntax: SyntaxNode, | ||
1437 | } | ||
1438 | unsafe impl TransparentNewType for LifetimeArg { | ||
1439 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1440 | } | ||
1441 | |||
1442 | impl AstNode for LifetimeArg { | ||
1443 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1444 | match syntax.kind() { | ||
1445 | LIFETIME_ARG => Some(LifetimeArg::from_repr(syntax.into_repr())), | ||
1446 | _ => None, | ||
1447 | } | ||
1448 | } | ||
1449 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1450 | fn to_owned(&self) -> TreeArc<LifetimeArg> { TreeArc::cast(self.syntax.to_owned()) } | ||
1451 | } | ||
1452 | |||
1453 | |||
1454 | impl LifetimeArg { | ||
1455 | pub fn lifetime(&self) -> Option<&Lifetime> { | ||
1456 | super::child_opt(self) | ||
1457 | } | ||
1458 | } | ||
1459 | |||
1400 | // LifetimeParam | 1460 | // LifetimeParam |
1401 | #[derive(Debug, PartialEq, Eq, Hash)] | 1461 | #[derive(Debug, PartialEq, Eq, Hash)] |
1402 | #[repr(transparent)] | 1462 | #[repr(transparent)] |
@@ -2355,6 +2415,10 @@ impl PathSegment { | |||
2355 | pub fn name_ref(&self) -> Option<&NameRef> { | 2415 | pub fn name_ref(&self) -> Option<&NameRef> { |
2356 | super::child_opt(self) | 2416 | super::child_opt(self) |
2357 | } | 2417 | } |
2418 | |||
2419 | pub fn type_arg_list(&self) -> Option<&TypeArgList> { | ||
2420 | super::child_opt(self) | ||
2421 | } | ||
2358 | } | 2422 | } |
2359 | 2423 | ||
2360 | // PathType | 2424 | // PathType |
@@ -3335,6 +3399,70 @@ impl TupleType { | |||
3335 | } | 3399 | } |
3336 | } | 3400 | } |
3337 | 3401 | ||
3402 | // TypeArg | ||
3403 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
3404 | #[repr(transparent)] | ||
3405 | pub struct TypeArg { | ||
3406 | pub(crate) syntax: SyntaxNode, | ||
3407 | } | ||
3408 | unsafe impl TransparentNewType for TypeArg { | ||
3409 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
3410 | } | ||
3411 | |||
3412 | impl AstNode for TypeArg { | ||
3413 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
3414 | match syntax.kind() { | ||
3415 | TYPE_ARG => Some(TypeArg::from_repr(syntax.into_repr())), | ||
3416 | _ => None, | ||
3417 | } | ||
3418 | } | ||
3419 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3420 | fn to_owned(&self) -> TreeArc<TypeArg> { TreeArc::cast(self.syntax.to_owned()) } | ||
3421 | } | ||
3422 | |||
3423 | |||
3424 | impl TypeArg { | ||
3425 | pub fn type_ref(&self) -> Option<&TypeRef> { | ||
3426 | super::child_opt(self) | ||
3427 | } | ||
3428 | } | ||
3429 | |||
3430 | // TypeArgList | ||
3431 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
3432 | #[repr(transparent)] | ||
3433 | pub struct TypeArgList { | ||
3434 | pub(crate) syntax: SyntaxNode, | ||
3435 | } | ||
3436 | unsafe impl TransparentNewType for TypeArgList { | ||
3437 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
3438 | } | ||
3439 | |||
3440 | impl AstNode for TypeArgList { | ||
3441 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
3442 | match syntax.kind() { | ||
3443 | TYPE_ARG_LIST => Some(TypeArgList::from_repr(syntax.into_repr())), | ||
3444 | _ => None, | ||
3445 | } | ||
3446 | } | ||
3447 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3448 | fn to_owned(&self) -> TreeArc<TypeArgList> { TreeArc::cast(self.syntax.to_owned()) } | ||
3449 | } | ||
3450 | |||
3451 | |||
3452 | impl TypeArgList { | ||
3453 | pub fn type_args(&self) -> impl Iterator<Item = &TypeArg> { | ||
3454 | super::children(self) | ||
3455 | } | ||
3456 | |||
3457 | pub fn lifetime_args(&self) -> impl Iterator<Item = &LifetimeArg> { | ||
3458 | super::children(self) | ||
3459 | } | ||
3460 | |||
3461 | pub fn assoc_type_args(&self) -> impl Iterator<Item = &AssocTypeArg> { | ||
3462 | super::children(self) | ||
3463 | } | ||
3464 | } | ||
3465 | |||
3338 | // TypeDef | 3466 | // TypeDef |
3339 | #[derive(Debug, PartialEq, Eq, Hash)] | 3467 | #[derive(Debug, PartialEq, Eq, Hash)] |
3340 | #[repr(transparent)] | 3468 | #[repr(transparent)] |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index fc47c36d3..0385183fd 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -597,8 +597,16 @@ Grammar( | |||
597 | ] | 597 | ] |
598 | ), | 598 | ), |
599 | "PathSegment": ( | 599 | "PathSegment": ( |
600 | options: [ "NameRef" ] | 600 | options: [ "NameRef", "TypeArgList" ] |
601 | ), | 601 | ), |
602 | "TypeArgList": (collections: [ | ||
603 | ["type_args", "TypeArg"], | ||
604 | ["lifetime_args", "LifetimeArg"], | ||
605 | ["assoc_type_args", "AssocTypeArg"], | ||
606 | ]), | ||
607 | "TypeArg": (options: ["TypeRef"]), | ||
608 | "AssocTypeArg": (options: ["NameRef", "TypeRef"]), | ||
609 | "LifetimeArg": (options: ["Lifetime"]), | ||
602 | "Comment": ( traits: ["AstToken"] ), | 610 | "Comment": ( traits: ["AstToken"] ), |
603 | "Whitespace": ( traits: ["AstToken"] ), | 611 | "Whitespace": ( traits: ["AstToken"] ), |
604 | }, | 612 | }, |