headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / model / Type.cpp
blob318abf2f26d61ca1d56bdf4099a7399eed6b914e
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "Type.h"
10 // #pragma mark - BaseType
13 BaseType::~BaseType()
18 // #pragma mark - DataMember
21 DataMember::~DataMember()
26 // #pragma mark - EnumeratorValue
29 EnumeratorValue::~EnumeratorValue()
34 // #pragma mark - ArrayDimension
37 ArrayDimension::~ArrayDimension()
42 uint64
43 ArrayDimension::CountElements() const
45 Type* type = GetType();
47 if (type->Kind() == TYPE_ENUMERATION)
48 return dynamic_cast<EnumerationType*>(type)->CountValues();
50 if (type->Kind() == TYPE_SUBRANGE) {
51 SubrangeType* subrangeType = dynamic_cast<SubrangeType*>(type);
52 BVariant lower = subrangeType->LowerBound();
53 BVariant upper = subrangeType->UpperBound();
54 bool isSigned;
55 if (!lower.IsInteger(&isSigned) || !upper.IsInteger())
56 return 0;
58 return isSigned
59 ? upper.ToInt64() - lower.ToInt64() + 1
60 : upper.ToUInt64() - lower.ToUInt64() + 1;
63 return 0;
67 // #pragma mark - FunctionParameter
70 FunctionParameter::~FunctionParameter()
75 // #pragma mark - TemplateParameter
78 TemplateParameter::~TemplateParameter()
83 // #pragma mark - Type
86 Type::~Type()
91 Type*
92 Type::ResolveRawType(bool nextOneOnly) const
94 return const_cast<Type*>(this);
98 status_t
99 Type::CreateDerivedAddressType(address_type_kind kind,
100 AddressType*& _resultType)
102 _resultType = NULL;
103 return B_ERROR;
107 status_t
108 Type::CreateDerivedArrayType(int64 lowerBound, int64 elementCount,
109 bool extendExisting, ArrayType*& _resultType)
111 _resultType = NULL;
112 return B_ERROR;
116 // #pragma mark - PrimitiveType
119 PrimitiveType::~PrimitiveType()
124 type_kind
125 PrimitiveType::Kind() const
127 return TYPE_PRIMITIVE;
131 // #pragma mark - CompoundType
134 CompoundType::~CompoundType()
139 type_kind
140 CompoundType::Kind() const
142 return TYPE_COMPOUND;
146 // #pragma mark - ModifiedType
149 ModifiedType::~ModifiedType()
154 type_kind
155 ModifiedType::Kind() const
157 return TYPE_MODIFIED;
161 Type*
162 ModifiedType::ResolveRawType(bool nextOneOnly) const
164 Type* baseType = BaseType();
165 return nextOneOnly ? baseType : baseType->ResolveRawType(true);
169 // #pragma mark - TypedefType
172 TypedefType::~TypedefType()
177 type_kind
178 TypedefType::Kind() const
180 return TYPE_TYPEDEF;
184 Type*
185 TypedefType::ResolveRawType(bool nextOneOnly) const
187 Type* baseType = BaseType();
188 return nextOneOnly ? baseType : baseType->ResolveRawType(true);
192 // #pragma mark - AddressType
195 AddressType::~AddressType()
200 type_kind
201 AddressType::Kind() const
203 return TYPE_ADDRESS;
207 // #pragma mark - EnumerationType
210 EnumerationType::~EnumerationType()
215 type_kind
216 EnumerationType::Kind() const
218 return TYPE_ENUMERATION;
222 EnumeratorValue*
223 EnumerationType::ValueFor(const BVariant& value) const
225 // TODO: Optimize?
226 for (int32 i = 0; EnumeratorValue* enumValue = ValueAt(i); i++) {
227 if (enumValue->Value() == value)
228 return enumValue;
231 return NULL;
235 // #pragma mark - SubrangeType
238 SubrangeType::~SubrangeType()
243 type_kind
244 SubrangeType::Kind() const
246 return TYPE_SUBRANGE;
250 // #pragma mark - ArrayType
253 ArrayType::~ArrayType()
258 type_kind
259 ArrayType::Kind() const
261 return TYPE_ARRAY;
265 // #pragma mark - UnspecifiedType
268 UnspecifiedType::~UnspecifiedType()
273 type_kind
274 UnspecifiedType::Kind() const
276 return TYPE_UNSPECIFIED;
280 // #pragma mark - FunctionType
283 FunctionType::~FunctionType()
288 type_kind
289 FunctionType::Kind() const
291 return TYPE_FUNCTION;
295 // #pragma mark - PointerToMemberType
298 PointerToMemberType::~PointerToMemberType()
303 type_kind
304 PointerToMemberType::Kind() const
306 return TYPE_POINTER_TO_MEMBER;