public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC 0/8] Beginning to remove globals from parser-defs.h
@ 2012-01-15 18:51 Sergio Durigan Junior
  2012-01-15 18:56 ` [RFC 1/8] Language independent bits Sergio Durigan Junior
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 18:51 UTC (permalink / raw)
  To: gdb-patches

Hello,

I have been working on this during my weekends, and I would like to know
what you guys think about this set of patches.

While I was working on another patch, I started to dive into the current
expression parsing mechanism, and it really bothered me all those
globals.  So, as a pet project, I decided to start removing them.
Initially I tried to remove them all, and create a big structure which
would hold the parsing state and be passed to parser-specific functions.
Unfortunately, this task proved to be non-sense because of its size and
increasing complexity, so I decided to tackle the problem using another
way: baby steps, as Tom would say.

These 8 patches basically contain adaptations on every .y file, as well
as on the *-lang.h ones, and on parser-defs.h/parse.c files.  The idea
now is to make three fields non-global: `expout', `expout_size' and
`expout_ptr'.  There are still some (lots of?) other global variables
there, which I didn't touch yet.  Maybe some day I will have
time/patience for that...

I decided to split the patches because the whole diff file contains more
than 7 thousand lines.  However, I did not bother to make those patches
compile independently!  So if you want to test, you'll have to apply
them all (order should not matter).

I hope you like the result.  It is still far from ideal, but I believe
it is a good step towards this "non-globalization" thing.

Comments, as usual, are welcome.  The patch has been regtested on an
x86_64 and i686 Fedora 15, without regressions.

Thank you,

Sergio.

P.S.: I still haven't written the ChangeLog's, I wanted to know your
opinion about it first.

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

* [RFC 1/8] Language independent bits
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
@ 2012-01-15 18:56 ` Sergio Durigan Junior
  2012-01-15 21:08   ` Jan Kratochvil
  2012-01-15 19:01 ` [RFC 2/8] C language Sergio Durigan Junior
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 18:56 UTC (permalink / raw)
  To: gdb-patches

Hi,

This is the first patch, which does a refactoring on
gdb/{parse.c,parser-defs.h,language.*} to accommodate the changes.  It
basically creates a new strucutre called `parser_state', which holds the
`expout*' fields mentioned in the previous message.

Thanks,

Sergio.

diff --git a/gdb/language.c b/gdb/language.c
index d70ae81..b02fc5b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -47,9 +47,9 @@
 
 extern void _initialize_language (void);
 
-static void unk_lang_error (char *);
+static void unk_lang_error (struct parser_state *, char *);
 
-static int unk_lang_parser (void);
+static int unk_lang_parser (struct parser_state *);
 
 static void show_check (char *, int);
 
@@ -803,13 +803,13 @@ default_get_string (struct value *value, gdb_byte **buffer, int *length,
 /* Define the language that is no language.  */
 
 static int
-unk_lang_parser (void)
+unk_lang_parser (struct parser_state *ps)
 {
   return 1;
 }
 
 static void
-unk_lang_error (char *msg)
+unk_lang_error (struct parser_state *ps, char *msg)
 {
   error (_("Attempted to parse an expression with unknown language"));
 }
diff --git a/gdb/language.h b/gdb/language.h
index 2ea2dca..6faf9c7 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -31,6 +31,7 @@ struct frame_info;
 struct expression;
 struct ui_file;
 struct value_print_options;
+struct parser_state;
 
 #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
 
@@ -172,11 +173,11 @@ struct language_defn
 
     /* Parser function.  */
 
-    int (*la_parser) (void);
+    int (*la_parser) (struct parser_state *);
 
     /* Parser error function.  */
 
-    void (*la_error) (char *);
+    void (*la_error) (struct parser_state *, char *);
 
     /* Given an expression *EXPP created by prefixifying the result of
        la_parser, perform any remaining processing necessary to complete
diff --git a/gdb/parse.c b/gdb/parse.c
index f405dc5..5dc6429 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -68,9 +68,6 @@ const struct exp_descriptor exp_descriptor_standard =
   };
 \f
 /* Global variables declared in parser-defs.h (and commented there).  */
-struct expression *expout;
-int expout_size;
-int expout_ptr;
 struct block *expression_context_block;
 CORE_ADDR expression_context_pc;
 struct block *innermost_block;
@@ -179,6 +176,45 @@ free_funcalls (void *ignore)
     }
 }
 \f
+
+/* Helper function used to initialize an struct expression that is going
+   to be used to store expression elements.  The arguments are the
+   parser_state PS containing the EXPOUT, the INITIAL_SIZE of the expression,
+   the language LANG parsed to build this expression, and the GDBARCH
+   pointer.  */
+
+static void
+initialize_expout (struct parser_state *ps, int initial_size,
+		   const struct language_defn *lang,
+		   struct gdbarch *gdbarch)
+{
+  ps->expout_size = initial_size;
+  ps->expout_ptr = 0;
+  ps->expout = (struct expression *)
+    xmalloc (sizeof (struct expression)
+    + EXP_ELEM_TO_BYTES (ps->expout_size));
+  ps->expout->language_defn = lang;
+  ps->expout->gdbarch = gdbarch;
+}
+
+/* Helper function that reallocates the EXPOUT inside PS in order to
+   eliminate any unused space.  It is generally used when the expression
+   has just been parsed and created.  */
+
+static void
+reallocate_expout (struct parser_state *ps)
+{
+  /* Record the actual number of expression elements, and then
+     reallocate the expression memory so that we free up any
+     excess elements.  */
+
+  ps->expout->nelts = ps->expout_ptr;
+  ps->expout = (struct expression *)
+     xrealloc (ps->expout,
+	       sizeof (struct expression)
+	       + EXP_ELEM_TO_BYTES (ps->expout_ptr));
+}
+
 /* This page contains the functions for adding data to the struct expression
    being constructed.  */
 
@@ -188,80 +224,80 @@ free_funcalls (void *ignore)
    a register through here.  */
 
 static void
-write_exp_elt (const union exp_element *expelt)
+write_exp_elt (struct parser_state *ps, const union exp_element *expelt)
 {
-  if (expout_ptr >= expout_size)
+  if (ps->expout_ptr >= ps->expout_size)
     {
-      expout_size *= 2;
-      expout = (struct expression *)
-	xrealloc ((char *) expout, sizeof (struct expression)
-		  + EXP_ELEM_TO_BYTES (expout_size));
+      ps->expout_size *= 2;
+      ps->expout = (struct expression *)
+	xrealloc (ps->expout, sizeof (struct expression)
+		  + EXP_ELEM_TO_BYTES (ps->expout_size));
     }
-  expout->elts[expout_ptr++] = *expelt;
+  ps->expout->elts[ps->expout_ptr++] = *expelt;
 }
 
 void
-write_exp_elt_opcode (enum exp_opcode expelt)
+write_exp_elt_opcode (struct parser_state *ps, enum exp_opcode expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.opcode = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_sym (struct symbol *expelt)
+write_exp_elt_sym (struct parser_state *ps, struct symbol *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.symbol = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_block (struct block *b)
+write_exp_elt_block (struct parser_state *ps, struct block *b)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.block = b;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_objfile (struct objfile *objfile)
+write_exp_elt_objfile (struct parser_state *ps, struct objfile *objfile)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.objfile = objfile;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_longcst (LONGEST expelt)
+write_exp_elt_longcst (struct parser_state *ps, LONGEST expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.longconst = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_dblcst (DOUBLEST expelt)
+write_exp_elt_dblcst (struct parser_state *ps, DOUBLEST expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.doubleconst = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_decfloatcst (gdb_byte expelt[16])
+write_exp_elt_decfloatcst (struct parser_state *ps, gdb_byte expelt[16])
 {
   union exp_element tmp;
   int index;
@@ -269,27 +305,27 @@ write_exp_elt_decfloatcst (gdb_byte expelt[16])
   for (index = 0; index < 16; index++)
     tmp.decfloatconst[index] = expelt[index];
 
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_type (struct type *expelt)
+write_exp_elt_type (struct parser_state *ps, struct type *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.type = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_intern (struct internalvar *expelt)
+write_exp_elt_intern (struct parser_state *ps, struct internalvar *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.internalvar = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 /* Add a string constant to the end of the expression.
@@ -314,7 +350,7 @@ write_exp_elt_intern (struct internalvar *expelt)
 
 
 void
-write_exp_string (struct stoken str)
+write_exp_string (struct parser_state *ps, struct stoken str)
 {
   int len = str.length;
   int lenelt;
@@ -327,28 +363,19 @@ write_exp_string (struct stoken str)
 
   lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1);
 
-  /* Ensure that we have enough available expression elements to store
-     everything.  */
-
-  if ((expout_ptr + lenelt) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, lenelt);
 
   /* Write the leading length expression element (which advances the current
      expression element index), then write the string constant followed by a
      terminating null byte, and then write the trailing length expression
      element.  */
 
-  write_exp_elt_longcst ((LONGEST) len);
-  strdata = (char *) &expout->elts[expout_ptr];
+  write_exp_elt_longcst (ps, (LONGEST) len);
+  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
   memcpy (strdata, str.ptr, len);
   *(strdata + len) = '\0';
-  expout_ptr += lenelt - 2;
-  write_exp_elt_longcst ((LONGEST) len);
+  ps->expout_ptr += lenelt - 2;
+  write_exp_elt_longcst (ps, (LONGEST) len);
 }
 
 /* Add a vector of string constants to the end of the expression.
@@ -365,7 +392,8 @@ write_exp_string (struct stoken str)
    long constant, followed by the contents of the string.  */
 
 void
-write_exp_string_vector (int type, struct stoken_vector *vec)
+write_exp_string_vector (struct parser_state *ps, int type,
+			 struct stoken_vector *vec)
 {
   int i, n_slots, len;
 
@@ -386,28 +414,22 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
   len = EXP_ELEM_TO_BYTES (n_slots) - 1;
 
   n_slots += 4;
-  if ((expout_ptr + n_slots) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + n_slots + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, n_slots);
 
-  write_exp_elt_opcode (OP_STRING);
-  write_exp_elt_longcst (len);
-  write_exp_elt_longcst (type);
+  write_exp_elt_opcode (ps, OP_STRING);
+  write_exp_elt_longcst (ps, len);
+  write_exp_elt_longcst (ps, type);
 
   for (i = 0; i < vec->len; ++i)
     {
-      write_exp_elt_longcst (vec->tokens[i].length);
-      memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr,
+      write_exp_elt_longcst (ps, vec->tokens[i].length);
+      memcpy (&ps->expout->elts[ps->expout_ptr], vec->tokens[i].ptr,
 	      vec->tokens[i].length);
-      expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
+      ps->expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
     }
 
-  write_exp_elt_longcst (len);
-  write_exp_elt_opcode (OP_STRING);
+  write_exp_elt_longcst (ps, len);
+  write_exp_elt_opcode (ps, OP_STRING);
 }
 
 /* Add a bitstring constant to the end of the expression.
@@ -422,7 +444,7 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
    either end of the bitstring.  */
 
 void
-write_exp_bitstring (struct stoken str)
+write_exp_bitstring (struct parser_state *ps, struct stoken str)
 {
   int bits = str.length;	/* length in bits */
   int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
@@ -435,33 +457,24 @@ write_exp_bitstring (struct stoken str)
 
   lenelt = 2 + BYTES_TO_EXP_ELEM (len);
 
-  /* Ensure that we have enough available expression elements to store
-     everything.  */
-
-  if ((expout_ptr + lenelt) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, lenelt);
 
   /* Write the leading length expression element (which advances the current
      expression element index), then write the bitstring constant, and then
      write the trailing length expression element.  */
 
-  write_exp_elt_longcst ((LONGEST) bits);
-  strdata = (char *) &expout->elts[expout_ptr];
+  write_exp_elt_longcst (ps, (LONGEST) bits);
+  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
   memcpy (strdata, str.ptr, len);
-  expout_ptr += lenelt - 2;
-  write_exp_elt_longcst ((LONGEST) bits);
+  ps->expout_ptr += lenelt - 2;
+  write_exp_elt_longcst (ps, (LONGEST) bits);
 }
 
 /* Add the appropriate elements for a minimal symbol to the end of
    the expression.  */
 
 void
-write_exp_msymbol (struct minimal_symbol *msymbol)
+write_exp_msymbol (struct parser_state *ps, struct minimal_symbol *msymbol)
 {
   struct objfile *objfile = msymbol_objfile (msymbol);
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -499,60 +512,60 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
   if (overlay_debugging)
     addr = symbol_overlayed_address (addr, section);
 
-  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_opcode (ps, OP_LONG);
   /* Let's make the type big enough to hold a 64-bit address.  */
-  write_exp_elt_type (objfile_type (objfile)->builtin_core_addr);
-  write_exp_elt_longcst ((LONGEST) addr);
-  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_type (ps, objfile_type (objfile)->builtin_core_addr);
+  write_exp_elt_longcst (ps, (LONGEST) addr);
+  write_exp_elt_opcode (ps, OP_LONG);
 
   if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL)
     {
-      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
-      write_exp_elt_objfile (objfile);
-      write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol);
-      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
+      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
+      write_exp_elt_objfile (ps, objfile);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_tls_symbol);
+      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
       return;
     }
 
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (ps, UNOP_MEMVAL);
   switch (type)
     {
     case mst_text:
     case mst_file_text:
     case mst_solib_trampoline:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_text_symbol);
       break;
 
     case mst_text_gnu_ifunc:
-      write_exp_elt_type (objfile_type (objfile)
-					       ->nodebug_text_gnu_ifunc_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)
+			  ->nodebug_text_gnu_ifunc_symbol);
       break;
 
     case mst_data:
     case mst_file_data:
     case mst_bss:
     case mst_file_bss:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_data_symbol);
       break;
 
     case mst_slot_got_plt:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_got_plt_symbol);
       break;
 
     default:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_unknown_symbol);
       break;
     }
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (ps, UNOP_MEMVAL);
 }
 
 /* Mark the current index as the starting location of a structure
    expression.  This is used when completing on field names.  */
 
 void
-mark_struct_expression (void)
+mark_struct_expression (struct parser_state *ps)
 {
-  expout_last_struct = expout_ptr;
+  expout_last_struct = ps->expout_ptr;
 }
 
 \f
@@ -578,7 +591,7 @@ mark_struct_expression (void)
    value in the value history, I.e. $$1  */
 
 void
-write_dollar_variable (struct stoken str)
+write_dollar_variable (struct parser_state *ps, struct stoken str)
 {
   struct symbol *sym = NULL;
   struct minimal_symbol *msym = NULL;
@@ -616,7 +629,7 @@ write_dollar_variable (struct stoken str)
 
   /* Handle tokens that refer to machine registers:
      $ followed by a register name.  */
-  i = user_reg_map_name_to_regnum (parse_gdbarch,
+  i = user_reg_map_name_to_regnum (parse_gdbarch (ps),
 				   str.ptr + 1, str.length - 1);
   if (i >= 0)
     goto handle_register;
@@ -626,9 +639,9 @@ write_dollar_variable (struct stoken str)
   isym = lookup_only_internalvar (copy_name (str) + 1);
   if (isym)
     {
-      write_exp_elt_opcode (OP_INTERNALVAR);
-      write_exp_elt_intern (isym);
-      write_exp_elt_opcode (OP_INTERNALVAR);
+      write_exp_elt_opcode (ps, OP_INTERNALVAR);
+      write_exp_elt_intern (ps, isym);
+      write_exp_elt_opcode (ps, OP_INTERNALVAR);
       return;
     }
 
@@ -639,36 +652,36 @@ write_dollar_variable (struct stoken str)
 		       VAR_DOMAIN, (int *) NULL);
   if (sym)
     {
-      write_exp_elt_opcode (OP_VAR_VALUE);
-      write_exp_elt_block (block_found);	/* set by lookup_symbol */
-      write_exp_elt_sym (sym);
-      write_exp_elt_opcode (OP_VAR_VALUE);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
+      write_exp_elt_block (ps, block_found);	/* set by lookup_symbol */
+      write_exp_elt_sym (ps, sym);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
       return;
     }
   msym = lookup_minimal_symbol (copy_name (str), NULL, NULL);
   if (msym)
     {
-      write_exp_msymbol (msym);
+      write_exp_msymbol (ps, msym);
       return;
     }
 
   /* Any other names are assumed to be debugger internal variables.  */
 
-  write_exp_elt_opcode (OP_INTERNALVAR);
-  write_exp_elt_intern (create_internalvar (copy_name (str) + 1));
-  write_exp_elt_opcode (OP_INTERNALVAR);
+  write_exp_elt_opcode (ps, OP_INTERNALVAR);
+  write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1));
+  write_exp_elt_opcode (ps, OP_INTERNALVAR);
   return;
 handle_last:
-  write_exp_elt_opcode (OP_LAST);
-  write_exp_elt_longcst ((LONGEST) i);
-  write_exp_elt_opcode (OP_LAST);
+  write_exp_elt_opcode (ps, OP_LAST);
+  write_exp_elt_longcst (ps, (LONGEST) i);
+  write_exp_elt_opcode (ps, OP_LAST);
   return;
 handle_register:
-  write_exp_elt_opcode (OP_REGISTER);
+  write_exp_elt_opcode (ps, OP_REGISTER);
   str.length--;
   str.ptr++;
-  write_exp_string (str);
-  write_exp_elt_opcode (OP_REGISTER);
+  write_exp_string (ps, str);
+  write_exp_elt_opcode (ps, OP_REGISTER);
   return;
 }
 
@@ -1093,6 +1106,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   volatile struct gdb_exception except;
   struct cleanup *old_chain;
   const struct language_defn *lang = NULL;
+  struct parser_state ps;
   int subexp;
 
   lexptr = *stringptr;
@@ -1156,56 +1170,44 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   else
     lang = current_language;
 
-  expout_size = 10;
-  expout_ptr = 0;
-  expout = (struct expression *)
-    xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
-  expout->language_defn = lang;
-  expout->gdbarch = get_current_arch ();
+  initialize_expout (&ps, 10, lang, get_current_arch ());
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      if (lang->la_parser ())
-        lang->la_error (NULL);
+      if (lang->la_parser (&ps))
+        lang->la_error (&ps, NULL);
     }
   if (except.reason < 0)
     {
       if (! in_parse_field)
 	{
-	  xfree (expout);
+	  xfree (ps.expout);
 	  throw_exception (except);
 	}
     }
 
   discard_cleanups (old_chain);
 
-  /* Record the actual number of expression elements, and then
-     reallocate the expression memory so that we free up any
-     excess elements.  */
-
-  expout->nelts = expout_ptr;
-  expout = (struct expression *)
-    xrealloc ((char *) expout,
-	      sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));
+  reallocate_expout (&ps);
 
   /* Convert expression from postfix form as generated by yacc
      parser, to a prefix form.  */
 
   if (expressiondebug)
-    dump_raw_expression (expout, gdb_stdlog,
+    dump_raw_expression (ps.expout, gdb_stdlog,
 			 "before conversion to prefix form");
 
-  subexp = prefixify_expression (expout);
+  subexp = prefixify_expression (ps.expout);
   if (out_subexp)
     *out_subexp = subexp;
 
-  lang->la_post_parser (&expout, void_context_p);
+  lang->la_post_parser (&ps.expout, void_context_p);
 
   if (expressiondebug)
-    dump_prefix_expression (expout, gdb_stdlog);
+    dump_prefix_expression (ps.expout, gdb_stdlog);
 
   *stringptr = lexptr;
-  return expout;
+  return ps.expout;
 }
 
 /* Parse STRING as an expression, and complain if this fails
@@ -1372,9 +1374,9 @@ push_type_int (int n)
 }
 
 void
-push_type_address_space (char *string)
+push_type_address_space (struct parser_state *ps, char *string)
 {
-  push_type_int (address_space_name_to_int (parse_gdbarch, string));
+  push_type_int (address_space_name_to_int (parse_gdbarch (ps), string));
 }
 
 enum type_pieces
@@ -1644,6 +1646,21 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
   return exp_iterate (exp, exp_uses_objfile_iter, objfile);
 }
 
+/* See definition in parser-defs.h.  */
+
+void
+increase_expout_size (struct parser_state *ps, int lenelt)
+{
+  if ((ps->expout_ptr + lenelt) >= ps->expout_size)
+    {
+      ps->expout_size = max (ps->expout_size * 2,
+			     ps->expout_ptr + lenelt + 10);
+      ps->expout = (struct expression *)
+	xrealloc (ps->expout, (sizeof (struct expression)
+			       + EXP_ELEM_TO_BYTES (ps->expout_size)));
+    }
+}
+
 void
 _initialize_parse (void)
 {
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 16b40ac..20632d2 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -30,12 +30,24 @@ struct block;
 
 extern int parser_debug;
 
-extern struct expression *expout;
-extern int expout_size;
-extern int expout_ptr;
+#define parse_gdbarch(ps) (ps->expout->gdbarch)
+#define parse_language(ps) (ps->expout->language_defn)
 
-#define parse_gdbarch (expout->gdbarch)
-#define parse_language (expout->language_defn)
+struct parser_state {
+
+    /* The expression related to this parser state.  */
+
+    struct expression *expout;
+
+    /* The size of the expression above.  */
+
+    int expout_size;
+
+    /* The number of elements already in the expression.  This is used
+       to know where to put new elements.  */
+
+    int expout_ptr;
+};
 
 /* If this is nonzero, this block is used as the lexical context
    for symbol names.  */
@@ -130,35 +142,38 @@ union type_stack_elt
 extern union type_stack_elt *type_stack;
 extern int type_stack_depth, type_stack_size;
 
-extern void write_exp_elt_opcode (enum exp_opcode);
+extern void write_exp_elt_opcode (struct parser_state *, enum exp_opcode);
 
-extern void write_exp_elt_sym (struct symbol *);
+extern void write_exp_elt_sym (struct parser_state *, struct symbol *);
 
-extern void write_exp_elt_longcst (LONGEST);
+extern void write_exp_elt_longcst (struct parser_state *, LONGEST);
 
-extern void write_exp_elt_dblcst (DOUBLEST);
+extern void write_exp_elt_dblcst (struct parser_state *, DOUBLEST);
 
-extern void write_exp_elt_decfloatcst (gdb_byte *);
+extern void write_exp_elt_decfloatcst (struct parser_state *, gdb_byte *);
 
-extern void write_exp_elt_type (struct type *);
+extern void write_exp_elt_type (struct parser_state *, struct type *);
 
-extern void write_exp_elt_intern (struct internalvar *);
+extern void write_exp_elt_intern (struct parser_state *, struct internalvar *);
 
-extern void write_exp_string (struct stoken);
+extern void write_exp_string (struct parser_state *, struct stoken);
 
-void write_exp_string_vector (int type, struct stoken_vector *vec);
+void write_exp_string_vector (struct parser_state *, int type,
+			      struct stoken_vector *vec);
 
-extern void write_exp_bitstring (struct stoken);
+extern void write_exp_bitstring (struct parser_state *, struct stoken);
 
-extern void write_exp_elt_block (struct block *);
+extern void write_exp_elt_block (struct parser_state *, struct block *);
 
-extern void write_exp_elt_objfile (struct objfile *objfile);
+extern void write_exp_elt_objfile (struct parser_state *,
+				   struct objfile *objfile);
 
-extern void write_exp_msymbol (struct minimal_symbol *);
+extern void write_exp_msymbol (struct parser_state *,
+			       struct minimal_symbol *);
 
-extern void write_dollar_variable (struct stoken str);
+extern void write_dollar_variable (struct parser_state *, struct stoken str);
 
-extern void mark_struct_expression (void);
+extern void mark_struct_expression (struct parser_state *);
 
 extern char *find_template_name_end (char *);
 
@@ -172,7 +187,7 @@ extern void push_type (enum type_pieces);
 
 extern void push_type_int (int);
 
-extern void push_type_address_space (char *);
+extern void push_type_address_space (struct parser_state *, char *);
 
 extern enum type_pieces pop_type (void);
 
@@ -315,4 +330,11 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
 
 extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
 
+/* Reallocate the `expout' pointer inside PS so that it can accommodate
+   at least LENELT expression elements.  This function does nothing if
+   there is enough room for the elements.  */
+
+extern void increase_expout_size (struct parser_state *ps, int lenelt);
+
+
 #endif /* PARSER_DEFS_H */
-- 
1.7.6.4

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

* [RFC 2/8] C language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
  2012-01-15 18:56 ` [RFC 1/8] Language independent bits Sergio Durigan Junior
@ 2012-01-15 19:01 ` Sergio Durigan Junior
  2012-01-16 19:29   ` Tom Tromey
  2012-01-15 19:04 ` [RFC 3/8] Ada language Sergio Durigan Junior
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:01 UTC (permalink / raw)
  To: gdb-patches

Hi,

This patch modifies gdb/{c-exp.y,c-lang.h} in order to reflect the
changes made by the first patch of the series.

Here and in all the .y files, I had to add an argument to the parser and
the lexer functions, which is a `struct parser_state *ps'.

Thanks,

Sergio.

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index bf4f4bc..139cf67 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -54,7 +54,7 @@
 #include "gdb_assert.h"
 #include "macroscope.h"
 
-#define parse_type builtin_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -110,14 +110,17 @@
 
 #define YYFPRINTF parser_fprintf
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -155,7 +158,8 @@ void yyerror (char *);
 
 %{
 /* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *ps, char *, int, int,
+			 YYSTYPE *);
 static struct stoken operator_stoken (const char *);
 %}
 
@@ -252,134 +256,134 @@ start   :	exp1
 	;
 
 type_exp:	type
-			{ write_exp_elt_opcode(OP_TYPE);
-			  write_exp_elt_type($1);
-			  write_exp_elt_opcode(OP_TYPE);}
+			{ write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, OP_TYPE);}
 	;
 
 /* Expressions, including the comma operator.  */
 exp1	:	exp
 	|	exp1 ',' exp
-			{ write_exp_elt_opcode (BINOP_COMMA); }
+			{ write_exp_elt_opcode (ps, BINOP_COMMA); }
 	;
 
 /* Expressions, not including the comma operator.  */
 exp	:	'*' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_IND); }
+			{ write_exp_elt_opcode (ps, UNOP_IND); }
 	;
 
 exp	:	'&' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_ADDR); }
+			{ write_exp_elt_opcode (ps, UNOP_ADDR); }
 	;
 
 exp	:	'-' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_NEG); }
+			{ write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 exp	:	'+' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PLUS); }
+			{ write_exp_elt_opcode (ps, UNOP_PLUS); }
 	;
 
 exp	:	'!' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 exp	:	'~' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_COMPLEMENT); }
 	;
 
 exp	:	INCREMENT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREINCREMENT); }
 	;
 
 exp	:	DECREMENT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREDECREMENT); }
 	;
 
 exp	:	exp INCREMENT    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_POSTINCREMENT); }
 	;
 
 exp	:	exp DECREMENT    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_POSTDECREMENT); }
 	;
 
 exp	:	SIZEOF exp       %prec UNARY
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 	;
 
 exp	:	exp ARROW name
-			{ write_exp_elt_opcode (STRUCTOP_PTR);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_PTR); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR); }
 	;
 
 exp	:	exp ARROW name COMPLETE
-			{ mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_PTR);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_PTR); }
+			{ mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR); }
 	;
 
 exp	:	exp ARROW COMPLETE
 			{ struct stoken s;
-			  mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_PTR);
+			  mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR);
 			  s.ptr = "";
 			  s.length = 0;
-			  write_exp_string (s);
-			  write_exp_elt_opcode (STRUCTOP_PTR); }
+			  write_exp_string (ps, s);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR); }
 	;
 
 exp	:	exp ARROW qualified_name
 			{ /* exp->type::name becomes exp->*(&type::name) */
 			  /* Note: this doesn't work if name is a
 			     static member!  FIXME */
-			  write_exp_elt_opcode (UNOP_ADDR);
-			  write_exp_elt_opcode (STRUCTOP_MPTR); }
+			  write_exp_elt_opcode (ps, UNOP_ADDR);
+			  write_exp_elt_opcode (ps, STRUCTOP_MPTR); }
 	;
 
 exp	:	exp ARROW_STAR exp
-			{ write_exp_elt_opcode (STRUCTOP_MPTR); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_MPTR); }
 	;
 
 exp	:	exp '.' name
-			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 exp	:	exp '.' name COMPLETE
-			{ mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			{ mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 exp	:	exp '.' COMPLETE
 			{ struct stoken s;
-			  mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
+			  mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
 			  s.ptr = "";
 			  s.length = 0;
-			  write_exp_string (s);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			  write_exp_string (ps, s);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 exp	:	exp '.' qualified_name
 			{ /* exp.type::name becomes exp.*(&type::name) */
 			  /* Note: this doesn't work if name is a
 			     static member!  FIXME */
-			  write_exp_elt_opcode (UNOP_ADDR);
-			  write_exp_elt_opcode (STRUCTOP_MEMBER); }
+			  write_exp_elt_opcode (ps, UNOP_ADDR);
+			  write_exp_elt_opcode (ps, STRUCTOP_MEMBER); }
 	;
 
 exp	:	exp DOT_STAR exp
-			{ write_exp_elt_opcode (STRUCTOP_MEMBER); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_MEMBER); }
 	;
 
 exp	:	exp '[' exp1 ']'
-			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+			{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 	;
 
 exp	:	exp '(' 
@@ -387,20 +391,20 @@ exp	:	exp '('
 			   being accumulated by an outer function call.  */
 			{ start_arglist (); }
 		arglist ')'	%prec ARROW
-			{ write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_FUNCALL); }
+			{ write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_FUNCALL); }
 	;
 
 exp	:	UNKNOWN_CPP_NAME '('
 			{
 			  /* This could potentially be a an argument defined
 			     lookup function (Koenig).  */
-			  write_exp_elt_opcode (OP_ADL_FUNC);
-			  write_exp_elt_block (expression_context_block);
-			  write_exp_elt_sym (NULL); /* Placeholder.  */
-			  write_exp_string ($1.stoken);
-			  write_exp_elt_opcode (OP_ADL_FUNC);
+			  write_exp_elt_opcode (ps, OP_ADL_FUNC);
+			  write_exp_elt_block (ps, expression_context_block);
+			  write_exp_elt_sym (ps, NULL); /* Placeholder.  */
+			  write_exp_string (ps, $1.stoken);
+			  write_exp_elt_opcode (ps, OP_ADL_FUNC);
 
 			/* This is to save the value of arglist_len
 			   being accumulated by an outer function call.  */
@@ -409,9 +413,9 @@ exp	:	UNKNOWN_CPP_NAME '('
 			}
 		arglist ')'	%prec ARROW
 			{
-			  write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_FUNCALL);
+			  write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_FUNCALL);
 			}
 	;
 
@@ -432,12 +436,12 @@ arglist	:	arglist ',' exp   %prec ABOVE_COMMA
 
 exp     :       exp '(' nonempty_typelist ')' const_or_volatile
 			{ int i;
-			  write_exp_elt_opcode (TYPE_INSTANCE);
-			  write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
+			  write_exp_elt_opcode (ps, TYPE_INSTANCE);
+			  write_exp_elt_longcst (ps, (LONGEST) $<ivec>3[0]);
 			  for (i = 0; i < $<ivec>3[0]; ++i)
-			    write_exp_elt_type ($<tvec>3[i + 1]);
-			  write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
-			  write_exp_elt_opcode (TYPE_INSTANCE);
+			    write_exp_elt_type (ps, $<tvec>3[i + 1]);
+			  write_exp_elt_longcst (ps, (LONGEST) $<ivec>3[0]);
+			  write_exp_elt_opcode (ps, TYPE_INSTANCE);
 			  free ($3);
 			}
 	;
@@ -446,22 +450,22 @@ rcurly	:	'}'
 			{ $$ = end_arglist () - 1; }
 	;
 exp	:	lcurly arglist rcurly	%prec ARROW
-			{ write_exp_elt_opcode (OP_ARRAY);
-			  write_exp_elt_longcst ((LONGEST) 0);
-			  write_exp_elt_longcst ((LONGEST) $3);
-			  write_exp_elt_opcode (OP_ARRAY); }
+			{ write_exp_elt_opcode (ps, OP_ARRAY);
+			  write_exp_elt_longcst (ps, (LONGEST) 0);
+			  write_exp_elt_longcst (ps, (LONGEST) $3);
+			  write_exp_elt_opcode (ps, OP_ARRAY); }
 	;
 
 exp	:	lcurly type rcurly exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_MEMVAL);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_MEMVAL); }
+			{ write_exp_elt_opcode (ps, UNOP_MEMVAL);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_MEMVAL); }
 	;
 
 exp	:	'(' type ')' exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 exp	:	'(' exp1 ')'
@@ -471,100 +475,100 @@ exp	:	'(' exp1 ')'
 /* Binary operators in order of decreasing precedence.  */
 
 exp	:	exp '@' exp
-			{ write_exp_elt_opcode (BINOP_REPEAT); }
+			{ write_exp_elt_opcode (ps, BINOP_REPEAT); }
 	;
 
 exp	:	exp '*' exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 exp	:	exp '/' exp
-			{ write_exp_elt_opcode (BINOP_DIV); }
+			{ write_exp_elt_opcode (ps, BINOP_DIV); }
 	;
 
 exp	:	exp '%' exp
-			{ write_exp_elt_opcode (BINOP_REM); }
+			{ write_exp_elt_opcode (ps, BINOP_REM); }
 	;
 
 exp	:	exp '+' exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 exp	:	exp '-' exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 exp	:	exp LSH exp
-			{ write_exp_elt_opcode (BINOP_LSH); }
+			{ write_exp_elt_opcode (ps, BINOP_LSH); }
 	;
 
 exp	:	exp RSH exp
-			{ write_exp_elt_opcode (BINOP_RSH); }
+			{ write_exp_elt_opcode (ps, BINOP_RSH); }
 	;
 
 exp	:	exp EQUAL exp
-			{ write_exp_elt_opcode (BINOP_EQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 	;
 
 exp	:	exp NOTEQUAL exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 	;
 
 exp	:	exp LEQ exp
-			{ write_exp_elt_opcode (BINOP_LEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 	;
 
 exp	:	exp GEQ exp
-			{ write_exp_elt_opcode (BINOP_GEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 	;
 
 exp	:	exp '<' exp
-			{ write_exp_elt_opcode (BINOP_LESS); }
+			{ write_exp_elt_opcode (ps, BINOP_LESS); }
 	;
 
 exp	:	exp '>' exp
-			{ write_exp_elt_opcode (BINOP_GTR); }
+			{ write_exp_elt_opcode (ps, BINOP_GTR); }
 	;
 
 exp	:	exp '&' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	;
 
 exp	:	exp '^' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 	;
 
 exp	:	exp '|' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	;
 
 exp	:	exp ANDAND exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 	;
 
 exp	:	exp OROR exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 	;
 
 exp	:	exp '?' exp ':' exp	%prec '?'
-			{ write_exp_elt_opcode (TERNOP_COND); }
+			{ write_exp_elt_opcode (ps, TERNOP_COND); }
 	;
 			  
 exp	:	exp '=' exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 exp	:	exp ASSIGN_MODIFY exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
-			  write_exp_elt_opcode ($2);
-			  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+			  write_exp_elt_opcode (ps, $2);
+			  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 	;
 
 exp	:	INT
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_longcst ((LONGEST)($1.val));
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_longcst (ps, (LONGEST) ($1.val));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	CHAR
@@ -572,33 +576,34 @@ exp	:	CHAR
 			  struct stoken_vector vec;
 			  vec.len = 1;
 			  vec.tokens = &$1;
-			  write_exp_string_vector ($1.type, &vec);
+			  write_exp_string_vector (ps, $1.type, &vec);
 			}
 	;
 
 exp	:	NAME_OR_INT
 			{ YYSTYPE val;
-			  parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (val.typed_val_int.type);
-			  write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
-			  write_exp_elt_opcode (OP_LONG);
+			  parse_number (ps, $1.stoken.ptr, $1.stoken.length,
+					0, &val);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, val.typed_val_int.type);
+			  write_exp_elt_longcst (ps, (LONGEST) val.typed_val_int.val);
+			  write_exp_elt_opcode (ps, OP_LONG);
 			}
 	;
 
 
 exp	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_dblcst ($1.dval);
-			  write_exp_elt_opcode (OP_DOUBLE); }
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_dblcst (ps, $1.dval);
+			  write_exp_elt_opcode (ps, OP_DOUBLE); }
 	;
 
 exp	:	DECFLOAT
-			{ write_exp_elt_opcode (OP_DECFLOAT);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_decfloatcst ($1.val);
-			  write_exp_elt_opcode (OP_DECFLOAT); }
+			{ write_exp_elt_opcode (ps, OP_DECFLOAT);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_decfloatcst (ps, $1.val);
+			  write_exp_elt_opcode (ps, OP_DECFLOAT); }
 	;
 
 exp	:	variable
@@ -606,44 +611,45 @@ exp	:	variable
 
 exp	:	VARIABLE
 			{
-			  write_dollar_variable ($1);
+			  write_dollar_variable (ps, $1);
 			}
 	;
 
 exp	:	SIZEOF '(' type ')'	%prec UNARY
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (lookup_signed_typename
-					      (parse_language, parse_gdbarch,
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, lookup_signed_typename
+					      (parse_language (ps),
+					       parse_gdbarch (ps),
 					       "int"));
 			  CHECK_TYPEDEF ($3);
-			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
-			  write_exp_elt_opcode (OP_LONG); }
+			  write_exp_elt_longcst (ps, (LONGEST) TYPE_LENGTH ($3));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	REINTERPRET_CAST '<' type '>' '(' exp ')' %prec UNARY
-			{ write_exp_elt_opcode (UNOP_REINTERPRET_CAST);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_REINTERPRET_CAST);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_REINTERPRET_CAST); }
 	;
 
 exp	:	STATIC_CAST '<' type '>' '(' exp ')' %prec UNARY
-			{ write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 exp	:	DYNAMIC_CAST '<' type '>' '(' exp ')' %prec UNARY
-			{ write_exp_elt_opcode (UNOP_DYNAMIC_CAST);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_DYNAMIC_CAST);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_DYNAMIC_CAST); }
 	;
 
 exp	:	CONST_CAST '<' type '>' '(' exp ')' %prec UNARY
 			{ /* We could do more error checking here, but
 			     it doesn't seem worthwhile.  */
-			  write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_CAST); }
+			  write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 string_exp:
@@ -708,7 +714,7 @@ exp	:	string_exp
 				}
 			    }
 
-			  write_exp_string_vector (type, &$1);
+			  write_exp_string_vector (ps, type, &$1);
 			  for (i = 0; i < $1.len; ++i)
 			    free ($1.tokens[i].ptr);
 			  free ($1.tokens);
@@ -717,17 +723,17 @@ exp	:	string_exp
 
 /* C++.  */
 exp     :       TRUEKEYWORD    
-                        { write_exp_elt_opcode (OP_LONG);
-                          write_exp_elt_type (parse_type->builtin_bool);
-                          write_exp_elt_longcst ((LONGEST) 1);
-                          write_exp_elt_opcode (OP_LONG); }
+                        { write_exp_elt_opcode (ps, OP_LONG);
+                          write_exp_elt_type (ps, parse_type (ps)->builtin_bool);
+                          write_exp_elt_longcst (ps, (LONGEST) 1);
+                          write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp     :       FALSEKEYWORD   
-                        { write_exp_elt_opcode (OP_LONG);
-                          write_exp_elt_type (parse_type->builtin_bool);
-                          write_exp_elt_longcst ((LONGEST) 0);
-                          write_exp_elt_opcode (OP_LONG); }
+                        { write_exp_elt_opcode (ps, OP_LONG);
+                          write_exp_elt_type (ps, parse_type (ps)->builtin_bool);
+                          write_exp_elt_longcst (ps, (LONGEST) 0);
+                          write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 /* end of C++.  */
@@ -765,9 +771,9 @@ variable:	name_not_typename ENTRY
 				     "parameters, not for \"%s\""),
 				   copy_name ($1.stoken));
 
-			  write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
-			  write_exp_elt_sym (sym);
-			  write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
+			  write_exp_elt_opcode (ps, OP_VAR_ENTRY_VALUE);
+			  write_exp_elt_sym (ps, sym);
+			  write_exp_elt_opcode (ps, OP_VAR_ENTRY_VALUE);
 			}
 	;
 
@@ -786,11 +792,11 @@ variable:	block COLONCOLON name
 				innermost_block = block_found;
 			    }
 
-			  write_exp_elt_opcode (OP_VAR_VALUE);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			  /* block_found is set by lookup_symbol.  */
-			  write_exp_elt_block (block_found);
-			  write_exp_elt_sym (sym);
-			  write_exp_elt_opcode (OP_VAR_VALUE); }
+			  write_exp_elt_block (ps, block_found);
+			  write_exp_elt_sym (ps, sym);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE); }
 	;
 
 qualified_name:	TYPENAME COLONCOLON name
@@ -803,10 +809,10 @@ qualified_name:	TYPENAME COLONCOLON name
 			    error (_("`%s' is not defined as an aggregate type."),
 				   TYPE_NAME (type));
 
-			  write_exp_elt_opcode (OP_SCOPE);
-			  write_exp_elt_type (type);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (OP_SCOPE);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
+			  write_exp_elt_type (ps, type);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
 			}
 	|	TYPENAME COLONCOLON '~' name
 			{
@@ -827,10 +833,10 @@ qualified_name:	TYPENAME COLONCOLON name
 
 			  /* Check for valid destructor name.  */
 			  destructor_name_p (tmp_token.ptr, $1.type);
-			  write_exp_elt_opcode (OP_SCOPE);
-			  write_exp_elt_type (type);
-			  write_exp_string (tmp_token);
-			  write_exp_elt_opcode (OP_SCOPE);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
+			  write_exp_elt_type (ps, type);
+			  write_exp_string (ps, tmp_token);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
 			}
 	|	TYPENAME COLONCOLON name COLONCOLON name
 			{
@@ -853,16 +859,16 @@ variable:	qualified_name
 					   VAR_DOMAIN, (int *) NULL);
 			  if (sym)
 			    {
-			      write_exp_elt_opcode (OP_VAR_VALUE);
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      break;
 			    }
 
 			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
 			  if (msymbol != NULL)
-			    write_exp_msymbol (msymbol);
+			    write_exp_msymbol (ps, msymbol);
 			  else if (!have_full_symbols () && !have_partial_symbols ())
 			    error (_("No symbol table is loaded.  Use the \"file\" command."));
 			  else
@@ -883,13 +889,13 @@ variable:	name_not_typename
 				    innermost_block = block_found;
 				}
 
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      /* We want to use the selected frame, not
 				 another more inner frame which happens to
 				 be in the same block.  */
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			    }
 			  else if ($1.is_a_field_of_this)
 			    {
@@ -900,11 +906,11 @@ variable:	name_not_typename
 				  || contained_in (block_found,
 						   innermost_block))
 				innermost_block = block_found;
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
-			      write_exp_string ($1.stoken);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			      write_exp_string (ps, $1.stoken);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
 			    }
 			  else
 			    {
@@ -914,7 +920,7 @@ variable:	name_not_typename
 			      msymbol =
 				lookup_minimal_symbol (arg, NULL, NULL);
 			      if (msymbol != NULL)
-				write_exp_msymbol (msymbol);
+				write_exp_msymbol (ps, msymbol);
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  Use the \"file\" command."));
 			      else
@@ -925,7 +931,7 @@ variable:	name_not_typename
 	;
 
 space_identifier : '@' NAME
-		{ push_type_address_space (copy_name ($2.stoken));
+		{ push_type_address_space (ps, copy_name ($2.stoken));
 		  push_type (tp_space_identifier);
 		}
 	;
@@ -1004,115 +1010,115 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 	:	TYPENAME
 			{ $$ = $1.type; }
 	|	INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "int"); }
 	|	LONG
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long"); }
 	|	SHORT
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "short"); }
 	|	LONG INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long"); }
 	|	LONG SIGNED_KEYWORD INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long"); }
 	|	LONG SIGNED_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long"); }
 	|	SIGNED_KEYWORD LONG INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long"); }
 	|	UNSIGNED LONG INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long"); }
 	|	LONG UNSIGNED INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long"); }
 	|	LONG UNSIGNED
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long"); }
 	|	LONG LONG
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	LONG LONG INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	LONG LONG SIGNED_KEYWORD INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	LONG LONG SIGNED_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	SIGNED_KEYWORD LONG LONG
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	SIGNED_KEYWORD LONG LONG INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "long long"); }
 	|	UNSIGNED LONG LONG
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long long"); }
 	|	UNSIGNED LONG LONG INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long long"); }
 	|	LONG LONG UNSIGNED
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long long"); }
 	|	LONG LONG UNSIGNED INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "long long"); }
 	|	SHORT INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "short"); }
 	|	SHORT SIGNED_KEYWORD INT_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "short"); }
 	|	SHORT SIGNED_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "short"); }
 	|	UNSIGNED SHORT INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "short"); }
 	|	SHORT UNSIGNED 
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "short"); }
 	|	SHORT UNSIGNED INT_KEYWORD
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "short"); }
 	|	DOUBLE_KEYWORD
-			{ $$ = lookup_typename (parse_language, parse_gdbarch,
+			{ $$ = lookup_typename (parse_language (ps), parse_gdbarch (ps),
 						"double", (struct block *) NULL,
 						0); }
 	|	LONG DOUBLE_KEYWORD
-			{ $$ = lookup_typename (parse_language, parse_gdbarch,
+			{ $$ = lookup_typename (parse_language (ps), parse_gdbarch (ps),
 						"long double",
 						(struct block *) NULL, 0); }
 	|	STRUCT name
@@ -1128,20 +1134,20 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			{ $$ = lookup_enum (copy_name ($2),
 					    expression_context_block); }
 	|	UNSIGNED typename
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 TYPE_NAME($2.type)); }
 	|	UNSIGNED
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 "int"); }
 	|	SIGNED_KEYWORD typename
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       TYPE_NAME($2.type)); }
 	|	SIGNED_KEYWORD
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       "int"); }
                 /* It appears that this rule for templates is never
                    reduced; template recognition happens by lookahead
@@ -1161,24 +1167,24 @@ typename:	TYPENAME
 		{
 		  $$.stoken.ptr = "int";
 		  $$.stoken.length = 3;
-		  $$.type = lookup_signed_typename (parse_language,
-						    parse_gdbarch,
+		  $$.type = lookup_signed_typename (parse_language (ps),
+						    parse_gdbarch (ps),
 						    "int");
 		}
 	|	LONG
 		{
 		  $$.stoken.ptr = "long";
 		  $$.stoken.length = 4;
-		  $$.type = lookup_signed_typename (parse_language,
-						    parse_gdbarch,
+		  $$.type = lookup_signed_typename (parse_language (ps),
+						    parse_gdbarch (ps),
 						    "long");
 		}
 	|	SHORT
 		{
 		  $$.stoken.ptr = "short";
 		  $$.stoken.length = 5;
-		  $$.type = lookup_signed_typename (parse_language,
-						    parse_gdbarch,
+		  $$.type = lookup_signed_typename (parse_language (ps),
+						    parse_gdbarch (ps),
 						    "short");
 		}
 	;
@@ -1388,7 +1394,8 @@ operator_stoken (const char *op)
 /*** Needs some error checking for the float case ***/
 
 static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (struct parser_state *ps, char *p, int len, int parsed_float,
+	      YYSTYPE *putithere)
 {
   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
      here, and we do kind of silly things like cast to unsigned.  */
@@ -1423,9 +1430,9 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 	{
 	  p[len - 2] = '\0';
 	  putithere->typed_val_decfloat.type
-	    = parse_type->builtin_decfloat;
+	    = parse_type (ps)->builtin_decfloat;
 	  decimal_from_string (putithere->typed_val_decfloat.val, 4,
-			       gdbarch_byte_order (parse_gdbarch), p);
+			       gdbarch_byte_order (parse_gdbarch (ps)), p);
 	  p[len - 2] = 'd';
 	  return DECFLOAT;
 	}
@@ -1434,9 +1441,9 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 	{
 	  p[len - 2] = '\0';
 	  putithere->typed_val_decfloat.type
-	    = parse_type->builtin_decdouble;
+	    = parse_type (ps)->builtin_decdouble;
 	  decimal_from_string (putithere->typed_val_decfloat.val, 8,
-			       gdbarch_byte_order (parse_gdbarch), p);
+			       gdbarch_byte_order (parse_gdbarch (ps)), p);
 	  p[len - 2] = 'd';
 	  return DECFLOAT;
 	}
@@ -1445,14 +1452,14 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 	{
 	  p[len - 2] = '\0';
 	  putithere->typed_val_decfloat.type
-	    = parse_type->builtin_declong;
+	    = parse_type (ps)->builtin_declong;
 	  decimal_from_string (putithere->typed_val_decfloat.val, 16,
-			       gdbarch_byte_order (parse_gdbarch), p);
+			       gdbarch_byte_order (parse_gdbarch (ps)), p);
 	  p[len - 2] = 'd';
 	  return DECFLOAT;
 	}
 
-      if (! parse_c_float (parse_gdbarch, p, len,
+      if (! parse_c_float (parse_gdbarch (ps), p, len,
 			   &putithere->typed_val_float.dval,
 			   &putithere->typed_val_float.type))
 	return ERROR;
@@ -1568,9 +1575,9 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 
   un = (ULONGEST)n >> 2;
   if (long_p == 0
-      && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
+      && (un >> (gdbarch_int_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (ps)) - 1);
 
       /* A large decimal (not hex or octal) constant (between INT_MAX
 	 and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -1578,28 +1585,28 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 	 int.  This probably should be fixed.  GCC gives a warning on
 	 such constants.  */
 
-      unsigned_type = parse_type->builtin_unsigned_int;
-      signed_type = parse_type->builtin_int;
+      unsigned_type = parse_type (ps)->builtin_unsigned_int;
+      signed_type = parse_type (ps)->builtin_int;
     }
   else if (long_p <= 1
-	   && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+	   && (un >> (gdbarch_long_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
-      unsigned_type = parse_type->builtin_unsigned_long;
-      signed_type = parse_type->builtin_long;
+      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (ps)) - 1);
+      unsigned_type = parse_type (ps)->builtin_unsigned_long;
+      signed_type = parse_type (ps)->builtin_long;
     }
   else
     {
       int shift;
       if (sizeof (ULONGEST) * HOST_CHAR_BIT 
-	  < gdbarch_long_long_bit (parse_gdbarch))
+	  < gdbarch_long_long_bit (parse_gdbarch (ps)))
 	/* A long long does not fit in a LONGEST.  */
 	shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
       else
-	shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
+	shift = (gdbarch_long_long_bit (parse_gdbarch (ps)) - 1);
       high_bit = (ULONGEST) 1 << shift;
-      unsigned_type = parse_type->builtin_unsigned_long_long;
-      signed_type = parse_type->builtin_long_long;
+      unsigned_type = parse_type (ps)->builtin_unsigned_long_long;
+      signed_type = parse_type (ps)->builtin_long_long;
     }
 
    putithere->typed_val_int.val = n;
@@ -2066,7 +2073,7 @@ static int last_was_structop;
 /* Read one token, getting characters through lexptr.  */
 
 static int
-lex_one_token (void)
+lex_one_token (struct parser_state *ps)
 {
   int c;
   int namelen;
@@ -2098,7 +2105,7 @@ lex_one_token (void)
     if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
       {
 	if (tokentab3[i].cxx_only
-	    && parse_language->la_language != language_cplus)
+	    && parse_language (ps)->la_language != language_cplus)
 	  break;
 
 	lexptr += 3;
@@ -2111,7 +2118,7 @@ lex_one_token (void)
     if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
       {
 	if (tokentab2[i].cxx_only
-	    && parse_language->la_language != language_cplus)
+	    && parse_language (ps)->la_language != language_cplus)
 	  break;
 
 	lexptr += 2;
@@ -2233,7 +2240,8 @@ lex_one_token (void)
 				  && (*p < 'A' || *p > 'Z')))
 	      break;
 	  }
-	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
+	toktype = parse_number (ps, tokstart, p - tokstart, got_dot|got_e,
+				&yylval);
         if (toktype == ERROR)
 	  {
 	    char *err_copy = (char *) alloca (p - tokstart + 1);
@@ -2385,7 +2393,7 @@ lex_one_token (void)
     if (strcmp (copy, ident_tokens[i].operator) == 0)
       {
 	if (ident_tokens[i].cxx_only
-	    && parse_language->la_language != language_cplus)
+	    && parse_language (ps)->la_language != language_cplus)
 	  break;
 
 	/* It is ok to always set this, even though we don't always
@@ -2427,7 +2435,7 @@ static struct obstack name_obstack;
    in which lookups start; this can be NULL to mean the global
    scope.  */
 static int
-classify_name (struct block *block)
+classify_name (struct parser_state *ps, struct block *block)
 {
   struct symbol *sym;
   char *copy;
@@ -2436,7 +2444,7 @@ classify_name (struct block *block)
   copy = copy_name (yylval.sval);
 
   sym = lookup_symbol (copy, block, VAR_DOMAIN, 
-		       parse_language->la_language == language_cplus
+		       parse_language (ps)->la_language == language_cplus
 		       ? &is_a_field_of_this : (int *) NULL);
 
   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
@@ -2465,8 +2473,8 @@ classify_name (struct block *block)
     }
 
   yylval.tsym.type
-    = language_lookup_primitive_type_by_name (parse_language,
-					      parse_gdbarch, copy);
+    = language_lookup_primitive_type_by_name (parse_language (ps),
+					      parse_gdbarch (ps), copy);
   if (yylval.tsym.type != NULL)
     return TYPENAME;
 
@@ -2478,7 +2486,7 @@ classify_name (struct block *block)
 	  || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
     {
       YYSTYPE newlval;	/* Its value is ignored.  */
-      int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
+      int hextype = parse_number (ps, copy, yylval.sval.length, 0, &newlval);
       if (hextype == INT)
 	{
 	  yylval.ssym.sym = sym;
@@ -2492,7 +2500,7 @@ classify_name (struct block *block)
   yylval.ssym.is_a_field_of_this = is_a_field_of_this;
 
   if (sym == NULL
-      && parse_language->la_language == language_cplus
+      && parse_language (ps)->la_language == language_cplus
       && !is_a_field_of_this
       && !lookup_minimal_symbol (copy, NULL, NULL))
     return UNKNOWN_CPP_NAME;
@@ -2506,13 +2514,14 @@ classify_name (struct block *block)
    this function returns NAME, it might not have updated `yylval'.
    This is ok because the caller only cares about TYPENAME.  */
 static int
-classify_inner_name (struct block *block, int first_name)
+classify_inner_name (struct parser_state *ps, struct block *block,
+		     int first_name)
 {
   struct type *type, *new_type;
   char *copy;
 
   if (first_name)
-    return classify_name (block);
+    return classify_name (ps, block);
 
   type = check_typedef (yylval.tsym.type);
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
@@ -2544,7 +2553,7 @@ classify_inner_name (struct block *block, int first_name)
    this is still an improvement over the earlier approach, and will
    suffice until we move to better parsing technology.  */
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   token_and_value current;
   int first_was_coloncolon, last_was_coloncolon, first_iter;
@@ -2558,10 +2567,10 @@ yylex (void)
     }
   popping = 0;
 
-  current.token = lex_one_token ();
+  current.token = lex_one_token (ps);
   if (current.token == NAME)
-    current.token = classify_name (expression_context_block);
-  if (parse_language->la_language != language_cplus
+    current.token = classify_name (ps, expression_context_block);
+  if (parse_language (ps)->la_language != language_cplus
       || (current.token != TYPENAME && current.token != COLONCOLON))
     return current.token;
 
@@ -2576,14 +2585,14 @@ yylex (void)
     {
       token_and_value next;
 
-      next.token = lex_one_token ();
+      next.token = lex_one_token (ps);
       next.value = yylval;
 
       if (next.token == NAME && last_was_coloncolon)
 	{
 	  int classification;
 
-	  classification = classify_inner_name (first_was_coloncolon
+	  classification = classify_inner_name (ps, first_was_coloncolon
 						? NULL
 						: expression_context_block,
 						first_iter);
@@ -2648,7 +2657,7 @@ yylex (void)
 }
 
 int
-c_parse (void)
+c_parse (struct parser_state *ps)
 {
   int result;
   struct cleanup *back_to = make_cleanup (free_current_contents,
@@ -2682,14 +2691,14 @@ c_parse (void)
   obstack_init (&name_obstack);
   make_cleanup_obstack_free (&name_obstack);
 
-  result = yyparse ();
+  result = yyparse (ps);
   do_cleanups (back_to);
   return result;
 }
 
 
 void
-yyerror (char *msg)
+yyerror (struct parser_state *ps, char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index e8c632f..1003b8d 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -24,6 +24,7 @@
 
 struct ui_file;
 struct language_arch_info;
+struct parser_state;
 
 #include "value.h"
 #include "macroexp.h"
@@ -57,9 +58,9 @@ enum c_string_type
 
 /* Defined in c-exp.y.  */
 
-extern int c_parse (void);
+extern int c_parse (struct parser_state *);
 
-extern void c_error (char *);
+extern void c_error (struct parser_state *, char *);
 
 extern int c_parse_escape (char **, struct obstack *);

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

* [RFC 3/8] Ada language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
  2012-01-15 18:56 ` [RFC 1/8] Language independent bits Sergio Durigan Junior
  2012-01-15 19:01 ` [RFC 2/8] C language Sergio Durigan Junior
@ 2012-01-15 19:04 ` Sergio Durigan Junior
  2012-01-15 19:05 ` [RFC 4/8] Fortran language Sergio Durigan Junior
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:04 UTC (permalink / raw)
  To: gdb-patches

Hi,

This patch reflects the changes for Ada language files.

Thanks,

Sergio.

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index d8c21a4..7c3be14 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -50,7 +50,7 @@
 #include "frame.h"
 #include "block.h"
 
-#define parse_type builtin_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -114,51 +114,58 @@ static struct stoken empty_stoken = { "", 0 };
  * NULL.  */
 static struct type *type_qualifier;
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 static struct stoken string_to_operator (struct stoken);
 
-static void write_int (LONGEST, struct type *);
+static void write_int (struct parser_state *, LONGEST, struct type *);
 
-static void write_object_renaming (struct block *, const char *, int,
+static void write_object_renaming (struct parser_state *, struct block *,
+				   const char *, int,
 				   const char *, int);
 
-static struct type* write_var_or_type (struct block *, struct stoken);
+static struct type* write_var_or_type (struct parser_state *, struct block *,
+				       struct stoken);
 
-static void write_name_assoc (struct stoken);
+static void write_name_assoc (struct parser_state *, struct stoken);
 
-static void write_exp_op_with_string (enum exp_opcode, struct stoken);
+static void write_exp_op_with_string (struct parser_state *, enum exp_opcode,
+				      struct stoken);
 
 static struct block *block_lookup (struct block *, char *);
 
 static LONGEST convert_char_literal (struct type *, LONGEST);
 
-static void write_ambiguous_var (struct block *, char *, int);
+static void write_ambiguous_var (struct parser_state *, struct block *,
+				 char *, int);
 
-static struct type *type_int (void);
+static struct type *type_int (struct parser_state *);
 
-static struct type *type_long (void);
+static struct type *type_long (struct parser_state *);
 
-static struct type *type_long_long (void);
+static struct type *type_long_long (struct parser_state *);
 
-static struct type *type_float (void);
+static struct type *type_float (struct parser_state *);
 
-static struct type *type_double (void);
+static struct type *type_double (struct parser_state *);
 
-static struct type *type_long_double (void);
+static struct type *type_long_double (struct parser_state *);
 
-static struct type *type_char (void);
+static struct type *type_char (struct parser_state *);
 
-static struct type *type_boolean (void);
+static struct type *type_boolean (struct parser_state *);
 
-static struct type *type_system_address (void);
+static struct type *type_system_address (struct parser_state *);
 
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 %union
   {
     LONGEST lval;
@@ -231,25 +238,25 @@ start   :	exp1
 /* Expressions, including the sequencing operator.  */
 exp1	:	exp
 	|	exp1 ';' exp
-			{ write_exp_elt_opcode (BINOP_COMMA); }
+			{ write_exp_elt_opcode (ps, BINOP_COMMA); }
 	| 	primary ASSIGN exp   /* Extension for convenience */
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 /* Expressions, not including the sequencing operator.  */
 primary :	primary DOT_ALL
-			{ write_exp_elt_opcode (UNOP_IND); }
+			{ write_exp_elt_opcode (ps, UNOP_IND); }
 	;
 
 primary :	primary DOT_ID
-			{ write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
+			{ write_exp_op_with_string (ps, STRUCTOP_STRUCT, $2); }
 	;
 
 primary :	primary '(' arglist ')'
 			{
-			  write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ($3);
-			  write_exp_elt_opcode (OP_FUNCALL);
+			  write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, $3);
+			  write_exp_elt_opcode (ps, OP_FUNCALL);
 		        }
 	|	var_or_type '(' arglist ')'
 			{
@@ -257,15 +264,15 @@ primary :	primary '(' arglist ')'
 			    {
 			      if ($3 != 1)
 				error (_("Invalid conversion"));
-			      write_exp_elt_opcode (UNOP_CAST);
-			      write_exp_elt_type ($1);
-			      write_exp_elt_opcode (UNOP_CAST);
+			      write_exp_elt_opcode (ps, UNOP_CAST);
+			      write_exp_elt_type (ps, $1);
+			      write_exp_elt_opcode (ps, UNOP_CAST);
 			    }
 			  else
 			    {
-			      write_exp_elt_opcode (OP_FUNCALL);
-			      write_exp_elt_longcst ($3);
-			      write_exp_elt_opcode (OP_FUNCALL);
+			      write_exp_elt_opcode (ps, OP_FUNCALL);
+			      write_exp_elt_longcst (ps, $3);
+			      write_exp_elt_opcode (ps, OP_FUNCALL);
 			    }
 			}
 	;
@@ -275,9 +282,9 @@ primary :	var_or_type '\'' save_qualifier { type_qualifier = $1; }
 			{
 			  if ($1 == NULL)
 			    error (_("Type required for qualification"));
-			  write_exp_elt_opcode (UNOP_QUAL);
-			  write_exp_elt_type ($1);
-			  write_exp_elt_opcode (UNOP_QUAL);
+			  write_exp_elt_opcode (ps, UNOP_QUAL);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, UNOP_QUAL);
 			  type_qualifier = $3;
 			}
 	;
@@ -287,10 +294,10 @@ save_qualifier : 	{ $$ = type_qualifier; }
 
 primary :
 		primary '(' simple_exp DOTDOT simple_exp ')'
-			{ write_exp_elt_opcode (TERNOP_SLICE); }
+			{ write_exp_elt_opcode (ps, TERNOP_SLICE); }
 	|	var_or_type '(' simple_exp DOTDOT simple_exp ')'
 			{ if ($1 == NULL) 
-                            write_exp_elt_opcode (TERNOP_SLICE);
+                            write_exp_elt_opcode (ps, TERNOP_SLICE);
 			  else
 			    error (_("Cannot slice a type"));
 			}
@@ -310,15 +317,15 @@ primary :	'(' exp1 ')'	{ }
 primary :	var_or_type	%prec VAR
 			{ if ($1 != NULL)
 			    {
-			      write_exp_elt_opcode (OP_TYPE);
-			      write_exp_elt_type ($1);
-			      write_exp_elt_opcode (OP_TYPE);
+			      write_exp_elt_opcode (ps, OP_TYPE);
+			      write_exp_elt_type (ps, $1);
+			      write_exp_elt_opcode (ps, OP_TYPE);
 			    }
 			}
 	;
 
 primary :	SPECIAL_VARIABLE /* Various GDB extensions */
-			{ write_dollar_variable ($1); }
+			{ write_dollar_variable (ps, $1); }
 	;
 
 primary :     	aggregate
@@ -328,19 +335,19 @@ simple_exp : 	primary
 	;
 
 simple_exp :	'-' simple_exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_NEG); }
+			{ write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 simple_exp :	'+' simple_exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PLUS); }
+			{ write_exp_elt_opcode (ps, UNOP_PLUS); }
 	;
 
 simple_exp :	NOT simple_exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 simple_exp :    ABS simple_exp	   %prec UNARY
-			{ write_exp_elt_opcode (UNOP_ABS); }
+			{ write_exp_elt_opcode (ps, UNOP_ABS); }
 	;
 
 arglist	:		{ $$ = 0; }
@@ -361,111 +368,111 @@ primary :	'{' var_or_type '}' primary  %prec '.'
 			{ 
 			  if ($2 == NULL)
 			    error (_("Type required within braces in coercion"));
-			  write_exp_elt_opcode (UNOP_MEMVAL);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_MEMVAL);
+			  write_exp_elt_opcode (ps, UNOP_MEMVAL);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_MEMVAL);
 			}
 	;
 
 /* Binary operators in order of decreasing precedence.  */
 
 simple_exp 	: 	simple_exp STARSTAR simple_exp
-			{ write_exp_elt_opcode (BINOP_EXP); }
+			{ write_exp_elt_opcode (ps, BINOP_EXP); }
 	;
 
 simple_exp	:	simple_exp '*' simple_exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 simple_exp	:	simple_exp '/' simple_exp
-			{ write_exp_elt_opcode (BINOP_DIV); }
+			{ write_exp_elt_opcode (ps, BINOP_DIV); }
 	;
 
 simple_exp	:	simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
-			{ write_exp_elt_opcode (BINOP_REM); }
+			{ write_exp_elt_opcode (ps, BINOP_REM); }
 	;
 
 simple_exp	:	simple_exp MOD simple_exp
-			{ write_exp_elt_opcode (BINOP_MOD); }
+			{ write_exp_elt_opcode (ps, BINOP_MOD); }
 	;
 
 simple_exp	:	simple_exp '@' simple_exp	/* GDB extension */
-			{ write_exp_elt_opcode (BINOP_REPEAT); }
+			{ write_exp_elt_opcode (ps, BINOP_REPEAT); }
 	;
 
 simple_exp	:	simple_exp '+' simple_exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 simple_exp	:	simple_exp '&' simple_exp
-			{ write_exp_elt_opcode (BINOP_CONCAT); }
+			{ write_exp_elt_opcode (ps, BINOP_CONCAT); }
 	;
 
 simple_exp	:	simple_exp '-' simple_exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 relation :	simple_exp
 	;
 
 relation :	simple_exp '=' simple_exp
-			{ write_exp_elt_opcode (BINOP_EQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 	;
 
 relation :	simple_exp NOTEQUAL simple_exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 	;
 
 relation :	simple_exp LEQ simple_exp
-			{ write_exp_elt_opcode (BINOP_LEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 	;
 
 relation :	simple_exp IN simple_exp DOTDOT simple_exp
-			{ write_exp_elt_opcode (TERNOP_IN_RANGE); }
+			{ write_exp_elt_opcode (ps, TERNOP_IN_RANGE); }
         |       simple_exp IN primary TICK_RANGE tick_arglist
-			{ write_exp_elt_opcode (BINOP_IN_BOUNDS);
-			  write_exp_elt_longcst ((LONGEST) $5);
-			  write_exp_elt_opcode (BINOP_IN_BOUNDS);
+			{ write_exp_elt_opcode (ps, BINOP_IN_BOUNDS);
+			  write_exp_elt_longcst (ps, (LONGEST) $5);
+			  write_exp_elt_opcode (ps, BINOP_IN_BOUNDS);
 			}
  	|	simple_exp IN var_or_type	%prec TICK_ACCESS
 			{ 
 			  if ($3 == NULL)
 			    error (_("Right operand of 'in' must be type"));
-			  write_exp_elt_opcode (UNOP_IN_RANGE);
-		          write_exp_elt_type ($3);
-		          write_exp_elt_opcode (UNOP_IN_RANGE);
+			  write_exp_elt_opcode (ps, UNOP_IN_RANGE);
+		          write_exp_elt_type (ps, $3);
+		          write_exp_elt_opcode (ps, UNOP_IN_RANGE);
 			}
 	|	simple_exp NOT IN simple_exp DOTDOT simple_exp
-			{ write_exp_elt_opcode (TERNOP_IN_RANGE);
-		          write_exp_elt_opcode (UNOP_LOGICAL_NOT);
+			{ write_exp_elt_opcode (ps, TERNOP_IN_RANGE);
+		          write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT);
 			}
         |       simple_exp NOT IN primary TICK_RANGE tick_arglist
-			{ write_exp_elt_opcode (BINOP_IN_BOUNDS);
-			  write_exp_elt_longcst ((LONGEST) $6);
-			  write_exp_elt_opcode (BINOP_IN_BOUNDS);
-		          write_exp_elt_opcode (UNOP_LOGICAL_NOT);
+			{ write_exp_elt_opcode (ps, BINOP_IN_BOUNDS);
+			  write_exp_elt_longcst (ps, (LONGEST) $6);
+			  write_exp_elt_opcode (ps, BINOP_IN_BOUNDS);
+		          write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT);
 			}
  	|	simple_exp NOT IN var_or_type	%prec TICK_ACCESS
 			{ 
 			  if ($4 == NULL)
 			    error (_("Right operand of 'in' must be type"));
-			  write_exp_elt_opcode (UNOP_IN_RANGE);
-		          write_exp_elt_type ($4);
-		          write_exp_elt_opcode (UNOP_IN_RANGE);
-		          write_exp_elt_opcode (UNOP_LOGICAL_NOT);
+			  write_exp_elt_opcode (ps, UNOP_IN_RANGE);
+		          write_exp_elt_type (ps, $4);
+		          write_exp_elt_opcode (ps, UNOP_IN_RANGE);
+		          write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT);
 			}
 	;
 
 relation :	simple_exp GEQ simple_exp
-			{ write_exp_elt_opcode (BINOP_GEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 	;
 
 relation :	simple_exp '<' simple_exp
-			{ write_exp_elt_opcode (BINOP_LESS); }
+			{ write_exp_elt_opcode (ps, BINOP_LESS); }
 	;
 
 relation :	simple_exp '>' simple_exp
-			{ write_exp_elt_opcode (BINOP_GTR); }
+			{ write_exp_elt_opcode (ps, BINOP_GTR); }
 	;
 
 exp	:	relation
@@ -478,36 +485,36 @@ exp	:	relation
 
 and_exp :
 		relation _AND_ relation 
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	|	and_exp _AND_ relation
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	;
 
 and_then_exp :
 	       relation _AND_ THEN relation
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 	|	and_then_exp _AND_ THEN relation
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
         ;
 
 or_exp :
 		relation OR relation 
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	|	or_exp OR relation
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	;
 
 or_else_exp :
 	       relation OR ELSE relation
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 	|      or_else_exp OR ELSE relation
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
         ;
 
 xor_exp :       relation XOR relation
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 	|	xor_exp XOR relation
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
         ;
 
 /* Primaries can denote types (OP_TYPE).  In cases such as 
@@ -519,36 +526,36 @@ xor_exp :       relation XOR relation
    aType'access evaluates to a type that evaluate_subexp attempts to 
    evaluate. */
 primary :	primary TICK_ACCESS
-			{ write_exp_elt_opcode (UNOP_ADDR); }
+			{ write_exp_elt_opcode (ps, UNOP_ADDR); }
 	|	primary TICK_ADDRESS
-			{ write_exp_elt_opcode (UNOP_ADDR);
-			  write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type (type_system_address ());
-			  write_exp_elt_opcode (UNOP_CAST);
+			{ write_exp_elt_opcode (ps, UNOP_ADDR);
+			  write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, type_system_address (ps));
+			  write_exp_elt_opcode (ps, UNOP_CAST);
 			}
 	|	primary TICK_FIRST tick_arglist
-			{ write_int ($3, type_int ());
-			  write_exp_elt_opcode (OP_ATR_FIRST); }
+			{ write_int (ps, $3, type_int (ps));
+			  write_exp_elt_opcode (ps, OP_ATR_FIRST); }
 	|	primary TICK_LAST tick_arglist
-			{ write_int ($3, type_int ());
-			  write_exp_elt_opcode (OP_ATR_LAST); }
+			{ write_int (ps, $3, type_int (ps));
+			  write_exp_elt_opcode (ps, OP_ATR_LAST); }
 	| 	primary TICK_LENGTH tick_arglist
-			{ write_int ($3, type_int ());
-			  write_exp_elt_opcode (OP_ATR_LENGTH); }
+			{ write_int (ps, $3, type_int (ps));
+			  write_exp_elt_opcode (ps, OP_ATR_LENGTH); }
         |       primary TICK_SIZE
-			{ write_exp_elt_opcode (OP_ATR_SIZE); }
+			{ write_exp_elt_opcode (ps, OP_ATR_SIZE); }
 	|	primary TICK_TAG
-			{ write_exp_elt_opcode (OP_ATR_TAG); }
+			{ write_exp_elt_opcode (ps, OP_ATR_TAG); }
         |       opt_type_prefix TICK_MIN '(' exp ',' exp ')'
-			{ write_exp_elt_opcode (OP_ATR_MIN); }
+			{ write_exp_elt_opcode (ps, OP_ATR_MIN); }
         |       opt_type_prefix TICK_MAX '(' exp ',' exp ')'
-			{ write_exp_elt_opcode (OP_ATR_MAX); }
+			{ write_exp_elt_opcode (ps, OP_ATR_MAX); }
 	| 	opt_type_prefix TICK_POS '(' exp ')'
-			{ write_exp_elt_opcode (OP_ATR_POS); }
+			{ write_exp_elt_opcode (ps, OP_ATR_POS); }
 	|	type_prefix TICK_VAL '(' exp ')'
-			{ write_exp_elt_opcode (OP_ATR_VAL); }
+			{ write_exp_elt_opcode (ps, OP_ATR_VAL); }
 	|	type_prefix TICK_MODULUS
-			{ write_exp_elt_opcode (OP_ATR_MODULUS); }
+			{ write_exp_elt_opcode (ps, OP_ATR_MODULUS); }
 	;
 
 tick_arglist :			%prec '('
@@ -562,53 +569,55 @@ type_prefix :
 			{ 
 			  if ($1 == NULL)
 			    error (_("Prefix must be type"));
-			  write_exp_elt_opcode (OP_TYPE);
-			  write_exp_elt_type ($1);
-			  write_exp_elt_opcode (OP_TYPE); }
+			  write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, OP_TYPE); }
 	;
 
 opt_type_prefix :
 		type_prefix
 	| 	/* EMPTY */
-			{ write_exp_elt_opcode (OP_TYPE);
-			  write_exp_elt_type (parse_type->builtin_void);
-			  write_exp_elt_opcode (OP_TYPE); }
+			{ write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps,
+					      parse_type (ps)->builtin_void);
+			  write_exp_elt_opcode (ps, OP_TYPE); }
 	;
 
 
 primary	:	INT
-			{ write_int ((LONGEST) $1.val, $1.type); }
+			{ write_int (ps, (LONGEST) $1.val, $1.type); }
 	;
 
 primary	:	CHARLIT
-                  { write_int (convert_char_literal (type_qualifier, $1.val),
+                  { write_int (ps,
+			       convert_char_literal (type_qualifier, $1.val),
 			       (type_qualifier == NULL) 
 			       ? $1.type : type_qualifier);
 		  }
 	;
 
 primary	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_dblcst ($1.dval);
-			  write_exp_elt_opcode (OP_DOUBLE);
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_dblcst (ps, $1.dval);
+			  write_exp_elt_opcode (ps, OP_DOUBLE);
 			}
 	;
 
 primary	:	NULL_PTR
-			{ write_int (0, type_int ()); }
+			{ write_int (ps, 0, type_int (ps)); }
 	;
 
 primary	:	STRING
 			{ 
-			  write_exp_op_with_string (OP_STRING, $1);
+			  write_exp_op_with_string (ps, OP_STRING, $1);
 			}
 	;
 
 primary :	TRUEKEYWORD
-			{ write_int (1, type_boolean ()); }
+			{ write_int (ps, 1, type_boolean (ps)); }
         |	FALSEKEYWORD
-			{ write_int (0, type_boolean ()); }
+			{ write_int (ps, 0, type_boolean (ps)); }
 	;
 
 primary	: 	NEW NAME
@@ -616,22 +625,22 @@ primary	: 	NEW NAME
 	;
 
 var_or_type:	NAME   	    %prec VAR
-				{ $$ = write_var_or_type (NULL, $1); } 
+				{ $$ = write_var_or_type (ps, NULL, $1); } 
 	|	block NAME  %prec VAR
-                                { $$ = write_var_or_type ($1, $2); }
+                                { $$ = write_var_or_type (ps, $1, $2); }
 	|       NAME TICK_ACCESS 
 			{ 
-			  $$ = write_var_or_type (NULL, $1);
+			  $$ = write_var_or_type (ps, NULL, $1);
 			  if ($$ == NULL)
-			    write_exp_elt_opcode (UNOP_ADDR);
+			    write_exp_elt_opcode (ps, UNOP_ADDR);
 			  else
 			    $$ = lookup_pointer_type ($$);
 			}
 	|	block NAME TICK_ACCESS
 			{ 
-			  $$ = write_var_or_type ($1, $2);
+			  $$ = write_var_or_type (ps, $1, $2);
 			  if ($$ == NULL)
-			    write_exp_elt_opcode (UNOP_ADDR);
+			    write_exp_elt_opcode (ps, UNOP_ADDR);
 			  else
 			    $$ = lookup_pointer_type ($$);
 			}
@@ -647,18 +656,18 @@ block   :       NAME COLONCOLON
 aggregate :
 		'(' aggregate_component_list ')'  
 			{
-			  write_exp_elt_opcode (OP_AGGREGATE);
-			  write_exp_elt_longcst ($2);
-			  write_exp_elt_opcode (OP_AGGREGATE);
+			  write_exp_elt_opcode (ps, OP_AGGREGATE);
+			  write_exp_elt_longcst (ps, $2);
+			  write_exp_elt_opcode (ps, OP_AGGREGATE);
 		        }
 	;
 
 aggregate_component_list :
 		component_groups	 { $$ = $1; }
 	|	positional_list exp
-			{ write_exp_elt_opcode (OP_POSITIONAL);
-			  write_exp_elt_longcst ($1);
-			  write_exp_elt_opcode (OP_POSITIONAL);
+			{ write_exp_elt_opcode (ps, OP_POSITIONAL);
+			  write_exp_elt_longcst (ps, $1);
+			  write_exp_elt_opcode (ps, OP_POSITIONAL);
 			  $$ = $1 + 1;
 			}
 	|	positional_list component_groups
@@ -667,15 +676,15 @@ aggregate_component_list :
 
 positional_list :
 		exp ','
-			{ write_exp_elt_opcode (OP_POSITIONAL);
-			  write_exp_elt_longcst (0);
-			  write_exp_elt_opcode (OP_POSITIONAL);
+			{ write_exp_elt_opcode (ps, OP_POSITIONAL);
+			  write_exp_elt_longcst (ps, 0);
+			  write_exp_elt_opcode (ps, OP_POSITIONAL);
 			  $$ = 1;
 			} 
 	|	positional_list exp ','
-			{ write_exp_elt_opcode (OP_POSITIONAL);
-			  write_exp_elt_longcst ($1);
-			  write_exp_elt_opcode (OP_POSITIONAL);
+			{ write_exp_elt_opcode (ps, OP_POSITIONAL);
+			  write_exp_elt_longcst (ps, $1);
+			  write_exp_elt_opcode (ps, OP_POSITIONAL);
 			  $$ = $1 + 1; 
 			}
 	;
@@ -688,15 +697,15 @@ component_groups:
 	;
 
 others 	:	OTHERS ARROW exp
-			{ write_exp_elt_opcode (OP_OTHERS); }
+			{ write_exp_elt_opcode (ps, OP_OTHERS); }
 	;
 
 component_group :
 		component_associations
 			{
-			  write_exp_elt_opcode (OP_CHOICES);
-			  write_exp_elt_longcst ($1);
-			  write_exp_elt_opcode (OP_CHOICES);
+			  write_exp_elt_opcode (ps, OP_CHOICES);
+			  write_exp_elt_longcst (ps, $1);
+			  write_exp_elt_opcode (ps, OP_CHOICES);
 		        }
 	;
 
@@ -707,22 +716,22 @@ component_group :
    resolved shift/reduce conflict. */
 component_associations :
 		NAME ARROW 
-			{ write_name_assoc ($1); }
+			{ write_name_assoc (ps, $1); }
 		    exp	{ $$ = 1; }
 	|	simple_exp ARROW exp
 			{ $$ = 1; }
 	|	simple_exp DOTDOT simple_exp ARROW 
-			{ write_exp_elt_opcode (OP_DISCRETE_RANGE);
-			  write_exp_op_with_string (OP_NAME, empty_stoken);
+			{ write_exp_elt_opcode (ps, OP_DISCRETE_RANGE);
+			  write_exp_op_with_string (ps, OP_NAME, empty_stoken);
 			}
 		    exp { $$ = 1; }
 	|	NAME '|' 
-		        { write_name_assoc ($1); }
+		        { write_name_assoc (ps, $1); }
 		    component_associations  { $$ = $4 + 1; }
 	|	simple_exp '|'  
 	            component_associations  { $$ = $3 + 1; }
 	|	simple_exp DOTDOT simple_exp '|'
-			{ write_exp_elt_opcode (OP_DISCRETE_RANGE); }
+			{ write_exp_elt_opcode (ps, OP_DISCRETE_RANGE); }
 		    component_associations  { $$ = $6 + 1; }
 	;
 
@@ -730,11 +739,11 @@ component_associations :
    can't get used to Ada notation in GDB.  */
 
 primary	:	'*' primary		%prec '.'
-			{ write_exp_elt_opcode (UNOP_IND); }
+			{ write_exp_elt_opcode (ps, UNOP_IND); }
 	|	'&' primary		%prec '.'
-			{ write_exp_elt_opcode (UNOP_ADDR); }
+			{ write_exp_elt_opcode (ps, UNOP_ADDR); }
 	|	primary '[' exp ']'
-			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+			{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 	;
 
 %%
@@ -765,18 +774,18 @@ static struct obstack temp_parse_space;
 #include "ada-lex.c"
 
 int
-ada_parse (void)
+ada_parse (struct parser_state *ps)
 {
   lexer_init (yyin);		/* (Re-)initialize lexer.  */
   type_qualifier = NULL;
   obstack_free (&temp_parse_space, NULL);
   obstack_init (&temp_parse_space);
 
-  return _ada_parse ();
+  return _ada_parse (ps);
 }
 
 void
-yyerror (char *msg)
+yyerror (struct parser_state *ps, char *msg)
 {
   error (_("Error in expression, near `%s'."), lexptr);
 }
@@ -812,7 +821,8 @@ string_to_operator (struct stoken string)
 /* Emit expression to access an instance of SYM, in block BLOCK (if
  * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT.  */
 static void
-write_var_from_sym (struct block *orig_left_context,
+write_var_from_sym (struct parser_state *ps,
+		    struct block *orig_left_context,
 		    struct block *block,
 		    struct symbol *sym)
 {
@@ -823,30 +833,31 @@ write_var_from_sym (struct block *orig_left_context,
 	innermost_block = block;
     }
 
-  write_exp_elt_opcode (OP_VAR_VALUE);
-  write_exp_elt_block (block);
-  write_exp_elt_sym (sym);
-  write_exp_elt_opcode (OP_VAR_VALUE);
+  write_exp_elt_opcode (ps, OP_VAR_VALUE);
+  write_exp_elt_block (ps, block);
+  write_exp_elt_sym (ps, sym);
+  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 }
 
 /* Write integer or boolean constant ARG of type TYPE.  */
 
 static void
-write_int (LONGEST arg, struct type *type)
+write_int (struct parser_state *ps, LONGEST arg, struct type *type)
 {
-  write_exp_elt_opcode (OP_LONG);
-  write_exp_elt_type (type);
-  write_exp_elt_longcst (arg);
-  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_opcode (ps, OP_LONG);
+  write_exp_elt_type (ps, type);
+  write_exp_elt_longcst (ps, arg);
+  write_exp_elt_opcode (ps, OP_LONG);
 }
 
 /* Write an OPCODE, string, OPCODE sequence to the current expression.  */
 static void
-write_exp_op_with_string (enum exp_opcode opcode, struct stoken token)
+write_exp_op_with_string (struct parser_state *ps, enum exp_opcode opcode,
+			  struct stoken token)
 {
-  write_exp_elt_opcode (opcode);
-  write_exp_string (token);
-  write_exp_elt_opcode (opcode);
+  write_exp_elt_opcode (ps, opcode);
+  write_exp_string (ps, token);
+  write_exp_elt_opcode (ps, opcode);
 }
   
 /* Emit expression corresponding to the renamed object named 
@@ -861,7 +872,8 @@ write_exp_op_with_string (enum exp_opcode opcode, struct stoken token)
  * new encoding entirely (FIXME pnh 7/20/2007).  */
 
 static void
-write_object_renaming (struct block *orig_left_context,
+write_object_renaming (struct parser_state *ps,
+		       struct block *orig_left_context,
 		       const char *renamed_entity, int renamed_entity_len,
 		       const char *renaming_expr, int max_depth)
 {
@@ -896,10 +908,10 @@ write_object_renaming (struct block *orig_left_context,
 				&inner_renaming_expr))
       {
       case ADA_NOT_RENAMING:
-	write_var_from_sym (orig_left_context, block, sym);
+	write_var_from_sym (ps, orig_left_context, block, sym);
 	break;
       case ADA_OBJECT_RENAMING:
-	write_object_renaming (block,
+	write_object_renaming (ps, block,
 			       inner_renamed_entity, inner_renamed_entity_len,
 			       inner_renaming_expr, max_depth - 1);
 	break;
@@ -916,7 +928,7 @@ write_object_renaming (struct block *orig_left_context,
       switch (*renaming_expr) {
       case 'A':
         renaming_expr += 1;
-        write_exp_elt_opcode (UNOP_IND);
+        write_exp_elt_opcode (ps, UNOP_IND);
         break;
       case 'L':
 	slice_state = LOWER_BOUND;
@@ -930,10 +942,10 @@ write_object_renaming (struct block *orig_left_context,
 	    if (next == renaming_expr)
 	      goto BadEncoding;
 	    renaming_expr = next;
-	    write_exp_elt_opcode (OP_LONG);
-	    write_exp_elt_type (type_int ());
-	    write_exp_elt_longcst ((LONGEST) val);
-	    write_exp_elt_opcode (OP_LONG);
+	    write_exp_elt_opcode (ps, OP_LONG);
+	    write_exp_elt_type (ps, type_int (ps));
+	    write_exp_elt_longcst (ps, (LONGEST) val);
+	    write_exp_elt_opcode (ps, OP_LONG);
 	  }
 	else
 	  {
@@ -957,19 +969,19 @@ write_object_renaming (struct block *orig_left_context,
 	    else if (SYMBOL_CLASS (index_sym) == LOC_TYPEDEF)
 	      /* Index is an old-style renaming symbol.  */
 	      block = orig_left_context;
-	    write_var_from_sym (NULL, block, index_sym);
+	    write_var_from_sym (ps, NULL, block, index_sym);
 	  }
 	if (slice_state == SIMPLE_INDEX)
 	  {
-	    write_exp_elt_opcode (OP_FUNCALL);
-	    write_exp_elt_longcst ((LONGEST) 1);
-	    write_exp_elt_opcode (OP_FUNCALL);
+	    write_exp_elt_opcode (ps, OP_FUNCALL);
+	    write_exp_elt_longcst (ps, (LONGEST) 1);
+	    write_exp_elt_opcode (ps, OP_FUNCALL);
 	  }
 	else if (slice_state == LOWER_BOUND)
 	  slice_state = UPPER_BOUND;
 	else if (slice_state == UPPER_BOUND)
 	  {
-	    write_exp_elt_opcode (TERNOP_SLICE);
+	    write_exp_elt_opcode (ps, TERNOP_SLICE);
 	    slice_state = SIMPLE_INDEX;
 	  }
 	break;
@@ -990,7 +1002,7 @@ write_object_renaming (struct block *orig_left_context,
 	  strncpy (field_name.ptr, renaming_expr, end - renaming_expr);
 	  field_name.ptr[end - renaming_expr] = '\000';
 	  renaming_expr = end;
-	  write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
+	  write_exp_op_with_string (ps, STRUCTOP_STRUCT, field_name);
 	  break;
 	}
 
@@ -1079,14 +1091,14 @@ select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
 }
 
 static struct type*
-find_primitive_type (char *name)
+find_primitive_type (struct parser_state *ps, char *name)
 {
   struct type *type;
-  type = language_lookup_primitive_type_by_name (parse_language,
-						 parse_gdbarch,
+  type = language_lookup_primitive_type_by_name (parse_language (ps),
+						 parse_gdbarch (ps),
 						 name);
   if (type == NULL && strcmp ("system__address", name) == 0)
-    type = type_system_address ();
+    type = type_system_address (ps);
 
   if (type != NULL)
     {
@@ -1135,7 +1147,7 @@ chop_separator (char *name)
    <sep> is '__' or '.', write the indicated sequence of
    STRUCTOP_STRUCT expression operators. */
 static void
-write_selectors (char *sels)
+write_selectors (struct parser_state *ps, char *sels)
 {
   while (*sels != '\0')
     {
@@ -1147,7 +1159,7 @@ write_selectors (char *sels)
 	sels += 1;
       field_name.length = sels - p;
       field_name.ptr = p;
-      write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
+      write_exp_op_with_string (ps, STRUCTOP_STRUCT, field_name);
     }
 }
 
@@ -1156,7 +1168,8 @@ write_selectors (char *sels)
    a temporary symbol that is valid until the next call to ada_parse.
    */
 static void
-write_ambiguous_var (struct block *block, char *name, int len)
+write_ambiguous_var (struct parser_state *ps, struct block *block, char *name,
+		     int len)
 {
   struct symbol *sym =
     obstack_alloc (&temp_parse_space, sizeof (struct symbol));
@@ -1165,10 +1178,10 @@ write_ambiguous_var (struct block *block, char *name, int len)
   SYMBOL_LINKAGE_NAME (sym) = obsavestring (name, len, &temp_parse_space);
   SYMBOL_LANGUAGE (sym) = language_ada;
 
-  write_exp_elt_opcode (OP_VAR_VALUE);
-  write_exp_elt_block (block);
-  write_exp_elt_sym (sym);
-  write_exp_elt_opcode (OP_VAR_VALUE);
+  write_exp_elt_opcode (ps, OP_VAR_VALUE);
+  write_exp_elt_block (ps, block);
+  write_exp_elt_sym (ps, sym);
+  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 }
 
 /* A convenient wrapper around ada_get_field_index that takes
@@ -1248,7 +1261,8 @@ get_symbol_field_type (struct symbol *sym, char *encoded_field_name)
    identifier).  */
 
 static struct type*
-write_var_or_type (struct block *block, struct stoken name0)
+write_var_or_type (struct parser_state *ps, struct block *block,
+		   struct stoken name0)
 {
   int depth;
   char *encoded_name;
@@ -1323,9 +1337,9 @@ write_var_or_type (struct block *block, struct stoken name0)
 		goto TryAfterRenaming;
 	      }	
 	    case ADA_OBJECT_RENAMING:
-	      write_object_renaming (block, renaming, renaming_len, 
+	      write_object_renaming (ps, block, renaming, renaming_len, 
 				     renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
-	      write_selectors (encoded_name + tail_index);
+	      write_selectors (ps, encoded_name + tail_index);
 	      return NULL;
 	    default:
 	      internal_error (__FILE__, __LINE__,
@@ -1352,7 +1366,7 @@ write_var_or_type (struct block *block, struct stoken name0)
 	    }
 	  else if (tail_index == name_len && nsyms == 0)
 	    {
-	      struct type *type = find_primitive_type (encoded_name);
+	      struct type *type = find_primitive_type (ps, encoded_name);
 
 	      if (type != NULL)
 		return type;
@@ -1360,8 +1374,8 @@ write_var_or_type (struct block *block, struct stoken name0)
 
 	  if (nsyms == 1)
 	    {
-	      write_var_from_sym (block, syms[0].block, syms[0].sym);
-	      write_selectors (encoded_name + tail_index);
+	      write_var_from_sym (ps, block, syms[0].block, syms[0].sym);
+	      write_selectors (ps, encoded_name + tail_index);
 	      return NULL;
 	    }
 	  else if (nsyms == 0) 
@@ -1370,9 +1384,9 @@ write_var_or_type (struct block *block, struct stoken name0)
 		= ada_lookup_simple_minsym (encoded_name);
 	      if (msym != NULL)
 		{
-		  write_exp_msymbol (msym);
+		  write_exp_msymbol (ps, msym);
 		  /* Maybe cause error here rather than later? FIXME? */
-		  write_selectors (encoded_name + tail_index);
+		  write_selectors (ps, encoded_name + tail_index);
 		  return NULL;
 		}
 
@@ -1385,8 +1399,8 @@ write_var_or_type (struct block *block, struct stoken name0)
 	    } 
 	  else
 	    {
-	      write_ambiguous_var (block, encoded_name, tail_index);
-	      write_selectors (encoded_name + tail_index);
+	      write_ambiguous_var (ps, block, encoded_name, tail_index);
+	      write_selectors (ps, encoded_name + tail_index);
 	      return NULL;
 	    }
 	}
@@ -1421,7 +1435,7 @@ write_var_or_type (struct block *block, struct stoken name0)
    ambiguous name, one must write instead ((R) => 42). */
    
 static void
-write_name_assoc (struct stoken name)
+write_name_assoc (struct parser_state *ps, struct stoken name)
 {
   if (strchr (name.ptr, '.') == NULL)
     {
@@ -1429,12 +1443,12 @@ write_name_assoc (struct stoken name)
       int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
 					  VAR_DOMAIN, &syms);
       if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
-	write_exp_op_with_string (OP_NAME, name);
+	write_exp_op_with_string (ps, OP_NAME, name);
       else
-	write_var_from_sym (NULL, syms[0].block, syms[0].sym);
+	write_var_from_sym (ps, NULL, syms[0].block, syms[0].sym);
     }
   else
-    if (write_var_or_type (NULL, name) != NULL)
+    if (write_var_or_type (ps, NULL, name) != NULL)
       error (_("Invalid use of type."));
 }
 
@@ -1465,61 +1479,61 @@ convert_char_literal (struct type *type, LONGEST val)
 }
 
 static struct type *
-type_int (void)
+type_int (struct parser_state *ps)
 {
-  return parse_type->builtin_int;
+  return parse_type (ps)->builtin_int;
 }
 
 static struct type *
-type_long (void)
+type_long (struct parser_state *ps)
 {
-  return parse_type->builtin_long;
+  return parse_type (ps)->builtin_long;
 }
 
 static struct type *
-type_long_long (void)
+type_long_long (struct parser_state *ps)
 {
-  return parse_type->builtin_long_long;
+  return parse_type (ps)->builtin_long_long;
 }
 
 static struct type *
-type_float (void)
+type_float (struct parser_state *ps)
 {
-  return parse_type->builtin_float;
+  return parse_type (ps)->builtin_float;
 }
 
 static struct type *
-type_double (void)
+type_double (struct parser_state *ps)
 {
-  return parse_type->builtin_double;
+  return parse_type (ps)->builtin_double;
 }
 
 static struct type *
-type_long_double (void)
+type_long_double (struct parser_state *ps)
 {
-  return parse_type->builtin_long_double;
+  return parse_type (ps)->builtin_long_double;
 }
 
 static struct type *
-type_char (void)
+type_char (struct parser_state *ps)
 {
-  return language_string_char_type (parse_language, parse_gdbarch);
+  return language_string_char_type (parse_language (ps), parse_gdbarch (ps));
 }
 
 static struct type *
-type_boolean (void)
+type_boolean (struct parser_state *ps)
 {
-  return parse_type->builtin_bool;
+  return parse_type (ps)->builtin_bool;
 }
 
 static struct type *
-type_system_address (void)
+type_system_address (struct parser_state *ps)
 {
   struct type *type 
-    = language_lookup_primitive_type_by_name (parse_language,
-					      parse_gdbarch,
+    = language_lookup_primitive_type_by_name (parse_language (ps),
+					      parse_gdbarch (ps),
 					      "system__address");
-  return  type != NULL ? type : parse_type->builtin_data_ptr;
+  return  type != NULL ? type : parse_type (ps)->builtin_data_ptr;
 }
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 29956d7..38d58d3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12305,10 +12305,10 @@ emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
 }
 
 static int
-parse (void)
+parse (struct parser_state *ps)
 {
   warnings_issued = 0;
-  return ada_parse ();
+  return ada_parse (ps);
 }
 
 static const struct exp_descriptor ada_exp_descriptor = {
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 9ab7b2d..b4e85eb 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -23,6 +23,7 @@
 
 struct frame_info;
 struct inferior;
+struct parser_state;
 
 #include "value.h"
 #include "gdbtypes.h"
@@ -153,9 +154,10 @@ extern int ada_get_field_index (const struct type *type,
                                 const char *field_name,
                                 int maybe_missing);
 
-extern int ada_parse (void);    /* Defined in ada-exp.y */
+extern int ada_parse (struct parser_state *);    /* Defined in ada-exp.y */
 
-extern void ada_error (char *); /* Defined in ada-exp.y */
+extern void ada_error (struct parser_state *, char *); /* Defined in
+							  ada-exp.y */
 
                         /* Defined in ada-typeprint.c */
 extern void ada_print_type (struct type *, const char *, struct ui_file *, int,
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 48667d0..b3fefd6 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -49,14 +49,15 @@ POSEXP  (e"+"?{NUM10})
 static char numbuf[NUMERAL_WIDTH];
  static void canonicalizeNumeral (char *s1, const char *);
 static struct stoken processString (const char*, int);
-static int processInt (const char *, const char *, const char *);
-static int processReal (const char *);
+static int processInt (struct parser_state *, const char *, const char *,
+		       const char *);
+static int processReal (struct parser_state *, const char *);
 static struct stoken processId (const char *, int);
 static int processAttribute (const char *);
 static int find_dot_all (const char *);
 
 #undef YY_DECL
-#define YY_DECL static int yylex ( void )
+#define YY_DECL static int yylex ( struct parser_state *ps )
 
 /* Flex generates a static function "input" which is not used.
    Defining YY_NO_INPUT comments it out.  */
@@ -89,40 +90,42 @@ static int find_dot_all (const char *);
 
 {NUM10}{POSEXP}  {
 		   canonicalizeNumeral (numbuf, yytext);
-		   return processInt (NULL, numbuf, strrchr(numbuf, 'e')+1);
+		   return processInt (ps, NULL, numbuf,
+				      strrchr (numbuf, 'e') + 1);
 		 }
 
 {NUM10}          {
 		   canonicalizeNumeral (numbuf, yytext);
-		   return processInt (NULL, numbuf, NULL);
+		   return processInt (ps, NULL, numbuf, NULL);
 		 }
 
 {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} {
 		   canonicalizeNumeral (numbuf, yytext);
-    		   return processInt (numbuf,
+    		   return processInt (ps, numbuf,
 				      strchr (numbuf, '#') + 1,
 				      strrchr(numbuf, '#') + 1);
 		 }
 
 {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
 		   canonicalizeNumeral (numbuf, yytext);
-    		   return processInt (numbuf, strchr (numbuf, '#') + 1, NULL);
+    		   return processInt (ps, numbuf, strchr (numbuf, '#') + 1,
+				      NULL);
 		 }
 
 "0x"{HEXDIG}+	{
 		  canonicalizeNumeral (numbuf, yytext+2);
-		  return processInt ("16#", numbuf, NULL);
+		  return processInt (ps, "16#", numbuf, NULL);
 		}
 
 
 {NUM10}"."{NUM10}{EXP} {
 		   canonicalizeNumeral (numbuf, yytext);
-		   return processReal (numbuf);
+		   return processReal (ps, numbuf);
 		}
 
 {NUM10}"."{NUM10} {
 		   canonicalizeNumeral (numbuf, yytext);
-		   return processReal (numbuf);
+		   return processReal (ps, numbuf);
 		}
 
 {NUM10}"#"{NUM16}"."{NUM16}"#"{EXP} {
@@ -134,14 +137,14 @@ static int find_dot_all (const char *);
 		}
 
 <INITIAL>"'"({GRAPHIC}|\")"'" {
-		   yylval.typed_val.type = type_char ();
+		   yylval.typed_val.type = type_char (ps);
 		   yylval.typed_val.val = yytext[1];
 		   return CHARLIT;
 		}
 
 <INITIAL>"'[\""{HEXDIG}{2}"\"]'"   {
                    int v;
-                   yylval.typed_val.type = type_char ();
+                   yylval.typed_val.type = type_char (ps);
 		   sscanf (yytext+3, "%2x", &v);
 		   yylval.typed_val.val = v;
 		   return CHARLIT;
@@ -325,7 +328,8 @@ canonicalizeNumeral (char *s1, const char *s2)
  */
 
 static int
-processInt (const char *base0, const char *num0, const char *exp0)
+processInt (struct parser_state *ps, const char *base0, const char *num0,
+	    const char *exp0)
 {
   ULONGEST result;
   long exp;
@@ -362,11 +366,11 @@ processInt (const char *base0, const char *num0, const char *exp0)
       exp -= 1;
     }
 
-  if ((result >> (gdbarch_int_bit (parse_gdbarch)-1)) == 0)
-    yylval.typed_val.type = type_int ();
-  else if ((result >> (gdbarch_long_bit (parse_gdbarch)-1)) == 0)
-    yylval.typed_val.type = type_long ();
-  else if (((result >> (gdbarch_long_bit (parse_gdbarch)-1)) >> 1) == 0)
+  if ((result >> (gdbarch_int_bit (parse_gdbarch (ps))-1)) == 0)
+    yylval.typed_val.type = type_int (ps);
+  else if ((result >> (gdbarch_long_bit (parse_gdbarch (ps))-1)) == 0)
+    yylval.typed_val.type = type_long (ps);
+  else if (((result >> (gdbarch_long_bit (parse_gdbarch (ps))-1)) >> 1) == 0)
     {
       /* We have a number representable as an unsigned integer quantity.
          For consistency with the C treatment, we will treat it as an
@@ -376,7 +380,7 @@ processInt (const char *base0, const char *num0, const char *exp0)
          assignment does the trick (no, it doesn't; read the reference manual).
        */
       yylval.typed_val.type
-	= builtin_type (parse_gdbarch)->builtin_unsigned_long;
+	= builtin_type (parse_gdbarch (ps))->builtin_unsigned_long;
       if (result & LONGEST_SIGN)
 	yylval.typed_val.val =
 	  (LONGEST) (result & ~LONGEST_SIGN)
@@ -386,24 +390,24 @@ processInt (const char *base0, const char *num0, const char *exp0)
       return INT;
     }
   else
-    yylval.typed_val.type = type_long_long ();
+    yylval.typed_val.type = type_long_long (ps);
 
   yylval.typed_val.val = (LONGEST) result;
   return INT;
 }
 
 static int
-processReal (const char *num0)
+processReal (struct parser_state *ps, const char *num0)
 {
   sscanf (num0, "%" DOUBLEST_SCAN_FORMAT, &yylval.typed_val_float.dval);
 
-  yylval.typed_val_float.type = type_float ();
-  if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch)
+  yylval.typed_val_float.type = type_float (ps);
+  if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch (ps))
 			    / TARGET_CHAR_BIT)
-    yylval.typed_val_float.type = type_double ();
-  if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch)
+    yylval.typed_val_float.type = type_double (ps);
+  if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch (ps))
 			    / TARGET_CHAR_BIT)
-    yylval.typed_val_float.type = type_long_double ();
+    yylval.typed_val_float.type = type_long_double (ps);
 
   return FLOAT;
 }

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

* [RFC 4/8] Fortran language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (2 preceding siblings ...)
  2012-01-15 19:04 ` [RFC 3/8] Ada language Sergio Durigan Junior
@ 2012-01-15 19:05 ` Sergio Durigan Junior
  2012-01-15 19:06 ` [RFC 5/8] Java language Sergio Durigan Junior
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:05 UTC (permalink / raw)
  To: gdb-patches

Hi,

This is the patch for the Fortran language files.

Thanks,

Sergio.

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index fa464cf..816f667 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -55,8 +55,8 @@
 #include "block.h"
 #include <ctype.h>
 
-#define parse_type builtin_type (parse_gdbarch)
-#define parse_f_type builtin_f_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
+#define parse_f_type(ps) builtin_f_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -112,11 +112,11 @@
 
 #define YYFPRINTF parser_fprintf
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 static void growbuf_by_size (int);
 
@@ -124,6 +124,9 @@ static int match_string_literal (void);
 
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -152,7 +155,7 @@ static int match_string_literal (void);
 
 %{
 /* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *, char *, int, int, YYSTYPE *);
 %}
 
 %type <voidval> exp  type_exp start variable 
@@ -234,9 +237,9 @@ start   :	exp
 	;
 
 type_exp:	type
-			{ write_exp_elt_opcode(OP_TYPE);
-			  write_exp_elt_type($1);
-			  write_exp_elt_opcode(OP_TYPE); }
+			{ write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, OP_TYPE); }
 	;
 
 exp     :       '(' exp ')'
@@ -245,27 +248,27 @@ exp     :       '(' exp ')'
 
 /* Expressions, not including the comma operator.  */
 exp	:	'*' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_IND); }
+			{ write_exp_elt_opcode (ps, UNOP_IND); }
 	;
 
 exp	:	'&' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_ADDR); }
+			{ write_exp_elt_opcode (ps, UNOP_ADDR); }
 	;
 
 exp	:	'-' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_NEG); }
+			{ write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 exp	:	BOOL_NOT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 exp	:	'~' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_COMPLEMENT); }
 	;
 
 exp	:	SIZEOF exp       %prec UNARY
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 	;
 
 /* No more explicit array operators, we treat everything in F77 as 
@@ -276,9 +279,9 @@ exp	:	SIZEOF exp       %prec UNARY
 exp	:	exp '(' 
 			{ start_arglist (); }
 		arglist ')'	
-			{ write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); }
+			{ write_exp_elt_opcode (ps, OP_F77_UNDETERMINED_ARGLIST);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_F77_UNDETERMINED_ARGLIST); }
 	;
 
 arglist	:
@@ -299,27 +302,27 @@ arglist	:	arglist ',' exp   %prec ABOVE_COMMA
 /* There are four sorts of subrange types in F90.  */
 
 subrange:	exp ':' exp	%prec ABOVE_COMMA
-			{ write_exp_elt_opcode (OP_F90_RANGE); 
-			  write_exp_elt_longcst (NONE_BOUND_DEFAULT);
-			  write_exp_elt_opcode (OP_F90_RANGE); }
+			{ write_exp_elt_opcode (ps, OP_F90_RANGE); 
+			  write_exp_elt_longcst (ps, NONE_BOUND_DEFAULT);
+			  write_exp_elt_opcode (ps, OP_F90_RANGE); }
 	;
 
 subrange:	exp ':'	%prec ABOVE_COMMA
-			{ write_exp_elt_opcode (OP_F90_RANGE);
-			  write_exp_elt_longcst (HIGH_BOUND_DEFAULT);
-			  write_exp_elt_opcode (OP_F90_RANGE); }
+			{ write_exp_elt_opcode (ps, OP_F90_RANGE);
+			  write_exp_elt_longcst (ps, HIGH_BOUND_DEFAULT);
+			  write_exp_elt_opcode (ps, OP_F90_RANGE); }
 	;
 
 subrange:	':' exp	%prec ABOVE_COMMA
-			{ write_exp_elt_opcode (OP_F90_RANGE);
-			  write_exp_elt_longcst (LOW_BOUND_DEFAULT);
-			  write_exp_elt_opcode (OP_F90_RANGE); }
+			{ write_exp_elt_opcode (ps, OP_F90_RANGE);
+			  write_exp_elt_longcst (ps, LOW_BOUND_DEFAULT);
+			  write_exp_elt_opcode (ps, OP_F90_RANGE); }
 	;
 
 subrange:	':'	%prec ABOVE_COMMA
-			{ write_exp_elt_opcode (OP_F90_RANGE);
-			  write_exp_elt_longcst (BOTH_BOUND_DEFAULT);
-			  write_exp_elt_opcode (OP_F90_RANGE); }
+			{ write_exp_elt_opcode (ps, OP_F90_RANGE);
+			  write_exp_elt_longcst (ps, BOTH_BOUND_DEFAULT);
+			  write_exp_elt_opcode (ps, OP_F90_RANGE); }
 	;
 
 complexnum:     exp ',' exp 
@@ -327,133 +330,138 @@ complexnum:     exp ',' exp
         ;
 
 exp	:	'(' complexnum ')'
-                	{ write_exp_elt_opcode(OP_COMPLEX);
-			  write_exp_elt_type (parse_f_type->builtin_complex_s16);
-                	  write_exp_elt_opcode(OP_COMPLEX); }
+                	{ write_exp_elt_opcode (ps, OP_COMPLEX);
+			  write_exp_elt_type (ps,
+					      parse_f_type (ps)
+					      ->builtin_complex_s16);
+                	  write_exp_elt_opcode (ps, OP_COMPLEX); }
 	;
 
 exp	:	'(' type ')' exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 exp     :       exp '%' name
-                        { write_exp_elt_opcode (STRUCTOP_STRUCT);
-                          write_exp_string ($3);
-                          write_exp_elt_opcode (STRUCTOP_STRUCT); }
+                        { write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+                          write_exp_string (ps, $3);
+                          write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
         ;
 
 /* Binary operators in order of decreasing precedence.  */
 
 exp	:	exp '@' exp
-			{ write_exp_elt_opcode (BINOP_REPEAT); }
+			{ write_exp_elt_opcode (ps, BINOP_REPEAT); }
 	;
 
 exp	:	exp STARSTAR exp
-			{ write_exp_elt_opcode (BINOP_EXP); }
+			{ write_exp_elt_opcode (ps, BINOP_EXP); }
 	;
 
 exp	:	exp '*' exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 exp	:	exp '/' exp
-			{ write_exp_elt_opcode (BINOP_DIV); }
+			{ write_exp_elt_opcode (ps, BINOP_DIV); }
 	;
 
 exp	:	exp '+' exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 exp	:	exp '-' exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 exp	:	exp LSH exp
-			{ write_exp_elt_opcode (BINOP_LSH); }
+			{ write_exp_elt_opcode (ps, BINOP_LSH); }
 	;
 
 exp	:	exp RSH exp
-			{ write_exp_elt_opcode (BINOP_RSH); }
+			{ write_exp_elt_opcode (ps, BINOP_RSH); }
 	;
 
 exp	:	exp EQUAL exp
-			{ write_exp_elt_opcode (BINOP_EQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 	;
 
 exp	:	exp NOTEQUAL exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 	;
 
 exp	:	exp LEQ exp
-			{ write_exp_elt_opcode (BINOP_LEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 	;
 
 exp	:	exp GEQ exp
-			{ write_exp_elt_opcode (BINOP_GEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 	;
 
 exp	:	exp LESSTHAN exp
-			{ write_exp_elt_opcode (BINOP_LESS); }
+			{ write_exp_elt_opcode (ps, BINOP_LESS); }
 	;
 
 exp	:	exp GREATERTHAN exp
-			{ write_exp_elt_opcode (BINOP_GTR); }
+			{ write_exp_elt_opcode (ps, BINOP_GTR); }
 	;
 
 exp	:	exp '&' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	;
 
 exp	:	exp '^' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 	;
 
 exp	:	exp '|' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	;
 
 exp     :       exp BOOL_AND exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 	;
 
 
 exp	:	exp BOOL_OR exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 	;
 
 exp	:	exp '=' exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 exp	:	exp ASSIGN_MODIFY exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
-			  write_exp_elt_opcode ($2);
-			  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+			  write_exp_elt_opcode (ps, $2);
+			  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 	;
 
 exp	:	INT
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_longcst ((LONGEST)($1.val));
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_longcst (ps, (LONGEST) ($1.val));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	NAME_OR_INT
 			{ YYSTYPE val;
-			  parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (val.typed_val.type);
-			  write_exp_elt_longcst ((LONGEST)val.typed_val.val);
-			  write_exp_elt_opcode (OP_LONG); }
+			  parse_number (ps, $1.stoken.ptr, $1.stoken.length,
+					0, &val);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, val.typed_val.type);
+			  write_exp_elt_longcst (ps, (LONGEST)val.typed_val.val);
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type (parse_f_type->builtin_real_s8);
-			  write_exp_elt_dblcst ($1);
-			  write_exp_elt_opcode (OP_DOUBLE); }
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps,
+					      parse_f_type (ps)
+					      ->builtin_real_s8);
+			  write_exp_elt_dblcst (ps, $1);
+			  write_exp_elt_opcode (ps, OP_DOUBLE); }
 	;
 
 exp	:	variable
@@ -463,25 +471,27 @@ exp	:	VARIABLE
 	;
 
 exp	:	SIZEOF '(' type ')'	%prec UNARY
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_f_type->builtin_integer);
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps,
+					      parse_f_type (ps)
+					      ->builtin_integer);
 			  CHECK_TYPEDEF ($3);
-			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
-			  write_exp_elt_opcode (OP_LONG); }
+			  write_exp_elt_longcst (ps, (LONGEST) TYPE_LENGTH ($3));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp     :       BOOLEAN_LITERAL
-			{ write_exp_elt_opcode (OP_BOOL);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_BOOL);
+			{ write_exp_elt_opcode (ps, OP_BOOL);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_BOOL);
 			}
         ;
 
 exp	:	STRING_LITERAL
 			{
-			  write_exp_elt_opcode (OP_STRING);
-			  write_exp_string ($1);
-			  write_exp_elt_opcode (OP_STRING);
+			  write_exp_elt_opcode (ps, OP_STRING);
+			  write_exp_string (ps, $1);
+			  write_exp_elt_opcode (ps, OP_STRING);
 			}
 	;
 
@@ -497,13 +507,13 @@ variable:	name_not_typename
 						       innermost_block))
 				    innermost_block = block_found;
 				}
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      /* We want to use the selected frame, not
 				 another more inner frame which happens to
 				 be in the same block.  */
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      break;
 			    }
 			  else
@@ -514,7 +524,7 @@ variable:	name_not_typename
 			      msymbol =
 				lookup_minimal_symbol (arg, NULL, NULL);
 			      if (msymbol != NULL)
-				write_exp_msymbol (msymbol);
+				write_exp_msymbol (ps, msymbol);
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  Use the \"file\" command."));
 			      else
@@ -555,7 +565,8 @@ ptype	:	typebase
 			  {
 			    range_type =
 			      create_range_type ((struct type *) NULL,
-						 parse_f_type->builtin_integer,
+						 parse_f_type (ps)
+						 ->builtin_integer,
 						 0, array_size - 1);
 			    follow_type =
 			      create_array_type ((struct type *) NULL,
@@ -601,31 +612,31 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 	:	TYPENAME
 			{ $$ = $1.type; }
 	|	INT_KEYWORD
-			{ $$ = parse_f_type->builtin_integer; }
+			{ $$ = parse_f_type (ps)->builtin_integer; }
 	|	INT_S2_KEYWORD 
-			{ $$ = parse_f_type->builtin_integer_s2; }
+			{ $$ = parse_f_type (ps)->builtin_integer_s2; }
 	|	CHARACTER 
-			{ $$ = parse_f_type->builtin_character; }
+			{ $$ = parse_f_type (ps)->builtin_character; }
 	|	LOGICAL_S8_KEYWORD
-			{ $$ = parse_f_type->builtin_logical_s8; }
+			{ $$ = parse_f_type (ps)->builtin_logical_s8; }
 	|	LOGICAL_KEYWORD 
-			{ $$ = parse_f_type->builtin_logical; }
+			{ $$ = parse_f_type (ps)->builtin_logical; }
 	|	LOGICAL_S2_KEYWORD
-			{ $$ = parse_f_type->builtin_logical_s2; }
+			{ $$ = parse_f_type (ps)->builtin_logical_s2; }
 	|	LOGICAL_S1_KEYWORD 
-			{ $$ = parse_f_type->builtin_logical_s1; }
+			{ $$ = parse_f_type (ps)->builtin_logical_s1; }
 	|	REAL_KEYWORD 
-			{ $$ = parse_f_type->builtin_real; }
+			{ $$ = parse_f_type (ps)->builtin_real; }
 	|       REAL_S8_KEYWORD
-			{ $$ = parse_f_type->builtin_real_s8; }
+			{ $$ = parse_f_type (ps)->builtin_real_s8; }
 	|	REAL_S16_KEYWORD
-			{ $$ = parse_f_type->builtin_real_s16; }
+			{ $$ = parse_f_type (ps)->builtin_real_s16; }
 	|	COMPLEX_S8_KEYWORD
-			{ $$ = parse_f_type->builtin_complex_s8; }
+			{ $$ = parse_f_type (ps)->builtin_complex_s8; }
 	|	COMPLEX_S16_KEYWORD 
-			{ $$ = parse_f_type->builtin_complex_s16; }
+			{ $$ = parse_f_type (ps)->builtin_complex_s16; }
 	|	COMPLEX_S32_KEYWORD 
-			{ $$ = parse_f_type->builtin_complex_s32; }
+			{ $$ = parse_f_type (ps)->builtin_complex_s32; }
 	;
 
 nonempty_typelist
@@ -664,11 +675,8 @@ name_not_typename :	NAME
 /*** Needs some error checking for the float case ***/
 
 static int
-parse_number (p, len, parsed_float, putithere)
-     char *p;
-     int len;
-     int parsed_float;
-     YYSTYPE *putithere;
+parse_number (struct parser_state *ps, char *p, int len, int parsed_float,
+	      YYSTYPE *putithere)
 {
   LONGEST n = 0;
   LONGEST prevn = 0;
@@ -774,20 +782,22 @@ parse_number (p, len, parsed_float, putithere)
      are the same size.  So we shift it twice, with fewer bits
      each time, for the same result.  */
   
-  if ((gdbarch_int_bit (parse_gdbarch) != gdbarch_long_bit (parse_gdbarch)
+  if ((gdbarch_int_bit (parse_gdbarch (ps))
+       != gdbarch_long_bit (parse_gdbarch (ps))
        && ((n >> 2)
-	   >> (gdbarch_int_bit (parse_gdbarch)-2))) /* Avoid shift warning */
+	   >> (gdbarch_int_bit (parse_gdbarch (ps))-2))) /* Avoid
+							    shift warning */
       || long_p)
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch)-1);
-      unsigned_type = parse_type->builtin_unsigned_long;
-      signed_type = parse_type->builtin_long;
+      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (ps))-1);
+      unsigned_type = parse_type (ps)->builtin_unsigned_long;
+      signed_type = parse_type (ps)->builtin_long;
     }
   else 
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch)-1);
-      unsigned_type = parse_type->builtin_unsigned_int;
-      signed_type = parse_type->builtin_int;
+      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (ps))-1);
+      unsigned_type = parse_type (ps)->builtin_unsigned_int;
+      signed_type = parse_type (ps)->builtin_int;
     }    
   
   putithere->typed_val.val = n;
@@ -895,8 +905,7 @@ static int tempbufindex;	/* Current index into buffer */
    first one on demand.  */
 
 static void
-growbuf_by_size (count)
-     int count;
+growbuf_by_size (int count)
 {
   int growby;
 
@@ -950,7 +959,7 @@ match_string_literal (void)
 /* Read one token, getting characters through lexptr.  */
 
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   int c;
   int namelen;
@@ -1090,7 +1099,8 @@ yylex (void)
 			 && (*p < 'A' || *p > 'Z')))
 	      break;
 	  }
-	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
+	toktype = parse_number (ps, tokstart, p - tokstart,
+				got_dot|got_e|got_d,
 				&yylval);
         if (toktype == ERROR)
           {
@@ -1164,7 +1174,7 @@ yylex (void)
   
   if (*tokstart == '$')
     {
-      write_dollar_variable (yylval.sval);
+      write_dollar_variable (ps, yylval.sval);
       return VARIABLE;
     }
   
@@ -1179,7 +1189,7 @@ yylex (void)
     
     sym = lookup_symbol (tmp, expression_context_block,
 			 VAR_DOMAIN,
-			 parse_language->la_language == language_cplus
+			 parse_language (ps)->la_language == language_cplus
 			 ? &is_a_field_of_this : NULL);
     if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
       {
@@ -1187,8 +1197,8 @@ yylex (void)
 	return TYPENAME;
       }
     yylval.tsym.type
-      = language_lookup_primitive_type_by_name (parse_language,
-						parse_gdbarch, tmp);
+      = language_lookup_primitive_type_by_name (parse_language (ps),
+						parse_gdbarch (ps), tmp);
     if (yylval.tsym.type != NULL)
       return TYPENAME;
     
@@ -1200,7 +1210,7 @@ yylex (void)
 	    || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
       {
  	YYSTYPE newlval;	/* Its value is ignored.  */
-	hextype = parse_number (tokstart, namelen, 0, &newlval);
+	hextype = parse_number (ps, tokstart, namelen, 0, &newlval);
 	if (hextype == INT)
 	  {
 	    yylval.ssym.sym = sym;
@@ -1217,8 +1227,7 @@ yylex (void)
 }
 
 void
-yyerror (msg)
-     char *msg;
+yyerror (struct parser_state *ps, char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 3a46ebf..0e55d94 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -21,9 +21,11 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-extern int f_parse (void);
+struct parser_state;
 
-extern void f_error (char *);	/* Defined in f-exp.y */
+extern int f_parse (struct parser_state *);
+
+extern void f_error (struct parser_state *, char *); /* Defined in f-exp.y */
 
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
 			  int);

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

* [RFC 5/8] Java language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (3 preceding siblings ...)
  2012-01-15 19:05 ` [RFC 4/8] Fortran language Sergio Durigan Junior
@ 2012-01-15 19:06 ` Sergio Durigan Junior
  2012-01-15 19:07 ` [RFC 6/8] Modula-2 language Sergio Durigan Junior
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:06 UTC (permalink / raw)
  To: gdb-patches

Hi,

This is the patch for the Java language.

Thanks,

Sergio.

diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y
index a8eb430..50d3383 100644
--- a/gdb/jv-exp.y
+++ b/gdb/jv-exp.y
@@ -48,8 +48,8 @@
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
 #include "block.h"
 
-#define parse_type builtin_type (parse_gdbarch)
-#define parse_java_type builtin_java_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
+#define parse_java_type(ps) builtin_java_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -105,21 +105,24 @@
 
 #define YYFPRINTF parser_fprintf
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 static struct type *java_type_from_name (struct stoken);
-static void push_expression_name (struct stoken);
-static void push_fieldnames (struct stoken);
+static void push_expression_name (struct parser_state *, struct stoken);
+static void push_fieldnames (struct parser_state *, struct stoken);
 
 static struct expression *copy_exp (struct expression *, int);
-static void insert_exp (int, struct expression *);
+static void insert_exp (struct parser_state *, int, struct expression *);
 
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -148,7 +151,7 @@ static void insert_exp (int, struct expression *);
 
 %{
 /* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *, char *, int, int, YYSTYPE *);
 %}
 
 %type <lval> rcurly Dims Dims_opt
@@ -208,9 +211,9 @@ start   :	exp1
 
 type_exp:	PrimitiveOrArrayType
 		{
-		  write_exp_elt_opcode(OP_TYPE);
-		  write_exp_elt_type($1);
-		  write_exp_elt_opcode(OP_TYPE);
+		  write_exp_elt_opcode (ps, OP_TYPE);
+		  write_exp_elt_type (ps, $1);
+		  write_exp_elt_opcode (ps, OP_TYPE);
 		}
 	;
 
@@ -222,36 +225,37 @@ PrimitiveOrArrayType:
 StringLiteral:
 	STRING_LITERAL
 		{
-		  write_exp_elt_opcode (OP_STRING);
-		  write_exp_string ($1);
-		  write_exp_elt_opcode (OP_STRING);
+		  write_exp_elt_opcode (ps, OP_STRING);
+		  write_exp_string (ps, $1);
+		  write_exp_elt_opcode (ps, OP_STRING);
 		}
 ;
 
 Literal:
 	INTEGER_LITERAL
-		{ write_exp_elt_opcode (OP_LONG);
-		  write_exp_elt_type ($1.type);
-		  write_exp_elt_longcst ((LONGEST)($1.val));
-		  write_exp_elt_opcode (OP_LONG); }
+		{ write_exp_elt_opcode (ps, OP_LONG);
+		  write_exp_elt_type (ps, $1.type);
+		  write_exp_elt_longcst (ps, (LONGEST)($1.val));
+		  write_exp_elt_opcode (ps, OP_LONG); }
 |	NAME_OR_INT
 		{ YYSTYPE val;
-		  parse_number ($1.ptr, $1.length, 0, &val);
-		  write_exp_elt_opcode (OP_LONG);
-		  write_exp_elt_type (val.typed_val_int.type);
-		  write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
-		  write_exp_elt_opcode (OP_LONG);
+		  parse_number (ps, $1.ptr, $1.length, 0, &val);
+		  write_exp_elt_opcode (ps, OP_LONG);
+		  write_exp_elt_type (ps, val.typed_val_int.type);
+		  write_exp_elt_longcst (ps, (LONGEST)val.typed_val_int.val);
+		  write_exp_elt_opcode (ps, OP_LONG);
 		}
 |	FLOATING_POINT_LITERAL
-		{ write_exp_elt_opcode (OP_DOUBLE);
-		  write_exp_elt_type ($1.type);
-		  write_exp_elt_dblcst ($1.dval);
-		  write_exp_elt_opcode (OP_DOUBLE); }
+		{ write_exp_elt_opcode (ps, OP_DOUBLE);
+		  write_exp_elt_type (ps, $1.type);
+		  write_exp_elt_dblcst (ps, $1.dval);
+		  write_exp_elt_opcode (ps, OP_DOUBLE); }
 |	BOOLEAN_LITERAL
-		{ write_exp_elt_opcode (OP_LONG);
-		  write_exp_elt_type (parse_java_type->builtin_boolean);
-		  write_exp_elt_longcst ((LONGEST)$1);
-		  write_exp_elt_opcode (OP_LONG); }
+		{ write_exp_elt_opcode (ps, OP_LONG);
+		  write_exp_elt_type (ps,
+				      parse_java_type (ps)->builtin_boolean);
+		  write_exp_elt_longcst (ps, (LONGEST)$1);
+		  write_exp_elt_opcode (ps, OP_LONG); }
 |	StringLiteral
 	;
 
@@ -265,7 +269,7 @@ Type:
 PrimitiveType:
 	NumericType
 |	BOOLEAN
-		{ $$ = parse_java_type->builtin_boolean; }
+		{ $$ = parse_java_type (ps)->builtin_boolean; }
 ;
 
 NumericType:
@@ -275,22 +279,22 @@ NumericType:
 
 IntegralType:
 	BYTE
-		{ $$ = parse_java_type->builtin_byte; }
+		{ $$ = parse_java_type (ps)->builtin_byte; }
 |	SHORT
-		{ $$ = parse_java_type->builtin_short; }
+		{ $$ = parse_java_type (ps)->builtin_short; }
 |	INT
-		{ $$ = parse_java_type->builtin_int; }
+		{ $$ = parse_java_type (ps)->builtin_int; }
 |	LONG
-		{ $$ = parse_java_type->builtin_long; }
+		{ $$ = parse_java_type (ps)->builtin_long; }
 |	CHAR
-		{ $$ = parse_java_type->builtin_char; }
+		{ $$ = parse_java_type (ps)->builtin_char; }
 ;
 
 FloatingPointType:
 	FLOAT
-		{ $$ = parse_java_type->builtin_float; }
+		{ $$ = parse_java_type (ps)->builtin_float; }
 |	DOUBLE
-		{ $$ = parse_java_type->builtin_double; }
+		{ $$ = parse_java_type (ps)->builtin_double; }
 ;
 
 /* UNUSED:
@@ -357,7 +361,7 @@ type_exp:	type
 /* Expressions, including the comma operator.  */
 exp1	:	Expression
 	|	exp1 ',' Expression
-			{ write_exp_elt_opcode (BINOP_COMMA); }
+			{ write_exp_elt_opcode (ps, BINOP_COMMA); }
 	;
 
 Primary:
@@ -373,10 +377,10 @@ PrimaryNoNewArray:
 |	MethodInvocation
 |	ArrayAccess
 |	lcurly ArgumentList rcurly
-		{ write_exp_elt_opcode (OP_ARRAY);
-		  write_exp_elt_longcst ((LONGEST) 0);
-		  write_exp_elt_longcst ((LONGEST) $3);
-		  write_exp_elt_opcode (OP_ARRAY); }
+		{ write_exp_elt_opcode (ps, OP_ARRAY);
+		  write_exp_elt_longcst (ps, (LONGEST) 0);
+		  write_exp_elt_longcst (ps, (LONGEST) $3);
+		  write_exp_elt_opcode (ps, OP_ARRAY); }
 ;
 
 lcurly:
@@ -441,24 +445,24 @@ Dims_opt:
 
 FieldAccess:
 	Primary '.' SimpleName
-		{ push_fieldnames ($3); }
+		{ push_fieldnames (ps, $3); }
 |	VARIABLE '.' SimpleName
-		{ push_fieldnames ($3); }
+		{ push_fieldnames (ps, $3); }
 /*|	SUPER '.' SimpleName { FIXME } */
 ;
 
 FuncStart:
 	Name '('
-                { push_expression_name ($1); }
+                { push_expression_name (ps, $1); }
 ;
 
 MethodInvocation:
 	FuncStart
                 { start_arglist(); }
 	ArgumentList_opt ')'
-                { write_exp_elt_opcode (OP_FUNCALL);
-		  write_exp_elt_longcst ((LONGEST) end_arglist ());
-		  write_exp_elt_opcode (OP_FUNCALL); }
+                { write_exp_elt_opcode (ps, OP_FUNCALL);
+		  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+		  write_exp_elt_opcode (ps, OP_FUNCALL); }
 |	Primary '.' SimpleName '(' ArgumentList_opt ')'
 		{ error (_("Form of method invocation not implemented")); }
 |	SUPER '.' SimpleName '(' ArgumentList_opt ')'
@@ -475,24 +479,26 @@ ArrayAccess:
 		     for our parsing kludges.  */
 		  struct expression *name_expr;
 
-		  push_expression_name ($1);
-		  name_expr = copy_exp (expout, expout_ptr);
-		  expout_ptr -= name_expr->nelts;
-		  insert_exp (expout_ptr-length_of_subexp (expout, expout_ptr),
+		  push_expression_name (ps, $1);
+		  name_expr = copy_exp (ps->expout, ps->expout_ptr);
+		  ps->expout_ptr -= name_expr->nelts;
+		  insert_exp (ps,
+			      ps->expout_ptr - length_of_subexp (ps->expout,
+							      ps->expout_ptr),
 			      name_expr);
 		  free (name_expr);
-		  write_exp_elt_opcode (BINOP_SUBSCRIPT);
+		  write_exp_elt_opcode (ps, BINOP_SUBSCRIPT);
 		}
 |	VARIABLE '[' Expression ']'
-		{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+		{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 |	PrimaryNoNewArray '[' Expression ']'
-		{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+		{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 ;
 
 PostfixExpression:
 	Primary
 |	Name
-		{ push_expression_name ($1); }
+		{ push_expression_name (ps, $1); }
 |	VARIABLE
 		/* Already written by write_dollar_variable.  */
 |	PostIncrementExpression
@@ -501,12 +507,12 @@ PostfixExpression:
 
 PostIncrementExpression:
 	PostfixExpression INCREMENT
-		{ write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+		{ write_exp_elt_opcode (ps, UNOP_POSTINCREMENT); }
 ;
 
 PostDecrementExpression:
 	PostfixExpression DECREMENT
-		{ write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+		{ write_exp_elt_opcode (ps, UNOP_POSTDECREMENT); }
 ;
 
 UnaryExpression:
@@ -514,144 +520,149 @@ UnaryExpression:
 |	PreDecrementExpression
 |	'+' UnaryExpression
 |	'-' UnaryExpression
-		{ write_exp_elt_opcode (UNOP_NEG); }
+		{ write_exp_elt_opcode (ps, UNOP_NEG); }
 |	'*' UnaryExpression 
-		{ write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java  */
+		{ write_exp_elt_opcode (ps, UNOP_IND); } /*FIXME not in Java  */
 |	UnaryExpressionNotPlusMinus
 ;
 
 PreIncrementExpression:
 	INCREMENT UnaryExpression
-		{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
+		{ write_exp_elt_opcode (ps, UNOP_PREINCREMENT); }
 ;
 
 PreDecrementExpression:
 	DECREMENT UnaryExpression
-		{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
+		{ write_exp_elt_opcode (ps, UNOP_PREDECREMENT); }
 ;
 
 UnaryExpressionNotPlusMinus:
 	PostfixExpression
 |	'~' UnaryExpression
-		{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
+		{ write_exp_elt_opcode (ps, UNOP_COMPLEMENT); }
 |	'!' UnaryExpression
-		{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+		{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 |	CastExpression
 	;
 
 CastExpression:
 	'(' PrimitiveType Dims_opt ')' UnaryExpression
-		{ write_exp_elt_opcode (UNOP_CAST);
-		  write_exp_elt_type (java_array_type ($2, $3));
-		  write_exp_elt_opcode (UNOP_CAST); }
+		{ write_exp_elt_opcode (ps, UNOP_CAST);
+		  write_exp_elt_type (ps, java_array_type ($2, $3));
+		  write_exp_elt_opcode (ps, UNOP_CAST); }
 |	'(' Expression ')' UnaryExpressionNotPlusMinus
 		{
-		  int last_exp_size = length_of_subexp(expout, expout_ptr);
+		  int last_exp_size = length_of_subexp (ps->expout,
+							ps->expout_ptr);
 		  struct type *type;
 		  int i;
-		  int base = expout_ptr - last_exp_size - 3;
-		  if (base < 0 || expout->elts[base+2].opcode != OP_TYPE)
+		  int base = ps->expout_ptr - last_exp_size - 3;
+
+		  if (base < 0 || ps->expout->elts[base+2].opcode != OP_TYPE)
 		    error (_("Invalid cast expression"));
-		  type = expout->elts[base+1].type;
+		  type = ps->expout->elts[base+1].type;
 		  /* Remove the 'Expression' and slide the
 		     UnaryExpressionNotPlusMinus down to replace it.  */
 		  for (i = 0;  i < last_exp_size;  i++)
-		    expout->elts[base + i] = expout->elts[base + i + 3];
-		  expout_ptr -= 3;
+		    ps->expout->elts[base + i]
+		      = ps->expout->elts[base + i + 3];
+		  ps->expout_ptr -= 3;
 		  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
 		    type = lookup_pointer_type (type);
-		  write_exp_elt_opcode (UNOP_CAST);
-		  write_exp_elt_type (type);
-		  write_exp_elt_opcode (UNOP_CAST);
+		  write_exp_elt_opcode (ps, UNOP_CAST);
+		  write_exp_elt_type (ps, type);
+		  write_exp_elt_opcode (ps, UNOP_CAST);
 		}
 |	'(' Name Dims ')' UnaryExpressionNotPlusMinus
-		{ write_exp_elt_opcode (UNOP_CAST);
-		  write_exp_elt_type (java_array_type (java_type_from_name ($2), $3));
-		  write_exp_elt_opcode (UNOP_CAST); }
+		{ write_exp_elt_opcode (ps, UNOP_CAST);
+		  write_exp_elt_type (ps,
+				      java_array_type (java_type_from_name
+						       ($2), $3));
+		  write_exp_elt_opcode (ps, UNOP_CAST); }
 ;
 
 
 MultiplicativeExpression:
 	UnaryExpression
 |	MultiplicativeExpression '*' UnaryExpression
-		{ write_exp_elt_opcode (BINOP_MUL); }
+		{ write_exp_elt_opcode (ps, BINOP_MUL); }
 |	MultiplicativeExpression '/' UnaryExpression
-		{ write_exp_elt_opcode (BINOP_DIV); }
+		{ write_exp_elt_opcode (ps, BINOP_DIV); }
 |	MultiplicativeExpression '%' UnaryExpression
-		{ write_exp_elt_opcode (BINOP_REM); }
+		{ write_exp_elt_opcode (ps, BINOP_REM); }
 ;
 
 AdditiveExpression:
 	MultiplicativeExpression
 |	AdditiveExpression '+' MultiplicativeExpression
-		{ write_exp_elt_opcode (BINOP_ADD); }
+		{ write_exp_elt_opcode (ps, BINOP_ADD); }
 |	AdditiveExpression '-' MultiplicativeExpression
-		{ write_exp_elt_opcode (BINOP_SUB); }
+		{ write_exp_elt_opcode (ps, BINOP_SUB); }
 ;
 
 ShiftExpression:
 	AdditiveExpression
 |	ShiftExpression LSH AdditiveExpression
-		{ write_exp_elt_opcode (BINOP_LSH); }
+		{ write_exp_elt_opcode (ps, BINOP_LSH); }
 |	ShiftExpression RSH AdditiveExpression
-		{ write_exp_elt_opcode (BINOP_RSH); }
+		{ write_exp_elt_opcode (ps, BINOP_RSH); }
 /* |	ShiftExpression >>> AdditiveExpression { FIXME } */
 ;
 
 RelationalExpression:
 	ShiftExpression
 |	RelationalExpression '<' ShiftExpression
-		{ write_exp_elt_opcode (BINOP_LESS); }
+		{ write_exp_elt_opcode (ps, BINOP_LESS); }
 |	RelationalExpression '>' ShiftExpression
-		{ write_exp_elt_opcode (BINOP_GTR); }
+		{ write_exp_elt_opcode (ps, BINOP_GTR); }
 |	RelationalExpression LEQ ShiftExpression
-		{ write_exp_elt_opcode (BINOP_LEQ); }
+		{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 |	RelationalExpression GEQ ShiftExpression
-		{ write_exp_elt_opcode (BINOP_GEQ); }
+		{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 /* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */
 ;
 
 EqualityExpression:
 	RelationalExpression
 |	EqualityExpression EQUAL RelationalExpression
-		{ write_exp_elt_opcode (BINOP_EQUAL); }
+		{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 |	EqualityExpression NOTEQUAL RelationalExpression
-		{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+		{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 ;
 
 AndExpression:
 	EqualityExpression
 |	AndExpression '&' EqualityExpression
-		{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+		{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 ;
 
 ExclusiveOrExpression:
 	AndExpression
 |	ExclusiveOrExpression '^' AndExpression
-		{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+		{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 ;
 InclusiveOrExpression:
 	ExclusiveOrExpression
 |	InclusiveOrExpression '|' ExclusiveOrExpression
-		{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+		{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 ;
 
 ConditionalAndExpression:
 	InclusiveOrExpression
 |	ConditionalAndExpression ANDAND InclusiveOrExpression
-		{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+		{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 ;
 
 ConditionalOrExpression:
 	ConditionalAndExpression
 |	ConditionalOrExpression OROR ConditionalAndExpression
-		{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+		{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 ;
 
 ConditionalExpression:
 	ConditionalOrExpression
 |	ConditionalOrExpression '?' Expression ':' ConditionalExpression
-		{ write_exp_elt_opcode (TERNOP_COND); }
+		{ write_exp_elt_opcode (ps, TERNOP_COND); }
 ;
 
 AssignmentExpression:
@@ -661,16 +672,16 @@ AssignmentExpression:
 			  
 Assignment:
 	LeftHandSide '=' ConditionalExpression
-		{ write_exp_elt_opcode (BINOP_ASSIGN); }
+		{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 |	LeftHandSide ASSIGN_MODIFY ConditionalExpression
-		{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
-		  write_exp_elt_opcode ($2);
-		  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
+		{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+		  write_exp_elt_opcode (ps, $2);
+		  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 ;
 
 LeftHandSide:
 	ForcedName
-		{ push_expression_name ($1); }
+		{ push_expression_name (ps, $1); }
 |	VARIABLE
 		/* Already written by write_dollar_variable.  */
 |	FieldAccess
@@ -690,7 +701,8 @@ Expression:
 /*** Needs some error checking for the float case ***/
 
 static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (struct parser_state *ps, char *p, int len, int parsed_float,
+	      YYSTYPE *putithere)
 {
   ULONGEST n = 0;
   ULONGEST limit, limit_div_base;
@@ -711,16 +723,16 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
       suffix_len = p + len - suffix;
 
       if (suffix_len == 0)
-	putithere->typed_val_float.type = parse_type->builtin_double;
+	putithere->typed_val_float.type = parse_type (ps)->builtin_double;
       else if (suffix_len == 1)
 	{
 	  /* See if it has `f' or `d' suffix (float or double).  */
 	  if (tolower (*suffix) == 'f')
 	    putithere->typed_val_float.type =
-	      parse_type->builtin_float;
+	      parse_type (ps)->builtin_float;
 	  else if (tolower (*suffix) == 'd')
 	    putithere->typed_val_float.type =
-	      parse_type->builtin_double;
+	      parse_type (ps)->builtin_double;
 	  else
 	    return ERROR;
 	}
@@ -767,12 +779,12 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
   limit = ((limit << 16) << 16) | limit;
   if (c == 'l' || c == 'L')
     {
-      type = parse_java_type->builtin_long;
+      type = parse_java_type (ps)->builtin_long;
       len--;
     }
   else
     {
-      type = parse_java_type->builtin_int;
+      type = parse_java_type (ps)->builtin_int;
     }
   limit_div_base = limit / (ULONGEST) base;
 
@@ -797,11 +809,12 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 
   /* If the type is bigger than a 32-bit signed integer can be, implicitly
      promote to long.  Java does not do this, so mark it as
-     parse_type->builtin_uint64 rather than parse_java_type->builtin_long.
+     parse_type (ps)->builtin_uint64 rather than
+     parse_java_type (ps)->builtin_long.
      0x80000000 will become -0x80000000 instead of 0x80000000L, because we
      don't know the sign at this point.  */
-  if (type == parse_java_type->builtin_int && n > (ULONGEST)0x80000000)
-    type = parse_type->builtin_uint64;
+  if (type == parse_java_type (ps)->builtin_int && n > (ULONGEST)0x80000000)
+    type = parse_type (ps)->builtin_uint64;
 
   putithere->typed_val_int.val = n;
   putithere->typed_val_int.type = type;
@@ -847,7 +860,7 @@ static const struct token tokentab2[] =
 /* Read one token, getting characters through lexptr.  */
 
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   int c;
   int namelen;
@@ -899,12 +912,12 @@ yylex (void)
       lexptr++;
       c = *lexptr++;
       if (c == '\\')
-	c = parse_escape (parse_gdbarch, &lexptr);
+	c = parse_escape (parse_gdbarch (ps), &lexptr);
       else if (c == '\'')
 	error (_("Empty character constant"));
 
       yylval.typed_val_int.val = c;
-      yylval.typed_val_int.type = parse_java_type->builtin_char;
+      yylval.typed_val_int.type = parse_java_type (ps)->builtin_char;
 
       c = *lexptr++;
       if (c != '\'')
@@ -997,7 +1010,8 @@ yylex (void)
 				  && (*p < 'A' || *p > 'Z')))
 	      break;
 	  }
-	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
+	toktype = parse_number (ps, tokstart, p - tokstart,
+				got_dot|got_e, &yylval);
         if (toktype == ERROR)
 	  {
 	    char *err_copy = (char *) alloca (p - tokstart + 1);
@@ -1062,7 +1076,7 @@ yylex (void)
 	    break;
 	  case '\\':
 	    tokptr++;
-	    c = parse_escape (parse_gdbarch, &tokptr);
+	    c = parse_escape (parse_gdbarch (ps), &tokptr);
 	    if (c == -1)
 	      {
 		continue;
@@ -1174,7 +1188,7 @@ yylex (void)
 
   if (*tokstart == '$')
     {
-      write_dollar_variable (yylval.sval);
+      write_dollar_variable (ps, yylval.sval);
       return VARIABLE;
     }
 
@@ -1185,7 +1199,7 @@ yylex (void)
        (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
     {
       YYSTYPE newlval;	/* Its value is ignored.  */
-      int hextype = parse_number (tokstart, namelen, 0, &newlval);
+      int hextype = parse_number (ps, tokstart, namelen, 0, &newlval);
       if (hextype == INTEGER_LITERAL)
 	return NAME_OR_INT;
     }
@@ -1193,7 +1207,7 @@ yylex (void)
 }
 
 void
-yyerror (char *msg)
+yyerror (struct parser_state *ps, char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
@@ -1209,6 +1223,7 @@ java_type_from_name (struct stoken name)
 {
   char *tmp = copy_name (name);
   struct type *typ = java_lookup_class (tmp);
+
   if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT)
     error (_("No class named `%s'"), tmp);
   return typ;
@@ -1218,11 +1233,12 @@ java_type_from_name (struct stoken name)
    Otherwise, return 0.  */
 
 static int
-push_variable (struct stoken name)
+push_variable (struct parser_state *ps, struct stoken name)
 {
   char *tmp = copy_name (name);
   int is_a_field_of_this = 0;
   struct symbol *sym;
+
   sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN,
 		       &is_a_field_of_this);
   if (sym && SYMBOL_CLASS (sym) != LOC_TYPEDEF)
@@ -1234,12 +1250,12 @@ push_variable (struct stoken name)
 	    innermost_block = block_found;
 	}
 
-      write_exp_elt_opcode (OP_VAR_VALUE);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
       /* We want to use the selected frame, not another more inner frame
 	 which happens to be in the same block.  */
-      write_exp_elt_block (NULL);
-      write_exp_elt_sym (sym);
-      write_exp_elt_opcode (OP_VAR_VALUE);
+      write_exp_elt_block (ps, NULL);
+      write_exp_elt_sym (ps, sym);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
       return 1;
     }
   if (is_a_field_of_this)
@@ -1249,11 +1265,11 @@ push_variable (struct stoken name)
       if (innermost_block == 0 || 
 	  contained_in (block_found, innermost_block))
 	innermost_block = block_found;
-      write_exp_elt_opcode (OP_THIS);
-      write_exp_elt_opcode (OP_THIS);
-      write_exp_elt_opcode (STRUCTOP_PTR);
-      write_exp_string (name);
-      write_exp_elt_opcode (STRUCTOP_PTR);
+      write_exp_elt_opcode (ps, OP_THIS);
+      write_exp_elt_opcode (ps, OP_THIS);
+      write_exp_elt_opcode (ps, STRUCTOP_PTR);
+      write_exp_string (ps, name);
+      write_exp_elt_opcode (ps, STRUCTOP_PTR);
       return 1;
     }
   return 0;
@@ -1264,7 +1280,7 @@ push_variable (struct stoken name)
    qualified name (has '.'), generate a field access for each part.  */
 
 static void
-push_fieldnames (struct stoken name)
+push_fieldnames (struct parser_state *ps, struct stoken name)
 {
   int i;
   struct stoken token;
@@ -1275,9 +1291,9 @@ push_fieldnames (struct stoken name)
 	{
 	  /* token.ptr is start of current field name.  */
 	  token.length = &name.ptr[i] - token.ptr;
-	  write_exp_elt_opcode (STRUCTOP_PTR);
-	  write_exp_string (token);
-	  write_exp_elt_opcode (STRUCTOP_PTR);
+	  write_exp_elt_opcode (ps, STRUCTOP_PTR);
+	  write_exp_string (ps, token);
+	  write_exp_elt_opcode (ps, STRUCTOP_PTR);
 	  token.ptr += token.length + 1;
 	}
       if (i >= name.length)
@@ -1289,7 +1305,8 @@ push_fieldnames (struct stoken name)
    Handle a qualified name, where DOT_INDEX is the index of the first '.' */
 
 static void
-push_qualified_expression_name (struct stoken name, int dot_index)
+push_qualified_expression_name (struct parser_state *ps, struct stoken name,
+				int dot_index)
 {
   struct stoken token;
   char *tmp;
@@ -1298,11 +1315,11 @@ push_qualified_expression_name (struct stoken name, int dot_index)
   token.ptr = name.ptr;
   token.length = dot_index;
 
-  if (push_variable (token))
+  if (push_variable (ps, token))
     {
       token.ptr = name.ptr + dot_index + 1;
       token.length = name.length - dot_index - 1;
-      push_fieldnames (token);
+      push_fieldnames (ps, token);
       return;
     }
 
@@ -1316,9 +1333,9 @@ push_qualified_expression_name (struct stoken name, int dot_index)
 	{
 	  if (dot_index == name.length)
 	    {
-	      write_exp_elt_opcode(OP_TYPE);
-	      write_exp_elt_type(typ);
-	      write_exp_elt_opcode(OP_TYPE);
+	      write_exp_elt_opcode (ps, OP_TYPE);
+	      write_exp_elt_type (ps, typ);
+	      write_exp_elt_opcode (ps, OP_TYPE);
 	      return;
 	    }
 	  dot_index++;  /* Skip '.' */
@@ -1329,16 +1346,16 @@ push_qualified_expression_name (struct stoken name, int dot_index)
 	    dot_index++;
 	  token.ptr = name.ptr;
 	  token.length = dot_index;
-	  write_exp_elt_opcode (OP_SCOPE);
-	  write_exp_elt_type (typ);
-	  write_exp_string (token);
-	  write_exp_elt_opcode (OP_SCOPE); 
+	  write_exp_elt_opcode (ps, OP_SCOPE);
+	  write_exp_elt_type (ps, typ);
+	  write_exp_string (ps, token);
+	  write_exp_elt_opcode (ps, OP_SCOPE); 
 	  if (dot_index < name.length)
 	    {
 	      dot_index++;
 	      name.ptr += dot_index;
 	      name.length -= dot_index;
-	      push_fieldnames (name);
+	      push_fieldnames (ps, name);
 	    }
 	  return;
 	}
@@ -1355,7 +1372,7 @@ push_qualified_expression_name (struct stoken name, int dot_index)
    Handle VAR, TYPE, TYPE.FIELD1....FIELDN and VAR.FIELD1....FIELDN.  */
 
 static void
-push_expression_name (struct stoken name)
+push_expression_name (struct parser_state *ps, struct stoken name)
 {
   char *tmp;
   struct type *typ;
@@ -1366,22 +1383,22 @@ push_expression_name (struct stoken name)
       if (name.ptr[i] == '.')
 	{
 	  /* It's a Qualified Expression Name.  */
-	  push_qualified_expression_name (name, i);
+	  push_qualified_expression_name (ps, name, i);
 	  return;
 	}
     }
 
   /* It's a Simple Expression Name.  */
   
-  if (push_variable (name))
+  if (push_variable (ps, name))
     return;
   tmp = copy_name (name);
   typ = java_lookup_class (tmp);
   if (typ != NULL)
     {
-      write_exp_elt_opcode(OP_TYPE);
-      write_exp_elt_type(typ);
-      write_exp_elt_opcode(OP_TYPE);
+      write_exp_elt_opcode (ps, OP_TYPE);
+      write_exp_elt_type (ps, typ);
+      write_exp_elt_opcode (ps, OP_TYPE);
     }
   else
     {
@@ -1389,7 +1406,7 @@ push_expression_name (struct stoken name)
 
       msymbol = lookup_minimal_symbol (tmp, NULL, NULL);
       if (msymbol != NULL)
-	write_exp_msymbol (msymbol);
+	write_exp_msymbol (ps, msymbol);
       else if (!have_full_symbols () && !have_partial_symbols ())
 	error (_("No symbol table is loaded.  Use the \"file\" command"));
       else
@@ -1413,6 +1430,7 @@ copy_exp (struct expression *expr, int endpos)
   int len = length_of_subexp (expr, endpos);
   struct expression *new
     = (struct expression *) malloc (sizeof (*new) + EXP_ELEM_TO_BYTES (len));
+
   new->nelts = len;
   memcpy (new->elts, expr->elts + endpos - len, EXP_ELEM_TO_BYTES (len));
   new->language_defn = 0;
@@ -1422,27 +1440,20 @@ copy_exp (struct expression *expr, int endpos)
 
 /* Insert the expression NEW into the current expression (expout) at POS.  */
 static void
-insert_exp (int pos, struct expression *new)
+insert_exp (struct parser_state *ps, int pos, struct expression *new)
 {
   int newlen = new->nelts;
+  int i;
+
 
   /* Grow expout if necessary.  In this function's only use at present,
      this should never be necessary.  */
-  if (expout_ptr + newlen > expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + newlen + 10);
-      expout = (struct expression *)
-	realloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, newlen);
 
-  {
-    int i;
 
-    for (i = expout_ptr - 1; i >= pos; i--)
-      expout->elts[i + newlen] = expout->elts[i];
-  }
+  for (i = ps->expout_ptr - 1; i >= pos; i--)
+    ps->expout->elts[i + newlen] = ps->expout->elts[i];
   
-  memcpy (expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen));
-  expout_ptr += newlen;
+  memcpy (ps->expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen));
+  ps->expout_ptr += newlen;
 }
diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h
index 4344706..d34c803 100644
--- a/gdb/jv-lang.h
+++ b/gdb/jv-lang.h
@@ -22,10 +22,12 @@
 #define JV_LANG_H
 
 struct value;
+struct parser_state;
 
-extern int java_parse (void);		/* Defined in jv-exp.y */
+extern int java_parse (struct parser_state *); /* Defined in jv-exp.y */
 
-extern void java_error (char *);	/* Defined in jv-exp.y */
+extern void java_error (struct parser_state *, char *);	/* Defined
+							   in jv-exp.y */
 
 struct builtin_java_type
 {

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

* [RFC 6/8] Modula-2 language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (4 preceding siblings ...)
  2012-01-15 19:06 ` [RFC 5/8] Java language Sergio Durigan Junior
@ 2012-01-15 19:07 ` Sergio Durigan Junior
  2012-01-17 10:21   ` Gaius Mulley
  2012-01-15 19:10 ` [RFC 7/8] Objective-C language Sergio Durigan Junior
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:07 UTC (permalink / raw)
  To: gdb-patches

Hello,

This is the patch for the Modula-2 language.

Thanks,

Sergio.

diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index ef9ec8e..afa96ef 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -50,8 +50,8 @@
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
 #include "block.h"
 
-#define parse_type builtin_type (parse_gdbarch)
-#define parse_m2_type builtin_m2_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
+#define parse_m2_type(ps) builtin_m2_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -107,29 +107,22 @@
 
 #define YYFPRINTF parser_fprintf
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
-
-#if 0
-static char *make_qualname (char *, char *);
-#endif
+void yyerror (struct parser_state *, char *);
 
 static int parse_number (int);
 
 /* The sign of the number being parsed.  */
 static int number_sign = 1;
 
-/* The block that the module specified by the qualifer on an identifer is
-   contained in, */
-#if 0
-static struct block *modblock=0;
-#endif
-
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -209,31 +202,31 @@ start   :	exp
 	;
 
 type_exp:	type
-		{ write_exp_elt_opcode(OP_TYPE);
-		  write_exp_elt_type($1);
-		  write_exp_elt_opcode(OP_TYPE);
+		{ write_exp_elt_opcode (ps, OP_TYPE);
+		  write_exp_elt_type (ps, $1);
+		  write_exp_elt_opcode (ps, OP_TYPE);
 		}
 	;
 
 /* Expressions */
 
 exp     :       exp '^'   %prec UNARY
-                        { write_exp_elt_opcode (UNOP_IND); }
+                        { write_exp_elt_opcode (ps, UNOP_IND); }
 	;
 
 exp	:	'-'
 			{ number_sign = -1; }
 		exp    %prec UNARY
 			{ number_sign = 1;
-			  write_exp_elt_opcode (UNOP_NEG); }
+			  write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 exp	:	'+' exp    %prec UNARY
-		{ write_exp_elt_opcode(UNOP_PLUS); }
+		{ write_exp_elt_opcode (ps, UNOP_PLUS); }
 	;
 
 exp	:	not_exp exp %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 not_exp	:	NOT
@@ -241,88 +234,88 @@ not_exp	:	NOT
 	;
 
 exp	:	CAP '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_CAP); }
+			{ write_exp_elt_opcode (ps, UNOP_CAP); }
 	;
 
 exp	:	ORD '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_ORD); }
+			{ write_exp_elt_opcode (ps, UNOP_ORD); }
 	;
 
 exp	:	ABS '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_ABS); }
+			{ write_exp_elt_opcode (ps, UNOP_ABS); }
 	;
 
 exp	: 	HIGH '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_HIGH); }
+			{ write_exp_elt_opcode (ps, UNOP_HIGH); }
 	;
 
 exp 	:	MIN_FUNC '(' type ')'
-			{ write_exp_elt_opcode (UNOP_MIN);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_MIN); }
+			{ write_exp_elt_opcode (ps, UNOP_MIN);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_MIN); }
 	;
 
 exp	: 	MAX_FUNC '(' type ')'
-			{ write_exp_elt_opcode (UNOP_MAX);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (UNOP_MAX); }
+			{ write_exp_elt_opcode (ps, UNOP_MAX);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, UNOP_MAX); }
 	;
 
 exp	:	FLOAT_FUNC '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_FLOAT); }
+			{ write_exp_elt_opcode (ps, UNOP_FLOAT); }
 	;
 
 exp	:	VAL '(' type ',' exp ')'
-			{ write_exp_elt_opcode (BINOP_VAL);
-			  write_exp_elt_type ($3);
-			  write_exp_elt_opcode (BINOP_VAL); }
+			{ write_exp_elt_opcode (ps, BINOP_VAL);
+			  write_exp_elt_type (ps, $3);
+			  write_exp_elt_opcode (ps, BINOP_VAL); }
 	;
 
 exp	:	CHR '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_CHR); }
+			{ write_exp_elt_opcode (ps, UNOP_CHR); }
 	;
 
 exp	:	ODD '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_ODD); }
+			{ write_exp_elt_opcode (ps, UNOP_ODD); }
 	;
 
 exp	:	TRUNC '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_TRUNC); }
+			{ write_exp_elt_opcode (ps, UNOP_TRUNC); }
 	;
 
 exp	:	TSIZE '(' exp ')'
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 	;
 
 exp	:	SIZE exp       %prec UNARY
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 	;
 
 
 exp	:	INC '(' exp ')'
-			{ write_exp_elt_opcode(UNOP_PREINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREINCREMENT); }
 	;
 
 exp	:	INC '(' exp ',' exp ')'
-			{ write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
-			  write_exp_elt_opcode(BINOP_ADD);
-			  write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+			  write_exp_elt_opcode (ps, BINOP_ADD);
+			  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 	;
 
 exp	:	DEC '(' exp ')'
-			{ write_exp_elt_opcode(UNOP_PREDECREMENT);}
+			{ write_exp_elt_opcode (ps, UNOP_PREDECREMENT);}
 	;
 
 exp	:	DEC '(' exp ',' exp ')'
-			{ write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
-			  write_exp_elt_opcode(BINOP_SUB);
-			  write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+			  write_exp_elt_opcode (ps, BINOP_SUB);
+			  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 	;
 
 exp	:	exp DOT NAME
-			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 exp	:	set
@@ -354,13 +347,13 @@ exp     :       exp '['
 			   function types */
                         { start_arglist(); }
                 non_empty_arglist ']'  %prec DOT
-                        { write_exp_elt_opcode (MULTI_SUBSCRIPT);
-			  write_exp_elt_longcst ((LONGEST) end_arglist());
-			  write_exp_elt_opcode (MULTI_SUBSCRIPT); }
+                        { write_exp_elt_opcode (ps, MULTI_SUBSCRIPT);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist());
+			  write_exp_elt_opcode (ps, MULTI_SUBSCRIPT); }
         ;
 
 exp	:	exp '[' exp ']'
-			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+			{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 	;
 
 exp	:	exp '('
@@ -368,9 +361,9 @@ exp	:	exp '('
 			   being accumulated by an outer function call.  */
 			{ start_arglist (); }
 		arglist ')'	%prec DOT
-			{ write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_FUNCALL); }
+			{ write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_FUNCALL); }
 	;
 
 arglist	:
@@ -396,15 +389,15 @@ non_empty_arglist
 
 /* GDB construct */
 exp	:	'{' type '}' exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_MEMVAL);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_MEMVAL); }
+			{ write_exp_elt_opcode (ps, UNOP_MEMVAL);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_MEMVAL); }
 	;
 
 exp     :       type '(' exp ')' %prec UNARY
-                        { write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($1);
-			  write_exp_elt_opcode (UNOP_CAST); }
+                        { write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 exp	:	'(' exp ')'
@@ -416,131 +409,139 @@ exp	:	'(' exp ')'
 
 /* GDB construct */
 exp	:	exp '@' exp
-			{ write_exp_elt_opcode (BINOP_REPEAT); }
+			{ write_exp_elt_opcode (ps, BINOP_REPEAT); }
 	;
 
 exp	:	exp '*' exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 exp	:	exp '/' exp
-			{ write_exp_elt_opcode (BINOP_DIV); }
+			{ write_exp_elt_opcode (ps, BINOP_DIV); }
 	;
 
 exp     :       exp DIV exp
-                        { write_exp_elt_opcode (BINOP_INTDIV); }
+                        { write_exp_elt_opcode (ps, BINOP_INTDIV); }
         ;
 
 exp	:	exp MOD exp
-			{ write_exp_elt_opcode (BINOP_REM); }
+			{ write_exp_elt_opcode (ps, BINOP_REM); }
 	;
 
 exp	:	exp '+' exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 exp	:	exp '-' exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 exp	:	exp '=' exp
-			{ write_exp_elt_opcode (BINOP_EQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 	;
 
 exp	:	exp NOTEQUAL exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
         |       exp '#' exp
-                        { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+                        { write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 	;
 
 exp	:	exp LEQ exp
-			{ write_exp_elt_opcode (BINOP_LEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 	;
 
 exp	:	exp GEQ exp
-			{ write_exp_elt_opcode (BINOP_GEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 	;
 
 exp	:	exp '<' exp
-			{ write_exp_elt_opcode (BINOP_LESS); }
+			{ write_exp_elt_opcode (ps, BINOP_LESS); }
 	;
 
 exp	:	exp '>' exp
-			{ write_exp_elt_opcode (BINOP_GTR); }
+			{ write_exp_elt_opcode (ps, BINOP_GTR); }
 	;
 
 exp	:	exp LOGICAL_AND exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 	;
 
 exp	:	exp OROR exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 	;
 
 exp	:	exp ASSIGN exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 
 /* Constants */
 
 exp	:	M2_TRUE
-			{ write_exp_elt_opcode (OP_BOOL);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_BOOL); }
+			{ write_exp_elt_opcode (ps, OP_BOOL);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_BOOL); }
 	;
 
 exp	:	M2_FALSE
-			{ write_exp_elt_opcode (OP_BOOL);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_BOOL); }
+			{ write_exp_elt_opcode (ps, OP_BOOL);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_BOOL); }
 	;
 
 exp	:	INT
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_m2_type->builtin_int);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps,
+					      parse_m2_type (ps)->builtin_int);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	UINT
 			{
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_m2_type->builtin_card);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_LONG);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps,
+					      parse_m2_type (ps)
+					      ->builtin_card);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_LONG);
 			}
 	;
 
 exp	:	CHAR
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_m2_type->builtin_char);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps,
+					      parse_m2_type (ps)
+					      ->builtin_char);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 
 exp	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type (parse_m2_type->builtin_real);
-			  write_exp_elt_dblcst ($1);
-			  write_exp_elt_opcode (OP_DOUBLE); }
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps,
+					      parse_m2_type (ps)
+					      ->builtin_real);
+			  write_exp_elt_dblcst (ps, $1);
+			  write_exp_elt_opcode (ps, OP_DOUBLE); }
 	;
 
 exp	:	variable
 	;
 
 exp	:	SIZE '(' type ')'	%prec UNARY
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_int);
-			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_int);
+			  write_exp_elt_longcst (ps,
+						 (LONGEST) TYPE_LENGTH ($3));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	STRING
-			{ write_exp_elt_opcode (OP_M2_STRING);
-			  write_exp_string ($1);
-			  write_exp_elt_opcode (OP_M2_STRING); }
+			{ write_exp_elt_opcode (ps, OP_M2_STRING);
+			  write_exp_string (ps, $1);
+			  write_exp_elt_opcode (ps, OP_M2_STRING); }
 	;
 
 /* This will be used for extensions later.  Like adding modules.  */
@@ -550,7 +551,8 @@ block	:	fblock
 
 fblock	:	BLOCKNAME
 			{ struct symbol *sym
-			    = lookup_symbol (copy_name ($1), expression_context_block,
+			    = lookup_symbol (copy_name ($1),
+					     expression_context_block,
 					     VAR_DOMAIN, 0);
 			  $$ = sym;}
 	;
@@ -570,10 +572,10 @@ fblock	:	block COLONCOLON BLOCKNAME
 
 /* Useful for assigning to PROCEDURE variables */
 variable:	fblock
-			{ write_exp_elt_opcode(OP_VAR_VALUE);
-			  write_exp_elt_block (NULL);
-			  write_exp_elt_sym ($1);
-			  write_exp_elt_opcode (OP_VAR_VALUE); }
+			{ write_exp_elt_opcode (ps, OP_VAR_VALUE);
+			  write_exp_elt_block (ps, NULL);
+			  write_exp_elt_sym (ps, $1);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE); }
 	;
 
 /* GDB internal ($foo) variable */
@@ -596,11 +598,11 @@ variable:	block COLONCOLON NAME
 				innermost_block = block_found;
 			    }
 
-			  write_exp_elt_opcode (OP_VAR_VALUE);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			  /* block_found is set by lookup_symbol.  */
-			  write_exp_elt_block (block_found);
-			  write_exp_elt_sym (sym);
-			  write_exp_elt_opcode (OP_VAR_VALUE); }
+			  write_exp_elt_block (ps, block_found);
+			  write_exp_elt_sym (ps, sym);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE); }
 	;
 
 /* Base case for variables.  */
@@ -622,13 +624,13 @@ variable:	NAME
 				    innermost_block = block_found;
 				}
 
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      /* We want to use the selected frame, not
 				 another more inner frame which happens to
 				 be in the same block.  */
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			    }
 			  else
 			    {
@@ -638,7 +640,7 @@ variable:	NAME
 			      msymbol =
 				lookup_minimal_symbol (arg, NULL, NULL);
 			      if (msymbol != NULL)
-				write_exp_msymbol (msymbol);
+				write_exp_msymbol (ps, msymbol);
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  Use the \"symbol-file\" command."));
 			      else
@@ -650,7 +652,8 @@ variable:	NAME
 
 type
 	:	TYPENAME
-			{ $$ = lookup_typename (parse_language, parse_gdbarch,
+			{ $$ = lookup_typename (parse_language (ps),
+						parse_gdbarch (ps),
 						copy_name ($1),
 						expression_context_block, 0); }
 
@@ -665,8 +668,7 @@ type
 /*** Needs some error checking for the float case ***/
 
 static int
-parse_number (olen)
-     int olen;
+parse_number (int olen)
 {
   char *p = lexptr;
   LONGEST n = 0;
@@ -811,11 +813,11 @@ static struct keyword keytab[] =
 
 /* Read one token, getting characters through lexptr.  */
 
-/* This is where we will check to make sure that the language and the operators used are
-   compatible  */
+/* This is where we will check to make sure that the language and the
+   operators used are compatible  */
 
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   int c;
   int namelen;
@@ -998,7 +1000,7 @@ yylex (void)
 
   if (*tokstart == '$')
     {
-      write_dollar_variable (yylval.sval);
+      write_dollar_variable (ps, yylval.sval);
       return INTERNAL_VAR;
     }
 
@@ -1018,7 +1020,7 @@ yylex (void)
     sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0);
     if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
       return BLOCKNAME;
-    if (lookup_typename (parse_language, parse_gdbarch,
+    if (lookup_typename (parse_language (ps), parse_gdbarch (ps),
 			 copy_name (yylval.sval), expression_context_block, 1))
       return TYPENAME;
 
@@ -1076,23 +1078,8 @@ yylex (void)
  }
 }
 
-#if 0		/* Unused */
-static char *
-make_qualname(mod,ident)
-   char *mod, *ident;
-{
-   char *new = malloc(strlen(mod)+strlen(ident)+2);
-
-   strcpy(new,mod);
-   strcat(new,".");
-   strcat(new,ident);
-   return new;
-}
-#endif  /* 0 */
-
 void
-yyerror (msg)
-     char *msg;
+yyerror (struct parser_state *ps, char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
index 2803e63..ce50701 100644
--- a/gdb/m2-lang.h
+++ b/gdb/m2-lang.h
@@ -18,9 +18,11 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-extern int m2_parse (void);	/* Defined in m2-exp.y */
+struct parser_state;
 
-extern void m2_error (char *);	/* Defined in m2-exp.y */
+extern int m2_parse (struct parser_state *); /* Defined in m2-exp.y */
+
+extern void m2_error (struct parser_state *, char *); /* Defined in m2-exp.y */
 
 /* Defined in m2-typeprint.c */
 extern void m2_print_type (struct type *, const char *, struct ui_file *, int,

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

* [RFC 7/8] Objective-C language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (5 preceding siblings ...)
  2012-01-15 19:07 ` [RFC 6/8] Modula-2 language Sergio Durigan Junior
@ 2012-01-15 19:10 ` Sergio Durigan Junior
  2012-01-15 20:34 ` [RFC 8/8] Pascal language Sergio Durigan Junior
  2012-01-16 19:29 ` [RFC 0/8] Beginning to remove globals from parser-defs.h Tom Tromey
  8 siblings, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 19:10 UTC (permalink / raw)
  To: gdb-patches

Hello,

This is the patch for the Objective-C language.

Thanks,

Sergio.

diff --git a/gdb/objc-exp.y b/gdb/objc-exp.y
index b43ba66..8ed73dc 100644
--- a/gdb/objc-exp.y
+++ b/gdb/objc-exp.y
@@ -52,7 +52,7 @@
 #include "completer.h" /* For skip_quoted().  */
 #include "block.h"
 
-#define parse_type builtin_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
    etc), as well as gratuitiously global symbol names, so we can have
@@ -107,14 +107,17 @@
 #define	YYDEBUG	0		/* Default to no yydebug support.  */
 #endif
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -147,7 +150,7 @@ void yyerror (char *);
 
 %{
 /* YYSTYPE gets defined by %union.  */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *, char *, int, int, YYSTYPE *);
 %}
 
 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
@@ -229,79 +232,79 @@ start   :	exp1
 	;
 
 type_exp:	type
-			{ write_exp_elt_opcode(OP_TYPE);
-			  write_exp_elt_type($1);
-			  write_exp_elt_opcode(OP_TYPE);}
+			{ write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, OP_TYPE);}
 	;
 
 /* Expressions, including the comma operator.  */
 exp1	:	exp
 	|	exp1 ',' exp
-			{ write_exp_elt_opcode (BINOP_COMMA); }
+			{ write_exp_elt_opcode (ps, BINOP_COMMA); }
 	;
 
 /* Expressions, not including the comma operator.  */
 exp	:	'*' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_IND); }
+			{ write_exp_elt_opcode (ps, UNOP_IND); }
 	;
 
 exp	:	'&' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_ADDR); }
+			{ write_exp_elt_opcode (ps, UNOP_ADDR); }
 	;
 
 exp	:	'-' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_NEG); }
+			{ write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 exp	:	'!' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 exp	:	'~' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_COMPLEMENT); }
 	;
 
 exp	:	INCREMENT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREINCREMENT); }
 	;
 
 exp	:	DECREMENT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREDECREMENT); }
 	;
 
 exp	:	exp INCREMENT    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_POSTINCREMENT); }
 	;
 
 exp	:	exp DECREMENT    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_POSTDECREMENT); }
 	;
 
 exp	:	SIZEOF exp       %prec UNARY
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 	;
 
 exp	:	exp ARROW name
-			{ write_exp_elt_opcode (STRUCTOP_PTR);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_PTR); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_PTR); }
 	;
 
 exp	:	exp ARROW qualified_name
 			{ /* exp->type::name becomes exp->*(&type::name) */
 			  /* Note: this doesn't work if name is a
 			     static member!  FIXME */
-			  write_exp_elt_opcode (UNOP_ADDR);
-			  write_exp_elt_opcode (STRUCTOP_MPTR); }
+			  write_exp_elt_opcode (ps, UNOP_ADDR);
+			  write_exp_elt_opcode (ps, STRUCTOP_MPTR); }
 	;
 exp	:	exp ARROW '*' exp
-			{ write_exp_elt_opcode (STRUCTOP_MPTR); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_MPTR); }
 	;
 
 exp	:	exp '.' name
-			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 
@@ -309,16 +312,16 @@ exp	:	exp '.' qualified_name
 			{ /* exp.type::name becomes exp.*(&type::name) */
 			  /* Note: this doesn't work if name is a
 			     static member!  FIXME */
-			  write_exp_elt_opcode (UNOP_ADDR);
-			  write_exp_elt_opcode (STRUCTOP_MEMBER); }
+			  write_exp_elt_opcode (ps, UNOP_ADDR);
+			  write_exp_elt_opcode (ps, STRUCTOP_MEMBER); }
 	;
 
 exp	:	exp '.' '*' exp
-			{ write_exp_elt_opcode (STRUCTOP_MEMBER); }
+			{ write_exp_elt_opcode (ps, STRUCTOP_MEMBER); }
 	;
 
 exp	:	exp '[' exp1 ']'
-			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+			{ write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); }
 	;
 /*
  * The rules below parse ObjC message calls of the form:
@@ -329,50 +332,50 @@ exp	: 	'[' TYPENAME
 			{
 			  CORE_ADDR class;
 
-			  class = lookup_objc_class (parse_gdbarch,
+			  class = lookup_objc_class (parse_gdbarch (ps),
 						     copy_name ($2.stoken));
 			  if (class == 0)
 			    error (_("%s is not an ObjC Class"), 
 				   copy_name ($2.stoken));
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_int);
-			  write_exp_elt_longcst ((LONGEST) class);
-			  write_exp_elt_opcode (OP_LONG);
-			  start_msglist();
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_int);
+			  write_exp_elt_longcst (ps, (LONGEST) class);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  start_msglist ();
 			}
 		msglist ']'
-			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
-			  end_msglist();
-			  write_exp_elt_opcode (OP_OBJC_MSGCALL); 
+			{ write_exp_elt_opcode (ps, OP_OBJC_MSGCALL);
+			  end_msglist (ps);
+			  write_exp_elt_opcode (ps, OP_OBJC_MSGCALL); 
 			}
 	;
 
 exp	:	'[' CLASSNAME
 			{
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_int);
-			  write_exp_elt_longcst ((LONGEST) $2.class);
-			  write_exp_elt_opcode (OP_LONG);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_int);
+			  write_exp_elt_longcst (ps, (LONGEST) $2.class);
+			  write_exp_elt_opcode (ps, OP_LONG);
 			  start_msglist();
 			}
 		msglist ']'
-			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
-			  end_msglist();
-			  write_exp_elt_opcode (OP_OBJC_MSGCALL); 
+			{ write_exp_elt_opcode (ps, OP_OBJC_MSGCALL);
+			  end_msglist (ps);
+			  write_exp_elt_opcode (ps, OP_OBJC_MSGCALL); 
 			}
 	;
 
 exp	:	'[' exp
-			{ start_msglist(); }
+			{ start_msglist (); }
 		msglist ']'
-			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
-			  end_msglist();
-			  write_exp_elt_opcode (OP_OBJC_MSGCALL); 
+			{ write_exp_elt_opcode (ps, OP_OBJC_MSGCALL);
+			  end_msglist (ps);
+			  write_exp_elt_opcode (ps, OP_OBJC_MSGCALL); 
 			}
 	;
 
 msglist :	name
-			{ add_msglist(&$1, 0); }
+			{ add_msglist (&$1, 0); }
 	|	msgarglist
 	;
 
@@ -393,9 +396,9 @@ exp	:	exp '('
 			   being accumulated by an outer function call.  */
 			{ start_arglist (); }
 		arglist ')'	%prec ARROW
-			{ write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_FUNCALL); }
+			{ write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_FUNCALL); }
 	;
 
 lcurly	:	'{'
@@ -417,22 +420,22 @@ rcurly	:	'}'
 			{ $$ = end_arglist () - 1; }
 	;
 exp	:	lcurly arglist rcurly	%prec ARROW
-			{ write_exp_elt_opcode (OP_ARRAY);
-			  write_exp_elt_longcst ((LONGEST) 0);
-			  write_exp_elt_longcst ((LONGEST) $3);
-			  write_exp_elt_opcode (OP_ARRAY); }
+			{ write_exp_elt_opcode (ps, OP_ARRAY);
+			  write_exp_elt_longcst (ps, (LONGEST) 0);
+			  write_exp_elt_longcst (ps, (LONGEST) $3);
+			  write_exp_elt_opcode (ps, OP_ARRAY); }
 	;
 
 exp	:	lcurly type rcurly exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_MEMVAL);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_MEMVAL); }
+			{ write_exp_elt_opcode (ps, UNOP_MEMVAL);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_MEMVAL); }
 	;
 
 exp	:	'(' type ')' exp  %prec UNARY
-			{ write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($2);
-			  write_exp_elt_opcode (UNOP_CAST); }
+			{ write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $2);
+			  write_exp_elt_opcode (ps, UNOP_CAST); }
 	;
 
 exp	:	'(' exp1 ')'
@@ -442,120 +445,120 @@ exp	:	'(' exp1 ')'
 /* Binary operators in order of decreasing precedence.  */
 
 exp	:	exp '@' exp
-			{ write_exp_elt_opcode (BINOP_REPEAT); }
+			{ write_exp_elt_opcode (ps, BINOP_REPEAT); }
 	;
 
 exp	:	exp '*' exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 exp	:	exp '/' exp
-			{ write_exp_elt_opcode (BINOP_DIV); }
+			{ write_exp_elt_opcode (ps, BINOP_DIV); }
 	;
 
 exp	:	exp '%' exp
-			{ write_exp_elt_opcode (BINOP_REM); }
+			{ write_exp_elt_opcode (ps, BINOP_REM); }
 	;
 
 exp	:	exp '+' exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 exp	:	exp '-' exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 exp	:	exp LSH exp
-			{ write_exp_elt_opcode (BINOP_LSH); }
+			{ write_exp_elt_opcode (ps, BINOP_LSH); }
 	;
 
 exp	:	exp RSH exp
-			{ write_exp_elt_opcode (BINOP_RSH); }
+			{ write_exp_elt_opcode (ps, BINOP_RSH); }
 	;
 
 exp	:	exp EQUAL exp
-			{ write_exp_elt_opcode (BINOP_EQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL); }
 	;
 
 exp	:	exp NOTEQUAL exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL); }
 	;
 
 exp	:	exp LEQ exp
-			{ write_exp_elt_opcode (BINOP_LEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_LEQ); }
 	;
 
 exp	:	exp GEQ exp
-			{ write_exp_elt_opcode (BINOP_GEQ); }
+			{ write_exp_elt_opcode (ps, BINOP_GEQ); }
 	;
 
 exp	:	exp '<' exp
-			{ write_exp_elt_opcode (BINOP_LESS); }
+			{ write_exp_elt_opcode (ps, BINOP_LESS); }
 	;
 
 exp	:	exp '>' exp
-			{ write_exp_elt_opcode (BINOP_GTR); }
+			{ write_exp_elt_opcode (ps, BINOP_GTR); }
 	;
 
 exp	:	exp '&' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	;
 
 exp	:	exp '^' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 	;
 
 exp	:	exp '|' exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	;
 
 exp	:	exp ANDAND exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); }
 	;
 
 exp	:	exp OROR exp
-			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+			{ write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); }
 	;
 
 exp	:	exp '?' exp ':' exp	%prec '?'
-			{ write_exp_elt_opcode (TERNOP_COND); }
+			{ write_exp_elt_opcode (ps, TERNOP_COND); }
 	;
 			  
 exp	:	exp '=' exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 exp	:	exp ASSIGN_MODIFY exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
-			  write_exp_elt_opcode ($2);
-			  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY);
+			  write_exp_elt_opcode (ps, $2);
+			  write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); }
 	;
 
 exp	:	INT
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_longcst ((LONGEST)($1.val));
-			  write_exp_elt_opcode (OP_LONG); }
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_longcst (ps, (LONGEST) ($1.val));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	NAME_OR_INT
 			{ YYSTYPE val;
-			  parse_number ($1.stoken.ptr,
+			  parse_number (ps, $1.stoken.ptr,
 					$1.stoken.length, 0, &val);
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (val.typed_val_int.type);
-			  write_exp_elt_longcst ((LONGEST) 
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, val.typed_val_int.type);
+			  write_exp_elt_longcst (ps, (LONGEST) 
 						 val.typed_val_int.val);
-			  write_exp_elt_opcode (OP_LONG);
+			  write_exp_elt_opcode (ps, OP_LONG);
 			}
 	;
 
 
 exp	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type ($1.type);
-			  write_exp_elt_dblcst ($1.dval);
-			  write_exp_elt_opcode (OP_DOUBLE); }
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps, $1.type);
+			  write_exp_elt_dblcst (ps, $1.dval);
+			  write_exp_elt_opcode (ps, OP_DOUBLE); }
 	;
 
 exp	:	variable
@@ -567,17 +570,17 @@ exp	:	VARIABLE
 
 exp	:	SELECTOR 
 			{
-			  write_exp_elt_opcode (OP_OBJC_SELECTOR);
-			  write_exp_string ($1);
-			  write_exp_elt_opcode (OP_OBJC_SELECTOR); }
+			  write_exp_elt_opcode (ps, OP_OBJC_SELECTOR);
+			  write_exp_string (ps, $1);
+			  write_exp_elt_opcode (ps, OP_OBJC_SELECTOR); }
 	;
 
 exp	:	SIZEOF '(' type ')'	%prec UNARY
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_int);
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_int);
 			  CHECK_TYPEDEF ($3);
-			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
-			  write_exp_elt_opcode (OP_LONG); }
+			  write_exp_elt_longcst (ps, (LONGEST) TYPE_LENGTH ($3));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	STRING
@@ -590,27 +593,27 @@ exp	:	STRING
 			  char *sp = $1.ptr; int count = $1.length;
 			  while (count-- > 0)
 			    {
-			      write_exp_elt_opcode (OP_LONG);
-			      write_exp_elt_type (parse_type->builtin_char);
-			      write_exp_elt_longcst ((LONGEST)(*sp++));
-			      write_exp_elt_opcode (OP_LONG);
+			      write_exp_elt_opcode (ps, OP_LONG);
+			      write_exp_elt_type (ps, parse_type (ps)->builtin_char);
+			      write_exp_elt_longcst (ps, (LONGEST) (*sp++));
+			      write_exp_elt_opcode (ps, OP_LONG);
 			    }
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_char);
-			  write_exp_elt_longcst ((LONGEST)'\0');
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_opcode (OP_ARRAY);
-			  write_exp_elt_longcst ((LONGEST) 0);
-			  write_exp_elt_longcst ((LONGEST) ($1.length));
-			  write_exp_elt_opcode (OP_ARRAY); }
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_char);
+			  write_exp_elt_longcst (ps, (LONGEST)'\0');
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_opcode (ps, OP_ARRAY);
+			  write_exp_elt_longcst (ps, (LONGEST) 0);
+			  write_exp_elt_longcst (ps, (LONGEST) ($1.length));
+			  write_exp_elt_opcode (ps, OP_ARRAY); }
 	;
 
 exp     :	NSSTRING	/* ObjC NextStep NSString constant
 				 * of the form '@' '"' string '"'.
 				 */
-			{ write_exp_elt_opcode (OP_OBJC_NSSTRING);
-			  write_exp_string ($1);
-			  write_exp_elt_opcode (OP_OBJC_NSSTRING); }
+			{ write_exp_elt_opcode (ps, OP_OBJC_NSSTRING);
+			  write_exp_string (ps, $1);
+			  write_exp_elt_opcode (ps, OP_OBJC_NSSTRING); }
 	;
 
 block	:	BLOCKNAME
@@ -656,11 +659,11 @@ variable:	block COLONCOLON name
 				innermost_block = block_found;
 			    }
 
-			  write_exp_elt_opcode (OP_VAR_VALUE);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			  /* block_found is set by lookup_symbol.  */
-			  write_exp_elt_block (block_found);
-			  write_exp_elt_sym (sym);
-			  write_exp_elt_opcode (OP_VAR_VALUE); }
+			  write_exp_elt_block (ps, block_found);
+			  write_exp_elt_sym (ps, sym);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE); }
 	;
 
 qualified_name:	typebase COLONCOLON name
@@ -671,10 +674,10 @@ qualified_name:	typebase COLONCOLON name
 			    error (_("`%s' is not defined as an aggregate type."),
 				   TYPE_NAME (type));
 
-			  write_exp_elt_opcode (OP_SCOPE);
-			  write_exp_elt_type (type);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (OP_SCOPE);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
+			  write_exp_elt_type (ps, type);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
 			}
 	|	typebase COLONCOLON '~' name
 			{
@@ -694,10 +697,10 @@ qualified_name:	typebase COLONCOLON name
 			  tmp_token.ptr[0] = '~';
 			  memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
 			  tmp_token.ptr[tmp_token.length] = 0;
-			  write_exp_elt_opcode (OP_SCOPE);
-			  write_exp_elt_type (type);
-			  write_exp_string (tmp_token);
-			  write_exp_elt_opcode (OP_SCOPE);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
+			  write_exp_elt_type (ps, type);
+			  write_exp_string (ps, tmp_token);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
 			}
 	;
 
@@ -713,16 +716,16 @@ variable:	qualified_name
 					   VAR_DOMAIN, (int *) NULL);
 			  if (sym)
 			    {
-			      write_exp_elt_opcode (OP_VAR_VALUE);
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      break;
 			    }
 
 			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
 			  if (msymbol != NULL)
-			    write_exp_msymbol (msymbol);
+			    write_exp_msymbol (ps, msymbol);
 			  else if (!have_full_symbols ()
 				   && !have_partial_symbols ())
 			    error (_("No symbol table is loaded.  "
@@ -746,13 +749,13 @@ variable:	name_not_typename
 				    innermost_block = block_found;
 				}
 
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      /* We want to use the selected frame, not
 				 another more inner frame which happens to
 				 be in the same block.  */
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			    }
 			  else if ($1.is_a_field_of_this)
 			    {
@@ -762,11 +765,11 @@ variable:	name_not_typename
 			      if (innermost_block == 0 || 
 				  contained_in (block_found, innermost_block))
 				innermost_block = block_found;
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
-			      write_exp_string ($1.stoken);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			      write_exp_string (ps, $1.stoken);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
 			    }
 			  else
 			    {
@@ -776,7 +779,7 @@ variable:	name_not_typename
 			      msymbol =
 				lookup_minimal_symbol (arg, NULL, NULL);
 			      if (msymbol != NULL)
-				write_exp_msymbol (msymbol);
+				write_exp_msymbol (ps, msymbol);
 			      else if (!have_full_symbols () && 
 				       !have_partial_symbols ())
 				error (_("No symbol table is loaded.  "
@@ -871,31 +874,31 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier.  */
 			    $$ = $1.type;
 			}
 	|	INT_KEYWORD
-			{ $$ = parse_type->builtin_int; }
+			{ $$ = parse_type (ps)->builtin_int; }
 	|	LONG
-			{ $$ = parse_type->builtin_long; }
+			{ $$ = parse_type (ps)->builtin_long; }
 	|	SHORT
-			{ $$ = parse_type->builtin_short; }
+			{ $$ = parse_type (ps)->builtin_short; }
 	|	LONG INT_KEYWORD
-			{ $$ = parse_type->builtin_long; }
+			{ $$ = parse_type (ps)->builtin_long; }
 	|	UNSIGNED LONG INT_KEYWORD
-			{ $$ = parse_type->builtin_unsigned_long; }
+			{ $$ = parse_type (ps)->builtin_unsigned_long; }
 	|	LONG LONG
-			{ $$ = parse_type->builtin_long_long; }
+			{ $$ = parse_type (ps)->builtin_long_long; }
 	|	LONG LONG INT_KEYWORD
-			{ $$ = parse_type->builtin_long_long; }
+			{ $$ = parse_type (ps)->builtin_long_long; }
 	|	UNSIGNED LONG LONG
-			{ $$ = parse_type->builtin_unsigned_long_long; }
+			{ $$ = parse_type (ps)->builtin_unsigned_long_long; }
 	|	UNSIGNED LONG LONG INT_KEYWORD
-			{ $$ = parse_type->builtin_unsigned_long_long; }
+			{ $$ = parse_type (ps)->builtin_unsigned_long_long; }
 	|	SHORT INT_KEYWORD
-			{ $$ = parse_type->builtin_short; }
+			{ $$ = parse_type (ps)->builtin_short; }
 	|	UNSIGNED SHORT INT_KEYWORD
-			{ $$ = parse_type->builtin_unsigned_short; }
+			{ $$ = parse_type (ps)->builtin_unsigned_short; }
 	|	DOUBLE_KEYWORD
-			{ $$ = parse_type->builtin_double; }
+			{ $$ = parse_type (ps)->builtin_double; }
 	|	LONG DOUBLE_KEYWORD
-			{ $$ = parse_type->builtin_long_double; }
+			{ $$ = parse_type (ps)->builtin_long_double; }
 	|	STRUCT name
 			{ $$ = lookup_struct (copy_name ($2),
 					      expression_context_block); }
@@ -909,17 +912,17 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier.  */
 			{ $$ = lookup_enum (copy_name ($2),
 					    expression_context_block); }
 	|	UNSIGNED typename
-			{ $$ = lookup_unsigned_typename (parse_language,
-							 parse_gdbarch,
+			{ $$ = lookup_unsigned_typename (parse_language (ps),
+							 parse_gdbarch (ps),
 							 TYPE_NAME($2.type)); }
 	|	UNSIGNED
-			{ $$ = parse_type->builtin_unsigned_int; }
+			{ $$ = parse_type (ps)->builtin_unsigned_int; }
 	|	SIGNED_KEYWORD typename
-			{ $$ = lookup_signed_typename (parse_language,
-						       parse_gdbarch,
+			{ $$ = lookup_signed_typename (parse_language (ps),
+						       parse_gdbarch (ps),
 						       TYPE_NAME($2.type)); }
 	|	SIGNED_KEYWORD
-			{ $$ = parse_type->builtin_int; }
+			{ $$ = parse_type (ps)->builtin_int; }
 	|	TEMPLATE name '<' type '>'
 			{ $$ = lookup_template_type(copy_name($2), $4,
 						    expression_context_block);
@@ -936,19 +939,19 @@ typename:	TYPENAME
 		{
 		  $$.stoken.ptr = "int";
 		  $$.stoken.length = 3;
-		  $$.type = parse_type->builtin_int;
+		  $$.type = parse_type (ps)->builtin_int;
 		}
 	|	LONG
 		{
 		  $$.stoken.ptr = "long";
 		  $$.stoken.length = 4;
-		  $$.type = parse_type->builtin_long;
+		  $$.type = parse_type (ps)->builtin_long;
 		}
 	|	SHORT
 		{
 		  $$.stoken.ptr = "short";
 		  $$.stoken.length = 5;
-		  $$.type = parse_type->builtin_short;
+		  $$.type = parse_type (ps)->builtin_short;
 		}
 	;
 
@@ -992,11 +995,8 @@ name_not_typename :	NAME
 /*** Needs some error checking for the float case.  ***/
 
 static int
-parse_number (p, len, parsed_float, putithere)
-     char *p;
-     int len;
-     int parsed_float;
-     YYSTYPE *putithere;
+parse_number (struct parser_state *ps, char *p, int len, int parsed_float,
+	      YYSTYPE *putithere)
 {
   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative
      values here, and we do kind of silly things like cast to
@@ -1022,7 +1022,7 @@ parse_number (p, len, parsed_float, putithere)
 
   if (parsed_float)
     {
-      if (! parse_c_float (parse_gdbarch, p, len,
+      if (! parse_c_float (parse_gdbarch (ps), p, len,
 			   &putithere->typed_val_float.dval,
 			   &putithere->typed_val_float.type))
 	return ERROR;
@@ -1128,10 +1128,10 @@ parse_number (p, len, parsed_float, putithere)
 
   un = (unsigned LONGEST)n >> 2;
   if (long_p == 0
-      && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
+      && (un >> (gdbarch_int_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
       high_bit
-	= ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+	= ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch (ps)) - 1);
 
       /* A large decimal (not hex or octal) constant (between INT_MAX
 	 and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -1139,29 +1139,29 @@ parse_number (p, len, parsed_float, putithere)
 	 int.  This probably should be fixed.  GCC gives a warning on
 	 such constants.  */
 
-      unsigned_type = parse_type->builtin_unsigned_int;
-      signed_type = parse_type->builtin_int;
+      unsigned_type = parse_type (ps)->builtin_unsigned_int;
+      signed_type = parse_type (ps)->builtin_int;
     }
   else if (long_p <= 1
-	   && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+	   && (un >> (gdbarch_long_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
       high_bit
-	= ((unsigned LONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
-      unsigned_type = parse_type->builtin_unsigned_long;
-      signed_type = parse_type->builtin_long;
+	= ((unsigned LONGEST)1) << (gdbarch_long_bit (parse_gdbarch (ps)) - 1);
+      unsigned_type = parse_type (ps)->builtin_unsigned_long;
+      signed_type = parse_type (ps)->builtin_long;
     }
   else
     {
       high_bit = (((unsigned LONGEST)1)
-		  << (gdbarch_long_long_bit (parse_gdbarch) - 32 - 1)
+		  << (gdbarch_long_long_bit (parse_gdbarch (ps)) - 32 - 1)
 		  << 16
 		  << 16);
       if (high_bit == 0)
 	/* A long long does not fit in a LONGEST.  */
 	high_bit =
 	  (unsigned LONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
-      unsigned_type = parse_type->builtin_unsigned_long_long;
-      signed_type = parse_type->builtin_long_long;
+      unsigned_type = parse_type (ps)->builtin_unsigned_long_long;
+      signed_type = parse_type (ps)->builtin_long_long;
     }
 
    putithere->typed_val_int.val = n;
@@ -1221,7 +1221,7 @@ static const struct token tokentab2[] =
 /* Read one token, getting characters through lexptr.  */
 
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   int c, tokchr;
   int namelen;
@@ -1272,12 +1272,12 @@ yylex (void)
       lexptr++;
       c = *lexptr++;
       if (c == '\\')
-	c = parse_escape (parse_gdbarch, &lexptr);
+	c = parse_escape (parse_gdbarch (ps), &lexptr);
       else if (c == '\'')
 	error (_("Empty character constant."));
 
       yylval.typed_val_int.val = c;
-      yylval.typed_val_int.type = parse_type->builtin_char;
+      yylval.typed_val_int.type = parse_type (ps)->builtin_char;
 
       c = *lexptr++;
       if (c != '\'')
@@ -1395,7 +1395,7 @@ yylex (void)
 	    else break;
 	  }
 	if (toktype != ERROR)
-	  toktype = parse_number (tokstart, p - tokstart, 
+	  toktype = parse_number (ps, tokstart, p - tokstart, 
 				  got_dot | got_e, &yylval);
         if (toktype == ERROR)
 	  {
@@ -1503,7 +1503,7 @@ yylex (void)
 	    break;
 	  case '\\':
 	    tokptr++;
-	    c = parse_escape (parse_gdbarch, &tokptr);
+	    c = parse_escape (parse_gdbarch (ps), &tokptr);
 	    if (c == -1)
 	      {
 		continue;
@@ -1564,7 +1564,7 @@ yylex (void)
     case 8:
       if (strncmp (tokstart, "unsigned", 8) == 0)
 	return UNSIGNED;
-      if (parse_language->la_language == language_cplus
+      if (parse_language (ps)->la_language == language_cplus
 	  && strncmp (tokstart, "template", 8) == 0)
 	return TEMPLATE;
       if (strncmp (tokstart, "volatile", 8) == 0)
@@ -1581,7 +1581,7 @@ yylex (void)
 	return DOUBLE_KEYWORD;
       break;
     case 5:
-      if ((parse_language->la_language == language_cplus)
+      if ((parse_language (ps)->la_language == language_cplus)
 	  && strncmp (tokstart, "class", 5) == 0)
 	return CLASS;
       if (strncmp (tokstart, "union", 5) == 0)
@@ -1610,7 +1610,7 @@ yylex (void)
 
   if (*tokstart == '$')
     {
-      write_dollar_variable (yylval.sval);
+      write_dollar_variable (ps, yylval.sval);
       return VARIABLE;
     }
 
@@ -1625,8 +1625,8 @@ yylex (void)
     int is_a_field_of_this = 0, *need_this;
     int hextype;
 
-    if (parse_language->la_language == language_cplus ||
-	parse_language->la_language == language_objc)
+    if (parse_language (ps)->la_language == language_cplus ||
+	parse_language (ps)->la_language == language_objc)
       need_this = &is_a_field_of_this;
     else
       need_this = (int *) NULL;
@@ -1738,15 +1738,15 @@ yylex (void)
 	  return TYPENAME;
         }
     yylval.tsym.type
-      = language_lookup_primitive_type_by_name (parse_language,
-						parse_gdbarch, tmp);
+      = language_lookup_primitive_type_by_name (parse_language (ps),
+						parse_gdbarch (ps), tmp);
     if (yylval.tsym.type != NULL)
       return TYPENAME;
 
     /* See if it's an ObjC classname.  */
     if (!sym)
       {
-	CORE_ADDR Class = lookup_objc_class (parse_gdbarch, tmp);
+	CORE_ADDR Class = lookup_objc_class (parse_gdbarch (ps), tmp);
 	if (Class)
 	  {
 	    yylval.class.class = Class;
@@ -1766,7 +1766,7 @@ yylex (void)
          (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
       {
  	YYSTYPE newlval;	/* Its value is ignored.  */
-	hextype = parse_number (tokstart, namelen, 0, &newlval);
+	hextype = parse_number (ps, tokstart, namelen, 0, &newlval);
 	if (hextype == INT)
 	  {
 	    yylval.ssym.sym = sym;
@@ -1783,8 +1783,7 @@ yylex (void)
 }
 
 void
-yyerror (msg)
-     char *msg;
+yyerror (struct parser_state *ps, char *msg)
 {
   if (*lexptr == '\0')
     error(_("A %s near end of expression."),  (msg ? msg : "error"));
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1c96309..9cb68ce 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -614,7 +614,7 @@ add_msglist(struct stoken *str, int addcolon)
 }
 
 int
-end_msglist(void)
+end_msglist (struct parser_state *ps)
 {
   int val = msglist_len;
   struct selname *sel = selname_chain;
@@ -624,12 +624,12 @@ end_msglist(void)
   selname_chain = sel->next;
   msglist_len = sel->msglist_len;
   msglist_sel = sel->msglist_sel;
-  selid = lookup_child_selector (parse_gdbarch, p);
+  selid = lookup_child_selector (parse_gdbarch (ps), p);
   if (!selid)
     error (_("Can't find selector \"%s\""), p);
-  write_exp_elt_longcst (selid);
+  write_exp_elt_longcst (ps, selid);
   xfree(p);
-  write_exp_elt_longcst (val);	/* Number of args */
+  write_exp_elt_longcst (ps, val);	/* Number of args */
   xfree(sel);
 
   return val;
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index 593ef02..d871d67 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -26,10 +26,12 @@ struct stoken;
 
 struct value;
 struct block;
+struct parser_state;
 
-extern int objc_parse (void);		/* Defined in c-exp.y */
+extern int objc_parse (struct parser_state *); /* Defined in objc-exp.y */
 
-extern void objc_error (char *);	/* Defined in c-exp.y */
+extern void objc_error (struct parser_state *, char *);	/* Defined
+							   in objc-exp.y */
 
 extern CORE_ADDR lookup_objc_class     (struct gdbarch *gdbarch,
 					char *classname);
@@ -48,7 +50,7 @@ extern struct value *value_nsstring (struct gdbarch *gdbarch,
 /* for parsing Objective C */
 extern void start_msglist (void);
 extern void add_msglist (struct stoken *str, int addcolon);
-extern int end_msglist (void);
+extern int end_msglist (struct parser_state *);
 
 struct symbol *lookup_struct_typedef (char *name, struct block *block,
 				      int noerr);

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

* [RFC 8/8] Pascal language
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (6 preceding siblings ...)
  2012-01-15 19:10 ` [RFC 7/8] Objective-C language Sergio Durigan Junior
@ 2012-01-15 20:34 ` Sergio Durigan Junior
  2012-01-16 19:29   ` Tom Tromey
  2012-01-16 19:29 ` [RFC 0/8] Beginning to remove globals from parser-defs.h Tom Tromey
  8 siblings, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 20:34 UTC (permalink / raw)
  To: gdb-patches

Hello,

This is the patch for the Pascal language.  I forgot to mention in the
other patches: I also took the liberty (in all files) to cleanup #if 0
functions, and to convert old-style function declarations to use the
"new" style, i.e.:

static void
foo (bar)
    int bar;
{
  /* ... */
}

becomes:

static void
foo (int bar)
{
  /* ... */
}

Thanks,

Sergio.

diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 7b05d58..a3d75e4 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -56,7 +56,7 @@
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols.  */
 #include "block.h"
 
-#define parse_type builtin_type (parse_gdbarch)
+#define parse_type(ps) builtin_type (parse_gdbarch (ps))
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -112,15 +112,18 @@
 
 #define YYFPRINTF parser_fprintf
 
-int yyparse (void);
+int yyparse (struct parser_state *);
 
-static int yylex (void);
+static int yylex (struct parser_state *);
 
-void yyerror (char *);
+void yyerror (struct parser_state *, char *);
 
 static char * uptok (char *, int);
 %}
 
+%parse-param {struct parser_state *ps}
+%lex-param {struct parser_state *ps}
+
 /* Although the yacc "value" of an expression is not used,
    since the result is stored in the structure being created,
    other node types do have values.  */
@@ -152,7 +155,7 @@ static char * uptok (char *, int);
 
 %{
 /* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *, char *, int, int, YYSTYPE *);
 
 static struct type *current_type;
 static struct internalvar *intvar;
@@ -245,44 +248,44 @@ normal_start	:
 	;
 
 type_exp:	type
-			{ write_exp_elt_opcode(OP_TYPE);
-			  write_exp_elt_type($1);
-			  write_exp_elt_opcode(OP_TYPE);
+			{ write_exp_elt_opcode (ps, OP_TYPE);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, OP_TYPE);
 			  current_type = $1; } ;
 
 /* Expressions, including the comma operator.  */
 exp1	:	exp
 	|	exp1 ',' exp
-			{ write_exp_elt_opcode (BINOP_COMMA); }
+			{ write_exp_elt_opcode (ps, BINOP_COMMA); }
 	;
 
 /* Expressions, not including the comma operator.  */
 exp	:	exp '^'   %prec UNARY
-			{ write_exp_elt_opcode (UNOP_IND);
+			{ write_exp_elt_opcode (ps, UNOP_IND);
 			  if (current_type)
 			    current_type = TYPE_TARGET_TYPE (current_type); }
 	;
 
 exp	:	'@' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_ADDR);
+			{ write_exp_elt_opcode (ps, UNOP_ADDR);
 			  if (current_type)
 			    current_type = TYPE_POINTER_TYPE (current_type); }
 	;
 
 exp	:	'-' exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_NEG); }
+			{ write_exp_elt_opcode (ps, UNOP_NEG); }
 	;
 
 exp	:	NOT exp    %prec UNARY
-			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+			{ write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); }
 	;
 
 exp	:	INCREMENT '(' exp ')'   %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREINCREMENT); }
 	;
 
 exp	:	DECREMENT  '(' exp ')'   %prec UNARY
-			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
+			{ write_exp_elt_opcode (ps, UNOP_PREDECREMENT); }
 	;
 
 
@@ -291,9 +294,9 @@ field_exp	:	exp '.'	%prec UNARY
 	;
 
 exp	:	field_exp FIELDNAME
-			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($2);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
+			{ write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $2);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
 			  search_field = 0;
 			  if (current_type)
 			    {
@@ -309,10 +312,10 @@ exp	:	field_exp FIELDNAME
 
 
 exp	:	field_exp name
-			{ mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
-			  write_exp_string ($2);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
+			{ mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			  write_exp_string (ps, $2);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
 			  search_field = 0;
 			  if (current_type)
 			    {
@@ -328,12 +331,12 @@ exp	:	field_exp name
 
 exp	:	field_exp COMPLETE
 			{ struct stoken s;
-			  mark_struct_expression ();
-			  write_exp_elt_opcode (STRUCTOP_STRUCT);
+			  mark_struct_expression (ps);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
 			  s.ptr = "";
 			  s.length = 0;
-			  write_exp_string (s);
-			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+			  write_exp_string (ps, s);
+			  write_exp_elt_opcode (ps, STRUCTOP_STRUCT); }
 	;
 
 exp	:	exp '['
@@ -351,14 +354,14 @@ exp	:	exp '['
 			      strcpy (stringsval.ptr, arrayname);
 			      current_type = TYPE_FIELD_TYPE (current_type,
 				arrayfieldindex - 1);
-			      write_exp_elt_opcode (STRUCTOP_STRUCT);
-			      write_exp_string (stringsval);
-			      write_exp_elt_opcode (STRUCTOP_STRUCT);
+			      write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
+			      write_exp_string (ps, stringsval);
+			      write_exp_elt_opcode (ps, STRUCTOP_STRUCT);
 			    }
 			  push_current_type ();  }
 		exp1 ']'
 			{ pop_current_type ();
-			  write_exp_elt_opcode (BINOP_SUBSCRIPT);
+			  write_exp_elt_opcode (ps, BINOP_SUBSCRIPT);
 			  if (current_type)
 			    current_type = TYPE_TARGET_TYPE (current_type); }
 	;
@@ -369,9 +372,9 @@ exp	:	exp '('
 			{ push_current_type ();
 			  start_arglist (); }
 		arglist ')'	%prec ARROW
-			{ write_exp_elt_opcode (OP_FUNCALL);
-			  write_exp_elt_longcst ((LONGEST) end_arglist ());
-			  write_exp_elt_opcode (OP_FUNCALL);
+			{ write_exp_elt_opcode (ps, OP_FUNCALL);
+			  write_exp_elt_longcst (ps, (LONGEST) end_arglist ());
+			  write_exp_elt_opcode (ps, OP_FUNCALL);
 			  pop_current_type ();
 			  if (current_type)
  	  		    current_type = TYPE_TARGET_TYPE (current_type);
@@ -392,11 +395,11 @@ exp	:	type '(' exp ')' %prec UNARY
 			      if ((TYPE_CODE (current_type) == TYPE_CODE_PTR)
 				  && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS)
 				  && (TYPE_CODE ($1) == TYPE_CODE_CLASS))
-				write_exp_elt_opcode (UNOP_IND);
+				write_exp_elt_opcode (ps, UNOP_IND);
 			    }
-			  write_exp_elt_opcode (UNOP_CAST);
-			  write_exp_elt_type ($1);
-			  write_exp_elt_opcode (UNOP_CAST);
+			  write_exp_elt_opcode (ps, UNOP_CAST);
+			  write_exp_elt_type (ps, $1);
+			  write_exp_elt_opcode (ps, UNOP_CAST);
 			  current_type = $1; }
 	;
 
@@ -407,7 +410,7 @@ exp	:	'(' exp1 ')'
 /* Binary operators in order of decreasing precedence.  */
 
 exp	:	exp '*' exp
-			{ write_exp_elt_opcode (BINOP_MUL); }
+			{ write_exp_elt_opcode (ps, BINOP_MUL); }
 	;
 
 exp	:	exp '/' {
@@ -419,135 +422,137 @@ exp	:	exp '/' {
 			  if (leftdiv_is_integer && current_type
 			      && is_integral_type (current_type))
 			    {
-			      write_exp_elt_opcode (UNOP_CAST);
-			      write_exp_elt_type (parse_type->builtin_long_double);
-			      current_type = parse_type->builtin_long_double;
-			      write_exp_elt_opcode (UNOP_CAST);
+			      write_exp_elt_opcode (ps, UNOP_CAST);
+			      write_exp_elt_type (ps,
+						  parse_type (ps)
+						  ->builtin_long_double);
+			      current_type = parse_type (ps)->builtin_long_double;
+			      write_exp_elt_opcode (ps, UNOP_CAST);
 			      leftdiv_is_integer = 0;
 			    }
 
-			  write_exp_elt_opcode (BINOP_DIV);
+			  write_exp_elt_opcode (ps, BINOP_DIV);
 			}
 	;
 
 exp	:	exp DIV exp
-			{ write_exp_elt_opcode (BINOP_INTDIV); }
+			{ write_exp_elt_opcode (ps, BINOP_INTDIV); }
 	;
 
 exp	:	exp MOD exp
-			{ write_exp_elt_opcode (BINOP_REM); }
+			{ write_exp_elt_opcode (ps, BINOP_REM); }
 	;
 
 exp	:	exp '+' exp
-			{ write_exp_elt_opcode (BINOP_ADD); }
+			{ write_exp_elt_opcode (ps, BINOP_ADD); }
 	;
 
 exp	:	exp '-' exp
-			{ write_exp_elt_opcode (BINOP_SUB); }
+			{ write_exp_elt_opcode (ps, BINOP_SUB); }
 	;
 
 exp	:	exp LSH exp
-			{ write_exp_elt_opcode (BINOP_LSH); }
+			{ write_exp_elt_opcode (ps, BINOP_LSH); }
 	;
 
 exp	:	exp RSH exp
-			{ write_exp_elt_opcode (BINOP_RSH); }
+			{ write_exp_elt_opcode (ps, BINOP_RSH); }
 	;
 
 exp	:	exp '=' exp
-			{ write_exp_elt_opcode (BINOP_EQUAL);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_EQUAL);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp NOTEQUAL exp
-			{ write_exp_elt_opcode (BINOP_NOTEQUAL);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_NOTEQUAL);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp LEQ exp
-			{ write_exp_elt_opcode (BINOP_LEQ);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_LEQ);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp GEQ exp
-			{ write_exp_elt_opcode (BINOP_GEQ);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_GEQ);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp '<' exp
-			{ write_exp_elt_opcode (BINOP_LESS);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_LESS);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp '>' exp
-			{ write_exp_elt_opcode (BINOP_GTR);
-			  current_type = parse_type->builtin_bool;
+			{ write_exp_elt_opcode (ps, BINOP_GTR);
+			  current_type = parse_type (ps)->builtin_bool;
 			}
 	;
 
 exp	:	exp ANDAND exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_AND); }
 	;
 
 exp	:	exp XOR exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); }
 	;
 
 exp	:	exp OR exp
-			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+			{ write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); }
 	;
 
 exp	:	exp ASSIGN exp
-			{ write_exp_elt_opcode (BINOP_ASSIGN); }
+			{ write_exp_elt_opcode (ps, BINOP_ASSIGN); }
 	;
 
 exp	:	TRUEKEYWORD
-			{ write_exp_elt_opcode (OP_BOOL);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  current_type = parse_type->builtin_bool;
-			  write_exp_elt_opcode (OP_BOOL); }
+			{ write_exp_elt_opcode (ps, OP_BOOL);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  current_type = parse_type (ps)->builtin_bool;
+			  write_exp_elt_opcode (ps, OP_BOOL); }
 	;
 
 exp	:	FALSEKEYWORD
-			{ write_exp_elt_opcode (OP_BOOL);
-			  write_exp_elt_longcst ((LONGEST) $1);
-			  current_type = parse_type->builtin_bool;
-			  write_exp_elt_opcode (OP_BOOL); }
+			{ write_exp_elt_opcode (ps, OP_BOOL);
+			  write_exp_elt_longcst (ps, (LONGEST) $1);
+			  current_type = parse_type (ps)->builtin_bool;
+			  write_exp_elt_opcode (ps, OP_BOOL); }
 	;
 
 exp	:	INT
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type ($1.type);
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, $1.type);
 			  current_type = $1.type;
-			  write_exp_elt_longcst ((LONGEST)($1.val));
-			  write_exp_elt_opcode (OP_LONG); }
+			  write_exp_elt_longcst (ps, (LONGEST)($1.val));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	NAME_OR_INT
 			{ YYSTYPE val;
-			  parse_number ($1.stoken.ptr,
+			  parse_number (ps, $1.stoken.ptr,
 					$1.stoken.length, 0, &val);
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (val.typed_val_int.type);
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, val.typed_val_int.type);
 			  current_type = val.typed_val_int.type;
-			  write_exp_elt_longcst ((LONGEST)
+			  write_exp_elt_longcst (ps, (LONGEST)
 						 val.typed_val_int.val);
-			  write_exp_elt_opcode (OP_LONG);
+			  write_exp_elt_opcode (ps, OP_LONG);
 			}
 	;
 
 
 exp	:	FLOAT
-			{ write_exp_elt_opcode (OP_DOUBLE);
-			  write_exp_elt_type ($1.type);
+			{ write_exp_elt_opcode (ps, OP_DOUBLE);
+			  write_exp_elt_type (ps, $1.type);
 			  current_type = $1.type;
-			  write_exp_elt_dblcst ($1.dval);
-			  write_exp_elt_opcode (OP_DOUBLE); }
+			  write_exp_elt_dblcst (ps, $1.dval);
+			  write_exp_elt_opcode (ps, OP_DOUBLE); }
 	;
 
 exp	:	variable
@@ -560,7 +565,7 @@ exp	:	VARIABLE
  			     struct value * val, * mark;
 
 			     mark = value_mark ();
- 			     val = value_of_internalvar (parse_gdbarch,
+ 			     val = value_of_internalvar (parse_gdbarch (ps),
  							 intvar);
  			     current_type = value_type (val);
 			     value_release_to_mark (mark);
@@ -569,15 +574,16 @@ exp	:	VARIABLE
  	;
 
 exp	:	SIZEOF '(' type ')'	%prec UNARY
-			{ write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_int);
+			{ write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps, parse_type (ps)->builtin_int);
 			  CHECK_TYPEDEF ($3);
-			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
-			  write_exp_elt_opcode (OP_LONG); }
+			  write_exp_elt_longcst (ps,
+						 (LONGEST) TYPE_LENGTH ($3));
+			  write_exp_elt_opcode (ps, OP_LONG); }
 	;
 
 exp	:	SIZEOF  '(' exp ')'      %prec UNARY
-			{ write_exp_elt_opcode (UNOP_SIZEOF); }
+			{ write_exp_elt_opcode (ps, UNOP_SIZEOF); }
 
 exp	:	STRING
 			{ /* C strings are converted into array constants with
@@ -588,19 +594,23 @@ exp	:	STRING
 			  char *sp = $1.ptr; int count = $1.length;
 			  while (count-- > 0)
 			    {
-			      write_exp_elt_opcode (OP_LONG);
-			      write_exp_elt_type (parse_type->builtin_char);
-			      write_exp_elt_longcst ((LONGEST)(*sp++));
-			      write_exp_elt_opcode (OP_LONG);
+			      write_exp_elt_opcode (ps, OP_LONG);
+			      write_exp_elt_type (ps,
+						  parse_type (ps)
+						  ->builtin_char);
+			      write_exp_elt_longcst (ps, (LONGEST) (*sp++));
+			      write_exp_elt_opcode (ps, OP_LONG);
 			    }
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_type (parse_type->builtin_char);
-			  write_exp_elt_longcst ((LONGEST)'\0');
-			  write_exp_elt_opcode (OP_LONG);
-			  write_exp_elt_opcode (OP_ARRAY);
-			  write_exp_elt_longcst ((LONGEST) 0);
-			  write_exp_elt_longcst ((LONGEST) ($1.length));
-			  write_exp_elt_opcode (OP_ARRAY); }
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_type (ps,
+					      parse_type (ps)
+					      ->builtin_char);
+			  write_exp_elt_longcst (ps, (LONGEST)'\0');
+			  write_exp_elt_opcode (ps, OP_LONG);
+			  write_exp_elt_opcode (ps, OP_ARRAY);
+			  write_exp_elt_longcst (ps, (LONGEST) 0);
+			  write_exp_elt_longcst (ps, (LONGEST) ($1.length));
+			  write_exp_elt_opcode (ps, OP_ARRAY); }
 	;
 
 /* Object pascal  */
@@ -608,10 +618,10 @@ exp	:	THIS
 			{
 			  struct value * this_val;
 			  struct type * this_type;
-			  write_exp_elt_opcode (OP_THIS);
-			  write_exp_elt_opcode (OP_THIS);
+			  write_exp_elt_opcode (ps, OP_THIS);
+			  write_exp_elt_opcode (ps, OP_THIS);
 			  /* We need type of this.  */
-			  this_val = value_of_this_silent (parse_language);
+			  this_val = value_of_this_silent (parse_language (ps));
 			  if (this_val)
 			    this_type = value_type (this_val);
 			  else
@@ -621,7 +631,7 @@ exp	:	THIS
 			      if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
 				{
 				  this_type = TYPE_TARGET_TYPE (this_type);
-				  write_exp_elt_opcode (UNOP_IND);
+				  write_exp_elt_opcode (ps, UNOP_IND);
 				}
 			    }
 
@@ -667,11 +677,11 @@ variable:	block COLONCOLON name
 			    error (_("No symbol \"%s\" in specified context."),
 				   copy_name ($3));
 
-			  write_exp_elt_opcode (OP_VAR_VALUE);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			  /* block_found is set by lookup_symbol.  */
-			  write_exp_elt_block (block_found);
-			  write_exp_elt_sym (sym);
-			  write_exp_elt_opcode (OP_VAR_VALUE); }
+			  write_exp_elt_block (ps, block_found);
+			  write_exp_elt_sym (ps, sym);
+			  write_exp_elt_opcode (ps, OP_VAR_VALUE); }
 	;
 
 qualified_name:	typebase COLONCOLON name
@@ -682,10 +692,10 @@ qualified_name:	typebase COLONCOLON name
 			    error (_("`%s' is not defined as an aggregate type."),
 				   TYPE_NAME (type));
 
-			  write_exp_elt_opcode (OP_SCOPE);
-			  write_exp_elt_type (type);
-			  write_exp_string ($3);
-			  write_exp_elt_opcode (OP_SCOPE);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
+			  write_exp_elt_type (ps, type);
+			  write_exp_string (ps, $3);
+			  write_exp_elt_opcode (ps, OP_SCOPE);
 			}
 	;
 
@@ -701,16 +711,16 @@ variable:	qualified_name
 					   VAR_DOMAIN, (int *) NULL);
 			  if (sym)
 			    {
-			      write_exp_elt_opcode (OP_VAR_VALUE);
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      break;
 			    }
 
 			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
 			  if (msymbol != NULL)
-			    write_exp_msymbol (msymbol);
+			    write_exp_msymbol (ps, msymbol);
 			  else if (!have_full_symbols ()
 				   && !have_partial_symbols ())
 			    error (_("No symbol table is loaded.  "
@@ -734,13 +744,13 @@ variable:	name_not_typename
 				    innermost_block = block_found;
 				}
 
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      /* We want to use the selected frame, not
 				 another more inner frame which happens to
 				 be in the same block.  */
-			      write_exp_elt_block (NULL);
-			      write_exp_elt_sym (sym);
-			      write_exp_elt_opcode (OP_VAR_VALUE);
+			      write_exp_elt_block (ps, NULL);
+			      write_exp_elt_sym (ps, sym);
+			      write_exp_elt_opcode (ps, OP_VAR_VALUE);
 			      current_type = sym->type; }
 			  else if ($1.is_a_field_of_this)
 			    {
@@ -753,13 +763,13 @@ variable:	name_not_typename
 				  || contained_in (block_found,
 						   innermost_block))
 				innermost_block = block_found;
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (OP_THIS);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
-			      write_exp_string ($1.stoken);
-			      write_exp_elt_opcode (STRUCTOP_PTR);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, OP_THIS);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
+			      write_exp_string (ps, $1.stoken);
+			      write_exp_elt_opcode (ps, STRUCTOP_PTR);
 			      /* We need type of this.  */
-			      this_val = value_of_this_silent (parse_language);
+			      this_val = value_of_this_silent (parse_language (ps));
 			      if (this_val)
 				this_type = value_type (this_val);
 			      else
@@ -779,7 +789,7 @@ variable:	name_not_typename
 			      msymbol =
 				lookup_minimal_symbol (arg, NULL, NULL);
 			      if (msymbol != NULL)
-				write_exp_msymbol (msymbol);
+				write_exp_msymbol (ps, msymbol);
 			      else if (!have_full_symbols ()
 				       && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  "
@@ -848,7 +858,8 @@ name_not_typename :	NAME
 /*** Needs some error checking for the float case ***/
 
 static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (struct parser_state *ps, char *p, int len, int parsed_float,
+	      YYSTYPE *putithere)
 {
   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
      here, and we do kind of silly things like cast to unsigned.  */
@@ -873,7 +884,7 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 
   if (parsed_float)
     {
-      if (! parse_c_float (parse_gdbarch, p, len,
+      if (! parse_c_float (parse_gdbarch (ps), p, len,
 			   &putithere->typed_val_float.dval,
 			   &putithere->typed_val_float.type))
 	return ERROR;
@@ -979,9 +990,9 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 
   un = (ULONGEST)n >> 2;
   if (long_p == 0
-      && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
+      && (un >> (gdbarch_int_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+      high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (ps)) - 1);
 
       /* A large decimal (not hex or octal) constant (between INT_MAX
 	 and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -989,28 +1000,28 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 	 int.  This probably should be fixed.  GCC gives a warning on
 	 such constants.  */
 
-      unsigned_type = parse_type->builtin_unsigned_int;
-      signed_type = parse_type->builtin_int;
+      unsigned_type = parse_type (ps)->builtin_unsigned_int;
+      signed_type = parse_type (ps)->builtin_int;
     }
   else if (long_p <= 1
-	   && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+	   && (un >> (gdbarch_long_bit (parse_gdbarch (ps)) - 2)) == 0)
     {
-      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
-      unsigned_type = parse_type->builtin_unsigned_long;
-      signed_type = parse_type->builtin_long;
+      high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (ps)) - 1);
+      unsigned_type = parse_type (ps)->builtin_unsigned_long;
+      signed_type = parse_type (ps)->builtin_long;
     }
   else
     {
       int shift;
       if (sizeof (ULONGEST) * HOST_CHAR_BIT
-	  < gdbarch_long_long_bit (parse_gdbarch))
+	  < gdbarch_long_long_bit (parse_gdbarch (ps)))
 	/* A long long does not fit in a LONGEST.  */
 	shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
       else
-	shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
+	shift = (gdbarch_long_long_bit (parse_gdbarch (ps)) - 1);
       high_bit = (ULONGEST) 1 << shift;
-      unsigned_type = parse_type->builtin_unsigned_long_long;
-      signed_type = parse_type->builtin_long_long;
+      unsigned_type = parse_type (ps)->builtin_unsigned_long_long;
+      signed_type = parse_type (ps)->builtin_long_long;
     }
 
    putithere->typed_val_int.val = n;
@@ -1093,9 +1104,7 @@ static const struct token tokentab2[] =
 
 /* Allocate uppercased var: */
 /* make an uppercased copy of tokstart.  */
-static char * uptok (tokstart, namelen)
-  char *tokstart;
-  int namelen;
+static char * uptok (char *tokstart, int namelen)
 {
   int i;
   char *uptokstart = (char *)malloc(namelen+1);
@@ -1118,7 +1127,7 @@ static int last_was_structop;
 /* Read one token, getting characters through lexptr.  */
 
 static int
-yylex (void)
+yylex (struct parser_state *ps)
 {
   int c;
   int namelen;
@@ -1185,12 +1194,12 @@ yylex (void)
       lexptr++;
       c = *lexptr++;
       if (c == '\\')
-	c = parse_escape (parse_gdbarch, &lexptr);
+	c = parse_escape (parse_gdbarch (ps), &lexptr);
       else if (c == '\'')
 	error (_("Empty character constant."));
 
       yylval.typed_val_int.val = c;
-      yylval.typed_val_int.type = parse_type->builtin_char;
+      yylval.typed_val_int.type = parse_type (ps)->builtin_char;
 
       c = *lexptr++;
       if (c != '\'')
@@ -1290,7 +1299,7 @@ yylex (void)
 				  && (*p < 'A' || *p > 'Z')))
 	      break;
 	  }
-	toktype = parse_number (tokstart,
+	toktype = parse_number (ps, tokstart,
 				p - tokstart, got_dot | got_e, &yylval);
         if (toktype == ERROR)
 	  {
@@ -1357,7 +1366,7 @@ yylex (void)
 	    break;
 	  case '\\':
 	    tokptr++;
-	    c = parse_escape (parse_gdbarch, &tokptr);
+	    c = parse_escape (parse_gdbarch (ps), &tokptr);
 	    if (c == -1)
 	      {
 		continue;
@@ -1499,7 +1508,7 @@ yylex (void)
         but this conflicts with the GDB use for debugger variables
         so in expression to enter hexadecimal values
         we still need to use C syntax with 0xff  */
-      write_dollar_variable (yylval.sval);
+      write_dollar_variable (ps, yylval.sval);
       c = tokstart[namelen];
       tokstart[namelen] = 0;
       intvar = lookup_only_internalvar (++tokstart);
@@ -1697,8 +1706,8 @@ yylex (void)
 	  return TYPENAME;
         }
     yylval.tsym.type
-      = language_lookup_primitive_type_by_name (parse_language,
-						parse_gdbarch, tmp);
+      = language_lookup_primitive_type_by_name (parse_language (ps),
+						parse_gdbarch (ps), tmp);
     if (yylval.tsym.type != NULL)
       {
 	free (uptokstart);
@@ -1713,7 +1722,7 @@ yylex (void)
             || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
       {
  	YYSTYPE newlval;	/* Its value is ignored.  */
-	hextype = parse_number (tokstart, namelen, 0, &newlval);
+	hextype = parse_number (ps, tokstart, namelen, 0, &newlval);
 	if (hextype == INT)
 	  {
 	    yylval.ssym.sym = sym;
@@ -1732,8 +1741,7 @@ yylex (void)
 }
 
 void
-yyerror (msg)
-     char *msg;
+yyerror (struct parser_state *ps, char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/p-lang.h b/gdb/p-lang.h
index 308b7b5..d07a249 100644
--- a/gdb/p-lang.h
+++ b/gdb/p-lang.h
@@ -20,13 +20,15 @@
 /* This file is derived from c-lang.h */
 
 struct value;
+struct parser_state;
 
 /* Defined in p-lang.c */
 extern const char *pascal_main_name (void);
 
-extern int pascal_parse (void);	/* Defined in p-exp.y */
+extern int pascal_parse (struct parser_state *); /* Defined in p-exp.y */
 
-extern void pascal_error (char *);	/* Defined in p-exp.y */
+extern void pascal_error (struct parser_state *, char *); /* Defined
+							     in p-exp.y */
 
 /* Defined in p-typeprint.c */
 extern void pascal_print_type (struct type *, const char *, struct ui_file *,

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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 18:56 ` [RFC 1/8] Language independent bits Sergio Durigan Junior
@ 2012-01-15 21:08   ` Jan Kratochvil
  2012-01-15 21:17     ` Sergio Durigan Junior
                       ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Jan Kratochvil @ 2012-01-15 21:08 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On Sun, 15 Jan 2012 19:55:27 +0100, Sergio Durigan Junior wrote:
>  static int
> -unk_lang_parser (void)
> +unk_lang_parser (struct parser_state *ps)
>  {
>    return 1;
>  }
>  
>  static void
> -unk_lang_error (char *msg)
> +unk_lang_error (struct parser_state *ps, char *msg)
>  {
>    error (_("Attempted to parse an expression with unknown language"));
>  }

Do you use `ps' in these two functions in some later patch?  Otherwise I do
not think it should be passed.  It can be always passed (sure incl. updating
callers and the callers of the callers) later when needed.


> +static void
> +initialize_expout (struct parser_state *ps, int initial_size,
> +		   const struct language_defn *lang,
> +		   struct gdbarch *gdbarch)
> +{
> +  ps->expout_size = initial_size;
> +  ps->expout_ptr = 0;
> +  ps->expout = (struct expression *)
> +    xmalloc (sizeof (struct expression)
> +    + EXP_ELEM_TO_BYTES (ps->expout_size));

That return type cast is excessive.  It had meaning for K&R C where xmalloc
returns PTR but that is no longer supported.  There should be done
s/PTR/void */ everywhere and #define PTR should be removed
and #pragma GCC poison -ed.


> +  ps->expout->language_defn = lang;
> +  ps->expout->gdbarch = gdbarch;
> +}
 [...]
> -extern struct expression *expout;
> -extern int expout_size;
> -extern int expout_ptr;
> +#define parse_gdbarch(ps) (ps->expout->gdbarch)
> +#define parse_language(ps) (ps->expout->language_defn)
->
   #define parse_gdbarch(ps) ((ps)->expout->gdbarch)
   #define parse_language(ps) ((ps)->expout->language_defn)

>  
> -#define parse_gdbarch (expout->gdbarch)
> -#define parse_language (expout->language_defn)
> +struct parser_state {

Opening { should be on a new line.


> +
> +    /* The expression related to this parser state.  */

Indentation should be by 2, not 4 spaces.

> +
> +    struct expression *expout;
> +
> +    /* The size of the expression above.  */
> +
> +    int expout_size;

Memory object size does not fit into `int', it should be `size_t'.


> +
> +    /* The number of elements already in the expression.  This is used
> +       to know where to put new elements.  */
> +
> +    int expout_ptr;

Likewise.


> +};
[...]
> +/* Reallocate the `expout' pointer inside PS so that it can accommodate
> +   at least LENELT expression elements.  This function does nothing if
> +   there is enough room for the elements.  */
> +
> +extern void increase_expout_size (struct parser_state *ps, int lenelt);

Memory object size does not fit into `int', it should be `size_t'.



Sorry this is not review/approval, just comments.


Thanks,
Jan

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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 21:08   ` Jan Kratochvil
@ 2012-01-15 21:17     ` Sergio Durigan Junior
  2012-01-15 22:03       ` Jan Kratochvil
  2012-01-16 20:40     ` Tom Tromey
  2012-01-17 16:44     ` Doug Evans
  2 siblings, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-15 21:17 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On Sunday, January 15 2012, Jan Kratochvil wrote:

> On Sun, 15 Jan 2012 19:55:27 +0100, Sergio Durigan Junior wrote:
>>  static int
>> -unk_lang_parser (void)
>> +unk_lang_parser (struct parser_state *ps)
>>  {
>>    return 1;
>>  }
>>  
>>  static void
>> -unk_lang_error (char *msg)
>> +unk_lang_error (struct parser_state *ps, char *msg)
>>  {
>>    error (_("Attempted to parse an expression with unknown language"));
>>  }
>
> Do you use `ps' in these two functions in some later patch?  Otherwise I do
> not think it should be passed.  It can be always passed (sure incl. updating
> callers and the callers of the callers) later when needed.

By "these two functions" you mean on `unk_lang_error' and
`unk_lang_parser'?  If so, then the answer is "no", but I still need to
pass `ps' because of the prototype of `la_parser' and `la_error'.

But if you mean `la_parser' and `la_error', then the answer is that `ps'
is used inside `la_parser', but not used inside `la_error'.  However, by
Bison rules, if you change the `yyparse' header you should reflect the
changes to `yyerror' header.

>> +static void
>> +initialize_expout (struct parser_state *ps, int initial_size,
>> +		   const struct language_defn *lang,
>> +		   struct gdbarch *gdbarch)
>> +{
>> +  ps->expout_size = initial_size;
>> +  ps->expout_ptr = 0;
>> +  ps->expout = (struct expression *)
>> +    xmalloc (sizeof (struct expression)
>> +    + EXP_ELEM_TO_BYTES (ps->expout_size));
>
> That return type cast is excessive.  It had meaning for K&R C where xmalloc
> returns PTR but that is no longer supported.  There should be done
> s/PTR/void */ everywhere and #define PTR should be removed
> and #pragma GCC poison -ed.

Sorry, I am not sure I understood your argument.  If you mean I should
remove the cast to `struct expression *', then OK, I can do that.

This is the updated patch, which addresses the issues you have pointed.
Thanks for the comments.

Sergio.

---
 gdb/language.c    |    8 +-
 gdb/language.h    |    5 +-
 gdb/parse.c       |  295 ++++++++++++++++++++++++++++-------------------------
 gdb/parser-defs.h |   63 ++++++++----
 4 files changed, 205 insertions(+), 166 deletions(-)

diff --git a/gdb/language.c b/gdb/language.c
index d70ae81..b02fc5b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -47,9 +47,9 @@
 
 extern void _initialize_language (void);
 
-static void unk_lang_error (char *);
+static void unk_lang_error (struct parser_state *, char *);
 
-static int unk_lang_parser (void);
+static int unk_lang_parser (struct parser_state *);
 
 static void show_check (char *, int);
 
@@ -803,13 +803,13 @@ default_get_string (struct value *value, gdb_byte **buffer, int *length,
 /* Define the language that is no language.  */
 
 static int
-unk_lang_parser (void)
+unk_lang_parser (struct parser_state *ps)
 {
   return 1;
 }
 
 static void
-unk_lang_error (char *msg)
+unk_lang_error (struct parser_state *ps, char *msg)
 {
   error (_("Attempted to parse an expression with unknown language"));
 }
diff --git a/gdb/language.h b/gdb/language.h
index 2ea2dca..6faf9c7 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -31,6 +31,7 @@ struct frame_info;
 struct expression;
 struct ui_file;
 struct value_print_options;
+struct parser_state;
 
 #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
 
@@ -172,11 +173,11 @@ struct language_defn
 
     /* Parser function.  */
 
-    int (*la_parser) (void);
+    int (*la_parser) (struct parser_state *);
 
     /* Parser error function.  */
 
-    void (*la_error) (char *);
+    void (*la_error) (struct parser_state *, char *);
 
     /* Given an expression *EXPP created by prefixifying the result of
        la_parser, perform any remaining processing necessary to complete
diff --git a/gdb/parse.c b/gdb/parse.c
index f405dc5..7f154b3 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -68,9 +68,6 @@ const struct exp_descriptor exp_descriptor_standard =
   };
 \f
 /* Global variables declared in parser-defs.h (and commented there).  */
-struct expression *expout;
-int expout_size;
-int expout_ptr;
 struct block *expression_context_block;
 CORE_ADDR expression_context_pc;
 struct block *innermost_block;
@@ -179,6 +176,44 @@ free_funcalls (void *ignore)
     }
 }
 \f
+
+/* Helper function used to initialize an struct expression that is going
+   to be used to store expression elements.  The arguments are the
+   parser_state PS containing the EXPOUT, the INITIAL_SIZE of the expression,
+   the language LANG parsed to build this expression, and the GDBARCH
+   pointer.  */
+
+static void
+initialize_expout (struct parser_state *ps, size_t initial_size,
+		   const struct language_defn *lang,
+		   struct gdbarch *gdbarch)
+{
+  ps->expout_size = initial_size;
+  ps->expout_ptr = 0;
+  ps->expout = xmalloc (sizeof (struct expression)
+			+ EXP_ELEM_TO_BYTES (ps->expout_size));
+  ps->expout->language_defn = lang;
+  ps->expout->gdbarch = gdbarch;
+}
+
+/* Helper function that reallocates the EXPOUT inside PS in order to
+   eliminate any unused space.  It is generally used when the expression
+   has just been parsed and created.  */
+
+static void
+reallocate_expout (struct parser_state *ps)
+{
+  /* Record the actual number of expression elements, and then
+     reallocate the expression memory so that we free up any
+     excess elements.  */
+
+  ps->expout->nelts = ps->expout_ptr;
+  ps->expout = (struct expression *)
+     xrealloc (ps->expout,
+	       sizeof (struct expression)
+	       + EXP_ELEM_TO_BYTES (ps->expout_ptr));
+}
+
 /* This page contains the functions for adding data to the struct expression
    being constructed.  */
 
@@ -188,80 +223,80 @@ free_funcalls (void *ignore)
    a register through here.  */
 
 static void
-write_exp_elt (const union exp_element *expelt)
+write_exp_elt (struct parser_state *ps, const union exp_element *expelt)
 {
-  if (expout_ptr >= expout_size)
+  if (ps->expout_ptr >= ps->expout_size)
     {
-      expout_size *= 2;
-      expout = (struct expression *)
-	xrealloc ((char *) expout, sizeof (struct expression)
-		  + EXP_ELEM_TO_BYTES (expout_size));
+      ps->expout_size *= 2;
+      ps->expout = (struct expression *)
+	xrealloc (ps->expout, sizeof (struct expression)
+		  + EXP_ELEM_TO_BYTES (ps->expout_size));
     }
-  expout->elts[expout_ptr++] = *expelt;
+  ps->expout->elts[ps->expout_ptr++] = *expelt;
 }
 
 void
-write_exp_elt_opcode (enum exp_opcode expelt)
+write_exp_elt_opcode (struct parser_state *ps, enum exp_opcode expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.opcode = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_sym (struct symbol *expelt)
+write_exp_elt_sym (struct parser_state *ps, struct symbol *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.symbol = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_block (struct block *b)
+write_exp_elt_block (struct parser_state *ps, struct block *b)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.block = b;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_objfile (struct objfile *objfile)
+write_exp_elt_objfile (struct parser_state *ps, struct objfile *objfile)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.objfile = objfile;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_longcst (LONGEST expelt)
+write_exp_elt_longcst (struct parser_state *ps, LONGEST expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.longconst = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_dblcst (DOUBLEST expelt)
+write_exp_elt_dblcst (struct parser_state *ps, DOUBLEST expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.doubleconst = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_decfloatcst (gdb_byte expelt[16])
+write_exp_elt_decfloatcst (struct parser_state *ps, gdb_byte expelt[16])
 {
   union exp_element tmp;
   int index;
@@ -269,27 +304,27 @@ write_exp_elt_decfloatcst (gdb_byte expelt[16])
   for (index = 0; index < 16; index++)
     tmp.decfloatconst[index] = expelt[index];
 
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_type (struct type *expelt)
+write_exp_elt_type (struct parser_state *ps, struct type *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.type = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 void
-write_exp_elt_intern (struct internalvar *expelt)
+write_exp_elt_intern (struct parser_state *ps, struct internalvar *expelt)
 {
   union exp_element tmp;
 
   memset (&tmp, 0, sizeof (union exp_element));
   tmp.internalvar = expelt;
-  write_exp_elt (&tmp);
+  write_exp_elt (ps, &tmp);
 }
 
 /* Add a string constant to the end of the expression.
@@ -314,10 +349,10 @@ write_exp_elt_intern (struct internalvar *expelt)
 
 
 void
-write_exp_string (struct stoken str)
+write_exp_string (struct parser_state *ps, struct stoken str)
 {
   int len = str.length;
-  int lenelt;
+  size_t lenelt;
   char *strdata;
 
   /* Compute the number of expression elements required to hold the string
@@ -327,28 +362,19 @@ write_exp_string (struct stoken str)
 
   lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1);
 
-  /* Ensure that we have enough available expression elements to store
-     everything.  */
-
-  if ((expout_ptr + lenelt) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, lenelt);
 
   /* Write the leading length expression element (which advances the current
      expression element index), then write the string constant followed by a
      terminating null byte, and then write the trailing length expression
      element.  */
 
-  write_exp_elt_longcst ((LONGEST) len);
-  strdata = (char *) &expout->elts[expout_ptr];
+  write_exp_elt_longcst (ps, (LONGEST) len);
+  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
   memcpy (strdata, str.ptr, len);
   *(strdata + len) = '\0';
-  expout_ptr += lenelt - 2;
-  write_exp_elt_longcst ((LONGEST) len);
+  ps->expout_ptr += lenelt - 2;
+  write_exp_elt_longcst (ps, (LONGEST) len);
 }
 
 /* Add a vector of string constants to the end of the expression.
@@ -365,9 +391,11 @@ write_exp_string (struct stoken str)
    long constant, followed by the contents of the string.  */
 
 void
-write_exp_string_vector (int type, struct stoken_vector *vec)
+write_exp_string_vector (struct parser_state *ps, int type,
+			 struct stoken_vector *vec)
 {
-  int i, n_slots, len;
+  int i, len;
+  size_t n_slots;
 
   /* Compute the size.  We compute the size in number of slots to
      avoid issues with string padding.  */
@@ -386,28 +414,22 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
   len = EXP_ELEM_TO_BYTES (n_slots) - 1;
 
   n_slots += 4;
-  if ((expout_ptr + n_slots) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + n_slots + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, n_slots);
 
-  write_exp_elt_opcode (OP_STRING);
-  write_exp_elt_longcst (len);
-  write_exp_elt_longcst (type);
+  write_exp_elt_opcode (ps, OP_STRING);
+  write_exp_elt_longcst (ps, len);
+  write_exp_elt_longcst (ps, type);
 
   for (i = 0; i < vec->len; ++i)
     {
-      write_exp_elt_longcst (vec->tokens[i].length);
-      memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr,
+      write_exp_elt_longcst (ps, vec->tokens[i].length);
+      memcpy (&ps->expout->elts[ps->expout_ptr], vec->tokens[i].ptr,
 	      vec->tokens[i].length);
-      expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
+      ps->expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
     }
 
-  write_exp_elt_longcst (len);
-  write_exp_elt_opcode (OP_STRING);
+  write_exp_elt_longcst (ps, len);
+  write_exp_elt_opcode (ps, OP_STRING);
 }
 
 /* Add a bitstring constant to the end of the expression.
@@ -422,11 +444,11 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
    either end of the bitstring.  */
 
 void
-write_exp_bitstring (struct stoken str)
+write_exp_bitstring (struct parser_state *ps, struct stoken str)
 {
   int bits = str.length;	/* length in bits */
   int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
-  int lenelt;
+  size_t lenelt;
   char *strdata;
 
   /* Compute the number of expression elements required to hold the bitstring,
@@ -435,33 +457,24 @@ write_exp_bitstring (struct stoken str)
 
   lenelt = 2 + BYTES_TO_EXP_ELEM (len);
 
-  /* Ensure that we have enough available expression elements to store
-     everything.  */
-
-  if ((expout_ptr + lenelt) >= expout_size)
-    {
-      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
-      expout = (struct expression *)
-	xrealloc ((char *) expout, (sizeof (struct expression)
-				    + EXP_ELEM_TO_BYTES (expout_size)));
-    }
+  increase_expout_size (ps, lenelt);
 
   /* Write the leading length expression element (which advances the current
      expression element index), then write the bitstring constant, and then
      write the trailing length expression element.  */
 
-  write_exp_elt_longcst ((LONGEST) bits);
-  strdata = (char *) &expout->elts[expout_ptr];
+  write_exp_elt_longcst (ps, (LONGEST) bits);
+  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
   memcpy (strdata, str.ptr, len);
-  expout_ptr += lenelt - 2;
-  write_exp_elt_longcst ((LONGEST) bits);
+  ps->expout_ptr += lenelt - 2;
+  write_exp_elt_longcst (ps, (LONGEST) bits);
 }
 
 /* Add the appropriate elements for a minimal symbol to the end of
    the expression.  */
 
 void
-write_exp_msymbol (struct minimal_symbol *msymbol)
+write_exp_msymbol (struct parser_state *ps, struct minimal_symbol *msymbol)
 {
   struct objfile *objfile = msymbol_objfile (msymbol);
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -499,60 +512,60 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
   if (overlay_debugging)
     addr = symbol_overlayed_address (addr, section);
 
-  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_opcode (ps, OP_LONG);
   /* Let's make the type big enough to hold a 64-bit address.  */
-  write_exp_elt_type (objfile_type (objfile)->builtin_core_addr);
-  write_exp_elt_longcst ((LONGEST) addr);
-  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_type (ps, objfile_type (objfile)->builtin_core_addr);
+  write_exp_elt_longcst (ps, (LONGEST) addr);
+  write_exp_elt_opcode (ps, OP_LONG);
 
   if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL)
     {
-      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
-      write_exp_elt_objfile (objfile);
-      write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol);
-      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
+      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
+      write_exp_elt_objfile (ps, objfile);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_tls_symbol);
+      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
       return;
     }
 
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (ps, UNOP_MEMVAL);
   switch (type)
     {
     case mst_text:
     case mst_file_text:
     case mst_solib_trampoline:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_text_symbol);
       break;
 
     case mst_text_gnu_ifunc:
-      write_exp_elt_type (objfile_type (objfile)
-					       ->nodebug_text_gnu_ifunc_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)
+			  ->nodebug_text_gnu_ifunc_symbol);
       break;
 
     case mst_data:
     case mst_file_data:
     case mst_bss:
     case mst_file_bss:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_data_symbol);
       break;
 
     case mst_slot_got_plt:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_got_plt_symbol);
       break;
 
     default:
-      write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
+      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_unknown_symbol);
       break;
     }
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (ps, UNOP_MEMVAL);
 }
 
 /* Mark the current index as the starting location of a structure
    expression.  This is used when completing on field names.  */
 
 void
-mark_struct_expression (void)
+mark_struct_expression (struct parser_state *ps)
 {
-  expout_last_struct = expout_ptr;
+  expout_last_struct = ps->expout_ptr;
 }
 
 \f
@@ -578,7 +591,7 @@ mark_struct_expression (void)
    value in the value history, I.e. $$1  */
 
 void
-write_dollar_variable (struct stoken str)
+write_dollar_variable (struct parser_state *ps, struct stoken str)
 {
   struct symbol *sym = NULL;
   struct minimal_symbol *msym = NULL;
@@ -616,7 +629,7 @@ write_dollar_variable (struct stoken str)
 
   /* Handle tokens that refer to machine registers:
      $ followed by a register name.  */
-  i = user_reg_map_name_to_regnum (parse_gdbarch,
+  i = user_reg_map_name_to_regnum (parse_gdbarch (ps),
 				   str.ptr + 1, str.length - 1);
   if (i >= 0)
     goto handle_register;
@@ -626,9 +639,9 @@ write_dollar_variable (struct stoken str)
   isym = lookup_only_internalvar (copy_name (str) + 1);
   if (isym)
     {
-      write_exp_elt_opcode (OP_INTERNALVAR);
-      write_exp_elt_intern (isym);
-      write_exp_elt_opcode (OP_INTERNALVAR);
+      write_exp_elt_opcode (ps, OP_INTERNALVAR);
+      write_exp_elt_intern (ps, isym);
+      write_exp_elt_opcode (ps, OP_INTERNALVAR);
       return;
     }
 
@@ -639,36 +652,36 @@ write_dollar_variable (struct stoken str)
 		       VAR_DOMAIN, (int *) NULL);
   if (sym)
     {
-      write_exp_elt_opcode (OP_VAR_VALUE);
-      write_exp_elt_block (block_found);	/* set by lookup_symbol */
-      write_exp_elt_sym (sym);
-      write_exp_elt_opcode (OP_VAR_VALUE);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
+      write_exp_elt_block (ps, block_found);	/* set by lookup_symbol */
+      write_exp_elt_sym (ps, sym);
+      write_exp_elt_opcode (ps, OP_VAR_VALUE);
       return;
     }
   msym = lookup_minimal_symbol (copy_name (str), NULL, NULL);
   if (msym)
     {
-      write_exp_msymbol (msym);
+      write_exp_msymbol (ps, msym);
       return;
     }
 
   /* Any other names are assumed to be debugger internal variables.  */
 
-  write_exp_elt_opcode (OP_INTERNALVAR);
-  write_exp_elt_intern (create_internalvar (copy_name (str) + 1));
-  write_exp_elt_opcode (OP_INTERNALVAR);
+  write_exp_elt_opcode (ps, OP_INTERNALVAR);
+  write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1));
+  write_exp_elt_opcode (ps, OP_INTERNALVAR);
   return;
 handle_last:
-  write_exp_elt_opcode (OP_LAST);
-  write_exp_elt_longcst ((LONGEST) i);
-  write_exp_elt_opcode (OP_LAST);
+  write_exp_elt_opcode (ps, OP_LAST);
+  write_exp_elt_longcst (ps, (LONGEST) i);
+  write_exp_elt_opcode (ps, OP_LAST);
   return;
 handle_register:
-  write_exp_elt_opcode (OP_REGISTER);
+  write_exp_elt_opcode (ps, OP_REGISTER);
   str.length--;
   str.ptr++;
-  write_exp_string (str);
-  write_exp_elt_opcode (OP_REGISTER);
+  write_exp_string (ps, str);
+  write_exp_elt_opcode (ps, OP_REGISTER);
   return;
 }
 
@@ -1093,6 +1106,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   volatile struct gdb_exception except;
   struct cleanup *old_chain;
   const struct language_defn *lang = NULL;
+  struct parser_state ps;
   int subexp;
 
   lexptr = *stringptr;
@@ -1156,56 +1170,44 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   else
     lang = current_language;
 
-  expout_size = 10;
-  expout_ptr = 0;
-  expout = (struct expression *)
-    xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
-  expout->language_defn = lang;
-  expout->gdbarch = get_current_arch ();
+  initialize_expout (&ps, 10, lang, get_current_arch ());
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      if (lang->la_parser ())
-        lang->la_error (NULL);
+      if (lang->la_parser (&ps))
+        lang->la_error (&ps, NULL);
     }
   if (except.reason < 0)
     {
       if (! in_parse_field)
 	{
-	  xfree (expout);
+	  xfree (ps.expout);
 	  throw_exception (except);
 	}
     }
 
   discard_cleanups (old_chain);
 
-  /* Record the actual number of expression elements, and then
-     reallocate the expression memory so that we free up any
-     excess elements.  */
-
-  expout->nelts = expout_ptr;
-  expout = (struct expression *)
-    xrealloc ((char *) expout,
-	      sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));
+  reallocate_expout (&ps);
 
   /* Convert expression from postfix form as generated by yacc
      parser, to a prefix form.  */
 
   if (expressiondebug)
-    dump_raw_expression (expout, gdb_stdlog,
+    dump_raw_expression (ps.expout, gdb_stdlog,
 			 "before conversion to prefix form");
 
-  subexp = prefixify_expression (expout);
+  subexp = prefixify_expression (ps.expout);
   if (out_subexp)
     *out_subexp = subexp;
 
-  lang->la_post_parser (&expout, void_context_p);
+  lang->la_post_parser (&ps.expout, void_context_p);
 
   if (expressiondebug)
-    dump_prefix_expression (expout, gdb_stdlog);
+    dump_prefix_expression (ps.expout, gdb_stdlog);
 
   *stringptr = lexptr;
-  return expout;
+  return ps.expout;
 }
 
 /* Parse STRING as an expression, and complain if this fails
@@ -1372,9 +1374,9 @@ push_type_int (int n)
 }
 
 void
-push_type_address_space (char *string)
+push_type_address_space (struct parser_state *ps, char *string)
 {
-  push_type_int (address_space_name_to_int (parse_gdbarch, string));
+  push_type_int (address_space_name_to_int (parse_gdbarch (ps), string));
 }
 
 enum type_pieces
@@ -1644,6 +1646,21 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
   return exp_iterate (exp, exp_uses_objfile_iter, objfile);
 }
 
+/* See definition in parser-defs.h.  */
+
+void
+increase_expout_size (struct parser_state *ps, size_t lenelt)
+{
+  if ((ps->expout_ptr + lenelt) >= ps->expout_size)
+    {
+      ps->expout_size = max (ps->expout_size * 2,
+			     ps->expout_ptr + lenelt + 10);
+      ps->expout = (struct expression *)
+	xrealloc (ps->expout, (sizeof (struct expression)
+			       + EXP_ELEM_TO_BYTES (ps->expout_size)));
+    }
+}
+
 void
 _initialize_parse (void)
 {
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 16b40ac..89880cb 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -30,12 +30,24 @@ struct block;
 
 extern int parser_debug;
 
-extern struct expression *expout;
-extern int expout_size;
-extern int expout_ptr;
+#define parse_gdbarch(ps) ((ps)->expout->gdbarch)
+#define parse_language(ps) ((ps)->expout->language_defn)
 
-#define parse_gdbarch (expout->gdbarch)
-#define parse_language (expout->language_defn)
+struct parser_state
+{
+  /* The expression related to this parser state.  */
+
+  struct expression *expout;
+
+  /* The size of the expression above.  */
+
+  size_t expout_size;
+
+  /* The number of elements already in the expression.  This is used
+     to know where to put new elements.  */
+
+  size_t expout_ptr;
+};
 
 /* If this is nonzero, this block is used as the lexical context
    for symbol names.  */
@@ -130,35 +142,38 @@ union type_stack_elt
 extern union type_stack_elt *type_stack;
 extern int type_stack_depth, type_stack_size;
 
-extern void write_exp_elt_opcode (enum exp_opcode);
+extern void write_exp_elt_opcode (struct parser_state *, enum exp_opcode);
 
-extern void write_exp_elt_sym (struct symbol *);
+extern void write_exp_elt_sym (struct parser_state *, struct symbol *);
 
-extern void write_exp_elt_longcst (LONGEST);
+extern void write_exp_elt_longcst (struct parser_state *, LONGEST);
 
-extern void write_exp_elt_dblcst (DOUBLEST);
+extern void write_exp_elt_dblcst (struct parser_state *, DOUBLEST);
 
-extern void write_exp_elt_decfloatcst (gdb_byte *);
+extern void write_exp_elt_decfloatcst (struct parser_state *, gdb_byte *);
 
-extern void write_exp_elt_type (struct type *);
+extern void write_exp_elt_type (struct parser_state *, struct type *);
 
-extern void write_exp_elt_intern (struct internalvar *);
+extern void write_exp_elt_intern (struct parser_state *, struct internalvar *);
 
-extern void write_exp_string (struct stoken);
+extern void write_exp_string (struct parser_state *, struct stoken);
 
-void write_exp_string_vector (int type, struct stoken_vector *vec);
+void write_exp_string_vector (struct parser_state *, int type,
+			      struct stoken_vector *vec);
 
-extern void write_exp_bitstring (struct stoken);
+extern void write_exp_bitstring (struct parser_state *, struct stoken);
 
-extern void write_exp_elt_block (struct block *);
+extern void write_exp_elt_block (struct parser_state *, struct block *);
 
-extern void write_exp_elt_objfile (struct objfile *objfile);
+extern void write_exp_elt_objfile (struct parser_state *,
+				   struct objfile *objfile);
 
-extern void write_exp_msymbol (struct minimal_symbol *);
+extern void write_exp_msymbol (struct parser_state *,
+			       struct minimal_symbol *);
 
-extern void write_dollar_variable (struct stoken str);
+extern void write_dollar_variable (struct parser_state *, struct stoken str);
 
-extern void mark_struct_expression (void);
+extern void mark_struct_expression (struct parser_state *);
 
 extern char *find_template_name_end (char *);
 
@@ -172,7 +187,7 @@ extern void push_type (enum type_pieces);
 
 extern void push_type_int (int);
 
-extern void push_type_address_space (char *);
+extern void push_type_address_space (struct parser_state *, char *);
 
 extern enum type_pieces pop_type (void);
 
@@ -315,4 +330,10 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
 
 extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
 
+/* Reallocate the `expout' pointer inside PS so that it can accommodate
+   at least LENELT expression elements.  This function does nothing if
+   there is enough room for the elements.  */
+
+extern void increase_expout_size (struct parser_state *ps, size_t lenelt);
+
 #endif /* PARSER_DEFS_H */



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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 21:17     ` Sergio Durigan Junior
@ 2012-01-15 22:03       ` Jan Kratochvil
  2012-01-16 12:32         ` Sergio Durigan Junior
  0 siblings, 1 reply; 26+ messages in thread
From: Jan Kratochvil @ 2012-01-15 22:03 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On Sun, 15 Jan 2012 22:07:30 +0100, Sergio Durigan Junior wrote:
> By "these two functions" you mean on `unk_lang_error' and
> `unk_lang_parser'?

Yes.

> If so, then the answer is "no", but I still need to
> pass `ps' because of the prototype of `la_parser' and `la_error'.

OK, sorry.


> >> +  ps->expout = (struct expression *)
> >> +    xmalloc (sizeof (struct expression)
> >> +    + EXP_ELEM_TO_BYTES (ps->expout_size));
> >
> > That return type cast is excessive.  It had meaning for K&R C where xmalloc
> > returns PTR but that is no longer supported.  There should be done
> > s/PTR/void */ everywhere and #define PTR should be removed
> > and #pragma GCC poison -ed.
> 
> Sorry, I am not sure I understood your argument.

I do not understand why you put that cast in.

void * clearly does not need casting to struct expression *, it is compatible
in the assignment.  I thought you may think xmalloc may return also char *
during some builds so I was assuring you this cannot happen anymore.

Another reason may be you are used to it from C++.  But GDB is not in C++ now.
If/when it will be it can be changed easily, I do not think we should write in
C++ already when it is not built as C++ yet, if ever.  But I would not mind
this reason much, I expected more the PTR (char *) reason.


> If you mean I should
> remove the cast to `struct expression *', then OK, I can do that.

Yes, thanks.


> 
> This is the updated patch, which addresses the issues you have pointed.
> Thanks for the comments.
> 
> Sergio.
> 
> ---
>  gdb/language.c    |    8 +-
>  gdb/language.h    |    5 +-
>  gdb/parse.c       |  295 ++++++++++++++++++++++++++++-------------------------
>  gdb/parser-defs.h |   63 ++++++++----
>  4 files changed, 205 insertions(+), 166 deletions(-)
> 
> diff --git a/gdb/language.c b/gdb/language.c
> index d70ae81..b02fc5b 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -47,9 +47,9 @@
>  
>  extern void _initialize_language (void);
>  
> -static void unk_lang_error (char *);
> +static void unk_lang_error (struct parser_state *, char *);
>  
> -static int unk_lang_parser (void);
> +static int unk_lang_parser (struct parser_state *);
>  
>  static void show_check (char *, int);
>  
> @@ -803,13 +803,13 @@ default_get_string (struct value *value, gdb_byte **buffer, int *length,
>  /* Define the language that is no language.  */
>  
>  static int
> -unk_lang_parser (void)
> +unk_lang_parser (struct parser_state *ps)
>  {
>    return 1;
>  }
>  
>  static void
> -unk_lang_error (char *msg)
> +unk_lang_error (struct parser_state *ps, char *msg)
>  {
>    error (_("Attempted to parse an expression with unknown language"));
>  }
> diff --git a/gdb/language.h b/gdb/language.h
> index 2ea2dca..6faf9c7 100644
> --- a/gdb/language.h
> +++ b/gdb/language.h
> @@ -31,6 +31,7 @@ struct frame_info;
>  struct expression;
>  struct ui_file;
>  struct value_print_options;
> +struct parser_state;
>  
>  #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
>  
> @@ -172,11 +173,11 @@ struct language_defn
>  
>      /* Parser function.  */
>  
> -    int (*la_parser) (void);
> +    int (*la_parser) (struct parser_state *);
>  
>      /* Parser error function.  */
>  
> -    void (*la_error) (char *);
> +    void (*la_error) (struct parser_state *, char *);
>  
>      /* Given an expression *EXPP created by prefixifying the result of
>         la_parser, perform any remaining processing necessary to complete
> diff --git a/gdb/parse.c b/gdb/parse.c
> index f405dc5..7f154b3 100644
> --- a/gdb/parse.c
> +++ b/gdb/parse.c
> @@ -68,9 +68,6 @@ const struct exp_descriptor exp_descriptor_standard =
>    };
>  \f
>  /* Global variables declared in parser-defs.h (and commented there).  */
> -struct expression *expout;
> -int expout_size;
> -int expout_ptr;
>  struct block *expression_context_block;
>  CORE_ADDR expression_context_pc;
>  struct block *innermost_block;
> @@ -179,6 +176,44 @@ free_funcalls (void *ignore)
>      }
>  }
>  \f
> +
> +/* Helper function used to initialize an struct expression that is going
> +   to be used to store expression elements.  The arguments are the
> +   parser_state PS containing the EXPOUT, the INITIAL_SIZE of the expression,
> +   the language LANG parsed to build this expression, and the GDBARCH
> +   pointer.  */
> +
> +static void
> +initialize_expout (struct parser_state *ps, size_t initial_size,
> +		   const struct language_defn *lang,
> +		   struct gdbarch *gdbarch)
> +{
> +  ps->expout_size = initial_size;
> +  ps->expout_ptr = 0;
> +  ps->expout = xmalloc (sizeof (struct expression)
> +			+ EXP_ELEM_TO_BYTES (ps->expout_size));
> +  ps->expout->language_defn = lang;
> +  ps->expout->gdbarch = gdbarch;
> +}
> +
> +/* Helper function that reallocates the EXPOUT inside PS in order to
> +   eliminate any unused space.  It is generally used when the expression
> +   has just been parsed and created.  */
> +
> +static void
> +reallocate_expout (struct parser_state *ps)
> +{
> +  /* Record the actual number of expression elements, and then
> +     reallocate the expression memory so that we free up any
> +     excess elements.  */
> +
> +  ps->expout->nelts = ps->expout_ptr;
> +  ps->expout = (struct expression *)
> +     xrealloc (ps->expout,
> +	       sizeof (struct expression)
> +	       + EXP_ELEM_TO_BYTES (ps->expout_ptr));
> +}
> +
>  /* This page contains the functions for adding data to the struct expression
>     being constructed.  */
>  
> @@ -188,80 +223,80 @@ free_funcalls (void *ignore)
>     a register through here.  */
>  
>  static void
> -write_exp_elt (const union exp_element *expelt)
> +write_exp_elt (struct parser_state *ps, const union exp_element *expelt)
>  {
> -  if (expout_ptr >= expout_size)
> +  if (ps->expout_ptr >= ps->expout_size)
>      {
> -      expout_size *= 2;
> -      expout = (struct expression *)
> -	xrealloc ((char *) expout, sizeof (struct expression)
> -		  + EXP_ELEM_TO_BYTES (expout_size));
> +      ps->expout_size *= 2;
> +      ps->expout = (struct expression *)
> +	xrealloc (ps->expout, sizeof (struct expression)
> +		  + EXP_ELEM_TO_BYTES (ps->expout_size));
>      }
> -  expout->elts[expout_ptr++] = *expelt;
> +  ps->expout->elts[ps->expout_ptr++] = *expelt;
>  }
>  
>  void
> -write_exp_elt_opcode (enum exp_opcode expelt)
> +write_exp_elt_opcode (struct parser_state *ps, enum exp_opcode expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.opcode = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_sym (struct symbol *expelt)
> +write_exp_elt_sym (struct parser_state *ps, struct symbol *expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.symbol = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_block (struct block *b)
> +write_exp_elt_block (struct parser_state *ps, struct block *b)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.block = b;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_objfile (struct objfile *objfile)
> +write_exp_elt_objfile (struct parser_state *ps, struct objfile *objfile)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.objfile = objfile;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_longcst (LONGEST expelt)
> +write_exp_elt_longcst (struct parser_state *ps, LONGEST expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.longconst = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_dblcst (DOUBLEST expelt)
> +write_exp_elt_dblcst (struct parser_state *ps, DOUBLEST expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.doubleconst = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_decfloatcst (gdb_byte expelt[16])
> +write_exp_elt_decfloatcst (struct parser_state *ps, gdb_byte expelt[16])
>  {
>    union exp_element tmp;
>    int index;
> @@ -269,27 +304,27 @@ write_exp_elt_decfloatcst (gdb_byte expelt[16])
>    for (index = 0; index < 16; index++)
>      tmp.decfloatconst[index] = expelt[index];
>  
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_type (struct type *expelt)
> +write_exp_elt_type (struct parser_state *ps, struct type *expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.type = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  void
> -write_exp_elt_intern (struct internalvar *expelt)
> +write_exp_elt_intern (struct parser_state *ps, struct internalvar *expelt)
>  {
>    union exp_element tmp;
>  
>    memset (&tmp, 0, sizeof (union exp_element));
>    tmp.internalvar = expelt;
> -  write_exp_elt (&tmp);
> +  write_exp_elt (ps, &tmp);
>  }
>  
>  /* Add a string constant to the end of the expression.
> @@ -314,10 +349,10 @@ write_exp_elt_intern (struct internalvar *expelt)
>  
>  
>  void
> -write_exp_string (struct stoken str)
> +write_exp_string (struct parser_state *ps, struct stoken str)
>  {
>    int len = str.length;
> -  int lenelt;
> +  size_t lenelt;
>    char *strdata;
>  
>    /* Compute the number of expression elements required to hold the string
> @@ -327,28 +362,19 @@ write_exp_string (struct stoken str)
>  
>    lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1);
>  
> -  /* Ensure that we have enough available expression elements to store
> -     everything.  */
> -
> -  if ((expout_ptr + lenelt) >= expout_size)
> -    {
> -      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
> -      expout = (struct expression *)
> -	xrealloc ((char *) expout, (sizeof (struct expression)
> -				    + EXP_ELEM_TO_BYTES (expout_size)));
> -    }
> +  increase_expout_size (ps, lenelt);
>  
>    /* Write the leading length expression element (which advances the current
>       expression element index), then write the string constant followed by a
>       terminating null byte, and then write the trailing length expression
>       element.  */
>  
> -  write_exp_elt_longcst ((LONGEST) len);
> -  strdata = (char *) &expout->elts[expout_ptr];
> +  write_exp_elt_longcst (ps, (LONGEST) len);
> +  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
>    memcpy (strdata, str.ptr, len);
>    *(strdata + len) = '\0';
> -  expout_ptr += lenelt - 2;
> -  write_exp_elt_longcst ((LONGEST) len);
> +  ps->expout_ptr += lenelt - 2;
> +  write_exp_elt_longcst (ps, (LONGEST) len);
>  }
>  
>  /* Add a vector of string constants to the end of the expression.
> @@ -365,9 +391,11 @@ write_exp_string (struct stoken str)
>     long constant, followed by the contents of the string.  */
>  
>  void
> -write_exp_string_vector (int type, struct stoken_vector *vec)
> +write_exp_string_vector (struct parser_state *ps, int type,
> +			 struct stoken_vector *vec)
>  {
> -  int i, n_slots, len;
> +  int i, len;
> +  size_t n_slots;
>  
>    /* Compute the size.  We compute the size in number of slots to
>       avoid issues with string padding.  */
> @@ -386,28 +414,22 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
>    len = EXP_ELEM_TO_BYTES (n_slots) - 1;
>  
>    n_slots += 4;
> -  if ((expout_ptr + n_slots) >= expout_size)
> -    {
> -      expout_size = max (expout_size * 2, expout_ptr + n_slots + 10);
> -      expout = (struct expression *)
> -	xrealloc ((char *) expout, (sizeof (struct expression)
> -				    + EXP_ELEM_TO_BYTES (expout_size)));
> -    }
> +  increase_expout_size (ps, n_slots);
>  
> -  write_exp_elt_opcode (OP_STRING);
> -  write_exp_elt_longcst (len);
> -  write_exp_elt_longcst (type);
> +  write_exp_elt_opcode (ps, OP_STRING);
> +  write_exp_elt_longcst (ps, len);
> +  write_exp_elt_longcst (ps, type);
>  
>    for (i = 0; i < vec->len; ++i)
>      {
> -      write_exp_elt_longcst (vec->tokens[i].length);
> -      memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr,
> +      write_exp_elt_longcst (ps, vec->tokens[i].length);
> +      memcpy (&ps->expout->elts[ps->expout_ptr], vec->tokens[i].ptr,
>  	      vec->tokens[i].length);
> -      expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
> +      ps->expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
>      }
>  
> -  write_exp_elt_longcst (len);
> -  write_exp_elt_opcode (OP_STRING);
> +  write_exp_elt_longcst (ps, len);
> +  write_exp_elt_opcode (ps, OP_STRING);
>  }
>  
>  /* Add a bitstring constant to the end of the expression.
> @@ -422,11 +444,11 @@ write_exp_string_vector (int type, struct stoken_vector *vec)
>     either end of the bitstring.  */
>  
>  void
> -write_exp_bitstring (struct stoken str)
> +write_exp_bitstring (struct parser_state *ps, struct stoken str)
>  {
>    int bits = str.length;	/* length in bits */
>    int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
> -  int lenelt;
> +  size_t lenelt;
>    char *strdata;
>  
>    /* Compute the number of expression elements required to hold the bitstring,
> @@ -435,33 +457,24 @@ write_exp_bitstring (struct stoken str)
>  
>    lenelt = 2 + BYTES_TO_EXP_ELEM (len);
>  
> -  /* Ensure that we have enough available expression elements to store
> -     everything.  */
> -
> -  if ((expout_ptr + lenelt) >= expout_size)
> -    {
> -      expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
> -      expout = (struct expression *)
> -	xrealloc ((char *) expout, (sizeof (struct expression)
> -				    + EXP_ELEM_TO_BYTES (expout_size)));
> -    }
> +  increase_expout_size (ps, lenelt);
>  
>    /* Write the leading length expression element (which advances the current
>       expression element index), then write the bitstring constant, and then
>       write the trailing length expression element.  */
>  
> -  write_exp_elt_longcst ((LONGEST) bits);
> -  strdata = (char *) &expout->elts[expout_ptr];
> +  write_exp_elt_longcst (ps, (LONGEST) bits);
> +  strdata = (char *) &ps->expout->elts[ps->expout_ptr];
>    memcpy (strdata, str.ptr, len);
> -  expout_ptr += lenelt - 2;
> -  write_exp_elt_longcst ((LONGEST) bits);
> +  ps->expout_ptr += lenelt - 2;
> +  write_exp_elt_longcst (ps, (LONGEST) bits);
>  }
>  
>  /* Add the appropriate elements for a minimal symbol to the end of
>     the expression.  */
>  
>  void
> -write_exp_msymbol (struct minimal_symbol *msymbol)
> +write_exp_msymbol (struct parser_state *ps, struct minimal_symbol *msymbol)
>  {
>    struct objfile *objfile = msymbol_objfile (msymbol);
>    struct gdbarch *gdbarch = get_objfile_arch (objfile);
> @@ -499,60 +512,60 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
>    if (overlay_debugging)
>      addr = symbol_overlayed_address (addr, section);
>  
> -  write_exp_elt_opcode (OP_LONG);
> +  write_exp_elt_opcode (ps, OP_LONG);
>    /* Let's make the type big enough to hold a 64-bit address.  */
> -  write_exp_elt_type (objfile_type (objfile)->builtin_core_addr);
> -  write_exp_elt_longcst ((LONGEST) addr);
> -  write_exp_elt_opcode (OP_LONG);
> +  write_exp_elt_type (ps, objfile_type (objfile)->builtin_core_addr);
> +  write_exp_elt_longcst (ps, (LONGEST) addr);
> +  write_exp_elt_opcode (ps, OP_LONG);
>  
>    if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL)
>      {
> -      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
> -      write_exp_elt_objfile (objfile);
> -      write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol);
> -      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
> +      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
> +      write_exp_elt_objfile (ps, objfile);
> +      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_tls_symbol);
> +      write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS);
>        return;
>      }
>  
> -  write_exp_elt_opcode (UNOP_MEMVAL);
> +  write_exp_elt_opcode (ps, UNOP_MEMVAL);
>    switch (type)
>      {
>      case mst_text:
>      case mst_file_text:
>      case mst_solib_trampoline:
> -      write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
> +      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_text_symbol);
>        break;
>  
>      case mst_text_gnu_ifunc:
> -      write_exp_elt_type (objfile_type (objfile)
> -					       ->nodebug_text_gnu_ifunc_symbol);
> +      write_exp_elt_type (ps, objfile_type (objfile)
> +			  ->nodebug_text_gnu_ifunc_symbol);
>        break;
>  
>      case mst_data:
>      case mst_file_data:
>      case mst_bss:
>      case mst_file_bss:
> -      write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
> +      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_data_symbol);
>        break;
>  
>      case mst_slot_got_plt:
> -      write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
> +      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_got_plt_symbol);
>        break;
>  
>      default:
> -      write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
> +      write_exp_elt_type (ps, objfile_type (objfile)->nodebug_unknown_symbol);
>        break;
>      }
> -  write_exp_elt_opcode (UNOP_MEMVAL);
> +  write_exp_elt_opcode (ps, UNOP_MEMVAL);
>  }
>  
>  /* Mark the current index as the starting location of a structure
>     expression.  This is used when completing on field names.  */
>  
>  void
> -mark_struct_expression (void)
> +mark_struct_expression (struct parser_state *ps)
>  {
> -  expout_last_struct = expout_ptr;
> +  expout_last_struct = ps->expout_ptr;
>  }
>  
>  \f
> @@ -578,7 +591,7 @@ mark_struct_expression (void)
>     value in the value history, I.e. $$1  */
>  
>  void
> -write_dollar_variable (struct stoken str)
> +write_dollar_variable (struct parser_state *ps, struct stoken str)
>  {
>    struct symbol *sym = NULL;
>    struct minimal_symbol *msym = NULL;
> @@ -616,7 +629,7 @@ write_dollar_variable (struct stoken str)
>  
>    /* Handle tokens that refer to machine registers:
>       $ followed by a register name.  */
> -  i = user_reg_map_name_to_regnum (parse_gdbarch,
> +  i = user_reg_map_name_to_regnum (parse_gdbarch (ps),
>  				   str.ptr + 1, str.length - 1);
>    if (i >= 0)
>      goto handle_register;
> @@ -626,9 +639,9 @@ write_dollar_variable (struct stoken str)
>    isym = lookup_only_internalvar (copy_name (str) + 1);
>    if (isym)
>      {
> -      write_exp_elt_opcode (OP_INTERNALVAR);
> -      write_exp_elt_intern (isym);
> -      write_exp_elt_opcode (OP_INTERNALVAR);
> +      write_exp_elt_opcode (ps, OP_INTERNALVAR);
> +      write_exp_elt_intern (ps, isym);
> +      write_exp_elt_opcode (ps, OP_INTERNALVAR);
>        return;
>      }
>  
> @@ -639,36 +652,36 @@ write_dollar_variable (struct stoken str)
>  		       VAR_DOMAIN, (int *) NULL);
>    if (sym)
>      {
> -      write_exp_elt_opcode (OP_VAR_VALUE);
> -      write_exp_elt_block (block_found);	/* set by lookup_symbol */
> -      write_exp_elt_sym (sym);
> -      write_exp_elt_opcode (OP_VAR_VALUE);
> +      write_exp_elt_opcode (ps, OP_VAR_VALUE);
> +      write_exp_elt_block (ps, block_found);	/* set by lookup_symbol */
> +      write_exp_elt_sym (ps, sym);
> +      write_exp_elt_opcode (ps, OP_VAR_VALUE);
>        return;
>      }
>    msym = lookup_minimal_symbol (copy_name (str), NULL, NULL);
>    if (msym)
>      {
> -      write_exp_msymbol (msym);
> +      write_exp_msymbol (ps, msym);
>        return;
>      }
>  
>    /* Any other names are assumed to be debugger internal variables.  */
>  
> -  write_exp_elt_opcode (OP_INTERNALVAR);
> -  write_exp_elt_intern (create_internalvar (copy_name (str) + 1));
> -  write_exp_elt_opcode (OP_INTERNALVAR);
> +  write_exp_elt_opcode (ps, OP_INTERNALVAR);
> +  write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1));
> +  write_exp_elt_opcode (ps, OP_INTERNALVAR);
>    return;
>  handle_last:
> -  write_exp_elt_opcode (OP_LAST);
> -  write_exp_elt_longcst ((LONGEST) i);
> -  write_exp_elt_opcode (OP_LAST);
> +  write_exp_elt_opcode (ps, OP_LAST);
> +  write_exp_elt_longcst (ps, (LONGEST) i);
> +  write_exp_elt_opcode (ps, OP_LAST);
>    return;
>  handle_register:
> -  write_exp_elt_opcode (OP_REGISTER);
> +  write_exp_elt_opcode (ps, OP_REGISTER);
>    str.length--;
>    str.ptr++;
> -  write_exp_string (str);
> -  write_exp_elt_opcode (OP_REGISTER);
> +  write_exp_string (ps, str);
> +  write_exp_elt_opcode (ps, OP_REGISTER);
>    return;
>  }
>  
> @@ -1093,6 +1106,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
>    volatile struct gdb_exception except;
>    struct cleanup *old_chain;
>    const struct language_defn *lang = NULL;
> +  struct parser_state ps;
>    int subexp;
>  
>    lexptr = *stringptr;
> @@ -1156,56 +1170,44 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
>    else
>      lang = current_language;
>  
> -  expout_size = 10;
> -  expout_ptr = 0;
> -  expout = (struct expression *)
> -    xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
> -  expout->language_defn = lang;
> -  expout->gdbarch = get_current_arch ();
> +  initialize_expout (&ps, 10, lang, get_current_arch ());
>  
>    TRY_CATCH (except, RETURN_MASK_ALL)
>      {
> -      if (lang->la_parser ())
> -        lang->la_error (NULL);
> +      if (lang->la_parser (&ps))
> +        lang->la_error (&ps, NULL);
>      }
>    if (except.reason < 0)
>      {
>        if (! in_parse_field)
>  	{
> -	  xfree (expout);
> +	  xfree (ps.expout);
>  	  throw_exception (except);
>  	}
>      }
>  
>    discard_cleanups (old_chain);
>  
> -  /* Record the actual number of expression elements, and then
> -     reallocate the expression memory so that we free up any
> -     excess elements.  */
> -
> -  expout->nelts = expout_ptr;
> -  expout = (struct expression *)
> -    xrealloc ((char *) expout,
> -	      sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));
> +  reallocate_expout (&ps);
>  
>    /* Convert expression from postfix form as generated by yacc
>       parser, to a prefix form.  */
>  
>    if (expressiondebug)
> -    dump_raw_expression (expout, gdb_stdlog,
> +    dump_raw_expression (ps.expout, gdb_stdlog,
>  			 "before conversion to prefix form");
>  
> -  subexp = prefixify_expression (expout);
> +  subexp = prefixify_expression (ps.expout);
>    if (out_subexp)
>      *out_subexp = subexp;
>  
> -  lang->la_post_parser (&expout, void_context_p);
> +  lang->la_post_parser (&ps.expout, void_context_p);
>  
>    if (expressiondebug)
> -    dump_prefix_expression (expout, gdb_stdlog);
> +    dump_prefix_expression (ps.expout, gdb_stdlog);
>  
>    *stringptr = lexptr;
> -  return expout;
> +  return ps.expout;
>  }
>  
>  /* Parse STRING as an expression, and complain if this fails
> @@ -1372,9 +1374,9 @@ push_type_int (int n)
>  }
>  
>  void
> -push_type_address_space (char *string)
> +push_type_address_space (struct parser_state *ps, char *string)
>  {
> -  push_type_int (address_space_name_to_int (parse_gdbarch, string));
> +  push_type_int (address_space_name_to_int (parse_gdbarch (ps), string));
>  }
>  
>  enum type_pieces
> @@ -1644,6 +1646,21 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
>    return exp_iterate (exp, exp_uses_objfile_iter, objfile);
>  }
>  
> +/* See definition in parser-defs.h.  */
> +
> +void
> +increase_expout_size (struct parser_state *ps, size_t lenelt)
> +{
> +  if ((ps->expout_ptr + lenelt) >= ps->expout_size)
> +    {
> +      ps->expout_size = max (ps->expout_size * 2,
> +			     ps->expout_ptr + lenelt + 10);
> +      ps->expout = (struct expression *)
> +	xrealloc (ps->expout, (sizeof (struct expression)
> +			       + EXP_ELEM_TO_BYTES (ps->expout_size)));
> +    }
> +}
> +
>  void
>  _initialize_parse (void)
>  {
> diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
> index 16b40ac..89880cb 100644
> --- a/gdb/parser-defs.h
> +++ b/gdb/parser-defs.h
> @@ -30,12 +30,24 @@ struct block;
>  
>  extern int parser_debug;
>  
> -extern struct expression *expout;
> -extern int expout_size;
> -extern int expout_ptr;
> +#define parse_gdbarch(ps) ((ps)->expout->gdbarch)
> +#define parse_language(ps) ((ps)->expout->language_defn)
>  
> -#define parse_gdbarch (expout->gdbarch)
> -#define parse_language (expout->language_defn)
> +struct parser_state
> +{
> +  /* The expression related to this parser state.  */
> +
> +  struct expression *expout;
> +
> +  /* The size of the expression above.  */
> +
> +  size_t expout_size;
> +
> +  /* The number of elements already in the expression.  This is used
> +     to know where to put new elements.  */
> +
> +  size_t expout_ptr;
> +};
>  
>  /* If this is nonzero, this block is used as the lexical context
>     for symbol names.  */
> @@ -130,35 +142,38 @@ union type_stack_elt
>  extern union type_stack_elt *type_stack;
>  extern int type_stack_depth, type_stack_size;
>  
> -extern void write_exp_elt_opcode (enum exp_opcode);
> +extern void write_exp_elt_opcode (struct parser_state *, enum exp_opcode);
>  
> -extern void write_exp_elt_sym (struct symbol *);
> +extern void write_exp_elt_sym (struct parser_state *, struct symbol *);
>  
> -extern void write_exp_elt_longcst (LONGEST);
> +extern void write_exp_elt_longcst (struct parser_state *, LONGEST);
>  
> -extern void write_exp_elt_dblcst (DOUBLEST);
> +extern void write_exp_elt_dblcst (struct parser_state *, DOUBLEST);
>  
> -extern void write_exp_elt_decfloatcst (gdb_byte *);
> +extern void write_exp_elt_decfloatcst (struct parser_state *, gdb_byte *);
>  
> -extern void write_exp_elt_type (struct type *);
> +extern void write_exp_elt_type (struct parser_state *, struct type *);
>  
> -extern void write_exp_elt_intern (struct internalvar *);
> +extern void write_exp_elt_intern (struct parser_state *, struct internalvar *);
>  
> -extern void write_exp_string (struct stoken);
> +extern void write_exp_string (struct parser_state *, struct stoken);
>  
> -void write_exp_string_vector (int type, struct stoken_vector *vec);
> +void write_exp_string_vector (struct parser_state *, int type,
> +			      struct stoken_vector *vec);
>  
> -extern void write_exp_bitstring (struct stoken);
> +extern void write_exp_bitstring (struct parser_state *, struct stoken);
>  
> -extern void write_exp_elt_block (struct block *);
> +extern void write_exp_elt_block (struct parser_state *, struct block *);
>  
> -extern void write_exp_elt_objfile (struct objfile *objfile);
> +extern void write_exp_elt_objfile (struct parser_state *,
> +				   struct objfile *objfile);
>  
> -extern void write_exp_msymbol (struct minimal_symbol *);
> +extern void write_exp_msymbol (struct parser_state *,
> +			       struct minimal_symbol *);
>  
> -extern void write_dollar_variable (struct stoken str);
> +extern void write_dollar_variable (struct parser_state *, struct stoken str);
>  
> -extern void mark_struct_expression (void);
> +extern void mark_struct_expression (struct parser_state *);
>  
>  extern char *find_template_name_end (char *);
>  
> @@ -172,7 +187,7 @@ extern void push_type (enum type_pieces);
>  
>  extern void push_type_int (int);
>  
> -extern void push_type_address_space (char *);
> +extern void push_type_address_space (struct parser_state *, char *);
>  
>  extern enum type_pieces pop_type (void);
>  
> @@ -315,4 +330,10 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
>  
>  extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
>  
> +/* Reallocate the `expout' pointer inside PS so that it can accommodate
> +   at least LENELT expression elements.  This function does nothing if
> +   there is enough room for the elements.  */
> +
> +extern void increase_expout_size (struct parser_state *ps, size_t lenelt);
> +
>  #endif /* PARSER_DEFS_H */
> 
> 

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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 22:03       ` Jan Kratochvil
@ 2012-01-16 12:32         ` Sergio Durigan Junior
  0 siblings, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-16 12:32 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On Sunday, January 15 2012, Jan Kratochvil wrote:

> On Sun, 15 Jan 2012 22:07:30 +0100, Sergio Durigan Junior wrote:
>> >> +  ps->expout = (struct expression *)
>> >> +    xmalloc (sizeof (struct expression)
>> >> +    + EXP_ELEM_TO_BYTES (ps->expout_size));
>> >
>> > That return type cast is excessive.  It had meaning for K&R C where xmalloc
>> > returns PTR but that is no longer supported.  There should be done
>> > s/PTR/void */ everywhere and #define PTR should be removed
>> > and #pragma GCC poison -ed.
>> 
>> Sorry, I am not sure I understood your argument.
>
> I do not understand why you put that cast in.

I didn't.  This code already existed, and I just copied and pasted it.
When I did that, I must confess that I did not notice the casting to
struct expression, so thanks for catching it.

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

* Re: [RFC 2/8] C language
  2012-01-15 19:01 ` [RFC 2/8] C language Sergio Durigan Junior
@ 2012-01-16 19:29   ` Tom Tromey
  2012-01-16 19:55     ` Sergio Durigan Junior
  2012-01-18 11:38     ` Sergio Durigan Junior
  0 siblings, 2 replies; 26+ messages in thread
From: Tom Tromey @ 2012-01-16 19:29 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> Here and in all the .y files, I had to add an argument to the parser and
Sergio> the lexer functions, which is a `struct parser_state *ps'.

I think 'ps' is too short a name for something used all over the file.

Sergio> +%parse-param {struct parser_state *ps}
Sergio> +%lex-param {struct parser_state *ps}

This means we would require bison.

I don't really mind us requiring bison, but I think it is a bigger issue
and would need a separate patch - and at least configury changes.

Another approach would be to temporarily make a "local global" in the .y
file, then set this local global in the entry point to the parser.

This does not solve the whole problem, but it does make things somewhat
more modular, as a first step.

Sergio> -			{ write_exp_elt_opcode (BINOP_COMMA); }
Sergio> +			{ write_exp_elt_opcode (ps, BINOP_COMMA); }

All the mechanical changes are ok.  Thanks for taking this on.

Tom

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

* Re: [RFC 0/8] Beginning to remove globals from parser-defs.h
  2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
                   ` (7 preceding siblings ...)
  2012-01-15 20:34 ` [RFC 8/8] Pascal language Sergio Durigan Junior
@ 2012-01-16 19:29 ` Tom Tromey
  8 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2012-01-16 19:29 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> I have been working on this during my weekends, and I would like
Sergio> to know what you guys think about this set of patches.

I sent a comment on the c-exp.y patch, but really the same comment
applies to all of them.

Other than that, I think it is a good cleanup.

Sergio> There are still some (lots of?) other global variables there,
Sergio> which I didn't touch yet.  Maybe some day I will have
Sergio> time/patience for that...

Yeah, it would be good if you could.  Half-done transitions are sort of
a pain; gdb has plenty of these already.

Tom

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

* Re: [RFC 8/8] Pascal language
  2012-01-15 20:34 ` [RFC 8/8] Pascal language Sergio Durigan Junior
@ 2012-01-16 19:29   ` Tom Tromey
  0 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2012-01-16 19:29 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> This is the patch for the Pascal language.  I forgot to mention in the
Sergio> other patches: I also took the liberty (in all files) to cleanup #if 0
Sergio> functions, and to convert old-style function declarations to use the
Sergio> "new" style, i.e.:

It is generally better to do different cleanups separately.
I know it can be a pain to do this, but at least now we have "git stash" :)

Removing most #if 0 code is obvious.  There may be an individual case or
two where there is some controversy.  Anyway, please do it, use your
best judgment and trust that people will push back if you pick the wrong
one :).

Converting K&R -> ANSI style is obvious as well.  Please just put these
in.

Tom

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

* Re: [RFC 1/8] Language independent bits
  2012-01-16 20:40     ` Tom Tromey
@ 2012-01-16 19:39       ` Sergio Durigan Junior
  2012-01-16 19:40         ` Jan Kratochvil
  2012-01-16 20:27         ` Tom Tromey
  0 siblings, 2 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-16 19:39 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Jan Kratochvil, gdb-patches

On Monday, January 16 2012, Tom Tromey wrote:

>>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
>>> +    int expout_size;
> Jan> Memory object size does not fit into `int', it should be `size_t'.
>
> I agree, but I think that mixing different kinds of refactorings into
> one patch can be unnecessarily complicated and confusing.  The 'int' is
> already there today.

I already replaced `int' by `size_t'.  Do you want me to revert the change?

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

* Re: [RFC 1/8] Language independent bits
  2012-01-16 19:39       ` Sergio Durigan Junior
@ 2012-01-16 19:40         ` Jan Kratochvil
  2012-01-16 20:27         ` Tom Tromey
  1 sibling, 0 replies; 26+ messages in thread
From: Jan Kratochvil @ 2012-01-16 19:40 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Tom Tromey, gdb-patches

On Mon, 16 Jan 2012 20:37:47 +0100, Sergio Durigan Junior wrote:
> I already replaced `int' by `size_t'.  Do you want me to revert the change?

FYI I did not notice it was there already.  This bug is common in GDB,
I understand it is an unrelated patch, though.


Thanks,
Jan

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

* Re: [RFC 2/8] C language
  2012-01-16 19:29   ` Tom Tromey
@ 2012-01-16 19:55     ` Sergio Durigan Junior
  2012-01-18 11:38     ` Sergio Durigan Junior
  1 sibling, 0 replies; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-16 19:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Monday, January 16 2012, Tom Tromey wrote:

>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> Here and in all the .y files, I had to add an argument to the parser and
> Sergio> the lexer functions, which is a `struct parser_state *ps'.
>
> I think 'ps' is too short a name for something used all over the file.

Right.  I was thinking about `pstate' then.  I had an initial version of
the patch with this name, but I decided to shorten it because of
reformatting burden.

> Sergio> +%parse-param {struct parser_state *ps}
> Sergio> +%lex-param {struct parser_state *ps}
>
> This means we would require bison.
>
> I don't really mind us requiring bison, but I think it is a bigger issue
> and would need a separate patch - and at least configury changes.
>
> Another approach would be to temporarily make a "local global" in the .y
> file, then set this local global in the entry point to the parser.
>
> This does not solve the whole problem, but it does make things somewhat
> more modular, as a first step.

Ok, thanks for pointing that out.  I will make the requested changes then.

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

* Re: [RFC 1/8] Language independent bits
  2012-01-16 19:39       ` Sergio Durigan Junior
  2012-01-16 19:40         ` Jan Kratochvil
@ 2012-01-16 20:27         ` Tom Tromey
  1 sibling, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2012-01-16 20:27 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Jan Kratochvil, gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> I already replaced `int' by `size_t'.  Do you want me to revert
Sergio> the change?

No, there's no need to do additional work.

My general rule is that we should review patches, not the context of
patches.  If the context of a patch has problems, and it matters to the
reviewer, then either (1) the review can ask for a separate patch to fix
it (and in this case accept "no" as an answer), or (2) the reviewer can
fix it himself (since it is so darn important :-).

Sometimes it can be hard to recognize that a particular gross bit in a
patch was actually just moved from elsewhere.  In this case, IMO, the
patch submitter can and probably should just push back against the
review -- whatever bad effect there was is already there.

Of course, it is nice if we improve the code as we go along.  I think it
is usually easier to understand, and thus also review and approve,
separate patches for separate issues.

Tom

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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 21:08   ` Jan Kratochvil
  2012-01-15 21:17     ` Sergio Durigan Junior
@ 2012-01-16 20:40     ` Tom Tromey
  2012-01-16 19:39       ` Sergio Durigan Junior
  2012-01-17 16:44     ` Doug Evans
  2 siblings, 1 reply; 26+ messages in thread
From: Tom Tromey @ 2012-01-16 20:40 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Sergio Durigan Junior, gdb-patches

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

>> +    int expout_size;
Jan> Memory object size does not fit into `int', it should be `size_t'.

I agree, but I think that mixing different kinds of refactorings into
one patch can be unnecessarily complicated and confusing.  The 'int' is
already there today.

Tom

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

* Re: [RFC 6/8] Modula-2 language
  2012-01-15 19:07 ` [RFC 6/8] Modula-2 language Sergio Durigan Junior
@ 2012-01-17 10:21   ` Gaius Mulley
  0 siblings, 0 replies; 26+ messages in thread
From: Gaius Mulley @ 2012-01-17 10:21 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

Sergio Durigan Junior <sergiodj@redhat.com> writes:

> Hello,
>
> This is the patch for the Modula-2 language.
>
> Thanks,
>
> Sergio.

Hi Sergio,

from eyeballing the code - this patch appears fine,

regards,
Gaius

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

* Re: [RFC 1/8] Language independent bits
  2012-01-15 21:08   ` Jan Kratochvil
  2012-01-15 21:17     ` Sergio Durigan Junior
  2012-01-16 20:40     ` Tom Tromey
@ 2012-01-17 16:44     ` Doug Evans
  2012-01-17 16:54       ` Jan Kratochvil
  2 siblings, 1 reply; 26+ messages in thread
From: Doug Evans @ 2012-01-17 16:44 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Sergio Durigan Junior, gdb-patches

On Sun, Jan 15, 2012 at 12:34 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
>> +
>> +    struct expression *expout;
>> +
>> +    /* The size of the expression above.  */
>> +
>> +    int expout_size;
>
> Memory object size does not fit into `int', it should be `size_t'.
>
>
>> +
>> +    /* The number of elements already in the expression.  This is used
>> +       to know where to put new elements.  */
>> +
>> +    int expout_ptr;
>
> Likewise.

Sure, but I think this is excessively nitpicky.
Each element is (at least) 16 bytes in size and gdb has been using
ints just fine so far.

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

* Re: [RFC 1/8] Language independent bits
  2012-01-17 16:44     ` Doug Evans
@ 2012-01-17 16:54       ` Jan Kratochvil
  0 siblings, 0 replies; 26+ messages in thread
From: Jan Kratochvil @ 2012-01-17 16:54 UTC (permalink / raw)
  To: Doug Evans; +Cc: Sergio Durigan Junior, gdb-patches

On Tue, 17 Jan 2012 17:34:03 +0100, Doug Evans wrote:
> On Sun, Jan 15, 2012 at 12:34 PM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> Sure, but I think this is excessively nitpicky.

I agree with the part this was code moving, not new fields.


> Each element is (at least) 16 bytes in size and gdb has been using
> ints just fine so far.

Evaluating each memory size carefully whether it can or can not exceed 2GB is
too much burden on the human.  Any such evaluation mistake then can mean
deployment failure like which happened to Red Hat customer(s).  I do not find
the performance impact 4 -> 8 bytes measurable nowadays to justify such
optimization cost.  It is and it will be already a lot of work to fix all the
existing wrong memory sizes as `int', trying to optimize them all properly for
4 vs. 8 bytes I do not find realistic.

It may make sense only in some special cases like struct partial_symbol or
struct main_type.


Thanks,
Jan

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

* Re: [RFC 2/8] C language
  2012-01-16 19:29   ` Tom Tromey
  2012-01-16 19:55     ` Sergio Durigan Junior
@ 2012-01-18 11:38     ` Sergio Durigan Junior
  2012-01-18 16:50       ` Tom Tromey
  1 sibling, 1 reply; 26+ messages in thread
From: Sergio Durigan Junior @ 2012-01-18 11:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Monday, January 16 2012, Tom Tromey wrote:

>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> Here and in all the .y files, I had to add an argument to the parser and
> Sergio> the lexer functions, which is a `struct parser_state *ps'.
>
> I think 'ps' is too short a name for something used all over the file.

Sorry, I am not sure you saw my other message.  I was questioning if
`pstate' is a better name in your opinion.  Since the find-and-replace
takes lots of time, I decided to ask instead of sending another round of
patches...

Thanks.

-- 
Sergio

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

* Re: [RFC 2/8] C language
  2012-01-18 11:38     ` Sergio Durigan Junior
@ 2012-01-18 16:50       ` Tom Tromey
  0 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2012-01-18 16:50 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> Sorry, I am not sure you saw my other message.  I was questioning if
Sergio> `pstate' is a better name in your opinion.  Since the find-and-replace
Sergio> takes lots of time, I decided to ask instead of sending another round of
Sergio> patches...

That would be fine by me.  Thanks for doing this.

Tom

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

end of thread, other threads:[~2012-01-18 16:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-15 18:51 [RFC 0/8] Beginning to remove globals from parser-defs.h Sergio Durigan Junior
2012-01-15 18:56 ` [RFC 1/8] Language independent bits Sergio Durigan Junior
2012-01-15 21:08   ` Jan Kratochvil
2012-01-15 21:17     ` Sergio Durigan Junior
2012-01-15 22:03       ` Jan Kratochvil
2012-01-16 12:32         ` Sergio Durigan Junior
2012-01-16 20:40     ` Tom Tromey
2012-01-16 19:39       ` Sergio Durigan Junior
2012-01-16 19:40         ` Jan Kratochvil
2012-01-16 20:27         ` Tom Tromey
2012-01-17 16:44     ` Doug Evans
2012-01-17 16:54       ` Jan Kratochvil
2012-01-15 19:01 ` [RFC 2/8] C language Sergio Durigan Junior
2012-01-16 19:29   ` Tom Tromey
2012-01-16 19:55     ` Sergio Durigan Junior
2012-01-18 11:38     ` Sergio Durigan Junior
2012-01-18 16:50       ` Tom Tromey
2012-01-15 19:04 ` [RFC 3/8] Ada language Sergio Durigan Junior
2012-01-15 19:05 ` [RFC 4/8] Fortran language Sergio Durigan Junior
2012-01-15 19:06 ` [RFC 5/8] Java language Sergio Durigan Junior
2012-01-15 19:07 ` [RFC 6/8] Modula-2 language Sergio Durigan Junior
2012-01-17 10:21   ` Gaius Mulley
2012-01-15 19:10 ` [RFC 7/8] Objective-C language Sergio Durigan Junior
2012-01-15 20:34 ` [RFC 8/8] Pascal language Sergio Durigan Junior
2012-01-16 19:29   ` Tom Tromey
2012-01-16 19:29 ` [RFC 0/8] Beginning to remove globals from parser-defs.h Tom Tromey

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).