diff options
Diffstat (limited to 'tools/libclang')
-rw-r--r-- | tools/libclang/CIndex.cpp | 114 | ||||
-rw-r--r-- | tools/libclang/CIndexCodeCompletion.cpp | 3 | ||||
-rw-r--r-- | tools/libclang/CIndexDiagnostic.cpp | 3 | ||||
-rw-r--r-- | tools/libclang/CIndexUSRs.cpp | 3 | ||||
-rw-r--r-- | tools/libclang/CIndexer.h | 3 | ||||
-rw-r--r-- | tools/libclang/CXCursor.cpp | 1 | ||||
-rw-r--r-- | tools/libclang/CXType.cpp | 7 | ||||
-rw-r--r-- | tools/libclang/libclang.darwin.exports | 2 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 2 |
9 files changed, 112 insertions, 26 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 28f1506..2a9d96d 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -30,6 +30,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/Lexer.h" +#include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/STLExtras.h" @@ -349,6 +350,7 @@ public: bool VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL); bool VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL); bool VisitTypeOfTypeLoc(TypeOfTypeLoc TL); + bool VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL); bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL); bool VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL); @@ -789,7 +791,7 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) { // FIXME: Attributes? } - if (ND->isThisDeclarationADefinition() && !ND->isLateTemplateParsed()) { + if (ND->doesThisDeclarationHaveABody() && !ND->isLateTemplateParsed()) { if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) { // Find the initializers that were written in the source. llvm::SmallVector<CXXCtorInitializer *, 4> WrittenInits; @@ -1552,6 +1554,13 @@ bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { return false; } +bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { + if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo()) + return Visit(TSInfo->getTypeLoc()); + + return false; +} + bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc())) return true; @@ -2375,10 +2384,12 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, const char * const *command_line_args, unsigned num_unsaved_files, struct CXUnsavedFile *unsaved_files) { + unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord | + CXTranslationUnit_NestedMacroInstantiations; return clang_parseTranslationUnit(CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, - CXTranslationUnit_DetailedPreprocessingRecord); + Options); } struct ParseTranslationUnitInfo { @@ -2479,9 +2490,12 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { Args->push_back(source_filename); // Do we need the detailed preprocessing record? + bool NestedMacroInstantiations = false; if (options & CXTranslationUnit_DetailedPreprocessingRecord) { Args->push_back("-Xclang"); Args->push_back("-detailed-preprocessing-record"); + NestedMacroInstantiations + = (options & CXTranslationUnit_NestedMacroInstantiations); } unsigned NumErrors = Diags->getClient()->getNumErrors(); @@ -2500,7 +2514,8 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { CompleteTranslationUnit, CacheCodeCompetionResults, CXXPrecompilePreamble, - CXXChainedPCH)); + CXXChainedPCH, + NestedMacroInstantiations)); if (NumErrors != Diags->getClient()->getNumErrors()) { // Make sure to check that 'Unit' is non-NULL. @@ -2559,8 +2574,10 @@ CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, fprintf(stderr, "}\n"); return 0; + } else if (getenv("LIBCLANG_RESOURCE_USAGE")) { + PrintLibclangResourceUsage(PTUI.result); } - + return PTUI.result; } @@ -2573,7 +2590,10 @@ int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, if (!TU) return 1; - return static_cast<ASTUnit *>(TU->TUData)->Save(FileName); + int result = static_cast<ASTUnit *>(TU->TUData)->Save(FileName); + if (getenv("LIBCLANG_RESOURCE_USAGE")) + PrintLibclangResourceUsage(TU); + return result; } void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) { @@ -2649,8 +2669,8 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU, fprintf(stderr, "libclang: crash detected during reparsing\n"); static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true); return 1; - } - + } else if (getenv("LIBCLANG_RESOURCE_USAGE")) + PrintLibclangResourceUsage(TU); return RTUI.result; } @@ -2807,17 +2827,8 @@ void clang_getSpellingLocation(CXSourceLocation location, unsigned *offset) { SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); - if (!location.ptr_data[0] || Loc.isInvalid()) { - if (file) - *file = 0; - if (line) - *line = 0; - if (column) - *column = 0; - if (offset) - *offset = 0; - return; - } + if (!location.ptr_data[0] || Loc.isInvalid()) + return createNullLocation(file, line, column, offset); const SourceManager &SM = *static_cast<const SourceManager*>(location.ptr_data[0]); @@ -2835,6 +2846,9 @@ void clang_getSpellingLocation(CXSourceLocation location, FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second; + if (FID.isInvalid()) + return createNullLocation(file, line, column, offset); + if (file) *file = (void *)SM.getFileEntryForID(FID); if (line) @@ -2890,6 +2904,16 @@ CXFile clang_getFile(CXTranslationUnit tu, const char *file_name) { return const_cast<FileEntry *>(FMgr.getFile(file_name)); } +unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file) { + if (!tu || !file) + return 0; + + ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData); + FileEntry *FEnt = static_cast<FileEntry *>(file); + return CXXUnit->getPreprocessor().getHeaderSearchInfo() + .isFileMultipleIncludeGuarded(FEnt); +} + } // end: extern "C" //===----------------------------------------------------------------------===// @@ -3357,7 +3381,11 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { case CXCursor_UsingDeclaration: return createCXString("UsingDeclaration"); case CXCursor_TypeAliasDecl: - return createCXString("TypeAliasDecl"); + return createCXString("TypeAliasDecl"); + case CXCursor_ObjCSynthesizeDecl: + return createCXString("ObjCSynthesizeDecl"); + case CXCursor_ObjCDynamicDecl: + return createCXString("ObjCDynamicDecl"); } llvm_unreachable("Unhandled CXCursorKind"); @@ -3899,6 +3927,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { case Decl::Namespace: case Decl::Typedef: case Decl::TypeAlias: + case Decl::TypeAliasTemplate: case Decl::TemplateTypeParm: case Decl::EnumConstant: case Decl::Field: @@ -5169,6 +5198,19 @@ unsigned clang_CXXMethod_isStatic(CXCursor C) { return (Method && Method->isStatic()) ? 1 : 0; } +unsigned clang_CXXMethod_isVirtual(CXCursor C) { + if (!clang_isDeclaration(C.kind)) + return 0; + + CXXMethodDecl *Method = 0; + Decl *D = cxcursor::getCursorDecl(C); + if (FunctionTemplateDecl *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D)) + Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); + else + Method = dyn_cast_or_null<CXXMethodDecl>(D); + return (Method && Method->isVirtual()) ? 1 : 0; +} + } // end: extern "C" //===----------------------------------------------------------------------===// @@ -5235,6 +5277,12 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) { case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap: str = "ExternalASTSource: mmap'ed memory buffers"; break; + case CXTUResourceUsage_Preprocessor: + str = "Preprocessor: malloc'ed memory"; + break; + case CXTUResourceUsage_PreprocessingRecord: + str = "Preprocessor: PreprocessingRecord"; + break; } return str; } @@ -5269,7 +5317,7 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { unsigned long completionBytes = 0; if (GlobalCodeCompletionAllocator *completionAllocator = astUnit->getCachedCompletionAllocator().getPtr()) { - completionBytes = completionAllocator-> getTotalMemory(); + completionBytes = completionAllocator->getTotalMemory(); } createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_GlobalCompletionResults, @@ -5303,7 +5351,21 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { CXTUResourceUsage_ExternalASTSource_Membuffer_MMap, (unsigned long) sizes.mmap_bytes); } - + + // How much memory is being used by the Preprocessor? + Preprocessor &pp = astUnit->getPreprocessor(); + const llvm::BumpPtrAllocator &ppAlloc = pp.getPreprocessorAllocator(); + createCXTUResourceUsageEntry(*entries, + CXTUResourceUsage_Preprocessor, + ppAlloc.getTotalMemory()); + + if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) { + createCXTUResourceUsageEntry(*entries, + CXTUResourceUsage_PreprocessingRecord, + pRec->getTotalMemory()); + } + + CXTUResourceUsage usage = { (void*) entries.get(), (unsigned) entries->size(), entries->size() ? &(*entries)[0] : 0 }; @@ -5318,6 +5380,16 @@ void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage) { } // end extern "C" +void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) { + CXTUResourceUsage Usage = clang_getCXTUResourceUsage(TU); + for (unsigned I = 0; I != Usage.numEntries; ++I) + fprintf(stderr, " %s: %lu\n", + clang_getTUResourceUsageName(Usage.entries[I].kind), + Usage.entries[I].amount); + + clang_disposeCXTUResourceUsage(Usage); +} + //===----------------------------------------------------------------------===// // Misc. utility functions. //===----------------------------------------------------------------------===// diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index e85e802..0c8317e 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -498,7 +498,8 @@ CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, fprintf(stderr, "libclang: crash detected in code completion\n"); static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true); return 0; - } + } else if (getenv("LIBCLANG_RESOURCE_USAGE")) + PrintLibclangResourceUsage(TU); return CCAI.result; } diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp index fa3b1ce..0fcdab7 100644 --- a/tools/libclang/CIndexDiagnostic.cpp +++ b/tools/libclang/CIndexDiagnostic.cpp @@ -220,7 +220,8 @@ CXString clang_getDiagnosticOption(CXDiagnostic Diag, CXString *Disable) { return createCXString(""); unsigned ID = StoredDiag->Diag.getID(); - if (const char *Option = DiagnosticIDs::getWarningOptionForDiag(ID)) { + llvm::StringRef Option = DiagnosticIDs::getWarningOptionForDiag(ID); + if (!Option.empty()) { if (Disable) *Disable = createCXString((llvm::Twine("-Wno-") + Option).str()); return createCXString((llvm::Twine("-W") + Option).str()); diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp index 9917d2a..4f1f071 100644 --- a/tools/libclang/CIndexUSRs.cpp +++ b/tools/libclang/CIndexUSRs.cpp @@ -477,6 +477,9 @@ bool USRGenerator::GenLoc(const Decl *D) { return true; } + // Use the location of canonical decl. + D = D->getCanonicalDecl(); + const SourceManager &SM = AU->getSourceManager(); SourceLocation L = D->getLocStart(); if (L.isInvalid()) { diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h index b40891a..45d0831 100644 --- a/tools/libclang/CIndexer.h +++ b/tools/libclang/CIndexer.h @@ -77,6 +77,9 @@ namespace clang { /// \return False if a crash was detected. bool RunSafely(llvm::CrashRecoveryContext &CRC, void (*Fn)(void*), void *UserData, unsigned Size = 0); + + /// \brief Print libclang's resource usage to standard error. + void PrintLibclangResourceUsage(CXTranslationUnit TU); } #endif diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 2a78012..b34370d 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -173,6 +173,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::OpaqueValueExprClass: case Stmt::PackExpansionExprClass: case Stmt::SizeOfPackExprClass: + case Stmt::AsTypeExprClass: K = CXCursor_UnexposedExpr; break; diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 9332672..5af9553 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -379,9 +379,10 @@ CXString clang_getDeclObjCTypeEncoding(CXCursor C) { ASTContext &Ctx = AU->getASTContext(); std::string encoding; - if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) - Ctx.getObjCEncodingForMethodDecl(OMD, encoding); - else if (ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D)) + if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) { + if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding)) + return cxstring::createCXString("?"); + } else if (ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D)) Ctx.getObjCEncodingForPropertyDecl(OPD, NULL, encoding); else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) Ctx.getObjCEncodingForFunctionDecl(FD, encoding); diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index 30c3fd1..85dfcb6 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -1,6 +1,7 @@ _clang_CXCursorSet_contains _clang_CXCursorSet_insert _clang_CXXMethod_isStatic +_clang_CXXMethod_isVirtual _clang_annotateTokens _clang_codeCompleteAt _clang_codeCompleteGetDiagnostic @@ -115,6 +116,7 @@ _clang_isConstQualifiedType _clang_isCursorDefinition _clang_isDeclaration _clang_isExpression +_clang_isFileMultipleIncludeGuarded _clang_isInvalid _clang_isPODType _clang_isPreprocessing diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 4e96e8a..403cd67 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -1,6 +1,7 @@ clang_CXCursorSet_contains clang_CXCursorSet_insert clang_CXXMethod_isStatic +clang_CXXMethod_isVirtual clang_annotateTokens clang_codeCompleteAt clang_codeCompleteGetDiagnostic @@ -115,6 +116,7 @@ clang_isConstQualifiedType clang_isCursorDefinition clang_isDeclaration clang_isExpression +clang_isFileMultipleIncludeGuarded clang_isInvalid clang_isPODType clang_isPreprocessing |