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