Changeset 30bf6bf
- Timestamp:
- Mar 26, 2025, 3:29:50 PM (3 weeks ago)
- Branches:
- master
- Children:
- 10c1770
- Parents:
- 379b6ea
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/InstantiateGeneric.cpp
r379b6ea r30bf6bf 42 42 43 43 using type_vector = ast::vector< ast::TypeExpr >; 44 45 template<typename C, typename V> 46 bool contains( C const & container, V const & value ) { 47 return std::any_of( container.begin(), container.end(), 48 [value]( auto& element ){ return element == value; } ); 49 } 44 50 45 51 /// Abstracts type equality for a list of parameter types. … … 423 429 } 424 430 425 structGenericInstantiator final :431 class GenericInstantiator final : 426 432 public ast::WithCodeLocation, 427 433 public ast::WithConstTypeSubstitution, … … 444 450 /// member from an instantiation. 445 451 int memberIndex = -1; 452 /// The polymorphic types we are currently instantiating. 453 ast::vector<ast::Decl> instantiating; 454 public: 446 455 447 456 GenericInstantiator() : … … 597 606 ); 598 607 599 // Forward declare before recursion. (TODO: Only when needed, #199.)608 // Insert the declaration so it doesn't create it again, 600 609 insert( inst, typeSubs, newDecl ); 601 if ( AggrDecl const * forwardDecl = ast::asForward( newDecl ) ) { 602 declsToAddBefore.push_back( forwardDecl ); 603 } 610 // ... but mark this declaration as one we are working on. 611 auto guard = makeFuncGuard( 612 [this, newDecl](){ instantiating.push_back( newDecl ); }, 613 [this](){ instantiating.pop_back(); } ); 604 614 // Recursively instantiate members: 605 615 concDecl = strict_dynamic_cast<AggrDecl const *>( 606 616 newDecl->accept( *visitor ) ); 607 // Must occur before declaration is added so 608 // that member instantiation appear first.617 618 // Produce the declaration after its members are instantiated. 609 619 declsToAddBefore.push_back( concDecl ); 620 } else if ( contains( instantiating, concDecl ) ) { 621 if ( AggrDecl const * forwardDecl = ast::asForward( concDecl ) ) { 622 declsToAddBefore.push_back( forwardDecl ); 623 } 610 624 } 611 625 return new ast::SueInstType<AggrDecl>( concDecl, inst->qualifiers ); -
tests/.expect/functions.arm64.txt
r379b6ea r30bf6bf 139 139 140 140 } 141 struct _conc__tuple2_0;142 141 struct _conc__tuple2_0 { 143 142 signed int field_0; … … 182 181 183 182 } 184 struct _conc__tuple3_1;185 183 struct _conc__tuple3_1 { 186 184 signed int field_0; … … 202 200 __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = { }; 203 201 } 204 struct _conc__tuple3_2;205 202 struct _conc__tuple3_2 { 206 203 signed int field_0; … … 294 291 __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1; 295 292 } 296 struct _conc__tuple2_3;297 293 struct _conc__tuple2_3 { 298 294 signed int *field_0; -
tests/.expect/functions.x64.txt
r379b6ea r30bf6bf 139 139 140 140 } 141 struct _conc__tuple2_0;142 141 struct _conc__tuple2_0 { 143 142 signed int field_0; … … 182 181 183 182 } 184 struct _conc__tuple3_1;185 183 struct _conc__tuple3_1 { 186 184 signed int field_0; … … 202 200 __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = { }; 203 201 } 204 struct _conc__tuple3_2;205 202 struct _conc__tuple3_2 { 206 203 signed int field_0; … … 294 291 __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1; 295 292 } 296 struct _conc__tuple2_3;297 293 struct _conc__tuple2_3 { 298 294 signed int *field_0; -
tests/.expect/functions.x86.txt
r379b6ea r30bf6bf 139 139 140 140 } 141 struct _conc__tuple2_0;142 141 struct _conc__tuple2_0 { 143 142 signed int field_0; … … 182 181 183 182 } 184 struct _conc__tuple3_1;185 183 struct _conc__tuple3_1 { 186 184 signed int field_0; … … 202 200 __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = { }; 203 201 } 204 struct _conc__tuple3_2;205 202 struct _conc__tuple3_2 { 206 203 signed int field_0; … … 294 291 __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1; 295 292 } 296 struct _conc__tuple2_3;297 293 struct _conc__tuple2_3 { 298 294 signed int *field_0;
Note: See TracChangeset
for help on using the changeset viewer.