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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user