Changes in src/Validate/HoistStruct.cpp [0153dbd:fc1a3e2]
- File:
-
- 1 edited
-
src/Validate/HoistStruct.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/HoistStruct.cpp
r0153dbd rfc1a3e2 27 27 namespace { 28 28 29 /// Is this a declaration can appear in a struct/union and should be hoisted?30 29 bool shouldHoist( ast::Decl const * decl ) { 31 30 return dynamic_cast< ast::StructDecl const * >( decl ) … … 35 34 } 36 35 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 36 /* This pass also does some renaming and internal field alteration, but the 37 * complex part is the actual hoisting. Hoisted declarations should always 64 38 * appear before the declaration they are hoisted out of and if two types are 65 39 * nested in the same declaration their order should not change. 66 * It also sets up parent relationships, does name mangling of hoisted types67 * and updates instance types of the hoisted types.68 40 */ 69 41 struct HoistStructCore final : … … 124 96 auto mut = ast::mutate( decl ); 125 97 mut->parent = parent; 98 mut->name = qualifiedName( mut ); 126 99 extendParams( mut->params, parent->params ); 127 100 decl = mut; … … 143 116 } 144 117 } 145 // Is this a nested type? Then update the name, after the parent's name146 // 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 make150 // 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 }159 118 return mut; 160 119 } … … 208 167 } 209 168 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 210 177 ast::StructInstType const * HoistStructCore::previsit( ast::StructInstType const * type ) { 211 178 return preInstType( preCollectionInstType( type ) );
Note:
See TracChangeset
for help on using the changeset viewer.