diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-15 00:05:00 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-15 00:05:00 +0000 |
commit | 643d3ce93c501d19353f2fa578fee3e97f1d1b4b (patch) | |
tree | be1d9ede9d38a2bb26637c8b4104947b531cb93e /tools/libclang/IndexingContext.h | |
parent | 90fd67af4aeec7d1661986dd25eabf924e11a76c (diff) |
[libclang] Indexing API: provide an attribute list inside CXIdxEntityInfo
so that we can access the attributes of an entity for a reference.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/IndexingContext.h')
-rw-r--r-- | tools/libclang/IndexingContext.h | 105 |
1 files changed, 69 insertions, 36 deletions
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h index b9234d88b3..f5498e5292 100644 --- a/tools/libclang/IndexingContext.h +++ b/tools/libclang/IndexingContext.h @@ -24,13 +24,18 @@ namespace clang { namespace cxindex { class IndexingContext; + class ScratchAlloc; + class AttrListInfo; struct EntityInfo : public CXIdxEntityInfo { const NamedDecl *Dcl; IndexingContext *IndexCtx; + llvm::IntrusiveRefCntPtr<AttrListInfo> AttrList; EntityInfo() { name = USR = 0; + attributes = 0; + numAttributes = 0; } }; @@ -195,14 +200,49 @@ struct IBOutletCollectionInfo : public AttrInfo { IBOutletCollectionInfo(CXCursor C, CXIdxLoc Loc, const Attr *A) : AttrInfo(CXIdxAttr_IBOutletCollection, C, Loc, A) { assert(C.kind == CXCursor_IBOutletCollectionAttr); + IBCollInfo.objcClass = 0; } + IBOutletCollectionInfo(const IBOutletCollectionInfo &other); + static bool classof(const AttrInfo *A) { return A->kind == CXIdxAttr_IBOutletCollection; } static bool classof(const IBOutletCollectionInfo *D) { return true; } }; +class AttrListInfo { + SmallVector<AttrInfo, 2> Attrs; + SmallVector<IBOutletCollectionInfo, 2> IBCollAttrs; + SmallVector<CXIdxAttrInfo *, 2> CXAttrs; + unsigned ref_cnt; + +public: + AttrListInfo(const Decl *D, + IndexingContext &IdxCtx, + ScratchAlloc &SA); + AttrListInfo(const AttrListInfo &other); + + const CXIdxAttrInfo *const *getAttrs() const { + if (CXAttrs.empty()) + return 0; + return CXAttrs.data(); + } + unsigned getNumAttrs() const { return (unsigned)CXAttrs.size(); } + + /// \brief Retain/Release only useful when we allocate a AttrListInfo from the + /// BumpPtrAllocator, and not from the stack; so that we keep a pointer + // in the EntityInfo + void Retain() { ++ref_cnt; } + void Release() { + assert (ref_cnt > 0 && "Reference count is already zero."); + if (--ref_cnt == 0) { + // Memory is allocated from a BumpPtrAllocator, no need to delete it. + this->~AttrListInfo(); + } + } +}; + struct RefFileOccurence { const FileEntry *File; const Decl *Dcl; @@ -233,24 +273,7 @@ class IndexingContext { llvm::BumpPtrAllocator StrScratch; unsigned StrAdapterCount; - - class StrAdapter { - IndexingContext &IdxCtx; - - public: - StrAdapter(IndexingContext &indexCtx) : IdxCtx(indexCtx) { - ++IdxCtx.StrAdapterCount; - } - - ~StrAdapter() { - --IdxCtx.StrAdapterCount; - if (IdxCtx.StrAdapterCount == 0) - IdxCtx.StrScratch.Reset(); - } - - const char *toCStr(StringRef Str); - const char *copyCStr(StringRef Str); - }; + friend class ScratchAlloc; struct ObjCProtocolListInfo { SmallVector<CXIdxObjCProtocolRefInfo, 4> ProtInfos; @@ -265,22 +288,7 @@ class IndexingContext { ObjCProtocolListInfo(const ObjCProtocolList &ProtList, IndexingContext &IdxCtx, - IndexingContext::StrAdapter &SA); - }; - - struct AttrListInfo { - SmallVector<AttrInfo, 2> Attrs; - SmallVector<IBOutletCollectionInfo, 2> IBCollAttrs; - SmallVector<CXIdxAttrInfo *, 2> CXAttrs; - - const CXIdxAttrInfo *const *getAttrs() const { - return CXAttrs.data(); - } - unsigned getNumAttrs() const { return (unsigned)CXAttrs.size(); } - - AttrListInfo(const Decl *D, - IndexingContext &IdxCtx, - IndexingContext::StrAdapter &SA); + ScratchAlloc &SA); }; struct CXXBasesListInfo { @@ -294,12 +302,14 @@ class IndexingContext { unsigned getNumBases() const { return (unsigned)CXBases.size(); } CXXBasesListInfo(const CXXRecordDecl *D, - IndexingContext &IdxCtx, IndexingContext::StrAdapter &SA); + IndexingContext &IdxCtx, ScratchAlloc &SA); private: SourceLocation getBaseLoc(const CXXBaseSpecifier &Base) const; }; + friend class AttrListInfo; + public: IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks, unsigned indexOptions, CXTranslationUnit cxTU) @@ -440,7 +450,7 @@ private: void getEntityInfo(const NamedDecl *D, EntityInfo &EntityInfo, - StrAdapter &SA); + ScratchAlloc &SA); void getContainerInfo(const DeclContext *DC, ContainerInfo &ContInfo); @@ -453,6 +463,29 @@ private: static bool shouldIgnoreIfImplicit(const NamedDecl *D); }; +class ScratchAlloc { + IndexingContext &IdxCtx; + +public: + explicit ScratchAlloc(IndexingContext &indexCtx) : IdxCtx(indexCtx) { + ++IdxCtx.StrAdapterCount; + } + + ~ScratchAlloc() { + --IdxCtx.StrAdapterCount; + if (IdxCtx.StrAdapterCount == 0) + IdxCtx.StrScratch.Reset(); + } + + const char *toCStr(StringRef Str); + const char *copyCStr(StringRef Str); + + template <typename T> + T *allocate() { + return IdxCtx.StrScratch.Allocate<T>(); + } +}; + }} // end clang::cxindex namespace llvm { |