/* Evaluate expressions for GDB.
- Copyright (C) 1986-2015 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 Free Software Foundation, Inc.
This file is part of GDB.
CORE_ADDR
parse_and_eval_address (const char *exp)
{
- struct expression *expr = parse_expression (exp);
- CORE_ADDR addr;
- struct cleanup *old_chain =
- make_cleanup (free_current_contents, &expr);
-
- addr = value_as_address (evaluate_expression (expr));
- do_cleanups (old_chain);
- return addr;
+ expression_up expr = parse_expression (exp);
+
+ return value_as_address (evaluate_expression (expr.get ()));
}
/* Like parse_and_eval_address, but treats the value of the expression
LONGEST
parse_and_eval_long (const char *exp)
{
- struct expression *expr = parse_expression (exp);
- LONGEST retval;
- struct cleanup *old_chain =
- make_cleanup (free_current_contents, &expr);
-
- retval = value_as_long (evaluate_expression (expr));
- do_cleanups (old_chain);
- return (retval);
+ expression_up expr = parse_expression (exp);
+
+ return value_as_long (evaluate_expression (expr.get ()));
}
struct value *
parse_and_eval (const char *exp)
{
- struct expression *expr = parse_expression (exp);
- struct value *val;
- struct cleanup *old_chain =
- make_cleanup (free_current_contents, &expr);
+ expression_up expr = parse_expression (exp);
- val = evaluate_expression (expr);
- do_cleanups (old_chain);
- return val;
+ return evaluate_expression (expr.get ());
}
/* Parse up to a comma (or to a closeparen)
struct value *
parse_to_comma_and_eval (const char **expp)
{
- struct expression *expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
- struct value *val;
- struct cleanup *old_chain =
- make_cleanup (free_current_contents, &expr);
+ expression_up expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
- val = evaluate_expression (expr);
- do_cleanups (old_chain);
- return val;
+ return evaluate_expression (expr.get ());
}
\f
/* Evaluate an expression in internal prefix form
int pc = (*pos) + 1;
LONGEST low_bound, high_bound;
struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
- enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
+ enum range_type range_type
+ = (enum range_type) longest_to_int (exp->elts[pc].longconst);
*pos += 3;
return set;
}
- argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
+ argvec = XALLOCAVEC (struct value *, nargs);
for (tem = 0; tem < nargs; tem++)
{
/* Ensure that array expressions are coerced into pointer
CORE_ADDR selector = 0;
int struct_return = 0;
- int sub_no_side = 0;
+ enum noside sub_no_side = EVAL_NORMAL;
struct value *msg_send = NULL;
struct value *msg_send_stret = NULL;
selector = exp->elts[pc + 1].longconst;
nargs = exp->elts[pc + 2].longconst;
- argvec = (struct value **) alloca (sizeof (struct value *)
- * (nargs + 5));
+ argvec = XALLOCAVEC (struct value *, nargs + 5);
(*pos) += 3;
block_for_pc (funaddr);
- CHECK_TYPEDEF (val_type);
+ val_type = check_typedef (val_type);
if ((val_type == NULL)
|| (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
name,
get_selected_block (0),
- VAR_DOMAIN);
+ VAR_DOMAIN).symbol;
if (function == NULL)
error (_("No symbol \"%s\" in namespace \"%s\"."),
name, TYPE_TAG_NAME (type));
switch (code)
{
case TYPE_CODE_ARRAY:
- if (exp->elts[*pos].opcode == OP_F90_RANGE)
+ if (exp->elts[*pos].opcode == OP_RANGE)
return value_f90_subarray (arg1, exp, pos, noside);
else
goto multi_f77_subscript;
case TYPE_CODE_STRING:
- if (exp->elts[*pos].opcode == OP_F90_RANGE)
+ if (exp->elts[*pos].opcode == OP_RANGE)
return value_f90_subarray (arg1, exp, pos, noside);
else
{
arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (value_type (arg3), not_lval);
+ arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
return arg3;
case STRUCTOP_PTR:
{
struct type *type = value_type (arg1);
struct type *real_type;
- int full, top, using_enc;
+ int full, using_enc;
+ LONGEST top;
struct value_print_options opts;
get_user_print_options (&opts);
arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
NULL, "structure pointer");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (value_type (arg3), not_lval);
+ arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
return arg3;
case STRUCTOP_MEMBER:
if (noside == EVAL_SKIP)
goto nosideret;
type = check_typedef (value_type (arg2));
- if (TYPE_CODE (type) != TYPE_CODE_INT)
+ if (TYPE_CODE (type) != TYPE_CODE_INT
+ && TYPE_CODE (type) != TYPE_CODE_ENUM)
error (_("Non-integral right operand for \"@\" operator."));
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
/* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
"When applied to a reference or a reference type, the result is
the size of the referenced type." */
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
if (exp->language_defn->la_language == language_cplus
&& TYPE_CODE (type) == TYPE_CODE_REF)
type = check_typedef (TYPE_TARGET_TYPE (type));
parse_and_eval_type (char *p, int length)
{
char *tmp = (char *) alloca (length + 4);
- struct expression *expr;
tmp[0] = '(';
memcpy (tmp + 1, p, length);
tmp[length + 1] = ')';
tmp[length + 2] = '0';
tmp[length + 3] = '\0';
- expr = parse_expression (tmp);
+ expression_up expr = parse_expression (tmp);
if (expr->elts[0].opcode != UNOP_CAST)
error (_("Internal error in eval_type."));
return expr->elts[1].type;