[llvm-branch-commits] [cfe-branch] r73490 - in /cfe/branches/Apple/Dib: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseStmt.cpp test/Parser/statements.c

Daniel Dunbar daniel at zuster.org
Tue Jun 16 09:17:01 PDT 2009


Author: ddunbar
Date: Tue Jun 16 11:17:01 2009
New Revision: 73490

URL: http://llvm.org/viewvc/llvm-project?rev=73490&view=rev
Log:
Merge in 73314, 73315 (<rdar://problem/6952287>):

------------------------------------------------------------------------
r73314 | lattner | 2009-06-13 17:07:48 -0700 (Sat, 13 Jun 2009) | 3 lines

improve localizability by not passing english phrases into 
diagnostics in some cases.

------------------------------------------------------------------------

------------------------------------------------------------------------
r73315 | lattner | 2009-06-13 17:23:56 -0700 (Sat, 13 Jun 2009) | 17 lines

change ParseStatementOrDeclaration to emit the 'missing ;' with
ExpectAndConsume instead of custom diag logic.  This gets us an
insertion hint and positions the ; at the end of the line 
instead of on the next token.  Before:

t.c:5:1: error: expected ';' after return statement
}
^

after:

t.c:4:11: error: expected ';' after return statement
  return 4
          ^
          ;


------------------------------------------------------------------------

Modified:
    cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticParseKinds.td
    cfe/branches/Apple/Dib/lib/Parse/ParseDeclCXX.cpp
    cfe/branches/Apple/Dib/lib/Parse/ParseStmt.cpp
    cfe/branches/Apple/Dib/test/Parser/statements.c

Modified: cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticParseKinds.td?rev=73490&r1=73489&r2=73490&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticParseKinds.td Tue Jun 16 11:17:01 2009
@@ -100,10 +100,16 @@
 def err_expected_lbrace_in_compound_literal : Error<
   "expected '{' in compound literal">;
 def err_expected_while : Error<"expected 'while' in do/while loop">;
+
 def err_expected_semi_after : Error<"expected ';' after %0">;
+def err_expected_semi_after_stmt : Error<"expected ';' after %0 statement">;
 def err_expected_semi_after_expr : Error<"expected ';' after expression">;
 def err_expected_semi_after_method_proto : Error<
   "expected ';' after method prototype">;
+def err_expected_semi_after_namespace_name : Error<
+  "expected ';' after namespace name">;
+def err_expected_semi_after_attribute_list : Error<
+  "expected ';' after attribute list">;
 def err_expected_semi_after_static_assert : Error<
   "expected ';' after static_assert">;
 def err_expected_semi_for : Error<"expected ';' in 'for' statement specifier">;

Modified: cfe/branches/Apple/Dib/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Parse/ParseDeclCXX.cpp?rev=73490&r1=73489&r2=73490&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Parse/ParseDeclCXX.cpp Tue Jun 16 11:17:01 2009
@@ -124,8 +124,8 @@
   
   // Eat the ';'.
   DeclEnd = Tok.getLocation();
-  ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
-                   "namespace name", tok::semi);
+  ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name,
+                   "", tok::semi);
   
   return Actions.ActOnNamespaceAliasDef(CurScope, NamespaceLoc, AliasLoc, Alias, 
                                         SS, IdentLoc, Ident);
@@ -233,8 +233,9 @@
   
   // Eat ';'.
   DeclEnd = Tok.getLocation();
-  ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
-                   AttrList ? "attributes list" : "namespace name", tok::semi);
+  ExpectAndConsume(tok::semi,
+                   AttrList ? diag::err_expected_semi_after_attribute_list :
+                   diag::err_expected_semi_after_namespace_name, "", tok::semi);
 
   return Actions.ActOnUsingDirective(CurScope, UsingLoc, NamespcLoc, SS,
                                       IdentLoc, NamespcName, AttrList);

Modified: cfe/branches/Apple/Dib/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Parse/ParseStmt.cpp?rev=73490&r1=73489&r2=73490&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Parse/ParseStmt.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Parse/ParseStmt.cpp Tue Jun 16 11:17:01 2009
@@ -143,33 +143,33 @@
     return ParseWhileStatement();
   case tok::kw_do:                  // C99 6.8.5.2: do-statement
     Res = ParseDoStatement();
-    SemiError = "do/while loop";
+    SemiError = "do/while";
     break;
   case tok::kw_for:                 // C99 6.8.5.3: for-statement
     return ParseForStatement();
 
   case tok::kw_goto:                // C99 6.8.6.1: goto-statement
     Res = ParseGotoStatement();
-    SemiError = "goto statement";
+    SemiError = "goto";
     break;
   case tok::kw_continue:            // C99 6.8.6.2: continue-statement
     Res = ParseContinueStatement();
-    SemiError = "continue statement";
+    SemiError = "continue";
     break;
   case tok::kw_break:               // C99 6.8.6.3: break-statement
     Res = ParseBreakStatement();
-    SemiError = "break statement";
+    SemiError = "break";
     break;
   case tok::kw_return:              // C99 6.8.6.4: return-statement
     Res = ParseReturnStatement();
-    SemiError = "return statement";
+    SemiError = "return";
     break;
 
   case tok::kw_asm: {
     bool msAsm = false;
     Res = ParseAsmStatement(msAsm);
     if (msAsm) return move(Res);
-    SemiError = "asm statement";
+    SemiError = "asm";
     break;
   }
 
@@ -181,10 +181,14 @@
   if (Tok.is(tok::semi)) {
     ConsumeToken();
   } else if (!Res.isInvalid()) {
-    Diag(Tok, diag::err_expected_semi_after) << SemiError;
+    // If the result was valid, then we do want to diagnose this.  Use
+    // ExpectAndConsume to emit the diagnostic, even though we know it won't
+    // succeed.
+    ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
     // Skip until we see a } or ;, but don't eat it.
     SkipUntil(tok::r_brace, true, true);
   }
+  
   return move(Res);
 }
 

Modified: cfe/branches/Apple/Dib/test/Parser/statements.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Parser/statements.c?rev=73490&r1=73489&r2=73490&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Parser/statements.c (original)
+++ cfe/branches/Apple/Dib/test/Parser/statements.c Tue Jun 16 11:17:01 2009
@@ -54,3 +54,6 @@
    while (0);
 }
 
+int test7() {
+  return 4     // expected-error {{expected ';' after return statement}}
+}





More information about the llvm-branch-commits mailing list