Changeset 93d2219 for src/GenPoly
- Timestamp:
- Oct 28, 2022, 3:12:16 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, stuck-waitfor-destruct
- Children:
- fa2e183
- Parents:
- e874605 (diff), 22a0e87 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/GenPoly
- Files:
-
- 4 edited
-
GenPoly.cc (modified) (5 diffs)
-
GenPoly.h (modified) (6 diffs)
-
InstantiateGenericNew.cpp (modified) (16 diffs)
-
ScrubTyVars.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
re874605 r93d2219 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 7 15:25:00 202213 // Update Count : 1 612 // Last Modified On : Mon Oct 24 15:19:00 2022 13 // Update Count : 17 14 14 // 15 15 … … 194 194 195 195 if ( auto inst = dynamic_cast< const ast::TypeInstType * >( type ) ) { 196 if ( typeVars.find( inst->typeString()) != typeVars.end() ) return type;196 if ( typeVars.find( *inst ) != typeVars.end() ) return type; 197 197 } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) { 198 198 return isPolyType( array->base, subst ); … … 227 227 228 228 if ( auto inst = dynamic_cast<ast::TypeInstType const *>( type ) ) { 229 auto var = typeVars.find( inst->name);229 auto var = typeVars.find( *inst ); 230 230 if ( var != typeVars.end() && var->second.isComplete ) { 231 231 … … 784 784 785 785 void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) { 786 typeVars.insert( type->typeString(), ast::TypeDecl::Data( type->base ) );786 typeVars.insert( *type, ast::TypeDecl::Data( type->base ) ); 787 787 } 788 788 … … 816 816 } 817 817 818 void printTypeVarMap( std::ostream &os, const TypeVarMap & typeVars ) {819 for ( auto const & pair : typeVars ) {820 os << pair.first << " (" << pair.second << ") ";821 } // for822 os << std::endl;823 }824 825 818 } // namespace GenPoly 826 819 -
src/GenPoly/GenPoly.h
re874605 r93d2219 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 7 15:06:00 202213 // Update Count : 912 // Last Modified On : Mon Oct 24 15:18:00 2022 13 // Update Count : 11 14 14 // 15 15 … … 22 22 #include "AST/Decl.hpp" // for TypeDecl::Data 23 23 #include "AST/Fwd.hpp" // for ApplicationExpr, BaseInstType, Func... 24 #include "AST/Type.hpp" // for TypeInstType::TypeEnvKey 24 25 #include "SymTab/Mangler.h" // for Mangler 25 26 #include "SynTree/Declaration.h" // for TypeDecl::Data, AggregateDecl, Type... … … 28 29 namespace GenPoly { 29 30 30 // TODO Via some tricks this works for ast::TypeDecl::Data as well.31 31 typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap; 32 using TypeVarMap = ErasableScopedMap< std::string, ast::TypeDecl::Data >;32 using TypeVarMap = ErasableScopedMap< ast::TypeInstType::TypeEnvKey, ast::TypeDecl::Data >; 33 33 34 34 /// Replaces a TypeInstType by its referrent in the environment, if applicable 35 35 Type* replaceTypeInst( Type* type, const TypeSubstitution* env ); 36 const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * ); 36 37 37 38 /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided … … 53 54 /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters 54 55 ReferenceToType *isDynRet( FunctionType *function ); 56 const ast::BaseInstType *isDynRet( const ast::FunctionType * func ); 55 57 56 58 /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type … … 112 114 /// Prints type variable map 113 115 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 114 void printTypeVarMap( std::ostream &os, const TypeVarMap & typeVars );115 116 116 117 /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType(). … … 128 129 /// Gets the name of the layout function for a given aggregate type, given its declaration 129 130 inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); } 131 inline std::string layoutofName( ast::AggregateDecl const * decl ) { 132 return std::string( "_layoutof_" ) + decl->name; 133 } 130 134 131 135 } // namespace GenPoly -
src/GenPoly/InstantiateGenericNew.cpp
re874605 r93d2219 26 26 #include "AST/Pass.hpp" // for Pass, WithGuard, WithShortCi... 27 27 #include "AST/TranslationUnit.hpp" // for TranslationUnit 28 #include "AST/Vector.hpp" // for vector 28 29 #include "CodeGen/OperatorTable.h" // for isAssignment 29 30 #include "Common/ScopedMap.h" // for ScopedMap … … 39 40 // Utilities: 40 41 41 using type_vector = std::vector< ast::ptr< ast::TypeExpr >>;42 using type_vector = ast::vector< ast::TypeExpr >; 42 43 43 44 /// Abstracts type equality for a list of parameter types. 44 45 struct TypeList { 45 46 TypeList() : params() {} 46 TypeList( std::vector< ast::ptr< ast::Type >> const & params ) :47 TypeList( ast::vector< ast::Type > const & params ) : 47 48 params( params ) {} 48 TypeList( std::vector< ast::ptr< ast::Type >> && params ) :49 TypeList( ast::vector< ast::Type > && params ) : 49 50 params( std::move( params ) ) {} 50 51 TypeList( TypeList const & that ) : params( that.params ) {} 51 52 TypeList( TypeList && that ) : params( std::move( that.params ) ) {} 52 53 53 TypeList( std::vector< ast::ptr< ast::TypeExpr >> const & exprs ) :54 TypeList( ast::vector< ast::TypeExpr > const & exprs ) : 54 55 params() { 55 56 for ( auto expr : exprs ) { … … 82 83 } 83 84 84 std::vector<ast::ptr<ast::Type>> params;85 ast::vector<ast::Type> params; 85 86 }; 86 87 … … 103 104 /// returns null if no such value exists. 104 105 ast::AggregateDecl const * lookup( 105 ast::AggregateDecl const * key, type_vector const & params ) const { 106 ast::AggregateDecl const * key, 107 type_vector const & params ) const { 106 108 // This type repackaging is used for the helpers. 107 109 ast::ptr<ast::AggregateDecl> ptr = key; … … 150 152 } 151 153 152 bool isDtypeStatic( std::vector<ast::ptr<ast::TypeDecl>> const & baseParams ) {154 bool isDtypeStatic( ast::vector<ast::TypeDecl> const & baseParams ) { 153 155 return std::all_of( baseParams.begin(), baseParams.end(), 154 156 []( ast::TypeDecl const * td ){ return !td->isComplete(); } … … 161 163 /// least one parameter type, and dynamic if there is no concrete instantiation. 162 164 GenericType makeSubstitutions( 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 ) {165 ast::vector<ast::TypeExpr> & out, 166 ast::vector<ast::TypeDecl> const & baseParams, 167 ast::vector<ast::Expr> const & params ) { 166 168 GenericType gt = GenericType::dtypeStatic; 167 169 … … 214 216 /// Substitutes types of members according to baseParams => typeSubs, 215 217 /// returning the result in a new vector. 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;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; 221 223 ast::TypeSubstitution subs( baseParams, typeSubs ); 222 224 for ( ast::ptr<ast::Decl> const & member : members ) { … … 235 237 /// modifying them in-place. 236 238 void substituteMembersHere( 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 ) {239 ast::vector<ast::Decl> & members, 240 ast::vector<ast::TypeDecl> const & baseParams, 241 ast::vector<ast::TypeExpr> const & typeSubs ) { 240 242 ast::TypeSubstitution subs( baseParams, typeSubs ); 241 243 for ( ast::ptr<ast::Decl> & member : members ) { … … 285 287 286 288 ast::Expr const * fixMemberExpr( 287 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,289 ast::vector<ast::TypeDecl> const & baseParams, 288 290 ast::MemberExpr const * memberExpr ); 289 291 … … 349 351 350 352 ast::Expr const * FixDtypeStatic::fixMemberExpr( 351 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,353 ast::vector<ast::TypeDecl> const & baseParams, 352 354 ast::MemberExpr const * memberExpr ) { 353 355 // Need to cast dtype-static member expressions to their actual type … … 461 463 type_vector const & typeSubs, ast::UnionDecl const * decl ); 462 464 463 void replaceParametersWithConcrete( std::vector<ast::ptr<ast::Expr>> & params );465 void replaceParametersWithConcrete( ast::vector<ast::Expr> & params ); 464 466 ast::Type const * replaceWithConcrete( ast::Type const * type, bool doClone ); 465 467 … … 470 472 /// marks it as stripped. 471 473 void stripDtypeParams( ast::AggregateDecl * base, 472 std::vector<ast::ptr<ast::TypeDecl>> & baseParams,473 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs );474 ast::vector<ast::TypeDecl> & baseParams, 475 ast::vector<ast::TypeExpr> const & typeSubs ); 474 476 }; 475 477 … … 511 513 // and put substitutions in typeSubs. 512 514 assertf( inst->base, "Base data-type has parameters." ); 513 std::vector<ast::ptr<ast::TypeExpr>> typeSubs;515 ast::vector<ast::TypeExpr> typeSubs; 514 516 GenericType gt = makeSubstitutions( typeSubs, inst->base->params, inst->params ); 515 517 switch ( gt ) { … … 570 572 ast::AggregateDecl const * aggr = 571 573 expr->aggregate->result.strict_as<ast::BaseInstType>()->aggr(); 572 std::vector<ast::ptr<ast::Decl>> const & members = aggr->members;574 ast::vector<ast::Decl> const & members = aggr->members; 573 575 auto it = std::find( members.begin(), members.end(), expr->member ); 574 576 memberIndex = std::distance( members.begin(), it ); … … 643 645 644 646 void GenericInstantiator::replaceParametersWithConcrete( 645 std::vector<ast::ptr<ast::Expr>> & params ) {647 ast::vector<ast::Expr> & params ) { 646 648 for ( ast::ptr<ast::Expr> & param : params ) { 647 649 auto paramType = param.as<ast::TypeExpr>(); … … 673 675 void GenericInstantiator::stripDtypeParams( 674 676 ast::AggregateDecl * base, 675 std::vector<ast::ptr<ast::TypeDecl>> & baseParams,676 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) {677 ast::vector<ast::TypeDecl> & baseParams, 678 ast::vector<ast::TypeExpr> const & typeSubs ) { 677 679 substituteMembersHere( base->members, baseParams, typeSubs ); 678 680 -
src/GenPoly/ScrubTyVars.cc
re874605 r93d2219 20 20 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_it... 21 21 #include "ScrubTyVars.h" 22 #include "SymTab/Mangler.h" // for mangle , typeMode22 #include "SymTab/Mangler.h" // for mangleType 23 23 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Typ... 24 24 #include "SynTree/Expression.h" // for Expression (ptr only), NameExpr … … 195 195 } 196 196 197 auto typeVar = typeVars->find( type->name );197 auto typeVar = typeVars->find( *type ); 198 198 if ( typeVar == typeVars->end() ) { 199 199 return type; … … 227 227 if ( dynType ) { 228 228 return new ast::NameExpr( expr->location, 229 sizeofName( Mangle::mangle ( dynType, Mangle::typeMode()) ) );229 sizeofName( Mangle::mangleType( dynType ) ) ); 230 230 } else { 231 231 return expr; … … 237 237 if ( dynType ) { 238 238 return new ast::NameExpr( expr->location, 239 alignofName( Mangle::mangle ( dynType, Mangle::typeMode()) ) );239 alignofName( Mangle::mangleType( dynType ) ) ); 240 240 } else { 241 241 return expr;
Note:
See TracChangeset
for help on using the changeset viewer.