source: src/SynTree/Type.h @ 0ad0c55

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 0ad0c55 was 99b7d4fc, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Fix isComplete for ArrayType?

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