Skip to content

Commit c736938

Browse files
committed
Address parsing/syntax review feedback.
1 parent cd1400d commit c736938

File tree

4 files changed

+30
-37
lines changed

4 files changed

+30
-37
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ class Parser {
13881388

13891389
/// Returns true if a base type for a qualified declaration name can be
13901390
/// parsed.
1391+
///
13911392
/// Examples:
13921393
/// 'Foo.f' -> true
13931394
/// 'Foo.Bar.f' -> true

lib/Parse/ParseType.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -633,30 +633,6 @@ ParserStatus Parser::parseGenericArguments(SmallVectorImpl<TypeRepr *> &Args,
633633
return makeParserSuccess();
634634
}
635635

636-
/// Returns true if a base type for a qualified declaration name can be
637-
/// parsed.
638-
///
639-
/// Examples:
640-
/// 'Foo.f' -> true
641-
/// 'Foo.Bar.f' -> true
642-
/// 'f' -> false, no base type
643-
bool Parser::canParseBaseTypeForQualifiedDeclName() {
644-
BacktrackingScope backtrack(*this);
645-
646-
// First, parse a single type identifier component.
647-
if (!Tok.isAny(tok::identifier, tok::kw_Self, tok::kw_Any))
648-
return false;
649-
consumeToken();
650-
if (startsWithLess(Tok)) {
651-
if (!canParseGenericArguments())
652-
return false;
653-
}
654-
655-
// If the next token is a period or starts with a period, then this can be
656-
// parsed as a type qualifier.
657-
return startsWithSymbol(Tok, '.');
658-
}
659-
660636
/// parseTypeIdentifier
661637
///
662638
/// type-identifier:
@@ -1595,7 +1571,7 @@ bool Parser::canParseTypeIdentifier() {
15951571
}
15961572

15971573
// Treat 'Foo.<anything>' as an attempt to write a dotted type
1598-
// unless <anything> is 'Type'.
1574+
// unless <anything> is 'Type' or 'Protocol'.
15991575
if ((Tok.is(tok::period) || Tok.is(tok::period_prefix)) &&
16001576
!peekToken().isContextualKeyword("Type") &&
16011577
!peekToken().isContextualKeyword("Protocol")) {
@@ -1606,6 +1582,22 @@ bool Parser::canParseTypeIdentifier() {
16061582
}
16071583
}
16081584

1585+
bool Parser::canParseBaseTypeForQualifiedDeclName() {
1586+
BacktrackingScope backtrack(*this);
1587+
1588+
// First, parse a single type identifier component.
1589+
if (!Tok.isAny(tok::identifier, tok::kw_Self, tok::kw_Any))
1590+
return false;
1591+
consumeToken();
1592+
if (startsWithLess(Tok)) {
1593+
if (!canParseGenericArguments())
1594+
return false;
1595+
}
1596+
1597+
// Qualified name base types must be followed by a period.
1598+
// If the next token starts with a period, return true.
1599+
return startsWithSymbol(Tok, '.');
1600+
}
16091601

16101602
bool Parser::canParseOldStyleProtocolComposition() {
16111603
consumeToken(tok::kw_protocol);

test/AutoDiff/Parse/transpose_attr_parse.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func transpose(v: Float) -> (Float, Float, Float, Float)
2424
@transpose(of: A.B.C.foo(x:y:_:z:))
2525
func transpose(v: Float) -> Float
2626

27+
// Qualified declaration with specialized generic type.
28+
@transpose(of: A<T>.B<U, V>.C.foo(x:y:_:z:))
29+
func transpose(v: Float) -> Float
30+
2731
// Qualified operator.
2832
// TODO(TF-1065): Consider disallowing qualified operators.
2933
@transpose(of: Swift.Float.+)

utils/gyb_syntax_support/AttributeNodes.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,24 +338,20 @@
338338
children=[
339339
Child('BaseType', kind='Type', description='''
340340
The base type of the qualified name, optionally specified.
341-
''',
342-
node_choices=[
343-
Child('MemberType', kind='MemberTypeIdentifier'),
344-
Child('SimpleType', kind='SimpleTypeIdentifier'),
345-
], is_optional=True),
341+
''', is_optional=True),
346342
Child('Dot', kind='Token',
347343
token_choices=[
348344
'PeriodToken', 'PrefixPeriodToken'
349345
], is_optional=True),
350-
Child('Name', kind='Syntax', description='''
346+
Child('Name', kind='Token', description='''
351347
The base name of the referenced function.
352348
''',
353-
node_choices=[
354-
Child('Identifier', kind='IdentifierToken'),
355-
Child('PrefixOperator', kind='PrefixOperatorToken'),
356-
Child('PostfixOperator', kind='PostfixOperatorToken'),
357-
Child('SpacedBinaryOperator',
358-
kind='SpacedBinaryOperatorToken'),
349+
token_choices=[
350+
'IdentifierToken',
351+
'UnspacedBinaryOperatorToken',
352+
'SpacedBinaryOperatorToken',
353+
'PrefixOperatorToken',
354+
'PostfixOperatorToken',
359355
]),
360356
Child('Arguments', kind='DeclNameArguments',
361357
is_optional=True, description='''

0 commit comments

Comments
 (0)