From 07758bdfa9e5a762f2ec0deeb51b11d6ad5fe376 Mon Sep 17 00:00:00 2001 From: Gaius Mulley Date: Tue, 25 Aug 2020 11:16:56 +0200 Subject: Fix for Bug 26372 [Modula-2] Parsing of multi-subscript arrays Here is a bugfix for Pr 26372 [Modula-2] Parsing of multi-subscript arrays. Also included is a dejagnu testcase. No extra regressions are caused on Debian GNU/Linux Buster amd64. gdb/ChangeLog: 2020-08-25 Gaius Mulley PR m2/26372 * m2-exp.y: Rewrite array subscript rules to support multidimension array access. (ArgumentList) replaces non_empty_arglist. gdb/testsuite/ChangeLog: 2020-08-25 Gaius Mulley PR m2/26372 * testsuite/gdb.modula2/multidim.exp: New file. * testsuite/gdb.modula2/multidim.c: New file. --- gdb/m2-exp.y | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'gdb/m2-exp.y') diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 70a3d9c483a..dba331f4054 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -293,21 +293,18 @@ set : '{' arglist '}' ; -/* Modula-2 array subscript notation [a,b,c...] */ -exp : exp '[' - /* This function just saves the number of arguments - that follow in the list. It is *not* specific to - function types */ - { pstate->start_arglist(); } - non_empty_arglist ']' %prec DOT - { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); - write_exp_elt_longcst (pstate, - pstate->end_arglist()); - write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); } - ; - -exp : exp '[' exp ']' - { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } +/* Modula-2 array subscript notation [a,b,c...]. */ +exp : exp '[' ArgumentList ']' %prec DOT + { + if (pstate->arglist_len > 1) + { + write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); + write_exp_elt_longcst (pstate, pstate->arglist_len); + write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); + } + else + write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); + } ; exp : exp '(' @@ -321,24 +318,22 @@ exp : exp '(' write_exp_elt_opcode (pstate, OP_FUNCALL); } ; -arglist : - ; - -arglist : exp +/* Non empty argument list. */ +ArgumentList: + exp { pstate->arglist_len = 1; } +| ArgumentList ',' exp + { pstate->arglist_len++; } ; -arglist : arglist ',' exp %prec ABOVE_COMMA - { pstate->arglist_len++; } +arglist : ; -non_empty_arglist - : exp +arglist : exp { pstate->arglist_len = 1; } ; -non_empty_arglist - : non_empty_arglist ',' exp %prec ABOVE_COMMA +arglist : arglist ',' exp %prec ABOVE_COMMA { pstate->arglist_len++; } ; -- cgit v1.2.1