Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/GuessTargetAndModeCompilationDatabase.cpp
Line
Count
Source (jump to first uncovered line)
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
//===----------------------------------------------------------------------===//
8
9
#include "clang/Tooling/CompilationDatabase.h"
10
#include "clang/Tooling/Tooling.h"
11
#include <memory>
12
13
namespace clang {
14
namespace tooling {
15
16
namespace {
17
class TargetAndModeAdderDatabase : public CompilationDatabase {
18
public:
19
  TargetAndModeAdderDatabase(std::unique_ptr<CompilationDatabase> Base)
20
23
      : Base(std::move(Base)) {
21
23
    assert(this->Base != nullptr);
22
23
  }
23
24
0
  std::vector<std::string> getAllFiles() const override {
25
0
    return Base->getAllFiles();
26
0
  }
27
28
1
  std::vector<CompileCommand> getAllCompileCommands() const override {
29
1
    return addTargetAndMode(Base->getAllCompileCommands());
30
1
  }
31
32
  std::vector<CompileCommand>
33
20
  getCompileCommands(StringRef FilePath) const override {
34
20
    return addTargetAndMode(Base->getCompileCommands(FilePath));
35
20
  }
36
37
private:
38
  std::vector<CompileCommand>
39
21
  addTargetAndMode(std::vector<CompileCommand> Cmds) const {
40
23
    for (auto &Cmd : Cmds) {
41
23
      if (Cmd.CommandLine.empty())
42
0
        continue;
43
23
      addTargetAndModeForProgramName(Cmd.CommandLine, Cmd.CommandLine.front());
44
23
    }
45
21
    return Cmds;
46
21
  }
47
  std::unique_ptr<CompilationDatabase> Base;
48
};
49
} // namespace
50
51
std::unique_ptr<CompilationDatabase>
52
23
inferTargetAndDriverMode(std::unique_ptr<CompilationDatabase> Base) {
53
23
  return std::make_unique<TargetAndModeAdderDatabase>(std::move(Base));
54
23
}
55
56
} // namespace tooling
57
} // namespace clang