Changeset 185cd94


Ignore:
Timestamp:
Mar 27, 2025, 3:48:34 PM (4 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
52931c5
Parents:
b1c220a (diff), 10c1770 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/GenPoly/InstantiateGeneric.cpp

    rb1c220a r185cd94  
    4242
    4343using type_vector = ast::vector< ast::TypeExpr >;
     44
     45template<typename C, typename V>
     46bool contains( C const & container, V const & value ) {
     47        return std::any_of( container.begin(), container.end(),
     48                        [value]( auto& element ){ return element == value; } );
     49}
    4450
    4551/// Abstracts type equality for a list of parameter types.
     
    423429}
    424430
    425 struct GenericInstantiator final :
     431class GenericInstantiator final :
    426432                public ast::WithCodeLocation,
    427433                public ast::WithConstTypeSubstitution,
     
    444450        /// member from an instantiation.
    445451        int memberIndex = -1;
     452        /// The polymorphic types we are currently instantiating.
     453        ast::vector<ast::Decl> instantiating;
     454public:
    446455
    447456        GenericInstantiator() :
     
    597606                        );
    598607
    599                         // Forward declare before recursion. (TODO: Only when needed, #199.)
     608                        // Insert the declaration so it doesn't create it again,
    600609                        insert( inst, typeSubs, newDecl );
    601                         if ( AggrDecl const * forwardDecl = ast::asForward( newDecl ) ) {
    602                                 declsToAddBefore.push_back( forwardDecl );
    603                         }
     610                        // ... but mark this declaration as one we are working on.
     611                        auto guard = makeFuncGuard(
     612                                [this, newDecl](){ instantiating.push_back( newDecl ); },
     613                                [this](){ instantiating.pop_back(); } );
    604614                        // Recursively instantiate members:
    605615                        concDecl = strict_dynamic_cast<AggrDecl const *>(
    606616                                newDecl->accept( *visitor ) );
    607                         // Must occur before declaration is added so
    608                         // that member instantiation appear first.
     617
     618                        // Produce the declaration after its members are instantiated.
    609619                        declsToAddBefore.push_back( concDecl );
     620                } else if ( contains( instantiating, concDecl ) ) {
     621                        if ( AggrDecl const * forwardDecl = ast::asForward( concDecl ) ) {
     622                                declsToAddBefore.push_back( forwardDecl );
     623                        }
    610624                }
    611625                return new ast::SueInstType<AggrDecl>( concDecl, inst->qualifiers );
  • TabularUnified src/ResolvExpr/Resolver.cpp

    rb1c220a r185cd94  
    703703        } else {
    704704                if ( !objectDecl->isTypeFixed ) {
    705                         auto newDecl = fixObjectType(objectDecl, context);
    706                         auto mutDecl = mutate(newDecl);
     705                        objectDecl = fixObjectType(objectDecl, context);
    707706
    708707                        // generate CtorInit wrapper when necessary.
     
    710709                        // this object in visitor pass, thus disabling CtorInit codegen.
    711710                        // this happens on aggregate members and function parameters.
    712                         if ( shouldGenCtorInit( mutDecl ) ) {
     711                        if ( shouldGenCtorInit( objectDecl ) ) {
    713712                                // constructed objects cannot be designated
    714                                 if ( InitTweak::isDesignated( mutDecl->init ) ) {
    715                                         ast::Pass<ResolveDesignators> res( context );
    716                                         maybe_accept( mutDecl->init.get(), res );
    717                                         if ( !res.core.result ) {
    718                                                 SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object.\n"
    719                                                                            "If this is really what you want, initialize with @=." );
    720                                         }
     713                                if ( InitTweak::isDesignated( objectDecl->init )
     714                                                && !ast::Pass<ResolveDesignators>::read(
     715                                                        objectDecl->init.get(), context ) ) {
     716                                        SemanticError( objectDecl, "Cannot include designations in the initializer for a managed Object.\n"
     717                                                        "If this is really what you want, initialize with @=." );
    721718                                }
    722719                                // constructed objects should not have initializers nested too deeply
    723                                 if ( ! InitTweak::checkInitDepth( mutDecl ) ) SemanticError( mutDecl, "Managed object's initializer is too deep " );
    724 
    725                                 mutDecl->init = InitTweak::genCtorInit( mutDecl->location, mutDecl );
     720                                if ( !InitTweak::checkInitDepth( objectDecl ) ) SemanticError( objectDecl, "Managed object's initializer is too deep " );
     721
     722                                objectDecl = ast::mutate_field( objectDecl, &ast::ObjectDecl::init,
     723                                        InitTweak::genCtorInit( objectDecl->location, objectDecl ) );
    726724                        }
    727 
    728                         objectDecl = mutDecl;
    729725                }
    730726                currentObject = ast::CurrentObject{ objectDecl->location, objectDecl->get_type() };
  • TabularUnified tests/.expect/functions.arm64.txt

    rb1c220a r185cd94  
    139139
    140140}
    141 struct _conc__tuple2_0;
    142141struct _conc__tuple2_0 {
    143142    signed int field_0;
     
    182181
    183182}
    184 struct _conc__tuple3_1;
    185183struct _conc__tuple3_1 {
    186184    signed int field_0;
     
    202200    __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = {  };
    203201}
    204 struct _conc__tuple3_2;
    205202struct _conc__tuple3_2 {
    206203    signed int field_0;
     
    294291    __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1;
    295292}
    296 struct _conc__tuple2_3;
    297293struct _conc__tuple2_3 {
    298294    signed int *field_0;
  • TabularUnified tests/.expect/functions.x64.txt

    rb1c220a r185cd94  
    139139
    140140}
    141 struct _conc__tuple2_0;
    142141struct _conc__tuple2_0 {
    143142    signed int field_0;
     
    182181
    183182}
    184 struct _conc__tuple3_1;
    185183struct _conc__tuple3_1 {
    186184    signed int field_0;
     
    202200    __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = {  };
    203201}
    204 struct _conc__tuple3_2;
    205202struct _conc__tuple3_2 {
    206203    signed int field_0;
     
    294291    __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1;
    295292}
    296 struct _conc__tuple2_3;
    297293struct _conc__tuple2_3 {
    298294    signed int *field_0;
  • TabularUnified tests/.expect/functions.x86.txt

    rb1c220a r185cd94  
    139139
    140140}
    141 struct _conc__tuple2_0;
    142141struct _conc__tuple2_0 {
    143142    signed int field_0;
     
    182181
    183182}
    184 struct _conc__tuple3_1;
    185183struct _conc__tuple3_1 {
    186184    signed int field_0;
     
    202200    __attribute__ ((unused)) struct _conc__tuple3_1 _X9_retval_fT3iii_1 = {  };
    203201}
    204 struct _conc__tuple3_2;
    205202struct _conc__tuple3_2 {
    206203    signed int field_0;
     
    294291    __attribute__ ((unused)) signed int *const _X10_retval_f3KPi_1;
    295292}
    296 struct _conc__tuple2_3;
    297293struct _conc__tuple2_3 {
    298294    signed int *field_0;
Note: See TracChangeset for help on using the changeset viewer.