forked from OSchip/llvm-project
Parse: Token consumption modernization and loop de-nesting
Cleanup only. llvm-svn: 198539
This commit is contained in:
parent
0db10c4fef
commit
094e521e3f
|
@ -132,45 +132,50 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
|
|||
return;
|
||||
}
|
||||
// Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
|
||||
while (Tok.is(tok::identifier) || isDeclarationSpecifier() ||
|
||||
Tok.is(tok::comma)) {
|
||||
if (Tok.is(tok::comma)) {
|
||||
// allows for empty/non-empty attributes. ((__vector_size__(16),,,,))
|
||||
ConsumeToken();
|
||||
while (true) {
|
||||
// Allow empty/non-empty attributes. ((__vector_size__(16),,,,))
|
||||
if (TryConsumeToken(tok::comma))
|
||||
continue;
|
||||
}
|
||||
// we have an identifier or declaration specifier (const, int, etc.)
|
||||
|
||||
// Expect an identifier or declaration specifier (const, int, etc.)
|
||||
if (Tok.isNot(tok::identifier) && !isDeclarationSpecifier())
|
||||
break;
|
||||
|
||||
IdentifierInfo *AttrName = Tok.getIdentifierInfo();
|
||||
SourceLocation AttrNameLoc = ConsumeToken();
|
||||
|
||||
if (Tok.is(tok::l_paren)) {
|
||||
// handle "parameterized" attributes
|
||||
if (LateAttrs && isAttributeLateParsed(*AttrName)) {
|
||||
LateParsedAttribute *LA =
|
||||
new LateParsedAttribute(this, *AttrName, AttrNameLoc);
|
||||
LateAttrs->push_back(LA);
|
||||
|
||||
// Attributes in a class are parsed at the end of the class, along
|
||||
// with other late-parsed declarations.
|
||||
if (!ClassStack.empty() && !LateAttrs->parseSoon())
|
||||
getCurrentClass().LateParsedDeclarations.push_back(LA);
|
||||
|
||||
// consume everything up to and including the matching right parens
|
||||
ConsumeAndStoreUntil(tok::r_paren, LA->Toks, true, false);
|
||||
|
||||
Token Eof;
|
||||
Eof.startToken();
|
||||
Eof.setLocation(Tok.getLocation());
|
||||
LA->Toks.push_back(Eof);
|
||||
} else {
|
||||
ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc,
|
||||
0, SourceLocation(), AttributeList::AS_GNU);
|
||||
}
|
||||
} else {
|
||||
if (Tok.isNot(tok::l_paren)) {
|
||||
attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, 0,
|
||||
AttributeList::AS_GNU);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle "parameterized" attributes
|
||||
if (!LateAttrs || !isAttributeLateParsed(*AttrName)) {
|
||||
ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc, 0,
|
||||
SourceLocation(), AttributeList::AS_GNU);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle attributes with arguments that require late parsing.
|
||||
LateParsedAttribute *LA =
|
||||
new LateParsedAttribute(this, *AttrName, AttrNameLoc);
|
||||
LateAttrs->push_back(LA);
|
||||
|
||||
// Attributes in a class are parsed at the end of the class, along
|
||||
// with other late-parsed declarations.
|
||||
if (!ClassStack.empty() && !LateAttrs->parseSoon())
|
||||
getCurrentClass().LateParsedDeclarations.push_back(LA);
|
||||
|
||||
// consume everything up to and including the matching right parens
|
||||
ConsumeAndStoreUntil(tok::r_paren, LA->Toks, true, false);
|
||||
|
||||
Token Eof;
|
||||
Eof.startToken();
|
||||
Eof.setLocation(Tok.getLocation());
|
||||
LA->Toks.push_back(Eof);
|
||||
}
|
||||
|
||||
if (ExpectAndConsume(tok::r_paren))
|
||||
SkipUntil(tok::r_paren, StopAtSemi);
|
||||
SourceLocation Loc = Tok.getLocation();
|
||||
|
@ -491,17 +496,15 @@ void Parser::ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident,
|
|||
|
||||
next_property_accessor:
|
||||
// Keep processing accessors until we run out.
|
||||
if (Tok.is(tok::comma)) {
|
||||
ConsumeAnyToken();
|
||||
if (TryConsumeToken(tok::comma))
|
||||
continue;
|
||||
|
||||
// If we run into the ')', stop without consuming it.
|
||||
} else if (Tok.is(tok::r_paren)) {
|
||||
if (Tok.is(tok::r_paren))
|
||||
break;
|
||||
} else {
|
||||
Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen);
|
||||
break;
|
||||
}
|
||||
|
||||
Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen);
|
||||
break;
|
||||
}
|
||||
|
||||
// Only add the property attribute if it was well-formed.
|
||||
|
@ -1276,12 +1279,10 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
|
|||
}
|
||||
IdentifierLoc *ArgumentKind = ParseIdentifierLoc();
|
||||
|
||||
if (Tok.isNot(tok::comma)) {
|
||||
Diag(Tok, diag::err_expected) << tok::comma;
|
||||
if (ExpectAndConsume(tok::comma)) {
|
||||
T.skipToEnd();
|
||||
return;
|
||||
}
|
||||
ConsumeToken();
|
||||
|
||||
SourceRange MatchingCTypeRange;
|
||||
TypeResult MatchingCType = ParseTypeName(&MatchingCTypeRange);
|
||||
|
|
|
@ -2365,12 +2365,10 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
|
|||
|
||||
// If we don't have a comma, it is either the end of the list (a ';')
|
||||
// or an error, bail out.
|
||||
if (Tok.isNot(tok::comma))
|
||||
SourceLocation CommaLoc;
|
||||
if (!TryConsumeToken(tok::comma, CommaLoc))
|
||||
break;
|
||||
|
||||
// Consume the comma.
|
||||
SourceLocation CommaLoc = ConsumeToken();
|
||||
|
||||
if (Tok.isAtStartOfLine() &&
|
||||
!MightBeDeclarator(Declarator::MemberContext)) {
|
||||
// This comma was followed by a line-break and something which can't be
|
||||
|
@ -2439,8 +2437,7 @@ ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction,
|
|||
EnterExpressionEvaluationContext Context(Actions,
|
||||
Sema::PotentiallyEvaluated,
|
||||
D);
|
||||
if (Tok.is(tok::equal)) {
|
||||
EqualLoc = ConsumeToken();
|
||||
if (TryConsumeToken(tok::equal, EqualLoc)) {
|
||||
if (Tok.is(tok::kw_delete)) {
|
||||
// In principle, an initializer of '= delete p;' is legal, but it will
|
||||
// never type-check. It's better to diagnose it as an ill-formed expression
|
||||
|
@ -2868,8 +2865,7 @@ Parser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) {
|
|||
return true;
|
||||
|
||||
SourceLocation EllipsisLoc;
|
||||
if (Tok.is(tok::ellipsis))
|
||||
EllipsisLoc = ConsumeToken();
|
||||
TryConsumeToken(tok::ellipsis, EllipsisLoc);
|
||||
|
||||
return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II,
|
||||
TemplateTypeTy, DS, IdLoc,
|
||||
|
|
|
@ -1008,10 +1008,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
|
|||
|
||||
// Parse 'mutable'[opt].
|
||||
SourceLocation MutableLoc;
|
||||
if (Tok.is(tok::kw_mutable)) {
|
||||
MutableLoc = ConsumeToken();
|
||||
if (TryConsumeToken(tok::kw_mutable, MutableLoc))
|
||||
DeclEndLoc = MutableLoc;
|
||||
}
|
||||
|
||||
// Parse exception-specification[opt].
|
||||
ExceptionSpecificationType ESpecType = EST_None;
|
||||
|
|
|
@ -1023,11 +1023,9 @@ ParsedTemplateArgument Parser::ParseTemplateTemplateArgument() {
|
|||
UnqualifiedId Name;
|
||||
Name.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
|
||||
ConsumeToken(); // the identifier
|
||||
|
||||
// Parse the ellipsis.
|
||||
if (Tok.is(tok::ellipsis))
|
||||
EllipsisLoc = ConsumeToken();
|
||||
|
||||
|
||||
TryConsumeToken(tok::ellipsis, EllipsisLoc);
|
||||
|
||||
// If the next token signals the end of a template argument,
|
||||
// then we have a dependent template name that could be a template
|
||||
// template argument.
|
||||
|
|
|
@ -1210,9 +1210,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
|
|||
// NOTE: GCC just makes this an ext-warn. It's not clear what it does with
|
||||
// the declarations though. It's trivial to ignore them, really hard to do
|
||||
// anything else with them.
|
||||
if (Tok.is(tok::semi)) {
|
||||
if (TryConsumeToken(tok::semi)) {
|
||||
Diag(DSStart, diag::err_declaration_does_not_declare_param);
|
||||
ConsumeToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue