2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
8 #include "CompoundValueNode.h"
12 #include "Architecture.h"
13 #include "IntegerValue.h"
16 #include "ValueLoader.h"
17 #include "ValueLocation.h"
18 #include "ValueNodeContainer.h"
21 // #pragma mark - Child
24 class CompoundValueNode::Child
: public ValueNodeChild
{
26 Child(CompoundValueNode
* parent
, const BString
& name
)
33 virtual const BString
& Name() const
38 virtual ValueNode
* Parent() const
44 CompoundValueNode
* fParent
;
49 // #pragma mark - BaseTypeChild
52 class CompoundValueNode::BaseTypeChild
: public Child
{
54 BaseTypeChild(CompoundValueNode
* parent
, BaseType
* baseType
)
56 Child(parent
, baseType
->GetType()->Name()),
59 fBaseType
->AcquireReference();
62 virtual ~BaseTypeChild()
64 fBaseType
->ReleaseReference();
67 virtual Type
* GetType() const
69 return fBaseType
->GetType();
72 virtual status_t
ResolveLocation(ValueLoader
* valueLoader
,
73 ValueLocation
*& _location
)
75 // The parent's location refers to the location of the complete
76 // object. We want to extract the location of a member.
77 ValueLocation
* parentLocation
= fParent
->Location();
78 if (parentLocation
== NULL
)
81 ValueLocation
* location
;
82 status_t error
= fParent
->fType
->ResolveBaseTypeLocation(fBaseType
,
83 *parentLocation
, location
);
85 TRACE_LOCALS("CompoundValueNode::BaseTypeChild::ResolveLocation(): "
86 "ResolveBaseTypeLocation() failed: %s\n", strerror(error
));
99 // #pragma mark - MemberChild
102 class CompoundValueNode::MemberChild
: public Child
{
104 MemberChild(CompoundValueNode
* parent
, DataMember
* member
)
106 Child(parent
, member
->Name()),
109 fMember
->AcquireReference();
112 virtual ~MemberChild()
114 fMember
->ReleaseReference();
117 virtual Type
* GetType() const
119 return fMember
->GetType();
122 virtual status_t
ResolveLocation(ValueLoader
* valueLoader
,
123 ValueLocation
*& _location
)
125 // The parent's location refers to the location of the complete
126 // object. We want to extract the location of a member.
127 ValueLocation
* parentLocation
= fParent
->Location();
128 if (parentLocation
== NULL
)
131 ValueLocation
* location
;
132 status_t error
= fParent
->fType
->ResolveDataMemberLocation(fMember
,
133 *parentLocation
, location
);
135 TRACE_LOCALS("CompoundValueNode::MemberChild::ResolveLocation(): "
136 "ResolveDataMemberLocation() failed: %s\n", strerror(error
));
140 _location
= location
;
149 // #pragma mark - CompoundValueNode
152 CompoundValueNode::CompoundValueNode(ValueNodeChild
* nodeChild
,
155 ValueNode(nodeChild
),
158 fType
->AcquireReference();
162 CompoundValueNode::~CompoundValueNode()
164 fType
->ReleaseReference();
166 for (int32 i
= 0; Child
* child
= fChildren
.ItemAt(i
); i
++)
167 child
->ReleaseReference();
172 CompoundValueNode::GetType() const
179 CompoundValueNode::ResolvedLocationAndValue(ValueLoader
* valueLoader
,
180 ValueLocation
*& _location
, Value
*& _value
)
183 ValueLocation
* location
= NodeChild()->Location();
184 if (location
== NULL
)
187 location
->AcquireReference();
188 _location
= location
;
195 CompoundValueNode::CreateChildren(TeamTypeInformation
* info
)
197 if (!fChildren
.IsEmpty())
201 for (int32 i
= 0; BaseType
* baseType
= fType
->BaseTypeAt(i
); i
++) {
202 TRACE_LOCALS(" base %" B_PRId32
"\n", i
);
204 BaseTypeChild
* child
= new(std::nothrow
) BaseTypeChild(this, baseType
);
205 if (child
== NULL
|| !fChildren
.AddItem(child
)) {
210 child
->SetContainer(fContainer
);
214 for (int32 i
= 0; DataMember
* member
= fType
->DataMemberAt(i
); i
++) {
215 TRACE_LOCALS(" member %" B_PRId32
": \"%s\"\n", i
, member
->Name());
217 MemberChild
* child
= new(std::nothrow
) MemberChild(this, member
);
218 if (child
== NULL
|| !fChildren
.AddItem(child
)) {
223 child
->SetContainer(fContainer
);
226 if (fContainer
!= NULL
)
227 fContainer
->NotifyValueNodeChildrenCreated(this);
234 CompoundValueNode::CountChildren() const
236 return fChildren
.CountItems();
241 CompoundValueNode::ChildAt(int32 index
) const
243 return fChildren
.ItemAt(index
);