vfs: check userland buffers before reading them.
[haiku.git] / headers / private / debugger / model / Type.h
blob8ebf55adbe5d3b2c2d40b2f873bf18afa39a09ad
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
9 #include <image.h>
11 #include <Referenceable.h>
12 #include <Variant.h>
14 #include "Types.h"
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
32 enum compound_type_kind {
33 COMPOUND_TYPE_CLASS,
34 COMPOUND_TYPE_STRUCT,
35 COMPOUND_TYPE_UNION,
36 COMPOUND_TYPE_INTERFACE
40 enum address_type_kind {
41 DERIVED_TYPE_POINTER,
42 DERIVED_TYPE_REFERENCE
46 enum template_type_kind {
47 TEMPLATE_TYPE_TYPE,
48 TEMPLATE_TYPE_VALUE
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
61 class AddressType;
62 class ArrayIndexPath;
63 class ArrayType;
64 class BString;
65 class Type;
66 class ValueLocation;
69 class BaseType : public BReferenceable {
70 public:
71 virtual ~BaseType();
73 virtual Type* GetType() const = 0;
77 class DataMember : public BReferenceable {
78 public:
79 virtual ~DataMember();
81 virtual const char* Name() const = 0;
82 virtual Type* GetType() const = 0;
86 class EnumeratorValue : public BReferenceable {
87 public:
88 virtual ~EnumeratorValue();
90 virtual const char* Name() const = 0;
91 virtual BVariant Value() const = 0;
95 class ArrayDimension : public BReferenceable {
96 public:
97 virtual ~ArrayDimension();
99 virtual Type* GetType() const = 0;
100 // subrange or enumeration
101 virtual uint64 CountElements() const;
102 // returns 0, if unknown
106 class FunctionParameter : public BReferenceable {
107 public:
108 virtual ~FunctionParameter();
110 virtual const char* Name() const = 0;
111 virtual Type* GetType() const = 0;
115 class TemplateParameter : public BReferenceable {
116 public:
117 virtual ~TemplateParameter();
119 virtual template_type_kind Kind() const = 0;
120 virtual Type* GetType() const = 0;
121 virtual BVariant Value() const = 0;
125 class Type : public BReferenceable {
126 public:
127 virtual ~Type();
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)
139 virtual status_t CreateDerivedAddressType(
140 address_type_kind kind,
141 AddressType*& _resultType);
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);
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
166 class PrimitiveType : public virtual Type {
167 public:
168 virtual ~PrimitiveType();
170 virtual type_kind Kind() const;
172 virtual uint32 TypeConstant() const = 0;
176 class CompoundType : public virtual Type {
177 public:
178 virtual ~CompoundType();
180 virtual type_kind Kind() const;
181 virtual compound_type_kind CompoundKind() const = 0;
183 virtual int32 CountBaseTypes() const = 0;
184 virtual BaseType* BaseTypeAt(int32 index) const = 0;
186 virtual int32 CountDataMembers() const = 0;
187 virtual DataMember* DataMemberAt(int32 index) const = 0;
189 virtual int32 CountTemplateParameters() const = 0;
190 virtual TemplateParameter* TemplateParameterAt(int32 index) const = 0;
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
204 class ModifiedType : public virtual Type {
205 public:
206 virtual ~ModifiedType();
208 virtual type_kind Kind() const;
210 virtual uint32 Modifiers() const = 0;
211 virtual Type* BaseType() const = 0;
212 virtual Type* ResolveRawType(bool nextOneOnly) const;
216 class TypedefType : public virtual Type {
217 public:
218 virtual ~TypedefType();
220 virtual type_kind Kind() const;
222 virtual Type* BaseType() const = 0;
223 virtual Type* ResolveRawType(bool nextOneOnly) const;
227 class AddressType : public virtual Type {
228 public:
229 virtual ~AddressType();
231 virtual type_kind Kind() const;
233 virtual address_type_kind AddressKind() const = 0;
234 virtual Type* BaseType() const = 0;
238 class EnumerationType : public virtual Type {
239 public:
240 virtual ~EnumerationType();
242 virtual type_kind Kind() const;
244 virtual Type* BaseType() const = 0;
245 // may return NULL
247 virtual int32 CountValues() const = 0;
248 virtual EnumeratorValue* ValueAt(int32 index) const = 0;
249 virtual EnumeratorValue* ValueFor(const BVariant& value) const;
253 class SubrangeType : public virtual Type {
254 public:
255 virtual ~SubrangeType();
257 virtual type_kind Kind() const;
259 virtual Type* BaseType() const = 0;
261 virtual BVariant LowerBound() const = 0;
262 virtual BVariant UpperBound() const = 0;
266 class ArrayType : public virtual Type {
267 public:
268 virtual ~ArrayType();
270 virtual type_kind Kind() const;
272 virtual Type* BaseType() const = 0;
274 virtual int32 CountDimensions() const = 0;
275 virtual ArrayDimension* DimensionAt(int32 index) const = 0;
277 virtual status_t ResolveElementLocation(
278 const ArrayIndexPath& indexPath,
279 const ValueLocation& parentLocation,
280 ValueLocation*& _location) = 0;
281 // returns a reference
285 class UnspecifiedType : public virtual Type {
286 public:
287 virtual ~UnspecifiedType();
289 virtual type_kind Kind() const;
293 class FunctionType : public virtual Type {
294 public:
295 virtual ~FunctionType();
297 virtual type_kind Kind() const;
299 virtual Type* ReturnType() const = 0;
301 virtual int32 CountParameters() const = 0;
302 virtual FunctionParameter* ParameterAt(int32 index) const = 0;
304 virtual bool HasVariableArguments() const = 0;
308 class PointerToMemberType : public virtual Type {
309 public:
310 virtual ~PointerToMemberType();
312 virtual type_kind Kind() const;
314 virtual CompoundType* ContainingType() const = 0;
315 virtual Type* BaseType() const = 0;
319 #endif // TYPE_H