public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Patch: Fix for Bug 26372 [Modula-2] Parsing of multi-subscript arrays
@ 2020-08-25  2:29 Gaius Mulley
  2020-08-25  9:22 ` Andrew Burgess
  2020-08-25  9:29 ` Tom de Vries
  0 siblings, 2 replies; 6+ messages in thread
From: Gaius Mulley @ 2020-08-25  2:29 UTC (permalink / raw)
  To: gdb-patches, gdb, Tom de Vries

[-- Attachment #1: Type: text/plain, Size: 2479 bytes --]



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  <gaiusmod2@gmail.com>

	* 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
===================


[-- Attachment #2: multidimension test case for Modula-2 --]
[-- Type: application/gzip, Size: 1081 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-25 12:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25  2:29 Patch: Fix for Bug 26372 [Modula-2] Parsing of multi-subscript arrays Gaius Mulley
2020-08-25  9:22 ` Andrew Burgess
2020-08-25 12:25   ` Gaius Mulley
2020-08-25  9:29 ` Tom de Vries
2020-08-25  9:36   ` Andrew Burgess
2020-08-25 12:33     ` Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).