/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/diagtool/DiagTool.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DiagTool.cpp - Classes for defining diagtool tools -------------------===// |
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 | | // This file implements the boilerplate for defining diagtool tools. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "DiagTool.h" |
14 | | #include "llvm/ADT/StringMap.h" |
15 | | #include "llvm/ADT/STLExtras.h" |
16 | | #include <vector> |
17 | | |
18 | | using namespace diagtool; |
19 | | |
20 | | DiagTool::DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc) |
21 | 92 | : cmd(std::string(toolCmd)), description(std::string(toolDesc)) {} |
22 | | |
23 | 0 | DiagTool::~DiagTool() {} |
24 | | |
25 | | typedef llvm::StringMap<DiagTool *> ToolMap; |
26 | 138 | static inline ToolMap *getTools(void *v) { return static_cast<ToolMap*>(v); } |
27 | | |
28 | 23 | DiagTools::DiagTools() : tools(new ToolMap()) {} |
29 | 0 | DiagTools::~DiagTools() { delete getTools(tools); } |
30 | | |
31 | 23 | DiagTool *DiagTools::getTool(llvm::StringRef toolCmd) { |
32 | 23 | ToolMap::iterator it = getTools(tools)->find(toolCmd); |
33 | 23 | return (it == getTools(tools)->end()) ? nullptr0 : it->getValue(); |
34 | 23 | } |
35 | | |
36 | 92 | void DiagTools::registerTool(DiagTool *tool) { |
37 | 92 | (*getTools(tools))[tool->getName()] = tool; |
38 | 92 | } |
39 | | |
40 | 0 | void DiagTools::printCommands(llvm::raw_ostream &out) { |
41 | 0 | std::vector<llvm::StringRef> toolNames; |
42 | 0 | unsigned maxName = 0; |
43 | 0 | for (ToolMap::iterator it = getTools(tools)->begin(), |
44 | 0 | ei = getTools(tools)->end(); it != ei; ++it) { |
45 | 0 | toolNames.push_back(it->getKey()); |
46 | 0 | unsigned len = it->getKey().size(); |
47 | 0 | if (len > maxName) |
48 | 0 | maxName = len; |
49 | 0 | } |
50 | 0 | llvm::sort(toolNames); |
51 | |
|
52 | 0 | for (std::vector<llvm::StringRef>::iterator it = toolNames.begin(), |
53 | 0 | ei = toolNames.end(); it != ei; ++it) { |
54 | |
|
55 | 0 | out << " " << (*it); |
56 | 0 | unsigned spaces = (maxName + 3) - (it->size()); |
57 | 0 | for (unsigned i = 0; i < spaces; ++i) |
58 | 0 | out << ' '; |
59 | | |
60 | 0 | out << getTool(*it)->getDescription() << '\n'; |
61 | 0 | } |
62 | 0 | } |
63 | | |
64 | | namespace diagtool { |
65 | | llvm::ManagedStatic<DiagTools> diagTools; |
66 | | } |