Changes in / [68c9165:3ca912a]
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
r68c9165 r3ca912a 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 141 101 void print( const ast::AggregateDecl * node ) { 142 102 os << node->typeString() << " " << node->name << ":"; … … 606 566 607 567 virtual const ast::Type * visit( const ast::VoidType * node ) { 608 preprint( node );609 os << "void";610 568 return node; 611 569 } 612 570 613 571 virtual const ast::Type * visit( const ast::BasicType * node ) { 614 preprint( node );615 os << ast::BasicType::typeNames[ node->kind ];616 572 return node; 617 573 } 618 574 619 575 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 }643 576 return node; 644 577 } 645 578 646 579 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 671 580 return node; 672 581 } 673 582 674 583 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 684 584 return node; 685 585 } 686 586 687 587 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 698 588 return node; 699 589 } 700 590 701 591 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 727 592 return node; 728 593 } 729 594 730 595 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 739 596 return node; 740 597 } 741 598 742 599 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 751 600 return node; 752 601 } 753 602 754 603 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 763 604 return node; 764 605 } 765 606 766 607 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 772 608 return node; 773 609 } 774 610 775 611 virtual const ast::Type * visit( const ast::TypeInstType * node ) { 776 preprint( node );777 778 os << "instance of type " << node->name779 << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";780 print( node->params );781 782 612 return node; 783 613 } 784 614 785 615 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 793 616 return node; 794 617 } 795 618 796 619 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 807 620 return node; 808 621 } 809 622 810 623 virtual const ast::Type * visit( const ast::VarArgsType * node ) { 811 preprint( node );812 os << "builtin var args pack";813 624 return node; 814 625 } 815 626 816 627 virtual const ast::Type * visit( const ast::ZeroType * node ) { 817 preprint( node );818 os << "zero_t";819 628 return node; 820 629 } 821 630 822 631 virtual const ast::Type * visit( const ast::OneType * node ) { 823 preprint( node );824 os << "one_t";825 632 return node; 826 633 } 827 634 828 635 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) { 829 preprint( node );830 os << "Global Scope Type";831 636 return node; 832 637 } -
src/AST/Type.hpp
r68c9165 r3ca912a 308 308 virtual ReferenceToType * clone() const override = 0; 309 309 MUTATE_FRIEND 310 311 protected: 312 /// Name for the kind of type this is 313 virtual std::string typeString() const = 0; 310 314 }; 311 315 … … 329 333 StructInstType * clone() const override { return new StructInstType{ *this }; } 330 334 MUTATE_FRIEND 335 336 std::string typeString() const override { return "struct"; } 331 337 }; 332 338 … … 350 356 UnionInstType * clone() const override { return new UnionInstType{ *this }; } 351 357 MUTATE_FRIEND 358 359 std::string typeString() const override { return "union"; } 352 360 }; 353 361 … … 371 379 EnumInstType * clone() const override { return new EnumInstType{ *this }; } 372 380 MUTATE_FRIEND 381 382 std::string typeString() const override { return "enum"; } 373 383 }; 374 384 … … 393 403 TraitInstType * clone() const override { return new TraitInstType{ *this }; } 394 404 MUTATE_FRIEND 405 406 std::string typeString() const override { return "trait"; } 395 407 }; 396 408 … … 420 432 TypeInstType * clone() const override { return new TypeInstType{ *this }; } 421 433 MUTATE_FRIEND 434 435 std::string typeString() const override { return "type"; } 422 436 }; 423 437
Note: See TracChangeset
for help on using the changeset viewer.