Changes in src/AST/Type.hpp [f3cc5b6:87701b6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Type.hpp
rf3cc5b6 r87701b6 29 29 #include "Visitor.hpp" 30 30 31 // Must be included in *all* AST classes; should be #undef'd at the end of the file32 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);33 34 31 namespace ast { 35 32 … … 37 34 public: 38 35 CV::Qualifiers qualifiers; 39 36 40 37 Type( CV::Qualifiers q = {} ) : qualifiers(q) {} 41 38 … … 73 70 private: 74 71 virtual Type * clone() const override = 0; 75 MUTATE_FRIEND76 72 }; 77 73 … … 80 76 public: 81 77 VoidType( CV::Qualifiers q = {} ) : Type( q ) {} 82 78 83 79 unsigned size() const override { return 0; } 84 80 bool isVoid() const override { return true; } … … 88 84 private: 89 85 VoidType * clone() const override { return new VoidType{ *this }; } 90 MUTATE_FRIEND91 86 }; 92 87 … … 151 146 private: 152 147 BasicType * clone() const override { return new BasicType{ *this }; } 153 MUTATE_FRIEND154 148 }; 155 149 … … 171 165 172 166 PointerType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b), dimension() {} 173 PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 167 PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 174 168 CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} 175 169 … … 182 176 private: 183 177 PointerType * clone() const override { return new PointerType{ *this }; } 184 MUTATE_FRIEND185 178 }; 186 179 … … 193 186 DimensionFlag isStatic; 194 187 195 ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 188 ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 196 189 CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} 197 190 … … 204 197 private: 205 198 ArrayType * clone() const override { return new ArrayType{ *this }; } 206 MUTATE_FRIEND207 199 }; 208 200 … … 224 216 private: 225 217 ReferenceType * clone() const override { return new ReferenceType{ *this }; } 226 MUTATE_FRIEND227 218 }; 228 219 … … 233 224 ptr<Type> child; 234 225 235 QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 226 QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 236 227 : Type(q), parent(p), child(c) {} 237 228 … … 239 230 private: 240 231 QualifiedType * clone() const override { return new QualifiedType{ *this }; } 241 MUTATE_FRIEND242 232 }; 243 233 … … 249 239 ForallList forall; 250 240 251 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 241 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 252 242 : Type(q), forall(std::move(fs)) {} 253 243 ParameterizedType( CV::Qualifiers q ) : Type(q), forall() {} … … 255 245 private: 256 246 virtual ParameterizedType * clone() const override = 0; 257 MUTATE_FRIEND258 247 }; 259 248 … … 267 256 std::vector<ptr<DeclWithType>> params; 268 257 269 /// Does the function accept a variable number of arguments following the arguments specified 258 /// Does the function accept a variable number of arguments following the arguments specified 270 259 /// in the parameters list. 271 260 /// This could be because of … … 285 274 private: 286 275 FunctionType * clone() const override { return new FunctionType{ *this }; } 287 MUTATE_FRIEND288 276 }; 289 277 … … 296 284 bool hoistType = false; 297 285 298 ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 286 ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 299 287 std::vector<ptr<Attribute>> && as = {} ) 300 288 : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {} … … 307 295 private: 308 296 virtual ReferenceToType * clone() const override = 0; 309 MUTATE_FRIEND310 297 311 298 protected: … … 319 306 readonly<StructDecl> base; 320 307 321 StructInstType( const std::string& n, CV::Qualifiers q = {}, 308 StructInstType( const std::string& n, CV::Qualifiers q = {}, 322 309 std::vector<ptr<Attribute>> && as = {} ) 323 310 : ReferenceToType( n, q, std::move(as) ), base() {} 324 StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 311 StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 325 312 std::vector<ptr<Attribute>> && as = {} ); 326 313 327 314 bool isComplete() const override; 328 315 … … 332 319 private: 333 320 StructInstType * clone() const override { return new StructInstType{ *this }; } 334 MUTATE_FRIEND335 321 336 322 std::string typeString() const override { return "struct"; } … … 342 328 readonly<UnionDecl> base; 343 329 344 UnionInstType( const std::string& n, CV::Qualifiers q = {}, 330 UnionInstType( const std::string& n, CV::Qualifiers q = {}, 345 331 std::vector<ptr<Attribute>> && as = {} ) 346 332 : ReferenceToType( n, q, std::move(as) ), base() {} 347 UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 333 UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 348 334 std::vector<ptr<Attribute>> && as = {} ); 349 335 350 336 bool isComplete() const override; 351 337 … … 355 341 private: 356 342 UnionInstType * clone() const override { return new UnionInstType{ *this }; } 357 MUTATE_FRIEND358 343 359 344 std::string typeString() const override { return "union"; } … … 365 350 readonly<EnumDecl> base; 366 351 367 EnumInstType( const std::string& n, CV::Qualifiers q = {}, 352 EnumInstType( const std::string& n, CV::Qualifiers q = {}, 368 353 std::vector<ptr<Attribute>> && as = {} ) 369 354 : ReferenceToType( n, q, std::move(as) ), base() {} 370 EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 355 EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 371 356 std::vector<ptr<Attribute>> && as = {} ); 372 357 373 358 bool isComplete() const override; 374 359 … … 378 363 private: 379 364 EnumInstType * clone() const override { return new EnumInstType{ *this }; } 380 MUTATE_FRIEND381 365 382 366 std::string typeString() const override { return "enum"; } … … 388 372 readonly<TraitDecl> base; 389 373 390 TraitInstType( const std::string& n, CV::Qualifiers q = {}, 374 TraitInstType( const std::string& n, CV::Qualifiers q = {}, 391 375 std::vector<ptr<Attribute>> && as = {} ) 392 376 : ReferenceToType( n, q, std::move(as) ), base() {} 393 TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 377 TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 394 378 std::vector<ptr<Attribute>> && as = {} ); 395 379 396 380 // not meaningful for TraitInstType 397 381 bool isComplete() const override { assert(false); } … … 402 386 private: 403 387 TraitInstType * clone() const override { return new TraitInstType{ *this }; } 404 MUTATE_FRIEND405 388 406 389 std::string typeString() const override { return "trait"; } … … 413 396 TypeVar::Kind kind; 414 397 415 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 398 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 416 399 std::vector<ptr<Attribute>> && as = {} ) 417 400 : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 418 TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 401 TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 419 402 std::vector<ptr<Attribute>> && as = {} ) 420 403 : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} … … 431 414 private: 432 415 TypeInstType * clone() const override { return new TypeInstType{ *this }; } 433 MUTATE_FRIEND434 416 435 417 std::string typeString() const override { return "type"; } … … 448 430 iterator begin() const { return types.begin(); } 449 431 iterator end() const { return types.end(); } 450 432 451 433 unsigned size() const override { return types.size(); } 452 434 453 435 const Type * getComponent( unsigned i ) override { 454 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 436 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 455 437 i, size() ); 456 438 return *(begin()+i); … … 460 442 private: 461 443 TupleType * clone() const override { return new TupleType{ *this }; } 462 MUTATE_FRIEND463 444 }; 464 445 … … 469 450 enum Kind { Typeof, Basetypeof } kind; 470 451 471 TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 452 TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 472 453 : Type(q), expr(e), kind(k) {} 473 454 … … 475 456 private: 476 457 TypeofType * clone() const override { return new TypeofType{ *this }; } 477 MUTATE_FRIEND478 458 }; 479 459 … … 482 462 public: 483 463 VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {} 484 464 485 465 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 486 466 private: 487 467 VarArgsType * clone() const override { return new VarArgsType{ *this }; } 488 MUTATE_FRIEND489 468 }; 490 469 … … 493 472 public: 494 473 ZeroType( CV::Qualifiers q = {} ) : Type( q ) {} 495 474 496 475 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 497 476 private: 498 477 ZeroType * clone() const override { return new ZeroType{ *this }; } 499 MUTATE_FRIEND500 478 }; 501 479 … … 508 486 private: 509 487 OneType * clone() const override { return new OneType{ *this }; } 510 MUTATE_FRIEND511 488 }; 512 489 … … 519 496 private: 520 497 GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; } 521 MUTATE_FRIEND 522 }; 523 524 //================================================================================================= 525 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency 526 /// remove only if there is a better solution. 527 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with 528 /// forward declarations 529 inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); } 530 inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); } 531 inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); } 532 inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); } 533 inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); } 534 inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); } 535 inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); } 536 inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); } 537 inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); } 538 inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); } 539 inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); } 540 inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); } 541 inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); } 542 inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); } 543 inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); } 544 inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); } 545 inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); } 546 inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); } 547 inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); } 548 inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); } 549 inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); } 550 inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); } 551 inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); } 552 inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); } 553 inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); } 554 inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); } 555 inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); } 556 inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); } 557 inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); } 558 inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); } 559 inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); } 560 inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); } 561 inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); } 562 inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); } 563 inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); } 564 inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); } 565 inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); } 566 inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); } 567 inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); } 568 inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); } 498 }; 569 499 570 500 } 571 572 #undef MUTATE_FRIEND573 501 574 502 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.