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