| [1f1c102] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 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 | // Copy.hpp -- Provides functions to copy the AST.
 | 
|---|
 | 8 | //
 | 
|---|
 | 9 | // Author           : Andrew Beach
 | 
|---|
 | 10 | // Created On       : Wed Jul 10 16:13:00 2019
 | 
|---|
 | 11 | // Last Modified By : Andrew Beach
 | 
|---|
| [a488783] | 12 | // Last Modified On : Wed Dec 15 11:07:00 2021
 | 
|---|
 | 13 | // Update Count     : 3
 | 
|---|
| [1f1c102] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
| [5c9b20c] | 16 | #pragma once
 | 
|---|
 | 17 | 
 | 
|---|
| [3249dd8b] | 18 | #include "Node.hpp"
 | 
|---|
 | 19 | #include <cassert>
 | 
|---|
| [1f1c102] | 20 | 
 | 
|---|
 | 21 | namespace ast {
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | template<typename node_t>
 | 
|---|
| [99da267] | 24 | node_t * shallowCopy( const node_t * node );
 | 
|---|
| [1f1c102] | 25 | /* Create a shallow copy of the node given.
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  * The new node has all the same primitive field values and points to the
 | 
|---|
 | 28 |  * same children nodes as the parent.
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | template<typename node_t>
 | 
|---|
| [99da267] | 32 | node_t * deepCopy( const node_t * localRoot );
 | 
|---|
| [1f1c102] | 33 | /* Create a deep copy of the tree rooted at localRoot.
 | 
|---|
 | 34 |  *
 | 
|---|
 | 35 |  * This creates a copy of every node in the sub-tree (reachable by strong
 | 
|---|
 | 36 |  * reference from local_root) and updates any readonly pointers on those nodes
 | 
|---|
 | 37 |  * that point to another node in the sub-tree to the new version of that node.
 | 
|---|
 | 38 |  */
 | 
|---|
 | 39 | 
 | 
|---|
| [3249dd8b] | 40 | // Implementations:
 | 
|---|
| [1f1c102] | 41 | template<typename node_t>
 | 
|---|
| [99da267] | 42 | node_t * shallowCopy( const node_t * localRoot ) {
 | 
|---|
| [1f1c102] | 43 |         return localRoot->clone();
 | 
|---|
 | 44 | }
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | template<typename node_t>
 | 
|---|
| [99da267] | 47 | node_t * deepCopy( const node_t * localRoot ) {
 | 
|---|
| [ce36b55] | 48 |         return strict_dynamic_cast<node_t *>( deepCopy<Node>( localRoot ) );
 | 
|---|
| [1f1c102] | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
| [ce36b55] | 51 | template<>
 | 
|---|
 | 52 | Node * deepCopy<Node>( const Node * localRoot );
 | 
|---|
 | 53 | 
 | 
|---|
| [a488783] | 54 | template<typename node_t, enum Node::ref_type ref_t>
 | 
|---|
 | 55 | node_t * shallowCopy( const ptr_base<node_t, ref_t> & localRoot ) {
 | 
|---|
 | 56 |         return shallowCopy( localRoot.get() );
 | 
|---|
 | 57 | }
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | template<typename node_t, enum Node::ref_type ref_t>
 | 
|---|
 | 60 | node_t * deepCopy( const ptr_base<node_t, ref_t> & localRoot ) {
 | 
|---|
 | 61 |         return deepCopy( localRoot.get() );
 | 
|---|
 | 62 | }
 | 
|---|
 | 63 | 
 | 
|---|
| [1f1c102] | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | // Local Variables: //
 | 
|---|
 | 67 | // tab-width: 4 //
 | 
|---|
 | 68 | // mode: c++ //
 | 
|---|
 | 69 | // compile-command: "make install" //
 | 
|---|
 | 70 | // End: //
 | 
|---|