aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Stmt.h13
-rw-r--r--include/clang/Parse/Action.h5
-rw-r--r--include/clang/Parse/Parser.h4
-rw-r--r--lib/Frontend/PCHReaderStmt.cpp1
-rw-r--r--lib/Frontend/PCHWriterStmt.cpp2
-rw-r--r--lib/Frontend/PrintParserCallbacks.cpp4
-rw-r--r--lib/Parse/ParseStmt.cpp14
-rw-r--r--lib/Sema/Sema.h4
-rw-r--r--lib/Sema/SemaStmt.cpp5
-rw-r--r--lib/Sema/SemaTemplateInstantiateStmt.cpp2
10 files changed, 37 insertions, 17 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 3656333d74..a8688f62e2 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -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;
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 43406b99a6..f1207e4f0f 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -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,
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 8eb76a4ef7..d613ae1329 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -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();
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index 10059f609b..e6871e3a0e 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -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;
}
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index b7caee5e55..73dea1061c 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -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;
}
diff --git a/lib/Frontend/PrintParserCallbacks.cpp b/lib/Frontend/PrintParserCallbacks.cpp
index 026e605c79..170ab5e33f 100644
--- a/lib/Frontend/PrintParserCallbacks.cpp
+++ b/lib/Frontend/PrintParserCallbacks.cpp
@@ -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();
}
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index f041d7dfd7..7766bfada7 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -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
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 09b316286d..7e32c11129 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -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,
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 15262e9c3a..aa9b8db0c9 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -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
diff --git a/lib/Sema/SemaTemplateInstantiateStmt.cpp b/lib/Sema/SemaTemplateInstantiateStmt.cpp
index fd349df27e..efdcec81af 100644
--- a/lib/Sema/SemaTemplateInstantiateStmt.cpp
+++ b/lib/Sema/SemaTemplateInstantiateStmt.cpp
@@ -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) {