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