Changeset 54e41b3 for src/AST/Node.hpp


Ignore:
Timestamp:
May 16, 2019, 1:46:28 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
24afc53
Parents:
89c2f7c9
Message:

Add first half of ast::Expr subclasses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r89c2f7c9 r54e41b3  
    7676// problems and be able to use auto return
    7777template<typename node_t>
    78 auto mutate(const node_t * node) {
     78auto mutate( const node_t * node ) {
    7979        assertf(
    8080                node->strong_count >= 1,
     
    9292}
    9393
    94 std::ostream& operator<< ( std::ostream& out, const Node* node );
     94std::ostream& operator<< ( std::ostream& out, const Node * node );
    9595
    9696/// Base class for the smart pointer types
     
    137137        operator const node_t * () const { return node; }
    138138
     139        /// wrapper for convenient access to dynamic_cast
    139140        template<typename o_node_t>
    140141        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
     142
     143        /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
     144        /// Returns a mutable version of the pointer in this node.
     145        node_t * set_and_mutate( const node_t * n ) {
     146                // ensure ownership of `n` by this node to avoid spurious single-owner mutates
     147                assign( n );
     148                // get mutable version of `n`
     149                auto r = mutate( node );
     150                // re-assign mutable version in case `mutate()` produced a new pointer
     151                assign( r );
     152                return r;
     153        }
    141154
    142155        using ptr = const node_t *;
Note: See TracChangeset for help on using the changeset viewer.