[cfe-commits] r53520 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseStmt.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Jul 12 14:04:42 PDT 2008
Author: akirtzidis
Date: Sat Jul 12 16:04:42 2008
New Revision: 53520
URL: http://llvm.org/viewvc/llvm-project?rev=53520&view=rev
Log:
Use of NextToken() makes ParseIdentifierStatement unnecessary.
Simplify the parser by removing Parser::ParseIdentifierStatement.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseStmt.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=53520&r1=53519&r2=53520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Jul 12 16:04:42 2008
@@ -456,7 +456,6 @@
StmtResult ParseStatement() { return ParseStatementOrDeclaration(true); }
StmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
- StmtResult ParseIdentifierStatement(bool OnlyStatement);
StmtResult ParseLabeledStatement();
StmtResult ParseCaseStatement();
StmtResult ParseDefaultStatement();
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=53520&r1=53519&r2=53520&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Jul 12 16:04:42 2008
@@ -79,21 +79,19 @@
tok::TokenKind Kind = Tok.getKind();
SourceLocation AtLoc;
switch (Kind) {
- case tok::identifier:
- if (NextToken().is(tok::colon)) { // C99 6.8.1: labeled-statement
- // identifier ':' statement
- return ParseLabeledStatement();
- }
- // declaration (if !OnlyStatement)
- // expression[opt] ';'
- return ParseIdentifierStatement(OnlyStatement);
-
case tok::at: // May be a @try or @throw statement
{
AtLoc = ConsumeToken(); // consume @
return ParseObjCAtStatement(AtLoc);
}
+ case tok::identifier:
+ if (NextToken().is(tok::colon)) { // C99 6.8.1: labeled-statement
+ // identifier ':' statement
+ return ParseLabeledStatement();
+ }
+ // PASS THROUGH.
+
default:
if (!OnlyStatement && isDeclarationSpecifier()) {
SourceLocation DeclStart = Tok.getLocation();
@@ -211,84 +209,6 @@
IdentTok.getIdentifierInfo(),
ColonLoc, SubStmt.Val);
}
-
-/// ParseIdentifierStatement - This is either part of a declaration
-/// (if the identifier is a type-name) or part of an expression.
-///
-/// declaration (if !OnlyStatement)
-/// expression[opt] ';'
-///
-Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) {
- assert(Tok.is(tok::identifier) && Tok.getIdentifierInfo() &&
- "Not an identifier!");
-
- // Check to see if this is a declaration.
- void *TypeRep;
- if (!OnlyStatement &&
- (TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope))) {
- // Handle this. Warn/disable if in middle of block and !C99.
- DeclSpec DS;
-
- Token IdentTok = Tok; // Save the whole token.
- ConsumeToken(); // eat the identifier.
-
- // Add the typedef name to the start of the decl-specs.
- const char *PrevSpec = 0;
- int isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typedef,
- IdentTok.getLocation(), PrevSpec,
- TypeRep);
- assert(!isInvalid && "First declspec can't be invalid!");
- SourceLocation endProtoLoc;
- if (Tok.is(tok::less)) {
- llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
- ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
- llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =
- new llvm::SmallVector<DeclTy *, 8>;
- DS.setProtocolQualifiers(ProtocolDecl);
- Actions.FindProtocolDeclaration(IdentTok.getLocation(),
- &ProtocolRefs[0], ProtocolRefs.size(),
- *ProtocolDecl);
- }
-
- // ParseDeclarationSpecifiers will continue from there.
- ParseDeclarationSpecifiers(DS);
-
- // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
- // declaration-specifiers init-declarator-list[opt] ';'
- if (Tok.is(tok::semi)) {
- // TODO: emit error on 'int;' or 'const enum foo;'.
- // if (!DS.isMissingDeclaratorOk()) Diag(...);
-
- ConsumeToken();
- // FIXME: Return this as a type decl.
- return 0;
- }
-
- // Parse all the declarators.
- Declarator DeclaratorInfo(DS, Declarator::BlockContext);
- ParseDeclarator(DeclaratorInfo);
-
- DeclTy *Decl = ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
- if (!Decl) return 0;
- return Actions.ActOnDeclStmt(Decl, DS.getSourceRange().getBegin(),
- DeclaratorInfo.getSourceRange().getEnd());
- }
-
- // Otherwise, this is an expression.
- ExprResult Res = ParseExpression();
- if (Res.isInvalid) {
- SkipUntil(tok::semi);
- return true;
- } else if (Tok.isNot(tok::semi)) {
- Diag(Tok, diag::err_expected_semi_after, "expression");
- SkipUntil(tok::semi);
- return true;
- } else {
- ConsumeToken();
- // Convert expr to a stmt.
- return Actions.ActOnExprStmt(Res.Val);
- }
-}
/// ParseCaseStatement
/// labeled-statement:
More information about the cfe-commits
mailing list