forked from OSchip/llvm-project
PCH support for while and continue statements
llvm-svn: 69332
This commit is contained in:
parent
5c3285b6fb
commit
e24cbc0f4b
|
@ -673,10 +673,18 @@ public:
|
||||||
WhileLoc = WL;
|
WhileLoc = WL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Build an empty while statement.
|
||||||
|
explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
|
||||||
|
|
||||||
Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
|
Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
|
||||||
const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
|
const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
|
||||||
|
void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
|
||||||
Stmt *getBody() { return SubExprs[BODY]; }
|
Stmt *getBody() { return SubExprs[BODY]; }
|
||||||
const Stmt *getBody() const { return SubExprs[BODY]; }
|
const Stmt *getBody() const { return SubExprs[BODY]; }
|
||||||
|
void setBody(Stmt *S) { SubExprs[BODY] = S; }
|
||||||
|
|
||||||
|
SourceLocation getWhileLoc() const { return WhileLoc; }
|
||||||
|
void setWhileLoc(SourceLocation L) { WhileLoc = L; }
|
||||||
|
|
||||||
virtual SourceRange getSourceRange() const {
|
virtual SourceRange getSourceRange() const {
|
||||||
return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
|
return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
|
||||||
|
@ -838,6 +846,12 @@ class ContinueStmt : public Stmt {
|
||||||
public:
|
public:
|
||||||
ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
|
ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
|
||||||
|
|
||||||
|
/// \brief Build an empty continue statement.
|
||||||
|
explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
|
||||||
|
|
||||||
|
SourceLocation getContinueLoc() const { return ContinueLoc; }
|
||||||
|
void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
|
||||||
|
|
||||||
virtual SourceRange getSourceRange() const {
|
virtual SourceRange getSourceRange() const {
|
||||||
return SourceRange(ContinueLoc);
|
return SourceRange(ContinueLoc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,6 +387,10 @@ namespace clang {
|
||||||
STMT_IF,
|
STMT_IF,
|
||||||
/// \brief A SwitchStmt record.
|
/// \brief A SwitchStmt record.
|
||||||
STMT_SWITCH,
|
STMT_SWITCH,
|
||||||
|
/// \brief A WhileStmt record.
|
||||||
|
STMT_WHILE,
|
||||||
|
/// \brief A ContinueStmt record.
|
||||||
|
STMT_CONTINUE,
|
||||||
/// \brief A BreakStmt record.
|
/// \brief A BreakStmt record.
|
||||||
STMT_BREAK,
|
STMT_BREAK,
|
||||||
/// \brief A PredefinedExpr record.
|
/// \brief A PredefinedExpr record.
|
||||||
|
|
|
@ -251,6 +251,8 @@ namespace {
|
||||||
unsigned VisitDefaultStmt(DefaultStmt *S);
|
unsigned VisitDefaultStmt(DefaultStmt *S);
|
||||||
unsigned VisitIfStmt(IfStmt *S);
|
unsigned VisitIfStmt(IfStmt *S);
|
||||||
unsigned VisitSwitchStmt(SwitchStmt *S);
|
unsigned VisitSwitchStmt(SwitchStmt *S);
|
||||||
|
unsigned VisitWhileStmt(WhileStmt *S);
|
||||||
|
unsigned VisitContinueStmt(ContinueStmt *S);
|
||||||
unsigned VisitBreakStmt(BreakStmt *S);
|
unsigned VisitBreakStmt(BreakStmt *S);
|
||||||
unsigned VisitExpr(Expr *E);
|
unsigned VisitExpr(Expr *E);
|
||||||
unsigned VisitPredefinedExpr(PredefinedExpr *E);
|
unsigned VisitPredefinedExpr(PredefinedExpr *E);
|
||||||
|
@ -356,6 +358,20 @@ unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
|
||||||
|
VisitStmt(S);
|
||||||
|
S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
|
||||||
|
S->setBody(StmtStack.back());
|
||||||
|
S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
|
||||||
|
VisitStmt(S);
|
||||||
|
S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
|
unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
|
||||||
VisitStmt(S);
|
VisitStmt(S);
|
||||||
S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
||||||
|
@ -2116,6 +2132,14 @@ Stmt *PCHReader::ReadStmt() {
|
||||||
S = new (Context) SwitchStmt(Empty);
|
S = new (Context) SwitchStmt(Empty);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case pch::STMT_WHILE:
|
||||||
|
S = new (Context) WhileStmt(Empty);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pch::STMT_CONTINUE:
|
||||||
|
S = new (Context) ContinueStmt(Empty);
|
||||||
|
break;
|
||||||
|
|
||||||
case pch::STMT_BREAK:
|
case pch::STMT_BREAK:
|
||||||
S = new (Context) BreakStmt(Empty);
|
S = new (Context) BreakStmt(Empty);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -453,6 +453,8 @@ namespace {
|
||||||
void VisitDefaultStmt(DefaultStmt *S);
|
void VisitDefaultStmt(DefaultStmt *S);
|
||||||
void VisitIfStmt(IfStmt *S);
|
void VisitIfStmt(IfStmt *S);
|
||||||
void VisitSwitchStmt(SwitchStmt *S);
|
void VisitSwitchStmt(SwitchStmt *S);
|
||||||
|
void VisitWhileStmt(WhileStmt *S);
|
||||||
|
void VisitContinueStmt(ContinueStmt *S);
|
||||||
void VisitBreakStmt(BreakStmt *S);
|
void VisitBreakStmt(BreakStmt *S);
|
||||||
void VisitExpr(Expr *E);
|
void VisitExpr(Expr *E);
|
||||||
void VisitPredefinedExpr(PredefinedExpr *E);
|
void VisitPredefinedExpr(PredefinedExpr *E);
|
||||||
|
@ -550,6 +552,20 @@ void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
|
||||||
Code = pch::STMT_SWITCH;
|
Code = pch::STMT_SWITCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) {
|
||||||
|
VisitStmt(S);
|
||||||
|
Writer.WriteSubStmt(S->getCond());
|
||||||
|
Writer.WriteSubStmt(S->getBody());
|
||||||
|
Writer.AddSourceLocation(S->getWhileLoc(), Record);
|
||||||
|
Code = pch::STMT_WHILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PCHStmtWriter::VisitContinueStmt(ContinueStmt *S) {
|
||||||
|
VisitStmt(S);
|
||||||
|
Writer.AddSourceLocation(S->getContinueLoc(), Record);
|
||||||
|
Code = pch::STMT_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
void PCHStmtWriter::VisitBreakStmt(BreakStmt *S) {
|
void PCHStmtWriter::VisitBreakStmt(BreakStmt *S) {
|
||||||
VisitStmt(S);
|
VisitStmt(S);
|
||||||
Writer.AddSourceLocation(S->getBreakLoc(), Record);
|
Writer.AddSourceLocation(S->getBreakLoc(), Record);
|
||||||
|
|
|
@ -19,4 +19,11 @@ void f0(int x) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (x > 20) {
|
||||||
|
if (x > 30) {
|
||||||
|
--x;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue