- Timestamp:
- May 23, 2019, 12:07:28 PM (5 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:
- af1e8f56
- Parents:
- b5fed34 (diff), 68c9165 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
rb5fed34 reffe5b0 99 99 } 100 100 101 void print( const ast::ParameterizedType::ForallList & forall ) { 102 if ( forall.empty() ) return; 103 os << "forall" << std::endl; 104 ++indent; 105 printAll( forall ); 106 os << indent; 107 --indent; 108 } 109 110 void print( const std::vector<ptr<Attribute>> & attrs ) { 111 if ( attrs.empty() ) return; 112 os << "with attributes" << std::endl; 113 ++indent; 114 printAll( attrs ); 115 --indent; 116 } 117 118 void print( const std::vector<ptr<Expr>> & params ) { 119 if ( params.empty() ) return; 120 os << std::endl << indent << "... with parameters" << std::endl; 121 ++indent; 122 printAll( params ); 123 --indent; 124 } 125 126 void preprint( const ast::Type * node ) { 127 print( node->qualifiers ); 128 } 129 130 void preprint( const ast::ParameterizedType * node ) { 131 print( node->forall ); 132 print( node->qualifiers ); 133 } 134 135 void preprint( const ast::ReferenceToType * node ) { 136 print( node->forall ); 137 print( node->attributes ); 138 print( node->qualifiers ); 139 } 140 101 141 void print( const ast::AggregateDecl * node ) { 102 142 os << node->typeString() << " " << node->name << ":"; … … 566 606 567 607 virtual const ast::Type * visit( const ast::VoidType * node ) { 608 preprint( node ); 609 os << "void"; 568 610 return node; 569 611 } 570 612 571 613 virtual const ast::Type * visit( const ast::BasicType * node ) { 614 preprint( node ); 615 os << ast::BasicType::typeNames[ node->kind ]; 572 616 return node; 573 617 } 574 618 575 619 virtual const ast::Type * visit( const ast::PointerType * node ) { 620 preprint( node ); 621 if ( ! node->isArray() ) { 622 os << "pointer to "; 623 } else { 624 os << "decayed "; 625 if ( node->isStatic ) { 626 os << "static "; 627 } 628 629 if ( node->isVarLen ) { 630 os << "variable length array of "; 631 } else if ( node->dimension ) { 632 os << "array of "; 633 node->dimension->accept( *this ); 634 os << " "; 635 } 636 } 637 638 if ( node->base ) { 639 node->base->accept( *this ); 640 } else { 641 os << "UNDEFINED"; 642 } 576 643 return node; 577 644 } 578 645 579 646 virtual const ast::Type * visit( const ast::ArrayType * node ) { 647 preprint( node ); 648 if ( node->isStatic ) { 649 os << "static "; 650 } 651 652 if ( node->isVarLen ) { 653 os << "variable length array of "; 654 } else if ( node->dimension ) { 655 os << "array of "; 656 } else { 657 os << "open array of "; 658 } 659 660 if ( node->base ) { 661 node->base->accept( *this ); 662 } else { 663 os << "UNDEFINED"; 664 } 665 666 if ( node->dimension ) { 667 os << " with dimension of "; 668 node->dimension->accept( *this ); 669 } 670 580 671 return node; 581 672 } 582 673 583 674 virtual const ast::Type * visit( const ast::ReferenceType * node ) { 675 preprint( node ); 676 677 os << "reference to "; 678 if ( node->base ) { 679 node->base->accept( *this ); 680 } else { 681 os << "UNDEFINED"; 682 } 683 584 684 return node; 585 685 } 586 686 587 687 virtual const ast::Type * visit( const ast::QualifiedType * node ) { 688 preprint( node ); 689 690 ++indent; 691 os << "Qualified Type:" << std::endl << indent; 692 node->parent->accept( *this ); 693 os << std::endl << indent; 694 node->child->accept( *this ); 695 os << std::endl; 696 --indent; 697 588 698 return node; 589 699 } 590 700 591 701 virtual const ast::Type * visit( const ast::FunctionType * node ) { 702 preprint( node ); 703 704 os << "function" << std::endl; 705 if ( ! node->params.empty() ) { 706 os << indent << "... with parameters" << std::endl; 707 ++indent; 708 printAll( node->params ); 709 if ( node->isVarArgs ) { 710 os << indent << "and a variable number of other arguments" << std::endl; 711 } 712 --indent; 713 } else if ( node->isVarArgs ) { 714 os << indent+1 << "accepting unspecified arguments" << std::endl; 715 } 716 717 os << indent << "... returning"; 718 if ( node->returns.empty() ) { 719 os << " nothing" << std::endl; 720 } else { 721 os << std::endl; 722 ++indent; 723 printAll( node->returns ); 724 --indent; 725 } 726 592 727 return node; 593 728 } 594 729 595 730 virtual const ast::Type * visit( const ast::StructInstType * node ) { 731 preprint( node ); 732 733 os << "instance of struct " << node->name; 734 if ( node->base ) { 735 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 736 } 737 print( node->params ); 738 596 739 return node; 597 740 } 598 741 599 742 virtual const ast::Type * visit( const ast::UnionInstType * node ) { 743 preprint( node ); 744 745 os << "instance of union " << node->name; 746 if ( node->base ) { 747 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 748 } 749 print( node->params ); 750 600 751 return node; 601 752 } 602 753 603 754 virtual const ast::Type * visit( const ast::EnumInstType * node ) { 755 preprint( node ); 756 757 os << "instance of enum " << node->name; 758 if ( node->base ) { 759 os << " " << ( node->base->body ? "with" : "without" ) << " body"; 760 } 761 print( node->params ); 762 604 763 return node; 605 764 } 606 765 607 766 virtual const ast::Type * visit( const ast::TraitInstType * node ) { 767 preprint( node ); 768 769 os << "instance of trait " << node->name; 770 print( node->params ); 771 608 772 return node; 609 773 } 610 774 611 775 virtual const ast::Type * visit( const ast::TypeInstType * node ) { 776 preprint( node ); 777 778 os << "instance of type " << node->name 779 << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)"; 780 print( node->params ); 781 612 782 return node; 613 783 } 614 784 615 785 virtual const ast::Type * visit( const ast::TupleType * node ) { 786 preprint( node ); 787 788 os << "tuple of types" << std::endl; 789 ++indent; 790 printAll( node->types ); 791 --indent; 792 616 793 return node; 617 794 } 618 795 619 796 virtual const ast::Type * visit( const ast::TypeofType * node ) { 797 preprint( node ); 798 799 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; } 800 os << "type-of expression "; 801 if ( node->expr ) { 802 node->expr->accept( *this ); 803 } else { 804 os << "UNDEFINED"; 805 } 806 620 807 return node; 621 808 } 622 809 623 810 virtual const ast::Type * visit( const ast::VarArgsType * node ) { 811 preprint( node ); 812 os << "builtin var args pack"; 624 813 return node; 625 814 } 626 815 627 816 virtual const ast::Type * visit( const ast::ZeroType * node ) { 817 preprint( node ); 818 os << "zero_t"; 628 819 return node; 629 820 } 630 821 631 822 virtual const ast::Type * visit( const ast::OneType * node ) { 823 preprint( node ); 824 os << "one_t"; 632 825 return node; 633 826 } 634 827 635 828 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) { 829 preprint( node ); 830 os << "Global Scope Type"; 636 831 return node; 637 832 } -
src/AST/Type.hpp
rb5fed34 reffe5b0 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.