Changeset b1ccdfd for src/GenPoly
- Timestamp:
- Mar 19, 2018, 2:06:57 PM (6 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, with_gc
- Children:
- 31cb252
- Parents:
- 0415e24
- git-author:
- Rob Schluntz <rschlunt@…> (03/15/18 14:43:27)
- git-committer:
- Rob Schluntz <rschlunt@…> (03/19/18 14:06:57)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r0415e24 rb1ccdfd 114 114 } 115 115 116 void convertLvalue( std::list< Declaration* > & translationUnit ) {116 void convertLvalue( std::list< Declaration* > & translationUnit ) { 117 117 PassVisitor<ReferenceConversions> refCvt; 118 118 PassVisitor<ReferenceTypeElimination> elim; … … 150 150 // use type of return variable rather than expr result type, since it may have been changed to a pointer type 151 151 FunctionType * ftype = GenPoly::getFunctionType( func->get_type() ); 152 Type * ret = ftype-> get_returnVals().empty() ? nullptr : ftype->get_returnVals().front()->get_type();153 return func-> get_linkage()== LinkageSpec::Intrinsic && dynamic_cast<ReferenceType *>( ret );152 Type * ret = ftype->returnVals.empty() ? nullptr : ftype->returnVals.front()->get_type(); 153 return func->linkage == LinkageSpec::Intrinsic && dynamic_cast<ReferenceType *>( ret ); 154 154 } 155 155 } … … 160 160 if ( isIntrinsicReference( appExpr ) ) { 161 161 // eliminate reference types from intrinsic applications - now they return lvalues 162 Type * result = appExpr-> get_result();163 appExpr-> set_result( result->stripReferences()->clone());164 appExpr-> get_result()->set_lvalue( true );162 Type * result = appExpr->result; 163 appExpr->result = result->stripReferences()->clone(); 164 appExpr->result->set_lvalue( true ); 165 165 if ( ! inIntrinsic ) { 166 166 // when not in an intrinsic function, add a cast to 167 167 // don't add cast when in an intrinsic function, since they already have the cast 168 168 Expression * ret = new CastExpr( appExpr, result ); 169 ret->set_env( appExpr->get_env() ); 170 appExpr->set_env( nullptr ); 169 std::swap( ret->env, appExpr->env ); 171 170 return ret; 172 171 } … … 187 186 assertf( ftype, "Function declaration does not have function type." ); 188 187 // can be of differing lengths only when function is variadic 189 assertf( ftype-> get_parameters().size() == appExpr->get_args().size() || ftype->get_isVarArgs(), "ApplicationExpr args do not match formal parameter type." );188 assertf( ftype->parameters.size() == appExpr->args.size() || ftype->isVarArgs, "ApplicationExpr args do not match formal parameter type." ); 190 189 191 190 192 191 unsigned int i = 0; 193 const unsigned int end = ftype-> get_parameters().size();194 for ( auto p : unsafe_group_iterate( appExpr-> get_args(), ftype->get_parameters()) ) {192 const unsigned int end = ftype->parameters.size(); 193 for ( auto p : unsafe_group_iterate( appExpr->args, ftype->parameters ) ) { 195 194 if (i == end) break; 196 195 Expression *& arg = std::get<0>( p ); … … 212 211 // std::cerr << "===adding deref to arg" << std::endl; 213 212 // if the parameter is a reference, add a dereference to the reference-typed argument. 214 Type * baseType = InitTweak::getPointerBase( arg-> get_result());215 assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg-> get_result()).c_str() );213 Type * baseType = InitTweak::getPointerBase( arg->result ); 214 assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() ); 216 215 PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() ); 217 delete arg-> get_result();216 delete arg->result; 218 217 arg->set_result( ptrType ); 219 218 arg = mkDeref( arg ); … … 249 248 Expression * AddrRef::postmutate( AddressExpr * addrExpr ) { 250 249 if ( refDepth == 0 ) { 251 if ( ! isIntrinsicReference( addrExpr-> get_arg()) ) {250 if ( ! isIntrinsicReference( addrExpr->arg ) ) { 252 251 // try to avoid ?[?] 253 refDepth = addrExpr-> get_arg()->get_result()->referenceDepth();252 refDepth = addrExpr->arg->result->referenceDepth(); 254 253 } 255 254 } … … 281 280 282 281 // conversion to reference type 283 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr-> get_result()) ) {282 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->result ) ) { 284 283 (void)refType; 285 if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( castExpr-> get_arg()->get_result()) ) {284 if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( castExpr->arg->result ) ) { 286 285 // nothing to do if casting from reference to reference. 287 286 (void)otherRef; 288 287 PRINT( std::cerr << "convert reference to reference -- nop" << std::endl; ) 289 if ( isIntrinsicReference( castExpr-> get_arg()) ) {290 Expression * callExpr = castExpr-> get_arg();288 if ( isIntrinsicReference( castExpr->arg ) ) { 289 Expression * callExpr = castExpr->arg; 291 290 PRINT( 292 291 std::cerr << "but arg is deref -- &" << std::endl; … … 294 293 ) 295 294 callExpr = new AddressExpr( callExpr ); // this doesn't work properly for multiple casts 296 delete callExpr-> get_result();295 delete callExpr->result; 297 296 callExpr->set_result( refType->clone() ); 298 297 // move environment out to new top-level 299 callExpr-> set_env( castExpr->get_env() );300 castExpr-> set_arg( nullptr );301 castExpr-> set_env( nullptr );298 callExpr->env = castExpr->env; 299 castExpr->arg = nullptr; 300 castExpr->env = nullptr; 302 301 delete castExpr; 303 302 return callExpr; … … 404 403 405 404 Type * ReferenceTypeElimination::postmutate( ReferenceType * refType ) { 406 Type * base = refType-> get_base();405 Type * base = refType->base; 407 406 Type::Qualifiers qualifiers = refType->get_qualifiers(); 408 refType-> set_base( nullptr );407 refType->base = nullptr; 409 408 delete refType; 410 409 return new PointerType( qualifiers, base ); … … 414 413 Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) { 415 414 if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) { 416 Expression * arg1 = commaExpr-> get_arg1()->clone();417 Expression * arg2 = commaExpr-> get_arg2()->clone();415 Expression * arg1 = commaExpr->arg1->clone(); 416 Expression * arg2 = commaExpr->arg2->clone(); 418 417 Expression * ret = new CommaExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ) ); 419 ret-> set_env( expr->get_env() );420 expr-> set_env( nullptr );418 ret->env = expr->env; 419 expr->env = nullptr; 421 420 delete expr; 422 421 return ret; 423 422 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) { 424 Expression * arg1 = condExpr-> get_arg1()->clone();425 Expression * arg2 = condExpr-> get_arg2()->clone();426 Expression * arg3 = condExpr-> get_arg3()->clone();423 Expression * arg1 = condExpr->arg1->clone(); 424 Expression * arg2 = condExpr->arg2->clone(); 425 Expression * arg3 = condExpr->arg3->clone(); 427 426 ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ), mkExpr( arg3 )->acceptMutator( *visitor ) ); 428 ret-> set_env( expr->get_env() );429 expr-> set_env( nullptr );427 ret->env = expr->env; 428 expr->env = nullptr; 430 429 delete expr; 431 430 … … 436 435 AssertionSet needAssertions, haveAssertions; 437 436 OpenVarSet openVars; 438 unify( ret-> get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType );439 ret-> set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone());437 unify( ret->arg2->result, ret->arg3->result, newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType ); 438 ret->result = commonType ? commonType : ret->arg2->result->clone(); 440 439 return ret; 441 440 } … … 444 443 445 444 Expression * GeneralizedLvalue::postmutate( MemberExpr * memExpr ) { 446 return applyTransformation( memExpr, memExpr-> get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } );445 return applyTransformation( memExpr, memExpr->aggregate, [=]( Expression * aggr ) { return new MemberExpr( memExpr->member, aggr ); } ); 447 446 } 448 447 449 448 Expression * GeneralizedLvalue::postmutate( AddressExpr * addrExpr ) { 450 return applyTransformation( addrExpr, addrExpr-> get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } );449 return applyTransformation( addrExpr, addrExpr->arg, []( Expression * arg ) { return new AddressExpr( arg ); } ); 451 450 } 452 451 453 452 Expression * CollapseAddrDeref::postmutate( AddressExpr * addrExpr ) { 454 Expression * arg = addrExpr-> get_arg();453 Expression * arg = addrExpr->arg; 455 454 if ( isIntrinsicReference( arg ) ) { 456 455 std::string fname = InitTweak::getFunctionName( arg ); … … 458 457 Expression *& arg0 = InitTweak::getCallArg( arg, 0 ); 459 458 Expression * ret = arg0; 460 ret->set_env( addrExpr-> get_env());459 ret->set_env( addrExpr->env ); 461 460 arg0 = nullptr; 462 addrExpr-> set_env( nullptr );461 addrExpr->env = nullptr; 463 462 delete addrExpr; 464 463 return ret; … … 487 486 // } 488 487 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( arg ) ) { 489 Expression * ret = addrExpr-> get_arg();490 ret-> set_env( appExpr->get_env() );491 addrExpr-> set_arg( nullptr );492 appExpr-> set_env( nullptr );488 Expression * ret = addrExpr->arg; 489 ret->env = appExpr->env; 490 addrExpr->arg = nullptr; 491 appExpr->env = nullptr; 493 492 delete appExpr; 494 493 return ret;
Note: See TracChangeset
for help on using the changeset viewer.