]> granicus.if.org Git - clang/commitdiff
Some utilities for using the smart pointers in Actions, especially Sema. Convert...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Sat, 13 Dec 2008 16:23:55 +0000 (16:23 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Sat, 13 Dec 2008 16:23:55 +0000 (16:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60983 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/PrintParserCallbacks.cpp
include/clang/Parse/Action.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseObjc.cpp
lib/Parse/ParseStmt.cpp
lib/Parse/Parser.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExprCXX.cpp

index 8ec45f27036669e3c0c82e4230f186e28e752b35..6546b08816fc8cbe2355952b389d6d4d629fb8d3 100644 (file)
@@ -108,7 +108,7 @@ namespace {
     /// This allows ActOnDeclarator to register "xx" prior to parsing the
     /// initializer. The declaration above should still result in a warning, 
     /// since the reference to "xx" is uninitialized.
-    virtual void AddInitializerToDecl(DeclTy *Dcl, ExprTy *Init) {
+    virtual void AddInitializerToDecl(DeclTy *Dcl, ExprArg Init) {
       llvm::cout << __FUNCTION__ << "\n";
     }
 
@@ -140,12 +140,12 @@ namespace {
   
     /// ActOnFunctionDefBody - This is called when a function body has completed
     /// parsing.  Decl is the DeclTy returned by ParseStartOfFunctionDef.
-    virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body) {
+    virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body) {
       llvm::cout << __FUNCTION__ << "\n";
       return 0;
     }
 
-    virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *AsmString) {
+    virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg AsmString) {
       llvm::cout << __FUNCTION__ << "\n";
       return 0;
     }
index 991bd49fe9f6c4a507a5cb4e799c3dbad3398891..bfb32000d0450367db3eb98ea02166c735ab7b3a 100644 (file)
@@ -87,6 +87,17 @@ public:
   typedef ASTMultiPtr<&ActionBase::DeleteExpr> MultiExprArg;
   typedef ASTMultiPtr<&ActionBase::DeleteStmt> MultiStmtArg;
 
+
+  // Utilities for Action implementations to return smart results.
+
+  OwningExprResult ExprError() { return OwningExprResult(*this, true); }
+  OwningStmtResult StmtError() { return OwningStmtResult(*this, true); }
+  OwningExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); }
+  OwningStmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); }
+
+  OwningExprResult ExprEmpty() { return OwningExprResult(*this, false); }
+  OwningStmtResult StmtEmpty() { return OwningStmtResult(*this, false); }
+
   /// Statistics.
   virtual void PrintStats() const {}
   //===--------------------------------------------------------------------===//
@@ -170,7 +181,7 @@ public:
   /// This allows ActOnDeclarator to register "xx" prior to parsing the
   /// initializer. The declaration above should still result in a warning, 
   /// since the reference to "xx" is uninitialized.
-  virtual void AddInitializerToDecl(DeclTy *Dcl, ExprTy *Init) {
+  virtual void AddInitializerToDecl(DeclTy *Dcl, ExprArg Init) {
     return;
   }
 
@@ -204,14 +215,14 @@ public:
   virtual void ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
     return;
   }
-  
+
   /// ActOnFunctionDefBody - This is called when a function body has completed
   /// parsing.  Decl is the DeclTy returned by ParseStartOfFunctionDef.
-  virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body) {
+  virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body) {
     return Decl;
   }
 
-  virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *AsmString) {
+  virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg AsmString) {
     return 0;
   }
   
index 201e9d3a74f357225d994eb14732d984bef4b568..ed151402744e34e165fedc90464b399b45f0e5b3 100644 (file)
@@ -294,7 +294,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
         SkipUntil(tok::semi);
         return 0;
       }
-      Actions.AddInitializerToDecl(LastDeclInGroup, Init.release());
+      Actions.AddInitializerToDecl(LastDeclInGroup, move_convert(Init));
     } else if (Tok.is(tok::l_paren)) {
       // Parse C++ direct initializer: '(' expression-list ')'
       SourceLocation LParenLoc = ConsumeParen();
index 994e7837418f5685925834205174a6f743a8deee..5f2ebad6dbce9de545d8eeb355cd9b7836289637 100644 (file)
@@ -1364,12 +1364,12 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() {
   // If the function body could not be parsed, make a bogus compoundstmt.
   if (FnBody.isInvalid())
     FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
-  
+
   // Leave the function body scope.
   BodyScope.Exit();
-  
+
   // TODO: Pass argument information.
-  Actions.ActOnFinishFunctionBody(MDecl, FnBody.release());
+  Actions.ActOnFinishFunctionBody(MDecl, move_convert(FnBody));
   return MDecl;
 }
 
index ed4563bb6fdfba99f1d0b0972ea4ccf6d1fc7a9e..9f8771c9193b857acebfb845997ec8dc4250a180 100644 (file)
@@ -1240,5 +1240,5 @@ Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl,
   if (FnBody.isInvalid())
     FnBody = Owned(Actions.ActOnCompoundStmt(L, R, 0, 0, false));
 
-  return Actions.ActOnFinishFunctionBody(Decl, FnBody.release());
+  return Actions.ActOnFinishFunctionBody(Decl, move_convert(FnBody));
 }
index 1cd7c0e07506678dbcbd8ea943f7a05e8dde39f9..058182eee6b27431644d5ab1740b09ee1b1d5ce6 100644 (file)
@@ -342,7 +342,8 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
                      "top-level asm block");
 
     if (!Result.isInvalid())
-      return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), Result.release());
+      return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(),
+                                           move_convert(Result));
     return 0;
   }
   case tok::at:
index 97e8507e9b3b3e4946ddb9603b505166b4b1b52b..3a64486002b9efc436fb59d3b15ab5ca54efcbbb 100644 (file)
@@ -39,6 +39,7 @@ namespace clang {
   class DeclSpec;
   class NamedDecl;
   class ScopedDecl;
+  class Stmt;
   class Expr;
   class InitListExpr;
   class CallExpr;
@@ -242,6 +243,9 @@ public:
   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 @@ public:
   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 @@ public:
   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);
index 2c5e46afa0e73a352798140c42dd80156ef16de8..2890464657332004c3cb4d1dff3c086b0947cc2d 100644 (file)
@@ -1884,9 +1884,9 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
   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 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
   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 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
       // 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 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
 }
 
 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);
 }
 
index 40fcecfb1cdaeeb066d66f9f6978e5a783df0f5b..c3e947d432183e8dfcc841550d286328c725eb5c 100644 (file)
@@ -1391,7 +1391,7 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
 
   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
index a32a6f68fade3a4662c76bce7305f3bf459a41b6..e951016361a0c644769816e389f488350bea5cf9 100644 (file)
@@ -645,7 +645,7 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
   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))