CheckFieldsVisitor.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_CHECK_FIELDS_VISITOR_H_
  5. #define TOOLS_BLINK_GC_PLUGIN_CHECK_FIELDS_VISITOR_H_
  6. #include <vector>
  7. #include "BlinkGCPluginOptions.h"
  8. #include "Edge.h"
  9. class FieldPoint;
  10. // This visitor checks that the fields of a class are "well formed".
  11. // - unique_ptr, scoped_refptr and WeakPtr must not point to a GC derived type.
  12. // - Part objects must not be a GC derived type.
  13. // - An on-heap class must never contain GC roots.
  14. // - Only stack-allocated types may point to stack-allocated types.
  15. class CheckFieldsVisitor : public RecursiveEdgeVisitor {
  16. public:
  17. enum Error {
  18. kRawPtrToGCManaged,
  19. kRefPtrToGCManaged,
  20. kWeakPtrToGCManaged,
  21. kReferencePtrToGCManaged,
  22. kUniquePtrToGCManaged,
  23. kMemberToGCUnmanaged,
  24. kMemberInUnmanaged,
  25. kPtrFromHeapToStack,
  26. kGCDerivedPartObject,
  27. kIteratorToGCManaged,
  28. kMemberInStackAllocated,
  29. };
  30. using Errors = std::vector<std::pair<FieldPoint*, Error>>;
  31. explicit CheckFieldsVisitor(const BlinkGCPluginOptions&);
  32. Errors& invalid_fields();
  33. bool ContainsInvalidFields(RecordInfo* info);
  34. void AtMember(Member*) override;
  35. void AtWeakMember(WeakMember*) override;
  36. void AtValue(Value*) override;
  37. void AtCollection(Collection*) override;
  38. void AtIterator(Iterator*) override;
  39. private:
  40. Error InvalidSmartPtr(Edge* ptr);
  41. const BlinkGCPluginOptions& options_;
  42. FieldPoint* current_;
  43. bool stack_allocated_host_;
  44. bool managed_host_;
  45. Errors invalid_fields_;
  46. };
  47. #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_FIELDS_VISITOR_H_