mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
This commit is contained in:
@@ -58,7 +58,7 @@ static ParserStatus parseDefaultArgument(Parser &P,
|
||||
unsigned argIndex,
|
||||
Expr *&init,
|
||||
Parser::ParameterContextKind paramContext) {
|
||||
SourceLoc equalLoc = P.consumeLoc(tok::equal);
|
||||
SourceLoc equalLoc = P.consumeToken(tok::equal);
|
||||
|
||||
// Enter a fresh default-argument context with a meaningless parent.
|
||||
// We'll change the parent to the function later after we've created
|
||||
@@ -149,11 +149,11 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
rightParenLoc.isInvalid() && "Must start with empty state");
|
||||
|
||||
// Consume the starting '(';
|
||||
leftParenLoc = consumeLoc(tok::l_paren);
|
||||
leftParenLoc = consumeToken(tok::l_paren);
|
||||
|
||||
// Trivial case: empty parameter list.
|
||||
if (Tok.is(tok::r_paren)) {
|
||||
rightParenLoc = consumeLoc(tok::r_paren);
|
||||
rightParenLoc = consumeToken(tok::r_paren);
|
||||
return ParserStatus();
|
||||
}
|
||||
|
||||
@@ -193,25 +193,25 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
param.SpecifierKind = Tok.is(tok::kw_inout) ? ParsedParameter::InOut :
|
||||
ParsedParameter::Var;
|
||||
}
|
||||
param.LetVarInOutLoc = consumeLoc();
|
||||
param.LetVarInOutLoc = consumeToken();
|
||||
hasSpecifier = true;
|
||||
} else {
|
||||
// Redundant specifiers are fairly common, recognize, reject, and recover
|
||||
// from this gracefully.
|
||||
diagnose(Tok, diag::parameter_inout_var_let_repeated)
|
||||
.fixItRemove(Tok.getLoc());
|
||||
consumeLoc();
|
||||
consumeToken();
|
||||
}
|
||||
}
|
||||
|
||||
if (startsParameterName(*this, isClosure)) {
|
||||
// identifier-or-none for the first name
|
||||
if (Tok.is(tok::kw__)) {
|
||||
param.FirstNameLoc = consumeLoc();
|
||||
param.FirstNameLoc = consumeToken();
|
||||
} else {
|
||||
assert(Tok.canBeArgumentLabel() && "startsParameterName() lied");
|
||||
param.FirstName = Context.getIdentifier(Tok.getText());
|
||||
param.FirstNameLoc = consumeLoc();
|
||||
param.FirstNameLoc = consumeToken();
|
||||
}
|
||||
|
||||
// identifier-or-none? for the second name
|
||||
@@ -219,7 +219,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
if (!Tok.is(tok::kw__))
|
||||
param.SecondName = Context.getIdentifier(Tok.getText());
|
||||
|
||||
param.SecondNameLoc = consumeLoc();
|
||||
param.SecondNameLoc = consumeToken();
|
||||
}
|
||||
|
||||
// Operators and closures cannot have API names.
|
||||
@@ -250,10 +250,10 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
if (hasSpecifier) {
|
||||
diagnose(Tok.getLoc(), diag::parameter_inout_var_let_repeated)
|
||||
.fixItRemove(param.LetVarInOutLoc);
|
||||
consumeLoc(tok::kw_inout);
|
||||
consumeToken(tok::kw_inout);
|
||||
} else {
|
||||
hasSpecifier = true;
|
||||
param.LetVarInOutLoc = consumeLoc(tok::kw_inout);
|
||||
param.LetVarInOutLoc = consumeToken(tok::kw_inout);
|
||||
param.SpecifierKind = ParsedParameter::InOut;
|
||||
}
|
||||
}
|
||||
@@ -330,7 +330,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
|
||||
// '...'?
|
||||
if (Tok.isEllipsis())
|
||||
param.EllipsisLoc = consumeLoc();
|
||||
param.EllipsisLoc = consumeToken();
|
||||
|
||||
// ('=' expr)?
|
||||
if (Tok.is(tok::equal)) {
|
||||
@@ -649,12 +649,12 @@ Parser::parseFunctionSignature(Identifier SimpleName,
|
||||
// Check for the 'throws' keyword.
|
||||
rethrows = false;
|
||||
if (Tok.is(tok::kw_throws)) {
|
||||
throwsLoc = consumeLoc();
|
||||
throwsLoc = consumeToken();
|
||||
} else if (Tok.is(tok::kw_rethrows)) {
|
||||
throwsLoc = consumeLoc();
|
||||
throwsLoc = consumeToken();
|
||||
rethrows = true;
|
||||
} else if (Tok.is(tok::kw_throw)) {
|
||||
throwsLoc = consumeLoc();
|
||||
throwsLoc = consumeToken();
|
||||
diagnose(throwsLoc, diag::throw_in_function_type)
|
||||
.fixItReplace(throwsLoc, "throws");
|
||||
}
|
||||
@@ -666,9 +666,9 @@ Parser::parseFunctionSignature(Identifier SimpleName,
|
||||
return None;
|
||||
|
||||
if (Tok.is(tok::kw_throws)) {
|
||||
throwsLoc = consumeLoc();
|
||||
throwsLoc = consumeToken();
|
||||
} else if (Tok.is(tok::kw_rethrows)) {
|
||||
throwsLoc = consumeLoc();
|
||||
throwsLoc = consumeToken();
|
||||
rethrows = true;
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ Parser::parseFunctionSignature(Identifier SimpleName,
|
||||
// FixIt ':' to '->'.
|
||||
diagnose(Tok, diag::func_decl_expected_arrow)
|
||||
.fixItReplace(Tok.getLoc(), " -> ");
|
||||
arrowLoc = consumeLoc(tok::colon);
|
||||
arrowLoc = consumeToken(tok::colon);
|
||||
}
|
||||
|
||||
// Check for 'throws' and 'rethrows' after the arrow, but
|
||||
@@ -776,7 +776,7 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
|
||||
|
||||
// Now parse an optional type annotation.
|
||||
if (Tok.is(tok::colon)) {
|
||||
SourceLoc colonLoc = consumeLoc(tok::colon);
|
||||
SourceLoc colonLoc = consumeToken(tok::colon);
|
||||
|
||||
if (result.isNull()) // Recover by creating AnyPattern.
|
||||
result = makeParserErrorResult(new (Context) AnyPattern(colonLoc));
|
||||
@@ -842,7 +842,7 @@ ParserResult<Pattern> Parser::parsePattern() {
|
||||
return parsePatternTuple();
|
||||
|
||||
case tok::kw__:
|
||||
return makeParserResult(new (Context) AnyPattern(consumeLoc(tok::kw__)));
|
||||
return makeParserResult(new (Context) AnyPattern(consumeToken(tok::kw__)));
|
||||
|
||||
case tok::identifier: {
|
||||
Identifier name;
|
||||
@@ -855,14 +855,14 @@ ParserResult<Pattern> Parser::parsePattern() {
|
||||
if (!CurDeclContext->getAsNominalTypeOrNominalTypeExtensionContext()) {
|
||||
// This cannot be an overridden property, so just eat the token. We cannot
|
||||
// code complete anything here -- we expect an identifier.
|
||||
consumeLoc(tok::code_complete);
|
||||
consumeToken(tok::code_complete);
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
case tok::kw_var:
|
||||
case tok::kw_let: {
|
||||
bool isLet = Tok.is(tok::kw_let);
|
||||
SourceLoc varLoc = consumeLoc();
|
||||
SourceLoc varLoc = consumeToken();
|
||||
|
||||
// 'var' and 'let' patterns shouldn't nest.
|
||||
if (InVarOrLetPattern == IVOLP_InLet ||
|
||||
@@ -893,7 +893,7 @@ ParserResult<Pattern> Parser::parsePattern() {
|
||||
diagnose(Tok, diag::backticks_to_escape)
|
||||
.fixItReplace(Tok.getLoc(), "`" + Tok.getText().str() + "`");
|
||||
SourceLoc Loc = Tok.getLoc();
|
||||
consumeLoc();
|
||||
consumeToken();
|
||||
return makeParserErrorResult(new (Context) AnyPattern(Loc));
|
||||
}
|
||||
diagnose(Tok, diag::expected_pattern);
|
||||
@@ -921,7 +921,7 @@ Parser::parsePatternTupleElement() {
|
||||
// If the tuple element has a label, parse it.
|
||||
if (Tok.is(tok::identifier) && peekToken().is(tok::colon)) {
|
||||
LabelLoc = consumeIdentifier(&Label);
|
||||
consumeLoc(tok::colon);
|
||||
consumeToken(tok::colon);
|
||||
}
|
||||
|
||||
// Parse the pattern.
|
||||
@@ -943,7 +943,7 @@ Parser::parsePatternTupleElement() {
|
||||
/// pattern-tuple-element (',' pattern-tuple-body)*
|
||||
ParserResult<Pattern> Parser::parsePatternTuple() {
|
||||
StructureMarkerRAII ParsingPatternTuple(*this, Tok);
|
||||
SourceLoc LPLoc = consumeLoc(tok::l_paren);
|
||||
SourceLoc LPLoc = consumeToken(tok::l_paren);
|
||||
SourceLoc RPLoc;
|
||||
|
||||
// Parse all the elements.
|
||||
@@ -1022,14 +1022,14 @@ ParserResult<Pattern> Parser::parseMatchingPattern(bool isExprBasic) {
|
||||
if (Tok.isAny(tok::kw_var, tok::kw_let)) {
|
||||
assert(Tok.isAny(tok::kw_let, tok::kw_var) && "expects var or let");
|
||||
bool isLet = Tok.is(tok::kw_let);
|
||||
SourceLoc varLoc = consumeLoc();
|
||||
SourceLoc varLoc = consumeToken();
|
||||
|
||||
return parseMatchingPatternAsLetOrVar(isLet, varLoc, isExprBasic);
|
||||
}
|
||||
|
||||
// matching-pattern ::= 'is' type
|
||||
if (Tok.is(tok::kw_is)) {
|
||||
SourceLoc isLoc = consumeLoc(tok::kw_is);
|
||||
SourceLoc isLoc = consumeToken(tok::kw_is);
|
||||
ParserResult<TypeRepr> castType = parseType();
|
||||
if (castType.isNull() || castType.hasCodeCompletion())
|
||||
return nullptr;
|
||||
@@ -1096,11 +1096,11 @@ static bool canParsePattern(Parser &P) {
|
||||
switch (P.Tok.getKind()) {
|
||||
case tok::identifier:
|
||||
case tok::kw__:
|
||||
P.consumeLoc();
|
||||
P.consumeToken();
|
||||
return true;
|
||||
case tok::kw_let:
|
||||
case tok::kw_var:
|
||||
P.consumeLoc();
|
||||
P.consumeToken();
|
||||
return canParsePattern(P);
|
||||
case tok::l_paren:
|
||||
return canParsePatternTuple(P);
|
||||
|
||||
Reference in New Issue
Block a user