Changeset a556492


Ignore:
Timestamp:
Feb 17, 2022, 4:04:23 PM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
9ef9644
Parents:
7d7ef6f
Message:

There was less extra code in ForallPointerDecay? then I hopped, but it is gone now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/ForallPointerDecay.cpp

    r7d7ef6f ra556492  
    8282                        (void)count;
    8383
     84                        // Update the type (type substution does not seem to cover it).
    8485                        if ( auto func = copy.as<ast::FunctionDecl>() ) {
    8586                                auto mut = ast::mutate( func );
     
    118119        }
    119120
    120         static AssertionList expandTrait_DR(
    121                         const TypeDeclVec & typeDecls, const ast::TraitInstType * inst ) {
    122                 assertf( inst->base, "Trait instance not linked to base trait: %s",
    123                         toCString( inst ) );
    124                 AssertionList assertions;
    125                 assertf( inst->params.size() == inst->base->params.size(),
    126                         "Trait instance has incorrect number of params: %s",
    127                         toCString( inst ) );
    128                 // Replace the TypeDecls that used to point to the trait.
    129                 ast::DeclReplacer::TypeMap typeMap;
    130                 for ( size_t i = 0 ; i < inst->params.size() ; ++i ) {
    131                         typeMap[ inst->base->params[i].get() ] = typeDecls[i].get();
    132                 }
    133                 for ( const ast::ptr<ast::Decl> & decl : inst->base->members ) {
    134                         auto copy = strict_dynamic_cast<const ast::DeclWithType *>(
    135                                 ast::DeclReplacer::replace(
    136                                         ast::deepCopy( decl.get() ), typeMap ) );
    137                         // TODO: Does DeclReplacer make this redundent?
    138                         if ( auto func = dynamic_cast<const ast::FunctionDecl *>(copy) ) {
    139                                 auto mut = ast::mutate( func );
    140                                 mut->type = makeFuncType( func );
    141                                 copy = mut;
    142                         }
    143                         assertions.push_back( copy );
    144                 }
    145                 return assertions;
    146         }
    147 
    148         static AssertionList expandAssertions_DR(
    149                         const TypeDeclVec & typeDecls, const AssertionList & assertions ) {
    150                 AssertionList newAsserts;
    151                 for ( const ast::ptr<ast::DeclWithType> & assert : assertions ) {
    152                         if ( auto traitInst = dynamic_cast<const ast::TraitInstType *>(
    153                                         assert->get_type() ) ) {
    154                                 auto moreAsserts = expandTrait_DR( typeDecls, traitInst );
    155                                 append( newAsserts, moreAsserts );
    156                         } else {
    157                                 newAsserts.push_back( assert );
    158                         }
    159                 }
    160                 return newAsserts;
    161         }
    162 
    163         // They had better all be unique for this to work.
    164         static TypeDeclVec expandTypeDecls_DR( const TypeDeclVec & old ) {
    165                 TypeDeclVec typeDecls;
    166                 for ( const ast::TypeDecl * typeDecl : old ) {
    167                         typeDecls.push_back( ast::mutate_field( typeDecl,
    168                                 &ast::TypeDecl::assertions,
    169                                 expandAssertions_DR( old, typeDecl->assertions ) ) );
    170                 }
    171                 return typeDecls;
    172         }
    173 
    174121        const ast::FunctionDecl * postvisit( const ast::FunctionDecl * decl ) {
    175122                if ( decl->assertions.empty() ) {
     
    178125                auto mut = ast::mutate( decl );
    179126                mut->assertions = expandAssertions( decl->assertions );
     127                // Update the assertion list on the type as well.
    180128                auto mutType = ast::mutate( mut->type.get() );
    181                 // *
    182                 mutType->params.clear();
    183                 for ( auto & param : mut->params ) {
    184                         mutType->params.emplace_back( param->get_type() );
    185                 }
    186                 mutType->returns.clear();
    187                 for ( auto & ret : mut->returns ) {
    188                         mutType->returns.emplace_back( ret->get_type() );
    189                 }
    190                 mutType->forall.clear();
    191                 for ( auto & type_param : mut->type_params ) {
    192                         mutType->forall.emplace_back(
    193                                 new ast::TypeInstType( type_param->name, type_param ) );
    194                 }
    195                 // * /
    196129                mutType->assertions.clear();
    197130                for ( auto & assertion : mut->assertions ) {
Note: See TracChangeset for help on using the changeset viewer.