Changes in / [1259c35:0c6900b]
- Location:
- src/AST
- Files:
-
- 5 edited
-
Convert.cpp (modified) (4 diffs)
-
Print.cpp (modified) (16 diffs)
-
Print.hpp (modified) (2 diffs)
-
Stmt.hpp (modified) (3 diffs)
-
porting.md (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r1259c35 r0c6900b 397 397 ThrowStmt::Kind kind; 398 398 switch (node->kind) { 399 case ast:: ExceptionKind::Terminate:399 case ast::ThrowStmt::Terminate: 400 400 kind = ThrowStmt::Terminate; 401 401 break; 402 case ast:: ExceptionKind::Resume:402 case ast::ThrowStmt::Resume: 403 403 kind = ThrowStmt::Resume; 404 404 break; … … 429 429 CatchStmt::Kind kind; 430 430 switch (node->kind) { 431 case ast:: ExceptionKind::Terminate:431 case ast::CatchStmt::Terminate: 432 432 kind = CatchStmt::Terminate; 433 433 break; 434 case ast:: ExceptionKind::Resume:434 case ast::CatchStmt::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:: ExceptionKind kind;1737 ast::ThrowStmt::Kind kind; 1738 1738 switch (old->kind) { 1739 1739 case ThrowStmt::Terminate: 1740 kind = ast:: ExceptionKind::Terminate;1740 kind = ast::ThrowStmt::Terminate; 1741 1741 break; 1742 1742 case ThrowStmt::Resume: 1743 kind = ast:: ExceptionKind::Resume;1743 kind = ast::ThrowStmt::Resume; 1744 1744 break; 1745 1745 default: … … 1771 1771 virtual void visit( CatchStmt * old ) override final { 1772 1772 if ( inCache( old ) ) return; 1773 ast:: ExceptionKind kind;1773 ast::CatchStmt::Kind kind; 1774 1774 switch (old->kind) { 1775 1775 case CatchStmt::Terminate: 1776 kind = ast:: ExceptionKind::Terminate;1776 kind = ast::CatchStmt::Terminate; 1777 1777 break; 1778 1778 case CatchStmt::Resume: 1779 kind = ast:: ExceptionKind::Resume;1779 kind = ast::CatchStmt::Resume; 1780 1780 break; 1781 1781 default: -
src/AST/Print.cpp
r1259c35 r0c6900b 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[]; … … 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 } … … 1508 1371 } 1509 1372 1510 void printShort( ostream & os, const ast:: Decl* node, Indenter indent ) {1373 void printShort( ostream & os, const ast::Node * node, Indenter indent ) { 1511 1374 Printer printer { os, indent, true }; 1512 1375 node->accept(printer); -
src/AST/Print.hpp
r1259c35 r0c6900b 23 23 namespace ast { 24 24 25 class Decl;26 27 /// Print a node with the given indenter28 25 void print( std::ostream & os, const ast::Node * node, Indenter indent = {} ); 29 26 … … 32 29 } 33 30 34 /// Print a declaration in its short form35 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 } );39 31 } 40 41 } -
src/AST/Stmt.hpp
r1259c35 r0c6900b 268 268 }; 269 269 270 /// Kind of exception271 enum ExceptionKind { Terminate, Resume };272 273 270 /// Throw statement `throw ...` 274 271 class ThrowStmt final : public Stmt { 275 272 public: 273 enum Kind { Terminate, Resume }; 274 276 275 ptr<Expr> expr; 277 276 ptr<Expr> target; 278 ExceptionKind kind; 279 280 ThrowStmt( 281 const CodeLocation & loc, ExceptionKind kind, const Expr * expr, const Expr * target, 277 Kind kind; 278 279 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target, 282 280 std::vector<Label> && labels = {} ) 283 281 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} … … 296 294 ptr<FinallyStmt> finally; 297 295 298 TryStmt( 299 const CodeLocation & loc, const CompoundStmt * body, 296 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 300 297 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 301 298 std::vector<Label> && labels = {} ) … … 311 308 class CatchStmt final : public Stmt { 312 309 public: 310 enum Kind { Terminate, Resume }; 311 313 312 ptr<Decl> decl; 314 313 ptr<Expr> cond; 315 314 ptr<Stmt> body; 316 ExceptionKind kind; 317 318 CatchStmt( 319 const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 315 Kind kind; 316 317 CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond, 320 318 const Stmt * body, std::vector<Label> && labels = {} ) 321 319 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} -
src/AST/porting.md
r1259c35 r0c6900b 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 40 * `Declaration::printShort` is alsointegrated39 `N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class 40 * **TODO** `Declaration::printShort` should also be 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 139 142 `Expr` 140 143 * Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version … … 148 151 * `function` => `func` 149 152 * removed `begin_args()` in favour of `args.begin()` 153 154 `MemberExpr` 155 * **TODO** port setup of `result` in constructor 150 156 151 157 `ConstantExpr` … … 198 204 `TryStmt` 199 205 * `block` -> `body` and `finallyBlock` -> `finally` 200 201 `ThrowStmt` `CatchStmt`202 * moved `Kind` enums to shared `ast::ExceptionKind` enum203 206 204 207 `FinallyStmt`
Note:
See TracChangeset
for help on using the changeset viewer.