Patch: Fix for Bug 26372 [Modula-2] Parsing of multi-subscript arrays

Gaius Mulley via Gdb-patches <[email protected]>
Newsgroups gmane.comp.gdb.patches,gmane.comp.gdb.devel
Message-ID <878se3xxtr.fsf@ettard>

Hi Tom,

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, is this ok to apply?

regards,
Gaius


gdb/ChangeLog entry
===================

2020-08-25  Gaius Mulley  <[email protected]>

	* m2-exp.y: Rewrite array subscript rules to support multidimension
	array access.  (ArgumentList) replaces non_empty_arglist.
	* testsuite/gdb.modula2/multidim.y:  (New file).
	* testsuite/gdb.modula2/multidim.c:  (New file).

Patch
=====

diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 70a3d9c483..ea5c83e60a 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++; }
 	;



and simple testcase
===================
gdb-testsuite.tar.gz (application/gzip, 1.1 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.