headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / value / value_nodes / PrimitiveValueNode.cpp
blob82d3d65fdbc6b7208f9c76b8f7cd3a834d3f0c4d
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "PrimitiveValueNode.h"
9 #include <new>
11 #include "BoolValue.h"
12 #include "FloatValue.h"
13 #include "IntegerValue.h"
14 #include "Tracing.h"
15 #include "Type.h"
16 #include "ValueLoader.h"
17 #include "ValueLocation.h"
20 PrimitiveValueNode::PrimitiveValueNode(ValueNodeChild* nodeChild,
21 PrimitiveType* type)
23 ChildlessValueNode(nodeChild),
24 fType(type)
26 fType->AcquireReference();
30 PrimitiveValueNode::~PrimitiveValueNode()
32 fType->ReleaseReference();
36 Type*
37 PrimitiveValueNode::GetType() const
39 return fType;
43 status_t
44 PrimitiveValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
45 ValueLocation*& _location, Value*& _value)
47 // get the location
48 ValueLocation* location = NodeChild()->Location();
49 if (location == NULL)
50 return B_BAD_VALUE;
52 // get the value type
53 type_code valueType = fType->TypeConstant();
54 if (!BVariant::TypeIsNumber(valueType) && valueType != B_BOOL_TYPE) {
55 TRACE_LOCALS(" -> unknown type constant\n");
56 return B_UNSUPPORTED;
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
67 BVariant valueData;
68 status_t error = valueLoader->LoadValue(location, valueType,
69 shortValueIsFine, valueData);
70 if (error != B_OK)
71 return error;
73 // create the type object
74 Value* value;
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);
81 else
82 return B_UNSUPPORTED;
84 if (value == NULL)
85 return B_NO_MEMORY;
87 location->AcquireReference();
88 _location = location;
89 _value = value;
90 return B_OK;