[tooling] Provide the compile commands of the JSON database in the order that they were provided in the JSON file.

This is useful for debugging of issues and reduction of test cases.
For example, an issue may show up due to the order that some commands were processed.
It is convenient to be able to remove commands from the file and still preserve the order
that they are returned, instead of getting a completely different order when removing a few commands.

llvm-svn: 248292
This commit is contained in:
Argyrios Kyrtzidis
2015-09-22 17:22:33 +00:00
parent 07a844d758
commit 64f67be319
3 changed files with 27 additions and 7 deletions

View File

@@ -206,11 +206,7 @@ JSONCompilationDatabase::getAllFiles() const {
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);
}
getCommands(AllCommands, Commands);
return Commands;
}
@@ -337,8 +333,9 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
} else {
llvm::sys::path::native(FileName, NativeFilePath);
}
IndexByFile[NativeFilePath].push_back(
CompileCommandRef(Directory, File, *Command));
auto Cmd = CompileCommandRef(Directory, File, *Command);
IndexByFile[NativeFilePath].push_back(Cmd);
AllCommands.push_back(Cmd);
MatchTrie.insert(NativeFilePath);
}
return true;