source: src/SynTree/Type.h @ c570806

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since c570806 was 85dac33, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Added 'const' in some leaf positions where it doesn't seem to effect much.

  • Property mode set to 100644
File size: 29.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
[ada4575]12// Last Modified On : Thu Feb 14 17:11:24 2019
13// Update Count     : 169
[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; }
[7870799]146        bool get_const() const { return tq.is_const; }
147        bool get_volatile() const { return tq.is_volatile; }
148        bool get_restrict() const { return tq.is_restrict; }
149        bool get_lvalue() const { return tq.is_lvalue; }
150        bool get_mutex() const { return tq.is_mutex; }
151        bool get_atomic() const { return tq.is_atomic; }
[615a096]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();
[85dac33]174        const Type * stripReferences() const;
[6f95000]175
[e6cee92]176        /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
177        virtual int referenceDepth() const;
178
[4a9ccc3]179        virtual bool isComplete() const { return true; }
180
[0b3b2ae]181        virtual AggregateDecl * getAggr() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
[9bfc9da]182
183        virtual TypeSubstitution genericSubstitution() const;
[373d0b5]184
[0dd3a2f]185        virtual Type *clone() const = 0;
[f2e40a9f]186        virtual void accept( Visitor & v ) = 0;
[7870799]187        virtual void accept( Visitor & v ) const = 0;
[f2e40a9f]188        virtual Type *acceptMutator( Mutator & m ) = 0;
[50377a4]189        virtual void print( std::ostream & os, Indenter indent = {} ) const;
[51b7345]190};
191
[65cdc1e]192extern const Type::FuncSpecifiers noFuncSpecifiers;
193extern const Type::StorageClasses noStorageClasses;
194extern const Type::Qualifiers noQualifiers;                     // no qualifiers on constants
[4cb935e]195
[c8ffe20b]196class VoidType : public Type {
197  public:
[f2e40a9f]198        VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[51b7345]199
[d67cdb7]200        virtual unsigned size() const override { return 0; };
201        virtual bool isComplete() const override { return false; }
[906e24d]202
[d67cdb7]203        virtual VoidType *clone() const override { return new VoidType( *this ); }
204        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]205        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]206        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]207        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]208};
209
[c8ffe20b]210class BasicType : public Type {
211  public:
[ada4575]212        // GENERATED START, DO NOT EDIT
[6fd1955]213        // GENERATED BY BasicTypes-gen.cc
[cdcddfe1]214        enum Kind {
[e15853c]215                Bool,
[cdcddfe1]216                Char,
217                SignedChar,
218                UnsignedChar,
219                ShortSignedInt,
220                ShortUnsignedInt,
221                SignedInt,
222                UnsignedInt,
223                LongSignedInt,
224                LongUnsignedInt,
225                LongLongSignedInt,
226                LongLongUnsignedInt,
227                SignedInt128,
228                UnsignedInt128,
[e15853c]229                uFloat16,
230                uFloat16Complex,
231                uFloat32,
232                uFloat32Complex,
[cdcddfe1]233                Float,
234                FloatComplex,
[e15853c]235                uFloat32x,
236                uFloat32xComplex,
237                uFloat64,
238                uFloat64Complex,
[cdcddfe1]239                Double,
240                DoubleComplex,
[e15853c]241                uFloat64x,
242                uFloat64xComplex,
243                uuFloat80,
244                uFloat128,
245                uFloat128Complex,
246                uuFloat128,
[cdcddfe1]247                LongDouble,
248                LongDoubleComplex,
[e15853c]249                uFloat128x,
250                uFloat128xComplex,
[0dd3a2f]251                NUMBER_OF_BASIC_TYPES
[65cdc1e]252        } kind;
[ada4575]253        // GENERATED END
[0dd3a2f]254
[59db689]255        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
[0dd3a2f]256
[f2e40a9f]257        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]258
[85dac33]259        Kind get_kind() const { return kind; }
[0dd3a2f]260        void set_kind( Kind newValue ) { kind = newValue; }
261
[d67cdb7]262        virtual BasicType *clone() const override { return new BasicType( *this ); }
263        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]264        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]265        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]266        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0dd3a2f]267
268        bool isInteger() const;
[51b7345]269};
270
[c8ffe20b]271class PointerType : public Type {
272  public:
[65cdc1e]273        Type *base;
274
275        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
276        Expression *dimension;
277        bool isVarLen;
278        bool isStatic;
279
[f2e40a9f]280        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
281        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]282        PointerType( const PointerType& );
283        virtual ~PointerType();
284
285        Type *get_base() { return base; }
286        void set_base( Type *newValue ) { base = newValue; }
287        Expression *get_dimension() { return dimension; }
288        void set_dimension( Expression *newValue ) { dimension = newValue; }
289        bool get_isVarLen() { return isVarLen; }
290        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
291        bool get_isStatic() { return isStatic; }
292        void set_isStatic( bool newValue ) { isStatic = newValue; }
293
[ed8a0d2]294        bool is_array() const { return isStatic || isVarLen || dimension; }
295
[d67cdb7]296        virtual bool isComplete() const override { return ! isVarLen; }
[ce8c12f]297
[d67cdb7]298        virtual PointerType *clone() const override { return new PointerType( *this ); }
299        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]300        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]301        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]302        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]303};
[ae63a18]304
[65cdc1e]305class ArrayType : public Type {
306  public:
307        Type *base;
[0dd3a2f]308        Expression *dimension;
309        bool isVarLen;
310        bool isStatic;
[51b7345]311
[f2e40a9f]312        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]313        ArrayType( const ArrayType& );
314        virtual ~ArrayType();
315
316        Type *get_base() { return base; }
317        void set_base( Type *newValue ) { base = newValue; }
318        Expression *get_dimension() { return dimension; }
319        void set_dimension( Expression *newValue ) { dimension = newValue; }
320        bool get_isVarLen() { return isVarLen; }
321        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
322        bool get_isStatic() { return isStatic; }
323        void set_isStatic( bool newValue ) { isStatic = newValue; }
324
[99b7d4fc]325        // array types are complete if they have a dimension expression or are
326        // VLAs ('*' in parameter declaration), and incomplete otherwise.
327        // See 6.7.6.2
328        virtual bool isComplete() const override { return dimension || isVarLen; }
[4a9ccc3]329
[d67cdb7]330        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
331        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]332        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]333        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]334        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]335};
336
[c5d7701]337class QualifiedType : public Type {
338public:
[c194661]339        Type * parent;
340        Type * child;
[c5d7701]341
[c194661]342        QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
[c5d7701]343        QualifiedType( const QualifiedType & tq );
344        virtual ~QualifiedType();
345
346        virtual QualifiedType *clone() const override { return new QualifiedType( *this ); }
347        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]348        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[c5d7701]349        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
350        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
351};
352
[ce8c12f]353class ReferenceType : public Type {
354public:
[9236060]355        Type *base;
356
[ce8c12f]357        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
358        ReferenceType( const ReferenceType & );
359        virtual ~ReferenceType();
360
361        Type *get_base() { return base; }
362        void set_base( Type *newValue ) { base = newValue; }
363
[d67cdb7]364        virtual int referenceDepth() const override;
[e6cee92]365
[5ccb10d]366        // Since reference types act like value types, their size is the size of the base.
367        // This makes it simple to cast the empty tuple to a reference type, since casts that increase
368        // the number of values are disallowed.
[d67cdb7]369        virtual unsigned size() const override { return base->size(); }
[5ccb10d]370
[9bfc9da]371        virtual TypeSubstitution genericSubstitution() const override;
372
[d67cdb7]373        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
374        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]375        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]376        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]377        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[ce8c12f]378};
379
[c8ffe20b]380class FunctionType : public Type {
381  public:
[65cdc1e]382        std::list<DeclarationWithType*> returnVals;
383        std::list<DeclarationWithType*> parameters;
384
385        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
386        // This could be because of
387        // - an ellipsis in a prototype declaration
388        // - an unprototyped declaration
389        bool isVarArgs;
390
[f2e40a9f]391        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]392        FunctionType( const FunctionType& );
393        virtual ~FunctionType();
394
[cf16f94]395        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
396        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
[8bf784a]397        bool get_isVarArgs() const { return isVarArgs; }
[0dd3a2f]398        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
[8bf784a]399        bool isTtype() const;
400
[8aa474a]401        bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
402
[d67cdb7]403        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
404        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]405        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]406        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]407        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]408};
409
[c8ffe20b]410class ReferenceToType : public Type {
411  public:
[65cdc1e]412        std::list< Expression* > parameters;
413        std::string name;
414        bool hoistType;
415
[f2e40a9f]416        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
417        ReferenceToType( const ReferenceToType & other );
[0dd3a2f]418        virtual ~ReferenceToType();
419
[f2e40a9f]420        const std::string & get_name() const { return name; }
[0dd3a2f]421        void set_name( std::string newValue ) { name = newValue; }
422        std::list< Expression* >& get_parameters() { return parameters; }
[43c89a7]423        bool get_hoistType() const { return hoistType; }
424        void set_hoistType( bool newValue ) { hoistType = newValue; }
[ae63a18]425
[d67cdb7]426        virtual ReferenceToType *clone() const override = 0;
427        virtual void accept( Visitor & v ) override = 0;
428        virtual Type *acceptMutator( Mutator & m ) override = 0;
[50377a4]429        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[6013bd7]430
[b3c36f4]431        virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
[c8ffe20b]432  protected:
[0dd3a2f]433        virtual std::string typeString() const = 0;
[51b7345]434};
435
[c8ffe20b]436class StructInstType : public ReferenceToType {
[0dd3a2f]437        typedef ReferenceToType Parent;
[c8ffe20b]438  public:
[65cdc1e]439        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
440        // where the structure used in this type is actually defined
441        StructDecl *baseStruct;
442
[f2e40a9f]443        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
444        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
445        StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
[51b7345]446
[0dd3a2f]447        StructDecl *get_baseStruct() const { return baseStruct; }
448        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
[37a3b8f9]449
[ed94eac]450        /// Accesses generic parameters of base struct (NULL if none such)
[839ccbb]451        std::list<TypeDecl*> * get_baseParameters();
[9bfc9da]452        const std::list<TypeDecl*> * get_baseParameters() const;
[ae63a18]453
[d67cdb7]454        virtual bool isComplete() const override;
[4a9ccc3]455
[0b3b2ae]456        virtual AggregateDecl * getAggr() const override;
[373d0b5]457
[9bfc9da]458        virtual TypeSubstitution genericSubstitution() const override;
459
[37a3b8f9]460        /// Looks up the members of this struct named "name" and places them into "foundDecls".
461        /// Clones declarations into "foundDecls", caller responsible for freeing
[d67cdb7]462        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
[51b7345]463
[d67cdb7]464        virtual StructInstType *clone() const override { return new StructInstType( *this ); }
465        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]466        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]467        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[5d125e4]468
[50377a4]469        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]470  private:
[d67cdb7]471        virtual std::string typeString() const override;
[51b7345]472};
473
[c8ffe20b]474class UnionInstType : public ReferenceToType {
[0dd3a2f]475        typedef ReferenceToType Parent;
[c8ffe20b]476  public:
[65cdc1e]477        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
478        // where the union used in this type is actually defined
479        UnionDecl *baseUnion;
480
[f2e40a9f]481        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
482        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
483        UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
[0dd3a2f]484
485        UnionDecl *get_baseUnion() const { return baseUnion; }
[c0aa336]486        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
[37a3b8f9]487
[ed94eac]488        /// Accesses generic parameters of base union (NULL if none such)
[9bfc9da]489        std::list<TypeDecl*> * get_baseParameters();
490        const std::list<TypeDecl*> * get_baseParameters() const;
[ae63a18]491
[d67cdb7]492        virtual bool isComplete() const override;
[4a9ccc3]493
[0b3b2ae]494        virtual AggregateDecl * getAggr() const override;
[373d0b5]495
[9bfc9da]496        virtual TypeSubstitution genericSubstitution() const override;
497
[37a3b8f9]498        /// looks up the members of this union named "name" and places them into "foundDecls"
499        /// Clones declarations into "foundDecls", caller responsible for freeing
[d67cdb7]500        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
[0dd3a2f]501
[d67cdb7]502        virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
503        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]504        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]505        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[5d125e4]506
[50377a4]507        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]508  private:
[d67cdb7]509        virtual std::string typeString() const override;
[51b7345]510};
511
[c8ffe20b]512class EnumInstType : public ReferenceToType {
[0dd3a2f]513        typedef ReferenceToType Parent;
[c8ffe20b]514  public:
[65cdc1e]515        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
516        // where the union used in this type is actually defined
517        EnumDecl *baseEnum = nullptr;
518
[f2e40a9f]519        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
520        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
521        EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
[51b7345]522
[c0aa336]523        EnumDecl *get_baseEnum() const { return baseEnum; }
524        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
525
[d67cdb7]526        virtual bool isComplete() const override;
[4a9ccc3]527
[2dc6621]528        virtual AggregateDecl * getAggr() const override;
[0b3b2ae]529
[d67cdb7]530        virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
531        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]532        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]533        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[6137fbb]534
535        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]536  private:
[d67cdb7]537        virtual std::string typeString() const override;
[51b7345]538};
539
[4040425]540class TraitInstType : public ReferenceToType {
[0dd3a2f]541        typedef ReferenceToType Parent;
[c8ffe20b]542  public:
[be9036d]543        // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree,
544        // where the trait used in this type is actually defined
545        TraitDecl * baseTrait = nullptr;
[65cdc1e]546
[be9036d]547        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
548        TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[f2e40a9f]549        TraitInstType( const TraitInstType & other );
[4040425]550        ~TraitInstType();
[51b7345]551
[d67cdb7]552        virtual bool isComplete() const override;
[4a9ccc3]553
[d67cdb7]554        virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
555        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]556        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]557        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[c8ffe20b]558  private:
[d67cdb7]559        virtual std::string typeString() const override;
[51b7345]560};
561
[c8ffe20b]562class TypeInstType : public ReferenceToType {
[0dd3a2f]563        typedef ReferenceToType Parent;
[c8ffe20b]564  public:
[65cdc1e]565        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
566        // where the type used here is actually defined
567        TypeDecl *baseType;
568        bool isFtype;
569
[f2e40a9f]570        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
571        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
572        TypeInstType( const TypeInstType & other );
[1e8b02f5]573        ~TypeInstType();
[0dd3a2f]574
575        TypeDecl *get_baseType() const { return baseType; }
576        void set_baseType( TypeDecl *newValue );
577        bool get_isFtype() const { return isFtype; }
578        void set_isFtype( bool newValue ) { isFtype = newValue; }
[ae63a18]579
[d67cdb7]580        virtual bool isComplete() const override;
[4a9ccc3]581
[d67cdb7]582        virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
583        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]584        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]585        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]586        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]587  private:
[d67cdb7]588        virtual std::string typeString() const override;
[51b7345]589};
590
[c8ffe20b]591class TupleType : public Type {
592  public:
[65cdc1e]593        std::list<Type *> types;
594        std::list<Declaration *> members;
595
[62423350]596        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]597        TupleType( const TupleType& );
598        virtual ~TupleType();
[51b7345]599
[0362d42]600        typedef std::list<Type*> value_type;
601        typedef value_type::iterator iterator;
602
[62423350]603        std::list<Type *> & get_types() { return types; }
[d67cdb7]604        virtual unsigned size() const override { return types.size(); };
[51b7345]605
[62423350]606        // For now, this is entirely synthetic -- tuple types always have unnamed members.
607        // Eventually, we may allow named tuples, in which case members should subsume types
608        std::list<Declaration *> & get_members() { return members; }
609
[0362d42]610        iterator begin() { return types.begin(); }
611        iterator end() { return types.end(); }
612
[d67cdb7]613        virtual Type * getComponent( unsigned i ) override {
[7933351]614                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
615                return *(begin()+i);
616        }
617
[d67cdb7]618        // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
[4a9ccc3]619
[d67cdb7]620        virtual TupleType *clone() const override { return new TupleType( *this ); }
621        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]622        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]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
[c8ffe20b]627class TypeofType : public Type {
628  public:
[f441c88]629        Expression *expr;    ///< expression to take the type of
630        bool is_basetypeof;  ///< true iff is basetypeof type
[65cdc1e]631
[f441c88]632        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[7870799]633        TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof,
[f441c88]634                const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]635        TypeofType( const TypeofType& );
636        virtual ~TypeofType();
[51b7345]637
[0dd3a2f]638        Expression *get_expr() const { return expr; }
639        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]640
[d67cdb7]641        virtual bool isComplete() const override { assert( false ); return false; }
[4a9ccc3]642
[d67cdb7]643        virtual TypeofType *clone() const override { return new TypeofType( *this ); }
644        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]645        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]646        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]647        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]648};
649
[c8ffe20b]650class AttrType : public Type {
651  public:
[65cdc1e]652        std::string name;
653        Expression *expr;
654        Type *type;
655        bool isType;
656
[f2e40a9f]657        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
658        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]659        AttrType( const AttrType& );
660        virtual ~AttrType();
661
[f2e40a9f]662        const std::string & get_name() const { return name; }
663        void set_name( const std::string & newValue ) { name = newValue; }
[0dd3a2f]664        Expression *get_expr() const { return expr; }
665        void set_expr( Expression *newValue ) { expr = newValue; }
666        Type *get_type() const { return type; }
667        void set_type( Type *newValue ) { type = newValue; }
668        bool get_isType() const { return isType; }
669        void set_isType( bool newValue ) { isType = newValue; }
670
[d67cdb7]671        virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here
[4a9ccc3]672
[d67cdb7]673        virtual AttrType *clone() const override { return new AttrType( *this ); }
674        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]675        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]676        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]677        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]678};
679
[44b7088]680/// Represents the GCC built-in varargs type
681class VarArgsType : public Type {
[90c3b1c]682  public:
[44b7088]683        VarArgsType();
[c0aa336]684        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[44b7088]685
[d67cdb7]686        virtual bool isComplete() const override{ return true; } // xxx - is this right?
[4a9ccc3]687
[d67cdb7]688        virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
689        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]690        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]691        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]692        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[44b7088]693};
694
[89e6ffc]695/// Represents a zero constant
696class ZeroType : public Type {
697  public:
698        ZeroType();
[c0aa336]699        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]700
[d67cdb7]701        virtual ZeroType *clone() const override { return new ZeroType( *this ); }
702        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]703        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]704        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]705        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[89e6ffc]706};
707
708/// Represents a one constant
709class OneType : public Type {
710  public:
711        OneType();
[c0aa336]712        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]713
[d67cdb7]714        virtual OneType *clone() const override { return new OneType( *this ); }
715        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]716        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[d67cdb7]717        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]718        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[89e6ffc]719};
720
[47498bd]721class GlobalScopeType : public Type {
722  public:
723        GlobalScopeType();
724
725        virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); }
726        virtual void accept( Visitor & v ) override { v.visit( this ); }
[7870799]727        virtual void accept( Visitor & v ) const override { v.visit( this ); }
[47498bd]728        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
729        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
730};
731
[0dd3a2f]732// Local Variables: //
733// tab-width: 4 //
734// mode: c++ //
735// compile-command: "make install" //
736// End: //
Note: See TracBrowser for help on using the repository browser.