1f4a2713aSLionel Sambuc //===- CIndexHigh.cpp - Higher level API functions ------------------------===//
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
10f4a2713aSLionel Sambuc #include "IndexingContext.h"
11f4a2713aSLionel Sambuc #include "clang/AST/DeclVisitor.h"
12f4a2713aSLionel Sambuc
13f4a2713aSLionel Sambuc using namespace clang;
14f4a2713aSLionel Sambuc using namespace cxindex;
15f4a2713aSLionel Sambuc
16f4a2713aSLionel Sambuc namespace {
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
19f4a2713aSLionel Sambuc IndexingContext &IndexCtx;
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc public:
IndexingDeclVisitor(IndexingContext & indexCtx)22f4a2713aSLionel Sambuc explicit IndexingDeclVisitor(IndexingContext &indexCtx)
23f4a2713aSLionel Sambuc : IndexCtx(indexCtx) { }
24f4a2713aSLionel Sambuc
25f4a2713aSLionel Sambuc /// \brief Returns true if the given method has been defined explicitly by the
26f4a2713aSLionel Sambuc /// user.
hasUserDefined(const ObjCMethodDecl * D,const ObjCImplDecl * Container)27f4a2713aSLionel Sambuc static bool hasUserDefined(const ObjCMethodDecl *D,
28f4a2713aSLionel Sambuc const ObjCImplDecl *Container) {
29f4a2713aSLionel Sambuc const ObjCMethodDecl *MD = Container->getMethod(D->getSelector(),
30f4a2713aSLionel Sambuc D->isInstanceMethod());
31f4a2713aSLionel Sambuc return MD && !MD->isImplicit() && MD->isThisDeclarationADefinition();
32f4a2713aSLionel Sambuc }
33f4a2713aSLionel Sambuc
handleDeclarator(const DeclaratorDecl * D,const NamedDecl * Parent=nullptr)34*0a6a1f1dSLionel Sambuc void handleDeclarator(const DeclaratorDecl *D,
35*0a6a1f1dSLionel Sambuc const NamedDecl *Parent = nullptr) {
36f4a2713aSLionel Sambuc if (!Parent) Parent = D;
37f4a2713aSLionel Sambuc
38f4a2713aSLionel Sambuc if (!IndexCtx.shouldIndexFunctionLocalSymbols()) {
39f4a2713aSLionel Sambuc IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent);
40f4a2713aSLionel Sambuc IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
41f4a2713aSLionel Sambuc } else {
42f4a2713aSLionel Sambuc if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
43f4a2713aSLionel Sambuc IndexCtx.handleVar(Parm);
44f4a2713aSLionel Sambuc } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
45*0a6a1f1dSLionel Sambuc for (auto PI : FD->params()) {
46*0a6a1f1dSLionel Sambuc IndexCtx.handleVar(PI);
47f4a2713aSLionel Sambuc }
48f4a2713aSLionel Sambuc }
49f4a2713aSLionel Sambuc }
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc
handleObjCMethod(const ObjCMethodDecl * D)52f4a2713aSLionel Sambuc void handleObjCMethod(const ObjCMethodDecl *D) {
53f4a2713aSLionel Sambuc IndexCtx.handleObjCMethod(D);
54f4a2713aSLionel Sambuc if (D->isImplicit())
55f4a2713aSLionel Sambuc return;
56f4a2713aSLionel Sambuc
57*0a6a1f1dSLionel Sambuc IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D);
58*0a6a1f1dSLionel Sambuc for (const auto *I : D->params())
59*0a6a1f1dSLionel Sambuc handleDeclarator(I, D);
60f4a2713aSLionel Sambuc
61f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition()) {
62f4a2713aSLionel Sambuc const Stmt *Body = D->getBody();
63f4a2713aSLionel Sambuc if (Body) {
64f4a2713aSLionel Sambuc IndexCtx.indexBody(Body, D, D);
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc }
67f4a2713aSLionel Sambuc }
68f4a2713aSLionel Sambuc
VisitFunctionDecl(const FunctionDecl * D)69f4a2713aSLionel Sambuc bool VisitFunctionDecl(const FunctionDecl *D) {
70f4a2713aSLionel Sambuc IndexCtx.handleFunction(D);
71f4a2713aSLionel Sambuc handleDeclarator(D);
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
74f4a2713aSLionel Sambuc // Constructor initializers.
75*0a6a1f1dSLionel Sambuc for (const auto *Init : Ctor->inits()) {
76f4a2713aSLionel Sambuc if (Init->isWritten()) {
77f4a2713aSLionel Sambuc IndexCtx.indexTypeSourceInfo(Init->getTypeSourceInfo(), D);
78f4a2713aSLionel Sambuc if (const FieldDecl *Member = Init->getAnyMember())
79f4a2713aSLionel Sambuc IndexCtx.handleReference(Member, Init->getMemberLocation(), D, D);
80f4a2713aSLionel Sambuc IndexCtx.indexBody(Init->getInit(), D, D);
81f4a2713aSLionel Sambuc }
82f4a2713aSLionel Sambuc }
83f4a2713aSLionel Sambuc }
84f4a2713aSLionel Sambuc
85f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition()) {
86f4a2713aSLionel Sambuc const Stmt *Body = D->getBody();
87f4a2713aSLionel Sambuc if (Body) {
88f4a2713aSLionel Sambuc IndexCtx.indexBody(Body, D, D);
89f4a2713aSLionel Sambuc }
90f4a2713aSLionel Sambuc }
91f4a2713aSLionel Sambuc return true;
92f4a2713aSLionel Sambuc }
93f4a2713aSLionel Sambuc
VisitVarDecl(const VarDecl * D)94f4a2713aSLionel Sambuc bool VisitVarDecl(const VarDecl *D) {
95f4a2713aSLionel Sambuc IndexCtx.handleVar(D);
96f4a2713aSLionel Sambuc handleDeclarator(D);
97f4a2713aSLionel Sambuc IndexCtx.indexBody(D->getInit(), D);
98f4a2713aSLionel Sambuc return true;
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc
VisitFieldDecl(const FieldDecl * D)101f4a2713aSLionel Sambuc bool VisitFieldDecl(const FieldDecl *D) {
102f4a2713aSLionel Sambuc IndexCtx.handleField(D);
103f4a2713aSLionel Sambuc handleDeclarator(D);
104f4a2713aSLionel Sambuc if (D->isBitField())
105f4a2713aSLionel Sambuc IndexCtx.indexBody(D->getBitWidth(), D);
106f4a2713aSLionel Sambuc else if (D->hasInClassInitializer())
107f4a2713aSLionel Sambuc IndexCtx.indexBody(D->getInClassInitializer(), D);
108f4a2713aSLionel Sambuc return true;
109f4a2713aSLionel Sambuc }
110f4a2713aSLionel Sambuc
VisitMSPropertyDecl(const MSPropertyDecl * D)111f4a2713aSLionel Sambuc bool VisitMSPropertyDecl(const MSPropertyDecl *D) {
112f4a2713aSLionel Sambuc handleDeclarator(D);
113f4a2713aSLionel Sambuc return true;
114f4a2713aSLionel Sambuc }
115f4a2713aSLionel Sambuc
VisitEnumConstantDecl(const EnumConstantDecl * D)116f4a2713aSLionel Sambuc bool VisitEnumConstantDecl(const EnumConstantDecl *D) {
117f4a2713aSLionel Sambuc IndexCtx.handleEnumerator(D);
118f4a2713aSLionel Sambuc IndexCtx.indexBody(D->getInitExpr(), D);
119f4a2713aSLionel Sambuc return true;
120f4a2713aSLionel Sambuc }
121f4a2713aSLionel Sambuc
VisitTypedefNameDecl(const TypedefNameDecl * D)122f4a2713aSLionel Sambuc bool VisitTypedefNameDecl(const TypedefNameDecl *D) {
123f4a2713aSLionel Sambuc IndexCtx.handleTypedefName(D);
124f4a2713aSLionel Sambuc IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
125f4a2713aSLionel Sambuc return true;
126f4a2713aSLionel Sambuc }
127f4a2713aSLionel Sambuc
VisitTagDecl(const TagDecl * D)128f4a2713aSLionel Sambuc bool VisitTagDecl(const TagDecl *D) {
129f4a2713aSLionel Sambuc // Non-free standing tags are handled in indexTypeSourceInfo.
130f4a2713aSLionel Sambuc if (D->isFreeStanding())
131f4a2713aSLionel Sambuc IndexCtx.indexTagDecl(D);
132f4a2713aSLionel Sambuc return true;
133f4a2713aSLionel Sambuc }
134f4a2713aSLionel Sambuc
VisitObjCInterfaceDecl(const ObjCInterfaceDecl * D)135f4a2713aSLionel Sambuc bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
136f4a2713aSLionel Sambuc IndexCtx.handleObjCInterface(D);
137f4a2713aSLionel Sambuc
138f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition()) {
139f4a2713aSLionel Sambuc IndexCtx.indexTUDeclsInObjCContainer();
140f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D);
141f4a2713aSLionel Sambuc }
142f4a2713aSLionel Sambuc return true;
143f4a2713aSLionel Sambuc }
144f4a2713aSLionel Sambuc
VisitObjCProtocolDecl(const ObjCProtocolDecl * D)145f4a2713aSLionel Sambuc bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
146f4a2713aSLionel Sambuc IndexCtx.handleObjCProtocol(D);
147f4a2713aSLionel Sambuc
148f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition()) {
149f4a2713aSLionel Sambuc IndexCtx.indexTUDeclsInObjCContainer();
150f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D);
151f4a2713aSLionel Sambuc }
152f4a2713aSLionel Sambuc return true;
153f4a2713aSLionel Sambuc }
154f4a2713aSLionel Sambuc
VisitObjCImplementationDecl(const ObjCImplementationDecl * D)155f4a2713aSLionel Sambuc bool VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
156f4a2713aSLionel Sambuc const ObjCInterfaceDecl *Class = D->getClassInterface();
157f4a2713aSLionel Sambuc if (!Class)
158f4a2713aSLionel Sambuc return true;
159f4a2713aSLionel Sambuc
160f4a2713aSLionel Sambuc if (Class->isImplicitInterfaceDecl())
161f4a2713aSLionel Sambuc IndexCtx.handleObjCInterface(Class);
162f4a2713aSLionel Sambuc
163f4a2713aSLionel Sambuc IndexCtx.handleObjCImplementation(D);
164f4a2713aSLionel Sambuc
165f4a2713aSLionel Sambuc IndexCtx.indexTUDeclsInObjCContainer();
166f4a2713aSLionel Sambuc
167f4a2713aSLionel Sambuc // Index the ivars first to make sure the synthesized ivars are indexed
168f4a2713aSLionel Sambuc // before indexing the methods that can reference them.
169*0a6a1f1dSLionel Sambuc for (const auto *IvarI : D->ivars())
170*0a6a1f1dSLionel Sambuc IndexCtx.indexDecl(IvarI);
171*0a6a1f1dSLionel Sambuc for (const auto *I : D->decls()) {
172*0a6a1f1dSLionel Sambuc if (!isa<ObjCIvarDecl>(I))
173*0a6a1f1dSLionel Sambuc IndexCtx.indexDecl(I);
174f4a2713aSLionel Sambuc }
175f4a2713aSLionel Sambuc
176f4a2713aSLionel Sambuc return true;
177f4a2713aSLionel Sambuc }
178f4a2713aSLionel Sambuc
VisitObjCCategoryDecl(const ObjCCategoryDecl * D)179f4a2713aSLionel Sambuc bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
180f4a2713aSLionel Sambuc IndexCtx.handleObjCCategory(D);
181f4a2713aSLionel Sambuc
182f4a2713aSLionel Sambuc IndexCtx.indexTUDeclsInObjCContainer();
183f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D);
184f4a2713aSLionel Sambuc return true;
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc
VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl * D)187f4a2713aSLionel Sambuc bool VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
188f4a2713aSLionel Sambuc const ObjCCategoryDecl *Cat = D->getCategoryDecl();
189f4a2713aSLionel Sambuc if (!Cat)
190f4a2713aSLionel Sambuc return true;
191f4a2713aSLionel Sambuc
192f4a2713aSLionel Sambuc IndexCtx.handleObjCCategoryImpl(D);
193f4a2713aSLionel Sambuc
194f4a2713aSLionel Sambuc IndexCtx.indexTUDeclsInObjCContainer();
195f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D);
196f4a2713aSLionel Sambuc return true;
197f4a2713aSLionel Sambuc }
198f4a2713aSLionel Sambuc
VisitObjCMethodDecl(const ObjCMethodDecl * D)199f4a2713aSLionel Sambuc bool VisitObjCMethodDecl(const ObjCMethodDecl *D) {
200f4a2713aSLionel Sambuc // Methods associated with a property, even user-declared ones, are
201f4a2713aSLionel Sambuc // handled when we handle the property.
202f4a2713aSLionel Sambuc if (D->isPropertyAccessor())
203f4a2713aSLionel Sambuc return true;
204f4a2713aSLionel Sambuc
205f4a2713aSLionel Sambuc handleObjCMethod(D);
206f4a2713aSLionel Sambuc return true;
207f4a2713aSLionel Sambuc }
208f4a2713aSLionel Sambuc
VisitObjCPropertyDecl(const ObjCPropertyDecl * D)209f4a2713aSLionel Sambuc bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
210f4a2713aSLionel Sambuc if (ObjCMethodDecl *MD = D->getGetterMethodDecl())
211f4a2713aSLionel Sambuc if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
212f4a2713aSLionel Sambuc handleObjCMethod(MD);
213f4a2713aSLionel Sambuc if (ObjCMethodDecl *MD = D->getSetterMethodDecl())
214f4a2713aSLionel Sambuc if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
215f4a2713aSLionel Sambuc handleObjCMethod(MD);
216f4a2713aSLionel Sambuc IndexCtx.handleObjCProperty(D);
217f4a2713aSLionel Sambuc IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
218f4a2713aSLionel Sambuc return true;
219f4a2713aSLionel Sambuc }
220f4a2713aSLionel Sambuc
VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl * D)221f4a2713aSLionel Sambuc bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
222f4a2713aSLionel Sambuc ObjCPropertyDecl *PD = D->getPropertyDecl();
223f4a2713aSLionel Sambuc IndexCtx.handleSynthesizedObjCProperty(D);
224f4a2713aSLionel Sambuc
225f4a2713aSLionel Sambuc if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
226f4a2713aSLionel Sambuc return true;
227f4a2713aSLionel Sambuc assert(D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize);
228f4a2713aSLionel Sambuc
229f4a2713aSLionel Sambuc if (ObjCIvarDecl *IvarD = D->getPropertyIvarDecl()) {
230f4a2713aSLionel Sambuc if (!IvarD->getSynthesize())
231*0a6a1f1dSLionel Sambuc IndexCtx.handleReference(IvarD, D->getPropertyIvarDeclLoc(), nullptr,
232f4a2713aSLionel Sambuc D->getDeclContext());
233f4a2713aSLionel Sambuc }
234f4a2713aSLionel Sambuc
235f4a2713aSLionel Sambuc if (ObjCMethodDecl *MD = PD->getGetterMethodDecl()) {
236f4a2713aSLionel Sambuc if (MD->isPropertyAccessor() &&
237f4a2713aSLionel Sambuc !hasUserDefined(MD, cast<ObjCImplDecl>(D->getDeclContext())))
238f4a2713aSLionel Sambuc IndexCtx.handleSynthesizedObjCMethod(MD, D->getLocation(),
239f4a2713aSLionel Sambuc D->getLexicalDeclContext());
240f4a2713aSLionel Sambuc }
241f4a2713aSLionel Sambuc if (ObjCMethodDecl *MD = PD->getSetterMethodDecl()) {
242f4a2713aSLionel Sambuc if (MD->isPropertyAccessor() &&
243f4a2713aSLionel Sambuc !hasUserDefined(MD, cast<ObjCImplDecl>(D->getDeclContext())))
244f4a2713aSLionel Sambuc IndexCtx.handleSynthesizedObjCMethod(MD, D->getLocation(),
245f4a2713aSLionel Sambuc D->getLexicalDeclContext());
246f4a2713aSLionel Sambuc }
247f4a2713aSLionel Sambuc return true;
248f4a2713aSLionel Sambuc }
249f4a2713aSLionel Sambuc
VisitNamespaceDecl(const NamespaceDecl * D)250f4a2713aSLionel Sambuc bool VisitNamespaceDecl(const NamespaceDecl *D) {
251f4a2713aSLionel Sambuc IndexCtx.handleNamespace(D);
252f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D);
253f4a2713aSLionel Sambuc return true;
254f4a2713aSLionel Sambuc }
255f4a2713aSLionel Sambuc
VisitUsingDecl(const UsingDecl * D)256f4a2713aSLionel Sambuc bool VisitUsingDecl(const UsingDecl *D) {
257f4a2713aSLionel Sambuc // FIXME: Parent for the following is CXIdxEntity_Unexposed with no USR,
258f4a2713aSLionel Sambuc // we should do better.
259f4a2713aSLionel Sambuc
260f4a2713aSLionel Sambuc IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
261*0a6a1f1dSLionel Sambuc for (const auto *I : D->shadows())
262*0a6a1f1dSLionel Sambuc IndexCtx.handleReference(I->getUnderlyingDecl(), D->getLocation(), D,
263*0a6a1f1dSLionel Sambuc D->getLexicalDeclContext());
264f4a2713aSLionel Sambuc return true;
265f4a2713aSLionel Sambuc }
266f4a2713aSLionel Sambuc
VisitUsingDirectiveDecl(const UsingDirectiveDecl * D)267f4a2713aSLionel Sambuc bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
268f4a2713aSLionel Sambuc // FIXME: Parent for the following is CXIdxEntity_Unexposed with no USR,
269f4a2713aSLionel Sambuc // we should do better.
270f4a2713aSLionel Sambuc
271f4a2713aSLionel Sambuc IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
272f4a2713aSLionel Sambuc IndexCtx.handleReference(D->getNominatedNamespaceAsWritten(),
273f4a2713aSLionel Sambuc D->getLocation(), D, D->getLexicalDeclContext());
274f4a2713aSLionel Sambuc return true;
275f4a2713aSLionel Sambuc }
276f4a2713aSLionel Sambuc
VisitClassTemplateDecl(const ClassTemplateDecl * D)277f4a2713aSLionel Sambuc bool VisitClassTemplateDecl(const ClassTemplateDecl *D) {
278f4a2713aSLionel Sambuc IndexCtx.handleClassTemplate(D);
279f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition())
280f4a2713aSLionel Sambuc IndexCtx.indexDeclContext(D->getTemplatedDecl());
281f4a2713aSLionel Sambuc return true;
282f4a2713aSLionel Sambuc }
283f4a2713aSLionel Sambuc
VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl * D)284f4a2713aSLionel Sambuc bool VisitClassTemplateSpecializationDecl(const
285f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *D) {
286f4a2713aSLionel Sambuc // FIXME: Notify subsequent callbacks if info comes from implicit
287f4a2713aSLionel Sambuc // instantiation.
288f4a2713aSLionel Sambuc if (D->isThisDeclarationADefinition() &&
289f4a2713aSLionel Sambuc (IndexCtx.shouldIndexImplicitTemplateInsts() ||
290f4a2713aSLionel Sambuc !IndexCtx.isTemplateImplicitInstantiation(D)))
291f4a2713aSLionel Sambuc IndexCtx.indexTagDecl(D);
292f4a2713aSLionel Sambuc return true;
293f4a2713aSLionel Sambuc }
294f4a2713aSLionel Sambuc
VisitFunctionTemplateDecl(const FunctionTemplateDecl * D)295f4a2713aSLionel Sambuc bool VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
296f4a2713aSLionel Sambuc IndexCtx.handleFunctionTemplate(D);
297f4a2713aSLionel Sambuc FunctionDecl *FD = D->getTemplatedDecl();
298f4a2713aSLionel Sambuc handleDeclarator(FD, D);
299f4a2713aSLionel Sambuc if (FD->isThisDeclarationADefinition()) {
300f4a2713aSLionel Sambuc const Stmt *Body = FD->getBody();
301f4a2713aSLionel Sambuc if (Body) {
302f4a2713aSLionel Sambuc IndexCtx.indexBody(Body, D, FD);
303f4a2713aSLionel Sambuc }
304f4a2713aSLionel Sambuc }
305f4a2713aSLionel Sambuc return true;
306f4a2713aSLionel Sambuc }
307f4a2713aSLionel Sambuc
VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl * D)308f4a2713aSLionel Sambuc bool VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
309f4a2713aSLionel Sambuc IndexCtx.handleTypeAliasTemplate(D);
310f4a2713aSLionel Sambuc IndexCtx.indexTypeSourceInfo(D->getTemplatedDecl()->getTypeSourceInfo(), D);
311f4a2713aSLionel Sambuc return true;
312f4a2713aSLionel Sambuc }
313f4a2713aSLionel Sambuc
VisitImportDecl(const ImportDecl * D)314f4a2713aSLionel Sambuc bool VisitImportDecl(const ImportDecl *D) {
315f4a2713aSLionel Sambuc IndexCtx.importedModule(D);
316f4a2713aSLionel Sambuc return true;
317f4a2713aSLionel Sambuc }
318f4a2713aSLionel Sambuc };
319f4a2713aSLionel Sambuc
320f4a2713aSLionel Sambuc } // anonymous namespace
321f4a2713aSLionel Sambuc
indexDecl(const Decl * D)322f4a2713aSLionel Sambuc void IndexingContext::indexDecl(const Decl *D) {
323f4a2713aSLionel Sambuc if (D->isImplicit() && shouldIgnoreIfImplicit(D))
324f4a2713aSLionel Sambuc return;
325f4a2713aSLionel Sambuc
326f4a2713aSLionel Sambuc bool Handled = IndexingDeclVisitor(*this).Visit(D);
327f4a2713aSLionel Sambuc if (!Handled && isa<DeclContext>(D))
328f4a2713aSLionel Sambuc indexDeclContext(cast<DeclContext>(D));
329f4a2713aSLionel Sambuc }
330f4a2713aSLionel Sambuc
indexDeclContext(const DeclContext * DC)331f4a2713aSLionel Sambuc void IndexingContext::indexDeclContext(const DeclContext *DC) {
332*0a6a1f1dSLionel Sambuc for (const auto *I : DC->decls())
333*0a6a1f1dSLionel Sambuc indexDecl(I);
334f4a2713aSLionel Sambuc }
335f4a2713aSLionel Sambuc
indexTopLevelDecl(const Decl * D)336f4a2713aSLionel Sambuc void IndexingContext::indexTopLevelDecl(const Decl *D) {
337f4a2713aSLionel Sambuc if (isNotFromSourceFile(D->getLocation()))
338f4a2713aSLionel Sambuc return;
339f4a2713aSLionel Sambuc
340f4a2713aSLionel Sambuc if (isa<ObjCMethodDecl>(D))
341f4a2713aSLionel Sambuc return; // Wait for the objc container.
342f4a2713aSLionel Sambuc
343f4a2713aSLionel Sambuc indexDecl(D);
344f4a2713aSLionel Sambuc }
345f4a2713aSLionel Sambuc
indexDeclGroupRef(DeclGroupRef DG)346f4a2713aSLionel Sambuc void IndexingContext::indexDeclGroupRef(DeclGroupRef DG) {
347f4a2713aSLionel Sambuc for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
348f4a2713aSLionel Sambuc indexTopLevelDecl(*I);
349f4a2713aSLionel Sambuc }
350f4a2713aSLionel Sambuc
indexTUDeclsInObjCContainer()351f4a2713aSLionel Sambuc void IndexingContext::indexTUDeclsInObjCContainer() {
352f4a2713aSLionel Sambuc while (!TUDeclsInObjCContainer.empty()) {
353f4a2713aSLionel Sambuc DeclGroupRef DG = TUDeclsInObjCContainer.front();
354f4a2713aSLionel Sambuc TUDeclsInObjCContainer.pop_front();
355f4a2713aSLionel Sambuc indexDeclGroupRef(DG);
356f4a2713aSLionel Sambuc }
357f4a2713aSLionel Sambuc }
358