- Timestamp:
- May 16, 2019, 5:25:40 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 246c245
- Parents:
- acd80b4
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
racd80b4 r6f8e87d 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu May 16 17:21:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 74 74 ast::Node * node; 75 75 76 // Local Utilities: 77 78 template<typename NewT, typename OldT> 79 NewT * getAccept1( OldT old ) { 80 old->accept(*this); 81 return strict_dynamic_cast< NewT * >( node ); 82 } 83 84 # define GET_ACCEPT_1(child, type) \ 85 getAccept1< ast::type, decltype( old->child ) >( old->child ) 86 87 template<typename NewT, typename OldC> 88 std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) { 89 std::vector< ast::ptr<NewT> > ret; 90 ret.reserve( old.size() ); 91 for ( auto a : old ) { 92 a->accept( *this ); 93 ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); 94 } 95 return ret; 96 } 97 98 # define GET_ACCEPT_V(child, type) \ 99 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 100 101 ast::Label make_label(Label* old) { 102 return ast::Label( 103 old->labelled->location, 104 old->name, 105 GET_ACCEPT_V(attributes, Attribute) 106 ); 107 } 108 76 109 template<template <class...> class C> 77 110 C<ast::Label> make_labels(C<Label> olds) { 78 111 C<ast::Label> ret; 79 for(auto oldn : olds) { 80 auto old = &oldn; // to reuse the MACRO 81 ACCEPT_N(attr, attributes, Attribute) 82 ast::Label l( 83 {}, 84 old->get_name(), 85 to<std::vector>::from( std::move( attr ) ) 86 ); 87 ret.push_back( l ); 112 for (auto oldn : olds) { 113 ret.push_back( make_label( &oldn ) ); 88 114 } 89 115 return ret; 90 116 } 117 118 # define GET_LABELS_V(labels) \ 119 to<std::vector>::from( make_labels( std::move( labels ) ) ) 120 121 // Now all the visit functions: 91 122 92 123 virtual void visit( ObjectDecl * old ) override final { … … 258 289 259 290 virtual void visit( ExprStmt * old ) override final { 260 ACCEPT_1(expr, expr, Expr) 261 auto stmt = new ast::ExprStmt( 262 old->location, 263 expr 264 ); 265 stmt->labels = to<std::vector>::from( make_labels( std::move( old->labels ) ) ); 291 this->node = new ast::ExprStmt( 292 old->location, 293 GET_ACCEPT_1(expr, Expr), 294 GET_LABELS_V(old->labels) 295 ); 296 } 297 298 virtual void visit( AsmStmt * old ) override final { 299 this->node = new ast::AsmStmt( 300 old->location, 301 old->voltile, 302 GET_ACCEPT_1(instruction, Expr), 303 GET_ACCEPT_V(output, Expr), 304 GET_ACCEPT_V(input, Expr), 305 GET_ACCEPT_V(clobber, ConstantExpr), 306 GET_LABELS_V(old->gotolabels), 307 GET_LABELS_V(old->labels) 308 ); 309 } 310 311 virtual void visit( DirectiveStmt * old ) override final { 312 this->node = new ast::DirectiveStmt( 313 old->location, 314 old->directive, 315 GET_LABELS_V(old->labels) 316 ); 317 } 318 319 virtual void visit( IfStmt * old ) override final { 320 this->node = new ast::IfStmt( 321 old->location, 322 GET_ACCEPT_1(condition, Expr), 323 GET_ACCEPT_1(thenPart, Stmt), 324 GET_ACCEPT_1(elsePart, Stmt), 325 GET_ACCEPT_V(initialization, Stmt), 326 GET_LABELS_V(old->labels) 327 ); 328 } 329 330 virtual void visit( SwitchStmt * old ) override final { 331 this->node = new ast::SwitchStmt( 332 old->location, 333 GET_ACCEPT_1(condition, Expr), 334 GET_ACCEPT_V(statements, Stmt), 335 GET_LABELS_V(old->labels) 336 ); 337 } 338 339 virtual void visit( CaseStmt * old ) override final { 340 this->node = new ast::CaseStmt( 341 old->location, 342 GET_ACCEPT_1(condition, Expr), 343 GET_ACCEPT_V(stmts, Stmt), 344 GET_LABELS_V(old->labels) 345 ); 346 } 347 348 virtual void visit( WhileStmt * old ) override final { 349 this->node = new ast::WhileStmt( 350 old->location, 351 GET_ACCEPT_1(condition, Expr), 352 GET_ACCEPT_1(body, Stmt), 353 GET_ACCEPT_V(initialization, Stmt), 354 old->isDoWhile, 355 GET_LABELS_V(old->labels) 356 ); 357 } 358 359 virtual void visit( ForStmt * old ) override final { 360 this->node = new ast::ForStmt( 361 old->location, 362 GET_ACCEPT_V(initialization, Stmt), 363 GET_ACCEPT_1(condition, Expr), 364 GET_ACCEPT_1(increment, Expr), 365 GET_ACCEPT_1(body, Stmt), 366 GET_LABELS_V(old->labels) 367 ); 368 } 369 370 virtual void visit( BranchStmt * old ) override final { 371 if (old->computedTarget) { 372 this->node = new ast::BranchStmt( 373 old->location, 374 GET_ACCEPT_1(computedTarget, Expr), 375 GET_LABELS_V(old->labels) 376 ); 377 } else { 378 ast::BranchStmt::Kind kind; 379 switch (old->type) { 380 #define CASE(n) \ 381 case BranchStmt::n: \ 382 kind = ast::BranchStmt::n; \ 383 break 384 CASE(Goto); 385 CASE(Break); 386 CASE(Continue); 387 CASE(FallThrough); 388 CASE(FallThroughDefault); 389 #undef CASE 390 } 391 392 Label label = old->originalTarget; 393 auto stmt = new ast::BranchStmt( 394 old->location, 395 kind, 396 make_label(&label), 397 GET_LABELS_V(old->labels) 398 ); 399 stmt->target = make_label(&old->target); 400 this->node = stmt; 401 } 402 } 403 404 virtual void visit( ReturnStmt * old ) override final { 405 this->node = new ast::ReturnStmt( 406 old->location, 407 GET_ACCEPT_1(expr, Expr), 408 GET_LABELS_V(old->labels) 409 ); 410 } 411 412 virtual void visit( ThrowStmt * old ) override final { 413 ast::ThrowStmt::Kind kind; 414 switch (old->kind) { 415 case ThrowStmt::Terminate: 416 kind = ast::ThrowStmt::Terminate; 417 break; 418 case ThrowStmt::Resume: 419 kind = ast::ThrowStmt::Resume; 420 break; 421 } 422 423 this->node = new ast::ThrowStmt( 424 old->location, 425 kind, 426 GET_ACCEPT_1(expr, Expr), 427 GET_ACCEPT_1(target, Expr), 428 GET_LABELS_V(old->labels) 429 ); 430 } 431 432 virtual void visit( TryStmt * old ) override final { 433 this->node = new ast::TryStmt( 434 old->location, 435 GET_ACCEPT_1(block, CompoundStmt), 436 GET_ACCEPT_V(handlers, CatchStmt), 437 GET_ACCEPT_1(finallyBlock, FinallyStmt), 438 GET_LABELS_V(old->labels) 439 ); 440 } 441 442 virtual void visit( CatchStmt * old ) override final { 443 ast::CatchStmt::Kind kind; 444 switch (old->kind) { 445 case CatchStmt::Terminate: 446 kind = ast::CatchStmt::Terminate; 447 break; 448 case CatchStmt::Resume: 449 kind = ast::CatchStmt::Resume; 450 break; 451 } 452 453 this->node = new ast::CatchStmt( 454 old->location, 455 kind, 456 GET_ACCEPT_1(decl, Decl), 457 GET_ACCEPT_1(cond, Expr), 458 GET_ACCEPT_1(body, Stmt), 459 GET_LABELS_V(old->labels) 460 ); 461 } 462 463 virtual void visit( FinallyStmt * old ) override final { 464 this->node = new ast::FinallyStmt( 465 old->location, 466 GET_ACCEPT_1(block, CompoundStmt), 467 GET_LABELS_V(old->labels) 468 ); 469 } 470 471 virtual void visit( WaitForStmt * old ) override final { 472 ast::WaitForStmt * stmt = new ast::WaitForStmt( 473 old->location, 474 GET_LABELS_V(old->labels) 475 ); 476 477 stmt->clauses.reserve( old->clauses.size() ); 478 for (size_t i = 0 ; i < old->clauses.size() ; ++i) { 479 stmt->clauses.push_back({ 480 ast::WaitForStmt::Target{ 481 GET_ACCEPT_1(clauses[i].target.function, Expr), 482 GET_ACCEPT_V(clauses[i].target.arguments, Expr) 483 }, 484 GET_ACCEPT_1(clauses[i].statement, Stmt), 485 GET_ACCEPT_1(clauses[i].condition, Expr) 486 }); 487 } 488 stmt->timeout = { 489 GET_ACCEPT_1(timeout.time, Expr), 490 GET_ACCEPT_1(timeout.statement, Stmt), 491 GET_ACCEPT_1(timeout.condition, Expr), 492 }; 493 stmt->orElse = { 494 GET_ACCEPT_1(timeout.statement, Stmt), 495 GET_ACCEPT_1(timeout.condition, Expr), 496 }; 266 497 267 498 this->node = stmt; 268 499 } 269 500 270 virtual void visit( AsmStmt * ) override final { 271 272 } 273 274 virtual void visit( DirectiveStmt * ) override final { 275 276 } 277 278 virtual void visit( IfStmt * ) override final { 279 280 } 281 282 virtual void visit( WhileStmt * ) override final { 283 284 } 285 286 virtual void visit( ForStmt * ) override final { 287 288 } 289 290 virtual void visit( SwitchStmt * ) override final { 291 292 } 293 294 virtual void visit( CaseStmt * ) override final { 295 296 } 297 298 virtual void visit( BranchStmt * ) override final { 299 300 } 301 302 virtual void visit( ReturnStmt * ) override final { 303 304 } 305 306 virtual void visit( ThrowStmt * ) override final { 307 308 } 309 310 virtual void visit( TryStmt * ) override final { 311 312 } 313 314 virtual void visit( CatchStmt * ) override final { 315 316 } 317 318 virtual void visit( FinallyStmt * ) override final { 319 320 } 321 322 virtual void visit( WaitForStmt * ) override final { 323 324 } 325 326 virtual void visit( WithStmt * ) override final { 327 501 virtual void visit( WithStmt * old ) override final { 502 this->node = new ast::WithStmt( 503 old->location, 504 GET_ACCEPT_V(exprs, Expr), 505 GET_ACCEPT_1(stmt, Stmt), 506 GET_LABELS_V(old->labels) 507 ); 328 508 } 329 509 330 510 virtual void visit( NullStmt * old ) override final { 331 auto stmt = new ast::NullStmt( 332 old->location, 333 to<std::vector>::from( make_labels( std::move( old->labels ) ) ) 334 ); 335 336 this->node = stmt; 337 } 338 339 virtual void visit( DeclStmt * ) override final { 340 341 } 342 343 virtual void visit( ImplicitCtorDtorStmt * ) override final { 344 511 this->node = new ast::NullStmt( 512 old->location, 513 GET_LABELS_V(old->labels) 514 ); 515 } 516 517 virtual void visit( DeclStmt * old ) override final { 518 this->node = new ast::DeclStmt( 519 old->location, 520 GET_ACCEPT_1(decl, Decl), 521 GET_LABELS_V(old->labels) 522 ); 523 } 524 525 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 526 this->node = new ast::ImplicitCtorDtorStmt( 527 old->location, 528 GET_ACCEPT_1(callStmt, Stmt), 529 GET_LABELS_V(old->labels) 530 ); 345 531 } 346 532 … … 598 784 } 599 785 }; 786 787 #undef GET_LABELS_V 788 #undef GET_ACCEPT_V 789 #undef GET_ACCEPT_1 600 790 601 791 #undef ACCEPT_N -
src/AST/Stmt.hpp
racd80b4 r6f8e87d 10 10 // Created On : Wed May 8 13:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 1 5 16:01:00 201913 // Update Count : 212 // Last Modified On : Wed May 16 12:20:00 2019 13 // Update Count : 3 14 14 // 15 15 … … 86 86 ptr<Expr> expr; 87 87 88 ExprStmt( const CodeLocation & loc, const Expr * e ) : Stmt(loc), expr(e) {} 88 ExprStmt( const CodeLocation& loc, const Expr* e, std::vector<Label>&& labels = {} ) 89 : Stmt(loc, std::move(labels)), expr(e) {} 89 90 90 91 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
Note: See TracChangeset
for help on using the changeset viewer.