Changeset d3aa64f1
- Timestamp:
- Aug 31, 2020, 6:55:22 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 25a1cb0, 68f0c4e
- Parents:
- 49a980b
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Copy.hpp
r49a980b rd3aa64f1 21 21 #include "Stmt.hpp" 22 22 #include "Type.hpp" 23 #include <unordered_set> 24 #include <unordered_map> 23 25 24 26 namespace ast { -
src/AST/Pass.hpp
r49a980b rd3aa64f1 266 266 267 267 /// Keep track of the polymorphic const TypeSubstitution * env for the current expression 268 269 /// marker to force shallow copies in pass visit 270 struct PureVisitor {}; 271 268 272 struct WithConstTypeSubstitution { 269 273 const TypeSubstitution * env = nullptr; -
src/AST/Pass.impl.hpp
r49a980b rd3aa64f1 21 21 22 22 #include "AST/TypeSubstitution.hpp" 23 // #include "AST/Copy.hpp" 23 24 24 25 #define VISIT_START( node ) \ … … 57 58 58 59 namespace ast { 60 template<typename node_t> 61 node_t * shallowCopy( const node_t * node ); 62 59 63 namespace __pass { 60 64 // Check if this is either a null pointer or a pointer to an empty container … … 62 66 static inline bool empty( T * ptr ) { 63 67 return !ptr || ptr->empty(); 68 } 69 70 template< typename core_t, typename node_t > 71 static inline node_t* mutate(const node_t *node) { 72 return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node); 64 73 } 65 74 … … 320 329 321 330 if( __pass::differs(old_val, new_val) ) { 322 auto new_parent = mutate(parent); 331 // auto new_parent = mutate(parent); 332 auto new_parent = __pass::mutate<core_t>(parent); 323 333 new_parent->*child = new_val; 324 334 parent = new_parent; … … 334 344 if ( node->forall.empty() ) return; 335 345 336 node_t * mut = mutate( node );346 node_t * mut = __pass::mutate<core_t>( node ); 337 347 mut->forall = subs->clone( node->forall, *this ); 338 348 node = mut; … … 894 904 895 905 if(mutated) { 896 auto n = mutate(node);906 auto n = __pass::mutate<core_t>(node); 897 907 n->clauses = std::move( new_clauses ); 898 908 node = n; … … 904 914 auto nval = call_accept( node->field ); \ 905 915 if(nval != node->field ) { \ 906 auto nparent = mutate(node); \916 auto nparent = __pass::mutate<core_t>(node); \ 907 917 nparent->field = nval; \ 908 918 node = nparent; \ … … 1610 1620 1611 1621 if(mutated) { 1612 auto n = mutate(node);1622 auto n = __pass::mutate<core_t>(node); 1613 1623 n->associations = std::move( new_kids ); 1614 1624 node = n; … … 1940 1950 } 1941 1951 if (mutated) { 1942 auto new_node = mutate( node );1952 auto new_node = __pass::mutate<core_t>( node ); 1943 1953 new_node->typeEnv.swap( new_map ); 1944 1954 node = new_node; … … 1956 1966 } 1957 1967 if (mutated) { 1958 auto new_node = mutate( node );1968 auto new_node = __pass::mutate<core_t>( node ); 1959 1969 new_node->varEnv.swap( new_map ); 1960 1970 node = new_node; -
src/AST/Pass.proto.hpp
r49a980b rd3aa64f1 22 22 template<typename core_t> 23 23 class Pass; 24 25 struct PureVisitor; 24 26 25 27 namespace __pass { -
src/AST/TypeSubstitution.hpp
r49a980b rd3aa64f1 159 159 160 160 // definitition must happen after PassVisitor is included so that WithGuards can be used 161 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {161 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter>, public PureVisitor { 162 162 static size_t traceId; 163 163 … … 187 187 assert( input ); 188 188 Pass<Substituter> sub( *this, false ); 189 input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 189 // input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 190 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 190 191 return { input, sub.core.subCount }; 191 192 } … … 195 196 assert( input ); 196 197 Pass<Substituter> sub( *this, true ); 197 input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 198 // input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 199 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 198 200 return { input, sub.core.subCount }; 199 201 } -
src/ResolvExpr/Unify.cc
r49a980b rd3aa64f1 767 767 /// If this isn't done when satifying ttype assertions, then argument lists can have 768 768 /// different size and structure when they should be compatible. 769 struct TtypeExpander_new : public ast::WithShortCircuiting {769 struct TtypeExpander_new : public ast::WithShortCircuiting, public ast::PureVisitor { 770 770 ast::TypeEnvironment & tenv; 771 771 … … 793 793 // TtypeExpander pass is impure (may mutate nodes in place) 794 794 // need to make nodes shared to prevent accidental mutation 795 ast::ptr<ast::DeclWithType> dc = d; 796 dc = dc->accept( expander ); 795 ast::ptr<ast::DeclWithType> dc = d->accept(expander); 797 796 auto types = flatten( dc->get_type() ); 798 797 for ( ast::ptr< ast::Type > & t : types ) { … … 1114 1113 ast::Pass<TtypeExpander_new> expander{ tenv }; 1115 1114 1116 ast::ptr<ast::TupleType> tuplec = tuple;1117 ast::ptr<ast::TupleType> tuple2c = tuple2;1118 const ast::Type * flat = tuple c->accept( expander );1119 const ast::Type * flat2 = tuple2 c->accept( expander );1115 // ast::ptr<ast::TupleType> tuplec = tuple; 1116 // ast::ptr<ast::TupleType> tuple2c = tuple2; 1117 const ast::Type * flat = tuple->accept( expander ); 1118 const ast::Type * flat2 = tuple2->accept( expander ); 1120 1119 1121 1120 auto types = flatten( flat );
Note: See TracChangeset
for help on using the changeset viewer.