class Redeclarable {
protected:
- // FIXME: PointerIntPair is a value class that should not be inherited from.
- // This should change to using containment.
- struct DeclLink : public llvm::PointerIntPair<decl_type *, 1, bool> {
+ class DeclLink {
+ llvm::PointerIntPair<decl_type *, 1, bool> NextAndIsPrevious;
+ public:
DeclLink(decl_type *D, bool isLatest)
- : llvm::PointerIntPair<decl_type *, 1, bool>(D, isLatest) { }
-
- typedef llvm::PointerIntPair<decl_type *, 1, bool> base_type;
+ : NextAndIsPrevious(D, isLatest) { }
- bool NextIsPrevious() const { return base_type::getInt() == false; }
- bool NextIsLatest() const { return base_type::getInt() == true; }
- decl_type *getNext() const { return base_type::getPointer(); }
+ bool NextIsPrevious() const { return !NextAndIsPrevious.getInt(); }
+ bool NextIsLatest() const { return NextAndIsPrevious.getInt(); }
+ decl_type *getNext() const { return NextAndIsPrevious.getPointer(); }
+ void setNext(decl_type *D) { NextAndIsPrevious.setPointer(D); }
};
- struct PreviousDeclLink : public DeclLink {
- PreviousDeclLink(decl_type *D) : DeclLink(D, false) { }
- };
+ static DeclLink PreviousDeclLink(decl_type *D) {
+ return DeclLink(D, false);
+ }
- struct LatestDeclLink : public DeclLink {
- LatestDeclLink(decl_type *D) : DeclLink(D, true) { }
- };
+ static DeclLink LatestDeclLink(decl_type *D) {
+ return DeclLink(D, true);
+ }
/// \brief Points to the next redeclaration in the chain.
///
// We temporarily set the first (canonical) declaration as the previous one
// which is the one that matters and mark the real previous DeclID to be
// loaded & attached later on.
- D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
+ D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
}
// Note that this declaration has been deserialized.
// Have our redeclaration link point back at the canonical declaration
// of the existing declaration, so that this declaration has the
// appropriate canonical declaration.
- D->RedeclLink
- = typename Redeclarable<T>::PreviousDeclLink(ExistingCanon);
+ D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
// When we merge a namespace, update its pointer to the first namespace.
if (NamespaceDecl *Namespace
void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
assert(D && previous);
if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
- TD->RedeclLink.setPointer(cast<TagDecl>(previous));
+ TD->RedeclLink.setNext(cast<TagDecl>(previous));
} else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
+ FD->RedeclLink.setNext(cast<FunctionDecl>(previous));
} else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
- VD->RedeclLink.setPointer(cast<VarDecl>(previous));
+ VD->RedeclLink.setNext(cast<VarDecl>(previous));
} else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
- TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
+ TD->RedeclLink.setNext(cast<TypedefNameDecl>(previous));
} else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
- ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
+ ID->RedeclLink.setNext(cast<ObjCInterfaceDecl>(previous));
} else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
- PD->RedeclLink.setPointer(cast<ObjCProtocolDecl>(previous));
+ PD->RedeclLink.setNext(cast<ObjCProtocolDecl>(previous));
} else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) {
- ND->RedeclLink.setPointer(cast<NamespaceDecl>(previous));
+ ND->RedeclLink.setNext(cast<NamespaceDecl>(previous));
} else {
RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
- TD->RedeclLink.setPointer(cast<RedeclarableTemplateDecl>(previous));
+ TD->RedeclLink.setNext(cast<RedeclarableTemplateDecl>(previous));
}
}