Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/HoistStruct.cpp

    r0153dbd rfc1a3e2  
    2727namespace {
    2828
    29 /// Is this a declaration can appear in a struct/union and should be hoisted?
    3029bool shouldHoist( ast::Decl const * decl ) {
    3130        return dynamic_cast< ast::StructDecl const * >( decl )
     
    3534}
    3635
    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
    6438 * appear before the declaration they are hoisted out of and if two types are
    6539 * 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.
    6840 */
    6941struct HoistStructCore final :
     
    12496                auto mut = ast::mutate( decl );
    12597                mut->parent = parent;
     98                mut->name = qualifiedName( mut );
    12699                extendParams( mut->params, parent->params );
    127100                decl = mut;
     
    143116                }
    144117        }
    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         }
    159118        return mut;
    160119}
     
    208167}
    209168
     169template<typename InstType>
     170InstType 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
    210177ast::StructInstType const * HoistStructCore::previsit( ast::StructInstType const * type ) {
    211178        return preInstType( preCollectionInstType( type ) );
Note: See TracChangeset for help on using the changeset viewer.