Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGenericNew.cpp

    rbc899d6 re01eb4a  
    2626#include "AST/Pass.hpp"                // for Pass, WithGuard, WithShortCi...
    2727#include "AST/TranslationUnit.hpp"     // for TranslationUnit
    28 #include "AST/Vector.hpp"              // for vector
    2928#include "CodeGen/OperatorTable.h"     // for isAssignment
    3029#include "Common/ScopedMap.h"          // for ScopedMap
     
    4039// Utilities:
    4140
    42 using type_vector = ast::vector< ast::TypeExpr >;
     41using type_vector = std::vector< ast::ptr< ast::TypeExpr > >;
    4342
    4443/// Abstracts type equality for a list of parameter types.
    4544struct TypeList {
    4645        TypeList() : params() {}
    47         TypeList( ast::vector< ast::Type > const & params ) :
     46        TypeList( std::vector< ast::ptr< ast::Type > > const & params ) :
    4847                params( params ) {}
    49         TypeList( ast::vector< ast::Type > && params ) :
     48        TypeList( std::vector< ast::ptr< ast::Type > > && params ) :
    5049                params( std::move( params ) ) {}
    5150        TypeList( TypeList const & that ) : params( that.params ) {}
    5251        TypeList( TypeList && that ) : params( std::move( that.params ) ) {}
    5352
    54         TypeList( ast::vector< ast::TypeExpr > const & exprs ) :
     53        TypeList( std::vector< ast::ptr< ast::TypeExpr > > const & exprs ) :
    5554                        params() {
    5655                for ( auto expr : exprs ) {
     
    8382        }
    8483
    85         ast::vector<ast::Type> params;
     84        std::vector<ast::ptr<ast::Type>> params;
    8685};
    8786
     
    104103        /// returns null if no such value exists.
    105104        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 {
    108106                // This type repackaging is used for the helpers.
    109107                ast::ptr<ast::AggregateDecl> ptr = key;
     
    152150}
    153151
    154 bool isDtypeStatic( ast::vector<ast::TypeDecl> const & baseParams ) {
     152bool isDtypeStatic( std::vector<ast::ptr<ast::TypeDecl>> const & baseParams ) {
    155153        return std::all_of( baseParams.begin(), baseParams.end(),
    156154                []( ast::TypeDecl const * td ){ return !td->isComplete(); }
     
    163161/// least one parameter type, and dynamic if there is no concrete instantiation.
    164162GenericType 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 ) {
    168166        GenericType gt = GenericType::dtypeStatic;
    169167
     
    216214/// Substitutes types of members according to baseParams => typeSubs,
    217215/// 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;
     216std::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;
    223221        ast::TypeSubstitution subs( baseParams, typeSubs );
    224222        for ( ast::ptr<ast::Decl> const & member : members ) {
     
    237235/// modifying them in-place.
    238236void 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 ) {
    242240        ast::TypeSubstitution subs( baseParams, typeSubs );
    243241        for ( ast::ptr<ast::Decl> & member : members ) {
     
    287285
    288286        ast::Expr const * fixMemberExpr(
    289                 ast::vector<ast::TypeDecl> const & baseParams,
     287                std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
    290288                ast::MemberExpr const * memberExpr );
    291289
     
    351349
    352350ast::Expr const * FixDtypeStatic::fixMemberExpr(
    353                 ast::vector<ast::TypeDecl> const & baseParams,
     351                std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
    354352                ast::MemberExpr const * memberExpr ) {
    355353        // Need to cast dtype-static member expressions to their actual type
     
    463461                type_vector const & typeSubs, ast::UnionDecl const * decl );
    464462
    465         void replaceParametersWithConcrete( ast::vector<ast::Expr> & params );
     463        void replaceParametersWithConcrete( std::vector<ast::ptr<ast::Expr>> & params );
    466464        ast::Type const * replaceWithConcrete( ast::Type const * type, bool doClone );
    467465
     
    472470        /// marks it as stripped.
    473471        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 );
    476474};
    477475
     
    513511        // and put substitutions in typeSubs.
    514512        assertf( inst->base, "Base data-type has parameters." );
    515         ast::vector<ast::TypeExpr> typeSubs;
     513        std::vector<ast::ptr<ast::TypeExpr>> typeSubs;
    516514        GenericType gt = makeSubstitutions( typeSubs, inst->base->params, inst->params );
    517515        switch ( gt ) {
     
    572570                ast::AggregateDecl const * aggr =
    573571                        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;
    575573                auto it = std::find( members.begin(), members.end(), expr->member );
    576574                memberIndex = std::distance( members.begin(), it );
     
    645643
    646644void GenericInstantiator::replaceParametersWithConcrete(
    647                 ast::vector<ast::Expr> & params ) {
     645                std::vector<ast::ptr<ast::Expr>> & params ) {
    648646        for ( ast::ptr<ast::Expr> & param : params ) {
    649647                auto paramType = param.as<ast::TypeExpr>();
     
    675673void GenericInstantiator::stripDtypeParams(
    676674                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 ) {
    679677        substituteMembersHere( base->members, baseParams, typeSubs );
    680678
Note: See TracChangeset for help on using the changeset viewer.