Re: [RFA] Add language-dependent post-parser

Paul Hilfinger
2004-04-07T09:32:46Z

Here is a second version of the post-parser patch I submitted before.
The Ada module will use the post-parser to do static overloaded name
resolution at translation time. The patch gives the current languages
a default nop post-parser.

I think I have addresses Daniel's comments. In this revision, I have
simplified the interface to the post-parser and to
parse_expression_in_context so that instead of an expected type, they
just take a flag indicating whether the client expects a value (as
opposed to simply evaluating for side effects).

At the moment, nothing uses this flag in the public sources. In ACT's
code (in a change I will propose later), we have modified the 'call'
command to use this flag, and our post-parser uses the void/non-void
context distinction to disambiguate between overloaded procedures
(void-returning functions) and value-returning functions. This sort
of limited, context-dependent disambiguation is not useful in C or
C++, but is useful in Ada. We do not implement Ada's full
context-dependent type resolution; for the debugger, that simply turns
out to be overkill.

This better?

Paul Hilfinger
ACT, Inc.

2004-03-04 Paul N. Hilfinger <Hilfinger@gnat.com>

* language.h (language_defn): Add new la_post_parser field.
* parser-defs.h (null_post_parser): New declaration (default for
la_post_parser).

* parse.c (parse_exp_1): Move code to parse_exp_in_context and
insert call to that function.
(parse_exp_in_context): New function, including code formerly in
parse_exp_1. Calls language-dependent post-parser after
prefixification.
(parse_expression_in_context): New exported function.
(null_post_parser): New definition.
* expression.h (parse_expression_in_context): Add declaration.

* p-lang.c (pascal_language_defn): Add trivial post-parser.
* c-lang.c (c_language_defn): Ditto.
(cplus_language_defn): Ditto.
(asm_language_defn): Ditto.
(minimal_language_defn): Ditto.
* f-lang.c (f_language_defn): Ditto.
* jv-lang.c (java_language_defn): Ditto.
* language.c (unknown_language_defn): Ditto.
(auto_language_defn): Ditto.
(local_language_defn): Ditto.
* m2-lang.c (m2_language_defn): Ditto.
* scm-lang.c (scm_language_defn): Ditto.
* obj-lang.c (objc_language_defn): Ditto.

Index: current-public.57/gdb/p-lang.c
--- current-public.57/gdb/p-lang.c Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/e/26_p-lang.c 1.1.1.2.2.1.2.1.1.1.3.1 644)
+++ submit.53(w)/gdb/p-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/e/26_p-lang.c 1.1.1.2.2.1.2.1.1.1.3.1.1.1 644)
@@ -454,6 +454,7 @@ const struct language_defn pascal_langua
&exp_descriptor_standard,
pascal_parse,
pascal_error,
+ null_post_parser,
pascal_printchar, /* Print a character constant */
pascal_printstr, /* Function to print string constant */
pascal_emit_char, /* Print a single char */
Index: current-public.57/gdb/c-lang.c
--- current-public.57/gdb/c-lang.c Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/g/28_c-lang.c 1.1.1.3.2.1.2.1.1.1.3.1 644)
+++ submit.53(w)/gdb/c-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/g/28_c-lang.c 1.1.1.3.2.1.2.1.1.1.3.1.1.1 644)
@@ -546,6 +546,7 @@ const struct language_defn c_language_de
&exp_descriptor_standard,
c_preprocess_and_parse,
c_error,
+ null_post_parser,
c_printchar, /* Print a character constant */
c_printstr, /* Function to print string constant */
c_emit_char, /* Print a single char */
@@ -604,6 +605,7 @@ const struct language_defn cplus_languag
&exp_descriptor_standard,
c_preprocess_and_parse,
c_error,
+ null_post_parser,
c_printchar, /* Print a character constant */
c_printstr, /* Function to print string constant */
c_emit_char, /* Print a single char */
@@ -639,6 +641,7 @@ const struct language_defn asm_language_
&exp_descriptor_standard,
c_preprocess_and_parse,
c_error,
+ null_post_parser,
c_printchar, /* Print a character constant */
c_printstr, /* Function to print string constant */
c_emit_char, /* Print a single char */
@@ -679,6 +682,7 @@ const struct language_defn minimal_langu
&exp_descriptor_standard,
c_preprocess_and_parse,
c_error,
+ null_post_parser,
c_printchar, /* Print a character constant */
c_printstr, /* Function to print string constant */
c_emit_char, /* Print a single char */
Index: current-public.57/gdb/expression.h
--- current-public.57/gdb/expression.h Thu, 25 Sep 2003 23:43:38 -0700 hilfingr (GdbPub/h/30_expression 1.1.1.2.3.1.1.1 644)
+++ submit.53(w)/gdb/expression.h Mon, 05 Apr 2004 03:48:52 -0700 hilfingr (GdbPub/h/30_expression 1.1.1.2.3.1.1.1.2.2 644)
@@ -378,6 +378,8 @@ struct expression

extern struct expression *parse_expression (char *);

+extern struct expression *parse_expression_in_context (char *, int);
+
extern struct expression *parse_exp_1 (char **, struct block *, int);

/* The innermost context required by the stack and register variables
Index: current-public.57/gdb/f-lang.c
--- current-public.57/gdb/f-lang.c Wed, 18 Feb 2004 01:34:45 -0800 hilfingr (GdbPub/h/32_f-lang.c 1.1.1.2.2.1.2.1.1.1.1.1.1.1.3.1.1.1 644)
+++ submit.53(w)/gdb/f-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/h/32_f-lang.c 1.1.1.2.2.1.2.1.1.1.1.1.1.1.3.1.1.1.1.1 644)
@@ -465,6 +465,7 @@ const struct language_defn f_language_de
&exp_descriptor_standard,
f_parse, /* parser */
f_error, /* parser error function */
+ null_post_parser,
f_printchar, /* Print character constant */
f_printstr, /* function to print string constant */
f_emit_char, /* Function to print a single character */
Index: current-public.57/gdb/jv-lang.c
--- current-public.57/gdb/jv-lang.c Mon, 09 Feb 2004 01:03:21 -0800 hilfingr (GdbPub/i/30_jv-lang.c 1.1.1.3.3.1.1.1.2.1.1.1.3.1.1.1 644)
+++ submit.53(w)/gdb/jv-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/i/30_jv-lang.c 1.1.1.3.3.1.1.1.2.1.1.1.3.1.1.1.1.1 644)
@@ -1036,6 +1036,7 @@ const struct language_defn java_language
&exp_descriptor_java,
java_parse,
java_error,
+ null_post_parser,
c_printchar, /* Print a character constant */
c_printstr, /* Function to print string constant */
java_emit_char, /* Function to print a single character */
Index: current-public.57/gdb/language.c
--- current-public.57/gdb/language.c Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/i/34_language.c 1.1.1.3.1.1.3.1.2.1.1.1.1.1.1.1.3.1 644)
+++ submit.53(w)/gdb/language.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/i/34_language.c 1.1.1.3.1.1.3.1.2.1.1.1.1.1.1.1.3.1.1.1 644)
@@ -1279,6 +1279,7 @@ const struct language_defn unknown_langu
&exp_descriptor_standard,
unk_lang_parser,
unk_lang_error,
+ null_post_parser,
unk_lang_printchar, /* Print character constant */
unk_lang_printstr,
unk_lang_emit_char,
@@ -1315,6 +1316,7 @@ const struct language_defn auto_language
&exp_descriptor_standard,
unk_lang_parser,
unk_lang_error,
+ null_post_parser,
unk_lang_printchar, /* Print character constant */
unk_lang_printstr,
unk_lang_emit_char,
@@ -1350,6 +1352,7 @@ const struct language_defn local_languag
&exp_descriptor_standard,
unk_lang_parser,
unk_lang_error,
+ null_post_parser,
unk_lang_printchar, /* Print character constant */
unk_lang_printstr,
unk_lang_emit_char,
Index: current-public.57/gdb/language.h
--- current-public.57/gdb/language.h Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/i/35_language.h 1.1.1.3.1.1.2.1.1.1.3.1 644)
+++ submit.53(w)/gdb/language.h Tue, 06 Apr 2004 00:23:54 -0700 hilfingr (GdbPub/i/35_language.h 1.1.1.3.1.1.2.1.1.1.3.1.1.2 644)
@@ -180,6 +180,14 @@ struct language_defn

void (*la_error) (char *);

+ /* Given an expression *EXPP created by prefixifying the result of
+ la_parser, perform any remaining processing necessary to complete
+ its translation. *EXPP may change; la_post_parser is responsible
+ for releasing its previous contents, if necessary. If
+ VOID_CONTEXT_P, then no value is expected from the expression. */
+
+ void (*la_post_parser) (struct expression ** expp, int void_context_p);
+
void (*la_printchar) (int ch, struct ui_file * stream);

void (*la_printstr) (struct ui_file * stream, char *string,
Index: current-public.57/gdb/m2-lang.c
--- current-public.57/gdb/m2-lang.c Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/i/38_m2-lang.c 1.1.1.2.2.1.2.1.1.1.3.1 644)
+++ submit.53(w)/gdb/m2-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/i/38_m2-lang.c 1.1.1.2.2.1.2.1.1.1.3.1.1.1 644)
@@ -418,6 +418,7 @@ const struct language_defn m2_language_d
&exp_descriptor_standard,
m2_parse, /* parser */
m2_error, /* parser error function */
+ null_post_parser,
m2_printchar, /* Print character constant */
m2_printstr, /* function to print string constant */
m2_emit_char, /* Function to print a single character */
Index: current-public.57/gdb/parse.c
--- current-public.57/gdb/parse.c Wed, 18 Feb 2004 01:34:45 -0800 hilfingr (GdbPub/j/29_parse.c 1.1.1.4.3.1.3.1.1.1.3.1 644)
+++ submit.53(w)/gdb/parse.c Tue, 06 Apr 2004 00:11:39 -0700 hilfingr (GdbPub/j/29_parse.c 1.1.1.4.3.1.3.1.1.1.3.1.1.3 644)
@@ -104,6 +104,9 @@ static void prefixify_expression (struct
static void prefixify_subexp (struct expression *, struct expression *, int,
int);

+static struct expression *parse_exp_in_context (char **, struct block *, int,
+ int);
+
void _initialize_parse (void);

/* Data structure for saving values of arglist_len for function calls whose
@@ -1023,6 +1026,16 @@ prefixify_subexp (struct expression *ine
struct expression *
parse_exp_1 (char **stringptr, struct block *block, int comma)
{
+ return parse_exp_in_context (stringptr, block, comma, 0);
+}
+
+/* As for parse_exp_1, except that if VOID_CONTEXT_P, then
+ no value is expected from the expression. */
+
+static struct expression *
+parse_exp_in_context (char **stringptr, struct block *block, int comma,
+ int void_context_p)
+{
struct cleanup *old_chain;

lexptr = *stringptr;
@@ -1078,6 +1091,8 @@ parse_exp_1 (char **stringptr, struct bl

prefixify_expression (expout);

+ current_language->la_post_parser (&expout, void_context_p);
+
if (expressiondebug)
dump_prefix_expression (expout, gdb_stdlog);

@@ -1096,6 +1111,28 @@ parse_expression (char *string)
if (*string)
error ("Junk after end of expression.");
return exp;
+}
+
+
+/* As for parse_expression, except that if VOID_CONTEXT_P, then
+ no value is expected from the expression. */
+
+struct expression *
+parse_expression_in_context (char *string, int void_context_p)
+{
+ struct expression *exp;
+ exp = parse_exp_in_context (&string, 0, 0, void_context_p);
+ if (*string != '\000')
+ error ("Junk after end of expression.");
+ return exp;
+}
+
+/* A post-parser that does nothing */
+
+/* ARGSUSED */
+void
+null_post_parser (struct expression **exp, int void_context_p)
+{
}
\f
/* Stuff for maintaining a stack of types. Currently just used by C, but
Index: current-public.57/gdb/parser-defs.h
--- current-public.57/gdb/parser-defs.h Thu, 25 Sep 2003 23:43:38 -0700 hilfingr (GdbPub/j/30_parser-def 1.1.1.2.4.1.1.1 644)
+++ submit.53(w)/gdb/parser-defs.h Tue, 06 Apr 2004 00:12:13 -0700 hilfingr (GdbPub/j/30_parser-def 1.1.1.2.4.1.1.1.3.2 644)
@@ -172,6 +172,8 @@ extern char *op_name_standard (enum exp_

extern struct type *follow_types (struct type *);

+extern void null_post_parser (struct expression **, int);
+
/* During parsing of a C expression, the pointer to the next character
is in this variable. */

Index: current-public.57/gdb/scm-lang.c
--- current-public.57/gdb/scm-lang.c Sun, 25 Jan 2004 23:26:24 -0800 hilfingr (GdbPub/k/14_scm-lang.c 1.1.1.3.2.1.2.1.1.1.3.1 644)
+++ submit.53(w)/gdb/scm-lang.c Thu, 04 Mar 2004 02:20:35 -0800 hilfingr (GdbPub/k/14_scm-lang.c 1.1.1.3.2.1.2.1.1.1.3.1.1.1 644)
@@ -253,6 +253,7 @@ const struct language_defn scm_language_
&exp_descriptor_scm,
scm_parse,
c_error,
+ null_post_parser,
scm_printchar, /* Print a character constant */
scm_printstr, /* Function to print string constant */
NULL, /* Function to print a single character */
Index: current-public.57/gdb/objc-lang.c
--- current-public.57/gdb/objc-lang.c Wed, 18 Feb 2004 01:34:45 -0800 hilfingr (GdbPub/C/b/24_objc-lang. 1.4.3.1.2.1.1.1.3.1.1.1 644)
+++ submit.53(w)/gdb/objc-lang.c Sat, 06 Mar 2004 02:52:55 -0800 hilfingr (GdbPub/C/b/24_objc-lang. 1.4.3.1.2.1.1.1.3.1.1.1.1.2 644)
@@ -662,6 +662,7 @@ const struct language_defn objc_language
&exp_descriptor_standard,
objc_parse,
objc_error,
+ null_post_parser,
objc_printchar, /* Print a character constant */
objc_printstr, /* Function to print string constant */
objc_emit_char,