1f4a2713aSLionel Sambuc //===- IndexingContext.h - Higher level API functions -----------*- C++ -*-===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc
10*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_TOOLS_LIBCLANG_INDEXINGCONTEXT_H
11*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_TOOLS_LIBCLANG_INDEXINGCONTEXT_H
12*0a6a1f1dSLionel Sambuc
13f4a2713aSLionel Sambuc #include "CXCursor.h"
14f4a2713aSLionel Sambuc #include "Index_Internal.h"
15f4a2713aSLionel Sambuc #include "clang/AST/DeclGroup.h"
16f4a2713aSLionel Sambuc #include "clang/AST/DeclObjC.h"
17f4a2713aSLionel Sambuc #include "llvm/ADT/DenseSet.h"
18f4a2713aSLionel Sambuc #include <deque>
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc namespace clang {
21f4a2713aSLionel Sambuc class FileEntry;
22f4a2713aSLionel Sambuc class MSPropertyDecl;
23f4a2713aSLionel Sambuc class ObjCPropertyDecl;
24f4a2713aSLionel Sambuc class ClassTemplateDecl;
25f4a2713aSLionel Sambuc class FunctionTemplateDecl;
26f4a2713aSLionel Sambuc class TypeAliasTemplateDecl;
27f4a2713aSLionel Sambuc class ClassTemplateSpecializationDecl;
28f4a2713aSLionel Sambuc
29f4a2713aSLionel Sambuc namespace cxindex {
30f4a2713aSLionel Sambuc class IndexingContext;
31f4a2713aSLionel Sambuc class AttrListInfo;
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc class ScratchAlloc {
34f4a2713aSLionel Sambuc IndexingContext &IdxCtx;
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc public:
37f4a2713aSLionel Sambuc explicit ScratchAlloc(IndexingContext &indexCtx);
38f4a2713aSLionel Sambuc ScratchAlloc(const ScratchAlloc &SA);
39f4a2713aSLionel Sambuc
40f4a2713aSLionel Sambuc ~ScratchAlloc();
41f4a2713aSLionel Sambuc
42f4a2713aSLionel Sambuc const char *toCStr(StringRef Str);
43f4a2713aSLionel Sambuc const char *copyCStr(StringRef Str);
44f4a2713aSLionel Sambuc
45f4a2713aSLionel Sambuc template <typename T>
46f4a2713aSLionel Sambuc T *allocate();
47f4a2713aSLionel Sambuc };
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc struct EntityInfo : public CXIdxEntityInfo {
50f4a2713aSLionel Sambuc const NamedDecl *Dcl;
51f4a2713aSLionel Sambuc IndexingContext *IndexCtx;
52f4a2713aSLionel Sambuc IntrusiveRefCntPtr<AttrListInfo> AttrList;
53f4a2713aSLionel Sambuc
EntityInfoEntityInfo54f4a2713aSLionel Sambuc EntityInfo() {
55*0a6a1f1dSLionel Sambuc name = USR = nullptr;
56*0a6a1f1dSLionel Sambuc attributes = nullptr;
57f4a2713aSLionel Sambuc numAttributes = 0;
58f4a2713aSLionel Sambuc }
59f4a2713aSLionel Sambuc };
60f4a2713aSLionel Sambuc
61f4a2713aSLionel Sambuc struct ContainerInfo : public CXIdxContainerInfo {
62f4a2713aSLionel Sambuc const DeclContext *DC;
63f4a2713aSLionel Sambuc IndexingContext *IndexCtx;
64f4a2713aSLionel Sambuc };
65f4a2713aSLionel Sambuc
66f4a2713aSLionel Sambuc struct DeclInfo : public CXIdxDeclInfo {
67f4a2713aSLionel Sambuc enum DInfoKind {
68f4a2713aSLionel Sambuc Info_Decl,
69f4a2713aSLionel Sambuc
70f4a2713aSLionel Sambuc Info_ObjCContainer,
71f4a2713aSLionel Sambuc Info_ObjCInterface,
72f4a2713aSLionel Sambuc Info_ObjCProtocol,
73f4a2713aSLionel Sambuc Info_ObjCCategory,
74f4a2713aSLionel Sambuc
75f4a2713aSLionel Sambuc Info_ObjCProperty,
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc Info_CXXClass
78f4a2713aSLionel Sambuc };
79f4a2713aSLionel Sambuc
80f4a2713aSLionel Sambuc DInfoKind Kind;
81f4a2713aSLionel Sambuc
82f4a2713aSLionel Sambuc EntityInfo EntInfo;
83f4a2713aSLionel Sambuc ContainerInfo SemanticContainer;
84f4a2713aSLionel Sambuc ContainerInfo LexicalContainer;
85f4a2713aSLionel Sambuc ContainerInfo DeclAsContainer;
86f4a2713aSLionel Sambuc
DeclInfoDeclInfo87f4a2713aSLionel Sambuc DeclInfo(bool isRedeclaration, bool isDefinition, bool isContainer)
88f4a2713aSLionel Sambuc : Kind(Info_Decl) {
89f4a2713aSLionel Sambuc this->isRedeclaration = isRedeclaration;
90f4a2713aSLionel Sambuc this->isDefinition = isDefinition;
91f4a2713aSLionel Sambuc this->isContainer = isContainer;
92*0a6a1f1dSLionel Sambuc attributes = nullptr;
93f4a2713aSLionel Sambuc numAttributes = 0;
94*0a6a1f1dSLionel Sambuc declAsContainer = semanticContainer = lexicalContainer = nullptr;
95f4a2713aSLionel Sambuc flags = 0;
96f4a2713aSLionel Sambuc }
DeclInfoDeclInfo97f4a2713aSLionel Sambuc DeclInfo(DInfoKind K,
98f4a2713aSLionel Sambuc bool isRedeclaration, bool isDefinition, bool isContainer)
99f4a2713aSLionel Sambuc : Kind(K) {
100f4a2713aSLionel Sambuc this->isRedeclaration = isRedeclaration;
101f4a2713aSLionel Sambuc this->isDefinition = isDefinition;
102f4a2713aSLionel Sambuc this->isContainer = isContainer;
103*0a6a1f1dSLionel Sambuc attributes = nullptr;
104f4a2713aSLionel Sambuc numAttributes = 0;
105*0a6a1f1dSLionel Sambuc declAsContainer = semanticContainer = lexicalContainer = nullptr;
106f4a2713aSLionel Sambuc flags = 0;
107f4a2713aSLionel Sambuc }
108f4a2713aSLionel Sambuc };
109f4a2713aSLionel Sambuc
110f4a2713aSLionel Sambuc struct ObjCContainerDeclInfo : public DeclInfo {
111f4a2713aSLionel Sambuc CXIdxObjCContainerDeclInfo ObjCContDeclInfo;
112f4a2713aSLionel Sambuc
ObjCContainerDeclInfoObjCContainerDeclInfo113f4a2713aSLionel Sambuc ObjCContainerDeclInfo(bool isForwardRef,
114f4a2713aSLionel Sambuc bool isRedeclaration,
115f4a2713aSLionel Sambuc bool isImplementation)
116f4a2713aSLionel Sambuc : DeclInfo(Info_ObjCContainer, isRedeclaration,
117f4a2713aSLionel Sambuc /*isDefinition=*/!isForwardRef, /*isContainer=*/!isForwardRef) {
118f4a2713aSLionel Sambuc init(isForwardRef, isImplementation);
119f4a2713aSLionel Sambuc }
ObjCContainerDeclInfoObjCContainerDeclInfo120f4a2713aSLionel Sambuc ObjCContainerDeclInfo(DInfoKind K,
121f4a2713aSLionel Sambuc bool isForwardRef,
122f4a2713aSLionel Sambuc bool isRedeclaration,
123f4a2713aSLionel Sambuc bool isImplementation)
124f4a2713aSLionel Sambuc : DeclInfo(K, isRedeclaration, /*isDefinition=*/!isForwardRef,
125f4a2713aSLionel Sambuc /*isContainer=*/!isForwardRef) {
126f4a2713aSLionel Sambuc init(isForwardRef, isImplementation);
127f4a2713aSLionel Sambuc }
128f4a2713aSLionel Sambuc
classofObjCContainerDeclInfo129f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
130f4a2713aSLionel Sambuc return Info_ObjCContainer <= D->Kind && D->Kind <= Info_ObjCCategory;
131f4a2713aSLionel Sambuc }
132f4a2713aSLionel Sambuc
133f4a2713aSLionel Sambuc private:
initObjCContainerDeclInfo134f4a2713aSLionel Sambuc void init(bool isForwardRef, bool isImplementation) {
135f4a2713aSLionel Sambuc if (isForwardRef)
136f4a2713aSLionel Sambuc ObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
137f4a2713aSLionel Sambuc else if (isImplementation)
138f4a2713aSLionel Sambuc ObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
139f4a2713aSLionel Sambuc else
140f4a2713aSLionel Sambuc ObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
141f4a2713aSLionel Sambuc }
142f4a2713aSLionel Sambuc };
143f4a2713aSLionel Sambuc
144f4a2713aSLionel Sambuc struct ObjCInterfaceDeclInfo : public ObjCContainerDeclInfo {
145f4a2713aSLionel Sambuc CXIdxObjCInterfaceDeclInfo ObjCInterDeclInfo;
146f4a2713aSLionel Sambuc CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
147f4a2713aSLionel Sambuc
ObjCInterfaceDeclInfoObjCInterfaceDeclInfo148f4a2713aSLionel Sambuc ObjCInterfaceDeclInfo(const ObjCInterfaceDecl *D)
149f4a2713aSLionel Sambuc : ObjCContainerDeclInfo(Info_ObjCInterface,
150f4a2713aSLionel Sambuc /*isForwardRef=*/false,
151*0a6a1f1dSLionel Sambuc /*isRedeclaration=*/D->getPreviousDecl() != nullptr,
152f4a2713aSLionel Sambuc /*isImplementation=*/false) { }
153f4a2713aSLionel Sambuc
classofObjCInterfaceDeclInfo154f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
155f4a2713aSLionel Sambuc return D->Kind == Info_ObjCInterface;
156f4a2713aSLionel Sambuc }
157f4a2713aSLionel Sambuc };
158f4a2713aSLionel Sambuc
159f4a2713aSLionel Sambuc struct ObjCProtocolDeclInfo : public ObjCContainerDeclInfo {
160f4a2713aSLionel Sambuc CXIdxObjCProtocolRefListInfo ObjCProtoRefListInfo;
161f4a2713aSLionel Sambuc
ObjCProtocolDeclInfoObjCProtocolDeclInfo162f4a2713aSLionel Sambuc ObjCProtocolDeclInfo(const ObjCProtocolDecl *D)
163f4a2713aSLionel Sambuc : ObjCContainerDeclInfo(Info_ObjCProtocol,
164f4a2713aSLionel Sambuc /*isForwardRef=*/false,
165f4a2713aSLionel Sambuc /*isRedeclaration=*/D->getPreviousDecl(),
166f4a2713aSLionel Sambuc /*isImplementation=*/false) { }
167f4a2713aSLionel Sambuc
classofObjCProtocolDeclInfo168f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
169f4a2713aSLionel Sambuc return D->Kind == Info_ObjCProtocol;
170f4a2713aSLionel Sambuc }
171f4a2713aSLionel Sambuc };
172f4a2713aSLionel Sambuc
173f4a2713aSLionel Sambuc struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
174f4a2713aSLionel Sambuc CXIdxObjCCategoryDeclInfo ObjCCatDeclInfo;
175f4a2713aSLionel Sambuc CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
176f4a2713aSLionel Sambuc
ObjCCategoryDeclInfoObjCCategoryDeclInfo177f4a2713aSLionel Sambuc explicit ObjCCategoryDeclInfo(bool isImplementation)
178f4a2713aSLionel Sambuc : ObjCContainerDeclInfo(Info_ObjCCategory,
179f4a2713aSLionel Sambuc /*isForwardRef=*/false,
180f4a2713aSLionel Sambuc /*isRedeclaration=*/isImplementation,
181f4a2713aSLionel Sambuc /*isImplementation=*/isImplementation) { }
182f4a2713aSLionel Sambuc
classofObjCCategoryDeclInfo183f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
184f4a2713aSLionel Sambuc return D->Kind == Info_ObjCCategory;
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc };
187f4a2713aSLionel Sambuc
188f4a2713aSLionel Sambuc struct ObjCPropertyDeclInfo : public DeclInfo {
189f4a2713aSLionel Sambuc CXIdxObjCPropertyDeclInfo ObjCPropDeclInfo;
190f4a2713aSLionel Sambuc
ObjCPropertyDeclInfoObjCPropertyDeclInfo191f4a2713aSLionel Sambuc ObjCPropertyDeclInfo()
192f4a2713aSLionel Sambuc : DeclInfo(Info_ObjCProperty,
193f4a2713aSLionel Sambuc /*isRedeclaration=*/false, /*isDefinition=*/false,
194f4a2713aSLionel Sambuc /*isContainer=*/false) { }
195f4a2713aSLionel Sambuc
classofObjCPropertyDeclInfo196f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
197f4a2713aSLionel Sambuc return D->Kind == Info_ObjCProperty;
198f4a2713aSLionel Sambuc }
199f4a2713aSLionel Sambuc };
200f4a2713aSLionel Sambuc
201f4a2713aSLionel Sambuc struct CXXClassDeclInfo : public DeclInfo {
202f4a2713aSLionel Sambuc CXIdxCXXClassDeclInfo CXXClassInfo;
203f4a2713aSLionel Sambuc
CXXClassDeclInfoCXXClassDeclInfo204f4a2713aSLionel Sambuc CXXClassDeclInfo(bool isRedeclaration, bool isDefinition)
205f4a2713aSLionel Sambuc : DeclInfo(Info_CXXClass, isRedeclaration, isDefinition, isDefinition) { }
206f4a2713aSLionel Sambuc
classofCXXClassDeclInfo207f4a2713aSLionel Sambuc static bool classof(const DeclInfo *D) {
208f4a2713aSLionel Sambuc return D->Kind == Info_CXXClass;
209f4a2713aSLionel Sambuc }
210f4a2713aSLionel Sambuc };
211f4a2713aSLionel Sambuc
212f4a2713aSLionel Sambuc struct AttrInfo : public CXIdxAttrInfo {
213f4a2713aSLionel Sambuc const Attr *A;
214f4a2713aSLionel Sambuc
AttrInfoAttrInfo215f4a2713aSLionel Sambuc AttrInfo(CXIdxAttrKind Kind, CXCursor C, CXIdxLoc Loc, const Attr *A) {
216f4a2713aSLionel Sambuc kind = Kind;
217f4a2713aSLionel Sambuc cursor = C;
218f4a2713aSLionel Sambuc loc = Loc;
219f4a2713aSLionel Sambuc this->A = A;
220f4a2713aSLionel Sambuc }
221f4a2713aSLionel Sambuc };
222f4a2713aSLionel Sambuc
223f4a2713aSLionel Sambuc struct IBOutletCollectionInfo : public AttrInfo {
224f4a2713aSLionel Sambuc EntityInfo ClassInfo;
225f4a2713aSLionel Sambuc CXIdxIBOutletCollectionAttrInfo IBCollInfo;
226f4a2713aSLionel Sambuc
IBOutletCollectionInfoIBOutletCollectionInfo227f4a2713aSLionel Sambuc IBOutletCollectionInfo(CXCursor C, CXIdxLoc Loc, const Attr *A) :
228f4a2713aSLionel Sambuc AttrInfo(CXIdxAttr_IBOutletCollection, C, Loc, A) {
229f4a2713aSLionel Sambuc assert(C.kind == CXCursor_IBOutletCollectionAttr);
230*0a6a1f1dSLionel Sambuc IBCollInfo.objcClass = nullptr;
231f4a2713aSLionel Sambuc }
232f4a2713aSLionel Sambuc
233f4a2713aSLionel Sambuc IBOutletCollectionInfo(const IBOutletCollectionInfo &other);
234f4a2713aSLionel Sambuc
classofIBOutletCollectionInfo235f4a2713aSLionel Sambuc static bool classof(const AttrInfo *A) {
236f4a2713aSLionel Sambuc return A->kind == CXIdxAttr_IBOutletCollection;
237f4a2713aSLionel Sambuc }
238f4a2713aSLionel Sambuc };
239f4a2713aSLionel Sambuc
240f4a2713aSLionel Sambuc class AttrListInfo {
241f4a2713aSLionel Sambuc ScratchAlloc SA;
242f4a2713aSLionel Sambuc
243f4a2713aSLionel Sambuc SmallVector<AttrInfo, 2> Attrs;
244f4a2713aSLionel Sambuc SmallVector<IBOutletCollectionInfo, 2> IBCollAttrs;
245f4a2713aSLionel Sambuc SmallVector<CXIdxAttrInfo *, 2> CXAttrs;
246f4a2713aSLionel Sambuc unsigned ref_cnt;
247f4a2713aSLionel Sambuc
248f4a2713aSLionel Sambuc AttrListInfo(const AttrListInfo &) LLVM_DELETED_FUNCTION;
249f4a2713aSLionel Sambuc void operator=(const AttrListInfo &) LLVM_DELETED_FUNCTION;
250f4a2713aSLionel Sambuc public:
251f4a2713aSLionel Sambuc AttrListInfo(const Decl *D, IndexingContext &IdxCtx);
252f4a2713aSLionel Sambuc
253f4a2713aSLionel Sambuc static IntrusiveRefCntPtr<AttrListInfo> create(const Decl *D,
254f4a2713aSLionel Sambuc IndexingContext &IdxCtx);
255f4a2713aSLionel Sambuc
getAttrs()256f4a2713aSLionel Sambuc const CXIdxAttrInfo *const *getAttrs() const {
257f4a2713aSLionel Sambuc if (CXAttrs.empty())
258*0a6a1f1dSLionel Sambuc return nullptr;
259f4a2713aSLionel Sambuc return CXAttrs.data();
260f4a2713aSLionel Sambuc }
getNumAttrs()261f4a2713aSLionel Sambuc unsigned getNumAttrs() const { return (unsigned)CXAttrs.size(); }
262f4a2713aSLionel Sambuc
263f4a2713aSLionel Sambuc /// \brief Retain/Release only useful when we allocate a AttrListInfo from the
264f4a2713aSLionel Sambuc /// BumpPtrAllocator, and not from the stack; so that we keep a pointer
265f4a2713aSLionel Sambuc // in the EntityInfo
Retain()266f4a2713aSLionel Sambuc void Retain() { ++ref_cnt; }
Release()267f4a2713aSLionel Sambuc void Release() {
268f4a2713aSLionel Sambuc assert (ref_cnt > 0 && "Reference count is already zero.");
269f4a2713aSLionel Sambuc if (--ref_cnt == 0) {
270f4a2713aSLionel Sambuc // Memory is allocated from a BumpPtrAllocator, no need to delete it.
271f4a2713aSLionel Sambuc this->~AttrListInfo();
272f4a2713aSLionel Sambuc }
273f4a2713aSLionel Sambuc }
274f4a2713aSLionel Sambuc };
275f4a2713aSLionel Sambuc
276f4a2713aSLionel Sambuc class IndexingContext {
277f4a2713aSLionel Sambuc ASTContext *Ctx;
278f4a2713aSLionel Sambuc CXClientData ClientData;
279f4a2713aSLionel Sambuc IndexerCallbacks &CB;
280f4a2713aSLionel Sambuc unsigned IndexOptions;
281f4a2713aSLionel Sambuc CXTranslationUnit CXTU;
282f4a2713aSLionel Sambuc
283f4a2713aSLionel Sambuc typedef llvm::DenseMap<const FileEntry *, CXIdxClientFile> FileMapTy;
284f4a2713aSLionel Sambuc typedef llvm::DenseMap<const DeclContext *, CXIdxClientContainer>
285f4a2713aSLionel Sambuc ContainerMapTy;
286f4a2713aSLionel Sambuc typedef llvm::DenseMap<const Decl *, CXIdxClientEntity> EntityMapTy;
287f4a2713aSLionel Sambuc
288f4a2713aSLionel Sambuc FileMapTy FileMap;
289f4a2713aSLionel Sambuc ContainerMapTy ContainerMap;
290f4a2713aSLionel Sambuc EntityMapTy EntityMap;
291f4a2713aSLionel Sambuc
292*0a6a1f1dSLionel Sambuc typedef std::pair<const FileEntry *, const Decl *> RefFileOccurrence;
293*0a6a1f1dSLionel Sambuc llvm::DenseSet<RefFileOccurrence> RefFileOccurrences;
294f4a2713aSLionel Sambuc
295f4a2713aSLionel Sambuc std::deque<DeclGroupRef> TUDeclsInObjCContainer;
296f4a2713aSLionel Sambuc
297f4a2713aSLionel Sambuc llvm::BumpPtrAllocator StrScratch;
298f4a2713aSLionel Sambuc unsigned StrAdapterCount;
299f4a2713aSLionel Sambuc friend class ScratchAlloc;
300f4a2713aSLionel Sambuc
301f4a2713aSLionel Sambuc struct ObjCProtocolListInfo {
302f4a2713aSLionel Sambuc SmallVector<CXIdxObjCProtocolRefInfo, 4> ProtInfos;
303f4a2713aSLionel Sambuc SmallVector<EntityInfo, 4> ProtEntities;
304f4a2713aSLionel Sambuc SmallVector<CXIdxObjCProtocolRefInfo *, 4> Prots;
305f4a2713aSLionel Sambuc
getListInfoObjCProtocolListInfo306f4a2713aSLionel Sambuc CXIdxObjCProtocolRefListInfo getListInfo() const {
307f4a2713aSLionel Sambuc CXIdxObjCProtocolRefListInfo Info = { Prots.data(),
308f4a2713aSLionel Sambuc (unsigned)Prots.size() };
309f4a2713aSLionel Sambuc return Info;
310f4a2713aSLionel Sambuc }
311f4a2713aSLionel Sambuc
312f4a2713aSLionel Sambuc ObjCProtocolListInfo(const ObjCProtocolList &ProtList,
313f4a2713aSLionel Sambuc IndexingContext &IdxCtx,
314f4a2713aSLionel Sambuc ScratchAlloc &SA);
315f4a2713aSLionel Sambuc };
316f4a2713aSLionel Sambuc
317f4a2713aSLionel Sambuc struct CXXBasesListInfo {
318f4a2713aSLionel Sambuc SmallVector<CXIdxBaseClassInfo, 4> BaseInfos;
319f4a2713aSLionel Sambuc SmallVector<EntityInfo, 4> BaseEntities;
320f4a2713aSLionel Sambuc SmallVector<CXIdxBaseClassInfo *, 4> CXBases;
321f4a2713aSLionel Sambuc
getBasesCXXBasesListInfo322f4a2713aSLionel Sambuc const CXIdxBaseClassInfo *const *getBases() const {
323f4a2713aSLionel Sambuc return CXBases.data();
324f4a2713aSLionel Sambuc }
getNumBasesCXXBasesListInfo325f4a2713aSLionel Sambuc unsigned getNumBases() const { return (unsigned)CXBases.size(); }
326f4a2713aSLionel Sambuc
327f4a2713aSLionel Sambuc CXXBasesListInfo(const CXXRecordDecl *D,
328f4a2713aSLionel Sambuc IndexingContext &IdxCtx, ScratchAlloc &SA);
329f4a2713aSLionel Sambuc
330f4a2713aSLionel Sambuc private:
331f4a2713aSLionel Sambuc SourceLocation getBaseLoc(const CXXBaseSpecifier &Base) const;
332f4a2713aSLionel Sambuc };
333f4a2713aSLionel Sambuc
334f4a2713aSLionel Sambuc friend class AttrListInfo;
335f4a2713aSLionel Sambuc
336f4a2713aSLionel Sambuc public:
IndexingContext(CXClientData clientData,IndexerCallbacks & indexCallbacks,unsigned indexOptions,CXTranslationUnit cxTU)337f4a2713aSLionel Sambuc IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks,
338f4a2713aSLionel Sambuc unsigned indexOptions, CXTranslationUnit cxTU)
339*0a6a1f1dSLionel Sambuc : Ctx(nullptr), ClientData(clientData), CB(indexCallbacks),
340f4a2713aSLionel Sambuc IndexOptions(indexOptions), CXTU(cxTU),
341*0a6a1f1dSLionel Sambuc StrScratch(), StrAdapterCount(0) { }
342f4a2713aSLionel Sambuc
getASTContext()343f4a2713aSLionel Sambuc ASTContext &getASTContext() const { return *Ctx; }
344f4a2713aSLionel Sambuc
345f4a2713aSLionel Sambuc void setASTContext(ASTContext &ctx);
346f4a2713aSLionel Sambuc void setPreprocessor(Preprocessor &PP);
347f4a2713aSLionel Sambuc
shouldSuppressRefs()348f4a2713aSLionel Sambuc bool shouldSuppressRefs() const {
349f4a2713aSLionel Sambuc return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
350f4a2713aSLionel Sambuc }
351f4a2713aSLionel Sambuc
shouldIndexFunctionLocalSymbols()352f4a2713aSLionel Sambuc bool shouldIndexFunctionLocalSymbols() const {
353f4a2713aSLionel Sambuc return IndexOptions & CXIndexOpt_IndexFunctionLocalSymbols;
354f4a2713aSLionel Sambuc }
355f4a2713aSLionel Sambuc
shouldIndexImplicitTemplateInsts()356f4a2713aSLionel Sambuc bool shouldIndexImplicitTemplateInsts() const {
357f4a2713aSLionel Sambuc return IndexOptions & CXIndexOpt_IndexImplicitTemplateInstantiations;
358f4a2713aSLionel Sambuc }
359f4a2713aSLionel Sambuc
360f4a2713aSLionel Sambuc static bool isFunctionLocalDecl(const Decl *D);
361f4a2713aSLionel Sambuc
362f4a2713aSLionel Sambuc bool shouldAbort();
363f4a2713aSLionel Sambuc
hasDiagnosticCallback()364f4a2713aSLionel Sambuc bool hasDiagnosticCallback() const { return CB.diagnostic; }
365f4a2713aSLionel Sambuc
366f4a2713aSLionel Sambuc void enteredMainFile(const FileEntry *File);
367f4a2713aSLionel Sambuc
368f4a2713aSLionel Sambuc void ppIncludedFile(SourceLocation hashLoc,
369f4a2713aSLionel Sambuc StringRef filename, const FileEntry *File,
370f4a2713aSLionel Sambuc bool isImport, bool isAngled, bool isModuleImport);
371f4a2713aSLionel Sambuc
372f4a2713aSLionel Sambuc void importedModule(const ImportDecl *ImportD);
373f4a2713aSLionel Sambuc void importedPCH(const FileEntry *File);
374f4a2713aSLionel Sambuc
375f4a2713aSLionel Sambuc void startedTranslationUnit();
376f4a2713aSLionel Sambuc
377f4a2713aSLionel Sambuc void indexDecl(const Decl *D);
378f4a2713aSLionel Sambuc
379f4a2713aSLionel Sambuc void indexTagDecl(const TagDecl *D);
380f4a2713aSLionel Sambuc
381f4a2713aSLionel Sambuc void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
382*0a6a1f1dSLionel Sambuc const DeclContext *DC = nullptr);
383f4a2713aSLionel Sambuc
384f4a2713aSLionel Sambuc void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
385*0a6a1f1dSLionel Sambuc const DeclContext *DC = nullptr);
386f4a2713aSLionel Sambuc
387f4a2713aSLionel Sambuc void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
388f4a2713aSLionel Sambuc const NamedDecl *Parent,
389*0a6a1f1dSLionel Sambuc const DeclContext *DC = nullptr);
390f4a2713aSLionel Sambuc
391f4a2713aSLionel Sambuc void indexDeclContext(const DeclContext *DC);
392f4a2713aSLionel Sambuc
393f4a2713aSLionel Sambuc void indexBody(const Stmt *S, const NamedDecl *Parent,
394*0a6a1f1dSLionel Sambuc const DeclContext *DC = nullptr);
395f4a2713aSLionel Sambuc
396f4a2713aSLionel Sambuc void handleDiagnosticSet(CXDiagnosticSet CXDiagSet);
397f4a2713aSLionel Sambuc
398f4a2713aSLionel Sambuc bool handleFunction(const FunctionDecl *FD);
399f4a2713aSLionel Sambuc
400f4a2713aSLionel Sambuc bool handleVar(const VarDecl *D);
401f4a2713aSLionel Sambuc
402f4a2713aSLionel Sambuc bool handleField(const FieldDecl *D);
403f4a2713aSLionel Sambuc
404f4a2713aSLionel Sambuc bool handleMSProperty(const MSPropertyDecl *D);
405f4a2713aSLionel Sambuc
406f4a2713aSLionel Sambuc bool handleEnumerator(const EnumConstantDecl *D);
407f4a2713aSLionel Sambuc
408f4a2713aSLionel Sambuc bool handleTagDecl(const TagDecl *D);
409f4a2713aSLionel Sambuc
410f4a2713aSLionel Sambuc bool handleTypedefName(const TypedefNameDecl *D);
411f4a2713aSLionel Sambuc
412f4a2713aSLionel Sambuc bool handleObjCInterface(const ObjCInterfaceDecl *D);
413f4a2713aSLionel Sambuc bool handleObjCImplementation(const ObjCImplementationDecl *D);
414f4a2713aSLionel Sambuc
415f4a2713aSLionel Sambuc bool handleObjCProtocol(const ObjCProtocolDecl *D);
416f4a2713aSLionel Sambuc
417f4a2713aSLionel Sambuc bool handleObjCCategory(const ObjCCategoryDecl *D);
418f4a2713aSLionel Sambuc bool handleObjCCategoryImpl(const ObjCCategoryImplDecl *D);
419f4a2713aSLionel Sambuc
420f4a2713aSLionel Sambuc bool handleObjCMethod(const ObjCMethodDecl *D);
421f4a2713aSLionel Sambuc
422f4a2713aSLionel Sambuc bool handleSynthesizedObjCProperty(const ObjCPropertyImplDecl *D);
423f4a2713aSLionel Sambuc bool handleSynthesizedObjCMethod(const ObjCMethodDecl *D, SourceLocation Loc,
424f4a2713aSLionel Sambuc const DeclContext *LexicalDC);
425f4a2713aSLionel Sambuc
426f4a2713aSLionel Sambuc bool handleObjCProperty(const ObjCPropertyDecl *D);
427f4a2713aSLionel Sambuc
428f4a2713aSLionel Sambuc bool handleNamespace(const NamespaceDecl *D);
429f4a2713aSLionel Sambuc
430f4a2713aSLionel Sambuc bool handleClassTemplate(const ClassTemplateDecl *D);
431f4a2713aSLionel Sambuc bool handleFunctionTemplate(const FunctionTemplateDecl *D);
432f4a2713aSLionel Sambuc bool handleTypeAliasTemplate(const TypeAliasTemplateDecl *D);
433f4a2713aSLionel Sambuc
434f4a2713aSLionel Sambuc bool handleReference(const NamedDecl *D, SourceLocation Loc, CXCursor Cursor,
435f4a2713aSLionel Sambuc const NamedDecl *Parent,
436f4a2713aSLionel Sambuc const DeclContext *DC,
437*0a6a1f1dSLionel Sambuc const Expr *E = nullptr,
438f4a2713aSLionel Sambuc CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
439f4a2713aSLionel Sambuc
440f4a2713aSLionel Sambuc bool handleReference(const NamedDecl *D, SourceLocation Loc,
441f4a2713aSLionel Sambuc const NamedDecl *Parent,
442f4a2713aSLionel Sambuc const DeclContext *DC,
443*0a6a1f1dSLionel Sambuc const Expr *E = nullptr,
444f4a2713aSLionel Sambuc CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
445f4a2713aSLionel Sambuc
446f4a2713aSLionel Sambuc bool isNotFromSourceFile(SourceLocation Loc) const;
447f4a2713aSLionel Sambuc
448f4a2713aSLionel Sambuc void indexTopLevelDecl(const Decl *D);
449f4a2713aSLionel Sambuc void indexTUDeclsInObjCContainer();
450f4a2713aSLionel Sambuc void indexDeclGroupRef(DeclGroupRef DG);
451f4a2713aSLionel Sambuc
addTUDeclInObjCContainer(DeclGroupRef DG)452f4a2713aSLionel Sambuc void addTUDeclInObjCContainer(DeclGroupRef DG) {
453f4a2713aSLionel Sambuc TUDeclsInObjCContainer.push_back(DG);
454f4a2713aSLionel Sambuc }
455f4a2713aSLionel Sambuc
456f4a2713aSLionel Sambuc void translateLoc(SourceLocation Loc, CXIdxClientFile *indexFile, CXFile *file,
457f4a2713aSLionel Sambuc unsigned *line, unsigned *column, unsigned *offset);
458f4a2713aSLionel Sambuc
459f4a2713aSLionel Sambuc CXIdxClientContainer getClientContainerForDC(const DeclContext *DC) const;
460f4a2713aSLionel Sambuc void addContainerInMap(const DeclContext *DC, CXIdxClientContainer container);
461f4a2713aSLionel Sambuc
462f4a2713aSLionel Sambuc CXIdxClientEntity getClientEntity(const Decl *D) const;
463f4a2713aSLionel Sambuc void setClientEntity(const Decl *D, CXIdxClientEntity client);
464f4a2713aSLionel Sambuc
465f4a2713aSLionel Sambuc static bool isTemplateImplicitInstantiation(const Decl *D);
466f4a2713aSLionel Sambuc
467f4a2713aSLionel Sambuc private:
468f4a2713aSLionel Sambuc bool handleDecl(const NamedDecl *D,
469f4a2713aSLionel Sambuc SourceLocation Loc, CXCursor Cursor,
470f4a2713aSLionel Sambuc DeclInfo &DInfo,
471*0a6a1f1dSLionel Sambuc const DeclContext *LexicalDC = nullptr);
472f4a2713aSLionel Sambuc
473f4a2713aSLionel Sambuc bool handleObjCContainer(const ObjCContainerDecl *D,
474f4a2713aSLionel Sambuc SourceLocation Loc, CXCursor Cursor,
475f4a2713aSLionel Sambuc ObjCContainerDeclInfo &ContDInfo);
476f4a2713aSLionel Sambuc
477f4a2713aSLionel Sambuc bool handleCXXRecordDecl(const CXXRecordDecl *RD, const NamedDecl *OrigD);
478f4a2713aSLionel Sambuc
479f4a2713aSLionel Sambuc bool markEntityOccurrenceInFile(const NamedDecl *D, SourceLocation Loc);
480f4a2713aSLionel Sambuc
481f4a2713aSLionel Sambuc const NamedDecl *getEntityDecl(const NamedDecl *D) const;
482f4a2713aSLionel Sambuc
483f4a2713aSLionel Sambuc const DeclContext *getEntityContainer(const Decl *D) const;
484f4a2713aSLionel Sambuc
485f4a2713aSLionel Sambuc CXIdxClientFile getIndexFile(const FileEntry *File);
486f4a2713aSLionel Sambuc
487f4a2713aSLionel Sambuc CXIdxLoc getIndexLoc(SourceLocation Loc) const;
488f4a2713aSLionel Sambuc
489f4a2713aSLionel Sambuc void getEntityInfo(const NamedDecl *D,
490f4a2713aSLionel Sambuc EntityInfo &EntityInfo,
491f4a2713aSLionel Sambuc ScratchAlloc &SA);
492f4a2713aSLionel Sambuc
493f4a2713aSLionel Sambuc void getContainerInfo(const DeclContext *DC, ContainerInfo &ContInfo);
494f4a2713aSLionel Sambuc
getCursor(const Decl * D)495f4a2713aSLionel Sambuc CXCursor getCursor(const Decl *D) {
496f4a2713aSLionel Sambuc return cxcursor::MakeCXCursor(D, CXTU);
497f4a2713aSLionel Sambuc }
498f4a2713aSLionel Sambuc
499f4a2713aSLionel Sambuc CXCursor getRefCursor(const NamedDecl *D, SourceLocation Loc);
500f4a2713aSLionel Sambuc
501f4a2713aSLionel Sambuc static bool shouldIgnoreIfImplicit(const Decl *D);
502f4a2713aSLionel Sambuc };
503f4a2713aSLionel Sambuc
ScratchAlloc(IndexingContext & idxCtx)504f4a2713aSLionel Sambuc inline ScratchAlloc::ScratchAlloc(IndexingContext &idxCtx) : IdxCtx(idxCtx) {
505f4a2713aSLionel Sambuc ++IdxCtx.StrAdapterCount;
506f4a2713aSLionel Sambuc }
ScratchAlloc(const ScratchAlloc & SA)507f4a2713aSLionel Sambuc inline ScratchAlloc::ScratchAlloc(const ScratchAlloc &SA) : IdxCtx(SA.IdxCtx) {
508f4a2713aSLionel Sambuc ++IdxCtx.StrAdapterCount;
509f4a2713aSLionel Sambuc }
510f4a2713aSLionel Sambuc
~ScratchAlloc()511f4a2713aSLionel Sambuc inline ScratchAlloc::~ScratchAlloc() {
512f4a2713aSLionel Sambuc --IdxCtx.StrAdapterCount;
513f4a2713aSLionel Sambuc if (IdxCtx.StrAdapterCount == 0)
514f4a2713aSLionel Sambuc IdxCtx.StrScratch.Reset();
515f4a2713aSLionel Sambuc }
516f4a2713aSLionel Sambuc
517f4a2713aSLionel Sambuc template <typename T>
allocate()518f4a2713aSLionel Sambuc inline T *ScratchAlloc::allocate() {
519f4a2713aSLionel Sambuc return IdxCtx.StrScratch.Allocate<T>();
520f4a2713aSLionel Sambuc }
521f4a2713aSLionel Sambuc
522f4a2713aSLionel Sambuc }} // end clang::cxindex
523*0a6a1f1dSLionel Sambuc
524*0a6a1f1dSLionel Sambuc #endif
525