diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-12-28 16:13:43 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-12-28 16:13:43 +0000 |
commit | 1cbb59182cb886eb3a23ee09e33821f064a0c24e (patch) | |
tree | 8b9bc1109bcf308ffc019d1f61a935730a158534 /clang/lib/Sema | |
parent | 4f84ddccc8a39a6df96ad13b6ffda7b9a96d79a8 (diff) | |
download | bcm5719-llvm-1cbb59182cb886eb3a23ee09e33821f064a0c24e.tar.gz bcm5719-llvm-1cbb59182cb886eb3a23ee09e33821f064a0c24e.zip |
Convert a two more statement actions to smart pointers.
llvm-svn: 61456
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/Sema.h | 12 | ||||
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 49 |
2 files changed, 33 insertions, 28 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 94e8a3ccccd..386639061dc 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -567,12 +567,12 @@ public: bool isStmtExpr); virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc, SourceLocation EndLoc); - virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, - SourceLocation DotDotDotLoc, ExprTy *RHSVal, - SourceLocation ColonLoc, StmtTy *SubStmt); - virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, - SourceLocation ColonLoc, StmtTy *SubStmt, - Scope *CurScope); + virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, + SourceLocation DotDotDotLoc, ExprArg RHSVal, + SourceLocation ColonLoc, StmtArg SubStmt); + virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, + SourceLocation ColonLoc, + StmtArg SubStmt, Scope *CurScope); virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, SourceLocation ColonLoc, StmtTy *SubStmt); virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 0c441f75231..b0f0c9b8ece 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -119,49 +119,54 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, return Owned(new CompoundStmt(Elts, NumElts, L, R)); } -Action::StmtResult -Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval, - SourceLocation DotDotDotLoc, ExprTy *rhsval, - SourceLocation ColonLoc, StmtTy *subStmt) { - Stmt *SubStmt = static_cast<Stmt*>(subStmt); - Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval); - assert((LHSVal != 0) && "missing expression in case statement"); - +Action::OwningStmtResult +Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, + SourceLocation DotDotDotLoc, ExprArg rhsval, + SourceLocation ColonLoc, StmtArg subStmt) { + Stmt *SubStmt = static_cast<Stmt*>(subStmt.release()); + assert((lhsval.get() != 0) && "missing expression in case statement"); + // C99 6.8.4.2p3: The expression shall be an integer constant. // However, GCC allows any evaluatable integer expression. + Expr *LHSVal = static_cast<Expr*>(lhsval.get()); if (VerifyIntegerConstantExpression(LHSVal)) - return SubStmt; + return Owned(SubStmt); // GCC extension: The expression shall be an integer constant. - - if (RHSVal && VerifyIntegerConstantExpression(RHSVal)) + + Expr *RHSVal = static_cast<Expr*>(rhsval.get()); + if (RHSVal && VerifyIntegerConstantExpression(RHSVal)) { RHSVal = 0; // Recover by just forgetting about it. - + rhsval = 0; + } + if (SwitchStack.empty()) { Diag(CaseLoc, diag::err_case_not_in_switch); - return SubStmt; + return Owned(SubStmt); } + // Only now release the smart pointers. + lhsval.release(); + rhsval.release(); CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc); SwitchStack.back()->addSwitchCase(CS); - return CS; + return Owned(CS); } -Action::StmtResult +Action::OwningStmtResult Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, - StmtTy *subStmt, Scope *CurScope) { - Stmt *SubStmt = static_cast<Stmt*>(subStmt); - + StmtArg subStmt, Scope *CurScope) { + Stmt *SubStmt = static_cast<Stmt*>(subStmt.release()); + if (SwitchStack.empty()) { Diag(DefaultLoc, diag::err_default_not_in_switch); - return SubStmt; + return Owned(SubStmt); } - + DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt); SwitchStack.back()->addSwitchCase(DS); - - return DS; + return Owned(DS); } Action::StmtResult |