source: src/SynTree/Type.h @ 3831b58

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3831b58 was c54b0b4, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Added isMutex qualifier

  • Property mode set to 100644
File size: 22.2 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
[90c3b1c]11// Last Modified By : Peter A. Buhr
[dd020c0]12// Last Modified On : Wed Mar  1 09:11:45 2017
13// Update Count     : 41
[0dd3a2f]14//
15
[51b7345]16#ifndef TYPE_H
17#define TYPE_H
18
[138e29e]19#include "BaseSyntaxNode.h"
20#include "Mutator.h"
[51b7345]21#include "SynTree.h"
22#include "Visitor.h"
23
[138e29e]24class Type : public BaseSyntaxNode {
[c8ffe20b]25  public:
[ae63a18]26        struct Qualifiers {
[c54b0b4]27                Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isMutex( false ) {}
28                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isMutex ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isMutex( isMutex ) {}
[ae63a18]29
[aa8f9df]30                Qualifiers &operator&=( const Qualifiers &other );
[0dd3a2f]31                Qualifiers &operator+=( const Qualifiers &other );
32                Qualifiers &operator-=( const Qualifiers &other );
33                Qualifiers operator+( const Type::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 );
38                bool operator<( const Qualifiers &other );
39                bool operator>( const Qualifiers &other );
[f1b1e4c]40                void print( std::ostream &os, int indent = 0 ) const;
[ae63a18]41
[0dd3a2f]42                bool isConst;
43                bool isVolatile;
44                bool isRestrict;
45                bool isLvalue;
46                bool isAtomic;
[c54b0b4]47                bool isMutex;
[ae63a18]48        };
[0dd3a2f]49
[c0aa336]50        Type( const Qualifiers &tq, const std::list< Attribute * > & attributes );
[0dd3a2f]51        Type( const Type &other );
52        virtual ~Type();
53
54        Qualifiers &get_qualifiers() { return tq; }
55        bool get_isConst() { return tq.isConst; }
56        bool get_isVolatile() { return tq.isVolatile; }
57        bool get_isRestrict() { return tq.isRestrict; }
58        bool get_isLvalue() { return tq.isLvalue; }
59        bool get_isAtomic() { return tq.isAtomic; }
60        void set_isConst( bool newValue ) { tq.isConst = newValue; }
[721f17a]61        void set_isVolatile( bool newValue ) { tq.isVolatile = newValue; }
[0dd3a2f]62        void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
63        void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
64        void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
[8c49c0e]65
66        typedef std::list<TypeDecl *> ForallList;
67        ForallList& get_forall() { return forall; }
[0dd3a2f]68
[c0aa336]69        std::list< Attribute * >& get_attributes() { return attributes; }
70        const std::list< Attribute * >& get_attributes() const { return attributes; }
71
[906e24d]72        /// How many elemental types are represented by this type
73        virtual unsigned size() const { return 1; };
74        virtual bool isVoid() const { return size() == 0; }
[7933351]75        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]76
[4a9ccc3]77        virtual bool isComplete() const { return true; }
78
[0dd3a2f]79        virtual Type *clone() const = 0;
80        virtual void accept( Visitor &v ) = 0;
81        virtual Type *acceptMutator( Mutator &m ) = 0;
82        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]83  private:
[0dd3a2f]84        Qualifiers tq;
[8c49c0e]85        ForallList forall;
[c0aa336]86        std::list< Attribute * > attributes;
[51b7345]87};
88
[4cb935e]89extern Type::Qualifiers emptyQualifiers;                                // no qualifiers on constants
90
[c8ffe20b]91class VoidType : public Type {
92  public:
[c0aa336]93        VoidType( const Type::Qualifiers &tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[51b7345]94
[906e24d]95        virtual unsigned size() const { return 0; };
[4a9ccc3]96        virtual bool isComplete() const { return false; }
[906e24d]97
[0dd3a2f]98        virtual VoidType *clone() const { return new VoidType( *this ); }
99        virtual void accept( Visitor &v ) { v.visit( this ); }
100        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
101        virtual void print( std::ostream &os, int indent = 0 ) const;
[51b7345]102};
103
[c8ffe20b]104class BasicType : public Type {
105  public:
[ae63a18]106        enum Kind {
[0dd3a2f]107                Bool,
108                Char,
109                SignedChar,
110                UnsignedChar,
111                ShortSignedInt,
112                ShortUnsignedInt,
113                SignedInt,
114                UnsignedInt,
115                LongSignedInt,
116                LongUnsignedInt,
117                LongLongSignedInt,
118                LongLongUnsignedInt,
119                Float,
120                Double,
121                LongDouble,
122                FloatComplex,
123                DoubleComplex,
124                LongDoubleComplex,
125                FloatImaginary,
126                DoubleImaginary,
127                LongDoubleImaginary,
128                NUMBER_OF_BASIC_TYPES
[ae63a18]129        };
[0dd3a2f]130
[59db689]131        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
[0dd3a2f]132
[c0aa336]133        BasicType( const Type::Qualifiers &tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]134
135        Kind get_kind() { return kind; }
136        void set_kind( Kind newValue ) { kind = newValue; }
137
138        virtual BasicType *clone() const { return new BasicType( *this ); }
139        virtual void accept( Visitor &v ) { v.visit( this ); }
140        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
141        virtual void print( std::ostream &os, int indent = 0 ) const;
142
143        bool isInteger() const;
[c8ffe20b]144  private:
[0dd3a2f]145        Kind kind;
[51b7345]146};
147
[c8ffe20b]148class PointerType : public Type {
149  public:
[c0aa336]150        PointerType( const Type::Qualifiers &tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
151        PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]152        PointerType( const PointerType& );
153        virtual ~PointerType();
154
155        Type *get_base() { return base; }
156        void set_base( Type *newValue ) { base = newValue; }
157        Expression *get_dimension() { return dimension; }
158        void set_dimension( Expression *newValue ) { dimension = newValue; }
159        bool get_isVarLen() { return isVarLen; }
160        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
161        bool get_isStatic() { return isStatic; }
162        void set_isStatic( bool newValue ) { isStatic = newValue; }
163
164        virtual PointerType *clone() const { return new PointerType( *this ); }
165        virtual void accept( Visitor &v ) { v.visit( this ); }
166        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
167        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]168  private:
[0dd3a2f]169        Type *base;
[ae63a18]170
[0dd3a2f]171        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
172        Expression *dimension;
173        bool isVarLen;
174        bool isStatic;
[51b7345]175};
176
[c8ffe20b]177class ArrayType : public Type {
178  public:
[c0aa336]179        ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]180        ArrayType( const ArrayType& );
181        virtual ~ArrayType();
182
183        Type *get_base() { return base; }
184        void set_base( Type *newValue ) { base = newValue; }
185        Expression *get_dimension() { return dimension; }
186        void set_dimension( Expression *newValue ) { dimension = newValue; }
187        bool get_isVarLen() { return isVarLen; }
188        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
189        bool get_isStatic() { return isStatic; }
190        void set_isStatic( bool newValue ) { isStatic = newValue; }
191
[4a9ccc3]192        virtual bool isComplete() const { return ! isVarLen; }
193
[0dd3a2f]194        virtual ArrayType *clone() const { return new ArrayType( *this ); }
195        virtual void accept( Visitor &v ) { v.visit( this ); }
196        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
197        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]198  private:
[0dd3a2f]199        Type *base;
200        Expression *dimension;
201        bool isVarLen;
202        bool isStatic;
[51b7345]203};
204
[c8ffe20b]205class FunctionType : public Type {
206  public:
[c0aa336]207        FunctionType( const Type::Qualifiers &tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
[0dd3a2f]208        FunctionType( const FunctionType& );
209        virtual ~FunctionType();
210
[cf16f94]211        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
212        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
[8bf784a]213        bool get_isVarArgs() const { return isVarArgs; }
[0dd3a2f]214        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
[8bf784a]215        bool isTtype() const;
216
[0dd3a2f]217        virtual FunctionType *clone() const { return new FunctionType( *this ); }
218        virtual void accept( Visitor &v ) { v.visit( this ); }
219        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
220        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]221  private:
[0dd3a2f]222        std::list<DeclarationWithType*> returnVals;
223        std::list<DeclarationWithType*> parameters;
224
[839ccbb]225        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
226        // This could be because of
[0dd3a2f]227        // - an ellipsis in a prototype declaration
228        // - an unprototyped declaration
229        bool isVarArgs;
[51b7345]230};
231
[c8ffe20b]232class ReferenceToType : public Type {
233  public:
[c0aa336]234        ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes );
[0dd3a2f]235        ReferenceToType( const ReferenceToType &other );
236        virtual ~ReferenceToType();
237
[5f2f2d7]238        const std::string &get_name() const { return name; }
[0dd3a2f]239        void set_name( std::string newValue ) { name = newValue; }
240        std::list< Expression* >& get_parameters() { return parameters; }
[43c89a7]241        bool get_hoistType() const { return hoistType; }
242        void set_hoistType( bool newValue ) { hoistType = newValue; }
[ae63a18]243
[0dd3a2f]244        virtual ReferenceToType *clone() const = 0;
245        virtual void accept( Visitor &v ) = 0;
246        virtual Type *acceptMutator( Mutator &m ) = 0;
247        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]248  protected:
[0dd3a2f]249        virtual std::string typeString() const = 0;
250        std::list< Expression* > parameters;
251        std::string name;
[5d125e4]252  private:
[43c89a7]253        bool hoistType;
[51b7345]254};
255
[c8ffe20b]256class StructInstType : public ReferenceToType {
[0dd3a2f]257        typedef ReferenceToType Parent;
[c8ffe20b]258  public:
[c0aa336]259        StructInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
260        StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]261        StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
[51b7345]262
[0dd3a2f]263        StructDecl *get_baseStruct() const { return baseStruct; }
264        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
[37a3b8f9]265
[ed94eac]266        /// Accesses generic parameters of base struct (NULL if none such)
[839ccbb]267        std::list<TypeDecl*> * get_baseParameters();
[ae63a18]268
[4a9ccc3]269        virtual bool isComplete() const;
270
[37a3b8f9]271        /// Looks up the members of this struct named "name" and places them into "foundDecls".
272        /// Clones declarations into "foundDecls", caller responsible for freeing
[0dd3a2f]273        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
[51b7345]274
[0dd3a2f]275        virtual StructInstType *clone() const { return new StructInstType( *this ); }
276        virtual void accept( Visitor &v ) { v.visit( this ); }
277        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[5d125e4]278
279        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]280  private:
[0dd3a2f]281        virtual std::string typeString() const;
[ae63a18]282
[0dd3a2f]283        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
284        // where the structure used in this type is actually defined
285        StructDecl *baseStruct;
[51b7345]286};
287
[c8ffe20b]288class UnionInstType : public ReferenceToType {
[0dd3a2f]289        typedef ReferenceToType Parent;
[c8ffe20b]290  public:
[c0aa336]291        UnionInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
292        UnionInstType( const Type::Qualifiers &tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]293        UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
294
295        UnionDecl *get_baseUnion() const { return baseUnion; }
[c0aa336]296        void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
[37a3b8f9]297
[ed94eac]298        /// Accesses generic parameters of base union (NULL if none such)
[c0aa336]299        std::list< TypeDecl * > * get_baseParameters();
[ae63a18]300
[4a9ccc3]301        virtual bool isComplete() const;
302
[37a3b8f9]303        /// looks up the members of this union named "name" and places them into "foundDecls"
304        /// Clones declarations into "foundDecls", caller responsible for freeing
[0dd3a2f]305        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
306
307        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
308        virtual void accept( Visitor &v ) { v.visit( this ); }
309        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[5d125e4]310
311        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]312  private:
[0dd3a2f]313        virtual std::string typeString() const;
[ae63a18]314
[0dd3a2f]315        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
316        // where the union used in this type is actually defined
317        UnionDecl *baseUnion;
[51b7345]318};
319
[c8ffe20b]320class EnumInstType : public ReferenceToType {
[0dd3a2f]321        typedef ReferenceToType Parent;
[c8ffe20b]322  public:
[c0aa336]323        EnumInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
324        EnumInstType( const Type::Qualifiers &tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
325        EnumInstType( const EnumInstType &other ) : Parent( other ), baseEnum( other.baseEnum ) {}
[51b7345]326
[c0aa336]327        EnumDecl *get_baseEnum() const { return baseEnum; }
328        void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
329
330        virtual bool isComplete() const;
[4a9ccc3]331
[0dd3a2f]332        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
333        virtual void accept( Visitor &v ) { v.visit( this ); }
334        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]335  private:
[0dd3a2f]336        virtual std::string typeString() const;
[c0aa336]337
338        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
339        // where the union used in this type is actually defined
340        EnumDecl *baseEnum = nullptr;
[51b7345]341};
342
[4040425]343class TraitInstType : public ReferenceToType {
[0dd3a2f]344        typedef ReferenceToType Parent;
[c8ffe20b]345  public:
[c0aa336]346        TraitInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
[4040425]347        TraitInstType( const TraitInstType &other );
348        ~TraitInstType();
[51b7345]349
[0dd3a2f]350        std::list< Declaration* >& get_members() { return members; }
[51b7345]351
[4a9ccc3]352        virtual bool isComplete() const;
353
[4040425]354        virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
[0dd3a2f]355        virtual void accept( Visitor &v ) { v.visit( this ); }
356        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[c8ffe20b]357  private:
[0dd3a2f]358        virtual std::string typeString() const;
[ae63a18]359
[0dd3a2f]360        // this member is filled in by the validate pass, which instantiates the members of the correponding
361        // aggregate with the actual type parameters specified for this use of the context
362        std::list< Declaration* > members;
[51b7345]363};
364
[c8ffe20b]365class TypeInstType : public ReferenceToType {
[0dd3a2f]366        typedef ReferenceToType Parent;
[c8ffe20b]367  public:
[c0aa336]368        TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
369        TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[2c57025]370        TypeInstType( const TypeInstType &other );
[1e8b02f5]371        ~TypeInstType();
[0dd3a2f]372
373        TypeDecl *get_baseType() const { return baseType; }
374        void set_baseType( TypeDecl *newValue );
375        bool get_isFtype() const { return isFtype; }
376        void set_isFtype( bool newValue ) { isFtype = newValue; }
[ae63a18]377
[4a9ccc3]378        virtual bool isComplete() const;
379
[0dd3a2f]380        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
381        virtual void accept( Visitor &v ) { v.visit( this ); }
382        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
383        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]384  private:
[0dd3a2f]385        virtual std::string typeString() const;
386        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
387        // where the type used here is actually defined
388        TypeDecl *baseType;
389        bool isFtype;
[51b7345]390};
391
[c8ffe20b]392class TupleType : public Type {
393  public:
[c0aa336]394        TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >(), const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]395        TupleType( const TupleType& );
396        virtual ~TupleType();
[51b7345]397
[0362d42]398        typedef std::list<Type*> value_type;
399        typedef value_type::iterator iterator;
400
[0dd3a2f]401        std::list<Type*>& get_types() { return types; }
[906e24d]402        virtual unsigned size() const { return types.size(); };
[51b7345]403
[0362d42]404        iterator begin() { return types.begin(); }
405        iterator end() { return types.end(); }
406
[7933351]407        virtual Type * getComponent( unsigned i ) {
408                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
409                return *(begin()+i);
410        }
411
[4a9ccc3]412        // virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
413
[0dd3a2f]414        virtual TupleType *clone() const { return new TupleType( *this ); }
415        virtual void accept( Visitor &v ) { v.visit( this ); }
416        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
417        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]418  private:
[0dd3a2f]419        std::list<Type*> types;
[51b7345]420};
421
[c8ffe20b]422class TypeofType : public Type {
423  public:
[c0aa336]424        TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]425        TypeofType( const TypeofType& );
426        virtual ~TypeofType();
[51b7345]427
[0dd3a2f]428        Expression *get_expr() const { return expr; }
429        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]430
[4a9ccc3]431        virtual bool isComplete() const { assert( false ); return false; }
432
[0dd3a2f]433        virtual TypeofType *clone() const { return new TypeofType( *this ); }
434        virtual void accept( Visitor &v ) { v.visit( this ); }
435        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
436        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]437  private:
[0dd3a2f]438        Expression *expr;
[51b7345]439};
440
[c8ffe20b]441class AttrType : public Type {
442  public:
[c0aa336]443        AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
444        AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[0dd3a2f]445        AttrType( const AttrType& );
446        virtual ~AttrType();
447
[5f2f2d7]448        const std::string &get_name() const { return name; }
[0dd3a2f]449        void set_name( const std::string &newValue ) { name = newValue; }
450        Expression *get_expr() const { return expr; }
451        void set_expr( Expression *newValue ) { expr = newValue; }
452        Type *get_type() const { return type; }
453        void set_type( Type *newValue ) { type = newValue; }
454        bool get_isType() const { return isType; }
455        void set_isType( bool newValue ) { isType = newValue; }
456
[4a9ccc3]457        virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here
458
[0dd3a2f]459        virtual AttrType *clone() const { return new AttrType( *this ); }
460        virtual void accept( Visitor &v ) { v.visit( this ); }
461        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
462        virtual void print( std::ostream &os, int indent = 0 ) const;
[c8ffe20b]463  private:
[0dd3a2f]464        std::string name;
465        Expression *expr;
466        Type *type;
467        bool isType;
[51b7345]468};
469
[44b7088]470/// Represents the GCC built-in varargs type
471class VarArgsType : public Type {
[90c3b1c]472  public:
[44b7088]473        VarArgsType();
[c0aa336]474        VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[44b7088]475
[4a9ccc3]476        virtual bool isComplete() const{ return true; } // xxx - is this right?
477
[44b7088]478        virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
479        virtual void accept( Visitor &v ) { v.visit( this ); }
480        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
481        virtual void print( std::ostream &os, int indent = 0 ) const;
482};
483
[89e6ffc]484/// Represents a zero constant
485class ZeroType : public Type {
486  public:
487        ZeroType();
[c0aa336]488        ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]489
490        virtual ZeroType *clone() const { return new ZeroType( *this ); }
491        virtual void accept( Visitor &v ) { v.visit( this ); }
492        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
493        virtual void print( std::ostream &os, int indent = 0 ) const;
494};
495
496/// Represents a one constant
497class OneType : public Type {
498  public:
499        OneType();
[c0aa336]500        OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
[89e6ffc]501
502        virtual OneType *clone() const { return new OneType( *this ); }
503        virtual void accept( Visitor &v ) { v.visit( this ); }
504        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
505        virtual void print( std::ostream &os, int indent = 0 ) const;
506};
507
[aa8f9df]508inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) {
509        isConst &= other.isConst;
510        isVolatile &= other.isVolatile;
511        isRestrict &= other.isRestrict;
512        isLvalue &= other.isLvalue;
513        isAtomic &= other.isAtomic;
[c54b0b4]514        isMutex &= other.isMutex;
[aa8f9df]515        return *this;
516}
517
[c8ffe20b]518inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
[0dd3a2f]519        isConst |= other.isConst;
520        isVolatile |= other.isVolatile;
521        isRestrict |= other.isRestrict;
522        isLvalue |= other.isLvalue;
523        isAtomic |= other.isAtomic;
[c54b0b4]524        isMutex |= other.isMutex;
[0dd3a2f]525        return *this;
[51b7345]526}
527
[c8ffe20b]528inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
[0dd3a2f]529        if ( other.isConst ) isConst = 0;
530        if ( other.isVolatile ) isVolatile = 0;
531        if ( other.isRestrict ) isRestrict = 0;
532        if ( other.isAtomic ) isAtomic = 0;
[c54b0b4]533        if ( other.isMutex ) isMutex = 0;
[0dd3a2f]534        return *this;
[51b7345]535}
536
[c8ffe20b]537inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
[0dd3a2f]538        Qualifiers q = other;
539        q += *this;
540        return q;
[51b7345]541}
542
[c8ffe20b]543inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
[0dd3a2f]544        return isConst == other.isConst
545                && isVolatile == other.isVolatile
[f6835e5]546//              && isRestrict == other.isRestrict
547//              && isLvalue == other.isLvalue
[0dd3a2f]548                && isAtomic == other.isAtomic;
[51b7345]549}
550
[c8ffe20b]551inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
[0dd3a2f]552        return isConst != other.isConst
553                || isVolatile != other.isVolatile
[f6835e5]554//              || isRestrict != other.isRestrict
555//              || isLvalue != other.isLvalue
[0dd3a2f]556                || isAtomic != other.isAtomic;
[51b7345]557}
558
[c8ffe20b]559inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
[0dd3a2f]560        return isConst <= other.isConst
561                && isVolatile <= other.isVolatile
[f6835e5]562//              && isRestrict <= other.isRestrict
563//              && isLvalue >= other.isLvalue
[0dd3a2f]564                && isAtomic == other.isAtomic;
[51b7345]565}
566
[c8ffe20b]567inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
[0dd3a2f]568        return isConst >= other.isConst
569                && isVolatile >= other.isVolatile
[f6835e5]570//              && isRestrict >= other.isRestrict
571//              && isLvalue <= other.isLvalue
[0dd3a2f]572                && isAtomic == other.isAtomic;
[51b7345]573}
574
[c8ffe20b]575inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
[0dd3a2f]576        return operator!=( other ) && operator<=( other );
[51b7345]577}
578
[c8ffe20b]579inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
[0dd3a2f]580        return operator!=( other ) && operator>=( other );
[51b7345]581}
582
[3906301]583std::ostream & operator<<( std::ostream & out, const Type * type );
[baf7fee]584
[c8ffe20b]585#endif // TYPE_H
[0dd3a2f]586
587// Local Variables: //
588// tab-width: 4 //
589// mode: c++ //
590// compile-command: "make install" //
591// End: //
Note: See TracBrowser for help on using the repository browser.