Changeset 3f06c05


Ignore:
Timestamp:
Jul 16, 2020, 12:35:19 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
463cb33
Parents:
cadec25
Message:

Fixed InstantiateGeneric? so that it can handle cyclic type references (fixes #198). Does produce some extra code now (see (#199).

Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGeneric.cc

    rcadec25 r3f06c05  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu Aug 04 18:33:00 2016
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu Aug 04 18:33:00 2016
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jul 16 10:17:00 2020
     13// Update Count     : 2
    1414//
    1515#include "InstantiateGeneric.h"
     
    297297        }
    298298
     299        template< typename AggrInst >
     300        static AggrInst * asForward( AggrInst * decl ) {
     301                if ( !decl->body ) {
     302                        return nullptr;
     303                }
     304                decl = decl->clone();
     305                decl->body = false;
     306                deleteAll( decl->members );
     307                decl->members.clear();
     308                return decl;
     309        }
     310
    299311        void GenericInstantiator::stripDtypeParams( AggregateDecl *base, std::list< TypeDecl* >& baseParams, const std::list< TypeExpr* >& typeSubs ) {
    300312                substituteMembers( base->get_members(), baseParams, typeSubs );
     
    373385                                concDecl->set_body( inst->get_baseStruct()->has_body() );
    374386                                substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
    375                                 insert( inst, typeSubs, concDecl ); // must insert before recursion
     387                                // Forward declare before recursion. (TODO: Only when needed, #199.)
     388                                insert( inst, typeSubs, concDecl );
     389                                if ( StructDecl *forwardDecl = asForward( concDecl ) ) {
     390                                        declsToAddBefore.push_back( forwardDecl );
     391                                }
    376392                                concDecl->acceptMutator( *visitor ); // recursively instantiate members
    377393                                declsToAddBefore.push_back( concDecl ); // must occur before declaration is added so that member instantiations appear first
     
    423439                                concDecl->set_body( inst->get_baseUnion()->has_body() );
    424440                                substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
    425                                 insert( inst, typeSubs, concDecl ); // must insert before recursion
     441                                // Forward declare before recursion. (TODO: Only when needed, #199.)
     442                                insert( inst, typeSubs, concDecl );
     443                                if ( UnionDecl *forwardDecl = asForward( concDecl ) ) {
     444                                        declsToAddBefore.push_back( forwardDecl );
     445                                }
    426446                                concDecl->acceptMutator( *visitor ); // recursively instantiate members
    427447                                declsToAddBefore.push_back( concDecl ); // must occur before declaration is added so that member instantiations appear first
  • tests/.expect/functions.x64.txt

    rcadec25 r3f06c05  
    121121
    122122}
     123struct _conc__tuple2_0;
    123124struct _conc__tuple2_0 {
    124125    signed int field_0;
     
    157158
    158159}
     160struct _conc__tuple3_1;
    159161struct _conc__tuple3_1 {
    160162    signed int field_0;
     
    170172    __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = {  };
    171173}
     174struct _conc__tuple3_2;
    172175struct _conc__tuple3_2 {
    173176    signed int field_0;
     
    260263    __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1;
    261264}
     265struct _conc__tuple2_3;
    262266struct _conc__tuple2_3 {
    263267    signed int *field_0;
  • tests/.expect/functions.x86.txt

    rcadec25 r3f06c05  
    121121
    122122}
     123struct _conc__tuple2_0;
    123124struct _conc__tuple2_0 {
    124125    signed int field_0;
     
    157158
    158159}
     160struct _conc__tuple3_1;
    159161struct _conc__tuple3_1 {
    160162    signed int field_0;
     
    170172    __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = {  };
    171173}
     174struct _conc__tuple3_2;
    172175struct _conc__tuple3_2 {
    173176    signed int field_0;
     
    260263    __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1;
    261264}
     265struct _conc__tuple2_3;
    262266struct _conc__tuple2_3 {
    263267    signed int *field_0;
Note: See TracChangeset for help on using the changeset viewer.