- File:
-
- 1 edited
-
src/GenPoly/InstantiateGenericNew.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/InstantiateGenericNew.cpp
rbc899d6 re01eb4a 26 26 #include "AST/Pass.hpp" // for Pass, WithGuard, WithShortCi... 27 27 #include "AST/TranslationUnit.hpp" // for TranslationUnit 28 #include "AST/Vector.hpp" // for vector29 28 #include "CodeGen/OperatorTable.h" // for isAssignment 30 29 #include "Common/ScopedMap.h" // for ScopedMap … … 40 39 // Utilities: 41 40 42 using type_vector = ast::vector< ast::TypeExpr>;41 using type_vector = std::vector< ast::ptr< ast::TypeExpr > >; 43 42 44 43 /// Abstracts type equality for a list of parameter types. 45 44 struct TypeList { 46 45 TypeList() : params() {} 47 TypeList( ast::vector< ast::Type> const & params ) :46 TypeList( std::vector< ast::ptr< ast::Type > > const & params ) : 48 47 params( params ) {} 49 TypeList( ast::vector< ast::Type> && params ) :48 TypeList( std::vector< ast::ptr< ast::Type > > && params ) : 50 49 params( std::move( params ) ) {} 51 50 TypeList( TypeList const & that ) : params( that.params ) {} 52 51 TypeList( TypeList && that ) : params( std::move( that.params ) ) {} 53 52 54 TypeList( ast::vector< ast::TypeExpr> const & exprs ) :53 TypeList( std::vector< ast::ptr< ast::TypeExpr > > const & exprs ) : 55 54 params() { 56 55 for ( auto expr : exprs ) { … … 83 82 } 84 83 85 ast::vector<ast::Type> params;84 std::vector<ast::ptr<ast::Type>> params; 86 85 }; 87 86 … … 104 103 /// returns null if no such value exists. 105 104 ast::AggregateDecl const * lookup( 106 ast::AggregateDecl const * key, 107 type_vector const & params ) const { 105 ast::AggregateDecl const * key, type_vector const & params ) const { 108 106 // This type repackaging is used for the helpers. 109 107 ast::ptr<ast::AggregateDecl> ptr = key; … … 152 150 } 153 151 154 bool isDtypeStatic( ast::vector<ast::TypeDecl> const & baseParams ) {152 bool isDtypeStatic( std::vector<ast::ptr<ast::TypeDecl>> const & baseParams ) { 155 153 return std::all_of( baseParams.begin(), baseParams.end(), 156 154 []( ast::TypeDecl const * td ){ return !td->isComplete(); } … … 163 161 /// least one parameter type, and dynamic if there is no concrete instantiation. 164 162 GenericType makeSubstitutions( 165 ast::vector<ast::TypeExpr> & out,166 ast::vector<ast::TypeDecl> const & baseParams,167 ast::vector<ast::Expr> const & params ) {163 std::vector<ast::ptr<ast::TypeExpr>> & out, 164 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams, 165 std::vector<ast::ptr<ast::Expr>> const & params ) { 168 166 GenericType gt = GenericType::dtypeStatic; 169 167 … … 216 214 /// Substitutes types of members according to baseParams => typeSubs, 217 215 /// returning the result in a new vector. 218 ast::vector<ast::Decl> substituteMembers(219 ast::vector<ast::Decl> const & members,220 ast::vector<ast::TypeDecl> const & baseParams,221 ast::vector<ast::TypeExpr> const & typeSubs ) {222 ast::vector<ast::Decl> out;216 std::vector<ast::ptr<ast::Decl>> substituteMembers( 217 std::vector<ast::ptr<ast::Decl>> const & members, 218 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams, 219 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) { 220 std::vector<ast::ptr<ast::Decl>> out; 223 221 ast::TypeSubstitution subs( baseParams, typeSubs ); 224 222 for ( ast::ptr<ast::Decl> const & member : members ) { … … 237 235 /// modifying them in-place. 238 236 void substituteMembersHere( 239 ast::vector<ast::Decl> & members,240 ast::vector<ast::TypeDecl> const & baseParams,241 ast::vector<ast::TypeExpr> const & typeSubs ) {237 std::vector<ast::ptr<ast::Decl>> & members, 238 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams, 239 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) { 242 240 ast::TypeSubstitution subs( baseParams, typeSubs ); 243 241 for ( ast::ptr<ast::Decl> & member : members ) { … … 287 285 288 286 ast::Expr const * fixMemberExpr( 289 ast::vector<ast::TypeDecl> const & baseParams,287 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams, 290 288 ast::MemberExpr const * memberExpr ); 291 289 … … 351 349 352 350 ast::Expr const * FixDtypeStatic::fixMemberExpr( 353 ast::vector<ast::TypeDecl> const & baseParams,351 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams, 354 352 ast::MemberExpr const * memberExpr ) { 355 353 // Need to cast dtype-static member expressions to their actual type … … 463 461 type_vector const & typeSubs, ast::UnionDecl const * decl ); 464 462 465 void replaceParametersWithConcrete( ast::vector<ast::Expr> & params );463 void replaceParametersWithConcrete( std::vector<ast::ptr<ast::Expr>> & params ); 466 464 ast::Type const * replaceWithConcrete( ast::Type const * type, bool doClone ); 467 465 … … 472 470 /// marks it as stripped. 473 471 void stripDtypeParams( ast::AggregateDecl * base, 474 ast::vector<ast::TypeDecl> & baseParams,475 ast::vector<ast::TypeExpr> const & typeSubs );472 std::vector<ast::ptr<ast::TypeDecl>> & baseParams, 473 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ); 476 474 }; 477 475 … … 513 511 // and put substitutions in typeSubs. 514 512 assertf( inst->base, "Base data-type has parameters." ); 515 ast::vector<ast::TypeExpr> typeSubs;513 std::vector<ast::ptr<ast::TypeExpr>> typeSubs; 516 514 GenericType gt = makeSubstitutions( typeSubs, inst->base->params, inst->params ); 517 515 switch ( gt ) { … … 572 570 ast::AggregateDecl const * aggr = 573 571 expr->aggregate->result.strict_as<ast::BaseInstType>()->aggr(); 574 ast::vector<ast::Decl> const & members = aggr->members;572 std::vector<ast::ptr<ast::Decl>> const & members = aggr->members; 575 573 auto it = std::find( members.begin(), members.end(), expr->member ); 576 574 memberIndex = std::distance( members.begin(), it ); … … 645 643 646 644 void GenericInstantiator::replaceParametersWithConcrete( 647 ast::vector<ast::Expr> & params ) {645 std::vector<ast::ptr<ast::Expr>> & params ) { 648 646 for ( ast::ptr<ast::Expr> & param : params ) { 649 647 auto paramType = param.as<ast::TypeExpr>(); … … 675 673 void GenericInstantiator::stripDtypeParams( 676 674 ast::AggregateDecl * base, 677 ast::vector<ast::TypeDecl> & baseParams,678 ast::vector<ast::TypeExpr> const & typeSubs ) {675 std::vector<ast::ptr<ast::TypeDecl>> & baseParams, 676 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) { 679 677 substituteMembersHere( base->members, baseParams, typeSubs ); 680 678
Note:
See TracChangeset
for help on using the changeset viewer.