/// @brief Dump a CompilationDatabase /// @param /// @param void chimera::cd_utils::dump( std::ostream &out, const clang::tooling::CompilationDatabase &database) { const CompileCommandVector commands = database.getAllCompileCommands(); if (commands.empty()) { // Maybe a FixedCompilationDatabase dump(out, database.getCompileCommands("filepath")); } else dump(out, database.getAllCompileCommands()); }
static void constructCompileCommands( CompileCommandPairs &compileCommands, const clang::tooling::CompilationDatabase &compilationDatabase, llvm::ArrayRef<std::string> sourcePaths) { for (unsigned pathIndex = 0, pathEnd = sourcePaths.size(); pathIndex != pathEnd; pathIndex++) { llvm::SmallString<1024> filePath(clang::tooling::getAbsolutePath(sourcePaths[pathIndex])); std::vector<clang::tooling::CompileCommand> compileCmdsForFile = compilationDatabase.getCompileCommands(filePath.str()); if (!compileCmdsForFile.empty()) { for (int commandsIndex = 0, commandsEnd = compileCmdsForFile.size(); commandsIndex != commandsEnd; commandsIndex++) { compileCommands.push_back( std::make_pair(filePath.str(), compileCmdsForFile[commandsIndex])); } } /* - this needs to be collected and the gathered information will be printed eventually - not here else { DEBUG({ llvm::dbgs() << "Skipping " << filePath << ". Command line not found.\n"; }); } */ } }
static void constructCompileCommands( CompileCommandPairs &compileCommands, const clang::tooling::CompilationDatabase &compilationDatabase, llvm::ArrayRef<std::string> sourcePaths) { for (const auto &sourcePath : sourcePaths) { std::string filePath(clang::tooling::getAbsolutePath(sourcePath)); std::vector<clang::tooling::CompileCommand> compileCmdsForFile = compilationDatabase.getCompileCommands(filePath); if (compileCmdsForFile.empty()) { llvm::errs() << "Skipping " << filePath << ". Compile command not found.\n"; continue; } for (auto &compileCommand : compileCmdsForFile) { compileCommands.push_back(std::make_pair(filePath, compileCommand)); } } }