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
18using namespace clang;
19
20class BlinkGCPluginAction : public PluginASTAction {
21 public:
22  BlinkGCPluginAction() {}
23
24 protected:
25  // Overridden from PluginASTAction:
26  virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(
27      CompilerInstance& instance,
28      llvm::StringRef ref) {
29    return llvm::make_unique<BlinkGCPluginConsumer>(instance, options_);
30  }
31
32  virtual bool ParseArgs(const CompilerInstance&,
33                         const std::vector<std::string>& args) {
34    for (const auto& arg : args) {
35      if (arg == "dump-graph") {
36        options_.dump_graph = true;
37      } else if (arg == "warn-unneeded-finalizer") {
38        options_.warn_unneeded_finalizer = true;
39      } else {
40        llvm::errs() << "Unknown blink-gc-plugin argument: " << arg << "\n";
41        return false;
42      }
43    }
44    return true;
45  }
46
47 private:
48  BlinkGCPluginOptions options_;
49};
50
51static FrontendPluginRegistry::Add<BlinkGCPluginAction> X(
52    "blink-gc-plugin",
53    "Check Blink GC invariants");
54