]> granicus.if.org Git - clang/commitdiff
add an a Attr::Destroy method and force clients to go through it. As part of
authorChris Lattner <sabre@nondot.org>
Wed, 4 Mar 2009 06:05:19 +0000 (06:05 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Mar 2009 06:05:19 +0000 (06:05 +0000)
this, make DeclBase::Destroy destroy attributes instead of the DeclBase dtor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66020 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
lib/AST/DeclBase.cpp
lib/Sema/SemaDecl.cpp

index e814c5c7197db2e5f0adcc535a7cdfd1eee6800b..89fe0f041665b9351d5477c4ec174d2005da25be 100644 (file)
@@ -20,6 +20,7 @@
 #include <algorithm>
 
 namespace clang {
+  class ASTContext;
 
 /// Attr - This represents one attribute.
 class Attr {
@@ -69,10 +70,14 @@ private:
 
 protected:
   Attr(Kind AK) : Next(0), AttrKind(AK), Inherited(false) {}
-public:
   virtual ~Attr() {
     delete Next;
   }
+public:
+  
+  void Destroy(ASTContext &C) {
+    delete this;
+  }
 
   /// \brief Whether this attribute should be merged to new
   /// declarations.
index ca67e28c717387599e77329dbd16af7adbd9eb10..3e968c7896262711edf4008b8f405ff803071bae 100644 (file)
@@ -121,15 +121,7 @@ Decl::~Decl() {
   if (isOutOfSemaDC())
     delete getMultipleDC();
 
-  if (!HasAttrs)
-    return;
-  
-  DeclAttrMapTy::iterator it = DeclAttrs->find(this);
-  assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
-
-  // release attributes.
-  delete it->second;
-  invalidateAttrs();
+  assert(!HasAttrs && "attributes should have been freed by Destroy");
 }
 
 void Decl::addAttr(Attr *NewAttr) {
@@ -189,7 +181,18 @@ void Decl::swapAttrs(Decl *RHS) {
 }
 
 
-void Decl::Destroy(ASTContext& C) {
+void Decl::Destroy(ASTContext &C) {
+  // Free attributes for this decl.
+  if (HasAttrs) {
+    DeclAttrMapTy::iterator it = DeclAttrs->find(this);
+    assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
+  
+    // release attributes.
+    it->second->Destroy(C);
+    invalidateAttrs();
+    HasAttrs = false;
+  }
+  
 #if 0
   // FIXME: Once ownership is fully understood, we can enable this code
   if (DeclContext *DC = dyn_cast<DeclContext>(this))
index 8d32578c98cf808626c4c359dc4f593effb44a8d..6a6628f748ef4bc5f14d2f9093b443ecb273d699 100644 (file)
@@ -482,11 +482,11 @@ static bool DeclHasAttr(const Decl *decl, const Attr *target) {
 }
 
 /// MergeAttributes - append attributes from the Old decl to the New one.
-static void MergeAttributes(Decl *New, Decl *Old) {
-  Attr *attr = const_cast<Attr*>(Old->getAttrs()), *tmp;
+static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) {
+  Attr *attr = const_cast<Attr*>(Old->getAttrs());
 
   while (attr) {
-    tmp = attr;
+    Attr *tmp = attr;
     attr = attr->getNext();
 
     if (!DeclHasAttr(New, tmp) && tmp->isMerged()) {
@@ -494,7 +494,7 @@ static void MergeAttributes(Decl *New, Decl *Old) {
       New->addAttr(tmp);
     } else {
       tmp->setNext(0);
-      delete(tmp);
+      tmp->Destroy(C);
     }
   }
 
@@ -678,7 +678,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
 /// \returns false
 bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) {
   // Merge the attributes
-  MergeAttributes(New, Old);
+  MergeAttributes(New, Old, Context);
 
   // Merge the storage class.
   New->setStorageClass(Old->getStorageClass());
@@ -767,7 +767,7 @@ bool Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
     return true;
   }
 
-  MergeAttributes(New, Old);
+  MergeAttributes(New, Old, Context);
 
   // Merge the types
   QualType MergedT = Context.mergeTypes(New->getType(), Old->getType());