Changeset 6949c45 for src/AST/Node.hpp


Ignore:
Timestamp:
Jun 10, 2019, 1:51:24 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2773ab8, 558d13b
Parents:
891b827 (diff), f9a7cf0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r891b827 r6949c45  
    9999
    100100/// Mutate a node field (only clones if not equal to existing value)
    101 template<typename node_t, typename field_t>
    102 const node_t * mutate_field(
    103         const node_t * node,
    104         typename std::remove_const<typename std::remove_reference<field_t>::type>::type node_t::* field,
    105         field_t&& val
    106 ) {
     101template<typename node_t, typename field_t, typename assn_t>
     102const node_t * mutate_field( const node_t * node, field_t node_t::* field, assn_t && val ) {
     103        // skip mutate if equivalent
    107104        if ( node->*field == val ) return node;
    108105       
     106        // mutate and return
    109107        node_t * ret = mutate( node );
    110         ret->*field = std::forward< field_t >( val );
     108        ret->*field = std::forward< assn_t >( val );
     109        return ret;
     110}
     111
     112/// Mutate a single index of a node field (only clones if not equal to existing value)
     113template<typename node_t, typename coll_t, typename ind_t, typename field_t>
     114const node_t * mutate_field_index(
     115        const node_t * node, coll_t node_t::* field, ind_t i, field_t && val
     116) {
     117        // skip mutate if equivalent
     118        if  ( (node->*field)[i] == val ) return node;
     119
     120        // mutate and return
     121        node_t * ret = mutate( node );
     122        (ret->*field)[i] = std::forward< field_t >( val );
    111123        return ret;
    112124}
Note: See TracChangeset for help on using the changeset viewer.