1 // Copyright 2014 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 // This clang plugin checks various invariants of the Blink garbage 6 // collection infrastructure. 7 // 8 // Errors are described at: 9 // http://www.chromium.org/developers/blink-gc-plugin-errors 10 11 #include "BlinkGCPluginConsumer.h" 12 #include "BlinkGCPluginOptions.h" 13 #include "Config.h" 14 15 #include "clang/Frontend/CompilerInstance.h" 16 #include "clang/Frontend/FrontendPluginRegistry.h" 17 18 using namespace clang; 19 20 class BlinkGCPluginAction : public PluginASTAction { 21 public: BlinkGCPluginAction()22 BlinkGCPluginAction() {} 23 24 protected: 25 // Overridden from PluginASTAction: CreateASTConsumer(CompilerInstance & instance,llvm::StringRef ref)26 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance& instance, 27 llvm::StringRef ref) override { 28 return llvm::make_unique<BlinkGCPluginConsumer>(instance, options_); 29 } 30 ParseArgs(const CompilerInstance &,const std::vector<std::string> & args)31 bool ParseArgs(const CompilerInstance&, 32 const std::vector<std::string>& args) override { 33 for (const auto& arg : args) { 34 if (arg == "dump-graph") { 35 options_.dump_graph = true; 36 } else if (arg == "warn-unneeded-finalizer") { 37 options_.warn_unneeded_finalizer = true; 38 } else if (arg == "enable-weak-members-in-unmanaged-classes") { 39 options_.enable_weak_members_in_unmanaged_classes = true; 40 } else { 41 llvm::errs() << "Unknown blink-gc-plugin argument: " << arg << "\n"; 42 return false; 43 } 44 } 45 return true; 46 } 47 48 private: 49 BlinkGCPluginOptions options_; 50 }; 51 52 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( 53 "blink-gc-plugin", 54 "Check Blink GC invariants"); 55