xref: /haiku/headers/private/debugger/model/Type.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef TYPE_H
6 #define TYPE_H
7 
8 
9 #include <image.h>
10 
11 #include <Referenceable.h>
12 #include <Variant.h>
13 
14 #include "Types.h"
15 
16 
17 enum type_kind {
18 	TYPE_PRIMITIVE,
19 	TYPE_COMPOUND,
20 	TYPE_MODIFIED,
21 	TYPE_TYPEDEF,
22 	TYPE_ADDRESS,
23 	TYPE_ENUMERATION,
24 	TYPE_SUBRANGE,
25 	TYPE_ARRAY,
26 	TYPE_UNSPECIFIED,
27 	TYPE_FUNCTION,
28 	TYPE_POINTER_TO_MEMBER
29 };
30 
31 
32 enum compound_type_kind {
33 	COMPOUND_TYPE_CLASS,
34 	COMPOUND_TYPE_STRUCT,
35 	COMPOUND_TYPE_UNION,
36 	COMPOUND_TYPE_INTERFACE
37 };
38 
39 
40 enum address_type_kind {
41 	DERIVED_TYPE_POINTER,
42 	DERIVED_TYPE_REFERENCE
43 };
44 
45 
46 enum template_type_kind {
47 	TEMPLATE_TYPE_TYPE,
48 	TEMPLATE_TYPE_VALUE
49 };
50 
51 
52 enum {
53 	TYPE_MODIFIER_CONST		= 0x01,
54 	TYPE_MODIFIER_VOLATILE	= 0x02,
55 	TYPE_MODIFIER_RESTRICT	= 0x04,
56 	TYPE_MODIFIER_PACKED	= 0x08,
57 	TYPE_MODIFIER_SHARED	= 0x10
58 };
59 
60 
61 class AddressType;
62 class ArrayIndexPath;
63 class ArrayType;
64 class BString;
65 class Type;
66 class ValueLocation;
67 
68 
69 class BaseType : public BReferenceable {
70 public:
71 	virtual						~BaseType();
72 
73 	virtual	Type*				GetType() const = 0;
74 };
75 
76 
77 class DataMember : public BReferenceable {
78 public:
79 	virtual						~DataMember();
80 
81 	virtual	const char*			Name() const = 0;
82 	virtual	Type*				GetType() const = 0;
83 };
84 
85 
86 class EnumeratorValue : public BReferenceable {
87 public:
88 	virtual						~EnumeratorValue();
89 
90 	virtual	const char*			Name() const = 0;
91 	virtual	BVariant			Value() const = 0;
92 };
93 
94 
95 class ArrayDimension : public BReferenceable {
96 public:
97 	virtual						~ArrayDimension();
98 
99 	virtual	Type*				GetType() const = 0;
100 									// subrange or enumeration
101 	virtual	uint64				CountElements() const;
102 									// returns 0, if unknown
103 };
104 
105 
106 class FunctionParameter : public BReferenceable {
107 public:
108 	virtual						~FunctionParameter();
109 
110 	virtual	const char*			Name() const = 0;
111 	virtual	Type*				GetType() const = 0;
112 };
113 
114 
115 class TemplateParameter : public BReferenceable {
116 public:
117 	virtual						~TemplateParameter();
118 
119 	virtual	template_type_kind	Kind() const = 0;
120 	virtual Type*				GetType() const = 0;
121 	virtual	BVariant			Value() const = 0;
122 };
123 
124 
125 class Type : public BReferenceable {
126 public:
127 	virtual						~Type();
128 
129 	virtual	image_id			ImageID() const = 0;
130 	virtual	const BString&		ID() const = 0;
131 	virtual	const BString&		Name() const = 0;
132 	virtual	type_kind			Kind() const = 0;
133 	virtual	target_size_t		ByteSize() const = 0;
134 	virtual	Type*				ResolveRawType(bool nextOneOnly) const;
135 									// strips modifiers and typedefs (only one,
136 									// if requested)
137 
138 
139 	virtual status_t			CreateDerivedAddressType(
140 									address_type_kind kind,
141 									AddressType*& _resultType);
142 
143 	virtual	status_t			CreateDerivedArrayType(
144 									int64 lowerBound,
145 									int64 elementCount,
146 									bool extendExisting,
147 										// if the current object is already
148 										// an array type, attach an extra
149 										// dimension to it rather than
150 										// creating a new encapsulating
151 										// type object
152 									ArrayType*& _resultType);
153 
154 
155 	virtual	status_t			ResolveObjectDataLocation(
156 									const ValueLocation& objectLocation,
157 									ValueLocation*& _location) = 0;
158 									// returns a reference
159 	virtual	status_t			ResolveObjectDataLocation(
160 									target_addr_t objectAddress,
161 									ValueLocation*& _location) = 0;
162 									// returns a reference
163 };
164 
165 
166 class PrimitiveType : public virtual Type {
167 public:
168 	virtual						~PrimitiveType();
169 
170 	virtual	type_kind			Kind() const;
171 
172 	virtual	uint32				TypeConstant() const = 0;
173 };
174 
175 
176 class CompoundType : public virtual Type {
177 public:
178 	virtual						~CompoundType();
179 
180 	virtual	type_kind			Kind() const;
181 	virtual compound_type_kind	CompoundKind() const = 0;
182 
183 	virtual	int32				CountBaseTypes() const = 0;
184 	virtual	BaseType*			BaseTypeAt(int32 index) const = 0;
185 
186 	virtual	int32				CountDataMembers() const = 0;
187 	virtual	DataMember*			DataMemberAt(int32 index) const = 0;
188 
189 	virtual int32				CountTemplateParameters() const = 0;
190 	virtual TemplateParameter*	TemplateParameterAt(int32 index) const = 0;
191 
192 
193 	virtual	status_t			ResolveBaseTypeLocation(BaseType* baseType,
194 									const ValueLocation& parentLocation,
195 									ValueLocation*& _location) = 0;
196 									// returns a reference
197 	virtual	status_t			ResolveDataMemberLocation(DataMember* member,
198 									const ValueLocation& parentLocation,
199 									ValueLocation*& _location) = 0;
200 									// returns a reference
201 };
202 
203 
204 class ModifiedType : public virtual Type {
205 public:
206 	virtual						~ModifiedType();
207 
208 	virtual	type_kind			Kind() const;
209 
210 	virtual	uint32				Modifiers() const = 0;
211 	virtual	Type*				BaseType() const = 0;
212 	virtual	Type*				ResolveRawType(bool nextOneOnly) const;
213 };
214 
215 
216 class TypedefType : public virtual Type {
217 public:
218 	virtual						~TypedefType();
219 
220 	virtual	type_kind			Kind() const;
221 
222 	virtual	Type*				BaseType() const = 0;
223 	virtual	Type*				ResolveRawType(bool nextOneOnly) const;
224 };
225 
226 
227 class AddressType : public virtual Type {
228 public:
229 	virtual						~AddressType();
230 
231 	virtual	type_kind			Kind() const;
232 
233 	virtual	address_type_kind	AddressKind() const = 0;
234 	virtual	Type*				BaseType() const = 0;
235 };
236 
237 
238 class EnumerationType : public virtual Type {
239 public:
240 	virtual						~EnumerationType();
241 
242 	virtual	type_kind			Kind() const;
243 
244 	virtual	Type*				BaseType() const = 0;
245 									// may return NULL
246 
247 	virtual	int32				CountValues() const = 0;
248 	virtual	EnumeratorValue*	ValueAt(int32 index) const = 0;
249 	virtual	EnumeratorValue*	ValueFor(const BVariant& value) const;
250 };
251 
252 
253 class SubrangeType : public virtual Type {
254 public:
255 	virtual						~SubrangeType();
256 
257 	virtual	type_kind			Kind() const;
258 
259 	virtual	Type*				BaseType() const = 0;
260 
261 	virtual	BVariant			LowerBound() const = 0;
262 	virtual	BVariant			UpperBound() const = 0;
263 };
264 
265 
266 class ArrayType : public virtual Type {
267 public:
268 	virtual						~ArrayType();
269 
270 	virtual	type_kind			Kind() const;
271 
272 	virtual	Type*				BaseType() const = 0;
273 
274 	virtual	int32				CountDimensions() const = 0;
275 	virtual	ArrayDimension*		DimensionAt(int32 index) const = 0;
276 
277 	virtual	status_t			ResolveElementLocation(
278 									const ArrayIndexPath& indexPath,
279 									const ValueLocation& parentLocation,
280 									ValueLocation*& _location) = 0;
281 									// returns a reference
282 };
283 
284 
285 class UnspecifiedType : public virtual Type {
286 public:
287 	virtual						~UnspecifiedType();
288 
289 	virtual	type_kind			Kind() const;
290 };
291 
292 
293 class FunctionType : public virtual Type {
294 public:
295 	virtual						~FunctionType();
296 
297 	virtual	type_kind			Kind() const;
298 
299 	virtual	Type*				ReturnType() const = 0;
300 
301 	virtual	int32				CountParameters() const = 0;
302 	virtual	FunctionParameter*	ParameterAt(int32 index) const = 0;
303 
304 	virtual	bool				HasVariableArguments() const = 0;
305 };
306 
307 
308 class PointerToMemberType : public virtual Type {
309 public:
310 	virtual						~PointerToMemberType();
311 
312 	virtual	type_kind			Kind() const;
313 
314 	virtual	CompoundType*		ContainingType() const = 0;
315 	virtual	Type*				BaseType() const = 0;
316 };
317 
318 
319 #endif	// TYPE_H
320