This turns value_zero into a static "constructor" of value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
{
struct type *type = builtin_type (exp->gdbarch)->builtin_int;
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
return value_from_longest (type, pos_atr (arg));
}
ada_val_atr (enum noside noside, struct type *type, struct value *arg)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
if (!discrete_type_p (type))
error (_("'VAL only defined on discrete types"));
struct value *arg1)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (ada_tag_type (arg1), not_lval);
+ return value::zero (ada_tag_type (arg1), not_lval);
return ada_value_tag (arg1);
}
type = type->target_type ();
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
else
return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
TARGET_CHAR_BIT * type->length ());
struct value *arg1)
{
unop_promote (exp->language_defn, exp->gdbarch, &arg1);
- if (value_less (arg1, value_zero (arg1->type (), not_lval)))
+ if (value_less (arg1, value::zero (arg1->type (), not_lval)))
return value_neg (arg1);
else
return arg1;
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
- return value_zero (arg1->type (), not_lval);
+ return value::zero (arg1->type (), not_lval);
}
else
{
{
struct type *type = language_bool_type (exp->language_defn,
exp->gdbarch);
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
}
struct type *type = ada_index_type (arg2->type (), n, "range");
}
}
- return value_zero (type_arg, not_lval);
+ return value::zero (type_arg, not_lval);
}
else if (type_arg == NULL)
{
struct value *arg1, struct value *arg2)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (arg1->type (), not_lval);
+ return value::zero (arg1->type (), not_lval);
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
struct value *arg1, struct value *arg2)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (arg1->type (), not_lval);
+ return value::zero (arg1->type (), not_lval);
else
{
/* For integer exponentiation operations,
enum noside noside)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (expect_type, not_lval);
+ return value::zero (expect_type, not_lval);
const bound_minimal_symbol &b = std::get<0> (m_storage);
value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
This can happen if the debugging information is
incomplete, for instance. */
actual_type = type;
- return value_zero (actual_type, not_lval);
+ return value::zero (actual_type, not_lval);
}
else
{
&& dynamic_template_type (type) != NULL)
|| (type->code () == TYPE_CODE_UNION
&& ada_find_parallel_type (type, "___XVU") != NULL))
- return value_zero (to_static_fixed_type (type), not_lval);
+ return value::zero (to_static_fixed_type (type), not_lval);
}
value *arg1 = var_value_operation::evaluate (expect_type, exp, noside);
(ada_aligned_type
(ada_check_typedef (type->target_type ())));
}
- return value_zero (type, lval_memory);
+ return value::zero (type, lval_memory);
}
else if (type->code () == TYPE_CODE_INT)
{
/* GDB allows dereferencing an int. */
if (expect_type == NULL)
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
lval_memory);
else
{
expect_type =
to_static_fixed_type (ada_aligned_type (expect_type));
- return value_zero (expect_type, lval_memory);
+ return value::zero (expect_type, lval_memory);
}
}
else
else
type = ada_lookup_struct_elt_type (type1, str, 1, 0);
- return value_zero (ada_aligned_type (type), lval_memory);
+ return value::zero (ada_aligned_type (type), lval_memory);
}
else
{
/* We don't know anything about what the internal
function might return, but we have to return
something. */
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
not_lval);
else
return call_internal_function (exp->gdbarch, exp->language_defn,
if (arity != nargs)
error (_("wrong number of subscripts; expecting %d"), arity);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (ada_aligned_type (type), lval_memory);
+ return value::zero (ada_aligned_type (type), lval_memory);
return
unwrap_value (ada_value_subscript
(callee, nargs, argvec.data ()));
if (type == NULL)
error (_("element type of array unknown"));
else
- return value_zero (ada_aligned_type (type), lval_memory);
+ return value::zero (ada_aligned_type (type), lval_memory);
}
return
unwrap_value (ada_value_subscript
if (type == NULL)
error (_("element type of array unknown"));
else
- return value_zero (ada_aligned_type (type), lval_memory);
+ return value::zero (ada_aligned_type (type), lval_memory);
}
return
unwrap_value (ada_value_ptr_subscript (callee, nargs,
/* Describe the register's location. Generic dummy frames always
have the register value in an ``expression''. */
- reg_val = value_zero (register_type (gdbarch, regnum), not_lval);
+ reg_val = value::zero (register_type (gdbarch, regnum), not_lval);
/* Use the regcache_cooked_read() method so that it, on the fly,
constructs either a raw or pseudo register from the raw
{
case DW_OP_abs:
if (value_less (result_val,
- value_zero (result_val->type (), not_lval)))
+ value::zero (result_val->type (), not_lval)))
result_val = value_neg (result_val);
break;
case DW_OP_neg:
value *
evaluate_var_value (enum noside noside, const block *blk, symbol *var)
{
- /* JYG: We used to just return value_zero of the symbol type if
+ /* JYG: We used to just return value::zero of the symbol type if
we're asked to avoid side effects. Otherwise we return
value_of_variable (...). However I'm not sure if
value_of_variable () has any side effect. We need a full value
if (noside != EVAL_AVOID_SIDE_EFFECTS)
throw;
- ret = value_zero (var->type (), not_lval);
+ ret = value::zero (var->type (), not_lval);
}
return ret;
type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
if (noside == EVAL_AVOID_SIDE_EFFECTS && !the_type->is_gnu_ifunc ())
- return value_zero (the_type, not_lval);
+ return value::zero (the_type, not_lval);
else
return value_at_lazy (the_type, address);
}
/* We don't know anything about what the internal
function might return, but we have to return
something. */
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
not_lval);
}
else if (ftype->code () == TYPE_CODE_XMETHOD)
if (return_type == NULL)
error (_("Xmethod is missing return type."));
- return value_zero (return_type, not_lval);
+ return value::zero (return_type, not_lval);
}
else if (ftype->code () == TYPE_CODE_FUNC
|| ftype->code () == TYPE_CODE_METHOD)
function_name = name.c_str ();
/* We need a properly typed value for method lookup. */
- argvec[0] = value_zero (type, lval_memory);
+ argvec[0] = value::zero (type, lval_memory);
}
for (int i = 0; i < args.size (); ++i)
if (a1_type->code () == TYPE_CODE_METHODPTR)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- callee = value_zero (a1_type->target_type (), not_lval);
+ callee = value::zero (a1_type->target_type (), not_lval);
else
callee = cplus_method_ptr_to_value (&lhs, rhs);
enum noside noside, symbol *sym)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (sym->type (), not_lval);
+ return value::zero (sym->type (), not_lval);
if (SYMBOL_COMPUTED_OPS (sym) == NULL
|| SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
of the evaluation mode. */
if (noside == EVAL_AVOID_SIDE_EFFECTS
&& regno < gdbarch_num_cooked_regs (exp->gdbarch))
- val = value_zero (register_type (exp->gdbarch, regno), not_lval);
+ val = value::zero (register_type (exp->gdbarch, regno), not_lval);
else
val = value_of_register (regno, get_selected_frame (NULL));
if (val == NULL)
struct value *arg3 = value_struct_elt (&arg1, {}, string,
NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+ arg3 = value::zero (arg3->type (), VALUE_LVAL (arg3));
return arg3;
}
struct value *arg3 = value_struct_elt (&arg1, {}, string,
NULL, "structure pointer");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+ arg3 = value::zero (arg3->type (), VALUE_LVAL (arg3));
return arg3;
}
{
case TYPE_CODE_METHODPTR:
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type->target_type (), not_lval);
+ return value::zero (type->target_type (), not_lval);
else
{
arg2 = cplus_method_ptr_to_value (&arg1, arg2);
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type->target_type (), VALUE_LVAL (arg1));
+ return value::zero (type->target_type (), VALUE_LVAL (arg1));
else
return value_subscript (arg1, value_as_long (arg2));
}
if (type->is_pointer_or_reference ()
/* In C you can dereference an array to get the 1st elt. */
|| type->code () == TYPE_CODE_ARRAY)
- return value_zero (type->target_type (),
+ return value::zero (type->target_type (),
lval_memory);
else if (type->code () == TYPE_CODE_INT)
/* GDB allows dereferencing an int. */
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
lval_memory);
else
error (_("Attempt to take contents of a non-pointer value."));
struct value *arg1, struct type *type)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type, lval_memory);
+ return value::zero (type, lval_memory);
else
return value_at_lazy (type, value_as_address (arg1));
}
struct type *type = check_typedef (x->type ());
if (TYPE_IS_REFERENCE (type))
- return value_zero (lookup_pointer_type (type->target_type ()),
+ return value::zero (lookup_pointer_type (type->target_type ()),
not_lval);
else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
- return value_zero (lookup_pointer_type (x->type ()),
+ return value::zero (lookup_pointer_type (x->type ()),
not_lval);
else
error (_("Attempt to take address of "
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *type = lookup_pointer_type (val->type ());
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
}
else
return value_addr (val);
|| sym_class == LOC_REGISTER)
error (_("Attempt to take address of register or constant."));
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
}
else
return address_of_variable (var, std::get<0> (m_storage).block);
/* FIXME: This should be size_t. */
struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
if (type_not_allocated (type) || type_not_associated (type))
- return value_zero (size_type, not_lval);
+ return value::zero (size_type, not_lval);
else if (is_dynamic_type (type->index_type ())
&& type->bounds ()->high.kind () == PROP_UNDEFINED)
return value::allocate_optimized_out (size_type);
enum noside noside)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (to_type, not_lval);
+ return value::zero (to_type, not_lval);
const bound_minimal_symbol &b = std::get<0> (m_storage);
value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
return value_cast (result_type, arg1);
else
return value_literal_complex (arg1,
- value_zero (arg1->type (), not_lval),
+ value::zero (arg1->type (), not_lval),
result_type);
}
= gdb::make_array_view (valaddr, elt_type->length ());
elt_type = resolve_dynamic_type (elt_type, view, address);
}
- elt = value_zero (elt_type, VALUE_LVAL (elt));
+ elt = value::zero (elt_type, VALUE_LVAL (elt));
}
return elt;
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
struct value *reg_val;
- reg_val = value_zero (register_type (gdbarch, regnum), not_lval);
+ reg_val = value::zero (register_type (gdbarch, regnum), not_lval);
store_unsigned_integer (value_contents_writeable (reg_val).data (),
register_size (gdbarch, regnum), byte_order, val);
return reg_val;
struct gdbarch *gdbarch = frame_unwind_arch (frame);
struct value *reg_val;
- reg_val = value_zero (register_type (gdbarch, regnum), not_lval);
+ reg_val = value::zero (register_type (gdbarch, regnum), not_lval);
memcpy (value_contents_raw (reg_val).data (), buf,
register_size (gdbarch, regnum));
return reg_val;
struct gdbarch *gdbarch = frame_unwind_arch (frame);
struct value *reg_val;
- reg_val = value_zero (register_type (gdbarch, regnum), not_lval);
+ reg_val = value::zero (register_type (gdbarch, regnum), not_lval);
pack_long (value_contents_writeable (reg_val).data (),
register_type (gdbarch, regnum), addr);
return reg_val;
res_val = arg1;
break;
case VALSCM_ABS:
- if (value_less (arg1, value_zero (arg1->type (), not_lval)))
+ if (value_less (arg1, value::zero (arg1->type (), not_lval)))
res_val = value_neg (arg1);
else
res_val = arg1;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type->target_type (), VALUE_LVAL (arg1));
+ return value::zero (type->target_type (), VALUE_LVAL (arg1));
else
return value_subscript (arg1, value_as_long (arg2));
}
if (n == 1)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- ret = value_zero (elm_type, not_lval);
+ ret = value::zero (elm_type, not_lval);
else
ret = value_subscript (val, indices[0]);
}
NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- v = value_zero (v->type (), VALUE_LVAL (v));
+ v = value::zero (v->type (), VALUE_LVAL (v));
return v;
}
}
{
scoped_value_mark free_values;
- if (value_less (value, value_zero (value->type (), not_lval)))
+ if (value_less (value, value::zero (value->type (), not_lval)))
isabs = 0;
}
catch (const gdb_exception &except)
high == NULL ? NULL : "end", index_type);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (range_type, lval_memory);
+ return value::zero (range_type, lval_memory);
addrval = value_allocate_space_in_inferior (range_type->length ());
addr = value_as_long (addrval);
else
new_type = base_type;
- return value_zero (new_type, VALUE_LVAL (lhs));
+ return value::zero (new_type, VALUE_LVAL (lhs));
}
else
{
else
result = value_struct_elt (&lhs, {}, field_name, NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- result = value_zero (result->type (), VALUE_LVAL (result));
+ result = value::zero (result->type (), VALUE_LVAL (result));
return result;
}
args[i + 1] = ops[i]->evaluate (nullptr, exp, noside);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (fn_type->target_type (), not_lval);
+ return value::zero (fn_type->target_type (), not_lval);
return call_function_by_hand (function, NULL, args);
}
if (return_type == NULL)
error (_("Xmethod is missing return type."));
- return value_zero (return_type, VALUE_LVAL (arg1));
+ return value::zero (return_type, VALUE_LVAL (arg1));
}
return call_xmethod (argvec[0], argvec.slice (1));
}
struct type *return_type;
return_type = check_typedef (argvec[0]->type ())->target_type ();
- return value_zero (return_type, VALUE_LVAL (arg1));
+ return value::zero (return_type, VALUE_LVAL (arg1));
}
return call_function_by_hand (argvec[0], NULL,
argvec.slice (1, 2 - static_memfuncp));
if (return_type == NULL)
error (_("Xmethod is missing return type."));
- return value_zero (return_type, VALUE_LVAL (arg1));
+ return value::zero (return_type, VALUE_LVAL (arg1));
}
return call_xmethod (argvec[0], argvec[1]);
}
struct type *return_type;
return_type = check_typedef (argvec[0]->type ())->target_type ();
- return value_zero (return_type, VALUE_LVAL (arg1));
+ return value::zero (return_type, VALUE_LVAL (arg1));
}
return call_function_by_hand (argvec[0], NULL,
argvec.slice (1, nargs));
else
{
arg1_real = arg1;
- arg1_imag = value_zero (arg1_type, not_lval);
+ arg1_imag = value::zero (arg1_type, not_lval);
}
if (arg2_type->code () == TYPE_CODE_COMPLEX)
{
else
{
arg2_real = arg2;
- arg2_imag = value_zero (arg2_type, not_lval);
+ arg2_imag = value::zero (arg2_type, not_lval);
}
struct type *comp_type = promotion_type (arg1_real->type (),
if (is_integral_type (type) || is_floating_type (type))
return value_binop (value_from_longest (type, 0), arg1, BINOP_SUB);
else if (is_fixed_point_type (type))
- return value_binop (value_zero (type, not_lval), arg1, BINOP_SUB);
+ return value_binop (value::zero (type, not_lval), arg1, BINOP_SUB);
else if (type->code () == TYPE_CODE_ARRAY && type->is_vector ())
{
struct value *val = value::allocate (type);
T2. This wouldn't work properly for classes with virtual
bases, but those were handled above. */
v = search_struct_field (t2->name (),
- value_zero (t1, not_lval), t1, 1);
+ value::zero (t1, not_lval), t1, 1);
if (v)
{
/* Downcasting is possible (t1 is superclass of v2). */
error (_("can only cast scalar to vector of same size"));
else if (code1 == TYPE_CODE_VOID)
{
- return value_zero (to_type, not_lval);
+ return value::zero (to_type, not_lval);
}
else if (type->length () == type2->length ())
{
/* Handle NULL pointers. */
if (value_as_long (arg) == 0)
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
arg = value_ind (arg);
}
: value_addr (result));
if (resolved_type->code () == TYPE_CODE_PTR)
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
error (_("dynamic_cast failed"));
}
else if (val->type ()->code () == TYPE_CODE_FLT
|| val->type ()->code () == TYPE_CODE_INT)
return value_literal_complex (val,
- value_zero (real_type, not_lval),
+ value::zero (real_type, not_lval),
type);
else
error (_("cannot cast non-number to complex"));
}
}
-
-/* Create a value of type TYPE that is zero, and return it. */
+/* See value.h. */
struct value *
-value_zero (struct type *type, enum lval_type lv)
+value::zero (struct type *type, enum lval_type lv)
{
struct value *val = value::allocate_lazy (type);
/* Allocate NOT_LVAL value for type TYPE being OPTIMIZED_OUT. */
static struct value *allocate_optimized_out (struct type *type);
+ /* Create a value of type TYPE that is zero, and return it. */
+ static struct value *zero (struct type *type, enum lval_type lv);
+
~value ();
DISABLE_COPY_AND_ASSIGN (value);
used instead of read_memory to enable extra caching. */
unsigned int m_stack : 1;
- /* True if this is a zero value, created by 'value_zero'; false
+ /* True if this is a zero value, created by 'value::zero'; false
otherwise. */
bool m_is_zero : 1;
extern struct value *value_dynamic_cast (struct type *type, struct value *arg);
-extern struct value *value_zero (struct type *type, enum lval_type lv);
-
extern struct value *value_one (struct type *type);
extern struct value *value_repeat (struct value *arg1, int count);