source: src/SynTree/Type.h @ e6cee92

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

Fix TupleAssignment? code for references

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