• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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 #ifndef TOOLS_BLINK_GC_PLUGIN_BLINK_GC_PLUGIN_CONSUMER_H_
6 #define TOOLS_BLINK_GC_PLUGIN_BLINK_GC_PLUGIN_CONSUMER_H_
7 
8 #include <string>
9 
10 #include "BlinkGCPluginOptions.h"
11 #include "Config.h"
12 #include "DiagnosticsReporter.h"
13 #include "clang/AST/AST.h"
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Frontend/CompilerInstance.h"
17 
18 class JsonWriter;
19 class RecordInfo;
20 
21 // Main class containing checks for various invariants of the Blink
22 // garbage collection infrastructure.
23 class BlinkGCPluginConsumer : public clang::ASTConsumer {
24  public:
25   BlinkGCPluginConsumer(clang::CompilerInstance& instance,
26                         const BlinkGCPluginOptions& options);
27 
28   void HandleTranslationUnit(clang::ASTContext& context) override;
29 
30  private:
31   void ParseFunctionTemplates(clang::TranslationUnitDecl* decl);
32 
33   // Main entry for checking a record declaration.
34   void CheckRecord(RecordInfo* info);
35 
36   // Check a class-like object (eg, class, specialization, instantiation).
37   void CheckClass(RecordInfo* info);
38 
39   clang::CXXRecordDecl* GetDependentTemplatedDecl(const clang::Type& type);
40 
41   void CheckPolymorphicClass(RecordInfo* info, clang::CXXMethodDecl* trace);
42 
43   clang::CXXRecordDecl* GetLeftMostBase(clang::CXXRecordDecl* left_most);
44 
45   bool DeclaresVirtualMethods(clang::CXXRecordDecl* decl);
46 
47   void CheckLeftMostDerived(RecordInfo* info);
48 
49   void CheckDispatch(RecordInfo* info);
50 
51   void CheckFinalization(RecordInfo* info);
52 
53   void CheckUnneededFinalization(RecordInfo* info);
54 
55   bool HasNonEmptyFinalizer(RecordInfo* info);
56 
57   // This is the main entry for tracing method definitions.
58   void CheckTracingMethod(clang::CXXMethodDecl* method);
59 
60   // Determine what type of tracing method this is (dispatch or trace).
61   void CheckTraceOrDispatchMethod(RecordInfo* parent,
62                                   clang::CXXMethodDecl* method);
63 
64   // Check an actual trace method.
65   void CheckTraceMethod(RecordInfo* parent,
66                         clang::CXXMethodDecl* trace,
67                         Config::TraceMethodType trace_type);
68 
69   void DumpClass(RecordInfo* info);
70 
71   // Adds either a warning or error, based on the current handling of -Werror.
72   clang::DiagnosticsEngine::Level getErrorLevel();
73 
74   std::string GetLocString(clang::SourceLocation loc);
75 
76   bool IsIgnored(RecordInfo* info);
77 
78   bool IsIgnoredClass(RecordInfo* info);
79 
80   bool InIgnoredDirectory(RecordInfo* info);
81 
82   bool InCheckedNamespace(RecordInfo* info);
83 
84   bool GetFilename(clang::SourceLocation loc, std::string* filename);
85 
86   clang::CompilerInstance& instance_;
87   DiagnosticsReporter reporter_;
88   BlinkGCPluginOptions options_;
89   RecordCache cache_;
90   JsonWriter* json_;
91 };
92 
93 #endif  // TOOLS_BLINK_GC_PLUGIN_BLINK_GC_PLUGIN_CONSUMER_H_
94