forked from OSchip/llvm-project
Remove multiple use of weak_import attribute on
same declaration. Templatize dropAttr for general use. llvm-svn: 133724
This commit is contained in:
parent
be5a4416ff
commit
0dfc950609
|
@ -363,7 +363,6 @@ public:
|
|||
const AttrVec &getAttrs() const;
|
||||
void swapAttrs(Decl *D);
|
||||
void dropAttrs();
|
||||
void dropWeakImportAttr();
|
||||
|
||||
void addAttr(Attr *A) {
|
||||
if (hasAttrs())
|
||||
|
@ -382,7 +381,10 @@ public:
|
|||
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());
|
||||
|
|
|
@ -520,20 +520,6 @@ void Decl::dropAttrs() {
|
|||
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 @@ Decl *Decl::castFromDeclContext (const DeclContext *D) {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -2046,7 +2046,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue