[cfe-commits] r38926 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/ParseExpr.cpp Parse/ParseInit.cpp Parse/ParseStmt.cpp Parse/Parser.cpp include/clang/Parse/Parser.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:25:51 PDT 2007


Author: sabre
Date: Wed Jul 11 11:25:50 2007
New Revision: 38926

URL: http://llvm.org/viewvc/llvm-project?rev=38926&view=rev
Log:
Make MatchRHSPunctuation smarter, allowing its clients to be simpler.

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/Parse/ParseExpr.cpp
    cfe/cfe/trunk/Parse/ParseInit.cpp
    cfe/cfe/trunk/Parse/ParseStmt.cpp
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:50 2007
@@ -504,7 +504,7 @@
       }
     }
 
-    MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{",diag::err_expected_rbrace);
+    MatchRHSPunctuation(tok::r_brace, LBraceLoc);
     
     // If attributes exist after struct contents, parse them.
     if (Tok.getKind() == tok::kw___attribute)
@@ -580,8 +580,7 @@
     }
     
     // Eat the }.
-    MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{", 
-                        diag::err_expected_rbrace);
+    MatchRHSPunctuation(tok::r_brace, LBraceLoc);
 
     // If attributes exist after the identifier list, parse them.
     if (Tok.getKind() == tok::kw___attribute)
@@ -886,8 +885,7 @@
       
       ParseDeclaratorInternal(D);
       // Match the ')'.
-      MatchRHSPunctuation(tok::r_paren, StartLoc, "(",
-                          diag::err_expected_rparen);
+      MatchRHSPunctuation(tok::r_paren, StartLoc);
       return;
     }
     
@@ -1072,7 +1070,7 @@
     return;
   }
   
-  MatchRHSPunctuation(tok::r_square, StartLoc, "[", diag::err_expected_rsquare);
+  MatchRHSPunctuation(tok::r_square, StartLoc);
     
   // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
   // it was not a constant expression.

Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:25:50 2007
@@ -541,7 +541,7 @@
       ConsumeBracket();
       ParseExpression();
       // Match the ']'.
-      MatchRHSPunctuation(tok::r_square, Loc, "[", diag::err_expected_rsquare);
+      MatchRHSPunctuation(tok::r_square, Loc);
       break;
       
     case tok::l_paren:     // p-e: p-e '(' argument-expression-list[opt] ')'
@@ -558,7 +558,7 @@
       }
         
       // Match the ')'.
-      MatchRHSPunctuation(tok::r_paren, Loc, "(", diag::err_expected_rparen);
+      MatchRHSPunctuation(tok::r_paren, Loc);
       break;
       
     case tok::arrow:       // postfix-expression: p-e '->' identifier
@@ -678,8 +678,7 @@
           return Res;
         }
 
-        MatchRHSPunctuation(tok::r_square, LSquareLoc, "[",
-                            diag::err_expected_rsquare);
+        MatchRHSPunctuation(tok::r_square, LSquareLoc);
       } else {
         break;
       }
@@ -708,8 +707,7 @@
     break;
   }      
   
-  MatchRHSPunctuation(tok::r_paren, LParenLoc, "(",
-                      diag::err_expected_rparen);
+  MatchRHSPunctuation(tok::r_paren, LParenLoc);
   
   // These can be followed by postfix-expr pieces because they are
   // primary-expressions.
@@ -763,7 +761,7 @@
     ParseTypeName();
 
     // Match the ')'.
-    MatchRHSPunctuation(tok::r_paren, OpenLoc, "(", diag::err_expected_rparen);
+    MatchRHSPunctuation(tok::r_paren, OpenLoc);
 
     if (Tok.getKind() == tok::l_brace) {
       if (!getLang().C99)   // Compound literals don't exist in C90.
@@ -787,6 +785,6 @@
   if (Result.isInvalid)
     SkipUntil(tok::r_paren);
   else
-    MatchRHSPunctuation(tok::r_paren, OpenLoc, "(", diag::err_expected_rparen);
+    MatchRHSPunctuation(tok::r_paren, OpenLoc);
   return Result;
 }

Modified: cfe/cfe/trunk/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseInit.cpp?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseInit.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseInit.cpp Wed Jul 11 11:25:50 2007
@@ -107,8 +107,7 @@
         }
       }
       
-      MatchRHSPunctuation(tok::r_square, StartLoc, "[", 
-                          diag::err_expected_rsquare);
+      MatchRHSPunctuation(tok::r_square, StartLoc);
       break;
     }
     case tok::identifier: {
@@ -186,8 +185,7 @@
   }
   
   // Match the '}'.
-  MatchRHSPunctuation(tok::r_brace, LBraceLoc, "{",
-                      diag::err_expected_rbrace);
+  MatchRHSPunctuation(tok::r_brace, LBraceLoc);
   return ExprResult(false);
 }
 

Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:25:50 2007
@@ -501,7 +501,7 @@
   }
   
   // Match the ')'.
-  MatchRHSPunctuation(tok::r_paren, LParenLoc, "(", diag::err_expected_rparen);
+  MatchRHSPunctuation(tok::r_paren, LParenLoc);
   
   // Read the body statement.
   ParseStatement();

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:25:50 2007
@@ -44,13 +44,20 @@
 /// present.  If not present, it emits the specified diagnostic indicating
 /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
 /// should be the name of the unmatched LHS token.
-void Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc,
-                                 const char *LHSName, unsigned DiagID) {
+void Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc) {
   
   if (Tok.getKind() == RHSTok) {
     ConsumeAnyToken();
   } else {
-    Diag(Tok, DiagID);
+    const char *LHSName = "unknown";
+    diag::kind DID = diag::err_parse_error;
+    switch (RHSTok) {
+    default: break;
+    case tok::r_paren : LHSName = "("; DID = diag::err_expected_rparen; break;
+    case tok::r_brace : LHSName = "{"; DID = diag::err_expected_rbrace; break;
+    case tok::r_square: LHSName = "["; DID = diag::err_expected_rsquare; break;
+    }
+    Diag(Tok, DID);
     Diag(LHSLoc, diag::err_matching, LHSName);
     SkipUntil(RHSTok);
   }
@@ -403,5 +410,5 @@
   
   // TODO: Diagnose: wide string literal in 'asm'
   
-  MatchRHSPunctuation(tok::r_paren, Loc, "(", diag::err_expected_rparen);
+  MatchRHSPunctuation(tok::r_paren, Loc);
 }

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38926&r1=38925&r2=38926&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:50 2007
@@ -156,8 +156,7 @@
   /// present.  If not present, it emits the specified diagnostic indicating
   /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
   /// should be the name of the unmatched LHS token.
-  void MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc,
-                           const char *LHSName, unsigned Diag);
+  void MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc);
   
   /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
   /// input.  If so, it is consumed and false is returned.





More information about the cfe-commits mailing list