* [PATCH 01/10] Language independent bits
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
@ 2012-06-02 19:33 ` Sergio Durigan Junior
2012-06-04 20:20 ` Tom Tromey
2012-06-02 19:33 ` [PATCH 02/10] SystemTap integration Sergio Durigan Junior
` (9 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 19:33 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
This patch does a refactoring on gdb/{parse.c,parser-defs.h,language.*}
in order to remove the `expout*' globals. I have created a new
structure called `parser_state' which holds those variables per-parser,
and eventually will hold all the global parser variables.
---
gdb/language.c | 4 +-
gdb/language.h | 3 +-
gdb/parse.c | 274 ++++++++++++++++++++++++++---------------------------
gdb/parser-defs.h | 84 +++++++++++------
4 files changed, 193 insertions(+), 172 deletions(-)
diff --git a/gdb/language.c b/gdb/language.c
index f0a8697..bcbce55 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -49,7 +49,7 @@ extern void _initialize_language (void);
static void unk_lang_error (char *);
-static int unk_lang_parser (void);
+static int unk_lang_parser (struct parser_state *);
static void show_check (char *, int);
@@ -803,7 +803,7 @@ 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;
}
diff --git a/gdb/language.h b/gdb/language.h
index d612c70..a146b33 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. */
@@ -182,7 +183,7 @@ struct language_defn
/* Parser function. */
- int (*la_parser) (void);
+ int (*la_parser) (struct parser_state *);
/* Parser error function. */
diff --git a/gdb/parse.c b/gdb/parse.c
index f54c6f2..2d4e6e1 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;
@@ -177,118 +174,121 @@ free_funcalls (void *ignore)
}
}
\f
-/* This page contains the functions for adding data to the struct expression
- being constructed. */
/* See definition in parser-defs.h. */
void
-initialize_expout (int initial_size, const struct language_defn *lang,
+initialize_expout (struct parser_state *ps, size_t initial_size,
+ const struct language_defn *lang,
struct gdbarch *gdbarch)
{
- expout_size = initial_size;
- expout_ptr = 0;
- expout = xmalloc (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (expout_size));
- expout->language_defn = lang;
- expout->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;
}
/* See definition in parser-defs.h. */
void
-reallocate_expout (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. */
- expout->nelts = expout_ptr;
- expout = xrealloc ((char *) expout,
- sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (expout_ptr));
+ 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. */
+
/* Add one element to the end of the expression. */
/* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
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;
@@ -296,27 +296,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.
@@ -341,10 +341,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
@@ -354,28 +354,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.
@@ -392,9 +383,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. */
@@ -413,28 +406,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.
@@ -449,11 +436,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,
@@ -462,33 +449,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);
@@ -526,60 +504,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
@@ -605,7 +583,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;
@@ -643,7 +621,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;
@@ -653,9 +631,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;
}
@@ -666,36 +644,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;
}
@@ -1116,6 +1094,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;
@@ -1179,44 +1158,44 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
else
lang = current_language;
- initialize_expout (10, lang, get_current_arch ());
+ initialize_expout (&ps, 10, lang, get_current_arch ());
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (lang->la_parser ())
+ if (lang->la_parser (&ps))
lang->la_error (NULL);
}
if (except.reason < 0)
{
if (! in_parse_field)
{
- xfree (expout);
+ xfree (ps.expout);
throw_exception (except);
}
}
discard_cleanups (old_chain);
- reallocate_expout ();
+ 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
@@ -1382,9 +1361,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
@@ -1654,6 +1633,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 72b9e2f..2defddf 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -25,17 +25,32 @@
#define PARSER_DEFS_H 1
#include "doublest.h"
+#include "expression.h"
struct block;
+struct language_defn;
+struct internalvar;
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. */
@@ -131,19 +146,21 @@ extern union type_stack_elt *type_stack;
extern int type_stack_depth, type_stack_size;
/* Helper function to initialize the expout, expout_size, expout_ptr
- trio before it is used to store expression elements created during
- the parsing of an expression. INITIAL_SIZE is the initial size of
+ trio inside PS before it is used to store expression elements created
+ during the parsing of an expression. INITIAL_SIZE is the initial size of
the expout array. LANG is the language used to parse the expression.
And GDBARCH is the gdbarch to use during parsing. */
-extern void initialize_expout (int, const struct language_defn *,
- struct gdbarch *);
+extern void initialize_expout (struct parser_state *ps,
+ size_t initial_size,
+ const struct language_defn *lang,
+ struct gdbarch *gdbarch);
-/* Helper function that frees any unsed space in the expout array.
- It is generally used when the parser has just been parsed and
- created. */
+/* 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. */
-extern void reallocate_expout (void);
+extern void reallocate_expout (struct parser_state *ps);
/* Reverse an expression from suffix form (in which it is constructed)
to prefix form (in which we can conveniently print or execute it).
@@ -154,35 +171,38 @@ extern void reallocate_expout (void);
extern int prefixify_expression (struct expression *expr);
-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 *);
@@ -196,7 +216,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);
@@ -339,4 +359,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 */
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 02/10] SystemTap integration
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 01/10] Language independent bits Sergio Durigan Junior
@ 2012-06-02 19:33 ` Sergio Durigan Junior
2012-06-04 20:23 ` Tom Tromey
2012-06-02 19:34 ` [PATCH 03/10] C language Sergio Durigan Junior
` (8 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 19:33 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
With the inclusion of the SystemTap integration patch, I had to create
this other patch to make it compile with this refactoring. It simply
uses the new field `pstate' present in `struct stap_parse_info'.
---
gdb/arm-linux-tdep.c | 26 ++++++++--------
gdb/i386-tdep.c | 85 ++++++++++++++++++++++++++------------------------
gdb/ppc-linux-tdep.c | 6 ++--
gdb/stap-probe.c | 64 +++++++++++++++++++------------------
gdb/stap-probe.h | 6 +++
5 files changed, 99 insertions(+), 88 deletions(-)
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f4eaa5c..be4f202 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -1147,28 +1147,28 @@ arm_stap_parse_special_token (struct gdbarch *gdbarch,
return 0;
/* The displacement. */
- write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (displacement);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
+ write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, displacement);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (got_minus)
- write_exp_elt_opcode (UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
/* The register name. */
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
str.ptr = regname;
str.length = len;
- write_exp_string (str);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, str);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
- write_exp_elt_opcode (BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
/* Casting to the expected type. */
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (lookup_pointer_type (p->arg_type));
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
+ write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
- write_exp_elt_opcode (UNOP_IND);
+ write_exp_elt_opcode (&p->pstate, UNOP_IND);
p->arg = tmp;
}
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 5b04505..5751a2d 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3499,34 +3499,36 @@ i386_stap_parse_special_token (struct gdbarch *gdbarch,
for (i = 0; i < 3; i++)
{
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
write_exp_elt_type
- (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (displacements[i]);
- write_exp_elt_opcode (OP_LONG);
+ (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, displacements[i]);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (got_minus[i])
- write_exp_elt_opcode (UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
}
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
str.ptr = regname;
str.length = len;
- write_exp_string (str);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, str);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (builtin_type (gdbarch)->builtin_data_ptr);
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
+ write_exp_elt_type (&p->pstate,
+ builtin_type (gdbarch)->builtin_data_ptr);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
- write_exp_elt_opcode (BINOP_ADD);
- write_exp_elt_opcode (BINOP_ADD);
- write_exp_elt_opcode (BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (lookup_pointer_type (p->arg_type));
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
+ write_exp_elt_type (&p->pstate,
+ lookup_pointer_type (p->arg_type));
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
- write_exp_elt_opcode (UNOP_IND);
+ write_exp_elt_opcode (&p->pstate, UNOP_IND);
p->arg = s;
@@ -3627,49 +3629,50 @@ i386_stap_parse_special_token (struct gdbarch *gdbarch,
if (offset)
{
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
write_exp_elt_type
- (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (offset);
- write_exp_elt_opcode (OP_LONG);
+ (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, offset);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (offset_minus)
- write_exp_elt_opcode (UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
}
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
base_token.ptr = base;
base_token.length = len_base;
- write_exp_string (base_token);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, base_token);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
if (offset)
- write_exp_elt_opcode (BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
index_token.ptr = index;
index_token.length = len_index;
- write_exp_string (index_token);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, index_token);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
if (size)
{
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
write_exp_elt_type
- (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (size);
- write_exp_elt_opcode (OP_LONG);
+ (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, size);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (size_minus)
- write_exp_elt_opcode (UNOP_NEG);
- write_exp_elt_opcode (BINOP_MUL);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, BINOP_MUL);
}
- write_exp_elt_opcode (BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (lookup_pointer_type (p->arg_type));
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
+ write_exp_elt_type (&p->pstate,
+ lookup_pointer_type (p->arg_type));
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
- write_exp_elt_opcode (UNOP_IND);
+ write_exp_elt_opcode (&p->pstate, UNOP_IND);
p->arg = s;
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 98704c1..2bf3259 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1335,11 +1335,11 @@ ppc_stap_parse_special_token (struct gdbarch *gdbarch,
error (_("Invalid register name `%s' on expression `%s'."),
regname, p->saved_arg);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
str.ptr = regname;
str.length = len;
- write_exp_string (str);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, str);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
p->arg = s;
}
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 506e6c3..80b0671 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -427,12 +427,12 @@ stap_parse_register_operand (struct stap_parse_info *p)
displacement = strtol (p->arg, (char **) &p->arg, 10);
/* Generating the expression for the displacement. */
- write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (displacement);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
+ write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, displacement);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (got_minus)
- write_exp_elt_opcode (UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
}
/* Getting rid of register indirection prefix. */
@@ -487,23 +487,23 @@ stap_parse_register_operand (struct stap_parse_info *p)
error (_("Invalid register name `%s' on expression `%s'."),
regname, p->saved_arg);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
str.ptr = regname;
str.length = len;
- write_exp_string (str);
- write_exp_elt_opcode (OP_REGISTER);
+ write_exp_string (&p->pstate, str);
+ write_exp_elt_opcode (&p->pstate, OP_REGISTER);
if (indirect_p)
{
if (disp_p)
- write_exp_elt_opcode (BINOP_ADD);
+ write_exp_elt_opcode (&p->pstate, BINOP_ADD);
/* Casting to the expected type. */
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (lookup_pointer_type (p->arg_type));
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
+ write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
+ write_exp_elt_opcode (&p->pstate, UNOP_CAST);
- write_exp_elt_opcode (UNOP_IND);
+ write_exp_elt_opcode (&p->pstate, UNOP_IND);
}
/* Getting rid of the register name suffix. */
@@ -608,9 +608,9 @@ stap_parse_single_operand (struct stap_parse_info *p)
++p->arg;
stap_parse_argument_conditionally (p);
if (c == '-')
- write_exp_elt_opcode (UNOP_NEG);
+ write_exp_elt_opcode (&p->pstate, UNOP_NEG);
else if (c == '~')
- write_exp_elt_opcode (UNOP_COMPLEMENT);
+ write_exp_elt_opcode (&p->pstate, UNOP_COMPLEMENT);
}
else
{
@@ -639,10 +639,11 @@ stap_parse_single_operand (struct stap_parse_info *p)
&& strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
{
/* We are dealing with a numeric constant. */
- write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (number);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
+ write_exp_elt_type (&p->pstate,
+ builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, number);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
p->arg = tmp;
@@ -671,10 +672,10 @@ stap_parse_single_operand (struct stap_parse_info *p)
p->arg += const_prefix_len;
number = strtol (p->arg, (char **) &p->arg, 10);
- write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
- write_exp_elt_longcst (number);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
+ write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
+ write_exp_elt_longcst (&p->pstate, number);
+ write_exp_elt_opcode (&p->pstate, OP_LONG);
if (const_suffix)
{
@@ -822,7 +823,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
stap_parse_argument_1 (p, 1, lookahead_prec);
}
- write_exp_elt_opcode (opcode);
+ write_exp_elt_opcode (&p->pstate, opcode);
}
}
@@ -863,8 +864,8 @@ stap_parse_argument (const char **arg, struct type *atype,
/* We need to initialize the expression buffer, in order to begin
our parsing efforts. The language here does not matter, since we
are using our own parser. */
- initialize_expout (10, current_language, gdbarch);
- back_to = make_cleanup (free_current_contents, &expout);
+ initialize_expout (&p.pstate, 10, current_language, gdbarch);
+ back_to = make_cleanup (free_current_contents, &p.pstate.expout);
p.saved_arg = *arg;
p.arg = *arg;
@@ -879,16 +880,17 @@ stap_parse_argument (const char **arg, struct type *atype,
gdb_assert (p.inside_paren_p == 0);
/* Casting the final expression to the appropriate type. */
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (atype);
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (&p.pstate, UNOP_CAST);
+ write_exp_elt_type (&p.pstate, atype);
+ write_exp_elt_opcode (&p.pstate, UNOP_CAST);
- reallocate_expout ();
+ reallocate_expout (&p.pstate);
p.arg = skip_spaces_const (p.arg);
*arg = p.arg;
- return expout;
+ /* We can safely return EXPOUT here. */
+ return p.pstate.expout;
}
/* Function which parses an argument string from PROBE, correctly splitting
diff --git a/gdb/stap-probe.h b/gdb/stap-probe.h
index e30d56a..003fad9 100644
--- a/gdb/stap-probe.h
+++ b/gdb/stap-probe.h
@@ -20,6 +20,9 @@
#if !defined (STAP_PROBE_H)
#define STAP_PROBE_H 1
+/* For `struct parser_state'. */
+#include "parser-defs.h"
+
/* Structure which holds information about the parsing process of one probe's
argument. */
@@ -28,6 +31,9 @@ struct stap_parse_info
/* The probe's argument in a string format. */
const char *arg;
+ /* The parser state to be used when generating the expression. */
+ struct parser_state pstate;
+
/* A pointer to the full chain of arguments. This is useful for printing
error messages. The parser functions should not modify this argument
directly; instead, they should use the ARG pointer above. */
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 00/10] Remove `expout*' globals from parser-defs.h
@ 2012-06-02 19:33 Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 01/10] Language independent bits Sergio Durigan Junior
` (10 more replies)
0 siblings, 11 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 19:33 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Hello,
This patch is the followup of:
http://sourceware.org/ml/gdb-patches/2012-01/msg00522.html
Thanks Tom for having reminded me about them! :-)
I have addressed the following comments from Tom:
http://sourceware.org/ml/gdb-patches/2012-01/msg00566.html
I also had to include some code to handle the recent included SystemTap
integration patch, because it uses the GDB expression mechanism in order
to parse & eval probes' arguments. And there is the Go programming
language support, which was included after my first attempt to get this
patch series in.
I regtested it on Fedora 16 x86{,_64}, and no regression was detected.
But please, I would like to ask to the language maintainers to take a
look either way: despite being mostly mechanical changes, there's always
a chance I got something wrong.
I separated this series in 10 logical patches, but they are not
independent from each other: you need all of them applied if you want to
build and test.
I am not sending the ChangeLogs yet, because they are somewhat hard to
generate. I will send them if the patches are approved, or if you
request it.
I hope everything is right this time. OK to apply?
Sergio Durigan Junior (10):
Language independent bits
SystemTap integration
C language
Ada language.
Fortran language
Java language
Modula-2 language
Objective-C language
Pascal language
Go programming language
gdb/ada-exp.y | 474 +++++++++++++++++++++-------------------
gdb/ada-lang.c | 4 +-
gdb/ada-lang.h | 3 +-
gdb/ada-lex.l | 54 +++---
gdb/arm-linux-tdep.c | 26 ++--
gdb/c-exp.y | 585 ++++++++++++++++++++++++++------------------------
gdb/c-lang.h | 3 +-
gdb/f-exp.y | 261 ++++++++++++----------
gdb/f-lang.h | 6 +-
gdb/go-exp.y | 268 +++++++++++++-----------
gdb/go-lang.h | 4 +-
gdb/i386-tdep.c | 85 ++++----
gdb/jv-exp.y | 357 ++++++++++++++++--------------
gdb/jv-lang.h | 5 +-
gdb/language.c | 4 +-
gdb/language.h | 3 +-
gdb/m2-exp.y | 261 ++++++++++++----------
gdb/m2-lang.h | 6 +-
gdb/objc-exp.y | 412 ++++++++++++++++++-----------------
gdb/objc-lang.c | 8 +-
gdb/objc-lang.h | 7 +-
gdb/p-exp.y | 327 +++++++++++++++-------------
gdb/p-lang.h | 5 +-
gdb/parse.c | 274 ++++++++++++------------
gdb/parser-defs.h | 84 +++++---
gdb/ppc-linux-tdep.c | 6 +-
gdb/stap-probe.c | 64 +++---
gdb/stap-probe.h | 6 +
28 files changed, 1914 insertions(+), 1688 deletions(-)
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 03/10] C language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 01/10] Language independent bits Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 02/10] SystemTap integration Sergio Durigan Junior
@ 2012-06-02 19:34 ` Sergio Durigan Junior
2012-06-04 4:25 ` Doug Evans
2012-06-04 20:32 ` Tom Tromey
2012-06-02 20:23 ` [PATCH 04/10] Ada language Sergio Durigan Junior
` (7 subsequent siblings)
10 siblings, 2 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 19:34 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
This patch modified gdb/{c-exp.y,c-lang.h} to reflect the changes made
by the first patch of the series.
As Tom suggested, I created a global variable inside the .y files which
holds the parser state; this avoided having to expand the prototype of
yylex and yyparse functions to accept this new argument (thus requiring
us to stick with bison).
All of the following patches do exactly the same as this one.
---
gdb/c-exp.y | 585 ++++++++++++++++++++++++++++++----------------------------
gdb/c-lang.h | 3 +-
2 files changed, 304 insertions(+), 284 deletions(-)
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index e912657..4a3c7ba 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
@@ -64,7 +64,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth c_maxdepth
-#define yyparse c_parse_internal
+#define yyparse _c_parse
#define yylex c_lex
#define yyerror c_error
#define yylval c_lval
@@ -116,6 +116,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -161,7 +166,8 @@ void yyerror (char *);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (struct parser_state *par_state, char *, int, int,
+ YYSTYPE *);
static struct stoken operator_stoken (const char *);
%}
@@ -258,134 +264,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);}
;
/* Expressions, including the comma operator. */
exp1 : exp
| exp1 ',' exp
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
;
/* Expressions, not including the comma operator. */
exp : '*' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
exp : '&' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_ADDR); }
+ { write_exp_elt_opcode (pstate, UNOP_ADDR); }
;
exp : '-' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
;
exp : '+' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PLUS); }
+ { write_exp_elt_opcode (pstate, UNOP_PLUS); }
;
exp : '!' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
exp : '~' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_COMPLEMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
;
exp : INCREMENT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PREINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
;
exp : DECREMENT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PREDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
;
exp : exp INCREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
;
exp : exp DECREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
;
exp : SIZEOF exp %prec UNARY
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
;
exp : exp ARROW COMPLETE
{ struct stoken s;
- mark_struct_expression ();
- write_exp_elt_opcode (STRUCTOP_PTR);
+ mark_struct_expression (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
s.ptr = "";
s.length = 0;
- write_exp_string (s);
- write_exp_elt_opcode (STRUCTOP_PTR); }
+ write_exp_string (pstate, s);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_ADDR);
+ write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
;
exp : exp ARROW_STAR exp
- { write_exp_elt_opcode (STRUCTOP_MPTR); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : exp '.' COMPLETE
{ struct stoken s;
- mark_struct_expression ();
- write_exp_elt_opcode (STRUCTOP_STRUCT);
+ mark_struct_expression (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
s.ptr = "";
s.length = 0;
- write_exp_string (s);
- write_exp_elt_opcode (STRUCTOP_STRUCT); }
+ write_exp_string (pstate, s);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_ADDR);
+ write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
;
exp : exp DOT_STAR exp
- { write_exp_elt_opcode (STRUCTOP_MEMBER); }
+ { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
;
exp : exp '[' exp1 ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
exp : exp '('
@@ -393,20 +399,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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_ADL_FUNC);
+ write_exp_elt_block (pstate, expression_context_block);
+ write_exp_elt_sym (pstate, NULL); /* Placeholder. */
+ write_exp_string (pstate, $1.stoken);
+ write_exp_elt_opcode (pstate, OP_ADL_FUNC);
/* This is to save the value of arglist_len
being accumulated by an outer function call. */
@@ -415,9 +421,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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
}
;
@@ -438,12 +444,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 (pstate, TYPE_INSTANCE);
+ write_exp_elt_longcst (pstate, (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 (pstate, $<tvec>3[i + 1]);
+ write_exp_elt_longcst (pstate, (LONGEST) $<ivec>3[0]);
+ write_exp_elt_opcode (pstate, TYPE_INSTANCE);
free ($3);
}
;
@@ -452,22 +458,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 (pstate, OP_ARRAY);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_longcst (pstate, (LONGEST) $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MEMVAL);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
exp : '(' exp1 ')'
@@ -477,100 +483,100 @@ exp : '(' exp1 ')'
/* Binary operators in order of decreasing precedence. */
exp : exp '@' exp
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
;
exp : exp '%' exp
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp LSH exp
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
;
exp : exp RSH exp
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
;
exp : exp EQUAL exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : exp '&' exp
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
exp : exp '^' exp
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
exp : exp '|' exp
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
exp : exp ANDAND exp
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
exp : exp OROR exp
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
exp : exp '?' exp ':' exp %prec '?'
- { write_exp_elt_opcode (TERNOP_COND); }
+ { write_exp_elt_opcode (pstate, TERNOP_COND); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : CHAR
@@ -578,33 +584,34 @@ exp : CHAR
struct stoken_vector vec;
vec.len = 1;
vec.tokens = &$1;
- write_exp_string_vector ($1.type, &vec);
+ write_exp_string_vector (pstate, $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 (pstate, $1.stoken.ptr, $1.stoken.length,
+ 0, &val);
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val_int.type);
+ write_exp_elt_longcst (pstate, (LONGEST) val.typed_val_int.val);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DECFLOAT);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_decfloatcst (pstate, $1.val);
+ write_exp_elt_opcode (pstate, OP_DECFLOAT); }
;
exp : variable
@@ -612,44 +619,45 @@ exp : variable
exp : VARIABLE
{
- write_dollar_variable ($1);
+ write_dollar_variable (pstate, $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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, lookup_signed_typename
+ (parse_language (pstate),
+ parse_gdbarch (pstate),
"int"));
CHECK_TYPEDEF ($3);
- write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
- write_exp_elt_opcode (OP_LONG); }
+ write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_REINTERPRET_CAST);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_DYNAMIC_CAST);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
string_exp:
@@ -714,7 +722,7 @@ exp : string_exp
}
}
- write_exp_string_vector (type, &$1);
+ write_exp_string_vector (pstate, type, &$1);
for (i = 0; i < $1.len; ++i)
free ($1.tokens[i].ptr);
free ($1.tokens);
@@ -723,17 +731,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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_bool);
+ write_exp_elt_longcst (pstate, (LONGEST) 1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_bool);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
/* end of C++. */
@@ -771,9 +779,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 (pstate, OP_VAR_ENTRY_VALUE);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
}
;
@@ -792,11 +800,11 @@ variable: block COLONCOLON name
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, block_found);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
;
qualified_name: TYPENAME COLONCOLON name
@@ -809,10 +817,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 (pstate, OP_SCOPE);
+ write_exp_elt_type (pstate, type);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_SCOPE);
}
| TYPENAME COLONCOLON '~' name
{
@@ -833,10 +841,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 (pstate, OP_SCOPE);
+ write_exp_elt_type (pstate, type);
+ write_exp_string (pstate, tmp_token);
+ write_exp_elt_opcode (pstate, OP_SCOPE);
}
| TYPENAME COLONCOLON name COLONCOLON name
{
@@ -859,16 +867,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 (pstate, OP_VAR_VALUE);
+ write_exp_elt_block (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
break;
}
msymbol = lookup_minimal_symbol (name, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
@@ -889,13 +897,13 @@ variable: name_not_typename
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
}
else if ($1.is_a_field_of_this)
{
@@ -906,11 +914,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 (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $1.stoken);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
}
else
{
@@ -920,7 +928,7 @@ variable: name_not_typename
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
@@ -931,7 +939,7 @@ variable: name_not_typename
;
space_identifier : '@' NAME
- { push_type_address_space (copy_name ($2.stoken));
+ { push_type_address_space (pstate, copy_name ($2.stoken));
push_type (tp_space_identifier);
}
;
@@ -1010,115 +1018,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 (pstate),
+ parse_gdbarch (pstate),
"int"); }
| LONG
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| SHORT
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| LONG INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| LONG SIGNED_KEYWORD INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| LONG SIGNED_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| SIGNED_KEYWORD LONG INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| UNSIGNED LONG INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| LONG UNSIGNED INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| LONG UNSIGNED
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long"); }
| LONG LONG
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| LONG LONG INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| LONG LONG SIGNED_KEYWORD INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| LONG LONG SIGNED_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| SIGNED_KEYWORD LONG LONG
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| SIGNED_KEYWORD LONG LONG INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| UNSIGNED LONG LONG
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| UNSIGNED LONG LONG INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| LONG LONG UNSIGNED
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| LONG LONG UNSIGNED INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long long"); }
| SHORT INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| SHORT SIGNED_KEYWORD INT_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| SHORT SIGNED_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| UNSIGNED SHORT INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| SHORT UNSIGNED
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| SHORT UNSIGNED INT_KEYWORD
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short"); }
| DOUBLE_KEYWORD
- { $$ = lookup_typename (parse_language, parse_gdbarch,
+ { $$ = lookup_typename (parse_language (pstate), parse_gdbarch (pstate),
"double", (struct block *) NULL,
0); }
| LONG DOUBLE_KEYWORD
- { $$ = lookup_typename (parse_language, parse_gdbarch,
+ { $$ = lookup_typename (parse_language (pstate), parse_gdbarch (pstate),
"long double",
(struct block *) NULL, 0); }
| STRUCT name
@@ -1134,20 +1142,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 (pstate),
+ parse_gdbarch (pstate),
TYPE_NAME($2.type)); }
| UNSIGNED
- { $$ = lookup_unsigned_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_unsigned_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"int"); }
| SIGNED_KEYWORD typename
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
TYPE_NAME($2.type)); }
| SIGNED_KEYWORD
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"int"); }
/* It appears that this rule for templates is never
reduced; template recognition happens by lookahead
@@ -1167,24 +1175,24 @@ typename: TYPENAME
{
$$.stoken.ptr = "int";
$$.stoken.length = 3;
- $$.type = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ $$.type = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"int");
}
| LONG
{
$$.stoken.ptr = "long";
$$.stoken.length = 4;
- $$.type = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ $$.type = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"long");
}
| SHORT
{
$$.stoken.ptr = "short";
$$.stoken.length = 5;
- $$.type = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ $$.type = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
"short");
}
;
@@ -1394,7 +1402,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 *par_state, 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. */
@@ -1426,9 +1435,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 (par_state)->builtin_decfloat;
decimal_from_string (putithere->typed_val_decfloat.val, 4,
- gdbarch_byte_order (parse_gdbarch), p);
+ gdbarch_byte_order (parse_gdbarch (par_state)), p);
p[len - 2] = 'd';
return DECFLOAT;
}
@@ -1437,9 +1446,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 (par_state)->builtin_decdouble;
decimal_from_string (putithere->typed_val_decfloat.val, 8,
- gdbarch_byte_order (parse_gdbarch), p);
+ gdbarch_byte_order (parse_gdbarch (par_state)), p);
p[len - 2] = 'd';
return DECFLOAT;
}
@@ -1448,14 +1457,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 (par_state)->builtin_declong;
decimal_from_string (putithere->typed_val_decfloat.val, 16,
- gdbarch_byte_order (parse_gdbarch), p);
+ gdbarch_byte_order (parse_gdbarch (par_state)), p);
p[len - 2] = 'd';
return DECFLOAT;
}
- if (! parse_c_float (parse_gdbarch, p, len,
+ if (! parse_c_float (parse_gdbarch (par_state), p, len,
&putithere->typed_val_float.dval,
&putithere->typed_val_float.type))
return ERROR;
@@ -1571,9 +1580,10 @@ 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 (par_state)) - 2)) == 0)
{
- high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+ high_bit
+ = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
/* A large decimal (not hex or octal) constant (between INT_MAX
and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -1581,28 +1591,29 @@ 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 (par_state)->builtin_unsigned_int;
+ signed_type = parse_type (par_state)->builtin_int;
}
else if (long_p <= 1
- && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+ && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_long;
+ signed_type = parse_type (par_state)->builtin_long;
}
else
{
int shift;
if (sizeof (ULONGEST) * HOST_CHAR_BIT
- < gdbarch_long_long_bit (parse_gdbarch))
+ < gdbarch_long_long_bit (parse_gdbarch (par_state)))
/* 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 (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
+ signed_type = parse_type (par_state)->builtin_long_long;
}
putithere->typed_val_int.val = n;
@@ -2069,7 +2080,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 *par_state)
{
int c;
int namelen;
@@ -2101,7 +2112,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 (par_state)->la_language != language_cplus)
break;
lexptr += 3;
@@ -2114,7 +2125,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 (par_state)->la_language != language_cplus)
break;
lexptr += 2;
@@ -2236,7 +2247,8 @@ lex_one_token (void)
&& (*p < 'A' || *p > 'Z')))
break;
}
- toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
+ toktype = parse_number (par_state, tokstart, p - tokstart,
+ got_dot|got_e, &yylval);
if (toktype == ERROR)
{
char *err_copy = (char *) alloca (p - tokstart + 1);
@@ -2388,7 +2400,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 (par_state)->la_language != language_cplus)
break;
/* It is ok to always set this, even though we don't always
@@ -2430,7 +2442,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 *par_state, struct block *block)
{
struct symbol *sym;
char *copy;
@@ -2439,7 +2451,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 (par_state)->la_language == language_cplus
? &is_a_field_of_this : (int *) NULL);
if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
@@ -2468,8 +2480,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 (par_state),
+ parse_gdbarch (par_state), copy);
if (yylval.tsym.type != NULL)
return TYPENAME;
@@ -2481,7 +2493,8 @@ 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 (par_state, copy, yylval.sval.length,
+ 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym = sym;
@@ -2495,7 +2508,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 (par_state)->la_language == language_cplus
&& !is_a_field_of_this
&& !lookup_minimal_symbol (copy, NULL, NULL))
return UNKNOWN_CPP_NAME;
@@ -2509,13 +2522,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 *par_state, struct block *block,
+ int first_name)
{
struct type *type, *new_type;
char *copy;
if (first_name)
- return classify_name (block);
+ return classify_name (par_state, block);
type = check_typedef (yylval.tsym.type);
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
@@ -2561,10 +2575,10 @@ yylex (void)
}
popping = 0;
- current.token = lex_one_token ();
+ current.token = lex_one_token (pstate);
if (current.token == NAME)
- current.token = classify_name (expression_context_block);
- if (parse_language->la_language != language_cplus
+ current.token = classify_name (pstate, expression_context_block);
+ if (parse_language (pstate)->la_language != language_cplus
|| (current.token != TYPENAME && current.token != COLONCOLON))
return current.token;
@@ -2579,14 +2593,14 @@ yylex (void)
{
token_and_value next;
- next.token = lex_one_token ();
+ next.token = lex_one_token (pstate);
next.value = yylval;
if (next.token == NAME && last_was_coloncolon)
{
int classification;
- classification = classify_inner_name (first_was_coloncolon
+ classification = classify_inner_name (pstate, first_was_coloncolon
? NULL
: expression_context_block,
first_iter);
@@ -2651,11 +2665,16 @@ yylex (void)
}
int
-c_parse (void)
+c_parse (struct parser_state *par_state)
{
int result;
- struct cleanup *back_to = make_cleanup (free_current_contents,
- &expression_macro_scope);
+ struct cleanup *back_to;
+
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ back_to = make_cleanup (free_current_contents, &expression_macro_scope);
/* Set up the scope for macro expansion. */
expression_macro_scope = NULL;
@@ -2685,7 +2704,7 @@ c_parse (void)
obstack_init (&name_obstack);
make_cleanup_obstack_free (&name_obstack);
- result = yyparse ();
+ result = _c_parse ();
do_cleanups (back_to);
return result;
}
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index 5cbe34d..be01561 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,7 +58,7 @@ 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 *);
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 04/10] Ada language.
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (2 preceding siblings ...)
2012-06-02 19:34 ` [PATCH 03/10] C language Sergio Durigan Junior
@ 2012-06-02 20:23 ` Sergio Durigan Junior
2012-06-13 4:57 ` Sergio Durigan Junior
2012-06-02 20:23 ` [PATCH 10/10] Go programming language Sergio Durigan Junior
` (6 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:23 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Ada language. This one is a bit different than the other
patches because it uses its own lexer, so I had to hack it too.
---
gdb/ada-exp.y | 474 +++++++++++++++++++++++++++++---------------------------
gdb/ada-lang.c | 4 +-
gdb/ada-lang.h | 3 +-
gdb/ada-lex.l | 54 ++++---
4 files changed, 282 insertions(+), 253 deletions(-)
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 1a80b0b..3c62187 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,6 +114,11 @@ struct name_info {
struct stoken stoken;
};
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
static struct stoken empty_stoken = { "", 0 };
/* If expression is in the context of TYPE'(...), then TYPE, else
@@ -128,40 +133,44 @@ void yyerror (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 *);
%}
@@ -237,25 +246,25 @@ start : exp1
/* Expressions, including the sequencing operator. */
exp1 : exp
| exp1 ';' exp
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
| primary ASSIGN exp /* Extension for convenience */
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
;
/* Expressions, not including the sequencing operator. */
primary : primary DOT_ALL
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
primary : primary DOT_ID
- { write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
+ { write_exp_op_with_string (pstate, 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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
}
| var_or_type '(' arglist ')'
{
@@ -263,15 +272,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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, UNOP_CAST);
}
else
{
- write_exp_elt_opcode (OP_FUNCALL);
- write_exp_elt_longcst ($3);
- write_exp_elt_opcode (OP_FUNCALL);
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
}
}
;
@@ -281,9 +290,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 (pstate, UNOP_QUAL);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, UNOP_QUAL);
type_qualifier = $3;
}
;
@@ -293,10 +302,10 @@ save_qualifier : { $$ = type_qualifier; }
primary :
primary '(' simple_exp DOTDOT simple_exp ')'
- { write_exp_elt_opcode (TERNOP_SLICE); }
+ { write_exp_elt_opcode (pstate, TERNOP_SLICE); }
| var_or_type '(' simple_exp DOTDOT simple_exp ')'
{ if ($1 == NULL)
- write_exp_elt_opcode (TERNOP_SLICE);
+ write_exp_elt_opcode (pstate, TERNOP_SLICE);
else
error (_("Cannot slice a type"));
}
@@ -316,15 +325,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);
}
}
;
primary : SPECIAL_VARIABLE /* Various GDB extensions */
- { write_dollar_variable ($1); }
+ { write_dollar_variable (pstate, $1); }
;
primary : aggregate
@@ -334,19 +343,19 @@ simple_exp : primary
;
simple_exp : '-' simple_exp %prec UNARY
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
;
simple_exp : '+' simple_exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PLUS); }
+ { write_exp_elt_opcode (pstate, UNOP_PLUS); }
;
simple_exp : NOT simple_exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
simple_exp : ABS simple_exp %prec UNARY
- { write_exp_elt_opcode (UNOP_ABS); }
+ { write_exp_elt_opcode (pstate, UNOP_ABS); }
;
arglist : { $$ = 0; }
@@ -367,111 +376,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 (pstate, UNOP_MEMVAL);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, BINOP_EXP); }
;
simple_exp : simple_exp '*' simple_exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
simple_exp : simple_exp '/' simple_exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_REM); }
;
simple_exp : simple_exp MOD simple_exp
- { write_exp_elt_opcode (BINOP_MOD); }
+ { write_exp_elt_opcode (pstate, BINOP_MOD); }
;
simple_exp : simple_exp '@' simple_exp /* GDB extension */
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
simple_exp : simple_exp '+' simple_exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
simple_exp : simple_exp '&' simple_exp
- { write_exp_elt_opcode (BINOP_CONCAT); }
+ { write_exp_elt_opcode (pstate, BINOP_CONCAT); }
;
simple_exp : simple_exp '-' simple_exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
relation : simple_exp
;
relation : simple_exp '=' simple_exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
relation : simple_exp NOTEQUAL simple_exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
relation : simple_exp LEQ simple_exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
relation : simple_exp IN simple_exp DOTDOT simple_exp
- { write_exp_elt_opcode (TERNOP_IN_RANGE); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_IN_BOUNDS);
+ write_exp_elt_longcst (pstate, (LONGEST) $5);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_IN_RANGE);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, TERNOP_IN_RANGE);
+ write_exp_elt_opcode (pstate, 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 (pstate, BINOP_IN_BOUNDS);
+ write_exp_elt_longcst (pstate, (LONGEST) $6);
+ write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_IN_RANGE);
+ write_exp_elt_type (pstate, $4);
+ write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
+ write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT);
}
;
relation : simple_exp GEQ simple_exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
relation : simple_exp '<' simple_exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
relation : simple_exp '>' simple_exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : relation
@@ -484,36 +493,36 @@ exp : relation
and_exp :
relation _AND_ relation
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
| and_exp _AND_ relation
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
and_then_exp :
relation _AND_ THEN relation
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
| and_then_exp _AND_ THEN relation
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
or_exp :
relation OR relation
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
| or_exp OR relation
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
or_else_exp :
relation OR ELSE relation
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
| or_else_exp OR ELSE relation
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
xor_exp : relation XOR relation
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
| xor_exp XOR relation
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
/* Primaries can denote types (OP_TYPE). In cases such as
@@ -525,36 +534,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 (pstate, 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 (pstate, UNOP_ADDR);
+ write_exp_elt_opcode (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, type_system_address (pstate));
+ write_exp_elt_opcode (pstate, UNOP_CAST);
}
| primary TICK_FIRST tick_arglist
- { write_int ($3, type_int ());
- write_exp_elt_opcode (OP_ATR_FIRST); }
+ { write_int (pstate, $3, type_int (pstate));
+ write_exp_elt_opcode (pstate, OP_ATR_FIRST); }
| primary TICK_LAST tick_arglist
- { write_int ($3, type_int ());
- write_exp_elt_opcode (OP_ATR_LAST); }
+ { write_int (pstate, $3, type_int (pstate));
+ write_exp_elt_opcode (pstate, OP_ATR_LAST); }
| primary TICK_LENGTH tick_arglist
- { write_int ($3, type_int ());
- write_exp_elt_opcode (OP_ATR_LENGTH); }
+ { write_int (pstate, $3, type_int (pstate));
+ write_exp_elt_opcode (pstate, OP_ATR_LENGTH); }
| primary TICK_SIZE
- { write_exp_elt_opcode (OP_ATR_SIZE); }
+ { write_exp_elt_opcode (pstate, OP_ATR_SIZE); }
| primary TICK_TAG
- { write_exp_elt_opcode (OP_ATR_TAG); }
+ { write_exp_elt_opcode (pstate, OP_ATR_TAG); }
| opt_type_prefix TICK_MIN '(' exp ',' exp ')'
- { write_exp_elt_opcode (OP_ATR_MIN); }
+ { write_exp_elt_opcode (pstate, OP_ATR_MIN); }
| opt_type_prefix TICK_MAX '(' exp ',' exp ')'
- { write_exp_elt_opcode (OP_ATR_MAX); }
+ { write_exp_elt_opcode (pstate, OP_ATR_MAX); }
| opt_type_prefix TICK_POS '(' exp ')'
- { write_exp_elt_opcode (OP_ATR_POS); }
+ { write_exp_elt_opcode (pstate, OP_ATR_POS); }
| type_prefix TICK_VAL '(' exp ')'
- { write_exp_elt_opcode (OP_ATR_VAL); }
+ { write_exp_elt_opcode (pstate, OP_ATR_VAL); }
| type_prefix TICK_MODULUS
- { write_exp_elt_opcode (OP_ATR_MODULUS); }
+ { write_exp_elt_opcode (pstate, OP_ATR_MODULUS); }
;
tick_arglist : %prec '('
@@ -568,53 +577,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate,
+ parse_type (pstate)->builtin_void);
+ write_exp_elt_opcode (pstate, OP_TYPE); }
;
primary : INT
- { write_int ((LONGEST) $1.val, $1.type); }
+ { write_int (pstate, (LONGEST) $1.val, $1.type); }
;
primary : CHARLIT
- { write_int (convert_char_literal (type_qualifier, $1.val),
+ { write_int (pstate,
+ 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, OP_DOUBLE);
}
;
primary : NULL_PTR
- { write_int (0, type_int ()); }
+ { write_int (pstate, 0, type_int (pstate)); }
;
primary : STRING
{
- write_exp_op_with_string (OP_STRING, $1);
+ write_exp_op_with_string (pstate, OP_STRING, $1);
}
;
primary : TRUEKEYWORD
- { write_int (1, type_boolean ()); }
+ { write_int (pstate, 1, type_boolean (pstate)); }
| FALSEKEYWORD
- { write_int (0, type_boolean ()); }
+ { write_int (pstate, 0, type_boolean (pstate)); }
;
primary : NEW NAME
@@ -622,22 +633,22 @@ primary : NEW NAME
;
var_or_type: NAME %prec VAR
- { $$ = write_var_or_type (NULL, $1); }
+ { $$ = write_var_or_type (pstate, NULL, $1); }
| block NAME %prec VAR
- { $$ = write_var_or_type ($1, $2); }
+ { $$ = write_var_or_type (pstate, $1, $2); }
| NAME TICK_ACCESS
{
- $$ = write_var_or_type (NULL, $1);
+ $$ = write_var_or_type (pstate, NULL, $1);
if ($$ == NULL)
- write_exp_elt_opcode (UNOP_ADDR);
+ write_exp_elt_opcode (pstate, UNOP_ADDR);
else
$$ = lookup_pointer_type ($$);
}
| block NAME TICK_ACCESS
{
- $$ = write_var_or_type ($1, $2);
+ $$ = write_var_or_type (pstate, $1, $2);
if ($$ == NULL)
- write_exp_elt_opcode (UNOP_ADDR);
+ write_exp_elt_opcode (pstate, UNOP_ADDR);
else
$$ = lookup_pointer_type ($$);
}
@@ -653,18 +664,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 (pstate, OP_AGGREGATE);
+ write_exp_elt_longcst (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_POSITIONAL);
+ write_exp_elt_longcst (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_POSITIONAL);
$$ = $1 + 1;
}
| positional_list component_groups
@@ -673,15 +684,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 (pstate, OP_POSITIONAL);
+ write_exp_elt_longcst (pstate, 0);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_POSITIONAL);
+ write_exp_elt_longcst (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_POSITIONAL);
$$ = $1 + 1;
}
;
@@ -694,15 +705,15 @@ component_groups:
;
others : OTHERS ARROW exp
- { write_exp_elt_opcode (OP_OTHERS); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, OP_CHOICES);
+ write_exp_elt_longcst (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_CHOICES);
}
;
@@ -713,22 +724,22 @@ component_group :
resolved shift/reduce conflict. */
component_associations :
NAME ARROW
- { write_name_assoc ($1); }
+ { write_name_assoc (pstate, $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 (pstate, OP_DISCRETE_RANGE);
+ write_exp_op_with_string (pstate, OP_NAME, empty_stoken);
}
exp { $$ = 1; }
| NAME '|'
- { write_name_assoc ($1); }
+ { write_name_assoc (pstate, $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 (pstate, OP_DISCRETE_RANGE); }
component_associations { $$ = $6 + 1; }
;
@@ -736,11 +747,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 (pstate, UNOP_IND); }
| '&' primary %prec '.'
- { write_exp_elt_opcode (UNOP_ADDR); }
+ { write_exp_elt_opcode (pstate, UNOP_ADDR); }
| primary '[' exp ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
%%
@@ -771,8 +782,12 @@ static struct obstack temp_parse_space;
#include "ada-lex.c"
int
-ada_parse (void)
+ada_parse (struct parser_state *par_state)
{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
lexer_init (yyin); /* (Re-)initialize lexer. */
type_qualifier = NULL;
obstack_free (&temp_parse_space, NULL);
@@ -818,7 +833,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 *par_state,
+ struct block *orig_left_context,
struct block *block,
struct symbol *sym)
{
@@ -829,30 +845,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 (par_state, OP_VAR_VALUE);
+ write_exp_elt_block (par_state, block);
+ write_exp_elt_sym (par_state, sym);
+ write_exp_elt_opcode (par_state, 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 *par_state, 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 (par_state, OP_LONG);
+ write_exp_elt_type (par_state, type);
+ write_exp_elt_longcst (par_state, arg);
+ write_exp_elt_opcode (par_state, 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 *par_state,
+ 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 (par_state, opcode);
+ write_exp_string (par_state, token);
+ write_exp_elt_opcode (par_state, opcode);
}
/* Emit expression corresponding to the renamed object named
@@ -867,7 +884,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 *par_state,
+ struct block *orig_left_context,
const char *renamed_entity, int renamed_entity_len,
const char *renaming_expr, int max_depth)
{
@@ -900,10 +918,11 @@ write_object_renaming (struct block *orig_left_context,
&inner_renaming_expr))
{
case ADA_NOT_RENAMING:
- write_var_from_sym (orig_left_context, sym_info.block, sym_info.sym);
+ write_var_from_sym (par_state, orig_left_context, sym_info.block,
+ sym_info.sym);
break;
case ADA_OBJECT_RENAMING:
- write_object_renaming (sym_info.block,
+ write_object_renaming (par_state, sym_info.block,
inner_renamed_entity, inner_renamed_entity_len,
inner_renaming_expr, max_depth - 1);
break;
@@ -920,7 +939,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 (par_state, UNOP_IND);
break;
case 'L':
slice_state = LOWER_BOUND;
@@ -934,10 +953,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 (par_state, OP_LONG);
+ write_exp_elt_type (par_state, type_int (par_state));
+ write_exp_elt_longcst (par_state, (LONGEST) val);
+ write_exp_elt_opcode (par_state, OP_LONG);
}
else
{
@@ -961,20 +980,20 @@ write_object_renaming (struct block *orig_left_context,
else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF)
/* Index is an old-style renaming symbol. */
index_sym_info.block = orig_left_context;
- write_var_from_sym (NULL, index_sym_info.block,
+ write_var_from_sym (par_state, NULL, index_sym_info.block,
index_sym_info.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 (par_state, OP_FUNCALL);
+ write_exp_elt_longcst (par_state, (LONGEST) 1);
+ write_exp_elt_opcode (par_state, 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 (par_state, TERNOP_SLICE);
slice_state = SIMPLE_INDEX;
}
break;
@@ -995,7 +1014,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 (par_state, STRUCTOP_STRUCT, field_name);
break;
}
@@ -1084,14 +1103,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 *par_state, 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 (par_state),
+ parse_gdbarch (par_state),
name);
if (type == NULL && strcmp ("system__address", name) == 0)
- type = type_system_address ();
+ type = type_system_address (par_state);
if (type != NULL)
{
@@ -1140,7 +1159,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 *par_state, char *sels)
{
while (*sels != '\0')
{
@@ -1152,7 +1171,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 (par_state, STRUCTOP_STRUCT, field_name);
}
}
@@ -1161,7 +1180,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 *par_state, struct block *block,
+ char *name, int len)
{
struct symbol *sym =
obstack_alloc (&temp_parse_space, sizeof (struct symbol));
@@ -1170,10 +1190,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 (par_state, OP_VAR_VALUE);
+ write_exp_elt_block (par_state, block);
+ write_exp_elt_sym (par_state, sym);
+ write_exp_elt_opcode (par_state, OP_VAR_VALUE);
}
/* A convenient wrapper around ada_get_field_index that takes
@@ -1253,7 +1273,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 *par_state, struct block *block,
+ struct stoken name0)
{
int depth;
char *encoded_name;
@@ -1327,9 +1348,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 (par_state, block, renaming, renaming_len,
renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
- write_selectors (encoded_name + tail_index);
+ write_selectors (par_state, encoded_name + tail_index);
return NULL;
default:
internal_error (__FILE__, __LINE__,
@@ -1356,7 +1377,8 @@ 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 (par_state,
+ encoded_name);
if (type != NULL)
return type;
@@ -1364,8 +1386,9 @@ 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 (par_state, block, syms[0].block,
+ syms[0].sym);
+ write_selectors (par_state, encoded_name + tail_index);
return NULL;
}
else if (nsyms == 0)
@@ -1374,9 +1397,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 (par_state, msym);
/* Maybe cause error here rather than later? FIXME? */
- write_selectors (encoded_name + tail_index);
+ write_selectors (par_state, encoded_name + tail_index);
return NULL;
}
@@ -1389,8 +1412,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 (par_state, block, encoded_name, tail_index);
+ write_selectors (par_state, encoded_name + tail_index);
return NULL;
}
}
@@ -1425,7 +1448,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 *par_state, struct stoken name)
{
if (strchr (name.ptr, '.') == NULL)
{
@@ -1433,12 +1456,12 @@ write_name_assoc (struct stoken name)
int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
VAR_DOMAIN, &syms, 1);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
- write_exp_op_with_string (OP_NAME, name);
+ write_exp_op_with_string (par_state, OP_NAME, name);
else
- write_var_from_sym (NULL, syms[0].block, syms[0].sym);
+ write_var_from_sym (par_state, NULL, syms[0].block, syms[0].sym);
}
else
- if (write_var_or_type (NULL, name) != NULL)
+ if (write_var_or_type (par_state, NULL, name) != NULL)
error (_("Invalid use of type."));
}
@@ -1469,61 +1492,62 @@ convert_char_literal (struct type *type, LONGEST val)
}
static struct type *
-type_int (void)
+type_int (struct parser_state *par_state)
{
- return parse_type->builtin_int;
+ return parse_type (par_state)->builtin_int;
}
static struct type *
-type_long (void)
+type_long (struct parser_state *par_state)
{
- return parse_type->builtin_long;
+ return parse_type (par_state)->builtin_long;
}
static struct type *
-type_long_long (void)
+type_long_long (struct parser_state *par_state)
{
- return parse_type->builtin_long_long;
+ return parse_type (par_state)->builtin_long_long;
}
static struct type *
-type_float (void)
+type_float (struct parser_state *par_state)
{
- return parse_type->builtin_float;
+ return parse_type (par_state)->builtin_float;
}
static struct type *
-type_double (void)
+type_double (struct parser_state *par_state)
{
- return parse_type->builtin_double;
+ return parse_type (par_state)->builtin_double;
}
static struct type *
-type_long_double (void)
+type_long_double (struct parser_state *par_state)
{
- return parse_type->builtin_long_double;
+ return parse_type (par_state)->builtin_long_double;
}
static struct type *
-type_char (void)
+type_char (struct parser_state *par_state)
{
- return language_string_char_type (parse_language, parse_gdbarch);
+ return language_string_char_type (parse_language (par_state),
+ parse_gdbarch (par_state));
}
static struct type *
-type_boolean (void)
+type_boolean (struct parser_state *par_state)
{
- return parse_type->builtin_bool;
+ return parse_type (par_state)->builtin_bool;
}
static struct type *
-type_system_address (void)
+type_system_address (struct parser_state *par_state)
{
struct type *type
- = language_lookup_primitive_type_by_name (parse_language,
- parse_gdbarch,
+ = language_lookup_primitive_type_by_name (parse_language (par_state),
+ parse_gdbarch (par_state),
"system__address");
- return type != NULL ? type : parse_type->builtin_data_ptr;
+ return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
}
/* Provide a prototype to silence -Wmissing-prototypes. */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index af0fdb5..a6308cf 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12464,10 +12464,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 9a93c50..1b172d4 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"
@@ -157,7 +158,7 @@ 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 */
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 714265e..f0e2369 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -49,8 +49,9 @@ 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 *);
@@ -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 (pstate, NULL, numbuf,
+ strrchr (numbuf, 'e') + 1);
}
{NUM10} {
canonicalizeNumeral (numbuf, yytext);
- return processInt (NULL, numbuf, NULL);
+ return processInt (pstate, NULL, numbuf, NULL);
}
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} {
canonicalizeNumeral (numbuf, yytext);
- return processInt (numbuf,
+ return processInt (pstate, numbuf,
strchr (numbuf, '#') + 1,
strrchr(numbuf, '#') + 1);
}
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
canonicalizeNumeral (numbuf, yytext);
- return processInt (numbuf, strchr (numbuf, '#') + 1, NULL);
+ return processInt (pstate, numbuf, strchr (numbuf, '#') + 1,
+ NULL);
}
"0x"{HEXDIG}+ {
canonicalizeNumeral (numbuf, yytext+2);
- return processInt ("16#", numbuf, NULL);
+ return processInt (pstate, "16#", numbuf, NULL);
}
{NUM10}"."{NUM10}{EXP} {
canonicalizeNumeral (numbuf, yytext);
- return processReal (numbuf);
+ return processReal (pstate, numbuf);
}
{NUM10}"."{NUM10} {
canonicalizeNumeral (numbuf, yytext);
- return processReal (numbuf);
+ return processReal (pstate, 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 (pstate);
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 (pstate);
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 *par_state, 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 (par_state))-1)) == 0)
+ yylval.typed_val.type = type_int (par_state);
+ else if ((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-1)) == 0)
+ yylval.typed_val.type = type_long (par_state);
+ else if (((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-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 (par_state))->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 (par_state);
yylval.typed_val.val = (LONGEST) result;
return INT;
}
static int
-processReal (const char *num0)
+processReal (struct parser_state *par_state, 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 (par_state);
+ if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch (par_state))
/ 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 (par_state);
+ if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch (par_state))
/ TARGET_CHAR_BIT)
- yylval.typed_val_float.type = type_long_double ();
+ yylval.typed_val_float.type = type_long_double (par_state);
return FLOAT;
}
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 10/10] Go programming language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (3 preceding siblings ...)
2012-06-02 20:23 ` [PATCH 04/10] Ada language Sergio Durigan Junior
@ 2012-06-02 20:23 ` Sergio Durigan Junior
2012-06-13 4:58 ` Sergio Durigan Junior
2012-06-02 20:24 ` [PATCH 05/10] Fortran language Sergio Durigan Junior
` (5 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:23 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Go programming language. Similar to the C language one.
---
gdb/go-exp.y | 268 +++++++++++++++++++++++++++++++--------------------------
gdb/go-lang.h | 4 +-
2 files changed, 148 insertions(+), 124 deletions(-)
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index c3171c3..7e02283 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -66,7 +66,7 @@
#include "charset.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
@@ -76,7 +76,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth go_maxdepth
-#define yyparse go_parse_internal
+#define yyparse _go_parse
#define yylex go_lex
#define yyerror go_error
#define yylval go_lval
@@ -122,6 +122,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -158,7 +163,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 *);
static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
DOUBLEST *d, struct type **t);
%}
@@ -239,77 +244,77 @@ 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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE); }
;
/* Expressions, including the comma operator. */
exp1 : exp
| exp1 ',' exp
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
;
/* Expressions, not including the comma operator. */
exp : '*' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
exp : '&' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_ADDR); }
+ { write_exp_elt_opcode (pstate, UNOP_ADDR); }
;
exp : '-' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
;
exp : '+' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PLUS); }
+ { write_exp_elt_opcode (pstate, UNOP_PLUS); }
;
exp : '!' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
exp : '^' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_COMPLEMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
;
exp : exp INCREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
;
exp : exp DECREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
;
/* foo->bar is not in Go. May want as a gdb extension. Later. */
exp : exp '.' name_not_typename
- { write_exp_elt_opcode (STRUCTOP_STRUCT);
- write_exp_string ($3.stoken);
- write_exp_elt_opcode (STRUCTOP_STRUCT); }
+ { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3.stoken);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : exp '.' name_not_typename COMPLETE
- { mark_struct_expression ();
- write_exp_elt_opcode (STRUCTOP_STRUCT);
- write_exp_string ($3.stoken);
- write_exp_elt_opcode (STRUCTOP_STRUCT); }
+ { mark_struct_expression (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3.stoken);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : exp '.' COMPLETE
{ struct stoken s;
- mark_struct_expression ();
- write_exp_elt_opcode (STRUCTOP_STRUCT);
+ mark_struct_expression (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
s.ptr = "";
s.length = 0;
- write_exp_string (s);
- write_exp_elt_opcode (STRUCTOP_STRUCT); }
+ write_exp_string (pstate, s);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : exp '[' exp1 ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
exp : exp '('
@@ -317,9 +322,10 @@ exp : exp '('
being accumulated by an outer function call. */
{ start_arglist (); }
arglist ')' %prec LEFT_ARROW
- { write_exp_elt_opcode (OP_FUNCALL);
- write_exp_elt_longcst ((LONGEST) end_arglist ());
- write_exp_elt_opcode (OP_FUNCALL); }
+ { write_exp_elt_opcode (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate,
+ (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
;
lcurly : '{'
@@ -342,15 +348,15 @@ rcurly : '}'
;
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 (pstate, UNOP_MEMVAL);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
exp : '(' exp1 ')'
@@ -360,100 +366,100 @@ exp : '(' exp1 ')'
/* Binary operators in order of decreasing precedence. */
exp : exp '@' exp
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
;
exp : exp '%' exp
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp LSH exp
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
;
exp : exp RSH exp
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
;
exp : exp EQUAL exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : exp '&' exp
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
exp : exp '^' exp
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
exp : exp '|' exp
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
exp : exp ANDAND exp
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
exp : exp OROR exp
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
exp : exp '?' exp ':' exp %prec '?'
- { write_exp_elt_opcode (TERNOP_COND); }
+ { write_exp_elt_opcode (pstate, TERNOP_COND); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_longcst (pstate, (LONGEST)($1.val));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : CHAR
@@ -461,28 +467,28 @@ exp : CHAR
struct stoken_vector vec;
vec.len = 1;
vec.tokens = &$1;
- write_exp_string_vector ($1.type, &vec);
+ write_exp_string_vector (pstate, $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)
+ parse_number (pstate, $1.stoken.ptr,
+ $1.stoken.length, 0, &val);
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val_int.type);
+ write_exp_elt_longcst (pstate, (LONGEST)
val.typed_val_int.val);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, OP_DOUBLE); }
;
exp : variable
@@ -490,26 +496,29 @@ exp : variable
exp : DOLLAR_VARIABLE
{
- write_dollar_variable ($1);
+ write_dollar_variable (pstate, $1);
}
;
exp : SIZEOF_KEYWORD '(' type ')' %prec UNARY
{
/* TODO(dje): Go objects in structs. */
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (pstate, OP_LONG);
/* TODO(dje): What's the right type here? */
- write_exp_elt_type (parse_type->builtin_unsigned_int);
+ write_exp_elt_type
+ (pstate,
+ parse_type (pstate)->builtin_unsigned_int);
CHECK_TYPEDEF ($3);
- write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_longcst (pstate,
+ (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, OP_LONG);
}
;
exp : SIZEOF_KEYWORD '(' exp ')' %prec UNARY
{
/* TODO(dje): Go objects in structs. */
- write_exp_elt_opcode (UNOP_SIZEOF);
+ write_exp_elt_opcode (pstate, UNOP_SIZEOF);
}
string_exp:
@@ -552,7 +561,8 @@ exp : string_exp %prec ABOVE_COMMA
{
int i;
- write_exp_string_vector (0 /*always utf8*/, &$1);
+ write_exp_string_vector (pstate, 0 /*always utf8*/,
+ &$1);
for (i = 0; i < $1.len; ++i)
free ($1.tokens[i].ptr);
free ($1.tokens);
@@ -560,15 +570,15 @@ exp : string_exp %prec ABOVE_COMMA
;
exp : TRUE_KEYWORD
- { write_exp_elt_opcode (OP_BOOL);
- write_exp_elt_longcst ((LONGEST) $1);
- write_exp_elt_opcode (OP_BOOL); }
+ { write_exp_elt_opcode (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, OP_BOOL); }
;
exp : FALSE_KEYWORD
- { write_exp_elt_opcode (OP_BOOL);
- write_exp_elt_longcst ((LONGEST) $1);
- write_exp_elt_opcode (OP_BOOL); }
+ { write_exp_elt_opcode (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, OP_BOOL); }
;
variable: name_not_typename ENTRY
@@ -581,9 +591,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 (pstate, OP_VAR_ENTRY_VALUE);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
}
;
@@ -600,13 +610,13 @@ variable: name_not_typename
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
}
else if ($1.is_a_field_of_this)
{
@@ -622,7 +632,7 @@ variable: name_not_typename
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
&& !have_partial_symbols ())
error (_("No symbol table is loaded. "
@@ -652,7 +662,7 @@ type /* Implements (approximately): [*] type-specifier */
expression_context_block); }
*/
| BYTE_KEYWORD
- { $$ = builtin_go_type (parse_gdbarch)
+ { $$ = builtin_go_type (parse_gdbarch (pstate))
->builtin_uint8; }
;
@@ -704,7 +714,8 @@ parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
as our YYSTYPE is different than c-exp.y's */
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (struct parser_state *par_state, 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. */
@@ -729,7 +740,7 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
if (parsed_float)
{
- if (! parse_go_float (parse_gdbarch, p, len,
+ if (! parse_go_float (parse_gdbarch (par_state), p, len,
&putithere->typed_val_float.dval,
&putithere->typed_val_float.type))
return ERROR;
@@ -845,9 +856,10 @@ 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 (par_state)) - 2)) == 0)
{
- high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+ high_bit
+ = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
/* A large decimal (not hex or octal) constant (between INT_MAX
and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -855,28 +867,29 @@ 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 (par_state)->builtin_unsigned_int;
+ signed_type = parse_type (par_state)->builtin_int;
}
else if (long_p <= 1
- && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+ && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_long;
+ signed_type = parse_type (par_state)->builtin_long;
}
else
{
int shift;
if (sizeof (ULONGEST) * HOST_CHAR_BIT
- < gdbarch_long_long_bit (parse_gdbarch))
+ < gdbarch_long_long_bit (parse_gdbarch (par_state)))
/* 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 (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
+ signed_type = parse_type (par_state)->builtin_long_long;
}
putithere->typed_val_int.val = n;
@@ -1044,7 +1057,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 *par_state)
{
int c;
int namelen;
@@ -1175,7 +1188,8 @@ lex_one_token (void)
&& (*p < 'A' || *p > 'Z')))
break;
}
- toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
+ toktype = parse_number (par_state, tokstart, p - tokstart,
+ got_dot|got_e, &yylval);
if (toktype == ERROR)
{
char *err_copy = (char *) alloca (p - tokstart + 1);
@@ -1430,7 +1444,7 @@ classify_packaged_name (struct block *block)
The result is one of NAME, NAME_OR_INT, or TYPENAME. */
static int
-classify_name (struct block *block)
+classify_name (struct parser_state *par_state, struct block *block)
{
struct type *type;
struct symbol *sym;
@@ -1440,8 +1454,9 @@ classify_name (struct block *block)
copy = copy_name (yylval.sval);
/* Try primitive types first so they win over bad/weird debug info. */
- type = language_lookup_primitive_type_by_name (parse_language,
- parse_gdbarch, copy);
+ type = language_lookup_primitive_type_by_name (parse_language (par_state),
+ parse_gdbarch (par_state),
+ copy);
if (type != NULL)
{
/* NOTE: We take advantage of the fact that yylval coming in was a
@@ -1497,7 +1512,8 @@ 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 (par_state, copy, yylval.sval.length,
+ 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym = NULL;
@@ -1530,7 +1546,7 @@ yylex (void)
}
popping = 0;
- current.token = lex_one_token ();
+ current.token = lex_one_token (pstate);
/* TODO: Need a way to force specifying name1 as a package.
.name1.name2 ? */
@@ -1541,14 +1557,14 @@ yylex (void)
/* See if we have "name1 . name2". */
current.value = yylval;
- next.token = lex_one_token ();
+ next.token = lex_one_token (pstate);
next.value = yylval;
if (next.token == '.')
{
token_and_value name2;
- name2.token = lex_one_token ();
+ name2.token = lex_one_token (pstate);
name2.value = yylval;
if (name2.token == NAME)
@@ -1587,14 +1603,20 @@ yylex (void)
popping = 1;
yylval = current.value;
- return classify_name (expression_context_block);
+ return classify_name (pstate, expression_context_block);
}
int
-go_parse (void)
+go_parse (struct parser_state *par_state)
{
int result;
- struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+ struct cleanup *back_to;
+
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ back_to = make_cleanup (null_cleanup, NULL);
make_cleanup_restore_integer (&yydebug);
yydebug = parser_debug;
diff --git a/gdb/go-lang.h b/gdb/go-lang.h
index 67b5d93..2be37b2 100644
--- a/gdb/go-lang.h
+++ b/gdb/go-lang.h
@@ -24,6 +24,8 @@
#include "symtab.h"
#include "value.h"
+struct parser_state;
+
struct builtin_go_type
{
struct type *builtin_void;
@@ -54,7 +56,7 @@ enum go_type
/* Defined in go-exp.y. */
-extern int go_parse (void);
+extern int go_parse (struct parser_state *);
extern void go_error (char *);
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 05/10] Fortran language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (4 preceding siblings ...)
2012-06-02 20:23 ` [PATCH 10/10] Go programming language Sergio Durigan Junior
@ 2012-06-02 20:24 ` Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-02 20:24 ` [PATCH 08/10] Objective-C language Sergio Durigan Junior
` (4 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:24 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Fortran language. This patch is similiar to the C
language one.
---
gdb/f-exp.y | 261 ++++++++++++++++++++++++++++++++--------------------------
gdb/f-lang.h | 6 +-
2 files changed, 148 insertions(+), 119 deletions(-)
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 33c7418..832b0b8 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
@@ -66,7 +66,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth f_maxdepth
-#define yyparse f_parse
+#define yyparse _f_parse
#define yylex f_lex
#define yyerror f_error
#define yylval f_lval
@@ -118,6 +118,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -158,7 +163,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
@@ -240,9 +245,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE); }
;
exp : '(' exp ')'
@@ -251,27 +256,27 @@ exp : '(' exp ')'
/* Expressions, not including the comma operator. */
exp : '*' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
exp : '&' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_ADDR); }
+ { write_exp_elt_opcode (pstate, UNOP_ADDR); }
;
exp : '-' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
;
exp : BOOL_NOT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
exp : '~' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_COMPLEMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
;
exp : SIZEOF exp %prec UNARY
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
;
/* No more explicit array operators, we treat everything in F77 as
@@ -282,9 +287,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 (pstate, OP_F77_UNDETERMINED_ARGLIST);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_F77_UNDETERMINED_ARGLIST); }
;
arglist :
@@ -305,27 +310,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 (pstate, OP_F90_RANGE);
+ write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
+ write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
+ write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
+ write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
+ write_exp_elt_opcode (pstate, OP_F90_RANGE); }
;
complexnum: exp ',' exp
@@ -333,133 +338,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 (pstate, OP_COMPLEX);
+ write_exp_elt_type (pstate,
+ parse_f_type (pstate)
+ ->builtin_complex_s16);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
/* Binary operators in order of decreasing precedence. */
exp : exp '@' exp
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
exp : exp STARSTAR exp
- { write_exp_elt_opcode (BINOP_EXP); }
+ { write_exp_elt_opcode (pstate, BINOP_EXP); }
;
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp LSH exp
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
;
exp : exp RSH exp
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
;
exp : exp EQUAL exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
exp : exp LESSTHAN exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
exp : exp GREATERTHAN exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : exp '&' exp
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
exp : exp '^' exp
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
exp : exp '|' exp
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
exp : exp BOOL_AND exp
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
exp : exp BOOL_OR exp
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
+ write_exp_elt_opcode (pstate, 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 (pstate, $1.stoken.ptr, $1.stoken.length,
+ 0, &val);
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val.type);
+ write_exp_elt_longcst (pstate, (LONGEST)val.typed_val.val);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate,
+ parse_f_type (pstate)
+ ->builtin_real_s8);
+ write_exp_elt_dblcst (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_DOUBLE); }
;
exp : variable
@@ -469,25 +479,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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_f_type (pstate)
+ ->builtin_integer);
CHECK_TYPEDEF ($3);
- write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
- write_exp_elt_opcode (OP_LONG); }
+ write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_STRING);
+ write_exp_string (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_STRING);
}
;
@@ -503,13 +515,13 @@ variable: name_not_typename
innermost_block))
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
break;
}
else
@@ -520,7 +532,7 @@ variable: name_not_typename
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
@@ -561,7 +573,8 @@ ptype : typebase
{
range_type =
create_range_type ((struct type *) NULL,
- parse_f_type->builtin_integer,
+ parse_f_type (pstate)
+ ->builtin_integer,
0, array_size - 1);
follow_type =
create_array_type ((struct type *) NULL,
@@ -607,31 +620,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */
: TYPENAME
{ $$ = $1.type; }
| INT_KEYWORD
- { $$ = parse_f_type->builtin_integer; }
+ { $$ = parse_f_type (pstate)->builtin_integer; }
| INT_S2_KEYWORD
- { $$ = parse_f_type->builtin_integer_s2; }
+ { $$ = parse_f_type (pstate)->builtin_integer_s2; }
| CHARACTER
- { $$ = parse_f_type->builtin_character; }
+ { $$ = parse_f_type (pstate)->builtin_character; }
| LOGICAL_S8_KEYWORD
- { $$ = parse_f_type->builtin_logical_s8; }
+ { $$ = parse_f_type (pstate)->builtin_logical_s8; }
| LOGICAL_KEYWORD
- { $$ = parse_f_type->builtin_logical; }
+ { $$ = parse_f_type (pstate)->builtin_logical; }
| LOGICAL_S2_KEYWORD
- { $$ = parse_f_type->builtin_logical_s2; }
+ { $$ = parse_f_type (pstate)->builtin_logical_s2; }
| LOGICAL_S1_KEYWORD
- { $$ = parse_f_type->builtin_logical_s1; }
+ { $$ = parse_f_type (pstate)->builtin_logical_s1; }
| REAL_KEYWORD
- { $$ = parse_f_type->builtin_real; }
+ { $$ = parse_f_type (pstate)->builtin_real; }
| REAL_S8_KEYWORD
- { $$ = parse_f_type->builtin_real_s8; }
+ { $$ = parse_f_type (pstate)->builtin_real_s8; }
| REAL_S16_KEYWORD
- { $$ = parse_f_type->builtin_real_s16; }
+ { $$ = parse_f_type (pstate)->builtin_real_s16; }
| COMPLEX_S8_KEYWORD
- { $$ = parse_f_type->builtin_complex_s8; }
+ { $$ = parse_f_type (pstate)->builtin_complex_s8; }
| COMPLEX_S16_KEYWORD
- { $$ = parse_f_type->builtin_complex_s16; }
+ { $$ = parse_f_type (pstate)->builtin_complex_s16; }
| COMPLEX_S32_KEYWORD
- { $$ = parse_f_type->builtin_complex_s32; }
+ { $$ = parse_f_type (pstate)->builtin_complex_s32; }
;
nonempty_typelist
@@ -670,7 +683,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 *par_state, char *p, int len,
+ int parsed_float, YYSTYPE *putithere)
{
LONGEST n = 0;
LONGEST prevn = 0;
@@ -776,20 +790,22 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *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 (par_state))
+ != gdbarch_long_bit (parse_gdbarch (par_state))
&& ((n >> 2)
- >> (gdbarch_int_bit (parse_gdbarch)-2))) /* Avoid shift warning */
+ >> (gdbarch_int_bit (parse_gdbarch (par_state))-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 (par_state))-1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_long;
+ signed_type = parse_type (par_state)->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 (par_state))-1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_int;
+ signed_type = parse_type (par_state)->builtin_int;
}
putithere->typed_val.val = n;
@@ -1091,7 +1107,8 @@ yylex (void)
&& (*p < 'A' || *p > 'Z')))
break;
}
- toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
+ toktype = parse_number (pstate, tokstart, p - tokstart,
+ got_dot|got_e|got_d,
&yylval);
if (toktype == ERROR)
{
@@ -1165,7 +1182,7 @@ yylex (void)
if (*tokstart == '$')
{
- write_dollar_variable (yylval.sval);
+ write_dollar_variable (pstate, yylval.sval);
return VARIABLE;
}
@@ -1180,7 +1197,7 @@ yylex (void)
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN,
- parse_language->la_language == language_cplus
+ parse_language (pstate)->la_language == language_cplus
? &is_a_field_of_this : NULL);
if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
{
@@ -1188,8 +1205,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 (pstate),
+ parse_gdbarch (pstate), tmp);
if (yylval.tsym.type != NULL)
return TYPENAME;
@@ -1201,7 +1218,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 (pstate, tokstart, namelen, 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym = sym;
@@ -1217,6 +1234,16 @@ yylex (void)
}
}
+int
+f_parse (struct parser_state *par_state)
+{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ return _f_parse ();
+}
+
void
yyerror (char *msg)
{
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 4aae3c5..1392345 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 (char *); /* Defined in f-exp.y */
extern void f_print_type (struct type *, const char *, struct ui_file *, int,
int);
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 08/10] Objective-C language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (5 preceding siblings ...)
2012-06-02 20:24 ` [PATCH 05/10] Fortran language Sergio Durigan Junior
@ 2012-06-02 20:24 ` Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-02 20:33 ` [PATCH 07/10] Modula-2 language Sergio Durigan Junior
` (3 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:24 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Objective-C language. Similar to the C language one.
---
gdb/objc-exp.y | 412 ++++++++++++++++++++++++++++--------------------------
gdb/objc-lang.c | 8 +-
gdb/objc-lang.h | 7 +-
3 files changed, 222 insertions(+), 205 deletions(-)
diff --git a/gdb/objc-exp.y b/gdb/objc-exp.y
index 6f51edf..5157596 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
@@ -63,7 +63,7 @@
adding those names to this list. */
#define yymaxdepth objc_maxdepth
-#define yyparse objc_parse
+#define yyparse _objc_parse
#define yylex objc_lex
#define yyerror objc_error
#define yylval objc_lval
@@ -113,6 +113,11 @@
#define YYDEBUG 0 /* Default to no yydebug support. */
#endif
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -153,7 +158,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
@@ -235,79 +240,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);}
;
/* Expressions, including the comma operator. */
exp1 : exp
| exp1 ',' exp
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
;
/* Expressions, not including the comma operator. */
exp : '*' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
exp : '&' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_ADDR); }
+ { write_exp_elt_opcode (pstate, UNOP_ADDR); }
;
exp : '-' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
;
exp : '!' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
exp : '~' exp %prec UNARY
- { write_exp_elt_opcode (UNOP_COMPLEMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
;
exp : INCREMENT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PREINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
;
exp : DECREMENT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_PREDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
;
exp : exp INCREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
;
exp : exp DECREMENT %prec UNARY
- { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
;
exp : SIZEOF exp %prec UNARY
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_ADDR);
+ write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
;
exp : exp ARROW '*' exp
- { write_exp_elt_opcode (STRUCTOP_MPTR); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
@@ -315,16 +320,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 (pstate, UNOP_ADDR);
+ write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
;
exp : exp '.' '*' exp
- { write_exp_elt_opcode (STRUCTOP_MEMBER); }
+ { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
;
exp : exp '[' exp1 ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
/*
* The rules below parse ObjC message calls of the form:
@@ -335,50 +340,50 @@ exp : '[' TYPENAME
{
CORE_ADDR class;
- class = lookup_objc_class (parse_gdbarch,
+ class = lookup_objc_class (parse_gdbarch (pstate),
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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
+ write_exp_elt_longcst (pstate, (LONGEST) class);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
+ end_msglist (pstate);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
+ write_exp_elt_longcst (pstate, (LONGEST) $2.class);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
+ end_msglist (pstate);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
+ end_msglist (pstate);
+ write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
}
;
msglist : name
- { add_msglist(&$1, 0); }
+ { add_msglist (&$1, 0); }
| msgarglist
;
@@ -399,9 +404,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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
;
lcurly : '{'
@@ -423,22 +428,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 (pstate, OP_ARRAY);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_longcst (pstate, (LONGEST) $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MEMVAL);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
exp : '(' exp1 ')'
@@ -448,120 +453,120 @@ exp : '(' exp1 ')'
/* Binary operators in order of decreasing precedence. */
exp : exp '@' exp
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
;
exp : exp '%' exp
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp LSH exp
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
;
exp : exp RSH exp
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
;
exp : exp EQUAL exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : exp '&' exp
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
exp : exp '^' exp
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
exp : exp '|' exp
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
exp : exp ANDAND exp
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
exp : exp OROR exp
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
exp : exp '?' exp ':' exp %prec '?'
- { write_exp_elt_opcode (TERNOP_COND); }
+ { write_exp_elt_opcode (pstate, TERNOP_COND); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : NAME_OR_INT
{ YYSTYPE val;
- parse_number ($1.stoken.ptr,
+ parse_number (pstate, $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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val_int.type);
+ write_exp_elt_longcst (pstate, (LONGEST)
val.typed_val_int.val);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, OP_DOUBLE); }
;
exp : variable
@@ -573,17 +578,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 (pstate, OP_OBJC_SELECTOR);
+ write_exp_string (pstate, $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
CHECK_TYPEDEF ($3);
- write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
- write_exp_elt_opcode (OP_LONG); }
+ write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : STRING
@@ -596,27 +601,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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
+ write_exp_elt_longcst (pstate, (LONGEST) (*sp++));
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
+ write_exp_elt_longcst (pstate, (LONGEST)'\0');
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_opcode (pstate, OP_ARRAY);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_longcst (pstate, (LONGEST) ($1.length));
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_NSSTRING);
+ write_exp_string (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); }
;
block : BLOCKNAME
@@ -662,11 +667,11 @@ variable: block COLONCOLON name
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, block_found);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
;
qualified_name: typebase COLONCOLON name
@@ -677,10 +682,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 (pstate, OP_SCOPE);
+ write_exp_elt_type (pstate, type);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_SCOPE);
}
| typebase COLONCOLON '~' name
{
@@ -700,10 +705,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 (pstate, OP_SCOPE);
+ write_exp_elt_type (pstate, type);
+ write_exp_string (pstate, tmp_token);
+ write_exp_elt_opcode (pstate, OP_SCOPE);
}
;
@@ -719,16 +724,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 (pstate, OP_VAR_VALUE);
+ write_exp_elt_block (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
break;
}
msymbol = lookup_minimal_symbol (name, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
&& !have_partial_symbols ())
error (_("No symbol table is loaded. "
@@ -752,13 +757,13 @@ variable: name_not_typename
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
}
else if ($1.is_a_field_of_this)
{
@@ -768,11 +773,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 (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $1.stoken);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
}
else
{
@@ -782,7 +787,7 @@ variable: name_not_typename
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () &&
!have_partial_symbols ())
error (_("No symbol table is loaded. "
@@ -877,31 +882,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
$$ = $1.type;
}
| INT_KEYWORD
- { $$ = parse_type->builtin_int; }
+ { $$ = parse_type (pstate)->builtin_int; }
| LONG
- { $$ = parse_type->builtin_long; }
+ { $$ = parse_type (pstate)->builtin_long; }
| SHORT
- { $$ = parse_type->builtin_short; }
+ { $$ = parse_type (pstate)->builtin_short; }
| LONG INT_KEYWORD
- { $$ = parse_type->builtin_long; }
+ { $$ = parse_type (pstate)->builtin_long; }
| UNSIGNED LONG INT_KEYWORD
- { $$ = parse_type->builtin_unsigned_long; }
+ { $$ = parse_type (pstate)->builtin_unsigned_long; }
| LONG LONG
- { $$ = parse_type->builtin_long_long; }
+ { $$ = parse_type (pstate)->builtin_long_long; }
| LONG LONG INT_KEYWORD
- { $$ = parse_type->builtin_long_long; }
+ { $$ = parse_type (pstate)->builtin_long_long; }
| UNSIGNED LONG LONG
- { $$ = parse_type->builtin_unsigned_long_long; }
+ { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
| UNSIGNED LONG LONG INT_KEYWORD
- { $$ = parse_type->builtin_unsigned_long_long; }
+ { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
| SHORT INT_KEYWORD
- { $$ = parse_type->builtin_short; }
+ { $$ = parse_type (pstate)->builtin_short; }
| UNSIGNED SHORT INT_KEYWORD
- { $$ = parse_type->builtin_unsigned_short; }
+ { $$ = parse_type (pstate)->builtin_unsigned_short; }
| DOUBLE_KEYWORD
- { $$ = parse_type->builtin_double; }
+ { $$ = parse_type (pstate)->builtin_double; }
| LONG DOUBLE_KEYWORD
- { $$ = parse_type->builtin_long_double; }
+ { $$ = parse_type (pstate)->builtin_long_double; }
| STRUCT name
{ $$ = lookup_struct (copy_name ($2),
expression_context_block); }
@@ -915,17 +920,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 (pstate),
+ parse_gdbarch (pstate),
TYPE_NAME($2.type)); }
| UNSIGNED
- { $$ = parse_type->builtin_unsigned_int; }
+ { $$ = parse_type (pstate)->builtin_unsigned_int; }
| SIGNED_KEYWORD typename
- { $$ = lookup_signed_typename (parse_language,
- parse_gdbarch,
+ { $$ = lookup_signed_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
TYPE_NAME($2.type)); }
| SIGNED_KEYWORD
- { $$ = parse_type->builtin_int; }
+ { $$ = parse_type (pstate)->builtin_int; }
| TEMPLATE name '<' type '>'
{ $$ = lookup_template_type(copy_name($2), $4,
expression_context_block);
@@ -942,19 +947,19 @@ typename: TYPENAME
{
$$.stoken.ptr = "int";
$$.stoken.length = 3;
- $$.type = parse_type->builtin_int;
+ $$.type = parse_type (pstate)->builtin_int;
}
| LONG
{
$$.stoken.ptr = "long";
$$.stoken.length = 4;
- $$.type = parse_type->builtin_long;
+ $$.type = parse_type (pstate)->builtin_long;
}
| SHORT
{
$$.stoken.ptr = "short";
$$.stoken.length = 5;
- $$.type = parse_type->builtin_short;
+ $$.type = parse_type (pstate)->builtin_short;
}
;
@@ -998,7 +1003,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 *par_state, 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
@@ -1024,7 +1030,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 (par_state), p, len,
&putithere->typed_val_float.dval,
&putithere->typed_val_float.type))
return ERROR;
@@ -1130,10 +1136,10 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
un = (unsigned LONGEST)n >> 2;
if (long_p == 0
- && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
+ && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0)
{
high_bit
- = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+ = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
/* A large decimal (not hex or octal) constant (between INT_MAX
and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -1141,29 +1147,29 @@ 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 (par_state)->builtin_unsigned_int;
+ signed_type = parse_type (par_state)->builtin_int;
}
else if (long_p <= 1
- && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+ && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_long;
+ signed_type = parse_type (par_state)->builtin_long;
}
else
{
high_bit = (((unsigned LONGEST)1)
- << (gdbarch_long_long_bit (parse_gdbarch) - 32 - 1)
+ << (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
+ signed_type = parse_type (par_state)->builtin_long_long;
}
putithere->typed_val_int.val = n;
@@ -1274,12 +1280,12 @@ yylex (void)
lexptr++;
c = *lexptr++;
if (c == '\\')
- c = parse_escape (parse_gdbarch, &lexptr);
+ c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
c = *lexptr++;
if (c != '\'')
@@ -1397,7 +1403,7 @@ yylex (void)
else break;
}
if (toktype != ERROR)
- toktype = parse_number (tokstart, p - tokstart,
+ toktype = parse_number (pstate, tokstart, p - tokstart,
got_dot | got_e, &yylval);
if (toktype == ERROR)
{
@@ -1502,7 +1508,7 @@ yylex (void)
break;
case '\\':
tokptr++;
- c = parse_escape (parse_gdbarch, &tokptr);
+ c = parse_escape (parse_gdbarch (pstate), &tokptr);
if (c == -1)
{
continue;
@@ -1563,7 +1569,7 @@ yylex (void)
case 8:
if (strncmp (tokstart, "unsigned", 8) == 0)
return UNSIGNED;
- if (parse_language->la_language == language_cplus
+ if (parse_language (pstate)->la_language == language_cplus
&& strncmp (tokstart, "template", 8) == 0)
return TEMPLATE;
if (strncmp (tokstart, "volatile", 8) == 0)
@@ -1580,7 +1586,7 @@ yylex (void)
return DOUBLE_KEYWORD;
break;
case 5:
- if ((parse_language->la_language == language_cplus)
+ if ((parse_language (pstate)->la_language == language_cplus)
&& strncmp (tokstart, "class", 5) == 0)
return CLASS;
if (strncmp (tokstart, "union", 5) == 0)
@@ -1609,7 +1615,7 @@ yylex (void)
if (*tokstart == '$')
{
- write_dollar_variable (yylval.sval);
+ write_dollar_variable (pstate, yylval.sval);
return VARIABLE;
}
@@ -1624,8 +1630,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 (pstate)->la_language == language_cplus ||
+ parse_language (pstate)->la_language == language_objc)
need_this = &is_a_field_of_this;
else
need_this = (int *) NULL;
@@ -1737,15 +1743,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 (pstate),
+ parse_gdbarch (pstate), 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 (pstate), tmp);
if (Class)
{
yylval.class.class = Class;
@@ -1765,7 +1771,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 (pstate, tokstart, namelen, 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym = sym;
@@ -1781,6 +1787,16 @@ yylex (void)
}
}
+int
+objc_parse (struct parser_state *par_state)
+{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ return _objc_parse ();
+}
+
void
yyerror (char *msg)
{
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 15bf792..52786cc 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -615,7 +615,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;
@@ -625,12 +625,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..ba656f8 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -26,10 +26,11 @@ 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 (char *); /* Defined in objc-exp.y */
extern CORE_ADDR lookup_objc_class (struct gdbarch *gdbarch,
char *classname);
@@ -48,7 +49,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);
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 09/10] Pascal language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (7 preceding siblings ...)
2012-06-02 20:33 ` [PATCH 07/10] Modula-2 language Sergio Durigan Junior
@ 2012-06-02 20:33 ` Sergio Durigan Junior
2012-06-05 7:39 ` Pierre Muller
2012-06-02 20:34 ` [PATCH 06/10] Java language Sergio Durigan Junior
2012-06-04 20:38 ` [PATCH 00/10] Remove `expout*' globals from parser-defs.h Tom Tromey
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:33 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Pascal language. Similar to the C language one.
---
gdb/p-exp.y | 327 +++++++++++++++++++++++++++++++---------------------------
gdb/p-lang.h | 5 +-
2 files changed, 178 insertions(+), 154 deletions(-)
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 5d344a4..43c4f30 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
@@ -66,7 +66,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth pascal_maxdepth
-#define yyparse pascal_parse
+#define yyparse _pascal_parse
#define yylex pascal_lex
#define yyerror pascal_error
#define yylval pascal_lval
@@ -118,6 +118,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -158,7 +163,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;
@@ -251,44 +256,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);
current_type = $1; } ;
/* Expressions, including the comma operator. */
exp1 : exp
| exp1 ',' exp
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
;
/* Expressions, not including the comma operator. */
exp : exp '^' %prec UNARY
- { write_exp_elt_opcode (UNOP_IND);
+ { write_exp_elt_opcode (pstate, 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 (pstate, 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 (pstate, UNOP_NEG); }
;
exp : NOT exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
exp : INCREMENT '(' exp ')' %prec UNARY
- { write_exp_elt_opcode (UNOP_PREINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
;
exp : DECREMENT '(' exp ')' %prec UNARY
- { write_exp_elt_opcode (UNOP_PREDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
;
@@ -297,9 +302,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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $2);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
search_field = 0;
if (current_type)
{
@@ -315,10 +320,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 (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $2);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
search_field = 0;
if (current_type)
{
@@ -334,12 +339,12 @@ exp : field_exp name
exp : field_exp COMPLETE
{ struct stoken s;
- mark_struct_expression ();
- write_exp_elt_opcode (STRUCTOP_STRUCT);
+ mark_struct_expression (pstate);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
s.ptr = "";
s.length = 0;
- write_exp_string (s);
- write_exp_elt_opcode (STRUCTOP_STRUCT); }
+ write_exp_string (pstate, s);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : exp '['
@@ -357,14 +362,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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, stringsval);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
}
push_current_type (); }
exp1 ']'
{ pop_current_type ();
- write_exp_elt_opcode (BINOP_SUBSCRIPT);
+ write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT);
if (current_type)
current_type = TYPE_TARGET_TYPE (current_type); }
;
@@ -375,9 +380,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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
pop_current_type ();
if (current_type)
current_type = TYPE_TARGET_TYPE (current_type);
@@ -398,11 +403,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 (pstate, UNOP_IND);
}
- write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type ($1);
- write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_opcode (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, UNOP_CAST);
current_type = $1; }
;
@@ -413,7 +418,7 @@ exp : '(' exp1 ')'
/* Binary operators in order of decreasing precedence. */
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' {
@@ -425,135 +430,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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate,
+ parse_type (pstate)
+ ->builtin_long_double);
+ current_type = parse_type (pstate)->builtin_long_double;
+ write_exp_elt_opcode (pstate, UNOP_CAST);
leftdiv_is_integer = 0;
}
- write_exp_elt_opcode (BINOP_DIV);
+ write_exp_elt_opcode (pstate, BINOP_DIV);
}
;
exp : exp DIV exp
- { write_exp_elt_opcode (BINOP_INTDIV); }
+ { write_exp_elt_opcode (pstate, BINOP_INTDIV); }
;
exp : exp MOD exp
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp LSH exp
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
;
exp : exp RSH exp
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_EQUAL);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_LEQ);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_GEQ);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_LESS);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR);
- current_type = parse_type->builtin_bool;
+ { write_exp_elt_opcode (pstate, BINOP_GTR);
+ current_type = parse_type (pstate)->builtin_bool;
}
;
exp : exp ANDAND exp
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
exp : exp XOR exp
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
exp : exp OR exp
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
exp : exp ASSIGN exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ current_type = parse_type (pstate)->builtin_bool;
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ current_type = parse_type (pstate)->builtin_bool;
+ write_exp_elt_opcode (pstate, OP_BOOL); }
;
exp : INT
- { write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type ($1.type);
+ { write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
current_type = $1.type;
- write_exp_elt_longcst ((LONGEST)($1.val));
- write_exp_elt_opcode (OP_LONG); }
+ write_exp_elt_longcst (pstate, (LONGEST)($1.val));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : NAME_OR_INT
{ YYSTYPE val;
- parse_number ($1.stoken.ptr,
+ parse_number (pstate, $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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val_int.type);
current_type = val.typed_val_int.type;
- write_exp_elt_longcst ((LONGEST)
+ write_exp_elt_longcst (pstate, (LONGEST)
val.typed_val_int.val);
- write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (pstate, OP_LONG);
}
;
exp : FLOAT
- { write_exp_elt_opcode (OP_DOUBLE);
- write_exp_elt_type ($1.type);
+ { write_exp_elt_opcode (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
current_type = $1.type;
- write_exp_elt_dblcst ($1.dval);
- write_exp_elt_opcode (OP_DOUBLE); }
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, OP_DOUBLE); }
;
exp : variable
@@ -566,7 +573,7 @@ exp : VARIABLE
struct value * val, * mark;
mark = value_mark ();
- val = value_of_internalvar (parse_gdbarch,
+ val = value_of_internalvar (parse_gdbarch (pstate),
intvar);
current_type = value_type (val);
value_release_to_mark (mark);
@@ -575,15 +582,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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
CHECK_TYPEDEF ($3);
- write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
- write_exp_elt_opcode (OP_LONG); }
+ write_exp_elt_longcst (pstate,
+ (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, OP_LONG); }
;
exp : SIZEOF '(' exp ')' %prec UNARY
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
exp : STRING
{ /* C strings are converted into array constants with
@@ -594,19 +602,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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_type (pstate)
+ ->builtin_char);
+ write_exp_elt_longcst (pstate, (LONGEST) (*sp++));
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_type (pstate)
+ ->builtin_char);
+ write_exp_elt_longcst (pstate, (LONGEST)'\0');
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_opcode (pstate, OP_ARRAY);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_longcst (pstate, (LONGEST) ($1.length));
+ write_exp_elt_opcode (pstate, OP_ARRAY); }
;
/* Object pascal */
@@ -614,10 +626,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 (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, OP_THIS);
/* We need type of this. */
- this_val = value_of_this_silent (parse_language);
+ this_val = value_of_this_silent (parse_language (pstate));
if (this_val)
this_type = value_type (this_val);
else
@@ -627,7 +639,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 (pstate, UNOP_IND);
}
}
@@ -673,11 +685,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 (pstate, 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 (pstate, block_found);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
;
qualified_name: typebase COLONCOLON name
@@ -688,10 +700,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 (pstate, OP_SCOPE);
+ write_exp_elt_type (pstate, type);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_SCOPE);
}
;
@@ -707,16 +719,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 (pstate, OP_VAR_VALUE);
+ write_exp_elt_block (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
break;
}
msymbol = lookup_minimal_symbol (name, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
&& !have_partial_symbols ())
error (_("No symbol table is loaded. "
@@ -740,13 +752,13 @@ variable: name_not_typename
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
current_type = sym->type; }
else if ($1.is_a_field_of_this)
{
@@ -759,13 +771,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 (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, OP_THIS);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
+ write_exp_string (pstate, $1.stoken);
+ write_exp_elt_opcode (pstate, STRUCTOP_PTR);
/* We need type of this. */
- this_val = value_of_this_silent (parse_language);
+ this_val = value_of_this_silent (parse_language (pstate));
if (this_val)
this_type = value_type (this_val);
else
@@ -785,7 +797,7 @@ variable: name_not_typename
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
&& !have_partial_symbols ())
error (_("No symbol table is loaded. "
@@ -854,7 +866,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 *par_state, 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. */
@@ -879,7 +892,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 (par_state), p, len,
&putithere->typed_val_float.dval,
&putithere->typed_val_float.type))
return ERROR;
@@ -985,9 +998,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 (par_state)) - 2)) == 0)
{
- high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
+ high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
/* A large decimal (not hex or octal) constant (between INT_MAX
and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -995,28 +1008,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 (par_state)->builtin_unsigned_int;
+ signed_type = parse_type (par_state)->builtin_int;
}
else if (long_p <= 1
- && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
+ && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
+ unsigned_type = parse_type (par_state)->builtin_unsigned_long;
+ signed_type = parse_type (par_state)->builtin_long;
}
else
{
int shift;
if (sizeof (ULONGEST) * HOST_CHAR_BIT
- < gdbarch_long_long_bit (parse_gdbarch))
+ < gdbarch_long_long_bit (parse_gdbarch (par_state)))
/* 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 (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
+ signed_type = parse_type (par_state)->builtin_long_long;
}
putithere->typed_val_int.val = n;
@@ -1190,12 +1203,12 @@ yylex (void)
lexptr++;
c = *lexptr++;
if (c == '\\')
- c = parse_escape (parse_gdbarch, &lexptr);
+ c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
c = *lexptr++;
if (c != '\'')
@@ -1295,7 +1308,7 @@ yylex (void)
&& (*p < 'A' || *p > 'Z')))
break;
}
- toktype = parse_number (tokstart,
+ toktype = parse_number (pstate, tokstart,
p - tokstart, got_dot | got_e, &yylval);
if (toktype == ERROR)
{
@@ -1362,7 +1375,7 @@ yylex (void)
break;
case '\\':
tokptr++;
- c = parse_escape (parse_gdbarch, &tokptr);
+ c = parse_escape (parse_gdbarch (pstate), &tokptr);
if (c == -1)
{
continue;
@@ -1504,7 +1517,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 (pstate, yylval.sval);
c = tokstart[namelen];
tokstart[namelen] = 0;
intvar = lookup_only_internalvar (++tokstart);
@@ -1702,8 +1715,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 (pstate),
+ parse_gdbarch (pstate), tmp);
if (yylval.tsym.type != NULL)
{
free (uptokstart);
@@ -1718,7 +1731,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 (pstate, tokstart, namelen, 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym = sym;
@@ -1736,6 +1749,16 @@ yylex (void)
}
}
+int
+pascal_parse (struct parser_state *par_state)
+{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ return _pascal_parse ();
+}
+
void
yyerror (char *msg)
{
diff --git a/gdb/p-lang.h b/gdb/p-lang.h
index b1e218c..a5168f8 100644
--- a/gdb/p-lang.h
+++ b/gdb/p-lang.h
@@ -20,13 +20,14 @@
/* 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 (char *); /* Defined in p-exp.y */
/* Defined in p-typeprint.c */
extern void pascal_print_type (struct type *, const char *, struct ui_file *,
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 07/10] Modula-2 language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (6 preceding siblings ...)
2012-06-02 20:24 ` [PATCH 08/10] Objective-C language Sergio Durigan Junior
@ 2012-06-02 20:33 ` Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-02 20:33 ` [PATCH 09/10] Pascal language Sergio Durigan Junior
` (2 subsequent siblings)
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:33 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Modula-2 language. Similar to the C language one.
---
gdb/m2-exp.y | 261 +++++++++++++++++++++++++++++++--------------------------
gdb/m2-lang.h | 6 +-
2 files changed, 147 insertions(+), 120 deletions(-)
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 19f9c24..153d482 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
@@ -61,7 +61,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth m2_maxdepth
-#define yyparse m2_parse
+#define yyparse _m2_parse
#define yylex m2_lex
#define yyerror m2_error
#define yylval m2_lval
@@ -113,6 +113,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -205,31 +210,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);
}
;
/* Expressions */
exp : exp '^' %prec UNARY
- { write_exp_elt_opcode (UNOP_IND); }
+ { write_exp_elt_opcode (pstate, UNOP_IND); }
;
exp : '-'
{ number_sign = -1; }
exp %prec UNARY
{ number_sign = 1;
- write_exp_elt_opcode (UNOP_NEG); }
+ write_exp_elt_opcode (pstate, UNOP_NEG); }
;
exp : '+' exp %prec UNARY
- { write_exp_elt_opcode(UNOP_PLUS); }
+ { write_exp_elt_opcode (pstate, UNOP_PLUS); }
;
exp : not_exp exp %prec UNARY
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
;
not_exp : NOT
@@ -237,88 +242,88 @@ not_exp : NOT
;
exp : CAP '(' exp ')'
- { write_exp_elt_opcode (UNOP_CAP); }
+ { write_exp_elt_opcode (pstate, UNOP_CAP); }
;
exp : ORD '(' exp ')'
- { write_exp_elt_opcode (UNOP_ORD); }
+ { write_exp_elt_opcode (pstate, UNOP_ORD); }
;
exp : ABS '(' exp ')'
- { write_exp_elt_opcode (UNOP_ABS); }
+ { write_exp_elt_opcode (pstate, UNOP_ABS); }
;
exp : HIGH '(' exp ')'
- { write_exp_elt_opcode (UNOP_HIGH); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MIN);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MAX);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, UNOP_MAX); }
;
exp : FLOAT_FUNC '(' exp ')'
- { write_exp_elt_opcode (UNOP_FLOAT); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_VAL);
+ write_exp_elt_type (pstate, $3);
+ write_exp_elt_opcode (pstate, BINOP_VAL); }
;
exp : CHR '(' exp ')'
- { write_exp_elt_opcode (UNOP_CHR); }
+ { write_exp_elt_opcode (pstate, UNOP_CHR); }
;
exp : ODD '(' exp ')'
- { write_exp_elt_opcode (UNOP_ODD); }
+ { write_exp_elt_opcode (pstate, UNOP_ODD); }
;
exp : TRUNC '(' exp ')'
- { write_exp_elt_opcode (UNOP_TRUNC); }
+ { write_exp_elt_opcode (pstate, UNOP_TRUNC); }
;
exp : TSIZE '(' exp ')'
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
;
exp : SIZE exp %prec UNARY
- { write_exp_elt_opcode (UNOP_SIZEOF); }
+ { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
;
exp : INC '(' exp ')'
- { write_exp_elt_opcode(UNOP_PREINCREMENT); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, BINOP_ADD);
+ write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
;
exp : DEC '(' exp ')'
- { write_exp_elt_opcode(UNOP_PREDECREMENT);}
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, BINOP_SUB);
+ write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : set
@@ -350,13 +355,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 (pstate, MULTI_SUBSCRIPT);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist());
+ write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); }
;
exp : exp '[' exp ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
exp : exp '('
@@ -364,9 +369,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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
;
arglist :
@@ -392,15 +397,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 (pstate, UNOP_MEMVAL);
+ write_exp_elt_type (pstate, $2);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
exp : '(' exp ')'
@@ -412,131 +417,139 @@ exp : '(' exp ')'
/* GDB construct */
exp : exp '@' exp
- { write_exp_elt_opcode (BINOP_REPEAT); }
+ { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
;
exp : exp '*' exp
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
;
exp : exp '/' exp
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
;
exp : exp DIV exp
- { write_exp_elt_opcode (BINOP_INTDIV); }
+ { write_exp_elt_opcode (pstate, BINOP_INTDIV); }
;
exp : exp MOD exp
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
exp : exp '+' exp
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
;
exp : exp '-' exp
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
| exp '#' exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
;
exp : exp LOGICAL_AND exp
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
exp : exp OROR exp
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
exp : exp ASSIGN exp
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_m2_type (pstate)->builtin_int);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_m2_type (pstate)
+ ->builtin_card);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_m2_type (pstate)
+ ->builtin_char);
+ write_exp_elt_longcst (pstate, (LONGEST) $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate,
+ parse_m2_type (pstate)
+ ->builtin_real);
+ write_exp_elt_dblcst (pstate, $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
+ write_exp_elt_longcst (pstate,
+ (LONGEST) TYPE_LENGTH ($3));
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_M2_STRING);
+ write_exp_string (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_M2_STRING); }
;
/* This will be used for extensions later. Like adding modules. */
@@ -546,7 +559,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;}
;
@@ -566,10 +580,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 (pstate, OP_VAR_VALUE);
+ write_exp_elt_block (pstate, NULL);
+ write_exp_elt_sym (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
;
/* GDB internal ($foo) variable */
@@ -592,11 +606,11 @@ variable: block COLONCOLON NAME
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, block_found);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
;
/* Base case for variables. */
@@ -618,13 +632,13 @@ variable: NAME
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (pstate, 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 (pstate, NULL);
+ write_exp_elt_sym (pstate, sym);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
}
else
{
@@ -634,7 +648,7 @@ variable: NAME
msymbol =
lookup_minimal_symbol (arg, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"symbol-file\" command."));
else
@@ -646,7 +660,8 @@ variable: NAME
type
: TYPENAME
- { $$ = lookup_typename (parse_language, parse_gdbarch,
+ { $$ = lookup_typename (parse_language (pstate),
+ parse_gdbarch (pstate),
copy_name ($1),
expression_context_block, 0); }
@@ -806,8 +821,8 @@ 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)
@@ -993,7 +1008,7 @@ yylex (void)
if (*tokstart == '$')
{
- write_dollar_variable (yylval.sval);
+ write_dollar_variable (pstate, yylval.sval);
return INTERNAL_VAR;
}
@@ -1013,7 +1028,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 (pstate), parse_gdbarch (pstate),
copy_name (yylval.sval), expression_context_block, 1))
return TYPENAME;
@@ -1071,6 +1086,16 @@ yylex (void)
}
}
+int
+m2_parse (struct parser_state *par_state)
+{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ return _m2_parse ();
+}
+
void
yyerror (char *msg)
{
diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
index fc6de34..daae348 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 (char *); /* Defined in m2-exp.y */
/* Defined in m2-typeprint.c */
extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 06/10] Java language
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (8 preceding siblings ...)
2012-06-02 20:33 ` [PATCH 09/10] Pascal language Sergio Durigan Junior
@ 2012-06-02 20:34 ` Sergio Durigan Junior
2012-06-04 20:27 ` Tom Tromey
2012-06-04 20:38 ` [PATCH 00/10] Remove `expout*' globals from parser-defs.h Tom Tromey
10 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-02 20:34 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Sergio Durigan Junior
Patch for the Java language. Similar to the C language one.
---
gdb/jv-exp.y | 357 ++++++++++++++++++++++++++++++---------------------------
gdb/jv-lang.h | 5 +-
2 files changed, 193 insertions(+), 169 deletions(-)
diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y
index ee17654..0338985 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
@@ -59,7 +59,7 @@
generators need to be fixed instead of adding those names to this list. */
#define yymaxdepth java_maxdepth
-#define yyparse java_parse
+#define yyparse _java_parse
#define yylex java_lex
#define yyerror java_error
#define yylval java_lval
@@ -111,6 +111,11 @@
#define YYFPRINTF parser_fprintf
+/* The state of the parser, used internally when we are parsing the
+ expression. */
+
+static struct parser_state *pstate = NULL;
+
int yyparse (void);
static int yylex (void);
@@ -118,11 +123,11 @@ static int yylex (void);
void yyerror (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 *);
%}
@@ -154,7 +159,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
@@ -214,9 +219,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 (pstate, OP_TYPE);
+ write_exp_elt_type (pstate, $1);
+ write_exp_elt_opcode (pstate, OP_TYPE);
}
;
@@ -228,36 +233,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 (pstate, OP_STRING);
+ write_exp_string (pstate, $1);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_longcst (pstate, (LONGEST)($1.val));
+ write_exp_elt_opcode (pstate, 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 (pstate, $1.ptr, $1.length, 0, &val);
+ write_exp_elt_opcode (pstate, OP_LONG);
+ write_exp_elt_type (pstate, val.typed_val_int.type);
+ write_exp_elt_longcst (pstate, (LONGEST)val.typed_val_int.val);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
+ write_exp_elt_type (pstate, $1.type);
+ write_exp_elt_dblcst (pstate, $1.dval);
+ write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
+ write_exp_elt_type (pstate,
+ parse_java_type (pstate)->builtin_boolean);
+ write_exp_elt_longcst (pstate, (LONGEST)$1);
+ write_exp_elt_opcode (pstate, OP_LONG); }
| StringLiteral
;
@@ -271,7 +277,7 @@ Type:
PrimitiveType:
NumericType
| BOOLEAN
- { $$ = parse_java_type->builtin_boolean; }
+ { $$ = parse_java_type (pstate)->builtin_boolean; }
;
NumericType:
@@ -281,22 +287,22 @@ NumericType:
IntegralType:
BYTE
- { $$ = parse_java_type->builtin_byte; }
+ { $$ = parse_java_type (pstate)->builtin_byte; }
| SHORT
- { $$ = parse_java_type->builtin_short; }
+ { $$ = parse_java_type (pstate)->builtin_short; }
| INT
- { $$ = parse_java_type->builtin_int; }
+ { $$ = parse_java_type (pstate)->builtin_int; }
| LONG
- { $$ = parse_java_type->builtin_long; }
+ { $$ = parse_java_type (pstate)->builtin_long; }
| CHAR
- { $$ = parse_java_type->builtin_char; }
+ { $$ = parse_java_type (pstate)->builtin_char; }
;
FloatingPointType:
FLOAT
- { $$ = parse_java_type->builtin_float; }
+ { $$ = parse_java_type (pstate)->builtin_float; }
| DOUBLE
- { $$ = parse_java_type->builtin_double; }
+ { $$ = parse_java_type (pstate)->builtin_double; }
;
/* UNUSED:
@@ -363,7 +369,7 @@ type_exp: type
/* Expressions, including the comma operator. */
exp1 : Expression
| exp1 ',' Expression
- { write_exp_elt_opcode (BINOP_COMMA); }
+ { write_exp_elt_opcode (pstate, BINOP_COMMA); }
;
Primary:
@@ -379,10 +385,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 (pstate, OP_ARRAY);
+ write_exp_elt_longcst (pstate, (LONGEST) 0);
+ write_exp_elt_longcst (pstate, (LONGEST) $3);
+ write_exp_elt_opcode (pstate, OP_ARRAY); }
;
lcurly:
@@ -447,24 +453,24 @@ Dims_opt:
FieldAccess:
Primary '.' SimpleName
- { push_fieldnames ($3); }
+ { push_fieldnames (pstate, $3); }
| VARIABLE '.' SimpleName
- { push_fieldnames ($3); }
+ { push_fieldnames (pstate, $3); }
/*| SUPER '.' SimpleName { FIXME } */
;
FuncStart:
Name '('
- { push_expression_name ($1); }
+ { push_expression_name (pstate, $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 (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
| Primary '.' SimpleName '(' ArgumentList_opt ')'
{ error (_("Form of method invocation not implemented")); }
| SUPER '.' SimpleName '(' ArgumentList_opt ')'
@@ -481,24 +487,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 (pstate, $1);
+ name_expr = copy_exp (pstate->expout, pstate->expout_ptr);
+ pstate->expout_ptr -= name_expr->nelts;
+ insert_exp (pstate,
+ pstate->expout_ptr - length_of_subexp (pstate->expout,
+ pstate->expout_ptr),
name_expr);
free (name_expr);
- write_exp_elt_opcode (BINOP_SUBSCRIPT);
+ write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT);
}
| VARIABLE '[' Expression ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
| PrimaryNoNewArray '[' Expression ']'
- { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
+ { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
;
PostfixExpression:
Primary
| Name
- { push_expression_name ($1); }
+ { push_expression_name (pstate, $1); }
| VARIABLE
/* Already written by write_dollar_variable. */
| PostIncrementExpression
@@ -507,12 +515,12 @@ PostfixExpression:
PostIncrementExpression:
PostfixExpression INCREMENT
- { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
;
PostDecrementExpression:
PostfixExpression DECREMENT
- { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
;
UnaryExpression:
@@ -520,144 +528,149 @@ UnaryExpression:
| PreDecrementExpression
| '+' UnaryExpression
| '-' UnaryExpression
- { write_exp_elt_opcode (UNOP_NEG); }
+ { write_exp_elt_opcode (pstate, UNOP_NEG); }
| '*' UnaryExpression
- { write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java */
+ { write_exp_elt_opcode (pstate, UNOP_IND); } /*FIXME not in Java */
| UnaryExpressionNotPlusMinus
;
PreIncrementExpression:
INCREMENT UnaryExpression
- { write_exp_elt_opcode (UNOP_PREINCREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
;
PreDecrementExpression:
DECREMENT UnaryExpression
- { write_exp_elt_opcode (UNOP_PREDECREMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
;
UnaryExpressionNotPlusMinus:
PostfixExpression
| '~' UnaryExpression
- { write_exp_elt_opcode (UNOP_COMPLEMENT); }
+ { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
| '!' UnaryExpression
- { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, java_array_type ($2, $3));
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
| '(' Expression ')' UnaryExpressionNotPlusMinus
{
- int last_exp_size = length_of_subexp(expout, expout_ptr);
+ int last_exp_size = length_of_subexp (pstate->expout,
+ pstate->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 = pstate->expout_ptr - last_exp_size - 3;
+
+ if (base < 0 || pstate->expout->elts[base+2].opcode != OP_TYPE)
error (_("Invalid cast expression"));
- type = expout->elts[base+1].type;
+ type = pstate->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;
+ pstate->expout->elts[base + i]
+ = pstate->expout->elts[base + i + 3];
+ pstate->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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate, type);
+ write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
+ write_exp_elt_type (pstate,
+ java_array_type (java_type_from_name
+ ($2), $3));
+ write_exp_elt_opcode (pstate, UNOP_CAST); }
;
MultiplicativeExpression:
UnaryExpression
| MultiplicativeExpression '*' UnaryExpression
- { write_exp_elt_opcode (BINOP_MUL); }
+ { write_exp_elt_opcode (pstate, BINOP_MUL); }
| MultiplicativeExpression '/' UnaryExpression
- { write_exp_elt_opcode (BINOP_DIV); }
+ { write_exp_elt_opcode (pstate, BINOP_DIV); }
| MultiplicativeExpression '%' UnaryExpression
- { write_exp_elt_opcode (BINOP_REM); }
+ { write_exp_elt_opcode (pstate, BINOP_REM); }
;
AdditiveExpression:
MultiplicativeExpression
| AdditiveExpression '+' MultiplicativeExpression
- { write_exp_elt_opcode (BINOP_ADD); }
+ { write_exp_elt_opcode (pstate, BINOP_ADD); }
| AdditiveExpression '-' MultiplicativeExpression
- { write_exp_elt_opcode (BINOP_SUB); }
+ { write_exp_elt_opcode (pstate, BINOP_SUB); }
;
ShiftExpression:
AdditiveExpression
| ShiftExpression LSH AdditiveExpression
- { write_exp_elt_opcode (BINOP_LSH); }
+ { write_exp_elt_opcode (pstate, BINOP_LSH); }
| ShiftExpression RSH AdditiveExpression
- { write_exp_elt_opcode (BINOP_RSH); }
+ { write_exp_elt_opcode (pstate, BINOP_RSH); }
/* | ShiftExpression >>> AdditiveExpression { FIXME } */
;
RelationalExpression:
ShiftExpression
| RelationalExpression '<' ShiftExpression
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (pstate, BINOP_LESS); }
| RelationalExpression '>' ShiftExpression
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (pstate, BINOP_GTR); }
| RelationalExpression LEQ ShiftExpression
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_LEQ); }
| RelationalExpression GEQ ShiftExpression
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (pstate, BINOP_GEQ); }
/* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */
;
EqualityExpression:
RelationalExpression
| EqualityExpression EQUAL RelationalExpression
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
| EqualityExpression NOTEQUAL RelationalExpression
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
;
AndExpression:
EqualityExpression
| AndExpression '&' EqualityExpression
- { write_exp_elt_opcode (BINOP_BITWISE_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
;
ExclusiveOrExpression:
AndExpression
| ExclusiveOrExpression '^' AndExpression
- { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
;
InclusiveOrExpression:
ExclusiveOrExpression
| InclusiveOrExpression '|' ExclusiveOrExpression
- { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
+ { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
;
ConditionalAndExpression:
InclusiveOrExpression
| ConditionalAndExpression ANDAND InclusiveOrExpression
- { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
;
ConditionalOrExpression:
ConditionalAndExpression
| ConditionalOrExpression OROR ConditionalAndExpression
- { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
+ { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
;
ConditionalExpression:
ConditionalOrExpression
| ConditionalOrExpression '?' Expression ':' ConditionalExpression
- { write_exp_elt_opcode (TERNOP_COND); }
+ { write_exp_elt_opcode (pstate, TERNOP_COND); }
;
AssignmentExpression:
@@ -667,16 +680,16 @@ AssignmentExpression:
Assignment:
LeftHandSide '=' ConditionalExpression
- { write_exp_elt_opcode (BINOP_ASSIGN); }
+ { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
+ write_exp_elt_opcode (pstate, $2);
+ write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
;
LeftHandSide:
ForcedName
- { push_expression_name ($1); }
+ { push_expression_name (pstate, $1); }
| VARIABLE
/* Already written by write_dollar_variable. */
| FieldAccess
@@ -696,7 +709,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 *par_state, char *p, int len,
+ int parsed_float, YYSTYPE *putithere)
{
ULONGEST n = 0;
ULONGEST limit, limit_div_base;
@@ -717,16 +731,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 (par_state)->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 (par_state)->builtin_float;
else if (tolower (*suffix) == 'd')
putithere->typed_val_float.type =
- parse_type->builtin_double;
+ parse_type (par_state)->builtin_double;
else
return ERROR;
}
@@ -773,12 +787,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 (par_state)->builtin_long;
len--;
}
else
{
- type = parse_java_type->builtin_int;
+ type = parse_java_type (par_state)->builtin_int;
}
limit_div_base = limit / (ULONGEST) base;
@@ -803,11 +817,13 @@ 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 (par_state)->builtin_uint64 rather than
+ parse_java_type (par_state)->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 (par_state)->builtin_int
+ && n > (ULONGEST)0x80000000)
+ type = parse_type (par_state)->builtin_uint64;
putithere->typed_val_int.val = n;
putithere->typed_val_int.type = type;
@@ -905,12 +921,12 @@ yylex (void)
lexptr++;
c = *lexptr++;
if (c == '\\')
- c = parse_escape (parse_gdbarch, &lexptr);
+ c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
c = *lexptr++;
if (c != '\'')
@@ -1003,7 +1019,8 @@ yylex (void)
&& (*p < 'A' || *p > 'Z')))
break;
}
- toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
+ toktype = parse_number (pstate, tokstart, p - tokstart,
+ got_dot|got_e, &yylval);
if (toktype == ERROR)
{
char *err_copy = (char *) alloca (p - tokstart + 1);
@@ -1068,7 +1085,7 @@ yylex (void)
break;
case '\\':
tokptr++;
- c = parse_escape (parse_gdbarch, &tokptr);
+ c = parse_escape (parse_gdbarch (pstate), &tokptr);
if (c == -1)
{
continue;
@@ -1180,7 +1197,7 @@ yylex (void)
if (*tokstart == '$')
{
- write_dollar_variable (yylval.sval);
+ write_dollar_variable (pstate, yylval.sval);
return VARIABLE;
}
@@ -1191,13 +1208,23 @@ 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 (pstate, tokstart, namelen, 0, &newlval);
if (hextype == INTEGER_LITERAL)
return NAME_OR_INT;
}
return IDENTIFIER;
}
+int
+java_parse (struct parser_state *par_state)
+{
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ return _java_parse ();
+}
+
void
yyerror (char *msg)
{
@@ -1215,6 +1242,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;
@@ -1224,11 +1252,12 @@ java_type_from_name (struct stoken name)
Otherwise, return 0. */
static int
-push_variable (struct stoken name)
+push_variable (struct parser_state *par_state, 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)
@@ -1240,12 +1269,12 @@ push_variable (struct stoken name)
innermost_block = block_found;
}
- write_exp_elt_opcode (OP_VAR_VALUE);
+ write_exp_elt_opcode (par_state, 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 (par_state, NULL);
+ write_exp_elt_sym (par_state, sym);
+ write_exp_elt_opcode (par_state, OP_VAR_VALUE);
return 1;
}
if (is_a_field_of_this)
@@ -1255,11 +1284,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 (par_state, OP_THIS);
+ write_exp_elt_opcode (par_state, OP_THIS);
+ write_exp_elt_opcode (par_state, STRUCTOP_PTR);
+ write_exp_string (par_state, name);
+ write_exp_elt_opcode (par_state, STRUCTOP_PTR);
return 1;
}
return 0;
@@ -1270,7 +1299,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 *par_state, struct stoken name)
{
int i;
struct stoken token;
@@ -1281,9 +1310,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 (par_state, STRUCTOP_PTR);
+ write_exp_string (par_state, token);
+ write_exp_elt_opcode (par_state, STRUCTOP_PTR);
token.ptr += token.length + 1;
}
if (i >= name.length)
@@ -1295,7 +1324,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 *par_state,
+ struct stoken name, int dot_index)
{
struct stoken token;
char *tmp;
@@ -1304,11 +1334,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 (par_state, token))
{
token.ptr = name.ptr + dot_index + 1;
token.length = name.length - dot_index - 1;
- push_fieldnames (token);
+ push_fieldnames (par_state, token);
return;
}
@@ -1322,9 +1352,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 (par_state, OP_TYPE);
+ write_exp_elt_type (par_state, typ);
+ write_exp_elt_opcode (par_state, OP_TYPE);
return;
}
dot_index++; /* Skip '.' */
@@ -1335,16 +1365,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 (par_state, OP_SCOPE);
+ write_exp_elt_type (par_state, typ);
+ write_exp_string (par_state, token);
+ write_exp_elt_opcode (par_state, OP_SCOPE);
if (dot_index < name.length)
{
dot_index++;
name.ptr += dot_index;
name.length -= dot_index;
- push_fieldnames (name);
+ push_fieldnames (par_state, name);
}
return;
}
@@ -1361,7 +1391,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 *par_state, struct stoken name)
{
char *tmp;
struct type *typ;
@@ -1372,22 +1402,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 (par_state, name, i);
return;
}
}
/* It's a Simple Expression Name. */
- if (push_variable (name))
+ if (push_variable (par_state, 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 (par_state, OP_TYPE);
+ write_exp_elt_type (par_state, typ);
+ write_exp_elt_opcode (par_state, OP_TYPE);
}
else
{
@@ -1395,7 +1425,7 @@ push_expression_name (struct stoken name)
msymbol = lookup_minimal_symbol (tmp, NULL, NULL);
if (msymbol != NULL)
- write_exp_msymbol (msymbol);
+ write_exp_msymbol (par_state, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command"));
else
@@ -1419,6 +1449,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;
@@ -1428,27 +1459,19 @@ 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 *par_state, 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)));
- }
-
- {
- int i;
+ increase_expout_size (par_state, newlen);
- for (i = expout_ptr - 1; i >= pos; i--)
- expout->elts[i + newlen] = expout->elts[i];
- }
+ for (i = par_state->expout_ptr - 1; i >= pos; i--)
+ par_state->expout->elts[i + newlen] = par_state->expout->elts[i];
- memcpy (expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen));
- expout_ptr += newlen;
+ memcpy (par_state->expout->elts + pos, new->elts,
+ EXP_ELEM_TO_BYTES (newlen));
+ par_state->expout_ptr += newlen;
}
diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h
index 8ea9c3c..fe38f82 100644
--- a/gdb/jv-lang.h
+++ b/gdb/jv-lang.h
@@ -22,10 +22,11 @@
#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 (char *); /* Defined in jv-exp.y */
struct builtin_java_type
{
--
1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-02 19:34 ` [PATCH 03/10] C language Sergio Durigan Junior
@ 2012-06-04 4:25 ` Doug Evans
2012-06-04 4:32 ` Sergio Durigan Junior
2012-06-04 20:32 ` Tom Tromey
1 sibling, 1 reply; 40+ messages in thread
From: Doug Evans @ 2012-06-04 4:25 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, Tom Tromey
On Sat, Jun 2, 2012 at 12:32 PM, Sergio Durigan Junior
<sergiodj@redhat.com> wrote:
> @@ -2651,11 +2665,16 @@ yylex (void)
> }
>
> int
> -c_parse (void)
> +c_parse (struct parser_state *par_state)
> {
> int result;
> - struct cleanup *back_to = make_cleanup (free_current_contents,
> - &expression_macro_scope);
> + struct cleanup *back_to;
> +
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + back_to = make_cleanup (free_current_contents, &expression_macro_scope);
>
> /* Set up the scope for macro expansion. */
> expression_macro_scope = NULL;
IWBN to reset pstate back to NULL when done.
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 4:25 ` Doug Evans
@ 2012-06-04 4:32 ` Sergio Durigan Junior
0 siblings, 0 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-04 4:32 UTC (permalink / raw)
To: Doug Evans; +Cc: GDB Patches, Tom Tromey
On Monday, June 04 2012, Doug Evans wrote:
> On Sat, Jun 2, 2012 at 12:32 PM, Sergio Durigan Junior
> <sergiodj@redhat.com> wrote:
>> @@ -2651,11 +2665,16 @@ yylex (void)
>> }
>>
>> int
>> -c_parse (void)
>> +c_parse (struct parser_state *par_state)
>> {
>> int result;
>> - struct cleanup *back_to = make_cleanup (free_current_contents,
>> - &expression_macro_scope);
>> + struct cleanup *back_to;
>> +
>> + /* Setting up the parser state. */
>> + gdb_assert (par_state != NULL);
>> + pstate = par_state;
>> +
>> + back_to = make_cleanup (free_current_contents, &expression_macro_scope);
>>
>> /* Set up the scope for macro expansion. */
>> expression_macro_scope = NULL;
>
> IWBN to reset pstate back to NULL when done.
I did that in a first draft, but then removed it. I will fix it for
every patch, then (but won't resubmit all of them because that would be
worthless). Thanks.
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 01/10] Language independent bits
2012-06-02 19:33 ` [PATCH 01/10] Language independent bits Sergio Durigan Junior
@ 2012-06-04 20:20 ` Tom Tromey
2012-06-05 0:39 ` Sergio Durigan Junior
0 siblings, 1 reply; 40+ messages in thread
From: Tom Tromey @ 2012-06-04 20:20 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> This patch does a refactoring on gdb/{parse.c,parser-defs.h,language.*}
Sergio> in order to remove the `expout*' globals. I have created a new
Sergio> structure called `parser_state' which holds those variables per-parser,
Sergio> and eventually will hold all the global parser variables.
This one is ok.
Thanks for splitting the patches up like this.
It makes them easy to follow.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 02/10] SystemTap integration
2012-06-02 19:33 ` [PATCH 02/10] SystemTap integration Sergio Durigan Junior
@ 2012-06-04 20:23 ` Tom Tromey
0 siblings, 0 replies; 40+ messages in thread
From: Tom Tromey @ 2012-06-04 20:23 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> With the inclusion of the SystemTap integration patch, I had to create
Sergio> this other patch to make it compile with this refactoring. It simply
Sergio> uses the new field `pstate' present in `struct stap_parse_info'.
This is ok.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 06/10] Java language
2012-06-02 20:34 ` [PATCH 06/10] Java language Sergio Durigan Junior
@ 2012-06-04 20:27 ` Tom Tromey
2012-06-05 0:35 ` Sergio Durigan Junior
0 siblings, 1 reply; 40+ messages in thread
From: Tom Tromey @ 2012-06-04 20:27 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> -static void insert_exp (int, struct expression *);
Sergio> +static void insert_exp (struct parser_state *, int, struct expression *);
If you ever want to do another cleanup in this area, here's an
opportunity :)
IMNSHO language parsers should not be manipulating the expout data
structure like this. copy_exp is likewise naughty.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-02 19:34 ` [PATCH 03/10] C language Sergio Durigan Junior
2012-06-04 4:25 ` Doug Evans
@ 2012-06-04 20:32 ` Tom Tromey
2012-06-04 20:39 ` Sergio Durigan Junior
2012-06-04 20:42 ` Mark Kettenis
1 sibling, 2 replies; 40+ messages in thread
From: Tom Tromey @ 2012-06-04 20:32 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
Sergio> +#define yyparse _c_parse
It is pedantically better to avoid names with a leading underscore.
While it probably will never cause any problem in practice, I think it
is also just as easy to pick pedantically-correct names at the outset.
So, could you rename these to $LANG_parse_internal or something like that?
Sergio> - result = yyparse ();
Sergio> + result = _c_parse ();
I think you don't need to change this line.
From a spot check it appears these comments apply to all the other yacc
parsers in the series.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 00/10] Remove `expout*' globals from parser-defs.h
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
` (9 preceding siblings ...)
2012-06-02 20:34 ` [PATCH 06/10] Java language Sergio Durigan Junior
@ 2012-06-04 20:38 ` Tom Tromey
10 siblings, 0 replies; 40+ messages in thread
From: Tom Tromey @ 2012-06-04 20:38 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> I separated this series in 10 logical patches, but they are not
Sergio> independent from each other: you need all of them applied if you want to
Sergio> build and test.
I read through all of these.
Other than the few nits remaining for the language bits, it all seems good.
Thanks for doing this.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 20:32 ` Tom Tromey
@ 2012-06-04 20:39 ` Sergio Durigan Junior
2012-06-04 20:42 ` Mark Kettenis
1 sibling, 0 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-04 20:39 UTC (permalink / raw)
To: Tom Tromey; +Cc: GDB Patches
On Monday, June 04 2012, Tom Tromey wrote:
> Sergio> +#define yyparse _c_parse
>
> It is pedantically better to avoid names with a leading underscore.
> While it probably will never cause any problem in practice, I think it
> is also just as easy to pick pedantically-correct names at the outset.
>
> So, could you rename these to $LANG_parse_internal or something like
> that?
Yeah, some languages were already using $LANG_parse_internal. You're
right, I will use this pattern instead of _$LANG.
> Sergio> - result = yyparse ();
> Sergio> + result = _c_parse ();
>
> I think you don't need to change this line.
>
> From a spot check it appears these comments apply to all the other yacc
> parsers in the series.
Ok, I will revert all those changes to `yyparse' instead of `_$LANG'.
Thanks,
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 20:32 ` Tom Tromey
2012-06-04 20:39 ` Sergio Durigan Junior
@ 2012-06-04 20:42 ` Mark Kettenis
2012-06-04 20:49 ` Sergio Durigan Junior
1 sibling, 1 reply; 40+ messages in thread
From: Mark Kettenis @ 2012-06-04 20:42 UTC (permalink / raw)
To: tromey; +Cc: sergiodj, gdb-patches
> From: Tom Tromey <tromey@redhat.com>
> Date: Mon, 04 Jun 2012 14:31:47 -0600
>
> Sergio> +#define yyparse _c_parse
>
> It is pedantically better to avoid names with a leading underscore.
> While it probably will never cause any problem in practice, I think it
> is also just as easy to pick pedantically-correct names at the outset.
>
> So, could you rename these to $LANG_parse_internal or something like that?
I hesitated to bring it up, but when I was looking into using the yacc
-p option to get rid of the #defines, the underscored names posed a
problem.
So if you go through the trouble of renaming things, it might make
sense to use a consistent prefix ($LANG_) and give the wrappers
different names.
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 20:42 ` Mark Kettenis
@ 2012-06-04 20:49 ` Sergio Durigan Junior
2012-06-04 21:19 ` Mark Kettenis
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-04 20:49 UTC (permalink / raw)
To: Mark Kettenis; +Cc: tromey, gdb-patches
On Monday, June 04 2012, Mark Kettenis wrote:
> I hesitated to bring it up, but when I was looking into using the yacc
> -p option to get rid of the #defines, the underscored names posed a
> problem.
>
> So if you go through the trouble of renaming things, it might make
> sense to use a consistent prefix ($LANG_) and give the wrappers
> different names.
Do you mean what Tom meant (i.e., using `$LANG_parse_internal' instead of
`_$LANG_parse'), or a bigger change?
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 20:49 ` Sergio Durigan Junior
@ 2012-06-04 21:19 ` Mark Kettenis
2012-06-06 19:17 ` Tom Tromey
0 siblings, 1 reply; 40+ messages in thread
From: Mark Kettenis @ 2012-06-04 21:19 UTC (permalink / raw)
To: sergiodj; +Cc: tromey, gdb-patches
> From: Sergio Durigan Junior <sergiodj@redhat.com>
> Date: Mon, 04 Jun 2012 17:49:12 -0300
>
> On Monday, June 04 2012, Mark Kettenis wrote:
>
> > I hesitated to bring it up, but when I was looking into using the yacc
> > -p option to get rid of the #defines, the underscored names posed a
> > problem.
> >
> > So if you go through the trouble of renaming things, it might make
> > sense to use a consistent prefix ($LANG_) and give the wrappers
> > different names.
>
> Do you mean what Tom meant (i.e., using `$LANG_parse_internal' instead of
> `_$LANG_parse'), or a bigger change?
I guess a bigger change. If you do:
yacc -p c_ c-exp.c
you'll end up with a .c file that contains:
#define yyparse c_parse
but since c-exp.c already defines a function named c_parse, that
becomes problematic.
But I just realised that you can work around the problem, by doing
#undef yyparse
#define yyparse c_parse_internal
So never mind.
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 06/10] Java language
2012-06-04 20:27 ` Tom Tromey
@ 2012-06-05 0:35 ` Sergio Durigan Junior
2012-06-06 20:02 ` Tom Tromey
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-05 0:35 UTC (permalink / raw)
To: Tom Tromey; +Cc: GDB Patches
On Monday, June 04 2012, Tom Tromey wrote:
>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> -static void insert_exp (int, struct expression *);
> Sergio> +static void insert_exp (struct parser_state *, int, struct expression *);
>
> If you ever want to do another cleanup in this area, here's an
> opportunity :)
Great!
> IMNSHO language parsers should not be manipulating the expout data
> structure like this. copy_exp is likewise naughty.
Hm, do you have some idea here? Some kind of abstraction, like putting
these functions on gdb/{parser-defs.h,parse.c}, or something better?
Thanks,
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 01/10] Language independent bits
2012-06-04 20:20 ` Tom Tromey
@ 2012-06-05 0:39 ` Sergio Durigan Junior
0 siblings, 0 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-05 0:39 UTC (permalink / raw)
To: Tom Tromey; +Cc: GDB Patches
On Monday, June 04 2012, Tom Tromey wrote:
>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> This patch does a refactoring on gdb/{parse.c,parser-defs.h,language.*}
> Sergio> in order to remove the `expout*' globals. I have created a new
> Sergio> structure called `parser_state' which holds those variables per-parser,
> Sergio> and eventually will hold all the global parser variables.
>
> This one is ok.
Thanks. I'll wait until all the other patches are approved before I
commit all of them at once.
> Thanks for splitting the patches up like this.
> It makes them easy to follow.
My pleasure :-). I took the opportunity to play with `git send-email',
so it was good for me as well.
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* RE: [PATCH 09/10] Pascal language
2012-06-02 20:33 ` [PATCH 09/10] Pascal language Sergio Durigan Junior
@ 2012-06-05 7:39 ` Pierre Muller
0 siblings, 0 replies; 40+ messages in thread
From: Pierre Muller @ 2012-06-05 7:39 UTC (permalink / raw)
To: 'Sergio Durigan Junior', 'GDB Patches'
Cc: 'Tom Tromey'
As pascal language maintainer,
I looked at your patch.
It seems that this patch is pretty mechanical
given the changes to the parameter list of the used functions.
Thus you can consider this patch approved
with similar changes to the C counterpart.
Pierre Muller
GDB pascal language maintainer
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Sergio Durigan Junior
> Envoyé : samedi 2 juin 2012 21:32
> À : GDB Patches
> Cc : Tom Tromey; Sergio Durigan Junior
> Objet : [PATCH 09/10] Pascal language
>
> Patch for the Pascal language. Similar to the C language one.
>
> ---
> gdb/p-exp.y | 327
+++++++++++++++++++++++++++++++------------------------
> ---
> gdb/p-lang.h | 5 +-
> 2 files changed, 178 insertions(+), 154 deletions(-)
>
> diff --git a/gdb/p-exp.y b/gdb/p-exp.y
> index 5d344a4..43c4f30 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
> @@ -66,7 +66,7 @@
> generators need to be fixed instead of adding those names to this
list.
> */
>
> #define yymaxdepth pascal_maxdepth
> -#define yyparse pascal_parse
> +#define yyparse _pascal_parse
> #define yylex pascal_lex
> #define yyerror pascal_error
> #define yylval pascal_lval
> @@ -118,6 +118,11 @@
>
> #define YYFPRINTF parser_fprintf
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> int yyparse (void);
>
> static int yylex (void);
> @@ -158,7 +163,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;
> @@ -251,44 +256,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE);
> current_type = $1; } ;
>
> /* Expressions, including the comma operator. */
> exp1 : exp
> | exp1 ',' exp
> - { write_exp_elt_opcode (BINOP_COMMA); }
> + { write_exp_elt_opcode (pstate, BINOP_COMMA); }
> ;
>
> /* Expressions, not including the comma operator. */
> exp : exp '^' %prec UNARY
> - { write_exp_elt_opcode (UNOP_IND);
> + { write_exp_elt_opcode (pstate, 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 (pstate, 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 (pstate, UNOP_NEG); }
> ;
>
> exp : NOT exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> exp : INCREMENT '(' exp ')' %prec UNARY
> - { write_exp_elt_opcode (UNOP_PREINCREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT);
}
> ;
>
> exp : DECREMENT '(' exp ')' %prec UNARY
> - { write_exp_elt_opcode (UNOP_PREDECREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT);
}
> ;
>
>
> @@ -297,9 +302,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 (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $2);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> search_field = 0;
> if (current_type)
> {
> @@ -315,10 +320,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 (pstate);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $2);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> search_field = 0;
> if (current_type)
> {
> @@ -334,12 +339,12 @@ exp : field_exp name
>
> exp : field_exp COMPLETE
> { struct stoken s;
> - mark_struct_expression ();
> - write_exp_elt_opcode (STRUCTOP_STRUCT);
> + mark_struct_expression (pstate);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> s.ptr = "";
> s.length = 0;
> - write_exp_string (s);
> - write_exp_elt_opcode (STRUCTOP_STRUCT); }
> + write_exp_string (pstate, s);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> exp : exp '['
> @@ -357,14 +362,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 (pstate,
STRUCTOP_STRUCT);
> + write_exp_string (pstate, stringsval);
> + write_exp_elt_opcode (pstate,
STRUCTOP_STRUCT);
> }
> push_current_type (); }
> exp1 ']'
> { pop_current_type ();
> - write_exp_elt_opcode (BINOP_SUBSCRIPT);
> + write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT);
> if (current_type)
> current_type = TYPE_TARGET_TYPE (current_type);
}
> ;
> @@ -375,9 +380,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 (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate, (LONGEST)
end_arglist
> ());
> + write_exp_elt_opcode (pstate, OP_FUNCALL);
> pop_current_type ();
> if (current_type)
> current_type = TYPE_TARGET_TYPE (current_type);
> @@ -398,11 +403,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 (pstate, UNOP_IND);
> }
> - write_exp_elt_opcode (UNOP_CAST);
> - write_exp_elt_type ($1);
> - write_exp_elt_opcode (UNOP_CAST);
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> current_type = $1; }
> ;
>
> @@ -413,7 +418,7 @@ exp : '(' exp1 ')'
> /* Binary operators in order of decreasing precedence. */
>
> exp : exp '*' exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> exp : exp '/' {
> @@ -425,135 +430,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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate,
> + parse_type (pstate)
> + ->builtin_long_double);
> + current_type = parse_type (pstate)-
> >builtin_long_double;
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> leftdiv_is_integer = 0;
> }
>
> - write_exp_elt_opcode (BINOP_DIV);
> + write_exp_elt_opcode (pstate, BINOP_DIV);
> }
> ;
>
> exp : exp DIV exp
> - { write_exp_elt_opcode (BINOP_INTDIV); }
> + { write_exp_elt_opcode (pstate, BINOP_INTDIV); }
> ;
>
> exp : exp MOD exp
> - { write_exp_elt_opcode (BINOP_REM); }
> + { write_exp_elt_opcode (pstate, BINOP_REM); }
> ;
>
> exp : exp '+' exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> exp : exp '-' exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> exp : exp LSH exp
> - { write_exp_elt_opcode (BINOP_LSH); }
> + { write_exp_elt_opcode (pstate, BINOP_LSH); }
> ;
>
> exp : exp RSH exp
> - { write_exp_elt_opcode (BINOP_RSH); }
> + { write_exp_elt_opcode (pstate, BINOP_RSH); }
> ;
>
> exp : exp '=' exp
> - { write_exp_elt_opcode (BINOP_EQUAL);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp NOTEQUAL exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp LEQ exp
> - { write_exp_elt_opcode (BINOP_LEQ);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_LEQ);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp GEQ exp
> - { write_exp_elt_opcode (BINOP_GEQ);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_GEQ);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp '<' exp
> - { write_exp_elt_opcode (BINOP_LESS);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_LESS);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp '>' exp
> - { write_exp_elt_opcode (BINOP_GTR);
> - current_type = parse_type->builtin_bool;
> + { write_exp_elt_opcode (pstate, BINOP_GTR);
> + current_type = parse_type (pstate)->builtin_bool;
> }
> ;
>
> exp : exp ANDAND exp
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND);
}
> ;
>
> exp : exp XOR exp
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR);
}
> ;
>
> exp : exp OR exp
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR);
}
> ;
>
> exp : exp ASSIGN exp
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + current_type = parse_type (pstate)->builtin_bool;
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + current_type = parse_type (pstate)->builtin_bool;
> + write_exp_elt_opcode (pstate, OP_BOOL); }
> ;
>
> exp : INT
> - { write_exp_elt_opcode (OP_LONG);
> - write_exp_elt_type ($1.type);
> + { write_exp_elt_opcode (pstate, OP_LONG);
> + write_exp_elt_type (pstate, $1.type);
> current_type = $1.type;
> - write_exp_elt_longcst ((LONGEST)($1.val));
> - write_exp_elt_opcode (OP_LONG); }
> + write_exp_elt_longcst (pstate, (LONGEST)($1.val));
> + write_exp_elt_opcode (pstate, OP_LONG); }
> ;
>
> exp : NAME_OR_INT
> { YYSTYPE val;
> - parse_number ($1.stoken.ptr,
> + parse_number (pstate, $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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
val.typed_val_int.type);
> current_type = val.typed_val_int.type;
> - write_exp_elt_longcst ((LONGEST)
> + write_exp_elt_longcst (pstate, (LONGEST)
> val.typed_val_int.val);
> - write_exp_elt_opcode (OP_LONG);
> + write_exp_elt_opcode (pstate, OP_LONG);
> }
> ;
>
>
> exp : FLOAT
> - { write_exp_elt_opcode (OP_DOUBLE);
> - write_exp_elt_type ($1.type);
> + { write_exp_elt_opcode (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate, $1.type);
> current_type = $1.type;
> - write_exp_elt_dblcst ($1.dval);
> - write_exp_elt_opcode (OP_DOUBLE); }
> + write_exp_elt_dblcst (pstate, $1.dval);
> + write_exp_elt_opcode (pstate, OP_DOUBLE); }
> ;
>
> exp : variable
> @@ -566,7 +573,7 @@ exp : VARIABLE
> struct value * val, * mark;
>
> mark = value_mark ();
> - val = value_of_internalvar (parse_gdbarch,
> + val = value_of_internalvar (parse_gdbarch
(pstate),
> intvar);
> current_type = value_type (val);
> value_release_to_mark (mark);
> @@ -575,15 +582,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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)-
> >builtin_int);
> CHECK_TYPEDEF ($3);
> - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH
($3));
> - write_exp_elt_opcode (OP_LONG); }
> + write_exp_elt_longcst (pstate,
> + (LONGEST) TYPE_LENGTH
($3));
> + write_exp_elt_opcode (pstate, OP_LONG); }
> ;
>
> exp : SIZEOF '(' exp ')' %prec UNARY
> - { write_exp_elt_opcode (UNOP_SIZEOF); }
> + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
>
> exp : STRING
> { /* C strings are converted into array constants
with
> @@ -594,19 +602,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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_type (pstate)
> + ->builtin_char);
> + write_exp_elt_longcst (pstate, (LONGEST)
(*sp++));
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_type (pstate)
> + ->builtin_char);
> + write_exp_elt_longcst (pstate, (LONGEST)'\0');
> + write_exp_elt_opcode (pstate, OP_LONG);
> + write_exp_elt_opcode (pstate, OP_ARRAY);
> + write_exp_elt_longcst (pstate, (LONGEST) 0);
> + write_exp_elt_longcst (pstate, (LONGEST)
($1.length));
> + write_exp_elt_opcode (pstate, OP_ARRAY); }
> ;
>
> /* Object pascal */
> @@ -614,10 +626,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 (pstate, OP_THIS);
> + write_exp_elt_opcode (pstate, OP_THIS);
> /* We need type of this. */
> - this_val = value_of_this_silent (parse_language);
> + this_val = value_of_this_silent (parse_language
> (pstate));
> if (this_val)
> this_type = value_type (this_val);
> else
> @@ -627,7 +639,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 (pstate, UNOP_IND);
> }
> }
>
> @@ -673,11 +685,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 (pstate, 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 (pstate, block_found);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> ;
>
> qualified_name: typebase COLONCOLON name
> @@ -688,10 +700,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 (pstate, OP_SCOPE);
> + write_exp_elt_type (pstate, type);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, OP_SCOPE);
> }
> ;
>
> @@ -707,16 +719,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 (pstate, OP_VAR_VALUE);
> + write_exp_elt_block (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> break;
> }
>
> msymbol = lookup_minimal_symbol (name, NULL,
NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols ()
> && !have_partial_symbols ())
> error (_("No symbol table is loaded. "
> @@ -740,13 +752,13 @@ variable: name_not_typename
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> current_type = sym->type; }
> else if ($1.is_a_field_of_this)
> {
> @@ -759,13 +771,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 (pstate, OP_THIS);
> + write_exp_elt_opcode (pstate, OP_THIS);
> + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> + write_exp_string (pstate, $1.stoken);
> + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> /* We need type of this. */
> - this_val = value_of_this_silent
(parse_language);
> + this_val = value_of_this_silent
(parse_language
> (pstate));
> if (this_val)
> this_type = value_type (this_val);
> else
> @@ -785,7 +797,7 @@ variable: name_not_typename
> msymbol =
> lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols ()
> && !have_partial_symbols ())
> error (_("No symbol table is loaded. "
> @@ -854,7 +866,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 *par_state, 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. */
> @@ -879,7 +892,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 (par_state), p, len,
> &putithere->typed_val_float.dval,
> &putithere->typed_val_float.type))
> return ERROR;
> @@ -985,9 +998,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 (par_state)) - 2)) == 0)
> {
> - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
> + high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch
> (par_state)) - 1);
>
> /* A large decimal (not hex or octal) constant (between INT_MAX
> and UINT_MAX) is a long or unsigned long, according to ANSI,
> @@ -995,28 +1008,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 (par_state)->builtin_unsigned_int;
> + signed_type = parse_type (par_state)->builtin_int;
> }
> else if (long_p <= 1
> - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
> + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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
> (par_state)) - 1);
> + unsigned_type = parse_type (par_state)->builtin_unsigned_long;
> + signed_type = parse_type (par_state)->builtin_long;
> }
> else
> {
> int shift;
> if (sizeof (ULONGEST) * HOST_CHAR_BIT
> - < gdbarch_long_long_bit (parse_gdbarch))
> + < gdbarch_long_long_bit (parse_gdbarch (par_state)))
> /* 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 (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
> + signed_type = parse_type (par_state)->builtin_long_long;
> }
>
> putithere->typed_val_int.val = n;
> @@ -1190,12 +1203,12 @@ yylex (void)
> lexptr++;
> c = *lexptr++;
> if (c == '\\')
> - c = parse_escape (parse_gdbarch, &lexptr);
> + c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
>
> c = *lexptr++;
> if (c != '\'')
> @@ -1295,7 +1308,7 @@ yylex (void)
> && (*p < 'A' || *p > 'Z')))
> break;
> }
> - toktype = parse_number (tokstart,
> + toktype = parse_number (pstate, tokstart,
> p - tokstart, got_dot | got_e, &yylval);
> if (toktype == ERROR)
> {
> @@ -1362,7 +1375,7 @@ yylex (void)
> break;
> case '\\':
> tokptr++;
> - c = parse_escape (parse_gdbarch, &tokptr);
> + c = parse_escape (parse_gdbarch (pstate), &tokptr);
> if (c == -1)
> {
> continue;
> @@ -1504,7 +1517,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 (pstate, yylval.sval);
> c = tokstart[namelen];
> tokstart[namelen] = 0;
> intvar = lookup_only_internalvar (++tokstart);
> @@ -1702,8 +1715,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 (pstate),
> + parse_gdbarch (pstate),
tmp);
> if (yylval.tsym.type != NULL)
> {
> free (uptokstart);
> @@ -1718,7 +1731,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 (pstate, tokstart, namelen, 0, &newlval);
> if (hextype == INT)
> {
> yylval.ssym.sym = sym;
> @@ -1736,6 +1749,16 @@ yylex (void)
> }
> }
>
> +int
> +pascal_parse (struct parser_state *par_state)
> +{
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + return _pascal_parse ();
> +}
> +
> void
> yyerror (char *msg)
> {
> diff --git a/gdb/p-lang.h b/gdb/p-lang.h
> index b1e218c..a5168f8 100644
> --- a/gdb/p-lang.h
> +++ b/gdb/p-lang.h
> @@ -20,13 +20,14 @@
> /* 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 (char *); /* Defined in p-exp.y */
>
> /* Defined in p-typeprint.c */
> extern void pascal_print_type (struct type *, const char *, struct
ui_file
> *,
> --
> 1.7.7.6
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 03/10] C language
2012-06-04 21:19 ` Mark Kettenis
@ 2012-06-06 19:17 ` Tom Tromey
0 siblings, 0 replies; 40+ messages in thread
From: Tom Tromey @ 2012-06-06 19:17 UTC (permalink / raw)
To: Mark Kettenis; +Cc: sergiodj, gdb-patches
>>>>> "Mark" == Mark Kettenis <mark.kettenis@xs4all.nl> writes:
Mark> yacc -p c_ c-exp.c
[...]
Mark> But I just realised that you can work around the problem, by doing
Mark> #undef yyparse
Mark> #define yyparse c_parse_internal
We can also rename the exported functions instead.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 06/10] Java language
2012-06-05 0:35 ` Sergio Durigan Junior
@ 2012-06-06 20:02 ` Tom Tromey
2012-06-07 0:57 ` Joel Brobecker
0 siblings, 1 reply; 40+ messages in thread
From: Tom Tromey @ 2012-06-06 20:02 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Tom> IMNSHO language parsers should not be manipulating the expout data
Tom> structure like this. copy_exp is likewise naughty.
Sergio> Hm, do you have some idea here? Some kind of abstraction, like putting
Sergio> these functions on gdb/{parser-defs.h,parse.c}, or something better?
I think that accessors and mutators for a data structure should all live
in one place. Spreading them out makes it harder to find them all when
doing refactorings. (In many cases you can rely on the compiler to
catch problems -- but you can still have planning difficulties due to
not seeing the code).
In the longer term, I think struct expression is just a crazy,
old-school data structure that should be replaced with something more
straightforward, even at the expense of using more memory.
I think the reason it has stayed this way so long is that the
cost/benefit for changing it is pretty low. This could be said of many
of the goofier areas of gdb.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 06/10] Java language
2012-06-06 20:02 ` Tom Tromey
@ 2012-06-07 0:57 ` Joel Brobecker
0 siblings, 0 replies; 40+ messages in thread
From: Joel Brobecker @ 2012-06-07 0:57 UTC (permalink / raw)
To: Tom Tromey; +Cc: Sergio Durigan Junior, GDB Patches
> In the longer term, I think struct expression is just a crazy,
> old-school data structure that should be replaced with something more
> straightforward, even at the expense of using more memory.
Hallelujah!
--
Joel
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 04/10] Ada language.
2012-06-02 20:23 ` [PATCH 04/10] Ada language Sergio Durigan Junior
@ 2012-06-13 4:57 ` Sergio Durigan Junior
2012-06-13 14:50 ` Joel Brobecker
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-13 4:57 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Joel Brobecker
On Saturday, June 02 2012, I wrote:
> Patch for the Ada language. This one is a bit different than the other
> patches because it uses its own lexer, so I had to hack it too.
Ping.
Joel, I know these changed are rather mechanical, but would you like to
take a look and see what you think?
Thanks,
>
> ---
> gdb/ada-exp.y | 474 +++++++++++++++++++++++++++++---------------------------
> gdb/ada-lang.c | 4 +-
> gdb/ada-lang.h | 3 +-
> gdb/ada-lex.l | 54 ++++---
> 4 files changed, 282 insertions(+), 253 deletions(-)
>
> diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
> index 1a80b0b..3c62187 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,6 +114,11 @@ struct name_info {
> struct stoken stoken;
> };
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> static struct stoken empty_stoken = { "", 0 };
>
> /* If expression is in the context of TYPE'(...), then TYPE, else
> @@ -128,40 +133,44 @@ void yyerror (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 *);
>
> %}
>
> @@ -237,25 +246,25 @@ start : exp1
> /* Expressions, including the sequencing operator. */
> exp1 : exp
> | exp1 ';' exp
> - { write_exp_elt_opcode (BINOP_COMMA); }
> + { write_exp_elt_opcode (pstate, BINOP_COMMA); }
> | primary ASSIGN exp /* Extension for convenience */
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
> ;
>
> /* Expressions, not including the sequencing operator. */
> primary : primary DOT_ALL
> - { write_exp_elt_opcode (UNOP_IND); }
> + { write_exp_elt_opcode (pstate, UNOP_IND); }
> ;
>
> primary : primary DOT_ID
> - { write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
> + { write_exp_op_with_string (pstate, 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 (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate, $3);
> + write_exp_elt_opcode (pstate, OP_FUNCALL);
> }
> | var_or_type '(' arglist ')'
> {
> @@ -263,15 +272,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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> }
> else
> {
> - write_exp_elt_opcode (OP_FUNCALL);
> - write_exp_elt_longcst ($3);
> - write_exp_elt_opcode (OP_FUNCALL);
> + write_exp_elt_opcode (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate, $3);
> + write_exp_elt_opcode (pstate, OP_FUNCALL);
> }
> }
> ;
> @@ -281,9 +290,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 (pstate, UNOP_QUAL);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, UNOP_QUAL);
> type_qualifier = $3;
> }
> ;
> @@ -293,10 +302,10 @@ save_qualifier : { $$ = type_qualifier; }
>
> primary :
> primary '(' simple_exp DOTDOT simple_exp ')'
> - { write_exp_elt_opcode (TERNOP_SLICE); }
> + { write_exp_elt_opcode (pstate, TERNOP_SLICE); }
> | var_or_type '(' simple_exp DOTDOT simple_exp ')'
> { if ($1 == NULL)
> - write_exp_elt_opcode (TERNOP_SLICE);
> + write_exp_elt_opcode (pstate, TERNOP_SLICE);
> else
> error (_("Cannot slice a type"));
> }
> @@ -316,15 +325,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE);
> }
> }
> ;
>
> primary : SPECIAL_VARIABLE /* Various GDB extensions */
> - { write_dollar_variable ($1); }
> + { write_dollar_variable (pstate, $1); }
> ;
>
> primary : aggregate
> @@ -334,19 +343,19 @@ simple_exp : primary
> ;
>
> simple_exp : '-' simple_exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_NEG); }
> + { write_exp_elt_opcode (pstate, UNOP_NEG); }
> ;
>
> simple_exp : '+' simple_exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_PLUS); }
> + { write_exp_elt_opcode (pstate, UNOP_PLUS); }
> ;
>
> simple_exp : NOT simple_exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> simple_exp : ABS simple_exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_ABS); }
> + { write_exp_elt_opcode (pstate, UNOP_ABS); }
> ;
>
> arglist : { $$ = 0; }
> @@ -367,111 +376,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 (pstate, UNOP_MEMVAL);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, BINOP_EXP); }
> ;
>
> simple_exp : simple_exp '*' simple_exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> simple_exp : simple_exp '/' simple_exp
> - { write_exp_elt_opcode (BINOP_DIV); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_REM); }
> ;
>
> simple_exp : simple_exp MOD simple_exp
> - { write_exp_elt_opcode (BINOP_MOD); }
> + { write_exp_elt_opcode (pstate, BINOP_MOD); }
> ;
>
> simple_exp : simple_exp '@' simple_exp /* GDB extension */
> - { write_exp_elt_opcode (BINOP_REPEAT); }
> + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> ;
>
> simple_exp : simple_exp '+' simple_exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> simple_exp : simple_exp '&' simple_exp
> - { write_exp_elt_opcode (BINOP_CONCAT); }
> + { write_exp_elt_opcode (pstate, BINOP_CONCAT); }
> ;
>
> simple_exp : simple_exp '-' simple_exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> relation : simple_exp
> ;
>
> relation : simple_exp '=' simple_exp
> - { write_exp_elt_opcode (BINOP_EQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> ;
>
> relation : simple_exp NOTEQUAL simple_exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> ;
>
> relation : simple_exp LEQ simple_exp
> - { write_exp_elt_opcode (BINOP_LEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> ;
>
> relation : simple_exp IN simple_exp DOTDOT simple_exp
> - { write_exp_elt_opcode (TERNOP_IN_RANGE); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_IN_BOUNDS);
> + write_exp_elt_longcst (pstate, (LONGEST) $5);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_IN_RANGE);
> + write_exp_elt_type (pstate, $3);
> + write_exp_elt_opcode (pstate, 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 (pstate, TERNOP_IN_RANGE);
> + write_exp_elt_opcode (pstate, 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 (pstate, BINOP_IN_BOUNDS);
> + write_exp_elt_longcst (pstate, (LONGEST) $6);
> + write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_IN_RANGE);
> + write_exp_elt_type (pstate, $4);
> + write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
> + write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT);
> }
> ;
>
> relation : simple_exp GEQ simple_exp
> - { write_exp_elt_opcode (BINOP_GEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> ;
>
> relation : simple_exp '<' simple_exp
> - { write_exp_elt_opcode (BINOP_LESS); }
> + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> ;
>
> relation : simple_exp '>' simple_exp
> - { write_exp_elt_opcode (BINOP_GTR); }
> + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> ;
>
> exp : relation
> @@ -484,36 +493,36 @@ exp : relation
>
> and_exp :
> relation _AND_ relation
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> | and_exp _AND_ relation
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> ;
>
> and_then_exp :
> relation _AND_ THEN relation
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> | and_then_exp _AND_ THEN relation
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> ;
>
> or_exp :
> relation OR relation
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> | or_exp OR relation
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> ;
>
> or_else_exp :
> relation OR ELSE relation
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> | or_else_exp OR ELSE relation
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> ;
>
> xor_exp : relation XOR relation
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> | xor_exp XOR relation
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> ;
>
> /* Primaries can denote types (OP_TYPE). In cases such as
> @@ -525,36 +534,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 (pstate, 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 (pstate, UNOP_ADDR);
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, type_system_address (pstate));
> + write_exp_elt_opcode (pstate, UNOP_CAST);
> }
> | primary TICK_FIRST tick_arglist
> - { write_int ($3, type_int ());
> - write_exp_elt_opcode (OP_ATR_FIRST); }
> + { write_int (pstate, $3, type_int (pstate));
> + write_exp_elt_opcode (pstate, OP_ATR_FIRST); }
> | primary TICK_LAST tick_arglist
> - { write_int ($3, type_int ());
> - write_exp_elt_opcode (OP_ATR_LAST); }
> + { write_int (pstate, $3, type_int (pstate));
> + write_exp_elt_opcode (pstate, OP_ATR_LAST); }
> | primary TICK_LENGTH tick_arglist
> - { write_int ($3, type_int ());
> - write_exp_elt_opcode (OP_ATR_LENGTH); }
> + { write_int (pstate, $3, type_int (pstate));
> + write_exp_elt_opcode (pstate, OP_ATR_LENGTH); }
> | primary TICK_SIZE
> - { write_exp_elt_opcode (OP_ATR_SIZE); }
> + { write_exp_elt_opcode (pstate, OP_ATR_SIZE); }
> | primary TICK_TAG
> - { write_exp_elt_opcode (OP_ATR_TAG); }
> + { write_exp_elt_opcode (pstate, OP_ATR_TAG); }
> | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
> - { write_exp_elt_opcode (OP_ATR_MIN); }
> + { write_exp_elt_opcode (pstate, OP_ATR_MIN); }
> | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
> - { write_exp_elt_opcode (OP_ATR_MAX); }
> + { write_exp_elt_opcode (pstate, OP_ATR_MAX); }
> | opt_type_prefix TICK_POS '(' exp ')'
> - { write_exp_elt_opcode (OP_ATR_POS); }
> + { write_exp_elt_opcode (pstate, OP_ATR_POS); }
> | type_prefix TICK_VAL '(' exp ')'
> - { write_exp_elt_opcode (OP_ATR_VAL); }
> + { write_exp_elt_opcode (pstate, OP_ATR_VAL); }
> | type_prefix TICK_MODULUS
> - { write_exp_elt_opcode (OP_ATR_MODULUS); }
> + { write_exp_elt_opcode (pstate, OP_ATR_MODULUS); }
> ;
>
> tick_arglist : %prec '('
> @@ -568,53 +577,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate,
> + parse_type (pstate)->builtin_void);
> + write_exp_elt_opcode (pstate, OP_TYPE); }
> ;
>
>
> primary : INT
> - { write_int ((LONGEST) $1.val, $1.type); }
> + { write_int (pstate, (LONGEST) $1.val, $1.type); }
> ;
>
> primary : CHARLIT
> - { write_int (convert_char_literal (type_qualifier, $1.val),
> + { write_int (pstate,
> + 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 (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_dblcst (pstate, $1.dval);
> + write_exp_elt_opcode (pstate, OP_DOUBLE);
> }
> ;
>
> primary : NULL_PTR
> - { write_int (0, type_int ()); }
> + { write_int (pstate, 0, type_int (pstate)); }
> ;
>
> primary : STRING
> {
> - write_exp_op_with_string (OP_STRING, $1);
> + write_exp_op_with_string (pstate, OP_STRING, $1);
> }
> ;
>
> primary : TRUEKEYWORD
> - { write_int (1, type_boolean ()); }
> + { write_int (pstate, 1, type_boolean (pstate)); }
> | FALSEKEYWORD
> - { write_int (0, type_boolean ()); }
> + { write_int (pstate, 0, type_boolean (pstate)); }
> ;
>
> primary : NEW NAME
> @@ -622,22 +633,22 @@ primary : NEW NAME
> ;
>
> var_or_type: NAME %prec VAR
> - { $$ = write_var_or_type (NULL, $1); }
> + { $$ = write_var_or_type (pstate, NULL, $1); }
> | block NAME %prec VAR
> - { $$ = write_var_or_type ($1, $2); }
> + { $$ = write_var_or_type (pstate, $1, $2); }
> | NAME TICK_ACCESS
> {
> - $$ = write_var_or_type (NULL, $1);
> + $$ = write_var_or_type (pstate, NULL, $1);
> if ($$ == NULL)
> - write_exp_elt_opcode (UNOP_ADDR);
> + write_exp_elt_opcode (pstate, UNOP_ADDR);
> else
> $$ = lookup_pointer_type ($$);
> }
> | block NAME TICK_ACCESS
> {
> - $$ = write_var_or_type ($1, $2);
> + $$ = write_var_or_type (pstate, $1, $2);
> if ($$ == NULL)
> - write_exp_elt_opcode (UNOP_ADDR);
> + write_exp_elt_opcode (pstate, UNOP_ADDR);
> else
> $$ = lookup_pointer_type ($$);
> }
> @@ -653,18 +664,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 (pstate, OP_AGGREGATE);
> + write_exp_elt_longcst (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_POSITIONAL);
> + write_exp_elt_longcst (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_POSITIONAL);
> $$ = $1 + 1;
> }
> | positional_list component_groups
> @@ -673,15 +684,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 (pstate, OP_POSITIONAL);
> + write_exp_elt_longcst (pstate, 0);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_POSITIONAL);
> + write_exp_elt_longcst (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_POSITIONAL);
> $$ = $1 + 1;
> }
> ;
> @@ -694,15 +705,15 @@ component_groups:
> ;
>
> others : OTHERS ARROW exp
> - { write_exp_elt_opcode (OP_OTHERS); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, OP_CHOICES);
> + write_exp_elt_longcst (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_CHOICES);
> }
> ;
>
> @@ -713,22 +724,22 @@ component_group :
> resolved shift/reduce conflict. */
> component_associations :
> NAME ARROW
> - { write_name_assoc ($1); }
> + { write_name_assoc (pstate, $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 (pstate, OP_DISCRETE_RANGE);
> + write_exp_op_with_string (pstate, OP_NAME, empty_stoken);
> }
> exp { $$ = 1; }
> | NAME '|'
> - { write_name_assoc ($1); }
> + { write_name_assoc (pstate, $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 (pstate, OP_DISCRETE_RANGE); }
> component_associations { $$ = $6 + 1; }
> ;
>
> @@ -736,11 +747,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 (pstate, UNOP_IND); }
> | '&' primary %prec '.'
> - { write_exp_elt_opcode (UNOP_ADDR); }
> + { write_exp_elt_opcode (pstate, UNOP_ADDR); }
> | primary '[' exp ']'
> - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> ;
>
> %%
> @@ -771,8 +782,12 @@ static struct obstack temp_parse_space;
> #include "ada-lex.c"
>
> int
> -ada_parse (void)
> +ada_parse (struct parser_state *par_state)
> {
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> lexer_init (yyin); /* (Re-)initialize lexer. */
> type_qualifier = NULL;
> obstack_free (&temp_parse_space, NULL);
> @@ -818,7 +833,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 *par_state,
> + struct block *orig_left_context,
> struct block *block,
> struct symbol *sym)
> {
> @@ -829,30 +845,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 (par_state, OP_VAR_VALUE);
> + write_exp_elt_block (par_state, block);
> + write_exp_elt_sym (par_state, sym);
> + write_exp_elt_opcode (par_state, 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 *par_state, 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 (par_state, OP_LONG);
> + write_exp_elt_type (par_state, type);
> + write_exp_elt_longcst (par_state, arg);
> + write_exp_elt_opcode (par_state, 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 *par_state,
> + 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 (par_state, opcode);
> + write_exp_string (par_state, token);
> + write_exp_elt_opcode (par_state, opcode);
> }
>
> /* Emit expression corresponding to the renamed object named
> @@ -867,7 +884,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 *par_state,
> + struct block *orig_left_context,
> const char *renamed_entity, int renamed_entity_len,
> const char *renaming_expr, int max_depth)
> {
> @@ -900,10 +918,11 @@ write_object_renaming (struct block *orig_left_context,
> &inner_renaming_expr))
> {
> case ADA_NOT_RENAMING:
> - write_var_from_sym (orig_left_context, sym_info.block, sym_info.sym);
> + write_var_from_sym (par_state, orig_left_context, sym_info.block,
> + sym_info.sym);
> break;
> case ADA_OBJECT_RENAMING:
> - write_object_renaming (sym_info.block,
> + write_object_renaming (par_state, sym_info.block,
> inner_renamed_entity, inner_renamed_entity_len,
> inner_renaming_expr, max_depth - 1);
> break;
> @@ -920,7 +939,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 (par_state, UNOP_IND);
> break;
> case 'L':
> slice_state = LOWER_BOUND;
> @@ -934,10 +953,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 (par_state, OP_LONG);
> + write_exp_elt_type (par_state, type_int (par_state));
> + write_exp_elt_longcst (par_state, (LONGEST) val);
> + write_exp_elt_opcode (par_state, OP_LONG);
> }
> else
> {
> @@ -961,20 +980,20 @@ write_object_renaming (struct block *orig_left_context,
> else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF)
> /* Index is an old-style renaming symbol. */
> index_sym_info.block = orig_left_context;
> - write_var_from_sym (NULL, index_sym_info.block,
> + write_var_from_sym (par_state, NULL, index_sym_info.block,
> index_sym_info.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 (par_state, OP_FUNCALL);
> + write_exp_elt_longcst (par_state, (LONGEST) 1);
> + write_exp_elt_opcode (par_state, 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 (par_state, TERNOP_SLICE);
> slice_state = SIMPLE_INDEX;
> }
> break;
> @@ -995,7 +1014,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 (par_state, STRUCTOP_STRUCT, field_name);
> break;
> }
>
> @@ -1084,14 +1103,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 *par_state, 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 (par_state),
> + parse_gdbarch (par_state),
> name);
> if (type == NULL && strcmp ("system__address", name) == 0)
> - type = type_system_address ();
> + type = type_system_address (par_state);
>
> if (type != NULL)
> {
> @@ -1140,7 +1159,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 *par_state, char *sels)
> {
> while (*sels != '\0')
> {
> @@ -1152,7 +1171,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 (par_state, STRUCTOP_STRUCT, field_name);
> }
> }
>
> @@ -1161,7 +1180,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 *par_state, struct block *block,
> + char *name, int len)
> {
> struct symbol *sym =
> obstack_alloc (&temp_parse_space, sizeof (struct symbol));
> @@ -1170,10 +1190,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 (par_state, OP_VAR_VALUE);
> + write_exp_elt_block (par_state, block);
> + write_exp_elt_sym (par_state, sym);
> + write_exp_elt_opcode (par_state, OP_VAR_VALUE);
> }
>
> /* A convenient wrapper around ada_get_field_index that takes
> @@ -1253,7 +1273,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 *par_state, struct block *block,
> + struct stoken name0)
> {
> int depth;
> char *encoded_name;
> @@ -1327,9 +1348,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 (par_state, block, renaming, renaming_len,
> renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
> - write_selectors (encoded_name + tail_index);
> + write_selectors (par_state, encoded_name + tail_index);
> return NULL;
> default:
> internal_error (__FILE__, __LINE__,
> @@ -1356,7 +1377,8 @@ 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 (par_state,
> + encoded_name);
>
> if (type != NULL)
> return type;
> @@ -1364,8 +1386,9 @@ 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 (par_state, block, syms[0].block,
> + syms[0].sym);
> + write_selectors (par_state, encoded_name + tail_index);
> return NULL;
> }
> else if (nsyms == 0)
> @@ -1374,9 +1397,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 (par_state, msym);
> /* Maybe cause error here rather than later? FIXME? */
> - write_selectors (encoded_name + tail_index);
> + write_selectors (par_state, encoded_name + tail_index);
> return NULL;
> }
>
> @@ -1389,8 +1412,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 (par_state, block, encoded_name, tail_index);
> + write_selectors (par_state, encoded_name + tail_index);
> return NULL;
> }
> }
> @@ -1425,7 +1448,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 *par_state, struct stoken name)
> {
> if (strchr (name.ptr, '.') == NULL)
> {
> @@ -1433,12 +1456,12 @@ write_name_assoc (struct stoken name)
> int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
> VAR_DOMAIN, &syms, 1);
> if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
> - write_exp_op_with_string (OP_NAME, name);
> + write_exp_op_with_string (par_state, OP_NAME, name);
> else
> - write_var_from_sym (NULL, syms[0].block, syms[0].sym);
> + write_var_from_sym (par_state, NULL, syms[0].block, syms[0].sym);
> }
> else
> - if (write_var_or_type (NULL, name) != NULL)
> + if (write_var_or_type (par_state, NULL, name) != NULL)
> error (_("Invalid use of type."));
> }
>
> @@ -1469,61 +1492,62 @@ convert_char_literal (struct type *type, LONGEST val)
> }
>
> static struct type *
> -type_int (void)
> +type_int (struct parser_state *par_state)
> {
> - return parse_type->builtin_int;
> + return parse_type (par_state)->builtin_int;
> }
>
> static struct type *
> -type_long (void)
> +type_long (struct parser_state *par_state)
> {
> - return parse_type->builtin_long;
> + return parse_type (par_state)->builtin_long;
> }
>
> static struct type *
> -type_long_long (void)
> +type_long_long (struct parser_state *par_state)
> {
> - return parse_type->builtin_long_long;
> + return parse_type (par_state)->builtin_long_long;
> }
>
> static struct type *
> -type_float (void)
> +type_float (struct parser_state *par_state)
> {
> - return parse_type->builtin_float;
> + return parse_type (par_state)->builtin_float;
> }
>
> static struct type *
> -type_double (void)
> +type_double (struct parser_state *par_state)
> {
> - return parse_type->builtin_double;
> + return parse_type (par_state)->builtin_double;
> }
>
> static struct type *
> -type_long_double (void)
> +type_long_double (struct parser_state *par_state)
> {
> - return parse_type->builtin_long_double;
> + return parse_type (par_state)->builtin_long_double;
> }
>
> static struct type *
> -type_char (void)
> +type_char (struct parser_state *par_state)
> {
> - return language_string_char_type (parse_language, parse_gdbarch);
> + return language_string_char_type (parse_language (par_state),
> + parse_gdbarch (par_state));
> }
>
> static struct type *
> -type_boolean (void)
> +type_boolean (struct parser_state *par_state)
> {
> - return parse_type->builtin_bool;
> + return parse_type (par_state)->builtin_bool;
> }
>
> static struct type *
> -type_system_address (void)
> +type_system_address (struct parser_state *par_state)
> {
> struct type *type
> - = language_lookup_primitive_type_by_name (parse_language,
> - parse_gdbarch,
> + = language_lookup_primitive_type_by_name (parse_language (par_state),
> + parse_gdbarch (par_state),
> "system__address");
> - return type != NULL ? type : parse_type->builtin_data_ptr;
> + return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
> }
>
> /* Provide a prototype to silence -Wmissing-prototypes. */
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index af0fdb5..a6308cf 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -12464,10 +12464,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 9a93c50..1b172d4 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"
> @@ -157,7 +158,7 @@ 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 */
>
> diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
> index 714265e..f0e2369 100644
> --- a/gdb/ada-lex.l
> +++ b/gdb/ada-lex.l
> @@ -49,8 +49,9 @@ 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 *);
> @@ -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 (pstate, NULL, numbuf,
> + strrchr (numbuf, 'e') + 1);
> }
>
> {NUM10} {
> canonicalizeNumeral (numbuf, yytext);
> - return processInt (NULL, numbuf, NULL);
> + return processInt (pstate, NULL, numbuf, NULL);
> }
>
> {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} {
> canonicalizeNumeral (numbuf, yytext);
> - return processInt (numbuf,
> + return processInt (pstate, numbuf,
> strchr (numbuf, '#') + 1,
> strrchr(numbuf, '#') + 1);
> }
>
> {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
> canonicalizeNumeral (numbuf, yytext);
> - return processInt (numbuf, strchr (numbuf, '#') + 1, NULL);
> + return processInt (pstate, numbuf, strchr (numbuf, '#') + 1,
> + NULL);
> }
>
> "0x"{HEXDIG}+ {
> canonicalizeNumeral (numbuf, yytext+2);
> - return processInt ("16#", numbuf, NULL);
> + return processInt (pstate, "16#", numbuf, NULL);
> }
>
>
> {NUM10}"."{NUM10}{EXP} {
> canonicalizeNumeral (numbuf, yytext);
> - return processReal (numbuf);
> + return processReal (pstate, numbuf);
> }
>
> {NUM10}"."{NUM10} {
> canonicalizeNumeral (numbuf, yytext);
> - return processReal (numbuf);
> + return processReal (pstate, 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 (pstate);
> 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 (pstate);
> 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 *par_state, 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 (par_state))-1)) == 0)
> + yylval.typed_val.type = type_int (par_state);
> + else if ((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-1)) == 0)
> + yylval.typed_val.type = type_long (par_state);
> + else if (((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-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 (par_state))->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 (par_state);
>
> yylval.typed_val.val = (LONGEST) result;
> return INT;
> }
>
> static int
> -processReal (const char *num0)
> +processReal (struct parser_state *par_state, 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 (par_state);
> + if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch (par_state))
> / 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 (par_state);
> + if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch (par_state))
> / TARGET_CHAR_BIT)
> - yylval.typed_val_float.type = type_long_double ();
> + yylval.typed_val_float.type = type_long_double (par_state);
>
> return FLOAT;
> }
> --
> 1.7.7.6
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 10/10] Go programming language
2012-06-02 20:23 ` [PATCH 10/10] Go programming language Sergio Durigan Junior
@ 2012-06-13 4:58 ` Sergio Durigan Junior
2012-06-13 17:02 ` Doug Evans
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-13 4:58 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey, Doug Evans
On Saturday, June 02 2012, I wrote:
> Patch for the Go programming language. Similar to the C language one.
Ping.
Doug, since you have put this code in, would you like to take a look
just to be safe?
Thanks,
>
> ---
> gdb/go-exp.y | 268 +++++++++++++++++++++++++++++++--------------------------
> gdb/go-lang.h | 4 +-
> 2 files changed, 148 insertions(+), 124 deletions(-)
>
> diff --git a/gdb/go-exp.y b/gdb/go-exp.y
> index c3171c3..7e02283 100644
> --- a/gdb/go-exp.y
> +++ b/gdb/go-exp.y
> @@ -66,7 +66,7 @@
> #include "charset.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
> @@ -76,7 +76,7 @@
> generators need to be fixed instead of adding those names to this list. */
>
> #define yymaxdepth go_maxdepth
> -#define yyparse go_parse_internal
> +#define yyparse _go_parse
> #define yylex go_lex
> #define yyerror go_error
> #define yylval go_lval
> @@ -122,6 +122,11 @@
>
> #define YYFPRINTF parser_fprintf
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> int yyparse (void);
>
> static int yylex (void);
> @@ -158,7 +163,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 *);
> static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
> DOUBLEST *d, struct type **t);
> %}
> @@ -239,77 +244,77 @@ 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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE); }
> ;
>
> /* Expressions, including the comma operator. */
> exp1 : exp
> | exp1 ',' exp
> - { write_exp_elt_opcode (BINOP_COMMA); }
> + { write_exp_elt_opcode (pstate, BINOP_COMMA); }
> ;
>
> /* Expressions, not including the comma operator. */
> exp : '*' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_IND); }
> + { write_exp_elt_opcode (pstate, UNOP_IND); }
> ;
>
> exp : '&' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_ADDR); }
> + { write_exp_elt_opcode (pstate, UNOP_ADDR); }
> ;
>
> exp : '-' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_NEG); }
> + { write_exp_elt_opcode (pstate, UNOP_NEG); }
> ;
>
> exp : '+' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_PLUS); }
> + { write_exp_elt_opcode (pstate, UNOP_PLUS); }
> ;
>
> exp : '!' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> exp : '^' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_COMPLEMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
> ;
>
> exp : exp INCREMENT %prec UNARY
> - { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
> ;
>
> exp : exp DECREMENT %prec UNARY
> - { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
> ;
>
> /* foo->bar is not in Go. May want as a gdb extension. Later. */
>
> exp : exp '.' name_not_typename
> - { write_exp_elt_opcode (STRUCTOP_STRUCT);
> - write_exp_string ($3.stoken);
> - write_exp_elt_opcode (STRUCTOP_STRUCT); }
> + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $3.stoken);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> exp : exp '.' name_not_typename COMPLETE
> - { mark_struct_expression ();
> - write_exp_elt_opcode (STRUCTOP_STRUCT);
> - write_exp_string ($3.stoken);
> - write_exp_elt_opcode (STRUCTOP_STRUCT); }
> + { mark_struct_expression (pstate);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $3.stoken);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> exp : exp '.' COMPLETE
> { struct stoken s;
> - mark_struct_expression ();
> - write_exp_elt_opcode (STRUCTOP_STRUCT);
> + mark_struct_expression (pstate);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
> s.ptr = "";
> s.length = 0;
> - write_exp_string (s);
> - write_exp_elt_opcode (STRUCTOP_STRUCT); }
> + write_exp_string (pstate, s);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> exp : exp '[' exp1 ']'
> - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> ;
>
> exp : exp '('
> @@ -317,9 +322,10 @@ exp : exp '('
> being accumulated by an outer function call. */
> { start_arglist (); }
> arglist ')' %prec LEFT_ARROW
> - { write_exp_elt_opcode (OP_FUNCALL);
> - write_exp_elt_longcst ((LONGEST) end_arglist ());
> - write_exp_elt_opcode (OP_FUNCALL); }
> + { write_exp_elt_opcode (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate,
> + (LONGEST) end_arglist ());
> + write_exp_elt_opcode (pstate, OP_FUNCALL); }
> ;
>
> lcurly : '{'
> @@ -342,15 +348,15 @@ rcurly : '}'
> ;
>
> 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 (pstate, UNOP_MEMVAL);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, UNOP_CAST); }
> ;
>
> exp : '(' exp1 ')'
> @@ -360,100 +366,100 @@ exp : '(' exp1 ')'
> /* Binary operators in order of decreasing precedence. */
>
> exp : exp '@' exp
> - { write_exp_elt_opcode (BINOP_REPEAT); }
> + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> ;
>
> exp : exp '*' exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> exp : exp '/' exp
> - { write_exp_elt_opcode (BINOP_DIV); }
> + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> ;
>
> exp : exp '%' exp
> - { write_exp_elt_opcode (BINOP_REM); }
> + { write_exp_elt_opcode (pstate, BINOP_REM); }
> ;
>
> exp : exp '+' exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> exp : exp '-' exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> exp : exp LSH exp
> - { write_exp_elt_opcode (BINOP_LSH); }
> + { write_exp_elt_opcode (pstate, BINOP_LSH); }
> ;
>
> exp : exp RSH exp
> - { write_exp_elt_opcode (BINOP_RSH); }
> + { write_exp_elt_opcode (pstate, BINOP_RSH); }
> ;
>
> exp : exp EQUAL exp
> - { write_exp_elt_opcode (BINOP_EQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> ;
>
> exp : exp NOTEQUAL exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> ;
>
> exp : exp LEQ exp
> - { write_exp_elt_opcode (BINOP_LEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> ;
>
> exp : exp GEQ exp
> - { write_exp_elt_opcode (BINOP_GEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> ;
>
> exp : exp '<' exp
> - { write_exp_elt_opcode (BINOP_LESS); }
> + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> ;
>
> exp : exp '>' exp
> - { write_exp_elt_opcode (BINOP_GTR); }
> + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> ;
>
> exp : exp '&' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> ;
>
> exp : exp '^' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> ;
>
> exp : exp '|' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> ;
>
> exp : exp ANDAND exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> ;
>
> exp : exp OROR exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> ;
>
> exp : exp '?' exp ':' exp %prec '?'
> - { write_exp_elt_opcode (TERNOP_COND); }
> + { write_exp_elt_opcode (pstate, TERNOP_COND); }
> ;
>
> exp : exp '=' exp
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> + write_exp_elt_opcode (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_longcst (pstate, (LONGEST)($1.val));
> + write_exp_elt_opcode (pstate, OP_LONG); }
> ;
>
> exp : CHAR
> @@ -461,28 +467,28 @@ exp : CHAR
> struct stoken_vector vec;
> vec.len = 1;
> vec.tokens = &$1;
> - write_exp_string_vector ($1.type, &vec);
> + write_exp_string_vector (pstate, $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)
> + parse_number (pstate, $1.stoken.ptr,
> + $1.stoken.length, 0, &val);
> + write_exp_elt_opcode (pstate, OP_LONG);
> + write_exp_elt_type (pstate, val.typed_val_int.type);
> + write_exp_elt_longcst (pstate, (LONGEST)
> val.typed_val_int.val);
> - write_exp_elt_opcode (OP_LONG);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_dblcst (pstate, $1.dval);
> + write_exp_elt_opcode (pstate, OP_DOUBLE); }
> ;
>
> exp : variable
> @@ -490,26 +496,29 @@ exp : variable
>
> exp : DOLLAR_VARIABLE
> {
> - write_dollar_variable ($1);
> + write_dollar_variable (pstate, $1);
> }
> ;
>
> exp : SIZEOF_KEYWORD '(' type ')' %prec UNARY
> {
> /* TODO(dje): Go objects in structs. */
> - write_exp_elt_opcode (OP_LONG);
> + write_exp_elt_opcode (pstate, OP_LONG);
> /* TODO(dje): What's the right type here? */
> - write_exp_elt_type (parse_type->builtin_unsigned_int);
> + write_exp_elt_type
> + (pstate,
> + parse_type (pstate)->builtin_unsigned_int);
> CHECK_TYPEDEF ($3);
> - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
> - write_exp_elt_opcode (OP_LONG);
> + write_exp_elt_longcst (pstate,
> + (LONGEST) TYPE_LENGTH ($3));
> + write_exp_elt_opcode (pstate, OP_LONG);
> }
> ;
>
> exp : SIZEOF_KEYWORD '(' exp ')' %prec UNARY
> {
> /* TODO(dje): Go objects in structs. */
> - write_exp_elt_opcode (UNOP_SIZEOF);
> + write_exp_elt_opcode (pstate, UNOP_SIZEOF);
> }
>
> string_exp:
> @@ -552,7 +561,8 @@ exp : string_exp %prec ABOVE_COMMA
> {
> int i;
>
> - write_exp_string_vector (0 /*always utf8*/, &$1);
> + write_exp_string_vector (pstate, 0 /*always utf8*/,
> + &$1);
> for (i = 0; i < $1.len; ++i)
> free ($1.tokens[i].ptr);
> free ($1.tokens);
> @@ -560,15 +570,15 @@ exp : string_exp %prec ABOVE_COMMA
> ;
>
> exp : TRUE_KEYWORD
> - { write_exp_elt_opcode (OP_BOOL);
> - write_exp_elt_longcst ((LONGEST) $1);
> - write_exp_elt_opcode (OP_BOOL); }
> + { write_exp_elt_opcode (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, OP_BOOL); }
> ;
>
> exp : FALSE_KEYWORD
> - { write_exp_elt_opcode (OP_BOOL);
> - write_exp_elt_longcst ((LONGEST) $1);
> - write_exp_elt_opcode (OP_BOOL); }
> + { write_exp_elt_opcode (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, OP_BOOL); }
> ;
>
> variable: name_not_typename ENTRY
> @@ -581,9 +591,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 (pstate, OP_VAR_ENTRY_VALUE);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
> }
> ;
>
> @@ -600,13 +610,13 @@ variable: name_not_typename
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> }
> else if ($1.is_a_field_of_this)
> {
> @@ -622,7 +632,7 @@ variable: name_not_typename
> msymbol =
> lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols ()
> && !have_partial_symbols ())
> error (_("No symbol table is loaded. "
> @@ -652,7 +662,7 @@ type /* Implements (approximately): [*] type-specifier */
> expression_context_block); }
> */
> | BYTE_KEYWORD
> - { $$ = builtin_go_type (parse_gdbarch)
> + { $$ = builtin_go_type (parse_gdbarch (pstate))
> ->builtin_uint8; }
> ;
>
> @@ -704,7 +714,8 @@ parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
> as our YYSTYPE is different than c-exp.y's */
>
> static int
> -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
> +parse_number (struct parser_state *par_state, 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. */
> @@ -729,7 +740,7 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
>
> if (parsed_float)
> {
> - if (! parse_go_float (parse_gdbarch, p, len,
> + if (! parse_go_float (parse_gdbarch (par_state), p, len,
> &putithere->typed_val_float.dval,
> &putithere->typed_val_float.type))
> return ERROR;
> @@ -845,9 +856,10 @@ 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 (par_state)) - 2)) == 0)
> {
> - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
> + high_bit
> + = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
>
> /* A large decimal (not hex or octal) constant (between INT_MAX
> and UINT_MAX) is a long or unsigned long, according to ANSI,
> @@ -855,28 +867,29 @@ 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 (par_state)->builtin_unsigned_int;
> + signed_type = parse_type (par_state)->builtin_int;
> }
> else if (long_p <= 1
> - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
> + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
> + unsigned_type = parse_type (par_state)->builtin_unsigned_long;
> + signed_type = parse_type (par_state)->builtin_long;
> }
> else
> {
> int shift;
> if (sizeof (ULONGEST) * HOST_CHAR_BIT
> - < gdbarch_long_long_bit (parse_gdbarch))
> + < gdbarch_long_long_bit (parse_gdbarch (par_state)))
> /* 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 (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
> + signed_type = parse_type (par_state)->builtin_long_long;
> }
>
> putithere->typed_val_int.val = n;
> @@ -1044,7 +1057,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 *par_state)
> {
> int c;
> int namelen;
> @@ -1175,7 +1188,8 @@ lex_one_token (void)
> && (*p < 'A' || *p > 'Z')))
> break;
> }
> - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
> + toktype = parse_number (par_state, tokstart, p - tokstart,
> + got_dot|got_e, &yylval);
> if (toktype == ERROR)
> {
> char *err_copy = (char *) alloca (p - tokstart + 1);
> @@ -1430,7 +1444,7 @@ classify_packaged_name (struct block *block)
> The result is one of NAME, NAME_OR_INT, or TYPENAME. */
>
> static int
> -classify_name (struct block *block)
> +classify_name (struct parser_state *par_state, struct block *block)
> {
> struct type *type;
> struct symbol *sym;
> @@ -1440,8 +1454,9 @@ classify_name (struct block *block)
> copy = copy_name (yylval.sval);
>
> /* Try primitive types first so they win over bad/weird debug info. */
> - type = language_lookup_primitive_type_by_name (parse_language,
> - parse_gdbarch, copy);
> + type = language_lookup_primitive_type_by_name (parse_language (par_state),
> + parse_gdbarch (par_state),
> + copy);
> if (type != NULL)
> {
> /* NOTE: We take advantage of the fact that yylval coming in was a
> @@ -1497,7 +1512,8 @@ 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 (par_state, copy, yylval.sval.length,
> + 0, &newlval);
> if (hextype == INT)
> {
> yylval.ssym.sym = NULL;
> @@ -1530,7 +1546,7 @@ yylex (void)
> }
> popping = 0;
>
> - current.token = lex_one_token ();
> + current.token = lex_one_token (pstate);
>
> /* TODO: Need a way to force specifying name1 as a package.
> .name1.name2 ? */
> @@ -1541,14 +1557,14 @@ yylex (void)
> /* See if we have "name1 . name2". */
>
> current.value = yylval;
> - next.token = lex_one_token ();
> + next.token = lex_one_token (pstate);
> next.value = yylval;
>
> if (next.token == '.')
> {
> token_and_value name2;
>
> - name2.token = lex_one_token ();
> + name2.token = lex_one_token (pstate);
> name2.value = yylval;
>
> if (name2.token == NAME)
> @@ -1587,14 +1603,20 @@ yylex (void)
>
> popping = 1;
> yylval = current.value;
> - return classify_name (expression_context_block);
> + return classify_name (pstate, expression_context_block);
> }
>
> int
> -go_parse (void)
> +go_parse (struct parser_state *par_state)
> {
> int result;
> - struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
> + struct cleanup *back_to;
> +
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + back_to = make_cleanup (null_cleanup, NULL);
>
> make_cleanup_restore_integer (&yydebug);
> yydebug = parser_debug;
> diff --git a/gdb/go-lang.h b/gdb/go-lang.h
> index 67b5d93..2be37b2 100644
> --- a/gdb/go-lang.h
> +++ b/gdb/go-lang.h
> @@ -24,6 +24,8 @@
> #include "symtab.h"
> #include "value.h"
>
> +struct parser_state;
> +
> struct builtin_go_type
> {
> struct type *builtin_void;
> @@ -54,7 +56,7 @@ enum go_type
>
> /* Defined in go-exp.y. */
>
> -extern int go_parse (void);
> +extern int go_parse (struct parser_state *);
>
> extern void go_error (char *);
>
> --
> 1.7.7.6
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 08/10] Objective-C language
2012-06-02 20:24 ` [PATCH 08/10] Objective-C language Sergio Durigan Junior
@ 2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:54 ` Joel Brobecker
2012-06-13 16:02 ` Tom Tromey
0 siblings, 2 replies; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-13 4:59 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey
On Saturday, June 02 2012, I wrote:
> Patch for the Objective-C language. Similar to the C language one.
Ping.
> ---
> gdb/objc-exp.y | 412 ++++++++++++++++++++++++++++--------------------------
> gdb/objc-lang.c | 8 +-
> gdb/objc-lang.h | 7 +-
> 3 files changed, 222 insertions(+), 205 deletions(-)
>
> diff --git a/gdb/objc-exp.y b/gdb/objc-exp.y
> index 6f51edf..5157596 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
> @@ -63,7 +63,7 @@
> adding those names to this list. */
>
> #define yymaxdepth objc_maxdepth
> -#define yyparse objc_parse
> +#define yyparse _objc_parse
> #define yylex objc_lex
> #define yyerror objc_error
> #define yylval objc_lval
> @@ -113,6 +113,11 @@
> #define YYDEBUG 0 /* Default to no yydebug support. */
> #endif
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> int yyparse (void);
>
> static int yylex (void);
> @@ -153,7 +158,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
> @@ -235,79 +240,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE);}
> ;
>
> /* Expressions, including the comma operator. */
> exp1 : exp
> | exp1 ',' exp
> - { write_exp_elt_opcode (BINOP_COMMA); }
> + { write_exp_elt_opcode (pstate, BINOP_COMMA); }
> ;
>
> /* Expressions, not including the comma operator. */
> exp : '*' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_IND); }
> + { write_exp_elt_opcode (pstate, UNOP_IND); }
> ;
>
> exp : '&' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_ADDR); }
> + { write_exp_elt_opcode (pstate, UNOP_ADDR); }
> ;
>
> exp : '-' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_NEG); }
> + { write_exp_elt_opcode (pstate, UNOP_NEG); }
> ;
>
> exp : '!' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> exp : '~' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_COMPLEMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
> ;
>
> exp : INCREMENT exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_PREINCREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
> ;
>
> exp : DECREMENT exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_PREDECREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
> ;
>
> exp : exp INCREMENT %prec UNARY
> - { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
> ;
>
> exp : exp DECREMENT %prec UNARY
> - { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
> ;
>
> exp : SIZEOF exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_SIZEOF); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_PTR);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_ADDR);
> + write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
> ;
> exp : exp ARROW '*' exp
> - { write_exp_elt_opcode (STRUCTOP_MPTR); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
>
> @@ -315,16 +320,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 (pstate, UNOP_ADDR);
> + write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
> ;
>
> exp : exp '.' '*' exp
> - { write_exp_elt_opcode (STRUCTOP_MEMBER); }
> + { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
> ;
>
> exp : exp '[' exp1 ']'
> - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> ;
> /*
> * The rules below parse ObjC message calls of the form:
> @@ -335,50 +340,50 @@ exp : '[' TYPENAME
> {
> CORE_ADDR class;
>
> - class = lookup_objc_class (parse_gdbarch,
> + class = lookup_objc_class (parse_gdbarch (pstate),
> 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> + write_exp_elt_longcst (pstate, (LONGEST) class);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> + end_msglist (pstate);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> + write_exp_elt_longcst (pstate, (LONGEST) $2.class);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> + end_msglist (pstate);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> + end_msglist (pstate);
> + write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
> }
> ;
>
> msglist : name
> - { add_msglist(&$1, 0); }
> + { add_msglist (&$1, 0); }
> | msgarglist
> ;
>
> @@ -399,9 +404,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 (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
> + write_exp_elt_opcode (pstate, OP_FUNCALL); }
> ;
>
> lcurly : '{'
> @@ -423,22 +428,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 (pstate, OP_ARRAY);
> + write_exp_elt_longcst (pstate, (LONGEST) 0);
> + write_exp_elt_longcst (pstate, (LONGEST) $3);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MEMVAL);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, UNOP_CAST); }
> ;
>
> exp : '(' exp1 ')'
> @@ -448,120 +453,120 @@ exp : '(' exp1 ')'
> /* Binary operators in order of decreasing precedence. */
>
> exp : exp '@' exp
> - { write_exp_elt_opcode (BINOP_REPEAT); }
> + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> ;
>
> exp : exp '*' exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> exp : exp '/' exp
> - { write_exp_elt_opcode (BINOP_DIV); }
> + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> ;
>
> exp : exp '%' exp
> - { write_exp_elt_opcode (BINOP_REM); }
> + { write_exp_elt_opcode (pstate, BINOP_REM); }
> ;
>
> exp : exp '+' exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> exp : exp '-' exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> exp : exp LSH exp
> - { write_exp_elt_opcode (BINOP_LSH); }
> + { write_exp_elt_opcode (pstate, BINOP_LSH); }
> ;
>
> exp : exp RSH exp
> - { write_exp_elt_opcode (BINOP_RSH); }
> + { write_exp_elt_opcode (pstate, BINOP_RSH); }
> ;
>
> exp : exp EQUAL exp
> - { write_exp_elt_opcode (BINOP_EQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> ;
>
> exp : exp NOTEQUAL exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> ;
>
> exp : exp LEQ exp
> - { write_exp_elt_opcode (BINOP_LEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> ;
>
> exp : exp GEQ exp
> - { write_exp_elt_opcode (BINOP_GEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> ;
>
> exp : exp '<' exp
> - { write_exp_elt_opcode (BINOP_LESS); }
> + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> ;
>
> exp : exp '>' exp
> - { write_exp_elt_opcode (BINOP_GTR); }
> + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> ;
>
> exp : exp '&' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> ;
>
> exp : exp '^' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> ;
>
> exp : exp '|' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> ;
>
> exp : exp ANDAND exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> ;
>
> exp : exp OROR exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> ;
>
> exp : exp '?' exp ':' exp %prec '?'
> - { write_exp_elt_opcode (TERNOP_COND); }
> + { write_exp_elt_opcode (pstate, TERNOP_COND); }
> ;
>
> exp : exp '=' exp
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> + write_exp_elt_opcode (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
> + write_exp_elt_opcode (pstate, OP_LONG); }
> ;
>
> exp : NAME_OR_INT
> { YYSTYPE val;
> - parse_number ($1.stoken.ptr,
> + parse_number (pstate, $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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, val.typed_val_int.type);
> + write_exp_elt_longcst (pstate, (LONGEST)
> val.typed_val_int.val);
> - write_exp_elt_opcode (OP_LONG);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_dblcst (pstate, $1.dval);
> + write_exp_elt_opcode (pstate, OP_DOUBLE); }
> ;
>
> exp : variable
> @@ -573,17 +578,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 (pstate, OP_OBJC_SELECTOR);
> + write_exp_string (pstate, $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> CHECK_TYPEDEF ($3);
> - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
> - write_exp_elt_opcode (OP_LONG); }
> + write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
> + write_exp_elt_opcode (pstate, OP_LONG); }
> ;
>
> exp : STRING
> @@ -596,27 +601,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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
> + write_exp_elt_longcst (pstate, (LONGEST) (*sp++));
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
> + write_exp_elt_longcst (pstate, (LONGEST)'\0');
> + write_exp_elt_opcode (pstate, OP_LONG);
> + write_exp_elt_opcode (pstate, OP_ARRAY);
> + write_exp_elt_longcst (pstate, (LONGEST) 0);
> + write_exp_elt_longcst (pstate, (LONGEST) ($1.length));
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_NSSTRING);
> + write_exp_string (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); }
> ;
>
> block : BLOCKNAME
> @@ -662,11 +667,11 @@ variable: block COLONCOLON name
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, block_found);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> ;
>
> qualified_name: typebase COLONCOLON name
> @@ -677,10 +682,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 (pstate, OP_SCOPE);
> + write_exp_elt_type (pstate, type);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, OP_SCOPE);
> }
> | typebase COLONCOLON '~' name
> {
> @@ -700,10 +705,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 (pstate, OP_SCOPE);
> + write_exp_elt_type (pstate, type);
> + write_exp_string (pstate, tmp_token);
> + write_exp_elt_opcode (pstate, OP_SCOPE);
> }
> ;
>
> @@ -719,16 +724,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 (pstate, OP_VAR_VALUE);
> + write_exp_elt_block (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> break;
> }
>
> msymbol = lookup_minimal_symbol (name, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols ()
> && !have_partial_symbols ())
> error (_("No symbol table is loaded. "
> @@ -752,13 +757,13 @@ variable: name_not_typename
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> }
> else if ($1.is_a_field_of_this)
> {
> @@ -768,11 +773,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 (pstate, OP_THIS);
> + write_exp_elt_opcode (pstate, OP_THIS);
> + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> + write_exp_string (pstate, $1.stoken);
> + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> }
> else
> {
> @@ -782,7 +787,7 @@ variable: name_not_typename
> msymbol =
> lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols () &&
> !have_partial_symbols ())
> error (_("No symbol table is loaded. "
> @@ -877,31 +882,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
> $$ = $1.type;
> }
> | INT_KEYWORD
> - { $$ = parse_type->builtin_int; }
> + { $$ = parse_type (pstate)->builtin_int; }
> | LONG
> - { $$ = parse_type->builtin_long; }
> + { $$ = parse_type (pstate)->builtin_long; }
> | SHORT
> - { $$ = parse_type->builtin_short; }
> + { $$ = parse_type (pstate)->builtin_short; }
> | LONG INT_KEYWORD
> - { $$ = parse_type->builtin_long; }
> + { $$ = parse_type (pstate)->builtin_long; }
> | UNSIGNED LONG INT_KEYWORD
> - { $$ = parse_type->builtin_unsigned_long; }
> + { $$ = parse_type (pstate)->builtin_unsigned_long; }
> | LONG LONG
> - { $$ = parse_type->builtin_long_long; }
> + { $$ = parse_type (pstate)->builtin_long_long; }
> | LONG LONG INT_KEYWORD
> - { $$ = parse_type->builtin_long_long; }
> + { $$ = parse_type (pstate)->builtin_long_long; }
> | UNSIGNED LONG LONG
> - { $$ = parse_type->builtin_unsigned_long_long; }
> + { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
> | UNSIGNED LONG LONG INT_KEYWORD
> - { $$ = parse_type->builtin_unsigned_long_long; }
> + { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
> | SHORT INT_KEYWORD
> - { $$ = parse_type->builtin_short; }
> + { $$ = parse_type (pstate)->builtin_short; }
> | UNSIGNED SHORT INT_KEYWORD
> - { $$ = parse_type->builtin_unsigned_short; }
> + { $$ = parse_type (pstate)->builtin_unsigned_short; }
> | DOUBLE_KEYWORD
> - { $$ = parse_type->builtin_double; }
> + { $$ = parse_type (pstate)->builtin_double; }
> | LONG DOUBLE_KEYWORD
> - { $$ = parse_type->builtin_long_double; }
> + { $$ = parse_type (pstate)->builtin_long_double; }
> | STRUCT name
> { $$ = lookup_struct (copy_name ($2),
> expression_context_block); }
> @@ -915,17 +920,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 (pstate),
> + parse_gdbarch (pstate),
> TYPE_NAME($2.type)); }
> | UNSIGNED
> - { $$ = parse_type->builtin_unsigned_int; }
> + { $$ = parse_type (pstate)->builtin_unsigned_int; }
> | SIGNED_KEYWORD typename
> - { $$ = lookup_signed_typename (parse_language,
> - parse_gdbarch,
> + { $$ = lookup_signed_typename (parse_language (pstate),
> + parse_gdbarch (pstate),
> TYPE_NAME($2.type)); }
> | SIGNED_KEYWORD
> - { $$ = parse_type->builtin_int; }
> + { $$ = parse_type (pstate)->builtin_int; }
> | TEMPLATE name '<' type '>'
> { $$ = lookup_template_type(copy_name($2), $4,
> expression_context_block);
> @@ -942,19 +947,19 @@ typename: TYPENAME
> {
> $$.stoken.ptr = "int";
> $$.stoken.length = 3;
> - $$.type = parse_type->builtin_int;
> + $$.type = parse_type (pstate)->builtin_int;
> }
> | LONG
> {
> $$.stoken.ptr = "long";
> $$.stoken.length = 4;
> - $$.type = parse_type->builtin_long;
> + $$.type = parse_type (pstate)->builtin_long;
> }
> | SHORT
> {
> $$.stoken.ptr = "short";
> $$.stoken.length = 5;
> - $$.type = parse_type->builtin_short;
> + $$.type = parse_type (pstate)->builtin_short;
> }
> ;
>
> @@ -998,7 +1003,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 *par_state, 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
> @@ -1024,7 +1030,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 (par_state), p, len,
> &putithere->typed_val_float.dval,
> &putithere->typed_val_float.type))
> return ERROR;
> @@ -1130,10 +1136,10 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
>
> un = (unsigned LONGEST)n >> 2;
> if (long_p == 0
> - && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
> + && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0)
> {
> high_bit
> - = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
> + = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
>
> /* A large decimal (not hex or octal) constant (between INT_MAX
> and UINT_MAX) is a long or unsigned long, according to ANSI,
> @@ -1141,29 +1147,29 @@ 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 (par_state)->builtin_unsigned_int;
> + signed_type = parse_type (par_state)->builtin_int;
> }
> else if (long_p <= 1
> - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
> + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
> + unsigned_type = parse_type (par_state)->builtin_unsigned_long;
> + signed_type = parse_type (par_state)->builtin_long;
> }
> else
> {
> high_bit = (((unsigned LONGEST)1)
> - << (gdbarch_long_long_bit (parse_gdbarch) - 32 - 1)
> + << (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
> + signed_type = parse_type (par_state)->builtin_long_long;
> }
>
> putithere->typed_val_int.val = n;
> @@ -1274,12 +1280,12 @@ yylex (void)
> lexptr++;
> c = *lexptr++;
> if (c == '\\')
> - c = parse_escape (parse_gdbarch, &lexptr);
> + c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
>
> c = *lexptr++;
> if (c != '\'')
> @@ -1397,7 +1403,7 @@ yylex (void)
> else break;
> }
> if (toktype != ERROR)
> - toktype = parse_number (tokstart, p - tokstart,
> + toktype = parse_number (pstate, tokstart, p - tokstart,
> got_dot | got_e, &yylval);
> if (toktype == ERROR)
> {
> @@ -1502,7 +1508,7 @@ yylex (void)
> break;
> case '\\':
> tokptr++;
> - c = parse_escape (parse_gdbarch, &tokptr);
> + c = parse_escape (parse_gdbarch (pstate), &tokptr);
> if (c == -1)
> {
> continue;
> @@ -1563,7 +1569,7 @@ yylex (void)
> case 8:
> if (strncmp (tokstart, "unsigned", 8) == 0)
> return UNSIGNED;
> - if (parse_language->la_language == language_cplus
> + if (parse_language (pstate)->la_language == language_cplus
> && strncmp (tokstart, "template", 8) == 0)
> return TEMPLATE;
> if (strncmp (tokstart, "volatile", 8) == 0)
> @@ -1580,7 +1586,7 @@ yylex (void)
> return DOUBLE_KEYWORD;
> break;
> case 5:
> - if ((parse_language->la_language == language_cplus)
> + if ((parse_language (pstate)->la_language == language_cplus)
> && strncmp (tokstart, "class", 5) == 0)
> return CLASS;
> if (strncmp (tokstart, "union", 5) == 0)
> @@ -1609,7 +1615,7 @@ yylex (void)
>
> if (*tokstart == '$')
> {
> - write_dollar_variable (yylval.sval);
> + write_dollar_variable (pstate, yylval.sval);
> return VARIABLE;
> }
>
> @@ -1624,8 +1630,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 (pstate)->la_language == language_cplus ||
> + parse_language (pstate)->la_language == language_objc)
> need_this = &is_a_field_of_this;
> else
> need_this = (int *) NULL;
> @@ -1737,15 +1743,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 (pstate),
> + parse_gdbarch (pstate), 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 (pstate), tmp);
> if (Class)
> {
> yylval.class.class = Class;
> @@ -1765,7 +1771,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 (pstate, tokstart, namelen, 0, &newlval);
> if (hextype == INT)
> {
> yylval.ssym.sym = sym;
> @@ -1781,6 +1787,16 @@ yylex (void)
> }
> }
>
> +int
> +objc_parse (struct parser_state *par_state)
> +{
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + return _objc_parse ();
> +}
> +
> void
> yyerror (char *msg)
> {
> diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> index 15bf792..52786cc 100644
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -615,7 +615,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;
> @@ -625,12 +625,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..ba656f8 100644
> --- a/gdb/objc-lang.h
> +++ b/gdb/objc-lang.h
> @@ -26,10 +26,11 @@ 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 (char *); /* Defined in objc-exp.y */
>
> extern CORE_ADDR lookup_objc_class (struct gdbarch *gdbarch,
> char *classname);
> @@ -48,7 +49,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);
> --
> 1.7.7.6
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 05/10] Fortran language
2012-06-02 20:24 ` [PATCH 05/10] Fortran language Sergio Durigan Junior
@ 2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:55 ` Joel Brobecker
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-13 4:59 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey
On Saturday, June 02 2012, I wrote:
> Patch for the Fortran language. This patch is similiar to the C
> language one.
Ping.
> ---
> gdb/f-exp.y | 261 ++++++++++++++++++++++++++++++++--------------------------
> gdb/f-lang.h | 6 +-
> 2 files changed, 148 insertions(+), 119 deletions(-)
>
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index 33c7418..832b0b8 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
> @@ -66,7 +66,7 @@
> generators need to be fixed instead of adding those names to this list. */
>
> #define yymaxdepth f_maxdepth
> -#define yyparse f_parse
> +#define yyparse _f_parse
> #define yylex f_lex
> #define yyerror f_error
> #define yylval f_lval
> @@ -118,6 +118,11 @@
>
> #define YYFPRINTF parser_fprintf
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> int yyparse (void);
>
> static int yylex (void);
> @@ -158,7 +163,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
> @@ -240,9 +245,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE); }
> ;
>
> exp : '(' exp ')'
> @@ -251,27 +256,27 @@ exp : '(' exp ')'
>
> /* Expressions, not including the comma operator. */
> exp : '*' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_IND); }
> + { write_exp_elt_opcode (pstate, UNOP_IND); }
> ;
>
> exp : '&' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_ADDR); }
> + { write_exp_elt_opcode (pstate, UNOP_ADDR); }
> ;
>
> exp : '-' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_NEG); }
> + { write_exp_elt_opcode (pstate, UNOP_NEG); }
> ;
>
> exp : BOOL_NOT exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> exp : '~' exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_COMPLEMENT); }
> + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
> ;
>
> exp : SIZEOF exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_SIZEOF); }
> + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
> ;
>
> /* No more explicit array operators, we treat everything in F77 as
> @@ -282,9 +287,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 (pstate, OP_F77_UNDETERMINED_ARGLIST);
> + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
> + write_exp_elt_opcode (pstate, OP_F77_UNDETERMINED_ARGLIST); }
> ;
>
> arglist :
> @@ -305,27 +310,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 (pstate, OP_F90_RANGE);
> + write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
> + write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
> + write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_F90_RANGE);
> + write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
> + write_exp_elt_opcode (pstate, OP_F90_RANGE); }
> ;
>
> complexnum: exp ',' exp
> @@ -333,133 +338,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 (pstate, OP_COMPLEX);
> + write_exp_elt_type (pstate,
> + parse_f_type (pstate)
> + ->builtin_complex_s16);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> /* Binary operators in order of decreasing precedence. */
>
> exp : exp '@' exp
> - { write_exp_elt_opcode (BINOP_REPEAT); }
> + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> ;
>
> exp : exp STARSTAR exp
> - { write_exp_elt_opcode (BINOP_EXP); }
> + { write_exp_elt_opcode (pstate, BINOP_EXP); }
> ;
>
> exp : exp '*' exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> exp : exp '/' exp
> - { write_exp_elt_opcode (BINOP_DIV); }
> + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> ;
>
> exp : exp '+' exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> exp : exp '-' exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> exp : exp LSH exp
> - { write_exp_elt_opcode (BINOP_LSH); }
> + { write_exp_elt_opcode (pstate, BINOP_LSH); }
> ;
>
> exp : exp RSH exp
> - { write_exp_elt_opcode (BINOP_RSH); }
> + { write_exp_elt_opcode (pstate, BINOP_RSH); }
> ;
>
> exp : exp EQUAL exp
> - { write_exp_elt_opcode (BINOP_EQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> ;
>
> exp : exp NOTEQUAL exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> ;
>
> exp : exp LEQ exp
> - { write_exp_elt_opcode (BINOP_LEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> ;
>
> exp : exp GEQ exp
> - { write_exp_elt_opcode (BINOP_GEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> ;
>
> exp : exp LESSTHAN exp
> - { write_exp_elt_opcode (BINOP_LESS); }
> + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> ;
>
> exp : exp GREATERTHAN exp
> - { write_exp_elt_opcode (BINOP_GTR); }
> + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> ;
>
> exp : exp '&' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> ;
>
> exp : exp '^' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> ;
>
> exp : exp '|' exp
> - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> ;
>
> exp : exp BOOL_AND exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> ;
>
>
> exp : exp BOOL_OR exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> ;
>
> exp : exp '=' exp
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> + write_exp_elt_opcode (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, $1.type);
> + write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
> + write_exp_elt_opcode (pstate, 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 (pstate, $1.stoken.ptr, $1.stoken.length,
> + 0, &val);
> + write_exp_elt_opcode (pstate, OP_LONG);
> + write_exp_elt_type (pstate, val.typed_val.type);
> + write_exp_elt_longcst (pstate, (LONGEST)val.typed_val.val);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate,
> + parse_f_type (pstate)
> + ->builtin_real_s8);
> + write_exp_elt_dblcst (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_DOUBLE); }
> ;
>
> exp : variable
> @@ -469,25 +479,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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_f_type (pstate)
> + ->builtin_integer);
> CHECK_TYPEDEF ($3);
> - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
> - write_exp_elt_opcode (OP_LONG); }
> + write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_STRING);
> + write_exp_string (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_STRING);
> }
> ;
>
> @@ -503,13 +515,13 @@ variable: name_not_typename
> innermost_block))
> innermost_block = block_found;
> }
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> break;
> }
> else
> @@ -520,7 +532,7 @@ variable: name_not_typename
> msymbol =
> lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols () && !have_partial_symbols ())
> error (_("No symbol table is loaded. Use the \"file\" command."));
> else
> @@ -561,7 +573,8 @@ ptype : typebase
> {
> range_type =
> create_range_type ((struct type *) NULL,
> - parse_f_type->builtin_integer,
> + parse_f_type (pstate)
> + ->builtin_integer,
> 0, array_size - 1);
> follow_type =
> create_array_type ((struct type *) NULL,
> @@ -607,31 +620,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */
> : TYPENAME
> { $$ = $1.type; }
> | INT_KEYWORD
> - { $$ = parse_f_type->builtin_integer; }
> + { $$ = parse_f_type (pstate)->builtin_integer; }
> | INT_S2_KEYWORD
> - { $$ = parse_f_type->builtin_integer_s2; }
> + { $$ = parse_f_type (pstate)->builtin_integer_s2; }
> | CHARACTER
> - { $$ = parse_f_type->builtin_character; }
> + { $$ = parse_f_type (pstate)->builtin_character; }
> | LOGICAL_S8_KEYWORD
> - { $$ = parse_f_type->builtin_logical_s8; }
> + { $$ = parse_f_type (pstate)->builtin_logical_s8; }
> | LOGICAL_KEYWORD
> - { $$ = parse_f_type->builtin_logical; }
> + { $$ = parse_f_type (pstate)->builtin_logical; }
> | LOGICAL_S2_KEYWORD
> - { $$ = parse_f_type->builtin_logical_s2; }
> + { $$ = parse_f_type (pstate)->builtin_logical_s2; }
> | LOGICAL_S1_KEYWORD
> - { $$ = parse_f_type->builtin_logical_s1; }
> + { $$ = parse_f_type (pstate)->builtin_logical_s1; }
> | REAL_KEYWORD
> - { $$ = parse_f_type->builtin_real; }
> + { $$ = parse_f_type (pstate)->builtin_real; }
> | REAL_S8_KEYWORD
> - { $$ = parse_f_type->builtin_real_s8; }
> + { $$ = parse_f_type (pstate)->builtin_real_s8; }
> | REAL_S16_KEYWORD
> - { $$ = parse_f_type->builtin_real_s16; }
> + { $$ = parse_f_type (pstate)->builtin_real_s16; }
> | COMPLEX_S8_KEYWORD
> - { $$ = parse_f_type->builtin_complex_s8; }
> + { $$ = parse_f_type (pstate)->builtin_complex_s8; }
> | COMPLEX_S16_KEYWORD
> - { $$ = parse_f_type->builtin_complex_s16; }
> + { $$ = parse_f_type (pstate)->builtin_complex_s16; }
> | COMPLEX_S32_KEYWORD
> - { $$ = parse_f_type->builtin_complex_s32; }
> + { $$ = parse_f_type (pstate)->builtin_complex_s32; }
> ;
>
> nonempty_typelist
> @@ -670,7 +683,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 *par_state, char *p, int len,
> + int parsed_float, YYSTYPE *putithere)
> {
> LONGEST n = 0;
> LONGEST prevn = 0;
> @@ -776,20 +790,22 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *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 (par_state))
> + != gdbarch_long_bit (parse_gdbarch (par_state))
> && ((n >> 2)
> - >> (gdbarch_int_bit (parse_gdbarch)-2))) /* Avoid shift warning */
> + >> (gdbarch_int_bit (parse_gdbarch (par_state))-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 (par_state))-1);
> + unsigned_type = parse_type (par_state)->builtin_unsigned_long;
> + signed_type = parse_type (par_state)->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 (par_state))-1);
> + unsigned_type = parse_type (par_state)->builtin_unsigned_int;
> + signed_type = parse_type (par_state)->builtin_int;
> }
>
> putithere->typed_val.val = n;
> @@ -1091,7 +1107,8 @@ yylex (void)
> && (*p < 'A' || *p > 'Z')))
> break;
> }
> - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
> + toktype = parse_number (pstate, tokstart, p - tokstart,
> + got_dot|got_e|got_d,
> &yylval);
> if (toktype == ERROR)
> {
> @@ -1165,7 +1182,7 @@ yylex (void)
>
> if (*tokstart == '$')
> {
> - write_dollar_variable (yylval.sval);
> + write_dollar_variable (pstate, yylval.sval);
> return VARIABLE;
> }
>
> @@ -1180,7 +1197,7 @@ yylex (void)
>
> sym = lookup_symbol (tmp, expression_context_block,
> VAR_DOMAIN,
> - parse_language->la_language == language_cplus
> + parse_language (pstate)->la_language == language_cplus
> ? &is_a_field_of_this : NULL);
> if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
> {
> @@ -1188,8 +1205,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 (pstate),
> + parse_gdbarch (pstate), tmp);
> if (yylval.tsym.type != NULL)
> return TYPENAME;
>
> @@ -1201,7 +1218,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 (pstate, tokstart, namelen, 0, &newlval);
> if (hextype == INT)
> {
> yylval.ssym.sym = sym;
> @@ -1217,6 +1234,16 @@ yylex (void)
> }
> }
>
> +int
> +f_parse (struct parser_state *par_state)
> +{
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + return _f_parse ();
> +}
> +
> void
> yyerror (char *msg)
> {
> diff --git a/gdb/f-lang.h b/gdb/f-lang.h
> index 4aae3c5..1392345 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 (char *); /* Defined in f-exp.y */
>
> extern void f_print_type (struct type *, const char *, struct ui_file *, int,
> int);
> --
> 1.7.7.6
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 07/10] Modula-2 language
2012-06-02 20:33 ` [PATCH 07/10] Modula-2 language Sergio Durigan Junior
@ 2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:51 ` Joel Brobecker
0 siblings, 1 reply; 40+ messages in thread
From: Sergio Durigan Junior @ 2012-06-13 4:59 UTC (permalink / raw)
To: GDB Patches; +Cc: Tom Tromey
On Saturday, June 02 2012, I wrote:
> Patch for the Modula-2 language. Similar to the C language one.
Ping.
I don't know exactly who is the maintainer of Modula-2...
> ---
> gdb/m2-exp.y | 261 +++++++++++++++++++++++++++++++--------------------------
> gdb/m2-lang.h | 6 +-
> 2 files changed, 147 insertions(+), 120 deletions(-)
>
> diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
> index 19f9c24..153d482 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
> @@ -61,7 +61,7 @@
> generators need to be fixed instead of adding those names to this list. */
>
> #define yymaxdepth m2_maxdepth
> -#define yyparse m2_parse
> +#define yyparse _m2_parse
> #define yylex m2_lex
> #define yyerror m2_error
> #define yylval m2_lval
> @@ -113,6 +113,11 @@
>
> #define YYFPRINTF parser_fprintf
>
> +/* The state of the parser, used internally when we are parsing the
> + expression. */
> +
> +static struct parser_state *pstate = NULL;
> +
> int yyparse (void);
>
> static int yylex (void);
> @@ -205,31 +210,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 (pstate, OP_TYPE);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_TYPE);
> }
> ;
>
> /* Expressions */
>
> exp : exp '^' %prec UNARY
> - { write_exp_elt_opcode (UNOP_IND); }
> + { write_exp_elt_opcode (pstate, UNOP_IND); }
> ;
>
> exp : '-'
> { number_sign = -1; }
> exp %prec UNARY
> { number_sign = 1;
> - write_exp_elt_opcode (UNOP_NEG); }
> + write_exp_elt_opcode (pstate, UNOP_NEG); }
> ;
>
> exp : '+' exp %prec UNARY
> - { write_exp_elt_opcode(UNOP_PLUS); }
> + { write_exp_elt_opcode (pstate, UNOP_PLUS); }
> ;
>
> exp : not_exp exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> ;
>
> not_exp : NOT
> @@ -237,88 +242,88 @@ not_exp : NOT
> ;
>
> exp : CAP '(' exp ')'
> - { write_exp_elt_opcode (UNOP_CAP); }
> + { write_exp_elt_opcode (pstate, UNOP_CAP); }
> ;
>
> exp : ORD '(' exp ')'
> - { write_exp_elt_opcode (UNOP_ORD); }
> + { write_exp_elt_opcode (pstate, UNOP_ORD); }
> ;
>
> exp : ABS '(' exp ')'
> - { write_exp_elt_opcode (UNOP_ABS); }
> + { write_exp_elt_opcode (pstate, UNOP_ABS); }
> ;
>
> exp : HIGH '(' exp ')'
> - { write_exp_elt_opcode (UNOP_HIGH); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MIN);
> + write_exp_elt_type (pstate, $3);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MAX);
> + write_exp_elt_type (pstate, $3);
> + write_exp_elt_opcode (pstate, UNOP_MAX); }
> ;
>
> exp : FLOAT_FUNC '(' exp ')'
> - { write_exp_elt_opcode (UNOP_FLOAT); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_VAL);
> + write_exp_elt_type (pstate, $3);
> + write_exp_elt_opcode (pstate, BINOP_VAL); }
> ;
>
> exp : CHR '(' exp ')'
> - { write_exp_elt_opcode (UNOP_CHR); }
> + { write_exp_elt_opcode (pstate, UNOP_CHR); }
> ;
>
> exp : ODD '(' exp ')'
> - { write_exp_elt_opcode (UNOP_ODD); }
> + { write_exp_elt_opcode (pstate, UNOP_ODD); }
> ;
>
> exp : TRUNC '(' exp ')'
> - { write_exp_elt_opcode (UNOP_TRUNC); }
> + { write_exp_elt_opcode (pstate, UNOP_TRUNC); }
> ;
>
> exp : TSIZE '(' exp ')'
> - { write_exp_elt_opcode (UNOP_SIZEOF); }
> + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
> ;
>
> exp : SIZE exp %prec UNARY
> - { write_exp_elt_opcode (UNOP_SIZEOF); }
> + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
> ;
>
>
> exp : INC '(' exp ')'
> - { write_exp_elt_opcode(UNOP_PREINCREMENT); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> + write_exp_elt_opcode (pstate, BINOP_ADD);
> + write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
> ;
>
> exp : DEC '(' exp ')'
> - { write_exp_elt_opcode(UNOP_PREDECREMENT);}
> + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> + write_exp_elt_opcode (pstate, BINOP_SUB);
> + write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
> + write_exp_string (pstate, $3);
> + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> ;
>
> exp : set
> @@ -350,13 +355,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 (pstate, MULTI_SUBSCRIPT);
> + write_exp_elt_longcst (pstate, (LONGEST) end_arglist());
> + write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); }
> ;
>
> exp : exp '[' exp ']'
> - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> ;
>
> exp : exp '('
> @@ -364,9 +369,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 (pstate, OP_FUNCALL);
> + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
> + write_exp_elt_opcode (pstate, OP_FUNCALL); }
> ;
>
> arglist :
> @@ -392,15 +397,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 (pstate, UNOP_MEMVAL);
> + write_exp_elt_type (pstate, $2);
> + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> + write_exp_elt_type (pstate, $1);
> + write_exp_elt_opcode (pstate, UNOP_CAST); }
> ;
>
> exp : '(' exp ')'
> @@ -412,131 +417,139 @@ exp : '(' exp ')'
>
> /* GDB construct */
> exp : exp '@' exp
> - { write_exp_elt_opcode (BINOP_REPEAT); }
> + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> ;
>
> exp : exp '*' exp
> - { write_exp_elt_opcode (BINOP_MUL); }
> + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> ;
>
> exp : exp '/' exp
> - { write_exp_elt_opcode (BINOP_DIV); }
> + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> ;
>
> exp : exp DIV exp
> - { write_exp_elt_opcode (BINOP_INTDIV); }
> + { write_exp_elt_opcode (pstate, BINOP_INTDIV); }
> ;
>
> exp : exp MOD exp
> - { write_exp_elt_opcode (BINOP_REM); }
> + { write_exp_elt_opcode (pstate, BINOP_REM); }
> ;
>
> exp : exp '+' exp
> - { write_exp_elt_opcode (BINOP_ADD); }
> + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> ;
>
> exp : exp '-' exp
> - { write_exp_elt_opcode (BINOP_SUB); }
> + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> ;
>
> exp : exp '=' exp
> - { write_exp_elt_opcode (BINOP_EQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> ;
>
> exp : exp NOTEQUAL exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> | exp '#' exp
> - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> ;
>
> exp : exp LEQ exp
> - { write_exp_elt_opcode (BINOP_LEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> ;
>
> exp : exp GEQ exp
> - { write_exp_elt_opcode (BINOP_GEQ); }
> + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> ;
>
> exp : exp '<' exp
> - { write_exp_elt_opcode (BINOP_LESS); }
> + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> ;
>
> exp : exp '>' exp
> - { write_exp_elt_opcode (BINOP_GTR); }
> + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> ;
>
> exp : exp LOGICAL_AND exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> ;
>
> exp : exp OROR exp
> - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> ;
>
> exp : exp ASSIGN exp
> - { write_exp_elt_opcode (BINOP_ASSIGN); }
> + { write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_m2_type (pstate)->builtin_int);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_m2_type (pstate)
> + ->builtin_card);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate,
> + parse_m2_type (pstate)
> + ->builtin_char);
> + write_exp_elt_longcst (pstate, (LONGEST) $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> + write_exp_elt_type (pstate,
> + parse_m2_type (pstate)
> + ->builtin_real);
> + write_exp_elt_dblcst (pstate, $1);
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> + write_exp_elt_longcst (pstate,
> + (LONGEST) TYPE_LENGTH ($3));
> + write_exp_elt_opcode (pstate, 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 (pstate, OP_M2_STRING);
> + write_exp_string (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_M2_STRING); }
> ;
>
> /* This will be used for extensions later. Like adding modules. */
> @@ -546,7 +559,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;}
> ;
> @@ -566,10 +580,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 (pstate, OP_VAR_VALUE);
> + write_exp_elt_block (pstate, NULL);
> + write_exp_elt_sym (pstate, $1);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> ;
>
> /* GDB internal ($foo) variable */
> @@ -592,11 +606,11 @@ variable: block COLONCOLON NAME
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, block_found);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> ;
>
> /* Base case for variables. */
> @@ -618,13 +632,13 @@ variable: NAME
> innermost_block = block_found;
> }
>
> - write_exp_elt_opcode (OP_VAR_VALUE);
> + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> + write_exp_elt_sym (pstate, sym);
> + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> }
> else
> {
> @@ -634,7 +648,7 @@ variable: NAME
> msymbol =
> lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> - write_exp_msymbol (msymbol);
> + write_exp_msymbol (pstate, msymbol);
> else if (!have_full_symbols () && !have_partial_symbols ())
> error (_("No symbol table is loaded. Use the \"symbol-file\" command."));
> else
> @@ -646,7 +660,8 @@ variable: NAME
>
> type
> : TYPENAME
> - { $$ = lookup_typename (parse_language, parse_gdbarch,
> + { $$ = lookup_typename (parse_language (pstate),
> + parse_gdbarch (pstate),
> copy_name ($1),
> expression_context_block, 0); }
>
> @@ -806,8 +821,8 @@ 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)
> @@ -993,7 +1008,7 @@ yylex (void)
>
> if (*tokstart == '$')
> {
> - write_dollar_variable (yylval.sval);
> + write_dollar_variable (pstate, yylval.sval);
> return INTERNAL_VAR;
> }
>
> @@ -1013,7 +1028,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 (pstate), parse_gdbarch (pstate),
> copy_name (yylval.sval), expression_context_block, 1))
> return TYPENAME;
>
> @@ -1071,6 +1086,16 @@ yylex (void)
> }
> }
>
> +int
> +m2_parse (struct parser_state *par_state)
> +{
> + /* Setting up the parser state. */
> + gdb_assert (par_state != NULL);
> + pstate = par_state;
> +
> + return _m2_parse ();
> +}
> +
> void
> yyerror (char *msg)
> {
> diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
> index fc6de34..daae348 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 (char *); /* Defined in m2-exp.y */
>
> /* Defined in m2-typeprint.c */
> extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
> --
> 1.7.7.6
--
Sergio
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 04/10] Ada language.
2012-06-13 4:57 ` Sergio Durigan Junior
@ 2012-06-13 14:50 ` Joel Brobecker
0 siblings, 0 replies; 40+ messages in thread
From: Joel Brobecker @ 2012-06-13 14:50 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, Tom Tromey
Hi Sergio,
> Ping.
Sorry, Sergio. I really thought I had reviewed this change and sent
my OK.
> > gdb/ada-exp.y | 474 +++++++++++++++++++++++++++++---------------------------
> > gdb/ada-lang.c | 4 +-
> > gdb/ada-lang.h | 3 +-
> > gdb/ada-lex.l | 54 ++++---
> > 4 files changed, 282 insertions(+), 253 deletions(-)
I skimmed through the changes again, and they still looked OK to me.
I really like changes like this one where globals are being removed.
Thanks!
--
Joel
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 07/10] Modula-2 language
2012-06-13 4:59 ` Sergio Durigan Junior
@ 2012-06-13 14:51 ` Joel Brobecker
2012-06-16 14:29 ` Gaius Mulley
0 siblings, 1 reply; 40+ messages in thread
From: Joel Brobecker @ 2012-06-13 14:51 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, gaius
> > Patch for the Modula-2 language. Similar to the C language one.
>
> Ping.
>
> I don't know exactly who is the maintainer of Modula-2...
It's Gaius Mulley (in Cc). I thkn that the changes are sufficiently
mechanical that we can go with GM approval if the language maintainer
doesn't comment.
>
> > ---
> > gdb/m2-exp.y | 261 +++++++++++++++++++++++++++++++--------------------------
> > gdb/m2-lang.h | 6 +-
> > 2 files changed, 147 insertions(+), 120 deletions(-)
> >
> > diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
> > index 19f9c24..153d482 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
> > @@ -61,7 +61,7 @@
> > generators need to be fixed instead of adding those names to this list. */
> >
> > #define yymaxdepth m2_maxdepth
> > -#define yyparse m2_parse
> > +#define yyparse _m2_parse
> > #define yylex m2_lex
> > #define yyerror m2_error
> > #define yylval m2_lval
> > @@ -113,6 +113,11 @@
> >
> > #define YYFPRINTF parser_fprintf
> >
> > +/* The state of the parser, used internally when we are parsing the
> > + expression. */
> > +
> > +static struct parser_state *pstate = NULL;
> > +
> > int yyparse (void);
> >
> > static int yylex (void);
> > @@ -205,31 +210,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 (pstate, OP_TYPE);
> > + write_exp_elt_type (pstate, $1);
> > + write_exp_elt_opcode (pstate, OP_TYPE);
> > }
> > ;
> >
> > /* Expressions */
> >
> > exp : exp '^' %prec UNARY
> > - { write_exp_elt_opcode (UNOP_IND); }
> > + { write_exp_elt_opcode (pstate, UNOP_IND); }
> > ;
> >
> > exp : '-'
> > { number_sign = -1; }
> > exp %prec UNARY
> > { number_sign = 1;
> > - write_exp_elt_opcode (UNOP_NEG); }
> > + write_exp_elt_opcode (pstate, UNOP_NEG); }
> > ;
> >
> > exp : '+' exp %prec UNARY
> > - { write_exp_elt_opcode(UNOP_PLUS); }
> > + { write_exp_elt_opcode (pstate, UNOP_PLUS); }
> > ;
> >
> > exp : not_exp exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> > + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> > ;
> >
> > not_exp : NOT
> > @@ -237,88 +242,88 @@ not_exp : NOT
> > ;
> >
> > exp : CAP '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_CAP); }
> > + { write_exp_elt_opcode (pstate, UNOP_CAP); }
> > ;
> >
> > exp : ORD '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_ORD); }
> > + { write_exp_elt_opcode (pstate, UNOP_ORD); }
> > ;
> >
> > exp : ABS '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_ABS); }
> > + { write_exp_elt_opcode (pstate, UNOP_ABS); }
> > ;
> >
> > exp : HIGH '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_HIGH); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MIN);
> > + write_exp_elt_type (pstate, $3);
> > + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MAX);
> > + write_exp_elt_type (pstate, $3);
> > + write_exp_elt_opcode (pstate, UNOP_MAX); }
> > ;
> >
> > exp : FLOAT_FUNC '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_FLOAT); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_VAL);
> > + write_exp_elt_type (pstate, $3);
> > + write_exp_elt_opcode (pstate, BINOP_VAL); }
> > ;
> >
> > exp : CHR '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_CHR); }
> > + { write_exp_elt_opcode (pstate, UNOP_CHR); }
> > ;
> >
> > exp : ODD '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_ODD); }
> > + { write_exp_elt_opcode (pstate, UNOP_ODD); }
> > ;
> >
> > exp : TRUNC '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_TRUNC); }
> > + { write_exp_elt_opcode (pstate, UNOP_TRUNC); }
> > ;
> >
> > exp : TSIZE '(' exp ')'
> > - { write_exp_elt_opcode (UNOP_SIZEOF); }
> > + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
> > ;
> >
> > exp : SIZE exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_SIZEOF); }
> > + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
> > ;
> >
> >
> > exp : INC '(' exp ')'
> > - { write_exp_elt_opcode(UNOP_PREINCREMENT); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> > + write_exp_elt_opcode (pstate, BINOP_ADD);
> > + write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
> > ;
> >
> > exp : DEC '(' exp ')'
> > - { write_exp_elt_opcode(UNOP_PREDECREMENT);}
> > + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> > + write_exp_elt_opcode (pstate, BINOP_SUB);
> > + write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
> > + write_exp_string (pstate, $3);
> > + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> > ;
> >
> > exp : set
> > @@ -350,13 +355,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 (pstate, MULTI_SUBSCRIPT);
> > + write_exp_elt_longcst (pstate, (LONGEST) end_arglist());
> > + write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); }
> > ;
> >
> > exp : exp '[' exp ']'
> > - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> > + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> > ;
> >
> > exp : exp '('
> > @@ -364,9 +369,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 (pstate, OP_FUNCALL);
> > + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
> > + write_exp_elt_opcode (pstate, OP_FUNCALL); }
> > ;
> >
> > arglist :
> > @@ -392,15 +397,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 (pstate, UNOP_MEMVAL);
> > + write_exp_elt_type (pstate, $2);
> > + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> > + write_exp_elt_type (pstate, $1);
> > + write_exp_elt_opcode (pstate, UNOP_CAST); }
> > ;
> >
> > exp : '(' exp ')'
> > @@ -412,131 +417,139 @@ exp : '(' exp ')'
> >
> > /* GDB construct */
> > exp : exp '@' exp
> > - { write_exp_elt_opcode (BINOP_REPEAT); }
> > + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> > ;
> >
> > exp : exp '*' exp
> > - { write_exp_elt_opcode (BINOP_MUL); }
> > + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> > ;
> >
> > exp : exp '/' exp
> > - { write_exp_elt_opcode (BINOP_DIV); }
> > + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> > ;
> >
> > exp : exp DIV exp
> > - { write_exp_elt_opcode (BINOP_INTDIV); }
> > + { write_exp_elt_opcode (pstate, BINOP_INTDIV); }
> > ;
> >
> > exp : exp MOD exp
> > - { write_exp_elt_opcode (BINOP_REM); }
> > + { write_exp_elt_opcode (pstate, BINOP_REM); }
> > ;
> >
> > exp : exp '+' exp
> > - { write_exp_elt_opcode (BINOP_ADD); }
> > + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> > ;
> >
> > exp : exp '-' exp
> > - { write_exp_elt_opcode (BINOP_SUB); }
> > + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> > ;
> >
> > exp : exp '=' exp
> > - { write_exp_elt_opcode (BINOP_EQUAL); }
> > + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> > ;
> >
> > exp : exp NOTEQUAL exp
> > - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> > + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> > | exp '#' exp
> > - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> > + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> > ;
> >
> > exp : exp LEQ exp
> > - { write_exp_elt_opcode (BINOP_LEQ); }
> > + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> > ;
> >
> > exp : exp GEQ exp
> > - { write_exp_elt_opcode (BINOP_GEQ); }
> > + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> > ;
> >
> > exp : exp '<' exp
> > - { write_exp_elt_opcode (BINOP_LESS); }
> > + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> > ;
> >
> > exp : exp '>' exp
> > - { write_exp_elt_opcode (BINOP_GTR); }
> > + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> > ;
> >
> > exp : exp LOGICAL_AND exp
> > - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> > + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> > ;
> >
> > exp : exp OROR exp
> > - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> > + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> > ;
> >
> > exp : exp ASSIGN exp
> > - { write_exp_elt_opcode (BINOP_ASSIGN); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> > + write_exp_elt_longcst (pstate, (LONGEST) $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_BOOL);
> > + write_exp_elt_longcst (pstate, (LONGEST) $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate,
> > + parse_m2_type (pstate)->builtin_int);
> > + write_exp_elt_longcst (pstate, (LONGEST) $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate,
> > + parse_m2_type (pstate)
> > + ->builtin_card);
> > + write_exp_elt_longcst (pstate, (LONGEST) $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate,
> > + parse_m2_type (pstate)
> > + ->builtin_char);
> > + write_exp_elt_longcst (pstate, (LONGEST) $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> > + write_exp_elt_type (pstate,
> > + parse_m2_type (pstate)
> > + ->builtin_real);
> > + write_exp_elt_dblcst (pstate, $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> > + write_exp_elt_longcst (pstate,
> > + (LONGEST) TYPE_LENGTH ($3));
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_M2_STRING);
> > + write_exp_string (pstate, $1);
> > + write_exp_elt_opcode (pstate, OP_M2_STRING); }
> > ;
> >
> > /* This will be used for extensions later. Like adding modules. */
> > @@ -546,7 +559,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;}
> > ;
> > @@ -566,10 +580,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 (pstate, OP_VAR_VALUE);
> > + write_exp_elt_block (pstate, NULL);
> > + write_exp_elt_sym (pstate, $1);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> > ;
> >
> > /* GDB internal ($foo) variable */
> > @@ -592,11 +606,11 @@ variable: block COLONCOLON NAME
> > innermost_block = block_found;
> > }
> >
> > - write_exp_elt_opcode (OP_VAR_VALUE);
> > + write_exp_elt_opcode (pstate, 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 (pstate, block_found);
> > + write_exp_elt_sym (pstate, sym);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> > ;
> >
> > /* Base case for variables. */
> > @@ -618,13 +632,13 @@ variable: NAME
> > innermost_block = block_found;
> > }
> >
> > - write_exp_elt_opcode (OP_VAR_VALUE);
> > + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> > + write_exp_elt_sym (pstate, sym);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> > }
> > else
> > {
> > @@ -634,7 +648,7 @@ variable: NAME
> > msymbol =
> > lookup_minimal_symbol (arg, NULL, NULL);
> > if (msymbol != NULL)
> > - write_exp_msymbol (msymbol);
> > + write_exp_msymbol (pstate, msymbol);
> > else if (!have_full_symbols () && !have_partial_symbols ())
> > error (_("No symbol table is loaded. Use the \"symbol-file\" command."));
> > else
> > @@ -646,7 +660,8 @@ variable: NAME
> >
> > type
> > : TYPENAME
> > - { $$ = lookup_typename (parse_language, parse_gdbarch,
> > + { $$ = lookup_typename (parse_language (pstate),
> > + parse_gdbarch (pstate),
> > copy_name ($1),
> > expression_context_block, 0); }
> >
> > @@ -806,8 +821,8 @@ 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)
> > @@ -993,7 +1008,7 @@ yylex (void)
> >
> > if (*tokstart == '$')
> > {
> > - write_dollar_variable (yylval.sval);
> > + write_dollar_variable (pstate, yylval.sval);
> > return INTERNAL_VAR;
> > }
> >
> > @@ -1013,7 +1028,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 (pstate), parse_gdbarch (pstate),
> > copy_name (yylval.sval), expression_context_block, 1))
> > return TYPENAME;
> >
> > @@ -1071,6 +1086,16 @@ yylex (void)
> > }
> > }
> >
> > +int
> > +m2_parse (struct parser_state *par_state)
> > +{
> > + /* Setting up the parser state. */
> > + gdb_assert (par_state != NULL);
> > + pstate = par_state;
> > +
> > + return _m2_parse ();
> > +}
> > +
> > void
> > yyerror (char *msg)
> > {
> > diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
> > index fc6de34..daae348 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 (char *); /* Defined in m2-exp.y */
> >
> > /* Defined in m2-typeprint.c */
> > extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
> > --
> > 1.7.7.6
>
> --
> Sergio
--
Joel
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 08/10] Objective-C language
2012-06-13 4:59 ` Sergio Durigan Junior
@ 2012-06-13 14:54 ` Joel Brobecker
2012-06-13 16:02 ` Tom Tromey
1 sibling, 0 replies; 40+ messages in thread
From: Joel Brobecker @ 2012-06-13 14:54 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, fedor
> > Patch for the Objective-C language. Similar to the C language one.
>
> Ping.
Looks OK to me. Objective-C maintainer is Adam Fedor (in Cc).
>
> > ---
> > gdb/objc-exp.y | 412 ++++++++++++++++++++++++++++--------------------------
> > gdb/objc-lang.c | 8 +-
> > gdb/objc-lang.h | 7 +-
> > 3 files changed, 222 insertions(+), 205 deletions(-)
> >
> > diff --git a/gdb/objc-exp.y b/gdb/objc-exp.y
> > index 6f51edf..5157596 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
> > @@ -63,7 +63,7 @@
> > adding those names to this list. */
> >
> > #define yymaxdepth objc_maxdepth
> > -#define yyparse objc_parse
> > +#define yyparse _objc_parse
> > #define yylex objc_lex
> > #define yyerror objc_error
> > #define yylval objc_lval
> > @@ -113,6 +113,11 @@
> > #define YYDEBUG 0 /* Default to no yydebug support. */
> > #endif
> >
> > +/* The state of the parser, used internally when we are parsing the
> > + expression. */
> > +
> > +static struct parser_state *pstate = NULL;
> > +
> > int yyparse (void);
> >
> > static int yylex (void);
> > @@ -153,7 +158,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
> > @@ -235,79 +240,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 (pstate, OP_TYPE);
> > + write_exp_elt_type (pstate, $1);
> > + write_exp_elt_opcode (pstate, OP_TYPE);}
> > ;
> >
> > /* Expressions, including the comma operator. */
> > exp1 : exp
> > | exp1 ',' exp
> > - { write_exp_elt_opcode (BINOP_COMMA); }
> > + { write_exp_elt_opcode (pstate, BINOP_COMMA); }
> > ;
> >
> > /* Expressions, not including the comma operator. */
> > exp : '*' exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_IND); }
> > + { write_exp_elt_opcode (pstate, UNOP_IND); }
> > ;
> >
> > exp : '&' exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_ADDR); }
> > + { write_exp_elt_opcode (pstate, UNOP_ADDR); }
> > ;
> >
> > exp : '-' exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_NEG); }
> > + { write_exp_elt_opcode (pstate, UNOP_NEG); }
> > ;
> >
> > exp : '!' exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
> > + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
> > ;
> >
> > exp : '~' exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_COMPLEMENT); }
> > + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
> > ;
> >
> > exp : INCREMENT exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_PREINCREMENT); }
> > + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
> > ;
> >
> > exp : DECREMENT exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_PREDECREMENT); }
> > + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
> > ;
> >
> > exp : exp INCREMENT %prec UNARY
> > - { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
> > + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
> > ;
> >
> > exp : exp DECREMENT %prec UNARY
> > - { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
> > + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
> > ;
> >
> > exp : SIZEOF exp %prec UNARY
> > - { write_exp_elt_opcode (UNOP_SIZEOF); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_PTR);
> > + write_exp_string (pstate, $3);
> > + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_ADDR);
> > + write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
> > ;
> > exp : exp ARROW '*' exp
> > - { write_exp_elt_opcode (STRUCTOP_MPTR); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, STRUCTOP_STRUCT);
> > + write_exp_string (pstate, $3);
> > + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
> > ;
> >
> >
> > @@ -315,16 +320,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 (pstate, UNOP_ADDR);
> > + write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
> > ;
> >
> > exp : exp '.' '*' exp
> > - { write_exp_elt_opcode (STRUCTOP_MEMBER); }
> > + { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
> > ;
> >
> > exp : exp '[' exp1 ']'
> > - { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
> > + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
> > ;
> > /*
> > * The rules below parse ObjC message calls of the form:
> > @@ -335,50 +340,50 @@ exp : '[' TYPENAME
> > {
> > CORE_ADDR class;
> >
> > - class = lookup_objc_class (parse_gdbarch,
> > + class = lookup_objc_class (parse_gdbarch (pstate),
> > 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> > + write_exp_elt_longcst (pstate, (LONGEST) class);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> > + end_msglist (pstate);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> > + write_exp_elt_longcst (pstate, (LONGEST) $2.class);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> > + end_msglist (pstate);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_MSGCALL);
> > + end_msglist (pstate);
> > + write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
> > }
> > ;
> >
> > msglist : name
> > - { add_msglist(&$1, 0); }
> > + { add_msglist (&$1, 0); }
> > | msgarglist
> > ;
> >
> > @@ -399,9 +404,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 (pstate, OP_FUNCALL);
> > + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
> > + write_exp_elt_opcode (pstate, OP_FUNCALL); }
> > ;
> >
> > lcurly : '{'
> > @@ -423,22 +428,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 (pstate, OP_ARRAY);
> > + write_exp_elt_longcst (pstate, (LONGEST) 0);
> > + write_exp_elt_longcst (pstate, (LONGEST) $3);
> > + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_MEMVAL);
> > + write_exp_elt_type (pstate, $2);
> > + write_exp_elt_opcode (pstate, 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 (pstate, UNOP_CAST);
> > + write_exp_elt_type (pstate, $2);
> > + write_exp_elt_opcode (pstate, UNOP_CAST); }
> > ;
> >
> > exp : '(' exp1 ')'
> > @@ -448,120 +453,120 @@ exp : '(' exp1 ')'
> > /* Binary operators in order of decreasing precedence. */
> >
> > exp : exp '@' exp
> > - { write_exp_elt_opcode (BINOP_REPEAT); }
> > + { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
> > ;
> >
> > exp : exp '*' exp
> > - { write_exp_elt_opcode (BINOP_MUL); }
> > + { write_exp_elt_opcode (pstate, BINOP_MUL); }
> > ;
> >
> > exp : exp '/' exp
> > - { write_exp_elt_opcode (BINOP_DIV); }
> > + { write_exp_elt_opcode (pstate, BINOP_DIV); }
> > ;
> >
> > exp : exp '%' exp
> > - { write_exp_elt_opcode (BINOP_REM); }
> > + { write_exp_elt_opcode (pstate, BINOP_REM); }
> > ;
> >
> > exp : exp '+' exp
> > - { write_exp_elt_opcode (BINOP_ADD); }
> > + { write_exp_elt_opcode (pstate, BINOP_ADD); }
> > ;
> >
> > exp : exp '-' exp
> > - { write_exp_elt_opcode (BINOP_SUB); }
> > + { write_exp_elt_opcode (pstate, BINOP_SUB); }
> > ;
> >
> > exp : exp LSH exp
> > - { write_exp_elt_opcode (BINOP_LSH); }
> > + { write_exp_elt_opcode (pstate, BINOP_LSH); }
> > ;
> >
> > exp : exp RSH exp
> > - { write_exp_elt_opcode (BINOP_RSH); }
> > + { write_exp_elt_opcode (pstate, BINOP_RSH); }
> > ;
> >
> > exp : exp EQUAL exp
> > - { write_exp_elt_opcode (BINOP_EQUAL); }
> > + { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
> > ;
> >
> > exp : exp NOTEQUAL exp
> > - { write_exp_elt_opcode (BINOP_NOTEQUAL); }
> > + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
> > ;
> >
> > exp : exp LEQ exp
> > - { write_exp_elt_opcode (BINOP_LEQ); }
> > + { write_exp_elt_opcode (pstate, BINOP_LEQ); }
> > ;
> >
> > exp : exp GEQ exp
> > - { write_exp_elt_opcode (BINOP_GEQ); }
> > + { write_exp_elt_opcode (pstate, BINOP_GEQ); }
> > ;
> >
> > exp : exp '<' exp
> > - { write_exp_elt_opcode (BINOP_LESS); }
> > + { write_exp_elt_opcode (pstate, BINOP_LESS); }
> > ;
> >
> > exp : exp '>' exp
> > - { write_exp_elt_opcode (BINOP_GTR); }
> > + { write_exp_elt_opcode (pstate, BINOP_GTR); }
> > ;
> >
> > exp : exp '&' exp
> > - { write_exp_elt_opcode (BINOP_BITWISE_AND); }
> > + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
> > ;
> >
> > exp : exp '^' exp
> > - { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
> > + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
> > ;
> >
> > exp : exp '|' exp
> > - { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
> > + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
> > ;
> >
> > exp : exp ANDAND exp
> > - { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
> > + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
> > ;
> >
> > exp : exp OROR exp
> > - { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
> > + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
> > ;
> >
> > exp : exp '?' exp ':' exp %prec '?'
> > - { write_exp_elt_opcode (TERNOP_COND); }
> > + { write_exp_elt_opcode (pstate, TERNOP_COND); }
> > ;
> >
> > exp : exp '=' exp
> > - { write_exp_elt_opcode (BINOP_ASSIGN); }
> > + { write_exp_elt_opcode (pstate, 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 (pstate, BINOP_ASSIGN_MODIFY);
> > + write_exp_elt_opcode (pstate, $2);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, $1.type);
> > + write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
> > + write_exp_elt_opcode (pstate, OP_LONG); }
> > ;
> >
> > exp : NAME_OR_INT
> > { YYSTYPE val;
> > - parse_number ($1.stoken.ptr,
> > + parse_number (pstate, $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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, val.typed_val_int.type);
> > + write_exp_elt_longcst (pstate, (LONGEST)
> > val.typed_val_int.val);
> > - write_exp_elt_opcode (OP_LONG);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_DOUBLE);
> > + write_exp_elt_type (pstate, $1.type);
> > + write_exp_elt_dblcst (pstate, $1.dval);
> > + write_exp_elt_opcode (pstate, OP_DOUBLE); }
> > ;
> >
> > exp : variable
> > @@ -573,17 +578,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 (pstate, OP_OBJC_SELECTOR);
> > + write_exp_string (pstate, $1);
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_int);
> > CHECK_TYPEDEF ($3);
> > - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
> > - write_exp_elt_opcode (OP_LONG); }
> > + write_exp_elt_longcst (pstate, (LONGEST) TYPE_LENGTH ($3));
> > + write_exp_elt_opcode (pstate, OP_LONG); }
> > ;
> >
> > exp : STRING
> > @@ -596,27 +601,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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
> > + write_exp_elt_longcst (pstate, (LONGEST) (*sp++));
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_LONG);
> > + write_exp_elt_type (pstate, parse_type (pstate)->builtin_char);
> > + write_exp_elt_longcst (pstate, (LONGEST)'\0');
> > + write_exp_elt_opcode (pstate, OP_LONG);
> > + write_exp_elt_opcode (pstate, OP_ARRAY);
> > + write_exp_elt_longcst (pstate, (LONGEST) 0);
> > + write_exp_elt_longcst (pstate, (LONGEST) ($1.length));
> > + write_exp_elt_opcode (pstate, 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 (pstate, OP_OBJC_NSSTRING);
> > + write_exp_string (pstate, $1);
> > + write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); }
> > ;
> >
> > block : BLOCKNAME
> > @@ -662,11 +667,11 @@ variable: block COLONCOLON name
> > innermost_block = block_found;
> > }
> >
> > - write_exp_elt_opcode (OP_VAR_VALUE);
> > + write_exp_elt_opcode (pstate, 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 (pstate, block_found);
> > + write_exp_elt_sym (pstate, sym);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
> > ;
> >
> > qualified_name: typebase COLONCOLON name
> > @@ -677,10 +682,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 (pstate, OP_SCOPE);
> > + write_exp_elt_type (pstate, type);
> > + write_exp_string (pstate, $3);
> > + write_exp_elt_opcode (pstate, OP_SCOPE);
> > }
> > | typebase COLONCOLON '~' name
> > {
> > @@ -700,10 +705,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 (pstate, OP_SCOPE);
> > + write_exp_elt_type (pstate, type);
> > + write_exp_string (pstate, tmp_token);
> > + write_exp_elt_opcode (pstate, OP_SCOPE);
> > }
> > ;
> >
> > @@ -719,16 +724,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 (pstate, OP_VAR_VALUE);
> > + write_exp_elt_block (pstate, NULL);
> > + write_exp_elt_sym (pstate, sym);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> > break;
> > }
> >
> > msymbol = lookup_minimal_symbol (name, NULL, NULL);
> > if (msymbol != NULL)
> > - write_exp_msymbol (msymbol);
> > + write_exp_msymbol (pstate, msymbol);
> > else if (!have_full_symbols ()
> > && !have_partial_symbols ())
> > error (_("No symbol table is loaded. "
> > @@ -752,13 +757,13 @@ variable: name_not_typename
> > innermost_block = block_found;
> > }
> >
> > - write_exp_elt_opcode (OP_VAR_VALUE);
> > + write_exp_elt_opcode (pstate, 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 (pstate, NULL);
> > + write_exp_elt_sym (pstate, sym);
> > + write_exp_elt_opcode (pstate, OP_VAR_VALUE);
> > }
> > else if ($1.is_a_field_of_this)
> > {
> > @@ -768,11 +773,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 (pstate, OP_THIS);
> > + write_exp_elt_opcode (pstate, OP_THIS);
> > + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> > + write_exp_string (pstate, $1.stoken);
> > + write_exp_elt_opcode (pstate, STRUCTOP_PTR);
> > }
> > else
> > {
> > @@ -782,7 +787,7 @@ variable: name_not_typename
> > msymbol =
> > lookup_minimal_symbol (arg, NULL, NULL);
> > if (msymbol != NULL)
> > - write_exp_msymbol (msymbol);
> > + write_exp_msymbol (pstate, msymbol);
> > else if (!have_full_symbols () &&
> > !have_partial_symbols ())
> > error (_("No symbol table is loaded. "
> > @@ -877,31 +882,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
> > $$ = $1.type;
> > }
> > | INT_KEYWORD
> > - { $$ = parse_type->builtin_int; }
> > + { $$ = parse_type (pstate)->builtin_int; }
> > | LONG
> > - { $$ = parse_type->builtin_long; }
> > + { $$ = parse_type (pstate)->builtin_long; }
> > | SHORT
> > - { $$ = parse_type->builtin_short; }
> > + { $$ = parse_type (pstate)->builtin_short; }
> > | LONG INT_KEYWORD
> > - { $$ = parse_type->builtin_long; }
> > + { $$ = parse_type (pstate)->builtin_long; }
> > | UNSIGNED LONG INT_KEYWORD
> > - { $$ = parse_type->builtin_unsigned_long; }
> > + { $$ = parse_type (pstate)->builtin_unsigned_long; }
> > | LONG LONG
> > - { $$ = parse_type->builtin_long_long; }
> > + { $$ = parse_type (pstate)->builtin_long_long; }
> > | LONG LONG INT_KEYWORD
> > - { $$ = parse_type->builtin_long_long; }
> > + { $$ = parse_type (pstate)->builtin_long_long; }
> > | UNSIGNED LONG LONG
> > - { $$ = parse_type->builtin_unsigned_long_long; }
> > + { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
> > | UNSIGNED LONG LONG INT_KEYWORD
> > - { $$ = parse_type->builtin_unsigned_long_long; }
> > + { $$ = parse_type (pstate)->builtin_unsigned_long_long; }
> > | SHORT INT_KEYWORD
> > - { $$ = parse_type->builtin_short; }
> > + { $$ = parse_type (pstate)->builtin_short; }
> > | UNSIGNED SHORT INT_KEYWORD
> > - { $$ = parse_type->builtin_unsigned_short; }
> > + { $$ = parse_type (pstate)->builtin_unsigned_short; }
> > | DOUBLE_KEYWORD
> > - { $$ = parse_type->builtin_double; }
> > + { $$ = parse_type (pstate)->builtin_double; }
> > | LONG DOUBLE_KEYWORD
> > - { $$ = parse_type->builtin_long_double; }
> > + { $$ = parse_type (pstate)->builtin_long_double; }
> > | STRUCT name
> > { $$ = lookup_struct (copy_name ($2),
> > expression_context_block); }
> > @@ -915,17 +920,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 (pstate),
> > + parse_gdbarch (pstate),
> > TYPE_NAME($2.type)); }
> > | UNSIGNED
> > - { $$ = parse_type->builtin_unsigned_int; }
> > + { $$ = parse_type (pstate)->builtin_unsigned_int; }
> > | SIGNED_KEYWORD typename
> > - { $$ = lookup_signed_typename (parse_language,
> > - parse_gdbarch,
> > + { $$ = lookup_signed_typename (parse_language (pstate),
> > + parse_gdbarch (pstate),
> > TYPE_NAME($2.type)); }
> > | SIGNED_KEYWORD
> > - { $$ = parse_type->builtin_int; }
> > + { $$ = parse_type (pstate)->builtin_int; }
> > | TEMPLATE name '<' type '>'
> > { $$ = lookup_template_type(copy_name($2), $4,
> > expression_context_block);
> > @@ -942,19 +947,19 @@ typename: TYPENAME
> > {
> > $$.stoken.ptr = "int";
> > $$.stoken.length = 3;
> > - $$.type = parse_type->builtin_int;
> > + $$.type = parse_type (pstate)->builtin_int;
> > }
> > | LONG
> > {
> > $$.stoken.ptr = "long";
> > $$.stoken.length = 4;
> > - $$.type = parse_type->builtin_long;
> > + $$.type = parse_type (pstate)->builtin_long;
> > }
> > | SHORT
> > {
> > $$.stoken.ptr = "short";
> > $$.stoken.length = 5;
> > - $$.type = parse_type->builtin_short;
> > + $$.type = parse_type (pstate)->builtin_short;
> > }
> > ;
> >
> > @@ -998,7 +1003,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 *par_state, 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
> > @@ -1024,7 +1030,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 (par_state), p, len,
> > &putithere->typed_val_float.dval,
> > &putithere->typed_val_float.type))
> > return ERROR;
> > @@ -1130,10 +1136,10 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
> >
> > un = (unsigned LONGEST)n >> 2;
> > if (long_p == 0
> > - && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
> > + && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0)
> > {
> > high_bit
> > - = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
> > + = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
> >
> > /* A large decimal (not hex or octal) constant (between INT_MAX
> > and UINT_MAX) is a long or unsigned long, according to ANSI,
> > @@ -1141,29 +1147,29 @@ 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 (par_state)->builtin_unsigned_int;
> > + signed_type = parse_type (par_state)->builtin_int;
> > }
> > else if (long_p <= 1
> > - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
> > + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 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 (par_state)) - 1);
> > + unsigned_type = parse_type (par_state)->builtin_unsigned_long;
> > + signed_type = parse_type (par_state)->builtin_long;
> > }
> > else
> > {
> > high_bit = (((unsigned LONGEST)1)
> > - << (gdbarch_long_long_bit (parse_gdbarch) - 32 - 1)
> > + << (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 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 (par_state)->builtin_unsigned_long_long;
> > + signed_type = parse_type (par_state)->builtin_long_long;
> > }
> >
> > putithere->typed_val_int.val = n;
> > @@ -1274,12 +1280,12 @@ yylex (void)
> > lexptr++;
> > c = *lexptr++;
> > if (c == '\\')
> > - c = parse_escape (parse_gdbarch, &lexptr);
> > + c = parse_escape (parse_gdbarch (pstate), &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 (pstate)->builtin_char;
> >
> > c = *lexptr++;
> > if (c != '\'')
> > @@ -1397,7 +1403,7 @@ yylex (void)
> > else break;
> > }
> > if (toktype != ERROR)
> > - toktype = parse_number (tokstart, p - tokstart,
> > + toktype = parse_number (pstate, tokstart, p - tokstart,
> > got_dot | got_e, &yylval);
> > if (toktype == ERROR)
> > {
> > @@ -1502,7 +1508,7 @@ yylex (void)
> > break;
> > case '\\':
> > tokptr++;
> > - c = parse_escape (parse_gdbarch, &tokptr);
> > + c = parse_escape (parse_gdbarch (pstate), &tokptr);
> > if (c == -1)
> > {
> > continue;
> > @@ -1563,7 +1569,7 @@ yylex (void)
> > case 8:
> > if (strncmp (tokstart, "unsigned", 8) == 0)
> > return UNSIGNED;
> > - if (parse_language->la_language == language_cplus
> > + if (parse_language (pstate)->la_language == language_cplus
> > && strncmp (tokstart, "template", 8) == 0)
> > return TEMPLATE;
> > if (strncmp (tokstart, "volatile", 8) == 0)
> > @@ -1580,7 +1586,7 @@ yylex (void)
> > return DOUBLE_KEYWORD;
> > break;
> > case 5:
> > - if ((parse_language->la_language == language_cplus)
> > + if ((parse_language (pstate)->la_language == language_cplus)
> > && strncmp (tokstart, "class", 5) == 0)
> > return CLASS;
> > if (strncmp (tokstart, "union", 5) == 0)
> > @@ -1609,7 +1615,7 @@ yylex (void)
> >
> > if (*tokstart == '$')
> > {
> > - write_dollar_variable (yylval.sval);
> > + write_dollar_variable (pstate, yylval.sval);
> > return VARIABLE;
> > }
> >
> > @@ -1624,8 +1630,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 (pstate)->la_language == language_cplus ||
> > + parse_language (pstate)->la_language == language_objc)
> > need_this = &is_a_field_of_this;
> > else
> > need_this = (int *) NULL;
> > @@ -1737,15 +1743,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 (pstate),
> > + parse_gdbarch (pstate), 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 (pstate), tmp);
> > if (Class)
> > {
> > yylval.class.class = Class;
> > @@ -1765,7 +1771,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 (pstate, tokstart, namelen, 0, &newlval);
> > if (hextype == INT)
> > {
> > yylval.ssym.sym = sym;
> > @@ -1781,6 +1787,16 @@ yylex (void)
> > }
> > }
> >
> > +int
> > +objc_parse (struct parser_state *par_state)
> > +{
> > + /* Setting up the parser state. */
> > + gdb_assert (par_state != NULL);
> > + pstate = par_state;
> > +
> > + return _objc_parse ();
> > +}
> > +
> > void
> > yyerror (char *msg)
> > {
> > diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> > index 15bf792..52786cc 100644
> > --- a/gdb/objc-lang.c
> > +++ b/gdb/objc-lang.c
> > @@ -615,7 +615,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;
> > @@ -625,12 +625,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..ba656f8 100644
> > --- a/gdb/objc-lang.h
> > +++ b/gdb/objc-lang.h
> > @@ -26,10 +26,11 @@ 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 (char *); /* Defined in objc-exp.y */
> >
> > extern CORE_ADDR lookup_objc_class (struct gdbarch *gdbarch,
> > char *classname);
> > @@ -48,7 +49,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);
> > --
> > 1.7.7.6
>
> --
> Sergio
--
Joel
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 05/10] Fortran language
2012-06-13 4:59 ` Sergio Durigan Junior
@ 2012-06-13 14:55 ` Joel Brobecker
0 siblings, 0 replies; 40+ messages in thread
From: Joel Brobecker @ 2012-06-13 14:55 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, Tom Tromey
> > Patch for the Fortran language. This patch is similiar to the C
> > language one.
>
> Ping.
Looks equally OK to me. I only skimmed it, but there is only so much
repetition your brain can take :-).
--
Joel
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 08/10] Objective-C language
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:54 ` Joel Brobecker
@ 2012-06-13 16:02 ` Tom Tromey
1 sibling, 0 replies; 40+ messages in thread
From: Tom Tromey @ 2012-06-13 16:02 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> Patch for the Objective-C language. Similar to the C language one.
Sergio> Ping.
>> + return _objc_parse ();
The comment here applies to this patch plus some of the others:
http://sourceware.org/ml/gdb-patches/2012-06/msg00096.html
Also Doug's comment applies to all the parsers:
http://sourceware.org/ml/gdb-patches/2012-06/msg00071.html
I was waiting for a new series to approve them all. Sorry I was not
clear enough about this.
Tom
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 10/10] Go programming language
2012-06-13 4:58 ` Sergio Durigan Junior
@ 2012-06-13 17:02 ` Doug Evans
0 siblings, 0 replies; 40+ messages in thread
From: Doug Evans @ 2012-06-13 17:02 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, Tom Tromey
On Tue, Jun 12, 2012 at 9:57 PM, Sergio Durigan Junior
<sergiodj@redhat.com> wrote:
> On Saturday, June 02 2012, I wrote:
>
>> Patch for the Go programming language. Similar to the C language one.
>
> Ping.
>
> Doug, since you have put this code in, would you like to take a look
> just to be safe?
Righto.
There's some indentation issues with parameters.
If it's because they would otherwise exceed 80 cols, I'm not sure what
the convention is.
@@ -317,9 +322,10 @@ exp : exp '('
being accumulated by an outer function call. */
{ start_arglist (); }
arglist ')' %prec LEFT_ARROW
- { write_exp_elt_opcode (OP_FUNCALL);
- write_exp_elt_longcst ((LONGEST) end_arglist ());
- write_exp_elt_opcode (OP_FUNCALL); }
+ { write_exp_elt_opcode (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate,
+ (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
;
lcurly : '{'
There's also the thought of making sure pstate is reset to NULL.
@@ -1587,14 +1603,20 @@ yylex (void)
popping = 1;
yylval = current.value;
- return classify_name (expression_context_block);
+ return classify_name (pstate, expression_context_block);
}
int
-go_parse (void)
+go_parse (struct parser_state *par_state)
{
int result;
- struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+ struct cleanup *back_to;
+
+ /* Setting up the parser state. */
+ gdb_assert (par_state != NULL);
+ pstate = par_state;
+
+ back_to = make_cleanup (null_cleanup, NULL);
make_cleanup_restore_integer (&yydebug);
yydebug = parser_debug;
Other than that LGTM.
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 07/10] Modula-2 language
2012-06-13 14:51 ` Joel Brobecker
@ 2012-06-16 14:29 ` Gaius Mulley
0 siblings, 0 replies; 40+ messages in thread
From: Gaius Mulley @ 2012-06-16 14:29 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Sergio Durigan Junior, GDB Patches
Joel Brobecker <brobecker@adacore.com> writes:
>> > Patch for the Modula-2 language. Similar to the C language one.
>>
>> Ping.
>>
>> I don't know exactly who is the maintainer of Modula-2...
>
> It's Gaius Mulley (in Cc). I thkn that the changes are sufficiently
> mechanical that we can go with GM approval if the language maintainer
> doesn't comment.
Hi,
apologies for the late reply - yes these look fine,
regards,
Gaius
^ permalink raw reply [flat|nested] 40+ messages in thread
end of thread, other threads:[~2012-06-16 14:29 UTC | newest]
Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-02 19:33 [PATCH 00/10] Remove `expout*' globals from parser-defs.h Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 01/10] Language independent bits Sergio Durigan Junior
2012-06-04 20:20 ` Tom Tromey
2012-06-05 0:39 ` Sergio Durigan Junior
2012-06-02 19:33 ` [PATCH 02/10] SystemTap integration Sergio Durigan Junior
2012-06-04 20:23 ` Tom Tromey
2012-06-02 19:34 ` [PATCH 03/10] C language Sergio Durigan Junior
2012-06-04 4:25 ` Doug Evans
2012-06-04 4:32 ` Sergio Durigan Junior
2012-06-04 20:32 ` Tom Tromey
2012-06-04 20:39 ` Sergio Durigan Junior
2012-06-04 20:42 ` Mark Kettenis
2012-06-04 20:49 ` Sergio Durigan Junior
2012-06-04 21:19 ` Mark Kettenis
2012-06-06 19:17 ` Tom Tromey
2012-06-02 20:23 ` [PATCH 04/10] Ada language Sergio Durigan Junior
2012-06-13 4:57 ` Sergio Durigan Junior
2012-06-13 14:50 ` Joel Brobecker
2012-06-02 20:23 ` [PATCH 10/10] Go programming language Sergio Durigan Junior
2012-06-13 4:58 ` Sergio Durigan Junior
2012-06-13 17:02 ` Doug Evans
2012-06-02 20:24 ` [PATCH 05/10] Fortran language Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:55 ` Joel Brobecker
2012-06-02 20:24 ` [PATCH 08/10] Objective-C language Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:54 ` Joel Brobecker
2012-06-13 16:02 ` Tom Tromey
2012-06-02 20:33 ` [PATCH 07/10] Modula-2 language Sergio Durigan Junior
2012-06-13 4:59 ` Sergio Durigan Junior
2012-06-13 14:51 ` Joel Brobecker
2012-06-16 14:29 ` Gaius Mulley
2012-06-02 20:33 ` [PATCH 09/10] Pascal language Sergio Durigan Junior
2012-06-05 7:39 ` Pierre Muller
2012-06-02 20:34 ` [PATCH 06/10] Java language Sergio Durigan Junior
2012-06-04 20:27 ` Tom Tromey
2012-06-05 0:35 ` Sergio Durigan Junior
2012-06-06 20:02 ` Tom Tromey
2012-06-07 0:57 ` Joel Brobecker
2012-06-04 20:38 ` [PATCH 00/10] Remove `expout*' 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