source: src/AST/Chain.hpp @ a951171

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since a951171 was 4864a73, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Added chain mutation and example use in resolver

  • Property mode set to 100644
File size: 1.7 KB
Line 
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 ) {
35                auto n = mutate(base.get());
36                actual_node_t * node = strict_dynamic_cast<actual_node_t *>(n);
37                base = node;
38                return _chain_mutator< typename std::remove_reference< decltype(node->*child) >::type >{node->*child};
39        }
40
41        node_t * operator->() {
42                auto n = mutate(base.get());
43                base = n;
44                return n;
45        }
46};
47
48template<template <class...> class container_t, typename node_t, Node::ref_type ref_t>
49struct _chain_mutator<container_t<ptr_base<node_t, ref_t>>> {
50        container_t<ptr_base<node_t, ref_t>> & base;
51
52        auto operator[]( size_t i ) {
53                return _chain_mutator<ptr_base<node_t, ref_t>>{base[i]};
54        }
55};
56
57
58template< typename node_t, Node::ref_type ref_t >
59auto chain_mutate( ptr_base<node_t, ref_t> & base ) {
60        return _chain_mutator<ptr_base<node_t, ref_t>>{ base };
61}
62
63}
Note: See TracBrowser for help on using the repository browser.