Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rae1b9ea ra31b384  
    600600
    601601                        // add size/align for generic types to parameter list
    602                         if ( ! appExpr->get_function()->result ) return;
     602                        if ( ! appExpr->get_function()->has_result() ) return;
    603603                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() );
    604604                        assert( funcType );
     
    714714
    715715                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    716                         assertf( arg->result, "arg does not have result: %s", toString( arg ).c_str() );
    717                         if ( ! needsBoxing( param, arg->result, exprTyVars, env ) ) return;
    718 
    719                         if ( arg->result->get_lvalue() ) {
    720                                 // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
    721                                 // if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( arg ) ) {
    722                                 //      if ( dynamic_cast<ArrayType *>( varExpr->var->get_type() ) ){
    723                                 //              // temporary hack - don't box arrays, because &arr is not the same as &arr[0]
    724                                 //              return;
    725                                 //      }
    726                                 // }
    727                                 arg =  generalizedLvalue( new AddressExpr( arg ) );
    728                                 if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    729                                         // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
    730                                         arg = new CastExpr( arg, param->clone() );
    731                                 }
    732                         } else {
    733                                 // use type computed in unification to declare boxed variables
    734                                 Type * newType = param->clone();
     716                        assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
     717                        if ( isPolyType( param, exprTyVars ) ) {
     718                                Type * newType = arg->get_result()->clone();
    735719                                if ( env ) env->apply( newType );
    736                                 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, newType, 0 );
    737                                 newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    738                                 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    739                                 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax?
    740                                 assign->get_args().push_back( new VariableExpr( newObj ) );
    741                                 assign->get_args().push_back( arg );
    742                                 stmtsToAddBefore.push_back( new ExprStmt( noLabels, assign ) );
    743                                 arg = new AddressExpr( new VariableExpr( newObj ) );
     720                                std::unique_ptr<Type> manager( newType );
     721                                if ( isPolyType( newType ) ) {
     722                                        // if the argument's type is polymorphic, we don't need to box again!
     723                                        return;
     724                                } else if ( arg->get_result()->get_lvalue() ) {
     725                                        // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
     726                                        // if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( arg ) ) {
     727                                        //      if ( dynamic_cast<ArrayType *>( varExpr->var->get_type() ) ){
     728                                        //              // temporary hack - don't box arrays, because &arr is not the same as &arr[0]
     729                                        //              return;
     730                                        //      }
     731                                        // }
     732                                        arg =  generalizedLvalue( new AddressExpr( arg ) );
     733                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
     734                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     735                                                arg = new CastExpr( arg, param->clone() );
     736                                        }
     737                                } else {
     738                                        // use type computed in unification to declare boxed variables
     739                                        Type * newType = param->clone();
     740                                        if ( env ) env->apply( newType );
     741                                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, newType, 0 );
     742                                        newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
     743                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
     744                                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax?
     745                                        assign->get_args().push_back( new VariableExpr( newObj ) );
     746                                        assign->get_args().push_back( arg );
     747                                        stmtsToAddBefore.push_back( new ExprStmt( noLabels, assign ) );
     748                                        arg = new AddressExpr( new VariableExpr( newObj ) );
     749                                } // if
    744750                        } // if
    745751                }
     
    959965                                if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
    960966                                        if ( varExpr->get_var()->get_name() == "?[?]" ) {
    961                                                 assert( appExpr->result );
     967                                                assert( appExpr->has_result() );
    962968                                                assert( appExpr->get_args().size() == 2 );
    963969                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     
    993999                                                } // if
    9941000                                        } else if ( varExpr->get_var()->get_name() == "*?" ) {
    995                                                 assert( appExpr->result );
     1001                                                assert( appExpr->has_result() );
    9961002                                                assert( ! appExpr->get_args().empty() );
    9971003                                                if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
     
    10101016                                                } // if
    10111017                                        } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) {
    1012                                                 assert( appExpr->result );
     1018                                                assert( appExpr->has_result() );
    10131019                                                assert( appExpr->get_args().size() == 1 );
    10141020                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
     
    10301036                                                } // if
    10311037                                        } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) {
    1032                                                 assert( appExpr->result );
     1038                                                assert( appExpr->has_result() );
    10331039                                                assert( appExpr->get_args().size() == 1 );
    10341040                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
     
    10361042                                                } // if
    10371043                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
    1038                                                 assert( appExpr->result );
     1044                                                assert( appExpr->has_result() );
    10391045                                                assert( appExpr->get_args().size() == 2 );
    10401046                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     
    10621068                                                } // if
    10631069                                        } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) {
    1064                                                 assert( appExpr->result );
     1070                                                assert( appExpr->has_result() );
    10651071                                                assert( appExpr->get_args().size() == 2 );
    10661072                                                Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env );
     
    11561162                void Pass1::premutate( AddressExpr * ) { visit_children = false; }
    11571163                Expression * Pass1::postmutate( AddressExpr * addrExpr ) {
    1158                         assert( addrExpr->get_arg()->result && ! addrExpr->get_arg()->get_result()->isVoid() );
     1164                        assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() );
    11591165
    11601166                        bool needs = false;
    11611167                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1162                                 if ( expr->result && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
     1168                                if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    11631169                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    11641170                                                if ( name->get_name() == "*?" ) {
    11651171                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    1166                                                                 assert( appExpr->get_function()->result );
     1172                                                                assert( appExpr->get_function()->has_result() );
    11671173                                                                FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
    11681174                                                                assert( function );
Note: See TracChangeset for help on using the changeset viewer.