Changeset bdd516a for translator/GenPoly
- Timestamp:
- Apr 28, 2015, 4:21:36 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 42e2ad7
- Parents:
- ad17ba6a
- Location:
- translator/GenPoly
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/GenPoly/Box.cc
rad17ba6a rbdd516a 772 772 Expression *Pass1::mutate( AddressExpr *addrExpr ) { 773 773 assert( !addrExpr->get_arg()->get_results().empty() ); 774 mutateExpression( addrExpr->get_arg() );774 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 775 775 if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) { 776 776 Expression *ret = addrExpr->get_arg(); -
translator/GenPoly/ScrubTyVars.cc
rad17ba6a rbdd516a 4 4 #include "SynTree/Mutator.h" 5 5 #include "SynTree/Type.h" 6 #include "SynTree/Expression.h" 6 7 7 8 8 9 namespace GenPoly { 10 Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { 11 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 12 if ( doAll || tyVar != tyVars.end() ) { 13 switch( tyVar->second ) { 14 case TypeDecl::Any: 15 case TypeDecl::Dtype: 16 { 17 PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 18 delete typeInst; 19 return ret; 20 } 21 case TypeDecl::Ftype: 22 delete typeInst; 23 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 24 } 25 } 26 return typeInst; 27 } 9 28 10 Type* 11 ScrubTyVars::mutate( TypeInstType *typeInst ) 12 { 13 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 14 if( doAll || tyVar != tyVars.end() ) { 15 switch( tyVar->second ) { 16 case TypeDecl::Any: 17 case TypeDecl::Dtype: 18 { 19 PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 20 delete typeInst; 21 return ret; 29 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { 30 // sizeof( T ) => T parameter, which is the size of T 31 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) { 32 Expression *expr = new NameExpr( typeInst->get_name() ); 33 return expr; 34 } else { 35 return Mutator::mutate( szeof ); 36 } 22 37 } 23 24 case TypeDecl::Ftype: 25 delete typeInst; 26 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 38 39 Type * ScrubTyVars::mutate( PointerType *pointer ) { 40 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) { 41 if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 42 Type *ret = mutate( typeInst ); 43 ret->get_qualifiers() += pointer->get_qualifiers(); 44 pointer->set_base( 0 ); 45 delete pointer; 46 return ret; 47 } 48 } 49 return Mutator::mutate( pointer ); 27 50 } 28 }29 return typeInst;30 }31 32 Type*33 ScrubTyVars::mutate( PointerType *pointer )34 {35 if( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {36 if( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {37 Type *ret = mutate( typeInst );38 /// std::cout << "pointer is ";39 /// pointer->print( std::cout );40 /// std::cout << std::endl << "ret is ";41 /// ret->print( std::cout );42 /// std::cout << std::endl;43 ret->get_qualifiers() += pointer->get_qualifiers();44 pointer->set_base( 0 );45 delete pointer;46 return ret;47 }48 }49 return Mutator::mutate( pointer );50 }51 52 51 } // namespace GenPoly -
translator/GenPoly/ScrubTyVars.h
rad17ba6a rbdd516a 1 /*2 * This file is part of the Cforall project3 *4 * $Id: ScrubTyVars.h,v 1.4 2005/08/29 20:14:13 rcbilson Exp $5 *6 */7 8 1 #ifndef GENPOLY_SCRUBTYVARS_H 9 2 #define GENPOLY_SCRUBTYVARS_H … … 15 8 16 9 namespace GenPoly { 10 class ScrubTyVars : public Mutator { 11 public: 12 ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {} 13 14 template< typename SynTreeClass > 15 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars ); 16 template< typename SynTreeClass > 17 static SynTreeClass *scrub( SynTreeClass *target ); 18 19 virtual Type* mutate( TypeInstType *typeInst ); 20 Expression* mutate( SizeofExpr *szeof ); 21 virtual Type* mutate( PointerType *pointer ); 22 private: 23 bool doAll; 24 const TyVarMap &tyVars; 25 }; 17 26 18 class ScrubTyVars : public Mutator 19 { 20 public: 21 ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {} 22 23 template< typename SynTreeClass > 24 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars ); 25 template< typename SynTreeClass > 26 static SynTreeClass *scrub( SynTreeClass *target ); 27 28 virtual Type* mutate( TypeInstType *typeInst ); 29 virtual Type* mutate( PointerType *pointer ); 27 /* static class method */ 28 template< typename SynTreeClass > 29 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) { 30 ScrubTyVars scrubber( false, tyVars ); 31 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 32 } 30 33 31 private: 32 bool doAll; 33 const TyVarMap &tyVars; 34 }; 35 36 /* static class method */ 37 template< typename SynTreeClass > 38 SynTreeClass * 39 ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) 40 { 41 ScrubTyVars scrubber( false, tyVars ); 42 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 43 } 44 45 /* static class method */ 46 template< typename SynTreeClass > 47 SynTreeClass * 48 ScrubTyVars::scrub( SynTreeClass *target ) 49 { 50 TyVarMap tyVars; 51 ScrubTyVars scrubber( true, tyVars ); 52 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 53 } 54 34 /* static class method */ 35 template< typename SynTreeClass > 36 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target ) { 37 TyVarMap tyVars; 38 ScrubTyVars scrubber( true, tyVars ); 39 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 40 } 55 41 } // namespace GenPoly 56 42 57 #endif / * #ifndef GENPOLY_SCRUBTYVARS_H */43 #endif // GENPOLY_SCRUBTYVARS_H
Note: See TracChangeset
for help on using the changeset viewer.