Changes in src/AST/Print.cpp [20a5977:335f2d8]
- File:
-
- 1 edited
-
src/AST/Print.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
r20a5977 r335f2d8 59 59 } 60 60 61 /// call if mandatory field is missing62 void undefined() {63 os << "UNDEFINED";64 }65 66 /// call for fields that should be mandatory67 void safe_print( const ast::Node * n ) {68 if ( n ) n->accept( *this );69 else undefined();70 }71 72 /// call to print short form. Incorporates features of safe_print()73 void short_print( const ast::Node * n ) {74 if ( ! n ) { undefined(); return; }75 bool old_short = short_mode; short_mode = true;76 n->accept( *this );77 short_mode = old_short;78 }79 80 61 81 62 static const char* Names[]; … … 118 99 } 119 100 120 void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) {121 switch ( inferred.mode ) {122 case ast::Expr::InferUnion::Empty: return;123 case ast::Expr::InferUnion::Slots: {124 os << indent << "with " << inferred.data.resnSlots.size() << " pending inference slots"125 << std::endl;126 return;127 }128 case ast::Expr::InferUnion::Params: {129 os << indent << "with inferred parameters " << level << ":" << std::endl;130 ++indent;131 for ( const auto & i : inferred.data.inferParams ) {132 os << indent;133 short_print( Decl::fromId( i.second.decl ) );134 os << std::endl;135 print( i.second.expr->inferred, level+1 );136 }137 --indent;138 return;139 }140 }141 }142 143 void print( const ast::ParameterizedType::ForallList & forall ) {144 if ( forall.empty() ) return;145 os << "forall" << std::endl;146 ++indent;147 printAll( forall );148 os << indent;149 --indent;150 }151 152 void print( const std::vector<ptr<Attribute>> & attrs ) {153 if ( attrs.empty() ) return;154 os << "with attributes" << std::endl;155 ++indent;156 printAll( attrs );157 --indent;158 }159 160 void print( const std::vector<ptr<Expr>> & params ) {161 if ( params.empty() ) return;162 os << std::endl << indent << "... with parameters" << std::endl;163 ++indent;164 printAll( params );165 --indent;166 }167 168 101 void print( const ast::AggregateDecl * node ) { 169 102 os << node->typeString() << " " << node->name << ":"; … … 222 155 } 223 156 224 void postprint( const ast::Expr * node ) {225 print( node->inferred );226 227 if ( node->env ) {228 os << std::endl << indent << "... with environment:" << std::endl;229 ++indent;230 node->env->accept( *this );231 --indent;232 }233 234 if ( node->extension ) {235 os << std::endl << indent << "... with extension";236 }237 }238 239 void preprint( const ast::Type * node ) {240 print( node->qualifiers );241 }242 243 void preprint( const ast::ParameterizedType * node ) {244 print( node->forall );245 print( node->qualifiers );246 }247 248 void preprint( const ast::ReferenceToType * node ) {249 print( node->forall );250 print( node->attributes );251 print( node->qualifiers );252 }253 254 157 public: 255 158 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) { … … 265 168 node->type->accept( *this ); 266 169 } else { 267 os << " untyped entity";170 os << " untyped entity "; 268 171 } // if 269 172 … … 311 214 node->type->accept( *this ); 312 215 } else { 313 os << "untyped entity ";216 os << "untyped entity "; 314 217 } // if 315 218 … … 388 291 ++indent; 389 292 os << "Expression Statement:" << endl << indent; 390 safe_print( node->expr);293 node->expr->accept( *this ); 391 294 --indent; 392 295 return node; … … 423 326 os << indent+1; 424 327 ++indent; 425 safe_print( node->cond);328 node->cond->accept( *this ); 426 329 --indent; 427 330 … … 441 344 ++indent; 442 345 os << indent; 443 safe_print( node->thenPart);346 node->thenPart->accept( *this ); 444 347 --indent; 445 348 … … 515 418 516 419 virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) { 517 ++indent;518 os << "Application of" << std::endl << indent;519 safe_print( node->func );520 os << std::endl;521 if ( ! node->args.empty() ) {522 os << indent << "... to arguments" << std::endl;523 printAll( node->args );524 }525 --indent;526 postprint( node );527 528 420 return node; 529 421 } 530 422 531 423 virtual const ast::Expr * visit( const ast::UntypedExpr * node ) { 532 ++indent;533 os << "Applying untyped:" << std::endl;534 os << indent;535 safe_print( node->func );536 os << std::endl << indent-1 << "...to:" << std::endl;537 printAll( node->args );538 --indent;539 postprint( node );540 541 424 return node; 542 425 } 543 426 544 427 virtual const ast::Expr * visit( const ast::NameExpr * node ) { 545 os << "Name: " << node->name;546 postprint( node );547 548 428 return node; 549 429 } 550 430 551 431 virtual const ast::Expr * visit( const ast::AddressExpr * node ) { 552 os << "Address of:" << std::endl;553 ++indent;554 os << indent;555 safe_print( node->arg );556 557 --indent;558 559 432 return node; 560 433 } 561 434 562 435 virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) { 563 os << "Address of label:" << node->arg;564 565 436 return node; 566 437 } 567 438 568 439 virtual const ast::Expr * visit( const ast::CastExpr * node ) { 569 ++indent;570 os << (node->isGenerated ? "Generated" : "Explicit") << " cast of:" << std::endl << indent;571 safe_print( node->arg );572 os << std::endl << indent-1 << "... to:";573 if ( ! node->result ) {574 os << " ";575 undefined();576 } else if ( node->result->isVoid() ) {577 os << " nothing";578 } else {579 os << std::endl << indent;580 node->result->accept( *this );581 } // if582 --indent;583 postprint( node );584 585 440 return node; 586 441 } 587 442 588 443 virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) { 589 ++indent;590 os << "Keyword Cast of:" << std::endl << indent;591 safe_print( node->arg );592 --indent;593 os << std::endl << indent << "... to: " << node->targetString();594 postprint( node );595 596 444 return node; 597 445 } 598 446 599 447 virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) { 600 ++indent;601 os << "Virtual Cast of:" << std::endl << indent;602 safe_print( node->arg );603 os << std::endl << indent-1 << "... to:";604 if ( ! node->result ) {605 os << " unknown";606 } else {607 os << std::endl << indent;608 node->result->accept( *this );609 }610 --indent;611 postprint( node );612 613 448 return node; 614 449 } 615 450 616 451 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) { 617 ++indent;618 os << "Untyped Member Expression, with field: " << std::endl << indent;619 safe_print( node->member );620 os << indent-1 << "... from aggregate:" << std::endl << indent;621 safe_print( node->aggregate );622 --indent;623 postprint( node );624 625 452 return node; 626 453 } 627 454 628 455 virtual const ast::Expr * visit( const ast::MemberExpr * node ) { 629 ++indent;630 os << "Member Expression, with field:" << std::endl << indent;631 safe_print( node->member );632 os << std::endl << indent-1 << "... from aggregate:" << std::endl << indent;633 safe_print( node->aggregate );634 --indent;635 postprint( node );636 637 456 return node; 638 457 } 639 458 640 459 virtual const ast::Expr * visit( const ast::VariableExpr * node ) { 641 os << "Variable Expression: ";642 short_print( node->var );643 postprint( node );644 645 460 return node; 646 461 } 647 462 648 463 virtual const ast::Expr * visit( const ast::ConstantExpr * node ) { 649 os << "Constant Expression (" << node->rep;650 if ( node->result ) {651 os << ": ";652 node->result->accept( *this );653 }654 os << ")";655 postprint( node );656 657 464 return node; 658 465 } … … 759 566 760 567 virtual const ast::Type * visit( const ast::VoidType * node ) { 761 preprint( node );762 os << "void";763 568 return node; 764 569 } 765 570 766 571 virtual const ast::Type * visit( const ast::BasicType * node ) { 767 preprint( node );768 os << ast::BasicType::typeNames[ node->kind ];769 572 return node; 770 573 } 771 574 772 575 virtual const ast::Type * visit( const ast::PointerType * node ) { 773 preprint( node );774 if ( ! node->isArray() ) {775 os << "pointer to ";776 } else {777 os << "decayed ";778 if ( node->isStatic ) {779 os << "static ";780 }781 782 if ( node->isVarLen ) {783 os << "variable length array of ";784 } else if ( node->dimension ) {785 os << "array of ";786 node->dimension->accept( *this );787 os << " ";788 }789 }790 safe_print( node->base );791 792 576 return node; 793 577 } 794 578 795 579 virtual const ast::Type * visit( const ast::ArrayType * node ) { 796 preprint( node );797 if ( node->isStatic ) {798 os << "static ";799 }800 801 if ( node->isVarLen ) {802 os << "variable length array of ";803 } else if ( node->dimension ) {804 os << "array of ";805 } else {806 os << "open array of ";807 }808 809 safe_print( node->base );810 811 if ( node->dimension ) {812 os << " with dimension of ";813 node->dimension->accept( *this );814 }815 816 580 return node; 817 581 } 818 582 819 583 virtual const ast::Type * visit( const ast::ReferenceType * node ) { 820 preprint( node );821 os << "reference to ";822 safe_print( node->base );823 824 584 return node; 825 585 } 826 586 827 587 virtual const ast::Type * visit( const ast::QualifiedType * node ) { 828 preprint( node );829 ++indent;830 os << "Qualified Type:" << std::endl << indent;831 safe_print( node->parent );832 os << std::endl << indent;833 safe_print( node->child );834 os << std::endl;835 --indent;836 837 588 return node; 838 589 } 839 590 840 591 virtual const ast::Type * visit( const ast::FunctionType * node ) { 841 preprint( node );842 843 os << "function" << std::endl;844 if ( ! node->params.empty() ) {845 os << indent << "... with parameters" << std::endl;846 ++indent;847 printAll( node->params );848 if ( node->isVarArgs ) {849 os << indent << "and a variable number of other arguments" << std::endl;850 }851 --indent;852 } else if ( node->isVarArgs ) {853 os << indent+1 << "accepting unspecified arguments" << std::endl;854 }855 856 os << indent << "... returning";857 if ( node->returns.empty() ) {858 os << " nothing" << std::endl;859 } else {860 os << std::endl;861 ++indent;862 printAll( node->returns );863 --indent;864 }865 866 592 return node; 867 593 } 868 594 869 595 virtual const ast::Type * visit( const ast::StructInstType * node ) { 870 preprint( node );871 os << "instance of struct " << node->name;872 if ( node->base ) {873 os << " " << ( node->base->body ? "with" : "without" ) << " body";874 }875 print( node->params );876 877 596 return node; 878 597 } 879 598 880 599 virtual const ast::Type * visit( const ast::UnionInstType * node ) { 881 preprint( node );882 os << "instance of union " << node->name;883 if ( node->base ) {884 os << " " << ( node->base->body ? "with" : "without" ) << " body";885 }886 print( node->params );887 888 600 return node; 889 601 } 890 602 891 603 virtual const ast::Type * visit( const ast::EnumInstType * node ) { 892 preprint( node );893 os << "instance of enum " << node->name;894 if ( node->base ) {895 os << " " << ( node->base->body ? "with" : "without" ) << " body";896 }897 print( node->params );898 899 604 return node; 900 605 } 901 606 902 607 virtual const ast::Type * visit( const ast::TraitInstType * node ) { 903 preprint( node );904 os << "instance of trait " << node->name;905 print( node->params );906 907 608 return node; 908 609 } 909 610 910 611 virtual const ast::Type * visit( const ast::TypeInstType * node ) { 911 preprint( node );912 os << "instance of type " << node->name913 << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";914 print( node->params );915 916 612 return node; 917 613 } 918 614 919 615 virtual const ast::Type * visit( const ast::TupleType * node ) { 920 preprint( node );921 os << "tuple of types" << std::endl;922 ++indent;923 printAll( node->types );924 --indent;925 926 616 return node; 927 617 } 928 618 929 619 virtual const ast::Type * visit( const ast::TypeofType * node ) { 930 preprint( node );931 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }932 os << "type-of expression ";933 safe_print( node->expr );934 935 620 return node; 936 621 } 937 622 938 623 virtual const ast::Type * visit( const ast::VarArgsType * node ) { 939 preprint( node );940 os << "builtin var args pack";941 624 return node; 942 625 } 943 626 944 627 virtual const ast::Type * visit( const ast::ZeroType * node ) { 945 preprint( node );946 os << "zero_t";947 628 return node; 948 629 } 949 630 950 631 virtual const ast::Type * visit( const ast::OneType * node ) { 951 preprint( node );952 os << "one_t";953 632 return node; 954 633 } 955 634 956 635 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) { 957 preprint( node );958 os << "Global Scope Type";959 636 return node; 960 637 } … … 975 652 virtual const ast::Init * visit( const ast::SingleInit * node ) { 976 653 os << "Simple Initializer: "; 977 safe_print( node->value);654 node->value->accept( *this ); 978 655 return node; 979 656 } … … 1038 715 os << indent+1 << i.first << " -> "; 1039 716 indent += 2; 1040 safe_print( i.second);717 i.second->accept( *this ); 1041 718 indent -= 2; 1042 719 os << std::endl; … … 1046 723 os << indent+1 << i->first << " -> "; 1047 724 indent += 2; 1048 safe_print( i->second);725 i->second->accept( *this ); 1049 726 indent -= 2; 1050 727 os << std::endl;
Note:
See TracChangeset
for help on using the changeset viewer.