Ignore:
Timestamp:
Jun 20, 2017, 1:19:53 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
579263a
Parents:
c6d2e93
git-author:
Rob Schluntz <rschlunt@…> (06/20/17 13:16:13)
git-committer:
Rob Schluntz <rschlunt@…> (06/20/17 13:19:53)
Message:

major effort on designations, works in many cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rc6d2e93 re4d829b  
    604604//          )
    605605                SymTab::Indexer decls( indexer );
    606                 PRINT(
    607                         std::cerr << "============= original indexer" << std::endl;
    608                         indexer.print( std::cerr );
    609                         std::cerr << "============= new indexer" << std::endl;
    610                         decls.print( std::cerr );
    611                 )
     606                // PRINT(
     607                //      std::cerr << "============= original indexer" << std::endl;
     608                //      indexer.print( std::cerr );
     609                //      std::cerr << "============= new indexer" << std::endl;
     610                //      decls.print( std::cerr );
     611                // )
    612612                addToIndexer( have, decls );
    613613                AssertionSet newNeed;
     
    11821182        }
    11831183
     1184        void AlternativeFinder::visit( UntypedInitExpr *initExpr ) {
     1185                AlternativeFinder finder( indexer, env );
     1186                finder.findWithAdjustment( initExpr->get_expr() );
     1187                // handle each option like a cast -- should probably push this info into AltFinder as a kind of expression, both to keep common code close and to have less 'reach-in', but more 'push-in'
     1188                AltList candidates;
     1189                std::cerr << "untyped init expr: " << initExpr << std::endl;
     1190                // O(N^2) checks of d-types with e-types
     1191                for ( Alternative & alt : finder.get_alternatives() ) {
     1192                        for ( InitAlternative & initAlt : initExpr->get_initAlts() ) {
     1193                                AssertionSet needAssertions, haveAssertions;
     1194                                OpenVarSet openVars;
     1195                                std::cerr << "  " << initAlt.type << " " << initAlt.designation << std::endl;
     1196                                // It's possible that a cast can throw away some values in a multiply-valued expression.  (An example is a
     1197                                // cast-to-void, which casts from one value to zero.)  Figure out the prefix of the subexpression results
     1198                                // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
     1199                                // to.
     1200                                int discardedValues = alt.expr->get_result()->size() - initAlt.type->size();
     1201                                if ( discardedValues < 0 ) continue;
     1202                                // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not
     1203                                // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))
     1204                                // unification run for side-effects
     1205                                unify( initAlt.type, alt.expr->get_result(), alt.env, needAssertions, haveAssertions, openVars, indexer );
     1206
     1207                                Cost thisCost = castCost( alt.expr->get_result(), initAlt.type, indexer, alt.env );
     1208                                if ( thisCost != Cost::infinity ) {
     1209                                        // count one safe conversion for each value that is thrown away
     1210                                        thisCost += Cost( 0, 0, discardedValues );
     1211                                        candidates.push_back( Alternative( new InitExpr( alt.expr->clone(), initAlt.type->clone(), initAlt.designation->clone() ), alt.env, alt.cost, thisCost ) );
     1212                                }
     1213                        }
     1214                }
     1215
     1216                // findMinCost selects the alternatives with the lowest "cost" members, but has the side effect of copying the
     1217                // cvtCost member to the cost member (since the old cost is now irrelevant).  Thus, calling findMinCost twice
     1218                // selects first based on argument cost, then on conversion cost.
     1219                AltList minArgCost;
     1220                findMinCost( candidates.begin(), candidates.end(), std::back_inserter( minArgCost ) );
     1221                findMinCost( minArgCost.begin(), minArgCost.end(), std::back_inserter( alternatives ) );
     1222        }
    11841223} // namespace ResolvExpr
    11851224
Note: See TracChangeset for help on using the changeset viewer.