Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    ra8706fc r43bd69d  
    698698                        const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart,
    699699                        const SymTab::Indexer& indexer, unsigned nTuples = 0 ) {
    700                 if ( TupleType * tupleType = dynamic_cast<TupleType*>( formalType ) ) {
     700                if ( TupleType* tupleType = dynamic_cast<TupleType*>( formalType ) ) {
    701701                        // formalType is a TupleType - group actuals into a TupleExpr
    702702                        ++nTuples;
    703703                        for ( Type* type : *tupleType ) {
    704704                                // xxx - dropping initializer changes behaviour from previous, but seems correct
    705                                 // ^^^ need to handle the case where a tuple has a default argument
    706705                                if ( ! instantiateArgument(
    707706                                                type, nullptr, args, results, genStart, indexer, nTuples ) )
     
    714713                        }
    715714                        return true;
    716                 } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) {
     715                } else if ( TypeInstType* ttype = Tuples::isTtype( formalType ) ) {
    717716                        // formalType is a ttype, consumes all remaining arguments
    718717                        // xxx - mixing default arguments with variadic??
     
    917916                                // consider only first exploded actual
    918917                                Expression* expr = expl.exprs.front().get();
    919                                 Type* actualType = expr->result->clone();
     918                                Type* actualType = expr->get_result()->clone();
    920919
    921920                                PRINT(
     
    948947                ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
    949948                // sum cost and accumulate actuals
    950                 std::list<Expression*>& args = appExpr->args;
     949                std::list<Expression*>& args = appExpr->get_args();
    951950                Cost cost = func.cost;
    952951                const ArgPack* pack = &result;
     
    975974                // add all type variables as open variables now so that those not used in the parameter
    976975                // list are still considered open.
    977                 funcEnv.add( funcType->forall );
    978 
    979                 if ( targetType && ! targetType->isVoid() && ! funcType->returnVals.empty() ) {
     976                funcEnv.add( funcType->get_forall() );
     977
     978                if ( targetType && ! targetType->isVoid() && ! funcType->get_returnVals().empty() ) {
    980979                        // attempt to narrow based on expected target type
    981                         Type * returnType = funcType->returnVals.front()->get_type();
     980                        Type * returnType = funcType->get_returnVals().front()->get_type();
    982981                        if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars,
    983982                                        indexer ) ) {
     
    992991                std::size_t genStart = 0;
    993992
    994                 for ( DeclarationWithType* formal : funcType->parameters ) {
     993                for ( DeclarationWithType* formal : funcType->get_parameters() ) {
    995994                        ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal );
    996995                        if ( ! instantiateArgument(
    997                                         obj->type, obj->init, args, results, genStart, indexer ) )
     996                                        obj->get_type(), obj->get_init(), args, results, genStart, indexer ) )
    998997                                return;
    999998                }
     
    10761075        void AlternativeFinder::Finder::postvisit( UntypedExpr *untypedExpr ) {
    10771076                AlternativeFinder funcFinder( indexer, env );
    1078                 funcFinder.findWithAdjustment( untypedExpr->function );
     1077                funcFinder.findWithAdjustment( untypedExpr->get_function() );
    10791078                // if there are no function alternatives, then proceeding is a waste of time.
    10801079                if ( funcFinder.alternatives.empty() ) return;
     
    11211120                                )
    11221121                                // check if the type is pointer to function
    1123                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->result->stripReferences() ) ) {
    1124                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->base ) ) {
     1122                                if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) {
     1123                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    11251124                                                Alternative newFunc( *func );
    11261125                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11281127                                                        std::back_inserter( candidates ) );
    11291128                                        }
    1130                                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
     1129                                } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
    11311130                                        EqvClass eqvClass;
    1132                                         if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) {
     1131                                        if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) {
    11331132                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11341133                                                        Alternative newFunc( *func );
     
    11591158                                        // check if type is a pointer to function
    11601159                                        if ( PointerType* pointer = dynamic_cast<PointerType*>(
    1161                                                         funcOp->expr->result->stripReferences() ) ) {
     1160                                                        funcOp->expr->get_result()->stripReferences() ) ) {
    11621161                                                if ( FunctionType* function =
    1163                                                                 dynamic_cast<FunctionType*>( pointer->base ) ) {
     1162                                                                dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
    11641163                                                        Alternative newFunc( *funcOp );
    11651164                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11831182                        PRINT(
    11841183                                ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr );
    1185                                 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->function->result );
    1186                                 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->base );
    1187                                 std::cerr << "Case +++++++++++++ " << appExpr->function << std::endl;
     1184                                PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     1185                                FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
     1186                                std::cerr << "Case +++++++++++++ " << appExpr->get_function() << std::endl;
    11881187                                std::cerr << "formals are:" << std::endl;
    1189                                 printAll( function->parameters, std::cerr, 8 );
     1188                                printAll( function->get_parameters(), std::cerr, 8 );
    11901189                                std::cerr << "actuals are:" << std::endl;
    1191                                 printAll( appExpr->args, std::cerr, 8 );
     1190                                printAll( appExpr->get_args(), std::cerr, 8 );
    11921191                                std::cerr << "bindings are:" << std::endl;
    11931192                                withFunc.env.print( std::cerr, 8 );
     
    12301229        bool isLvalue( Expression *expr ) {
    12311230                // xxx - recurse into tuples?
    1232                 return expr->result && ( expr->result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result ) );
     1231                return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
    12331232        }
    12341233
     
    12861285                AlternativeFinder finder( indexer, env );
    12871286                finder.targetType = toType;
    1288                 finder.findWithAdjustment( castExpr->arg );
     1287                finder.findWithAdjustment( castExpr->get_arg() );
    12891288
    12901289                AltList candidates;
     
    12931292                        OpenVarSet openVars;
    12941293
    1295                         alt.env.extractOpenVars( openVars );
    1296 
    12971294                        // It's possible that a cast can throw away some values in a multiply-valued expression.  (An example is a
    12981295                        // cast-to-void, which casts from one value to zero.)  Figure out the prefix of the subexpression results
    12991296                        // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
    13001297                        // to.
    1301                         int discardedValues = alt.expr->result->size() - castExpr->result->size();
     1298                        int discardedValues = alt.expr->get_result()->size() - castExpr->get_result()->size();
    13021299                        if ( discardedValues < 0 ) continue;
    13031300                        // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not
    13041301                        // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))
    13051302                        // unification run for side-effects
    1306                         unify( castExpr->result, alt.expr->result, alt.env, needAssertions,
     1303                        unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions,
    13071304                                haveAssertions, openVars, indexer );
    1308                         Cost thisCost = castCost( alt.expr->result, castExpr->result, indexer,
     1305                        Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer,
    13091306                                alt.env );
    13101307                        PRINT(
     
    17121709                        AlternativeFinder finder( indexer, env );
    17131710                        finder.targetType = toType;
    1714                         finder.findWithAdjustment( initExpr->expr );
     1711                        finder.findWithAdjustment( initExpr->get_expr() );
    17151712                        for ( Alternative & alt : finder.get_alternatives() ) {
    17161713                                TypeEnvironment newEnv( alt.env );
     
    17191716                                PRINT(
    17201717                                        std::cerr << "  @ " << toType << " " << initAlt.designation << std::endl;
    1721                                 )
     1718                                 )
    17221719                                // It's possible that a cast can throw away some values in a multiply-valued expression.  (An example is a
    17231720                                // cast-to-void, which casts from one value to zero.)  Figure out the prefix of the subexpression results
    17241721                                // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
    17251722                                // to.
    1726                                 int discardedValues = alt.expr->result->size() - toType->size();
     1723                                int discardedValues = alt.expr->get_result()->size() - toType->size();
    17271724                                if ( discardedValues < 0 ) continue;
    17281725                                // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not
    17291726                                // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))
    17301727                                // unification run for side-effects
    1731                                 unify( toType, alt.expr->result, newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type??
    1732 
    1733                                 Cost thisCost = castCost( alt.expr->result, toType, indexer, newEnv );
     1728                                unify( toType, alt.expr->get_result(), newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type??
     1729
     1730                                Cost thisCost = castCost( alt.expr->get_result(), toType, indexer, newEnv );
    17341731                                if ( thisCost != Cost::infinity ) {
    17351732                                        // count one safe conversion for each value that is thrown away
Note: See TracChangeset for help on using the changeset viewer.