Changes in / [0c6900b:1259c35]
- Location:
- src/AST
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r0c6900b r1259c35 397 397 ThrowStmt::Kind kind; 398 398 switch (node->kind) { 399 case ast:: ThrowStmt::Terminate:399 case ast::ExceptionKind::Terminate: 400 400 kind = ThrowStmt::Terminate; 401 401 break; 402 case ast:: ThrowStmt::Resume:402 case ast::ExceptionKind::Resume: 403 403 kind = ThrowStmt::Resume; 404 404 break; … … 429 429 CatchStmt::Kind kind; 430 430 switch (node->kind) { 431 case ast:: CatchStmt::Terminate:431 case ast::ExceptionKind::Terminate: 432 432 kind = CatchStmt::Terminate; 433 433 break; 434 case ast:: CatchStmt::Resume:434 case ast::ExceptionKind::Resume: 435 435 kind = CatchStmt::Resume; 436 436 break; … … 1735 1735 virtual void visit( ThrowStmt * old ) override final { 1736 1736 if ( inCache( old ) ) return; 1737 ast:: ThrowStmt::Kind kind;1737 ast::ExceptionKind kind; 1738 1738 switch (old->kind) { 1739 1739 case ThrowStmt::Terminate: 1740 kind = ast:: ThrowStmt::Terminate;1740 kind = ast::ExceptionKind::Terminate; 1741 1741 break; 1742 1742 case ThrowStmt::Resume: 1743 kind = ast:: ThrowStmt::Resume;1743 kind = ast::ExceptionKind::Resume; 1744 1744 break; 1745 1745 default: … … 1771 1771 virtual void visit( CatchStmt * old ) override final { 1772 1772 if ( inCache( old ) ) return; 1773 ast:: CatchStmt::Kind kind;1773 ast::ExceptionKind kind; 1774 1774 switch (old->kind) { 1775 1775 case CatchStmt::Terminate: 1776 kind = ast:: CatchStmt::Terminate;1776 kind = ast::ExceptionKind::Terminate; 1777 1777 break; 1778 1778 case CatchStmt::Resume: 1779 kind = ast:: CatchStmt::Resume;1779 kind = ast::ExceptionKind::Resume; 1780 1780 break; 1781 1781 default: -
src/AST/Print.cpp
r0c6900b r1259c35 71 71 72 72 /// call to print short form. Incorporates features of safe_print() 73 void short_print( const ast:: Node* n ) {73 void short_print( const ast::Decl * 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 80 79 81 80 static const char* Names[]; … … 178 177 179 178 void print( const ast::AggregateDecl * node ) { 180 os << node->typeString() << " " << node->name << ":"; 181 if ( node->linkage != Linkage::Cforall ) { 179 os << node->typeString() << " " << node->name; 180 181 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 182 182 os << " " << Linkage::name( node->linkage ); 183 } // if 184 os << " with body : " << (node->body ? "yes " : "no "); 183 } 184 185 os << " " << (node->body ? "with" : "without") << " body"; 185 186 186 187 if ( ! node->params.empty() ) { … … 189 190 printAll( node->params ); 190 191 --indent; 191 } // if 192 if ( ! node->members.empty() ) { 192 } 193 194 if ( ! short_mode && ! node->members.empty() ) { 193 195 os << endl << indent << "... with members" << endl; 194 196 ++indent; 195 197 printAll( node->members ); 196 198 --indent; 197 } // if 198 if ( ! node->attributes.empty() ) { 199 } 200 201 if ( ! short_mode && ! node->attributes.empty() ) { 199 202 os << endl << indent << "... with attributes" << endl; 200 203 ++indent; 201 204 printAll( node->attributes ); 202 205 --indent; 203 } // if 206 } 207 204 208 os << endl; 205 209 } 206 210 207 void pr int( const ast::NamedTypeDecl * node ) {208 if ( ! node->name.empty() ) os << node->name << ": ";209 210 if ( node->linkage != Linkage::Cforall ) {211 void preprint( const ast::NamedTypeDecl * node ) { 212 if ( ! node->name.empty() ) os << node->name << ": "; 213 214 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 211 215 os << Linkage::name( node->linkage ) << " "; 212 } // if 216 } 217 213 218 print( node->storage ); 214 219 os << node->typeString(); 220 215 221 if ( node->base ) { 216 222 os << " for "; … … 218 224 node->base->accept( *this ); 219 225 --indent; 220 } // if 226 } 227 221 228 if ( ! node->params.empty() ) { 222 229 os << endl << indent << "... with parameters" << endl; … … 224 231 printAll( node->params ); 225 232 --indent; 226 } // if 227 if ( ! node->assertions.empty() ) { 233 } 234 235 if ( ! short_mode && ! node->assertions.empty() ) { 228 236 os << endl << indent << "... with assertions" << endl; 229 237 ++indent; 230 238 printAll( node->assertions ); 231 239 --indent; 232 } // if240 } 233 241 } 234 242 … … 265 273 public: 266 274 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) { 267 if ( ! node->name.empty() ) os << node->name << ": ";268 269 if ( node->linkage != Linkage::Cforall ) {275 if ( ! node->name.empty() ) os << node->name << ": "; 276 277 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 270 278 os << Linkage::name( node->linkage ) << " "; 271 } // if279 } 272 280 273 281 print( node->storage ); … … 277 285 } else { 278 286 os << "untyped entity"; 279 } // if 280 281 if ( node->init ) { 287 } 288 289 if ( ! short_mode && node->init ) { 290 ++indent; 282 291 os << " with initializer (" << ( 283 292 node->init->maybeConstructed 284 293 ? "maybe constructed" 285 294 : "not constructed" 286 ) << ")" << endl << indent+1; 287 288 ++indent; 295 ) << ")" << endl << indent; 289 296 node->init->accept( *this ); 290 297 --indent; 291 298 os << endl; 292 } // if293 294 if ( ! node->attributes.empty() ) {299 } 300 301 if ( ! short_mode && ! node->attributes.empty() ) { 295 302 os << endl << indent << "... with attributes:" << endl; 296 303 ++indent; … … 302 309 os << indent << " with bitfield width "; 303 310 node->bitfieldWidth->accept( *this ); 304 } // if 311 } 312 305 313 return node; 306 314 } 307 315 308 316 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) { 309 if ( !node->name.empty() ) { 310 os << node->name << ": "; 311 } // if 312 if ( node->linkage != Linkage::Cforall ) { 317 if ( !node->name.empty() ) os << node->name << ": "; 318 319 if ( ! short_mode && node->linkage != Linkage::Cforall ) { 313 320 os << Linkage::name( node->linkage ) << " "; 314 } // if315 316 printAll( node->attributes );321 } 322 323 if ( ! short_mode ) printAll( node->attributes ); 317 324 318 325 print( node->storage ); … … 323 330 } else { 324 331 os << "untyped entity"; 325 } // if326 327 if ( node->stmts ) {328 os << indent << "... with body" << endl << indent+1;329 ++indent;332 } 333 334 if ( ! short_mode && node->stmts ) { 335 ++indent; 336 os << " with body" << endl << indent; 330 337 node->stmts->accept( *this ); 331 338 --indent; 332 } // if 339 } 340 333 341 return node; 334 342 } … … 355 363 356 364 virtual const ast::Decl * visit( const ast::TypeDecl * node ) { 357 pr int( node );358 if ( node->init ) {365 preprint( node ); 366 if ( ! short_mode && node->init ) { 359 367 os << endl << indent << "with type initializer: "; 360 368 ++indent; … … 362 370 --indent; 363 371 } 372 364 373 return node; 365 374 } 366 375 367 376 virtual const ast::Decl * visit( const ast::TypedefDecl * node ) { 368 pr int( node );377 preprint( node ); 369 378 return node; 370 379 } 371 380 372 381 virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) { 373 node->stmt->accept( *this);382 safe_print( node->stmt ); 374 383 return node; 375 384 } … … 378 387 os << "Static Assert with condition: "; 379 388 ++indent; 380 node->cond->accept( *this ); 381 --indent; 382 os << endl << indent << "and message: "; 383 ++indent; 384 node->msg->accept( *this ); 389 safe_print( node->cond ); 390 os << endl << indent-1 << "and message: "; 391 safe_print( node->msg ); 385 392 --indent; 386 393 os << endl; 394 387 395 return node; 388 396 } … … 594 602 595 603 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 596 620 return node; 597 621 } 598 622 599 623 virtual const ast::Stmt * visit( const ast::TryStmt * node ) { 624 ++indent; 625 os << "Try Statement" << endl << indent-1 626 << "... 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 600 641 return node; 601 642 } 602 643 603 644 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 604 666 return node; 605 667 } 606 668 607 669 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 608 677 return node; 609 678 } 610 679 611 680 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 612 731 return node; 613 732 } 614 733 615 734 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 616 743 return node; 617 744 } … … 625 752 626 753 virtual const ast::Stmt * visit( const ast::DeclStmt * node ) { 754 os << "Declaration of "; 755 safe_print( node->decl ); 756 627 757 return node; 628 758 } 629 759 630 760 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 631 768 return node; 632 769 } … … 1371 1508 } 1372 1509 1373 void printShort( ostream & os, const ast:: Node* node, Indenter indent ) {1510 void printShort( ostream & os, const ast::Decl * node, Indenter indent ) { 1374 1511 Printer printer { os, indent, true }; 1375 1512 node->accept(printer); -
src/AST/Print.hpp
r0c6900b r1259c35 23 23 namespace ast { 24 24 25 class Decl; 26 27 /// Print a node with the given indenter 25 28 void print( std::ostream & os, const ast::Node * node, Indenter indent = {} ); 26 29 … … 29 32 } 30 33 34 /// Print a declaration in its short form 35 void printShort( std::ostream & os, const ast::Decl * node, Indenter indent = {} ); 36 37 inline void printShort( std::ostream & os, const ast::Decl * node, unsigned int indent ) { 38 printShort( os, node, Indenter{ Indenter::tabsize, indent } ); 31 39 } 40 41 } -
src/AST/Stmt.hpp
r0c6900b r1259c35 268 268 }; 269 269 270 /// Kind of exception 271 enum ExceptionKind { Terminate, Resume }; 272 270 273 /// Throw statement `throw ...` 271 274 class ThrowStmt final : public Stmt { 272 275 public: 273 enum Kind { Terminate, Resume };274 275 276 ptr<Expr> expr; 276 277 ptr<Expr> target; 277 Kind kind; 278 279 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target, 278 ExceptionKind kind; 279 280 ThrowStmt( 281 const CodeLocation & loc, ExceptionKind kind, const Expr * expr, const Expr * target, 280 282 std::vector<Label> && labels = {} ) 281 283 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} … … 294 296 ptr<FinallyStmt> finally; 295 297 296 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 298 TryStmt( 299 const CodeLocation & loc, const CompoundStmt * body, 297 300 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 298 301 std::vector<Label> && labels = {} ) … … 308 311 class CatchStmt final : public Stmt { 309 312 public: 310 enum Kind { Terminate, Resume };311 312 313 ptr<Decl> decl; 313 314 ptr<Expr> cond; 314 315 ptr<Stmt> body; 315 Kind kind; 316 317 CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond, 316 ExceptionKind kind; 317 318 CatchStmt( 319 const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 318 320 const Stmt * body, std::vector<Label> && labels = {} ) 319 321 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} -
src/AST/porting.md
r0c6900b r1259c35 37 37 * all subclass constructors must fill it; by convention, from their first argument 38 38 39 `N->print(std::ostream&)` is a visitor now , port these methods to `ast::Print` class40 * **TODO** `Declaration::printShort` should also beintegrated39 `N->print(std::ostream&)` is a visitor now 40 * `Declaration::printShort` is also integrated 41 41 42 42 `clone` is private to `Node` now … … 137 137 * `parameters` => `params` 138 138 139 `EnumDecl`140 * **TODO** rebuild `eval` for new AST (re: `valueOf` implementation)141 142 139 `Expr` 143 140 * Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version … … 151 148 * `function` => `func` 152 149 * removed `begin_args()` in favour of `args.begin()` 153 154 `MemberExpr`155 * **TODO** port setup of `result` in constructor156 150 157 151 `ConstantExpr` … … 204 198 `TryStmt` 205 199 * `block` -> `body` and `finallyBlock` -> `finally` 200 201 `ThrowStmt` `CatchStmt` 202 * moved `Kind` enums to shared `ast::ExceptionKind` enum 206 203 207 204 `FinallyStmt`
Note: See TracChangeset
for help on using the changeset viewer.