BlinkGCPluginConsumer.h 2.8 KB

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