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