headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / value / value_nodes / EnumerationValueNode.cpp
blob6cff1f4d22f752edf636705e27ac4be2dded47ec
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "EnumerationValueNode.h"
9 #include <new>
11 #include "EnumerationValue.h"
12 #include "Tracing.h"
13 #include "Type.h"
14 #include "ValueLoader.h"
15 #include "ValueLocation.h"
18 EnumerationValueNode::EnumerationValueNode(ValueNodeChild* nodeChild,
19 EnumerationType* type)
21 ChildlessValueNode(nodeChild),
22 fType(type)
24 fType->AcquireReference();
28 EnumerationValueNode::~EnumerationValueNode()
30 fType->ReleaseReference();
34 Type*
35 EnumerationValueNode::GetType() const
37 return fType;
41 status_t
42 EnumerationValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
43 ValueLocation*& _location, Value*& _value)
45 // get the location
46 ValueLocation* location = NodeChild()->Location();
47 if (location == NULL)
48 return B_BAD_VALUE;
50 TRACE_LOCALS(" TYPE_ENUMERATION\n");
52 // get the value type
53 type_code valueType = 0;
55 // If a base type is known, try that.
56 if (PrimitiveType* baseType = dynamic_cast<PrimitiveType*>(
57 fType->BaseType())) {
58 valueType = baseType->TypeConstant();
59 if (!BVariant::TypeIsInteger(valueType))
60 valueType = 0;
63 // If we don't have a value type yet, guess it from the type size.
64 if (valueType == 0) {
65 // TODO: This is C source language specific!
66 switch (fType->ByteSize()) {
67 case 1:
68 valueType = B_INT8_TYPE;
69 break;
70 case 2:
71 valueType = B_INT16_TYPE;
72 break;
73 case 4:
74 default:
75 valueType = B_INT32_TYPE;
76 break;
77 case 8:
78 valueType = B_INT64_TYPE;
79 break;
83 // load the value data
84 BVariant valueData;
85 status_t error = valueLoader->LoadValue(location, valueType, true,
86 valueData);
87 if (error != B_OK)
88 return error;
90 // create the type object
91 Value* value = new(std::nothrow) EnumerationValue(fType, valueData);
92 if (value == NULL)
93 return B_NO_MEMORY;
95 location->AcquireReference();
96 _location = location;
97 _value = value;
98 return B_OK;