Changes in / [4389966:5f6c42c]
- Location:
- src/GenPoly
- Files:
-
- 5 edited
-
Box.cc (modified) (30 diffs)
-
GenPoly.cc (modified) (4 diffs)
-
GenPoly.h (modified) (1 diff)
-
ScrubTyVars.cc (modified) (2 diffs)
-
ScrubTyVars.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r4389966 r5f6c42c 55 55 public: 56 56 Pass1(); 57 virtual Expression * mutate( ApplicationExpr *appExpr );58 virtual Expression * mutate( AddressExpr *addrExpr );59 virtual Expression * mutate( UntypedExpr *expr );60 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );61 virtual TypeDecl * mutate( TypeDecl *typeDecl );62 virtual Expression * mutate( CommaExpr *commaExpr );63 virtual Expression * mutate( ConditionalExpr *condExpr );57 virtual Expression *mutate( ApplicationExpr *appExpr ); 58 virtual Expression *mutate( AddressExpr *addrExpr ); 59 virtual Expression *mutate( UntypedExpr *expr ); 60 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ); 61 virtual TypeDecl *mutate( TypeDecl *typeDecl ); 62 virtual Expression *mutate( CommaExpr *commaExpr ); 63 virtual Expression *mutate( ConditionalExpr *condExpr ); 64 64 virtual Statement * mutate( ReturnStmt *returnStmt ); 65 virtual Type * mutate( PointerType *pointerType );65 virtual Type *mutate( PointerType *pointerType ); 66 66 virtual Type * mutate( FunctionType *functionType ); 67 67 … … 155 155 // with the same mangled name, so we need to further mangle the names. 156 156 for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) { 157 if ( isPoly Val( (*retval)->get_type(), tyVars ) ) {157 if ( isPolyType( (*retval)->get_type(), tyVars ) ) { 158 158 name << "P"; 159 159 } else { … … 164 164 std::list< DeclarationWithType *> ¶mList = function->get_parameters(); 165 165 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) { 166 if ( isPoly Val( (*arg)->get_type(), tyVars ) ) {166 if ( isPolyType( (*arg)->get_type(), tyVars ) ) { 167 167 name << "P"; 168 168 } else { … … 281 281 282 282 TypeDecl *Pass1::mutate( TypeDecl *typeDecl ) { 283 /// std::cerr << "add " << typeDecl->get_name() << "\n";284 283 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 285 284 return Mutator::mutate( typeDecl ); … … 330 329 } 331 330 332 TypeInstType *isPolyType( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {333 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {334 if ( env ) {335 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {336 return isPolyType( newType, env, tyVars );337 } // if338 } // if339 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {340 return typeInst;341 } else {342 return 0;343 } // if344 } else {345 return 0;346 } // if347 }348 349 331 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) { 350 332 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous. … … 362 344 // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the 363 345 // temporary is already boxed and can be used directly. 364 if ( ! isPolyType( newObj->get_type(), env, scopeTyVars) ) {346 if ( ! isPolyType( newObj->get_type(), scopeTyVars, env ) ) { 365 347 paramExpr = new AddressExpr( paramExpr ); 366 348 } // if … … 388 370 Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 389 371 Expression *ret = appExpr; 390 if ( ! function->get_returnVals().empty() && isPoly Val( function->get_returnVals().front()->get_type(), tyVars ) ) {372 if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) { 391 373 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 392 374 } // if … … 402 384 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 403 385 assert( ! arg->get_results().empty() ); 404 // /if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {386 // if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) { 405 387 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param ); 406 388 if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) { … … 422 404 } // if 423 405 } // if 424 // /}406 // } 425 407 } 426 408 … … 428 410 Type *newType = formal->clone(); 429 411 std::list< FunctionType *> functions; 430 // instead of functions needing adapters, this really ought to look for any function mentioning a431 // polymorphic type412 // instead of functions needing adapters, this really ought to look for 413 // any function mentioning a polymorphic type 432 414 findAndReplaceFunction( newType, functions, tyVars, needsAdapter ); 433 415 if ( ! functions.empty() ) { … … 439 421 440 422 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 441 /// std::cout << "function is ";442 /// function->print( std::cout );443 423 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) { 444 /// std::cout << "parameter is ";445 /// (*param)->print( std::fcout );446 /// std::cout << std::endl << "argument is ";447 /// (*arg)->print( std::cout );448 424 assert( arg != appExpr->get_args().end() ); 449 425 addCast( *arg, (*param)->get_type(), exprTyVars ); … … 480 456 // actually make the adapter type 481 457 FunctionType *adapter = adaptee->clone(); 482 if ( ! adapter->get_returnVals().empty() && isPoly Val( adapter->get_returnVals().front()->get_type(), tyVars ) ) {458 if ( ! adapter->get_returnVals().empty() && isPolyType( adapter->get_returnVals().front()->get_type(), tyVars ) ) { 483 459 makeRetParm( adapter ); 484 460 } // if … … 490 466 assert( param ); 491 467 assert( arg ); 492 /// std::cout << "arg type is "; 493 /// arg->get_type()->print( std::cout ); 494 /// std::cout << "param type is "; 495 /// param->get_type()->print( std::cout ); 496 /// std::cout << " tyVars are: "; 497 /// printTyVarMap( std::cout, tyVars ); 498 if ( isPolyVal( realParam->get_type(), tyVars ) ) { 499 /// if ( dynamic_cast< PointerType *>( arg->get_type() ) ) { 500 /// return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() ); 501 /// } else { 468 if ( isPolyType( realParam->get_type(), tyVars ) ) { 469 // if ( dynamic_cast< PointerType *>( arg->get_type() ) ) { 470 // return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() ); 471 // } else { 502 472 if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) { 503 473 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); … … 506 476 return deref; 507 477 } // if 508 // /}478 // } 509 479 } // if 510 480 return new VariableExpr( param ); … … 553 523 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 554 524 bodyStmt = new ExprStmt( noLabels, adapteeApp ); 555 } else if ( isPoly Val( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {525 } else if ( isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 556 526 if ( (*param)->get_name() == "" ) { 557 527 (*param)->set_name( "_ret" ); … … 625 595 } // passAdapters 626 596 627 TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {628 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {629 return isPolyType( ptr->get_base(), env, tyVars );630 } else if ( env ) {631 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {632 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {633 return isPolyPtr( newType, env, tyVars );634 } // if635 } // if636 } // if637 return 0;638 }639 640 TypeInstType *isPolyPtrPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {641 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {642 return isPolyPtr( ptr->get_base(), env, tyVars );643 } else if ( env ) {644 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {645 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {646 return isPolyPtrPtr( newType, env, tyVars );647 } // if648 } // if649 } // if650 return 0;651 }652 653 597 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) { 654 598 NameExpr *opExpr; … … 681 625 assert( ! appExpr->get_results().empty() ); 682 626 assert( appExpr->get_args().size() == 2 ); 683 Type InstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars);684 Type InstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars);685 assert( ! typeInst1 || ! typeInst2 );627 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env ); 628 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env ); 629 assert( ! baseType1 || ! baseType2 ); 686 630 UntypedExpr *ret = 0; 687 if ( typeInst1 || typeInst2 ) {631 if ( baseType1 || baseType2 ) { 688 632 ret = new UntypedExpr( new NameExpr( "?+?" ) ); 689 633 } // if 690 if ( typeInst1 ) {634 if ( baseType1 ) { 691 635 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 692 636 multiply->get_args().push_back( appExpr->get_args().back() ); 693 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );637 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 694 638 ret->get_args().push_back( appExpr->get_args().front() ); 695 639 ret->get_args().push_back( multiply ); 696 } else if ( typeInst2 ) {640 } else if ( baseType2 ) { 697 641 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 698 642 multiply->get_args().push_back( appExpr->get_args().front() ); 699 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );643 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) ); 700 644 ret->get_args().push_back( multiply ); 701 645 ret->get_args().push_back( appExpr->get_args().back() ); 702 646 } // if 703 if ( typeInst1 || typeInst2 ) {647 if ( baseType1 || baseType2 ) { 704 648 ret->get_results().push_front( appExpr->get_results().front()->clone() ); 705 649 if ( appExpr->get_env() ) { … … 714 658 assert( ! appExpr->get_results().empty() ); 715 659 assert( ! appExpr->get_args().empty() ); 716 if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars) ) {660 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) { 717 661 Expression *ret = appExpr->get_args().front(); 718 662 delete ret->get_results().front(); … … 729 673 assert( ! appExpr->get_results().empty() ); 730 674 assert( appExpr->get_args().size() == 1 ); 731 if ( Type InstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars) ) {675 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) { 732 676 Type *tempType = appExpr->get_results().front()->clone(); 733 677 if ( env ) { … … 743 687 assignExpr->get_args().push_back( appExpr->get_args().front()->clone() ); 744 688 } // if 745 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) );689 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "?++" ) ); 746 690 return new CommaExpr( firstComma, tempExpr ); 747 691 } // if … … 749 693 assert( ! appExpr->get_results().empty() ); 750 694 assert( appExpr->get_args().size() == 1 ); 751 if ( Type InstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars) ) {752 return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" );695 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) { 696 return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" ); 753 697 } // if 754 698 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { 755 699 assert( ! appExpr->get_results().empty() ); 756 700 assert( appExpr->get_args().size() == 2 ); 757 Type InstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars);758 Type InstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars);759 if ( typeInst1 && typeInst2 ) {701 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env ); 702 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env ); 703 if ( baseType1 && baseType2 ) { 760 704 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 761 705 divide->get_args().push_back( appExpr ); 762 divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );706 divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 763 707 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 764 708 if ( appExpr->get_env() ) { … … 767 711 } // if 768 712 return divide; 769 } else if ( typeInst1 ) {713 } else if ( baseType1 ) { 770 714 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 771 715 multiply->get_args().push_back( appExpr->get_args().back() ); 772 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );716 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 773 717 appExpr->get_args().back() = multiply; 774 } else if ( typeInst2 ) {718 } else if ( baseType2 ) { 775 719 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 776 720 multiply->get_args().push_back( appExpr->get_args().front() ); 777 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );721 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) ); 778 722 appExpr->get_args().front() = multiply; 779 723 } // if … … 781 725 assert( ! appExpr->get_results().empty() ); 782 726 assert( appExpr->get_args().size() == 2 ); 783 Type InstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars);784 if ( typeInst) {727 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ); 728 if ( baseType ) { 785 729 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 786 730 multiply->get_args().push_back( appExpr->get_args().back() ); 787 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst) ) );731 multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) ); 788 732 appExpr->get_args().back() = multiply; 789 733 } // if … … 852 796 853 797 Expression *Pass1::mutate( UntypedExpr *expr ) { 854 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars) ) {798 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) { 855 799 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 856 800 if ( name->get_name() == "*?" ) { … … 870 814 bool needs = false; 871 815 if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) { 872 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars) ) {816 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) { 873 817 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 874 818 if ( name->get_name() == "*?" ) { … … 886 830 } // if 887 831 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 888 if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars) || needs ) {832 if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ) || needs ) { 889 833 Expression *ret = addrExpr->get_arg(); 890 834 delete ret->get_results().front(); … … 910 854 castExpr->set_arg( 0 ); 911 855 delete castExpr; 912 } // while856 } //while 913 857 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ); 914 858 assert( typeInst ); … … 924 868 stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) ); 925 869 // } else { 926 // std::cerr << "THOMAS " << std::endl;927 870 // useRetval = true; 928 871 // stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) ); … … 984 927 } 985 928 } 986 // /deleteAll( functions );929 // deleteAll( functions ); 987 930 } 988 931 … … 1134 1077 Statement *Pass3::mutate( DeclStmt *declStmt ) { 1135 1078 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1136 if ( isPoly Val( objectDecl->get_type(), scopeTyVars ) ) {1137 // change initialization of a polymorphic value object to allocate storage with alloca1138 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );1139 assert( typeInst);1079 if ( isPolyType( objectDecl->get_type(), scopeTyVars ) ) { 1080 // change initialization of a polymorphic value object 1081 // to allocate storage with alloca 1082 Type *declType = objectDecl->get_type(); 1140 1083 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1141 alloc->get_args().push_back( new NameExpr( sizeofName( typeInst) ) );1084 alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) ); 1142 1085 1143 1086 delete objectDecl->get_init(); -
src/GenPoly/GenPoly.cc
r4389966 r5f6c42c 15 15 16 16 #include "GenPoly.h" 17 18 #include "SymTab/Mangler.h" 19 #include "SynTree/Expression.h" 17 20 #include "SynTree/Type.h" 18 21 … … 21 24 22 25 namespace GenPoly { 23 /// A function needs an adapter if it returns a polymorphic value or if any of its parameters have polymorphic type24 26 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 25 if ( ! adaptee->get_returnVals().empty() && isPoly Val( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {27 if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 26 28 return true; 27 29 } // if 28 30 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) { 29 if ( isPoly Val( (*innerArg)->get_type(), tyVars ) ) {31 if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) { 30 32 return true; 31 33 } // if … … 65 67 } 66 68 67 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 69 namespace { 70 /// Checks a parameter list for polymorphic parameters 71 bool hasPolyParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) { 72 for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) { 73 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param ); 74 assert(paramType && "Aggregate parameters should be type expressions"); 75 if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true; 76 } 77 return false; 78 } 79 } 80 81 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 68 82 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) { 69 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 70 return true; 83 if ( env ) { 84 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 85 return isPolyType( newType, tyVars, env ); 71 86 } // if 72 87 } // if 73 return false; 88 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 89 return type; 90 } 91 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { 92 if ( hasPolyParams( structType->get_parameters(), tyVars, env ) ) return type; 93 } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) { 94 if ( hasPolyParams( unionType->get_parameters(), tyVars, env ) ) return type; 95 } 96 return 0; 74 97 } 75 98 76 bool isPolyObj( Type *type, const TyVarMap &tyVars ) { 77 if ( isPolyVal( type, tyVars ) ) { 78 return true; 79 } else if ( PointerType *pt = dynamic_cast<PointerType*>( type ) ) { 80 return isPolyObj( pt->get_base(), tyVars ); 81 } else { 82 return false; 83 } 99 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 100 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 101 return isPolyType( ptr->get_base(), tyVars, env ); 102 } else if ( env ) { 103 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 104 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 105 return isPolyPtr( newType, tyVars, env ); 106 } // if 107 } // if 108 } // if 109 return 0; 84 110 } 85 111 … … 90 116 os << std::endl; 91 117 } 118 119 std::string sizeofName( Type *ty ) { 120 return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false ); 121 } 122 123 std::string alignofName( Type *ty ) { 124 return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false ); 125 } 92 126 } // namespace GenPoly 93 127 -
src/GenPoly/GenPoly.h
r4389966 r5f6c42c 20 20 #include <string> 21 21 #include <iostream> 22 22 23 #include "SynTree/Declaration.h" 24 #include "SynTree/TypeSubstitution.h" 23 25 24 26 namespace GenPoly { 25 27 typedef std::map< std::string, TypeDecl::Kind > TyVarMap; 26 28 29 /// A function needs an adapter if it returns a polymorphic value or if any of its 30 /// parameters have polymorphic type 27 31 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); 32 33 /// true iff function has polymorphic return type 28 34 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ); 29 35 bool isPolyRet( FunctionType *function, std::string &name ); 30 36 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ); 31 // bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );32 bool isPolyVal( Type *type, const TyVarMap &tyVars );33 37 34 // true if type variable or any number of pointers to type variable 35 bool isPolyObj( Type *type, const TyVarMap &tyVars ); 38 /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided 39 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 40 41 /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided 42 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 43 44 /// Prints type variable map 36 45 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 46 47 /// Gets the name of the sizeof parameter for the type 48 std::string sizeofName( Type *ty ); 49 50 /// Gets the name of the alignof parameter for the type 51 std::string alignofName( Type *ty ); 37 52 } // namespace GenPoly 38 53 -
src/GenPoly/ScrubTyVars.cc
r4389966 r5f6c42c 19 19 #include "GenPoly.h" 20 20 #include "ScrubTyVars.h" 21 22 #include "SymTab/Mangler.h"23 21 24 22 #include "SynTree/Mutator.h" … … 78 76 return Mutator::mutate( pointer ); 79 77 } 80 81 std::string sizeofName( Type *ty ) {82 return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false );83 }84 85 std::string alignofName( Type *ty ) {86 return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false );87 }88 78 } // namespace GenPoly 89 79 -
src/GenPoly/ScrubTyVars.h
r4389966 r5f6c42c 59 59 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 60 60 } 61 62 /// Gets the name of the sizeof parameter for the type63 std::string sizeofName( Type *ty );64 65 /// Gets the name of the alignof parameter for the type66 std::string alignofName( Type *ty );67 61 } // namespace GenPoly 68 62
Note:
See TracChangeset
for help on using the changeset viewer.