Changes in / [4f57930:87c5f40]
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r4f57930 r87c5f40 226 226 \end{lstlisting} 227 227 Within the block, the nested version of @<@ performs @>@ and this local version overrides the built-in @<@ so it is passed to @qsort@. 228 Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.228 Hence, programmers can easily form a local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types. 229 229 230 230 Finally, \CFA allows variable overloading: -
src/ResolvExpr/AlternativeFinder.cc
r4f57930 r87c5f40 211 211 } 212 212 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 } 213 // std::unordered_map< Expression *, UniqueExpr * > ; 226 214 227 215 template< typename StructOrUnionType > … … 232 220 std::list< Declaration* > members; 233 221 aggInst->lookup( name, members ); 234 235 222 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 236 223 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 237 224 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 238 225 renameTypes( alternatives.back().expr ); 239 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.240 226 } else { 241 227 assert( false ); … … 744 730 if ( candidates.empty() && ! errors.isEmpty() ) { throw errors; } 745 731 746 // compute conversionsion costs747 732 for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) { 748 733 Cost cvtCost = computeConversionCost( *withFunc, indexer ); … … 766 751 } // if 767 752 } // 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 members769 for ( const Alternative & alt : alternatives ) {770 addAnonConversions( alt );771 }772 773 753 candidates.clear(); 774 754 candidates.splice( candidates.end(), alternatives ); … … 905 885 ) 906 886 renameTypes( alternatives.back().expr ); 907 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 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 908 894 } // for 909 895 } -
src/ResolvExpr/AlternativeFinder.h
r4f57930 r87c5f40 78 78 void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out ); 79 79 80 /// Adds alternatives for anonymous members81 void addAnonConversions( const Alternative & alt );82 80 /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member 83 81 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ); -
src/SymTab/Autogen.cc
r4f57930 r87c5f40 498 498 makeUnionFieldsAssignment( srcParam, dstParam, back_inserter( funcDecl->get_statements()->get_kids() ) ); 499 499 if ( returnVal ) { 500 funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 500 if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, back_inserter( funcDecl->get_statements()->get_kids() ) ); 501 else funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 501 502 } 502 503 } -
src/SynTree/Expression.cc
r4f57930 r87c5f40 339 339 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() ); 340 340 } else { 341 assertf( false, "makeSub expects struct or union type for aggregate , but got: %s", toString( t ).c_str());341 assertf( false, "makeSub expects struct or union type for aggregate" ); 342 342 } 343 343 }
Note: See TracChangeset
for help on using the changeset viewer.