Changeset b5fed34
- Timestamp:
- May 23, 2019, 12:07:20 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:
- effe5b0
- Parents:
- d7aa12c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
rd7aa12c rb5fed34 474 474 } 475 475 476 //template<typename CallExpr>477 //const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) {478 //if( pos >= call->args.size() ) {479 //assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.",480 //pos, toString( call ).c_str() );481 //}482 //for ( const ast::Expr * arg : call->args ) {483 //if ( pos == 0 ) return arg;484 //--pos;485 //}486 //assert( false );487 //}476 template<typename CallExpr> 477 const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) { 478 if( pos >= call->args.size() ) { 479 assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.", 480 pos, toString( call ).c_str() ); 481 } 482 for ( const ast::Expr * arg : call->args ) { 483 if ( pos == 0 ) return arg; 484 --pos; 485 } 486 assert( false ); 487 } 488 488 } 489 489 … … 506 506 } 507 507 } 508 508 509 const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ) { 509 (void)call; 510 (void)pos; 511 #warning unimplemented; needs to build AST/Expr.cpp 512 assertf(false, "unimplemented; needs to build AST/Expr.cpp"); 513 // if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) { 514 // return callArg( app, pos ); 515 // } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) { 516 // return callArg( untyped, pos ); 517 // } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) { 518 // const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids; 519 // assertf( ! stmts.empty(), "TupleAssignExpr missing statements." ); 520 // const ExprStmt * stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back() ); 521 // const TupleExpr * tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr ); 522 // assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr."); 523 // return getCallArg( tuple->exprs.front(), pos ); 524 // } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) { 525 // return getCallArg( ctor->callExpr, pos ); 526 // } else { 527 // assertf( false, "Unexpected expression type passed to getCallArg: %s", 528 // toString( call ).c_str() ); 529 // } 510 if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) { 511 return callArg( app, pos ); 512 } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) { 513 return callArg( untyped, pos ); 514 } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) { 515 const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids; 516 assertf( ! stmts.empty(), "TupleAssignExpr missing statements." ); 517 auto stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back().get() ); 518 auto tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr.get() ); 519 assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr."); 520 return getCallArg( tuple->exprs.front(), pos ); 521 } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) { 522 return getCallArg( ctor->callExpr, pos ); 523 } else { 524 assertf( false, "Unexpected expression type passed to getCallArg: %s", 525 toString( call ).c_str() ); 526 } 530 527 } 531 528 … … 637 634 } 638 635 const ast::Type* getPointerBase( const ast::Type* t ) { 639 (void)t; 640 #warning needs to build Type.cpp before inclusion 641 assertf(false, "needs to build Type.cpp before inclusion"); 642 // if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) { 643 // return p->base; 644 // } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) { 645 // return a->base; 646 // } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) { 647 // return r->base; 648 // } else return nullptr; 636 if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) { 637 return p->base; 638 } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) { 639 return a->base; 640 } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) { 641 return r->base; 642 } else return nullptr; 649 643 } 650 644
Note: See TracChangeset
for help on using the changeset viewer.