Changeset d464b79


Ignore:
Timestamp:
Jun 30, 2023, 3:59:28 PM (11 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
bdf4cd9
Parents:
4bae7b4
Message:

added flattening so that the mutex statement now can accept tuples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/KeywordsNew.cpp

    r4bae7b4 rd464b79  
    12361236}
    12371237
     1238void flattenTuple( const ast::UntypedTupleExpr * tuple, std::vector<ast::ptr<ast::Expr>> & output ) {
     1239    for ( auto & expr : tuple->exprs ) {
     1240        const ast::UntypedTupleExpr * innerTuple = dynamic_cast<const ast::UntypedTupleExpr *>(expr.get());
     1241        if ( innerTuple ) flattenTuple( innerTuple, output );
     1242        else output.emplace_back( ast::deepCopy( expr ));
     1243    }
     1244}
     1245
    12381246ast::CompoundStmt * MutexKeyword::addStatements(
    12391247                const ast::CompoundStmt * body,
     
    12481256        // std::string lockFnName = mutex_func_namer.newName();
    12491257        // std::string unlockFnName = mutex_func_namer.newName();
     1258
     1259    // If any arguments to the mutex stmt are tuples, flatten them
     1260    std::vector<ast::ptr<ast::Expr>> flattenedArgs;
     1261    for ( auto & arg : args ) {
     1262        const ast::UntypedTupleExpr * tuple = dynamic_cast<const ast::UntypedTupleExpr *>(args.at(0).get());
     1263        if ( tuple ) flattenTuple( tuple, flattenedArgs );
     1264        else flattenedArgs.emplace_back( ast::deepCopy( arg ));
     1265    }
    12501266
    12511267        // Make pointer to the monitors.
     
    12571273                                new ast::VoidType()
    12581274                        ),
    1259                         ast::ConstantExpr::from_ulong( location, args.size() ),
     1275                        ast::ConstantExpr::from_ulong( location, flattenedArgs.size() ),
    12601276                        ast::FixedLen,
    12611277                        ast::DynamicDim
     
    12641280                        location,
    12651281                        map_range<std::vector<ast::ptr<ast::Init>>>(
    1266                                 args, [](const ast::Expr * expr) {
     1282                                flattenedArgs, [](const ast::Expr * expr) {
    12671283                                        return new ast::SingleInit(
    12681284                                                expr->location,
     
    12871303
    12881304        // adds a nested try stmt for each lock we are locking
    1289         for ( long unsigned int i = 0; i < args.size(); i++ ) {
     1305        for ( long unsigned int i = 0; i < flattenedArgs.size(); i++ ) {
    12901306                ast::UntypedExpr * innerAccess = new ast::UntypedExpr(
    12911307                        location,
     
    12981314                // make the try body
    12991315                ast::CompoundStmt * currTryBody = new ast::CompoundStmt( location );
    1300                 ast::IfStmt * lockCall = genTypeDiscrimLockUnlock( "lock", args, location, innerAccess );
     1316                ast::IfStmt * lockCall = genTypeDiscrimLockUnlock( "lock", flattenedArgs, location, innerAccess );
    13011317                currTryBody->push_back( lockCall );
    13021318
    13031319                // make the finally stmt
    13041320                ast::CompoundStmt * currFinallyBody = new ast::CompoundStmt( location );
    1305                 ast::IfStmt * unlockCall = genTypeDiscrimLockUnlock( "unlock", args, location, innerAccess );
     1321                ast::IfStmt * unlockCall = genTypeDiscrimLockUnlock( "unlock", flattenedArgs, location, innerAccess );
    13061322                currFinallyBody->push_back( unlockCall );
    13071323
     
    13431359                                                new ast::SingleInit(
    13441360                                                        location,
    1345                                                         ast::ConstantExpr::from_ulong( location, args.size() ) ),
     1361                                                        ast::ConstantExpr::from_ulong( location, flattenedArgs.size() ) ),
    13461362                                        },
    13471363                                        {},
Note: See TracChangeset for help on using the changeset viewer.