Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    racd7c5dd r8ca3a72  
    2727#include "SynTree/Mutator.h"
    2828#include "SymTab/Indexer.h"
    29 
    3029#include "ResolvExpr/Resolver.h"
    31 #include "ResolvExpr/TypeEnvironment.h"
    3230#include "ResolvExpr/typeops.h"
    33 #include "ResolvExpr/Unify.h"
    3431
    3532#include "Common/UniqueName.h"
     
    6360                        typedef Mutator Parent;
    6461
    65                         virtual Expression * mutate( MemberExpr * memExpr );
    6662                        virtual Expression * mutate( AddressExpr * addressExpr );
    67 
    68                         template<typename Func>
    69                         Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr );
    7063                };
    7164        } // namespace
     
    7871                acceptAll( translationUnit, p2 );
    7972                mutateAll( translationUnit, genLval );
    80         }
    81 
    82         Expression * generalizedLvalue( Expression * expr ) {
    83                 GeneralizedLvalue genLval;
    84                 return expr->acceptMutator( genLval );
    8573        }
    8674
     
    175163                }
    176164
    177                 template<typename Func>
    178                 Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) {
    179                         if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) {
     165                Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
     166                        addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
     167                        if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) {
    180168                                Expression * arg1 = commaExpr->get_arg1()->clone();
    181169                                Expression * arg2 = commaExpr->get_arg2()->clone();
    182                                 Expression * ret = new CommaExpr( arg1, mkExpr( arg2 ) );
    183                                 ret->set_env( expr->get_env() );
    184                                 expr->set_env( nullptr );
    185                                 delete expr;
    186                                 return ret->acceptMutator( *this );
    187                         } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) {
     170                                delete addrExpr;
     171                                return new CommaExpr( arg1, new AddressExpr( arg2 ) );
     172                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) {
    188173                                Expression * arg1 = condExpr->get_arg1()->clone();
    189174                                Expression * arg2 = condExpr->get_arg2()->clone();
    190175                                Expression * arg3 = condExpr->get_arg3()->clone();
    191                                 ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 ), mkExpr( arg3 ) );
    192                                 ret->set_env( expr->get_env() );
    193                                 expr->set_env( nullptr );
    194                                 delete expr;
    195 
    196                                 // conditional expr type may not be either of the argument types, need to unify
    197                                 using namespace ResolvExpr;
    198                                 Type* commonType = nullptr;
    199                                 TypeEnvironment newEnv;
    200                                 AssertionSet needAssertions, haveAssertions;
    201                                 OpenVarSet openVars;
    202                                 unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType );
    203                                 ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() );
    204                                 return ret->acceptMutator( *this );
     176                                delete addrExpr;
     177                                return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) );
    205178                        }
    206                         return expr;
    207                 }
    208 
    209                 Expression * GeneralizedLvalue::mutate( MemberExpr * memExpr ) {
    210                         Parent::mutate( memExpr );
    211                         return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } );
    212                 }
    213 
    214                 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
    215                         addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
    216                         return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } );
     179                        return addrExpr;
    217180                }
    218181        } // namespace
Note: See TracChangeset for help on using the changeset viewer.