source: src/SynTree/Type.h @ ce8c12f

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 ce8c12f was ce8c12f, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

initial work on references: reference types passed through the system, very simple examples work

  • Property mode set to 100644
File size: 23.8 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        virtual bool isComplete() const { return true; }
163
164        virtual Type *clone() const = 0;
165        virtual void accept( Visitor & v ) = 0;
166        virtual Type *acceptMutator( Mutator & m ) = 0;
167        virtual void print( std::ostream & os, int indent = 0 ) const;
168  private:
169        Qualifiers tq;
170        ForallList forall;
171        std::list< Attribute * > attributes;
172};
173
174extern Type::Qualifiers emptyQualifiers;                                // no qualifiers on constants
175
176class VoidType : public Type {
177  public:
178        VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
179
180        virtual unsigned size() const { return 0; };
181        virtual bool isComplete() const { return false; }
182
183        virtual VoidType *clone() const { return new VoidType( *this ); }
184        virtual void accept( Visitor & v ) { v.visit( this ); }
185        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
186        virtual void print( std::ostream & os, int indent = 0 ) const;
187};
188
189class BasicType : public Type {
190  public:
191        enum Kind {
192                Bool,
193                Char,
194                SignedChar,
195                UnsignedChar,
196                ShortSignedInt,
197                ShortUnsignedInt,
198                SignedInt,
199                UnsignedInt,
200                LongSignedInt,
201                LongUnsignedInt,
202                LongLongSignedInt,
203                LongLongUnsignedInt,
204                Float,
205                Double,
206                LongDouble,
207                FloatComplex,
208                DoubleComplex,
209                LongDoubleComplex,
210                FloatImaginary,
211                DoubleImaginary,
212                LongDoubleImaginary,
213                NUMBER_OF_BASIC_TYPES
214        };
215
216        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
217
218        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
219
220        Kind get_kind() { return kind; }
221        void set_kind( Kind newValue ) { kind = newValue; }
222
223        virtual BasicType *clone() const { return new BasicType( *this ); }
224        virtual void accept( Visitor & v ) { v.visit( this ); }
225        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
226        virtual void print( std::ostream & os, int indent = 0 ) const;
227
228        bool isInteger() const;
229  private:
230        Kind kind;
231};
232
233class PointerType : public Type {
234  public:
235        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
236        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
237        PointerType( const PointerType& );
238        virtual ~PointerType();
239
240        Type *get_base() { return base; }
241        void set_base( Type *newValue ) { base = newValue; }
242        Expression *get_dimension() { return dimension; }
243        void set_dimension( Expression *newValue ) { dimension = newValue; }
244        bool get_isVarLen() { return isVarLen; }
245        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
246        bool get_isStatic() { return isStatic; }
247        void set_isStatic( bool newValue ) { isStatic = newValue; }
248
249        bool is_array() const { return isStatic || isVarLen || dimension; }
250
251        virtual bool isComplete() const { return ! isVarLen; }
252
253        virtual PointerType *clone() const { return new PointerType( *this ); }
254        virtual void accept( Visitor & v ) { v.visit( this ); }
255        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
256        virtual void print( std::ostream & os, int indent = 0 ) const;
257  private:
258        Type *base;
259
260        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
261        Expression *dimension;
262        bool isVarLen;
263        bool isStatic;
264};
265
266class ArrayType : public Type {
267  public:
268        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
269        ArrayType( const ArrayType& );
270        virtual ~ArrayType();
271
272        Type *get_base() { return base; }
273        void set_base( Type *newValue ) { base = newValue; }
274        Expression *get_dimension() { return dimension; }
275        void set_dimension( Expression *newValue ) { dimension = newValue; }
276        bool get_isVarLen() { return isVarLen; }
277        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
278        bool get_isStatic() { return isStatic; }
279        void set_isStatic( bool newValue ) { isStatic = newValue; }
280
281        virtual bool isComplete() const { return ! isVarLen; }
282
283        virtual ArrayType *clone() const { return new ArrayType( *this ); }
284        virtual void accept( Visitor & v ) { v.visit( this ); }
285        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
286        virtual void print( std::ostream & os, int indent = 0 ) const;
287  private:
288        Type *base;
289        Expression *dimension;
290        bool isVarLen;
291        bool isStatic;
292};
293
294class ReferenceType : public Type {
295public:
296        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
297        ReferenceType( const ReferenceType & );
298        virtual ~ReferenceType();
299
300        Type *get_base() { return base; }
301        void set_base( Type *newValue ) { base = newValue; }
302
303        virtual ReferenceType *clone() const { return new ReferenceType( *this ); }
304        virtual void accept( Visitor & v ) { v.visit( this ); }
305        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
306        virtual void print( std::ostream & os, int indent = 0 ) const;
307private:
308        Type *base;
309        unsigned int level = 0;
310};
311
312class FunctionType : public Type {
313  public:
314        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
315        FunctionType( const FunctionType& );
316        virtual ~FunctionType();
317
318        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
319        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
320        bool get_isVarArgs() const { return isVarArgs; }
321        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
322        bool isTtype() const;
323
324        virtual FunctionType *clone() const { return new FunctionType( *this ); }
325        virtual void accept( Visitor & v ) { v.visit( this ); }
326        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
327        virtual void print( std::ostream & os, int indent = 0 ) const;
328  private:
329        std::list<DeclarationWithType*> returnVals;
330        std::list<DeclarationWithType*> parameters;
331
332        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
333        // This could be because of
334        // - an ellipsis in a prototype declaration
335        // - an unprototyped declaration
336        bool isVarArgs;
337};
338
339class ReferenceToType : public Type {
340  public:
341        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
342        ReferenceToType( const ReferenceToType & other );
343        virtual ~ReferenceToType();
344
345        const std::string & get_name() const { return name; }
346        void set_name( std::string newValue ) { name = newValue; }
347        std::list< Expression* >& get_parameters() { return parameters; }
348        bool get_hoistType() const { return hoistType; }
349        void set_hoistType( bool newValue ) { hoistType = newValue; }
350
351        virtual ReferenceToType *clone() const = 0;
352        virtual void accept( Visitor & v ) = 0;
353        virtual Type *acceptMutator( Mutator & m ) = 0;
354        virtual void print( std::ostream & os, int indent = 0 ) const;
355
356        virtual void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const {}
357  protected:
358        virtual std::string typeString() const = 0;
359        std::list< Expression* > parameters;
360        std::string name;
361  private:
362        bool hoistType;
363};
364
365class StructInstType : public ReferenceToType {
366        typedef ReferenceToType Parent;
367  public:
368        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
369        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
370        StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
371
372        StructDecl *get_baseStruct() const { return baseStruct; }
373        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
374
375        /// Accesses generic parameters of base struct (NULL if none such)
376        std::list<TypeDecl*> * get_baseParameters();
377
378        virtual bool isComplete() const;
379
380        /// Looks up the members of this struct named "name" and places them into "foundDecls".
381        /// Clones declarations into "foundDecls", caller responsible for freeing
382        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const;
383
384        virtual StructInstType *clone() const { return new StructInstType( *this ); }
385        virtual void accept( Visitor & v ) { v.visit( this ); }
386        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
387
388        virtual void print( std::ostream & os, int indent = 0 ) const;
389  private:
390        virtual std::string typeString() const;
391
392        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
393        // where the structure used in this type is actually defined
394        StructDecl *baseStruct;
395};
396
397class UnionInstType : public ReferenceToType {
398        typedef ReferenceToType Parent;
399  public:
400        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
401        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
402        UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
403
404        UnionDecl *get_baseUnion() const { return baseUnion; }
405        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
406
407        /// Accesses generic parameters of base union (NULL if none such)
408        std::list< TypeDecl * > * get_baseParameters();
409
410        virtual bool isComplete() const;
411
412        /// looks up the members of this union named "name" and places them into "foundDecls"
413        /// Clones declarations into "foundDecls", caller responsible for freeing
414        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const;
415
416        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
417        virtual void accept( Visitor & v ) { v.visit( this ); }
418        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
419
420        virtual void print( std::ostream & os, int indent = 0 ) const;
421  private:
422        virtual std::string typeString() const;
423
424        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
425        // where the union used in this type is actually defined
426        UnionDecl *baseUnion;
427};
428
429class EnumInstType : public ReferenceToType {
430        typedef ReferenceToType Parent;
431  public:
432        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
433        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
434        EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
435
436        EnumDecl *get_baseEnum() const { return baseEnum; }
437        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
438
439        virtual bool isComplete() const;
440
441        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
442        virtual void accept( Visitor & v ) { v.visit( this ); }
443        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
444  private:
445        virtual std::string typeString() const;
446
447        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
448        // where the union used in this type is actually defined
449        EnumDecl *baseEnum = nullptr;
450};
451
452class TraitInstType : public ReferenceToType {
453        typedef ReferenceToType Parent;
454  public:
455        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
456        TraitInstType( const TraitInstType & other );
457        ~TraitInstType();
458
459        std::list< Declaration* >& get_members() { return members; }
460
461        virtual bool isComplete() const;
462
463        virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
464        virtual void accept( Visitor & v ) { v.visit( this ); }
465        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
466  private:
467        virtual std::string typeString() const;
468
469        // this member is filled in by the validate pass, which instantiates the members of the correponding
470        // aggregate with the actual type parameters specified for this use of the context
471        std::list< Declaration* > members;
472};
473
474class TypeInstType : public ReferenceToType {
475        typedef ReferenceToType Parent;
476  public:
477        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
478        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
479        TypeInstType( const TypeInstType & other );
480        ~TypeInstType();
481
482        TypeDecl *get_baseType() const { return baseType; }
483        void set_baseType( TypeDecl *newValue );
484        bool get_isFtype() const { return isFtype; }
485        void set_isFtype( bool newValue ) { isFtype = newValue; }
486
487        virtual bool isComplete() const;
488
489        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
490        virtual void accept( Visitor & v ) { v.visit( this ); }
491        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
492        virtual void print( std::ostream & os, int indent = 0 ) const;
493  private:
494        virtual std::string typeString() const;
495        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
496        // where the type used here is actually defined
497        TypeDecl *baseType;
498        bool isFtype;
499};
500
501class TupleType : public Type {
502  public:
503        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types = std::list< Type * >(), const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
504        TupleType( const TupleType& );
505        virtual ~TupleType();
506
507        typedef std::list<Type*> value_type;
508        typedef value_type::iterator iterator;
509
510        std::list<Type*>& get_types() { return types; }
511        virtual unsigned size() const { return types.size(); };
512
513        iterator begin() { return types.begin(); }
514        iterator end() { return types.end(); }
515
516        virtual Type * getComponent( unsigned i ) {
517                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
518                return *(begin()+i);
519        }
520
521        // virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
522
523        virtual TupleType *clone() const { return new TupleType( *this ); }
524        virtual void accept( Visitor & v ) { v.visit( this ); }
525        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
526        virtual void print( std::ostream & os, int indent = 0 ) const;
527  private:
528        std::list<Type*> types;
529};
530
531class TypeofType : public Type {
532  public:
533        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
534        TypeofType( const TypeofType& );
535        virtual ~TypeofType();
536
537        Expression *get_expr() const { return expr; }
538        void set_expr( Expression *newValue ) { expr = newValue; }
539
540        virtual bool isComplete() const { assert( false ); return false; }
541
542        virtual TypeofType *clone() const { return new TypeofType( *this ); }
543        virtual void accept( Visitor & v ) { v.visit( this ); }
544        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
545        virtual void print( std::ostream & os, int indent = 0 ) const;
546  private:
547        Expression *expr;
548};
549
550class AttrType : public Type {
551  public:
552        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
553        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
554        AttrType( const AttrType& );
555        virtual ~AttrType();
556
557        const std::string & get_name() const { return name; }
558        void set_name( const std::string & newValue ) { name = newValue; }
559        Expression *get_expr() const { return expr; }
560        void set_expr( Expression *newValue ) { expr = newValue; }
561        Type *get_type() const { return type; }
562        void set_type( Type *newValue ) { type = newValue; }
563        bool get_isType() const { return isType; }
564        void set_isType( bool newValue ) { isType = newValue; }
565
566        virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here
567
568        virtual AttrType *clone() const { return new AttrType( *this ); }
569        virtual void accept( Visitor & v ) { v.visit( this ); }
570        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
571        virtual void print( std::ostream & os, int indent = 0 ) const;
572  private:
573        std::string name;
574        Expression *expr;
575        Type *type;
576        bool isType;
577};
578
579/// Represents the GCC built-in varargs type
580class VarArgsType : public Type {
581  public:
582        VarArgsType();
583        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
584
585        virtual bool isComplete() const{ return true; } // xxx - is this right?
586
587        virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
588        virtual void accept( Visitor & v ) { v.visit( this ); }
589        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
590        virtual void print( std::ostream & os, int indent = 0 ) const;
591};
592
593/// Represents a zero constant
594class ZeroType : public Type {
595  public:
596        ZeroType();
597        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
598
599        virtual ZeroType *clone() const { return new ZeroType( *this ); }
600        virtual void accept( Visitor & v ) { v.visit( this ); }
601        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
602        virtual void print( std::ostream & os, int indent = 0 ) const;
603};
604
605/// Represents a one constant
606class OneType : public Type {
607  public:
608        OneType();
609        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
610
611        virtual OneType *clone() const { return new OneType( *this ); }
612        virtual void accept( Visitor & v ) { v.visit( this ); }
613        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
614        virtual void print( std::ostream & os, int indent = 0 ) const;
615};
616
617std::ostream & operator<<( std::ostream & out, const Type * type );
618
619#endif // TYPE_H
620
621// Local Variables: //
622// tab-width: 4 //
623// mode: c++ //
624// compile-command: "make install" //
625// End: //
Note: See TracBrowser for help on using the repository browser.