comparison libinterp/parse-tree/oct-parse.yy @ 28518:b8ab8b58547d

accept spmd command blocks as language elements (bug #58676) * pt-spmd.h, pt-spmd.cc: New files. * libinterp/parse-tree/module.mk: Update. * parse.h, oct-parse.yy (base_parser::make_spmd_command): New function. (spmd_command): New non-terminal. (command): Include spmd_command in list of possible commands. * pt-all.h: Also include pt-spmd.h. * pt-walk.h, pt-walk.cc (tree_walker::visit_spmd_command): New virtual function. * pt-eval.h, pt-eval.cc (tree_evaluator::visit_spmd_command): New function. * pt-pr-code.h, pt-pr-code.cc (tree_print_code::visit_spmd_command): New function.
author John W. Eaton <jwe@octave.org>
date Tue, 30 Jun 2020 15:52:25 -0400
parents 6e8a9845d118
children a5541f5a78dd
comparison
equal deleted inserted replaced
28517:6e8a9845d118 28518:b8ab8b58547d
252 %type <tree_argument_list_type> cell_or_matrix_row 252 %type <tree_argument_list_type> cell_or_matrix_row
253 %type <tree_parameter_list_type> opt_param_list param_list 253 %type <tree_parameter_list_type> opt_param_list param_list
254 %type <tree_parameter_list_type> param_list1 param_list2 254 %type <tree_parameter_list_type> param_list1 param_list2
255 %type <tree_parameter_list_type> return_list return_list1 255 %type <tree_parameter_list_type> return_list return_list1
256 %type <tree_command_type> command select_command loop_command 256 %type <tree_command_type> command select_command loop_command
257 %type <tree_command_type> jump_command except_command 257 %type <tree_command_type> jump_command spmd_command except_command
258 %type <tree_function_def_type> function 258 %type <tree_function_def_type> function
259 %type <tree_classdef_type> classdef 259 %type <tree_classdef_type> classdef
260 %type <tree_command_type> file 260 %type <tree_command_type> file
261 %type <tree_if_command_type> if_command 261 %type <tree_if_command_type> if_command
262 %type <tree_if_clause_type> elseif_clause else_clause 262 %type <tree_if_clause_type> elseif_clause else_clause
1051 { $$ = $1; } 1051 { $$ = $1; }
1052 | loop_command 1052 | loop_command
1053 { $$ = $1; } 1053 { $$ = $1; }
1054 | jump_command 1054 | jump_command
1055 { $$ = $1; } 1055 { $$ = $1; }
1056 | spmd_command
1057 { $$ = $1; }
1056 | except_command 1058 | except_command
1057 { $$ = $1; } 1059 { $$ = $1; }
1058 | function 1060 | function
1059 { $$ = $1; } 1061 { $$ = $1; }
1060 | file 1062 | file
1319 if (! ($$ = parser.make_continue_command ($1))) 1321 if (! ($$ = parser.make_continue_command ($1)))
1320 YYABORT; 1322 YYABORT;
1321 } 1323 }
1322 | FUNC_RET 1324 | FUNC_RET
1323 { $$ = parser.make_return_command ($1); } 1325 { $$ = parser.make_return_command ($1); }
1326 ;
1327
1328 // =======================
1329 // Parallel execution pool
1330 // =======================
1331
1332 spmd_command : SPMD stash_comment opt_sep opt_list END
1333 {
1334 YYUSE ($3);
1335
1336 octave::comment_list *lc = $2;
1337 octave::comment_list *tc = lexer.get_comment ();
1338
1339 if (! ($$ = parser.make_spmd_command ($1, $4, $5, lc, tc)))
1340 {
1341 // make_spmd_command deleted $4, LC, and TC.
1342 YYABORT;
1343 }
1344 }
1324 ; 1345 ;
1325 1346
1326 // ========== 1347 // ==========
1327 // Exceptions 1348 // Exceptions
1328 // ========== 1349 // ==========
3219 { 3240 {
3220 int l = return_tok->line (); 3241 int l = return_tok->line ();
3221 int c = return_tok->column (); 3242 int c = return_tok->column ();
3222 3243
3223 return new tree_return_command (l, c); 3244 return new tree_return_command (l, c);
3245 }
3246
3247 // Build an spmd command.
3248
3249 tree_spmd_command *
3250 base_parser::make_spmd_command (token *spmd_tok, tree_statement_list *body,
3251 token *end_tok, comment_list *lc,
3252 comment_list *tc)
3253 {
3254 tree_spmd_command *retval = nullptr;
3255
3256 if (end_token_ok (end_tok, token::if_end))
3257 {
3258 int l = spmd_tok->line ();
3259 int c = spmd_tok->column ();
3260
3261 retval = new tree_spmd_command (body, lc, tc, l, c);
3262 }
3263 else
3264 {
3265 delete body;
3266 delete lc;
3267 delete tc;
3268
3269 end_token_error (end_tok, token::spmd_end);
3270 }
3271
3272 return retval;
3224 } 3273 }
3225 3274
3226 // Start an if command. 3275 // Start an if command.
3227 3276
3228 tree_if_command_list * 3277 tree_if_command_list *