Changeset add7117 for src/ResolvExpr


Ignore:
Timestamp:
Sep 10, 2016, 11:08:47 AM (8 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, resolv-new, with_gc
Children:
5af62f1
Parents:
f5e81d1 (diff), 03e3117 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into tuples

Conflicts:

src/ResolvExpr/AlternativeFinder.cc
src/ResolvExpr/AlternativeFinder.h

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rf5e81d1 radd7117  
    209209        }
    210210
    211         void AlternativeFinder::find( Expression *expr, bool adjust ) {
     211        void AlternativeFinder::find( Expression *expr, bool adjust, bool prune ) {
    212212                expr->accept( *this );
    213213                if ( alternatives.empty() ) {
     
    219219                        }
    220220                }
    221                 PRINT(
    222                         std::cerr << "alternatives before prune:" << std::endl;
    223                         printAlts( alternatives, std::cerr );
    224                 )
    225                 AltList::iterator oldBegin = alternatives.begin();
    226                 pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer );
    227                 if ( alternatives.begin() == oldBegin ) {
    228                         std::ostringstream stream;
    229                         stream << "Can't choose between alternatives for expression ";
    230                         expr->print( stream );
    231                         stream << "Alternatives are:";
    232                         AltList winners;
    233                         findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) );
    234                         printAlts( winners, stream, 8 );
    235                         throw SemanticError( stream.str() );
    236                 }
    237                 alternatives.erase( oldBegin, alternatives.end() );
    238                 PRINT(
    239                         std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    240                 )
     221                if ( prune ) {
     222                        PRINT(
     223                                std::cerr << "alternatives before prune:" << std::endl;
     224                                printAlts( alternatives, std::cerr );
     225                        )
     226                        AltList::iterator oldBegin = alternatives.begin();
     227                        pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer );
     228                        if ( alternatives.begin() == oldBegin ) {
     229                                std::ostringstream stream;
     230                                stream << "Can't choose between alternatives for expression ";
     231                                expr->print( stream );
     232                                stream << "Alternatives are:";
     233                                AltList winners;
     234                                findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) );
     235                                printAlts( winners, stream, 8 );
     236                                throw SemanticError( stream.str() );
     237                        }
     238                        alternatives.erase( oldBegin, alternatives.end() );
     239                        PRINT(
     240                                std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
     241                        )
     242                }
    241243
    242244                // Central location to handle gcc extension keyword for all expression types.
     
    246248        }
    247249
    248         void AlternativeFinder::findWithAdjustment( Expression *expr ) {
    249                 find( expr, true );
     250        void AlternativeFinder::findWithAdjustment( Expression *expr, bool prune ) {
     251                find( expr, true, prune );
    250252        }
    251253
    252254        template< typename StructOrUnionType >
    253         void AlternativeFinder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, Expression * member ) {
     255        void AlternativeFinder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
    254256                NameExpr * nameExpr = safe_dynamic_cast< NameExpr * >( member );
    255257                const std::string & name = nameExpr->get_name();
    256 
    257258                std::list< Declaration* > members;
    258259                aggInst->lookup( name, members );
     
    813814                        if ( agg->expr->get_results().size() == 1 ) {
    814815                                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( agg->expr->get_results().front() ) ) {
    815                                         addAggMembers( structInst, agg->expr, agg->cost, memberExpr->get_member() );
     816                                        addAggMembers( structInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    816817                                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( agg->expr->get_results().front() ) ) {
    817                                         addAggMembers( unionInst, agg->expr, agg->cost, memberExpr->get_member() );
     818                                        addAggMembers( unionInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    818819                                } // if
    819820                        } // if
     
    843844                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) {
    844845                                NameExpr nameExpr( "" );
    845                                 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), &nameExpr );
     846                                addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr );
    846847                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) {
    847848                                NameExpr nameExpr( "" );
    848                                 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), &nameExpr );
     849                                addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr );
    849850                        } // if
    850851                } // for
     
    10671068                alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) );
    10681069        }
     1070
     1071        void AlternativeFinder::visit( ConstructorExpr * ctorExpr ) {
     1072                AlternativeFinder finder( indexer, env );
     1073                // don't prune here, since it's guaranteed all alternatives will have the same type
     1074                // (giving the alternatives different types is half of the point of ConstructorExpr nodes)
     1075                finder.findWithAdjustment( ctorExpr->get_callExpr(), false );
     1076                for ( Alternative & alt : finder.alternatives ) {
     1077                        alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
     1078                }
     1079        }
    10691080} // namespace ResolvExpr
    10701081
  • src/ResolvExpr/AlternativeFinder.h

    rf5e81d1 radd7117  
    2929          public:
    3030                AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env );
    31                 void find( Expression *expr, bool adjust = false );
     31                void find( Expression *expr, bool adjust = false, bool prune = true );
    3232                /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types
    33                 void findWithAdjustment( Expression *expr );
     33                void findWithAdjustment( Expression *expr, bool prune = true );
    3434                AltList &get_alternatives() { return alternatives; }
    3535
     
    6666                virtual void visit( TupleExpr *tupleExpr );
    6767                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
     68                virtual void visit( ConstructorExpr * ctorExpr );
    6869          public:  // xxx - temporary hack - should make Tuples::TupleAssignment a friend
    6970          /// Runs a new alternative finder on each element in [begin, end)
     
    7475          private:
    7576                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    76                 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, Expression * member );
     77                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
    7778                /// Adds alternatives for offsetof expressions, given the base type and name of the member
    7879                template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
Note: See TracChangeset for help on using the changeset viewer.