Changeset 6f81db3
- Timestamp:
- Apr 13, 2018, 5:00:24 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- 24de7b1
- Parents:
- 04570c7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r04570c7 r6f81db3 102 102 void addAnonConversions( const Alternative & alt ); 103 103 /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member 104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member);104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ); 105 105 /// Adds alternatives for member expressions where the left side has tuple type 106 106 void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ); … … 306 306 307 307 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 308 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, new NameExpr(""));308 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 309 309 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 310 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, new NameExpr(""));310 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 311 311 } // if 312 312 } 313 313 314 314 template< typename StructOrUnionType > 315 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) { 316 // by this point, member must be a name expr 317 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ); 318 if ( ! nameExpr ) return; 319 const std::string & name = nameExpr->get_name(); 315 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) { 320 316 std::list< Declaration* > members; 321 317 aggInst->lookup( name, members ); … … 1335 1331 } 1336 1332 1333 namespace { 1334 /// Gets name from untyped member expression (member must be NameExpr) 1335 const std::string& get_member_name( UntypedMemberExpr *memberExpr ) { 1336 NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() ); 1337 assert( nameExpr ); 1338 return nameExpr->get_name(); 1339 } 1340 } 1341 1337 1342 void AlternativeFinder::Finder::postvisit( UntypedMemberExpr *memberExpr ) { 1338 1343 AlternativeFinder funcFinder( indexer, env ); … … 1346 1351 // find member of the given type 1347 1352 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 1348 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1353 addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1349 1354 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 1350 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1355 addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1351 1356 } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) { 1352 1357 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
Note: See TracChangeset
for help on using the changeset viewer.