source: src/SynTree/Type.h@ fa2c005

ADT
Last change on this file since fa2c005 was fa2c005, checked in by JiadaL <j82liang@…>, 3 years ago

Finish Adt POC

  • Property mode set to 100644
File size: 32.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Type.h --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sun Feb 19 22:37:10 2023
13// Update Count : 176
14//
15
16#pragma once
17
18#include <strings.h> // for ffs
19#include <cassert> // for assert, assertf
20#include <list> // for list, _List_iterator
21#include <ostream> // for ostream, operator<<, basic_ostream
22#include <string> // for string
23
24#include "BaseSyntaxNode.h" // for BaseSyntaxNode
25#include "Common/Iterate.hpp"// for operator+
26#include "Mutator.h" // for Mutator
27#include "SynTree.h" // for AST nodes
28#include "Visitor.h" // for Visitor
29
30class Type : public BaseSyntaxNode {
31 public:
32 // Simulate inheritance because union does not allow it.
33 // Bug in g++-4.9 prevents static field in union
34 //static const char * Names[];
35 #define BFCommon( BFType, N ) \
36 bool operator[]( unsigned int i ) const { return val & (1 << i); } \
37 bool any() const { return val != 0; } \
38 void reset() { val = 0; } \
39 int ffs() { return ::ffs( val ) - 1; } \
40 BFType operator&=( BFType other ) { \
41 val &= other.val; return *this; \
42 } \
43 BFType operator&( BFType other ) const { \
44 BFType q = other; \
45 q &= *this; \
46 return q; \
47 } \
48 BFType operator|=( BFType other ) { \
49 val |= other.val; return *this; \
50 } \
51 BFType operator|( BFType other ) const { \
52 BFType q = other; \
53 q |= *this; \
54 return q; \
55 } \
56 BFType operator-=( BFType other ) { \
57 val &= ~other.val; return *this; \
58 } \
59 void print( std::ostream & os ) const { \
60 if ( (*this).any() ) { \
61 for ( unsigned int i = 0; i < N; i += 1 ) { \
62 if ( (*this)[i] ) { \
63 os << BFType##Names[i] << ' '; \
64 } \
65 } \
66 } \
67 }
68
69 // enum must remain in the same order as the corresponding bit fields.
70
71 enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
72 static const char * FuncSpecifiersNames[];
73 union FuncSpecifiers {
74 unsigned int val;
75 struct {
76 bool is_inline : 1;
77 bool is_noreturn : 1;
78 bool is_fortran : 1;
79 };
80 FuncSpecifiers() : val( 0 ) {}
81 FuncSpecifiers( unsigned int val ) : val( val ) {}
82 // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
83 BFCommon( FuncSpecifiers, NumFuncSpecifier )
84 }; // FuncSpecifiers
85
86 enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, ThreadlocalGcc = 1 << 4, ThreadlocalC11 = 1 << 5, NumStorageClass = 6 };
87 static const char * StorageClassesNames[];
88 union StorageClasses {
89 unsigned int val;
90 struct {
91 bool is_extern : 1;
92 bool is_static : 1;
93 bool is_auto : 1;
94 bool is_register : 1;
95 bool is_threadlocalGcc : 1;
96 bool is_threadlocalC11 : 1;
97 };
98
99 StorageClasses() : val( 0 ) {}
100 StorageClasses( unsigned int val ) : val( val ) {}
101 // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
102 BFCommon( StorageClasses, NumStorageClass )
103
104 bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; }
105 }; // StorageClasses
106
107 enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Mutex = 1 << 3, Atomic = 1 << 4, NumTypeQualifier = 5 };
108 static const char * QualifiersNames[];
109 union Qualifiers {
110 enum { Mask = ~Restrict };
111 unsigned int val;
112 struct {
113 bool is_const : 1;
114 bool is_restrict : 1;
115 bool is_volatile : 1;
116 bool is_mutex : 1;
117 bool is_atomic : 1;
118 };
119
120 Qualifiers() : val( 0 ) {}
121 Qualifiers( unsigned int val ) : val( val ) {}
122 // Complex comparisons provide implicit qualifier downcasting, e.g., T downcast to const T.
123 bool operator==( Qualifiers other ) const { return (val & Mask) == (other.val & Mask); }
124 bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); }
125 bool operator<=( Qualifiers other ) const {
126 return is_const <= other.is_const // Any non-const converts to const without cost
127 && is_volatile <= other.is_volatile // Any non-volatile converts to volatile without cost
128 && is_mutex >= other.is_mutex // Any mutex converts to non-mutex without cost
129 && is_atomic == other.is_atomic; // No conversion from atomic to non atomic is free
130 }
131 bool operator<( Qualifiers other ) const { return *this != other && *this <= other; }
132 bool operator>=( Qualifiers other ) const { return ! (*this < other); }
133 bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
134 BFCommon( Qualifiers, NumTypeQualifier )
135
136 Qualifiers unify( Qualifiers const & other ) const {
137 int or_flags = Mask & (val | other.val);
138 int and_flags = val & other.val;
139 return Qualifiers( or_flags | and_flags );
140 }
141 }; // Qualifiers
142
143 typedef std::list<TypeDecl *> ForallList;
144
145 Qualifiers tq;
146 ForallList forall;
147 std::list< Attribute * > attributes;
148
149 Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
150 Type( const Type & other );
151 virtual ~Type();
152
153 Qualifiers & get_qualifiers() { return tq; }
154 bool get_const() const { return tq.is_const; }
155 bool get_volatile() const { return tq.is_volatile; }
156 bool get_restrict() const { return tq.is_restrict; }
157 bool get_mutex() const { return tq.is_mutex; }
158 bool get_atomic() const { return tq.is_atomic; }
159 void set_const( bool newValue ) { tq.is_const = newValue; }
160 void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
161 void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
162 void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
163 void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
164
165 ForallList& get_forall() { return forall; }
166
167 std::list< Attribute * >& get_attributes() { return attributes; }
168 const std::list< Attribute * >& get_attributes() const { return attributes; }
169
170 /// How many elemental types are represented by this type
171 virtual unsigned size() const { return 1; };
172 virtual bool isVoid() const { return size() == 0; }
173 virtual Type * getComponent( unsigned i ) { assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); return this; }
174
175 /// return type without outer pointers and arrays
176 Type * stripDeclarator();
177
178 /// return type without outer references
179 Type * stripReferences();
180 const Type * stripReferences() const;
181
182 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
183 virtual int referenceDepth() const;
184
185 virtual bool isComplete() const { return true; }
186
187 virtual AggregateDecl * getAggr() const;
188
189 virtual TypeSubstitution genericSubstitution() const;
190
191 virtual Type * clone() const = 0;
192 virtual void accept( Visitor & v ) = 0;
193 virtual void accept( Visitor & v ) const = 0;
194 virtual Type * acceptMutator( Mutator & m ) = 0;
195 virtual void print( std::ostream & os, Indenter indent = {} ) const;
196};
197
198extern const Type::FuncSpecifiers noFuncSpecifiers;
199extern const Type::StorageClasses noStorageClasses;
200extern const Type::Qualifiers noQualifiers; // no qualifiers on constants
201
202class VoidType : public Type {
203 public:
204 VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
205
206 virtual unsigned size() const override { return 0; };
207 virtual bool isComplete() const override { return false; }
208
209 virtual VoidType * clone() const override { return new VoidType( *this ); }
210 virtual void accept( Visitor & v ) override { v.visit( this ); }
211 virtual void accept( Visitor & v ) const override { v.visit( this ); }
212 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
213 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
214};
215
216class BasicType : public Type {
217 public:
218 // GENERATED START, DO NOT EDIT
219 // GENERATED BY BasicTypes-gen.cc
220 enum Kind {
221 Bool,
222 Char,
223 SignedChar,
224 UnsignedChar,
225 ShortSignedInt,
226 ShortUnsignedInt,
227 SignedInt,
228 UnsignedInt,
229 LongSignedInt,
230 LongUnsignedInt,
231 LongLongSignedInt,
232 LongLongUnsignedInt,
233 SignedInt128,
234 UnsignedInt128,
235 uFloat16,
236 uFloat16Complex,
237 uFloat32,
238 uFloat32Complex,
239 Float,
240 FloatComplex,
241 uFloat32x,
242 uFloat32xComplex,
243 uFloat64,
244 uFloat64Complex,
245 Double,
246 DoubleComplex,
247 uFloat64x,
248 uFloat64xComplex,
249 uuFloat80,
250 uFloat128,
251 uFloat128Complex,
252 uuFloat128,
253 LongDouble,
254 LongDoubleComplex,
255 uFloat128x,
256 uFloat128xComplex,
257 NUMBER_OF_BASIC_TYPES
258 } kind;
259 // GENERATED END
260
261 static const char * typeNames[]; // string names for basic types, MUST MATCH with Kind
262
263 BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
264
265 Kind get_kind() const { return kind; }
266 void set_kind( Kind newValue ) { kind = newValue; }
267
268 virtual BasicType * clone() const override { return new BasicType( *this ); }
269 virtual void accept( Visitor & v ) override { v.visit( this ); }
270 virtual void accept( Visitor & v ) const override { v.visit( this ); }
271 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
272 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
273 bool isInteger() const;
274};
275
276class PointerType : public Type {
277 public:
278 Type * base;
279
280 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
281 Expression * dimension;
282 bool isVarLen;
283 bool isStatic;
284
285 PointerType( const Type::Qualifiers & tq, Type * base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
286 PointerType( const Type::Qualifiers & tq, Type * base, Expression * dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
287 PointerType( const PointerType& );
288 virtual ~PointerType();
289
290 Type * get_base() { return base; }
291 void set_base( Type * newValue ) { base = newValue; }
292 Expression * get_dimension() { return dimension; }
293 void set_dimension( Expression * newValue ) { dimension = newValue; }
294 bool get_isVarLen() { return isVarLen; }
295 void set_isVarLen( bool newValue ) { isVarLen = newValue; }
296 bool get_isStatic() { return isStatic; }
297 void set_isStatic( bool newValue ) { isStatic = newValue; }
298
299 bool is_array() const { return isStatic || isVarLen || dimension; }
300
301 virtual bool isComplete() const override { return ! isVarLen; }
302
303 virtual PointerType * clone() const override { return new PointerType( * this ); }
304 virtual void accept( Visitor & v ) override { v.visit( this ); }
305 virtual void accept( Visitor & v ) const override { v.visit( this ); }
306 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
307 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
308};
309
310class ArrayType : public Type {
311 public:
312 Type * base;
313 Expression * dimension;
314 bool isVarLen;
315 bool isStatic;
316
317 ArrayType( const Type::Qualifiers & tq, Type * base, Expression * dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
318 ArrayType( const ArrayType& );
319 virtual ~ArrayType();
320
321 Type * get_base() { return base; }
322 void set_base( Type * newValue ) { base = newValue; }
323 Expression * get_dimension() { return dimension; }
324 void set_dimension( Expression * newValue ) { dimension = newValue; }
325 bool get_isVarLen() { return isVarLen; }
326 void set_isVarLen( bool newValue ) { isVarLen = newValue; }
327 bool get_isStatic() { return isStatic; }
328 void set_isStatic( bool newValue ) { isStatic = newValue; }
329
330 // array types are complete if they have a dimension expression or are
331 // VLAs ('*' in parameter declaration), and incomplete otherwise.
332 // See 6.7.6.2
333 virtual bool isComplete() const override { return dimension || isVarLen; }
334
335 virtual ArrayType * clone() const override { return new ArrayType( *this ); }
336 virtual void accept( Visitor & v ) override { v.visit( this ); }
337 virtual void accept( Visitor & v ) const override { v.visit( this ); }
338 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
339 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
340};
341
342class QualifiedType : public Type {
343public:
344 Type * parent;
345 Type * child;
346 QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
347 QualifiedType( const QualifiedType & tq );
348 virtual ~QualifiedType();
349
350 virtual QualifiedType * clone() const override { return new QualifiedType( *this ); }
351 virtual void accept( Visitor & v ) override { v.visit( this ); }
352 virtual void accept( Visitor & v ) const override { v.visit( this ); }
353 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
354 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
355};
356
357class ReferenceType : public Type {
358public:
359 Type * base;
360
361 ReferenceType( const Type::Qualifiers & tq, Type * base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
362 ReferenceType( const ReferenceType & );
363 virtual ~ReferenceType();
364
365 Type * get_base() { return base; }
366 void set_base( Type * newValue ) { base = newValue; }
367
368 virtual int referenceDepth() const override;
369
370 // Since reference types act like value types, their size is the size of the base.
371 // This makes it simple to cast the empty tuple to a reference type, since casts that increase
372 // the number of values are disallowed.
373 virtual unsigned size() const override { return base->size(); }
374
375 virtual TypeSubstitution genericSubstitution() const override;
376
377 virtual ReferenceType * clone() const override { return new ReferenceType( *this ); }
378 virtual void accept( Visitor & v ) override { v.visit( this ); }
379 virtual void accept( Visitor & v ) const override { v.visit( this ); }
380 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
381 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
382};
383
384class FunctionType : public Type {
385 public:
386 std::list<DeclarationWithType*> returnVals;
387 std::list<DeclarationWithType*> parameters;
388
389 // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
390 // This could be because of
391 // - an ellipsis in a prototype declaration
392 // - an unprototyped declaration
393 bool isVarArgs;
394
395 FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
396 FunctionType( const FunctionType& );
397 virtual ~FunctionType();
398
399 std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
400 std::list<DeclarationWithType*> & get_parameters() { return parameters; }
401 bool get_isVarArgs() const { return isVarArgs; }
402 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
403 bool isTtype() const;
404
405 bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
406
407 virtual FunctionType * clone() const override { return new FunctionType( *this ); }
408 virtual void accept( Visitor & v ) override { v.visit( this ); }
409 virtual void accept( Visitor & v ) const override { v.visit( this ); }
410 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
411 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
412};
413
414class ReferenceToType : public Type {
415 public:
416 std::list< Expression * > parameters;
417 std::string name;
418 bool hoistType;
419
420 ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
421 ReferenceToType( const ReferenceToType & other );
422 virtual ~ReferenceToType();
423
424 const std::string & get_name() const { return name; }
425 void set_name( std::string newValue ) { name = newValue; }
426 std::list< Expression* >& get_parameters() { return parameters; }
427 bool get_hoistType() const { return hoistType; }
428 void set_hoistType( bool newValue ) { hoistType = newValue; }
429
430 virtual ReferenceToType * clone() const override = 0;
431 virtual void accept( Visitor & v ) override = 0;
432 virtual Type * acceptMutator( Mutator & m ) override = 0;
433 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
434
435 virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
436 protected:
437 virtual std::string typeString() const = 0;
438};
439
440class StructInstType : public ReferenceToType {
441 typedef ReferenceToType Parent;
442 public:
443 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
444 // where the structure used in this type is actually defined
445 StructDecl * baseStruct;
446
447 StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
448 StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
449 StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
450
451 StructDecl * get_baseStruct() const { return baseStruct; }
452 void set_baseStruct( StructDecl * newValue ) { baseStruct = newValue; }
453
454 /// Accesses generic parameters of base struct (NULL if none such)
455 std::list<TypeDecl*> * get_baseParameters();
456 const std::list<TypeDecl*> * get_baseParameters() const;
457
458 virtual bool isComplete() const override;
459
460 virtual AggregateDecl * getAggr() const override;
461
462 virtual TypeSubstitution genericSubstitution() const override;
463
464 /// Looks up the members of this struct named "name" and places them into "foundDecls".
465 /// Clones declarations into "foundDecls", caller responsible for freeing
466 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
467
468 virtual StructInstType * clone() const override { return new StructInstType( *this ); }
469 virtual void accept( Visitor & v ) override { v.visit( this ); }
470 virtual void accept( Visitor & v ) const override { v.visit( this ); }
471 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
472
473 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
474 private:
475 virtual std::string typeString() const override;
476};
477
478class AdtInstType : public ReferenceToType {
479 typedef ReferenceToType Parent;
480 public:
481 AdtDecl * baseAdt;
482
483 AdtInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseAdt( 0 ) {}
484 AdtInstType( const Type::Qualifiers & tq, AdtDecl * baseAdt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
485 AdtInstType( const AdtInstType & other ) : Parent( other ), baseAdt( other.baseAdt ) {}
486
487 AdtDecl * get_baseAdt() const { return baseAdt; }
488 void set_baseAdt( AdtDecl * newValue ) { baseAdt = newValue; }
489
490 std::list<TypeDecl*> * get_baseParameters();
491 const std::list<TypeDecl*> * get_baseParameters() const;
492
493 virtual bool isComplete() const override;
494
495 virtual AggregateDecl * getAggr() const override;
496
497 virtual TypeSubstitution genericSubstitution() const override;
498
499 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
500
501 virtual AdtInstType * clone() const override { return new AdtInstType( * this ); }
502 virtual void accept( Visitor & v ) override { v.visit( this ); }
503 virtual void accept( Visitor & v ) const override { v.visit( this ); }
504 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
505
506 virtual void print( std::ostream & os, Indenter indenter = {} ) const override;
507 private:
508 virtual std::string typeString() const override;
509};
510
511class UnionInstType : public ReferenceToType {
512 typedef ReferenceToType Parent;
513 public:
514 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
515 // where the union used in this type is actually defined
516 UnionDecl * baseUnion;
517
518 UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
519 UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
520 UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
521
522 UnionDecl * get_baseUnion() const { return baseUnion; }
523 void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
524
525 /// Accesses generic parameters of base union (NULL if none such)
526 std::list<TypeDecl*> * get_baseParameters();
527 const std::list<TypeDecl*> * get_baseParameters() const;
528
529 virtual bool isComplete() const override;
530
531 virtual AggregateDecl * getAggr() const override;
532
533 virtual TypeSubstitution genericSubstitution() const override;
534
535 /// looks up the members of this union named "name" and places them into "foundDecls"
536 /// Clones declarations into "foundDecls", caller responsible for freeing
537 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
538
539 virtual UnionInstType * clone() const override { return new UnionInstType( *this ); }
540 virtual void accept( Visitor & v ) override { v.visit( this ); }
541 virtual void accept( Visitor & v ) const override { v.visit( this ); }
542 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
543
544 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
545 private:
546 virtual std::string typeString() const override;
547};
548
549class EnumInstType : public ReferenceToType {
550 typedef ReferenceToType Parent;
551 public:
552 // this decl is not "owned" by the enum inst; it is merely a pointer to elsewhere in the tree,
553 // where the enum used in this type is actually defined
554 EnumDecl * baseEnum = nullptr;
555
556 EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
557 EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
558 EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
559
560 EnumDecl * get_baseEnum() const { return baseEnum; }
561 void set_baseEnum( EnumDecl * newValue ) { baseEnum = newValue; }
562
563 virtual bool isComplete() const override;
564
565 virtual AggregateDecl * getAggr() const override;
566
567 virtual EnumInstType * clone() const override { return new EnumInstType( *this ); }
568 virtual void accept( Visitor & v ) override { v.visit( this ); }
569 virtual void accept( Visitor & v ) const override { v.visit( this ); }
570 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
571
572 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
573 private:
574 virtual std::string typeString() const override;
575};
576
577class TraitInstType : public ReferenceToType {
578 typedef ReferenceToType Parent;
579 public:
580 // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree,
581 // where the trait used in this type is actually defined
582 TraitDecl * baseTrait = nullptr;
583
584 TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
585 TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
586 TraitInstType( const TraitInstType & other );
587 ~TraitInstType();
588
589 virtual bool isComplete() const override;
590
591 virtual TraitInstType * clone() const override { return new TraitInstType( *this ); }
592 virtual void accept( Visitor & v ) override { v.visit( this ); }
593 virtual void accept( Visitor & v ) const override { v.visit( this ); }
594 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
595 private:
596 virtual std::string typeString() const override;
597};
598
599class TypeInstType : public ReferenceToType {
600 typedef ReferenceToType Parent;
601 public:
602 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
603 // where the type used here is actually defined
604 TypeDecl * baseType;
605 bool isFtype;
606
607 TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl * baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
608 TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
609 TypeInstType( const TypeInstType & other );
610 ~TypeInstType();
611
612 TypeDecl * get_baseType() const { return baseType; }
613 void set_baseType( TypeDecl * newValue );
614 bool get_isFtype() const { return isFtype; }
615 void set_isFtype( bool newValue ) { isFtype = newValue; }
616
617 virtual bool isComplete() const override;
618
619 virtual TypeInstType * clone() const override { return new TypeInstType( *this ); }
620 virtual void accept( Visitor & v ) override { v.visit( this ); }
621 virtual void accept( Visitor & v ) const override { v.visit( this ); }
622 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
623 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
624 private:
625 virtual std::string typeString() const override;
626};
627
628class TupleType : public Type {
629 public:
630 std::list<Type *> types;
631 std::list<Declaration *> members;
632
633 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
634 TupleType( const TupleType& );
635 virtual ~TupleType();
636
637 typedef std::list<Type*> value_type;
638 typedef value_type::iterator iterator;
639
640 std::list<Type *> & get_types() { return types; }
641 virtual unsigned size() const override { return types.size(); };
642
643 // For now, this is entirely synthetic -- tuple types always have unnamed members.
644 // Eventually, we may allow named tuples, in which case members should subsume types
645 std::list<Declaration *> & get_members() { return members; }
646
647 iterator begin() { return types.begin(); }
648 iterator end() { return types.end(); }
649
650 virtual Type * getComponent( unsigned i ) override {
651 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
652 return *(begin()+i);
653 }
654
655 // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
656
657 virtual TupleType * clone() const override { return new TupleType( *this ); }
658 virtual void accept( Visitor & v ) override { v.visit( this ); }
659 virtual void accept( Visitor & v ) const override { v.visit( this ); }
660 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
661 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
662};
663
664class TypeofType : public Type {
665 public:
666 Expression * expr; ///< expression to take the type of
667 bool is_basetypeof; ///< true iff is basetypeof type
668
669 TypeofType( const Type::Qualifiers & tq, Expression * expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
670 TypeofType( const Type::Qualifiers & tq, Expression * expr, bool is_basetypeof,
671 const std::list< Attribute * > & attributes = std::list< Attribute * >() );
672 TypeofType( const TypeofType& );
673 virtual ~TypeofType();
674
675 Expression * get_expr() const { return expr; }
676 void set_expr( Expression * newValue ) { expr = newValue; }
677
678 virtual bool isComplete() const override { assert( false ); return false; }
679
680 virtual TypeofType * clone() const override { return new TypeofType( *this ); }
681 virtual void accept( Visitor & v ) override { v.visit( this ); }
682 virtual void accept( Visitor & v ) const override { v.visit( this ); }
683 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
684 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
685};
686
687class VTableType : public Type {
688public:
689 Type * base;
690
691 VTableType( const Type::Qualifiers & tq, Type * base,
692 const std::list< Attribute * > & attributes = std::list< Attribute * >() );
693 VTableType( const VTableType & );
694 virtual ~VTableType();
695
696 Type * get_base() { return base; }
697 void set_base( Type * newValue ) { base = newValue; }
698
699 virtual VTableType * clone() const override { return new VTableType( *this ); }
700 virtual void accept( Visitor & v ) override { v.visit( this ); }
701 virtual void accept( Visitor & v ) const override { v.visit( this ); }
702 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
703 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
704};
705
706class AttrType : public Type {
707 public:
708 std::string name;
709 Expression * expr;
710 Type * type;
711 bool isType;
712
713 AttrType( const Type::Qualifiers & tq, const std::string & name, Expression * expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
714 AttrType( const Type::Qualifiers & tq, const std::string & name, Type * type, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
715 AttrType( const AttrType& );
716 virtual ~AttrType();
717
718 const std::string & get_name() const { return name; }
719 void set_name( const std::string & newValue ) { name = newValue; }
720 Expression * get_expr() const { return expr; }
721 void set_expr( Expression * newValue ) { expr = newValue; }
722 Type * get_type() const { return type; }
723 void set_type( Type * newValue ) { type = newValue; }
724 bool get_isType() const { return isType; }
725 void set_isType( bool newValue ) { isType = newValue; }
726
727 virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here
728
729 virtual AttrType * clone() const override { return new AttrType( *this ); }
730 virtual void accept( Visitor & v ) override { v.visit( this ); }
731 virtual void accept( Visitor & v ) const override { v.visit( this ); }
732 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
733 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
734};
735
736/// Represents the GCC built-in varargs type
737class VarArgsType : public Type {
738 public:
739 VarArgsType();
740 VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
741
742 virtual bool isComplete() const override{ return true; } // xxx - is this right?
743
744 virtual VarArgsType * clone() const override { return new VarArgsType( *this ); }
745 virtual void accept( Visitor & v ) override { v.visit( this ); }
746 virtual void accept( Visitor & v ) const override { v.visit( this ); }
747 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
748 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
749};
750
751/// Represents a zero constant
752class ZeroType : public Type {
753 public:
754 ZeroType();
755 ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
756
757 virtual ZeroType * clone() const override { return new ZeroType( *this ); }
758 virtual void accept( Visitor & v ) override { v.visit( this ); }
759 virtual void accept( Visitor & v ) const override { v.visit( this ); }
760 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
761 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
762};
763
764/// Represents a one constant
765class OneType : public Type {
766 public:
767 OneType();
768 OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
769
770 virtual OneType * clone() const override { return new OneType( *this ); }
771 virtual void accept( Visitor & v ) override { v.visit( this ); }
772 virtual void accept( Visitor & v ) const override { v.visit( this ); }
773 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
774 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
775};
776
777class GlobalScopeType : public Type {
778 public:
779 GlobalScopeType();
780
781 virtual GlobalScopeType * clone() const override { return new GlobalScopeType( *this ); }
782 virtual void accept( Visitor & v ) override { v.visit( this ); }
783 virtual void accept( Visitor & v ) const override { v.visit( this ); }
784 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
785 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
786};
787
788
789bool isUnboundType(const Type * type);
790bool isUnboundType(const std::string & tname);
791
792// Local Variables: //
793// tab-width: 4 //
794// mode: c++ //
795// compile-command: "make install" //
796// End: //
Note: See TracBrowser for help on using the repository browser.