Changeset 2f42718
- Timestamp:
- Feb 22, 2019, 10:43:29 AM (5 years ago)
- Branches:
- no_list
- Parents:
- 43e0949
- Location:
- src
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/FixMain.cc
r43e0949 r2f42718 49 49 50 50 os << main_signature->get_scopedMangleName() << "("; 51 const auto& params = main_signature->get_functionType()-> get_parameters();51 const auto& params = main_signature->get_functionType()->parameters; 52 52 switch(params.size()) { 53 53 case 3: os << "(" << genTypeAt(params, 0) << ")argc, (" << genTypeAt(params, 1) << ")argv, (" << genTypeAt(params, 2) << ")envp"; break; -
src/CodeGen/FixNames.cc
r43e0949 r2f42718 50 50 main_type = new FunctionType( Type::Qualifiers(), true ), nullptr ) 51 51 }; 52 main_type-> get_returnVals().push_back(52 main_type->returnVals.push_back( 53 53 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) 54 54 ); … … 63 63 main_type = new FunctionType( Type::Qualifiers(), false ), nullptr ) 64 64 }; 65 main_type-> get_returnVals().push_back(65 main_type->returnVals.push_back( 66 66 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) 67 67 ); 68 68 69 main_type-> get_parameters().push_back(69 main_type->parameters.push_back( 70 70 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) 71 71 ); 72 72 73 main_type-> get_parameters().push_back(73 main_type->parameters.push_back( 74 74 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, 75 75 new PointerType( Type::Qualifiers(), new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Char ) ) ), … … 116 116 117 117 if(is_main( SymTab::Mangler::mangle(functionDecl, true, true) )) { 118 int nargs = functionDecl->get_functionType()-> get_parameters().size();118 int nargs = functionDecl->get_functionType()->parameters.size(); 119 119 if( !(nargs == 0 || nargs == 2 || nargs == 3) ) { 120 120 SemanticError(functionDecl, "Main expected to have 0, 2 or 3 arguments\n"); -
src/CodeGen/GenType.cc
r43e0949 r2f42718 186 186 /************* parameters ***************/ 187 187 188 const std::list<DeclarationWithType *> &pars = funcType->parameters;188 const auto & pars = funcType->parameters; 189 189 190 190 if ( pars.empty() ) { -
src/CodeTools/DeclStats.cc
r43e0949 r2f42718 183 183 } 184 184 185 void analyzeSubtypes( std:: list<DeclarationWithType*>& tys, Stats& stats,185 void analyzeSubtypes( std::vector<DeclarationWithType*>& tys, Stats& stats, 186 186 std::unordered_set<std::string>& elSeen, unsigned& n_poly, bool& seen_poly, 187 unsigned& max_depth, unsigned depth, unsigned& n_subs ) { 187 unsigned& max_depth, unsigned depth, unsigned& n_subs ) 188 { 188 189 for ( DeclarationWithType* dwt : tys ) { 189 190 Type* ty = dwt->get_type(); … … 204 205 } 205 206 206 void analyzeSubtypes( std:: list<Type*>& tys, Stats& stats,207 void analyzeSubtypes( std::vector<Type*>& tys, Stats& stats, 207 208 std::unordered_set<std::string>& elSeen, unsigned& n_poly, bool& seen_poly, 208 209 unsigned& max_depth, unsigned depth ) { … … 246 247 unsigned n_subs = 0; 247 248 analyzeSubtypes( 248 ft-> get_returnVals(), stats, elSeen, n_poly, seen_poly, max_depth, depth,249 ft->returnVals, stats, elSeen, n_poly, seen_poly, max_depth, depth, 249 250 n_subs ); 250 251 analyzeSubtypes( 251 ft-> get_parameters(), stats, elSeen, n_poly, seen_poly, max_depth, depth,252 ft->parameters, stats, elSeen, n_poly, seen_poly, max_depth, depth, 252 253 n_subs ); 253 254 ++stats.n_generic_params.at( n_subs ); … … 280 281 name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen); 281 282 analyzeSubtypes( 282 tt-> get_types(), stats, elSeen, n_poly, seen_poly, max_depth, depth );283 tt->types, stats, elSeen, n_poly, seen_poly, max_depth, depth ); 283 284 ++stats.n_generic_params.at( tt->size() ); 284 285 } else if ( dynamic_cast<VarArgsType*>(ty) ) { … … 299 300 300 301 /// Update arg pack stats based on a declaration list 301 void analyze( Stats& stats, std::unordered_set<std::string> & seen,302 std::unordered_set<std::string> & elSeen, ArgPackStats& pstats,303 std:: list<DeclarationWithType*>& decls ) {302 void analyze( Stats& stats, std::unordered_set<std::string> & seen, 303 std::unordered_set<std::string> & elSeen, ArgPackStats & pstats, 304 std::vector<DeclarationWithType*> & decls ) { 304 305 std::unordered_set<std::string> types; 305 306 unsigned n = 0; ///< number of args/returns … … 345 346 std::unordered_set<std::string> seen; 346 347 std::unordered_set<std::string> elSeen; 347 analyze( stats, seen, elSeen, params , fnTy->get_parameters());348 analyze( stats, seen, elSeen, returns, fnTy-> get_returnVals());348 analyze( stats, seen, elSeen, params , fnTy->parameters ); 349 analyze( stats, seen, elSeen, returns, fnTy->returnVals ); 349 350 } 350 351 -
src/CodeTools/ResolvProtoDump.cc
r43e0949 r2f42718 102 102 /// builds space-separated list of types 103 103 template<typename V> 104 static void build( V& visitor, const std:: list< Type* >& tys, std::stringstream& ss,104 static void build( V& visitor, const std::vector< Type* >& tys, std::stringstream& ss, 105 105 septype mode = separated ) { 106 106 if ( tys.empty() ) return; … … 121 121 /// builds list of types wrapped as tuple type 122 122 template<typename V> 123 static void buildAsTuple( V& visitor, const std:: list< Type* >& tys,123 static void buildAsTuple( V& visitor, const std::vector< Type * > & tys, 124 124 std::stringstream& ss ) { 125 125 switch ( tys.size() ) { … … 135 135 136 136 /// gets types from DWT list 137 static std:: list< Type* > from_decls( const std::list< DeclarationWithType* >& decls ) {138 std:: list< Type* > tys;137 static std::vector< Type * > from_decls( const std::vector< DeclarationWithType * > & decls ) { 138 std::vector< Type * > tys; 139 139 for ( auto decl : decls ) { tys.emplace_back( decl->get_type() ); } 140 140 return tys; … … 142 142 143 143 /// gets types from TypeExpr list 144 static std:: list< Type* > from_exprs( const std::list< Expression* >& exprs ) {145 std:: list< Type* > tys;144 static std::vector< Type* > from_exprs( const std::list< Expression* >& exprs ) { 145 std::vector< Type* > tys; 146 146 for ( auto expr : exprs ) { 147 147 if ( TypeExpr* tyExpr = dynamic_cast<TypeExpr*>(expr) ) { … … 587 587 588 588 /// Adds all named declarations in a list to the local scope 589 void addAll( const std:: list<DeclarationWithType*>& decls ) {589 void addAll( const std::vector<DeclarationWithType*>& decls ) { 590 590 for ( auto decl : decls ) { 591 591 // skip anonymous decls … … 644 644 // add body if available 645 645 if ( decl->statements ) { 646 std::list<Type*>rtns = from_decls( decl->type->returnVals );646 auto rtns = from_decls( decl->type->returnVals ); 647 647 Type* rtn = nullptr; 648 648 if ( rtns.size() == 1 ) { -
src/Common/utility.h
r43e0949 r2f42718 497 497 } 498 498 499 // ----------------------------------------------------------------------------- 500 /// Simple ranged-base standard algorithms 501 namespace std { 502 template< typename range, typename out > 503 static inline auto move( range & r, out o ) -> decltype(std::move( std::begin(r), std::end(r), o )) { 504 return std::move( std::begin(r), std::end(r), o ); 505 } 506 507 template< typename range, typename out > 508 static inline auto copy( range & r, out o ) -> decltype(std::copy( std::begin(r), std::end(r), o )) { 509 return std::copy( std::begin(r), std::end(r), o ); 510 } 511 } 512 499 513 // Local Variables: // 500 514 // tab-width: 4 // -
src/Concurrency/Keywords.cc
r43e0949 r2f42718 337 337 ); 338 338 339 get_type-> get_parameters().push_back( this_decl->clone() );340 get_type-> get_returnVals().push_back(339 get_type->parameters.push_back( this_decl->clone() ); 340 get_type->returnVals.push_back( 341 341 new ObjectDecl( 342 342 "ret", … … 371 371 FunctionType * main_type = new FunctionType( noQualifiers, false ); 372 372 373 main_type-> get_parameters().push_back( this_decl->clone() );373 main_type->parameters.push_back( this_decl->clone() ); 374 374 375 375 main_decl = new FunctionDecl( … … 405 405 ); 406 406 407 decl-> get_members().push_back( field );407 decl->members.push_back( field ); 408 408 409 409 return field; … … 418 418 field, 419 419 new CastExpr( 420 new VariableExpr( func->get_functionType()-> get_parameters().front() ),421 func->get_functionType()-> get_parameters().front()->get_type()->stripReferences()->clone()420 new VariableExpr( func->get_functionType()->parameters.front() ), 421 func->get_functionType()->parameters.front()->get_type()->stripReferences()->clone() 422 422 ) 423 423 ) … … 449 449 // If this is the destructor for a monitor it must be mutex 450 450 if(isDtor) { 451 Type* ty = decl->get_functionType()-> get_parameters().front()->get_type();451 Type* ty = decl->get_functionType()->parameters.front()->get_type(); 452 452 453 453 // If it's a copy, it's not a mutex … … 483 483 484 484 // Check if we need to instrument the body 485 CompoundStmt* body = decl-> get_statements();485 CompoundStmt* body = decl->statements; 486 486 if( ! body ) return; 487 487 … … 519 519 520 520 bool once = true; 521 for( auto arg : decl->get_functionType()-> get_parameters()) {521 for( auto arg : decl->get_functionType()->parameters) { 522 522 //Find mutex arguments 523 523 Type* ty = arg->get_type(); … … 681 681 } 682 682 683 DeclarationWithType * param = decl->get_functionType()-> get_parameters().front();683 DeclarationWithType * param = decl->get_functionType()->parameters.front(); 684 684 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 685 685 if( type && type->get_baseStruct()->is_thread() ) { -
src/ControlStruct/ExceptTranslate.cc
r43e0949 r2f42718 187 187 unused_index_obj->attributes.push_back( new Attribute( "unused" ) ); 188 188 189 catch_func_t. get_parameters().push_back( index_obj.clone() );190 catch_func_t. get_parameters().push_back( exception_obj.clone() );191 match_func_t. get_returnVals().push_back( unused_index_obj );192 match_func_t. get_parameters().push_back( exception_obj.clone() );193 handle_func_t. get_returnVals().push_back( bool_obj.clone() );194 handle_func_t. get_parameters().push_back( exception_obj.clone() );195 finally_func_t. get_parameters().push_back( voidptr_obj.clone() );189 catch_func_t.parameters.push_back( index_obj.clone() ); 190 catch_func_t.parameters.push_back( exception_obj.clone() ); 191 match_func_t.returnVals.push_back( unused_index_obj ); 192 match_func_t.parameters.push_back( exception_obj.clone() ); 193 handle_func_t.returnVals.push_back( bool_obj.clone() ); 194 handle_func_t.parameters.push_back( exception_obj.clone() ); 195 finally_func_t.parameters.push_back( voidptr_obj.clone() ); 196 196 } 197 197 … … 275 275 276 276 FunctionType *func_type = catch_func_t.clone(); 277 DeclarationWithType * index_obj = func_type->get_parameters().front();278 DeclarationWithType * except_obj = func_type-> get_parameters().back();277 DeclarationWithType * index_obj = func_type->parameters.front(); 278 DeclarationWithType * except_obj = func_type->parameters.back(); 279 279 280 280 // Index 1..{number of handlers} … … 397 397 398 398 FunctionType * func_type = match_func_t.clone(); 399 DeclarationWithType * except_obj = func_type-> get_parameters().back();399 DeclarationWithType * except_obj = func_type->parameters.back(); 400 400 401 401 // Index 1..{number of handlers} … … 451 451 452 452 FunctionType * func_type = handle_func_t.clone(); 453 DeclarationWithType * except_obj = func_type-> get_parameters().back();453 DeclarationWithType * except_obj = func_type->parameters.back(); 454 454 455 455 CatchList::iterator it; -
src/GenPoly/Box.cc
r43e0949 r2f42718 286 286 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); 287 287 std::string paramName = mangleType( ¶mType ); 288 layoutFnType-> get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );289 layoutFnType-> get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );288 layoutFnType->parameters.push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 289 layoutFnType->parameters.push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 290 290 } 291 291 } … … 367 367 368 368 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 369 layoutFnType-> get_parameters().push_back( sizeParam );369 layoutFnType->parameters.push_back( sizeParam ); 370 370 ObjectDecl *alignParam = new ObjectDecl( alignofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 371 layoutFnType-> get_parameters().push_back( alignParam );371 layoutFnType->parameters.push_back( alignParam ); 372 372 ObjectDecl *offsetParam = new ObjectDecl( offsetofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 373 layoutFnType-> get_parameters().push_back( offsetParam );373 layoutFnType->parameters.push_back( offsetParam ); 374 374 addOtypeParams( layoutFnType, otypeParams ); 375 375 … … 428 428 429 429 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 430 layoutFnType-> get_parameters().push_back( sizeParam );430 layoutFnType->parameters.push_back( sizeParam ); 431 431 ObjectDecl *alignParam = new ObjectDecl( alignofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 432 layoutFnType-> get_parameters().push_back( alignParam );432 layoutFnType->parameters.push_back( alignParam ); 433 433 addOtypeParams( layoutFnType, otypeParams ); 434 434 … … 468 468 // to take those polymorphic types as pointers. Therefore, there can be two different functions 469 469 // with the same mangled name, so we need to further mangle the names. 470 for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval) {471 if ( isPolyType( (*retval)->get_type(), tyVars ) ) {470 for ( auto retval : function->returnVals ) { 471 if ( isPolyType( retval->get_type(), tyVars ) ) { 472 472 name << "P"; 473 473 } else { … … 476 476 } 477 477 name << "_"; 478 std::list< DeclarationWithType *> ¶mList = function->get_parameters();479 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {480 if ( isPolyType( (*arg)->get_type(), tyVars ) ) {478 auto & paramList = function->parameters; 479 for ( auto arg : paramList ) { 480 if ( isPolyType( arg->get_type(), tyVars ) ) { 481 481 name << "P"; 482 482 } else { … … 518 518 makeTyVarMap( functionType, scopeTyVars ); 519 519 520 std::list< DeclarationWithType *> ¶mList = functionType->parameters;521 std:: list< FunctionType *> functions;522 for ( Type::ForallList::iterator tyVar = functionType->forall.begin(); tyVar != functionType->forall.end(); ++tyVar) {523 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert) {524 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );520 auto & paramList = functionType->parameters; 521 std::vector< FunctionType *> functions; 522 for ( auto tyVar : functionType->forall ) { 523 for ( auto assert : tyVar->assertions ) { 524 findFunction( assert->get_type(), functions, scopeTyVars, needsAdapter ); 525 525 } // for 526 526 } // for 527 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {528 findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );527 for ( auto arg : paramList ) { 528 findFunction( arg->get_type(), functions, scopeTyVars, needsAdapter ); 529 529 } // for 530 530 531 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {532 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );531 for ( auto funType : functions ) { 532 std::string mangleName = mangleAdapterName( funType, scopeTyVars ); 533 533 if ( adapters.find( mangleName ) == adapters.end() ) { 534 534 std::string adapterName = makeAdapterName( mangleName ); 535 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), nullptr ) ) );535 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) ); 536 536 } // if 537 537 } // for … … 612 612 assert( funcType ); 613 613 614 std:: list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();614 std::vector< DeclarationWithType* >::const_iterator fnParm = funcType->parameters.begin(); 615 615 std::list< Expression* >::const_iterator fnArg = arg; 616 616 std::set< std::string > seenTypes; ///< names for generic types we've seen … … 624 624 625 625 // add type information args for presently unseen types in parameter list 626 for ( ; fnParm != funcType-> get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {626 for ( ; fnParm != funcType->parameters.end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) { 627 627 if ( ! (*fnArg)->get_result() ) continue; 628 628 Type * argType = (*fnArg)->get_result(); … … 708 708 // if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) { 709 709 if ( isDynRet( function, tyVars ) ) { 710 ret = addRetParam( appExpr, function-> get_returnVals().front()->get_type(), arg );710 ret = addRetParam( appExpr, function->returnVals.front()->get_type(), arg ); 711 711 } // if 712 712 std::string mangleName = mangleAdapterName( function, tyVars ); … … 786 786 } 787 787 788 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 789 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->parameters.end(); ++param, ++arg ) { 790 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( *param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 791 addCast( *arg, (*param)->get_type(), exprTyVars ); 792 boxParam( (*param)->get_type(), *arg, exprTyVars ); 788 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator & arg, const TyVarMap &exprTyVars ) { 789 for ( auto param : function->parameters ) { 790 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 791 addCast( *arg, param->get_type(), exprTyVars ); 792 boxParam( param->get_type(), *arg, exprTyVars ); 793 ++arg; 793 794 } // for 794 795 } … … 796 797 void Pass1::addInferredParams( ApplicationExpr *appExpr, FunctionType *functionType, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 797 798 std::list< Expression *>::iterator cur = arg; 798 for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar) {799 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert) {800 InferredParams::const_iterator inferParam = appExpr->inferParams.find( (*assert)->get_uniqueId() );801 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( *assert ).c_str(), toString( appExpr ).c_str() );799 for ( auto tyVar : functionType->forall ) { 800 for ( auto assert : tyVar->assertions ) { 801 InferredParams::const_iterator inferParam = appExpr->inferParams.find( assert->get_uniqueId() ); 802 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( assert ).c_str(), toString( appExpr ).c_str() ); 802 803 Expression *newExpr = inferParam->second.expr->clone(); 803 addCast( newExpr, (*assert)->get_type(), tyVars );804 boxParam( (*assert)->get_type(), newExpr, tyVars );804 addCast( newExpr, assert->get_type(), tyVars ); 805 boxParam( assert->get_type(), newExpr, tyVars ); 805 806 appExpr->get_args().insert( cur, newExpr ); 806 807 } // for … … 813 814 // make a new parameter that is a pointer to the type of the old return value 814 815 retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) ); 815 funcType-> get_parameters().push_front(retParm );816 funcType->parameters.insert( funcType->parameters.begin(), retParm ); 816 817 817 818 // we don't need the return value any more 818 funcType-> get_returnVals().clear();819 funcType->returnVals.clear(); 819 820 } 820 821 … … 825 826 makeRetParm( adapter ); 826 827 } // if 827 adapter-> get_parameters().push_front(new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) );828 adapter->parameters.insert( adapter->parameters.begin(), new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) ); 828 829 return adapter; 829 830 } … … 844 845 } 845 846 846 void addAdapterParams( ApplicationExpr *adapteeApp, std:: list< DeclarationWithType *>::iterator arg, std::list< DeclarationWithType *>::iterator param, std::list< DeclarationWithType *>::iterator paramEnd, std::list< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) {847 void addAdapterParams( ApplicationExpr *adapteeApp, std::vector< DeclarationWithType *>::iterator arg, std::vector< DeclarationWithType *>::iterator param, std::vector< DeclarationWithType *>::iterator paramEnd, std::vector< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) { 847 848 UniqueName paramNamer( "_p" ); 848 849 for ( ; param != paramEnd; ++param, ++arg, ++realParam ) { … … 858 859 FunctionType *adapterType = makeAdapterType( adaptee, tyVars ); 859 860 adapterType = ScrubTyVars::scrub( adapterType, tyVars ); 860 DeclarationWithType *adapteeDecl = adapterType-> get_parameters().front();861 DeclarationWithType *adapteeDecl = adapterType->parameters.front(); 861 862 adapteeDecl->set_name( "_adaptee" ); 862 863 // do not carry over attributes to real type parameters/return values … … 877 878 for ( ; tyParam != adapterType->get_forall().end(); ++tyArg, ++tyParam, ++realTyParam ) { 878 879 assert( tyArg != realType->get_forall().end() ); 879 std:: list< DeclarationWithType *>::iterator assertArg = (*tyArg)->get_assertions().begin();880 std:: list< DeclarationWithType *>::iterator assertParam = (*tyParam)->get_assertions().begin();881 std:: list< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->get_assertions().begin();882 for ( ; assertParam != (*tyParam)-> get_assertions().end(); ++assertArg, ++assertParam, ++realAssertParam ) {883 assert( assertArg != (*tyArg)-> get_assertions().end() );880 std::vector< DeclarationWithType *>::iterator assertArg = (*tyArg)->assertions.begin(); 881 std::vector< DeclarationWithType *>::iterator assertParam = (*tyParam)->assertions.begin(); 882 std::vector< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->assertions.begin(); 883 for ( ; assertParam != (*tyParam)->assertions.end(); ++assertArg, ++assertParam, ++realAssertParam ) { 884 assert( assertArg != (*tyArg)->assertions.end() ); 884 885 adapteeApp->get_args().push_back( makeAdapterArg( *assertParam, *assertArg, *realAssertParam, tyVars ) ); 885 886 } // for 886 887 } // for 887 888 888 std:: list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();889 std:: list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();890 std:: list< DeclarationWithType *>::iterator realParam = adaptee->get_parameters().begin();889 std::vector< DeclarationWithType *>::iterator arg = realType->parameters.begin(); 890 std::vector< DeclarationWithType *>::iterator param = adapterType->parameters.begin(); 891 std::vector< DeclarationWithType *>::iterator realParam = adaptee->parameters.begin(); 891 892 param++; // skip adaptee parameter in the adapter type 892 if ( realType-> get_returnVals().empty() ) {893 if ( realType->returnVals.empty() ) { 893 894 // void return 894 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );895 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 895 896 bodyStmt = new ExprStmt( adapteeApp ); 896 } else if ( isDynType( adaptee-> get_returnVals().front()->get_type(), tyVars ) ) {897 } else if ( isDynType( adaptee->returnVals.front()->get_type(), tyVars ) ) { 897 898 // return type T 898 899 if ( (*param)->get_name() == "" ) { … … 901 902 } // if 902 903 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 903 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType-> get_returnVals().front()->get_type()->clone() ) ) );904 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->returnVals.front()->get_type()->clone() ) ) ); 904 905 assign->get_args().push_back( deref ); 905 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );906 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 906 907 assign->get_args().push_back( adapteeApp ); 907 908 bodyStmt = new ExprStmt( assign ); 908 909 } else { 909 910 // adapter for a function that returns a monomorphic value 910 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );911 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 911 912 bodyStmt = new ReturnStmt( adapteeApp ); 912 913 } // if … … 919 920 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) { 920 921 // collect a list of function types passed as parameters or implicit parameters (assertions) 921 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters();922 std:: list< FunctionType *> functions;923 for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar) {924 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert) {925 findFunction( (*assert)->get_type(), functions, exprTyVars, needsAdapter );922 auto & paramList = functionType->parameters; 923 std::vector< FunctionType *> functions; 924 for ( auto tyVar : functionType->forall ) { 925 for ( auto assert : tyVar->assertions ) { 926 findFunction( assert->get_type(), functions, exprTyVars, needsAdapter ); 926 927 } // for 927 928 } // for 928 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {929 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );929 for ( auto arg : paramList ) { 930 findFunction( arg->get_type(), functions, exprTyVars, needsAdapter ); 930 931 } // for 931 932 … … 934 935 std::set< std::string > adaptersDone; 935 936 936 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {937 FunctionType * originalFunction = (*funType)->clone();938 FunctionType * realFunction = (*funType)->clone();937 for ( auto funType : functions ) { 938 FunctionType * originalFunction = funType->clone(); 939 FunctionType * realFunction = funType->clone(); 939 940 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 940 941 … … 954 955 if ( adapter == adapters.end() ) { 955 956 // adapter has not been created yet in the current scope, so define it 956 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );957 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars ); 957 958 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 958 959 adapter = answer.first; … … 1255 1256 1256 1257 void Pass2::addAdapters( FunctionType *functionType ) { 1257 std::list< DeclarationWithType *> ¶mList = functionType->parameters;1258 std:: list< FunctionType *> functions;1259 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {1260 Type *orig = (*arg)->get_type();1258 auto & paramList = functionType->parameters; 1259 std::vector< FunctionType *> functions; 1260 for ( auto arg : paramList ) { 1261 Type *orig = arg->get_type(); 1261 1262 findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter ); 1262 (*arg)->set_type( orig );1263 arg->set_type( orig ); 1263 1264 } 1264 1265 std::set< std::string > adaptersDone; 1265 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {1266 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );1266 for ( auto funType : functions ) { 1267 std::string mangleName = mangleAdapterName( funType, scopeTyVars ); 1267 1268 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 1268 1269 std::string adapterName = makeAdapterName( mangleName ); 1269 1270 // adapter may not be used in body, pass along with unused attribute. 1270 paramList. push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );1271 paramList.insert( paramList.begin(), new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) ); 1271 1272 adaptersDone.insert( adaptersDone.begin(), mangleName ); 1272 1273 } 1273 1274 } 1274 // deleteAll( functions );1275 1275 } 1276 1276 … … 1324 1324 1325 1325 void Pass2::premutate( FunctionType *funcType ) { 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1326 1345 GuardScope( scopeTyVars ); 1327 1346 makeTyVarMap( funcType, scopeTyVars ); … … 1329 1348 // move polymorphic return type to parameter list 1330 1349 if ( isDynRet( funcType ) ) { 1331 ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType-> get_returnVals().front() );1350 ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType->returnVals.front() ); 1332 1351 ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) ); 1333 funcType-> get_parameters().push_front(ret );1334 funcType-> get_returnVals().pop_front();1352 funcType->parameters.insert( funcType->parameters.begin(), ret ); 1353 funcType->returnVals.erase(funcType->returnVals.begin()); 1335 1354 ret->set_init( nullptr ); // xxx - memory leak? 1336 1355 } 1337 1356 1338 // add size/align and assertions for type parameters to parameter list 1339 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1340 std::list< DeclarationWithType *> inferredParams; 1357 // create a list of parameters after adding new ones 1358 std::vector<DeclarationWithType *> newParams; 1359 std::vector<DeclarationWithType *> inferredParams; 1360 1361 // reserve some memory for these vectors 1362 // Number of elements needed should be somewhat linear with the number of parameters / forall 1363 // "somewhat linear" == 2X 1364 newParams.reserve(funcType->parameters.size() * 2 + funcType->forall.size() * 2); 1365 inferredParams.reserve(funcType->forall.size() * 2); 1366 1341 1367 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1342 1368 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, … … 1344 1370 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1345 1371 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1346 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1347 ObjectDecl *sizeParm, *alignParm; 1372 1373 // We do this several time, create a functor for it 1374 auto pushObj = [&newObj, &newParams]( const std::string & name ) { 1375 auto parm = newObj.clone(); 1376 parm->set_name( name ); 1377 newParams.push_back( parm ); 1378 }; 1379 1380 // add size/align and assertions for type parameters to parameter list 1381 for ( auto tyParm : funcType->forall ) { 1348 1382 // add all size and alignment parameters to parameter list 1349 if ( (*tyParm)->isComplete() ) {1350 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );1383 if ( tyParm->isComplete() ) { 1384 TypeInstType parmType( Type::Qualifiers(), tyParm->get_name(), tyParm ); 1351 1385 std::string parmName = mangleType( &parmType ); 1352 1353 sizeParm = newObj.clone(); 1354 sizeParm->set_name( sizeofName( parmName ) ); 1355 last = funcType->get_parameters().insert( last, sizeParm ); 1356 ++last; 1357 1358 alignParm = newObj.clone(); 1359 alignParm->set_name( alignofName( parmName ) ); 1360 last = funcType->get_parameters().insert( last, alignParm ); 1361 ++last; 1386 pushObj( sizeofName( parmName ) ); 1387 pushObj( alignofName( parmName ) ); 1362 1388 } 1363 1389 // move all assertions into parameter list 1364 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1390 // move all assertions into parameter list 1391 for ( auto assert : tyParm->assertions ) { 1365 1392 // assertion parameters may not be used in body, pass along with unused attribute. 1366 (*assert)->get_attributes().push_back( new Attribute( "unused" ) );1367 inferredParams.push_back( *assert );1368 } 1369 (*tyParm)->get_assertions().clear();1393 assert->attributes.push_back( new Attribute( "unused" ) ); 1394 inferredParams.push_back( assert ); 1395 } 1396 tyParm->assertions.clear(); 1370 1397 } 1371 1398 1372 1399 // add size/align for generic parameter types to parameter list 1373 1400 std::set< std::string > seenTypes; // sizeofName for generic types we've seen 1374 for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) { 1375 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars ); 1376 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1401 for ( DeclarationWithType * fnParm : funcType->parameters ) 1402 { 1403 Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars ); 1404 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) 1405 { 1377 1406 std::string typeName = mangleType( polyType ); 1378 1407 if ( seenTypes.count( typeName ) ) continue; 1379 1408 1380 ObjectDecl *sizeParm, *alignParm, *offsetParm; 1381 sizeParm = newObj.clone(); 1382 sizeParm->set_name( sizeofName( typeName ) ); 1383 last = funcType->get_parameters().insert( last, sizeParm ); 1384 ++last; 1385 1386 alignParm = newObj.clone(); 1387 alignParm->set_name( alignofName( typeName ) ); 1388 last = funcType->get_parameters().insert( last, alignParm ); 1389 ++last; 1409 pushObj( sizeofName ( typeName ) ); 1410 pushObj( alignofName( typeName ) ); 1390 1411 1391 1412 if ( StructInstType *polyBaseStruct = dynamic_cast< StructInstType* >( polyType ) ) { 1392 1413 // NOTE zero-length arrays are illegal in C, so empty structs have no offset array 1393 1414 if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) { 1394 offsetParm = newPtr.clone(); 1395 offsetParm->set_name( offsetofName( typeName ) ); 1396 last = funcType->get_parameters().insert( last, offsetParm ); 1397 ++last; 1415 auto offset = newPtr.clone(); 1416 offset->set_name( offsetofName( typeName ) ); 1417 newParams.push_back( offset ); 1398 1418 } 1399 1419 } … … 1403 1423 1404 1424 // splice assertion parameters into parameter list 1405 funcType->get_parameters().splice( last, inferredParams ); 1425 std::copy( inferredParams , std::back_inserter(newParams) ); 1426 std::copy( funcType->parameters, std::back_inserter(newParams) ); 1427 1428 funcType->parameters.swap(newParams); 1429 1406 1430 addAdapters( funcType ); 1407 1431 } … … 1470 1494 1471 1495 // make sure that any type information passed into the function is accounted for 1472 for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm) {1496 for ( auto fnParm : funcType->parameters ) { 1473 1497 // condition here duplicates that in Pass2::mutate( FunctionType* ) 1474 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );1498 Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars ); 1475 1499 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1476 1500 knownLayouts.insert( mangleType( polyType ) ); -
src/GenPoly/FindFunction.cc
r43e0949 r2f42718 29 29 class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting { 30 30 public: 31 FindFunction( std:: list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );31 FindFunction( std::vector< FunctionType* > & functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 32 32 33 33 void premutate( FunctionType * functionType ); … … 37 37 void handleForall( const Type::ForallList &forall ); 38 38 39 std:: list< FunctionType* > &functions;39 std::vector< FunctionType* > &functions; 40 40 TyVarMap tyVars; 41 41 bool replaceMode; … … 43 43 }; 44 44 45 void findFunction( Type *type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {45 void findFunction( Type *type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 46 46 PassVisitor<FindFunction> finder( functions, tyVars, false, predicate ); 47 47 type->acceptMutator( finder ); 48 48 } 49 49 50 void findAndReplaceFunction( Type *&type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {50 void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 51 51 PassVisitor<FindFunction> finder( functions, tyVars, true, predicate ); 52 52 type = type->acceptMutator( finder ); 53 53 } 54 54 55 FindFunction::FindFunction( std:: list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )55 FindFunction::FindFunction( std::vector< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ) 56 56 : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) { 57 57 } … … 70 70 GuardScope( tyVars ); 71 71 handleForall( functionType->get_forall() ); 72 mutateAll( functionType-> get_returnVals(), *visitor );72 mutateAll( functionType->returnVals, *visitor ); 73 73 } 74 74 -
src/GenPoly/FindFunction.h
r43e0949 r2f42718 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FindFunction.h -- 7 // FindFunction.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 27 27 28 28 /// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions` 29 void findFunction( Type *type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );29 void findFunction( Type *type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 30 30 /// like `findFunction`, but also replaces the function type with void ()(void) 31 void findAndReplaceFunction( Type *&type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );31 void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 32 32 } // namespace GenPoly 33 33 -
src/GenPoly/GenPoly.cc
r43e0949 r2f42718 144 144 145 145 ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &forallTypes ) { 146 if ( function-> get_returnVals().empty() ) return 0;147 148 return (ReferenceToType*)isDynType( function-> get_returnVals().front()->get_type(), forallTypes );146 if ( function->returnVals.empty() ) return 0; 147 148 return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes ); 149 149 } 150 150 151 151 ReferenceToType *isDynRet( FunctionType *function ) { 152 if ( function-> get_returnVals().empty() ) return 0;152 if ( function->returnVals.empty() ) return 0; 153 153 154 154 TyVarMap forallTypes( TypeDecl::Data{} ); 155 155 makeTyVarMap( function, forallTypes ); 156 return (ReferenceToType*)isDynType( function-> get_returnVals().front()->get_type(), forallTypes );156 return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes ); 157 157 } 158 158 159 159 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 160 // if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {161 // return true;162 // } // if163 160 if ( isDynRet( adaptee, tyVars ) ) return true; 164 161 165 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) { 166 // if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) { 167 if ( isDynType( (*innerArg)->get_type(), tyVars ) ) { 162 for ( auto innerArg : adaptee->parameters ) { 163 if ( isDynType( innerArg->get_type(), tyVars ) ) { 168 164 return true; 169 165 } // if … … 315 311 /// Flattens a declaration list 316 312 template<typename Output> 317 void flattenList( list< DeclarationWithType* > src, Output out ) {313 void flattenList( vector< DeclarationWithType* > src, Output out ) { 318 314 for ( DeclarationWithType* decl : src ) { 319 315 ResolvExpr::flatten( decl->get_type(), out ); … … 323 319 /// Flattens a list of types 324 320 template<typename Output> 325 void flattenList( list< Type* > src, Output out ) {321 void flattenList( vector< Type* > src, Output out ) { 326 322 for ( Type* ty : src ) { 327 323 ResolvExpr::flatten( ty, out ); … … 395 391 396 392 vector<Type*> aparams, bparams; 397 flattenList( af-> get_parameters(), back_inserter( aparams ) );398 flattenList( bf-> get_parameters(), back_inserter( bparams ) );393 flattenList( af->parameters, back_inserter( aparams ) ); 394 flattenList( bf->parameters, back_inserter( bparams ) ); 399 395 if ( aparams.size() != bparams.size() ) return false; 400 396 401 397 vector<Type*> areturns, breturns; 402 flattenList( af-> get_returnVals(), back_inserter( areturns ) );403 flattenList( bf-> get_returnVals(), back_inserter( breturns ) );398 flattenList( af->returnVals, back_inserter( areturns ) ); 399 flattenList( bf->returnVals, back_inserter( breturns ) ); 404 400 if ( areturns.size() != breturns.size() ) return false; 405 401 … … 429 425 430 426 vector<Type*> atypes, btypes; 431 flattenList( at-> get_types(), back_inserter( atypes ) );432 flattenList( bt-> get_types(), back_inserter( btypes ) );427 flattenList( at->types, back_inserter( atypes ) ); 428 flattenList( bt->types, back_inserter( btypes ) ); 433 429 if ( atypes.size() != btypes.size() ) return false; 434 430 -
src/GenPoly/Specialize.cc
r43e0949 r2f42718 91 91 if ( tuple1 && tuple2 ) { 92 92 if ( tuple1->size() != tuple2->size() ) return false; 93 for ( auto types : group_iterate( tuple1-> get_types(), tuple2->get_types()) ) {93 for ( auto types : group_iterate( tuple1->types, tuple2->types ) ) { 94 94 if ( ! matchingTupleStructure( std::get<0>( types ), std::get<1>( types ) ) ) return false; 95 95 } … … 115 115 size_t functionParameterSize( FunctionType * ftype ) { 116 116 size_t sz = 0; 117 for ( DeclarationWithType * p : ftype-> get_parameters()) {117 for ( DeclarationWithType * p : ftype->parameters ) { 118 118 sz += singleParameterSize( p->get_type() ); 119 119 } … … 227 227 } 228 228 std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII 229 std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();230 std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();229 auto actualBegin = actualType->parameters.begin(); 230 auto actualEnd = actualType->parameters.end(); 231 231 232 232 std::list< Expression * > args; 233 for ( DeclarationWithType* param : thunkFunc->get_functionType()-> get_parameters()) {233 for ( DeclarationWithType* param : thunkFunc->get_functionType()->parameters ) { 234 234 // name each thunk parameter and explode it - these are then threaded back into the actual function call. 235 235 param->set_name( paramNamer.newName() ); … … 281 281 FunctionType *function = getFunctionType( appExpr->function->result ); 282 282 assert( function ); 283 std:: list< DeclarationWithType* >::iterator formal;283 std::vector< DeclarationWithType* >::iterator formal; 284 284 std::list< Expression* >::iterator actual; 285 for ( formal = function-> get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {285 for ( formal = function->parameters.begin(), actual = appExpr->get_args().begin(); formal != function->parameters.end() && actual != appExpr->get_args().end(); ++formal, ++actual ) { 286 286 *actual = doSpecialization( (*formal)->get_type(), *actual, &appExpr->inferParams ); 287 287 } -
src/InitTweak/FixInit.cc
r43e0949 r2f42718 1042 1042 if ( checkWarnings( function ) ) { 1043 1043 FunctionType * type = function->get_functionType(); 1044 assert( ! type-> get_parameters().empty() );1045 thisParam = strict_dynamic_cast< ObjectDecl * >( type-> get_parameters().front() );1044 assert( ! type->parameters.empty() ); 1045 thisParam = strict_dynamic_cast< ObjectDecl * >( type->parameters.front() ); 1046 1046 Type * thisType = getPointerBase( thisParam->get_type() ); 1047 1047 StructInstType * structType = dynamic_cast< StructInstType * >( thisType ); … … 1099 1099 if ( isCopyConstructor( function ) ) { 1100 1100 // if copy ctor, need to pass second-param-of-this-function.field 1101 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();1101 auto & params = function->get_functionType()->parameters; 1102 1102 assert( params.size() == 2 ); 1103 1103 arg2 = new MemberExpr( field, new VariableExpr( params.back() ) ); -
src/InitTweak/GenInit.cc
r43e0949 r2f42718 127 127 128 128 void ReturnFixer::premutate( ReturnStmt *returnStmt ) { 129 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();129 auto & returnVals = ftype->returnVals; 130 130 assert( returnVals.size() == 0 || returnVals.size() == 1 ); 131 131 // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address … … 242 242 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 243 243 if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && CodeGen::isCtorDtor( dwt->get_name() ) ) { 244 std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters();244 auto & params = GenPoly::getFunctionType( dwt->get_type() )->parameters; 245 245 assert( ! params.empty() ); 246 246 Type * type = InitTweak::getPointerBase( params.front()->get_type() ); … … 335 335 // go through assertions and recursively add seen ctor/dtors 336 336 for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) { 337 for ( DeclarationWithType *& assertion : tyDecl-> get_assertions()) {337 for ( DeclarationWithType *& assertion : tyDecl->assertions ) { 338 338 managedTypes.handleDWT( assertion ); 339 339 } -
src/InitTweak/InitTweak.cc
r43e0949 r2f42718 410 410 FunctionType *funcType = GenPoly::getFunctionType( appExpr->function->result ); 411 411 assert( funcType ); 412 return funcType-> get_parameters().size() == 1;412 return funcType->parameters.size() == 1; 413 413 } 414 414 return false; … … 616 616 if ( ftype->parameters.size() != 2 ) return nullptr; 617 617 618 Type * t1 = getPointerBase( ftype-> get_parameters().front()->get_type() );618 Type * t1 = getPointerBase( ftype->parameters.front()->get_type() ); 619 619 Type * t2 = ftype->parameters.back()->get_type(); 620 620 assert( t1 ); -
src/MakeLibCfa.cc
r43e0949 r2f42718 103 103 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( funcDecl->get_name() ) ); 104 104 UniqueName paramNamer( "_p" ); 105 std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin();106 assert( param != funcDecl->get_functionType()->get_parameters().end() );105 auto & params = funcDecl->get_functionType()->parameters; 106 assert( !params.empty() ); 107 107 108 for ( ; param != funcDecl->get_functionType()->get_parameters().end(); ++param) {108 for ( auto param : params ) { 109 109 // name each unnamed parameter 110 if ( (*param)->get_name() == "" ) {111 (*param)->set_name( paramNamer.newName() );112 (*param)->set_linkage( LinkageSpec::C );110 if ( param->get_name() == "" ) { 111 param->set_name( paramNamer.newName() ); 112 param->set_linkage( LinkageSpec::C ); 113 113 } 114 114 // add parameter to the expression 115 newExpr->get_args().push_back( new VariableExpr( *param ) );115 newExpr->get_args().push_back( new VariableExpr( param ) ); 116 116 } // for 117 117 -
src/Parser/DeclarationNode.cc
r43e0949 r2f42718 1065 1065 } // buildList 1066 1066 1067 void buildTypeList( const DeclarationNode * firstNode, std:: list< Type * > & outputList ) {1067 void buildTypeList( const DeclarationNode * firstNode, std::vector< Type * > & outputList ) { 1068 1068 SemanticErrorException errors; 1069 std::back_insert_iterator< std:: list< Type * > > out( outputList );1069 std::back_insert_iterator< std::vector< Type * > > out( outputList ); 1070 1070 const DeclarationNode * cur = firstNode; 1071 1071 … … 1097 1097 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1098 1098 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == Otype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1099 buildList( variable.assertions, ret-> get_assertions());1099 buildList( variable.assertions, ret->assertions ); 1100 1100 return ret; 1101 1101 } // if -
src/Parser/ParseNode.h
r43e0949 r2f42718 467 467 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ); 468 468 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ); 469 void buildTypeList( const DeclarationNode * firstNode, std:: list< Type * > & outputList );469 void buildTypeList( const DeclarationNode * firstNode, std::vector< Type * > & outputList ); 470 470 471 471 template< typename SynTreeType, typename NodeType > -
src/Parser/TypeData.cc
r43e0949 r2f42718 493 493 // add dtor: void ^?{}(T *) 494 494 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false ); 495 dtorType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );496 td-> get_assertions().push_front(new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );495 dtorType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 496 td->assertions.insert( td->assertions.begin(), new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) ); 497 497 498 498 // add copy ctor: void ?{}(T *, T) 499 499 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false ); 500 copyCtorType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );501 copyCtorType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );502 td-> get_assertions().push_front(new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );500 copyCtorType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 501 copyCtorType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 502 td->assertions.insert( td->assertions.begin(), new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) ); 503 503 504 504 // add default ctor: void ?{}(T *) 505 505 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false ); 506 ctorType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );507 td-> get_assertions().push_front(new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );506 ctorType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 507 td->assertions.insert( td->assertions.begin(), new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) ); 508 508 509 509 // add assignment operator: T * ?=?(T *, T) 510 510 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false ); 511 assignType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );512 assignType-> get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );513 assignType-> get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );514 td-> get_assertions().push_front(new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );511 assignType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 512 assignType->parameters.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 513 assignType->returnVals.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 514 td->assertions.insert( td->assertions.begin(), new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) ); 515 515 } // if 516 516 } // for … … 897 897 } // if 898 898 buildList( td->symbolic.params, ret->get_parameters() ); 899 buildList( td->symbolic.assertions, ret-> get_assertions());899 buildList( td->symbolic.assertions, ret->assertions ); 900 900 ret->base->attributes.insert( ret->base->attributes.end(), attributes.begin(), attributes.end() ); 901 901 return ret; … … 930 930 TupleType * buildTuple( const TypeData * td ) { 931 931 assert( td->kind == TypeData::Tuple ); 932 std:: list< Type * > types;932 std::vector< Type * > types; 933 933 buildTypeList( td->tuple, types ); 934 934 TupleType * ret = new TupleType( buildQualifiers( td ), types ); … … 983 983 break; 984 984 default: 985 ft-> get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, Type::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );985 ft->returnVals.push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, Type::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) ); 986 986 } // switch 987 987 } else { 988 ft-> get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );988 ft->returnVals.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 989 989 } // if 990 990 return ft; -
src/ResolvExpr/AlternativeFinder.cc
r43e0949 r2f42718 434 434 435 435 Cost convCost = Cost::zero; 436 std::list< DeclarationWithType* >& formals = function->parameters;437 std::list< DeclarationWithType* >::iterator formal= formals.begin();438 std::list< Expression* >& actuals = appExpr->args;436 auto & formals = function->parameters; 437 auto formal = formals.begin(); 438 auto & actuals = appExpr->args; 439 439 440 440 for ( Expression*& actualExpr : actuals ) { … … 493 493 /// Adds type variables to the open variable set and marks their assertions 494 494 void makeUnifiableVars( Type *type, OpenVarSet &unifiableVars, AssertionSet &needAssertions ) { 495 for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar) {496 unifiableVars[ (*tyvar)->get_name() ] = TypeDecl::Data{ *tyvar };497 for ( std::list< DeclarationWithType* >::iterator assert = (*tyvar)->assertions.begin(); assert != (*tyvar)->assertions.end(); ++assert) {498 needAssertions[ *assert ].isUsed = true;495 for ( auto tyvar : type->forall ) { 496 unifiableVars[ tyvar->get_name() ] = TypeDecl::Data{ tyvar }; 497 for ( auto assert : tyvar->assertions ) { 498 needAssertions[ assert ].isUsed = true; 499 499 } 500 500 } … … 1407 1407 // assume no polymorphism 1408 1408 // assume no implicit conversions 1409 assert( function-> get_parameters().size() == 1 );1409 assert( function->parameters.size() == 1 ); 1410 1410 PRINT( 1411 1411 std::cerr << "resolvAttr: funcDecl is "; … … 1417 1417 const SymTab::Indexer & indexer = finder.get_indexer(); 1418 1418 AltList & alternatives = finder.get_alternatives(); 1419 if ( typesCompatibleIgnoreQualifiers( argType, function-> get_parameters().front()->get_type(), indexer, env ) ) {1419 if ( typesCompatibleIgnoreQualifiers( argType, function->parameters.front()->get_type(), indexer, env ) ) { 1420 1420 Cost cost = Cost::zero; 1421 1421 Expression * newExpr = data.combine( cost ); … … 1442 1442 if ( FunctionType *function = dynamic_cast< FunctionType* >( id->get_type() ) ) { 1443 1443 // assume exactly one parameter 1444 if ( function-> get_parameters().size() == 1 ) {1444 if ( function->parameters.size() == 1 ) { 1445 1445 if ( attrExpr->get_isType() ) { 1446 1446 resolveAttr( data, function, attrExpr->get_type(), env, altFinder); -
src/ResolvExpr/ConversionCost.cc
r43e0949 r2f42718 388 388 Cost c = Cost::zero; 389 389 if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) { 390 std:: list< Type * >::const_iterator srcIt = tupleType->types.begin();391 std:: list< Type * >::const_iterator destIt = destAsTuple->types.begin();390 std::vector< Type * >::const_iterator srcIt = tupleType->types.begin(); 391 std::vector< Type * >::const_iterator destIt = destAsTuple->types.begin(); 392 392 while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) { 393 393 Cost newCost = costFunc( *srcIt++, *destIt++, indexer, env ); -
src/ResolvExpr/FindOpenVars.cc
r43e0949 r2f42718 50 50 void FindOpenVars::common_action( Type *type ) { 51 51 if ( nextIsOpen ) { 52 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i) {53 openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i)};54 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert) {55 needAssertions[ *assert ].isUsed = false;52 for ( const auto i : type->get_forall() ) { 53 openVars[ i->get_name() ] = TypeDecl::Data{ i }; 54 for ( const auto assert : i->assertions ) { 55 needAssertions[ assert ].isUsed = false; 56 56 } 57 /// cloneAll( (*i)->get_assertions(), needAssertions );58 /// needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );59 57 } 60 58 } else { 61 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i) {62 closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i)};63 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert) {64 haveAssertions[ *assert ].isUsed = false;59 for ( const auto i : type->get_forall() ) { 60 closedVars[ i->get_name() ] = TypeDecl::Data{ i }; 61 for ( const auto assert : i->assertions ) { 62 haveAssertions[ assert ].isUsed = false; 65 63 } 66 /// cloneAll( (*i)->get_assertions(), haveAssertions );67 /// haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );68 64 } // for 69 65 } // if 70 /// std::cerr << "type is ";71 /// type->print( std::cerr );72 /// std::cerr << std::endl << "need is" << std::endl;73 /// printAssertionSet( needAssertions, std::cerr );74 /// std::cerr << std::endl << "have is" << std::endl;75 /// printAssertionSet( haveAssertions, std::cerr );76 66 } 77 67 -
src/ResolvExpr/SpecCost.cc
r43e0949 r2f42718 42 42 private: 43 43 // takes minimum non-negative count over parameter/return list 44 void takeminover( int& mincount, std:: list<DeclarationWithType*>& dwts ) {44 void takeminover( int& mincount, std::vector<DeclarationWithType*> & dwts ) { 45 45 for ( DeclarationWithType* dwt : dwts ) { 46 46 count = -1; … … 61 61 visit_children = false; 62 62 } 63 63 64 64 private: 65 65 // returns minimum non-negative count + 1 over type parameters (-1 if none such) … … 80 80 visit_children = false; 81 81 } 82 82 83 83 // look for polymorphic parameters 84 84 void previsit(UnionInstType* uty) { -
src/ResolvExpr/Unify.cc
r43e0949 r2f42718 283 283 void markAssertions( AssertionSet &assertion1, AssertionSet &assertion2, Type *type ) { 284 284 for ( auto tyvar : type->get_forall() ) { 285 for ( auto assert : tyvar-> get_assertions()) {285 for ( auto assert : tyvar->assertions ) { 286 286 markAssertionSet( assertion1, assert ); 287 287 markAssertionSet( assertion2, assert ); … … 336 336 template< typename Iterator, typename Func > 337 337 std::unique_ptr<Type> combineTypes( Iterator begin, Iterator end, Func & toType ) { 338 std:: list< Type * > types;338 std::vector< Type * > types; 339 339 for ( ; begin != end; ++begin ) { 340 340 // it's guaranteed that a ttype variable will be bound to a flat tuple, so ensure that this results in a flat tuple … … 404 404 /// flattens a list of declarations, so that each tuple type has a single declaration. 405 405 /// makes use of TtypeExpander to ensure ttypes are flat as well. 406 void flattenList( std:: list< DeclarationWithType * > src, std::list< DeclarationWithType * > & dst, TypeEnvironment & env ) {406 void flattenList( std::vector< DeclarationWithType * > src, std::vector< DeclarationWithType * > & dst, TypeEnvironment & env ) { 407 407 dst.clear(); 408 408 for ( DeclarationWithType * dcl : src ) { … … 429 429 std::unique_ptr<FunctionType> flatFunc( functionType->clone() ); 430 430 std::unique_ptr<FunctionType> flatOther( otherFunction->clone() ); 431 flattenList( flatFunc ->get_parameters(), flatFunc->get_parameters(), env );432 flattenList( flatOther-> get_parameters(), flatOther->get_parameters(), env );431 flattenList( flatFunc ->parameters, flatFunc ->parameters, env ); 432 flattenList( flatOther->parameters, flatOther->parameters, env ); 433 433 434 434 // sizes don't have to match if ttypes are involved; need to be more precise wrt where the ttype is to prevent errors … … 481 481 } else if ( tupleParam ) { 482 482 // bundle other parameters into tuple to match 483 std:: list< Type * > binderTypes;483 std::vector< Type * > binderTypes; 484 484 485 485 do { … … 497 497 } else if ( otherTupleParam ) { 498 498 // bundle parameters into tuple to match other 499 std:: list< Type * > binderTypes;499 std::vector< Type * > binderTypes; 500 500 501 501 do { … … 626 626 // xxx - compute once and store in the FunctionType? 627 627 Type * extractResultType( FunctionType * function ) { 628 if ( function-> get_returnVals().size() == 0 ) {628 if ( function->returnVals.size() == 0 ) { 629 629 return new VoidType( Type::Qualifiers() ); 630 } else if ( function-> get_returnVals().size() == 1 ) {631 return function-> get_returnVals().front()->get_type()->clone();630 } else if ( function->returnVals.size() == 1 ) { 631 return function->returnVals.front()->get_type()->clone(); 632 632 } else { 633 std:: list< Type * > types;634 for ( DeclarationWithType * decl : function-> get_returnVals()) {633 std::vector< Type * > types; 634 for ( DeclarationWithType * decl : function->returnVals ) { 635 635 types.push_back( decl->get_type()->clone() ); 636 636 } // for -
src/ResolvExpr/typeops.h
r43e0949 r2f42718 73 73 74 74 // in AlternativeFinder.cc 75 Cost computeConversionCost( Type *actualType, Type *formalType, 75 Cost computeConversionCost( Type *actualType, Type *formalType, 76 76 const SymTab::Indexer &indexer, const TypeEnvironment &env ); 77 77 … … 112 112 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ); 113 113 114 template<typename Iter> 114 template<typename Iter> 115 115 bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) { 116 116 while ( begin != end ) { … … 128 128 void flatten( Type * type, OutputIterator out ) { 129 129 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) { 130 for ( Type * t : tupleType-> get_types()) {130 for ( Type * t : tupleType->types ) { 131 131 flatten( t, out ); 132 132 } -
src/SymTab/Autogen.cc
r43e0949 r2f42718 410 410 } 411 411 412 assert( ! func->get_functionType()-> get_parameters().empty() );413 ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( func->get_functionType()-> get_parameters().front() );412 assert( ! func->get_functionType()->parameters.empty() ); 413 ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->parameters.front() ); 414 414 ObjectDecl * srcParam = nullptr; 415 if ( func->get_functionType()-> get_parameters().size() == 2 ) {416 srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()-> get_parameters().back() );415 if ( func->get_functionType()->parameters.size() == 2 ) { 416 srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->parameters.back() ); 417 417 } 418 418 … … 429 429 void StructFuncGenerator::makeFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func ) { 430 430 FunctionType * ftype = func->type; 431 std::list<DeclarationWithType*>& params = ftype->parameters;431 auto & params = ftype->parameters; 432 432 assert( params.size() >= 2 ); // should not call this function for default ctor, etc. 433 433 … … 435 435 ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( params.front() ); 436 436 assert( dstParam ); 437 std::list<DeclarationWithType*>::iteratorparameter = params.begin()+1;437 auto parameter = params.begin()+1; 438 438 for ( ; member != end; ++member ) { 439 439 if ( DeclarationWithType * field = dynamic_cast<DeclarationWithType*>( *member ) ) { … … 656 656 void makeTupleFunctionBody( FunctionDecl * function ) { 657 657 FunctionType * ftype = function->get_functionType(); 658 assertf( ftype-> get_parameters().size() == 1 || ftype->get_parameters().size() == 2, "too many parameters in generated tuple function" );658 assertf( ftype->parameters.size() == 1 || ftype->parameters.size() == 2, "too many parameters in generated tuple function" ); 659 659 660 660 UntypedExpr * untyped = new UntypedExpr( new NameExpr( function->get_name() ) ); 661 661 662 662 /// xxx - &* is used to make this easier for later passes to handle 663 untyped->get_args().push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( ftype-> get_parameters().front() ) ) ) );664 if ( ftype-> get_parameters().size() == 2 ) {665 untyped->get_args().push_back( new VariableExpr( ftype-> get_parameters().back() ) );666 } 667 function-> get_statements()->get_kids().push_back( new ExprStmt( untyped ) );668 function-> get_statements()->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );663 untyped->get_args().push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( ftype->parameters.front() ) ) ) ); 664 if ( ftype->parameters.size() == 2 ) { 665 untyped->get_args().push_back( new VariableExpr( ftype->parameters.back() ) ); 666 } 667 function->statements->get_kids().push_back( new ExprStmt( untyped ) ); 668 function->statements->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->parameters.front() ) ) ) ); 669 669 } 670 670 … … 691 691 TypeDecl * newDecl = new TypeDecl( ty->get_baseType()->get_name(), Type::StorageClasses(), nullptr, TypeDecl::Dtype, true ); 692 692 TypeInstType * inst = new TypeInstType( Type::Qualifiers(), newDecl->get_name(), newDecl ); 693 newDecl-> get_assertions().push_back( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, genAssignType( inst ), nullptr,693 newDecl->assertions.push_back( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, genAssignType( inst ), nullptr, 694 694 std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) ); 695 newDecl-> get_assertions().push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,695 newDecl->assertions.push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr, 696 696 std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) ); 697 newDecl-> get_assertions().push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genCopyType( inst ), nullptr,697 newDecl->assertions.push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genCopyType( inst ), nullptr, 698 698 std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) ); 699 newDecl-> get_assertions().push_back( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,699 newDecl->assertions.push_back( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr, 700 700 std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) ); 701 701 typeParams.push_back( newDecl ); -
src/SymTab/Demangle.cc
r43e0949 r2f42718 173 173 174 174 /************* parameters ***************/ 175 const std:: list<DeclarationWithType *> &pars = funcType->parameters;175 const std::vector<DeclarationWithType *> &pars = funcType->parameters; 176 176 177 177 if ( pars.empty() ) { … … 476 476 Type * StringView::parseTuple(Type::Qualifiers tq) { 477 477 PRINT( std::cerr << "tuple..." << std::endl; ) 478 std:: list< Type * > types;478 std::vector< Type * > types; 479 479 size_t ncomponents; 480 480 if (! extractNumber(ncomponents)) return nullptr; -
src/SymTab/Indexer.cc
r43e0949 r2f42718 142 142 for ( auto decl : copy ) { 143 143 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) { 144 std::list< DeclarationWithType * >& params = function->type->parameters;144 auto & params = function->type->parameters; 145 145 assert( ! params.empty() ); 146 146 // use base type of pointer, so that qualifiers on the pointer type aren't considered. … … 668 668 } 669 669 670 void Indexer::addIds( const std:: list< DeclarationWithType * > & decls ) {670 void Indexer::addIds( const std::vector< DeclarationWithType * > & decls ) { 671 671 for ( auto d : decls ) { 672 672 addId( d ); -
src/SymTab/Indexer.h
r43e0949 r2f42718 117 117 118 118 /// convenience function for adding a list of Ids to the indexer 119 void addIds( const std:: list< DeclarationWithType * > & decls );119 void addIds( const std::vector< DeclarationWithType * > & decls ); 120 120 121 121 /// convenience function for adding a list of forall parameters to the indexer -
src/SymTab/Mangler.cc
r43e0949 r2f42718 79 79 80 80 public: 81 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 82 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 81 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 82 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 83 83 const VarMapType& varNums ); 84 84 … … 109 109 } 110 110 111 std::string mangleAssnKey( DeclarationWithType* decl, 111 std::string mangleAssnKey( DeclarationWithType* decl, 112 112 const ResolvExpr::TypeEnvironment& env ) { 113 113 PassVisitor<Mangler> mangler( env ); … … 118 118 namespace { 119 119 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams ) 120 : nextVarNum( 0 ), env(nullptr), isTopLevel( true ), 121 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 120 : nextVarNum( 0 ), env(nullptr), isTopLevel( true ), 121 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 122 122 mangleGenericParams( mangleGenericParams ) {} 123 123 124 124 Mangler::Mangler( const ResolvExpr::TypeEnvironment& env ) 125 125 : nextVarNum( 0 ), env( &env ), isTopLevel( true ), mangleOverridable( false ), 126 126 typeMode( false ), mangleGenericParams( true ) {} 127 128 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 129 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 127 128 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 129 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 130 130 const VarMapType& varNums ) 131 : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ), 132 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 131 : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ), 132 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 133 133 mangleGenericParams( mangleGenericParams ) {} 134 134 … … 207 207 208 208 namespace { 209 inline std:: list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) {210 std:: list< Type* > ret;209 inline std::vector< Type* > getTypes( const std::vector< DeclarationWithType* > decls ) { 210 std::vector< Type* > ret; 211 211 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 212 212 std::mem_fun( &DeclarationWithType::get_type ) ); … … 223 223 GuardValue( inFunctionType ); 224 224 inFunctionType = true; 225 std:: list< Type* > returnTypes = getTypes( functionType->returnVals );225 std::vector< Type* > returnTypes = getTypes( functionType->returnVals ); 226 226 if (returnTypes.empty()) mangleName << Encoding::void_t; 227 227 else acceptAll( returnTypes, *visitor ); 228 228 mangleName << "_"; 229 std:: list< Type* > paramTypes = getTypes( functionType->parameters );229 std::vector< Type* > paramTypes = getTypes( functionType->parameters ); 230 230 acceptAll( paramTypes, *visitor ); 231 231 mangleName << "_"; … … 238 238 239 239 if ( mangleGenericParams ) { 240 std::list< Expression* > & params = refType->parameters;240 std::list< Expression* > & params = refType->parameters; 241 241 if ( ! params.empty() ) { 242 242 mangleName << "_"; 243 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param) {244 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );245 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString( *param));243 for ( auto param : params ) { 244 TypeExpr *paramType = dynamic_cast< TypeExpr* >( param ); 245 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param)); 246 246 maybeAccept( paramType->type, *visitor ); 247 247 } … … 364 364 if ( varClass && varClass->type ) { 365 365 PassVisitor<Mangler> sub_mangler( 366 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, 366 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, 367 367 env, varNums ); 368 368 varClass->type->accept( sub_mangler ); … … 375 375 } 376 376 varNums[ (*i)->name ] = std::make_pair( varName, (int)(*i)->get_kind() ); 377 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert) {378 PassVisitor<Mangler> sub_mangler( 379 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env, 377 for ( auto assert : (*i)->assertions ) { 378 PassVisitor<Mangler> sub_mangler( 379 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env, 380 380 varNums ); 381 (*assert)->accept( sub_mangler );381 assert->accept( sub_mangler ); 382 382 assertionNames.push_back( sub_mangler.pass.get_mangleName() ); 383 383 acount++; -
src/SymTab/Validate.cc
r43e0949 r2f42718 179 179 void previsit( ReturnStmt * returnStmt ); 180 180 181 typedef std::list< DeclarationWithType * > ReturnVals; 182 ReturnVals returnVals; 181 std::vector< DeclarationWithType * > returnVals; 183 182 }; 184 183 … … 866 865 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 867 866 GuardValue( returnVals ); 868 returnVals = functionDecl->get_functionType()-> get_returnVals();867 returnVals = functionDecl->get_functionType()->returnVals; 869 868 } 870 869 … … 1121 1120 void VerifyCtorDtorAssign::previsit( FunctionDecl * funcDecl ) { 1122 1121 FunctionType * funcType = funcDecl->get_functionType(); 1123 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();1124 std::list< DeclarationWithType * > ¶ms = funcType->get_parameters();1122 auto & returnVals = funcType->returnVals; 1123 auto & params = funcType->parameters; 1125 1124 1126 1125 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. … … 1205 1204 void ReturnTypeFixer::postvisit( FunctionDecl * functionDecl ) { 1206 1205 FunctionType * ftype = functionDecl->get_functionType(); 1207 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();1206 auto & retVals = ftype->returnVals; 1208 1207 assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() ); 1209 1208 if ( retVals.size() == 1 ) { … … 1223 1222 // Note that this pass needs to happen early so that other passes which look for tuple types 1224 1223 // find them in all of the right places, including function return types. 1225 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();1224 auto & retVals = ftype->returnVals; 1226 1225 if ( retVals.size() > 1 ) { 1227 1226 // generate a single return parameter which is the tuple of all of the return values … … 1320 1319 if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) { 1321 1320 FunctionType * ftype = funcDecl->get_functionType(); 1322 if ( ftype-> get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {1321 if ( ftype->parameters.size() == 1 && ftype->parameters.front()->get_type()->get_qualifiers() == Type::Qualifiers() ) { 1323 1322 dereferenceOperator = funcDecl; 1324 1323 } -
src/SynTree/Declaration.h
r43e0949 r2f42718 182 182 Type *base; 183 183 std::list< TypeDecl* > parameters; 184 std:: list< DeclarationWithType* > assertions;184 std::vector< DeclarationWithType* > assertions; 185 185 186 186 NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type ); … … 191 191 void set_base( Type *newValue ) { base = newValue; } 192 192 std::list< TypeDecl* >& get_parameters() { return parameters; } 193 std::list< DeclarationWithType* >& get_assertions() { return assertions; }194 193 195 194 virtual std::string typeString() const = 0; -
src/SynTree/FunctionType.cc
r43e0949 r2f42718 39 39 40 40 namespace { 41 bool containsTtype( const std:: list<DeclarationWithType * > & l ) {41 bool containsTtype( const std::vector<DeclarationWithType * > & l ) { 42 42 if ( ! l.empty() ) { 43 43 return Tuples::isTtype( l.back()->get_type() ); -
src/SynTree/TupleExpr.cc
r43e0949 r2f42718 66 66 TupleType * type = strict_dynamic_cast< TupleType * >( tuple->get_result() ); 67 67 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 68 set_result( (*std::next( type-> get_types().begin(), index ))->clone() );68 set_result( (*std::next( type->types.begin(), index ))->clone() ); 69 69 // like MemberExpr, TupleIndexExpr is always an lvalue 70 70 get_result()->set_lvalue( true ); -
src/SynTree/TupleType.cc
r43e0949 r2f42718 25 25 class Attribute; 26 26 27 TupleType::TupleType( const Type::Qualifiers &tq, const std:: list< Type * > & types, const std::vector< Attribute * > & attributes ) : Type( tq, attributes ), types( types ) {27 TupleType::TupleType( const Type::Qualifiers &tq, const std::vector< Type * > & types, const std::vector< Attribute * > & attributes ) : Type( tq, attributes ), types( types ) { 28 28 for ( Type * t : *this ) { 29 29 // xxx - this is very awkward. TupleTypes should contain objects so that members can be named, but if they don't have an initializer node then -
src/SynTree/Type.h
r43e0949 r2f42718 359 359 class FunctionType : public Type { 360 360 public: 361 std:: list<DeclarationWithType*> returnVals;362 std:: list<DeclarationWithType*> parameters;361 std::vector<DeclarationWithType*> returnVals; 362 std::vector<DeclarationWithType*> parameters; 363 363 364 364 // Does the function accept a variable number of arguments following the arguments specified in the parameters list. … … 372 372 virtual ~FunctionType(); 373 373 374 std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }375 std::list<DeclarationWithType*> & get_parameters() { return parameters; }376 374 bool get_isVarArgs() const { return isVarArgs; } 377 375 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } … … 564 562 class TupleType : public Type { 565 563 public: 566 std:: list<Type *> types;564 std::vector<Type *> types; 567 565 std::list<Declaration *> members; 568 566 569 TupleType( const Type::Qualifiers & tq, const std:: list< Type * > & types, const std::vector< Attribute * > & attributes = std::vector< Attribute * >() );567 TupleType( const Type::Qualifiers & tq, const std::vector< Type * > & types, const std::vector< Attribute * > & attributes = std::vector< Attribute * >() ); 570 568 TupleType( const TupleType& ); 571 569 virtual ~TupleType(); 572 570 573 typedef std:: list<Type*> value_type;571 typedef std::vector< Type * > value_type; 574 572 typedef value_type::iterator iterator; 575 573 576 std::list<Type *> & get_types() { return types; }577 574 virtual unsigned size() const override { return types.size(); }; 578 575 -
src/Tuples/TupleExpansion.cc
r43e0949 r2f42718 217 217 StructDecl * decl = typeMap[tupleSize]; 218 218 StructInstType * newType = new StructInstType( qualifiers, decl ); 219 for ( auto p : group_iterate( tupleType-> get_types(), decl->get_parameters() ) ) {219 for ( auto p : group_iterate( tupleType->types, decl->get_parameters() ) ) { 220 220 Type * t = std::get<0>(p); 221 221 newType->get_parameters().push_back( new TypeExpr( t->clone() ) ); … … 298 298 Type * makeTupleType( const std::list< Expression * > & exprs ) { 299 299 // produce the TupleType which aggregates the types of the exprs 300 std::list< Type * > types; 300 std::vector< Type * > types; 301 types.reserve(exprs.size()); 301 302 Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex ); 302 303 for ( Expression * expr : exprs ) {
Note: See TracChangeset
for help on using the changeset viewer.