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" | 9 #include "BlinkGCPluginOptions.h" |
10 #include "RecordInfo.h" | 10 #include "RecordInfo.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return; | 86 return; |
87 | 87 |
88 // Disallow OwnPtr<T>, RefPtr<T> and T* to stack-allocated types. | 88 // Disallow OwnPtr<T>, RefPtr<T> and T* to stack-allocated types. |
89 if (Parent()->IsOwnPtr() || | 89 if (Parent()->IsOwnPtr() || |
90 (Parent()->IsRefPtr() && !edge->value()->IsGCRefCounted()) || | 90 (Parent()->IsRefPtr() && !edge->value()->IsGCRefCounted()) || |
91 (stack_allocated_host_ && Parent()->IsRawPtr())) { | 91 (stack_allocated_host_ && Parent()->IsRawPtr())) { |
92 invalid_fields_.push_back(std::make_pair( | 92 invalid_fields_.push_back(std::make_pair( |
93 current_, InvalidSmartPtr(Parent()))); | 93 current_, InvalidSmartPtr(Parent()))); |
94 return; | 94 return; |
95 } | 95 } |
96 if (options_.warn_raw_ptr && Parent()->IsRawPtr()) { | 96 if (Parent()->IsRawPtr()) { |
97 if (static_cast<RawPtr*>(Parent())->HasReferenceType()) { | 97 RawPtr* rawPtr = static_cast<RawPtr*>(Parent()); |
98 invalid_fields_.push_back(std::make_pair( | 98 Error error = rawPtr->HasReferenceType() ? |
99 current_, kReferencePtrToGCManagedWarning)); | 99 kReferencePtrToGCManaged : kRawPtrToGCManaged; |
100 } else { | 100 invalid_fields_.push_back(std::make_pair(current_, error)); |
101 invalid_fields_.push_back(std::make_pair( | |
102 current_, kRawPtrToGCManagedWarning)); | |
103 } | |
104 } | 101 } |
105 } | 102 } |
106 | 103 |
107 void CheckFieldsVisitor::AtCollection(Collection* edge) { | 104 void CheckFieldsVisitor::AtCollection(Collection* edge) { |
108 if (edge->on_heap() && Parent() && Parent()->IsOwnPtr()) | 105 if (edge->on_heap() && Parent() && Parent()->IsOwnPtr()) |
109 invalid_fields_.push_back(std::make_pair(current_, kOwnPtrToGCManaged)); | 106 invalid_fields_.push_back(std::make_pair(current_, kOwnPtrToGCManaged)); |
110 } | 107 } |
111 | 108 |
112 bool CheckFieldsVisitor::IsWarning(Error error) { | |
113 if (error == kRawPtrToGCManagedWarning) | |
114 return true; | |
115 if (error == kReferencePtrToGCManagedWarning) | |
116 return true; | |
117 return false; | |
118 } | |
119 | |
120 bool CheckFieldsVisitor::IsRawPtrError(Error error) { | |
121 return (error == kRawPtrToGCManaged || | |
122 error == kRawPtrToGCManagedWarning); | |
123 } | |
124 | |
125 bool CheckFieldsVisitor::IsReferencePtrError(Error error) { | |
126 return (error == kReferencePtrToGCManaged || | |
127 error == kReferencePtrToGCManagedWarning); | |
128 } | |
129 | |
130 CheckFieldsVisitor::Error CheckFieldsVisitor::InvalidSmartPtr(Edge* ptr) { | 109 CheckFieldsVisitor::Error CheckFieldsVisitor::InvalidSmartPtr(Edge* ptr) { |
131 if (ptr->IsRawPtr()) { | 110 if (ptr->IsRawPtr()) { |
132 if (static_cast<RawPtr*>(ptr)->HasReferenceType()) | 111 if (static_cast<RawPtr*>(ptr)->HasReferenceType()) |
133 return kReferencePtrToGCManaged; | 112 return kReferencePtrToGCManaged; |
134 else | 113 else |
135 return kRawPtrToGCManaged; | 114 return kRawPtrToGCManaged; |
136 } | 115 } |
137 if (ptr->IsRefPtr()) | 116 if (ptr->IsRefPtr()) |
138 return kRefPtrToGCManaged; | 117 return kRefPtrToGCManaged; |
139 if (ptr->IsOwnPtr()) | 118 if (ptr->IsOwnPtr()) |
140 return kOwnPtrToGCManaged; | 119 return kOwnPtrToGCManaged; |
141 assert(false && "Unknown smart pointer kind"); | 120 assert(false && "Unknown smart pointer kind"); |
142 } | 121 } |
OLD | NEW |