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.
5 #include "CheckGCRootsVisitor.h"
7 CheckGCRootsVisitor::CheckGCRootsVisitor() {
10 CheckGCRootsVisitor::Errors
& CheckGCRootsVisitor::gc_roots() {
14 bool CheckGCRootsVisitor::ContainsGCRoots(RecordInfo
* info
) {
15 for (RecordInfo::Fields::iterator it
= info
->GetFields().begin();
16 it
!= info
->GetFields().end();
18 current_
.push_back(&it
->second
);
19 it
->second
.edge()->Accept(this);
22 return !gc_roots_
.empty();
25 void CheckGCRootsVisitor::VisitValue(Value
* edge
) {
26 // TODO: what should we do to check unions?
27 if (edge
->value()->record()->isUnion())
30 // Prevent infinite regress for cyclic part objects.
31 if (visiting_set_
.find(edge
->value()) != visiting_set_
.end())
34 visiting_set_
.insert(edge
->value());
35 // If the value is a part object, then continue checking for roots.
36 for (Context::iterator it
= context().begin();
37 it
!= context().end();
39 if (!(*it
)->IsCollection())
42 ContainsGCRoots(edge
->value());
43 visiting_set_
.erase(edge
->value());
46 void CheckGCRootsVisitor::VisitPersistent(Persistent
* edge
) {
47 gc_roots_
.push_back(current_
);
50 void CheckGCRootsVisitor::AtCollection(Collection
* edge
) {
52 gc_roots_
.push_back(current_
);