2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "PrimitiveValueNode.h"
11 #include "BoolValue.h"
12 #include "FloatValue.h"
13 #include "IntegerValue.h"
16 #include "ValueLoader.h"
17 #include "ValueLocation.h"
20 PrimitiveValueNode::PrimitiveValueNode(ValueNodeChild
* nodeChild
,
23 ChildlessValueNode(nodeChild
),
26 fType
->AcquireReference();
30 PrimitiveValueNode::~PrimitiveValueNode()
32 fType
->ReleaseReference();
37 PrimitiveValueNode::GetType() const
44 PrimitiveValueNode::ResolvedLocationAndValue(ValueLoader
* valueLoader
,
45 ValueLocation
*& _location
, Value
*& _value
)
48 ValueLocation
* location
= NodeChild()->Location();
53 type_code valueType
= fType
->TypeConstant();
54 if (!BVariant::TypeIsNumber(valueType
) && valueType
!= B_BOOL_TYPE
) {
55 TRACE_LOCALS(" -> unknown type constant\n");
59 bool shortValueIsFine
= BVariant::TypeIsInteger(valueType
)
60 || valueType
== B_BOOL_TYPE
;
62 TRACE_LOCALS(" TYPE_PRIMITIVE: '%c%c%c%c'\n",
63 int(valueType
>> 24), int(valueType
>> 16),
64 int(valueType
>> 8), int(valueType
));
66 // load the value data
68 status_t error
= valueLoader
->LoadValue(location
, valueType
,
69 shortValueIsFine
, valueData
);
73 // create the type object
75 if (valueType
== B_BOOL_TYPE
)
76 value
= new(std::nothrow
) BoolValue(valueData
.ToBool());
77 else if (BVariant::TypeIsInteger(valueType
))
78 value
= new(std::nothrow
) IntegerValue(valueData
);
79 else if (BVariant::TypeIsFloat(valueType
))
80 value
= new(std::nothrow
) FloatValue(valueData
);
87 location
->AcquireReference();