Ignore:
Timestamp:
Apr 23, 2024, 1:37:17 PM (4 weeks ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
4a3eb1c
Parents:
15215f02
Message:

Updated files in ResolvExpr? to the new indentation style. It seems the remaining places have reason to break from the style.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/typeops.h

    r15215f02 r13de4478  
    2121
    2222namespace ResolvExpr {
    23         class TypeEnvironment;
    2423
    25         // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
    26         // picking one element out of each set
    27         template< typename InputIterator, typename OutputIterator >
    28         void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
    29                 typedef typename InputIterator::value_type SetType;
    30                 typedef typename std::vector< typename SetType::value_type > ListType;
     24class TypeEnvironment;
    3125
    32                 if ( begin == end )     {
    33                         *out++ = ListType();
    34                         return;
    35                 } // if
     26// combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
     27// picking one element out of each set
     28template< typename InputIterator, typename OutputIterator >
     29void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
     30        typedef typename InputIterator::value_type SetType;
     31        typedef typename std::vector< typename SetType::value_type > ListType;
    3632
    37                 InputIterator current = begin;
    38                 begin++;
     33        if ( begin == end )     {
     34                *out++ = ListType();
     35                return;
     36        } // if
    3937
    40                 std::vector< ListType > recursiveResult;
    41                 combos( begin, end, back_inserter( recursiveResult ) );
     38        InputIterator current = begin;
     39        begin++;
    4240
    43                 for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) {
    44                         ListType result;
    45                         std::back_insert_iterator< ListType > inserter = back_inserter( result );
    46                         *inserter++ = j;
    47                         std::copy( i.begin(), i.end(), inserter );
    48                         *out++ = result;
     41        std::vector< ListType > recursiveResult;
     42        combos( begin, end, back_inserter( recursiveResult ) );
     43
     44        for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) {
     45                ListType result;
     46                std::back_insert_iterator< ListType > inserter = back_inserter( result );
     47                *inserter++ = j;
     48                std::copy( i.begin(), i.end(), inserter );
     49                *out++ = result;
     50        }
     51}
     52
     53/// Flatten tuple type into existing list of types.
     54inline void flatten(
     55        const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
     56) {
     57        if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
     58                for ( const ast::Type * t : tupleType->types ) {
     59                        flatten( t, out );
    4960                }
     61        } else {
     62                out.emplace_back( type );
     63        }
     64}
     65
     66/// Flatten tuple type into list of types.
     67inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
     68        std::vector< ast::ptr< ast::Type > > out;
     69        out.reserve( type->size() );
     70        flatten( type, out );
     71        return out;
     72}
     73
     74template< typename Iter >
     75const ast::Type * tupleFromTypes( Iter crnt, Iter end ) {
     76        std::vector< ast::ptr< ast::Type > > types;
     77        while ( crnt != end ) {
     78                // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure
     79                // that this results in a flat tuple
     80                flatten( *crnt, types );
     81
     82                ++crnt;
    5083        }
    5184
    52         /// flatten tuple type into existing list of types
    53         inline void flatten(
    54                 const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
    55         ) {
    56                 if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
    57                         for ( const ast::Type * t : tupleType->types ) {
    58                                 flatten( t, out );
    59                         }
    60                 } else {
    61                         out.emplace_back( type );
    62                 }
    63         }
     85        return new ast::TupleType( std::move(types) );
     86}
    6487
    65         /// flatten tuple type into list of types
    66         inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
    67                 std::vector< ast::ptr< ast::Type > > out;
    68                 out.reserve( type->size() );
    69                 flatten( type, out );
    70                 return out;
    71         }
     88inline const ast::Type * tupleFromTypes(
     89        const std::vector< ast::ptr< ast::Type > > & tys
     90) {
     91        return tupleFromTypes( tys.begin(), tys.end() );
     92}
    7293
    73         template< typename Iter >
    74         const ast::Type * tupleFromTypes( Iter crnt, Iter end ) {
    75                 std::vector< ast::ptr< ast::Type > > types;
    76                 while ( crnt != end ) {
    77                         // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure
    78                         // that this results in a flat tuple
    79                         flatten( *crnt, types );
    80 
    81                         ++crnt;
    82                 }
    83 
    84                 return new ast::TupleType{ std::move(types) };
    85         }
    86 
    87         inline const ast::Type * tupleFromTypes(
    88                 const std::vector< ast::ptr< ast::Type > > & tys
    89         ) {
    90                 return tupleFromTypes( tys.begin(), tys.end() );
    91         }
    9294} // namespace ResolvExpr
    9395
Note: See TracChangeset for help on using the changeset viewer.