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