Changes in src/AST/Print.cpp [a7d50b6:94b1f718]
- File:
-
- 1 edited
-
src/AST/Print.cpp (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
ra7d50b6 r94b1f718 71 71 72 72 /// call to print short form. Incorporates features of safe_print() 73 void short_print( const ast:: Decl* n ) {73 void short_print( const ast::Node * n ) { 74 74 if ( ! n ) { undefined(); return; } 75 75 bool old_short = short_mode; short_mode = true; … … 77 77 short_mode = old_short; 78 78 } 79 79 80 80 81 static const char* Names[]; … … 132 133 case ast::Expr::InferUnion::Empty: return; 133 134 case ast::Expr::InferUnion::Slots: { 134 os << indent << "with " << inferred.data.resnSlots.size() 135 os << indent << "with " << inferred.data.resnSlots.size() 135 136 << " pending inference slots" << endl; 136 137 return; … … 152 153 153 154 void print( const ast::ParameterizedType::ForallList & forall ) { 154 if ( forall.empty() ) return; 155 if ( forall.empty() ) return; 155 156 os << "forall" << endl; 156 157 ++indent; … … 177 178 178 179 void print( const ast::AggregateDecl * node ) { 179 os << node->typeString() << " " << node->name; 180 181 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 180 os << node->typeString() << " " << node->name << ":"; 181 if ( node->linkage != Linkage::Cforall ) { 182 182 os << " " << Linkage::name( node->linkage ); 183 } 184 185 os << " " << (node->body ? "with" : "without") << " body"; 183 } // if 184 os << " with body : " << (node->body ? "yes " : "no "); 186 185 187 186 if ( ! node->params.empty() ) { … … 190 189 printAll( node->params ); 191 190 --indent; 192 } 193 194 if ( ! short_mode && ! node->members.empty() ) { 191 } // if 192 if ( ! node->members.empty() ) { 195 193 os << endl << indent << "... with members" << endl; 196 194 ++indent; 197 195 printAll( node->members ); 198 196 --indent; 199 } 200 201 if ( ! short_mode && ! node->attributes.empty() ) { 197 } // if 198 if ( ! node->attributes.empty() ) { 202 199 os << endl << indent << "... with attributes" << endl; 203 200 ++indent; 204 201 printAll( node->attributes ); 205 202 --indent; 206 } 207 203 } // if 208 204 os << endl; 209 205 } 210 206 211 void pr eprint( const ast::NamedTypeDecl * node ) {212 if ( ! node->name.empty() ) os << node->name << ": ";213 214 if ( ! short_mode &&node->linkage != Linkage::Cforall ) {207 void print( const ast::NamedTypeDecl * node ) { 208 if ( !node->name.empty() ) os << node->name << ": "; 209 210 if ( node->linkage != Linkage::Cforall ) { 215 211 os << Linkage::name( node->linkage ) << " "; 216 } 217 212 } // if 218 213 print( node->storage ); 219 214 os << node->typeString(); 220 221 215 if ( node->base ) { 222 216 os << " for "; … … 224 218 node->base->accept( *this ); 225 219 --indent; 226 } 227 220 } // if 228 221 if ( ! node->params.empty() ) { 229 222 os << endl << indent << "... with parameters" << endl; … … 231 224 printAll( node->params ); 232 225 --indent; 233 } 234 235 if ( ! short_mode && ! node->assertions.empty() ) { 226 } // if 227 if ( ! node->assertions.empty() ) { 236 228 os << endl << indent << "... with assertions" << endl; 237 229 ++indent; 238 230 printAll( node->assertions ); 239 231 --indent; 240 } 232 } // if 241 233 } 242 234 … … 273 265 public: 274 266 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) { 275 if ( ! node->name.empty() ) os << node->name << ": ";276 277 if ( ! short_mode &&node->linkage != Linkage::Cforall ) {267 if ( !node->name.empty() ) os << node->name << ": "; 268 269 if ( node->linkage != Linkage::Cforall ) { 278 270 os << Linkage::name( node->linkage ) << " "; 279 } 271 } // if 280 272 281 273 print( node->storage ); … … 285 277 } else { 286 278 os << "untyped entity"; 287 } 288 289 if ( ! short_mode && node->init ) { 290 ++indent; 279 } // if 280 281 if ( node->init ) { 291 282 os << " with initializer (" << ( 292 283 node->init->maybeConstructed 293 284 ? "maybe constructed" 294 285 : "not constructed" 295 ) << ")" << endl << indent; 286 ) << ")" << endl << indent+1; 287 288 ++indent; 296 289 node->init->accept( *this ); 297 290 --indent; 298 291 os << endl; 299 } 300 301 if ( ! short_mode && !node->attributes.empty() ) {292 } // if 293 294 if ( ! node->attributes.empty() ) { 302 295 os << endl << indent << "... with attributes:" << endl; 303 296 ++indent; … … 309 302 os << indent << " with bitfield width "; 310 303 node->bitfieldWidth->accept( *this ); 311 } 312 304 } // if 313 305 return node; 314 306 } 315 307 316 308 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) { 317 if ( !node->name.empty() ) os << node->name << ": "; 318 319 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 309 if ( !node->name.empty() ) { 310 os << node->name << ": "; 311 } // if 312 if ( node->linkage != Linkage::Cforall ) { 320 313 os << Linkage::name( node->linkage ) << " "; 321 } 322 323 if ( ! short_mode )printAll( node->attributes );314 } // if 315 316 printAll( node->attributes ); 324 317 325 318 print( node->storage ); … … 330 323 } else { 331 324 os << "untyped entity"; 332 } 333 334 if ( ! short_mode &&node->stmts ) {335 ++indent;336 os << " with body" << endl <<indent;325 } // if 326 327 if ( node->stmts ) { 328 os << indent << "... with body" << endl << indent+1; 329 ++indent; 337 330 node->stmts->accept( *this ); 338 331 --indent; 339 } 340 332 } // if 341 333 return node; 342 334 } … … 363 355 364 356 virtual const ast::Decl * visit( const ast::TypeDecl * node ) { 365 pr eprint( node );366 if ( ! short_mode &&node->init ) {357 print( node ); 358 if ( node->init ) { 367 359 os << endl << indent << "with type initializer: "; 368 360 ++indent; … … 370 362 --indent; 371 363 } 372 373 364 return node; 374 365 } 375 366 376 367 virtual const ast::Decl * visit( const ast::TypedefDecl * node ) { 377 pr eprint( node );368 print( node ); 378 369 return node; 379 370 } 380 371 381 372 virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) { 382 safe_print( node->stmt);373 node->stmt->accept( *this ); 383 374 return node; 384 375 } … … 387 378 os << "Static Assert with condition: "; 388 379 ++indent; 389 safe_print( node->cond ); 390 os << endl << indent-1 << "and message: "; 391 safe_print( node->msg ); 380 node->cond->accept( *this ); 381 --indent; 382 os << endl << indent << "and message: "; 383 ++indent; 384 node->msg->accept( *this ); 392 385 --indent; 393 386 os << endl; 394 395 387 return node; 396 388 } … … 602 594 603 595 virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) { 604 if ( node->target ) os << "Non-Local ";605 606 switch( node->kind ) {607 case ast::ExceptionKind::Terminate: os << "Terminate "; break;608 case ast::ExceptionKind::Resume: os << "Resume "; break;609 }610 611 ++indent;612 os << "Throw Statement, raising: ";613 safe_print( node->expr );614 if ( node->target ) {615 os << "... at: ";616 node->target->accept( *this );617 }618 --indent;619 620 596 return node; 621 597 } 622 598 623 599 virtual const ast::Stmt * visit( const ast::TryStmt * node ) { 624 ++indent;625 os << "Try Statement" << endl << indent-1626 << "... with block:" << endl << indent;627 safe_print( node->body );628 629 os << indent-1 << "... and handlers:" << endl;630 for ( const ast::CatchStmt * stmt : node->handlers ) {631 os << indent;632 stmt->accept( *this );633 }634 635 if ( node->finally ) {636 os << indent-1 << "... and finally:" << endl << indent;637 node->finally->accept( *this );638 }639 --indent;640 641 600 return node; 642 601 } 643 602 644 603 virtual const ast::Stmt * visit( const ast::CatchStmt * node ) { 645 os << "Catch ";646 switch ( node->kind ) {647 case ast::ExceptionKind::Terminate: os << "Terminate "; break;648 case ast::ExceptionKind::Resume: os << "Resume "; break;649 }650 os << "Statement" << endl << indent;651 652 ++indent;653 os << "... catching: ";654 short_print( node->decl );655 os << endl;656 657 if ( node->cond ) {658 os << indent-1 << "... with conditional:" << endl << indent;659 node->cond->accept( *this );660 }661 662 os << indent-1 << "... with block:" << endl << indent;663 safe_print( node->body );664 --indent;665 666 604 return node; 667 605 } 668 606 669 607 virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) { 670 os << "Finally Statement" << endl;671 os << indent << "... with block:" << endl;672 ++indent;673 os << indent;674 safe_print( node->body );675 --indent;676 677 608 return node; 678 609 } 679 610 680 611 virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) { 681 os << "Waitfor Statement" << endl;682 indent += 2;683 for( const auto & clause : node->clauses ) {684 os << indent-1 << "target function: ";685 safe_print( clause.target.func );686 687 if ( ! clause.target.args.empty() ) {688 os << endl << indent-1 << "... with arguments:" << endl;689 for( const ast::Expr * arg : clause.target.args ) {690 arg->accept( *this );691 }692 }693 694 if ( clause.stmt ) {695 os << indent-1 << "... with statment:" << endl;696 clause.stmt->accept( *this );697 }698 699 if ( clause.cond ) {700 os << indent-1 << "... with condition:" << endl;701 clause.cond->accept( *this );702 }703 }704 705 if ( node->timeout.time ) {706 os << indent-1 << "timeout of:" << endl;707 node->timeout.time->accept( *this );708 709 if ( node->timeout.stmt ) {710 os << indent-1 << "... with statment:" << endl;711 node->timeout.stmt->accept( *this );712 }713 714 if ( node->timeout.cond ) {715 os << indent-1 << "... with condition:" << endl;716 node->timeout.cond->accept( *this );717 }718 }719 720 if ( node->orElse.stmt ) {721 os << indent-1 << "else:" << endl;722 node->orElse.stmt->accept( *this );723 724 if ( node->orElse.cond ) {725 os << indent-1 << "... with condition:" << endl;726 node->orElse.cond->accept( *this );727 }728 }729 indent -= 2;730 731 612 return node; 732 613 } 733 614 734 615 virtual const ast::Stmt * visit( const ast::WithStmt * node ) { 735 os << "With statement" << endl;736 os << indent << "... with expressions:" << endl;737 ++indent;738 printAll( node->exprs );739 os << indent-1 << "... with statement:" << endl << indent;740 safe_print( node->stmt );741 --indent;742 743 616 return node; 744 617 } … … 752 625 753 626 virtual const ast::Stmt * visit( const ast::DeclStmt * node ) { 754 os << "Declaration of ";755 safe_print( node->decl );756 757 627 return node; 758 628 } 759 629 760 630 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) { 761 os << "Implicit Ctor Dtor Statement" << endl;762 os << indent << "... with Ctor/Dtor: ";763 ++indent;764 safe_print( node->callStmt );765 --indent;766 os << endl;767 768 631 return node; 769 632 } … … 800 663 os << "Name: " << node->name; 801 664 postprint( node ); 802 665 803 666 return node; 804 667 } … … 931 794 --indent; 932 795 postprint( node ); 933 796 934 797 return node; 935 798 } … … 1015 878 if ( node->operand ) node->operand->accept( *this ); 1016 879 --indent; 1017 880 1018 881 return node; 1019 882 } … … 1093 956 --indent; 1094 957 postprint( node ); 1095 958 1096 959 return node; 1097 960 } … … 1292 1155 virtual const ast::Type * visit( const ast::FunctionType * node ) { 1293 1156 preprint( node ); 1294 1157 1295 1158 os << "function" << endl; 1296 1159 if ( ! node->params.empty() ) { … … 1362 1225 virtual const ast::Type * visit( const ast::TypeInstType * node ) { 1363 1226 preprint( node ); 1364 os << "instance of type " << node->name 1227 os << "instance of type " << node->name 1365 1228 << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)"; 1366 1229 print( node->params ); … … 1512 1375 } 1513 1376 1514 void printShort( ostream & os, const ast:: Decl* node, Indenter indent ) {1377 void printShort( ostream & os, const ast::Node * node, Indenter indent ) { 1515 1378 Printer printer { os, indent, true }; 1516 1379 node->accept(printer);
Note:
See TracChangeset
for help on using the changeset viewer.