IndexingContext.cpp revision 3da76bfbd24b2747ceb72d1918bbbe3123dac841
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::importedPCH(const FileEntry *File) { 277 if (!CB.importedASTFile) 278 return; 279 280 CXIdxImportedASTFileInfo Info = { 281 (CXFile)File, 282 getIndexLoc(SourceLocation()), 283 /*isModule=*/false, 284 /*isImplicit=*/false, 285 /*moduleName=*/NULL 286 }; 287 CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info); 288 (void)astFile; 289} 290 291void IndexingContext::startedTranslationUnit() { 292 CXIdxClientContainer idxCont = 0; 293 if (CB.startedTranslationUnit) 294 idxCont = CB.startedTranslationUnit(ClientData, 0); 295 addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont); 296} 297 298void IndexingContext::handleDiagnosticSet(CXDiagnostic CXDiagSet) { 299 if (!CB.diagnostic) 300 return; 301 302 CB.diagnostic(ClientData, CXDiagSet, 0); 303} 304 305bool IndexingContext::handleDecl(const NamedDecl *D, 306 SourceLocation Loc, CXCursor Cursor, 307 DeclInfo &DInfo, 308 const DeclContext *LexicalDC) { 309 if (!CB.indexDeclaration || !D) 310 return false; 311 if (D->isImplicit() && shouldIgnoreIfImplicit(D)) 312 return false; 313 314 ScratchAlloc SA(*this); 315 getEntityInfo(D, DInfo.EntInfo, SA); 316 if ((!shouldIndexFunctionLocalSymbols() && !DInfo.EntInfo.USR) 317 || Loc.isInvalid()) 318 return false; 319 320 if (!LexicalDC) 321 LexicalDC = D->getLexicalDeclContext(); 322 323 if (shouldSuppressRefs()) 324 markEntityOccurrenceInFile(D, Loc); 325 326 DInfo.entityInfo = &DInfo.EntInfo; 327 DInfo.cursor = Cursor; 328 DInfo.loc = getIndexLoc(Loc); 329 DInfo.isImplicit = D->isImplicit(); 330 331 DInfo.attributes = DInfo.EntInfo.attributes; 332 DInfo.numAttributes = DInfo.EntInfo.numAttributes; 333 334 getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer); 335 DInfo.semanticContainer = &DInfo.SemanticContainer; 336 337 if (LexicalDC == D->getDeclContext()) { 338 DInfo.lexicalContainer = &DInfo.SemanticContainer; 339 } else if (isTemplateImplicitInstantiation(D)) { 340 // Implicit instantiations have the lexical context of where they were 341 // instantiated first. We choose instead the semantic context because: 342 // 1) at the time that we see the instantiation we have not seen the 343 // function where it occurred yet. 344 // 2) the lexical context of the first instantiation is not useful 345 // information anyway. 346 DInfo.lexicalContainer = &DInfo.SemanticContainer; 347 } else { 348 getContainerInfo(LexicalDC, DInfo.LexicalContainer); 349 DInfo.lexicalContainer = &DInfo.LexicalContainer; 350 } 351 352 if (DInfo.isContainer) { 353 getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer); 354 DInfo.declAsContainer = &DInfo.DeclAsContainer; 355 } 356 357 CB.indexDeclaration(ClientData, &DInfo); 358 return true; 359} 360 361bool IndexingContext::handleObjCContainer(const ObjCContainerDecl *D, 362 SourceLocation Loc, CXCursor Cursor, 363 ObjCContainerDeclInfo &ContDInfo) { 364 ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo; 365 return handleDecl(D, Loc, Cursor, ContDInfo); 366} 367 368bool IndexingContext::handleFunction(const FunctionDecl *D) { 369 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 370 D->isThisDeclarationADefinition()); 371 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 372} 373 374bool IndexingContext::handleVar(const VarDecl *D) { 375 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 376 /*isContainer=*/false); 377 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 378} 379 380bool IndexingContext::handleField(const FieldDecl *D) { 381 DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, 382 /*isContainer=*/false); 383 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 384} 385 386bool IndexingContext::handleEnumerator(const EnumConstantDecl *D) { 387 DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, 388 /*isContainer=*/false); 389 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 390} 391 392bool IndexingContext::handleTagDecl(const TagDecl *D) { 393 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(D)) 394 return handleCXXRecordDecl(CXXRD, D); 395 396 DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), 397 D->isThisDeclarationADefinition()); 398 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 399} 400 401bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) { 402 DeclInfo DInfo(!D->isFirstDeclaration(), /*isDefinition=*/true, 403 /*isContainer=*/false); 404 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 405} 406 407bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) { 408 // For @class forward declarations, suppress them the same way as references. 409 if (!D->isThisDeclarationADefinition()) { 410 if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) 411 return false; // already occurred. 412 413 // FIXME: This seems like the wrong definition for redeclaration. 414 bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); 415 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration, 416 /*isImplementation=*/false); 417 return handleObjCContainer(D, D->getLocation(), 418 MakeCursorObjCClassRef(D, D->getLocation(), 419 CXTU), 420 ContDInfo); 421 } 422 423 ScratchAlloc SA(*this); 424 425 CXIdxBaseClassInfo BaseClass; 426 EntityInfo BaseEntity; 427 BaseClass.cursor = clang_getNullCursor(); 428 if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) { 429 getEntityInfo(SuperD, BaseEntity, SA); 430 SourceLocation SuperLoc = D->getSuperClassLoc(); 431 BaseClass.base = &BaseEntity; 432 BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU); 433 BaseClass.loc = getIndexLoc(SuperLoc); 434 435 if (shouldSuppressRefs()) 436 markEntityOccurrenceInFile(SuperD, SuperLoc); 437 } 438 439 ObjCProtocolList EmptyProtoList; 440 ObjCProtocolListInfo ProtInfo(D->isThisDeclarationADefinition() 441 ? D->getReferencedProtocols() 442 : EmptyProtoList, 443 *this, SA); 444 445 ObjCInterfaceDeclInfo InterInfo(D); 446 InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); 447 InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo; 448 InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0; 449 InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo; 450 451 return handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo); 452} 453 454bool IndexingContext::handleObjCImplementation( 455 const ObjCImplementationDecl *D) { 456 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false, 457 /*isRedeclaration=*/true, 458 /*isImplementation=*/true); 459 return handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo); 460} 461 462bool IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) { 463 if (!D->isThisDeclarationADefinition()) { 464 if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) 465 return false; // already occurred. 466 467 // FIXME: This seems like the wrong definition for redeclaration. 468 bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); 469 ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, 470 isRedeclaration, 471 /*isImplementation=*/false); 472 return handleObjCContainer(D, D->getLocation(), 473 MakeCursorObjCProtocolRef(D, D->getLocation(), 474 CXTU), 475 ContDInfo); 476 } 477 478 ScratchAlloc SA(*this); 479 ObjCProtocolList EmptyProtoList; 480 ObjCProtocolListInfo ProtListInfo(D->isThisDeclarationADefinition() 481 ? D->getReferencedProtocols() 482 : EmptyProtoList, 483 *this, SA); 484 485 ObjCProtocolDeclInfo ProtInfo(D); 486 ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo(); 487 488 return handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo); 489} 490 491bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) { 492 ScratchAlloc SA(*this); 493 494 ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false); 495 EntityInfo ClassEntity; 496 const ObjCInterfaceDecl *IFaceD = D->getClassInterface(); 497 SourceLocation ClassLoc = D->getLocation(); 498 SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc 499 : D->getCategoryNameLoc(); 500 getEntityInfo(IFaceD, ClassEntity, SA); 501 502 if (shouldSuppressRefs()) 503 markEntityOccurrenceInFile(IFaceD, ClassLoc); 504 505 ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA); 506 507 CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; 508 if (IFaceD) { 509 CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; 510 CatDInfo.ObjCCatDeclInfo.classCursor = 511 MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); 512 } else { 513 CatDInfo.ObjCCatDeclInfo.objcClass = 0; 514 CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); 515 } 516 CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); 517 CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); 518 CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo; 519 520 return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); 521} 522 523bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) { 524 ScratchAlloc SA(*this); 525 526 const ObjCCategoryDecl *CatD = D->getCategoryDecl(); 527 ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true); 528 EntityInfo ClassEntity; 529 const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface(); 530 SourceLocation ClassLoc = D->getLocation(); 531 SourceLocation CategoryLoc = D->getCategoryNameLoc(); 532 getEntityInfo(IFaceD, ClassEntity, SA); 533 534 if (shouldSuppressRefs()) 535 markEntityOccurrenceInFile(IFaceD, ClassLoc); 536 537 CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; 538 if (IFaceD) { 539 CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; 540 CatDInfo.ObjCCatDeclInfo.classCursor = 541 MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); 542 } else { 543 CatDInfo.ObjCCatDeclInfo.objcClass = 0; 544 CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); 545 } 546 CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); 547 CatDInfo.ObjCCatDeclInfo.protocols = 0; 548 549 return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); 550} 551 552bool IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) { 553 DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(), 554 D->isThisDeclarationADefinition()); 555 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 556} 557 558bool IndexingContext::handleSynthesizedObjCProperty( 559 const ObjCPropertyImplDecl *D) { 560 ObjCPropertyDecl *PD = D->getPropertyDecl(); 561 return handleReference(PD, D->getLocation(), getCursor(D), 0, D->getDeclContext()); 562} 563 564bool IndexingContext::handleSynthesizedObjCMethod(const ObjCMethodDecl *D, 565 SourceLocation Loc, 566 const DeclContext *LexicalDC) { 567 DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true, 568 /*isContainer=*/false); 569 return handleDecl(D, Loc, getCursor(D), DInfo, LexicalDC); 570} 571 572bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) { 573 ScratchAlloc SA(*this); 574 575 ObjCPropertyDeclInfo DInfo; 576 EntityInfo GetterEntity; 577 EntityInfo SetterEntity; 578 579 DInfo.ObjCPropDeclInfo.declInfo = &DInfo; 580 581 if (ObjCMethodDecl *Getter = D->getGetterMethodDecl()) { 582 getEntityInfo(Getter, GetterEntity, SA); 583 DInfo.ObjCPropDeclInfo.getter = &GetterEntity; 584 } else { 585 DInfo.ObjCPropDeclInfo.getter = 0; 586 } 587 if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) { 588 getEntityInfo(Setter, SetterEntity, SA); 589 DInfo.ObjCPropDeclInfo.setter = &SetterEntity; 590 } else { 591 DInfo.ObjCPropDeclInfo.setter = 0; 592 } 593 594 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 595} 596 597bool IndexingContext::handleNamespace(const NamespaceDecl *D) { 598 DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(), 599 /*isDefinition=*/true, 600 /*isContainer=*/true); 601 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 602} 603 604bool IndexingContext::handleClassTemplate(const ClassTemplateDecl *D) { 605 return handleCXXRecordDecl(D->getTemplatedDecl(), D); 606} 607 608bool IndexingContext::handleFunctionTemplate(const FunctionTemplateDecl *D) { 609 DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), 610 /*isDefinition=*/D->isThisDeclarationADefinition(), 611 /*isContainer=*/D->isThisDeclarationADefinition()); 612 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 613} 614 615bool IndexingContext::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) { 616 DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), 617 /*isDefinition=*/true, /*isContainer=*/false); 618 return handleDecl(D, D->getLocation(), getCursor(D), DInfo); 619} 620 621bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, 622 const NamedDecl *Parent, 623 const DeclContext *DC, 624 const Expr *E, 625 CXIdxEntityRefKind Kind) { 626 if (!D) 627 return false; 628 629 CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E), 630 const_cast<Decl*>(cast<Decl>(DC)), CXTU) 631 : getRefCursor(D, Loc); 632 return handleReference(D, Loc, Cursor, Parent, DC, E, Kind); 633} 634 635bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, 636 CXCursor Cursor, 637 const NamedDecl *Parent, 638 const DeclContext *DC, 639 const Expr *E, 640 CXIdxEntityRefKind Kind) { 641 if (!CB.indexEntityReference) 642 return false; 643 644 if (!D) 645 return false; 646 if (Loc.isInvalid()) 647 return false; 648 if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D)) 649 return false; 650 if (isNotFromSourceFile(D->getLocation())) 651 return false; 652 if (D->isImplicit() && shouldIgnoreIfImplicit(D)) 653 return false; 654 655 if (shouldSuppressRefs()) { 656 if (markEntityOccurrenceInFile(D, Loc)) 657 return false; // already occurred. 658 } 659 660 ScratchAlloc SA(*this); 661 EntityInfo RefEntity, ParentEntity; 662 getEntityInfo(D, RefEntity, SA); 663 if (!RefEntity.USR) 664 return false; 665 666 getEntityInfo(Parent, ParentEntity, SA); 667 668 ContainerInfo Container; 669 getContainerInfo(DC, Container); 670 671 CXIdxEntityRefInfo Info = { Kind, 672 Cursor, 673 getIndexLoc(Loc), 674 &RefEntity, 675 Parent ? &ParentEntity : 0, 676 &Container }; 677 CB.indexEntityReference(ClientData, &Info); 678 return true; 679} 680 681bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const { 682 if (Loc.isInvalid()) 683 return true; 684 SourceManager &SM = Ctx->getSourceManager(); 685 SourceLocation FileLoc = SM.getFileLoc(Loc); 686 FileID FID = SM.getFileID(FileLoc); 687 return SM.getFileEntryForID(FID) == 0; 688} 689 690void IndexingContext::addContainerInMap(const DeclContext *DC, 691 CXIdxClientContainer container) { 692 if (!DC) 693 return; 694 695 ContainerMapTy::iterator I = ContainerMap.find(DC); 696 if (I == ContainerMap.end()) { 697 if (container) 698 ContainerMap[DC] = container; 699 return; 700 } 701 // Allow changing the container of a previously seen DeclContext so we 702 // can handle invalid user code, like a function re-definition. 703 if (container) 704 I->second = container; 705 else 706 ContainerMap.erase(I); 707} 708 709CXIdxClientEntity IndexingContext::getClientEntity(const Decl *D) const { 710 if (!D) 711 return 0; 712 EntityMapTy::const_iterator I = EntityMap.find(D); 713 if (I == EntityMap.end()) 714 return 0; 715 return I->second; 716} 717 718void IndexingContext::setClientEntity(const Decl *D, CXIdxClientEntity client) { 719 if (!D) 720 return; 721 EntityMap[D] = client; 722} 723 724bool IndexingContext::handleCXXRecordDecl(const CXXRecordDecl *RD, 725 const NamedDecl *OrigD) { 726 if (RD->isThisDeclarationADefinition()) { 727 ScratchAlloc SA(*this); 728 CXXClassDeclInfo CXXDInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), 729 /*isDefinition=*/RD->isThisDeclarationADefinition()); 730 CXXBasesListInfo BaseList(RD, *this, SA); 731 CXXDInfo.CXXClassInfo.declInfo = &CXXDInfo; 732 CXXDInfo.CXXClassInfo.bases = BaseList.getBases(); 733 CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases(); 734 735 if (shouldSuppressRefs()) { 736 // Go through bases and mark them as referenced. 737 for (unsigned i = 0, e = BaseList.getNumBases(); i != e; ++i) { 738 const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i]; 739 if (baseInfo->base) { 740 const NamedDecl *BaseD = BaseList.BaseEntities[i].Dcl; 741 SourceLocation 742 Loc = SourceLocation::getFromRawEncoding(baseInfo->loc.int_data); 743 markEntityOccurrenceInFile(BaseD, Loc); 744 } 745 } 746 } 747 748 return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), CXXDInfo); 749 } 750 751 DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), 752 /*isDefinition=*/RD->isThisDeclarationADefinition(), 753 /*isContainer=*/RD->isThisDeclarationADefinition()); 754 return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo); 755} 756 757bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D, 758 SourceLocation Loc) { 759 if (!D || Loc.isInvalid()) 760 return true; 761 762 SourceManager &SM = Ctx->getSourceManager(); 763 D = getEntityDecl(D); 764 765 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc)); 766 FileID FID = LocInfo.first; 767 if (FID.isInvalid()) 768 return true; 769 770 const FileEntry *FE = SM.getFileEntryForID(FID); 771 if (!FE) 772 return true; 773 RefFileOccurence RefOccur(FE, D); 774 std::pair<llvm::DenseSet<RefFileOccurence>::iterator, bool> 775 res = RefFileOccurences.insert(RefOccur); 776 if (!res.second) 777 return true; // already in map. 778 779 return false; 780} 781 782const NamedDecl *IndexingContext::getEntityDecl(const NamedDecl *D) const { 783 assert(D); 784 D = cast<NamedDecl>(D->getCanonicalDecl()); 785 786 if (const ObjCImplementationDecl * 787 ImplD = dyn_cast<ObjCImplementationDecl>(D)) { 788 return getEntityDecl(ImplD->getClassInterface()); 789 790 } else if (const ObjCCategoryImplDecl * 791 CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) { 792 return getEntityDecl(CatImplD->getCategoryDecl()); 793 } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 794 if (FunctionTemplateDecl *TemplD = FD->getDescribedFunctionTemplate()) 795 return getEntityDecl(TemplD); 796 } else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { 797 if (ClassTemplateDecl *TemplD = RD->getDescribedClassTemplate()) 798 return getEntityDecl(TemplD); 799 } 800 801 return D; 802} 803 804const DeclContext * 805IndexingContext::getEntityContainer(const Decl *D) const { 806 const DeclContext *DC = dyn_cast<DeclContext>(D); 807 if (DC) 808 return DC; 809 810 if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) { 811 DC = ClassTempl->getTemplatedDecl(); 812 } if (const FunctionTemplateDecl * 813 FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) { 814 DC = FuncTempl->getTemplatedDecl(); 815 } 816 817 return DC; 818} 819 820CXIdxClientContainer 821IndexingContext::getClientContainerForDC(const DeclContext *DC) const { 822 if (!DC) 823 return 0; 824 825 ContainerMapTy::const_iterator I = ContainerMap.find(DC); 826 if (I == ContainerMap.end()) 827 return 0; 828 829 return I->second; 830} 831 832CXIdxClientFile IndexingContext::getIndexFile(const FileEntry *File) { 833 if (!File) 834 return 0; 835 836 FileMapTy::iterator FI = FileMap.find(File); 837 if (FI != FileMap.end()) 838 return FI->second; 839 840 return 0; 841} 842 843CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const { 844 CXIdxLoc idxLoc = { {0, 0}, 0 }; 845 if (Loc.isInvalid()) 846 return idxLoc; 847 848 idxLoc.ptr_data[0] = (void*)this; 849 idxLoc.int_data = Loc.getRawEncoding(); 850 return idxLoc; 851} 852 853void IndexingContext::translateLoc(SourceLocation Loc, 854 CXIdxClientFile *indexFile, CXFile *file, 855 unsigned *line, unsigned *column, 856 unsigned *offset) { 857 if (Loc.isInvalid()) 858 return; 859 860 SourceManager &SM = Ctx->getSourceManager(); 861 Loc = SM.getFileLoc(Loc); 862 863 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); 864 FileID FID = LocInfo.first; 865 unsigned FileOffset = LocInfo.second; 866 867 if (FID.isInvalid()) 868 return; 869 870 const FileEntry *FE = SM.getFileEntryForID(FID); 871 if (indexFile) 872 *indexFile = getIndexFile(FE); 873 if (file) 874 *file = (void *)FE; 875 if (line) 876 *line = SM.getLineNumber(FID, FileOffset); 877 if (column) 878 *column = SM.getColumnNumber(FID, FileOffset); 879 if (offset) 880 *offset = FileOffset; 881} 882 883void IndexingContext::getEntityInfo(const NamedDecl *D, 884 EntityInfo &EntityInfo, 885 ScratchAlloc &SA) { 886 if (!D) 887 return; 888 889 D = getEntityDecl(D); 890 EntityInfo.cursor = getCursor(D); 891 EntityInfo.Dcl = D; 892 EntityInfo.IndexCtx = this; 893 EntityInfo.kind = CXIdxEntity_Unexposed; 894 EntityInfo.templateKind = CXIdxEntity_NonTemplate; 895 EntityInfo.lang = CXIdxEntityLang_C; 896 897 if (D->hasAttrs()) { 898 EntityInfo.AttrList = AttrListInfo::create(D, *this); 899 EntityInfo.attributes = EntityInfo.AttrList->getAttrs(); 900 EntityInfo.numAttributes = EntityInfo.AttrList->getNumAttrs(); 901 } 902 903 if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { 904 switch (TD->getTagKind()) { 905 case TTK_Struct: 906 EntityInfo.kind = CXIdxEntity_Struct; break; 907 case TTK_Union: 908 EntityInfo.kind = CXIdxEntity_Union; break; 909 case TTK_Class: 910 EntityInfo.kind = CXIdxEntity_CXXClass; 911 EntityInfo.lang = CXIdxEntityLang_CXX; 912 break; 913 case TTK_Interface: 914 EntityInfo.kind = CXIdxEntity_CXXInterface; 915 EntityInfo.lang = CXIdxEntityLang_CXX; 916 break; 917 case TTK_Enum: 918 EntityInfo.kind = CXIdxEntity_Enum; break; 919 } 920 921 if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) 922 if (!CXXRec->isCLike()) 923 EntityInfo.lang = CXIdxEntityLang_CXX; 924 925 if (isa<ClassTemplatePartialSpecializationDecl>(D)) { 926 EntityInfo.templateKind = CXIdxEntity_TemplatePartialSpecialization; 927 } else if (isa<ClassTemplateSpecializationDecl>(D)) { 928 EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; 929 } 930 931 } else { 932 switch (D->getKind()) { 933 case Decl::Typedef: 934 EntityInfo.kind = CXIdxEntity_Typedef; break; 935 case Decl::Function: 936 EntityInfo.kind = CXIdxEntity_Function; 937 break; 938 case Decl::ParmVar: 939 EntityInfo.kind = CXIdxEntity_Variable; 940 break; 941 case Decl::Var: 942 EntityInfo.kind = CXIdxEntity_Variable; 943 if (isa<CXXRecordDecl>(D->getDeclContext())) { 944 EntityInfo.kind = CXIdxEntity_CXXStaticVariable; 945 EntityInfo.lang = CXIdxEntityLang_CXX; 946 } 947 break; 948 case Decl::Field: 949 EntityInfo.kind = CXIdxEntity_Field; 950 if (const CXXRecordDecl * 951 CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { 952 // FIXME: isPOD check is not sufficient, a POD can contain methods, 953 // we want a isCStructLike check. 954 if (!CXXRec->isPOD()) 955 EntityInfo.lang = CXIdxEntityLang_CXX; 956 } 957 break; 958 case Decl::EnumConstant: 959 EntityInfo.kind = CXIdxEntity_EnumConstant; break; 960 case Decl::ObjCInterface: 961 EntityInfo.kind = CXIdxEntity_ObjCClass; 962 EntityInfo.lang = CXIdxEntityLang_ObjC; 963 break; 964 case Decl::ObjCProtocol: 965 EntityInfo.kind = CXIdxEntity_ObjCProtocol; 966 EntityInfo.lang = CXIdxEntityLang_ObjC; 967 break; 968 case Decl::ObjCCategory: 969 EntityInfo.kind = CXIdxEntity_ObjCCategory; 970 EntityInfo.lang = CXIdxEntityLang_ObjC; 971 break; 972 case Decl::ObjCMethod: 973 if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) 974 EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod; 975 else 976 EntityInfo.kind = CXIdxEntity_ObjCClassMethod; 977 EntityInfo.lang = CXIdxEntityLang_ObjC; 978 break; 979 case Decl::ObjCProperty: 980 EntityInfo.kind = CXIdxEntity_ObjCProperty; 981 EntityInfo.lang = CXIdxEntityLang_ObjC; 982 break; 983 case Decl::ObjCIvar: 984 EntityInfo.kind = CXIdxEntity_ObjCIvar; 985 EntityInfo.lang = CXIdxEntityLang_ObjC; 986 break; 987 case Decl::Namespace: 988 EntityInfo.kind = CXIdxEntity_CXXNamespace; 989 EntityInfo.lang = CXIdxEntityLang_CXX; 990 break; 991 case Decl::NamespaceAlias: 992 EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias; 993 EntityInfo.lang = CXIdxEntityLang_CXX; 994 break; 995 case Decl::CXXConstructor: 996 EntityInfo.kind = CXIdxEntity_CXXConstructor; 997 EntityInfo.lang = CXIdxEntityLang_CXX; 998 break; 999 case Decl::CXXDestructor: 1000 EntityInfo.kind = CXIdxEntity_CXXDestructor; 1001 EntityInfo.lang = CXIdxEntityLang_CXX; 1002 break; 1003 case Decl::CXXConversion: 1004 EntityInfo.kind = CXIdxEntity_CXXConversionFunction; 1005 EntityInfo.lang = CXIdxEntityLang_CXX; 1006 break; 1007 case Decl::CXXMethod: { 1008 const CXXMethodDecl *MD = cast<CXXMethodDecl>(D); 1009 if (MD->isStatic()) 1010 EntityInfo.kind = CXIdxEntity_CXXStaticMethod; 1011 else 1012 EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; 1013 EntityInfo.lang = CXIdxEntityLang_CXX; 1014 break; 1015 } 1016 case Decl::ClassTemplate: 1017 EntityInfo.kind = CXIdxEntity_CXXClass; 1018 EntityInfo.templateKind = CXIdxEntity_Template; 1019 break; 1020 case Decl::FunctionTemplate: 1021 EntityInfo.kind = CXIdxEntity_Function; 1022 EntityInfo.templateKind = CXIdxEntity_Template; 1023 if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>( 1024 cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) { 1025 if (isa<CXXConstructorDecl>(MD)) 1026 EntityInfo.kind = CXIdxEntity_CXXConstructor; 1027 else if (isa<CXXDestructorDecl>(MD)) 1028 EntityInfo.kind = CXIdxEntity_CXXDestructor; 1029 else if (isa<CXXConversionDecl>(MD)) 1030 EntityInfo.kind = CXIdxEntity_CXXConversionFunction; 1031 else { 1032 if (MD->isStatic()) 1033 EntityInfo.kind = CXIdxEntity_CXXStaticMethod; 1034 else 1035 EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; 1036 } 1037 } 1038 break; 1039 case Decl::TypeAliasTemplate: 1040 EntityInfo.kind = CXIdxEntity_CXXTypeAlias; 1041 EntityInfo.templateKind = CXIdxEntity_Template; 1042 break; 1043 case Decl::TypeAlias: 1044 EntityInfo.kind = CXIdxEntity_CXXTypeAlias; 1045 EntityInfo.lang = CXIdxEntityLang_CXX; 1046 break; 1047 default: 1048 break; 1049 } 1050 } 1051 1052 if (EntityInfo.kind == CXIdxEntity_Unexposed) 1053 return; 1054 1055 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1056 if (FD->getTemplatedKind() == 1057 FunctionDecl::TK_FunctionTemplateSpecialization) 1058 EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; 1059 } 1060 1061 if (EntityInfo.templateKind != CXIdxEntity_NonTemplate) 1062 EntityInfo.lang = CXIdxEntityLang_CXX; 1063 1064 if (IdentifierInfo *II = D->getIdentifier()) { 1065 EntityInfo.name = SA.toCStr(II->getName()); 1066 1067 } else if (isa<TagDecl>(D) || isa<FieldDecl>(D) || isa<NamespaceDecl>(D)) { 1068 EntityInfo.name = 0; // anonymous tag/field/namespace. 1069 1070 } else { 1071 SmallString<256> StrBuf; 1072 { 1073 llvm::raw_svector_ostream OS(StrBuf); 1074 D->printName(OS); 1075 } 1076 EntityInfo.name = SA.copyCStr(StrBuf.str()); 1077 } 1078 1079 { 1080 SmallString<512> StrBuf; 1081 bool Ignore = getDeclCursorUSR(D, StrBuf); 1082 if (Ignore) { 1083 EntityInfo.USR = 0; 1084 } else { 1085 EntityInfo.USR = SA.copyCStr(StrBuf.str()); 1086 } 1087 } 1088} 1089 1090void IndexingContext::getContainerInfo(const DeclContext *DC, 1091 ContainerInfo &ContInfo) { 1092 ContInfo.cursor = getCursor(cast<Decl>(DC)); 1093 ContInfo.DC = DC; 1094 ContInfo.IndexCtx = this; 1095} 1096 1097CXCursor IndexingContext::getRefCursor(const NamedDecl *D, SourceLocation Loc) { 1098 if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) 1099 return MakeCursorTypeRef(TD, Loc, CXTU); 1100 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) 1101 return MakeCursorObjCClassRef(ID, Loc, CXTU); 1102 if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) 1103 return MakeCursorObjCProtocolRef(PD, Loc, CXTU); 1104 if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) 1105 return MakeCursorTemplateRef(Template, Loc, CXTU); 1106 if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(D)) 1107 return MakeCursorNamespaceRef(Namespace, Loc, CXTU); 1108 if (const NamespaceAliasDecl *Namespace = dyn_cast<NamespaceAliasDecl>(D)) 1109 return MakeCursorNamespaceRef(Namespace, Loc, CXTU); 1110 if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) 1111 return MakeCursorMemberRef(Field, Loc, CXTU); 1112 if (const VarDecl *Var = dyn_cast<VarDecl>(D)) 1113 return MakeCursorVariableRef(Var, Loc, CXTU); 1114 1115 return clang_getNullCursor(); 1116} 1117 1118bool IndexingContext::shouldIgnoreIfImplicit(const Decl *D) { 1119 if (isa<ObjCInterfaceDecl>(D)) 1120 return false; 1121 if (isa<ObjCCategoryDecl>(D)) 1122 return false; 1123 if (isa<ObjCIvarDecl>(D)) 1124 return false; 1125 if (isa<ObjCMethodDecl>(D)) 1126 return false; 1127 if (isa<ImportDecl>(D)) 1128 return false; 1129 return true; 1130} 1131 1132bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { 1133 if (const ClassTemplateSpecializationDecl * 1134 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { 1135 return SD->getSpecializationKind() == TSK_ImplicitInstantiation; 1136 } 1137 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1138 return FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation; 1139 } 1140 return false; 1141} 1142