From 251ad5e06b2002ae8e0a0c1b2c03f89356fb55f5 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 4 Dec 2012 07:26:44 +0000 Subject: Introduce CompilationDatabase::getAllCompileCommands() that returns all compile commands of the database and expose it via the libclang API. llvm-svn: 169226 --- clang/lib/Tooling/JSONCompilationDatabase.cpp | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'clang/lib/Tooling/JSONCompilationDatabase.cpp') diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp index cf35a256663..d54e1d86a01 100644 --- a/clang/lib/Tooling/JSONCompilationDatabase.cpp +++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp @@ -178,16 +178,8 @@ JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const { CommandsRefI = IndexByFile.find(Match); if (CommandsRefI == IndexByFile.end()) return std::vector(); - const std::vector &CommandsRef = CommandsRefI->getValue(); std::vector 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 +198,30 @@ JSONCompilationDatabase::getAllFiles() const { return Result; } +std::vector +JSONCompilationDatabase::getAllCompileCommands() const { + std::vector Commands; + for (llvm::StringMap< std::vector >::const_iterator + CommandsRefI = IndexByFile.begin(), CommandsRefEnd = IndexByFile.end(); + CommandsRefI != CommandsRefEnd; ++CommandsRefI) { + getCommands(CommandsRefI->getValue(), Commands); + } + return Commands; +} + +void JSONCompilationDatabase::getCommands( + ArrayRef CommandsRef, + std::vector &Commands) const { + 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)))); + } +} + bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { llvm::yaml::document_iterator I = YAMLStream.begin(); if (I == YAMLStream.end()) { -- cgit v1.2.3