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