~ubuntu-branches/ubuntu/jaunty/aspectc++/jaunty

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/inc/Puma/CTypeInfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-07-07 14:41:02 UTC
  • mfrom: (1.1.3 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707144102-lzml7t07f3sl00r5
Tags: 1.0pre4~svn.20080711-1
* new upstream snapshot.
* include all upstream documentation. Clarifying emails regarding
  licensing has been included into debian/copyright.
* reformat description following recomendations of
  http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
  (Closes: #480316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifndef __CTypeInfo_h__
20
20
#define __CTypeInfo_h__
21
21
 
 
22
/** \file
 
23
 *  Entity type information. */
 
24
 
22
25
#include "Puma/Printable.h"
23
26
 
24
27
namespace Puma {
25
28
 
26
29
 
27
 
class CClassDatabase;
 
30
class CSemDatabase;
28
31
class CRecord;
29
32
class CClassInfo;
30
33
class CUnionInfo;
49
52
class CObjectInfo;
50
53
class CScopeInfo;
51
54
class CTemplateParamInfo;
52
 
//class ostream;
53
 
 
 
55
 
 
56
 
 
57
/** \class CTypeInfo CTypeInfo.h Puma/CTypeInfo.h
 
58
 *  Type information for an entity (class, function, object, etc). 
 
59
 *  There are two kinds of types: fundamental types like 'int', 
 
60
 *  and compound types like 'class X {int i;}'. Types describe 
 
61
 *  objects, references, or functions. 
 
62
 *
 
63
 *  A type is identified by its ID.
 
64
 *  \code 
 
65
 * // check if type is a function type
 
66
 * if (type.Id() == Puma::CTypeInfo::TYPE_FUNCTION) {
 
67
 *   ...
 
68
 * }
 
69
 * // same check
 
70
 * if (type.TypeFunction()) {
 
71
 *   ...
 
72
 * }
 
73
 * // same check
 
74
 * if (type.isFunction()) {
 
75
 *   ...
 
76
 * }
 
77
 *  \endcode */
54
78
class CTypeInfo : public Printable {
55
79
  // needed for type printing
56
80
  enum PrintState {
63
87
  };
64
88
 
65
89
public:
 
90
  /** Type identifiers. */
66
91
  enum TypeId {
67
 
    /* DO NOT CHANGE THIS ORDER */
 
92
    // DO NOT CHANGE THIS ORDER!!!
 
93
    /** bool */
68
94
    TYPE_BOOL,
 
95
    /** signed char */
69
96
    TYPE_SIGNED_CHAR,
 
97
    /** unsiged char */
70
98
    TYPE_UNSIGNED_CHAR,
 
99
    /** char */
71
100
    TYPE_CHAR,
 
101
    /** unsigned short */
72
102
    TYPE_UNSIGNED_SHORT,
 
103
    /** short */
73
104
    TYPE_SHORT,
 
105
    /** unsigned int */
74
106
    TYPE_UNSIGNED_INT,
 
107
    /** wchar_t */
75
108
    TYPE_WCHAR_T,
 
109
    /** int */
76
110
    TYPE_INT,
 
111
    /** unsigned long */
77
112
    TYPE_UNSIGNED_LONG,
 
113
    /** long */
78
114
    TYPE_LONG,
 
115
    /** unsigned long long */
79
116
    TYPE_UNSIGNED_LONG_LONG,
 
117
    /** long long */
80
118
    TYPE_LONG_LONG,
 
119
    /** float */
81
120
    TYPE_FLOAT,
 
121
    /** double */
82
122
    TYPE_DOUBLE,
 
123
    /** long double */
83
124
    TYPE_LONG_DOUBLE,
84
125
 
 
126
    /** void */
85
127
    TYPE_VOID,
 
128
    /** Undefined type. */
86
129
    TYPE_UNDEFINED,
 
130
    /** unknown_t */
87
131
    TYPE_UNKNOWN_T,
 
132
    /** Any type. */
88
133
    TYPE_ELLIPSIS,
89
134
    
 
135
    /** Class type. */
90
136
    TYPE_CLASS,
 
137
    /** Union type. */
91
138
    TYPE_UNION,
 
139
    /** Enumeration type. */
92
140
    TYPE_ENUM,
 
141
    /** Pointer type. */
93
142
    TYPE_POINTER,
 
143
    /** Reference type. */
94
144
    TYPE_ADDRESS,
 
145
    /** Member pointer type. */
95
146
    TYPE_MEMBER_POINTER,
 
147
    /** Function type. */
96
148
    TYPE_FUNCTION,
 
149
    /** Array type. */
97
150
    TYPE_ARRAY,
 
151
    /** Variable length array type. */
98
152
    TYPE_VAR_ARRAY,
 
153
    /** Qualified type. */
99
154
    TYPE_QUALIFIED,
 
155
    /** Bitfield type. */
100
156
    TYPE_BIT_FIELD,
101
157
    
 
158
    /** Template parameter type. */
102
159
    TYPE_TEMPLATE_PARAM,
 
160
    /** No type. */
103
161
    TYPE_EMPTY
104
162
  };
105
163
  
106
 
  // internal representation of size_t and ptrdiff_t types
 
164
  /** Internal representation of size_t. */
107
165
  static CTypeInfo *CTYPE_SIZE_T;
 
166
  /** Internal representation of ptrdiff_t. */
108
167
  static CTypeInfo *CTYPE_PTRDIFF_T;
109
168
 
110
169
private:
113
172
  CObjectInfo *_TypedefInfo;
114
173
 
115
174
public:
116
 
  CTypeInfo (CTypeInfo *, TypeId);
 
175
  /** Constructor.
 
176
   *  \param base The base type of a compound type.
 
177
   *  \param id The type ID. */
 
178
  CTypeInfo (CTypeInfo *base, TypeId id);
 
179
  /** Destructor. */
117
180
  ~CTypeInfo ();
118
181
 
119
 
  bool operator ==(const CTypeInfo &) const;
120
 
  bool operator !=(const CTypeInfo &) const;
 
182
  /** Check if this type equals the given type. 
 
183
   *  \param type The type to compare with. */
 
184
  bool operator ==(const CTypeInfo &type) const;
 
185
  /** Check if this type not equals the given type. 
 
186
   *  \param type The type to compare with. */
 
187
  bool operator !=(const CTypeInfo &type) const;
121
188
  
 
189
  /** Print the textual representation of this 
 
190
   *  type on the given stream.
 
191
   *  \param os The output stream. */
122
192
  void print (ostream& os) const;
123
 
  void TypeText (ostream &, const char *name = (const char*)0,
 
193
  /** Print the textual representation of this 
 
194
   *  type on the given stream.
 
195
   *  \param os The output stream. 
 
196
   *  \param name Optional name of the entity to print. 
 
197
   *  \param abs Print qualified names with root qualifier. 
 
198
   *  \param tdef Print the name of a typedef instead of the underlying type.
 
199
   *  \param elaborated_type_spec Print elaborated type specifier before 
 
200
   *                              class, union, and enumeration types. */
 
201
  void TypeText (ostream &os, const char *name = (const char*)0,
124
202
                 bool abs = false, bool tdef = false, 
125
203
                 bool elaborated_type_spec = false) const;
 
204
  
 
205
  /** Get the dimension of an array type. */
126
206
  long int Dimension () const;
127
 
  
 
207
  /** Get the size in bits of a type. */
128
208
  long int Size () const;
 
209
  /** Get the alignment of a type. */
129
210
  long int Align () const;
130
211
 
 
212
  /** Get the type identifier. */
131
213
  TypeId Id () const;
132
214
 
 
215
  /** Get the base type of a compound type. 
 
216
   *  \return The base type or this if not a compound type. */
133
217
  CTypeInfo *BaseType () const;
134
 
  void BaseType (CTypeInfo *);
 
218
  /** Set the base type of a compount type.
 
219
   *  \param base The base type. */
 
220
  void BaseType (CTypeInfo *base);
135
221
 
 
222
  /** Check if this is a typedef type. */
136
223
  bool isTypedef () const;
 
224
  /** Get the typedef information if this is a typedef type. */
137
225
  CObjectInfo *TypedefInfo () const;
 
226
  /** Set the typedef information if this is a typedef type. */
138
227
  CTypeInfo *TypedefInfo (CObjectInfo *);
139
228
 
140
 
  bool isComplete (unsigned long = 0) const;
 
229
  /** Check if this is a complete type. Optionally limited to
 
230
   *  a specific source code position. A type is complete
 
231
   *  if it is not undefined, not void, not an fixed length
 
232
   *  array without dimension, and not a class or enumeration 
 
233
   *  that is only declared but not defined.
 
234
   *  \param pos Optional source code position. */
 
235
  bool isComplete (unsigned long pos = 0) const;
 
236
  
 
237
  /** Check if this type or one of its base types depends on 
 
238
   *  a template parameter. 
 
239
   *  \param consider_unknown_t Consider unknown_t as dependent. */
 
240
  bool isDependent (bool consider_unknown_t = true) const;
 
241
 
 
242
  /** Check if this type is \e const qualified. */
141
243
  bool isConst () const;
 
244
  /** Check if this type is \e volatile qualified. */
142
245
  bool isVolatile () const;
 
246
  /** Check if this type is \e restrict qualified. */
143
247
  bool isRestrict () const;
144
 
  bool isDependent (bool = true) const;
145
 
  
 
248
 
 
249
  /** Get the class or union of a class or union type.
 
250
   *  \return The class or union, or NULL if not such a type. */  
146
251
  CRecord *Record () const;
 
252
  /** Get the class information if this is a class type.
 
253
   *  \return The class information or NULL if not a class type. */  
147
254
  CClassInfo *ClassInfo () const;
 
255
  /** Get the union information if this is a union type.
 
256
   *  \return The union information or NULL if not a union type. */  
148
257
  CUnionInfo *UnionInfo () const;
 
258
  /** Get the enumeration information if this is an enumeration type.
 
259
   *  \return The enumeration information or NULL if not an enumeration type. */  
149
260
  CEnumInfo *EnumInfo () const;
 
261
  /** Get the function information if this is a function type.
 
262
   *  \return The function information or NULL if not a function type. */  
150
263
  CFunctionInfo *FunctionInfo () const;
151
264
 
 
265
  /** Get the base type of a pointer type. */
152
266
  CTypeInfo *PtrBaseType () const;
 
267
  /** Get the argument type list of a function or qualified type. */
153
268
  CTypeList *ArgTypes () const;
 
269
  /** Get the virtual type of this type. If this type is a qualified, 
 
270
   *  bit-field, or reference type then the virtual type is the 
 
271
   *  virtual type of the base type of this type. 
 
272
   *  \return The base type or this. */
154
273
  CTypeInfo *VirtualType () const;
 
274
  /** Get the unqualified version of this type.
 
275
   *  \return The unqualified type or this if not qualified. */
155
276
  CTypeInfo *UnqualType () const;
156
277
    
 
278
  /** Get the function type of a pointer-to-function type.
 
279
   *  \return The function type or NULL if not a pointer to function. */
157
280
  CTypeFunction *PtrToFct () const;
 
281
  /** Get the array type of a pointer-to-array type.
 
282
   *  \return The array type or NULL if not a pointer to array. */
158
283
  CTypeArray *PtrToArray () const;
159
284
  
 
285
  /** Get the pointer to CTypeQualified if this is a qualified type. 
 
286
   *  \return The valid pointer or NULL. */
160
287
  CTypeQualified *TypeQualified () const;
 
288
  /** Get the pointer to CTypeFunction if this is a function type.
 
289
   *  \return The valid pointer or NULL. */
161
290
  CTypeFunction *TypeFunction () const;
 
291
  /** Get the pointer to CTypeBitField if this is a bit-field type.
 
292
   *  \return The valid pointer or NULL. */
162
293
  CTypeBitField *TypeBitField () const; 
 
294
  /** Get the pointer to CTypePointer if this is a pointer type.
 
295
   *  \return The valid pointer or NULL. */
163
296
  CTypePointer *TypePointer () const; 
 
297
  /** Get the pointer to CTypeMemberPointer if this is a member pointer type.
 
298
   *  \return The valid pointer or NULL. */
164
299
  CTypeMemberPointer *TypeMemberPointer () const; 
 
300
  /** Get the pointer to CTypeAddress if this is a reference type.
 
301
   *  \return The valid pointer or NULL. */
165
302
  CTypeAddress *TypeAddress () const; 
 
303
  /** Get the pointer to CTypeArray if this is an array type.
 
304
   *  \return The valid pointer or NULL. */
166
305
  CTypeArray *TypeArray () const; 
 
306
  /** Get the pointer to CTypeVarArray if this is a variable length array type.
 
307
   *  \return The valid pointer or NULL. */
167
308
  CTypeVarArray *TypeVarArray () const;
 
309
  /** Get the pointer to CTypeClass if this is a class type.
 
310
   *  \return The valid pointer or NULL. */
168
311
  CTypeClass *TypeClass () const;
 
312
  /** Get the pointer to CTypeUnion if this is a union type.
 
313
   *  \return The valid pointer or NULL. */
169
314
  CTypeUnion *TypeUnion () const;
 
315
  /** Get the pointer to CTypeRecord if this is a class or union type.
 
316
   *  \return The valid pointer or NULL. */
170
317
  CTypeRecord *TypeRecord () const;
 
318
  /** Get the pointer to CTypeEnum if this is an enumeration type.
 
319
   *  \return The valid pointer or NULL. */
171
320
  CTypeEnum *TypeEnum () const;
 
321
  /** Get the pointer to CTypePrimitive if this is a primitive type.
 
322
   *  \return The valid pointer or NULL. */
172
323
  CTypePrimitive *TypePrimitive () const;
 
324
  /** Get the pointer to CTypeInfo if this is type Puma::CTYPE_EMPTY.
 
325
   *  \return The valid pointer or NULL. */
173
326
  CTypeInfo *TypeEmpty () const;
 
327
  /** Get the pointer to CTypeTemplateParam if this is a template parameter type.
 
328
   *  \return The valid pointer or NULL. */
174
329
  CTypeTemplateParam *TypeTemplateParam () const;
175
330
 
 
331
  /** Check if this is a qualified type. */
176
332
  bool isQualified () const;
 
333
  /** Check if this is a pointer type. */
177
334
  bool isPointer () const;
 
335
  /** Check if this is a pointer or array type. */
178
336
  bool isPointerOrArray () const;
 
337
  /** Check if this is a reference type. */
179
338
  bool isAddress () const;
 
339
  /** Check if this is a class or union type. */
180
340
  bool isRecord () const;
 
341
  /** Check if this is a class type. */
181
342
  bool isClass () const;
 
343
  /** Check if this is a union type. */
182
344
  bool isUnion () const;
 
345
  /** Check if this is an array type. */
183
346
  bool isArray () const;
 
347
  /** Check if this is a fixed length array type. */
184
348
  bool isFixedArray () const;
 
349
  /** Check if this is a variable length type. */
185
350
  bool isVarArray () const;
 
351
  /** Check if this is an arithmetic type. */
186
352
  bool isArithmetic () const;
 
353
  /** Check if this is a pointer or arithmetic type. */
187
354
  bool isScalar () const;
 
355
  /** Check if this is an array, class, or union type. */
188
356
  bool isAggregate () const;
 
357
  /** Check if this is an integer type. */
189
358
  bool isInteger () const;
 
359
  /** Check if this is type \e void. */
190
360
  bool isVoid () const;
 
361
  /** Check if this is an enumeration type. */
191
362
  bool isEnum () const;
 
363
  /** Check if this is a floating point type. */
192
364
  bool isReal () const;
 
365
  /** Check if this is a member pointer type. */
193
366
  bool isMemberPointer () const;
 
367
  /** Check if this is an undefined type. */
194
368
  bool isUndefined () const;
 
369
  /** Check if this is a function type. */
195
370
  bool isFunction () const;
 
371
  /** Check if this is a bit-field type. */
196
372
  bool isBitField () const;
 
373
  /** Check if this is a class member function type. */
197
374
  bool isMethod () const;
 
375
  /** Check if this is a non-class-member function type. */
198
376
  bool isStdFunction () const;
 
377
  /** Check if this is a template type. */
199
378
  bool isTemplate () const;
 
379
  /** Check if this is a template instance type. */
200
380
  bool isTemplateInstance () const;
 
381
  /** Check if this is a template parameter type. */
201
382
  bool isTemplateParam () const;
 
383
  /** Check if this is a type template parameter type. */
202
384
  bool isTypeParam () const;
 
385
  /** Check if this is a non-type template parameter type. */
203
386
  bool isNonTypeParam () const;
204
 
  bool isObject (unsigned long = 0) const;
 
387
  /** Check if this is an object type. An object type is a 
 
388
   *  complete non-function type. 
 
389
   *  \param pos Optional source code position. */
 
390
  bool isObject (unsigned long pos = 0) const;
205
391
 
206
392
  // Primitive types.
 
393
  /** Check if the ID of this type is CTypeInfo::TYPE_BOOL. */
207
394
  bool is_bool () const;
 
395
  /** Check if the ID of this type is CTypeInfo::TYPE_CHAR. */
208
396
  bool is_char () const;
 
397
  /** Check if the ID of this type is CTypeInfo::TYPE_WCHAR_T. */
209
398
  bool is_wchar_t () const;
 
399
  /** Check if the ID of this type is CTypeInfo::TYPE_SHORT. */
210
400
  bool is_short () const;
 
401
  /** Check if the ID of this type is CTypeInfo::TYPE_INT. */
211
402
  bool is_int () const;
 
403
  /** Check if the ID of this type is CTypeInfo::TYPE_LONG. */
212
404
  bool is_long () const;
 
405
  /** Check if the ID of this type is CTypeInfo::TYPE_LONG_LONG. */
213
406
  bool is_long_long () const;
 
407
  /** Check if the ID of this type is CTypeInfo::TYPE_SIGNED_CHAR. */
214
408
  bool is_signed_char () const;
 
409
  /** Check if the ID of this type is CTypeInfo::TYPE_UNSIGNED_CHAR. */
215
410
  bool is_unsigned_char () const;
 
411
  /** Check if the ID of this type is CTypeInfo::TYPE_UNSIGNED_SHORT. */
216
412
  bool is_unsigned_short () const;
 
413
  /** Check if the ID of this type is CTypeInfo::TYPE_UNSIGNED_INT. */
217
414
  bool is_unsigned_int () const;
 
415
  /** Check if the ID of this type is CTypeInfo::TYPE_UNSIGNED_LONG. */
218
416
  bool is_unsigned_long () const;
 
417
  /** Check if the ID of this type is CTypeInfo::TYPE_UNSIGNED_LONG_LONG. */
219
418
  bool is_unsigned_long_long () const;
 
419
  /** Check if the ID of this type is CTypeInfo::TYPE_FLOAT. */
220
420
  bool is_float () const;
 
421
  /** Check if the ID of this type is CTypeInfo::TYPE_DOUBLE. */
221
422
  bool is_double () const;
 
423
  /** Check if the ID of this type is CTypeInfo::TYPE_LONG_DOUBLE. */
222
424
  bool is_long_double () const;
 
425
  /** Check if the ID of this type is CTypeInfo::TYPE_VOID. */
223
426
  bool is_void () const;
 
427
  /** Check if the ID of this type is CTypeInfo::TYPE_UNDEFINED. */
224
428
  bool is_undefined () const;
 
429
  /** Check if the ID of this type is CTypeInfo::TYPE_UNKNOWN_T. */
225
430
  bool is_unknown_t () const;
 
431
  /** Check if the ID of this type is CTypeInfo::TYPE_ELLIPSIS. */
226
432
  bool is_ellipsis () const;
227
433
  
 
434
  /** Check if this is a signed integer type. */
228
435
  bool is_signed () const;
 
436
  /** Check if this is an unsigned integer type. */
229
437
  bool is_unsigned () const;
230
438
 
231
 
  // arithmetic conversion rank (C only)
 
439
  /** Get the arithmetic conversion rank of the type.
 
440
   *  \note Language C only! */
232
441
  unsigned conv_rank () const;
233
 
  // compare arithmetic types (C only)
234
 
  bool operator >(const CTypeInfo &) const;
235
 
  bool operator >=(const CTypeInfo &) const;
236
 
  bool operator <=(const CTypeInfo &) const;
237
 
  bool operator <(const CTypeInfo &) const;
 
442
  /** Check if the conversion rank of this type is greater
 
443
   *  than the conversion rank of the given type.
 
444
   *  \note Language C only!
 
445
   *  \param type The type to compare with. */
 
446
  bool operator >(const CTypeInfo &type) const;
 
447
  /** Check if the conversion rank of this type equals or
 
448
   *  is greater than the conversion rank of the given type.
 
449
   *  \note Language C only!
 
450
   *  \param type The type to compare with. */
 
451
  bool operator >=(const CTypeInfo &type) const;
 
452
  /** Check if the conversion rank of this type equals or
 
453
   *  is greater than the conversion rank of the given type.
 
454
   *  \note Language C only!
 
455
   *  \param type The type to compare with. */
 
456
  bool operator <=(const CTypeInfo &type) const;
 
457
  /** Check if the conversion rank of this type is less
 
458
   *  than the conversion rank of the given type.
 
459
   *  \note Language C only!
 
460
   *  \param type The type to compare with. */
 
461
  bool operator <(const CTypeInfo &type) const;
238
462
  
239
 
  // rank C++ arithmetic types
 
463
  /** Get the rank of this type if it is an arithmetic type.
 
464
   *  \note Language C++ only! 
 
465
   *  \return The rank or 0 if not an arithmetic type. */
240
466
  unsigned rank () const;
241
467
  
242
468
public:
243
 
  // Duplicate the given type structure.
244
 
#ifndef __puma // PUMA is confused by static and non-static declaration
245
 
  static
246
 
#endif
247
 
  CTypeInfo *Duplicate (const CTypeInfo *);
248
 
  // Duplicate this.
 
469
  /** Make a duplicate of the given type.
 
470
   *  \param type The type to duplicate. */
 
471
  static CTypeInfo *Duplicate (const CTypeInfo *type);
 
472
  /** Maka a duplicate of this type. */
249
473
  CTypeInfo *Duplicate () const;
250
474
 
251
 
  // Destroy the given type structure.
252
 
  static void Destroy (CTypeInfo *);
 
475
  /** Destroy the given type.
 
476
   *  \param type The type to destroy. */
 
477
  static void Destroy (CTypeInfo *type);
253
478
 
254
 
  void Mangled (ostream &) const;
 
479
  /** Print the mangled textual representation of
 
480
   *  the type on the given stream. According to the
 
481
   *  C++ V3 ABI mangling (see http://www.codesourcery.com/cxx-abi/abi.html).
 
482
   *  \param os The output stream. */
 
483
  void Mangled (ostream &os) const;
255
484
 
256
485
private:
257
486
  bool equalTemplateParams (CTemplateParamInfo *p1, CTemplateParamInfo *p2) const;
260
489
  void printScope (char, ostream &, CObjectInfo *) const;
261
490
};
262
491
 
 
492
/** Empty type. */
263
493
extern CTypeInfo CTYPE_EMPTY;
264
494
 
265
495
} // namespace Puma