mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Use parseDeclNameRef in a few more places
This commit is contained in:
@@ -1840,6 +1840,9 @@ public:
|
||||
return DeclNameOptions(flag1) | flag2;
|
||||
}
|
||||
|
||||
/// Parse a declaration name that results in a `DeclNameRef` in the syntax
|
||||
/// tree.
|
||||
///
|
||||
/// Without \c DeclNameFlag::AllowCompoundNames, parse an
|
||||
/// unqualified-decl-base-name.
|
||||
///
|
||||
|
||||
@@ -10330,8 +10330,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
// designated protocol. These both look like identifiers, so we
|
||||
// parse them both as identifiers here and sort it out in type
|
||||
// checking.
|
||||
SourceLoc colonLoc, groupLoc;
|
||||
Identifier groupName;
|
||||
SourceLoc colonLoc;
|
||||
DeclNameLoc groupLoc;
|
||||
DeclNameRef groupName;
|
||||
if (Tok.is(tok::colon)) {
|
||||
colonLoc = consumeToken();
|
||||
if (Tok.is(tok::code_complete)) {
|
||||
@@ -10344,9 +10345,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
return makeParserCodeCompletionResult<OperatorDecl>();
|
||||
}
|
||||
|
||||
(void)parseIdentifier(groupName, groupLoc,
|
||||
diag::operator_decl_expected_precedencegroup,
|
||||
/*diagnoseDollarPrefix=*/false);
|
||||
groupName = parseDeclNameRef(groupLoc,
|
||||
diag::operator_decl_expected_precedencegroup,
|
||||
{});
|
||||
|
||||
if (Context.TypeCheckerOpts.EnableOperatorDesignatedTypes) {
|
||||
// Designated types have been removed; consume the list (mainly for source
|
||||
@@ -10361,7 +10362,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
// These have no precedence group, so we already parsed the first entry
|
||||
// in the designated types list. Retroactively include it in the range.
|
||||
typesStartLoc = colonLoc;
|
||||
typesEndLoc = groupLoc;
|
||||
typesEndLoc = groupLoc.getEndLoc();
|
||||
}
|
||||
|
||||
while (Tok.isNot(tok::eof)) {
|
||||
@@ -10380,7 +10381,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
} else {
|
||||
if (isPrefix || isPostfix) {
|
||||
// If we have nothing after the colon, then just remove the colon.
|
||||
auto endLoc = groupLoc.isValid() ? groupLoc : colonLoc;
|
||||
auto endLoc = groupLoc.isValid() ? groupLoc.getEndLoc() : colonLoc;
|
||||
diagnose(colonLoc, diag::precedencegroup_not_infix)
|
||||
.fixItRemove({colonLoc, endLoc});
|
||||
}
|
||||
@@ -10391,6 +10392,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
}
|
||||
|
||||
// Diagnose deprecated operator body syntax `operator + { ... }`.
|
||||
SourceLoc lastGoodLoc = PreviousLoc;
|
||||
SourceLoc lBraceLoc;
|
||||
if (consumeIf(tok::l_brace, lBraceLoc)) {
|
||||
if (isInfix && !Tok.is(tok::r_brace)) {
|
||||
@@ -10398,7 +10400,6 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
} else {
|
||||
auto Diag = diagnose(lBraceLoc, diag::deprecated_operator_body);
|
||||
if (Tok.is(tok::r_brace)) {
|
||||
SourceLoc lastGoodLoc = groupLoc.isValid() ? groupLoc : NameLoc;
|
||||
SourceLoc lastGoodLocEnd = Lexer::getLocForEndOfToken(SourceMgr,
|
||||
lastGoodLoc);
|
||||
SourceLoc rBraceEnd = Lexer::getLocForEndOfToken(SourceMgr, Tok.getLoc());
|
||||
@@ -10420,7 +10421,8 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
else
|
||||
res = new (Context)
|
||||
InfixOperatorDecl(CurDeclContext, OperatorLoc, Name, NameLoc, colonLoc,
|
||||
groupName, groupLoc);
|
||||
groupName.getBaseIdentifier(),
|
||||
groupLoc.getBaseNameLoc());
|
||||
|
||||
diagnoseOperatorFixityAttributes(*this, Attributes, res);
|
||||
|
||||
@@ -10639,14 +10641,16 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
|
||||
return abortBody(/*hasCodeCompletion*/true);
|
||||
}
|
||||
|
||||
if (Tok.isNot(tok::identifier)) {
|
||||
diagnose(Tok, diag::expected_precedencegroup_relation, attrName);
|
||||
DeclNameLoc nameLoc;
|
||||
auto name = parseDeclNameRef(nameLoc,
|
||||
{ diag::expected_precedencegroup_relation,
|
||||
attrName },
|
||||
{});
|
||||
if (!name) {
|
||||
return abortBody();
|
||||
}
|
||||
Identifier name;
|
||||
SourceLoc nameLoc = consumeIdentifier(name,
|
||||
/*diagnoseDollarPrefix=*/false);
|
||||
relations.push_back({nameLoc, name, nullptr});
|
||||
relations.push_back({nameLoc.getBaseNameLoc(), name.getBaseIdentifier(),
|
||||
nullptr});
|
||||
|
||||
if (skipUnspacedCodeCompleteToken())
|
||||
return abortBody(/*hasCodeCompletion*/true);
|
||||
|
||||
@@ -83,6 +83,9 @@ precedencegroup D {
|
||||
precedencegroup E {
|
||||
higherThan:
|
||||
} // expected-error {{expected name of related precedence group after 'higherThan'}}
|
||||
precedencegroup EE {
|
||||
higherThan: E,
|
||||
} // expected-error {{expected name of related precedence group after 'higherThan'}}
|
||||
|
||||
precedencegroup F {
|
||||
higherThan: A, B, C
|
||||
|
||||
Reference in New Issue
Block a user