summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/TreeTransform.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-25 00:27:52 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-25 00:27:52 +0000
commit7bab5ff8e70c2f5076a26bcc6099b81c06a4de9a (patch)
treeb63c8c9608093b38f19e045cbbdfaa29698a044d /clang/lib/Sema/TreeTransform.h
parentd6f7850117e25b64b9f79a1b30e30293db3ae95a (diff)
downloadbcm5719-llvm-7bab5ff8e70c2f5076a26bcc6099b81c06a4de9a.tar.gz
bcm5719-llvm-7bab5ff8e70c2f5076a26bcc6099b81c06a4de9a.zip
Eliminate CXXConditionDeclExpr with extreme prejudice.
All statements that involve conditions can now hold on to a separate condition declaration (a VarDecl), and will use a DeclRefExpr referring to that VarDecl for the condition expression. ForStmts now have such a VarDecl (I'd missed those in previous commits). Also, since this change reworks the Action interface for if/while/switch/for, use FullExprArg for the full expressions in those expressions, to ensure that we're emitting Note that we are (still) not generating the right cleanups for condition variables in for statements. That will be a follow-on commit. llvm-svn: 89817
Diffstat (limited to 'clang/lib/Sema/TreeTransform.h')
-rw-r--r--clang/lib/Sema/TreeTransform.h120
1 files changed, 58 insertions, 62 deletions
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 202e16e31e3..1071aebe177 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -95,7 +95,8 @@ public:
typedef Sema::ExprArg ExprArg;
typedef Sema::MultiExprArg MultiExprArg;
typedef Sema::MultiStmtArg MultiStmtArg;
-
+ typedef Sema::DeclPtrTy DeclPtrTy;
+
/// \brief Initializes a new tree transformer.
TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
@@ -665,17 +666,19 @@ public:
/// By default, performs semantic analysis to build the new statement.
/// Subclasses may override this routine to provide different behavior.
OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
- StmtArg Then, SourceLocation ElseLoc,
- StmtArg Else) {
- return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
+ VarDecl *CondVar, StmtArg Then,
+ SourceLocation ElseLoc, StmtArg Else) {
+ return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
+ move(Then), ElseLoc, move(Else));
}
/// \brief Start building a new switch statement.
///
/// By default, performs semantic analysis to build the new statement.
/// Subclasses may override this routine to provide different behavior.
- OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
- return getSema().ActOnStartOfSwitchStmt(move(Cond));
+ OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
+ VarDecl *CondVar) {
+ return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
}
/// \brief Attach the body to the switch statement.
@@ -694,8 +697,10 @@ public:
/// Subclasses may override this routine to provide different behavior.
OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Sema::FullExprArg Cond,
+ VarDecl *CondVar,
StmtArg Body) {
- return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
+ return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
+ move(Body));
}
/// \brief Build a new do-while statement.
@@ -717,10 +722,12 @@ public:
/// Subclasses may override this routine to provide different behavior.
OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
SourceLocation LParenLoc,
- StmtArg Init, ExprArg Cond, ExprArg Inc,
+ StmtArg Init, Sema::FullExprArg Cond,
+ VarDecl *CondVar, Sema::FullExprArg Inc,
SourceLocation RParenLoc, StmtArg Body) {
- return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
- move(Inc), RParenLoc, move(Body));
+ return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
+ DeclPtrTy::make(CondVar),
+ Inc, RParenLoc, move(Body));
}
/// \brief Build a new goto statement.
@@ -1374,18 +1381,6 @@ public:
0, RParenLoc);
}
- /// \brief Build a new C++ conditional declaration expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
- SourceLocation EqLoc,
- VarDecl *Var) {
- return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
- EqLoc,
- Var));
- }
-
/// \brief Build a new C++ "new" expression.
///
/// By default, performs semantic analysis to build the new expression.
@@ -3071,13 +3066,12 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
getDerived().TransformDefinition(S->getConditionVariable()));
if (!ConditionVar)
return SemaRef.StmtError();
-
- Cond = getSema().CheckConditionVariable(ConditionVar);
- } else
+ } else {
Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return SemaRef.StmtError();
+ if (Cond.isInvalid())
+ return SemaRef.StmtError();
+ }
Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
@@ -3093,11 +3087,13 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
if (!getDerived().AlwaysRebuild() &&
FullCond->get() == S->getCond() &&
+ ConditionVar == S->getConditionVariable() &&
Then.get() == S->getThen() &&
Else.get() == S->getElse())
return SemaRef.Owned(S->Retain());
- return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
+ return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
+ move(Then),
S->getElseLoc(), move(Else));
}
@@ -3113,15 +3109,18 @@ TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
getDerived().TransformDefinition(S->getConditionVariable()));
if (!ConditionVar)
return SemaRef.StmtError();
-
- Cond = getSema().CheckConditionVariable(ConditionVar);
- } else
+ } else {
Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return SemaRef.StmtError();
+
+ if (Cond.isInvalid())
+ return SemaRef.StmtError();
+ }
+ Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
+
// Rebuild the switch statement.
- OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
+ OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
+ ConditionVar);
if (Switch.isInvalid())
return SemaRef.StmtError();
@@ -3147,12 +3146,12 @@ TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
getDerived().TransformDefinition(S->getConditionVariable()));
if (!ConditionVar)
return SemaRef.StmtError();
-
- Cond = getSema().CheckConditionVariable(ConditionVar);
- } else
+ } else {
Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return SemaRef.StmtError();
+
+ if (Cond.isInvalid())
+ return SemaRef.StmtError();
+ }
Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
@@ -3163,10 +3162,12 @@ TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
if (!getDerived().AlwaysRebuild() &&
FullCond->get() == S->getCond() &&
+ ConditionVar == S->getConditionVariable() &&
Body.get() == S->getBody())
return SemaRef.Owned(S->Retain());
- return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
+ return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
+ move(Body));
}
template<typename Derived>
@@ -3201,9 +3202,20 @@ TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
return SemaRef.StmtError();
// Transform the condition
- OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return SemaRef.StmtError();
+ OwningExprResult Cond(SemaRef);
+ VarDecl *ConditionVar = 0;
+ if (S->getConditionVariable()) {
+ ConditionVar
+ = cast_or_null<VarDecl>(
+ getDerived().TransformDefinition(S->getConditionVariable()));
+ if (!ConditionVar)
+ return SemaRef.StmtError();
+ } else {
+ Cond = getDerived().TransformExpr(S->getCond());
+
+ if (Cond.isInvalid())
+ return SemaRef.StmtError();
+ }
// Transform the increment
OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
@@ -3223,7 +3235,9 @@ TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
return SemaRef.Owned(S->Retain());
return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
- move(Init), move(Cond), move(Inc),
+ move(Init), getSema().FullExpr(Cond),
+ ConditionVar,
+ getSema().FullExpr(Inc),
S->getRParenLoc(), move(Body));
}
@@ -4418,24 +4432,6 @@ TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
template<typename Derived>
Sema::OwningExprResult
-TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E,
- bool isAddressOfOperand) {
- VarDecl *Var
- = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
- if (!Var)
- return SemaRef.ExprError();
-
- if (!getDerived().AlwaysRebuild() &&
- Var == E->getVarDecl())
- return SemaRef.Owned(E->Retain());
-
- return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
- /*FIXME:*/E->getStartLoc(),
- Var);
-}
-
-template<typename Derived>
-Sema::OwningExprResult
TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
bool isAddressOfOperand) {
// Transform the type that we're allocating
OpenPOWER on IntegriCloud