From: Sebastian Redl Date: Sun, 28 Dec 2008 16:13:43 +0000 (+0000) Subject: Convert a two more statement actions to smart pointers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=117054a99f4994e4ec8a1fc904b554e1f2dc9b29;p=clang Convert a two more statement actions to smart pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61456 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/PrintParserCallbacks.cpp b/Driver/PrintParserCallbacks.cpp index 291ee393c1..c5d754e73d 100644 --- a/Driver/PrintParserCallbacks.cpp +++ b/Driver/PrintParserCallbacks.cpp @@ -269,17 +269,20 @@ namespace { /// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension, /// which can specify an RHS value. - virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, - SourceLocation DotDotDotLoc, ExprTy *RHSVal, - SourceLocation ColonLoc, StmtTy *SubStmt) { + virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, + ExprArg LHSVal, + SourceLocation DotDotDotLoc, + ExprArg RHSVal, + SourceLocation ColonLoc, + StmtArg SubStmt) { llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } - virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, - SourceLocation ColonLoc, StmtTy *SubStmt, - Scope *CurScope){ + virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, + SourceLocation ColonLoc, + StmtArg SubStmt, Scope *CurScope){ llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 335b97224c..b55106a9c6 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -366,15 +366,15 @@ public: /// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension, /// which can specify an RHS value. - virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, - SourceLocation DotDotDotLoc, ExprTy *RHSVal, - SourceLocation ColonLoc, StmtTy *SubStmt) { - return 0; + virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, + SourceLocation DotDotDotLoc, ExprArg RHSVal, + SourceLocation ColonLoc, StmtArg SubStmt) { + return StmtEmpty(); } - virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, - SourceLocation ColonLoc, StmtTy *SubStmt, - Scope *CurScope){ - return 0; + virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, + SourceLocation ColonLoc, + StmtArg SubStmt, Scope *CurScope){ + return StmtEmpty(); } virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index c853ecf884..9f525a5491 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -271,9 +271,9 @@ Parser::OwningStmtResult Parser::ParseCaseStatement() { if (SubStmt.isInvalid()) SubStmt = Actions.ActOnNullStmt(ColonLoc); - return Owned(Actions.ActOnCaseStmt(CaseLoc, LHS.release(), DotDotDotLoc, - RHS.release(), ColonLoc, - SubStmt.release())); + return Actions.ActOnCaseStmt(CaseLoc, move_convert(LHS), DotDotDotLoc, + move_convert(RHS), ColonLoc, + move_convert(SubStmt)); } /// ParseDefaultStatement @@ -303,8 +303,8 @@ Parser::OwningStmtResult Parser::ParseDefaultStatement() { if (SubStmt.isInvalid()) return StmtError(); - return Owned(Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc, - SubStmt.release(), CurScope)); + return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc, + move_convert(SubStmt), CurScope); } diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 94e8a3cccc..386639061d 100644 --- a/lib/Sema/Sema.h +++ b/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/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 0c441f7523..b0f0c9b8ec 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/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(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(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(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(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(subStmt); - + StmtArg subStmt, Scope *CurScope) { + Stmt *SubStmt = static_cast(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