Changeset 4389966 for src/GenPoly/Box.cc
- Timestamp:
- Dec 15, 2015, 4:14:01 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:
- 5f6c42c
- Parents:
- cf16f94 (diff), 78dd0da (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/GenPoly/Box.cc
rcf16f94 r4389966 28 28 #include "Parser/ParseNode.h" 29 29 30 #include "SynTree/Constant.h" 30 31 #include "SynTree/Type.h" 31 32 #include "SynTree/Expression.h" … … 50 51 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 51 52 53 /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call 52 54 class Pass1 : public PolyMutator { 53 55 public: … … 88 90 }; 89 91 92 /// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well 90 93 class Pass2 : public PolyMutator { 91 94 public: 92 Pass2();93 95 template< typename DeclClass > 94 96 DeclClass *handleDecl( DeclClass *decl, Type *type ); … … 105 107 }; 106 108 109 /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable 107 110 class Pass3 : public PolyMutator { 108 111 public: … … 178 181 } 179 182 180 Pass1::Pass1() 181 : useRetval( false ), tempNamer( "_temp" ) { 183 Pass1::Pass1() : useRetval( false ), tempNamer( "_temp" ) { 182 184 adapters.push(AdapterMap()); 183 185 } … … 312 314 if ( concrete ) { 313 315 arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) ); 316 arg++; 317 arg = appExpr->get_args().insert( arg, new AlignofExpr( concrete->clone() ) ); 314 318 arg++; 315 319 } else { … … 647 651 } 648 652 649 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, std::string polyName, bool isIncr ) {653 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) { 650 654 NameExpr *opExpr; 651 655 if ( isIncr ) { … … 660 664 addAssign->get_args().push_back( appExpr->get_args().front() ); 661 665 } // if 662 addAssign->get_args().push_back( new NameExpr( polyName) );666 addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) ); 663 667 addAssign->get_results().front() = appExpr->get_results().front()->clone(); 664 668 if ( appExpr->get_env() ) { … … 687 691 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 688 692 multiply->get_args().push_back( appExpr->get_args().back() ); 689 multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );693 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 690 694 ret->get_args().push_back( appExpr->get_args().front() ); 691 695 ret->get_args().push_back( multiply ); … … 693 697 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 694 698 multiply->get_args().push_back( appExpr->get_args().front() ); 695 multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );699 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 696 700 ret->get_args().push_back( multiply ); 697 701 ret->get_args().push_back( appExpr->get_args().back() ); … … 739 743 assignExpr->get_args().push_back( appExpr->get_args().front()->clone() ); 740 744 } // if 741 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst ->get_name(), varExpr->get_var()->get_name() == "?++" ) );745 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) ); 742 746 return new CommaExpr( firstComma, tempExpr ); 743 747 } // if … … 746 750 assert( appExpr->get_args().size() == 1 ); 747 751 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { 748 return makeIncrDecrExpr( appExpr, typeInst ->get_name(), varExpr->get_var()->get_name() == "++?" );752 return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" ); 749 753 } // if 750 754 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { … … 756 760 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 757 761 divide->get_args().push_back( appExpr ); 758 divide->get_args().push_back( new NameExpr( typeInst1->get_name() ) );762 divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 759 763 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 760 764 if ( appExpr->get_env() ) { … … 766 770 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 767 771 multiply->get_args().push_back( appExpr->get_args().back() ); 768 multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );772 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 769 773 appExpr->get_args().back() = multiply; 770 774 } else if ( typeInst2 ) { 771 775 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 772 776 multiply->get_args().push_back( appExpr->get_args().front() ); 773 multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );777 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 774 778 appExpr->get_args().front() = multiply; 775 779 } // if … … 781 785 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 782 786 multiply->get_args().push_back( appExpr->get_args().back() ); 783 multiply->get_args().push_back( new NameExpr( typeInst->get_name() ) );787 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 784 788 appExpr->get_args().back() = multiply; 785 789 } // if … … 963 967 ////////////////////////////////////////// Pass2 //////////////////////////////////////////////////// 964 968 965 Pass2::Pass2() {}966 967 969 void Pass2::addAdapters( FunctionType *functionType ) { 968 970 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters(); … … 1037 1039 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1038 1040 std::list< DeclarationWithType *> inferredParams; 1039 ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );1040 // /ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );1041 ObjectDecl newObj( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ); 1042 // ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ); 1041 1043 for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1042 ObjectDecl * thisParm;1043 // add all size parameters to parameter list1044 ObjectDecl *sizeParm, *alignParm; 1045 // add all size and alignment parameters to parameter list 1044 1046 if ( (*tyParm)->get_kind() == TypeDecl::Any ) { 1045 thisParm = newObj->clone(); 1046 thisParm->set_name( (*tyParm)->get_name() ); 1047 last = funcType->get_parameters().insert( last, thisParm ); 1047 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1048 1049 sizeParm = newObj.clone(); 1050 sizeParm->set_name( sizeofName( &parmType ) ); 1051 last = funcType->get_parameters().insert( last, sizeParm ); 1052 ++last; 1053 1054 alignParm = newObj.clone(); 1055 alignParm->set_name( alignofName( &parmType ) ); 1056 last = funcType->get_parameters().insert( last, alignParm ); 1048 1057 ++last; 1049 1058 } 1050 1059 // move all assertions into parameter list 1051 1060 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1052 // /*assert = (*assert)->acceptMutator( *this );1061 // *assert = (*assert)->acceptMutator( *this ); 1053 1062 inferredParams.push_back( *assert ); 1054 1063 } 1055 1064 (*tyParm)->get_assertions().clear(); 1056 1065 } 1057 delete newObj;1058 1066 funcType->get_parameters().splice( last, inferredParams ); 1059 1067 addAdapters( funcType ); … … 1092 1100 1093 1101 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) { 1094 // /Initializer *init = 0;1095 // /std::list< Expression *> designators;1096 // /scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();1097 // /if ( typeDecl->get_base() ) {1098 // /init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );1099 // /}1100 // /return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );1102 // Initializer *init = 0; 1103 // std::list< Expression *> designators; 1104 // scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 1105 // if ( typeDecl->get_base() ) { 1106 // init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators ); 1107 // } 1108 // return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init ); 1101 1109 1102 1110 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); … … 1131 1139 assert( typeInst ); 1132 1140 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1133 alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) );1141 alloc->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 1134 1142 1135 1143 delete objectDecl->get_init();
Note: See TracChangeset
for help on using the changeset viewer.