- Timestamp:
- May 23, 2019, 11:27:57 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 68c9165
- Parents:
- c957e7f
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
rc957e7f rb0ec971 96 96 } 97 97 98 void print( const ast::ParameterizedType::ForallList & forall ) { 99 if ( forall.empty() ) return; 100 os << "forall" << std::endl; 101 ++indent; 102 printAll( forall ); 103 os << indent; 104 --indent; 105 } 106 107 void print( const std::vector<ptr<Attribute>> & attrs ) { 108 if ( attrs.empty() ) return; 109 os << "with attributes" << std::endl; 110 ++indent; 111 printAll( attrs ); 112 --indent; 113 } 114 115 void print( const std::vector<ptr<Expr>> & params ) { 116 if ( params.empty() ) return; 117 os << std::endl << indent << "... with parameters" << std::endl; 118 ++indent; 119 printAll( params ); 120 --indent; 121 } 122 123 void preprint( const ast::Type * node ) { 124 print( node->qualifiers ); 125 } 126 127 void preprint( const ast::ParameterizedType * node ) { 128 print( node->forall ); 129 print( node->qualifiers ); 130 } 131 132 void preprint( const ast::ReferenceToType * node ) { 133 print( node->forall ); 134 print( node->attributes ); 135 print( node->qualifiers ); 136 } 137 98 138 public: 99 139 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) { … … 404 444 405 445 virtual const ast::Type * visit( const ast::VoidType * node ) { 446 preprint( node ); 447 os << "void"; 406 448 return node; 407 449 } 408 450 409 451 virtual const ast::Type * visit( const ast::BasicType * node ) { 452 preprint( node ); 453 os << ast::BasicType::typeNames[ node->kind ]; 410 454 return node; 411 455 } 412 456 413 457 virtual const ast::Type * visit( const ast::PointerType * node ) { 458 preprint( node ); 459 if ( ! node->isArray() ) { 460 os << "pointer to "; 461 } else { 462 os << "decayed "; 463 if ( node->isStatic ) { 464 os << "static "; 465 } 466 467 if ( node->isVarLen ) { 468 os << "variable length array of "; 469 } else if ( node->dimension ) { 470 os << "array of "; 471 node->dimension->accept( *this ); 472 os << " "; 473 } 474 } 475 476 if ( node->base ) { 477 node->base->accept( *this ); 478 } else { 479 os << "UNDEFINED"; 480 } 414 481 return node; 415 482 } 416 483 417 484 virtual const ast::Type * visit( const ast::ArrayType * node ) { 485 preprint( node ); 486 if ( node->isStatic ) { 487 os << "static "; 488 } 489 490 if ( node->isVarLen ) { 491 os << "variable length array of "; 492 } else if ( node->dimension ) { 493 os << "array of "; 494 } else { 495 os << "open array of "; 496 } 497 498 if ( node->base ) { 499 node->base->accept( *this ); 500 } else { 501 os << "UNDEFINED"; 502 } 503 504 if ( node->dimension ) { 505 os << " with dimension of "; 506 node->dimension->accept( *this ); 507 } 508 418 509 return node; 419 510 } 420 511 421 512 virtual const ast::Type * visit( const ast::ReferenceType * node ) { 513 preprint( node ); 514 515 os << "reference to "; 516 if ( node->base ) { 517 node->base->accept( *this ); 518 } else { 519 os << "UNDEFINED"; 520 } 521 422 522 return node; 423 523 } 424 524 425 525 virtual const ast::Type * visit( const ast::QualifiedType * node ) { 526 preprint( node ); 527 528 ++indent; 529 os << "Qualified Type:" << std::endl << indent; 530 node->parent->accept( *this ); 531 os << std::endl << indent; 532 node->child->accept( *this ); 533 os << std::endl; 534 --indent; 535 426 536 return node; 427 537 } 428 538 429 539 virtual const ast::Type * visit( const ast::FunctionType * node ) { 540 preprint( node ); 541 542 os << "function" << std::endl; 543 if ( ! node->params.empty() ) { 544 os << indent << "... with parameters" << std::endl; 545 ++indent; 546 printAll( node->params ); 547 if ( node->isVarArgs ) { 548 os << indent << "and a variable number of other arguments" << std::endl; 549 } 550 --indent; 551 } else if ( node->isVarArgs ) { 552 os << indent+1 << "accepting unspecified arguments" << std::endl; 553 } 554 555 os << indent << "... returning"; 556 if ( node->returns.empty() ) { 557 os << " nothing" << std::endl; 558 } else { 559 os << std::endl; 560 ++indent; 561 printAll( node->returns ); 562 --indent; 563 } 564 430 565 return node; 431 566 } 432 567 433 568 virtual const ast::Type * visit( const ast::StructInstType * node ) { 569 preprint( node ); 570 571 os << "instance of struct " << node->name; 572 if ( node->base ) { 573 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 574 } 575 print( node->params ); 576 434 577 return node; 435 578 } 436 579 437 580 virtual const ast::Type * visit( const ast::UnionInstType * node ) { 581 preprint( node ); 582 583 os << "instance of union " << node->name; 584 if ( node->base ) { 585 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 586 } 587 print( node->params ); 588 438 589 return node; 439 590 } 440 591 441 592 virtual const ast::Type * visit( const ast::EnumInstType * node ) { 593 preprint( node ); 594 595 os << "instance of enum " << node->name; 596 if ( node->base ) { 597 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 598 } 599 print( node->params ); 600 442 601 return node; 443 602 } 444 603 445 604 virtual const ast::Type * visit( const ast::TraitInstType * node ) { 605 preprint( node ); 606 607 os << "instance of trait " << node->name; 608 print( node->params ); 609 446 610 return node; 447 611 } 448 612 449 613 virtual const ast::Type * visit( const ast::TypeInstType * node ) { 614 preprint( node ); 615 616 os << "instance of type " << node->name 617 << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)"; 618 print( node->params ); 619 450 620 return node; 451 621 } 452 622 453 623 virtual const ast::Type * visit( const ast::TupleType * node ) { 624 preprint( node ); 625 626 os << "tuple of types" << std::endl; 627 ++indent; 628 printAll( node->types ); 629 --indent; 630 454 631 return node; 455 632 } 456 633 457 634 virtual const ast::Type * visit( const ast::TypeofType * node ) { 635 preprint( node ); 636 637 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; } 638 os << "type-of expression "; 639 if ( node->expr ) { 640 node->expr->accept( *this ); 641 } else { 642 os << "UNDEFINED"; 643 } 644 458 645 return node; 459 646 } 460 647 461 648 virtual const ast::Type * visit( const ast::VarArgsType * node ) { 649 preprint( node ); 650 os << "builtin var args pack"; 462 651 return node; 463 652 } 464 653 465 654 virtual const ast::Type * visit( const ast::ZeroType * node ) { 655 preprint( node ); 656 os << "zero_t"; 466 657 return node; 467 658 } 468 659 469 660 virtual const ast::Type * visit( const ast::OneType * node ) { 661 preprint( node ); 662 os << "one_t"; 470 663 return node; 471 664 } 472 665 473 666 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) { 667 preprint( node ); 668 os << "Global Scope Type"; 474 669 return node; 475 670 } -
src/AST/Type.hpp
rc957e7f rb0ec971 308 308 virtual ReferenceToType * clone() const override = 0; 309 309 MUTATE_FRIEND 310 311 protected:312 /// Name for the kind of type this is313 virtual std::string typeString() const = 0;314 310 }; 315 311 … … 333 329 StructInstType * clone() const override { return new StructInstType{ *this }; } 334 330 MUTATE_FRIEND 335 336 std::string typeString() const override { return "struct"; }337 331 }; 338 332 … … 356 350 UnionInstType * clone() const override { return new UnionInstType{ *this }; } 357 351 MUTATE_FRIEND 358 359 std::string typeString() const override { return "union"; }360 352 }; 361 353 … … 379 371 EnumInstType * clone() const override { return new EnumInstType{ *this }; } 380 372 MUTATE_FRIEND 381 382 std::string typeString() const override { return "enum"; }383 373 }; 384 374 … … 403 393 TraitInstType * clone() const override { return new TraitInstType{ *this }; } 404 394 MUTATE_FRIEND 405 406 std::string typeString() const override { return "trait"; }407 395 }; 408 396 … … 432 420 TypeInstType * clone() const override { return new TypeInstType{ *this }; } 433 421 MUTATE_FRIEND 434 435 std::string typeString() const override { return "type"; }436 422 }; 437 423
Note: See TracChangeset
for help on using the changeset viewer.