aboutsummaryrefslogtreecommitdiff
path: root/gdb/d-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-03-31 13:43:54 -0600
committerTom Tromey <tom@tromey.com>2019-04-04 19:55:11 -0600
commitdac43e327d002107f6bc9481749de039f410df73 (patch)
treee3f3ae3d7b892d2a68e271127e5b53cf75e2c0d0 /gdb/d-exp.y
parent2a61252965c91540133bece7deb92eb22e3cf929 (diff)
downloadgdb-dac43e327d002107f6bc9481749de039f410df73.zip
gdb-dac43e327d002107f6bc9481749de039f410df73.tar.gz
gdb-dac43e327d002107f6bc9481749de039f410df73.tar.bz2
Move type stack handling to a new class
This introduces a new "type_stack" class, and moves all the parser type stack handling to this class. Parsers that wish to use this facility must now instantiate this class somehow. I chose this approach because a minority of the existing parsers require this. gdb/ChangeLog 2019-04-04 Tom Tromey <tom@tromey.com> * type-stack.h: New file. * type-stack.c: New file. * parser-defs.h (enum type_pieces, union type_stack_elt): Move to type-stack.h. (insert_into_type_stack, insert_type, push_type, push_type_int) (insert_type_address_space, pop_type, pop_type_int) (pop_typelist, pop_type_stack, append_type_stack) (push_type_stack, get_type_stack, push_typelist) (follow_type_instance_flags, follow_types): Don't declare. * parse.c (type_stack): Remove global. (parse_exp_in_context): Update. (insert_into_type_stack, insert_type, push_type, push_type_int) (insert_type_address_space, pop_type, pop_type_int) (pop_typelist, pop_type_stack, append_type_stack) (push_type_stack, get_type_stack, push_typelist) (follow_type_instance_flags, follow_types): Remove (moved to type-stack.c). * f-exp.y (type_stack): New global. Update rules. (push_kind_type, f_parse): Update. * d-exp.y (type_stack): New global. Update rules. (d_parse): Update. * c-exp.y (struct c_parse_state) <type_stack>: New member. Update rules. * Makefile.in (COMMON_SFILES): Add type-stack.c. (HFILES_NO_SRCDIR): Add type-stack.h.
Diffstat (limited to 'gdb/d-exp.y')
-rw-r--r--gdb/d-exp.y22
1 files changed, 15 insertions, 7 deletions
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 4d51cfd..ca9aaf8 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -51,6 +51,7 @@
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
#include "charset.h"
#include "block.h"
+#include "type-stack.h"
#define parse_type(ps) builtin_type (ps->gdbarch ())
#define parse_d_type(ps) builtin_d_type (ps->gdbarch ())
@@ -65,6 +66,9 @@
static struct parser_state *pstate = NULL;
+/* The current type stack. */
+static struct type_stack *type_stack;
+
int yyparse (void);
static int yylex (void);
@@ -606,7 +610,7 @@ TypeExp:
write_exp_elt_type (pstate, $1);
write_exp_elt_opcode (pstate, OP_TYPE); }
| BasicType BasicType2
- { $$ = follow_types ($1);
+ { $$ = type_stack->follow_types ($1);
write_exp_elt_opcode (pstate, OP_TYPE);
write_exp_elt_type (pstate, $$);
write_exp_elt_opcode (pstate, OP_TYPE);
@@ -615,15 +619,15 @@ TypeExp:
BasicType2:
'*'
- { push_type (tp_pointer); }
+ { type_stack->push (tp_pointer); }
| '*' BasicType2
- { push_type (tp_pointer); }
+ { type_stack->push (tp_pointer); }
| '[' INTEGER_LITERAL ']'
- { push_type_int ($2.val);
- push_type (tp_array); }
+ { type_stack->push ($2.val);
+ type_stack->push (tp_array); }
| '[' INTEGER_LITERAL ']' BasicType2
- { push_type_int ($2.val);
- push_type (tp_array); }
+ { type_stack->push ($2.val);
+ type_stack->push (tp_array); }
;
BasicType:
@@ -1619,6 +1623,10 @@ d_parse (struct parser_state *par_state)
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
parser_debug);
+ struct type_stack stack;
+ scoped_restore restore_type_stack = make_scoped_restore (&type_stack,
+ &stack);
+
/* Initialize some state used by the lexer. */
last_was_structop = 0;
saw_name_at_eof = 0;