- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r64ac636 r4b0f997 10 10 // Created On : Sat May 16 23:52:08 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 4 17:02:51 201613 // Update Count : 2912 // Last Modified On : Fri Mar 17 09:14:17 2017 13 // Update Count : 30 14 14 // 15 15 … … 211 211 } 212 212 213 // std::unordered_map< Expression *, UniqueExpr * > ; 213 void AlternativeFinder::addAnonConversions( const Alternative & alt ) { 214 // adds anonymous member interpretations whenever an aggregate value type is seen. 215 Expression * expr = alt.expr->clone(); 216 std::unique_ptr< Expression > manager( expr ); // RAII for expr 217 alt.env.apply( expr->get_result() ); 218 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( expr->get_result() ) ) { 219 NameExpr nameExpr( "" ); 220 addAggMembers( structInst, expr, alt.cost+Cost( 0, 0, 1 ), alt.env, &nameExpr ); 221 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( expr->get_result() ) ) { 222 NameExpr nameExpr( "" ); 223 addAggMembers( unionInst, expr, alt.cost+Cost( 0, 0, 1 ), alt.env, &nameExpr ); 224 } // if 225 } 214 226 215 227 template< typename StructOrUnionType > … … 220 232 std::list< Declaration* > members; 221 233 aggInst->lookup( name, members ); 234 222 235 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 223 236 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 224 237 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 225 238 renameTypes( alternatives.back().expr ); 239 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 226 240 } else { 227 241 assert( false ); … … 730 744 if ( candidates.empty() && ! errors.isEmpty() ) { throw errors; } 731 745 746 // compute conversionsion costs 732 747 for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) { 733 748 Cost cvtCost = computeConversionCost( *withFunc, indexer ); … … 751 766 } // if 752 767 } // for 768 // function may return struct or union value, in which case we need to add alternatives for implicit conversions to each of the anonymous members 769 for ( const Alternative & alt : alternatives ) { 770 addAnonConversions( alt ); 771 } 772 753 773 candidates.clear(); 754 774 candidates.splice( candidates.end(), alternatives ); … … 772 792 bool isLvalue( Expression *expr ) { 773 793 // xxx - recurse into tuples? 774 return expr->has_result() && expr->get_result()->get_ isLvalue();794 return expr->has_result() && expr->get_result()->get_lvalue(); 775 795 } 776 796 … … 885 905 ) 886 906 renameTypes( alternatives.back().expr ); 887 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) { 888 NameExpr nameExpr( "" ); 889 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr ); 890 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) { 891 NameExpr nameExpr( "" ); 892 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), env, &nameExpr ); 893 } // if 907 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 894 908 } // for 895 909 }
Note: See TracChangeset
for help on using the changeset viewer.