IndexingContext.cpp revision 37f2f52fbc16b0d426d4d86c7e1662e5c6b9e3b8
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#include "CXTranslationUnit.h" 12#include "CIndexDiagnostic.h" 13 14#include "clang/Frontend/ASTUnit.h" 15#include "clang/AST/DeclCXX.h" 16#include "clang/AST/DeclTemplate.h" 17 18using namespace clang; 19using namespace cxindex; 20using namespace cxcursor; 21 22IndexingContext::ObjCProtocolListInfo::ObjCProtocolListInfo( 23 const ObjCProtocolList &ProtList, 24 IndexingContext &IdxCtx, 25 ScratchAlloc &SA) { 26 ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin(); 27 for (ObjCInterfaceDecl::protocol_iterator 28 I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) { 29 SourceLocation Loc = *LI; 30 ObjCProtocolDecl *PD = *I; 31 ProtEntities.push_back(EntityInfo()); 32 IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA); 33 CXIdxObjCProtocolRefInfo ProtInfo = { 0, 34 MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU), 35 IdxCtx.getIndexLoc(Loc) }; 36 ProtInfos.push_back(ProtInfo); 37 38 if (IdxCtx.shouldSuppressRefs()) 39 IdxCtx.markEntityOccurrenceInFile(PD, Loc); 40 } 41 42 for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i) 43 ProtInfos[i].protocol = &ProtEntities[i]; 44 45 for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i) 46 Prots.push_back(&ProtInfos[i]); 47} 48 49 50IBOutletCollectionInfo::IBOutletCollectionInfo( 51 const IBOutletCollectionInfo &other) 52 : AttrInfo(CXIdxAttr_IBOutletCollection, other.cursor, other.loc, other.A) { 53 54 IBCollInfo.attrInfo = this; 55 IBCollInfo.classCursor = other.IBCollInfo.classCursor; 56 IBCollInfo.classLoc = other.IBCollInfo.classLoc; 57 if (other.IBCollInfo.objcClass) { 58 ClassInfo = other.ClassInfo; 59 IBCollInfo.objcClass = &ClassInfo; 60 } else 61 IBCollInfo.objcClass = 0; 62} 63 64AttrListInfo::AttrListInfo(const Decl *D, IndexingContext &IdxCtx) 65 : SA(IdxCtx), ref_cnt(0) { 66 67 if (!D->hasAttrs()) 68 return; 69 70 for (AttrVec::const_iterator AttrI = D->attr_begin(), AttrE = D->attr_end(); 71 AttrI != AttrE; ++AttrI) { 72 const Attr *A = *AttrI; 73 CXCursor C = MakeCXCursor(A, const_cast<Decl *>(D), IdxCtx.CXTU); 74 CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation()); 75 switch (C.kind) { 76 default: 77 Attrs.push_back(AttrInfo(CXIdxAttr_Unexposed, C, Loc, A)); 78 break; 79 case CXCursor_IBActionAttr: 80 Attrs.push_back(AttrInfo(CXIdxAttr_IBAction, C, Loc, A)); 81 break; 82 case CXCursor_IBOutletAttr: 83 Attrs.push_back(AttrInfo(CXIdxAttr_IBOutlet, C, Loc, A)); 84 break; 85 case CXCursor_IBOutletCollectionAttr: 86 IBCollAttrs.push_back(IBOutletCollectionInfo(C, Loc, A)); 87 break; 88 } 89 } 90 91 for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i) { 92 IBOutletCollectionInfo &IBInfo = IBCollAttrs[i]; 93 CXAttrs.push_back(&IBInfo); 94 95 const IBOutletCollectionAttr * 96 IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A); 97 IBInfo.IBCollInfo.attrInfo = &IBInfo; 98 IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(IBAttr->getInterfaceLoc()); 99 IBInfo.IBCollInfo.objcClass = 0; 100 IBInfo.IBCollInfo.classCursor = clang_getNullCursor(); 101 QualType Ty = IBAttr->getInterface(); 102 if (const ObjCInterfaceType *InterTy = Ty->getAs<ObjCInterfaceType>()) { 103 if (const ObjCInterfaceDecl *InterD = InterTy->getInterface()) { 104 IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA); 105 IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo; 106 IBInfo.IBCollInfo.classCursor = MakeCursorObjCClassRef(InterD, 107 IBAttr->getInterfaceLoc(), IdxCtx.CXTU); 108 } 109 } 110 } 111 112 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) 113 CXAttrs.push_back(&Attrs[i]); 114} 115 116IntrusiveRefCntPtr<AttrListInfo> 117AttrListInfo::create(const Decl *D, IndexingContext &IdxCtx) { 118 ScratchAlloc SA(IdxCtx); 119 AttrListInfo *attrs = SA.allocate<AttrListInfo>(); 120 return new (attrs) AttrListInfo(D, IdxCtx); 121} 122 123IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D, 124 IndexingContext &IdxCtx, 125 ScratchAlloc &SA) { 126 for (CXXRecordDecl::base_class_const_iterator 127 I = D->bases_begin(), E = D->bases_end(); I != E; ++I) { 128 const CXXBaseSpecifier &Base = *I; 129 BaseEntities.push_back(EntityInfo()); 130 const NamedDecl *BaseD = 0; 131 QualType T = Base.getType(); 132 SourceLocation Loc = getBaseLoc(Base); 133 134 if (const TypedefType *TDT = T->getAs<TypedefType>()) { 135 BaseD = TDT->getDecl(); 136 } else if (const TemplateSpecializationType * 137 TST = T->getAs<TemplateSpecializationType>()) { 138 BaseD = TST->getTemplateName().getAsTemplateDecl(); 139 } else if (const RecordType *RT = T->getAs<RecordType>()) { 140 BaseD = RT->getDecl(); 141 } 142 143 if (BaseD) 144 IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA); 145 CXIdxBaseClassInfo BaseInfo = { 0, 146 MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU), 147 IdxCtx.getIndexLoc(Loc) }; 148 BaseInfos.push_back(BaseInfo); 149 } 150 151 for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) { 152 if (BaseEntities[i].name && BaseEntities[i].USR) 153 BaseInfos[i].base = &BaseEntities[i]; 154 } 155 156 for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) 157 CXBases.push_back(&BaseInfos[i]); 158} 159 160SourceLocation IndexingContext::CXXBasesListInfo::getBaseLoc( 161 const CXXBaseSpecifier &Base) const { 162 SourceLocation Loc = Base.getSourceRange().getBegin(); 163 TypeLoc TL; 164 if (Base.getTypeSourceInfo()) 165 TL = Base.getTypeSourceInfo()->getTypeLoc(); 166 if (TL.isNull()) 167 return Loc; 168 169 if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL)) 170 TL = QL->getUnqualifiedLoc(); 171 172 if (const ElaboratedTypeLoc *EL = dyn_cast<ElaboratedTypeLoc>(&TL)) 173 return EL->getNamedTypeLoc().getBeginLoc(); 174 if (const DependentNameTypeLoc *DL = dyn_cast<DependentNameTypeLoc>(&TL)) 175 return DL->getNameLoc(); 176 if (const DependentTemplateSpecializationTypeLoc * 177 DTL = dyn_cast<DependentTemplateSpecializationTypeLoc>(&TL)) 178 return DTL->getTemplateNameLoc(); 179 180 return Loc; 181} 182 183const char *ScratchAlloc::toCStr(StringRef Str) { 184 if (Str.empty()) 185 return ""; 186 if (Str.data()[Str.size()] == '\0') 187 return Str.data(); 188 return copyCStr(Str); 189} 190 191const char *ScratchAlloc::copyCStr(StringRef Str) { 192 char *buf = IdxCtx.StrScratch.Allocate<char>(Str.size() + 1); 193 std::uninitialized_copy(Str.begin(), Str.end(), buf); 194 buf[Str.size()] = '\0'; 195 return buf; 196} 197 198void IndexingContext::setASTContext(ASTContext &ctx) { 199 Ctx = &ctx; 200 static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx); 201} 202 203void IndexingContext::setPreprocessor(Preprocessor &PP) { 204 static_cast<ASTUnit*>(CXTU->TUData)->setPreprocessor(&PP); 205} 206 207bool IndexingContext::isFunctionLocalDecl(const Decl *D) { 208 assert(D); 209 210 if (!D->getParentFunctionOrMethod()) 211 return false; 212 213 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { 214 switch (ND->getLinkage()) { 215 case NoLinkage: 216 case InternalLinkage: 217 return true; 218 case UniqueExternalLinkage: 219 case ExternalLinkage: 220 return false; 221 } 222 } 223 224 return true; 225} 226 227bool IndexingContext::shouldAbort() { 228 if (!CB.abortQuery) 229 return false; 230 return CB.abortQuery(ClientData, 0); 231} 232 233void IndexingContext::enteredMainFile(const FileEntry *File) { 234 if (File && CB.enteredMainFile) { 235 CXIdxClientFile idxFile = CB.enteredMainFile(ClientData, (CXFile)File, 0); 236 FileMap[File] = idxFile; 237 } 238} 239 240void IndexingContext::ppIncludedFile(SourceLocation hashLoc, 241 StringRef filename, 242 const FileEntry *File, 243 bool isImport, bool isAngled) { 244 if (!CB.ppIncludedFile) 245 return; 246 247 ScratchAlloc SA(*this); 248 CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc), 249 SA.toCStr(filename), 250 (CXFile)File, 251 isImport, isAngled }; 252 CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info); 253 FileMap[File] = idxFile; 254} 255 256void IndexingContext::importedModule(const ImportDecl *ImportD) { 257 if (!CB.importedASTFile) 258 return; 259 260 Module *Mod = ImportD->getImportedModule(); 261 if (!Mod) 262 return; 263 std::string ModuleName = Mod->getFullModuleName(); 264 265 CXIdxImportedASTFileInfo Info = { 266 (CXFile)Mod->getASTFile(), 267 getIndexLoc(ImportD->getLocation()), 268 /*isModule=*/true, 269 ImportD->isImplicit(), 270 ModuleName.c_str(), 271 }; 272 CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info); 273 (void)astFile; 274} 275 276void IndexingContext::startedTranslationUnit() { 277 CXIdxClientContainer idxCont = 0; 278 if (CB.startedTranslationUnit) 279 idxCont = CB.startedTranslationUnit(ClientData, 0); 280 addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont); 281} 282 283void IndexingContext::handleDiagnosticSet(CXDiagnostic CXDiagSet) { 284 if (!CB.diagnostic) 285 return; 286 287 CB.diagnostic(ClientData, CXDiagSet, 0); 288} 289 290bool IndexingContext::handleDecl(const NamedDecl *D, 291 SourceLocation Loc, CXCursor Cursor, 292 DeclInfo &DInfo, 293 const DeclContext *LexicalDC) { 294 if (!CB.indexDeclaration || !D) 295 return false; 296 if (D->isImplicit() && shouldIgnoreIfImplicit(D)) 297 return false; 298 299 ScratchAlloc SA(*this); 300 getEntityInfo(D, DInfo.EntInfo, SA); 301 if ((!shouldIndexFunctionLocalSymbols() && !DInfo.EntInfo.USR) 302 || Loc.isInvalid()) 303 return false; 304 305 if (!LexicalDC) 306 LexicalDC = D->getLexicalDeclContext(); 307 308 if (shouldSuppressRefs()) 309 markEntityOccurrenceInFile(D, Loc); 310 311 DInfo.entityInfo = &DInfo.EntInfo; 312 DInfo.cursor = Cursor; 313 DInfo.loc = getIndexLoc(Loc); 314 DInfo.isImplicit = D->isImplicit(); 315 316 DInfo.attributes = DInfo.EntInfo.attributes; 317 DInfo.numAttributes = DInfo.EntInfo.numAttributes; 318 319 getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer); 320 DInfo.semanticContainer = &DInfo.SemanticContainer; 321 322 if (LexicalDC == D->getDeclContext()) { 323 DInfo.lexicalContainer = &DInfo.SemanticContainer; 324 } else if (isTemplateImplicitInstantiation(D)) { 325 // Implicit instantiations have the lexical context of where they were 326 // instantiated first. We choose instead the semantic context because: 327 // 1) at the time that we see the instantiation we have not seen the 328 // function where it occurred yet. 329 // 2) the lexical context of the first instantiation is not useful 330 // information anyway. 331 DInfo.lexicalContainer = &DInfo.SemanticContainer; 332 } else { 333 getContainerInfo(LexicalDC, DInfo.LexicalContainer); 334 DInfo.lexicalContainer = &DInfo.LexicalContainer; 335 } 336 337 if (DInfo.isContainer) { 338 getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer); 339 DInfo.declAsContainer = &DInfo.DeclAsContainer; 340 } 341 342 CB.indexDeclaration(ClientData, &DInfo); 343 return true; 344} 345 346bool IndexingContext::handleObjCContainer(const ObjCContainerDecl *D, 347 SourceLocation Loc, CXCursor Cursor, 348 ObjCContainerDeclInfo &ContDInfo) { 349 ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo; 350 return handleDecl(D, Loc, Cursor, ContDInfo); 351} 352 353bool IndexingContext::handleFunction(const FunctionDecl *D) { 354 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 355 D->isThisDeclarationADefinition()); 356 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 357} 358 359bool IndexingContext::handleVar(const VarDecl *D) { 360 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 361 /*isContainer=*/false); 362 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 363} 364 365bool IndexingContext::handleField(const FieldDecl *D) { 366 DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, 367 /*isContainer=*/false); 368 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 369} 370 371bool IndexingContext::handleEnumerator(const EnumConstantDecl *D) { 372 DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, 373 /*isContainer=*/false); 374 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 375} 376 377bool IndexingContext::handleTagDecl(const TagDecl *D) { 378 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(D)) 379 return handleCXXRecordDecl(CXXRD, D); 380 381 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 382 D->isThisDeclarationADefinition()); 383 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 384} 385 386bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) { 387 DeclInfo DInfo(!D->isFirstDeclaration(), /*isDefinition=*/true, 388 /*isContainer=*/false); 389 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 390} 391 392bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) { 393 // For @class forward declarations, suppress them the same way as references. 394 if (!D->isThisDeclarationADefinition()) { 395 if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) 396 return false; // already occurred. 397 398 // FIXME: This seems like the wrong definition for redeclaration. 399 bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); 400 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration, 401 /*isImplementation=*/false); 402 return handleObjCContainer(D, D->getLocation(), 403 MakeCursorObjCClassRef(D, D->getLocation(), 404 CXTU), 405 ContDInfo); 406 } 407 408 ScratchAlloc SA(*this); 409 410 CXIdxBaseClassInfo BaseClass; 411 EntityInfo BaseEntity; 412 BaseClass.cursor = clang_getNullCursor(); 413 if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) { 414 getEntityInfo(SuperD, BaseEntity, SA); 415 SourceLocation SuperLoc = D->getSuperClassLoc(); 416 BaseClass.base = &BaseEntity; 417 BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU); 418 BaseClass.loc = getIndexLoc(SuperLoc); 419 420 if (shouldSuppressRefs()) 421 markEntityOccurrenceInFile(SuperD, SuperLoc); 422 } 423 424 ObjCProtocolList EmptyProtoList; 425 ObjCProtocolListInfo ProtInfo(D->isThisDeclarationADefinition() 426 ? D->getReferencedProtocols() 427 : EmptyProtoList, 428 *this, SA); 429 430 ObjCInterfaceDeclInfo InterInfo(D); 431 InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); 432 InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo; 433 InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0; 434 InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo; 435 436 return handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo); 437} 438 439bool IndexingContext::handleObjCImplementation( 440 const ObjCImplementationDecl *D) { 441 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false, 442 /*isRedeclaration=*/true, 443 /*isImplementation=*/true); 444 return handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo); 445} 446 447bool IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) { 448 if (!D->isThisDeclarationADefinition()) { 449 if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) 450 return false; // already occurred. 451 452 // FIXME: This seems like the wrong definition for redeclaration. 453 bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); 454 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, 455 isRedeclaration, 456 /*isImplementation=*/false); 457 return handleObjCContainer(D, D->getLocation(), 458 MakeCursorObjCProtocolRef(D, D->getLocation(), 459 CXTU), 460 ContDInfo); 461 } 462 463 ScratchAlloc SA(*this); 464 ObjCProtocolList EmptyProtoList; 465 ObjCProtocolListInfo ProtListInfo(D->isThisDeclarationADefinition() 466 ? D->getReferencedProtocols() 467 : EmptyProtoList, 468 *this, SA); 469 470 ObjCProtocolDeclInfo ProtInfo(D); 471 ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo(); 472 473 return handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo); 474} 475 476bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) { 477 ScratchAlloc SA(*this); 478 479 ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false); 480 EntityInfo ClassEntity; 481 const ObjCInterfaceDecl *IFaceD = D->getClassInterface(); 482 SourceLocation ClassLoc = D->getLocation(); 483 SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc 484 : D->getCategoryNameLoc(); 485 getEntityInfo(IFaceD, ClassEntity, SA); 486 487 if (shouldSuppressRefs()) 488 markEntityOccurrenceInFile(IFaceD, ClassLoc); 489 490 ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA); 491 492 CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; 493 if (IFaceD) { 494 CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; 495 CatDInfo.ObjCCatDeclInfo.classCursor = 496 MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); 497 } else { 498 CatDInfo.ObjCCatDeclInfo.objcClass = 0; 499 CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); 500 } 501 CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); 502 CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); 503 CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo; 504 505 return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); 506} 507 508bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) { 509 ScratchAlloc SA(*this); 510 511 const ObjCCategoryDecl *CatD = D->getCategoryDecl(); 512 ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true); 513 EntityInfo ClassEntity; 514 const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface(); 515 SourceLocation ClassLoc = D->getLocation(); 516 SourceLocation CategoryLoc = D->getCategoryNameLoc(); 517 getEntityInfo(IFaceD, ClassEntity, SA); 518 519 if (shouldSuppressRefs()) 520 markEntityOccurrenceInFile(IFaceD, ClassLoc); 521 522 CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; 523 if (IFaceD) { 524 CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; 525 CatDInfo.ObjCCatDeclInfo.classCursor = 526 MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); 527 } else { 528 CatDInfo.ObjCCatDeclInfo.objcClass = 0; 529 CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); 530 } 531 CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); 532 CatDInfo.ObjCCatDeclInfo.protocols = 0; 533 534 return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); 535} 536 537bool IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) { 538 DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(), 539 D->isThisDeclarationADefinition()); 540 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 541} 542 543bool IndexingContext::handleSynthesizedObjCProperty( 544 const ObjCPropertyImplDecl *D) { 545 ObjCPropertyDecl *PD = D->getPropertyDecl(); 546 return handleReference(PD, D->getLocation(), getCursor(D), 0, D->getDeclContext()); 547} 548 549bool IndexingContext::handleSynthesizedObjCMethod(const ObjCMethodDecl *D, 550 SourceLocation Loc, 551 const DeclContext *LexicalDC) { 552 DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true, 553 /*isContainer=*/false); 554 return handleDecl(D, Loc, getCursor(D), DInfo, LexicalDC); 555} 556 557bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) { 558 ScratchAlloc SA(*this); 559 560 ObjCPropertyDeclInfo DInfo; 561 EntityInfo GetterEntity; 562 EntityInfo SetterEntity; 563 564 DInfo.ObjCPropDeclInfo.declInfo = &DInfo; 565 566 if (ObjCMethodDecl *Getter = D->getGetterMethodDecl()) { 567 getEntityInfo(Getter, GetterEntity, SA); 568 DInfo.ObjCPropDeclInfo.getter = &GetterEntity; 569 } else { 570 DInfo.ObjCPropDeclInfo.getter = 0; 571 } 572 if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) { 573 getEntityInfo(Setter, SetterEntity, SA); 574 DInfo.ObjCPropDeclInfo.setter = &SetterEntity; 575 } else { 576 DInfo.ObjCPropDeclInfo.setter = 0; 577 } 578 579 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 580} 581 582bool IndexingContext::handleNamespace(const NamespaceDecl *D) { 583 DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(), 584 /*isDefinition=*/true, 585 /*isContainer=*/true); 586 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 587} 588 589bool IndexingContext::handleClassTemplate(const ClassTemplateDecl *D) { 590 return handleCXXRecordDecl(D->getTemplatedDecl(), D); 591} 592 593bool IndexingContext::handleFunctionTemplate(const FunctionTemplateDecl *D) { 594 DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), 595 /*isDefinition=*/D->isThisDeclarationADefinition(), 596 /*isContainer=*/D->isThisDeclarationADefinition()); 597 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 598} 599 600bool IndexingContext::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) { 601 DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), 602 /*isDefinition=*/true, /*isContainer=*/false); 603 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 604} 605 606bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, 607 const NamedDecl *Parent, 608 const DeclContext *DC, 609 const Expr *E, 610 CXIdxEntityRefKind Kind) { 611 if (!D) 612 return false; 613 614 CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E), 615 const_cast<Decl*>(cast<Decl>(DC)), CXTU) 616 : getRefCursor(D, Loc); 617 return handleReference(D, Loc, Cursor, Parent, DC, E, Kind); 618} 619 620bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, 621 CXCursor Cursor, 622 const NamedDecl *Parent, 623 const DeclContext *DC, 624 const Expr *E, 625 CXIdxEntityRefKind Kind) { 626 if (!CB.indexEntityReference) 627 return false; 628 629 if (!D) 630 return false; 631 if (Loc.isInvalid()) 632 return false; 633 if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D)) 634 return false; 635 if (isNotFromSourceFile(D->getLocation())) 636 return false; 637 if (D->isImplicit() && shouldIgnoreIfImplicit(D)) 638 return false; 639 640 if (shouldSuppressRefs()) { 641 if (markEntityOccurrenceInFile(D, Loc)) 642 return false; // already occurred. 643 } 644 645 ScratchAlloc SA(*this); 646 EntityInfo RefEntity, ParentEntity; 647 getEntityInfo(D, RefEntity, SA); 648 if (!RefEntity.USR) 649 return false; 650 651 getEntityInfo(Parent, ParentEntity, SA); 652 653 ContainerInfo Container; 654 getContainerInfo(DC, Container); 655 656 CXIdxEntityRefInfo Info = { Kind, 657 Cursor, 658 getIndexLoc(Loc), 659 &RefEntity, 660 Parent ? &ParentEntity : 0, 661 &Container }; 662 CB.indexEntityReference(ClientData, &Info); 663 return true; 664} 665 666bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const { 667 if (Loc.isInvalid()) 668 return true; 669 SourceManager &SM = Ctx->getSourceManager(); 670 SourceLocation FileLoc = SM.getFileLoc(Loc); 671 FileID FID = SM.getFileID(FileLoc); 672 return SM.getFileEntryForID(FID) == 0; 673} 674 675void IndexingContext::addContainerInMap(const DeclContext *DC, 676 CXIdxClientContainer container) { 677 if (!DC) 678 return; 679 680 ContainerMapTy::iterator I = ContainerMap.find(DC); 681 if (I == ContainerMap.end()) { 682 if (container) 683 ContainerMap[DC] = container; 684 return; 685 } 686 // Allow changing the container of a previously seen DeclContext so we 687 // can handle invalid user code, like a function re-definition. 688 if (container) 689 I->second = container; 690 else 691 ContainerMap.erase(I); 692} 693 694CXIdxClientEntity IndexingContext::getClientEntity(const Decl *D) const { 695 if (!D) 696 return 0; 697 EntityMapTy::const_iterator I = EntityMap.find(D); 698 if (I == EntityMap.end()) 699 return 0; 700 return I->second; 701} 702 703void IndexingContext::setClientEntity(const Decl *D, CXIdxClientEntity client) { 704 if (!D) 705 return; 706 EntityMap[D] = client; 707} 708 709bool IndexingContext::handleCXXRecordDecl(const CXXRecordDecl *RD, 710 const NamedDecl *OrigD) { 711 if (RD->isThisDeclarationADefinition()) { 712 ScratchAlloc SA(*this); 713 CXXClassDeclInfo CXXDInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), 714 /*isDefinition=*/RD->isThisDeclarationADefinition()); 715 CXXBasesListInfo BaseList(RD, *this, SA); 716 CXXDInfo.CXXClassInfo.declInfo = &CXXDInfo; 717 CXXDInfo.CXXClassInfo.bases = BaseList.getBases(); 718 CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases(); 719 720 if (shouldSuppressRefs()) { 721 // Go through bases and mark them as referenced. 722 for (unsigned i = 0, e = BaseList.getNumBases(); i != e; ++i) { 723 const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i]; 724 if (baseInfo->base) { 725 const NamedDecl *BaseD = BaseList.BaseEntities[i].Dcl; 726 SourceLocation 727 Loc = SourceLocation::getFromRawEncoding(baseInfo->loc.int_data); 728 markEntityOccurrenceInFile(BaseD, Loc); 729 } 730 } 731 } 732 733 return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), CXXDInfo); 734 } 735 736 DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), 737 /*isDefinition=*/RD->isThisDeclarationADefinition(), 738 /*isContainer=*/RD->isThisDeclarationADefinition()); 739 return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo); 740} 741 742bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D, 743 SourceLocation Loc) { 744 if (!D || Loc.isInvalid()) 745 return true; 746 747 SourceManager &SM = Ctx->getSourceManager(); 748 D = getEntityDecl(D); 749 750 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc)); 751 FileID FID = LocInfo.first; 752 if (FID.isInvalid()) 753 return true; 754 755 const FileEntry *FE = SM.getFileEntryForID(FID); 756 if (!FE) 757 return true; 758 RefFileOccurence RefOccur(FE, D); 759 std::pair<llvm::DenseSet<RefFileOccurence>::iterator, bool> 760 res = RefFileOccurences.insert(RefOccur); 761 if (!res.second) 762 return true; // already in map. 763 764 return false; 765} 766 767const NamedDecl *IndexingContext::getEntityDecl(const NamedDecl *D) const { 768 assert(D); 769 D = cast<NamedDecl>(D->getCanonicalDecl()); 770 771 if (const ObjCImplementationDecl * 772 ImplD = dyn_cast<ObjCImplementationDecl>(D)) { 773 return getEntityDecl(ImplD->getClassInterface()); 774 775 } else if (const ObjCCategoryImplDecl * 776 CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) { 777 return getEntityDecl(CatImplD->getCategoryDecl()); 778 } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 779 if (FunctionTemplateDecl *TemplD = FD->getDescribedFunctionTemplate()) 780 return getEntityDecl(TemplD); 781 } else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { 782 if (ClassTemplateDecl *TemplD = RD->getDescribedClassTemplate()) 783 return getEntityDecl(TemplD); 784 } 785 786 return D; 787} 788 789const DeclContext * 790IndexingContext::getEntityContainer(const Decl *D) const { 791 const DeclContext *DC = dyn_cast<DeclContext>(D); 792 if (DC) 793 return DC; 794 795 if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) { 796 DC = ClassTempl->getTemplatedDecl(); 797 } if (const FunctionTemplateDecl * 798 FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) { 799 DC = FuncTempl->getTemplatedDecl(); 800 } 801 802 return DC; 803} 804 805CXIdxClientContainer 806IndexingContext::getClientContainerForDC(const DeclContext *DC) const { 807 if (!DC) 808 return 0; 809 810 ContainerMapTy::const_iterator I = ContainerMap.find(DC); 811 if (I == ContainerMap.end()) 812 return 0; 813 814 return I->second; 815} 816 817CXIdxClientFile IndexingContext::getIndexFile(const FileEntry *File) { 818 if (!File) 819 return 0; 820 821 FileMapTy::iterator FI = FileMap.find(File); 822 if (FI != FileMap.end()) 823 return FI->second; 824 825 return 0; 826} 827 828CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const { 829 CXIdxLoc idxLoc = { {0, 0}, 0 }; 830 if (Loc.isInvalid()) 831 return idxLoc; 832 833 idxLoc.ptr_data[0] = (void*)this; 834 idxLoc.int_data = Loc.getRawEncoding(); 835 return idxLoc; 836} 837 838void IndexingContext::translateLoc(SourceLocation Loc, 839 CXIdxClientFile *indexFile, CXFile *file, 840 unsigned *line, unsigned *column, 841 unsigned *offset) { 842 if (Loc.isInvalid()) 843 return; 844 845 SourceManager &SM = Ctx->getSourceManager(); 846 Loc = SM.getFileLoc(Loc); 847 848 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); 849 FileID FID = LocInfo.first; 850 unsigned FileOffset = LocInfo.second; 851 852 if (FID.isInvalid()) 853 return; 854 855 const FileEntry *FE = SM.getFileEntryForID(FID); 856 if (indexFile) 857 *indexFile = getIndexFile(FE); 858 if (file) 859 *file = (void *)FE; 860 if (line) 861 *line = SM.getLineNumber(FID, FileOffset); 862 if (column) 863 *column = SM.getColumnNumber(FID, FileOffset); 864 if (offset) 865 *offset = FileOffset; 866} 867 868void IndexingContext::getEntityInfo(const NamedDecl *D, 869 EntityInfo &EntityInfo, 870 ScratchAlloc &SA) { 871 if (!D) 872 return; 873 874 D = getEntityDecl(D); 875 EntityInfo.cursor = getCursor(D); 876 EntityInfo.Dcl = D; 877 EntityInfo.IndexCtx = this; 878 EntityInfo.kind = CXIdxEntity_Unexposed; 879 EntityInfo.templateKind = CXIdxEntity_NonTemplate; 880 EntityInfo.lang = CXIdxEntityLang_C; 881 882 if (D->hasAttrs()) { 883 EntityInfo.AttrList = AttrListInfo::create(D, *this); 884 EntityInfo.attributes = EntityInfo.AttrList->getAttrs(); 885 EntityInfo.numAttributes = EntityInfo.AttrList->getNumAttrs(); 886 } 887 888 if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { 889 switch (TD->getTagKind()) { 890 case TTK_Struct: 891 EntityInfo.kind = CXIdxEntity_Struct; break; 892 case TTK_Union: 893 EntityInfo.kind = CXIdxEntity_Union; break; 894 case TTK_Class: 895 EntityInfo.kind = CXIdxEntity_CXXClass; 896 EntityInfo.lang = CXIdxEntityLang_CXX; 897 break; 898 case TTK_Interface: 899 EntityInfo.kind = CXIdxEntity_CXXInterface; 900 EntityInfo.lang = CXIdxEntityLang_CXX; 901 break; 902 case TTK_Enum: 903 EntityInfo.kind = CXIdxEntity_Enum; break; 904 } 905 906 if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) 907 if (!CXXRec->isCLike()) 908 EntityInfo.lang = CXIdxEntityLang_CXX; 909 910 if (isa<ClassTemplatePartialSpecializationDecl>(D)) { 911 EntityInfo.templateKind = CXIdxEntity_TemplatePartialSpecialization; 912 } else if (isa<ClassTemplateSpecializationDecl>(D)) { 913 EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; 914 } 915 916 } else { 917 switch (D->getKind()) { 918 case Decl::Typedef: 919 EntityInfo.kind = CXIdxEntity_Typedef; break; 920 case Decl::Function: 921 EntityInfo.kind = CXIdxEntity_Function; 922 break; 923 case Decl::ParmVar: 924 EntityInfo.kind = CXIdxEntity_Variable; 925 break; 926 case Decl::Var: 927 EntityInfo.kind = CXIdxEntity_Variable; 928 if (isa<CXXRecordDecl>(D->getDeclContext())) { 929 EntityInfo.kind = CXIdxEntity_CXXStaticVariable; 930 EntityInfo.lang = CXIdxEntityLang_CXX; 931 } 932 break; 933 case Decl::Field: 934 EntityInfo.kind = CXIdxEntity_Field; 935 if (const CXXRecordDecl * 936 CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { 937 // FIXME: isPOD check is not sufficient, a POD can contain methods, 938 // we want a isCStructLike check. 939 if (!CXXRec->isPOD()) 940 EntityInfo.lang = CXIdxEntityLang_CXX; 941 } 942 break; 943 case Decl::EnumConstant: 944 EntityInfo.kind = CXIdxEntity_EnumConstant; break; 945 case Decl::ObjCInterface: 946 EntityInfo.kind = CXIdxEntity_ObjCClass; 947 EntityInfo.lang = CXIdxEntityLang_ObjC; 948 break; 949 case Decl::ObjCProtocol: 950 EntityInfo.kind = CXIdxEntity_ObjCProtocol; 951 EntityInfo.lang = CXIdxEntityLang_ObjC; 952 break; 953 case Decl::ObjCCategory: 954 EntityInfo.kind = CXIdxEntity_ObjCCategory; 955 EntityInfo.lang = CXIdxEntityLang_ObjC; 956 break; 957 case Decl::ObjCMethod: 958 if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) 959 EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod; 960 else 961 EntityInfo.kind = CXIdxEntity_ObjCClassMethod; 962 EntityInfo.lang = CXIdxEntityLang_ObjC; 963 break; 964 case Decl::ObjCProperty: 965 EntityInfo.kind = CXIdxEntity_ObjCProperty; 966 EntityInfo.lang = CXIdxEntityLang_ObjC; 967 break; 968 case Decl::ObjCIvar: 969 EntityInfo.kind = CXIdxEntity_ObjCIvar; 970 EntityInfo.lang = CXIdxEntityLang_ObjC; 971 break; 972 case Decl::Namespace: 973 EntityInfo.kind = CXIdxEntity_CXXNamespace; 974 EntityInfo.lang = CXIdxEntityLang_CXX; 975 break; 976 case Decl::NamespaceAlias: 977 EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias; 978 EntityInfo.lang = CXIdxEntityLang_CXX; 979 break; 980 case Decl::CXXConstructor: 981 EntityInfo.kind = CXIdxEntity_CXXConstructor; 982 EntityInfo.lang = CXIdxEntityLang_CXX; 983 break; 984 case Decl::CXXDestructor: 985 EntityInfo.kind = CXIdxEntity_CXXDestructor; 986 EntityInfo.lang = CXIdxEntityLang_CXX; 987 break; 988 case Decl::CXXConversion: 989 EntityInfo.kind = CXIdxEntity_CXXConversionFunction; 990 EntityInfo.lang = CXIdxEntityLang_CXX; 991 break; 992 case Decl::CXXMethod: { 993 const CXXMethodDecl *MD = cast<CXXMethodDecl>(D); 994 if (MD->isStatic()) 995 EntityInfo.kind = CXIdxEntity_CXXStaticMethod; 996 else 997 EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; 998 EntityInfo.lang = CXIdxEntityLang_CXX; 999 break; 1000 } 1001 case Decl::ClassTemplate: 1002 EntityInfo.kind = CXIdxEntity_CXXClass; 1003 EntityInfo.templateKind = CXIdxEntity_Template; 1004 break; 1005 case Decl::FunctionTemplate: 1006 EntityInfo.kind = CXIdxEntity_Function; 1007 EntityInfo.templateKind = CXIdxEntity_Template; 1008 if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>( 1009 cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) { 1010 if (isa<CXXConstructorDecl>(MD)) 1011 EntityInfo.kind = CXIdxEntity_CXXConstructor; 1012 else if (isa<CXXDestructorDecl>(MD)) 1013 EntityInfo.kind = CXIdxEntity_CXXDestructor; 1014 else if (isa<CXXConversionDecl>(MD)) 1015 EntityInfo.kind = CXIdxEntity_CXXConversionFunction; 1016 else { 1017 if (MD->isStatic()) 1018 EntityInfo.kind = CXIdxEntity_CXXStaticMethod; 1019 else 1020 EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; 1021 } 1022 } 1023 break; 1024 case Decl::TypeAliasTemplate: 1025 EntityInfo.kind = CXIdxEntity_CXXTypeAlias; 1026 EntityInfo.templateKind = CXIdxEntity_Template; 1027 break; 1028 case Decl::TypeAlias: 1029 EntityInfo.kind = CXIdxEntity_CXXTypeAlias; 1030 EntityInfo.lang = CXIdxEntityLang_CXX; 1031 break; 1032 default: 1033 break; 1034 } 1035 } 1036 1037 if (EntityInfo.kind == CXIdxEntity_Unexposed) 1038 return; 1039 1040 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1041 if (FD->getTemplatedKind() == 1042 FunctionDecl::TK_FunctionTemplateSpecialization) 1043 EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; 1044 } 1045 1046 if (EntityInfo.templateKind != CXIdxEntity_NonTemplate) 1047 EntityInfo.lang = CXIdxEntityLang_CXX; 1048 1049 if (IdentifierInfo *II = D->getIdentifier()) { 1050 EntityInfo.name = SA.toCStr(II->getName()); 1051 1052 } else if (isa<TagDecl>(D) || isa<FieldDecl>(D) || isa<NamespaceDecl>(D)) { 1053 EntityInfo.name = 0; // anonymous tag/field/namespace. 1054 1055 } else { 1056 SmallString<256> StrBuf; 1057 { 1058 llvm::raw_svector_ostream OS(StrBuf); 1059 D->printName(OS); 1060 } 1061 EntityInfo.name = SA.copyCStr(StrBuf.str()); 1062 } 1063 1064 { 1065 SmallString<512> StrBuf; 1066 bool Ignore = getDeclCursorUSR(D, StrBuf); 1067 if (Ignore) { 1068 EntityInfo.USR = 0; 1069 } else { 1070 EntityInfo.USR = SA.copyCStr(StrBuf.str()); 1071 } 1072 } 1073} 1074 1075void IndexingContext::getContainerInfo(const DeclContext *DC, 1076 ContainerInfo &ContInfo) { 1077 ContInfo.cursor = getCursor(cast<Decl>(DC)); 1078 ContInfo.DC = DC; 1079 ContInfo.IndexCtx = this; 1080} 1081 1082CXCursor IndexingContext::getRefCursor(const NamedDecl *D, SourceLocation Loc) { 1083 if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) 1084 return MakeCursorTypeRef(TD, Loc, CXTU); 1085 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) 1086 return MakeCursorObjCClassRef(ID, Loc, CXTU); 1087 if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) 1088 return MakeCursorObjCProtocolRef(PD, Loc, CXTU); 1089 if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) 1090 return MakeCursorTemplateRef(Template, Loc, CXTU); 1091 if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(D)) 1092 return MakeCursorNamespaceRef(Namespace, Loc, CXTU); 1093 if (const NamespaceAliasDecl *Namespace = dyn_cast<NamespaceAliasDecl>(D)) 1094 return MakeCursorNamespaceRef(Namespace, Loc, CXTU); 1095 if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) 1096 return MakeCursorMemberRef(Field, Loc, CXTU); 1097 if (const VarDecl *Var = dyn_cast<VarDecl>(D)) 1098 return MakeCursorVariableRef(Var, Loc, CXTU); 1099 1100 return clang_getNullCursor(); 1101} 1102 1103bool IndexingContext::shouldIgnoreIfImplicit(const Decl *D) { 1104 if (isa<ObjCInterfaceDecl>(D)) 1105 return false; 1106 if (isa<ObjCCategoryDecl>(D)) 1107 return false; 1108 if (isa<ObjCIvarDecl>(D)) 1109 return false; 1110 if (isa<ObjCMethodDecl>(D)) 1111 return false; 1112 if (isa<ImportDecl>(D)) 1113 return false; 1114 return true; 1115} 1116 1117bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { 1118 if (const ClassTemplateSpecializationDecl * 1119 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { 1120 return SD->getSpecializationKind() == TSK_ImplicitInstantiation; 1121 } 1122 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1123 return FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation; 1124 } 1125 return false; 1126} 1127