Coverage Report

Created: 2020-10-24 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Execution.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- lib/Tooling/Execution.cpp - Implements tool execution framework. ---===//
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/Execution.h"
10
#include "clang/Tooling/ToolExecutorPluginRegistry.h"
11
#include "clang/Tooling/Tooling.h"
12
13
LLVM_INSTANTIATE_REGISTRY(clang::tooling::ToolExecutorPluginRegistry)
14
15
namespace clang {
16
namespace tooling {
17
18
llvm::cl::opt<std::string>
19
    ExecutorName("executor", llvm::cl::desc("The name of the executor to use."),
20
                 llvm::cl::init("standalone"));
21
22
104
void InMemoryToolResults::addResult(StringRef Key, StringRef Value) {
23
104
  KVResults.push_back({Strings.save(Key), Strings.save(Value)});
24
104
}
25
26
std::vector<std::pair<llvm::StringRef, llvm::StringRef>>
27
3
InMemoryToolResults::AllKVResults() {
28
3
  return KVResults;
29
3
}
30
31
void InMemoryToolResults::forEachResult(
32
2
    llvm::function_ref<void(StringRef Key, StringRef Value)> Callback) {
33
101
  for (const auto &KV : KVResults) {
34
101
    Callback(KV.first, KV.second);
35
101
  }
36
2
}
37
38
104
void ExecutionContext::reportResult(StringRef Key, StringRef Value) {
39
104
  Results->addResult(Key, Value);
40
104
}
41
42
llvm::Error
43
4
ToolExecutor::execute(std::unique_ptr<FrontendActionFactory> Action) {
44
4
  return execute(std::move(Action), ArgumentsAdjuster());
45
4
}
46
47
llvm::Error ToolExecutor::execute(std::unique_ptr<FrontendActionFactory> Action,
48
5
                                  ArgumentsAdjuster Adjuster) {
49
5
  std::vector<
50
5
      std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
51
5
      Actions;
52
5
  Actions.emplace_back(std::move(Action), std::move(Adjuster));
53
5
  return execute(Actions);
54
5
}
55
56
namespace internal {
57
llvm::Expected<std::unique_ptr<ToolExecutor>>
58
createExecutorFromCommandLineArgsImpl(int &argc, const char **argv,
59
                                      llvm::cl::OptionCategory &Category,
60
4
                                      const char *Overview) {
61
4
  auto OptionsParser =
62
4
      CommonOptionsParser::create(argc, argv, Category, llvm::cl::ZeroOrMore,
63
4
                                  /*Overview=*/Overview);
64
4
  if (!OptionsParser)
65
1
    return OptionsParser.takeError();
66
7
  
for (const auto &TEPlugin : ToolExecutorPluginRegistry::entries())3
{
67
7
    if (TEPlugin.getName() != ExecutorName) {
68
4
      continue;
69
4
    }
70
3
    std::unique_ptr<ToolExecutorPlugin> Plugin(TEPlugin.instantiate());
71
3
    llvm::Expected<std::unique_ptr<ToolExecutor>> Executor =
72
3
        Plugin->create(*OptionsParser);
73
3
    if (!Executor) {
74
0
      return llvm::make_error<llvm::StringError>(
75
0
          llvm::Twine("Failed to create '") + TEPlugin.getName() +
76
0
              "': " + llvm::toString(Executor.takeError()) + "\n",
77
0
          llvm::inconvertibleErrorCode());
78
0
    }
79
3
    return std::move(*Executor);
80
3
  }
81
0
  return llvm::make_error<llvm::StringError>(
82
0
      llvm::Twine("Executor \"") + ExecutorName + "\" is not registered.",
83
0
      llvm::inconvertibleErrorCode());
84
3
}
85
} // end namespace internal
86
87
llvm::Expected<std::unique_ptr<ToolExecutor>>
88
createExecutorFromCommandLineArgs(int &argc, const char **argv,
89
                                  llvm::cl::OptionCategory &Category,
90
0
                                  const char *Overview) {
91
0
  return internal::createExecutorFromCommandLineArgsImpl(argc, argv, Category,
92
0
                                                         Overview);
93
0
}
94
95
// This anchor is used to force the linker to link in the generated object file
96
// and thus register the StandaloneToolExecutorPlugin etc.
97
extern volatile int StandaloneToolExecutorAnchorSource;
98
extern volatile int AllTUsToolExecutorAnchorSource;
99
static int LLVM_ATTRIBUTE_UNUSED StandaloneToolExecutorAnchorDest =
100
    StandaloneToolExecutorAnchorSource;
101
static int LLVM_ATTRIBUTE_UNUSED AllTUsToolExecutorAnchorDest =
102
    AllTUsToolExecutorAnchorSource;
103
104
} // end namespace tooling
105
} // end namespace clang