Changeset 3249dd8b
- Timestamp:
- Nov 11, 2021, 9:43:09 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 5dcb881
- Parents:
- b7fd9daf
- Location:
- src/AST
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Copy.hpp
rb7fd9daf r3249dd8b 10 10 // Created On : Wed Jul 10 16:13:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 19 16:43:00 202013 // Update Count : 112 // Last Modified On : Thr Nov 11 9:22:00 2021 13 // Update Count : 2 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "Decl.hpp" 19 #include "Expr.hpp" 20 #include "Pass.hpp" 21 #include "Stmt.hpp" 22 #include "Type.hpp" 23 #include <unordered_set> 24 #include <unordered_map> 18 #include "Node.hpp" 19 #include <cassert> 25 20 26 21 namespace ast { … … 43 38 */ 44 39 45 class DeepCopyCore { 46 std::unordered_map< const Node *, const Node * > nodeCache; 47 std::unordered_set< readonly<Node> * > readonlyCache; 48 49 template<typename node_t> 50 void readonlyInsert( const readonly<node_t> * ptrptr ) { 51 readonlyCache.insert( (readonly<Node> *) ptrptr ); 52 } 53 54 public: 55 template<typename node_t> 56 const node_t * previsit( const node_t * node ) { 57 const node_t * copy = shallowCopy( node ); 58 nodeCache.insert( std::make_pair( node, copy ) ); 59 return copy; 60 } 61 62 void postvisit( const AggregateDecl * node ) { 63 readonlyInsert( &node->parent ); 64 } 65 66 void postvisit( const StructInstType * node ) { 67 readonlyInsert( &node->base ); 68 } 69 70 void postvisit( const UnionInstType * node ) { 71 readonlyInsert( &node->base ); 72 } 73 74 void postvisit( const EnumInstType * node ) { 75 readonlyInsert( &node->base ); 76 } 77 78 void postvisit( const TraitInstType * node ) { 79 readonlyInsert( &node->base ); 80 } 81 82 void postvisit( const TypeInstType * node ) { 83 readonlyInsert( &node->base ); 84 } 85 86 void postvisit( const ImplicitCtorDtorStmt * node ) { 87 readonlyInsert( (const readonly<Stmt> *) &node->callStmt ); 88 } 89 90 void postvisit( const StmtExpr * node ) { 91 readonlyInsert( &node->resultExpr ); 92 } 93 94 void postvisit( const MemberExpr * node ) { 95 readonlyInsert( &node->member ); 96 } 97 98 void postvisit( const VariableExpr * node ) { 99 readonlyInsert( &node->var ); 100 } 101 102 void postvisit( const OffsetofExpr * node ) { 103 readonlyInsert( &node->member ); 104 } 105 106 void postvisit( const DeletedExpr * node ) { 107 readonlyInsert( &node->deleteStmt ); 108 } 109 110 void readonlyUpdates() { 111 for ( readonly<Node> * ptr : readonlyCache ) { 112 auto it = nodeCache.find( ptr->get() ); 113 if ( nodeCache.end() != it ) { 114 *ptr = it->second; 115 } 116 } 117 } 118 }; 119 40 // Implementations: 120 41 template<typename node_t> 121 42 node_t * shallowCopy( const node_t * localRoot ) { … … 123 44 } 124 45 46 Node * deepCopyNode( const Node * node ); 47 125 48 template<typename node_t> 126 49 node_t * deepCopy( const node_t * localRoot ) { 127 Pass< DeepCopyCore > dc; 128 node_t const * newRoot = strict_dynamic_cast<node_t const*>(localRoot->accept( dc )); 129 dc.core.readonlyUpdates(); 130 return const_cast< node_t * >( newRoot ); 50 return strict_dynamic_cast<node_t *>( deepCopyNode( localRoot ) ); 131 51 } 132 52 -
src/AST/Expr.hpp
rb7fd9daf r3249dd8b 767 767 768 768 /// An expression which must only be evaluated once 769 class 770 UniqueExpr final : public Expr { 769 class UniqueExpr final : public Expr { 771 770 static unsigned long long nextId; 772 771 public: -
src/AST/module.mk
rb7fd9daf r3249dd8b 24 24 AST/Convert.cpp \ 25 25 AST/Convert.hpp \ 26 AST/Copy.cpp \ 26 27 AST/Copy.hpp \ 27 28 AST/CVQualifiers.hpp \
Note: See TracChangeset
for help on using the changeset viewer.