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. 4 5 #include "FindBadConstructsAction.h" 6 7 #include "clang/AST/ASTConsumer.h" 8 #include "clang/Frontend/FrontendPluginRegistry.h" 9 10 #include "FindBadConstructsConsumer.h" 11 12 using namespace clang; 13 14 namespace chrome_checker { 15 16 namespace { 17 18 class PluginConsumer : public ASTConsumer { 19 public: PluginConsumer(CompilerInstance * instance,const Options & options)20 PluginConsumer(CompilerInstance* instance, const Options& options) 21 : visitor_(*instance, options) {} 22 HandleTranslationUnit(clang::ASTContext & context)23 void HandleTranslationUnit(clang::ASTContext& context) override { 24 visitor_.Traverse(context); 25 } 26 27 private: 28 FindBadConstructsConsumer visitor_; 29 }; 30 31 } // namespace 32 FindBadConstructsAction()33FindBadConstructsAction::FindBadConstructsAction() { 34 } 35 CreateASTConsumer(CompilerInstance & instance,llvm::StringRef ref)36std::unique_ptr<ASTConsumer> FindBadConstructsAction::CreateASTConsumer( 37 CompilerInstance& instance, 38 llvm::StringRef ref) { 39 return llvm::make_unique<PluginConsumer>(&instance, options_); 40 } 41 ParseArgs(const CompilerInstance & instance,const std::vector<std::string> & args)42bool FindBadConstructsAction::ParseArgs(const CompilerInstance& instance, 43 const std::vector<std::string>& args) { 44 bool parsed = true; 45 46 for (size_t i = 0; i < args.size() && parsed; ++i) { 47 if (args[i] == "check-base-classes") { 48 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. 49 options_.check_base_classes = true; 50 } else if (args[i] == "enforce-in-thirdparty-webkit") { 51 // TODO(dcheng): Remove completely. 52 } else if (args[i] == "check-enum-max-value") { 53 // TODO(dcheng): Remove completely. 54 } else if (args[i] == "check-ipc") { 55 options_.check_ipc = true; 56 } else if (args[i] == "check-gmock-objects") { 57 options_.check_gmock_objects = true; 58 } else { 59 parsed = false; 60 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; 61 } 62 } 63 64 return parsed; 65 } 66 67 } // namespace chrome_checker 68 69 static FrontendPluginRegistry::Add<chrome_checker::FindBadConstructsAction> X( 70 "find-bad-constructs", 71 "Finds bad C++ constructs"); 72