Changeset e67a82d for src/AST/TypeSubstitution.hpp
- Timestamp:
- Aug 20, 2020, 11:48:15 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:
- d685cb0
- Parents:
- 67ca73e (diff), 013b028 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/TypeSubstitution.hpp
r67ca73e re67a82d 44 44 TypeSubstitution &operator=( const TypeSubstitution &other ); 45 45 46 template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const; 47 template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const; 46 template< typename SynTreeClass > 47 struct ApplyResult { 48 // const SynTreeClass * node; 49 ast::ptr<SynTreeClass> node; 50 int count; 51 }; 52 53 template< typename SynTreeClass > ApplyResult<SynTreeClass> apply( const SynTreeClass * input ) const; 54 template< typename SynTreeClass > ApplyResult<SynTreeClass> applyFree( const SynTreeClass * input ) const; 48 55 49 56 template< typename node_t, enum Node::ref_type ref_t > 50 57 int apply( ptr_base< node_t, ref_t > & input ) const { 51 58 const node_t * p = input.get(); 52 intret = apply(p);53 input = p;54 return ret ;59 auto ret = apply(p); 60 input = ret.node; 61 return ret.count; 55 62 } 56 63 … … 58 65 int applyFree( ptr_base< node_t, ref_t > & input ) const { 59 66 const node_t * p = input.get(); 60 intret = applyFree(p);61 input = p;62 return ret ;67 auto ret = applyFree(p); 68 input = ret.node; 69 return ret.count; 63 70 } 64 71 … … 92 99 void initialize( const TypeSubstitution &src, TypeSubstitution &dest ); 93 100 94 template<typename pass_type>101 template<typename core_t> 95 102 friend class Pass; 96 103 … … 147 154 // PassVisitor are defined before PassVisitor implementation accesses TypeSubstitution internals. 148 155 #include "Pass.hpp" 156 #include "Copy.hpp" 149 157 150 158 namespace ast { … … 152 160 // definitition must happen after PassVisitor is included so that WithGuards can be used 153 161 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> { 162 static size_t traceId; 154 163 155 164 Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 156 165 157 #if TIME_TO_CONVERT_PASSES 158 159 Type * postmutate( TypeInstType * aggregateUseType ); 160 Expression * postmutate( NameExpr * nameExpr ); 166 const Type * postvisit( const TypeInstType * aggregateUseType ); 167 const Expr * postvisit( const NameExpr * nameExpr ); 161 168 162 169 /// Records type variable bindings from forall-statements 163 void pre mutate(Type * type );170 void previsit( const ParameterizedType * type ); 164 171 /// Records type variable bindings from forall-statements and instantiations of generic types 165 template< typename TypeClass > void handleAggregateType( TypeClass * type ); 166 167 void premutate( StructInstType * aggregateUseType ); 168 void premutate( UnionInstType * aggregateUseType ); 169 170 #endif 172 void handleAggregateType( const ReferenceToType * type ); 173 174 void previsit( const StructInstType * aggregateUseType ); 175 void previsit( const UnionInstType * aggregateUseType ); 171 176 172 177 const TypeSubstitution & sub; … … 179 184 180 185 template< typename SynTreeClass > 181 int TypeSubstitution::apply( const SynTreeClass *&input ) const {186 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::apply( const SynTreeClass * input ) const { 182 187 assert( input ); 183 188 Pass<Substituter> sub( *this, false ); 184 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 185 /// std::cerr << "substitution result is: "; 186 /// newType->print( std::cerr ); 187 /// std::cerr << std::endl; 188 return sub.pass.subCount; 189 input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 190 return { input, sub.core.subCount }; 189 191 } 190 192 191 193 template< typename SynTreeClass > 192 int TypeSubstitution::applyFree( const SynTreeClass *&input ) const {194 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::applyFree( const SynTreeClass * input ) const { 193 195 assert( input ); 194 196 Pass<Substituter> sub( *this, true ); 195 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 196 /// std::cerr << "substitution result is: "; 197 /// newType->print( std::cerr ); 198 /// std::cerr << std::endl; 199 return sub.pass.subCount; 197 input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) ); 198 return { input, sub.core.subCount }; 200 199 } 201 200
Note: See TracChangeset
for help on using the changeset viewer.