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