/* Parse expressions for GDB.
- Copyright (C) 1986-2014 Free Software Foundation, Inc.
+ Copyright (C) 1986-2016 Free Software Foundation, Inc.
Modified from expread.y by the Department of Computer Science at the
State University of New York at Buffalo, 1991.
#include "source.h"
#include "objfiles.h"
#include "user-regs.h"
+#include <algorithm>
/* Standard set of definitions for printing, dumping, prefixifying,
* and evaluating expressions. */
static int prefixify_subexp (struct expression *, struct expression *, int,
int);
-static struct expression *parse_exp_in_context (const char **, CORE_ADDR,
- const struct block *, int,
- int, int *);
-static struct expression *parse_exp_in_context_1 (const char **, CORE_ADDR,
- const struct block *, int,
- int, int *);
+static expression_up parse_exp_in_context (const char **, CORE_ADDR,
+ const struct block *, int,
+ int, int *);
+static expression_up parse_exp_in_context_1 (const char **, CORE_ADDR,
+ const struct block *, int,
+ int, int *);
void _initialize_parse (void);
void
start_arglist (void)
{
- struct funcall *new;
+ struct funcall *newobj;
- new = (struct funcall *) xmalloc (sizeof (struct funcall));
- new->next = funcall_chain;
- new->arglist_len = arglist_len;
+ newobj = XNEW (struct funcall);
+ newobj->next = funcall_chain;
+ newobj->arglist_len = arglist_len;
arglist_len = 0;
- funcall_chain = new;
+ funcall_chain = newobj;
}
/* Return the number of arguments in a function call just terminated,
{
ps->expout_size = initial_size;
ps->expout_ptr = 0;
- ps->expout = xmalloc (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size));
+ ps->expout
+ = (struct expression *) xmalloc (sizeof (struct expression)
+ + EXP_ELEM_TO_BYTES (ps->expout_size));
ps->expout->language_defn = lang;
ps->expout->gdbarch = gdbarch;
}
|| tag == TYPE_CODE_STRUCT
|| tag == TYPE_CODE_ENUM);
expout_tag_completion_type = tag;
- expout_completion_name = xmalloc (length + 1);
+ expout_completion_name = (char *) xmalloc (length + 1);
memcpy (expout_completion_name, ptr, length);
expout_completion_name[length] = '\0';
}
void
write_dollar_variable (struct parser_state *ps, struct stoken str)
{
- struct symbol *sym = NULL;
+ struct block_symbol sym;
struct bound_minimal_symbol msym;
struct internalvar *isym = NULL;
sym = lookup_symbol (copy_name (str), (struct block *) NULL,
VAR_DOMAIN, NULL);
- if (sym)
+ if (sym.symbol)
{
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_block (ps, sym.block);
+ write_exp_elt_sym (ps, sym.symbol);
write_exp_elt_opcode (ps, OP_VAR_VALUE);
return;
}
if (namecopy_size < token.length + 1)
{
namecopy_size = token.length + 1;
- namecopy = xrealloc (namecopy, token.length + 1);
+ namecopy = (char *) xrealloc (namecopy, token.length + 1);
}
memcpy (namecopy, token.ptr, token.length);
{
int oplen = 1;
int args = 0;
- enum f90_range_type range_type;
+ enum range_type range_type;
int i;
if (endpos < 1)
oplen = 2;
break;
- case OP_F90_RANGE:
+ case OP_RANGE:
oplen = 3;
+ range_type = (enum range_type)
+ longest_to_int (expr->elts[endpos - 2].longconst);
- range_type = longest_to_int (expr->elts[endpos - 2].longconst);
switch (range_type)
{
case LOW_BOUND_DEFAULT:
If COMMA is nonzero, stop if a comma is reached. */
-struct expression *
+expression_up
parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block,
int comma)
{
return parse_exp_in_context (stringptr, pc, block, comma, 0, NULL);
}
-static struct expression *
+static expression_up
parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
const struct block *block,
int comma, int void_context_p, int *out_subexp)
left-hand-side of the struct op. If not doing such completion, it
is left untouched. */
-static struct expression *
+static expression_up
parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
const struct block *block,
int comma, int void_context_p, int *out_subexp)
{
- volatile struct gdb_exception except;
struct cleanup *old_chain, *inner_chain;
const struct language_defn *lang = NULL;
struct parser_state ps;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
if (cursal.symtab)
expression_context_block
- = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK);
+ = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (cursal.symtab),
+ STATIC_BLOCK);
if (expression_context_block)
expression_context_pc = BLOCK_START (expression_context_block);
}
inner_chain = make_cleanup_restore_current_language ();
set_language (lang->la_language);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
if (lang->la_parser (&ps))
lang->la_error (NULL);
}
- if (except.reason < 0)
+ CATCH (except, RETURN_MASK_ALL)
{
if (! parse_completion)
{
throw_exception (except);
}
}
+ END_CATCH
reallocate_expout (&ps);
discard_cleanups (old_chain);
*stringptr = lexptr;
- return ps.expout;
+ return expression_up (ps.expout);
}
/* Parse STRING as an expression, and complain if this fails
to use up all of the contents of STRING. */
-struct expression *
+expression_up
parse_expression (const char *string)
{
- struct expression *exp;
-
- exp = parse_exp_1 (&string, 0, 0, 0);
+ expression_up exp = parse_exp_1 (&string, 0, 0, 0);
if (*string)
error (_("Junk after end of expression."));
return exp;
}
+/* Same as parse_expression, but using the given language (LANG)
+ to parse the expression. */
+
+expression_up
+parse_expression_with_language (const char *string, enum language lang)
+{
+ struct cleanup *old_chain = NULL;
+
+ if (current_language->la_language != lang)
+ {
+ old_chain = make_cleanup_restore_current_language ();
+ set_language (lang);
+ }
+
+ expression_up expr = parse_expression (string);
+
+ if (old_chain != NULL)
+ do_cleanups (old_chain);
+ return expr;
+}
+
/* Parse STRING as an expression. If parsing ends in the middle of a
field reference, return the type of the left-hand-side of the
reference; furthermore, if the parsing ends in the field name,
parse_expression_for_completion (const char *string, char **name,
enum type_code *code)
{
- struct expression *exp = NULL;
+ expression_up exp;
struct value *val;
int subexp;
- volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ERROR)
+ TRY
{
parse_completion = 1;
exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp);
}
+ CATCH (except, RETURN_MASK_ERROR)
+ {
+ /* Nothing, EXP remains NULL. */
+ }
+ END_CATCH
+
parse_completion = 0;
- if (except.reason < 0 || ! exp)
+ if (exp == NULL)
return NULL;
if (expout_tag_completion_type != TYPE_CODE_UNDEF)
}
if (expout_last_struct == -1)
- {
- xfree (exp);
- return NULL;
- }
+ return NULL;
- *name = extract_field_op (exp, &subexp);
+ *name = extract_field_op (exp.get (), &subexp);
if (!*name)
- {
- xfree (exp);
- return NULL;
- }
+ return NULL;
/* This might throw an exception. If so, we want to let it
propagate. */
- val = evaluate_subexpression_type (exp, subexp);
+ val = evaluate_subexpression_type (exp.get (), subexp);
/* (*NAME) is a part of the EXP memory block freed below. */
*name = xstrdup (*name);
- xfree (exp);
return value_type (val);
}
char *copy;
int n, num;
- copy = xmalloc (len + 1);
+ copy = (char *) xmalloc (len + 1);
memcpy (copy, p, len);
copy[len] = 0;
stack->size *= 2;
if (stack->size < howmuch)
stack->size = howmuch;
- stack->elements = xrealloc (stack->elements,
- stack->size * sizeof (union type_stack_elt));
+ stack->elements = XRESIZEVEC (union type_stack_elt, stack->elements,
+ stack->size);
}
}
void
type_stack_cleanup (void *arg)
{
- struct type_stack *stack = arg;
+ struct type_stack *stack = (struct type_stack *) arg;
xfree (stack->elements);
xfree (stack);
/* Check objfile where the variable itself is placed.
SYMBOL_OBJ_SECTION (symbol) may be NULL. */
- if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
+ if ((*objfile_func) (symbol_objfile (symbol), data))
return 1;
/* Check objfile where is placed the code touching the variable. */
static int
exp_uses_objfile_iter (struct objfile *exp_objfile, void *objfile_voidp)
{
- struct objfile *objfile = objfile_voidp;
+ struct objfile *objfile = (struct objfile *) objfile_voidp;
if (exp_objfile->separate_debug_objfile_backlink)
exp_objfile = exp_objfile->separate_debug_objfile_backlink;
{
if ((ps->expout_ptr + lenelt) >= ps->expout_size)
{
- ps->expout_size = max (ps->expout_size * 2,
+ ps->expout_size = std::max (ps->expout_size * 2,
ps->expout_ptr + lenelt + 10);
ps->expout = (struct expression *)
xrealloc (ps->expout, (sizeof (struct expression)