Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / clang / blink_gc_plugin / BlinkGCPlugin.cpp
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 // Checks that are implemented:
9 // [currently none]
10
11 #include "Config.h"
12
13 #include "clang/AST/AST.h"
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/Frontend/CompilerInstance.h"
16 #include "clang/Frontend/FrontendPluginRegistry.h"
17
18 using namespace clang;
19 using std::string;
20
21 namespace {
22
23 struct BlinkGCPluginOptions {
24   BlinkGCPluginOptions() {
25   }
26 };
27
28 // Main class containing checks for various invariants of the Blink
29 // garbage collection infrastructure.
30 class BlinkGCPluginConsumer : public ASTConsumer {
31  public:
32   BlinkGCPluginConsumer(CompilerInstance& instance,
33                         const BlinkGCPluginOptions& options) {
34   }
35
36   virtual void HandleTranslationUnit(ASTContext& context) {
37     // FIXME: implement consistency checks.
38   }
39 };
40
41
42 class BlinkGCPluginAction : public PluginASTAction {
43  public:
44   BlinkGCPluginAction() {
45   }
46
47  protected:
48   // Overridden from PluginASTAction:
49   virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance,
50                                          llvm::StringRef ref) {
51     return new BlinkGCPluginConsumer(instance, options_);
52   }
53
54   virtual bool ParseArgs(const CompilerInstance& instance,
55                          const std::vector<string>& args) {
56     bool parsed = true;
57
58     for (size_t i = 0; i < args.size() && parsed; ++i) {
59       if (args[i] == "enable-oilpan") {
60         // TODO: Remove this once all transition types are eliminated.
61         Config::set_oilpan_enabled(true);
62       } else {
63         parsed = false;
64         llvm::errs() << "Unknown blink-gc-plugin argument: " << args[i] << "\n";
65       }
66     }
67
68     return parsed;
69   }
70
71  private:
72   BlinkGCPluginOptions options_;
73 };
74
75 }  // namespace
76
77 bool Config::oilpan_enabled_ = false;
78
79 static FrontendPluginRegistry::Add<BlinkGCPluginAction>
80 X("blink-gc-plugin", "Check Blink GC invariants");