diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-11-04 15:04:32 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-11-04 15:04:32 +0000 |
commit | b6d5e15aae202f157c6cd63da8fa4b089e7b31e9 (patch) | |
tree | 59e0e47a9831dcf0e21e547927c8ebb7e113bfd1 /tools | |
parent | 5563df30b9c8d1fe87a54baae0d6bd86642563f4 (diff) | |
download | FreeBSD-src-b6d5e15aae202f157c6cd63da8fa4b089e7b31e9.zip FreeBSD-src-b6d5e15aae202f157c6cd63da8fa4b089e7b31e9.tar.gz |
Update clang to r86025.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 106 | ||||
-rw-r--r-- | tools/CIndex/CIndex.exports | 32 | ||||
-rw-r--r-- | tools/CIndex/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 24 | ||||
-rw-r--r-- | tools/clang-cc/clang-cc.cpp | 263 | ||||
-rw-r--r-- | tools/wpa/clang-wpa.cpp | 4 |
7 files changed, 170 insertions, 265 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 64dfcfe..4798e28 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -116,6 +116,10 @@ class TUVisitor : public DeclVisitor<TUVisitor> { if (ND->getPCHLevel() > MaxPCHLevel) return; + // Filter any implicit declarations (since the source info will be bogus). + if (ND->isImplicit()) + return; + CXCursor C = { CK, ND, 0 }; Callback(TUnit, C, CData); } @@ -380,10 +384,8 @@ CXTranslationUnit clang_createTranslationUnit( CXXIdx->getOnlyLocalDecls(), /* UseBumpAllocator = */ true); - if (!ErrMsg.empty()) { - (llvm::errs() << "clang_createTranslationUnit: " << ErrMsg - << '\n').flush(); - } + if (!ErrMsg.empty()) + llvm::errs() << "clang_createTranslationUnit: " << ErrMsg << '\n'; return TU; } @@ -436,8 +438,9 @@ CXTranslationUnit clang_createTranslationUnitFromSourceFile( // Add the null terminator. argv.push_back(NULL); -#ifndef LLVM_ON_WIN32 - llvm::sys::Path DevNull("/dev/null"); + // Invoke 'clang'. + llvm::sys::Path DevNull; // leave empty, causes redirection to /dev/null + // on Unix or NUL (Windows). std::string ErrMsg; const llvm::sys::Path *Redirects[] = { &DevNull, &DevNull, &DevNull, NULL }; llvm::sys::Program::ExecuteAndWait(ClangPath, &argv[0], /* env */ NULL, @@ -448,16 +451,12 @@ CXTranslationUnit clang_createTranslationUnitFromSourceFile( llvm::errs() << "clang_createTranslationUnitFromSourceFile: " << ErrMsg << '\n' << "Arguments: \n"; for (std::vector<const char*>::iterator I = argv.begin(), E = argv.end(); - I!=E; ++I) - if (*I) llvm::errs() << ' ' << *I << '\n'; - - (llvm::errs() << '\n').flush(); + I!=E; ++I) { + if (*I) + llvm::errs() << ' ' << *I << '\n'; + } + llvm::errs() << '\n'; } -#else - // FIXME: I don't know what is the equivalent '/dev/null' redirect for - // Windows for this API. - llvm::sys::Program::ExecuteAndWait(ClangPath, &argv[0]); -#endif // Finally, we create the translation unit from the ast file. ASTUnit *ATU = static_cast<ASTUnit *>( @@ -550,7 +549,13 @@ const char *clang_getDeclSpelling(CXDecl AnonDecl) if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) { return OMD->getSelector().getAsString().c_str(); - } + } + if (ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND)) + // No, this isn't the same as the code below. getIdentifier() is non-virtual + // and returns different names. NamedDecl returns the class name and + // ObjCCategoryImplDecl returns the category name. + return CIMP->getIdentifier()->getNameStart(); + if (ND->getIdentifier()) return ND->getIdentifier()->getNameStart(); else @@ -576,9 +581,40 @@ unsigned clang_getDeclColumn(CXDecl AnonDecl) const char *clang_getDeclSource(CXDecl AnonDecl) { assert(AnonDecl && "Passed null CXDecl"); + FileEntry *FEnt = static_cast<FileEntry *>(clang_getDeclSourceFile(AnonDecl)); + assert (FEnt && "Cannot find FileEntry for Decl"); + return clang_getFileName(FEnt); +} + +static const FileEntry *getFileEntryFromSourceLocation(SourceManager &SMgr, + SourceLocation SLoc) +{ + FileID FID; + if (SLoc.isFileID()) + FID = SMgr.getFileID(SLoc); + else + FID = SMgr.getDecomposedSpellingLoc(SLoc).first; + return SMgr.getFileEntryForID(FID); +} + +CXFile clang_getDeclSourceFile(CXDecl AnonDecl) +{ + assert(AnonDecl && "Passed null CXDecl"); NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl); SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); - return SourceMgr.getBufferName(ND->getLocation()); + return (void *)getFileEntryFromSourceLocation(SourceMgr, ND->getLocation()); +} + +const char *clang_getFileName(CXFile SFile) { + assert(SFile && "Passed null CXFile"); + FileEntry *FEnt = static_cast<FileEntry *>(SFile); + return FEnt->getName(); +} + +time_t clang_getFileTime(CXFile SFile) { + assert(SFile && "Passed null CXFile"); + FileEntry *FEnt = static_cast<FileEntry *>(SFile); + return FEnt->getModificationTime(); } const char *clang_getCursorSpelling(CXCursor C) @@ -695,26 +731,12 @@ static enum CXCursorKind TranslateKind(Decl *D) { // // CXCursor Operations. // -void clang_initCXLookupHint(CXLookupHint *hint) { - memset(hint, 0, sizeof(*hint)); -} - CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name, - unsigned line, unsigned column) { - return clang_getCursorWithHint(CTUnit, source_name, line, column, NULL); -} - -CXCursor clang_getCursorWithHint(CXTranslationUnit CTUnit, - const char *source_name, - unsigned line, unsigned column, - CXLookupHint *hint) + unsigned line, unsigned column) { assert(CTUnit && "Passed null CXTranslationUnit"); ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); - // FIXME: Make this better. - CXDecl RelativeToDecl = hint ? hint->decl : NULL; - FileManager &FMgr = CXXUnit->getFileManager(); const FileEntry *File = FMgr.getFile(source_name, source_name+strlen(source_name)); @@ -725,9 +747,13 @@ CXCursor clang_getCursorWithHint(CXTranslationUnit CTUnit, SourceLocation SLoc = CXXUnit->getSourceManager().getLocation(File, line, column); - ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc, - static_cast<NamedDecl *>(RelativeToDecl)); - + ASTLocation LastLoc = CXXUnit->getLastASTLocation(); + + ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc, + &LastLoc); + if (ALoc.isValid()) + CXXUnit->setLastASTLocation(ALoc); + Decl *Dcl = ALoc.getParentDecl(); if (ALoc.isNamedRef()) Dcl = ALoc.AsNamedRef().ND; @@ -935,6 +961,16 @@ const char *clang_getCursorSource(CXCursor C) return Buffer->getBufferIdentifier(); } +CXFile clang_getCursorSourceFile(CXCursor C) +{ + assert(C.decl && "CXCursor has null decl"); + NamedDecl *ND = static_cast<NamedDecl *>(C.decl); + SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); + + return (void *)getFileEntryFromSourceLocation(SourceMgr, + getLocationFromCursor(C,SourceMgr, ND)); +} + void clang_getDefinitionSpellingAndExtent(CXCursor C, const char **startBuf, const char **endBuf, diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports index e9d44a0..5f461d8 100644 --- a/tools/CIndex/CIndex.exports +++ b/tools/CIndex/CIndex.exports @@ -1,32 +1,34 @@ _clang_createIndex +_clang_createTranslationUnit +_clang_createTranslationUnitFromSourceFile _clang_disposeIndex +_clang_disposeTranslationUnit _clang_getCursor _clang_getCursorColumn _clang_getCursorDecl _clang_getCursorFromDecl _clang_getCursorKind +_clang_getCursorKindSpelling _clang_getCursorLine _clang_getCursorSource -_clang_getCursorWithHint -_clang_getDeclarationName -_clang_getDeclSpelling -_clang_getDeclLine +_clang_getCursorSourceFile +_clang_getCursorSpelling _clang_getDeclColumn +_clang_getDeclLine _clang_getDeclSource +_clang_getDeclSourceFile +_clang_getDeclSpelling +_clang_getDeclarationName +_clang_getDefinitionSpellingAndExtent _clang_getEntity _clang_getEntityFromDecl +_clang_getFileName +_clang_getFileTime +_clang_getTranslationUnitSpelling _clang_getURI -_clang_loadDeclaration -_clang_loadTranslationUnit -_clang_createTranslationUnit -_clang_createTranslationUnitFromSourceFile -_clang_disposeTranslationUnit -_clang_initCXLookupHint _clang_isDeclaration -_clang_isReference _clang_isDefinition _clang_isInvalid -_clang_getCursorSpelling -_clang_getCursorKindSpelling -_clang_getDefinitionSpellingAndExtent -_clang_getTranslationUnitSpelling +_clang_isReference +_clang_loadDeclaration +_clang_loadTranslationUnit diff --git a/tools/CIndex/CMakeLists.txt b/tools/CIndex/CMakeLists.txt index ee77c03..dd0eeea 100644 --- a/tools/CIndex/CMakeLists.txt +++ b/tools/CIndex/CMakeLists.txt @@ -26,6 +26,7 @@ if(MSVC) # windows.h doesn't compile with /Za get_target_property(NON_ANSI_COMPILE_FLAGS CIndex COMPILE_FLAGS) string(REPLACE /Za "" NON_ANSI_COMPILE_FLAGS ${NON_ANSI_COMPILE_FLAGS}) + set(NON_ANSI_COMPILE_FLAGS "${NON_ANSI_COMPILE_FLAGS} /D_CINDEX_LIB_") set_target_properties(CIndex PROPERTIES COMPILE_FLAGS ${NON_ANSI_COMPILE_FLAGS}) endif(MSVC) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index cb2aa20..222512a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -6,7 +6,4 @@ if (CLANG_BUILD_EXPERIMENTAL) add_subdirectory(wpa) endif () add_subdirectory(CIndex) -if (MSVC) -else () - add_subdirectory(c-index-test) -endif () +add_subdirectory(c-index-test) diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index cf2a706..8791ee2 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -4,7 +4,23 @@ #include <stdio.h> #include <string.h> +#ifdef _MSC_VER +char *basename(const char* path) +{ + char* base1 = (char*)strrchr(path, '/'); + char* base2 = (char*)strrchr(path, '\\'); + if (base1 && base2) + return((base1 > base2) ? base1 + 1 : base2 + 1); + else if (base1) + return(base1 + 1); + else if (base2) + return(base2 + 1); + + return((char*)path); +} +#else extern char *basename(const char *); +#endif static void PrintCursor(CXCursor Cursor) { if (clang_isInvalid(Cursor.kind)) @@ -54,7 +70,6 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, CXCursor Ref; while (startBuf < endBuf) { - CXLookupHint hint; if (*startBuf == '\n') { startBuf++; curLine++; @@ -62,11 +77,8 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, } else if (*startBuf != '\t') curColumn++; - clang_initCXLookupHint(&hint); - hint.decl = Cursor.decl; - - Ref = clang_getCursorWithHint(Unit, clang_getCursorSource(Cursor), - curLine, curColumn, &hint); + Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor), + curLine, curColumn); if (Ref.kind == CXCursor_NoDeclFound) { /* Nothing found here; that's fine. */ } else if (Ref.kind != CXCursor_FunctionDecl) { diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index f77767c..671fc35 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -26,6 +26,7 @@ #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompileOptions.h" +#include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/FixItRewriter.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/InitHeaderSearch.h" @@ -69,7 +70,6 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/System/Host.h" #include "llvm/System/Path.h" -#include "llvm/System/Process.h" #include "llvm/System/Program.h" #include "llvm/System/Signals.h" #include "llvm/Target/TargetSelect.h" @@ -106,8 +106,6 @@ static bool ResolveParsedLocation(ParsedSourceLocation &ParsedLoc, /// anything. llvm::Timer *ClangFrontendTimer = 0; -static bool HadErrors = false; - static llvm::cl::opt<bool> Verbose("v", llvm::cl::desc("Enable verbose output")); static llvm::cl::opt<bool> @@ -240,6 +238,8 @@ TokenCache("token-cache", llvm::cl::value_desc("path"), // Diagnostic Options //===----------------------------------------------------------------------===// +static DiagnosticOptions DiagOpts; + static llvm::cl::opt<bool> VerifyDiagnostics("verify", llvm::cl::desc("Verify emitted diagnostics and warnings")); @@ -283,10 +283,9 @@ MessageLength("fmessage-length", llvm::cl::value_desc("N")); static llvm::cl::opt<bool> -NoColorDiagnostic("fno-color-diagnostics", - llvm::cl::desc("Don't use colors when showing diagnostics " - "(automatically turned off if output is not a " - "terminal).")); +PrintColorDiagnostic("fcolor-diagnostics", + llvm::cl::desc("Use colors in diagnostics")); + //===----------------------------------------------------------------------===// // C++ Visualization. //===----------------------------------------------------------------------===// @@ -655,10 +654,18 @@ static llvm::cl::opt<bool> NoElideConstructors("fno-elide-constructors", llvm::cl::desc("Disable C++ copy constructor elision")); +static llvm::cl::opt<bool> +NoMergeConstants("fno-merge-all-constants", + llvm::cl::desc("Disallow merging of constants.")); + static llvm::cl::opt<std::string> TargetABI("target-abi", llvm::cl::desc("Target a particular ABI type")); +static llvm::cl::opt<std::string> +TargetTriple("triple", + llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)")); + // It might be nice to add bounds to the CommandLine library directly. struct OptLevelParser : public llvm::cl::parser<unsigned> { @@ -878,132 +885,6 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, } //===----------------------------------------------------------------------===// -// Target Triple Processing. -//===----------------------------------------------------------------------===// - -static llvm::cl::opt<std::string> -TargetTriple("triple", - llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)")); - -static llvm::cl::opt<std::string> -MacOSVersionMin("mmacosx-version-min", - llvm::cl::desc("Specify target Mac OS X version (e.g. 10.5)")); - -// If -mmacosx-version-min=10.3.9 is specified, change the triple from being -// something like powerpc-apple-darwin9 to powerpc-apple-darwin7 - -// FIXME: We should have the driver do this instead. -static void HandleMacOSVersionMin(llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) { - fprintf(stderr, - "-mmacosx-version-min only valid for darwin (Mac OS X) targets\n"); - exit(1); - } - - // Validate that MacOSVersionMin is a 'version number', starting with 10.[3-9] - if (MacOSVersionMin.size() < 4 || - MacOSVersionMin.substr(0, 3) != "10." || - !isdigit(MacOSVersionMin[3])) { - fprintf(stderr, - "-mmacosx-version-min=%s is invalid, expected something like '10.4'.\n", - MacOSVersionMin.c_str()); - exit(1); - } - - unsigned VersionNum = MacOSVersionMin[3]-'0'; - - if (VersionNum <= 4 && Triple.getArch() == llvm::Triple::x86_64) { - fprintf(stderr, - "-mmacosx-version-min=%s is invalid with -arch x86_64.\n", - MacOSVersionMin.c_str()); - exit(1); - } - - - llvm::SmallString<16> NewDarwinString; - NewDarwinString += "darwin"; - - // Turn MacOSVersionMin into a darwin number: e.g. 10.3.9 is 3 -> darwin7. - VersionNum += 4; - if (VersionNum > 9) { - NewDarwinString += '1'; - VersionNum -= 10; - } - NewDarwinString += (VersionNum+'0'); - - if (MacOSVersionMin.size() == 4) { - // "10.4" is ok. - } else if (MacOSVersionMin.size() == 6 && - MacOSVersionMin[4] == '.' && - isdigit(MacOSVersionMin[5])) { // 10.4.7 is ok. - // Add the period piece (.7) to the end of the triple. This gives us - // something like ...-darwin8.7 - NewDarwinString += '.'; - NewDarwinString += MacOSVersionMin[5]; - } else { // "10.4" is ok. 10.4x is not. - fprintf(stderr, - "-mmacosx-version-min=%s is invalid, expected something like '10.4'.\n", - MacOSVersionMin.c_str()); - exit(1); - } - - Triple.setOSName(NewDarwinString.str()); -} - -static llvm::cl::opt<std::string> -IPhoneOSVersionMin("miphoneos-version-min", - llvm::cl::desc("Specify target iPhone OS version (e.g. 2.0)")); - -// If -miphoneos-version-min=2.2 is specified, change the triple from being -// something like armv6-apple-darwin10 to armv6-apple-darwin9.2.2. We use -// 9 as the default major Darwin number, and encode the iPhone OS version -// number in the minor version and revision. - -// FIXME: We should have the driver do this instead. -static void HandleIPhoneOSVersionMin(llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) { - fprintf(stderr, - "-miphoneos-version-min only valid for darwin (Mac OS X) targets\n"); - exit(1); - } - - // Validate that IPhoneOSVersionMin is a 'version number', starting with - // [2-9].[0-9] - if (IPhoneOSVersionMin.size() != 3 || !isdigit(IPhoneOSVersionMin[0]) || - IPhoneOSVersionMin[1] != '.' || !isdigit(IPhoneOSVersionMin[2])) { - fprintf(stderr, - "-miphoneos-version-min=%s is invalid, expected something like '2.0'.\n", - IPhoneOSVersionMin.c_str()); - exit(1); - } - - // Turn IPhoneOSVersionMin into a darwin number: e.g. 2.0 is 2 -> 9.2.0 - llvm::SmallString<16> NewDarwinString; - NewDarwinString += "darwin9."; - NewDarwinString += IPhoneOSVersionMin; - Triple.setOSName(NewDarwinString.str()); -} - -/// CreateTargetTriple - Process the various options that affect the target -/// triple and build a final aggregate triple that we are compiling for. -static llvm::Triple CreateTargetTriple() { - // Initialize base triple. If a -triple option has been specified, use - // that triple. Otherwise, default to the host triple. - llvm::Triple Triple(TargetTriple); - if (Triple.getTriple().empty()) - Triple = llvm::Triple(llvm::sys::getHostTriple()); - - // If -mmacosx-version-min=10.3.9 is specified, change the triple from being - // something like powerpc-apple-darwin9 to powerpc-apple-darwin7 - if (!MacOSVersionMin.empty()) - HandleMacOSVersionMin(Triple); - else if (!IPhoneOSVersionMin.empty()) - HandleIPhoneOSVersionMin(Triple); - - return Triple; -} - -//===----------------------------------------------------------------------===// // SourceManager initialization. //===----------------------------------------------------------------------===// @@ -1056,6 +937,9 @@ static bool InitializeSourceManager(Preprocessor &PP, // -A... - Play with #assertions // -undef - Undefine all predefined macros +static llvm::cl::opt<bool> +undef_macros("undef", llvm::cl::value_desc("macro"), llvm::cl::desc("undef all system defines")); + static llvm::cl::list<std::string> D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix, llvm::cl::desc("Predefine the specified macro")); @@ -1099,8 +983,8 @@ static llvm::cl::opt<bool> nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories")); static llvm::cl::opt<bool> -nostdclanginc("nostdclanginc", - llvm::cl::desc("Disable standard clang #include directories")); +nobuiltininc("nobuiltininc", + llvm::cl::desc("Disable builtin #include directories")); // Various command line options. These four add directories to each chain. static llvm::cl::list<std::string> @@ -1240,7 +1124,7 @@ void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, Init.AddDefaultEnvVarPaths(Lang); - if (!nostdclanginc) + if (!nobuiltininc) AddClangIncludePaths(Argv0, &Init); if (!nostdinc) @@ -1367,7 +1251,7 @@ public: PreprocessorInitOptions InitOpts; InitializePreprocessorInitOptions(InitOpts); - if (InitializePreprocessor(*PP, InitOpts)) + if (InitializePreprocessor(*PP, InitOpts, undef_macros)) return 0; return PP.take(); @@ -1493,6 +1377,8 @@ static void InitializeCompileOptions(CompileOptions &Opts, Opts.DisableRedZone = DisableRedZone; Opts.NoImplicitFloat = NoImplicitFloat; + + Opts.MergeAllConstants = !NoMergeConstants; } //===----------------------------------------------------------------------===// @@ -1681,14 +1567,7 @@ public: // Output diags both where requested... Chain1.reset(Normal); // .. and to our log file. - Chain2.reset(new TextDiagnosticPrinter(*BuildLogFile, - !NoShowColumn, - !NoCaretDiagnostics, - !NoShowLocation, - PrintSourceRangeInfo, - PrintDiagnosticOption, - !NoDiagnosticsFixIt, - MessageLength)); + Chain2.reset(new TextDiagnosticPrinter(*BuildLogFile, DiagOpts)); } virtual void setLangOptions(const LangOptions *LO) { @@ -1862,8 +1741,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, Features, Context)); if (!Consumer.get()) { - fprintf(stderr, "Unexpected program action!\n"); - HadErrors = true; + PP.getDiagnostics().Report(FullSourceLoc(), + diag::err_fe_invalid_ast_action); return; } @@ -2082,25 +1961,25 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, if (InitializeSourceManager(PP, InFile)) return; } - + // If we have an ASTConsumer, run the parser with it. if (Consumer) { CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *) = 0; void *CreateCodeCompleterData = 0; - + if (!CodeCompletionAt.FileName.empty()) { // Tell the source manager to chop off the given file at a specific // line and column. - if (const FileEntry *Entry + if (const FileEntry *Entry = PP.getFileManager().getFile(CodeCompletionAt.FileName)) { // Truncate the named file at the given line/column. PP.getSourceManager().truncateFileAt(Entry, CodeCompletionAt.Line, CodeCompletionAt.Column); - + // Set up the creation routine for code-completion. CreateCodeCompleter = BuildPrintingCodeCompleter; } else { - PP.getDiagnostics().Report(FullSourceLoc(), + PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_invalid_code_complete_file) << CodeCompletionAt.FileName; } @@ -2174,11 +2053,9 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, // handles. Also, we don't want to try to erase an open file. OS.reset(); - if ((HadErrors || (PP.getDiagnostics().getNumErrors() != 0)) && - !OutPath.isEmpty()) { - // If we had errors, try to erase the output file. + // If we had errors, try to erase the output file. + if (PP.getDiagnostics().getNumErrors() && !OutPath.isEmpty()) OutPath.eraseFromDisk(); - } } /// ProcessInputFile - Process a single AST input file with the specified state. @@ -2233,11 +2110,9 @@ static void ProcessASTInputFile(const std::string &InFile, ProgActions PA, // handles. Also, we don't want to try to erase an open file. OS.reset(); - if ((HadErrors || (PP.getDiagnostics().getNumErrors() != 0)) && - !OutPath.isEmpty()) { - // If we had errors, try to erase the output file. + // If we had errors, try to erase the output file. + if (PP.getDiagnostics().getNumErrors() && !OutPath.isEmpty()) OutPath.eraseFromDisk(); - } } static llvm::cl::list<std::string> @@ -2276,6 +2151,16 @@ int main(int argc, char **argv) { if (InputFilenames.empty()) InputFilenames.push_back("-"); + // Initialize the diagnostic options. + DiagOpts.ShowColumn = !NoShowColumn; + DiagOpts.ShowLocation = !NoShowLocation; + DiagOpts.ShowCarets = !NoCaretDiagnostics; + DiagOpts.ShowFixits = !NoDiagnosticsFixIt; + DiagOpts.ShowSourceRanges = PrintSourceRangeInfo; + DiagOpts.ShowOptionNames = PrintDiagnosticOption; + DiagOpts.ShowColors = PrintColorDiagnostic; + DiagOpts.MessageLength = MessageLength; + // Create the diagnostic client for reporting errors or for // implementing -verify. llvm::OwningPtr<DiagnosticClient> DiagClient; @@ -2292,26 +2177,7 @@ int main(int argc, char **argv) { } } else if (HTMLDiag.empty()) { // Print diagnostics to stderr by default. - - // If -fmessage-length=N was not specified, determine whether this - // is a terminal and, if so, implicitly define -fmessage-length - // appropriately. - if (MessageLength.getNumOccurrences() == 0) - MessageLength.setValue(llvm::sys::Process::StandardErrColumns()); - - if (!NoColorDiagnostic) { - NoColorDiagnostic.setValue(!llvm::sys::Process::StandardErrHasColors()); - } - - DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), - !NoShowColumn, - !NoCaretDiagnostics, - !NoShowLocation, - PrintSourceRangeInfo, - PrintDiagnosticOption, - !NoDiagnosticsFixIt, - MessageLength, - !NoColorDiagnostic)); + DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), DiagOpts)); } else { DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag)); } @@ -2338,18 +2204,14 @@ int main(int argc, char **argv) { llvm::llvm_install_error_handler(LLVMErrorHandler, static_cast<void*>(&Diags)); - // -I- is a deprecated GCC feature, scan for it and reject it. - for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) { - if (I_dirs[i] == "-") { - Diags.Report(FullSourceLoc(), diag::err_pp_I_dash_not_supported); - I_dirs.erase(I_dirs.begin()+i); - --i; - } - } + // Initialize base triple. If a -triple option has been specified, use + // that triple. Otherwise, default to the host triple. + llvm::Triple Triple(TargetTriple); + if (Triple.getTriple().empty()) + Triple = llvm::Triple(llvm::sys::getHostTriple()); // Get information about the target being compiled for. - llvm::Triple Triple = CreateTargetTriple(); - llvm::OwningPtr<TargetInfo> + llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple.getTriple())); if (Target == 0) { @@ -2390,8 +2252,8 @@ int main(int argc, char **argv) { continue; } - /// Create a SourceManager object. This tracks and owns all the file - /// buffers allocated to a translation unit. + // Create a SourceManager object. This tracks and owns all the file + // buffers allocated to a translation unit. if (!SourceMgr) SourceMgr.reset(new SourceManager()); else @@ -2415,26 +2277,21 @@ int main(int argc, char **argv) { *SourceMgr.get(), HeaderInfo); llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor()); - if (!PP) continue; - // Handle generating dependencies, if requested + // Handle generating dependencies, if requested. if (!DependencyFile.empty()) { - llvm::raw_ostream *DependencyOS; if (DependencyTargets.empty()) { - // FIXME: Use a proper diagnostic - llvm::errs() << "-dependency-file requires at least one -MT option\n"; - HadErrors = true; + Diags.Report(FullSourceLoc(), diag::err_fe_dependency_file_requires_MT); continue; } std::string ErrStr; - DependencyOS = + llvm::raw_ostream *DependencyOS = new llvm::raw_fd_ostream(DependencyFile.c_str(), ErrStr); if (!ErrStr.empty()) { - // FIXME: Use a proper diagnostic - llvm::errs() << "unable to open dependency file: " + ErrStr; - HadErrors = true; + Diags.Report(FullSourceLoc(), diag::err_fe_error_opening) + << DependencyFile << ErrStr; continue; } @@ -2483,5 +2340,5 @@ int main(int argc, char **argv) { // -time-passes usable. llvm::llvm_shutdown(); - return HadErrors || (Diags.getNumErrors() != 0); + return (Diags.getNumErrors() != 0); } diff --git a/tools/wpa/clang-wpa.cpp b/tools/wpa/clang-wpa.cpp index fa2326d..346634b 100644 --- a/tools/wpa/clang-wpa.cpp +++ b/tools/wpa/clang-wpa.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/Analysis/CallGraph.h" - +#include "clang/Frontend/ASTUnit.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/TextDiagnosticBuffer.h" @@ -56,7 +56,7 @@ int main(int argc, char **argv) { CG.reset(new CallGraph()); for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i) - CG->addTU(*ASTUnits[i]); + CG->addTU(ASTUnits[i]->getASTContext()); CG->ViewCallGraph(); } |