source: src/SynTree/Type.h @ 43e0949

no_list
Last change on this file since 43e0949 was 80eefcb, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Forall list now uses vector

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