Changeset d60a4c2 for src/ControlStruct


Ignore:
Timestamp:
Jan 11, 2025, 5:48:46 PM (9 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
f886608
Parents:
7d65715f (diff), 32a119e9 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptDecl.cpp

    r7d65715f rd60a4c2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ExceptDecl.cpp --
     7// ExceptDecl.cpp -- Translate "exception" and exception related declarations.
    88//
    99// Author           : Andrew Beach
    1010// Created On       : Tue Jul 12 15:50:00 2022
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  7 12:05:55 2024
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jan 10 15:35:55 2024
     13// Update Count     : 2
    1414//
    1515
     
    117117        decl->body = true;
    118118        for ( ast::ptr<ast::TypeDecl> const & param : forallClause ) {
    119                 decl->params.push_back( ast::deepCopy( param ) );
     119                // Create an unsized and assertionless copy of the parameter.
     120                decl->params.push_back( new ast::TypeDecl(
     121                        param->location,
     122                        param->name,
     123                        param->storage,
     124                        param->base ? ast::deepCopy( param->base ) : nullptr,
     125                        ast::TypeDecl::Dtype,
     126                        false,
     127                        nullptr
     128                ) );
    120129        }
    121130        return decl;
     
    445454}
    446455
     456ast::NameExpr const * designatedName( ast::Designation const * des ) {
     457        if ( des && 1 == des->designators.size() ) {
     458                return des->designators.front().as<ast::NameExpr>();
     459        }
     460        return nullptr;
     461}
     462
    447463ast::ObjectDecl const * ExceptDeclCore::transformVTable(
    448464                ast::ObjectDecl const * decl, ast::VTableType const * type ) {
     
    467483                                createTypeIdValue( location, exceptionName, params ) );
    468484                }
    469                 declsToAddBefore.push_back(
    470                         createCopy( location, exceptionName, params ) );
    471                 declsToAddBefore.push_back(
    472                         createMsg( location, exceptionName, params ) );
    473485                retDecl = createVirtualTable(
    474486                        location, exceptionName, params, tableName );
     487                // There is quite a bit of work to pull over any initializers and
     488                // decide if we want to insert the default functions.
     489                bool foundCopy = false;
     490                bool foundMsg = false;
     491                ast::ListInit const * init = decl->init.as<ast::ListInit>();
     492                if ( init ) {
     493                        for ( size_t i = 0 ; i < init->initializers.size() ; ++i ) {
     494                                ast::Designation const * des = init->designations.at(i);
     495                                auto name = designatedName( des );
     496                                if ( nullptr == name ) continue;
     497                                if ( "copy" == name->name ) {
     498                                        foundCopy = true;
     499                                } else if ( "msg" == name->name ) {
     500                                        foundMsg = true;
     501                                }
     502                                auto retInit = retDecl->init.as<ast::ListInit>();
     503                                for ( size_t j = 0 ; j < retInit->initializers.size() ; ++j ) {
     504                                        ast::Designation const * des = retInit->designations.at(j);
     505                                        auto retName = designatedName( des );
     506                                        if ( retName && name->name == retName->name ) {
     507                                                retInit = ast::mutate_field_index( retInit,
     508                                                        &ast::ListInit::initializers, j,
     509                                                        init->initializers.at(i) );
     510                                        }
     511                                }
     512                                retDecl->init = retInit;
     513                        }
     514                }
     515                if ( !foundCopy ) {
     516                        declsToAddBefore.push_back(
     517                                createCopy( location, exceptionName, params ) );
     518                }
     519                if ( !foundMsg ) {
     520                        declsToAddBefore.push_back(
     521                                createMsg( location, exceptionName, params ) );
     522                }
    475523        }
    476524
Note: See TracChangeset for help on using the changeset viewer.