Changeset 0153dbd
- Timestamp:
- Apr 29, 2024, 6:35:39 PM (6 months ago)
- Branches:
- master
- Children:
- 69867ad9
- Parents:
- 5c27b6a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/HoistStruct.cpp
r5c27b6a r0153dbd 27 27 namespace { 28 28 29 /// Is this a declaration can appear in a struct/union and should be hoisted? 29 30 bool shouldHoist( ast::Decl const * decl ) { 30 31 return dynamic_cast< ast::StructDecl const * >( decl ) … … 34 35 } 35 36 36 /* This pass also does some renaming and internal field alteration, but the 37 * complex part is the actual hoisting. Hoisted declarations should always 37 /// Helper that updates an InstType if the base name could be updated. 38 template<typename InstType> 39 InstType const * preInstType( InstType const * type ) { 40 assert( type->base ); 41 if ( nullptr == type->base->parent ) return type; 42 auto mut = ast::mutate( type ); 43 mut->name = mut->base->name; 44 return mut; 45 } 46 47 /// Update StructInstType and UnionInstType names. 48 struct NameUpdater { 49 ast::StructInstType const * previsit( ast::StructInstType const * type ) { 50 return preInstType( type ); 51 } 52 53 ast::UnionInstType const * previsit( ast::UnionInstType const * type ) { 54 return preInstType( type ); 55 } 56 }; 57 58 ast::Decl const * updateNames( ast::Decl const * decl ) { 59 ast::Pass<NameUpdater> visitor; 60 return decl->accept( visitor ); 61 } 62 63 /* This pass hoists from structs/unions. Hoisted declarations should always 38 64 * appear before the declaration they are hoisted out of and if two types are 39 65 * nested in the same declaration their order should not change. 66 * It also sets up parent relationships, does name mangling of hoisted types 67 * and updates instance types of the hoisted types. 40 68 */ 41 69 struct HoistStructCore final : … … 96 124 auto mut = ast::mutate( decl ); 97 125 mut->parent = parent; 98 mut->name = qualifiedName( mut );99 126 extendParams( mut->params, parent->params ); 100 127 decl = mut; … … 116 143 } 117 144 } 145 // Is this a nested type? Then update the name, after the parent's name 146 // has been updated (hence the post visit). 147 if ( mut->parent ) { 148 mut->name = qualifiedName( mut ); 149 // Top level type that has hoisted? Then do a second pass subpass to make 150 // sure we update instance type names after the declaration is renamed. 151 } else if ( !declsToAddBefore.empty() ) { 152 for ( ast::ptr<ast::Decl> & member : mut->members ) { 153 member = updateNames( member.get() ); 154 } 155 for ( ast::ptr<ast::Decl> & declToAdd : declsToAddBefore ) { 156 declToAdd = updateNames( declToAdd ); 157 } 158 } 118 159 return mut; 119 160 } … … 167 208 } 168 209 169 template<typename InstType>170 InstType const * preInstType( InstType const * type ) {171 assert( type->base );172 auto mut = ast::mutate( type );173 mut->name = mut->base->name;174 return mut;175 }176 177 210 ast::StructInstType const * HoistStructCore::previsit( ast::StructInstType const * type ) { 178 211 return preInstType( preCollectionInstType( type ) );
Note: See TracChangeset
for help on using the changeset viewer.