diff options
author | svnmir <svnmir@FreeBSD.org> | 2015-08-07 23:02:56 +0000 |
---|---|---|
committer | svnmir <svnmir@FreeBSD.org> | 2015-08-07 23:02:56 +0000 |
commit | 6416b56f5a3923c6c264b46365e16718ccabf081 (patch) | |
tree | ca13cf9e2e8c2499f61f1246e455efd2804abd36 /tools/libclang/CIndex.cpp | |
parent | e7bcad327814a78ecb8d5f5545d2e3df84c67a5c (diff) | |
download | FreeBSD-src-6416b56f5a3923c6c264b46365e16718ccabf081.zip FreeBSD-src-6416b56f5a3923c6c264b46365e16718ccabf081.tar.gz |
Vendor import of clang trunk r242221:
https://llvm.org/svn/llvm-project/cfe/trunk@242221
Diffstat (limited to 'tools/libclang/CIndex.cpp')
-rw-r--r-- | tools/libclang/CIndex.cpp | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index bf5b582..6e48bab 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -29,6 +29,7 @@ #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" +#include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -53,6 +54,7 @@ #include "llvm/Support/Program.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/TargetSelect.h" #include "llvm/Support/Threading.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" @@ -916,6 +918,18 @@ bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { return false; } +bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { + // Visit the bound, if it's explicit. + if (D->hasExplicitBound()) { + if (auto TInfo = D->getTypeSourceInfo()) { + if (Visit(TInfo->getTypeLoc())) + return true; + } + } + + return false; +} + bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) { if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo()) if (Visit(TSInfo->getTypeLoc())) @@ -1021,6 +1035,9 @@ bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { TU))) return true; + if (VisitObjCTypeParamList(ND->getTypeParamList())) + return true; + ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin(); for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(), E = ND->protocol_end(); I != E; ++I, ++PL) @@ -1080,12 +1097,29 @@ bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { return false; } +bool CursorVisitor::VisitObjCTypeParamList(ObjCTypeParamList *typeParamList) { + if (!typeParamList) + return false; + + for (auto *typeParam : *typeParamList) { + // Visit the type parameter. + if (Visit(MakeCXCursor(typeParam, TU, RegionOfInterest))) + return true; + } + + return false; +} + bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { if (!D->isThisDeclarationADefinition()) { // Forward declaration is treated like a reference. return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU)); } + // Objective-C type parameters. + if (VisitObjCTypeParamList(D->getTypeParamListAsWritten())) + return true; + // Issue callbacks for super class. if (D->getSuperClass() && Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), @@ -1093,6 +1127,10 @@ bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { TU))) return true; + if (TypeSourceInfo *SuperClassTInfo = D->getSuperClassTInfo()) + if (Visit(SuperClassTInfo->getTypeLoc())) + return true; + ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(); for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I, ++PL) @@ -1486,6 +1524,11 @@ bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc())) return true; + for (unsigned I = 0, N = TL.getNumTypeArgs(); I != N; ++I) { + if (Visit(TL.getTypeArgTInfo(I)->getTypeLoc())) + return true; + } + for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), TU))) @@ -2835,7 +2878,14 @@ CXIndex clang_createIndex(int excludeDeclarationsFromPCH, // registered once. (void)*RegisterFatalErrorHandlerOnce; - CIndexer *CIdxr = new CIndexer(); + // Initialize targets for clang module support. + llvm::InitializeAllTargets(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmPrinters(); + llvm::InitializeAllAsmParsers(); + + CIndexer *CIdxr = + new CIndexer(std::make_shared<ObjectFilePCHContainerOperations>()); if (excludeDeclarationsFromPCH) CIdxr->setOnlyLocalDecls(); if (displayDiagnostics) @@ -3052,6 +3102,12 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, /*UserFilesAreVolatile=*/true, ForSerialization, &ErrUnit)); + // Early failures in LoadFromCommandLine may return with ErrUnit unset. + if (!Unit && !ErrUnit) { + PTUI->result = CXError_ASTReadError; + return; + } + if (NumErrors != Diags->getClient()->getNumErrors()) { // Make sure to check that 'Unit' is non-NULL. if (CXXIdx->getDisplayDiagnostics()) @@ -4411,7 +4467,12 @@ static enum CXChildVisitResult GetCursorVisitor(CXCursor cursor, *BestCursor = getTypeRefedCallExprCursor(*BestCursor); return CXChildVisit_Recurse; } - + + // If we already have an Objective-C superclass reference, don't + // update it further. + if (BestCursor->kind == CXCursor_ObjCSuperClassRef) + return CXChildVisit_Break; + *BestCursor = cursor; return CXChildVisit_Recurse; } @@ -5038,6 +5099,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { case Decl::ClassScopeFunctionSpecialization: case Decl::Import: case Decl::OMPThreadPrivate: + case Decl::ObjCTypeParam: return C; // Declaration kinds that don't make any sense here, but are @@ -6321,6 +6383,7 @@ static CXLanguageKind getDeclLanguage(const Decl *D) { case Decl::ObjCProperty: case Decl::ObjCPropertyImpl: case Decl::ObjCProtocol: + case Decl::ObjCTypeParam: return CXLanguage_ObjC; case Decl::CXXConstructor: case Decl::CXXConversion: |