Changeset d85141f for src/GenPoly


Ignore:
Timestamp:
Oct 16, 2023, 7:01:37 PM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
1b41219
Parents:
52a5262e
Message:

Small refactoring of some helper functions to avoid repeating a loop.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/SpecializeNew.cpp

    r52a5262e rd85141f  
    8181}
    8282
    83 // The number of elements in a type if it is a flattened tuple.
    84 size_t flatTupleSize( const ast::Type * type ) {
    85         if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {
    86                 size_t sum = 0;
    87                 for ( auto t : *tuple ) {
    88                         sum += flatTupleSize( t );
    89                 }
    90                 return sum;
    91         } else {
    92                 return 1;
    93         }
     83// The number of elements in a list, if all tuples had been flattened.
     84size_t flatTypeListSize( const std::vector<ast::ptr<ast::Type>> & types ) {
     85        size_t sum = 0;
     86        for ( const ast::ptr<ast::Type> & type : types ) {
     87                if ( const ast::TupleType * tuple = type.as<ast::TupleType>() ) {
     88                        sum += flatTypeListSize( tuple->types );
     89                } else {
     90                        sum += 1;
     91                }
     92        }
     93        return sum;
    9494}
    9595
    9696// Find the total number of components in a parameter list.
    9797size_t functionParameterSize( const ast::FunctionType * type ) {
    98         size_t sum = 0;
    99         for ( auto param : type->params ) {
    100                 sum += flatTupleSize( param );
    101         }
    102         return sum;
     98        return flatTypeListSize( type->params );
    10399}
    104100
Note: See TracChangeset for help on using the changeset viewer.