source: src/SynTree/Type.h @ 64b6913

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 64b6913 was 64b6913, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

move type StorageClasses? from DeclarationNode? to Type

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