Changeset 906e24d for src/GenPoly


Ignore:
Timestamp:
Sep 15, 2016, 10:17:16 AM (9 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, resolv-new, with_gc
Children:
aa8f9df
Parents:
96a10cdd
git-author:
Rob Schluntz <rschlunt@…> (09/14/16 22:32:34)
git-committer:
Rob Schluntz <rschlunt@…> (09/15/16 10:17:16)
Message:

replace results list on Expressions with a single Type field

Location:
src/GenPoly
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r96a10cdd r906e24d  
    782782
    783783                        // add size/align for generic types to parameter list
    784                         if ( appExpr->get_function()->get_results().empty() ) return;
    785                         FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
     784                        if ( ! appExpr->get_function()->has_result() ) return;
     785                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() );
    786786                        assert( funcType );
    787787
     
    799799                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
    800800                                VariableExpr *fnArgBase = getBaseVar( *fnArg );
    801                                 if ( ! fnArgBase || fnArgBase->get_results().empty() ) continue;
    802                                 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_results().front(), arg, exprTyVars, seenTypes );
     801                                if ( ! fnArgBase ) continue; // xxx - previously had check for non-empty fnArgBase results
     802                                passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result(), arg, exprTyVars, seenTypes );
    803803                        }
    804804                }
     
    890890                        Type * adapteeType = new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
    891891                        appExpr->get_args().push_front( new CastExpr( appExpr->get_function(), adapteeType ) );
    892                         appExpr->set_function( new NameExpr( adapterName ) );
     892                        appExpr->set_function( new NameExpr( adapterName ) ); // xxx - result is never set on NameExpr
    893893
    894894                        return ret;
     
    896896
    897897                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    898                         assert( ! arg->get_results().empty() );
     898                        assert( arg->has_result() );
    899899                        if ( isPolyType( param, exprTyVars ) ) {
    900                                 if ( isPolyType( arg->get_results().front() ) ) {
     900                                if ( isPolyType( arg->get_result() ) ) {
    901901                                        // if the argument's type is polymorphic, we don't need to box again!
    902902                                        return;
    903                                 } else if ( arg->get_results().front()->get_isLvalue() ) {
     903                                } else if ( arg->get_result()->get_isLvalue() ) {
    904904                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    905905                                        // xxx - need to test that this code is still reachable
     
    987987                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    988988                                        deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) );
    989                                         deref->get_results().push_back( arg->get_type()->clone() );
     989                                        deref->set_result( arg->get_type()->clone() );
    990990                                        return deref;
    991991                                } // if
     
    11241124                        } // if
    11251125                        addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType ) ) ) );
    1126                         addAssign->get_results().front() = appExpr->get_results().front()->clone();
     1126                        addAssign->set_result( appExpr->get_result()->clone() );
    11271127                        if ( appExpr->get_env() ) {
    11281128                                addAssign->set_env( appExpr->get_env() );
     
    11381138                                if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
    11391139                                        if ( varExpr->get_var()->get_name() == "?[?]" ) {
    1140                                                 assert( ! appExpr->get_results().empty() );
     1140                                                assert( appExpr->has_result() );
    11411141                                                assert( appExpr->get_args().size() == 2 );
    1142                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    1143                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     1142                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     1143                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
    11441144                                                assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
    11451145                                                UntypedExpr *ret = 0;
     
    11611161                                                } // if
    11621162                                                if ( baseType1 || baseType2 ) {
    1163                                                         ret->get_results().push_front( appExpr->get_results().front()->clone() );
     1163                                                        ret->set_result( appExpr->get_result()->clone() );
    11641164                                                        if ( appExpr->get_env() ) {
    11651165                                                                ret->set_env( appExpr->get_env() );
     
    11711171                                                } // if
    11721172                                        } else if ( varExpr->get_var()->get_name() == "*?" ) {
    1173                                                 assert( ! appExpr->get_results().empty() );
     1173                                                assert( appExpr->has_result() );
    11741174                                                assert( ! appExpr->get_args().empty() );
    1175                                                 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
     1175                                                if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
    11761176                                                        Expression *ret = appExpr->get_args().front();
    1177                                                         delete ret->get_results().front();
    1178                                                         ret->get_results().front() = appExpr->get_results().front()->clone();
     1177                                                        delete ret->get_result();
     1178                                                        ret->set_result( appExpr->get_result()->clone() );
    11791179                                                        if ( appExpr->get_env() ) {
    11801180                                                                ret->set_env( appExpr->get_env() );
     
    11861186                                                } // if
    11871187                                        } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) {
    1188                                                 assert( ! appExpr->get_results().empty() );
     1188                                                assert( appExpr->has_result() );
    11891189                                                assert( appExpr->get_args().size() == 1 );
    1190                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
    1191                                                         Type *tempType = appExpr->get_results().front()->clone();
     1190                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
     1191                                                        Type *tempType = appExpr->get_result()->clone();
    11921192                                                        if ( env ) {
    11931193                                                                env->apply( tempType );
     
    12061206                                                } // if
    12071207                                        } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) {
    1208                                                 assert( ! appExpr->get_results().empty() );
     1208                                                assert( appExpr->has_result() );
    12091209                                                assert( appExpr->get_args().size() == 1 );
    1210                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
     1210                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
    12111211                                                        return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );
    12121212                                                } // if
    12131213                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
    1214                                                 assert( ! appExpr->get_results().empty() );
     1214                                                assert( appExpr->has_result() );
    12151215                                                assert( appExpr->get_args().size() == 2 );
    1216                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    1217                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     1216                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     1217                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
    12181218                                                if ( baseType1 && baseType2 ) {
    12191219                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    12201220                                                        divide->get_args().push_back( appExpr );
    12211221                                                        divide->get_args().push_back( new SizeofExpr( baseType1->clone() ) );
    1222                                                         divide->get_results().push_front( appExpr->get_results().front()->clone() );
     1222                                                        divide->set_result( appExpr->get_result()->clone() );
    12231223                                                        if ( appExpr->get_env() ) {
    12241224                                                                divide->set_env( appExpr->get_env() );
     
    12381238                                                } // if
    12391239                                        } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) {
    1240                                                 assert( ! appExpr->get_results().empty() );
     1240                                                assert( appExpr->has_result() );
    12411241                                                assert( appExpr->get_args().size() == 2 );
    1242                                                 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
     1242                                                Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env );
    12431243                                                if ( baseType ) {
    12441244                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
     
    12661266                        useRetval = oldUseRetval;
    12671267
    1268                         assert( ! appExpr->get_function()->get_results().empty() );
    1269                         PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
    1270                         assert( pointer );
    1271                         FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    1272                         assert( function );
     1268                        assert( appExpr->get_function()->has_result() );
     1269                        PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
     1270                        FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
    12731271
    12741272                        if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
     
    13081306
    13091307                Expression *Pass1::mutate( UntypedExpr *expr ) {
    1310                         if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     1308                        if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    13111309                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13121310                                        if ( name->get_name() == "*?" ) {
     
    13221320
    13231321                Expression *Pass1::mutate( AddressExpr *addrExpr ) {
    1324                         assert( ! addrExpr->get_arg()->get_results().empty() );
     1322                        assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() );
    13251323
    13261324                        bool needs = false;
    13271325                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1328                                 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     1326                                if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    13291327                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13301328                                                if ( name->get_name() == "*?" ) {
    13311329                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    1332                                                                 assert( ! appExpr->get_function()->get_results().empty() );
    1333                                                                 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
    1334                                                                 assert( pointer );
    1335                                                                 FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    1336                                                                 assert( function );
     1330                                                                assert( appExpr->get_function()->has_result() );
     1331                                                                PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
     1332                                                                FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
    13371333                                                                needs = needsAdapter( function, scopeTyVars );
    13381334                                                        } // if
     
    13431339                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    13441340                        // out of the if condition.
    1345                         bool polytype = isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env );
     1341                        bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
    13461342                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    13471343                        if ( polytype || needs ) {
    13481344                                Expression *ret = addrExpr->get_arg();
    1349                                 delete ret->get_results().front();
    1350                                 ret->get_results().front() = addrExpr->get_results().front()->clone();
     1345                                delete ret->get_result();
     1346                                ret->set_result( addrExpr->get_result()->clone() );
    13511347                                addrExpr->set_arg( 0 );
    13521348                                delete addrExpr;
     
    13861382                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    13871383                        if ( retval && returnStmt->get_expr() ) {
    1388                                 assert( ! returnStmt->get_expr()->get_results().empty() );
     1384                                assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() );
    13891385                                // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
    13901386                                // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     
    14661462                                // replace return statement with appropriate assignment to out parameter
    14671463                                Expression *retParm = new NameExpr( retval->get_name() );
    1468                                 retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     1464                                retParm->set_result( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
    14691465                                assignExpr->get_args().push_back( retParm );
    14701466                                assignExpr->get_args().push_back( returnStmt->get_expr() );
  • src/GenPoly/Lvalue.cc

    r96a10cdd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.cc -- 
     7// Lvalue.cc --
    88//
    99// Author           : Richard C. Bilson
     
    4141                  public:
    4242                        Pass1();
    43  
     43
    4444                        virtual Expression *mutate( ApplicationExpr *appExpr );
    4545                        virtual Statement *mutate( ReturnStmt *appExpr );
     
    9999                        appExpr->get_function()->acceptMutator( *this );
    100100                        mutateAll( appExpr->get_args(), *this );
    101  
    102                         assert( ! appExpr->get_function()->get_results().empty() );
    103101
    104                         PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() );
    105                         assert( pointer );
    106                         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    107                         assert( function );
     102                        PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     103                        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    108104
    109105                        Type *funType = isLvalueRet( function );
    110106                        if ( funType && ! isIntrinsicApp( appExpr ) ) {
    111107                                Expression *expr = appExpr;
    112                                 Type *appType = appExpr->get_results().front();
     108                                Type *appType = appExpr->get_result();
    113109                                if ( isPolyType( funType ) && ! isPolyType( appType ) ) {
    114110                                        // make sure cast for polymorphic type is inside dereference
     
    116112                                }
    117113                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    118                                 deref->get_results().push_back( appType->clone() );
    119                                 appExpr->get_results().front() = new PointerType( Type::Qualifiers(), appType );
     114                                deref->set_result( appType->clone() );
     115                                appExpr->set_result( new PointerType( Type::Qualifiers(), appType ) );
    120116                                deref->get_args().push_back( expr );
    121117                                return deref;
     
    127123                Statement * Pass1::mutate(ReturnStmt *retStmt) {
    128124                        if ( retval && retStmt->get_expr() ) {
    129                                 assert( ! retStmt->get_expr()->get_results().empty() );
    130                                 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     125                                if ( retStmt->get_expr()->get_result()->get_isLvalue() ) {
    131126                                        // ***** Code Removal ***** because casts may be stripped already
    132127
     
    155150                                retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) );
    156151                        } // if
    157  
     152
    158153                        Visitor::visit( funType );
    159154                }
  • src/GenPoly/Specialize.cc

    r96a10cdd r906e24d  
    147147
    148148        Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
    149                 assert( ! actual->get_results().empty() ); // using front, should have this assert
    150                 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) {
     149                assert( actual->has_result() );
     150                if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
    151151                        FunctionType *funType;
    152152                        if ( ( funType = getFunctionType( formalType ) ) ) {
     
    171171        void Specialize::handleExplicitParams( ApplicationExpr *appExpr ) {
    172172                // create thunks for the explicit parameters
    173                 assert( ! appExpr->get_function()->get_results().empty() );
    174                 FunctionType *function = getFunctionType( appExpr->get_function()->get_results().front() );
     173                assert( appExpr->get_function()->has_result() );
     174                FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
    175175                assert( function );
    176176                std::list< DeclarationWithType* >::iterator formal;
     
    200200        Expression * Specialize::mutate( AddressExpr *addrExpr ) {
    201201                addrExpr->get_arg()->acceptMutator( *this );
    202                 assert( ! addrExpr->get_results().empty() );
    203                 addrExpr->set_arg( doSpecialization( addrExpr->get_results().front(), addrExpr->get_arg() ) );
     202                assert( addrExpr->has_result() );
     203                addrExpr->set_arg( doSpecialization( addrExpr->get_result(), addrExpr->get_arg() ) );
    204204                return addrExpr;
    205205        }
     
    207207        Expression * Specialize::mutate( CastExpr *castExpr ) {
    208208                castExpr->get_arg()->acceptMutator( *this );
    209                 if ( castExpr->get_results().empty() ) {
     209                if ( castExpr->get_result()->isVoid() ) {
    210210                        // can't specialize if we don't have a return value
    211211                        return castExpr;
    212212                }
    213                 Expression *specialized = doSpecialization( castExpr->get_results().front(), castExpr->get_arg() );
     213                Expression *specialized = doSpecialization( castExpr->get_result(), castExpr->get_arg() );
    214214                if ( specialized != castExpr->get_arg() ) {
    215215                        // assume here that the specialization incorporates the cast
Note: See TracChangeset for help on using the changeset viewer.