Changeset add7117 for src/ResolvExpr
- Timestamp:
- Sep 10, 2016, 11:08:47 AM (8 years ago)
- 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. - Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rf5e81d1 radd7117 209 209 } 210 210 211 void AlternativeFinder::find( Expression *expr, bool adjust ) {211 void AlternativeFinder::find( Expression *expr, bool adjust, bool prune ) { 212 212 expr->accept( *this ); 213 213 if ( alternatives.empty() ) { … … 219 219 } 220 220 } 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 } 241 243 242 244 // Central location to handle gcc extension keyword for all expression types. … … 246 248 } 247 249 248 void AlternativeFinder::findWithAdjustment( Expression *expr ) {249 find( expr, true );250 void AlternativeFinder::findWithAdjustment( Expression *expr, bool prune ) { 251 find( expr, true, prune ); 250 252 } 251 253 252 254 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 ) { 254 256 NameExpr * nameExpr = safe_dynamic_cast< NameExpr * >( member ); 255 257 const std::string & name = nameExpr->get_name(); 256 257 258 std::list< Declaration* > members; 258 259 aggInst->lookup( name, members ); … … 813 814 if ( agg->expr->get_results().size() == 1 ) { 814 815 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() ); 816 817 } 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() ); 818 819 } // if 819 820 } // if … … 843 844 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) { 844 845 NameExpr nameExpr( "" ); 845 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), &nameExpr );846 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr ); 846 847 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) { 847 848 NameExpr nameExpr( "" ); 848 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), &nameExpr );849 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr ); 849 850 } // if 850 851 } // for … … 1067 1068 alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) ); 1068 1069 } 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 } 1069 1080 } // namespace ResolvExpr 1070 1081 -
src/ResolvExpr/AlternativeFinder.h
rf5e81d1 radd7117 29 29 public: 30 30 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 ); 32 32 /// 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 ); 34 34 AltList &get_alternatives() { return alternatives; } 35 35 … … 66 66 virtual void visit( TupleExpr *tupleExpr ); 67 67 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ); 68 virtual void visit( ConstructorExpr * ctorExpr ); 68 69 public: // xxx - temporary hack - should make Tuples::TupleAssignment a friend 69 70 /// Runs a new alternative finder on each element in [begin, end) … … 74 75 private: 75 76 /// 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 ); 77 78 /// Adds alternatives for offsetof expressions, given the base type and name of the member 78 79 template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
Note: See TracChangeset
for help on using the changeset viewer.