Changes in / [5f6c42c:4389966]
- 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
r5f6c42c r4389966 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 Type( (*retval)->get_type(), tyVars ) ) {157 if ( isPolyVal( (*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 Type( (*arg)->get_type(), tyVars ) ) {166 if ( isPolyVal( (*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"; 283 284 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 284 285 return Mutator::mutate( typeDecl ); … … 329 330 } 330 331 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 } // if 338 } // if 339 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 340 return typeInst; 341 } else { 342 return 0; 343 } // if 344 } else { 345 return 0; 346 } // if 347 } 348 331 349 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) { 332 350 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous. … … 344 362 // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the 345 363 // temporary is already boxed and can be used directly. 346 if ( ! isPolyType( newObj->get_type(), scopeTyVars, env) ) {364 if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) { 347 365 paramExpr = new AddressExpr( paramExpr ); 348 366 } // if … … 370 388 Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 371 389 Expression *ret = appExpr; 372 if ( ! function->get_returnVals().empty() && isPoly Type( function->get_returnVals().front()->get_type(), tyVars ) ) {390 if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) { 373 391 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 374 392 } // if … … 384 402 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 385 403 assert( ! arg->get_results().empty() ); 386 // if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {404 /// if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) { 387 405 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param ); 388 406 if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) { … … 404 422 } // if 405 423 } // if 406 // }424 /// } 407 425 } 408 426 … … 410 428 Type *newType = formal->clone(); 411 429 std::list< FunctionType *> functions; 412 // instead of functions needing adapters, this really ought to look for 413 // any function mentioning apolymorphic type430 // instead of functions needing adapters, this really ought to look for any function mentioning a 431 // polymorphic type 414 432 findAndReplaceFunction( newType, functions, tyVars, needsAdapter ); 415 433 if ( ! functions.empty() ) { … … 421 439 422 440 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 ); 423 443 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 ); 424 448 assert( arg != appExpr->get_args().end() ); 425 449 addCast( *arg, (*param)->get_type(), exprTyVars ); … … 456 480 // actually make the adapter type 457 481 FunctionType *adapter = adaptee->clone(); 458 if ( ! adapter->get_returnVals().empty() && isPoly Type( adapter->get_returnVals().front()->get_type(), tyVars ) ) {482 if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) { 459 483 makeRetParm( adapter ); 460 484 } // if … … 466 490 assert( param ); 467 491 assert( arg ); 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 { 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 { 472 502 if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) { 473 503 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); … … 476 506 return deref; 477 507 } // if 478 // }508 /// } 479 509 } // if 480 510 return new VariableExpr( param ); … … 523 553 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 524 554 bodyStmt = new ExprStmt( noLabels, adapteeApp ); 525 } else if ( isPoly Type( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {555 } else if ( isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 526 556 if ( (*param)->get_name() == "" ) { 527 557 (*param)->set_name( "_ret" ); … … 595 625 } // passAdapters 596 626 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 } // if 635 } // if 636 } // if 637 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 } // if 648 } // if 649 } // if 650 return 0; 651 } 652 597 653 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) { 598 654 NameExpr *opExpr; … … 625 681 assert( ! appExpr->get_results().empty() ); 626 682 assert( appExpr->get_args().size() == 2 ); 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 );683 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); 684 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars ); 685 assert( ! typeInst1 || ! typeInst2 ); 630 686 UntypedExpr *ret = 0; 631 if ( baseType1 || baseType2 ) {687 if ( typeInst1 || typeInst2 ) { 632 688 ret = new UntypedExpr( new NameExpr( "?+?" ) ); 633 689 } // if 634 if ( baseType1 ) {690 if ( typeInst1 ) { 635 691 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 636 692 multiply->get_args().push_back( appExpr->get_args().back() ); 637 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );693 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 638 694 ret->get_args().push_back( appExpr->get_args().front() ); 639 695 ret->get_args().push_back( multiply ); 640 } else if ( baseType2 ) {696 } else if ( typeInst2 ) { 641 697 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 642 698 multiply->get_args().push_back( appExpr->get_args().front() ); 643 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );699 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 644 700 ret->get_args().push_back( multiply ); 645 701 ret->get_args().push_back( appExpr->get_args().back() ); 646 702 } // if 647 if ( baseType1 || baseType2 ) {703 if ( typeInst1 || typeInst2 ) { 648 704 ret->get_results().push_front( appExpr->get_results().front()->clone() ); 649 705 if ( appExpr->get_env() ) { … … 658 714 assert( ! appExpr->get_results().empty() ); 659 715 assert( ! appExpr->get_args().empty() ); 660 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env) ) {716 if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars ) ) { 661 717 Expression *ret = appExpr->get_args().front(); 662 718 delete ret->get_results().front(); … … 673 729 assert( ! appExpr->get_results().empty() ); 674 730 assert( appExpr->get_args().size() == 1 ); 675 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env) ) {731 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { 676 732 Type *tempType = appExpr->get_results().front()->clone(); 677 733 if ( env ) { … … 687 743 assignExpr->get_args().push_back( appExpr->get_args().front()->clone() ); 688 744 } // if 689 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "?++" ) );745 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) ); 690 746 return new CommaExpr( firstComma, tempExpr ); 691 747 } // if … … 693 749 assert( ! appExpr->get_results().empty() ); 694 750 assert( appExpr->get_args().size() == 1 ); 695 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env) ) {696 return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );751 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { 752 return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" ); 697 753 } // if 698 754 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { 699 755 assert( ! appExpr->get_results().empty() ); 700 756 assert( appExpr->get_args().size() == 2 ); 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 ) {757 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); 758 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars ); 759 if ( typeInst1 && typeInst2 ) { 704 760 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 705 761 divide->get_args().push_back( appExpr ); 706 divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );762 divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 707 763 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 708 764 if ( appExpr->get_env() ) { … … 711 767 } // if 712 768 return divide; 713 } else if ( baseType1 ) {769 } else if ( typeInst1 ) { 714 770 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 715 771 multiply->get_args().push_back( appExpr->get_args().back() ); 716 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );772 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 717 773 appExpr->get_args().back() = multiply; 718 } else if ( baseType2 ) {774 } else if ( typeInst2 ) { 719 775 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 720 776 multiply->get_args().push_back( appExpr->get_args().front() ); 721 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );777 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 722 778 appExpr->get_args().front() = multiply; 723 779 } // if … … 725 781 assert( ! appExpr->get_results().empty() ); 726 782 assert( appExpr->get_args().size() == 2 ); 727 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env);728 if ( baseType) {783 TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ); 784 if ( typeInst ) { 729 785 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 730 786 multiply->get_args().push_back( appExpr->get_args().back() ); 731 multiply->get_args().push_back( new NameExpr( sizeofName( baseType) ) );787 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 732 788 appExpr->get_args().back() = multiply; 733 789 } // if … … 796 852 797 853 Expression *Pass1::mutate( UntypedExpr *expr ) { 798 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env) ) {854 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) { 799 855 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 800 856 if ( name->get_name() == "*?" ) { … … 814 870 bool needs = false; 815 871 if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) { 816 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env) ) {872 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) { 817 873 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 818 874 if ( name->get_name() == "*?" ) { … … 830 886 } // if 831 887 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 832 if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env) || needs ) {888 if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) || needs ) { 833 889 Expression *ret = addrExpr->get_arg(); 834 890 delete ret->get_results().front(); … … 854 910 castExpr->set_arg( 0 ); 855 911 delete castExpr; 856 } // while912 } // while 857 913 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ); 858 914 assert( typeInst ); … … 868 924 stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) ); 869 925 // } else { 926 // std::cerr << "THOMAS " << std::endl; 870 927 // useRetval = true; 871 928 // stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) ); … … 927 984 } 928 985 } 929 // deleteAll( functions );986 /// deleteAll( functions ); 930 987 } 931 988 … … 1077 1134 Statement *Pass3::mutate( DeclStmt *declStmt ) { 1078 1135 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1079 if ( isPoly Type( objectDecl->get_type(), scopeTyVars ) ) {1080 // change initialization of a polymorphic value object 1081 // to allocate storage with alloca1082 Type *declType = objectDecl->get_type();1136 if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) { 1137 // change initialization of a polymorphic value object to allocate storage with alloca 1138 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() ); 1139 assert( typeInst ); 1083 1140 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1084 alloc->get_args().push_back( new NameExpr( sizeofName( declType) ) );1141 alloc->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 1085 1142 1086 1143 delete objectDecl->get_init(); -
src/GenPoly/GenPoly.cc
r5f6c42c r4389966 15 15 16 16 #include "GenPoly.h" 17 18 #include "SymTab/Mangler.h"19 #include "SynTree/Expression.h"20 17 #include "SynTree/Type.h" 21 18 … … 24 21 25 22 namespace GenPoly { 23 /// A function needs an adapter if it returns a polymorphic value or if any of its parameters have polymorphic type 26 24 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 27 if ( ! adaptee->get_returnVals().empty() && isPoly Type( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {25 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 28 26 return true; 29 27 } // if 30 28 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) { 31 if ( isPoly Type( (*innerArg)->get_type(), tyVars ) ) {29 if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) { 32 30 return true; 33 31 } // if … … 67 65 } 68 66 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 } 67 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 68 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) { 69 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 70 return true; 71 } // if 72 } // if 73 return false; 74 } 75 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 { 77 82 return false; 78 83 } 79 }80 81 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {82 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {83 if ( env ) {84 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {85 return isPolyType( newType, tyVars, env );86 } // if87 } // if88 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;97 }98 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 } // if107 } // if108 } // if109 return 0;110 84 } 111 85 … … 116 90 os << std::endl; 117 91 } 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 }126 92 } // namespace GenPoly 127 93 -
src/GenPoly/GenPoly.h
r5f6c42c r4389966 20 20 #include <string> 21 21 #include <iostream> 22 23 22 #include "SynTree/Declaration.h" 24 #include "SynTree/TypeSubstitution.h"25 23 26 24 namespace GenPoly { 27 25 typedef std::map< std::string, TypeDecl::Kind > TyVarMap; 28 26 29 /// A function needs an adapter if it returns a polymorphic value or if any of its30 /// parameters have polymorphic type31 27 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); 32 33 /// true iff function has polymorphic return type34 28 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ); 35 29 bool isPolyRet( FunctionType *function, std::string &name ); 36 30 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ); 31 // bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars ); 32 bool isPolyVal( Type *type, const TyVarMap &tyVars ); 37 33 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 34 // true if type variable or any number of pointers to type variable 35 bool isPolyObj( Type *type, const TyVarMap &tyVars ); 45 36 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 46 47 /// Gets the name of the sizeof parameter for the type48 std::string sizeofName( Type *ty );49 50 /// Gets the name of the alignof parameter for the type51 std::string alignofName( Type *ty );52 37 } // namespace GenPoly 53 38 -
src/GenPoly/ScrubTyVars.cc
r5f6c42c r4389966 19 19 #include "GenPoly.h" 20 20 #include "ScrubTyVars.h" 21 22 #include "SymTab/Mangler.h" 21 23 22 24 #include "SynTree/Mutator.h" … … 76 78 return Mutator::mutate( pointer ); 77 79 } 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 } 78 88 } // namespace GenPoly 79 89 -
src/GenPoly/ScrubTyVars.h
r5f6c42c r4389966 59 59 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 60 60 } 61 62 /// Gets the name of the sizeof parameter for the type 63 std::string sizeofName( Type *ty ); 64 65 /// Gets the name of the alignof parameter for the type 66 std::string alignofName( Type *ty ); 61 67 } // namespace GenPoly 62 68
Note:
See TracChangeset
for help on using the changeset viewer.