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" |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 11 | #include "clang/AST/DeclVisitor.h" |
| 12 | |
| 13 | using namespace clang; |
| 14 | using namespace cxindex; |
| 15 | |
| 16 | namespace { |
| 17 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 18 | class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 19 | IndexingContext &IndexCtx; |
| 20 | |
| 21 | public: |
| 22 | explicit IndexingDeclVisitor(IndexingContext &indexCtx) |
| 23 | : IndexCtx(indexCtx) { } |
| 24 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 25 | void handleDeclarator(const DeclaratorDecl *D, const NamedDecl *Parent = 0) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 26 | if (!Parent) Parent = D; |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 27 | |
Argyrios Kyrtzidis | 58d2dbe | 2012-02-14 22:23:11 +0000 | [diff] [blame] | 28 | if (!IndexCtx.shouldIndexFunctionLocalSymbols()) { |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 29 | IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent); |
| 30 | IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent); |
| 31 | } else { |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 32 | if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 33 | IndexCtx.handleVar(Parm); |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 34 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 35 | for (FunctionDecl::param_const_iterator PI = FD->param_begin(), |
| 36 | PE = FD->param_end(); |
| 37 | PI != PE; ++PI) { |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 38 | IndexCtx.handleVar(*PI); |
| 39 | } |
| 40 | } |
| 41 | } |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 44 | void handleObjCMethod(const ObjCMethodDecl *D) { |
Argyrios Kyrtzidis | d7c15a6 | 2012-02-28 17:50:28 +0000 | [diff] [blame] | 45 | IndexCtx.handleObjCMethod(D); |
| 46 | if (D->isImplicit()) |
| 47 | return; |
| 48 | |
| 49 | IndexCtx.indexTypeSourceInfo(D->getResultTypeSourceInfo(), D); |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 50 | for (ObjCMethodDecl::param_const_iterator I = D->param_begin(), |
| 51 | E = D->param_end(); |
| 52 | I != E; ++I) |
Argyrios Kyrtzidis | d7c15a6 | 2012-02-28 17:50:28 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 63 | bool VisitFunctionDecl(const FunctionDecl *D) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 67 | if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) { |
Argyrios Kyrtzidis | 8818d45 | 2012-01-23 16:58:36 +0000 | [diff] [blame] | 68 | // Constructor initializers. |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 69 | for (CXXConstructorDecl::init_const_iterator I = Ctor->init_begin(), |
| 70 | E = Ctor->init_end(); |
Argyrios Kyrtzidis | 8818d45 | 2012-01-23 16:58:36 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 91 | bool VisitVarDecl(const VarDecl *D) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 98 | bool VisitFieldDecl(const FieldDecl *D) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 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 | } |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 107 | |
| 108 | bool VisitEnumConstantDecl(const EnumConstantDecl *D) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 114 | bool VisitTypedefNameDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 120 | bool VisitTagDecl(const TagDecl *D) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 121 | // Non-free standing tags are handled in indexTypeSourceInfo. |
| 122 | if (D->isFreeStanding()) |
| 123 | IndexCtx.indexTagDecl(D); |
| 124 | return true; |
| 125 | } |
| 126 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 127 | bool VisitObjCInterfaceDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 137 | bool VisitObjCProtocolDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 147 | bool VisitObjCImplementationDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 175 | bool VisitObjCCategoryDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 183 | bool VisitObjCCategoryImplDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 195 | bool VisitObjCMethodDecl(const 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. |
Jordan Rose | 1e4691b | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 198 | if (D->isPropertyAccessor()) |
Argyrios Kyrtzidis | d7c15a6 | 2012-02-28 17:50:28 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 205 | bool VisitObjCPropertyDecl(const 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 217 | bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 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()) { |
Jordan Rose | 1e4691b | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 232 | if (MD->isPropertyAccessor()) |
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()) { |
Jordan Rose | 1e4691b | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 237 | if (MD->isPropertyAccessor()) |
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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 244 | bool VisitNamespaceDecl(const NamespaceDecl *D) { |
Argyrios Kyrtzidis | 68478b0 | 2011-12-07 05:52:06 +0000 | [diff] [blame] | 245 | IndexCtx.handleNamespace(D); |
| 246 | IndexCtx.indexDeclContext(D); |
| 247 | return true; |
| 248 | } |
| 249 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 250 | bool VisitUsingDecl(const UsingDecl *D) { |
Argyrios Kyrtzidis | 911d717 | 2012-02-10 20:10:48 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 263 | bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { |
Argyrios Kyrtzidis | 911d717 | 2012-02-10 20:10:48 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 273 | bool VisitClassTemplateDecl(const ClassTemplateDecl *D) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 274 | IndexCtx.handleClassTemplate(D); |
| 275 | if (D->isThisDeclarationADefinition()) |
| 276 | IndexCtx.indexDeclContext(D->getTemplatedDecl()); |
| 277 | return true; |
| 278 | } |
| 279 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 280 | bool VisitClassTemplateSpecializationDecl(const |
Argyrios Kyrtzidis | 6d96836 | 2012-02-10 20:10:44 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 291 | bool VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 304 | bool VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 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 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 310 | bool VisitImportDecl(const ImportDecl *D) { |
Argyrios Kyrtzidis | 37f2f52 | 2012-10-03 21:05:44 +0000 | [diff] [blame] | 311 | IndexCtx.importedModule(D); |
Argyrios Kyrtzidis | 2c3e05c | 2012-10-02 16:10:38 +0000 | [diff] [blame] | 312 | return true; |
| 313 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | } // anonymous namespace |
| 317 | |
| 318 | void IndexingContext::indexDecl(const Decl *D) { |
Argyrios Kyrtzidis | d089008 | 2012-02-07 22:46:16 +0000 | [diff] [blame] | 319 | if (D->isImplicit() && shouldIgnoreIfImplicit(D)) |
| 320 | return; |
| 321 | |
Dmitri Gribenko | 361d79c | 2013-02-03 13:42:20 +0000 | [diff] [blame] | 322 | bool Handled = IndexingDeclVisitor(*this).Visit(D); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 323 | if (!Handled && isa<DeclContext>(D)) |
| 324 | indexDeclContext(cast<DeclContext>(D)); |
| 325 | } |
| 326 | |
| 327 | void IndexingContext::indexDeclContext(const DeclContext *DC) { |
| 328 | for (DeclContext::decl_iterator |
| 329 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { |
| 330 | indexDecl(*I); |
| 331 | } |
| 332 | } |
| 333 | |
Argyrios Kyrtzidis | 3bed3d1 | 2012-09-10 22:58:04 +0000 | [diff] [blame] | 334 | void IndexingContext::indexTopLevelDecl(const Decl *D) { |
Argyrios Kyrtzidis | 21ee570 | 2011-11-15 06:20:16 +0000 | [diff] [blame] | 335 | if (isNotFromSourceFile(D->getLocation())) |
| 336 | return; |
| 337 | |
| 338 | if (isa<ObjCMethodDecl>(D)) |
| 339 | return; // Wait for the objc container. |
| 340 | |
| 341 | indexDecl(D); |
| 342 | } |
| 343 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 344 | void IndexingContext::indexDeclGroupRef(DeclGroupRef DG) { |
Argyrios Kyrtzidis | 21ee570 | 2011-11-15 06:20:16 +0000 | [diff] [blame] | 345 | for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |
| 346 | indexTopLevelDecl(*I); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void IndexingContext::indexTUDeclsInObjCContainer() { |
Argyrios Kyrtzidis | 30a2805 | 2012-03-23 23:24:18 +0000 | [diff] [blame] | 350 | while (!TUDeclsInObjCContainer.empty()) { |
| 351 | DeclGroupRef DG = TUDeclsInObjCContainer.front(); |
| 352 | TUDeclsInObjCContainer.pop_front(); |
| 353 | indexDeclGroupRef(DG); |
| 354 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 355 | } |