DiagnosticsReporter.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2016 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_DIAGNOSTICS_REPORTER_H_
  5. #define TOOLS_BLINK_GC_PLUGIN_DIAGNOSTICS_REPORTER_H_
  6. #include "CheckFieldsVisitor.h"
  7. #include "CheckFinalizerVisitor.h"
  8. #include "CheckGCRootsVisitor.h"
  9. #include "Config.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 RecordInfo;
  15. // All error/warning reporting methods under one roof.
  16. //
  17. class DiagnosticsReporter {
  18. public:
  19. explicit DiagnosticsReporter(clang::CompilerInstance&);
  20. bool hasErrorOccurred() const;
  21. clang::DiagnosticsEngine::Level getErrorLevel() const;
  22. void ClassMustLeftMostlyDeriveGC(RecordInfo* info);
  23. void ClassRequiresTraceMethod(RecordInfo* info);
  24. void BaseRequiresTracing(RecordInfo* derived,
  25. clang::CXXMethodDecl* trace,
  26. clang::CXXRecordDecl* base);
  27. void FieldsImproperlyTraced(RecordInfo* info,
  28. clang::CXXMethodDecl* trace);
  29. void ClassContainsInvalidFields(
  30. RecordInfo* info,
  31. const CheckFieldsVisitor::Errors& errors);
  32. void ClassContainsGCRoots(RecordInfo* info,
  33. const CheckGCRootsVisitor::Errors& errors);
  34. void FinalizerAccessesFinalizedFields(
  35. clang::CXXMethodDecl* dtor,
  36. const CheckFinalizerVisitor::Errors& errors);
  37. void ClassMustDeclareGCMixinTraceMethod(RecordInfo* info);
  38. void OverriddenNonVirtualTrace(RecordInfo* info,
  39. clang::CXXMethodDecl* trace,
  40. clang::CXXMethodDecl* overridden);
  41. void MissingTraceDispatchMethod(RecordInfo* info);
  42. void VirtualAndManualDispatch(RecordInfo* info,
  43. clang::CXXMethodDecl* dispatch);
  44. void MissingTraceDispatch(const clang::FunctionDecl* dispatch,
  45. RecordInfo* receiver);
  46. void MissingFinalizeDispatch(const clang::FunctionDecl* dispatch,
  47. RecordInfo* receiver);
  48. void StackAllocatedDerivesGarbageCollected(RecordInfo* info, BasePoint* base);
  49. void ClassOverridesNew(RecordInfo* info, clang::CXXMethodDecl* newop);
  50. void ClassDeclaresPureVirtualTrace(RecordInfo* info,
  51. clang::CXXMethodDecl* trace);
  52. void LeftMostBaseMustBePolymorphic(RecordInfo* derived,
  53. clang::CXXRecordDecl* base);
  54. void BaseClassMustDeclareVirtualTrace(RecordInfo* derived,
  55. clang::CXXRecordDecl* base);
  56. void ClassMustCRTPItself(const RecordInfo* derived,
  57. const clang::CXXRecordDecl* base,
  58. const clang::CXXBaseSpecifier* base_spec);
  59. void TraceMethodForStackAllocatedClass(RecordInfo* parent,
  60. clang::CXXMethodDecl* trace);
  61. void NoteManualDispatchMethod(clang::CXXMethodDecl* dispatch);
  62. void NoteBaseRequiresTracing(BasePoint* base);
  63. void NoteFieldRequiresTracing(RecordInfo* holder, clang::FieldDecl* field);
  64. void NoteFieldShouldNotBeTraced(RecordInfo* holder, clang::FieldDecl* field);
  65. void NotePartObjectContainsGCRoot(FieldPoint* point);
  66. void NoteFieldContainsGCRoot(FieldPoint* point);
  67. void NoteField(FieldPoint* point, unsigned note);
  68. void NoteField(clang::FieldDecl* field, unsigned note);
  69. void NoteOverriddenNonVirtualTrace(clang::CXXMethodDecl* overridden);
  70. // Used by FindBadPatterns.
  71. void UniquePtrUsedWithGC(const clang::Expr* expr,
  72. const clang::FunctionDecl* bad_function,
  73. const clang::CXXRecordDecl* gc_type);
  74. void OptionalUsedWithGC(const clang::Expr* expr,
  75. const clang::CXXRecordDecl* optional,
  76. const clang::CXXRecordDecl* gc_type);
  77. private:
  78. clang::DiagnosticBuilder ReportDiagnostic(
  79. clang::SourceLocation location,
  80. unsigned diag_id);
  81. void ReportMissingDispatchMethod(RecordInfo* info, unsigned error);
  82. void ReportMissingDispatch(const clang::FunctionDecl* dispatch,
  83. RecordInfo* receiver,
  84. unsigned error);
  85. clang::CompilerInstance& instance_;
  86. clang::DiagnosticsEngine& diagnostic_;
  87. unsigned diag_class_must_left_mostly_derive_gc_;
  88. unsigned diag_class_requires_trace_method_;
  89. unsigned diag_base_requires_tracing_;
  90. unsigned diag_fields_require_tracing_;
  91. unsigned diag_fields_improperly_traced_;
  92. unsigned diag_class_contains_invalid_fields_;
  93. unsigned diag_class_contains_gc_root_;
  94. unsigned diag_finalizer_accesses_finalized_field_;
  95. unsigned diag_overridden_non_virtual_trace_;
  96. unsigned diag_missing_trace_dispatch_method_;
  97. unsigned diag_virtual_and_manual_dispatch_;
  98. unsigned diag_missing_trace_dispatch_;
  99. unsigned diag_missing_finalize_dispatch_;
  100. unsigned diag_stack_allocated_derives_gc_;
  101. unsigned diag_class_overrides_new_;
  102. unsigned diag_class_declares_pure_virtual_trace_;
  103. unsigned diag_left_most_base_must_be_polymorphic_;
  104. unsigned diag_base_class_must_declare_virtual_trace_;
  105. unsigned diag_class_must_crtp_itself_;
  106. unsigned diag_base_requires_tracing_note_;
  107. unsigned diag_field_requires_tracing_note_;
  108. unsigned diag_field_should_not_be_traced_note_;
  109. unsigned diag_raw_ptr_to_gc_managed_class_note_;
  110. unsigned diag_ref_ptr_to_gc_managed_class_note_;
  111. unsigned diag_weak_ptr_to_gc_managed_class_note_;
  112. unsigned diag_reference_ptr_to_gc_managed_class_note_;
  113. unsigned diag_own_ptr_to_gc_managed_class_note_;
  114. unsigned diag_unique_ptr_to_gc_managed_class_note_;
  115. unsigned diag_member_to_gc_unmanaged_class_note_;
  116. unsigned diag_stack_allocated_field_note_;
  117. unsigned diag_member_in_unmanaged_class_note_;
  118. unsigned diag_part_object_to_gc_derived_class_note_;
  119. unsigned diag_part_object_contains_gc_root_note_;
  120. unsigned diag_field_contains_gc_root_note_;
  121. unsigned diag_finalized_field_note_;
  122. unsigned diag_overridden_non_virtual_trace_note_;
  123. unsigned diag_manual_dispatch_method_note_;
  124. unsigned diag_iterator_to_gc_managed_collection_note_;
  125. unsigned diag_trace_method_of_stack_allocated_parent_;
  126. unsigned diag_member_in_stack_allocated_class_;
  127. unsigned diag_unique_ptr_used_with_gc_;
  128. unsigned diag_optional_used_with_gc_;
  129. };
  130. #endif // TOOLS_BLINK_GC_PLUGIN_DIAGNOSTICS_REPORTER_H_