Path: blob/main/contrib/llvm-project/clang/lib/Tooling/GuessTargetAndModeCompilationDatabase.cpp
35233 views
//===- GuessTargetAndModeCompilationDatabase.cpp --------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Tooling/CompilationDatabase.h"9#include "clang/Tooling/Tooling.h"10#include <memory>1112namespace clang {13namespace tooling {1415namespace {16class TargetAndModeAdderDatabase : public CompilationDatabase {17public:18TargetAndModeAdderDatabase(std::unique_ptr<CompilationDatabase> Base)19: Base(std::move(Base)) {20assert(this->Base != nullptr);21}2223std::vector<std::string> getAllFiles() const override {24return Base->getAllFiles();25}2627std::vector<CompileCommand> getAllCompileCommands() const override {28return addTargetAndMode(Base->getAllCompileCommands());29}3031std::vector<CompileCommand>32getCompileCommands(StringRef FilePath) const override {33return addTargetAndMode(Base->getCompileCommands(FilePath));34}3536private:37std::vector<CompileCommand>38addTargetAndMode(std::vector<CompileCommand> Cmds) const {39for (auto &Cmd : Cmds) {40if (Cmd.CommandLine.empty())41continue;42addTargetAndModeForProgramName(Cmd.CommandLine, Cmd.CommandLine.front());43}44return Cmds;45}46std::unique_ptr<CompilationDatabase> Base;47};48} // namespace4950std::unique_ptr<CompilationDatabase>51inferTargetAndDriverMode(std::unique_ptr<CompilationDatabase> Base) {52return std::make_unique<TargetAndModeAdderDatabase>(std::move(Base));53}5455} // namespace tooling56} // namespace clang575859