public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Gaius Mulley <gaius.southwales@gmail.com>
To: gdb-patches@sourceware.org, gdb@sourceware.org,
	Tom de Vries <tdevries@suse.de>
Subject: Patch: Fix for Bug 26372 [Modula-2] Parsing of multi-subscript arrays
Date: Tue, 25 Aug 2020 03:29:20 +0100	[thread overview]
Message-ID: <878se3xxtr.fsf@ettard> (raw)

[-- 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 --]

             reply	other threads:[~2020-08-25  2:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25  2:29 Gaius Mulley [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878se3xxtr.fsf@ettard \
    --to=gaius.southwales@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=gdb@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).