mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Parser] Consistently use consumeIdentifier() for normal identifiers.
consumeIdentifier() provides the general way in which we consume an identifier token and fill in an Identifier. Use it consistently in the parser.
This commit is contained in:
@@ -1243,9 +1243,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
|
||||
return false;
|
||||
}
|
||||
|
||||
Identifier name = Context.getIdentifier(Tok.getText());
|
||||
|
||||
consumeToken(tok::identifier);
|
||||
Identifier name;
|
||||
consumeIdentifier(&name);
|
||||
|
||||
auto range = SourceRange(Loc, Tok.getRange().getStart());
|
||||
|
||||
@@ -4251,8 +4250,7 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
|
||||
EndLoc = StartLoc;
|
||||
} else {
|
||||
// We have a name.
|
||||
Name = P.Context.getIdentifier(P.Tok.getText());
|
||||
NameLoc = P.consumeToken();
|
||||
NameLoc = P.consumeIdentifier(&Name);
|
||||
|
||||
auto DiagID =
|
||||
Kind == AccessorKind::Set ? diag::expected_rparen_set_name :
|
||||
@@ -6734,15 +6732,17 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
SyntaxParsingContext GroupCtxt(SyntaxContext,
|
||||
SyntaxKind::IdentifierList);
|
||||
|
||||
identifiers.push_back(Context.getIdentifier(Tok.getText()));
|
||||
identifierLocs.push_back(consumeToken(tok::identifier));
|
||||
Identifier name;
|
||||
identifierLocs.push_back(consumeIdentifier(&name));
|
||||
identifiers.push_back(name);
|
||||
|
||||
while (Tok.is(tok::comma)) {
|
||||
auto comma = consumeToken();
|
||||
|
||||
if (Tok.is(tok::identifier)) {
|
||||
identifiers.push_back(Context.getIdentifier(Tok.getText()));
|
||||
identifierLocs.push_back(consumeToken(tok::identifier));
|
||||
Identifier name;
|
||||
identifierLocs.push_back(consumeIdentifier(&name));
|
||||
identifiers.push_back(name);
|
||||
} else {
|
||||
if (Tok.isNot(tok::eof)) {
|
||||
auto otherTokLoc = consumeToken();
|
||||
@@ -7034,8 +7034,9 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
|
||||
diagnose(Tok, diag::expected_precedencegroup_relation, attrName);
|
||||
return abortBody();
|
||||
}
|
||||
auto name = Context.getIdentifier(Tok.getText());
|
||||
relations.push_back({consumeToken(), name, nullptr});
|
||||
Identifier name;
|
||||
SourceLoc nameLoc = consumeIdentifier(&name);
|
||||
relations.push_back({nameLoc, name, nullptr});
|
||||
|
||||
if (skipUnspacedCodeCompleteToken())
|
||||
return abortBody(/*hasCodeCompletion*/true);
|
||||
|
||||
@@ -2132,8 +2132,9 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
|
||||
DeclBaseName baseName;
|
||||
SourceLoc baseNameLoc;
|
||||
if (Tok.isAny(tok::identifier, tok::kw_Self, tok::kw_self)) {
|
||||
baseName = Context.getIdentifier(Tok.getText());
|
||||
baseNameLoc = consumeToken();
|
||||
Identifier baseNameId;
|
||||
baseNameLoc = consumeIdentifier(&baseNameId);
|
||||
baseName = baseNameId;
|
||||
} else if (allowOperators && Tok.isAnyOperator()) {
|
||||
baseName = Context.getIdentifier(Tok.getText());
|
||||
baseNameLoc = consumeToken();
|
||||
@@ -2643,13 +2644,17 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
|
||||
break;
|
||||
}
|
||||
|
||||
Identifier name = Tok.is(tok::identifier) ?
|
||||
Context.getIdentifier(Tok.getText()) : Identifier();
|
||||
Identifier name;
|
||||
SourceLoc nameLoc;
|
||||
if (Tok.is(tok::identifier)) {
|
||||
nameLoc = consumeIdentifier(&name);
|
||||
} else {
|
||||
nameLoc = consumeToken(tok::kw__);
|
||||
}
|
||||
auto var = new (Context)
|
||||
ParamDecl(VarDecl::Specifier::Default, SourceLoc(), SourceLoc(),
|
||||
Identifier(), Tok.getLoc(), name, nullptr);
|
||||
Identifier(), nameLoc, name, nullptr);
|
||||
elements.push_back(var);
|
||||
consumeToken();
|
||||
|
||||
// Consume a comma to continue.
|
||||
HasNext = consumeIf(tok::comma);
|
||||
|
||||
@@ -297,8 +297,8 @@ ParserStatus Parser::parseGenericWhereClause(
|
||||
getLayoutConstraint(Context.getIdentifier(Tok.getText()), Context)
|
||||
->isKnownLayout()) {
|
||||
// Parse a layout constraint.
|
||||
auto LayoutName = Context.getIdentifier(Tok.getText());
|
||||
auto LayoutLoc = consumeToken();
|
||||
Identifier LayoutName;
|
||||
auto LayoutLoc = consumeIdentifier(&LayoutName);
|
||||
auto LayoutInfo = parseLayoutConstraint(LayoutName);
|
||||
if (!LayoutInfo->isKnownLayout()) {
|
||||
// There was a bug in the layout constraint.
|
||||
|
||||
@@ -864,7 +864,12 @@ bool Parser::parseSpecificIdentifier(StringRef expected, SourceLoc &loc,
|
||||
/// its name in Result. Otherwise, emit an error and return true.
|
||||
bool Parser::parseAnyIdentifier(Identifier &Result, SourceLoc &Loc,
|
||||
const Diagnostic &D) {
|
||||
if (Tok.is(tok::identifier) || Tok.isAnyOperator()) {
|
||||
if (Tok.is(tok::identifier)) {
|
||||
Loc = consumeIdentifier(&Result);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Tok.isAnyOperator()) {
|
||||
Result = Context.getIdentifier(Tok.getText());
|
||||
Loc = Tok.getLoc();
|
||||
consumeToken();
|
||||
|
||||
Reference in New Issue
Block a user