OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "CheckFieldsVisitor.h" | 5 #include "CheckFieldsVisitor.h" |
6 | 6 |
7 #include <cassert> | 7 #include <cassert> |
8 | 8 |
9 #include "BlinkGCPluginOptions.h" | |
10 #include "RecordInfo.h" | 9 #include "RecordInfo.h" |
11 | 10 |
12 CheckFieldsVisitor::CheckFieldsVisitor() | 11 CheckFieldsVisitor::CheckFieldsVisitor(const BlinkGCPluginOptions& options) |
13 : current_(0), | 12 : options_(options), current_(0), stack_allocated_host_(false) {} |
14 stack_allocated_host_(false) { | |
15 } | |
16 | 13 |
17 CheckFieldsVisitor::Errors& CheckFieldsVisitor::invalid_fields() { | 14 CheckFieldsVisitor::Errors& CheckFieldsVisitor::invalid_fields() { |
18 return invalid_fields_; | 15 return invalid_fields_; |
19 } | 16 } |
20 | 17 |
21 bool CheckFieldsVisitor::ContainsInvalidFields(RecordInfo* info) { | 18 bool CheckFieldsVisitor::ContainsInvalidFields(RecordInfo* info) { |
22 stack_allocated_host_ = info->IsStackAllocated(); | 19 stack_allocated_host_ = info->IsStackAllocated(); |
23 managed_host_ = stack_allocated_host_ || | 20 managed_host_ = stack_allocated_host_ || |
24 info->IsGCAllocated() || | 21 info->IsGCAllocated() || |
25 info->IsNonNewable() || | 22 info->IsNonNewable() || |
26 info->IsOnlyPlacementNewable(); | 23 info->IsOnlyPlacementNewable(); |
27 for (RecordInfo::Fields::iterator it = info->GetFields().begin(); | 24 for (RecordInfo::Fields::iterator it = info->GetFields().begin(); |
28 it != info->GetFields().end(); | 25 it != info->GetFields().end(); |
29 ++it) { | 26 ++it) { |
30 context().clear(); | 27 context().clear(); |
31 current_ = &it->second; | 28 current_ = &it->second; |
32 current_->edge()->Accept(this); | 29 current_->edge()->Accept(this); |
33 } | 30 } |
34 return !invalid_fields_.empty(); | 31 return !invalid_fields_.empty(); |
35 } | 32 } |
36 | 33 |
37 void CheckFieldsVisitor::AtMember(Member* edge) { | 34 void CheckFieldsVisitor::AtMember(Member*) { |
38 if (managed_host_) | 35 if (managed_host_) |
39 return; | 36 return; |
40 // A member is allowed to appear in the context of a root. | 37 // A member is allowed to appear in the context of a root. |
41 for (Context::iterator it = context().begin(); | 38 for (Context::iterator it = context().begin(); |
42 it != context().end(); | 39 it != context().end(); |
43 ++it) { | 40 ++it) { |
44 if ((*it)->Kind() == Edge::kRoot) | 41 if ((*it)->Kind() == Edge::kRoot) |
45 return; | 42 return; |
46 } | 43 } |
47 invalid_fields_.push_back(std::make_pair(current_, kMemberInUnmanaged)); | 44 invalid_fields_.push_back(std::make_pair(current_, kMemberInUnmanaged)); |
48 } | 45 } |
49 | 46 |
| 47 void CheckFieldsVisitor::AtWeakMember(WeakMember*) { |
| 48 // TODO(sof): remove this once crbug.com/724418's change |
| 49 // has safely been rolled out. |
| 50 if (options_.enable_weak_members_in_unmanaged_classes) |
| 51 return; |
| 52 AtMember(nullptr); |
| 53 } |
| 54 |
50 void CheckFieldsVisitor::AtIterator(Iterator* edge) { | 55 void CheckFieldsVisitor::AtIterator(Iterator* edge) { |
51 if (!managed_host_) | 56 if (!managed_host_) |
52 return; | 57 return; |
53 | 58 |
54 if (edge->IsUnsafe()) | 59 if (edge->IsUnsafe()) |
55 invalid_fields_.push_back(std::make_pair(current_, kIteratorToGCManaged)); | 60 invalid_fields_.push_back(std::make_pair(current_, kIteratorToGCManaged)); |
56 } | 61 } |
57 | 62 |
58 void CheckFieldsVisitor::AtValue(Value* edge) { | 63 void CheckFieldsVisitor::AtValue(Value* edge) { |
59 // TODO: what should we do to check unions? | 64 // TODO: what should we do to check unions? |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return kRawPtrToGCManaged; | 129 return kRawPtrToGCManaged; |
125 } | 130 } |
126 if (ptr->IsRefPtr()) | 131 if (ptr->IsRefPtr()) |
127 return kRefPtrToGCManaged; | 132 return kRefPtrToGCManaged; |
128 if (ptr->IsOwnPtr()) | 133 if (ptr->IsOwnPtr()) |
129 return kOwnPtrToGCManaged; | 134 return kOwnPtrToGCManaged; |
130 if (ptr->IsUniquePtr()) | 135 if (ptr->IsUniquePtr()) |
131 return kUniquePtrToGCManaged; | 136 return kUniquePtrToGCManaged; |
132 assert(false && "Unknown smart pointer kind"); | 137 assert(false && "Unknown smart pointer kind"); |
133 } | 138 } |
OLD | NEW |