diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /tools | |
parent | d7279c4c177bca357ef96ff1379fd9bc420bfe83 (diff) | |
download | src-test2-4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2.tar.gz src-test2-4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2.zip |
Notes
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 8 | ||||
-rw-r--r-- | tools/c-index-test/Makefile | 7 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 47 | ||||
-rw-r--r-- | tools/driver/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/driver/Makefile | 13 | ||||
-rw-r--r-- | tools/driver/cc1_main.cpp | 20 | ||||
-rw-r--r-- | tools/driver/cc1as_main.cpp | 9 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 41 | ||||
-rw-r--r-- | tools/libclang/CIndexCodeCompletion.cpp | 5 | ||||
-rw-r--r-- | tools/libclang/CIndexer.cpp | 1 | ||||
-rw-r--r-- | tools/libclang/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/libclang/CXCursor.cpp | 8 | ||||
-rw-r--r-- | tools/libclang/CXSourceLocation.h | 7 | ||||
-rw-r--r-- | tools/libclang/CXTypes.cpp | 39 | ||||
-rw-r--r-- | tools/libclang/Makefile | 11 | ||||
-rw-r--r-- | tools/libclang/libclang.darwin.exports | 3 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 4 | ||||
-rwxr-xr-x | tools/scan-build/ccc-analyzer | 3 |
18 files changed, 146 insertions, 84 deletions
diff --git a/tools/Makefile b/tools/Makefile index 8407dfdedde7..0202cc5bbbb0 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -7,13 +7,13 @@ # ##===----------------------------------------------------------------------===## -LEVEL := ../../.. +CLANG_LEVEL := .. DIRS := driver libclang c-index-test -include $(LEVEL)/Makefile.config +include $(CLANG_LEVEL)/../../Makefile.config -ifeq ($(OS), $(filter $(OS), Cygwin MingW)) +ifeq ($(OS), $(filter $(OS), Cygwin MingW Minix)) DIRS := $(filter-out libclang c-index-test, $(DIRS)) endif -include $(LEVEL)/Makefile.common +include $(CLANG_LEVEL)/Makefile diff --git a/tools/c-index-test/Makefile b/tools/c-index-test/Makefile index 24fed16006dd..d168df553651 100644 --- a/tools/c-index-test/Makefile +++ b/tools/c-index-test/Makefile @@ -6,18 +6,15 @@ # License. See LICENSE.TXT for details. # ##===----------------------------------------------------------------------===## -LEVEL = ../../../.. +CLANG_LEVEL := ../.. TOOLNAME = c-index-test -CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include # No plugins, optimize startup time. TOOL_NO_EXPORTS = 1 -include $(LEVEL)/Makefile.config - LINK_COMPONENTS := bitreader mc core USEDLIBS = clang.a clangIndex.a clangFrontend.a clangDriver.a clangSema.a \ clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a -include $(LLVM_SRC_ROOT)/Makefile.rules +include $(CLANG_LEVEL)/Makefile diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 4268cec1b231..4ed24b15c9d3 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -455,16 +455,29 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p, if (!clang_isInvalid(clang_getCursorKind(cursor))) { CXType T = clang_getCursorType(cursor); - CXType CT = clang_getCanonicalType(T); CXString S = clang_getTypeKindSpelling(T.kind); PrintCursor(cursor); printf(" typekind=%s", clang_getCString(S)); - if (!clang_equalTypes(T, CT)) { - CXString CS = clang_getTypeKindSpelling(CT.kind); - printf(" [canonical=%s]", clang_getCString(CS)); - clang_disposeString(CS); - } clang_disposeString(S); + /* Print the canonical type if it is different. */ + { + CXType CT = clang_getCanonicalType(T); + if (!clang_equalTypes(T, CT)) { + CXString CS = clang_getTypeKindSpelling(CT.kind); + printf(" [canonical=%s]", clang_getCString(CS)); + clang_disposeString(CS); + } + } + /* Print the return type if it exists. */ + { + CXType RT = clang_getCursorResultType(cursor); + if (RT.kind != CXType_Invalid) { + CXString RS = clang_getTypeKindSpelling(RT.kind); + printf(" [result=%s]", clang_getCString(RS)); + clang_disposeString(RS); + } + } + printf("\n"); } return CXChildVisit_Recurse; @@ -786,7 +799,7 @@ void print_completion_result(CXCompletionResult *completion_result, clang_getCompletionPriority(completion_result->CompletionString)); } -int perform_code_completion(int argc, const char **argv) { +int perform_code_completion(int argc, const char **argv, int timing_only) { const char *input = argv[1]; char *filename = 0; unsigned line; @@ -797,7 +810,11 @@ int perform_code_completion(int argc, const char **argv) { int num_unsaved_files = 0; CXCodeCompleteResults *results = 0; - input += strlen("-code-completion-at="); + if (timing_only) + input += strlen("-code-completion-timing="); + else + input += strlen("-code-completion-at="); + if ((errorCode = parse_file_line_column(input, &filename, &line, &column, 0, 0))) return errorCode; @@ -814,8 +831,9 @@ int perform_code_completion(int argc, const char **argv) { if (results) { unsigned i, n = results->NumResults; - for (i = 0; i != n; ++i) - print_completion_result(results->Results + i, stdout); + if (!timing_only) + for (i = 0; i != n; ++i) + print_completion_result(results->Results + i, stdout); n = clang_codeCompleteGetNumDiagnostics(results); for (i = 0; i != n; ++i) { CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i); @@ -1191,6 +1209,7 @@ static CXCursorVisitor GetVisitor(const char *s) { static void print_usage(void) { fprintf(stderr, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n" + " c-index-test -code-completion-timing=<site> <compiler arguments>\n" " c-index-test -cursor-at=<site> <compiler arguments>\n" " c-index-test -test-file-scan <AST file> <source file> " "[FileCheck prefix]\n" @@ -1198,9 +1217,9 @@ static void print_usage(void) { "[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> " "[FileCheck prefix]\n" - " c-index-test -test-load-source <symbol filter> {<args>}*\n" - " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"); + " c-index-test -test-load-source <symbol filter> {<args>}*\n"); fprintf(stderr, + " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n" " c-index-test -test-annotate-tokens=<range> {<args>}*\n" " c-index-test -test-inclusion-stack-source {<args>}*\n" " c-index-test -test-inclusion-stack-tu <AST file>\n" @@ -1222,7 +1241,9 @@ static void print_usage(void) { int main(int argc, const char **argv) { clang_enableStackTraces(); if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1]) - return perform_code_completion(argc, argv); + return perform_code_completion(argc, argv, 0); + if (argc > 2 && strstr(argv[1], "-code-completion-timing=") == argv[1]) + return perform_code_completion(argc, argv, 1); if (argc > 2 && strstr(argv[1], "-cursor-at=") == argv[1]) return inspect_cursor_at(argc, argv); else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) { diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 706f05051c52..0eaddba4739d 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -16,6 +16,7 @@ set( LLVM_USED_LIBS set( LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} + asmparser bitreader bitwriter codegen diff --git a/tools/driver/Makefile b/tools/driver/Makefile index f88d229d00c1..b049af64bbf4 100644 --- a/tools/driver/Makefile +++ b/tools/driver/Makefile @@ -6,7 +6,7 @@ # License. See LICENSE.TXT for details. # ##===----------------------------------------------------------------------===## -LEVEL = ../../../.. +CLANG_LEVEL := ../.. TOOLNAME = clang ifndef CLANG_IS_PRODUCTION @@ -16,22 +16,19 @@ else TOOLALIAS = clang++ endif endif -CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include - -# Clang tool has no plugins, optimize startup time. -TOOL_NO_EXPORTS = 1 # Include this here so we can get the configuration of the targets that have # been configured for construction. We have to do this early so we can set up # LINK_COMPONENTS before including Makefile.rules -include $(LEVEL)/Makefile.config +include $(CLANG_LEVEL)/../../Makefile.config -LINK_COMPONENTS := $(TARGETS_TO_BUILD) bitreader bitwriter codegen ipo selectiondag +LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \ + ipo selectiondag USEDLIBS = clangFrontend.a clangDriver.a clangCodeGen.a clangSema.a \ clangChecker.a clangAnalysis.a clangRewrite.a clangAST.a \ clangParse.a clangLex.a clangBasic.a -include $(LLVM_SRC_ROOT)/Makefile.rules +include $(CLANG_LEVEL)/Makefile # Translate make variable to define when building a "production" clang. ifdef CLANG_IS_PRODUCTION diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index ac19e9393c5b..841e40abfc75 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -14,12 +14,13 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/Diagnostic.h" +#include "clang/Checker/FrontendActions.h" +#include "clang/CodeGen/CodeGenAction.h" #include "clang/Driver/Arg.h" #include "clang/Driver/ArgList.h" #include "clang/Driver/CC1Options.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/OptTable.h" -#include "clang/Frontend/CodeGenAction.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" @@ -27,6 +28,7 @@ #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/Rewrite/FrontendActions.h" #include "llvm/LLVMContext.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/Statistic.h" @@ -83,21 +85,15 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { case ParseSyntaxOnly: return new SyntaxOnlyAction(); case PluginAction: { - if (CI.getFrontendOpts().ActionName == "help") { - llvm::errs() << "clang -cc1 plugins:\n"; - for (FrontendPluginRegistry::iterator it = - FrontendPluginRegistry::begin(), - ie = FrontendPluginRegistry::end(); - it != ie; ++it) - llvm::errs() << " " << it->getName() << " - " << it->getDesc() << "\n"; - return 0; - } for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); it != ie; ++it) { - if (it->getName() == CI.getFrontendOpts().ActionName) - return it->instantiate(); + if (it->getName() == CI.getFrontendOpts().ActionName) { + PluginASTAction* plugin = it->instantiate(); + plugin->ParseArgs(CI.getFrontendOpts().PluginArgs); + return plugin; + } } CI.getDiagnostics().Report(diag::err_fe_invalid_plugin_name) diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 5f1ee092ba4f..3c5ca9213f67 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -136,7 +136,7 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, // Issue errors on unknown arguments. for (arg_iterator it = Args->filtered_begin(cc1asoptions::OPT_UNKNOWN), ie = Args->filtered_end(); it != ie; ++it) - Diags.Report(diag::err_drv_unknown_argument) << it->getAsString(*Args); + Diags.Report(diag::err_drv_unknown_argument) << (*it) ->getAsString(*Args); // Construct the invocation. @@ -154,10 +154,11 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, bool First = true; for (arg_iterator it = Args->filtered_begin(OPT_INPUT), ie = Args->filtered_end(); it != ie; ++it, First=false) { + const Arg *A = it; if (First) - Opts.InputFile = it->getValue(*Args); + Opts.InputFile = A->getValue(*Args); else - Diags.Report(diag::err_drv_unknown_argument) << it->getAsString(*Args); + Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(*Args); } } Opts.LLVMArgs = Args->getAllArgValues(OPT_mllvm); @@ -274,7 +275,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, Diagnostic &Diags) { Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get(), Opts.RelaxAll)); } - AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI); + AsmParser Parser(*TheTarget, SrcMgr, Ctx, *Str.get(), *MAI); OwningPtr<TargetAsmParser> TAP(TheTarget->createAsmParser(Parser)); if (!TAP) { Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index a077589c8f79..7f32a1c148dd 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -177,12 +177,12 @@ static RangeComparisonResult LocationCompare(SourceManager &SM, /// does the appropriate translation. CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, const LangOptions &LangOpts, - SourceRange R) { + const CharSourceRange &R) { // We want the last character in this location, so we will adjust the // location accordingly. // FIXME: How do do this with a macro instantiation location? SourceLocation EndLoc = R.getEnd(); - if (!EndLoc.isInvalid() && EndLoc.isFileID()) { + if (R.isTokenRange() && !EndLoc.isInvalid() && EndLoc.isFileID()) { unsigned Length = Lexer::MeasureTokenLength(EndLoc, SM, LangOpts); EndLoc = EndLoc.getFileLocWithOffset(Length); } @@ -517,10 +517,8 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { } bool CursorVisitor::VisitBlockDecl(BlockDecl *B) { - for (BlockDecl::param_iterator I=B->param_begin(), E=B->param_end(); I!=E;++I) - if (Decl *D = *I) - if (Visit(D)) - return true; + if (Visit(B->getSignatureAsWritten()->getTypeLoc())) + return true; return Visit(MakeCXCursor(B->getBody(), StmtParent, TU)); } @@ -672,6 +670,9 @@ bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { } bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { + if (Visit(PD->getTypeSourceInfo()->getTypeLoc())) + return true; + // FIXME: This implements a workaround with @property declarations also being // installed in the DeclContext for the @interface. Eventually this code // should be removed. @@ -1183,6 +1184,15 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, // in the actual argument list. if (source_filename) Args.push_back(source_filename); + + // Since the Clang C library is primarily used by batch tools dealing with + // (often very broken) source code, where spell-checking can have a + // significant negative impact on performance (particularly when + // precompiled headers are involved), we disable it by default. + // Note that we place this argument early in the list, so that it can be + // overridden by the caller with "-fspell-checking". + Args.push_back("-fno-spell-checking"); + Args.insert(Args.end(), command_line_args, command_line_args + num_command_line_args); Args.push_back("-Xclang"); @@ -1246,6 +1256,14 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, argv.push_back("-o"); char astTmpFile[L_tmpnam]; argv.push_back(tmpnam(astTmpFile)); + + // Since the Clang C library is primarily used by batch tools dealing with + // (often very broken) source code, where spell-checking can have a + // significant negative impact on performance (particularly when + // precompiled headers are involved), we disable it by default. + // Note that we place this argument early in the list, so that it can be + // overridden by the caller with "-fspell-checking". + argv.push_back("-fno-spell-checking"); // Remap any unsaved files to temporary files. std::vector<llvm::sys::Path> TemporaryFiles; @@ -1479,16 +1497,6 @@ CXSourceLocation clang_getRangeEnd(CXSourceRange range) { return Result; } -unsigned clang_isFromMainFile(CXSourceLocation loc) { - SourceLocation Loc = SourceLocation::getFromRawEncoding(loc.int_data); - if (!loc.ptr_data[0] || Loc.isInvalid()) - return 0; - - const SourceManager &SM = - *static_cast<const SourceManager*>(loc.ptr_data[0]); - return SM.isFromMainFile(Loc) ? 1 : 0; -} - } // end: extern "C" //===----------------------------------------------------------------------===// @@ -2048,6 +2056,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { case Decl::TemplateTemplateParm: case Decl::ObjCCategoryImpl: case Decl::ObjCImplementation: + case Decl::AccessSpec: case Decl::LinkageSpec: case Decl::ObjCPropertyImpl: case Decl::FileScopeAsm: diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 481a375fb839..277fadf683bc 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -202,7 +202,7 @@ unsigned clang_getNumCompletionChunks(CXCompletionString completion_string) { unsigned clang_getCompletionPriority(CXCompletionString completion_string) { CXStoredCodeCompletionString *CCStr = (CXStoredCodeCompletionString *)completion_string; - return CCStr? CCStr->getPriority() : CCP_Unlikely; + return CCStr? CCStr->getPriority() : unsigned(CCP_Unlikely); } static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd, @@ -291,6 +291,9 @@ CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, llvm::sys::Path ClangPath = CXXIdx->getClangPath(); argv.push_back(ClangPath.c_str()); + // Always use Clang C++ support. + argv.push_back("-ccc-clang-cxx"); + // Add the '-fsyntax-only' argument so that we only perform a basic // syntax check of the code. argv.push_back("-fsyntax-only"); diff --git a/tools/libclang/CIndexer.cpp b/tools/libclang/CIndexer.cpp index d5131ff6d869..cdf6c61a09e2 100644 --- a/tools/libclang/CIndexer.cpp +++ b/tools/libclang/CIndexer.cpp @@ -135,6 +135,7 @@ bool clang::RemapFiles(unsigned num_unsaved_files, OS.close(); if (OS.has_error()) { SavedFile.eraseFromDisk(); + OS.clear_error(); return true; } diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt index 62c973852dc1..ab4accae5e27 100644 --- a/tools/libclang/CMakeLists.txt +++ b/tools/libclang/CMakeLists.txt @@ -3,7 +3,7 @@ set(SHARED_LIBRARY TRUE) set(LLVM_NO_RTTI 1) set(LLVM_USED_LIBS - clangFrontend + clangFrontend clangDriver clangSema clangAnalysis @@ -29,7 +29,6 @@ add_clang_library(libclang CXTypes.cpp ../../include/clang-c/Index.h ) -set_target_properties(libclang PROPERTIES OUTPUT_NAME clang) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # FIXME: Deal with LLVM_SUBMIT_VERSION? diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index f7192dd7e2c8..be3623f6e9e2 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -78,9 +78,9 @@ static CXCursorKind GetCursorKind(const Attr *A) { assert(A && "Invalid arguments!"); switch (A->getKind()) { default: break; - case Attr::IBActionKind: return CXCursor_IBActionAttr; - case Attr::IBOutletKind: return CXCursor_IBOutletAttr; - case Attr::IBOutletCollectionKind: return CXCursor_IBOutletCollectionAttr; + case attr::IBAction: return CXCursor_IBActionAttr; + case attr::IBOutlet: return CXCursor_IBOutletAttr; + case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; } return CXCursor_UnexposedAttr; @@ -174,7 +174,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) { case Stmt::CXXThisExprClass: case Stmt::CXXThrowExprClass: case Stmt::CXXDefaultArgExprClass: - case Stmt::CXXZeroInitValueExprClass: + case Stmt::CXXScalarValueInitExprClass: case Stmt::CXXNewExprClass: case Stmt::CXXDeleteExprClass: case Stmt::CXXPseudoDestructorExprClass: diff --git a/tools/libclang/CXSourceLocation.h b/tools/libclang/CXSourceLocation.h index 66566c126891..7a502059634a 100644 --- a/tools/libclang/CXSourceLocation.h +++ b/tools/libclang/CXSourceLocation.h @@ -29,6 +29,9 @@ namespace cxloc { static inline CXSourceLocation translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation Loc) { + if (Loc.isInvalid()) + clang_getNullLocation(); + CXSourceLocation Result = { { (void*) &SM, (void*) &LangOpts, }, Loc.getRawEncoding() }; return Result; @@ -50,14 +53,14 @@ static inline CXSourceLocation translateSourceLocation(ASTContext &Context, /// does the appropriate translation. CXSourceRange translateSourceRange(const SourceManager &SM, const LangOptions &LangOpts, - SourceRange R); + const CharSourceRange &R); /// \brief Translate a Clang source range into a CIndex source range. static inline CXSourceRange translateSourceRange(ASTContext &Context, SourceRange R) { return translateSourceRange(Context.getSourceManager(), Context.getLangOptions(), - R); + CharSourceRange::getTokenRange(R)); } static inline SourceLocation translateSourceLocation(CXSourceLocation L) { diff --git a/tools/libclang/CXTypes.cpp b/tools/libclang/CXTypes.cpp index 137370adb200..d5c9f452100b 100644 --- a/tools/libclang/CXTypes.cpp +++ b/tools/libclang/CXTypes.cpp @@ -77,6 +77,8 @@ static CXTypeKind GetTypeKind(QualType T) { TKCASE(Typedef); TKCASE(ObjCInterface); TKCASE(ObjCObjectPointer); + TKCASE(FunctionNoProto); + TKCASE(FunctionProto); default: return CXType_Unexposed; } @@ -116,7 +118,10 @@ CXType clang_getCursorType(CXCursor C) { return MakeCXType(QualType(ID->getTypeForDecl(), 0), AU); if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) return MakeCXType(VD->getType(), AU); - + if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) + return MakeCXType(PD->getType(), AU); + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + return MakeCXType(FD->getType(), AU); return MakeCXType(QualType(), AU); } @@ -165,8 +170,15 @@ CXType clang_getPointeeType(CXType CT) { } CXCursor clang_getTypeDeclaration(CXType CT) { + if (CT.kind == CXType_Invalid) + return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound); + QualType T = GetQualType(CT); Type *TP = T.getTypePtr(); + + if (!TP) + return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound); + Decl *D = 0; switch (TP->getTypeClass()) { @@ -237,6 +249,8 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) { TKIND(Typedef); TKIND(ObjCInterface); TKIND(ObjCObjectPointer); + TKIND(FunctionNoProto); + TKIND(FunctionProto); } #undef TKIND return cxstring::createCXString(s); @@ -246,4 +260,27 @@ unsigned clang_equalTypes(CXType A, CXType B) { return A.data[0] == B.data[0] && A.data[1] == B.data[1];; } +CXType clang_getResultType(CXType X) { + QualType T = GetQualType(X); + if (!T.getTypePtr()) + return MakeCXType(QualType(), GetASTU(X)); + + if (const FunctionType *FD = T->getAs<FunctionType>()) + return MakeCXType(FD->getResultType(), GetASTU(X)); + + return MakeCXType(QualType(), GetASTU(X)); +} + +CXType clang_getCursorResultType(CXCursor C) { + if (clang_isDeclaration(C.kind)) { + Decl *D = cxcursor::getCursorDecl(C); + if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) + return MakeCXType(MD->getResultType(), cxcursor::getCursorASTUnit(C)); + + return clang_getResultType(clang_getCursorType(C)); + } + + return MakeCXType(QualType(), cxcursor::getCursorASTUnit(C)); +} + } // end: extern "C" diff --git a/tools/libclang/Makefile b/tools/libclang/Makefile index ff0fa33e41eb..253ea38c7b94 100644 --- a/tools/libclang/Makefile +++ b/tools/libclang/Makefile @@ -7,18 +7,11 @@ # ##===----------------------------------------------------------------------===## -LEVEL = ../../../.. +CLANG_LEVEL := ../.. LIBRARYNAME = clang EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/libclang.exports -CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include - -# Include this here so we can get the configuration of the targets -# that have been configured for construction. We have to do this -# early so we can set up LINK_COMPONENTS before including Makefile.rules -include $(LEVEL)/Makefile.config - LINK_LIBS_IN_SHARED = 1 SHARED_LIBRARY = 1 @@ -26,7 +19,7 @@ LINK_COMPONENTS := bitreader mc core USEDLIBS = clangFrontend.a clangDriver.a clangSema.a \ clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a -include $(LEVEL)/Makefile.common +include $(CLANG_LEVEL)/Makefile ##===----------------------------------------------------------------------===## # FIXME: This is copied from the 'lto' makefile. Should we share this? diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index a9f4f0777cdc..f21fec63f48a 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -41,6 +41,7 @@ _clang_getCursorLinkage _clang_getCursorLocation _clang_getCursorReferenced _clang_getCursorSpelling +_clang_getCursorResultType _clang_getCursorType _clang_getCursorUSR _clang_getDefinitionSpellingAndExtent @@ -67,6 +68,7 @@ _clang_getPointeeType _clang_getRange _clang_getRangeEnd _clang_getRangeStart +_clang_getResultType _clang_getTokenExtent _clang_getTokenKind _clang_getTokenLocation @@ -78,7 +80,6 @@ _clang_getTypeKindSpelling _clang_isCursorDefinition _clang_isDeclaration _clang_isExpression -_clang_isFromMainFile _clang_isInvalid _clang_isPreprocessing _clang_isReference diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index b09e6ac56c85..dcb40d413ca9 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -41,6 +41,7 @@ clang_getCursorLinkage clang_getCursorLocation clang_getCursorReferenced clang_getCursorSpelling +clang_getCursorResultType clang_getCursorType clang_getCursorUSR clang_getDefinitionSpellingAndExtent @@ -67,6 +68,7 @@ clang_getPointeeType clang_getRange clang_getRangeEnd clang_getRangeStart +clang_getResultType clang_getTokenExtent clang_getTokenKind clang_getTokenLocation @@ -78,7 +80,6 @@ clang_getTypeKindSpelling clang_isCursorDefinition clang_isDeclaration clang_isExpression -clang_isFromMainFile clang_isInvalid clang_isPreprocessing clang_isReference @@ -88,4 +89,3 @@ clang_isUnexposed clang_setUseExternalASTGeneration clang_tokenize clang_visitChildren - diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer index 391ea57faa23..c182a686202f 100755 --- a/tools/scan-build/ccc-analyzer +++ b/tools/scan-build/ccc-analyzer @@ -315,11 +315,13 @@ sub Analyze { my %CompileOptionMap = ( '-nostdinc' => 0, '-fblocks' => 0, + '-fno-builtin' => 0, '-fobjc-gc-only' => 0, '-fobjc-gc' => 0, '-ffreestanding' => 0, '-include' => 1, '-idirafter' => 1, + '-imacros' => 1, '-iprefix' => 1, '-iquote' => 1, '-isystem' => 1, @@ -364,6 +366,7 @@ my %IgnoredOptionMap = ( my %LangMap = ( 'c' => 'c', + 'cp' => 'c++', 'cpp' => 'c++', 'cc' => 'c++', 'i' => 'c-cpp-output', |