Ignore:
Timestamp:
May 18, 2015, 11:20:23 AM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
51587aa
Parents:
a32b204
Message:

licencing: third groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/SynTree/Type.h

    ra32b204 r0dd3a2f  
     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 : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:01:40 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef TYPE_H
    217#define TYPE_H
     
    621#include "Mutator.h"
    722
    8 
    923class Type {
    1024  public:
    11     struct Qualifiers { 
    12       Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
    13       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 ) {}
    14        
    15         Qualifiers &operator+=( const Qualifiers &other );
    16         Qualifiers &operator-=( const Qualifiers &other );
    17         Qualifiers operator+( const Type::Qualifiers &other );
    18         bool operator==( const Qualifiers &other );
    19         bool operator!=( const Qualifiers &other );
    20         bool operator<=( const Qualifiers &other );
    21         bool operator>=( const Qualifiers &other );
    22         bool operator<( const Qualifiers &other );
    23         bool operator>( const Qualifiers &other );
    24        
    25         bool isConst;
    26         bool isVolatile;
    27         bool isRestrict;
    28         bool isLvalue;
    29         bool isAtomic;
    30         bool isAttribute;
    31     }; 
    32 
    33     Type( const Qualifiers &tq );
    34     Type( const Type &other );
    35     virtual ~Type();
    36 
    37     Qualifiers &get_qualifiers() { return tq; }
    38     bool get_isConst() { return tq.isConst; }
    39     bool get_isVolatile() { return tq.isVolatile; }
    40     bool get_isRestrict() { return tq.isRestrict; }
    41     bool get_isLvalue() { return tq.isLvalue; }
    42     bool get_isAtomic() { return tq.isAtomic; }
    43     bool get_isAttribute() { return tq.isAttribute; }
    44     void set_isConst( bool newValue ) { tq.isConst = newValue; }
    45     void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; }
    46     void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
    47     void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
    48     void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
    49     void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
    50     std::list<TypeDecl*>& get_forall() { return forall; }
    51 
    52     virtual Type *clone() const = 0;
    53     virtual void accept( Visitor &v ) = 0;
    54     virtual Type *acceptMutator( Mutator &m ) = 0;
    55     virtual void print( std::ostream &os, int indent = 0 ) const;
    56   private:
    57     Qualifiers tq;
    58     std::list<TypeDecl*> forall;
     25        struct Qualifiers { 
     26                Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
     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 ) {}
     28       
     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 );
     38       
     39                bool isConst;
     40                bool isVolatile;
     41                bool isRestrict;
     42                bool isLvalue;
     43                bool isAtomic;
     44                bool isAttribute;
     45        };     
     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; }
     59        void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; }
     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;
     70  private:
     71        Qualifiers tq;
     72        std::list<TypeDecl*> forall;
    5973};
    6074
    6175class VoidType : public Type {
    6276  public:
    63     VoidType( const Type::Qualifiers &tq );
    64 
    65     virtual VoidType *clone() const { return new VoidType( *this ); }
    66     virtual void accept( Visitor &v ) { v.visit( this ); }
    67     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    68     virtual void print( std::ostream &os, int indent = 0 ) const;
     77        VoidType( const Type::Qualifiers &tq );
     78
     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;
    6983};
    7084
    7185class BasicType : public Type {
    7286  public:
    73     enum Kind { 
    74         Bool,
    75         Char,
    76         SignedChar,
    77         UnsignedChar,
    78         ShortSignedInt,
    79         ShortUnsignedInt,
    80         SignedInt,
    81         UnsignedInt,
    82         LongSignedInt,
    83         LongUnsignedInt,
    84         LongLongSignedInt,
    85         LongLongUnsignedInt,
    86         Float,
    87         Double,
    88         LongDouble,
    89         FloatComplex,
    90         DoubleComplex,
    91         LongDoubleComplex,
    92         FloatImaginary,
    93         DoubleImaginary,
    94         LongDoubleImaginary,
    95         NUMBER_OF_BASIC_TYPES
    96     }; 
    97 
    98     static const char *typeNames[];                     // string names for basic types, MUST MATCH with Kind
    99 
    100     BasicType( const Type::Qualifiers &tq, Kind bt );
    101 
    102     Kind get_kind() { return kind; }
    103     void set_kind( Kind newValue ) { kind = newValue; }
    104 
    105     virtual BasicType *clone() const { return new BasicType( *this ); }
    106     virtual void accept( Visitor &v ) { v.visit( this ); }
    107     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    108     virtual void print( std::ostream &os, int indent = 0 ) const;
    109 
    110     bool isInteger() const;
    111   private:
    112     Kind kind;
     87        enum Kind { 
     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
     110        }; 
     111
     112        static const char *typeNames[];                 // string names for basic types, MUST MATCH with Kind
     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;
     125  private:
     126        Kind kind;
    113127};
    114128
    115129class PointerType : public Type {
    116130  public:
    117     PointerType( const Type::Qualifiers &tq, Type *base );
    118     PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    119     PointerType( const PointerType& );
    120     virtual ~PointerType();
    121 
    122     Type *get_base() { return base; }
    123     void set_base( Type *newValue ) { base = newValue; }
    124     Expression *get_dimension() { return dimension; }
    125     void set_dimension( Expression *newValue ) { dimension = newValue; }
    126     bool get_isVarLen() { return isVarLen; }
    127     void set_isVarLen( bool newValue ) { isVarLen = newValue; }
    128     bool get_isStatic() { return isStatic; }
    129     void set_isStatic( bool newValue ) { isStatic = newValue; }
    130 
    131     virtual PointerType *clone() const { return new PointerType( *this ); }
    132     virtual void accept( Visitor &v ) { v.visit( this ); }
    133     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    134     virtual void print( std::ostream &os, int indent = 0 ) const;
    135   private:
    136     Type *base;
    137    
    138     // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
    139     Expression *dimension;
    140     bool isVarLen;
    141     bool isStatic;
     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;
     149  private:
     150        Type *base;
     151       
     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;
    142156};
    143157
    144158class ArrayType : public Type {
    145159  public:
    146     ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    147     ArrayType( const ArrayType& );
    148     virtual ~ArrayType();
    149 
    150     Type *get_base() { return base; }
    151     void set_base( Type *newValue ) { base = newValue; }
    152     Expression *get_dimension() { return dimension; }
    153     void set_dimension( Expression *newValue ) { dimension = newValue; }
    154     bool get_isVarLen() { return isVarLen; }
    155     void set_isVarLen( bool newValue ) { isVarLen = newValue; }
    156     bool get_isStatic() { return isStatic; }
    157     void set_isStatic( bool newValue ) { isStatic = newValue; }
    158 
    159     virtual ArrayType *clone() const { return new ArrayType( *this ); }
    160     virtual void accept( Visitor &v ) { v.visit( this ); }
    161     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    162     virtual void print( std::ostream &os, int indent = 0 ) const;
    163   private:
    164     Type *base;
    165     Expression *dimension;
    166     bool isVarLen;
    167     bool isStatic;
     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;
     177  private:
     178        Type *base;
     179        Expression *dimension;
     180        bool isVarLen;
     181        bool isStatic;
    168182};
    169183
    170184class FunctionType : public Type {
    171185  public:
    172     FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
    173     FunctionType( const FunctionType& );
    174     virtual ~FunctionType();
    175 
    176     std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
    177     std::list<DeclarationWithType*>& get_parameters() { return parameters; }
    178     bool get_isVarArgs() { return isVarArgs; }
    179     void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
    180 
    181     virtual FunctionType *clone() const { return new FunctionType( *this ); }
    182     virtual void accept( Visitor &v ) { v.visit( this ); }
    183     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    184     virtual void print( std::ostream &os, int indent = 0 ) const;
    185   private:
    186     std::list<DeclarationWithType*> returnVals;
    187     std::list<DeclarationWithType*> parameters;
    188 
    189     // does the function accept a variable number of arguments following the arguments
    190     // specified in the parameters list.    This could be because of
    191     // - an ellipsis in a prototype declaration
    192     // - an unprototyped declaration
    193     bool isVarArgs;
     186        FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
     187        FunctionType( const FunctionType& );
     188        virtual ~FunctionType();
     189
     190        std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
     191        std::list<DeclarationWithType*>& get_parameters() { return parameters; }
     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;
     199  private:
     200        std::list<DeclarationWithType*> returnVals;
     201        std::list<DeclarationWithType*> parameters;
     202
     203        // does the function accept a variable number of arguments following the arguments
     204        // specified in the parameters list.    This could be because of
     205        // - an ellipsis in a prototype declaration
     206        // - an unprototyped declaration
     207        bool isVarArgs;
    194208};
    195209
    196210class ReferenceToType : public Type {
    197211  public:
    198     ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
    199     ReferenceToType( const ReferenceToType &other );
    200     virtual ~ReferenceToType();
    201 
    202     std::string get_name() const { return name; }
    203     void set_name( std::string newValue ) { name = newValue; }
    204     std::list< Expression* >& get_parameters() { return parameters; }
    205    
    206     virtual ReferenceToType *clone() const = 0;
    207     virtual void accept( Visitor &v ) = 0;
    208     virtual Type *acceptMutator( Mutator &m ) = 0;
    209     virtual void print( std::ostream &os, int indent = 0 ) const;
     212        ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
     213        ReferenceToType( const ReferenceToType &other );
     214        virtual ~ReferenceToType();
     215
     216        std::string get_name() const { return name; }
     217        void set_name( std::string newValue ) { name = newValue; }
     218        std::list< Expression* >& get_parameters() { return parameters; }
     219       
     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;
    210224  protected:
    211     virtual std::string typeString() const = 0;
    212     std::list< Expression* > parameters;
    213   private:
    214     std::string name;
     225        virtual std::string typeString() const = 0;
     226        std::list< Expression* > parameters;
     227  private:
     228        std::string name;
    215229};
    216230
    217231class StructInstType : public ReferenceToType {
    218     typedef ReferenceToType Parent;
    219   public:
    220     StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
    221     StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
    222 
    223     StructDecl *get_baseStruct() const { return baseStruct; }
    224     void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
    225    
    226     // a utility function
    227     void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
    228 
    229     virtual StructInstType *clone() const { return new StructInstType( *this ); }
    230     virtual void accept( Visitor &v ) { v.visit( this ); }
    231     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    232 
    233   private:
    234     virtual std::string typeString() const;
    235    
    236     // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
    237     // where the structure used in this type is actually defined
    238     StructDecl *baseStruct;
     232        typedef ReferenceToType Parent;
     233  public:
     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 ) {}
     236
     237        StructDecl *get_baseStruct() const { return baseStruct; }
     238        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
     239       
     240        // a utility function
     241        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
     242
     243        virtual StructInstType *clone() const { return new StructInstType( *this ); }
     244        virtual void accept( Visitor &v ) { v.visit( this ); }
     245        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     246  private:
     247        virtual std::string typeString() const;
     248       
     249        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
     250        // where the structure used in this type is actually defined
     251        StructDecl *baseStruct;
    239252};
    240253
    241254class UnionInstType : public ReferenceToType {
    242     typedef ReferenceToType Parent;
    243   public:
    244     UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
    245     UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
    246 
    247     UnionDecl *get_baseUnion() const { return baseUnion; }
    248     void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
    249    
    250     // a utility function
    251     void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
    252 
    253     virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
    254     virtual void accept( Visitor &v ) { v.visit( this ); }
    255     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    256   private:
    257     virtual std::string typeString() const;
    258    
    259     // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    260     // where the union used in this type is actually defined
    261     UnionDecl *baseUnion;
     255        typedef ReferenceToType Parent;
     256  public:
     257        UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
     258        UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
     259
     260        UnionDecl *get_baseUnion() const { return baseUnion; }
     261        void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
     262       
     263        // a utility function
     264        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
     265
     266        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
     267        virtual void accept( Visitor &v ) { v.visit( this ); }
     268        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     269  private:
     270        virtual std::string typeString() const;
     271       
     272        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
     273        // where the union used in this type is actually defined
     274        UnionDecl *baseUnion;
    262275};
    263276
    264277class EnumInstType : public ReferenceToType {
    265     typedef ReferenceToType Parent;
    266   public:
    267     EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
    268     EnumInstType( const EnumInstType &other ) : Parent( other ) {}
    269 
    270     virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
    271     virtual void accept( Visitor &v ) { v.visit( this ); }
    272     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    273 
    274   private:
    275     virtual std::string typeString() const;
     278        typedef ReferenceToType Parent;
     279  public:
     280        EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     281        EnumInstType( const EnumInstType &other ) : Parent( other ) {}
     282
     283        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
     284        virtual void accept( Visitor &v ) { v.visit( this ); }
     285        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     286  private:
     287        virtual std::string typeString() const;
    276288};
    277289
    278290class ContextInstType : public ReferenceToType {
    279     typedef ReferenceToType Parent;
    280   public:
    281     ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
    282     ContextInstType( const ContextInstType &other );
    283     ~ContextInstType();
    284 
    285     std::list< Declaration* >& get_members() { return members; }
    286 
    287     virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
    288     virtual void accept( Visitor &v ) { v.visit( this ); }
    289     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    290   private:
    291     virtual std::string typeString() const;
    292    
    293     // this member is filled in by the validate pass, which instantiates the members of the correponding
    294     // aggregate with the actual type parameters specified for this use of the context
    295     std::list< Declaration* > members;
     291        typedef ReferenceToType Parent;
     292  public:
     293        ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     294        ContextInstType( const ContextInstType &other );
     295        ~ContextInstType();
     296
     297        std::list< Declaration* >& get_members() { return members; }
     298
     299        virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
     300        virtual void accept( Visitor &v ) { v.visit( this ); }
     301        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     302  private:
     303        virtual std::string typeString() const;
     304       
     305        // this member is filled in by the validate pass, which instantiates the members of the correponding
     306        // aggregate with the actual type parameters specified for this use of the context
     307        std::list< Declaration* > members;
    296308};
    297309
    298310class TypeInstType : public ReferenceToType {
    299     typedef ReferenceToType Parent;
    300   public:
    301     TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
    302     TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
    303     TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
    304 
    305     TypeDecl *get_baseType() const { return baseType; }
    306     void set_baseType( TypeDecl *newValue );
    307     bool get_isFtype() const { return isFtype; }
    308     void set_isFtype( bool newValue ) { isFtype = newValue; }
    309    
    310     virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
    311     virtual void accept( Visitor &v ) { v.visit( this ); }
    312     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    313     virtual void print( std::ostream &os, int indent = 0 ) const;
    314   private:
    315     virtual std::string typeString() const;
    316     // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
    317     // where the type used here is actually defined
    318     TypeDecl *baseType;
    319     bool isFtype;
     311        typedef ReferenceToType Parent;
     312  public:
     313        TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
     314        TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
     315        TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
     316
     317        TypeDecl *get_baseType() const { return baseType; }
     318        void set_baseType( TypeDecl *newValue );
     319        bool get_isFtype() const { return isFtype; }
     320        void set_isFtype( bool newValue ) { isFtype = newValue; }
     321       
     322        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
     323        virtual void accept( Visitor &v ) { v.visit( this ); }
     324        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     325        virtual void print( std::ostream &os, int indent = 0 ) const;
     326  private:
     327        virtual std::string typeString() const;
     328        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
     329        // where the type used here is actually defined
     330        TypeDecl *baseType;
     331        bool isFtype;
    320332};
    321333
    322334class TupleType : public Type {
    323335  public:
    324     TupleType( const Type::Qualifiers &tq );
    325     TupleType( const TupleType& );
    326     virtual ~TupleType();
    327 
    328     std::list<Type*>& get_types() { return types; }
    329 
    330     virtual TupleType *clone() const { return new TupleType( *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;
    334   private:
    335     std::list<Type*> types;
     336        TupleType( const Type::Qualifiers &tq );
     337        TupleType( const TupleType& );
     338        virtual ~TupleType();
     339
     340        std::list<Type*>& get_types() { return types; }
     341
     342        virtual TupleType *clone() const { return new TupleType( *this ); }
     343        virtual void accept( Visitor &v ) { v.visit( this ); }
     344        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     345        virtual void print( std::ostream &os, int indent = 0 ) const;
     346  private:
     347        std::list<Type*> types;
    336348};
    337349
    338350class TypeofType : public Type {
    339351  public:
    340     TypeofType( const Type::Qualifiers &tq, Expression *expr );
    341     TypeofType( const TypeofType& );
    342     virtual ~TypeofType();
    343 
    344     Expression *get_expr() const { return expr; }
    345     void set_expr( Expression *newValue ) { expr = newValue; }
    346 
    347     virtual TypeofType *clone() const { return new TypeofType( *this ); }
    348     virtual void accept( Visitor &v ) { v.visit( this ); }
    349     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    350     virtual void print( std::ostream &os, int indent = 0 ) const;
    351   private:
    352     Expression *expr;
     352        TypeofType( const Type::Qualifiers &tq, Expression *expr );
     353        TypeofType( const TypeofType& );
     354        virtual ~TypeofType();
     355
     356        Expression *get_expr() const { return expr; }
     357        void set_expr( Expression *newValue ) { expr = newValue; }
     358
     359        virtual TypeofType *clone() const { return new TypeofType( *this ); }
     360        virtual void accept( Visitor &v ) { v.visit( this ); }
     361        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     362        virtual void print( std::ostream &os, int indent = 0 ) const;
     363  private:
     364        Expression *expr;
    353365};
    354366
    355367class AttrType : public Type {
    356368  public:
    357     AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
    358     AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
    359     AttrType( const AttrType& );
    360     virtual ~AttrType();
    361 
    362     std::string get_name() const { return name; }
    363     void set_name( const std::string &newValue ) { name = newValue; }
    364     Expression *get_expr() const { return expr; }
    365     void set_expr( Expression *newValue ) { expr = newValue; }
    366     Type *get_type() const { return type; }
    367     void set_type( Type *newValue ) { type = newValue; }
    368     bool get_isType() const { return isType; }
    369     void set_isType( bool newValue ) { isType = newValue; }
    370 
    371     virtual AttrType *clone() const { return new AttrType( *this ); }
    372     virtual void accept( Visitor &v ) { v.visit( this ); }
    373     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    374     virtual void print( std::ostream &os, int indent = 0 ) const;
    375 
    376   private:
    377     std::string name;
    378     Expression *expr;
    379     Type *type;
    380     bool isType;
     369        AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
     370        AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
     371        AttrType( const AttrType& );
     372        virtual ~AttrType();
     373
     374        std::string get_name() const { return name; }
     375        void set_name( const std::string &newValue ) { name = newValue; }
     376        Expression *get_expr() const { return expr; }
     377        void set_expr( Expression *newValue ) { expr = newValue; }
     378        Type *get_type() const { return type; }
     379        void set_type( Type *newValue ) { type = newValue; }
     380        bool get_isType() const { return isType; }
     381        void set_isType( bool newValue ) { isType = newValue; }
     382
     383        virtual AttrType *clone() const { return new AttrType( *this ); }
     384        virtual void accept( Visitor &v ) { v.visit( this ); }
     385        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     386        virtual void print( std::ostream &os, int indent = 0 ) const;
     387  private:
     388        std::string name;
     389        Expression *expr;
     390        Type *type;
     391        bool isType;
    381392};
    382393
    383394inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    384     isConst |= other.isConst;
    385     isVolatile |= other.isVolatile;
    386     isRestrict |= other.isRestrict;
    387     isLvalue |= other.isLvalue;
    388     isAtomic |= other.isAtomic;
    389     return *this;
     395        isConst |= other.isConst;
     396        isVolatile |= other.isVolatile;
     397        isRestrict |= other.isRestrict;
     398        isLvalue |= other.isLvalue;
     399        isAtomic |= other.isAtomic;
     400        return *this;
    390401}
    391402
    392403inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
    393     if ( other.isConst ) isConst = 0;
    394     if ( other.isVolatile ) isVolatile = 0;
    395     if ( other.isRestrict ) isRestrict = 0;
    396     if ( other.isAtomic ) isAtomic = 0;
    397     return *this;
     404        if ( other.isConst ) isConst = 0;
     405        if ( other.isVolatile ) isVolatile = 0;
     406        if ( other.isRestrict ) isRestrict = 0;
     407        if ( other.isAtomic ) isAtomic = 0;
     408        return *this;
    398409}
    399410
    400411inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
    401     Qualifiers q = other;
    402     q += *this;
    403     return q;
     412        Qualifiers q = other;
     413        q += *this;
     414        return q;
    404415}
    405416
    406417inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
    407     return isConst == other.isConst
    408         && isVolatile == other.isVolatile
    409         && isRestrict == other.isRestrict
     418        return isConst == other.isConst
     419                && isVolatile == other.isVolatile
     420                && isRestrict == other.isRestrict
    410421//      && isLvalue == other.isLvalue
    411         && isAtomic == other.isAtomic;
     422                && isAtomic == other.isAtomic;
    412423}
    413424
    414425inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
    415     return isConst != other.isConst
    416         || isVolatile != other.isVolatile
    417         || isRestrict != other.isRestrict
     426        return isConst != other.isConst
     427                || isVolatile != other.isVolatile
     428                || isRestrict != other.isRestrict
    418429//      || isLvalue != other.isLvalue
    419         || isAtomic != other.isAtomic;
     430                || isAtomic != other.isAtomic;
    420431}
    421432
    422433inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
    423     return isConst <= other.isConst
    424         && isVolatile <= other.isVolatile
    425         && isRestrict <= other.isRestrict
     434        return isConst <= other.isConst
     435                && isVolatile <= other.isVolatile
     436                && isRestrict <= other.isRestrict
    426437//      && isLvalue >= other.isLvalue
    427         && isAtomic == other.isAtomic;
     438                && isAtomic == other.isAtomic;
    428439}
    429440
    430441inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
    431     return isConst >= other.isConst
    432         && isVolatile >= other.isVolatile
    433         && isRestrict >= other.isRestrict
     442        return isConst >= other.isConst
     443                && isVolatile >= other.isVolatile
     444                && isRestrict >= other.isRestrict
    434445//      && isLvalue <= other.isLvalue
    435         && isAtomic == other.isAtomic;
     446                && isAtomic == other.isAtomic;
    436447}
    437448
    438449inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
    439     return operator!=( other ) && operator<=( other );
     450        return operator!=( other ) && operator<=( other );
    440451}
    441452
    442453inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
    443     return operator!=( other ) && operator>=( other );
     454        return operator!=( other ) && operator>=( other );
    444455}
    445456
    446457#endif // TYPE_H
     458
     459// Local Variables: //
     460// tab-width: 4 //
     461// mode: c++ //
     462// compile-command: "make install" //
     463// End: //
Note: See TracChangeset for help on using the changeset viewer.