[4864a73] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // Chain.hpp -- |
---|
| 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Wed Jun 05 14:11:52 2019 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #include "Node.hpp" |
---|
| 17 | |
---|
| 18 | namespace ast { |
---|
| 19 | |
---|
| 20 | template<typename T> |
---|
| 21 | struct _chain_mutator; |
---|
| 22 | |
---|
| 23 | template<typename node_t, Node::ref_type ref_t> |
---|
| 24 | struct _chain_mutator<ptr_base<node_t, ref_t>>; |
---|
| 25 | |
---|
| 26 | template<template <class...> class container_t, typename node_t, Node::ref_type ref_t> |
---|
| 27 | struct _chain_mutator<container_t<ptr_base<node_t, ref_t>>>; |
---|
| 28 | |
---|
| 29 | template<typename node_t, Node::ref_type ref_t> |
---|
| 30 | struct _chain_mutator<ptr_base<node_t, ref_t>> { |
---|
| 31 | ptr_base<node_t, ref_t> & base; |
---|
| 32 | |
---|
| 33 | template<typename actual_node_t, typename child_t> |
---|
| 34 | auto operator()( child_t actual_node_t::*child ) { |
---|
[2345ab3] | 35 | node_t * n = base.get_and_mutate(); |
---|
[4864a73] | 36 | actual_node_t * node = strict_dynamic_cast<actual_node_t *>(n); |
---|
| 37 | return _chain_mutator< typename std::remove_reference< decltype(node->*child) >::type >{node->*child}; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | node_t * operator->() { |
---|
[2345ab3] | 41 | return base.get_and_mutate(); |
---|
[4864a73] | 42 | } |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | template<template <class...> class container_t, typename node_t, Node::ref_type ref_t> |
---|
| 46 | struct _chain_mutator<container_t<ptr_base<node_t, ref_t>>> { |
---|
| 47 | container_t<ptr_base<node_t, ref_t>> & base; |
---|
| 48 | |
---|
| 49 | auto operator[]( size_t i ) { |
---|
| 50 | return _chain_mutator<ptr_base<node_t, ref_t>>{base[i]}; |
---|
| 51 | } |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | template< typename node_t, Node::ref_type ref_t > |
---|
| 56 | auto chain_mutate( ptr_base<node_t, ref_t> & base ) { |
---|
| 57 | return _chain_mutator<ptr_base<node_t, ref_t>>{ base }; |
---|
| 58 | } |
---|
| 59 | |
---|
[2345ab3] | 60 | } |
---|