source: src/SynTree/Type.h @ f1a4ccb

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

change #ifndef to #pragma once

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