]> granicus.if.org Git - clang/commitdiff
add the location of the ')' in a do/while statement to DoStmt.
authorChris Lattner <sabre@nondot.org>
Fri, 12 Jun 2009 23:04:47 +0000 (23:04 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Jun 2009 23:04:47 +0000 (23:04 +0000)
This fixes a source range problem reported by Olaf Krzikalla.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73266 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
include/clang/Parse/Action.h
include/clang/Parse/Parser.h
lib/Frontend/PCHReaderStmt.cpp
lib/Frontend/PCHWriterStmt.cpp
lib/Frontend/PrintParserCallbacks.cpp
lib/Parse/ParseStmt.cpp
lib/Sema/Sema.h
lib/Sema/SemaStmt.cpp
lib/Sema/SemaTemplateInstantiateStmt.cpp

index 3656333d7423533ed710fe2d8aced4ab3a888492..a8688f62e2d9e201edf9bf3489e75be28eab8261 100644 (file)
@@ -709,14 +709,14 @@ class DoStmt : public Stmt {
   Stmt* SubExprs[END_EXPR];
   SourceLocation DoLoc;
   SourceLocation WhileLoc;
+  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
 
 public:
-  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL) 
-    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL) {
+  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
+         SourceLocation RP)
+    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
     SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
     SubExprs[BODY] = body;
-    DoLoc = DL;
-    WhileLoc = WL;
   }  
 
   /// \brief Build an empty do-while statement.
@@ -734,8 +734,11 @@ public:
   SourceLocation getWhileLoc() const { return WhileLoc; }
   void setWhileLoc(SourceLocation L) { WhileLoc = L; }
 
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+
   virtual SourceRange getSourceRange() const { 
-    return SourceRange(DoLoc, SubExprs[BODY]->getLocEnd()); 
+    return SourceRange(DoLoc, RParenLoc); 
   }
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == DoStmtClass; 
index 43406b99a679bdb1e37c40711f24776e3a477e78..f1207e4f0f73e1c87a443f2f56ec480336ea0e99 100644 (file)
@@ -517,7 +517,10 @@ public:
     return StmtEmpty();
   }
   virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
-                                       SourceLocation WhileLoc, ExprArg Cond) {
+                                       SourceLocation WhileLoc, 
+                                       SourceLocation CondLParen,
+                                       ExprArg Cond,
+                                       SourceLocation CondRParen) {
     return StmtEmpty();
   }
   virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
index 8eb76a4ef704af09a09f320c0807eac7cb102b42..d613ae13293531e946873838835800b78fabb334 100644 (file)
@@ -868,7 +868,9 @@ private:
   OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
   OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
   bool ParseParenExprOrCondition(OwningExprResult &CondExp,
-                                 bool OnlyAllowCondition = false);
+                                 bool OnlyAllowCondition = false,
+                                 SourceLocation *LParenLoc = 0,
+                                 SourceLocation *RParenLoc = 0);
   OwningStmtResult ParseIfStatement();
   OwningStmtResult ParseSwitchStatement();
   OwningStmtResult ParseWhileStatement();
index 10059f609b10ff6d42c37e509088400ec17e221f..e6871e3a0eb676961e7d3cba9d02a164eedb4103 100644 (file)
@@ -210,6 +210,7 @@ unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) {
   S->setBody(StmtStack.back());
   S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   return 2;
 }
 
index b7caee5e55109ccc53ae912a8270f34d86e0523f..73dea1061c283a4a46aeef73425d8cab1e8c674d 100644 (file)
@@ -23,7 +23,6 @@ using namespace clang;
 
 namespace {
   class PCHStmtWriter : public StmtVisitor<PCHStmtWriter, void> {
-
     PCHWriter &Writer;
     PCHWriter::RecordData &Record;
 
@@ -197,6 +196,7 @@ void PCHStmtWriter::VisitDoStmt(DoStmt *S) {
   Writer.WriteSubStmt(S->getBody());
   Writer.AddSourceLocation(S->getDoLoc(), Record);
   Writer.AddSourceLocation(S->getWhileLoc(), Record);
+  Writer.AddSourceLocation(S->getRParenLoc(), Record);
   Code = pch::STMT_DO;
 }
 
index 026e605c79437efacb18d04dba69a9bd3158bad9..170ab5e33f5a3ed1ca9bb5ff0f48a51d48aa9c96 100644 (file)
@@ -327,7 +327,9 @@ namespace {
       return StmtEmpty();
     }
     virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
-                                         SourceLocation WhileLoc, ExprArg Cond){
+                                         SourceLocation WhileLoc, 
+                                         SourceLocation LPLoc, ExprArg Cond,
+                                         SourceLocation RPLoc){
       Out << __FUNCTION__ << "\n";
       return StmtEmpty();
     }
index f041d7dfd7907adf96e1fb66119375587a94d0e7..7766bfada76644cc0cc393731859781002150c84 100644 (file)
@@ -487,8 +487,11 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
 /// successfully parsed.  Note that a successful parse can still have semantic
 /// errors in the condition.
 bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp,
-                                       bool OnlyAllowCondition) {
+                                       bool OnlyAllowCondition,
+                                       SourceLocation *LParenLocPtr,
+                                       SourceLocation *RParenLocPtr) {
   SourceLocation LParenLoc = ConsumeParen();
+  if (LParenLocPtr) *LParenLocPtr = LParenLoc;
   
   if (getLang().CPlusPlus)
     CondExp = ParseCXXCondition();
@@ -507,7 +510,8 @@ bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp,
   }
   
   // Otherwise the condition is valid or the rparen is present.
-  MatchRHSPunctuation(tok::r_paren, LParenLoc);
+  SourceLocation RPLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+  if (RParenLocPtr) *RParenLocPtr = RPLoc;
   return false;
 }
 
@@ -837,14 +841,16 @@ Parser::OwningStmtResult Parser::ParseDoStatement() {
 
   // Parse the parenthesized condition.
   OwningExprResult Cond(Actions);
-  ParseParenExprOrCondition(Cond, true);
+  SourceLocation LPLoc, RPLoc;
+  ParseParenExprOrCondition(Cond, true, &LPLoc, &RPLoc);
   
   DoScope.Exit();
 
   if (Cond.isInvalid() || Body.isInvalid())
     return StmtError();
 
-  return Actions.ActOnDoStmt(DoLoc, move(Body), WhileLoc, move(Cond));
+  return Actions.ActOnDoStmt(DoLoc, move(Body), WhileLoc, LPLoc,
+                             move(Cond), RPLoc);
 }
 
 /// ParseForStatement
index 09b316286d356f088af77df4e676da8c663c1691..7e32c111292e82af36940feea70ab2bed6c4b133 100644 (file)
@@ -1205,7 +1205,9 @@ public:
   virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, 
                                           FullExprArg Cond, StmtArg Body);
   virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
-                                       SourceLocation WhileLoc, ExprArg Cond);
+                                       SourceLocation WhileLoc,
+                                       SourceLocation CondLParen, ExprArg Cond,
+                                       SourceLocation CondRParen);
 
   virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
                                         SourceLocation LParenLoc,
index 15262e9c3ac2ca74c53569cf5721a9badb9c178d..aa9b8db0c9f27ab72544df74861a6c9ee122eb58 100644 (file)
@@ -568,7 +568,8 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body) {
 
 Action::OwningStmtResult
 Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
-                  SourceLocation WhileLoc, ExprArg Cond) {
+                  SourceLocation WhileLoc, SourceLocation CondLParen,
+                  ExprArg Cond, SourceLocation CondRParen) {
   Expr *condExpr = Cond.takeAs<Expr>();
   assert(condExpr && "ActOnDoStmt(): missing expression");
 
@@ -588,7 +589,7 @@ Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
 
   Cond.release();
   return Owned(new (Context) DoStmt(Body.takeAs<Stmt>(), condExpr, DoLoc,
-                                    WhileLoc));
+                                    WhileLoc, CondRParen));
 }
 
 Action::OwningStmtResult
index fd349df27edd03b08d2a16f836199e48539ab279..efdcec81afffcaaefa6cfba2b02ea64dec665bd2 100644 (file)
@@ -260,7 +260,7 @@ Sema::OwningStmtResult TemplateStmtInstantiator::VisitDoStmt(DoStmt *S) {
     return SemaRef.StmtError();
 
   return SemaRef.ActOnDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
-                             move(Cond));
+                             SourceLocation(), move(Cond), S->getRParenLoc());
 }
 
 Sema::OwningStmtResult TemplateStmtInstantiator::VisitForStmt(ForStmt *S) {