2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "EnumerationValueNode.h"
11 #include "EnumerationValue.h"
14 #include "ValueLoader.h"
15 #include "ValueLocation.h"
18 EnumerationValueNode::EnumerationValueNode(ValueNodeChild
* nodeChild
,
19 EnumerationType
* type
)
21 ChildlessValueNode(nodeChild
),
24 fType
->AcquireReference();
28 EnumerationValueNode::~EnumerationValueNode()
30 fType
->ReleaseReference();
35 EnumerationValueNode::GetType() const
42 EnumerationValueNode::ResolvedLocationAndValue(ValueLoader
* valueLoader
,
43 ValueLocation
*& _location
, Value
*& _value
)
46 ValueLocation
* location
= NodeChild()->Location();
50 TRACE_LOCALS(" TYPE_ENUMERATION\n");
53 type_code valueType
= 0;
55 // If a base type is known, try that.
56 if (PrimitiveType
* baseType
= dynamic_cast<PrimitiveType
*>(
58 valueType
= baseType
->TypeConstant();
59 if (!BVariant::TypeIsInteger(valueType
))
63 // If we don't have a value type yet, guess it from the type size.
65 // TODO: This is C source language specific!
66 switch (fType
->ByteSize()) {
68 valueType
= B_INT8_TYPE
;
71 valueType
= B_INT16_TYPE
;
75 valueType
= B_INT32_TYPE
;
78 valueType
= B_INT64_TYPE
;
83 // load the value data
85 status_t error
= valueLoader
->LoadValue(location
, valueType
, true,
90 // create the type object
91 Value
* value
= new(std::nothrow
) EnumerationValue(fType
, valueData
);
95 location
->AcquireReference();