]> granicus.if.org Git - clang/commitdiff
use smarter error recovery for do/while.
authorChris Lattner <sabre@nondot.org>
Fri, 12 Dec 2008 06:35:28 +0000 (06:35 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Dec 2008 06:35:28 +0000 (06:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60933 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bb0a76e4ea0ed1b8d140e21939ec9aa559217e36..fafaac595433f8860999d076793de3668cbc6305 100644 (file)
@@ -640,7 +640,8 @@ private:
   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();
index 45092aa612fe265247b22131908541aa3e9d8b59..ed4563bb6fdfba99f1d0b0972ea4ccf6d1fc7a9e 100644 (file)
@@ -416,7 +416,7 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
 
 /// 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 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
 /// 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 @@ Parser::OwningStmtResult Parser::ParseDoStatement() {
     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())