Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r906e24d r1ba88a0  
    2929#include "PolyMutator.h"
    3030#include "FindFunction.h"
     31#include "ScopedMap.h"
    3132#include "ScopedSet.h"
    3233#include "ScrubTyVars.h"
     
    5051#include "SymTab/Mangler.h"
    5152
    52 #include "Common/ScopedMap.h"
    5353#include "Common/SemanticError.h"
    5454#include "Common/UniqueName.h"
     
    782782
    783783                        // add size/align for generic types to parameter list
    784                         if ( ! appExpr->get_function()->has_result() ) return;
    785                         FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() );
     784                        if ( appExpr->get_function()->get_results().empty() ) return;
     785                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
    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 ) continue; // xxx - previously had check for non-empty fnArgBase results
    802                                 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result(), arg, exprTyVars, seenTypes );
     801                                if ( ! fnArgBase || fnArgBase->get_results().empty() ) continue;
     802                                passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_results().front(), 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 ) ); // xxx - result is never set on NameExpr
     892                        appExpr->set_function( new NameExpr( adapterName ) );
    893893
    894894                        return ret;
     
    896896
    897897                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    898                         assert( arg->has_result() );
     898                        assert( ! arg->get_results().empty() );
    899899                        if ( isPolyType( param, exprTyVars ) ) {
    900                                 if ( isPolyType( arg->get_result() ) ) {
     900                                if ( isPolyType( arg->get_results().front() ) ) {
    901901                                        // if the argument's type is polymorphic, we don't need to box again!
    902902                                        return;
    903                                 } else if ( arg->get_result()->get_isLvalue() ) {
     903                                } else if ( arg->get_results().front()->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->set_result( arg->get_type()->clone() );
     989                                        deref->get_results().push_back( arg->get_type()->clone() );
    990990                                        return deref;
    991991                                } // if
     
    11241124                        } // if
    11251125                        addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType ) ) ) );
    1126                         addAssign->set_result( appExpr->get_result()->clone() );
     1126                        addAssign->get_results().front() = appExpr->get_results().front()->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->has_result() );
     1140                                                assert( ! appExpr->get_results().empty() );
    11411141                                                assert( appExpr->get_args().size() == 2 );
    1142                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
    1143                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
     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 );
    11441144                                                assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
    11451145                                                UntypedExpr *ret = 0;
     
    11611161                                                } // if
    11621162                                                if ( baseType1 || baseType2 ) {
    1163                                                         ret->set_result( appExpr->get_result()->clone() );
     1163                                                        ret->get_results().push_front( appExpr->get_results().front()->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->has_result() );
     1173                                                assert( ! appExpr->get_results().empty() );
    11741174                                                assert( ! appExpr->get_args().empty() );
    1175                                                 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
     1175                                                if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
    11761176                                                        Expression *ret = appExpr->get_args().front();
    1177                                                         delete ret->get_result();
    1178                                                         ret->set_result( appExpr->get_result()->clone() );
     1177                                                        delete ret->get_results().front();
     1178                                                        ret->get_results().front() = appExpr->get_results().front()->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->has_result() );
     1188                                                assert( ! appExpr->get_results().empty() );
    11891189                                                assert( appExpr->get_args().size() == 1 );
    1190                                                 if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
    1191                                                         Type *tempType = appExpr->get_result()->clone();
     1190                                                if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
     1191                                                        Type *tempType = appExpr->get_results().front()->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->has_result() );
     1208                                                assert( ! appExpr->get_results().empty() );
    12091209                                                assert( appExpr->get_args().size() == 1 );
    1210                                                 if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
     1210                                                if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), 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->has_result() );
     1214                                                assert( ! appExpr->get_results().empty() );
    12151215                                                assert( appExpr->get_args().size() == 2 );
    1216                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
    1217                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
     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 );
    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->set_result( appExpr->get_result()->clone() );
     1222                                                        divide->get_results().push_front( appExpr->get_results().front()->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->has_result() );
     1240                                                assert( ! appExpr->get_results().empty() );
    12411241                                                assert( appExpr->get_args().size() == 2 );
    1242                                                 Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env );
     1242                                                Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
    12431243                                                if ( baseType ) {
    12441244                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
     
    12661266                        useRetval = oldUseRetval;
    12671267
    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() );
     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 );
    12711273
    12721274                        if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
     
    13061308
    13071309                Expression *Pass1::mutate( UntypedExpr *expr ) {
    1308                         if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
     1310                        if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
    13091311                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13101312                                        if ( name->get_name() == "*?" ) {
     
    13201322
    13211323                Expression *Pass1::mutate( AddressExpr *addrExpr ) {
    1322                         assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() );
     1324                        assert( ! addrExpr->get_arg()->get_results().empty() );
    13231325
    13241326                        bool needs = false;
    13251327                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1326                                 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
     1328                                if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
    13271329                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13281330                                                if ( name->get_name() == "*?" ) {
    13291331                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    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() );
     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 );
    13331337                                                                needs = needsAdapter( function, scopeTyVars );
    13341338                                                        } // if
     
    13391343                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    13401344                        // out of the if condition.
    1341                         bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
     1345                        bool polytype = isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env );
    13421346                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    13431347                        if ( polytype || needs ) {
    13441348                                Expression *ret = addrExpr->get_arg();
    1345                                 delete ret->get_result();
    1346                                 ret->set_result( addrExpr->get_result()->clone() );
     1349                                delete ret->get_results().front();
     1350                                ret->get_results().front() = addrExpr->get_results().front()->clone();
    13471351                                addrExpr->set_arg( 0 );
    13481352                                delete addrExpr;
     
    13821386                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    13831387                        if ( retval && returnStmt->get_expr() ) {
    1384                                 assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() );
     1388                                assert( ! returnStmt->get_expr()->get_results().empty() );
    13851389                                // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
    13861390                                // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     
    14621466                                // replace return statement with appropriate assignment to out parameter
    14631467                                Expression *retParm = new NameExpr( retval->get_name() );
    1464                                 retParm->set_result( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     1468                                retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
    14651469                                assignExpr->get_args().push_back( retParm );
    14661470                                assignExpr->get_args().push_back( returnStmt->get_expr() );
Note: See TracChangeset for help on using the changeset viewer.