source: src/SynTree/Type.h @ b21c77a

new-env
Last change on this file since b21c77a was 28f3a19, checked in by Aaron Moss <a3moss@…>, 6 years ago

Merge branch 'master' into with_gc

  • Property mode set to 100644
File size: 26.5 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
[f2e40a9f]144        Qualifiers & get_qualifiers() { return tq; }
[615a096]145        bool get_const() { return tq.is_const; }
146        bool get_volatile() { return tq.is_volatile; }
147        bool get_restrict() { return tq.is_restrict; }
148        bool get_lvalue() { return tq.is_lvalue; }
149        bool get_mutex() { return tq.is_mutex; }
150        bool get_atomic() { return tq.is_atomic; }
151        void set_const( bool newValue ) { tq.is_const = newValue; }
152        void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
153        void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
154        void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }
155        void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
156        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
[8c49c0e]157
158        ForallList& get_forall() { return forall; }
[0dd3a2f]159
[c0aa336]160        std::list< Attribute * >& get_attributes() { return attributes; }
161        const std::list< Attribute * >& get_attributes() const { return attributes; }
162
[906e24d]163        /// How many elemental types are represented by this type
164        virtual unsigned size() const { return 1; };
165        virtual bool isVoid() const { return size() == 0; }
[7933351]166        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]167
[142cf5d]168        /// return type without outer pointers and arrays
[0698aa1]169        Type * stripDeclarator();
170
171        /// return type without outer references
172        Type * stripReferences();
[6f95000]173
[e6cee92]174        /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
175        virtual int referenceDepth() const;
176
[4a9ccc3]177        virtual bool isComplete() const { return true; }
178
[9bfc9da]179        virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
180
181        virtual TypeSubstitution genericSubstitution() const;
[373d0b5]182
[0dd3a2f]183        virtual Type *clone() const = 0;
[f2e40a9f]184        virtual void accept( Visitor & v ) = 0;
185        virtual Type *acceptMutator( Mutator & m ) = 0;
[50377a4]186        virtual void print( std::ostream & os, Indenter indent = {} ) const;
[51b7345]187};
188
[65cdc1e]189extern const Type::FuncSpecifiers noFuncSpecifiers;
190extern const Type::StorageClasses noStorageClasses;
191extern const Type::Qualifiers noQualifiers;                     // no qualifiers on constants
[4cb935e]192
[c8ffe20b]193class VoidType : public Type {
194  public:
[f2e40a9f]195        VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[51b7345]196
[d67cdb7]197        virtual unsigned size() const override { return 0; };
198        virtual bool isComplete() const override { return false; }
[906e24d]199
[d67cdb7]200        virtual VoidType *clone() const override { return new VoidType( *this ); }
201        virtual void accept( Visitor & v ) override { v.visit( this ); }
202        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]203        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]204};
205
[c8ffe20b]206class BasicType : public Type {
207  public:
[ae63a18]208        enum Kind {
[0dd3a2f]209                Bool,
210                Char,
211                SignedChar,
212                UnsignedChar,
213                ShortSignedInt,
214                ShortUnsignedInt,
215                SignedInt,
216                UnsignedInt,
217                LongSignedInt,
218                LongUnsignedInt,
219                LongLongSignedInt,
220                LongLongUnsignedInt,
221                Float,
222                Double,
223                LongDouble,
224                FloatComplex,
225                DoubleComplex,
226                LongDoubleComplex,
227                FloatImaginary,
228                DoubleImaginary,
229                LongDoubleImaginary,
[201aeb9]230                SignedInt128,
231                UnsignedInt128,
[4ee3b0c1]232                Float80,
233                Float128,
[0dd3a2f]234                NUMBER_OF_BASIC_TYPES
[65cdc1e]235        } kind;
[0dd3a2f]236
[59db689]237        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
[0dd3a2f]238
[f2e40a9f]239        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]240
241        Kind get_kind() { return kind; }
242        void set_kind( Kind newValue ) { kind = newValue; }
243
[d67cdb7]244        virtual BasicType *clone() const override { return new BasicType( *this ); }
245        virtual void accept( Visitor & v ) override { v.visit( this ); }
246        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]247        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0dd3a2f]248
249        bool isInteger() const;
[51b7345]250};
251
[c8ffe20b]252class PointerType : public Type {
253  public:
[65cdc1e]254        Type *base;
255
256        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
257        Expression *dimension;
258        bool isVarLen;
259        bool isStatic;
260
[f2e40a9f]261        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
262        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]263        PointerType( const 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
294        Type *get_base() { return base; }
295        void set_base( Type *newValue ) { base = newValue; }
296        Expression *get_dimension() { return dimension; }
297        void set_dimension( Expression *newValue ) { dimension = newValue; }
298        bool get_isVarLen() { return isVarLen; }
299        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
300        bool get_isStatic() { return isStatic; }
301        void set_isStatic( bool newValue ) { isStatic = newValue; }
302
[99b7d4fc]303        // array types are complete if they have a dimension expression or are
304        // VLAs ('*' in parameter declaration), and incomplete otherwise.
305        // See 6.7.6.2
306        virtual bool isComplete() const override { return dimension || isVarLen; }
[4a9ccc3]307
[d67cdb7]308        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
309        virtual void accept( Visitor & v ) override { v.visit( this ); }
310        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]311        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]312};
313
[ce8c12f]314class ReferenceType : public Type {
315public:
[9236060]316        Type *base;
317
[ce8c12f]318        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
319        ReferenceType( const ReferenceType & );
320
321        Type *get_base() { return base; }
322        void set_base( Type *newValue ) { base = newValue; }
323
[d67cdb7]324        virtual int referenceDepth() const override;
[e6cee92]325
[5ccb10d]326        // Since reference types act like value types, their size is the size of the base.
327        // This makes it simple to cast the empty tuple to a reference type, since casts that increase
328        // the number of values are disallowed.
[d67cdb7]329        virtual unsigned size() const override { return base->size(); }
[5ccb10d]330
[9bfc9da]331        virtual TypeSubstitution genericSubstitution() const override;
332
[d67cdb7]333        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
334        virtual void accept( Visitor & v ) override { v.visit( this ); }
335        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]336        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[ce8c12f]337};
338
[c8ffe20b]339class FunctionType : public Type {
340  public:
[65cdc1e]341        std::list<DeclarationWithType*> returnVals;
342        std::list<DeclarationWithType*> parameters;
343
344        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
345        // This could be because of
346        // - an ellipsis in a prototype declaration
347        // - an unprototyped declaration
348        bool isVarArgs;
349
[f2e40a9f]350        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]351        FunctionType( const FunctionType& );
352
[cf16f94]353        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
354        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
[8bf784a]355        bool get_isVarArgs() const { return isVarArgs; }
[0dd3a2f]356        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
[8bf784a]357        bool isTtype() const;
358
[8aa474a]359        bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
360
[d67cdb7]361        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
362        virtual void accept( Visitor & v ) override { v.visit( this ); }
363        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]364        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]365};
366
[c8ffe20b]367class ReferenceToType : public Type {
368  public:
[65cdc1e]369        std::list< Expression* > parameters;
370        std::string name;
371        bool hoistType;
372
[f2e40a9f]373        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
374        ReferenceToType( const ReferenceToType & other );
[0dd3a2f]375
[f2e40a9f]376        const std::string & get_name() const { return name; }
[0dd3a2f]377        void set_name( std::string newValue ) { name = newValue; }
378        std::list< Expression* >& get_parameters() { return parameters; }
[43c89a7]379        bool get_hoistType() const { return hoistType; }
380        void set_hoistType( bool newValue ) { hoistType = newValue; }
[ae63a18]381
[d67cdb7]382        virtual ReferenceToType *clone() const override = 0;
383        virtual void accept( Visitor & v ) override = 0;
384        virtual Type *acceptMutator( Mutator & m ) override = 0;
[50377a4]385        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[6013bd7]386
[b3c36f4]387        virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
[c8ffe20b]388  protected:
[0dd3a2f]389        virtual std::string typeString() const = 0;
[51b7345]390};
391
[c8ffe20b]392class StructInstType : public ReferenceToType {
[0dd3a2f]393        typedef ReferenceToType Parent;
[c8ffe20b]394  public:
[65cdc1e]395        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
396        // where the structure used in this type is actually defined
397        StructDecl *baseStruct;
398
[f2e40a9f]399        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
400        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
401        StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
[51b7345]402
[0dd3a2f]403        StructDecl *get_baseStruct() const { return baseStruct; }
404        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
[37a3b8f9]405
[ed94eac]406        /// Accesses generic parameters of base struct (NULL if none such)
[839ccbb]407        std::list<TypeDecl*> * get_baseParameters();
[9bfc9da]408        const std::list<TypeDecl*> * get_baseParameters() const;
[ae63a18]409
[d67cdb7]410        virtual bool isComplete() const override;
[4a9ccc3]411
[373d0b5]412        virtual AggregateDecl * getAggr() override;
413
[9bfc9da]414        virtual TypeSubstitution genericSubstitution() const override;
415
[37a3b8f9]416        /// Looks up the members of this struct named "name" and places them into "foundDecls".
417        /// Clones declarations into "foundDecls", caller responsible for freeing
[d67cdb7]418        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
[51b7345]419
[d67cdb7]420        virtual StructInstType *clone() const override { return new StructInstType( *this ); }
421        virtual void accept( Visitor & v ) override { v.visit( this ); }
422        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[5d125e4]423
[50377a4]424        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]425  private:
[d67cdb7]426        virtual std::string typeString() const override;
[51b7345]427};
428
[c8ffe20b]429class UnionInstType : public ReferenceToType {
[0dd3a2f]430        typedef ReferenceToType Parent;
[c8ffe20b]431  public:
[65cdc1e]432        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
433        // where the union used in this type is actually defined
434        UnionDecl *baseUnion;
435
[f2e40a9f]436        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
437        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
438        UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
[0dd3a2f]439
440        UnionDecl *get_baseUnion() const { return baseUnion; }
[c0aa336]441        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
[37a3b8f9]442
[ed94eac]443        /// Accesses generic parameters of base union (NULL if none such)
[9bfc9da]444        std::list<TypeDecl*> * get_baseParameters();
445        const std::list<TypeDecl*> * get_baseParameters() const;
[ae63a18]446
[d67cdb7]447        virtual bool isComplete() const override;
[4a9ccc3]448
[373d0b5]449        virtual AggregateDecl * getAggr() override;
450
[9bfc9da]451        virtual TypeSubstitution genericSubstitution() const override;
452
[37a3b8f9]453        /// looks up the members of this union named "name" and places them into "foundDecls"
454        /// Clones declarations into "foundDecls", caller responsible for freeing
[d67cdb7]455        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
[0dd3a2f]456
[d67cdb7]457        virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
458        virtual void accept( Visitor & v ) override { v.visit( this ); }
459        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[5d125e4]460
[50377a4]461        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]462  private:
[d67cdb7]463        virtual std::string typeString() const override;
[51b7345]464};
465
[c8ffe20b]466class EnumInstType : public ReferenceToType {
[0dd3a2f]467        typedef ReferenceToType Parent;
[c8ffe20b]468  public:
[65cdc1e]469        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
470        // where the union used in this type is actually defined
471        EnumDecl *baseEnum = nullptr;
472
[f2e40a9f]473        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
474        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
475        EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
[51b7345]476
[c0aa336]477        EnumDecl *get_baseEnum() const { return baseEnum; }
478        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
479
[d67cdb7]480        virtual bool isComplete() const override;
[4a9ccc3]481
[d67cdb7]482        virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
483        virtual void accept( Visitor & v ) override { v.visit( this ); }
484        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[6137fbb]485
486        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]487  private:
[d67cdb7]488        virtual std::string typeString() const override;
[51b7345]489};
490
[4040425]491class TraitInstType : public ReferenceToType {
[0dd3a2f]492        typedef ReferenceToType Parent;
[c8ffe20b]493  public:
[be9036d]494        // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree,
495        // where the trait used in this type is actually defined
496        TraitDecl * baseTrait = nullptr;
[65cdc1e]497
[be9036d]498        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
499        TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[f2e40a9f]500        TraitInstType( const TraitInstType & other );
[51b7345]501
[d67cdb7]502        virtual bool isComplete() const override;
[4a9ccc3]503
[d67cdb7]504        virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
505        virtual void accept( Visitor & v ) override { v.visit( this ); }
506        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[c8ffe20b]507  private:
[d67cdb7]508        virtual std::string typeString() const override;
[51b7345]509};
510
[c8ffe20b]511class TypeInstType : public ReferenceToType {
[0dd3a2f]512        typedef ReferenceToType Parent;
[c8ffe20b]513  public:
[65cdc1e]514        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
515        // where the type used here is actually defined
516        TypeDecl *baseType;
517        bool isFtype;
518
[f2e40a9f]519        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
520        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
521        TypeInstType( const TypeInstType & other );
[0dd3a2f]522
523        TypeDecl *get_baseType() const { return baseType; }
524        void set_baseType( TypeDecl *newValue );
525        bool get_isFtype() const { return isFtype; }
526        void set_isFtype( bool newValue ) { isFtype = newValue; }
[ae63a18]527
[d67cdb7]528        virtual bool isComplete() const override;
[4a9ccc3]529
[d67cdb7]530        virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
531        virtual void accept( Visitor & v ) override { v.visit( this ); }
532        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]533        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[c8ffe20b]534  private:
[d67cdb7]535        virtual std::string typeString() const override;
[51b7345]536};
537
[c8ffe20b]538class TupleType : public Type {
539  public:
[65cdc1e]540        std::list<Type *> types;
541        std::list<Declaration *> members;
542
[62423350]543        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]544        TupleType( const TupleType& );
[51b7345]545
[0362d42]546        typedef std::list<Type*> value_type;
547        typedef value_type::iterator iterator;
548
[62423350]549        std::list<Type *> & get_types() { return types; }
[d67cdb7]550        virtual unsigned size() const override { return types.size(); };
[51b7345]551
[62423350]552        // For now, this is entirely synthetic -- tuple types always have unnamed members.
553        // Eventually, we may allow named tuples, in which case members should subsume types
554        std::list<Declaration *> & get_members() { return members; }
555
[0362d42]556        iterator begin() { return types.begin(); }
557        iterator end() { return types.end(); }
558
[d67cdb7]559        virtual Type * getComponent( unsigned i ) override {
[7933351]560                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
561                return *(begin()+i);
562        }
563
[d67cdb7]564        // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
[4a9ccc3]565
[d67cdb7]566        virtual TupleType *clone() const override { return new TupleType( *this ); }
567        virtual void accept( Visitor & v ) override { v.visit( this ); }
568        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]569        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]570};
571
[c8ffe20b]572class TypeofType : public Type {
573  public:
[65cdc1e]574        Expression *expr;
575
[f2e40a9f]576        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]577        TypeofType( const TypeofType& );
[51b7345]578
[0dd3a2f]579        Expression *get_expr() const { return expr; }
580        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]581
[d67cdb7]582        virtual bool isComplete() const override { assert( false ); return false; }
[4a9ccc3]583
[d67cdb7]584        virtual TypeofType *clone() const override { return new TypeofType( *this ); }
585        virtual void accept( Visitor & v ) override { v.visit( this ); }
586        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]587        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]588};
589
[c8ffe20b]590class AttrType : public Type {
591  public:
[65cdc1e]592        std::string name;
593        Expression *expr;
594        Type *type;
595        bool isType;
596
[f2e40a9f]597        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
598        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]599        AttrType( const AttrType& );
600
[f2e40a9f]601        const std::string & get_name() const { return name; }
602        void set_name( const std::string & newValue ) { name = newValue; }
[0dd3a2f]603        Expression *get_expr() const { return expr; }
604        void set_expr( Expression *newValue ) { expr = newValue; }
605        Type *get_type() const { return type; }
606        void set_type( Type *newValue ) { type = newValue; }
607        bool get_isType() const { return isType; }
608        void set_isType( bool newValue ) { isType = newValue; }
609
[d67cdb7]610        virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here
[4a9ccc3]611
[d67cdb7]612        virtual AttrType *clone() const override { return new AttrType( *this ); }
613        virtual void accept( Visitor & v ) override { v.visit( this ); }
614        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]615        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]616};
617
[44b7088]618/// Represents the GCC built-in varargs type
619class VarArgsType : public Type {
[90c3b1c]620  public:
[44b7088]621        VarArgsType();
[c0aa336]622        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[44b7088]623
[d67cdb7]624        virtual bool isComplete() const override{ return true; } // xxx - is this right?
[4a9ccc3]625
[d67cdb7]626        virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
627        virtual void accept( Visitor & v ) override { v.visit( this ); }
628        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]629        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[44b7088]630};
631
[89e6ffc]632/// Represents a zero constant
633class ZeroType : public Type {
634  public:
635        ZeroType();
[c0aa336]636        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]637
[d67cdb7]638        virtual ZeroType *clone() const override { return new ZeroType( *this ); }
639        virtual void accept( Visitor & v ) override { v.visit( this ); }
640        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]641        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[89e6ffc]642};
643
644/// Represents a one constant
645class OneType : public Type {
646  public:
647        OneType();
[c0aa336]648        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]649
[d67cdb7]650        virtual OneType *clone() const override { return new OneType( *this ); }
651        virtual void accept( Visitor & v ) override { v.visit( this ); }
652        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
[50377a4]653        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[89e6ffc]654};
655
[0dd3a2f]656// Local Variables: //
657// tab-width: 4 //
658// mode: c++ //
659// compile-command: "make install" //
660// End: //
Note: See TracBrowser for help on using the repository browser.