source: src/SynTree/Type.h @ 294647b

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 294647b was c0aa336, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

third attempt at gcc attributes

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