Coverage Report

Created: 2020-02-25 14:32

/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 <vector>
16
17
using namespace diagtool;
18
19
DiagTool::DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc)
20
92
    : cmd(std::string(toolCmd)), description(std::string(toolDesc)) {}
21
22
0
DiagTool::~DiagTool() {}
23
24
typedef llvm::StringMap<DiagTool *> ToolMap;
25
138
static inline ToolMap *getTools(void *v) { return static_cast<ToolMap*>(v); }
26
27
23
DiagTools::DiagTools() : tools(new ToolMap()) {}
28
0
DiagTools::~DiagTools() { delete getTools(tools); }
29
30
23
DiagTool *DiagTools::getTool(llvm::StringRef toolCmd) {
31
23
  ToolMap::iterator it = getTools(tools)->find(toolCmd);
32
23
  return (it == getTools(tools)->end()) ? 
nullptr0
: it->getValue();
33
23
}
34
35
92
void DiagTools::registerTool(DiagTool *tool) {
36
92
  (*getTools(tools))[tool->getName()] = tool;
37
92
}
38
39
0
void DiagTools::printCommands(llvm::raw_ostream &out) {
40
0
  std::vector<llvm::StringRef> toolNames;
41
0
  unsigned maxName = 0;
42
0
  for (ToolMap::iterator it = getTools(tools)->begin(),
43
0
       ei = getTools(tools)->end(); it != ei; ++it) {
44
0
    toolNames.push_back(it->getKey());
45
0
    unsigned len = it->getKey().size();
46
0
    if (len > maxName)
47
0
      maxName = len;    
48
0
  }
49
0
  llvm::sort(toolNames);
50
0
51
0
  for (std::vector<llvm::StringRef>::iterator it = toolNames.begin(),
52
0
       ei = toolNames.end(); it != ei; ++it) {
53
0
54
0
    out << "  " << (*it);
55
0
    unsigned spaces = (maxName + 3) - (it->size());
56
0
    for (unsigned i = 0; i < spaces; ++i)
57
0
      out << ' ';
58
0
    
59
0
    out << getTool(*it)->getDescription() << '\n';    
60
0
  }
61
0
}
62
63
namespace diagtool {
64
  llvm::ManagedStatic<DiagTools> diagTools;
65
}