source: src/SynTree/Type.h @ 216597d

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 216597d was 3315e3d, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Unify uses Qualifiers::unify, which should handle lvalue better.

  • Property mode set to 100644
File size: 29.8 KB
Line 
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//
7// Type.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Sep  4 09:58:00 2019
13// Update Count     : 170
14//
15
16#pragma once
17
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
29
30class Type : public BaseSyntaxNode {
31  public:
32        // Simulate inheritance because union does not allow it.
33        // Bug in g++-4.9 prevents static field in union
34        //static const char * Names[];
35        #define BFCommon( BFType, N ) \
36                bool operator[]( unsigned int i ) const { return val & (1 << i); } \
37                bool any() const { return val != 0; } \
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                } \
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] ) { \
63                                                os << BFType##Names[i] << ' '; \
64                                        } \
65                                } \
66                        } \
67                }
68
69        // enum must remain in the same order as the corresponding bit fields.
70
71        enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
72        static const char * FuncSpecifiersNames[];
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 ) {}
82                // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
83                BFCommon( FuncSpecifiers, NumFuncSpecifier )
84        }; // FuncSpecifiers
85
86        enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };
87        static const char * StorageClassesNames[];
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 ) {}
100                // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
101                BFCommon( StorageClasses, NumStorageClass )
102        }; // StorageClasses
103
104        enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
105        static const char * QualifiersNames[];
106        union Qualifiers {
107                enum { Mask = ~(Restrict | Lvalue) };
108                unsigned int val;
109                struct {
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;
116                };
117
118                Qualifiers() : val( 0 ) {}
119                Qualifiers( unsigned int val ) : val( val ) {}
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); }
123                bool operator<=( Qualifiers other ) const {
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
128                }
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 )
133
134                Qualifiers unify( Qualifiers const & other ) const {
135                        int or_flags = Mask & (val | other.val);
136                        int and_flags = val & other.val;
137                        return Qualifiers( or_flags | and_flags );
138                }
139        }; // Qualifiers
140
141        typedef std::list<TypeDecl *> ForallList;
142
143        Qualifiers tq;
144        ForallList forall;
145        std::list< Attribute * > attributes;
146
147        Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
148        Type( const Type & other );
149        virtual ~Type();
150
151        Qualifiers & get_qualifiers() { return tq; }
152        bool get_const() const { return tq.is_const; }
153        bool get_volatile() const { return tq.is_volatile; }
154        bool get_restrict() const { return tq.is_restrict; }
155        bool get_lvalue() const { return tq.is_lvalue; }
156        bool get_mutex() const { return tq.is_mutex; }
157        bool get_atomic() const { return tq.is_atomic; }
158        void set_const( bool newValue ) { tq.is_const = newValue; }
159        void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
160        void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
161        void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }
162        void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
163        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
164
165        ForallList& get_forall() { return forall; }
166
167        std::list< Attribute * >& get_attributes() { return attributes; }
168        const std::list< Attribute * >& get_attributes() const { return attributes; }
169
170        /// How many elemental types are represented by this type
171        virtual unsigned size() const { return 1; };
172        virtual bool isVoid() const { return size() == 0; }
173        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; }
174
175        /// return type without outer pointers and arrays
176        Type * stripDeclarator();
177
178        /// return type without outer references
179        Type * stripReferences();
180        const Type * stripReferences() const;
181
182        /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
183        virtual int referenceDepth() const;
184
185        virtual bool isComplete() const { return true; }
186
187        virtual AggregateDecl * getAggr() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
188
189        virtual TypeSubstitution genericSubstitution() const;
190
191        virtual Type *clone() const = 0;
192        virtual void accept( Visitor & v ) = 0;
193        virtual void accept( Visitor & v ) const = 0;
194        virtual Type *acceptMutator( Mutator & m ) = 0;
195        virtual void print( std::ostream & os, Indenter indent = {} ) const;
196};
197
198extern const Type::FuncSpecifiers noFuncSpecifiers;
199extern const Type::StorageClasses noStorageClasses;
200extern const Type::Qualifiers noQualifiers;                     // no qualifiers on constants
201
202class VoidType : public Type {
203  public:
204        VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
205
206        virtual unsigned size() const override { return 0; };
207        virtual bool isComplete() const override { return false; }
208
209        virtual VoidType *clone() const override { return new VoidType( *this ); }
210        virtual void accept( Visitor & v ) override { v.visit( this ); }
211        virtual void accept( Visitor & v ) const override { v.visit( this ); }
212        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
213        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
214};
215
216class BasicType : public Type {
217  public:
218        // GENERATED START, DO NOT EDIT
219        // GENERATED BY BasicTypes-gen.cc
220        enum Kind {
221                Bool,
222                Char,
223                SignedChar,
224                UnsignedChar,
225                ShortSignedInt,
226                ShortUnsignedInt,
227                SignedInt,
228                UnsignedInt,
229                LongSignedInt,
230                LongUnsignedInt,
231                LongLongSignedInt,
232                LongLongUnsignedInt,
233                SignedInt128,
234                UnsignedInt128,
235                uFloat16,
236                uFloat16Complex,
237                uFloat32,
238                uFloat32Complex,
239                Float,
240                FloatComplex,
241                uFloat32x,
242                uFloat32xComplex,
243                uFloat64,
244                uFloat64Complex,
245                Double,
246                DoubleComplex,
247                uFloat64x,
248                uFloat64xComplex,
249                uuFloat80,
250                uFloat128,
251                uFloat128Complex,
252                uuFloat128,
253                LongDouble,
254                LongDoubleComplex,
255                uFloat128x,
256                uFloat128xComplex,
257                NUMBER_OF_BASIC_TYPES
258        } kind;
259        // GENERATED END
260
261        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
262
263        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
264
265        Kind get_kind() const { return kind; }
266        void set_kind( Kind newValue ) { kind = newValue; }
267
268        virtual BasicType *clone() const override { return new BasicType( *this ); }
269        virtual void accept( Visitor & v ) override { v.visit( this ); }
270        virtual void accept( Visitor & v ) const override { v.visit( this ); }
271        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
272        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
273
274        bool isInteger() const;
275};
276
277class PointerType : public Type {
278  public:
279        Type *base;
280
281        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
282        Expression *dimension;
283        bool isVarLen;
284        bool isStatic;
285
286        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
287        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
288        PointerType( const PointerType& );
289        virtual ~PointerType();
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
300        bool is_array() const { return isStatic || isVarLen || dimension; }
301
302        virtual bool isComplete() const override { return ! isVarLen; }
303
304        virtual PointerType *clone() const override { return new PointerType( *this ); }
305        virtual void accept( Visitor & v ) override { v.visit( this ); }
306        virtual void accept( Visitor & v ) const override { v.visit( this ); }
307        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
308        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
309};
310
311class ArrayType : public Type {
312  public:
313        Type *base;
314        Expression *dimension;
315        bool isVarLen;
316        bool isStatic;
317
318        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
319        ArrayType( const ArrayType& );
320        virtual ~ArrayType();
321
322        Type *get_base() { return base; }
323        void set_base( Type *newValue ) { base = newValue; }
324        Expression *get_dimension() { return dimension; }
325        void set_dimension( Expression *newValue ) { dimension = newValue; }
326        bool get_isVarLen() { return isVarLen; }
327        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
328        bool get_isStatic() { return isStatic; }
329        void set_isStatic( bool newValue ) { isStatic = newValue; }
330
331        // array types are complete if they have a dimension expression or are
332        // VLAs ('*' in parameter declaration), and incomplete otherwise.
333        // See 6.7.6.2
334        virtual bool isComplete() const override { return dimension || isVarLen; }
335
336        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
337        virtual void accept( Visitor & v ) override { v.visit( this ); }
338        virtual void accept( Visitor & v ) const override { v.visit( this ); }
339        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
340        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
341};
342
343class QualifiedType : public Type {
344public:
345        Type * parent;
346        Type * child;
347
348        QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
349        QualifiedType( const QualifiedType & tq );
350        virtual ~QualifiedType();
351
352        virtual QualifiedType *clone() const override { return new QualifiedType( *this ); }
353        virtual void accept( Visitor & v ) override { v.visit( this ); }
354        virtual void accept( Visitor & v ) const override { v.visit( this ); }
355        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
356        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
357};
358
359class ReferenceType : public Type {
360public:
361        Type *base;
362
363        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
364        ReferenceType( const ReferenceType & );
365        virtual ~ReferenceType();
366
367        Type *get_base() { return base; }
368        void set_base( Type *newValue ) { base = newValue; }
369
370        virtual int referenceDepth() const override;
371
372        // Since reference types act like value types, their size is the size of the base.
373        // This makes it simple to cast the empty tuple to a reference type, since casts that increase
374        // the number of values are disallowed.
375        virtual unsigned size() const override { return base->size(); }
376
377        virtual TypeSubstitution genericSubstitution() const override;
378
379        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
380        virtual void accept( Visitor & v ) override { v.visit( this ); }
381        virtual void accept( Visitor & v ) const override { v.visit( this ); }
382        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
383        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
384};
385
386class FunctionType : public Type {
387  public:
388        std::list<DeclarationWithType*> returnVals;
389        std::list<DeclarationWithType*> parameters;
390
391        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
392        // This could be because of
393        // - an ellipsis in a prototype declaration
394        // - an unprototyped declaration
395        bool isVarArgs;
396
397        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
398        FunctionType( const FunctionType& );
399        virtual ~FunctionType();
400
401        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
402        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
403        bool get_isVarArgs() const { return isVarArgs; }
404        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
405        bool isTtype() const;
406
407        bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
408
409        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
410        virtual void accept( Visitor & v ) override { v.visit( this ); }
411        virtual void accept( Visitor & v ) const override { v.visit( this ); }
412        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
413        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
414};
415
416class ReferenceToType : public Type {
417  public:
418        std::list< Expression* > parameters;
419        std::string name;
420        bool hoistType;
421
422        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
423        ReferenceToType( const ReferenceToType & other );
424        virtual ~ReferenceToType();
425
426        const std::string & get_name() const { return name; }
427        void set_name( std::string newValue ) { name = newValue; }
428        std::list< Expression* >& get_parameters() { return parameters; }
429        bool get_hoistType() const { return hoistType; }
430        void set_hoistType( bool newValue ) { hoistType = newValue; }
431
432        virtual ReferenceToType *clone() const override = 0;
433        virtual void accept( Visitor & v ) override = 0;
434        virtual Type *acceptMutator( Mutator & m ) override = 0;
435        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
436
437        virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
438  protected:
439        virtual std::string typeString() const = 0;
440};
441
442class StructInstType : public ReferenceToType {
443        typedef ReferenceToType Parent;
444  public:
445        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
446        // where the structure used in this type is actually defined
447        StructDecl *baseStruct;
448
449        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
450        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
451        StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
452
453        StructDecl *get_baseStruct() const { return baseStruct; }
454        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
455
456        /// Accesses generic parameters of base struct (NULL if none such)
457        std::list<TypeDecl*> * get_baseParameters();
458        const std::list<TypeDecl*> * get_baseParameters() const;
459
460        virtual bool isComplete() const override;
461
462        virtual AggregateDecl * getAggr() const override;
463
464        virtual TypeSubstitution genericSubstitution() const override;
465
466        /// Looks up the members of this struct named "name" and places them into "foundDecls".
467        /// Clones declarations into "foundDecls", caller responsible for freeing
468        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
469
470        virtual StructInstType *clone() const override { return new StructInstType( *this ); }
471        virtual void accept( Visitor & v ) override { v.visit( this ); }
472        virtual void accept( Visitor & v ) const override { v.visit( this ); }
473        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
474
475        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
476  private:
477        virtual std::string typeString() const override;
478};
479
480class UnionInstType : public ReferenceToType {
481        typedef ReferenceToType Parent;
482  public:
483        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
484        // where the union used in this type is actually defined
485        UnionDecl *baseUnion;
486
487        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
488        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
489        UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
490
491        UnionDecl *get_baseUnion() const { return baseUnion; }
492        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
493
494        /// Accesses generic parameters of base union (NULL if none such)
495        std::list<TypeDecl*> * get_baseParameters();
496        const std::list<TypeDecl*> * get_baseParameters() const;
497
498        virtual bool isComplete() const override;
499
500        virtual AggregateDecl * getAggr() const override;
501
502        virtual TypeSubstitution genericSubstitution() const override;
503
504        /// looks up the members of this union named "name" and places them into "foundDecls"
505        /// Clones declarations into "foundDecls", caller responsible for freeing
506        void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
507
508        virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
509        virtual void accept( Visitor & v ) override { v.visit( this ); }
510        virtual void accept( Visitor & v ) const override { v.visit( this ); }
511        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
512
513        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
514  private:
515        virtual std::string typeString() const override;
516};
517
518class EnumInstType : public ReferenceToType {
519        typedef ReferenceToType Parent;
520  public:
521        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
522        // where the union used in this type is actually defined
523        EnumDecl *baseEnum = nullptr;
524
525        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
526        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
527        EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
528
529        EnumDecl *get_baseEnum() const { return baseEnum; }
530        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
531
532        virtual bool isComplete() const override;
533
534        virtual AggregateDecl * getAggr() const override;
535
536        virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
537        virtual void accept( Visitor & v ) override { v.visit( this ); }
538        virtual void accept( Visitor & v ) const override { v.visit( this ); }
539        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
540
541        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
542  private:
543        virtual std::string typeString() const override;
544};
545
546class TraitInstType : public ReferenceToType {
547        typedef ReferenceToType Parent;
548  public:
549        // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree,
550        // where the trait used in this type is actually defined
551        TraitDecl * baseTrait = nullptr;
552
553        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
554        TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
555        TraitInstType( const TraitInstType & other );
556        ~TraitInstType();
557
558        virtual bool isComplete() const override;
559
560        virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
561        virtual void accept( Visitor & v ) override { v.visit( this ); }
562        virtual void accept( Visitor & v ) const override { v.visit( this ); }
563        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
564  private:
565        virtual std::string typeString() const override;
566};
567
568class TypeInstType : public ReferenceToType {
569        typedef ReferenceToType Parent;
570  public:
571        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
572        // where the type used here is actually defined
573        TypeDecl *baseType;
574        bool isFtype;
575
576        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
577        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
578        TypeInstType( const TypeInstType & other );
579        ~TypeInstType();
580
581        TypeDecl *get_baseType() const { return baseType; }
582        void set_baseType( TypeDecl *newValue );
583        bool get_isFtype() const { return isFtype; }
584        void set_isFtype( bool newValue ) { isFtype = newValue; }
585
586        virtual bool isComplete() const override;
587
588        virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
589        virtual void accept( Visitor & v ) override { v.visit( this ); }
590        virtual void accept( Visitor & v ) const override { v.visit( this ); }
591        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
592        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
593  private:
594        virtual std::string typeString() const override;
595};
596
597class TupleType : public Type {
598  public:
599        std::list<Type *> types;
600        std::list<Declaration *> members;
601
602        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
603        TupleType( const TupleType& );
604        virtual ~TupleType();
605
606        typedef std::list<Type*> value_type;
607        typedef value_type::iterator iterator;
608
609        std::list<Type *> & get_types() { return types; }
610        virtual unsigned size() const override { return types.size(); };
611
612        // For now, this is entirely synthetic -- tuple types always have unnamed members.
613        // Eventually, we may allow named tuples, in which case members should subsume types
614        std::list<Declaration *> & get_members() { return members; }
615
616        iterator begin() { return types.begin(); }
617        iterator end() { return types.end(); }
618
619        virtual Type * getComponent( unsigned i ) override {
620                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
621                return *(begin()+i);
622        }
623
624        // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
625
626        virtual TupleType *clone() const override { return new TupleType( *this ); }
627        virtual void accept( Visitor & v ) override { v.visit( this ); }
628        virtual void accept( Visitor & v ) const override { v.visit( this ); }
629        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
630        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
631};
632
633class TypeofType : public Type {
634  public:
635        Expression *expr;    ///< expression to take the type of
636        bool is_basetypeof;  ///< true iff is basetypeof type
637
638        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
639        TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof,
640                const std::list< Attribute * > & attributes = std::list< Attribute * >() );
641        TypeofType( const TypeofType& );
642        virtual ~TypeofType();
643
644        Expression *get_expr() const { return expr; }
645        void set_expr( Expression *newValue ) { expr = newValue; }
646
647        virtual bool isComplete() const override { assert( false ); return false; }
648
649        virtual TypeofType *clone() const override { return new TypeofType( *this ); }
650        virtual void accept( Visitor & v ) override { v.visit( this ); }
651        virtual void accept( Visitor & v ) const override { v.visit( this ); }
652        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
653        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
654};
655
656class AttrType : public Type {
657  public:
658        std::string name;
659        Expression *expr;
660        Type *type;
661        bool isType;
662
663        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
664        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
665        AttrType( const AttrType& );
666        virtual ~AttrType();
667
668        const std::string & get_name() const { return name; }
669        void set_name( const std::string & newValue ) { name = newValue; }
670        Expression *get_expr() const { return expr; }
671        void set_expr( Expression *newValue ) { expr = newValue; }
672        Type *get_type() const { return type; }
673        void set_type( Type *newValue ) { type = newValue; }
674        bool get_isType() const { return isType; }
675        void set_isType( bool newValue ) { isType = newValue; }
676
677        virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here
678
679        virtual AttrType *clone() const override { return new AttrType( *this ); }
680        virtual void accept( Visitor & v ) override { v.visit( this ); }
681        virtual void accept( Visitor & v ) const override { v.visit( this ); }
682        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
683        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
684};
685
686/// Represents the GCC built-in varargs type
687class VarArgsType : public Type {
688  public:
689        VarArgsType();
690        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
691
692        virtual bool isComplete() const override{ return true; } // xxx - is this right?
693
694        virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
695        virtual void accept( Visitor & v ) override { v.visit( this ); }
696        virtual void accept( Visitor & v ) const override { v.visit( this ); }
697        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
698        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
699};
700
701/// Represents a zero constant
702class ZeroType : public Type {
703  public:
704        ZeroType();
705        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
706
707        virtual ZeroType *clone() const override { return new ZeroType( *this ); }
708        virtual void accept( Visitor & v ) override { v.visit( this ); }
709        virtual void accept( Visitor & v ) const override { v.visit( this ); }
710        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
711        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
712};
713
714/// Represents a one constant
715class OneType : public Type {
716  public:
717        OneType();
718        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
719
720        virtual OneType *clone() const override { return new OneType( *this ); }
721        virtual void accept( Visitor & v ) override { v.visit( this ); }
722        virtual void accept( Visitor & v ) const override { v.visit( this ); }
723        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
724        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
725};
726
727class GlobalScopeType : public Type {
728  public:
729        GlobalScopeType();
730
731        virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); }
732        virtual void accept( Visitor & v ) override { v.visit( this ); }
733        virtual void accept( Visitor & v ) const override { v.visit( this ); }
734        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
735        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
736};
737
738// Local Variables: //
739// tab-width: 4 //
740// mode: c++ //
741// compile-command: "make install" //
742// End: //
Note: See TracBrowser for help on using the repository browser.