source: src/AST/Chain.hpp @ d3b33d5

Last change on this file since d3b33d5 was 2345ab3, checked in by Andrew Beach <ajbeach@…>, 12 months ago

Clean-up of the chain mutator. Seems like it is underused.

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[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
18namespace ast {
19
20template<typename T>
21struct _chain_mutator;
22
23template<typename node_t, Node::ref_type ref_t>
24struct _chain_mutator<ptr_base<node_t, ref_t>>;
25
26template<template <class...> class container_t, typename node_t, Node::ref_type ref_t>
27struct _chain_mutator<container_t<ptr_base<node_t, ref_t>>>;
28
29template<typename node_t, Node::ref_type ref_t>
30struct _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
45template<template <class...> class container_t, typename node_t, Node::ref_type ref_t>
46struct _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
55template< typename node_t, Node::ref_type ref_t >
56auto chain_mutate( ptr_base<node_t, ref_t> & base ) {
57        return _chain_mutator<ptr_base<node_t, ref_t>>{ base };
58}
59
[2345ab3]60}
Note: See TracBrowser for help on using the repository browser.