1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "Type.h"
8
9
10// #pragma mark - BaseType
11
12
13BaseType::~BaseType()
14{
15}
16
17
18// #pragma mark - DataMember
19
20
21DataMember::~DataMember()
22{
23}
24
25
26// #pragma mark - EnumeratorValue
27
28
29EnumeratorValue::~EnumeratorValue()
30{
31}
32
33
34// #pragma mark - ArrayDimension
35
36
37ArrayDimension::~ArrayDimension()
38{
39}
40
41
42uint64
43ArrayDimension::CountElements() const
44{
45	Type* type = GetType();
46
47	if (type->Kind() == TYPE_ENUMERATION)
48		return dynamic_cast<EnumerationType*>(type)->CountValues();
49
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;
57
58		return isSigned
59			? upper.ToInt64() - lower.ToInt64() + 1
60			: upper.ToUInt64() - lower.ToUInt64() + 1;
61	}
62
63	return 0;
64}
65
66
67// #pragma mark - FunctionParameter
68
69
70FunctionParameter::~FunctionParameter()
71{
72}
73
74
75// #pragma mark - TemplateParameter
76
77
78TemplateParameter::~TemplateParameter()
79{
80}
81
82
83// #pragma mark - Type
84
85
86Type::~Type()
87{
88}
89
90
91Type*
92Type::ResolveRawType(bool nextOneOnly) const
93{
94	return const_cast<Type*>(this);
95}
96
97
98status_t
99Type::CreateDerivedAddressType(address_type_kind kind,
100	AddressType*& _resultType)
101{
102	_resultType = NULL;
103	return B_ERROR;
104}
105
106
107status_t
108Type::CreateDerivedArrayType(int64 lowerBound, int64 elementCount,
109	bool extendExisting, ArrayType*& _resultType)
110{
111	_resultType = NULL;
112	return B_ERROR;
113}
114
115
116// #pragma mark - PrimitiveType
117
118
119PrimitiveType::~PrimitiveType()
120{
121}
122
123
124type_kind
125PrimitiveType::Kind() const
126{
127	return TYPE_PRIMITIVE;
128}
129
130
131// #pragma mark - CompoundType
132
133
134CompoundType::~CompoundType()
135{
136}
137
138
139type_kind
140CompoundType::Kind() const
141{
142	return TYPE_COMPOUND;
143}
144
145
146// #pragma mark - ModifiedType
147
148
149ModifiedType::~ModifiedType()
150{
151}
152
153
154type_kind
155ModifiedType::Kind() const
156{
157	return TYPE_MODIFIED;
158}
159
160
161Type*
162ModifiedType::ResolveRawType(bool nextOneOnly) const
163{
164	Type* baseType = BaseType();
165	return nextOneOnly ? baseType : baseType->ResolveRawType(true);
166}
167
168
169// #pragma mark - TypedefType
170
171
172TypedefType::~TypedefType()
173{
174}
175
176
177type_kind
178TypedefType::Kind() const
179{
180	return TYPE_TYPEDEF;
181}
182
183
184Type*
185TypedefType::ResolveRawType(bool nextOneOnly) const
186{
187	Type* baseType = BaseType();
188	return nextOneOnly ? baseType : baseType->ResolveRawType(true);
189}
190
191
192// #pragma mark - AddressType
193
194
195AddressType::~AddressType()
196{
197}
198
199
200type_kind
201AddressType::Kind() const
202{
203	return TYPE_ADDRESS;
204}
205
206
207// #pragma mark - EnumerationType
208
209
210EnumerationType::~EnumerationType()
211{
212}
213
214
215type_kind
216EnumerationType::Kind() const
217{
218	return TYPE_ENUMERATION;
219}
220
221
222EnumeratorValue*
223EnumerationType::ValueFor(const BVariant& value) const
224{
225	// TODO: Optimize?
226	for (int32 i = 0; EnumeratorValue* enumValue = ValueAt(i); i++) {
227		if (enumValue->Value() == value)
228			return enumValue;
229	}
230
231	return NULL;
232}
233
234
235// #pragma mark - SubrangeType
236
237
238SubrangeType::~SubrangeType()
239{
240}
241
242
243type_kind
244SubrangeType::Kind() const
245{
246	return TYPE_SUBRANGE;
247}
248
249
250// #pragma mark - ArrayType
251
252
253ArrayType::~ArrayType()
254{
255}
256
257
258type_kind
259ArrayType::Kind() const
260{
261	return TYPE_ARRAY;
262}
263
264
265// #pragma mark - UnspecifiedType
266
267
268UnspecifiedType::~UnspecifiedType()
269{
270}
271
272
273type_kind
274UnspecifiedType::Kind() const
275{
276	return TYPE_UNSPECIFIED;
277}
278
279
280// #pragma mark - FunctionType
281
282
283FunctionType::~FunctionType()
284{
285}
286
287
288type_kind
289FunctionType::Kind() const
290{
291	return TYPE_FUNCTION;
292}
293
294
295// #pragma mark - PointerToMemberType
296
297
298PointerToMemberType::~PointerToMemberType()
299{
300}
301
302
303type_kind
304PointerToMemberType::Kind() const
305{
306	return TYPE_POINTER_TO_MEMBER;
307}
308