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

Douglas Gregor dgregor at apple.com
Thu Jun 23 11:02:12 PDT 2011


On Jun 23, 2011, at 10:50 AM, Fariborz Jahanian wrote:

> 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;

This will generally work, but we'll end up wrapping "i" around when erasing the first element. How about:

for (unsigned i = 0, e = Attrs.size(); i != e; /* in loop */) {
  if (isa<T>(Attrs[i])) {
     Attrs.erase(Attrs.begin() + i);
     --e;
  } else {
    ++i;
  }
}

?


Thanks!

	- Doug



More information about the cfe-commits mailing list