Some utilities for using the smart pointers in Actions, especially Sema. Convert a few functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60983 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 97e8507..3a64486 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -39,6 +39,7 @@
class DeclSpec;
class NamedDecl;
class ScopedDecl;
+ class Stmt;
class Expr;
class InitListExpr;
class CallExpr;
@@ -242,6 +243,9 @@
virtual void DeleteExpr(ExprTy *E);
virtual void DeleteStmt(StmtTy *S);
+ OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
+ OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
+
virtual void ActOnEndOfTranslationUnit();
//===--------------------------------------------------------------------===//
@@ -268,7 +272,7 @@
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
ExprTy *defarg);
- void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
+ void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
void ActOnUninitializedDecl(DeclTy *dcl);
virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
@@ -276,11 +280,11 @@
virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
- virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body);
+ virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
virtual DeclTy *ActOnLinkageSpec(SourceLocation Loc, SourceLocation LBrace,
SourceLocation RBrace, const char *Lang,
unsigned StrSize, DeclTy *D);
- virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *expr);
+ virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
/// Scope actions.
virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 2c5e46a..2890464 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1884,9 +1884,9 @@
return true;
}
-void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
+void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init) {
Decl *RealDecl = static_cast<Decl *>(dcl);
- Expr *Init = static_cast<Expr *>(init);
+ Expr *Init = static_cast<Expr *>(init.release());
assert(Init && "missing initializer");
// If there is no declaration, there was an error parsing it. Just ignore
@@ -2281,10 +2281,11 @@
return FD;
}
-Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
+Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
Decl *dcl = static_cast<Decl *>(D);
+ Stmt *Body = static_cast<Stmt*>(BodyArg.release());
if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(dcl)) {
- FD->setBody((Stmt*)Body);
+ FD->setBody(Body);
assert(FD == getCurFunctionDecl() && "Function parsing confused");
} else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
MD->setBody((Stmt*)Body);
@@ -2309,7 +2310,7 @@
// formed.
if (Body) {
L->setSubStmt(new NullStmt(L->getIdentLoc()));
- cast<CompoundStmt>((Stmt*)Body)->push_back(L);
+ cast<CompoundStmt>(Body)->push_back(L);
} else {
// The whole function wasn't parsed correctly, just delete this.
delete L;
@@ -3358,9 +3359,9 @@
}
Sema::DeclTy *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc,
- ExprTy *expr) {
- StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr);
-
+ ExprArg expr) {
+ StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr.release());
+
return FileScopeAsmDecl::Create(Context, Loc, AsmString);
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 40fcecf..c3e947d 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -1391,7 +1391,7 @@
assert(NumExprs == 1 && "Expected 1 expression");
// Set the init expression, handles conversions.
- AddInitializerToDecl(Dcl, ExprTys[0]);
+ AddInitializerToDecl(Dcl, ExprArg(*this, ExprTys[0]));
}
/// PerformInitializationByConstructor - Perform initialization by
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index a32a6f6..e951016 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -645,7 +645,7 @@
DeclTy *Dcl = ActOnDeclarator(S, D, 0);
if (!Dcl)
return true;
- AddInitializerToDecl(Dcl, AssignExprVal);
+ AddInitializerToDecl(Dcl, ExprArg(*this, AssignExprVal));
// Mark this variable as one that is declared within a conditional.
if (VarDecl *VD = dyn_cast<VarDecl>((Decl *)Dcl))