[cfe-commits] r60933 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseStmt.cpp

Chris Lattner sabre at nondot.org
Thu Dec 11 22:35:29 PST 2008


Author: lattner
Date: Fri Dec 12 00:35:28 2008
New Revision: 60933

URL: http://llvm.org/viewvc/llvm-project?rev=60933&view=rev
Log:
use smarter error recovery for do/while.

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=60933&r1=60932&r2=60933&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Dec 12 00:35:28 2008
@@ -640,7 +640,8 @@
   OwningStmtResult ParseDefaultStatement();
   OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
   OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
-  bool ParseParenExprOrCondition(OwningExprResult &CondExp);
+  bool ParseParenExprOrCondition(OwningExprResult &CondExp,
+                                 bool OnlyAllowCondition = false);
   OwningStmtResult ParseIfStatement();
   OwningStmtResult ParseSwitchStatement();
   OwningStmtResult ParseWhileStatement();

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Dec 12 00:35:28 2008
@@ -416,7 +416,7 @@
 
 /// ParseParenExprOrCondition:
 /// [C  ]     '(' expression ')'
-/// [C++]     '(' condition ')'
+/// [C++]     '(' condition ')'       [not allowed if OnlyAllowCondition=true]
 ///
 /// This function parses and performs error recovery on the specified condition
 /// or expression (depending on whether we're in C++ or C mode).  This function
@@ -425,7 +425,8 @@
 /// should try to recover harder.  It returns false if the condition is
 /// successfully parsed.  Note that a successful parse can still have semantic
 /// errors in the condition.
-bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp) {
+bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp,
+                                       bool OnlyAllowCondition) {
   SourceLocation LParenLoc = ConsumeParen();
   
   if (getLang().CPlusPlus)
@@ -769,8 +770,10 @@
     return StmtError();
   }
 
-  // Parse the condition.
-  OwningExprResult Cond(ParseSimpleParenExpression());
+  // Parse the parenthesized condition.
+  OwningExprResult Cond(Actions);
+  ParseParenExprOrCondition(Cond, true);
+  
   DoScope.Exit();
 
   if (Cond.isInvalid() || Body.isInvalid())





More information about the cfe-commits mailing list