2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "StackFrameValueInfos.h"
11 #include "FunctionID.h"
13 #include "TypeComponentPath.h"
14 #include "ValueLocation.h"
17 struct StackFrameValueInfos::Key
{
19 TypeComponentPath
* path
;
21 Key(ObjectID
* variable
, TypeComponentPath
* path
)
28 uint32
HashValue() const
30 return variable
->HashValue() ^ path
->HashValue();
33 bool operator==(const Key
& other
) const
35 return *variable
== *other
.variable
&& *path
== *other
.path
;
40 struct StackFrameValueInfos::InfoEntry
: Key
{
42 ValueLocation
* location
;
45 InfoEntry(ObjectID
* variable
, TypeComponentPath
* path
)
51 variable
->AcquireReference();
52 path
->AcquireReference();
58 variable
->ReleaseReference();
59 path
->ReleaseReference();
63 void SetInfo(Type
* type
, ValueLocation
* location
)
66 type
->AcquireReference();
68 location
->AcquireReference();
70 if (this->type
!= NULL
)
71 this->type
->ReleaseReference();
72 if (this->location
!= NULL
)
73 this->location
->ReleaseReference();
76 this->location
= location
;
81 struct StackFrameValueInfos::InfoEntryHashDefinition
{
83 typedef InfoEntry ValueType
;
85 size_t HashKey(const Key
& key
) const
87 return key
.HashValue();
90 size_t Hash(const InfoEntry
* value
) const
92 return value
->HashValue();
95 bool Compare(const Key
& key
, const InfoEntry
* value
) const
100 InfoEntry
*& GetLink(InfoEntry
* value
) const
107 StackFrameValueInfos::StackFrameValueInfos()
114 StackFrameValueInfos::~StackFrameValueInfos()
121 StackFrameValueInfos::Init()
123 fValues
= new(std::nothrow
) ValueTable
;
127 return fValues
->Init();
132 StackFrameValueInfos::GetInfo(ObjectID
* variable
,
133 const TypeComponentPath
* path
, Type
** _type
,
134 ValueLocation
** _location
) const
136 InfoEntry
* entry
= fValues
->Lookup(
137 Key(variable
, (TypeComponentPath
*)path
));
142 entry
->type
->AcquireReference();
143 *_type
= entry
->type
;
146 if (_location
!= NULL
) {
147 entry
->location
->AcquireReference();
148 *_location
= entry
->location
;
156 StackFrameValueInfos::HasInfo(ObjectID
* variable
,
157 const TypeComponentPath
* path
) const
159 return fValues
->Lookup(Key(variable
, (TypeComponentPath
*)path
)) != NULL
;
164 StackFrameValueInfos::SetInfo(ObjectID
* variable
, TypeComponentPath
* path
,
165 Type
* type
, ValueLocation
* location
)
167 InfoEntry
* entry
= fValues
->Lookup(Key(variable
, path
));
169 entry
= new(std::nothrow
) InfoEntry(variable
, path
);
172 fValues
->Insert(entry
);
175 entry
->SetInfo(type
, location
);
181 StackFrameValueInfos::_Cleanup()
183 if (fValues
!= NULL
) {
184 InfoEntry
* entry
= fValues
->Clear(true);
186 while (entry
!= NULL
) {
187 InfoEntry
* next
= entry
->next
;