source: src/SynTree/Type.h @ a61ad31

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since a61ad31 was 0698aa1, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add stripReferences, fix createDeref and makeSub to work with reference types

  • Property mode set to 100644
File size: 24.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 : Thu Mar 23 16:16:36 2017
13// Update Count     : 149
14//
15
16#ifndef TYPE_H
17#define TYPE_H
18
19#include "BaseSyntaxNode.h"
20#include "Mutator.h"
21#include "SynTree.h"
22#include "Visitor.h"
23#include <strings.h>                                                                    // ffs
24
25class Type : public BaseSyntaxNode {
26  public:
27        // Simulate inheritance because union does not allow it.
28        // Bug in g++-4.9 prevents static field in union
29        //static const char * Names[];
30        #define BFCommon( BFType, N ) \
31                bool operator[]( unsigned int i ) const { return val & (1 << i); } \
32                bool any() const { return val != 0; } \
33                void reset() { val = 0; } \
34                int ffs() { return ::ffs( val ) - 1; } \
35                BFType operator&=( BFType other ) { \
36                        val &= other.val; return *this; \
37                } \
38                BFType operator&( BFType other ) const { \
39                        BFType q = other; \
40                        q &= *this; \
41                        return q; \
42                } \
43                BFType operator|=( BFType other ) { \
44                        val |= other.val; return *this; \
45                } \
46                BFType operator|( BFType other ) const { \
47                        BFType q = other; \
48                        q |= *this; \
49                        return q; \
50                } \
51                BFType operator-=( BFType other ) { \
52                        val &= ~other.val; return *this; \
53                } \
54                void print( std::ostream & os ) const { \
55                        if ( (*this).any() ) { \
56                                for ( unsigned int i = 0; i < N; i += 1 ) { \
57                                        if ( (*this)[i] ) { \
58                                                os << BFType##Names[i] << ' '; \
59                                        } \
60                                } \
61                        } \
62                }
63
64        // enum must remain in the same order as the corresponding bit fields.
65
66        enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
67        static const char * FuncSpecifiersNames[];
68        union FuncSpecifiers {
69                unsigned int val;
70                struct {
71                        bool is_inline : 1;
72                        bool is_noreturn : 1;
73                        bool is_fortran : 1;
74                };
75                FuncSpecifiers() : val( 0 ) {}
76                FuncSpecifiers( unsigned int val ) : val( val ) {}
77                // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
78                BFCommon( FuncSpecifiers, NumFuncSpecifier )
79        }; // FuncSpecifiers
80
81        enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };
82        static const char * StorageClassesNames[];
83        union StorageClasses {
84                unsigned int val;
85                struct {
86                        bool is_extern : 1;
87                        bool is_static : 1;
88                        bool is_auto : 1;
89                        bool is_register : 1;
90                        bool is_threadlocal : 1;
91                };
92
93                StorageClasses() : val( 0 ) {}
94                StorageClasses( unsigned int val ) : val( val ) {}
95                // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
96                BFCommon( StorageClasses, NumStorageClass )
97        }; // StorageClasses
98
99        enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
100        static const char * QualifiersNames[];
101        union Qualifiers {
102                enum { Mask = ~(Restrict | Lvalue) };
103                unsigned int val;
104                struct {
105                        bool is_const : 1;
106                        bool is_restrict : 1;
107                        bool is_volatile : 1;
108                        bool is_lvalue : 1;
109                        bool is_mutex : 1;
110                        bool is_atomic : 1;
111                };
112
113                Qualifiers() : val( 0 ) {}
114                Qualifiers( unsigned int val ) : val( val ) {}
115                // Complex comparisons provide implicit qualifier downcasting, e.g., T downcast to const T.
116                bool operator==( Qualifiers other ) const { return (val & Mask) == (other.val & Mask); }
117                bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); }
118                bool operator<=( Qualifiers other ) const {
119                        return is_const    <= other.is_const        //Any non-const converts to const without cost
120                                        && is_volatile <= other.is_volatile     //Any non-volatile converts to volatile without cost
121                                        && is_mutex    >= other.is_mutex        //Any mutex converts to non-mutex without cost
122                                        && is_atomic   == other.is_atomic;      //No conversion from atomic to non atomic is free
123                }
124                bool operator<( Qualifiers other ) const { return *this != other && *this <= other; }
125                bool operator>=( Qualifiers other ) const { return ! (*this < other); }
126                bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
127                BFCommon( Qualifiers, NumTypeQualifier )
128        }; // Qualifiers
129
130        Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
131        Type( const Type & other );
132        virtual ~Type();
133
134        Qualifiers & get_qualifiers() { return tq; }
135        bool get_const() { return tq.is_const; }
136        bool get_volatile() { return tq.is_volatile; }
137        bool get_restrict() { return tq.is_restrict; }
138        bool get_lvalue() { return tq.is_lvalue; }
139        bool get_mutex() { return tq.is_mutex; }
140        bool get_atomic() { return tq.is_atomic; }
141        void set_const( bool newValue ) { tq.is_const = newValue; }
142        void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
143        void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
144        void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }
145        void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
146        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
147
148        typedef std::list<TypeDecl *> ForallList;
149        ForallList& get_forall() { return forall; }
150
151        std::list< Attribute * >& get_attributes() { return attributes; }
152        const std::list< Attribute * >& get_attributes() const { return attributes; }
153
154        /// How many elemental types are represented by this type
155        virtual unsigned size() const { return 1; };
156        virtual bool isVoid() const { return size() == 0; }
157        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; }
158
159        /// return type without outer pointers and arrays
160        Type * stripDeclarator();
161
162        /// return type without outer references
163        Type * stripReferences();
164
165        virtual bool isComplete() const { return true; }
166
167        virtual Type *clone() const = 0;
168        virtual void accept( Visitor & v ) = 0;
169        virtual Type *acceptMutator( Mutator & m ) = 0;
170        virtual void print( std::ostream & os, int indent = 0 ) const;
171  private:
172        Qualifiers tq;
173        ForallList forall;
174        std::list< Attribute * > attributes;
175};
176
177extern Type::Qualifiers emptyQualifiers;                                // no qualifiers on constants
178
179class VoidType : public Type {
180  public:
181        VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
182
183        virtual unsigned size() const { return 0; };
184        virtual bool isComplete() const { return false; }
185
186        virtual VoidType *clone() const { return new VoidType( *this ); }
187        virtual void accept( Visitor & v ) { v.visit( this ); }
188        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
189        virtual void print( std::ostream & os, int indent = 0 ) const;
190};
191
192class BasicType : public Type {
193  public:
194        enum Kind {
195                Bool,
196                Char,
197                SignedChar,
198                UnsignedChar,
199                ShortSignedInt,
200                ShortUnsignedInt,
201                SignedInt,
202                UnsignedInt,
203                LongSignedInt,
204                LongUnsignedInt,
205                LongLongSignedInt,
206                LongLongUnsignedInt,
207                Float,
208                Double,
209                LongDouble,
210                FloatComplex,
211                DoubleComplex,
212                LongDoubleComplex,
213                FloatImaginary,
214                DoubleImaginary,
215                LongDoubleImaginary,
216                NUMBER_OF_BASIC_TYPES
217        };
218
219        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
220
221        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
222
223        Kind get_kind() { return kind; }
224        void set_kind( Kind newValue ) { kind = newValue; }
225
226        virtual BasicType *clone() const { return new BasicType( *this ); }
227        virtual void accept( Visitor & v ) { v.visit( this ); }
228        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
229        virtual void print( std::ostream & os, int indent = 0 ) const;
230
231        bool isInteger() const;
232  private:
233        Kind kind;
234};
235
236class PointerType : public Type {
237  public:
238        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
239        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
240        PointerType( const PointerType& );
241        virtual ~PointerType();
242
243        Type *get_base() { return base; }
244        void set_base( Type *newValue ) { base = newValue; }
245        Expression *get_dimension() { return dimension; }
246        void set_dimension( Expression *newValue ) { dimension = newValue; }
247        bool get_isVarLen() { return isVarLen; }
248        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
249        bool get_isStatic() { return isStatic; }
250        void set_isStatic( bool newValue ) { isStatic = newValue; }
251
252        bool is_array() const { return isStatic || isVarLen || dimension; }
253
254        virtual bool isComplete() const { return ! isVarLen; }
255
256        virtual PointerType *clone() const { return new PointerType( *this ); }
257        virtual void accept( Visitor & v ) { v.visit( this ); }
258        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
259        virtual void print( std::ostream & os, int indent = 0 ) const;
260  private:
261        Type *base;
262
263        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
264        Expression *dimension;
265        bool isVarLen;
266        bool isStatic;
267};
268
269class ArrayType : public Type {
270  public:
271        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
272        ArrayType( const ArrayType& );
273        virtual ~ArrayType();
274
275        Type *get_base() { return base; }
276        void set_base( Type *newValue ) { base = newValue; }
277        Expression *get_dimension() { return dimension; }
278        void set_dimension( Expression *newValue ) { dimension = newValue; }
279        bool get_isVarLen() { return isVarLen; }
280        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
281        bool get_isStatic() { return isStatic; }
282        void set_isStatic( bool newValue ) { isStatic = newValue; }
283
284        virtual bool isComplete() const { return ! isVarLen; }
285
286        virtual ArrayType *clone() const { return new ArrayType( *this ); }
287        virtual void accept( Visitor & v ) { v.visit( this ); }
288        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
289        virtual void print( std::ostream & os, int indent = 0 ) const;
290  private:
291        Type *base;
292        Expression *dimension;
293        bool isVarLen;
294        bool isStatic;
295};
296
297class ReferenceType : public Type {
298public:
299        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
300        ReferenceType( const ReferenceType & );
301        virtual ~ReferenceType();
302
303        Type *get_base() { return base; }
304        void set_base( Type *newValue ) { base = newValue; }
305
306        virtual ReferenceType *clone() const { return new ReferenceType( *this ); }
307        virtual void accept( Visitor & v ) { v.visit( this ); }
308        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
309        virtual void print( std::ostream & os, int indent = 0 ) const;
310private:
311        Type *base;
312};
313
314class FunctionType : public Type {
315  public:
316        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
317        FunctionType( const FunctionType& );
318        virtual ~FunctionType();
319
320        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
321        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
322        bool get_isVarArgs() const { return isVarArgs; }
323        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
324        bool isTtype() const;
325
326        virtual FunctionType *clone() const { return new FunctionType( *this ); }
327        virtual void accept( Visitor & v ) { v.visit( this ); }
328        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
329        virtual void print( std::ostream & os, int indent = 0 ) const;
330  private:
331        std::list<DeclarationWithType*> returnVals;
332        std::list<DeclarationWithType*> parameters;
333
334        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
335        // This could be because of
336        // - an ellipsis in a prototype declaration
337        // - an unprototyped declaration
338        bool isVarArgs;
339};
340
341class ReferenceToType : public Type {
342  public:
343        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
344        ReferenceToType( const ReferenceToType & other );
345        virtual ~ReferenceToType();
346
347        const std::string & get_name() const { return name; }
348        void set_name( std::string newValue ) { name = newValue; }
349        std::list< Expression* >& get_parameters() { return parameters; }
350        bool get_hoistType() const { return hoistType; }
351        void set_hoistType( bool newValue ) { hoistType = newValue; }
352
353        virtual ReferenceToType *clone() const = 0;
354        virtual void accept( Visitor & v ) = 0;
355        virtual Type *acceptMutator( Mutator & m ) = 0;
356        virtual void print( std::ostream & os, int indent = 0 ) const;
357
358        virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
359  protected:
360        virtual std::string typeString() const = 0;
361        std::list< Expression* > parameters;
362        std::string name;
363  private:
364        bool hoistType;
365};
366
367class StructInstType : public ReferenceToType {
368        typedef ReferenceToType Parent;
369  public:
370        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
371        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
372        StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
373
374        StructDecl *get_baseStruct() const { return baseStruct; }
375        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
376
377        /// Accesses generic parameters of base struct (NULL if none such)
378        std::list<TypeDecl*> * get_baseParameters();
379
380        virtual bool isComplete() const;
381
382        /// Looks up the members of this struct named "name" and places them into "foundDecls".
383        /// Clones declarations into "foundDecls", caller responsible for freeing
384        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const;
385
386        virtual StructInstType *clone() const { return new StructInstType( *this ); }
387        virtual void accept( Visitor & v ) { v.visit( this ); }
388        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
389
390        virtual void print( std::ostream & os, int indent = 0 ) const;
391  private:
392        virtual std::string typeString() const;
393
394        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
395        // where the structure used in this type is actually defined
396        StructDecl *baseStruct;
397};
398
399class UnionInstType : public ReferenceToType {
400        typedef ReferenceToType Parent;
401  public:
402        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
403        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
404        UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
405
406        UnionDecl *get_baseUnion() const { return baseUnion; }
407        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
408
409        /// Accesses generic parameters of base union (NULL if none such)
410        std::list< TypeDecl * > * get_baseParameters();
411
412        virtual bool isComplete() const;
413
414        /// looks up the members of this union named "name" and places them into "foundDecls"
415        /// Clones declarations into "foundDecls", caller responsible for freeing
416        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const;
417
418        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
419        virtual void accept( Visitor & v ) { v.visit( this ); }
420        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
421
422        virtual void print( std::ostream & os, int indent = 0 ) const;
423  private:
424        virtual std::string typeString() const;
425
426        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
427        // where the union used in this type is actually defined
428        UnionDecl *baseUnion;
429};
430
431class EnumInstType : public ReferenceToType {
432        typedef ReferenceToType Parent;
433  public:
434        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
435        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
436        EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
437
438        EnumDecl *get_baseEnum() const { return baseEnum; }
439        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
440
441        virtual bool isComplete() const;
442
443        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
444        virtual void accept( Visitor & v ) { v.visit( this ); }
445        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
446  private:
447        virtual std::string typeString() const;
448
449        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
450        // where the union used in this type is actually defined
451        EnumDecl *baseEnum = nullptr;
452};
453
454class TraitInstType : public ReferenceToType {
455        typedef ReferenceToType Parent;
456  public:
457        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
458        TraitInstType( const TraitInstType & other );
459        ~TraitInstType();
460
461        std::list< Declaration* >& get_members() { return members; }
462
463        virtual bool isComplete() const;
464
465        virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
466        virtual void accept( Visitor & v ) { v.visit( this ); }
467        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
468  private:
469        virtual std::string typeString() const;
470
471        // this member is filled in by the validate pass, which instantiates the members of the correponding
472        // aggregate with the actual type parameters specified for this use of the context
473        std::list< Declaration* > members;
474};
475
476class TypeInstType : public ReferenceToType {
477        typedef ReferenceToType Parent;
478  public:
479        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
480        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
481        TypeInstType( const TypeInstType & other );
482        ~TypeInstType();
483
484        TypeDecl *get_baseType() const { return baseType; }
485        void set_baseType( TypeDecl *newValue );
486        bool get_isFtype() const { return isFtype; }
487        void set_isFtype( bool newValue ) { isFtype = newValue; }
488
489        virtual bool isComplete() const;
490
491        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
492        virtual void accept( Visitor & v ) { v.visit( this ); }
493        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
494        virtual void print( std::ostream & os, int indent = 0 ) const;
495  private:
496        virtual std::string typeString() const;
497        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
498        // where the type used here is actually defined
499        TypeDecl *baseType;
500        bool isFtype;
501};
502
503class TupleType : public Type {
504  public:
505        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
506        TupleType( const TupleType& );
507        virtual ~TupleType();
508
509        typedef std::list<Type*> value_type;
510        typedef value_type::iterator iterator;
511
512        std::list<Type *> & get_types() { return types; }
513        virtual unsigned size() const { return types.size(); };
514
515        // For now, this is entirely synthetic -- tuple types always have unnamed members.
516        // Eventually, we may allow named tuples, in which case members should subsume types
517        std::list<Declaration *> & get_members() { return members; }
518
519        iterator begin() { return types.begin(); }
520        iterator end() { return types.end(); }
521
522        virtual Type * getComponent( unsigned i ) {
523                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
524                return *(begin()+i);
525        }
526
527        // virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
528
529        virtual TupleType *clone() const { return new TupleType( *this ); }
530        virtual void accept( Visitor & v ) { v.visit( this ); }
531        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
532        virtual void print( std::ostream & os, int indent = 0 ) const;
533  private:
534        std::list<Type *> types;
535        std::list<Declaration *> members;
536};
537
538class TypeofType : public Type {
539  public:
540        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
541        TypeofType( const TypeofType& );
542        virtual ~TypeofType();
543
544        Expression *get_expr() const { return expr; }
545        void set_expr( Expression *newValue ) { expr = newValue; }
546
547        virtual bool isComplete() const { assert( false ); return false; }
548
549        virtual TypeofType *clone() const { return new TypeofType( *this ); }
550        virtual void accept( Visitor & v ) { v.visit( this ); }
551        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
552        virtual void print( std::ostream & os, int indent = 0 ) const;
553  private:
554        Expression *expr;
555};
556
557class AttrType : public Type {
558  public:
559        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
560        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
561        AttrType( const AttrType& );
562        virtual ~AttrType();
563
564        const std::string & get_name() const { return name; }
565        void set_name( const std::string & newValue ) { name = newValue; }
566        Expression *get_expr() const { return expr; }
567        void set_expr( Expression *newValue ) { expr = newValue; }
568        Type *get_type() const { return type; }
569        void set_type( Type *newValue ) { type = newValue; }
570        bool get_isType() const { return isType; }
571        void set_isType( bool newValue ) { isType = newValue; }
572
573        virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here
574
575        virtual AttrType *clone() const { return new AttrType( *this ); }
576        virtual void accept( Visitor & v ) { v.visit( this ); }
577        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
578        virtual void print( std::ostream & os, int indent = 0 ) const;
579  private:
580        std::string name;
581        Expression *expr;
582        Type *type;
583        bool isType;
584};
585
586/// Represents the GCC built-in varargs type
587class VarArgsType : public Type {
588  public:
589        VarArgsType();
590        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
591
592        virtual bool isComplete() const{ return true; } // xxx - is this right?
593
594        virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
595        virtual void accept( Visitor & v ) { v.visit( this ); }
596        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
597        virtual void print( std::ostream & os, int indent = 0 ) const;
598};
599
600/// Represents a zero constant
601class ZeroType : public Type {
602  public:
603        ZeroType();
604        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
605
606        virtual ZeroType *clone() const { return new ZeroType( *this ); }
607        virtual void accept( Visitor & v ) { v.visit( this ); }
608        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
609        virtual void print( std::ostream & os, int indent = 0 ) const;
610};
611
612/// Represents a one constant
613class OneType : public Type {
614  public:
615        OneType();
616        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
617
618        virtual OneType *clone() const { return new OneType( *this ); }
619        virtual void accept( Visitor & v ) { v.visit( this ); }
620        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
621        virtual void print( std::ostream & os, int indent = 0 ) const;
622};
623
624std::ostream & operator<<( std::ostream & out, const Type * type );
625
626#endif // TYPE_H
627
628// Local Variables: //
629// tab-width: 4 //
630// mode: c++ //
631// compile-command: "make install" //
632// End: //
Note: See TracBrowser for help on using the repository browser.