Changeset b1ccdfd


Ignore:
Timestamp:
Mar 19, 2018, 2:06:57 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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)
Message:

Code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    r0415e24 rb1ccdfd  
    114114        }
    115115
    116         void convertLvalue( std::list< Declaration* >& translationUnit ) {
     116        void convertLvalue( std::list< Declaration* > & translationUnit ) {
    117117                PassVisitor<ReferenceConversions> refCvt;
    118118                PassVisitor<ReferenceTypeElimination> elim;
     
    150150                                        // use type of return variable rather than expr result type, since it may have been changed to a pointer type
    151151                                        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 );
    154154                                }
    155155                        }
     
    160160                        if ( isIntrinsicReference( appExpr ) ) {
    161161                                // 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 );
    165165                                if ( ! inIntrinsic ) {
    166166                                        // when not in an intrinsic function, add a cast to
    167167                                        // don't add cast when in an intrinsic function, since they already have the cast
    168168                                        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 );
    171170                                        return ret;
    172171                                }
     
    187186                                assertf( ftype, "Function declaration does not have function type." );
    188187                                // 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." );
    190189
    191190
    192191                                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 ) ) {
    195194                                        if (i == end) break;
    196195                                        Expression *& arg = std::get<0>( p );
     
    212211                                                        // std::cerr << "===adding deref to arg" << std::endl;
    213212                                                        // 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() );
    216215                                                        PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() );
    217                                                         delete arg->get_result();
     216                                                        delete arg->result;
    218217                                                        arg->set_result( ptrType );
    219218                                                        arg = mkDeref( arg );
     
    249248                Expression * AddrRef::postmutate( AddressExpr * addrExpr ) {
    250249                        if ( refDepth == 0 ) {
    251                                 if ( ! isIntrinsicReference( addrExpr->get_arg() ) ) {
     250                                if ( ! isIntrinsicReference( addrExpr->arg ) ) {
    252251                                        // try to avoid ?[?]
    253                                         refDepth = addrExpr->get_arg()->get_result()->referenceDepth();
     252                                        refDepth = addrExpr->arg->result->referenceDepth();
    254253                                }
    255254                        }
     
    281280
    282281                        // conversion to reference type
    283                         if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->get_result() ) ) {
     282                        if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->result ) ) {
    284283                                (void)refType;
    285                                 if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( castExpr->get_arg()->get_result() ) ) {
     284                                if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( castExpr->arg->result ) ) {
    286285                                        // nothing to do if casting from reference to reference.
    287286                                        (void)otherRef;
    288287                                        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;
    291290                                                PRINT(
    292291                                                        std::cerr << "but arg is deref -- &" << std::endl;
     
    294293                                                )
    295294                                                callExpr = new AddressExpr( callExpr ); // this doesn't work properly for multiple casts
    296                                                 delete callExpr->get_result();
     295                                                delete callExpr->result;
    297296                                                callExpr->set_result( refType->clone() );
    298297                                                // 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;
    302301                                                delete castExpr;
    303302                                                return callExpr;
     
    404403
    405404                Type * ReferenceTypeElimination::postmutate( ReferenceType * refType ) {
    406                         Type * base = refType->get_base();
     405                        Type * base = refType->base;
    407406                        Type::Qualifiers qualifiers = refType->get_qualifiers();
    408                         refType->set_base( nullptr );
     407                        refType->base = nullptr;
    409408                        delete refType;
    410409                        return new PointerType( qualifiers, base );
     
    414413                Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) {
    415414                        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();
    418417                                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;
    421420                                delete expr;
    422421                                return ret;
    423422                        } 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();
    427426                                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;
    430429                                delete expr;
    431430
     
    436435                                AssertionSet needAssertions, haveAssertions;
    437436                                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();
    440439                                return ret;
    441440                        }
     
    444443
    445444                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 ); } );
    447446                }
    448447
    449448                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 ); } );
    451450                }
    452451
    453452                Expression * CollapseAddrDeref::postmutate( AddressExpr * addrExpr ) {
    454                         Expression * arg = addrExpr->get_arg();
     453                        Expression * arg = addrExpr->arg;
    455454                        if ( isIntrinsicReference( arg ) ) {
    456455                                std::string fname = InitTweak::getFunctionName( arg );
     
    458457                                        Expression *& arg0 = InitTweak::getCallArg( arg, 0 );
    459458                                        Expression * ret = arg0;
    460                                         ret->set_env( addrExpr->get_env() );
     459                                        ret->set_env( addrExpr->env );
    461460                                        arg0 = nullptr;
    462                                         addrExpr->set_env( nullptr );
     461                                        addrExpr->env = nullptr;
    463462                                        delete addrExpr;
    464463                                        return ret;
     
    487486                                        // }
    488487                                        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;
    493492                                                delete appExpr;
    494493                                                return ret;
Note: See TracChangeset for help on using the changeset viewer.