Changes in src/SymTab/Validate.cc [67cf18c:11ab8ea8]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r67cf18c r11ab8ea8 506 506 void LinkReferenceToTypes::visit( StructDecl *structDecl ) { 507 507 // visit struct members first so that the types of self-referencing members are updated properly 508 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and and their defaults)509 508 Parent::visit( structDecl ); 510 509 if ( ! structDecl->get_members().empty() ) { … … 845 844 if ( params != NULL ) { 846 845 std::list< Expression * > & args = inst->get_parameters(); 847 848 // insert defaults arguments when a type argument is missing (currently only supports missing arguments at the end of the list).849 // A substitution is used to ensure that defaults are replaced correctly, e.g.,850 // forall(otype T, otype alloc = heap_allocator(T)) struct vector;851 // vector(int) v;852 // after insertion of default values becomes853 // vector(int, heap_allocator(T))854 // and the substitution is built with T=int so that after substitution, the result is855 // vector(int, heap_allocator(int))856 TypeSubstitution sub;857 auto paramIter = params->begin();858 for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {859 if ( i < args.size() ) {860 TypeExpr * expr = safe_dynamic_cast< TypeExpr * >( *std::next( args.begin(), i ) );861 sub.add( (*paramIter)->get_name(), expr->get_type()->clone() );862 } else if ( i == args.size() ) {863 Type * defaultType = (*paramIter)->get_init();864 if ( defaultType ) {865 args.push_back( new TypeExpr( defaultType->clone() ) );866 sub.add( (*paramIter)->get_name(), defaultType->clone() );867 }868 }869 }870 871 sub.apply( inst );872 846 if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst ); 873 847 if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
Note:
See TracChangeset
for help on using the changeset viewer.