Changeset a32b204 for translator/GenPoly
- Timestamp:
- May 17, 2015, 1:19:35 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:
- 0dd3a2f
- Parents:
- b87a5ed
- Location:
- translator/GenPoly
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/GenPoly/Box.cc
rb87a5ed ra32b204 110 110 void printAllNotBuiltin( const std::list< Declaration *>& translationUnit, std::ostream &os ) { 111 111 for ( std::list< Declaration *>::const_iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) { 112 if ( ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) {112 if ( ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) { 113 113 (*i)->print( os ); 114 114 os << std::endl; … … 135 135 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) { 136 136 bool doTransform = false; 137 if ( ! function->get_returnVals().empty() ) {137 if ( ! function->get_returnVals().empty() ) { 138 138 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) { 139 139 … … 146 146 } // if 147 147 } // for 148 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {148 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) { 149 149 doTransform = true; 150 150 } // if … … 304 304 ObjectDecl *newObj = makeTemporary( retType->clone() ); 305 305 Expression *paramExpr = new VariableExpr( newObj ); 306 if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {306 if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) { 307 307 paramExpr = new AddressExpr( paramExpr ); 308 308 } // if … … 330 330 Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 331 331 Expression *ret = appExpr; 332 if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) {332 if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) { 333 333 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 334 334 } // if … … 343 343 344 344 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 345 assert( ! arg->get_results().empty() );346 /// if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {345 assert( ! arg->get_results().empty() ); 346 /// if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) { 347 347 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param ); 348 348 if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) { … … 373 373 // any function mentioning a polymorphic type 374 374 findAndReplaceFunction( newType, functions, tyVars, needsAdapter ); 375 if ( ! functions.empty() ) {375 if ( ! functions.empty() ) { 376 376 actual = new CastExpr( actual, newType ); 377 377 } else { … … 422 422 // actually make the adapter type 423 423 FunctionType *adapter = adaptee->clone(); 424 if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) {424 if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) { 425 425 makeRetParm( adapter ); 426 426 } // if … … 611 611 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 612 612 if ( varExpr->get_var()->get_name() == "?[?]" ) { 613 assert( ! appExpr->get_results().empty() );613 assert( ! appExpr->get_results().empty() ); 614 614 assert( appExpr->get_args().size() == 2 ); 615 615 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); 616 616 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars ); 617 assert( ! typeInst1 || !typeInst2 );617 assert( ! typeInst1 || ! typeInst2 ); 618 618 UntypedExpr *ret = 0; 619 619 if ( typeInst1 || typeInst2 ) { … … 644 644 } // if 645 645 } else if ( varExpr->get_var()->get_name() == "*?" ) { 646 assert( ! appExpr->get_results().empty() );647 assert( ! appExpr->get_args().empty() );646 assert( ! appExpr->get_results().empty() ); 647 assert( ! appExpr->get_args().empty() ); 648 648 if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars ) ) { 649 649 Expression *ret = appExpr->get_args().front(); … … 659 659 } // if 660 660 } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) { 661 assert( ! appExpr->get_results().empty() );661 assert( ! appExpr->get_results().empty() ); 662 662 assert( appExpr->get_args().size() == 1 ); 663 663 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { … … 679 679 } // if 680 680 } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) { 681 assert( ! appExpr->get_results().empty() );681 assert( ! appExpr->get_results().empty() ); 682 682 assert( appExpr->get_args().size() == 1 ); 683 683 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { … … 685 685 } // if 686 686 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { 687 assert( ! appExpr->get_results().empty() );687 assert( ! appExpr->get_results().empty() ); 688 688 assert( appExpr->get_args().size() == 2 ); 689 689 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); … … 711 711 } // if 712 712 } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) { 713 assert( ! appExpr->get_results().empty() );713 assert( ! appExpr->get_results().empty() ); 714 714 assert( appExpr->get_args().size() == 2 ); 715 715 TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ); … … 739 739 useRetval = oldUseRetval; 740 740 741 assert( ! appExpr->get_function()->get_results().empty() );741 assert( ! appExpr->get_function()->get_results().empty() ); 742 742 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() ); 743 743 assert( pointer ); … … 784 784 785 785 Expression *Pass1::mutate( UntypedExpr *expr ) { 786 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {786 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) { 787 787 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 788 788 if ( name->get_name() == "*?" ) { … … 798 798 799 799 Expression *Pass1::mutate( AddressExpr *addrExpr ) { 800 assert( ! addrExpr->get_arg()->get_results().empty() );800 assert( ! addrExpr->get_arg()->get_results().empty() ); 801 801 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 802 802 if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) { … … 823 823 } 824 824 if ( retval && retStmt->get_expr() ) { 825 assert( ! retStmt->get_expr()->get_results().empty() );825 assert( ! retStmt->get_expr()->get_results().empty() ); 826 826 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) { 827 827 /// retStmt->set_expr( mutateExpression( retStmt->get_expr() ) ); -
translator/GenPoly/CopyParams.cc
rb87a5ed ra32b204 46 46 } // if 47 47 } // for 48 for ( std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin(); param != funcDecl->get_functionType()->get_parameters().end(); ++param ) {48 for ( std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin(); param != funcDecl->get_functionType()->get_parameters().end(); ++param ) { 49 49 std::set< UniqueId >::const_iterator var = modVars.find( (*param)->get_uniqueId() ); 50 50 if ( var != modVars.end() ) { -
translator/GenPoly/FindFunction.cc
rb87a5ed ra32b204 52 52 FindFunction::handleForall( const std::list< TypeDecl* > &forall ) 53 53 { 54 for ( std::list< TypeDecl* >::const_iterator i = forall.begin(); i != forall.end(); ++i ) {54 for ( std::list< TypeDecl* >::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 55 55 TyVarMap::iterator var = tyVars.find( (*i)->get_name() ); 56 if ( var != tyVars.end() ) {56 if ( var != tyVars.end() ) { 57 57 tyVars.erase( var ); 58 58 } … … 67 67 mutateAll( functionType->get_returnVals(), *this ); 68 68 Type *ret = functionType; 69 if ( predicate( functionType, tyVars ) ) {69 if ( predicate( functionType, tyVars ) ) { 70 70 functions.push_back( functionType ); 71 if ( replaceMode ) {71 if ( replaceMode ) { 72 72 ret = new FunctionType( Type::Qualifiers(), true ); 73 73 } -
translator/GenPoly/GenPoly.cc
rb87a5ed ra32b204 26 26 isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) 27 27 { 28 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {29 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {28 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 29 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 30 30 return true; 31 31 } … … 41 41 { 42 42 bool needsAdapter = false; 43 if ( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) {43 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { 44 44 needsAdapter = true; 45 45 } 46 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); !needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) {47 if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) {46 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { 47 if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { 48 48 needsAdapter = true; 49 49 } … … 56 56 printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) 57 57 { 58 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {58 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { 59 59 os << i->first << " (" << i->second << ") "; 60 60 } -
translator/GenPoly/Lvalue.cc
rb87a5ed ra32b204 67 67 isLvalueRet( FunctionType *function ) 68 68 { 69 if ( !function->get_returnVals().empty() ) {69 if ( ! function->get_returnVals().empty() ) { 70 70 return function->get_returnVals().front()->get_type()->get_isLvalue(); 71 71 } else { … … 77 77 isIntrinsicApp( ApplicationExpr *appExpr ) 78 78 { 79 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( appExpr->get_function() ) ) {79 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( appExpr->get_function() ) ) { 80 80 return varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic; 81 81 } else { … … 91 91 Pass1::mutate( FunctionDecl *funcDecl ) 92 92 { 93 if ( funcDecl->get_statements() ) {93 if ( funcDecl->get_statements() ) { 94 94 DeclarationWithType* oldRetval = retval; 95 95 retval = 0; 96 if ( !LinkageSpec::isBuiltin( funcDecl->get_linkage() ) && isLvalueRet( funcDecl->get_functionType() ) ) {96 if ( ! LinkageSpec::isBuiltin( funcDecl->get_linkage() ) && isLvalueRet( funcDecl->get_functionType() ) ) { 97 97 retval = funcDecl->get_functionType()->get_returnVals().front(); 98 98 } … … 110 110 mutateAll( appExpr->get_args(), *this ); 111 111 112 assert( ! appExpr->get_function()->get_results().empty() );112 assert( ! appExpr->get_function()->get_results().empty() ); 113 113 114 114 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() ); … … 118 118 119 119 std::string typeName; 120 if ( isLvalueRet( function ) && !isIntrinsicApp( appExpr ) ) {120 if ( isLvalueRet( function ) && ! isIntrinsicApp( appExpr ) ) { 121 121 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 122 122 deref->get_results().push_back( appExpr->get_results().front() ); … … 132 132 Pass1::mutate(ReturnStmt *retStmt) 133 133 { 134 if ( retval && retStmt->get_expr() ) {135 assert( ! retStmt->get_expr()->get_results().empty() );136 while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {134 if ( retval && retStmt->get_expr() ) { 135 assert( ! retStmt->get_expr()->get_results().empty() ); 136 while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) { 137 137 retStmt->set_expr( castExpr->get_arg() ); 138 138 retStmt->get_expr()->set_env( castExpr->get_env() ); … … 141 141 delete castExpr; 142 142 } 143 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {143 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) { 144 144 retStmt->set_expr( new AddressExpr( retStmt->get_expr()->acceptMutator( *this ) ) ); 145 145 } else { … … 154 154 { 155 155 std::string typeName; 156 if ( isLvalueRet( funType ) ) {156 if ( isLvalueRet( funType ) ) { 157 157 DeclarationWithType *retParm = funType->get_returnVals().front(); 158 158 -
translator/GenPoly/PolyMutator.cc
rb87a5ed ra32b204 28 28 PolyMutator::mutateStatementList( std::list< Statement* > &statements ) 29 29 { 30 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {31 if ( !stmtsToAddAfter.empty() ) {30 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 31 if ( ! stmtsToAddAfter.empty() ) { 32 32 statements.splice( i, stmtsToAddAfter ); 33 33 } 34 34 *i = (*i)->acceptMutator( *this ); 35 if ( !stmtsToAdd.empty() ) {35 if ( ! stmtsToAdd.empty() ) { 36 36 statements.splice( i, stmtsToAdd ); 37 37 } 38 38 } 39 if ( !stmtsToAddAfter.empty() ) {39 if ( ! stmtsToAddAfter.empty() ) { 40 40 statements.splice( statements.end(), stmtsToAddAfter ); 41 41 } … … 46 46 { 47 47 Statement *newStmt = maybeMutate( stmt, *this ); 48 if ( !stmtsToAdd.empty() || !stmtsToAddAfter.empty() ) {48 if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) { 49 49 CompoundStmt *compound = new CompoundStmt( noLabels ); 50 50 compound->get_kids().splice( compound->get_kids().end(), stmtsToAdd ); … … 61 61 PolyMutator::mutateExpression( Expression *expr ) 62 62 { 63 if ( expr ) {64 if ( expr->get_env() ) {63 if ( expr ) { 64 if ( expr->get_env() ) { 65 65 env = expr->get_env(); 66 66 } … … 167 167 PolyMutator::mutate(UntypedExpr *untypedExpr) 168 168 { 169 for ( std::list< Expression* >::iterator i = untypedExpr->get_args().begin(); i != untypedExpr->get_args().end(); ++i ) {169 for ( std::list< Expression* >::iterator i = untypedExpr->get_args().begin(); i != untypedExpr->get_args().end(); ++i ) { 170 170 *i = mutateExpression( *i ); 171 171 } … … 177 177 PolyMutator::makeTyVarMap( Type *type, TyVarMap &tyVarMap ) 178 178 { 179 for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {179 for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) { 180 180 assert( *tyVar ); 181 181 tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind(); 182 182 } 183 if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {183 if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) { 184 184 makeTyVarMap( pointer->get_base(), tyVarMap ); 185 185 } -
translator/GenPoly/ScrubTyVars.cc
rb87a5ed ra32b204 11 11 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 12 12 if ( doAll || tyVar != tyVars.end() ) { 13 switch ( tyVar->second ) {13 switch ( tyVar->second ) { 14 14 case TypeDecl::Any: 15 15 case TypeDecl::Dtype: -
translator/GenPoly/Specialize.cc
rb87a5ed ra32b204 61 61 needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) 62 62 { 63 if ( env ) {63 if ( env ) { 64 64 using namespace ResolvExpr; 65 65 OpenVarSet openVars, closedVars; … … 67 67 findOpenVars( formalType, openVars, closedVars, need, have, false ); 68 68 findOpenVars( actualType, openVars, closedVars, need, have, true ); 69 for ( OpenVarSet::const_iterator openVar = openVars.begin(); openVar != openVars.end(); ++openVar ) {69 for ( OpenVarSet::const_iterator openVar = openVars.begin(); openVar != openVars.end(); ++openVar ) { 70 70 Type *boundType = env->lookup( openVar->first ); 71 if ( !boundType ) continue;72 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( boundType ) ) {73 if ( closedVars.find( typeInst->get_name() ) == closedVars.end() ) {71 if ( ! boundType ) continue; 72 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( boundType ) ) { 73 if ( closedVars.find( typeInst->get_name() ) == closedVars.end() ) { 74 74 return true; 75 75 } … … 87 87 Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) 88 88 { 89 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) {89 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) { 90 90 PointerType *ptrType; 91 91 FunctionType *funType; 92 if ( ( ptrType = dynamic_cast< PointerType* >( formalType ) ) && ( funType = dynamic_cast< FunctionType* >( ptrType->get_base() ) ) ) {92 if ( ( ptrType = dynamic_cast< PointerType* >( formalType ) ) && ( funType = dynamic_cast< FunctionType* >( ptrType->get_base() ) ) ) { 93 93 FunctionType *newType = funType->clone(); 94 if ( env ) {94 if ( env ) { 95 95 TypeSubstitution newEnv( *env ); 96 96 // it is important to replace only occurrences of type variables that occur free in the … … 103 103 UniqueName paramNamer( paramPrefix ); 104 104 ApplicationExpr *appExpr = new ApplicationExpr( actual ); 105 for ( std::list< DeclarationWithType* >::iterator param = thunkFunc->get_functionType()->get_parameters().begin(); param != thunkFunc->get_functionType()->get_parameters().end(); ++param ) {105 for ( std::list< DeclarationWithType* >::iterator param = thunkFunc->get_functionType()->get_parameters().begin(); param != thunkFunc->get_functionType()->get_parameters().end(); ++param ) { 106 106 (*param)->set_name( paramNamer.newName() ); 107 107 appExpr->get_args().push_back( new VariableExpr( *param ) ); 108 108 } 109 109 appExpr->set_env( maybeClone( env ) ); 110 if ( inferParams ) {110 if ( inferParams ) { 111 111 appExpr->get_inferParams() = *inferParams; 112 112 } … … 123 123 124 124 Statement *appStmt; 125 if ( funType->get_returnVals().empty() ) {125 if ( funType->get_returnVals().empty() ) { 126 126 appStmt = new ExprStmt( noLabels, appExpr ); 127 127 } else { … … 143 143 { 144 144 // create thunks for the explicit parameters 145 assert( ! appExpr->get_function()->get_results().empty() );145 assert( ! appExpr->get_function()->get_results().empty() ); 146 146 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() ); 147 147 assert( pointer ); … … 149 149 std::list< DeclarationWithType* >::iterator formal; 150 150 std::list< Expression* >::iterator actual; 151 for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {151 for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) { 152 152 *actual = doSpecialization( (*formal)->get_type(), *actual, &appExpr->get_inferParams() ); 153 153 } … … 161 161 162 162 // create thunks for the inferred parameters 163 for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) {163 for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) { 164 164 inferParam->second.expr = doSpecialization( inferParam->second.formalType, inferParam->second.expr, &appExpr->get_inferParams() ); 165 165 }
Note: See TracChangeset
for help on using the changeset viewer.