| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "FindBadConstructsAction.h" |
| |
| #include "clang/AST/ASTConsumer.h" |
| #include "clang/Frontend/FrontendPluginRegistry.h" |
| |
| #include "FindBadConstructsConsumer.h" |
| |
| using namespace clang; |
| |
| namespace chrome_checker { |
| |
| namespace { |
| |
| class PluginConsumer : public ASTConsumer { |
| public: |
| PluginConsumer(CompilerInstance* instance, const Options& options) |
| : visitor_(*instance, options) {} |
| |
| void HandleTranslationUnit(clang::ASTContext& context) override { |
| visitor_.Traverse(context); |
| } |
| |
| private: |
| FindBadConstructsConsumer visitor_; |
| }; |
| |
| } // namespace |
| |
| FindBadConstructsAction::FindBadConstructsAction() { |
| } |
| |
| std::unique_ptr<ASTConsumer> FindBadConstructsAction::CreateASTConsumer( |
| CompilerInstance& instance, |
| llvm::StringRef ref) { |
| return std::make_unique<PluginConsumer>(&instance, options_); |
| } |
| |
| bool FindBadConstructsAction::ParseArgs(const CompilerInstance& instance, |
| const std::vector<std::string>& args) { |
| bool parsed = true; |
| |
| for (size_t i = 0; i < args.size() && parsed; ++i) { |
| if (args[i] == "check-base-classes") { |
| // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. |
| options_.check_base_classes = true; |
| } else if (args[i] == "check-ipc") { |
| options_.check_ipc = true; |
| } else if (args[i] == "check-gmock-objects") { |
| options_.check_gmock_objects = true; |
| } else if (args[i] == "check-layout-object-methods") { |
| options_.check_layout_object_methods = true; |
| } else if (args[i] == "checked-ptr-as-trivial-member") { |
| options_.checked_ptr_as_trivial_member = true; |
| } else if (args[i] == "raw-ptr-template-as-trivial-member") { |
| options_.raw_ptr_template_as_trivial_member = true; |
| } else if (args[i] == "use-classify-type") { |
| // This option is ignored, will be removed soon. |
| } else { |
| parsed = false; |
| llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; |
| } |
| } |
| |
| return parsed; |
| } |
| |
| } // namespace chrome_checker |
| |
| static FrontendPluginRegistry::Add<chrome_checker::FindBadConstructsAction> X( |
| "find-bad-constructs", |
| "Finds bad C++ constructs"); |