Changeset 0a22cda
- Timestamp:
- Oct 19, 2017, 11:13:11 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 6137fbb
- Parents:
- eaa2edaa
- git-author:
- Rob Schluntz <rschlunt@…> (10/11/17 15:57:07)
- git-committer:
- Rob Schluntz <rschlunt@…> (10/19/17 11:13:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
reaa2edaa r0a22cda 113 113 env.makeSubstitution( *expr->get_env() ); 114 114 } 115 116 void removeExtraneousCast( Expression *& expr, const SymTab::Indexer & indexer ) { 117 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 118 if ( ResolvExpr::typesCompatible( castExpr->arg->result, castExpr->result, indexer ) ) { 119 // cast is to the same type as its argument, so it's unnecessary -- remove it 120 expr = castExpr->arg; 121 castExpr->arg = nullptr; 122 std::swap( expr->env, castExpr->env ); 123 delete castExpr; 124 } 125 } 126 } 115 127 } // namespace 116 128 … … 151 163 untyped = new CastExpr( untyped, type ); 152 164 findSingleExpression( untyped, indexer ); 153 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( untyped ) ) { 154 if ( ResolvExpr::typesCompatible( castExpr->arg->result, castExpr->result, indexer ) ) { 155 // cast is to the same type as its argument, so it's unnecessary -- remove it 156 untyped = castExpr->arg; 157 castExpr->arg = nullptr; 158 delete castExpr; 159 } 160 } 165 removeExtraneousCast( untyped, indexer ); 161 166 } 162 167 … … 577 582 visit_children = false; 578 583 // resolve initialization using the possibilities as determined by the currentObject cursor 579 Expression * newExpr = new UntypedInitExpr( singleInit-> get_value(), currentObject.getOptions() );584 Expression * newExpr = new UntypedInitExpr( singleInit->value, currentObject.getOptions() ); 580 585 findSingleExpression( newExpr, indexer ); 581 586 InitExpr * initExpr = strict_dynamic_cast< InitExpr * >( newExpr ); … … 592 597 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) 593 598 Type * initContext = currentObject.getCurrentType(); 599 600 removeExtraneousCast( newExpr, indexer ); 594 601 595 602 // check if actual object's type is char[] … … 599 606 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 600 607 if ( isCharType( pt->get_base() ) ) { 601 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 602 CastExpr *ce = strict_dynamic_cast< CastExpr * >( newExpr ); 603 newExpr = ce->get_arg(); 604 ce->set_arg( nullptr ); 605 delete ce; 608 if ( CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ) ) { 609 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 610 newExpr = ce->get_arg(); 611 ce->set_arg( nullptr ); 612 std::swap( ce->env, newExpr->env ); 613 delete ce; 614 } 606 615 } 607 616 } … … 610 619 611 620 // set initializer expr to resolved express 612 singleInit-> set_value( newExpr );621 singleInit->value = newExpr; 613 622 614 623 // move cursor to next object in preparation for next initializer
Note: See TracChangeset
for help on using the changeset viewer.