source: src/SynTree/Type.h @ 17417cf

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 17417cf was 9bfc9da, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Refactor makeSub into genericSubstitution

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