aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-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/f-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/f-exp.y')
-rw-r--r--gdb/f-exp.y30
1 files changed, 19 insertions, 11 deletions
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index da47322..403dfa2 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -54,6 +54,7 @@
#include "block.h"
#include <ctype.h>
#include <algorithm>
+#include "type-stack.h"
#define parse_type(ps) builtin_type (ps->gdbarch ())
#define parse_f_type(ps) builtin_f_type (ps->gdbarch ())
@@ -71,6 +72,9 @@ static struct parser_state *pstate = NULL;
/* Depth of parentheses. */
static int paren_depth;
+/* The current type stack. */
+static struct type_stack *type_stack;
+
int yyparse (void);
static int yylex (void);
@@ -515,7 +519,7 @@ ptype : typebase
struct type *range_type;
while (!done)
- switch (pop_type ())
+ switch (type_stack->pop ())
{
case tp_end:
done = 1;
@@ -527,7 +531,7 @@ ptype : typebase
follow_type = lookup_lvalue_reference_type (follow_type);
break;
case tp_array:
- array_size = pop_type_int ();
+ array_size = type_stack->pop_int ();
if (array_size != -1)
{
range_type =
@@ -547,7 +551,7 @@ ptype : typebase
break;
case tp_kind:
{
- int kind_val = pop_type_int ();
+ int kind_val = type_stack->pop_int ();
follow_type
= convert_to_kind_type (follow_type, kind_val);
}
@@ -558,13 +562,13 @@ ptype : typebase
;
abs_decl: '*'
- { push_type (tp_pointer); $$ = 0; }
+ { type_stack->push (tp_pointer); $$ = 0; }
| '*' abs_decl
- { push_type (tp_pointer); $$ = $2; }
+ { type_stack->push (tp_pointer); $$ = $2; }
| '&'
- { push_type (tp_reference); $$ = 0; }
+ { type_stack->push (tp_reference); $$ = 0; }
| '&' abs_decl
- { push_type (tp_reference); $$ = $2; }
+ { type_stack->push (tp_reference); $$ = $2; }
| direct_abs_decl
;
@@ -575,9 +579,9 @@ direct_abs_decl: '(' abs_decl ')'
| '*' INT
{ push_kind_type ($2.val, $2.type); }
| direct_abs_decl func_mod
- { push_type (tp_function); }
+ { type_stack->push (tp_function); }
| func_mod
- { push_type (tp_function); }
+ { type_stack->push (tp_function); }
;
func_mod: '(' ')'
@@ -821,8 +825,8 @@ push_kind_type (LONGEST val, struct type *type)
ival = static_cast <int> (val);
}
- push_type_int (ival);
- push_type (tp_kind);
+ type_stack->push (ival);
+ type_stack->push (tp_kind);
}
/* Called when a type has a '(kind=N)' modifier after it, for example
@@ -1333,6 +1337,10 @@ f_parse (struct parser_state *par_state)
pstate = par_state;
paren_depth = 0;
+ struct type_stack stack;
+ scoped_restore restore_type_stack = make_scoped_restore (&type_stack,
+ &stack);
+
return yyparse ();
}