Changeset c8ffe20b for translator/SynTree
- Timestamp:
- Nov 15, 2014, 10:46:42 PM (10 years ago)
- 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:
- 1ead581
- Parents:
- 8c17ab0
- Location:
- translator/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/FunctionType.cc
r8c17ab0 rc8ffe20b 1 /*2 * This file is part of the Cforall project3 *4 * $Id: FunctionType.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <algorithm> 9 2 … … 13 6 14 7 15 FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) 16 : Type( tq ), isVarArgs( isVarArgs ) 17 { 8 FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) { 18 9 } 19 10 20 FunctionType::FunctionType( const FunctionType &other ) 21 : Type( other ), isVarArgs( other.isVarArgs ) 22 { 11 FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) { 23 12 cloneAll( other.returnVals, returnVals ); 24 13 cloneAll( other.parameters, parameters ); 25 14 } 26 15 27 FunctionType::~FunctionType() 28 { 16 FunctionType::~FunctionType() { 29 17 deleteAll( returnVals ); 30 18 deleteAll( parameters ); 31 19 } 32 20 33 void 34 FunctionType::print( std::ostream &os, int indent ) const 35 { 21 void FunctionType::print( std::ostream &os, int indent ) const { 36 22 using std::string; 37 23 using std::endl; … … 39 25 Type::print( os, indent ); 40 26 os << "function" << endl; 41 if ( !parameters.empty() ) {42 os << string( indent +2, ' ' ) << "with parameters" << endl;43 printAll( parameters, os, indent +4 );44 if ( isVarArgs ) {45 os << string( indent +4, ' ' ) << "and a variable number of other arguments" << endl;27 if ( ! parameters.empty() ) { 28 os << string( indent + 2, ' ' ) << "with parameters" << endl; 29 printAll( parameters, os, indent + 4 ); 30 if ( isVarArgs ) { 31 os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl; 46 32 } 47 } else if ( isVarArgs ) {48 os << string( indent +4, ' ' ) << "accepting unspecified arguments" << endl;33 } else if ( isVarArgs ) { 34 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl; 49 35 } 50 os << string( indent +2, ' ' ) << "returning ";51 if ( returnVals.empty() ) {52 os << endl << string( indent +4, ' ' ) << "nothing " << endl;36 os << string( indent + 2, ' ' ) << "returning "; 37 if ( returnVals.empty() ) { 38 os << endl << string( indent + 4, ' ' ) << "nothing " << endl; 53 39 } else { 54 40 os << endl; 55 printAll( returnVals, os, indent +4 );41 printAll( returnVals, os, indent + 4 ); 56 42 } 57 58 43 } 59 44 -
translator/SynTree/Type.h
r8c17ab0 rc8ffe20b 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Type.h,v 1.30 2005/08/29 20:59:26 rcbilson Exp $5 *6 */7 8 1 #ifndef TYPE_H 9 2 #define TYPE_H … … 14 7 15 8 16 class Type 17 { 18 public: 19 struct Qualifiers 20 { 21 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ) {} 22 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ) {} 9 class Type { 10 public: 11 struct Qualifiers { 12 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ) {} 13 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ) {} 23 14 24 Qualifiers &operator+=( const Qualifiers &other );25 Qualifiers &operator-=( const Qualifiers &other );15 Qualifiers &operator+=( const Qualifiers &other ); 16 Qualifiers &operator-=( const Qualifiers &other ); 26 17 Qualifiers operator+( const Type::Qualifiers &other ); 27 bool operator==( const Qualifiers &other );28 bool operator!=( const Qualifiers &other );18 bool operator==( const Qualifiers &other ); 19 bool operator!=( const Qualifiers &other ); 29 20 bool operator<=( const Qualifiers &other ); 30 21 bool operator>=( const Qualifiers &other ); … … 57 48 virtual Type *acceptMutator( Mutator &m ) = 0; 58 49 virtual void print( std::ostream &os, int indent = 0 ) const; 59 60 private: 50 private: 61 51 Qualifiers tq; 62 52 std::list<TypeDecl*> forall; 63 53 }; 64 54 65 class VoidType : public Type 66 { 67 public: 55 class VoidType : public Type { 56 public: 68 57 VoidType( const Type::Qualifiers &tq ); 69 58 … … 74 63 }; 75 64 76 class BasicType : public Type 77 { 78 public: 79 enum Kind 80 { 81 Bool, 82 Char, 83 SignedChar, 84 UnsignedChar, 85 ShortSignedInt, 86 ShortUnsignedInt, 87 SignedInt, 88 UnsignedInt, 89 LongSignedInt, 90 LongUnsignedInt, 91 LongLongSignedInt, 92 LongLongUnsignedInt, 93 Float, 94 Double, 95 LongDouble, 96 FloatComplex, 97 DoubleComplex, 98 LongDoubleComplex, 99 FloatImaginary, 100 DoubleImaginary, 101 LongDoubleImaginary, 102 NUMBER_OF_BASIC_TYPES 103 }; 65 class BasicType : public Type { 66 public: 67 enum Kind { 68 Bool, 69 Char, 70 SignedChar, 71 UnsignedChar, 72 ShortSignedInt, 73 ShortUnsignedInt, 74 SignedInt, 75 UnsignedInt, 76 LongSignedInt, 77 LongUnsignedInt, 78 LongLongSignedInt, 79 LongLongUnsignedInt, 80 Float, 81 Double, 82 LongDouble, 83 FloatComplex, 84 DoubleComplex, 85 LongDoubleComplex, 86 FloatImaginary, 87 DoubleImaginary, 88 LongDoubleImaginary, 89 NUMBER_OF_BASIC_TYPES 90 }; 104 91 105 92 BasicType( const Type::Qualifiers &tq, Kind bt ); … … 114 101 115 102 bool isInteger() const; 116 117 private: 103 private: 118 104 Kind kind; 119 105 }; 120 106 121 class PointerType : public Type 122 { 123 public: 107 class PointerType : public Type { 108 public: 124 109 PointerType( const Type::Qualifiers &tq, Type *base ); 125 110 PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); … … 140 125 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 141 126 virtual void print( std::ostream &os, int indent = 0 ) const; 142 143 private: 127 private: 144 128 Type *base; 145 129 146 // in C99, pointer types can be qualified in many ways 147 // e.g., int f( int a[ static 3 ] ) 130 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) 148 131 Expression *dimension; 149 132 bool isVarLen; … … 151 134 }; 152 135 153 class ArrayType : public Type 154 { 155 public: 136 class ArrayType : public Type { 137 public: 156 138 ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 157 139 ArrayType( const ArrayType& ); … … 171 153 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 172 154 virtual void print( std::ostream &os, int indent = 0 ) const; 173 174 private: 155 private: 175 156 Type *base; 176 157 Expression *dimension; … … 179 160 }; 180 161 181 class FunctionType : public Type 182 { 183 public: 162 class FunctionType : public Type { 163 public: 184 164 FunctionType( const Type::Qualifiers &tq, bool isVarArgs ); 185 165 FunctionType( const FunctionType& ); … … 195 175 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 196 176 virtual void print( std::ostream &os, int indent = 0 ) const; 197 198 private: 177 private: 199 178 std::list<DeclarationWithType*> returnVals; 200 179 std::list<DeclarationWithType*> parameters; … … 207 186 }; 208 187 209 class ReferenceToType : public Type 210 { 211 public: 188 class ReferenceToType : public Type { 189 public: 212 190 ReferenceToType( const Type::Qualifiers &tq, const std::string &name ); 213 191 ReferenceToType( const ReferenceToType &other ); … … 222 200 virtual Type *acceptMutator( Mutator &m ) = 0; 223 201 virtual void print( std::ostream &os, int indent = 0 ) const; 224 225 protected: 202 protected: 226 203 virtual std::string typeString() const = 0; 227 204 std::list< Expression* > parameters; 228 229 private: 205 private: 230 206 std::string name; 231 232 }; 233 234 class StructInstType : public ReferenceToType 235 { 207 }; 208 209 class StructInstType : public ReferenceToType { 236 210 typedef ReferenceToType Parent; 237 238 public: 211 public: 239 212 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 240 213 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} … … 250 223 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 251 224 252 private:225 private: 253 226 virtual std::string typeString() const; 254 227 … … 258 231 }; 259 232 260 class UnionInstType : public ReferenceToType 261 { 233 class UnionInstType : public ReferenceToType { 262 234 typedef ReferenceToType Parent; 263 264 public: 235 public: 265 236 UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {} 266 237 UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {} … … 275 246 virtual void accept( Visitor &v ) { v.visit( this ); } 276 247 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 277 278 private: 248 private: 279 249 virtual std::string typeString() const; 280 250 … … 284 254 }; 285 255 286 class EnumInstType : public ReferenceToType 287 { 256 class EnumInstType : public ReferenceToType { 288 257 typedef ReferenceToType Parent; 289 290 public: 258 public: 291 259 EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 292 260 EnumInstType( const EnumInstType &other ) : Parent( other ) {} … … 296 264 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 297 265 298 private:266 private: 299 267 virtual std::string typeString() const; 300 268 }; 301 269 302 class ContextInstType : public ReferenceToType 303 { 270 class ContextInstType : public ReferenceToType { 304 271 typedef ReferenceToType Parent; 305 306 public: 272 public: 307 273 ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 308 274 ContextInstType( const ContextInstType &other ); … … 314 280 virtual void accept( Visitor &v ) { v.visit( this ); } 315 281 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 316 317 private: 282 private: 318 283 virtual std::string typeString() const; 319 284 … … 323 288 }; 324 289 325 class TypeInstType : public ReferenceToType 326 { 290 class TypeInstType : public ReferenceToType { 327 291 typedef ReferenceToType Parent; 328 329 public: 292 public: 330 293 TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ); 331 294 TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ); … … 341 304 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 342 305 virtual void print( std::ostream &os, int indent = 0 ) const; 343 344 private: 306 private: 345 307 virtual std::string typeString() const; 346 347 308 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, 348 309 // where the type used here is actually defined … … 351 312 }; 352 313 353 class TupleType : public Type 354 { 355 public: 314 class TupleType : public Type { 315 public: 356 316 TupleType( const Type::Qualifiers &tq ); 357 317 TupleType( const TupleType& ); … … 364 324 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 365 325 virtual void print( std::ostream &os, int indent = 0 ) const; 366 367 private: 326 private: 368 327 std::list<Type*> types; 369 328 }; 370 329 371 class TypeofType : public Type 372 { 373 public: 330 class TypeofType : public Type { 331 public: 374 332 TypeofType( const Type::Qualifiers &tq, Expression *expr ); 375 333 TypeofType( const TypeofType& ); … … 383 341 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 384 342 virtual void print( std::ostream &os, int indent = 0 ) const; 385 386 private: 343 private: 387 344 Expression *expr; 388 345 }; 389 346 390 class AttrType : public Type 391 { 392 public: 347 class AttrType : public Type { 348 public: 393 349 AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); 394 350 AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); … … 410 366 virtual void print( std::ostream &os, int indent = 0 ) const; 411 367 412 private:368 private: 413 369 std::string name; 414 370 Expression *expr; … … 417 373 }; 418 374 419 inline Type::Qualifiers & 420 Type::Qualifiers::operator+=( const Type::Qualifiers &other ) 421 { 375 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { 422 376 isConst |= other.isConst; 423 377 isVolatile |= other.isVolatile; … … 427 381 } 428 382 429 inline Type::Qualifiers & 430 Type::Qualifiers::operator-=( const Type::Qualifiers &other ) 431 { 432 if( other.isConst ) isConst = 0; 433 if( other.isVolatile ) isVolatile = 0; 434 if( other.isRestrict ) isRestrict = 0; 383 inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) { 384 if ( other.isConst ) isConst = 0; 385 if ( other.isVolatile ) isVolatile = 0; 386 if ( other.isRestrict ) isRestrict = 0; 435 387 return *this; 436 388 } 437 389 438 inline Type::Qualifiers 439 Type::Qualifiers::operator+( const Type::Qualifiers &other ) 440 { 390 inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) { 441 391 Qualifiers q = other; 442 392 q += *this; … … 444 394 } 445 395 446 inline bool 447 Type::Qualifiers::operator==( const Qualifiers &other) 448 { 396 inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { 449 397 return isConst == other.isConst 450 451 398 && isVolatile == other.isVolatile 399 && isRestrict == other.isRestrict; 452 400 /// && isLvalue == other.isLvalue; 453 401 } 454 402 455 inline bool 456 Type::Qualifiers::operator!=( const Qualifiers &other) 457 { 403 inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) { 458 404 return isConst != other.isConst 459 405 || isVolatile != other.isVolatile … … 462 408 } 463 409 464 inline bool 465 Type::Qualifiers::operator<=( const Type::Qualifiers &other ) 466 { 410 inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) { 467 411 return isConst <= other.isConst 468 412 && isVolatile <= other.isVolatile … … 471 415 } 472 416 473 inline bool 474 Type::Qualifiers::operator>=( const Type::Qualifiers &other ) 475 { 417 inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) { 476 418 return isConst >= other.isConst 477 419 && isVolatile >= other.isVolatile … … 480 422 } 481 423 482 inline bool 483 Type::Qualifiers::operator<( const Type::Qualifiers &other ) 484 { 424 inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) { 485 425 return operator!=( other ) && operator<=( other ); 486 426 } 487 427 488 inline bool 489 Type::Qualifiers::operator>( const Type::Qualifiers &other ) 490 { 428 inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) { 491 429 return operator!=( other ) && operator>=( other ); 492 430 } 493 431 494 495 #endif /* #ifndef TYPE_H */ 432 #endif // TYPE_H
Note: See TracChangeset
for help on using the changeset viewer.