Changeset d464b79
- Timestamp:
- Jun 30, 2023, 3:59:28 PM (17 months ago)
- Branches:
- master
- Children:
- bdf4cd9e
- Parents:
- 4bae7b4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/KeywordsNew.cpp
r4bae7b4 rd464b79 1236 1236 } 1237 1237 1238 void 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 1238 1246 ast::CompoundStmt * MutexKeyword::addStatements( 1239 1247 const ast::CompoundStmt * body, … … 1248 1256 // std::string lockFnName = mutex_func_namer.newName(); 1249 1257 // 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 } 1250 1266 1251 1267 // Make pointer to the monitors. … … 1257 1273 new ast::VoidType() 1258 1274 ), 1259 ast::ConstantExpr::from_ulong( location, args.size() ),1275 ast::ConstantExpr::from_ulong( location, flattenedArgs.size() ), 1260 1276 ast::FixedLen, 1261 1277 ast::DynamicDim … … 1264 1280 location, 1265 1281 map_range<std::vector<ast::ptr<ast::Init>>>( 1266 args, [](const ast::Expr * expr) {1282 flattenedArgs, [](const ast::Expr * expr) { 1267 1283 return new ast::SingleInit( 1268 1284 expr->location, … … 1287 1303 1288 1304 // 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++ ) { 1290 1306 ast::UntypedExpr * innerAccess = new ast::UntypedExpr( 1291 1307 location, … … 1298 1314 // make the try body 1299 1315 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 ); 1301 1317 currTryBody->push_back( lockCall ); 1302 1318 1303 1319 // make the finally stmt 1304 1320 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 ); 1306 1322 currFinallyBody->push_back( unlockCall ); 1307 1323 … … 1343 1359 new ast::SingleInit( 1344 1360 location, 1345 ast::ConstantExpr::from_ulong( location, args.size() ) ),1361 ast::ConstantExpr::from_ulong( location, flattenedArgs.size() ) ), 1346 1362 }, 1347 1363 {},
Note: See TracChangeset
for help on using the changeset viewer.