Ignore:
Timestamp:
Oct 3, 2023, 10:58:40 AM (10 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
cf34e82
Parents:
46f9f02
Message:

Translated the box pass to the new AST. This includes direct as possible translations of the existing passes are two fix in passes which correct AST problems the direct translation causes. Outside the box pass there have already been many changes, ad there is another in Instantiate Generics, which disconnects designators instead of leaving them connected to the original polymorphic type, which breaks the invarants once the fields are removed in the Eraser sub-pass. There was also a change that was made and un-made in one commit. If translate from the new-AST to the old-AST part way you must, where possible, sort the TypeEnvKey? values by string comparison. However, it now passes over that so it would be just extra complexity and run time, so I removed it. I stand at the exit from a great woods, just shy of a year from when I entered it. It has been a difficult and tiring journey. The path has been long and at times comically winding; but most often it was invisible, hidden under an impenetrable canopy and I spend days looking for it. All for a short jog forward before getting lost again. In front of me is another woods. It looks smaller, but I can't see the other side. Anyways, time to keep walking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGenericNew.cpp

    r46f9f02 r1ee0a4da  
    335335ast::Expr const * FixDtypeStatic::postvisit( ast::MemberExpr const * expr ) {
    336336        ast::ptr<ast::Type> const & type = expr->aggregate->result;
    337         if ( !isGenericType( type ) ) {
    338                 return expr;
    339         } else if ( auto inst = type.as<ast::StructInstType>() ) {
    340                 return fixMemberExpr( inst, expr );
     337        if ( auto inst = type.as<ast::StructInstType>() ) {
     338                if ( !inst->params.empty() ) return fixMemberExpr( inst, expr );
    341339        } else if ( auto inst = type.as<ast::UnionInstType>() ) {
    342                 return fixMemberExpr( inst, expr );
     340                if ( !inst->params.empty() ) return fixMemberExpr( inst, expr );
    343341        }
    344342        return expr;
     
    451449        ast::Expr const * postvisit( ast::MemberExpr const * expr );
    452450        ast::Expr const * postvisit( ast::Expr const * expr );
    453         void previsit( ast::ParseNode const * node );
    454 
     451        ast::Designation const * postvisit( ast::Designation const * );
     452
     453        void previsit( ast::ParseNode const * node ) {
     454                GuardValue( location ) = &node->location;
     455        }
    455456        void previsit( ast::FunctionType const * ) {
    456457                GuardValue( inFunctionType ) = true;
     
    628629}
    629630
    630 void GenericInstantiator::previsit( ast::ParseNode const * node ) {
    631         GuardValue( location ) = &node->location;
     631// This attempts to figure out what the final name of the field will be.
     632// Pretty printing can cause this to become incorrect.
     633std::string getPrintName( ast::DeclWithType const * decl ) {
     634        return ( decl->linkage.is_mangled )
     635                ? decl->scopedMangleName() : decl->name;
     636}
     637
     638ast::Designation const * GenericInstantiator::postvisit(
     639                ast::Designation const * designation ) {
     640        // Disconnect designator names from their fields.
     641        // It is now incorrect to point at the generic definition where the used
     642        // type now is replaced with a concrete instance. Ideally, new variable
     643        // expressions would point at fields in the concrete instances, but that
     644        // is work and that information should not be needed this late in
     645        // compilation.
     646
     647        // Modify all designations, even if not needed.
     648        auto mutNode = mutate( designation );
     649        for ( ast::ptr<ast::Expr> & designator : mutNode->designators ) {
     650                if ( auto var = designator.as<ast::VariableExpr>() ) {
     651                        designator = new ast::NameExpr(
     652                                var->location, getPrintName( var->var ) );
     653                }
     654        }
     655        return mutNode;
    632656}
    633657
Note: See TracChangeset for help on using the changeset viewer.