Introduce CompilationDatabase::getAllCompileCommands() that returns all

compile commands of the database and expose it via the libclang API.

llvm-svn: 169226
This commit is contained in:
Argyrios Kyrtzidis
2012-12-04 07:26:44 +00:00
parent 0e9acc94bc
commit 251ad5e06b
9 changed files with 116 additions and 10 deletions

View File

@@ -178,16 +178,8 @@ JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const {
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 +198,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) {
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()) {