2019-04-04 Tom Tromey <tom@tromey.com>
+ * rust-exp.y (rust_parser::crate_name, rust_parser::super_name)
+ (rust_parser::convert_ast_to_type)
+ (rust_parser::convert_ast_to_expression, rust_lex_tests): Update.
+ * parser-defs.h (struct parser_state) <parser_state>: Add
+ parameters. Initialize new members.
+ <expression_context_block, expression_context_pc>: New members.
+ * parse.c (expression_context_block, expression_context_pc):
+ Remove globals.
+ (parse_exp_in_context): Update.
+ * p-exp.y: Update all rules.
+ (yylex): Update.
+ * m2-exp.y: Update all rules.
+ (yylex): Update.
+ * go-exp.y (yylex): Update.
+ * f-exp.y (yylex): Update.
+ * d-exp.y: Update all rules.
+ (yylex): Update.
+ * c-exp.y: Update all rules.
+ (lex_one_token, classify_name, yylex, c_parse): Update.
+ * ada-exp.y (write_var_or_type, write_name_assoc): Update.
+
+2019-04-04 Tom Tromey <tom@tromey.com>
+
* gdbarch.h, gdbarch.c: Rebuild.
* gdbarch.sh (dtrace_parse_probe_argument): Change type.
* stap-probe.h:
int name_len;
if (block == NULL)
- block = expression_context_block;
+ block = par_state->expression_context_block;
encoded_name = ada_encode (name0.ptr);
name_len = strlen (encoded_name);
if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
error (_("No symbol table is loaded. Use the \"file\" command."));
- if (block == expression_context_block)
+ if (block == par_state->expression_context_block)
error (_("No definition of \"%s\" in current context."), name0.ptr);
else
error (_("No definition of \"%s\" in specified context."), name0.ptr);
if (strchr (name.ptr, '.') == NULL)
{
std::vector<struct block_symbol> syms;
- int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
+ int nsyms = ada_lookup_symbol_list (name.ptr,
+ par_state->expression_context_block,
VAR_DOMAIN, &syms);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
/* This could potentially be a an argument defined
lookup function (Koenig). */
write_exp_elt_opcode (pstate, OP_ADL_FUNC);
- write_exp_elt_block (pstate,
- expression_context_block);
+ write_exp_elt_block
+ (pstate, pstate->expression_context_block);
write_exp_elt_sym (pstate,
NULL); /* Placeholder. */
write_exp_string (pstate, $1.stoken);
NULL,
0); }
| STRUCT name
- { $$ = lookup_struct (copy_name ($2),
- expression_context_block); }
+ { $$
+ = lookup_struct (copy_name ($2),
+ pstate->expression_context_block);
+ }
| STRUCT COMPLETE
{
mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
$$ = NULL;
}
| CLASS name
- { $$ = lookup_struct (copy_name ($2),
- expression_context_block); }
+ { $$ = lookup_struct
+ (copy_name ($2), pstate->expression_context_block);
+ }
| CLASS COMPLETE
{
mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
$$ = NULL;
}
| UNION name
- { $$ = lookup_union (copy_name ($2),
- expression_context_block); }
+ { $$
+ = lookup_union (copy_name ($2),
+ pstate->expression_context_block);
+ }
| UNION COMPLETE
{
mark_completion_tag (TYPE_CODE_UNION, "", 0);
}
| ENUM name
{ $$ = lookup_enum (copy_name ($2),
- expression_context_block); }
+ pstate->expression_context_block);
+ }
| ENUM COMPLETE
{
mark_completion_tag (TYPE_CODE_ENUM, "", 0);
reduced; template recognition happens by lookahead
in the token processing code in yylex. */
| TEMPLATE name '<' type '>'
- { $$ = lookup_template_type(copy_name($2), $4,
- expression_context_block);
+ { $$ = lookup_template_type
+ (copy_name($2), $4,
+ pstate->expression_context_block);
}
| const_or_volatile_or_space_identifier_noopt typebase
{ $$ = follow_types ($2); }
struct field_of_this_result is_a_field_of_this;
$$.stoken = $1;
- $$.sym = lookup_symbol ($1.ptr,
- expression_context_block,
- VAR_DOMAIN,
- &is_a_field_of_this);
+ $$.sym
+ = lookup_symbol ($1.ptr,
+ pstate->expression_context_block,
+ VAR_DOMAIN,
+ &is_a_field_of_this);
$$.is_a_field_of_this
= is_a_field_of_this.type != NULL;
}
{
struct field_of_this_result is_a_field_of_this;
- if (lookup_symbol (copy, expression_context_block,
+ if (lookup_symbol (copy,
+ pstate->expression_context_block,
VAR_DOMAIN,
(par_state->language ()->la_language
== language_cplus ? &is_a_field_of_this
struct symbol *sym;
yylval.theclass.theclass = Class;
- sym = lookup_struct_typedef (copy, expression_context_block, 1);
+ sym = lookup_struct_typedef (copy,
+ par_state->expression_context_block, 1);
if (sym)
yylval.theclass.type = SYMBOL_TYPE (sym);
return CLASSNAME;
name-like token. */
current.token = lex_one_token (pstate, &is_quoted_name);
if (current.token == NAME)
- current.token = classify_name (pstate, expression_context_block,
+ current.token = classify_name (pstate, pstate->expression_context_block,
is_quoted_name, last_lex_was_structop);
if (pstate->language ()->la_language != language_cplus
|| (current.token != TYPENAME && current.token != COLONCOLON
else
{
gdb_assert (current.token == TYPENAME);
- search_block = expression_context_block;
+ search_block = pstate->expression_context_block;
obstack_grow (&name_obstack, current.value.sval.ptr,
current.value.sval.length);
context_type = current.value.tsym.type;
gdb::unique_xmalloc_ptr<struct macro_scope> macro_scope;
- if (expression_context_block)
- macro_scope = sal_macro_scope (find_pc_line (expression_context_pc, 0));
+ if (par_state->expression_context_block)
+ macro_scope
+ = sal_macro_scope (find_pc_line (par_state->expression_context_pc, 0));
else
macro_scope = default_macro_scope ();
if (! macro_scope)
struct block_symbol sym;
/* Handle VAR, which could be local or global. */
- sym = lookup_symbol (copy, expression_context_block, VAR_DOMAIN,
- &is_a_field_of_this);
+ sym = lookup_symbol (copy, pstate->expression_context_block,
+ VAR_DOMAIN, &is_a_field_of_this);
if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
{
if (symbol_read_needs_frame (sym.symbol))
if (current.token == IDENTIFIER)
{
yylval = current.value;
- current.token = classify_name (pstate, expression_context_block);
+ current.token = classify_name (pstate, pstate->expression_context_block);
current.value = yylval;
}
yylval.sval.ptr = (char *) obstack_base (&name_obstack);
yylval.sval.length = obstack_object_size (&name_obstack);
- current.token = classify_name (pstate, expression_context_block);
+ current.token = classify_name (pstate,
+ pstate->expression_context_block);
current.value = yylval;
/* We keep going until we find a TYPENAME. */
else
{
gdb_assert (current.token == TYPENAME);
- search_block = expression_context_block;
+ search_block = pstate->expression_context_block;
obstack_grow (&name_obstack, current.value.sval.ptr,
current.value.sval.length);
context_type = current.value.tsym.type;
way we can refer to it unconditionally below. */
memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
- result = lookup_symbol (tmp, expression_context_block,
+ result = lookup_symbol (tmp, pstate->expression_context_block,
lookup_domains[i],
pstate->language ()->la_language
== language_cplus
return classify_unsafe_function (name2.value.sval);
}
- if (package_name_p (copy, expression_context_block))
+ if (package_name_p (copy, pstate->expression_context_block))
{
popping = 1;
yylval.sval = build_packaged_name (current.value.sval.ptr,
current.value.sval.length,
name2.value.sval.ptr,
name2.value.sval.length);
- return classify_packaged_name (expression_context_block);
+ return classify_packaged_name (pstate->expression_context_block);
}
}
popping = 1;
yylval = current.value;
- return classify_name (pstate, expression_context_block);
+ return classify_name (pstate, pstate->expression_context_block);
}
int
fblock : BLOCKNAME
{ struct symbol *sym
= lookup_symbol (copy_name ($1),
- expression_context_block,
+ pstate->expression_context_block,
VAR_DOMAIN, 0).symbol;
$$ = sym;}
;
{ struct block_symbol sym;
struct field_of_this_result is_a_field_of_this;
- sym = lookup_symbol (copy_name ($1),
- expression_context_block,
- VAR_DOMAIN,
- &is_a_field_of_this);
+ sym
+ = lookup_symbol (copy_name ($1),
+ pstate->expression_context_block,
+ VAR_DOMAIN,
+ &is_a_field_of_this);
if (sym.symbol)
{
type
: TYPENAME
- { $$ = lookup_typename (pstate->language (),
- pstate->gdbarch (),
- copy_name ($1),
- expression_context_block, 0); }
+ { $$
+ = lookup_typename (pstate->language (),
+ pstate->gdbarch (),
+ copy_name ($1),
+ pstate->expression_context_block,
+ 0);
+ }
;
if (lookup_symtab (tmp))
return BLOCKNAME;
- sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0).symbol;
+ sym = lookup_symbol (tmp, pstate->expression_context_block,
+ VAR_DOMAIN, 0).symbol;
if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
return BLOCKNAME;
if (lookup_typename (pstate->language (), pstate->gdbarch (),
copy_name (yylval.sval),
- expression_context_block, 1))
+ pstate->expression_context_block, 1))
return TYPENAME;
if(sym)
| TYPENAME
{ $$ = $1.type; }
| STRUCT name
- { $$ = lookup_struct (copy_name ($2),
- expression_context_block); }
+ { $$
+ = lookup_struct (copy_name ($2),
+ pstate->expression_context_block);
+ }
| CLASS name
- { $$ = lookup_struct (copy_name ($2),
- expression_context_block); }
+ { $$
+ = lookup_struct (copy_name ($2),
+ pstate->expression_context_block);
+ }
/* "const" and "volatile" are curently ignored. A type qualifier
after the type is handled in the ptype rule. I think these could
be too. */
inserted in FPC stabs debug info. */
static const char this_name[] = "this";
- if (lookup_symbol (this_name, expression_context_block,
+ if (lookup_symbol (this_name, pstate->expression_context_block,
VAR_DOMAIN, NULL).symbol)
{
free (uptokstart);
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, expression_context_block,
+ sym = lookup_symbol (tmp, pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
/* second chance uppercased (as Free Pascal does). */
if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, expression_context_block,
+ sym = lookup_symbol (tmp, pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
}
/* Third chance Capitalized (as GPC does). */
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, expression_context_block,
+ sym = lookup_symbol (tmp, pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
}
tmp1 += 2;
memcpy (tmp1, namestart, p - namestart);
tmp1[p - namestart] = '\0';
- cur_sym = lookup_symbol (ncopy, expression_context_block,
- VAR_DOMAIN, NULL).symbol;
+ cur_sym
+ = lookup_symbol (ncopy,
+ pstate->expression_context_block,
+ VAR_DOMAIN, NULL).symbol;
if (cur_sym)
{
if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
};
\f
/* Global variables declared in parser-defs.h (and commented there). */
-const struct block *expression_context_block;
-CORE_ADDR expression_context_pc;
innermost_block_tracker innermost_block;
int arglist_len;
static struct type_stack type_stack;
value in the value history, I.e. $$1 */
void
-write_dollar_variable (struct expr_builder *ps, struct stoken str)
+write_dollar_variable (struct parser_state *ps, struct stoken str)
{
struct block_symbol sym;
struct bound_minimal_symbol msym;
str.ptr++;
write_exp_string (ps, str);
write_exp_elt_opcode (ps, OP_REGISTER);
- innermost_block.update (expression_context_block,
+ innermost_block.update (ps->expression_context_block,
INNERMOST_BLOCK_FOR_REGISTERS);
return;
}
scoped_restore save_funcall_chain = make_scoped_restore (&funcall_chain,
&funcalls);
- expression_context_block = block;
+ const struct block *expression_context_block = block;
+ CORE_ADDR expression_context_pc = 0;
/* If no context specified, try using the current frame, if any. */
if (!expression_context_block)
and others called from *.y) ensure CURRENT_LANGUAGE gets restored
to the value matching SELECTED_FRAME as set by get_current_arch. */
- parser_state ps (lang, get_current_arch ());
+ parser_state ps (lang, get_current_arch (), expression_context_block,
+ expression_context_pc);
scoped_restore_current_language lang_saver;
set_language (lang->la_language);
And GDBARCH is the gdbarch to use during parsing. */
parser_state (const struct language_defn *lang,
- struct gdbarch *gdbarch)
- : expr_builder (lang, gdbarch)
+ struct gdbarch *gdbarch,
+ const struct block *context_block,
+ CORE_ADDR context_pc)
+ : expr_builder (lang, gdbarch),
+ expression_context_block (context_block),
+ expression_context_pc (context_pc)
{
}
DISABLE_COPY_AND_ASSIGN (parser_state);
-};
-/* If this is nonzero, this block is used as the lexical context
- for symbol names. */
+ /* If this is nonzero, this block is used as the lexical context for
+ symbol names. */
-extern const struct block *expression_context_block;
+ const struct block * const expression_context_block;
-/* If expression_context_block is non-zero, then this is the PC within
- the block that we want to evaluate expressions at. When debugging
- C or C++ code, we use this to find the exact line we're at, and
- then look up the macro definitions active at that point. */
-extern CORE_ADDR expression_context_pc;
+ /* If expression_context_block is non-zero, then this is the PC
+ within the block that we want to evaluate expressions at. When
+ debugging C or C++ code, we use this to find the exact line we're
+ at, and then look up the macro definitions active at that
+ point. */
+ const CORE_ADDR expression_context_pc;
+};
/* When parsing expressions we track the innermost block that was
referenced. */
extern void write_exp_msymbol (struct expr_builder *,
struct bound_minimal_symbol);
-extern void write_dollar_variable (struct expr_builder *, struct stoken str);
+extern void write_dollar_variable (struct parser_state *, struct stoken str);
extern void mark_struct_expression (struct expr_builder *);
const struct rust_op *
rust_parser::crate_name (const struct rust_op *name)
{
- std::string crate = rust_crate_for_block (expression_context_block);
+ std::string crate = rust_crate_for_block (pstate->expression_context_block);
struct stoken result;
gdb_assert (name->opcode == OP_VAR_VALUE);
const struct rust_op *
rust_parser::super_name (const struct rust_op *ident, unsigned int n_supers)
{
- const char *scope = block_scope (expression_context_block);
+ const char *scope = block_scope (pstate->expression_context_block);
int offset;
gdb_assert (ident->opcode == OP_VAR_VALUE);
{
const char *varname = convert_name (operation);
- result = rust_lookup_type (varname, expression_context_block);
+ result = rust_lookup_type (varname, pstate->expression_context_block);
if (result == NULL)
error (_("No typed name '%s' in current context"), varname);
return result;
/* We don't allow creating new tuple types (yet), but we do
allow looking up existing tuple types. */
- result = rust_lookup_type (name, expression_context_block);
+ result = rust_lookup_type (name, pstate->expression_context_block);
if (result == NULL)
error (_("could not find tuple type '%s'"), name);
}
struct type *type;
const char *varname = convert_name (operation->left.op);
- type = rust_lookup_type (varname, expression_context_block);
+ type = rust_lookup_type (varname,
+ pstate->expression_context_block);
if (type != NULL)
{
/* This is actually a tuple struct expression, not a
}
varname = convert_name (operation);
- sym = rust_lookup_symbol (varname, expression_context_block,
+ sym = rust_lookup_symbol (varname, pstate->expression_context_block,
VAR_DOMAIN);
if (sym.symbol != NULL && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
{
type = SYMBOL_TYPE (sym.symbol);
}
if (type == NULL)
- type = rust_lookup_type (varname, expression_context_block);
+ type = rust_lookup_type (varname,
+ pstate->expression_context_block);
if (type == NULL)
error (_("No symbol '%s' in current context"), varname);
}
name = convert_name (operation->left.op);
- type = rust_lookup_type (name, expression_context_block);
+ type = rust_lookup_type (name, pstate->expression_context_block);
if (type == NULL)
error (_("Could not find type '%s'"), operation->left.sval.ptr);
int i;
// Set up dummy "parser", so that rust_type works.
- struct parser_state ps (&rust_language_defn, target_gdbarch ());
+ struct parser_state ps (&rust_language_defn, target_gdbarch (),
+ nullptr, 0);
rust_parser parser (&ps);
rust_lex_test_one (&parser, "", 0);