[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / lib / Tooling / GuessTargetAndModeCompilationDatabase.cpp
blobb6c1c0952aca9d6e0008c720b8785ad1d594de55
1 //===- GuessTargetAndModeCompilationDatabase.cpp --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "clang/Tooling/CompilationDatabase.h"
10 #include "clang/Tooling/Tooling.h"
11 #include <memory>
13 namespace clang {
14 namespace tooling {
16 namespace {
17 class TargetAndModeAdderDatabase : public CompilationDatabase {
18 public:
19 TargetAndModeAdderDatabase(std::unique_ptr<CompilationDatabase> Base)
20 : Base(std::move(Base)) {
21 assert(this->Base != nullptr);
24 std::vector<std::string> getAllFiles() const override {
25 return Base->getAllFiles();
28 std::vector<CompileCommand> getAllCompileCommands() const override {
29 return addTargetAndMode(Base->getAllCompileCommands());
32 std::vector<CompileCommand>
33 getCompileCommands(StringRef FilePath) const override {
34 return addTargetAndMode(Base->getCompileCommands(FilePath));
37 private:
38 std::vector<CompileCommand>
39 addTargetAndMode(std::vector<CompileCommand> Cmds) const {
40 for (auto &Cmd : Cmds) {
41 if (Cmd.CommandLine.empty())
42 continue;
43 addTargetAndModeForProgramName(Cmd.CommandLine, Cmd.CommandLine.front());
45 return Cmds;
47 std::unique_ptr<CompilationDatabase> Base;
49 } // namespace
51 std::unique_ptr<CompilationDatabase>
52 inferTargetAndDriverMode(std::unique_ptr<CompilationDatabase> Base) {
53 return std::make_unique<TargetAndModeAdderDatabase>(std::move(Base));
56 } // namespace tooling
57 } // namespace clang