forked from OSchip/llvm-project
make CaseStmt::getSourceRange() iterative for deeply
nested cases instead of recursive. llvm-svn: 66013
This commit is contained in:
parent
3efa41a478
commit
e46f6e7d9c
|
@ -422,7 +422,6 @@ public:
|
|||
|
||||
void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
|
||||
|
||||
virtual Stmt* v_getSubStmt() = 0;
|
||||
Stmt *getSubStmt() { return v_getSubStmt(); }
|
||||
|
||||
virtual SourceRange getSourceRange() const { return SourceRange(); }
|
||||
|
@ -432,6 +431,8 @@ public:
|
|||
T->getStmtClass() == DefaultStmtClass;
|
||||
}
|
||||
static bool classof(const SwitchCase *) { return true; }
|
||||
protected:
|
||||
virtual Stmt* v_getSubStmt() = 0;
|
||||
};
|
||||
|
||||
class CaseStmt : public SwitchCase {
|
||||
|
@ -439,6 +440,7 @@ class CaseStmt : public SwitchCase {
|
|||
Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
|
||||
// GNU "case 1 ... 4" extension
|
||||
SourceLocation CaseLoc;
|
||||
virtual Stmt* v_getSubStmt() { return getSubStmt(); }
|
||||
public:
|
||||
CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc)
|
||||
: SwitchCase(CaseStmtClass) {
|
||||
|
@ -453,7 +455,6 @@ public:
|
|||
Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
|
||||
Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
|
||||
Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
|
||||
virtual Stmt* v_getSubStmt() { return getSubStmt(); }
|
||||
const Expr *getLHS() const {
|
||||
return reinterpret_cast<const Expr*>(SubExprs[LHS]);
|
||||
}
|
||||
|
@ -468,7 +469,12 @@ public:
|
|||
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(CaseLoc, SubExprs[SUBSTMT]->getLocEnd());
|
||||
// Handle deeply nested case statements with iteration instead of recursion.
|
||||
const CaseStmt *CS = this;
|
||||
while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(getSubStmt()))
|
||||
CS = CS2;
|
||||
|
||||
return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
|
||||
}
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == CaseStmtClass;
|
||||
|
@ -486,12 +492,12 @@ public:
|
|||
class DefaultStmt : public SwitchCase {
|
||||
Stmt* SubStmt;
|
||||
SourceLocation DefaultLoc;
|
||||
virtual Stmt* v_getSubStmt() { return getSubStmt(); }
|
||||
public:
|
||||
DefaultStmt(SourceLocation DL, Stmt *substmt) :
|
||||
SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL) {}
|
||||
|
||||
Stmt *getSubStmt() { return SubStmt; }
|
||||
virtual Stmt* v_getSubStmt() { return getSubStmt(); }
|
||||
const Stmt *getSubStmt() const { return SubStmt; }
|
||||
|
||||
SourceLocation getDefaultLoc() const { return DefaultLoc; }
|
||||
|
|
Loading…
Reference in New Issue