source: src/SynTree/Type.h @ b18b0b5

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since b18b0b5 was ae63a18, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

resolving conflicts

  • Property mode set to 100644
File size: 16.4 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
[baf7fee]11// Last Modified By : Rob Schluntz
[ae63a18]12// Last Modified On : Fri Dec 18 14:46:18 2015
13// Update Count     : 18
[0dd3a2f]14//
15
[51b7345]16#ifndef TYPE_H
17#define TYPE_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22
[c8ffe20b]23class Type {
24  public:
[ae63a18]25        struct Qualifiers {
[0dd3a2f]26                Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
[1db21619]27                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
[ae63a18]28
[0dd3a2f]29                Qualifiers &operator+=( const Qualifiers &other );
30                Qualifiers &operator-=( const Qualifiers &other );
31                Qualifiers operator+( const Type::Qualifiers &other );
32                bool operator==( const Qualifiers &other );
33                bool operator!=( const Qualifiers &other );
34                bool operator<=( const Qualifiers &other );
35                bool operator>=( const Qualifiers &other );
36                bool operator<( const Qualifiers &other );
37                bool operator>( const Qualifiers &other );
[ae63a18]38
[0dd3a2f]39                bool isConst;
40                bool isVolatile;
41                bool isRestrict;
42                bool isLvalue;
43                bool isAtomic;
44                bool isAttribute;
[ae63a18]45        };
[0dd3a2f]46
47        Type( const Qualifiers &tq );
48        Type( const Type &other );
49        virtual ~Type();
50
51        Qualifiers &get_qualifiers() { return tq; }
52        bool get_isConst() { return tq.isConst; }
53        bool get_isVolatile() { return tq.isVolatile; }
54        bool get_isRestrict() { return tq.isRestrict; }
55        bool get_isLvalue() { return tq.isLvalue; }
56        bool get_isAtomic() { return tq.isAtomic; }
57        bool get_isAttribute() { return tq.isAttribute; }
58        void set_isConst( bool newValue ) { tq.isConst = newValue; }
[721f17a]59        void set_isVolatile( bool newValue ) { tq.isVolatile = newValue; }
[0dd3a2f]60        void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
61        void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
62        void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
63        void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
64        std::list<TypeDecl*>& get_forall() { return forall; }
65
66        virtual Type *clone() const = 0;
67        virtual void accept( Visitor &v ) = 0;
68        virtual Type *acceptMutator( Mutator &m ) = 0;
69        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]70  private:
[0dd3a2f]71        Qualifiers tq;
72        std::list<TypeDecl*> forall;
[51b7345]73};
74
[c8ffe20b]75class VoidType : public Type {
76  public:
[0dd3a2f]77        VoidType( const Type::Qualifiers &tq );
[51b7345]78
[0dd3a2f]79        virtual VoidType *clone() const { return new VoidType( *this ); }
80        virtual void accept( Visitor &v ) { v.visit( this ); }
81        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
82        virtual void print( std::ostream &os, int indent = 0 ) const;
[51b7345]83};
84
[c8ffe20b]85class BasicType : public Type {
86  public:
[ae63a18]87        enum Kind {
[0dd3a2f]88                Bool,
89                Char,
90                SignedChar,
91                UnsignedChar,
92                ShortSignedInt,
93                ShortUnsignedInt,
94                SignedInt,
95                UnsignedInt,
96                LongSignedInt,
97                LongUnsignedInt,
98                LongLongSignedInt,
99                LongLongUnsignedInt,
100                Float,
101                Double,
102                LongDouble,
103                FloatComplex,
104                DoubleComplex,
105                LongDoubleComplex,
106                FloatImaginary,
107                DoubleImaginary,
108                LongDoubleImaginary,
109                NUMBER_OF_BASIC_TYPES
[ae63a18]110        };
[0dd3a2f]111
[59db689]112        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
[0dd3a2f]113
114        BasicType( const Type::Qualifiers &tq, Kind bt );
115
116        Kind get_kind() { return kind; }
117        void set_kind( Kind newValue ) { kind = newValue; }
118
119        virtual BasicType *clone() const { return new BasicType( *this ); }
120        virtual void accept( Visitor &v ) { v.visit( this ); }
121        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
122        virtual void print( std::ostream &os, int indent = 0 ) const;
123
124        bool isInteger() const;
[c8ffe20b]125  private:
[0dd3a2f]126        Kind kind;
[51b7345]127};
128
[c8ffe20b]129class PointerType : public Type {
130  public:
[0dd3a2f]131        PointerType( const Type::Qualifiers &tq, Type *base );
132        PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
133        PointerType( const PointerType& );
134        virtual ~PointerType();
135
136        Type *get_base() { return base; }
137        void set_base( Type *newValue ) { base = newValue; }
138        Expression *get_dimension() { return dimension; }
139        void set_dimension( Expression *newValue ) { dimension = newValue; }
140        bool get_isVarLen() { return isVarLen; }
141        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
142        bool get_isStatic() { return isStatic; }
143        void set_isStatic( bool newValue ) { isStatic = newValue; }
144
145        virtual PointerType *clone() const { return new PointerType( *this ); }
146        virtual void accept( Visitor &v ) { v.visit( this ); }
147        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
148        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]149  private:
[0dd3a2f]150        Type *base;
[ae63a18]151
[0dd3a2f]152        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
153        Expression *dimension;
154        bool isVarLen;
155        bool isStatic;
[51b7345]156};
157
[c8ffe20b]158class ArrayType : public Type {
159  public:
[0dd3a2f]160        ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
161        ArrayType( const ArrayType& );
162        virtual ~ArrayType();
163
164        Type *get_base() { return base; }
165        void set_base( Type *newValue ) { base = newValue; }
166        Expression *get_dimension() { return dimension; }
167        void set_dimension( Expression *newValue ) { dimension = newValue; }
168        bool get_isVarLen() { return isVarLen; }
169        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
170        bool get_isStatic() { return isStatic; }
171        void set_isStatic( bool newValue ) { isStatic = newValue; }
172
173        virtual ArrayType *clone() const { return new ArrayType( *this ); }
174        virtual void accept( Visitor &v ) { v.visit( this ); }
175        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
176        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]177  private:
[0dd3a2f]178        Type *base;
179        Expression *dimension;
180        bool isVarLen;
181        bool isStatic;
[51b7345]182};
183
[c8ffe20b]184class FunctionType : public Type {
185  public:
[0dd3a2f]186        FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
187        FunctionType( const FunctionType& );
188        virtual ~FunctionType();
189
[cf16f94]190        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
191        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
[0dd3a2f]192        bool get_isVarArgs() { return isVarArgs; }
193        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
194
195        virtual FunctionType *clone() const { return new FunctionType( *this ); }
196        virtual void accept( Visitor &v ) { v.visit( this ); }
197        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
198        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]199  private:
[0dd3a2f]200        std::list<DeclarationWithType*> returnVals;
201        std::list<DeclarationWithType*> parameters;
202
[839ccbb]203        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
204        // This could be because of
[0dd3a2f]205        // - an ellipsis in a prototype declaration
206        // - an unprototyped declaration
207        bool isVarArgs;
[51b7345]208};
209
[c8ffe20b]210class ReferenceToType : public Type {
211  public:
[0dd3a2f]212        ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
213        ReferenceToType( const ReferenceToType &other );
214        virtual ~ReferenceToType();
215
[5f2f2d7]216        const std::string &get_name() const { return name; }
[0dd3a2f]217        void set_name( std::string newValue ) { name = newValue; }
218        std::list< Expression* >& get_parameters() { return parameters; }
[ae63a18]219
[0dd3a2f]220        virtual ReferenceToType *clone() const = 0;
221        virtual void accept( Visitor &v ) = 0;
222        virtual Type *acceptMutator( Mutator &m ) = 0;
223        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]224  protected:
[0dd3a2f]225        virtual std::string typeString() const = 0;
226        std::list< Expression* > parameters;
[c8ffe20b]227  private:
[0dd3a2f]228        std::string name;
[51b7345]229};
230
[c8ffe20b]231class StructInstType : public ReferenceToType {
[0dd3a2f]232        typedef ReferenceToType Parent;
[c8ffe20b]233  public:
[0dd3a2f]234        StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
235        StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
[51b7345]236
[0dd3a2f]237        StructDecl *get_baseStruct() const { return baseStruct; }
238        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
[37a3b8f9]239
[ed94eac]240        /// Accesses generic parameters of base struct (NULL if none such)
[839ccbb]241        std::list<TypeDecl*> * get_baseParameters();
[ae63a18]242
[37a3b8f9]243        /// Looks up the members of this struct named "name" and places them into "foundDecls".
244        /// Clones declarations into "foundDecls", caller responsible for freeing
[0dd3a2f]245        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
[51b7345]246
[0dd3a2f]247        virtual StructInstType *clone() const { return new StructInstType( *this ); }
248        virtual void accept( Visitor &v ) { v.visit( this ); }
249        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]250  private:
[0dd3a2f]251        virtual std::string typeString() const;
[ae63a18]252
[0dd3a2f]253        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
254        // where the structure used in this type is actually defined
255        StructDecl *baseStruct;
[51b7345]256};
257
[c8ffe20b]258class UnionInstType : public ReferenceToType {
[0dd3a2f]259        typedef ReferenceToType Parent;
[c8ffe20b]260  public:
[0dd3a2f]261        UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
262        UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
263
264        UnionDecl *get_baseUnion() const { return baseUnion; }
265        void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
[37a3b8f9]266
[ed94eac]267        /// Accesses generic parameters of base union (NULL if none such)
[839ccbb]268        std::list<TypeDecl*> * get_baseParameters();
[ae63a18]269
[37a3b8f9]270        /// looks up the members of this union named "name" and places them into "foundDecls"
271        /// Clones declarations into "foundDecls", caller responsible for freeing
[0dd3a2f]272        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
273
274        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
275        virtual void accept( Visitor &v ) { v.visit( this ); }
276        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]277  private:
[0dd3a2f]278        virtual std::string typeString() const;
[ae63a18]279
[0dd3a2f]280        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
281        // where the union used in this type is actually defined
282        UnionDecl *baseUnion;
[51b7345]283};
284
[c8ffe20b]285class EnumInstType : public ReferenceToType {
[0dd3a2f]286        typedef ReferenceToType Parent;
[c8ffe20b]287  public:
[0dd3a2f]288        EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
289        EnumInstType( const EnumInstType &other ) : Parent( other ) {}
[51b7345]290
[0dd3a2f]291        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
292        virtual void accept( Visitor &v ) { v.visit( this ); }
293        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]294  private:
[0dd3a2f]295        virtual std::string typeString() const;
[51b7345]296};
297
[c8ffe20b]298class ContextInstType : public ReferenceToType {
[0dd3a2f]299        typedef ReferenceToType Parent;
[c8ffe20b]300  public:
[0dd3a2f]301        ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
302        ContextInstType( const ContextInstType &other );
303        ~ContextInstType();
[51b7345]304
[0dd3a2f]305        std::list< Declaration* >& get_members() { return members; }
[51b7345]306
[0dd3a2f]307        virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
308        virtual void accept( Visitor &v ) { v.visit( this ); }
309        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]310  private:
[0dd3a2f]311        virtual std::string typeString() const;
[ae63a18]312
[0dd3a2f]313        // this member is filled in by the validate pass, which instantiates the members of the correponding
314        // aggregate with the actual type parameters specified for this use of the context
315        std::list< Declaration* > members;
[51b7345]316};
317
[c8ffe20b]318class TypeInstType : public ReferenceToType {
[0dd3a2f]319        typedef ReferenceToType Parent;
[c8ffe20b]320  public:
[0dd3a2f]321        TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
322        TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
323        TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
324
325        TypeDecl *get_baseType() const { return baseType; }
326        void set_baseType( TypeDecl *newValue );
327        bool get_isFtype() const { return isFtype; }
328        void set_isFtype( bool newValue ) { isFtype = newValue; }
[ae63a18]329
[0dd3a2f]330        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
331        virtual void accept( Visitor &v ) { v.visit( this ); }
332        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
333        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]334  private:
[0dd3a2f]335        virtual std::string typeString() const;
336        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
337        // where the type used here is actually defined
338        TypeDecl *baseType;
339        bool isFtype;
[51b7345]340};
341
[c8ffe20b]342class TupleType : public Type {
343  public:
[0dd3a2f]344        TupleType( const Type::Qualifiers &tq );
345        TupleType( const TupleType& );
346        virtual ~TupleType();
[51b7345]347
[0dd3a2f]348        std::list<Type*>& get_types() { return types; }
[51b7345]349
[0dd3a2f]350        virtual TupleType *clone() const { return new TupleType( *this ); }
351        virtual void accept( Visitor &v ) { v.visit( this ); }
352        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
353        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]354  private:
[0dd3a2f]355        std::list<Type*> types;
[51b7345]356};
357
[c8ffe20b]358class TypeofType : public Type {
359  public:
[0dd3a2f]360        TypeofType( const Type::Qualifiers &tq, Expression *expr );
361        TypeofType( const TypeofType& );
362        virtual ~TypeofType();
[51b7345]363
[0dd3a2f]364        Expression *get_expr() const { return expr; }
365        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]366
[0dd3a2f]367        virtual TypeofType *clone() const { return new TypeofType( *this ); }
368        virtual void accept( Visitor &v ) { v.visit( this ); }
369        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
370        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]371  private:
[0dd3a2f]372        Expression *expr;
[51b7345]373};
374
[c8ffe20b]375class AttrType : public Type {
376  public:
[0dd3a2f]377        AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
378        AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
379        AttrType( const AttrType& );
380        virtual ~AttrType();
381
[5f2f2d7]382        const std::string &get_name() const { return name; }
[0dd3a2f]383        void set_name( const std::string &newValue ) { name = newValue; }
384        Expression *get_expr() const { return expr; }
385        void set_expr( Expression *newValue ) { expr = newValue; }
386        Type *get_type() const { return type; }
387        void set_type( Type *newValue ) { type = newValue; }
388        bool get_isType() const { return isType; }
389        void set_isType( bool newValue ) { isType = newValue; }
390
391        virtual AttrType *clone() const { return new AttrType( *this ); }
392        virtual void accept( Visitor &v ) { v.visit( this ); }
393        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
394        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]395  private:
[0dd3a2f]396        std::string name;
397        Expression *expr;
398        Type *type;
399        bool isType;
[51b7345]400};
401
[c8ffe20b]402inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
[0dd3a2f]403        isConst |= other.isConst;
404        isVolatile |= other.isVolatile;
405        isRestrict |= other.isRestrict;
406        isLvalue |= other.isLvalue;
407        isAtomic |= other.isAtomic;
408        return *this;
[51b7345]409}
410
[c8ffe20b]411inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
[0dd3a2f]412        if ( other.isConst ) isConst = 0;
413        if ( other.isVolatile ) isVolatile = 0;
414        if ( other.isRestrict ) isRestrict = 0;
415        if ( other.isAtomic ) isAtomic = 0;
416        return *this;
[51b7345]417}
418
[c8ffe20b]419inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
[0dd3a2f]420        Qualifiers q = other;
421        q += *this;
422        return q;
[51b7345]423}
424
[c8ffe20b]425inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
[0dd3a2f]426        return isConst == other.isConst
427                && isVolatile == other.isVolatile
[f6835e5]428//              && isRestrict == other.isRestrict
429//              && isLvalue == other.isLvalue
[0dd3a2f]430                && isAtomic == other.isAtomic;
[51b7345]431}
432
[c8ffe20b]433inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
[0dd3a2f]434        return isConst != other.isConst
435                || isVolatile != other.isVolatile
[f6835e5]436//              || isRestrict != other.isRestrict
437//              || isLvalue != other.isLvalue
[0dd3a2f]438                || isAtomic != other.isAtomic;
[51b7345]439}
440
[c8ffe20b]441inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
[0dd3a2f]442        return isConst <= other.isConst
443                && isVolatile <= other.isVolatile
[f6835e5]444//              && isRestrict <= other.isRestrict
445//              && isLvalue >= other.isLvalue
[0dd3a2f]446                && isAtomic == other.isAtomic;
[51b7345]447}
448
[c8ffe20b]449inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
[0dd3a2f]450        return isConst >= other.isConst
451                && isVolatile >= other.isVolatile
[f6835e5]452//              && isRestrict >= other.isRestrict
453//              && isLvalue <= other.isLvalue
[0dd3a2f]454                && isAtomic == other.isAtomic;
[51b7345]455}
456
[c8ffe20b]457inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
[0dd3a2f]458        return operator!=( other ) && operator<=( other );
[51b7345]459}
460
[c8ffe20b]461inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
[0dd3a2f]462        return operator!=( other ) && operator>=( other );
[51b7345]463}
464
[baf7fee]465std::ostream & operator<<( std::ostream & out, Type * type );
466
[c8ffe20b]467#endif // TYPE_H
[0dd3a2f]468
469// Local Variables: //
470// tab-width: 4 //
471// mode: c++ //
472// compile-command: "make install" //
473// End: //
Note: See TracBrowser for help on using the repository browser.