• 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_CHECK_FIELDS_VISITOR_H_
6 #define TOOLS_BLINK_GC_PLUGIN_CHECK_FIELDS_VISITOR_H_
7 
8 #include <vector>
9 
10 #include "Edge.h"
11 
12 class FieldPoint;
13 
14 // This visitor checks that the fields of a class are "well formed".
15 // - OwnPtr and RefPtr must not point to a GC derived type.
16 // - Part objects must not be a GC derived type.
17 // - An on-heap class must never contain GC roots.
18 // - Only stack-allocated types may point to stack-allocated types.
19 
20 class CheckFieldsVisitor : public RecursiveEdgeVisitor {
21  public:
22   enum Error {
23     kRawPtrToGCManaged,
24     kRefPtrToGCManaged,
25     kReferencePtrToGCManaged,
26     kOwnPtrToGCManaged,
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   CheckFieldsVisitor();
38 
39   Errors& invalid_fields();
40 
41   bool ContainsInvalidFields(RecordInfo* info);
42 
43   void AtMember(Member* edge) override;
44   void AtValue(Value* edge) override;
45   void AtCollection(Collection* edge) override;
46   void AtIterator(Iterator*) override;
47 
48  private:
49   Error InvalidSmartPtr(Edge* ptr);
50 
51   FieldPoint* current_;
52   bool stack_allocated_host_;
53   bool managed_host_;
54   Errors invalid_fields_;
55 };
56 
57 #endif  // TOOLS_BLINK_GC_PLUGIN_CHECK_FIELDS_VISITOR_H_
58