changeset 49:c0c81d8e222e

fix ParseCbCGotoStatement and add new diags for goto cs();
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 13 Jan 2014 23:04:29 +0900
parents 4b59af982ef3
children bd668f746740
files tools/clang/include/clang/Basic/DiagnosticParseKinds.td tools/clang/lib/Parse/ParseStmt.cpp
diffstat 2 files changed, 19 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/include/clang/Basic/DiagnosticParseKinds.td	Sun Jan 12 19:15:16 2014 +0900
+++ b/tools/clang/include/clang/Basic/DiagnosticParseKinds.td	Mon Jan 13 23:04:29 2014 +0900
@@ -859,6 +859,10 @@
   "unexpected OpenMP clause '%0' in directive '#pragma omp %1'">;
 def err_omp_more_one_clause : Error <
   "directive '#pragma omp %0' cannot contain more than one '%1' clause">;
+
+// noCbC (We cannot use #ifndef in this file. It is for a check)
+def err_expected_ident_or_cs : Error<"expected identifier or codesegment call">;
+// noCbC end
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
--- a/tools/clang/lib/Parse/ParseStmt.cpp	Sun Jan 12 19:15:16 2014 +0900
+++ b/tools/clang/lib/Parse/ParseStmt.cpp	Mon Jan 13 23:04:29 2014 +0900
@@ -260,7 +260,8 @@
 
   case tok::kw_goto:                // C99 6.8.6.1: goto-statement
 #ifndef noCbC
-    if (PP.LookAhead(1).is(tok::l_paren)) { // is CbC goto : 'goto' codeSegment() ';'
+    if (!(NextToken().is(tok::identifier) && PP.LookAhead(1).is(tok::colon)) && 
+	NextToken().isNot(tok::star)) { // CbC: goto codesegment statement
       SemiError = "goto code segment";
       return ParseCbCGotoStatement(Attrs, Stmts);
     }
@@ -1700,47 +1701,28 @@
   assert(Tok.is(tok::kw_goto) && "Not a goto stmt!");
   SourceLocation gotoLoc = ConsumeToken();  // eat the 'goto'.
   StmtResult gotoRes;
-    
-  if (Tok.is(tok::identifier) && NextToken().is(tok::l_paren)) { // 'goto' codeSegment() ';'
-
-    CorrectionCandidateCallback DefaultValidator;
-    DefaultValidator.WantTypeSpecifiers = true;
-    DefaultValidator.WantExpressionKeywords = true;
-    DefaultValidator.WantRemainingKeywords = true;
-    DefaultValidator.WantCXXNamedCasts = false;
-    
-    if (TryAnnotateName(/*IsAddressOfOperand*/false, &DefaultValidator)
-	== ANK_Error) {
-      // Handle errors here by skipping up to the next semicolon or '}', and
-      // eat the semicolon if that's what stopped us.
-      SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-      if (Tok.is(tok::semi))
-	ConsumeToken();
-      return StmtError();
-    }
-
-    Stmtsp = &Stmts;
-    gotoRes = ParseExprStatement();
-
-    // don't need return because this code segment caller isn't code segment.
-    if (!Actions.getCurFunctionDecl()->getResultType().getTypePtr()->is__CodeType())
-      return gotoRes;
-    
-  }
-  else {
-    Diag(Tok, diag::err_expected_ident);
+  Token TokAfterGoto = Tok;
+  Stmtsp = &Stmts;
+  
+  gotoRes = ParseStatementOrDeclaration(Stmts, false);
+  if (gotoRes.get()->getStmtClass() != Stmt::CallExprClass) { // isFunctionCall ?
+    Diag(TokAfterGoto, diag::err_expected_ident_or_cs);
     return StmtError();
   }
+  
+  // don't need return because this code segment caller isn't code segment.
+  if (!Actions.getCurFunctionDecl()->getResultType().getTypePtr()->is__CodeType())
+    return gotoRes;
   assert((Attrs.empty() || gotoRes.isInvalid() || gotoRes.isUsable()) &&
          "attributes on empty statement");
-
+  
   if (!(Attrs.empty() || gotoRes.isInvalid()))
     gotoRes = Actions.ProcessStmtAttributes(gotoRes.get(), Attrs.getList(), Attrs.Range);
-
+  
   if(gotoRes.isUsable())
     Stmts.push_back(gotoRes.release());
   /* add return; after goto code segment. */
-
+  
   ExprResult R;
   return Actions.ActOnReturnStmt(gotoLoc, R.take());
 }