1
// This file is part of PUMA.
2
// Copyright (C) 1999-2003 The PUMA developer team.
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License as
6
// published by the Free Software Foundation; either version 2 of
7
// the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public
15
// License along with this program; if not, write to the Free
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19
#ifndef __CTypeInfo_h__
20
#define __CTypeInfo_h__
22
#include "Puma/Printable.h"
38
class CTypeMemberPointer;
39
class CTypeTemplateParam;
53
class CTypeInfo : public Printable {
54
// needed for type printing
56
PRINT_STD = 0, // standard
57
PRINT_PRE = 1, // printing a declarator prefix like '*' or '&'
58
PRINT_ABS = 2, // printing absolute names
59
PRINT_TPL = 4, // printing template argument list
60
PRINT_TDN = 8 // print typedef names instead of defined type
65
/* DO NOT CHANGE THIS ORDER */
77
TYPE_UNSIGNED_LONG_LONG,
104
// internal representation of size_t and ptrdiff_t types
105
static CTypeInfo *CTYPE_SIZE_T;
106
static CTypeInfo *CTYPE_PTRDIFF_T;
111
CObjectInfo *_TypedefInfo;
114
CTypeInfo (CTypeInfo *, TypeId);
117
bool operator ==(const CTypeInfo &) const;
118
bool operator !=(const CTypeInfo &) const;
120
void print (ostream& os) const;
121
void TypeText (ostream &, const char * = (const char*)0,
122
bool abs = false, bool tdef = false) const;
123
long int Dimension () const;
125
long int Size () const;
126
long int Align () const;
130
CTypeInfo *BaseType () const;
131
void BaseType (CTypeInfo *);
133
bool isTypedef () const;
134
CObjectInfo *TypedefInfo () const;
135
CTypeInfo *TypedefInfo (CObjectInfo *);
137
bool isComplete (unsigned long = 0) const;
138
bool isConst () const;
139
bool isVolatile () const;
140
bool isRestrict () const;
141
bool isDependent (bool = true) const;
143
CRecord *Record () const;
144
CClassInfo *ClassInfo () const;
145
CUnionInfo *UnionInfo () const;
146
CEnumInfo *EnumInfo () const;
147
CFunctionInfo *FunctionInfo () const;
149
CTypeInfo *PtrBaseType () const;
150
CTypeList *ArgTypes () const;
151
CTypeInfo *VirtualType () const;
152
CTypeInfo *UnqualType () const;
154
CTypeFunction *PtrToFct () const;
155
CTypeArray *PtrToArray () const;
157
CTypeQualified *TypeQualified () const;
158
CTypeFunction *TypeFunction () const;
159
CTypeBitField *TypeBitField () const;
160
CTypePointer *TypePointer () const;
161
CTypeMemberPointer *TypeMemberPointer () const;
162
CTypeAddress *TypeAddress () const;
163
CTypeArray *TypeArray () const;
164
CTypeVarArray *TypeVarArray () const;
165
CTypeClass *TypeClass () const;
166
CTypeUnion *TypeUnion () const;
167
CTypeRecord *TypeRecord () const;
168
CTypeEnum *TypeEnum () const;
169
CTypePrimitive *TypePrimitive () const;
170
CTypeInfo *TypeEmpty () const;
171
CTypeTemplateParam *TypeTemplateParam () const;
173
bool isQualified () const;
174
bool isPointer () const;
175
bool isPointerOrArray () const;
176
bool isAddress () const;
177
bool isRecord () const;
178
bool isClass () const;
179
bool isUnion () const;
180
bool isArray () const;
181
bool isFixedArray () const;
182
bool isVarArray () const;
183
bool isArithmetic () const;
184
bool isScalar () const;
185
bool isAggregate () const;
186
bool isInteger () const;
187
bool isVoid () const;
188
bool isEnum () const;
189
bool isReal () const;
190
bool isMemberPointer () const;
191
bool isUndefined () const;
192
bool isFunction () const;
193
bool isBitField () const;
194
bool isMethod () const;
195
bool isStdFunction () const;
196
bool isTemplate () const;
197
bool isTemplateInstance () const;
198
bool isTemplateParam () const;
199
bool isTypeParam () const;
200
bool isNonTypeParam () const;
201
bool isObject (unsigned long = 0) const;
204
bool is_bool () const;
205
bool is_char () const;
206
bool is_wchar_t () const;
207
bool is_short () const;
208
bool is_int () const;
209
bool is_long () const;
210
bool is_long_long () const;
211
bool is_signed_char () const;
212
bool is_unsigned_char () const;
213
bool is_unsigned_short () const;
214
bool is_unsigned_int () const;
215
bool is_unsigned_long () const;
216
bool is_unsigned_long_long () const;
217
bool is_float () const;
218
bool is_double () const;
219
bool is_long_double () const;
220
bool is_void () const;
221
bool is_undefined () const;
222
bool is_unknown_t () const;
223
bool is_ellipsis () const;
225
bool is_signed () const;
226
bool is_unsigned () const;
228
// arithmetic conversion rank (C only)
229
unsigned conv_rank () const;
230
// compare arithmetic types (C only)
231
bool operator >(const CTypeInfo &) const;
232
bool operator >=(const CTypeInfo &) const;
233
bool operator <=(const CTypeInfo &) const;
234
bool operator <(const CTypeInfo &) const;
236
// rank C++ arithmetic types
237
unsigned rank () const;
240
// Duplicate the given type structure.
241
#ifndef __puma // PUMA is confused by static and non-static declaration
244
CTypeInfo *Duplicate (const CTypeInfo *);
246
CTypeInfo *Duplicate () const;
248
// Destroy the given type structure.
249
static void Destroy (CTypeInfo *);
251
void Mangled (ostream &) const;
254
void TypeText (char, ostream &, const char * = (const char*)0) const;
255
void printName (char, ostream &, CObjectInfo *) const;
256
void printScope (char, ostream &, CObjectInfo *) const;
259
extern CTypeInfo CTYPE_EMPTY;
264
#include "Puma/CTypePrimitive.h"
265
#include "Puma/CTypeQualified.h"
266
#include "Puma/CTypeAddress.h"
267
#include "Puma/CTypeBitField.h"
268
#include "Puma/CTypeArray.h"
269
#include "Puma/CTypeVarArray.h"
270
#include "Puma/CTypePointer.h"
271
#include "Puma/CTypeMemberPointer.h"
272
#include "Puma/CTypeFunction.h"
273
#include "Puma/CTypeEnum.h"
274
#include "Puma/CTypeRecord.h"
275
#include "Puma/CTypeClass.h"
276
#include "Puma/CTypeUnion.h"
277
#include "Puma/CTypeTemplateParam.h"
282
inline CTypeInfo::CTypeInfo (CTypeInfo *info, CTypeInfo::TypeId id) :
283
_Base (info ? info : this),
287
inline CTypeInfo::~CTypeInfo ()
290
inline CTypeInfo *CTypeInfo::Duplicate () const
293
return Duplicate (this);
297
inline CTypeInfo::TypeId CTypeInfo::Id () const
300
inline bool CTypeInfo::operator !=(const CTypeInfo &type) const
301
{ return ! (*this == type); }
303
inline void CTypeInfo::print (ostream& out) const
304
{ TypeText ((char)PRINT_STD, out); }
305
inline void CTypeInfo::TypeText (ostream &out, const char *t, bool abs, bool tdef) const
306
{ char flags = (char)(abs ? PRINT_ABS : PRINT_STD);
307
if (tdef) flags |= (char)PRINT_TDN; TypeText (flags, out, t); }
309
inline long int CTypeInfo::Dimension () const
310
{ return TypeArray () ? TypeArray ()->Dimension () :
311
TypeBitField () ? TypeBitField ()->Dimension () : -1; }
313
inline bool CTypeInfo::isTypedef () const
314
{ return (bool)_TypedefInfo; }
315
inline CObjectInfo *CTypeInfo::TypedefInfo () const
316
{ return _TypedefInfo; }
318
inline bool CTypeInfo::isConst () const
319
{ return TypeQualified () && TypeQualified ()->isConst (); }
320
inline bool CTypeInfo::isVolatile () const
321
{ return TypeQualified () && TypeQualified ()->isVolatile (); }
322
inline bool CTypeInfo::isRestrict () const
323
{ return TypeQualified () && TypeQualified ()->isRestrict (); }
325
inline CRecord *CTypeInfo::Record () const
326
{ return TypeRecord () ? TypeRecord ()->Record () :
327
TypeFunction () ? TypeFunction ()->Record () :
328
TypeMemberPointer () ? TypeMemberPointer ()->Record () : (CRecord*)0; }
329
inline CEnumInfo *CTypeInfo::EnumInfo () const
330
{ return TypeEnum () ? TypeEnum ()->EnumInfo () : (CEnumInfo*)0; }
331
inline CFunctionInfo *CTypeInfo::FunctionInfo () const
332
{ return TypeFunction () ? TypeFunction ()->FunctionInfo () : (CFunctionInfo*)0; }
334
inline CTypeInfo *CTypeInfo::BaseType () const
335
{ assert(_Base); return _Base; }
336
inline void CTypeInfo::BaseType (CTypeInfo *type)
338
inline CTypeInfo *CTypeInfo::PtrBaseType () const
339
{ return VirtualType ()->BaseType (); }
341
inline CTypeList *CTypeInfo::ArgTypes () const
342
{ return TypeFunction () ? TypeFunction ()->ArgTypes () :
343
TypeQualified () ? TypeQualified ()->ArgTypes () : (CTypeList*)0; }
345
inline CTypePrimitive *CTypeInfo::TypePrimitive () const
346
{ return _Id < TYPE_CLASS ? (CTypePrimitive*)this : (CTypePrimitive*)0; }
347
inline CTypeQualified *CTypeInfo::TypeQualified () const
348
{ return _Id == TYPE_QUALIFIED ? (CTypeQualified*)this : (CTypeQualified*)0; }
349
inline CTypeFunction *CTypeInfo::TypeFunction () const
350
{ return _Id == TYPE_FUNCTION ? (CTypeFunction*)this : (CTypeFunction*)0; }
351
inline CTypeBitField *CTypeInfo::TypeBitField () const
352
{ return _Id == TYPE_BIT_FIELD ? (CTypeBitField*)this : (CTypeBitField*)0; }
353
inline CTypePointer *CTypeInfo::TypePointer () const
354
{ return _Id == TYPE_POINTER || _Id == TYPE_MEMBER_POINTER ? (CTypePointer*)this : (CTypePointer*)0; }
355
inline CTypeMemberPointer* CTypeInfo::TypeMemberPointer () const
356
{ return _Id == TYPE_MEMBER_POINTER ? (CTypeMemberPointer*)this : (CTypeMemberPointer*)0; }
357
inline CTypeAddress *CTypeInfo::TypeAddress () const
358
{ return _Id == TYPE_ADDRESS ? (CTypeAddress*)this : (CTypeAddress*)0; }
359
inline CTypeArray *CTypeInfo::TypeArray () const
360
{ return _Id == TYPE_ARRAY || _Id == TYPE_VAR_ARRAY ? (CTypeArray*)this : (CTypeArray*)0; }
361
inline CTypeVarArray *CTypeInfo::TypeVarArray () const
362
{ return _Id == TYPE_VAR_ARRAY ? (CTypeVarArray*)this : (CTypeVarArray*)0; }
363
inline CTypeRecord *CTypeInfo::TypeRecord () const
364
{ return _Id == TYPE_CLASS || _Id == TYPE_UNION ? (CTypeRecord*)this : (CTypeRecord*)0; }
365
inline CTypeClass *CTypeInfo::TypeClass () const
366
{ return _Id == TYPE_CLASS ? (CTypeClass*)this : (CTypeClass*)0; }
367
inline CTypeUnion *CTypeInfo::TypeUnion () const
368
{ return _Id == TYPE_UNION ? (CTypeUnion*)this : (CTypeUnion*)0; }
369
inline CTypeEnum *CTypeInfo::TypeEnum () const
370
{ return _Id == TYPE_ENUM ? (CTypeEnum*)this : (CTypeEnum*)0; }
371
inline CTypeInfo *CTypeInfo::TypeEmpty () const
372
{ return _Id == TYPE_EMPTY ? (CTypeInfo*)this : (CTypeInfo*)0; }
373
inline CTypeTemplateParam *CTypeInfo::TypeTemplateParam () const
374
{ return _Id == TYPE_TEMPLATE_PARAM ? (CTypeTemplateParam*)this : (CTypeTemplateParam*)0; }
376
inline CTypeInfo *CTypeInfo::VirtualType () const
377
{ return TypeQualified () || TypeBitField () || TypeAddress () ?
378
BaseType ()->VirtualType () : (CTypeInfo*)this; }
379
inline CTypeInfo *CTypeInfo::UnqualType () const
380
{ return TypeQualified () ? BaseType ()->UnqualType () : (CTypeInfo*)this; }
382
inline bool CTypeInfo::isQualified () const
383
{ return TypeQualified (); }
384
inline bool CTypeInfo::isTemplateParam () const
385
{ return VirtualType ()->TypeTemplateParam (); }
386
inline bool CTypeInfo::isPointer () const
387
{ return VirtualType ()->TypePointer (); }
388
inline bool CTypeInfo::isMemberPointer () const
389
{ return VirtualType ()->TypeMemberPointer (); }
390
inline bool CTypeInfo::isClass () const
391
{ return VirtualType ()->TypeClass (); }
392
inline bool CTypeInfo::isUnion () const
393
{ return VirtualType ()->TypeUnion (); }
394
inline bool CTypeInfo::isArray () const
395
{ return VirtualType ()->TypeArray (); }
396
inline bool CTypeInfo::isFixedArray () const
397
{ return VirtualType ()->TypeArray () &&
398
VirtualType ()->TypeArray ()->isFixed (); }
399
inline bool CTypeInfo::isVarArray () const
400
{ return VirtualType ()->TypeVarArray (); }
401
inline bool CTypeInfo::isEnum () const
402
{ return VirtualType ()->TypeEnum (); }
403
inline bool CTypeInfo::isFunction () const
404
{ return VirtualType ()->TypeFunction (); }
405
inline bool CTypeInfo::isBitField () const
406
{ return TypeBitField (); }
407
inline bool CTypeInfo::isUndefined () const
408
{ return VirtualType ()->is_undefined (); }
409
inline bool CTypeInfo::isInteger () const
410
{ return VirtualType ()->_Id < TYPE_FLOAT || VirtualType ()->isEnum (); }
411
inline bool CTypeInfo::isReal () const
412
{ CTypeInfo *base = VirtualType ();
413
return base->is_float () || base->is_double () || base->is_long_double (); }
414
inline bool CTypeInfo::isMethod () const
415
{ CTypeInfo *base = VirtualType ();
416
return base->TypeFunction () && base->TypeFunction ()->Record (); }
417
inline bool CTypeInfo::isStdFunction () const
418
{ return VirtualType ()->TypeFunction () && ! isMethod (); }
419
inline bool CTypeInfo::isPointerOrArray () const
420
{ CTypeInfo *base = VirtualType ();
421
return base->TypePointer () || base->TypeArray (); }
422
inline bool CTypeInfo::isAddress () const
423
{ return TypeAddress () || ((TypeQualified () || TypeBitField ()) &&
424
BaseType ()->isAddress ()); }
425
inline bool CTypeInfo::isRecord () const
426
{ return VirtualType ()->TypeRecord (); }
427
inline bool CTypeInfo::isScalar () const
428
{ return isArithmetic () || isPointer (); }
429
inline bool CTypeInfo::isAggregate () const
430
{ return isArray () || isClass () || isUnion (); }
431
inline bool CTypeInfo::isVoid () const
432
{ return VirtualType ()->is_void (); }
433
inline bool CTypeInfo::isObject (unsigned long pos) const
434
{ return ! isFunction () && (pos ? isComplete (pos) : true); }
435
inline bool CTypeInfo::isTypeParam () const
436
{ return isTemplateParam () &&
437
VirtualType ()->TypeTemplateParam ()->isType (); }
438
inline bool CTypeInfo::isNonTypeParam () const
439
{ return isTemplateParam () &&
440
! VirtualType ()->TypeTemplateParam ()->isType (); }
442
inline bool CTypeInfo::is_bool () const
443
{ return _Id == TYPE_BOOL; }
444
inline bool CTypeInfo::is_char () const
445
{ return _Id == TYPE_CHAR; }
446
inline bool CTypeInfo::is_wchar_t () const
447
{ return _Id == TYPE_WCHAR_T; }
448
inline bool CTypeInfo::is_short () const
449
{ return _Id == TYPE_SHORT; }
450
inline bool CTypeInfo::is_int () const
451
{ return _Id == TYPE_INT; }
452
inline bool CTypeInfo::is_long () const
453
{ return _Id == TYPE_LONG; }
454
inline bool CTypeInfo::is_long_long () const
455
{ return _Id == TYPE_LONG_LONG; }
456
inline bool CTypeInfo::is_signed_char () const
457
{ return _Id == TYPE_SIGNED_CHAR; }
458
inline bool CTypeInfo::is_unsigned_char () const
459
{ return _Id == TYPE_UNSIGNED_CHAR; }
460
inline bool CTypeInfo::is_unsigned_short () const
461
{ return _Id == TYPE_UNSIGNED_SHORT; }
462
inline bool CTypeInfo::is_unsigned_int () const
463
{ return _Id == TYPE_UNSIGNED_INT; }
464
inline bool CTypeInfo::is_unsigned_long () const
465
{ return _Id == TYPE_UNSIGNED_LONG; }
466
inline bool CTypeInfo::is_unsigned_long_long () const
467
{ return _Id == TYPE_UNSIGNED_LONG_LONG; }
468
inline bool CTypeInfo::is_float () const
469
{ return _Id == TYPE_FLOAT; }
470
inline bool CTypeInfo::is_double () const
471
{ return _Id == TYPE_DOUBLE; }
472
inline bool CTypeInfo::is_long_double () const
473
{ return _Id == TYPE_LONG_DOUBLE; }
474
inline bool CTypeInfo::is_void () const
475
{ return _Id == TYPE_VOID; }
476
inline bool CTypeInfo::is_unknown_t () const
477
{ return _Id == TYPE_UNKNOWN_T; }
478
inline bool CTypeInfo::is_undefined () const
479
{ return _Id == TYPE_UNDEFINED; }
480
inline bool CTypeInfo::is_ellipsis () const
481
{ return _Id == TYPE_ELLIPSIS; }
483
inline bool CTypeInfo::operator <=(const CTypeInfo &type) const
484
{ return ! (*this > type); }
485
inline bool CTypeInfo::operator >=(const CTypeInfo &type) const
486
{ return ! (*this < type); }
491
#endif /* __CTypeInfo_h__ */