Changes in src/SymTab/Validate.cc [b95fe40:8e0147a]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rb95fe40 r8e0147a 124 124 125 125 /// Associates forward declarations of aggregates with their definitions 126 struct LinkReferenceToTypes final : public WithIndexer , public WithGuards{126 struct LinkReferenceToTypes final : public WithIndexer { 127 127 LinkReferenceToTypes( const Indexer *indexer ); 128 128 void postvisit( TypeInstType *typeInst ); … … 137 137 void postvisit( UnionDecl *unionDecl ); 138 138 void postvisit( TraitDecl * traitDecl ); 139 140 void previsit( StructDecl *structDecl );141 void previsit( UnionDecl *unionDecl );142 143 void renameGenericParams( std::list< TypeDecl * > & params );144 139 145 140 private: … … 152 147 ForwardStructsType forwardStructs; 153 148 ForwardUnionsType forwardUnions; 154 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately155 bool inGeneric = false;156 149 }; 157 150 … … 430 423 } 431 424 432 void checkGenericParameters( ReferenceToType * inst ) {433 for ( Expression * param : inst->parameters ) {434 if ( ! dynamic_cast< TypeExpr * >( param ) ) {435 throw SemanticError( "Expression parameters for generic types are currently unsupported: ", inst );436 }437 }438 }439 440 425 void LinkReferenceToTypes::postvisit( StructInstType *structInst ) { 441 426 StructDecl *st = local_indexer->lookupStruct( structInst->get_name() ); … … 449 434 forwardStructs[ structInst->get_name() ].push_back( structInst ); 450 435 } // if 451 checkGenericParameters( structInst );452 436 } 453 437 … … 462 446 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 463 447 } // if 464 checkGenericParameters( unionInst );465 448 } 466 449 … … 542 525 // need to carry over the 'sized' status of each decl in the instance 543 526 for ( auto p : group_iterate( traitDecl->get_parameters(), traitInst->get_parameters() ) ) { 544 TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) ); 545 if ( ! expr ) { 546 throw SemanticError( "Expression parameters for trait instances are currently unsupported: ", std::get<1>(p) ); 547 } 527 TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( std::get<1>(p) ); 548 528 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) { 549 529 TypeDecl * formalDecl = std::get<0>(p); … … 566 546 } // if 567 547 } // if 568 }569 570 void LinkReferenceToTypes::renameGenericParams( std::list< TypeDecl * > & params ) {571 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.572 // forall(otype T)573 // struct Box {574 // T x;575 // };576 // forall(otype T)577 // void f(Box(T) b) {578 // ...579 // }580 // The T in Box and the T in f are different, so internally the naming must reflect that.581 GuardValue( inGeneric );582 inGeneric = ! params.empty();583 for ( TypeDecl * td : params ) {584 td->name = "__" + td->name + "_generic_";585 }586 }587 588 void LinkReferenceToTypes::previsit( StructDecl * structDecl ) {589 renameGenericParams( structDecl->parameters );590 }591 592 void LinkReferenceToTypes::previsit( UnionDecl * unionDecl ) {593 renameGenericParams( unionDecl->parameters );594 548 } 595 549 … … 621 575 622 576 void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) { 623 // ensure generic parameter instances are renamed like the base type624 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;625 577 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) { 626 578 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.