summaryrefslogtreecommitdiff
path: root/clang/tools/diagtool/DiagTool.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
commitbe1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch)
tree1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/tools/diagtool/DiagTool.cpp
parentc4626a62754862d20b41e8a46a3574264ea80e6d (diff)
parentf1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/tools/diagtool/DiagTool.cpp')
-rw-r--r--clang/tools/diagtool/DiagTool.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/clang/tools/diagtool/DiagTool.cpp b/clang/tools/diagtool/DiagTool.cpp
new file mode 100644
index 0000000..36e72a2
--- /dev/null
+++ b/clang/tools/diagtool/DiagTool.cpp
@@ -0,0 +1,68 @@
+//===- DiagTool.cpp - Classes for defining diagtool tools -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the boilerplate for defining diagtool tools.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DiagTool.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/SmallString.h"
+#include <vector>
+
+using namespace diagtool;
+
+DiagTool::DiagTool(llvm::StringRef toolCmd,
+ llvm::StringRef toolDesc)
+ : cmd(toolCmd), description(toolDesc) {}
+
+DiagTool::~DiagTool() {}
+
+typedef llvm::StringMap<DiagTool *> ToolMap;
+static inline ToolMap *getTools(void *v) { return static_cast<ToolMap*>(v); }
+
+DiagTools::DiagTools() : tools(new ToolMap()) {}
+DiagTools::~DiagTools() { delete getTools(tools); }
+
+DiagTool *DiagTools::getTool(llvm::StringRef toolCmd) {
+ ToolMap::iterator it = getTools(tools)->find(toolCmd);
+ return (it == getTools(tools)->end()) ? 0 : it->getValue();
+}
+
+void DiagTools::registerTool(DiagTool *tool) {
+ getTools(tools)->GetOrCreateValue(tool->getName(), tool);
+}
+
+void DiagTools::printCommands(llvm::raw_ostream &out) {
+ std::vector<llvm::StringRef> toolNames;
+ unsigned maxName = 0;
+ for (ToolMap::iterator it = getTools(tools)->begin(),
+ ei = getTools(tools)->end(); it != ei; ++it) {
+ toolNames.push_back(it->getKey());
+ unsigned len = it->getKey().size();
+ if (len > maxName)
+ maxName = len;
+ }
+ std::sort(toolNames.begin(), toolNames.end());
+
+ for (std::vector<llvm::StringRef>::iterator it = toolNames.begin(),
+ ei = toolNames.end(); it != ei; ++it) {
+
+ out << " " << (*it);
+ unsigned spaces = (maxName + 3) - (it->size());
+ for (unsigned i = 0; i < spaces; ++i)
+ out << ' ';
+
+ out << getTool(*it)->getDescription() << '\n';
+ }
+}
+
+namespace diagtool {
+ llvm::ManagedStatic<DiagTools> diagTools;
+}