]> granicus.if.org Git - clang/commitdiff
Use of NextToken() makes ParseIdentifierStatement unnecessary.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 12 Jul 2008 21:04:42 +0000 (21:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 12 Jul 2008 21:04:42 +0000 (21:04 +0000)
Simplify the parser by removing Parser::ParseIdentifierStatement.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53520 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseStmt.cpp

index e45aa3501ab7b888a018bc7c2785e14e7d8f32a1..3421cc4c5024de2e9cf7b5f823198c1c367a008d 100644 (file)
@@ -456,7 +456,6 @@ private:
   
   StmtResult ParseStatement() { return ParseStatementOrDeclaration(true); }
   StmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
-  StmtResult ParseIdentifierStatement(bool OnlyStatement);
   StmtResult ParseLabeledStatement();
   StmtResult ParseCaseStatement();
   StmtResult ParseDefaultStatement();
index b8ebc42a067de0ed6ffa722d8c2bb2c57545c9dc..e20e056ebdb9ede6d02e418ba6964a2e6e4a8abe 100644 (file)
@@ -79,21 +79,19 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
   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 @@ Parser::StmtResult Parser::ParseLabeledStatement() {
                                 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: