Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / clang / plugins / FindBadConstructsAction.cpp
blob6c39d724b1a7a476287ce4d48365f8732374dbdd
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "FindBadConstructsAction.h"
7 #include "clang/AST/ASTConsumer.h"
8 #include "clang/Frontend/FrontendPluginRegistry.h"
10 #include "FindBadConstructsConsumer.h"
12 using namespace clang;
14 namespace chrome_checker {
16 namespace {
18 class PluginConsumer : public ASTConsumer {
19 public:
20 PluginConsumer(CompilerInstance* instance, const Options& options)
21 : visitor_(*instance, options) {}
23 void HandleTranslationUnit(clang::ASTContext& context) override {
24 visitor_.TraverseDecl(context.getTranslationUnitDecl());
27 private:
28 FindBadConstructsConsumer visitor_;
31 } // namespace
33 FindBadConstructsAction::FindBadConstructsAction() {
36 std::unique_ptr<ASTConsumer> FindBadConstructsAction::CreateASTConsumer(
37 CompilerInstance& instance,
38 llvm::StringRef ref) {
39 if (options_.with_ast_visitor)
40 return llvm::make_unique<PluginConsumer>(&instance, options_);
41 return llvm::make_unique<FindBadConstructsConsumer>(instance, options_);
44 bool FindBadConstructsAction::ParseArgs(const CompilerInstance& instance,
45 const std::vector<std::string>& args) {
46 bool parsed = true;
48 for (size_t i = 0; i < args.size() && parsed; ++i) {
49 if (args[i] == "check-base-classes") {
50 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed.
51 options_.check_base_classes = true;
52 } else if (args[i] == "check-enum-last-value") {
53 // TODO(tsepez): Enable this by default once http://crbug.com/356815
54 // and http://crbug.com/356816 are fixed.
55 options_.check_enum_last_value = true;
56 } else if (args[i] == "with-ast-visitor") {
57 options_.with_ast_visitor = true;
58 } else if (args[i] == "check-templates") {
59 options_.check_templates = true;
60 } else {
61 parsed = false;
62 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n";
66 return parsed;
69 } // namespace chrome_checker
71 static FrontendPluginRegistry::Add<chrome_checker::FindBadConstructsAction> X(
72 "find-bad-constructs",
73 "Finds bad C++ constructs");