IBCollInfo.objcClass = 0;
}
-AttrListInfo::AttrListInfo(const Decl *D,
- IndexingContext &IdxCtx,
- ScratchAlloc &SA) : ref_cnt(0) {
+AttrListInfo::AttrListInfo(const Decl *D, IndexingContext &IdxCtx)
+ : SA(IdxCtx), ref_cnt(0) {
+
if (!D->hasAttrs())
return;
CXAttrs.push_back(&Attrs[i]);
}
-AttrListInfo::AttrListInfo(const AttrListInfo &other) {
- assert(other.ref_cnt == 0 &&
- "Should not copy an AttrListInfo that is ref-counted");
- ref_cnt = 0;
-
- Attrs = other.Attrs;
- IBCollAttrs = other.IBCollAttrs;
-
- for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i)
- CXAttrs.push_back(&IBCollAttrs[i]);
-
- for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
- CXAttrs.push_back(&Attrs[i]);
+IntrusiveRefCntPtr<AttrListInfo>
+AttrListInfo::create(const Decl *D, IndexingContext &IdxCtx) {
+ ScratchAlloc SA(IdxCtx);
+ AttrListInfo *attrs = SA.allocate<AttrListInfo>();
+ return new (attrs) AttrListInfo(D, IdxCtx);
}
IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
DInfo.loc = getIndexLoc(Loc);
DInfo.isImplicit = D->isImplicit();
- AttrListInfo AttrList(D, *this, SA);
- DInfo.attributes = AttrList.getAttrs();
- DInfo.numAttributes = AttrList.getNumAttrs();
+ DInfo.attributes = DInfo.EntInfo.attributes;
+ DInfo.numAttributes = DInfo.EntInfo.numAttributes;
getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer);
DInfo.semanticContainer = &DInfo.SemanticContainer;
}
bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
+ ScratchAlloc SA(*this);
+
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false);
EntityInfo ClassEntity;
- ScratchAlloc SA(*this);
const ObjCInterfaceDecl *IFaceD = D->getClassInterface();
SourceLocation ClassLoc = D->getLocation();
SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc
}
bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
+ ScratchAlloc SA(*this);
+
const ObjCCategoryDecl *CatD = D->getCategoryDecl();
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true);
EntityInfo ClassEntity;
- ScratchAlloc SA(*this);
const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface();
SourceLocation ClassLoc = D->getLocation();
SourceLocation CategoryLoc = D->getCategoryNameLoc();
}
bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
+ ScratchAlloc SA(*this);
+
ObjCPropertyDeclInfo DInfo;
EntityInfo GetterEntity;
EntityInfo SetterEntity;
- ScratchAlloc SA(*this);
DInfo.ObjCPropDeclInfo.declInfo = &DInfo;
EntityInfo.lang = CXIdxEntityLang_C;
if (D->hasAttrs()) {
- AttrListInfo *attrs = SA.allocate<AttrListInfo>();
- new (attrs) AttrListInfo(D, *this, SA);
- EntityInfo.AttrList = attrs;
- EntityInfo.attributes = attrs->getAttrs();
- EntityInfo.numAttributes = attrs->getNumAttrs();
+ EntityInfo.AttrList = AttrListInfo::create(D, *this);
+ EntityInfo.attributes = EntityInfo.AttrList->getAttrs();
+ EntityInfo.numAttributes = EntityInfo.AttrList->getNumAttrs();
}
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
namespace cxindex {
class IndexingContext;
- class ScratchAlloc;
class AttrListInfo;
+class ScratchAlloc {
+ IndexingContext &IdxCtx;
+
+public:
+ explicit ScratchAlloc(IndexingContext &indexCtx);
+ ScratchAlloc(const ScratchAlloc &SA);
+
+ ~ScratchAlloc();
+
+ const char *toCStr(StringRef Str);
+ const char *copyCStr(StringRef Str);
+
+ template <typename T>
+ T *allocate();
+};
+
struct EntityInfo : public CXIdxEntityInfo {
const NamedDecl *Dcl;
IndexingContext *IndexCtx;
};
class AttrListInfo {
+ ScratchAlloc SA;
+
SmallVector<AttrInfo, 2> Attrs;
SmallVector<IBOutletCollectionInfo, 2> IBCollAttrs;
SmallVector<CXIdxAttrInfo *, 2> CXAttrs;
unsigned ref_cnt;
+ AttrListInfo(const AttrListInfo&); // DO NOT IMPLEMENT
+ void operator=(const AttrListInfo&); // DO NOT IMPLEMENT
public:
- AttrListInfo(const Decl *D,
- IndexingContext &IdxCtx,
- ScratchAlloc &SA);
- AttrListInfo(const AttrListInfo &other);
+ AttrListInfo(const Decl *D, IndexingContext &IdxCtx);
+
+ static IntrusiveRefCntPtr<AttrListInfo> create(const Decl *D,
+ IndexingContext &IdxCtx);
const CXIdxAttrInfo *const *getAttrs() const {
if (CXAttrs.empty())
static bool shouldIgnoreIfImplicit(const Decl *D);
};
-class ScratchAlloc {
- IndexingContext &IdxCtx;
-
-public:
- explicit ScratchAlloc(IndexingContext &indexCtx) : IdxCtx(indexCtx) {
- ++IdxCtx.StrAdapterCount;
- }
-
- ~ScratchAlloc() {
- --IdxCtx.StrAdapterCount;
- if (IdxCtx.StrAdapterCount == 0)
- IdxCtx.StrScratch.Reset();
- }
+inline ScratchAlloc::ScratchAlloc(IndexingContext &idxCtx) : IdxCtx(idxCtx) {
+ ++IdxCtx.StrAdapterCount;
+}
+inline ScratchAlloc::ScratchAlloc(const ScratchAlloc &SA) : IdxCtx(SA.IdxCtx) {
+ ++IdxCtx.StrAdapterCount;
+}
- const char *toCStr(StringRef Str);
- const char *copyCStr(StringRef Str);
+inline ScratchAlloc::~ScratchAlloc() {
+ --IdxCtx.StrAdapterCount;
+ if (IdxCtx.StrAdapterCount == 0)
+ IdxCtx.StrScratch.Reset();
+}
- template <typename T>
- T *allocate() {
- return IdxCtx.StrScratch.Allocate<T>();
- }
-};
+template <typename T>
+inline T *ScratchAlloc::allocate() {
+ return IdxCtx.StrScratch.Allocate<T>();
+}
}} // end clang::cxindex