Changeset 3d2ae8d


Ignore:
Timestamp:
May 22, 2018, 3:19:18 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:
753bf60
Parents:
2f0a0678
Message:

Minor cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r2f0a0678 r3d2ae8d  
    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
    705706                                if ( ! instantiateArgument(
    706707                                                type, nullptr, args, results, genStart, indexer, nTuples ) )
     
    713714                        }
    714715                        return true;
    715                 } else if ( TypeInstType* ttype = Tuples::isTtype( formalType ) ) {
     716                } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) {
    716717                        // formalType is a ttype, consumes all remaining arguments
    717718                        // xxx - mixing default arguments with variadic??
     
    916917                                // consider only first exploded actual
    917918                                Expression* expr = expl.exprs.front().get();
    918                                 Type* actualType = expr->get_result()->clone();
     919                                Type* actualType = expr->result->clone();
    919920
    920921                                PRINT(
     
    947948                ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
    948949                // sum cost and accumulate actuals
    949                 std::list<Expression*>& args = appExpr->get_args();
     950                std::list<Expression*>& args = appExpr->args;
    950951                Cost cost = func.cost;
    951952                const ArgPack* pack = &result;
     
    974975                // add all type variables as open variables now so that those not used in the parameter
    975976                // list are still considered open.
    976                 funcEnv.add( funcType->get_forall() );
    977 
    978                 if ( targetType && ! targetType->isVoid() && ! funcType->get_returnVals().empty() ) {
     977                funcEnv.add( funcType->forall );
     978
     979                if ( targetType && ! targetType->isVoid() && ! funcType->returnVals.empty() ) {
    979980                        // attempt to narrow based on expected target type
    980                         Type * returnType = funcType->get_returnVals().front()->get_type();
     981                        Type * returnType = funcType->returnVals.front()->get_type();
    981982                        if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars,
    982983                                        indexer ) ) {
     
    991992                std::size_t genStart = 0;
    992993
    993                 for ( DeclarationWithType* formal : funcType->get_parameters() ) {
     994                for ( DeclarationWithType* formal : funcType->parameters ) {
    994995                        ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal );
    995996                        if ( ! instantiateArgument(
    996                                         obj->get_type(), obj->get_init(), args, results, genStart, indexer ) )
     997                                        obj->type, obj->init, args, results, genStart, indexer ) )
    997998                                return;
    998999                }
     
    10751076        void AlternativeFinder::Finder::postvisit( UntypedExpr *untypedExpr ) {
    10761077                AlternativeFinder funcFinder( indexer, env );
    1077                 funcFinder.findWithAdjustment( untypedExpr->get_function() );
     1078                funcFinder.findWithAdjustment( untypedExpr->function );
    10781079                // if there are no function alternatives, then proceeding is a waste of time.
    10791080                if ( funcFinder.alternatives.empty() ) return;
     
    11201121                                )
    11211122                                // check if the type is pointer to function
    1122                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) {
    1123                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     1123                                if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->result->stripReferences() ) ) {
     1124                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->base ) ) {
    11241125                                                Alternative newFunc( *func );
    11251126                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11271128                                                        std::back_inserter( candidates ) );
    11281129                                        }
    1129                                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
     1130                                } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
    11301131                                        EqvClass eqvClass;
    1131                                         if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) {
     1132                                        if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) {
    11321133                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11331134                                                        Alternative newFunc( *func );
     
    11581159                                        // check if type is a pointer to function
    11591160                                        if ( PointerType* pointer = dynamic_cast<PointerType*>(
    1160                                                         funcOp->expr->get_result()->stripReferences() ) ) {
     1161                                                        funcOp->expr->result->stripReferences() ) ) {
    11611162                                                if ( FunctionType* function =
    1162                                                                 dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
     1163                                                                dynamic_cast<FunctionType*>( pointer->base ) ) {
    11631164                                                        Alternative newFunc( *funcOp );
    11641165                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11821183                        PRINT(
    11831184                                ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr );
    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;
     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;
    11871188                                std::cerr << "formals are:" << std::endl;
    1188                                 printAll( function->get_parameters(), std::cerr, 8 );
     1189                                printAll( function->parameters, std::cerr, 8 );
    11891190                                std::cerr << "actuals are:" << std::endl;
    1190                                 printAll( appExpr->get_args(), std::cerr, 8 );
     1191                                printAll( appExpr->args, std::cerr, 8 );
    11911192                                std::cerr << "bindings are:" << std::endl;
    11921193                                withFunc.env.print( std::cerr, 8 );
     
    12291230        bool isLvalue( Expression *expr ) {
    12301231                // xxx - recurse into tuples?
    1231                 return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
     1232                return expr->result && ( expr->result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result ) );
    12321233        }
    12331234
     
    17091710                        AlternativeFinder finder( indexer, env );
    17101711                        finder.targetType = toType;
    1711                         finder.findWithAdjustment( initExpr->get_expr() );
     1712                        finder.findWithAdjustment( initExpr->expr );
    17121713                        for ( Alternative & alt : finder.get_alternatives() ) {
    17131714                                TypeEnvironment newEnv( alt.env );
     
    17161717                                PRINT(
    17171718                                        std::cerr << "  @ " << toType << " " << initAlt.designation << std::endl;
    1718                                  )
     1719                                )
    17191720                                // It's possible that a cast can throw away some values in a multiply-valued expression.  (An example is a
    17201721                                // cast-to-void, which casts from one value to zero.)  Figure out the prefix of the subexpression results
    17211722                                // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
    17221723                                // to.
    1723                                 int discardedValues = alt.expr->get_result()->size() - toType->size();
     1724                                int discardedValues = alt.expr->result->size() - toType->size();
    17241725                                if ( discardedValues < 0 ) continue;
    17251726                                // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not
     
    17281729                                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??
    17291730
    1730                                 Cost thisCost = castCost( alt.expr->get_result(), toType, indexer, newEnv );
     1731                                Cost thisCost = castCost( alt.expr->result, toType, indexer, newEnv );
    17311732                                if ( thisCost != Cost::infinity ) {
    17321733                                        // count one safe conversion for each value that is thrown away
Note: See TracChangeset for help on using the changeset viewer.