[0dd3a2f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[ae63a18] | 7 | // Type.h -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[90c3b1c] | 11 | // Last Modified By : Peter A. Buhr |
---|
[dd020c0] | 12 | // Last Modified On : Wed Mar 1 09:11:45 2017 |
---|
| 13 | // Update Count : 41 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #ifndef TYPE_H |
---|
| 17 | #define TYPE_H |
---|
| 18 | |
---|
[138e29e] | 19 | #include "BaseSyntaxNode.h" |
---|
| 20 | #include "Mutator.h" |
---|
[51b7345] | 21 | #include "SynTree.h" |
---|
| 22 | #include "Visitor.h" |
---|
| 23 | |
---|
[138e29e] | 24 | class Type : public BaseSyntaxNode { |
---|
[c8ffe20b] | 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] | 88 | extern Type::Qualifiers emptyQualifiers; // no qualifiers on constants |
---|
| 89 | |
---|
[c8ffe20b] | 90 | class 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] | 103 | class 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] | 147 | class 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] | 176 | class 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] | 204 | class 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; } |
---|
[8bf784a] | 214 | bool isTtype() const; |
---|
| 215 | |
---|
[0dd3a2f] | 216 | virtual FunctionType *clone() const { return new FunctionType( *this ); } |
---|
| 217 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 218 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 219 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 220 | private: |
---|
[0dd3a2f] | 221 | std::list<DeclarationWithType*> returnVals; |
---|
| 222 | std::list<DeclarationWithType*> parameters; |
---|
| 223 | |
---|
[839ccbb] | 224 | // Does the function accept a variable number of arguments following the arguments specified in the parameters list. |
---|
| 225 | // This could be because of |
---|
[0dd3a2f] | 226 | // - an ellipsis in a prototype declaration |
---|
| 227 | // - an unprototyped declaration |
---|
| 228 | bool isVarArgs; |
---|
[51b7345] | 229 | }; |
---|
| 230 | |
---|
[c8ffe20b] | 231 | class ReferenceToType : public Type { |
---|
| 232 | public: |
---|
[c0aa336] | 233 | ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ); |
---|
[0dd3a2f] | 234 | ReferenceToType( const ReferenceToType &other ); |
---|
| 235 | virtual ~ReferenceToType(); |
---|
| 236 | |
---|
[5f2f2d7] | 237 | const std::string &get_name() const { return name; } |
---|
[0dd3a2f] | 238 | void set_name( std::string newValue ) { name = newValue; } |
---|
| 239 | std::list< Expression* >& get_parameters() { return parameters; } |
---|
[43c89a7] | 240 | bool get_hoistType() const { return hoistType; } |
---|
| 241 | void set_hoistType( bool newValue ) { hoistType = newValue; } |
---|
[ae63a18] | 242 | |
---|
[0dd3a2f] | 243 | virtual ReferenceToType *clone() const = 0; |
---|
| 244 | virtual void accept( Visitor &v ) = 0; |
---|
| 245 | virtual Type *acceptMutator( Mutator &m ) = 0; |
---|
| 246 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 247 | protected: |
---|
[0dd3a2f] | 248 | virtual std::string typeString() const = 0; |
---|
| 249 | std::list< Expression* > parameters; |
---|
| 250 | std::string name; |
---|
[5d125e4] | 251 | private: |
---|
[43c89a7] | 252 | bool hoistType; |
---|
[51b7345] | 253 | }; |
---|
| 254 | |
---|
[c8ffe20b] | 255 | class StructInstType : public ReferenceToType { |
---|
[0dd3a2f] | 256 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 257 | public: |
---|
[c0aa336] | 258 | StructInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {} |
---|
| 259 | StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 260 | StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} |
---|
[51b7345] | 261 | |
---|
[0dd3a2f] | 262 | StructDecl *get_baseStruct() const { return baseStruct; } |
---|
| 263 | void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } |
---|
[37a3b8f9] | 264 | |
---|
[ed94eac] | 265 | /// Accesses generic parameters of base struct (NULL if none such) |
---|
[839ccbb] | 266 | std::list<TypeDecl*> * get_baseParameters(); |
---|
[ae63a18] | 267 | |
---|
[4a9ccc3] | 268 | virtual bool isComplete() const; |
---|
| 269 | |
---|
[37a3b8f9] | 270 | /// Looks up the members of this struct named "name" and places them into "foundDecls". |
---|
| 271 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[0dd3a2f] | 272 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; |
---|
[51b7345] | 273 | |
---|
[0dd3a2f] | 274 | virtual StructInstType *clone() const { return new StructInstType( *this ); } |
---|
| 275 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 276 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[5d125e4] | 277 | |
---|
| 278 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 279 | private: |
---|
[0dd3a2f] | 280 | virtual std::string typeString() const; |
---|
[ae63a18] | 281 | |
---|
[0dd3a2f] | 282 | // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, |
---|
| 283 | // where the structure used in this type is actually defined |
---|
| 284 | StructDecl *baseStruct; |
---|
[51b7345] | 285 | }; |
---|
| 286 | |
---|
[c8ffe20b] | 287 | class UnionInstType : public ReferenceToType { |
---|
[0dd3a2f] | 288 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 289 | public: |
---|
[c0aa336] | 290 | UnionInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {} |
---|
| 291 | UnionInstType( const Type::Qualifiers &tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 292 | UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {} |
---|
| 293 | |
---|
| 294 | UnionDecl *get_baseUnion() const { return baseUnion; } |
---|
[c0aa336] | 295 | void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; } |
---|
[37a3b8f9] | 296 | |
---|
[ed94eac] | 297 | /// Accesses generic parameters of base union (NULL if none such) |
---|
[c0aa336] | 298 | std::list< TypeDecl * > * get_baseParameters(); |
---|
[ae63a18] | 299 | |
---|
[4a9ccc3] | 300 | virtual bool isComplete() const; |
---|
| 301 | |
---|
[37a3b8f9] | 302 | /// looks up the members of this union named "name" and places them into "foundDecls" |
---|
| 303 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[0dd3a2f] | 304 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; |
---|
| 305 | |
---|
| 306 | virtual UnionInstType *clone() const { return new UnionInstType( *this ); } |
---|
| 307 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 308 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[5d125e4] | 309 | |
---|
| 310 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 311 | private: |
---|
[0dd3a2f] | 312 | virtual std::string typeString() const; |
---|
[ae63a18] | 313 | |
---|
[0dd3a2f] | 314 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
| 315 | // where the union used in this type is actually defined |
---|
| 316 | UnionDecl *baseUnion; |
---|
[51b7345] | 317 | }; |
---|
| 318 | |
---|
[c8ffe20b] | 319 | class EnumInstType : public ReferenceToType { |
---|
[0dd3a2f] | 320 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 321 | public: |
---|
[c0aa336] | 322 | EnumInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
| 323 | EnumInstType( const Type::Qualifiers &tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 324 | EnumInstType( const EnumInstType &other ) : Parent( other ), baseEnum( other.baseEnum ) {} |
---|
[51b7345] | 325 | |
---|
[c0aa336] | 326 | EnumDecl *get_baseEnum() const { return baseEnum; } |
---|
| 327 | void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; } |
---|
| 328 | |
---|
| 329 | virtual bool isComplete() const; |
---|
[4a9ccc3] | 330 | |
---|
[0dd3a2f] | 331 | virtual EnumInstType *clone() const { return new EnumInstType( *this ); } |
---|
| 332 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 333 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 334 | private: |
---|
[0dd3a2f] | 335 | virtual std::string typeString() const; |
---|
[c0aa336] | 336 | |
---|
| 337 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
| 338 | // where the union used in this type is actually defined |
---|
| 339 | EnumDecl *baseEnum = nullptr; |
---|
[51b7345] | 340 | }; |
---|
| 341 | |
---|
[4040425] | 342 | class TraitInstType : public ReferenceToType { |
---|
[0dd3a2f] | 343 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 344 | public: |
---|
[c0aa336] | 345 | TraitInstType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
[4040425] | 346 | TraitInstType( const TraitInstType &other ); |
---|
| 347 | ~TraitInstType(); |
---|
[51b7345] | 348 | |
---|
[0dd3a2f] | 349 | std::list< Declaration* >& get_members() { return members; } |
---|
[51b7345] | 350 | |
---|
[4a9ccc3] | 351 | virtual bool isComplete() const; |
---|
| 352 | |
---|
[4040425] | 353 | virtual TraitInstType *clone() const { return new TraitInstType( *this ); } |
---|
[0dd3a2f] | 354 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 355 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 356 | private: |
---|
[0dd3a2f] | 357 | virtual std::string typeString() const; |
---|
[ae63a18] | 358 | |
---|
[0dd3a2f] | 359 | // this member is filled in by the validate pass, which instantiates the members of the correponding |
---|
| 360 | // aggregate with the actual type parameters specified for this use of the context |
---|
| 361 | std::list< Declaration* > members; |
---|
[51b7345] | 362 | }; |
---|
| 363 | |
---|
[c8ffe20b] | 364 | class TypeInstType : public ReferenceToType { |
---|
[0dd3a2f] | 365 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 366 | public: |
---|
[c0aa336] | 367 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 368 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[2c57025] | 369 | TypeInstType( const TypeInstType &other ); |
---|
[1e8b02f5] | 370 | ~TypeInstType(); |
---|
[0dd3a2f] | 371 | |
---|
| 372 | TypeDecl *get_baseType() const { return baseType; } |
---|
| 373 | void set_baseType( TypeDecl *newValue ); |
---|
| 374 | bool get_isFtype() const { return isFtype; } |
---|
| 375 | void set_isFtype( bool newValue ) { isFtype = newValue; } |
---|
[ae63a18] | 376 | |
---|
[4a9ccc3] | 377 | virtual bool isComplete() const; |
---|
| 378 | |
---|
[0dd3a2f] | 379 | virtual TypeInstType *clone() const { return new TypeInstType( *this ); } |
---|
| 380 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 381 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 382 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 383 | private: |
---|
[0dd3a2f] | 384 | virtual std::string typeString() const; |
---|
| 385 | // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, |
---|
| 386 | // where the type used here is actually defined |
---|
| 387 | TypeDecl *baseType; |
---|
| 388 | bool isFtype; |
---|
[51b7345] | 389 | }; |
---|
| 390 | |
---|
[c8ffe20b] | 391 | class TupleType : public Type { |
---|
| 392 | public: |
---|
[c0aa336] | 393 | TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >(), const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 394 | TupleType( const TupleType& ); |
---|
| 395 | virtual ~TupleType(); |
---|
[51b7345] | 396 | |
---|
[0362d42] | 397 | typedef std::list<Type*> value_type; |
---|
| 398 | typedef value_type::iterator iterator; |
---|
| 399 | |
---|
[0dd3a2f] | 400 | std::list<Type*>& get_types() { return types; } |
---|
[906e24d] | 401 | virtual unsigned size() const { return types.size(); }; |
---|
[51b7345] | 402 | |
---|
[0362d42] | 403 | iterator begin() { return types.begin(); } |
---|
| 404 | iterator end() { return types.end(); } |
---|
| 405 | |
---|
[7933351] | 406 | virtual Type * getComponent( unsigned i ) { |
---|
| 407 | assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() ); |
---|
| 408 | return *(begin()+i); |
---|
| 409 | } |
---|
| 410 | |
---|
[4a9ccc3] | 411 | // virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness |
---|
| 412 | |
---|
[0dd3a2f] | 413 | virtual TupleType *clone() const { return new TupleType( *this ); } |
---|
| 414 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 415 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 416 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 417 | private: |
---|
[0dd3a2f] | 418 | std::list<Type*> types; |
---|
[51b7345] | 419 | }; |
---|
| 420 | |
---|
[c8ffe20b] | 421 | class TypeofType : public Type { |
---|
| 422 | public: |
---|
[c0aa336] | 423 | TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 424 | TypeofType( const TypeofType& ); |
---|
| 425 | virtual ~TypeofType(); |
---|
[51b7345] | 426 | |
---|
[0dd3a2f] | 427 | Expression *get_expr() const { return expr; } |
---|
| 428 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
[51b7345] | 429 | |
---|
[4a9ccc3] | 430 | virtual bool isComplete() const { assert( false ); return false; } |
---|
| 431 | |
---|
[0dd3a2f] | 432 | virtual TypeofType *clone() const { return new TypeofType( *this ); } |
---|
| 433 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 434 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 435 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 436 | private: |
---|
[0dd3a2f] | 437 | Expression *expr; |
---|
[51b7345] | 438 | }; |
---|
| 439 | |
---|
[c8ffe20b] | 440 | class AttrType : public Type { |
---|
| 441 | public: |
---|
[c0aa336] | 442 | AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 443 | AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 444 | AttrType( const AttrType& ); |
---|
| 445 | virtual ~AttrType(); |
---|
| 446 | |
---|
[5f2f2d7] | 447 | const std::string &get_name() const { return name; } |
---|
[0dd3a2f] | 448 | void set_name( const std::string &newValue ) { name = newValue; } |
---|
| 449 | Expression *get_expr() const { return expr; } |
---|
| 450 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
| 451 | Type *get_type() const { return type; } |
---|
| 452 | void set_type( Type *newValue ) { type = newValue; } |
---|
| 453 | bool get_isType() const { return isType; } |
---|
| 454 | void set_isType( bool newValue ) { isType = newValue; } |
---|
| 455 | |
---|
[4a9ccc3] | 456 | virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here |
---|
| 457 | |
---|
[0dd3a2f] | 458 | virtual AttrType *clone() const { return new AttrType( *this ); } |
---|
| 459 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 460 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 461 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 462 | private: |
---|
[0dd3a2f] | 463 | std::string name; |
---|
| 464 | Expression *expr; |
---|
| 465 | Type *type; |
---|
| 466 | bool isType; |
---|
[51b7345] | 467 | }; |
---|
| 468 | |
---|
[44b7088] | 469 | /// Represents the GCC built-in varargs type |
---|
| 470 | class VarArgsType : public Type { |
---|
[90c3b1c] | 471 | public: |
---|
[44b7088] | 472 | VarArgsType(); |
---|
[c0aa336] | 473 | VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[44b7088] | 474 | |
---|
[4a9ccc3] | 475 | virtual bool isComplete() const{ return true; } // xxx - is this right? |
---|
| 476 | |
---|
[44b7088] | 477 | virtual VarArgsType *clone() const { return new VarArgsType( *this ); } |
---|
| 478 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 479 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 480 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 481 | }; |
---|
| 482 | |
---|
[89e6ffc] | 483 | /// Represents a zero constant |
---|
| 484 | class ZeroType : public Type { |
---|
| 485 | public: |
---|
| 486 | ZeroType(); |
---|
[c0aa336] | 487 | ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[89e6ffc] | 488 | |
---|
| 489 | virtual ZeroType *clone() const { return new ZeroType( *this ); } |
---|
| 490 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 491 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 492 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 493 | }; |
---|
| 494 | |
---|
| 495 | /// Represents a one constant |
---|
| 496 | class OneType : public Type { |
---|
| 497 | public: |
---|
| 498 | OneType(); |
---|
[c0aa336] | 499 | OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[89e6ffc] | 500 | |
---|
| 501 | virtual OneType *clone() const { return new OneType( *this ); } |
---|
| 502 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 503 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 504 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 505 | }; |
---|
| 506 | |
---|
[aa8f9df] | 507 | inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) { |
---|
| 508 | isConst &= other.isConst; |
---|
| 509 | isVolatile &= other.isVolatile; |
---|
| 510 | isRestrict &= other.isRestrict; |
---|
| 511 | isLvalue &= other.isLvalue; |
---|
| 512 | isAtomic &= other.isAtomic; |
---|
| 513 | return *this; |
---|
| 514 | } |
---|
| 515 | |
---|
[c8ffe20b] | 516 | inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 517 | isConst |= other.isConst; |
---|
| 518 | isVolatile |= other.isVolatile; |
---|
| 519 | isRestrict |= other.isRestrict; |
---|
| 520 | isLvalue |= other.isLvalue; |
---|
| 521 | isAtomic |= other.isAtomic; |
---|
| 522 | return *this; |
---|
[51b7345] | 523 | } |
---|
| 524 | |
---|
[c8ffe20b] | 525 | inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 526 | if ( other.isConst ) isConst = 0; |
---|
| 527 | if ( other.isVolatile ) isVolatile = 0; |
---|
| 528 | if ( other.isRestrict ) isRestrict = 0; |
---|
| 529 | if ( other.isAtomic ) isAtomic = 0; |
---|
| 530 | return *this; |
---|
[51b7345] | 531 | } |
---|
| 532 | |
---|
[c8ffe20b] | 533 | inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 534 | Qualifiers q = other; |
---|
| 535 | q += *this; |
---|
| 536 | return q; |
---|
[51b7345] | 537 | } |
---|
| 538 | |
---|
[c8ffe20b] | 539 | inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { |
---|
[0dd3a2f] | 540 | return isConst == other.isConst |
---|
| 541 | && isVolatile == other.isVolatile |
---|
[f6835e5] | 542 | // && isRestrict == other.isRestrict |
---|
| 543 | // && isLvalue == other.isLvalue |
---|
[0dd3a2f] | 544 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 545 | } |
---|
| 546 | |
---|
[c8ffe20b] | 547 | inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) { |
---|
[0dd3a2f] | 548 | return isConst != other.isConst |
---|
| 549 | || isVolatile != other.isVolatile |
---|
[f6835e5] | 550 | // || isRestrict != other.isRestrict |
---|
| 551 | // || isLvalue != other.isLvalue |
---|
[0dd3a2f] | 552 | || isAtomic != other.isAtomic; |
---|
[51b7345] | 553 | } |
---|
| 554 | |
---|
[c8ffe20b] | 555 | inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 556 | return isConst <= other.isConst |
---|
| 557 | && isVolatile <= other.isVolatile |
---|
[f6835e5] | 558 | // && isRestrict <= other.isRestrict |
---|
| 559 | // && isLvalue >= other.isLvalue |
---|
[0dd3a2f] | 560 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 561 | } |
---|
| 562 | |
---|
[c8ffe20b] | 563 | inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 564 | return isConst >= other.isConst |
---|
| 565 | && isVolatile >= other.isVolatile |
---|
[f6835e5] | 566 | // && isRestrict >= other.isRestrict |
---|
| 567 | // && isLvalue <= other.isLvalue |
---|
[0dd3a2f] | 568 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 569 | } |
---|
| 570 | |
---|
[c8ffe20b] | 571 | inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 572 | return operator!=( other ) && operator<=( other ); |
---|
[51b7345] | 573 | } |
---|
| 574 | |
---|
[c8ffe20b] | 575 | inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 576 | return operator!=( other ) && operator>=( other ); |
---|
[51b7345] | 577 | } |
---|
| 578 | |
---|
[3906301] | 579 | std::ostream & operator<<( std::ostream & out, const Type * type ); |
---|
[baf7fee] | 580 | |
---|
[c8ffe20b] | 581 | #endif // TYPE_H |
---|
[0dd3a2f] | 582 | |
---|
| 583 | // Local Variables: // |
---|
| 584 | // tab-width: 4 // |
---|
| 585 | // mode: c++ // |
---|
| 586 | // compile-command: "make install" // |
---|
| 587 | // End: // |
---|