[cfe-commits] r133724 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/Sema/SemaDecl.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Jun 23 10:50:10 PDT 2011


Author: fjahanian
Date: Thu Jun 23 12:50:10 2011
New Revision: 133724

URL: http://llvm.org/viewvc/llvm-project?rev=133724&view=rev
Log:
Remove multiple use of weak_import attribute on
same declaration. Templatize dropAttr for general use.


Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=133724&r1=133723&r2=133724&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Jun 23 12:50:10 2011
@@ -363,7 +363,6 @@
   const AttrVec &getAttrs() const;
   void swapAttrs(Decl *D);
   void dropAttrs();
-  void dropWeakImportAttr();
 
   void addAttr(Attr *A) {
     if (hasAttrs())
@@ -382,7 +381,10 @@
   attr_iterator attr_end() const {
     return hasAttrs() ? getAttrs().end() : 0;
   }
-
+  
+  template <typename T>
+  void dropAttr();
+  
   template <typename T>
   specific_attr_iterator<T> specific_attr_begin() const {
     return specific_attr_iterator<T>(attr_begin());

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=133724&r1=133723&r2=133724&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Jun 23 12:50:10 2011
@@ -520,20 +520,6 @@
   getASTContext().eraseDeclAttrs(this);
 }
 
-void Decl::dropWeakImportAttr() {
-  if (!HasAttrs) return;
-  AttrVec &Attrs = getASTContext().getDeclAttrs(this);
-  for (llvm::SmallVectorImpl<Attr*>::iterator A = Attrs.begin();
-       A != Attrs.end(); ++A) {
-    if (isa<WeakImportAttr>(*A)) {
-      Attrs.erase(A);
-      break;
-    }
-  }
-  if (Attrs.empty())
-    HasAttrs = false;
-}
-
 const AttrVec &Decl::getAttrs() const {
   assert(HasAttrs && "No attrs to get!");
   return getASTContext().getDeclAttrs(this);
@@ -585,6 +571,22 @@
   }
 }
 
+template <typename T>
+void Decl::dropAttr() {
+  if (!HasAttrs) return;
+  AttrVec &Attrs = getASTContext().getDeclAttrs(this);
+  for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
+    if (isa<T>(Attrs[i])) {
+      Attrs.erase(Attrs.begin() + i);
+      --i, --e;
+    }
+  }
+  if (Attrs.empty())
+    HasAttrs = false;
+}
+// Force instantiation for WeakImportAttr which gets used.
+template void Decl::dropAttr<WeakImportAttr>();
+
 DeclContext *Decl::castToDeclContext(const Decl *D) {
   Decl::Kind DK = D->getKind();
   switch(DK) {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=133724&r1=133723&r2=133724&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jun 23 12:50:10 2011
@@ -2046,7 +2046,7 @@
     Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
     Diag(Old->getLocation(), diag::note_previous_definition);
     // Remove weak_import attribute on new declaration.
-    New->dropWeakImportAttr();
+    New->dropAttr<WeakImportAttr>();
   }
 
   // Merge the types.





More information about the cfe-commits mailing list