/* Evaluate expressions for GDB.
- Copyright (C) 1986-2016 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
ptrmath_type_p (const struct language_defn *lang, struct type *type)
{
type = check_typedef (type);
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type))
type = TYPE_TARGET_TYPE (type);
switch (TYPE_CODE (type))
{
type = check_typedef (value_type (arg1));
if (TYPE_CODE (type) == TYPE_CODE_PTR
- || TYPE_CODE (type) == TYPE_CODE_REF
+ || TYPE_IS_REFERENCE (type)
/* In C you can dereference an array to get the 1st elt. */
|| TYPE_CODE (type) == TYPE_CODE_ARRAY
)
{
struct type *type = value_type (result);
- if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
+ if (!TYPE_IS_REFERENCE (type))
{
- type = lookup_reference_type (type);
+ type = lookup_lvalue_reference_type (type);
result = allocate_value (type);
}
}
/* C++: The "address" of a reference should yield the address
* of the object pointed to. Let value_addr() deal with it. */
- if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var)))
goto default_case;
(*pos) += 4;
{
struct type *type = check_typedef (value_type (x));
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type))
return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
not_lval);
else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
type = check_typedef (value_type (val));
if (TYPE_CODE (type) != TYPE_CODE_PTR
- && TYPE_CODE (type) != TYPE_CODE_REF
+ && !TYPE_IS_REFERENCE (type)
&& TYPE_CODE (type) != TYPE_CODE_ARRAY)
error (_("Attempt to take contents of a non-pointer value."));
type = TYPE_TARGET_TYPE (type);
the size of the referenced type." */
type = check_typedef (type);
if (exp->language_defn->la_language == language_cplus
- && TYPE_CODE (type) == TYPE_CODE_REF)
+ && (TYPE_IS_REFERENCE (type)))
type = check_typedef (TYPE_TARGET_TYPE (type));
return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (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;