Changeset 9236060 for src/GenPoly/Lvalue.cc
- Timestamp:
- Aug 14, 2017, 2:03:39 PM (5 years ago)
- Branches:
- aaron-thesis, arm-eh, 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, resolv-new, with_gc
- Children:
- 74b007ba
- Parents:
- fd344aa (diff), 54cd58b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
rfd344aa r9236060 30 30 31 31 #include "ResolvExpr/Resolver.h" 32 #include "ResolvExpr/TypeEnvironment.h" 32 33 #include "ResolvExpr/typeops.h" 34 #include "ResolvExpr/Unify.h" 33 35 34 36 #include "Common/UniqueName.h" … … 64 66 65 67 struct ReferenceConversions final { 66 void premutate( AddressExpr * addrExpr );67 68 68 Expression * postmutate( CastExpr * castExpr ); 69 69 Expression * postmutate( AddressExpr * addrExpr ); … … 89 89 struct GeneralizedLvalue final : public WithVisitorRef<GeneralizedLvalue> { 90 90 Expression * postmutate( AddressExpr * addressExpr ); 91 Expression * postmutate( MemberExpr * memExpr ); 92 93 template<typename Func> 94 Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr ); 91 95 }; 92 96 … … 133 137 // from this point forward, no other pass should create reference types. 134 138 referencesEliminated = true; 139 } 140 141 Expression * generalizedLvalue( Expression * expr ) { 142 PassVisitor<GeneralizedLvalue> genLval; 143 return expr->acceptMutator( genLval ); 135 144 } 136 145 … … 359 368 } 360 369 361 Expression * GeneralizedLvalue::postmutate( AddressExpr * addrExpr ) { 362 if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) { 370 template<typename Func> 371 Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) { 372 if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) { 363 373 Expression * arg1 = commaExpr->get_arg1()->clone(); 364 374 Expression * arg2 = commaExpr->get_arg2()->clone(); 365 Expression * ret = new CommaExpr( arg1, (new AddressExpr( arg2 ))->acceptMutator( *visitor ) );366 ret->set_env( addrExpr->get_env() );367 addrExpr->set_env( nullptr );368 delete addrExpr;369 return ret; 370 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( a ddrExpr->get_arg()) ) {375 Expression * ret = new CommaExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ) ); 376 ret->set_env( expr->get_env() ); 377 expr->set_env( nullptr ); 378 delete expr; 379 return ret; 380 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) { 371 381 Expression * arg1 = condExpr->get_arg1()->clone(); 372 382 Expression * arg2 = condExpr->get_arg2()->clone(); 373 383 Expression * arg3 = condExpr->get_arg3()->clone(); 374 Expression * ret = new ConditionalExpr( arg1, (new AddressExpr( arg2 ))->acceptMutator( *visitor ), (new AddressExpr( arg3 ))->acceptMutator( *visitor ) ); 375 ret->set_env( addrExpr->get_env() ); 376 addrExpr->set_env( nullptr ); 377 delete addrExpr; 378 return ret; 379 } 380 return addrExpr; 384 ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ), mkExpr( arg3 )->acceptMutator( *visitor ) ); 385 ret->set_env( expr->get_env() ); 386 expr->set_env( nullptr ); 387 delete expr; 388 389 // conditional expr type may not be either of the argument types, need to unify 390 using namespace ResolvExpr; 391 Type* commonType = nullptr; 392 TypeEnvironment newEnv; 393 AssertionSet needAssertions, haveAssertions; 394 OpenVarSet openVars; 395 unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType ); 396 ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() ); 397 return ret; 398 } 399 return expr; 400 } 401 402 Expression * GeneralizedLvalue::postmutate( MemberExpr * memExpr ) { 403 return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } ); 404 } 405 406 Expression * GeneralizedLvalue::postmutate( AddressExpr * addrExpr ) { 407 return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } ); 381 408 } 382 409
Note: See TracChangeset
for help on using the changeset viewer.