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

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:41:54 PDT 2007


Author: sabre
Date: Wed Jul 11 11:41:54 2007
New Revision: 39249

URL: http://llvm.org/viewvc/llvm-project?rev=39249&view=rev
Log:
Split code out of ParseCompoundStatement into ParseCompoundStatementBody.
This fixes a bug where a missing } could cause the scope stacks to get
unbalanced and will be used for function body parsing.

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

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

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:41:54 2007
@@ -364,11 +364,25 @@
 ///
 Parser::StmtResult Parser::ParseCompoundStatement() {
   assert(Tok.getKind() == tok::l_brace && "Not a compount stmt!");
-  SourceLocation LBraceLoc = ConsumeBrace();  // eat the '{'.
   
   // Enter a scope to hold everything within the compound stmt.
   EnterScope(0);
-  
+
+  // Parse the statements in the body.
+  StmtResult Body = ParseCompoundStatementBody();
+
+  ExitScope();
+  return Body;
+}
+
+
+/// ParseCompoundStatementBody - Parse a sequence of statements and invoke the
+/// ParseCompoundStmt action.  This expects the '{' to be the current token, and
+/// consume the '}' at the end of the block.  It does not manipulate the scope
+/// stack.
+Parser::StmtResult Parser::ParseCompoundStatementBody() {
+  SourceLocation LBraceLoc = ConsumeBrace();  // eat the '{'.
+
   SmallVector<StmtTy*, 32> Stmts;
   while (Tok.getKind() != tok::r_brace && Tok.getKind() != tok::eof) {
     StmtResult R = ParseStatementOrDeclaration(false);
@@ -381,9 +395,7 @@
     Diag(Tok, diag::err_expected_rbrace);
     return 0;
   }
-
-  ExitScope();
-
+  
   SourceLocation RBraceLoc = ConsumeBrace();
   return Actions.ParseCompoundStmt(LBraceLoc, RBraceLoc,
                                    &Stmts[0], Stmts.size());

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=39249&r1=39248&r2=39249&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:41:54 2007
@@ -310,6 +310,7 @@
   StmtResult ParseCaseStatement();
   StmtResult ParseDefaultStatement();
   StmtResult ParseCompoundStatement();
+  StmtResult ParseCompoundStatementBody();
   StmtResult ParseIfStatement();
   StmtResult ParseSwitchStatement();
   StmtResult ParseWhileStatement();





More information about the cfe-commits mailing list