diff options
Diffstat (limited to 'lib/Tooling')
-rw-r--r-- | lib/Tooling/CommonOptionsParser.cpp | 4 | ||||
-rw-r--r-- | lib/Tooling/CompilationDatabase.cpp | 11 | ||||
-rw-r--r-- | lib/Tooling/FileMatchTrie.cpp | 4 | ||||
-rw-r--r-- | lib/Tooling/JSONCompilationDatabase.cpp | 94 | ||||
-rw-r--r-- | lib/Tooling/Refactoring.cpp | 75 | ||||
-rw-r--r-- | lib/Tooling/Tooling.cpp | 43 |
6 files changed, 132 insertions, 99 deletions
diff --git a/lib/Tooling/CommonOptionsParser.cpp b/lib/Tooling/CommonOptionsParser.cpp index 15091c7..99aff9f 100644 --- a/lib/Tooling/CommonOptionsParser.cpp +++ b/lib/Tooling/CommonOptionsParser.cpp @@ -38,8 +38,8 @@ const char *const CommonOptionsParser::HelpMessage = "\tFor example, it can be a CMake build directory in which a file named\n" "\tcompile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\n" "\tCMake option to get this output). When no build path is specified,\n" - "\tclang-check will attempt to locate it automatically using all parent\n" - "\tpaths of the first input file. See:\n" + "\ta search for compile_commands.json will be attempted through all\n" + "\tparent paths of the first input file . See:\n" "\thttp://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an\n" "\texample of setting up Clang Tooling on a source tree.\n" "\n" diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 4149cda..b5b99cb 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -12,13 +12,13 @@ // //===----------------------------------------------------------------------===// -#include <sstream> #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/CompilationDatabasePluginRegistry.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" #include "llvm/Support/system_error.h" +#include <sstream> namespace clang { namespace tooling { @@ -72,7 +72,7 @@ findCompilationDatabaseFromDirectory(StringRef Directory, CompilationDatabase * CompilationDatabase::autoDetectFromSource(StringRef SourceFile, std::string &ErrorMessage) { - llvm::SmallString<1024> AbsolutePath(getAbsolutePath(SourceFile)); + SmallString<1024> AbsolutePath(getAbsolutePath(SourceFile)); StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); CompilationDatabase *DB = findCompilationDatabaseFromDirectory(Directory, @@ -87,7 +87,7 @@ CompilationDatabase::autoDetectFromSource(StringRef SourceFile, CompilationDatabase * CompilationDatabase::autoDetectFromDirectory(StringRef SourceDir, std::string &ErrorMessage) { - llvm::SmallString<1024> AbsolutePath(getAbsolutePath(SourceDir)); + SmallString<1024> AbsolutePath(getAbsolutePath(SourceDir)); CompilationDatabase *DB = findCompilationDatabaseFromDirectory(AbsolutePath, ErrorMessage); @@ -132,6 +132,11 @@ FixedCompilationDatabase::getAllFiles() const { return std::vector<std::string>(); } +std::vector<CompileCommand> +FixedCompilationDatabase::getAllCompileCommands() const { + return std::vector<CompileCommand>(); +} + // This anchor is used to force the linker to link in the generated object file // and thus register the JSONCompilationDatabasePlugin. extern volatile int JSONAnchorSource; diff --git a/lib/Tooling/FileMatchTrie.cpp b/lib/Tooling/FileMatchTrie.cpp index 8f25a8c..5eb4bb9 100644 --- a/lib/Tooling/FileMatchTrie.cpp +++ b/lib/Tooling/FileMatchTrie.cpp @@ -11,12 +11,12 @@ // //===----------------------------------------------------------------------===// -#include <sstream> #include "clang/Tooling/FileMatchTrie.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/PathV2.h" #include "llvm/Support/raw_ostream.h" +#include <sstream> namespace clang { namespace tooling { @@ -172,7 +172,7 @@ void FileMatchTrie::insert(StringRef NewPath) { } StringRef FileMatchTrie::findEquivalent(StringRef FileName, - llvm::raw_ostream &Error) const { + raw_ostream &Error) const { if (llvm::sys::path::is_relative(FileName)) { Error << "Cannot resolve relative paths"; return StringRef(); diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp index cf35a25..254b069 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "clang/Tooling/JSONCompilationDatabase.h" - #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/CompilationDatabasePluginRegistry.h" #include "clang/Tooling/Tooling.h" @@ -50,7 +49,9 @@ class CommandLineArgumentParser { bool parseStringInto(std::string &String) { do { if (*Position == '"') { - if (!parseQuotedStringInto(String)) return false; + if (!parseDoubleQuotedStringInto(String)) return false; + } else if (*Position == '\'') { + if (!parseSingleQuotedStringInto(String)) return false; } else { if (!parseFreeStringInto(String)) return false; } @@ -58,7 +59,7 @@ class CommandLineArgumentParser { return true; } - bool parseQuotedStringInto(std::string &String) { + bool parseDoubleQuotedStringInto(std::string &String) { if (!next()) return false; while (*Position != '"') { if (!skipEscapeCharacter()) return false; @@ -68,12 +69,21 @@ class CommandLineArgumentParser { return next(); } + bool parseSingleQuotedStringInto(std::string &String) { + if (!next()) return false; + while (*Position != '\'') { + String.push_back(*Position); + if (!next()) return false; + } + return next(); + } + bool parseFreeStringInto(std::string &String) { do { if (!skipEscapeCharacter()) return false; String.push_back(*Position); if (!next()) return false; - } while (*Position != ' ' && *Position != '"'); + } while (*Position != ' ' && *Position != '"' && *Position != '\''); return true; } @@ -112,9 +122,9 @@ std::vector<std::string> unescapeCommandLine( class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin { virtual CompilationDatabase *loadFromDirectory( StringRef Directory, std::string &ErrorMessage) { - llvm::SmallString<1024> JSONDatabasePath(Directory); + SmallString<1024> JSONDatabasePath(Directory); llvm::sys::path::append(JSONDatabasePath, "compile_commands.json"); - llvm::OwningPtr<CompilationDatabase> Database( + OwningPtr<CompilationDatabase> Database( JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage)); if (!Database) return NULL; @@ -134,14 +144,14 @@ volatile int JSONAnchorSource = 0; JSONCompilationDatabase * JSONCompilationDatabase::loadFromFile(StringRef FilePath, std::string &ErrorMessage) { - llvm::OwningPtr<llvm::MemoryBuffer> DatabaseBuffer; + OwningPtr<llvm::MemoryBuffer> DatabaseBuffer; llvm::error_code Result = llvm::MemoryBuffer::getFile(FilePath, DatabaseBuffer); if (Result != 0) { ErrorMessage = "Error while opening JSON database: " + Result.message(); return NULL; } - llvm::OwningPtr<JSONCompilationDatabase> Database( + OwningPtr<JSONCompilationDatabase> Database( new JSONCompilationDatabase(DatabaseBuffer.take())); if (!Database->parse(ErrorMessage)) return NULL; @@ -151,10 +161,10 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath, JSONCompilationDatabase * JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage) { - llvm::OwningPtr<llvm::MemoryBuffer> DatabaseBuffer( + OwningPtr<llvm::MemoryBuffer> DatabaseBuffer( llvm::MemoryBuffer::getMemBuffer(DatabaseString)); - llvm::OwningPtr<JSONCompilationDatabase> Database( - new JSONCompilationDatabase(DatabaseBuffer.take())); + OwningPtr<JSONCompilationDatabase> Database( + new JSONCompilationDatabase(DatabaseBuffer.take())); if (!Database->parse(ErrorMessage)) return NULL; return Database.take(); @@ -162,32 +172,20 @@ JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString, std::vector<CompileCommand> JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const { - llvm::SmallString<128> NativeFilePath; + SmallString<128> NativeFilePath; llvm::sys::path::native(FilePath, NativeFilePath); std::vector<StringRef> PossibleMatches; std::string Error; llvm::raw_string_ostream ES(Error); StringRef Match = MatchTrie.findEquivalent(NativeFilePath.str(), ES); - if (Match.empty()) { - if (Error.empty()) - Error = "No match found."; - llvm::outs() << Error << "\n"; + if (Match.empty()) return std::vector<CompileCommand>(); - } llvm::StringMap< std::vector<CompileCommandRef> >::const_iterator CommandsRefI = IndexByFile.find(Match); if (CommandsRefI == IndexByFile.end()) return std::vector<CompileCommand>(); - const std::vector<CompileCommandRef> &CommandsRef = CommandsRefI->getValue(); std::vector<CompileCommand> Commands; - for (int I = 0, E = CommandsRef.size(); I != E; ++I) { - llvm::SmallString<8> DirectoryStorage; - llvm::SmallString<1024> CommandStorage; - Commands.push_back(CompileCommand( - // FIXME: Escape correctly: - CommandsRef[I].first->getValue(DirectoryStorage), - unescapeCommandLine(CommandsRef[I].second->getValue(CommandStorage)))); - } + getCommands(CommandsRefI->getValue(), Commands); return Commands; } @@ -206,6 +204,30 @@ JSONCompilationDatabase::getAllFiles() const { return Result; } +std::vector<CompileCommand> +JSONCompilationDatabase::getAllCompileCommands() const { + std::vector<CompileCommand> Commands; + for (llvm::StringMap< std::vector<CompileCommandRef> >::const_iterator + CommandsRefI = IndexByFile.begin(), CommandsRefEnd = IndexByFile.end(); + CommandsRefI != CommandsRefEnd; ++CommandsRefI) { + getCommands(CommandsRefI->getValue(), Commands); + } + return Commands; +} + +void JSONCompilationDatabase::getCommands( + ArrayRef<CompileCommandRef> CommandsRef, + std::vector<CompileCommand> &Commands) const { + for (int I = 0, E = CommandsRef.size(); I != E; ++I) { + SmallString<8> DirectoryStorage; + SmallString<1024> CommandStorage; + Commands.push_back(CompileCommand( + // FIXME: Escape correctly: + CommandsRef[I].first->getValue(DirectoryStorage), + unescapeCommandLine(CommandsRef[I].second->getValue(CommandStorage)))); + } +} + bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { llvm::yaml::document_iterator I = YAMLStream.begin(); if (I == YAMLStream.end()) { @@ -217,8 +239,7 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { ErrorMessage = "Error while parsing YAML."; return false; } - llvm::yaml::SequenceNode *Array = - llvm::dyn_cast<llvm::yaml::SequenceNode>(Root); + llvm::yaml::SequenceNode *Array = dyn_cast<llvm::yaml::SequenceNode>(Root); if (Array == NULL) { ErrorMessage = "Expected array."; return false; @@ -226,8 +247,7 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { for (llvm::yaml::SequenceNode::iterator AI = Array->begin(), AE = Array->end(); AI != AE; ++AI) { - llvm::yaml::MappingNode *Object = - llvm::dyn_cast<llvm::yaml::MappingNode>(&*AI); + llvm::yaml::MappingNode *Object = dyn_cast<llvm::yaml::MappingNode>(&*AI); if (Object == NULL) { ErrorMessage = "Expected object."; return false; @@ -244,18 +264,18 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { return false; } llvm::yaml::ScalarNode *ValueString = - llvm::dyn_cast<llvm::yaml::ScalarNode>(Value); + dyn_cast<llvm::yaml::ScalarNode>(Value); if (ValueString == NULL) { ErrorMessage = "Expected string as value."; return false; } llvm::yaml::ScalarNode *KeyString = - llvm::dyn_cast<llvm::yaml::ScalarNode>((*KVI).getKey()); + dyn_cast<llvm::yaml::ScalarNode>((*KVI).getKey()); if (KeyString == NULL) { ErrorMessage = "Expected strings as key."; return false; } - llvm::SmallString<8> KeyStorage; + SmallString<8> KeyStorage; if (KeyString->getValue(KeyStorage) == "directory") { Directory = ValueString; } else if (KeyString->getValue(KeyStorage) == "command") { @@ -280,12 +300,12 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { ErrorMessage = "Missing key: \"directory\"."; return false; } - llvm::SmallString<8> FileStorage; + SmallString<8> FileStorage; StringRef FileName = File->getValue(FileStorage); - llvm::SmallString<128> NativeFilePath; + SmallString<128> NativeFilePath; if (llvm::sys::path::is_relative(FileName)) { - llvm::SmallString<8> DirectoryStorage; - llvm::SmallString<128> AbsolutePath( + SmallString<8> DirectoryStorage; + SmallString<128> AbsolutePath( Directory->getValue(DirectoryStorage)); llvm::sys::path::append(AbsolutePath, FileName); llvm::sys::path::native(AbsolutePath.str(), NativeFilePath); diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index c5002ef..d8440d6 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -28,18 +28,18 @@ static const char * const InvalidLocation = ""; Replacement::Replacement() : FilePath(InvalidLocation), Offset(0), Length(0) {} -Replacement::Replacement(llvm::StringRef FilePath, unsigned Offset, - unsigned Length, llvm::StringRef ReplacementText) +Replacement::Replacement(StringRef FilePath, unsigned Offset, + unsigned Length, StringRef ReplacementText) : FilePath(FilePath), Offset(Offset), Length(Length), ReplacementText(ReplacementText) {} Replacement::Replacement(SourceManager &Sources, SourceLocation Start, - unsigned Length, llvm::StringRef ReplacementText) { + unsigned Length, StringRef ReplacementText) { setFromSourceLocation(Sources, Start, Length, ReplacementText); } Replacement::Replacement(SourceManager &Sources, const CharSourceRange &Range, - llvm::StringRef ReplacementText) { + StringRef ReplacementText) { setFromSourceRange(Sources, Range, ReplacementText); } @@ -89,7 +89,7 @@ bool Replacement::Less::operator()(const Replacement &R1, void Replacement::setFromSourceLocation(SourceManager &Sources, SourceLocation Start, unsigned Length, - llvm::StringRef ReplacementText) { + StringRef ReplacementText) { const std::pair<FileID, unsigned> DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); @@ -116,7 +116,7 @@ static int getRangeSize(SourceManager &Sources, const CharSourceRange &Range) { void Replacement::setFromSourceRange(SourceManager &Sources, const CharSourceRange &Range, - llvm::StringRef ReplacementText) { + StringRef ReplacementText) { setFromSourceLocation(Sources, Sources.getSpellingLoc(Range.getBegin()), getRangeSize(Sources, Range), ReplacementText); } @@ -135,7 +135,38 @@ bool applyAllReplacements(Replacements &Replaces, Rewriter &Rewrite) { return Result; } -bool saveRewrittenFiles(Rewriter &Rewrite) { +RefactoringTool::RefactoringTool(const CompilationDatabase &Compilations, + ArrayRef<std::string> SourcePaths) + : ClangTool(Compilations, SourcePaths) {} + +Replacements &RefactoringTool::getReplacements() { return Replace; } + +int RefactoringTool::runAndSave(FrontendActionFactory *ActionFactory) { + if (int Result = run(ActionFactory)) { + return Result; + } + + LangOptions DefaultLangOptions; + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); + DiagnosticsEngine Diagnostics( + IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), + &*DiagOpts, &DiagnosticPrinter, false); + SourceManager Sources(Diagnostics, getFiles()); + Rewriter Rewrite(Sources, DefaultLangOptions); + + if (!applyAllReplacements(Rewrite)) { + llvm::errs() << "Skipped some replacements.\n"; + } + + return saveRewrittenFiles(Rewrite); +} + +bool RefactoringTool::applyAllReplacements(Rewriter &Rewrite) { + return tooling::applyAllReplacements(Replace, Rewrite); +} + +int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) { for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(), E = Rewrite.buffer_end(); I != E; ++I) { @@ -148,37 +179,11 @@ bool saveRewrittenFiles(Rewriter &Rewrite) { llvm::raw_fd_ostream FileStream( Entry->getName(), ErrorInfo, llvm::raw_fd_ostream::F_Binary); if (!ErrorInfo.empty()) - return false; + return 1; I->second.write(FileStream); FileStream.flush(); } - return true; -} - -RefactoringTool::RefactoringTool(const CompilationDatabase &Compilations, - ArrayRef<std::string> SourcePaths) - : Tool(Compilations, SourcePaths) {} - -Replacements &RefactoringTool::getReplacements() { return Replace; } - -int RefactoringTool::run(FrontendActionFactory *ActionFactory) { - int Result = Tool.run(ActionFactory); - LangOptions DefaultLangOptions; - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagnosticsEngine Diagnostics( - llvm::IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), - &*DiagOpts, &DiagnosticPrinter, false); - SourceManager Sources(Diagnostics, Tool.getFiles()); - Rewriter Rewrite(Sources, DefaultLangOptions); - if (!applyAllReplacements(Replace, Rewrite)) { - llvm::errs() << "Skipped some replacements.\n"; - } - if (!saveRewrittenFiles(Rewrite)) { - llvm::errs() << "Could not save rewritten files.\n"; - return 1; - } - return Result; + return 0; } } // end namespace tooling diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index af20254..52855f6 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -12,16 +12,17 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/ArgumentsAdjusters.h" #include "clang/Tooling/Tooling.h" -#include "clang/Tooling/CompilationDatabase.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Tool.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/Tooling/ArgumentsAdjusters.h" +#include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/raw_ostream.h" @@ -48,7 +49,7 @@ static clang::driver::Driver *newDriver(clang::DiagnosticsEngine *Diagnostics, const std::string DefaultOutputName = "a.out"; clang::driver::Driver *CompilerDriver = new clang::driver::Driver( BinaryName, llvm::sys::getDefaultTargetTriple(), - DefaultOutputName, false, *Diagnostics); + DefaultOutputName, *Diagnostics); CompilerDriver->setTitle("clang_based_tool"); return CompilerDriver; } @@ -63,7 +64,7 @@ static const clang::driver::ArgStringList *getCC1Arguments( // failed. Extract that job from the Compilation. const clang::driver::JobList &Jobs = Compilation->getJobs(); if (Jobs.size() != 1 || !isa<clang::driver::Command>(*Jobs.begin())) { - llvm::SmallString<256> error_msg; + SmallString<256> error_msg; llvm::raw_svector_ostream error_stream(error_msg); Compilation->PrintJob(error_stream, Compilation->getJobs(), "; ", true); Diagnostics->Report(clang::diag::err_fe_expected_compiler_job) @@ -121,7 +122,7 @@ bool runToolOnCodeWithArgs(clang::FrontendAction *ToolAction, const Twine &Code, } std::string getAbsolutePath(StringRef File) { - llvm::SmallString<1024> BaseDirectory; + SmallString<1024> BaseDirectory; if (const char *PWD = ::getenv("PWD")) BaseDirectory = PWD; else @@ -136,7 +137,7 @@ std::string getAbsolutePath(StringRef File) { if (RelativePath.startswith("./")) { RelativePath = RelativePath.substr(strlen("./")); } - llvm::SmallString<1024> AbsolutePath(BaseDirectory); + SmallString<1024> AbsolutePath(BaseDirectory); llvm::sys::path::append(AbsolutePath, RelativePath); llvm::sys::path::native(Twine(AbsolutePath), PathStorage); return PathStorage.str(); @@ -163,31 +164,29 @@ bool ToolInvocation::run() { TextDiagnosticPrinter DiagnosticPrinter( llvm::errs(), &*DiagOpts); DiagnosticsEngine Diagnostics( - llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), + IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, &DiagnosticPrinter, false); - const llvm::OwningPtr<clang::driver::Driver> Driver( + const OwningPtr<clang::driver::Driver> Driver( newDriver(&Diagnostics, BinaryName)); // Since the input might only be virtual, don't check whether it exists. Driver->setCheckInputsExist(false); - const llvm::OwningPtr<clang::driver::Compilation> Compilation( + const OwningPtr<clang::driver::Compilation> Compilation( Driver->BuildCompilation(llvm::makeArrayRef(Argv))); const clang::driver::ArgStringList *const CC1Args = getCC1Arguments( &Diagnostics, Compilation.get()); if (CC1Args == NULL) { return false; } - llvm::OwningPtr<clang::CompilerInvocation> Invocation( + OwningPtr<clang::CompilerInvocation> Invocation( newInvocation(&Diagnostics, *CC1Args)); - return runInvocation(BinaryName, Compilation.get(), Invocation.take(), - *CC1Args); + return runInvocation(BinaryName, Compilation.get(), Invocation.take()); } bool ToolInvocation::runInvocation( const char *BinaryName, clang::driver::Compilation *Compilation, - clang::CompilerInvocation *Invocation, - const clang::driver::ArgStringList &CC1Args) { + clang::CompilerInvocation *Invocation) { // Show the invocation, with -v. if (Invocation->getHeaderSearchOpts().Verbose) { llvm::errs() << "clang Invocation:\n"; @@ -204,11 +203,10 @@ bool ToolInvocation::runInvocation( // ToolAction can have lifetime requirements for Compiler or its members, and // we need to ensure it's deleted earlier than Compiler. So we pass it to an // OwningPtr declared after the Compiler variable. - llvm::OwningPtr<FrontendAction> ScopedToolAction(ToolAction.take()); + OwningPtr<FrontendAction> ScopedToolAction(ToolAction.take()); // Create the compilers actual diagnostics engine. - Compiler.createDiagnostics(CC1Args.size(), - const_cast<char**>(CC1Args.data())); + Compiler.createDiagnostics(); if (!Compiler.hasDiagnostics()) return false; @@ -241,7 +239,7 @@ ClangTool::ClangTool(const CompilationDatabase &Compilations, : Files((FileSystemOptions())), ArgsAdjuster(new ClangSyntaxOnlyAdjuster()) { for (unsigned I = 0, E = SourcePaths.size(); I != E; ++I) { - llvm::SmallString<1024> File(getAbsolutePath(SourcePaths[I])); + SmallString<1024> File(getAbsolutePath(SourcePaths[I])); std::vector<CompileCommand> CompileCommandsForFile = Compilations.getCompileCommands(File.str()); @@ -298,14 +296,19 @@ int ClangTool::run(FrontendActionFactory *ActionFactory) { ArgsAdjuster->Adjust(CompileCommands[I].second.CommandLine); assert(!CommandLine.empty()); CommandLine[0] = MainExecutable; - llvm::outs() << "Processing: " << File << ".\n"; + // FIXME: We need a callback mechanism for the tool writer to output a + // customized message for each file. + DEBUG({ + llvm::dbgs() << "Processing: " << File << ".\n"; + }); ToolInvocation Invocation(CommandLine, ActionFactory->create(), &Files); for (int I = 0, E = MappedFileContents.size(); I != E; ++I) { Invocation.mapVirtualFile(MappedFileContents[I].first, MappedFileContents[I].second); } if (!Invocation.run()) { - llvm::outs() << "Error while processing " << File << ".\n"; + // FIXME: Diagnostics should be used instead. + llvm::errs() << "Error while processing " << File << ".\n"; ProcessingFailed = true; } } |