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