get_int_var_value
I noticed that get_int_var_value's parameters could use some constification. And then realized that client code would become simpler by changing the interface to return the success/failure indication as actual return value, as it allows getting rid of the local "boolean" variable. gdb/ChangeLog: 2017-07-20 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_to_fixed_type_1): Adjust. (get_var_value): Constify parameters. (get_int_var_value): Change prototype. (to_fixed_range_type): Adjust. * ada-lang.h (get_int_var_value): Change prototype.
This commit is contained in:
parent
a778f165ad
commit
edb0c9cb22
4 changed files with 24 additions and 34 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2017-07-20 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* ada-lang.c (ada_to_fixed_type_1): Adjust.
|
||||||
|
(get_var_value): Constify parameters.
|
||||||
|
(get_int_var_value): Change prototype.
|
||||||
|
(to_fixed_range_type): Adjust.
|
||||||
|
* ada-lang.h (get_int_var_value): Change prototype.
|
||||||
|
|
||||||
2017-07-20 Pedro Alves <palves@redhat.com>
|
2017-07-20 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* dwarf2read.c (dw2_lookup_symbol): Use
|
* dwarf2read.c (dw2_lookup_symbol): Use
|
||||||
|
|
|
@ -194,8 +194,6 @@ static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
|
||||||
static struct value *coerce_unspec_val_to_type (struct value *,
|
static struct value *coerce_unspec_val_to_type (struct value *,
|
||||||
struct type *);
|
struct type *);
|
||||||
|
|
||||||
static struct value *get_var_value (char *, char *);
|
|
||||||
|
|
||||||
static int lesseq_defined_than (struct symbol *, struct symbol *);
|
static int lesseq_defined_than (struct symbol *, struct symbol *);
|
||||||
|
|
||||||
static int equiv_types (struct type *, struct type *);
|
static int equiv_types (struct type *, struct type *);
|
||||||
|
@ -8989,12 +8987,11 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
|
||||||
const char *name = ada_type_name (fixed_record_type);
|
const char *name = ada_type_name (fixed_record_type);
|
||||||
char *xvz_name
|
char *xvz_name
|
||||||
= (char *) alloca (strlen (name) + 7 /* "___XVZ\0" */);
|
= (char *) alloca (strlen (name) + 7 /* "___XVZ\0" */);
|
||||||
int xvz_found = 0;
|
|
||||||
LONGEST size;
|
LONGEST size;
|
||||||
|
|
||||||
xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
|
xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
|
||||||
size = get_int_var_value (xvz_name, &xvz_found);
|
if (get_int_var_value (xvz_name, size)
|
||||||
if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
|
&& TYPE_LENGTH (fixed_record_type) != size)
|
||||||
{
|
{
|
||||||
fixed_record_type = copy_type (fixed_record_type);
|
fixed_record_type = copy_type (fixed_record_type);
|
||||||
TYPE_LENGTH (fixed_record_type) = size;
|
TYPE_LENGTH (fixed_record_type) = size;
|
||||||
|
@ -11614,7 +11611,7 @@ scan_discrim_bound (const char *str, int k, struct value *dval, LONGEST * px,
|
||||||
otherwise causes an error with message ERR_MSG. */
|
otherwise causes an error with message ERR_MSG. */
|
||||||
|
|
||||||
static struct value *
|
static struct value *
|
||||||
get_var_value (char *name, char *err_msg)
|
get_var_value (const char *name, const char *err_msg)
|
||||||
{
|
{
|
||||||
struct block_symbol *syms;
|
struct block_symbol *syms;
|
||||||
int nsyms;
|
int nsyms;
|
||||||
|
@ -11633,27 +11630,20 @@ get_var_value (char *name, char *err_msg)
|
||||||
return value_of_variable (syms[0].symbol, syms[0].block);
|
return value_of_variable (syms[0].symbol, syms[0].block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Value of integer variable named NAME in the current environment. If
|
/* Value of integer variable named NAME in the current environment.
|
||||||
no such variable found, returns 0, and sets *FLAG to 0. If
|
If no such variable is found, returns false. Otherwise, sets VALUE
|
||||||
successful, sets *FLAG to 1. */
|
to the variable's value and returns true. */
|
||||||
|
|
||||||
LONGEST
|
bool
|
||||||
get_int_var_value (char *name, int *flag)
|
get_int_var_value (const char *name, LONGEST &value)
|
||||||
{
|
{
|
||||||
struct value *var_val = get_var_value (name, 0);
|
struct value *var_val = get_var_value (name, 0);
|
||||||
|
|
||||||
if (var_val == 0)
|
if (var_val == 0)
|
||||||
{
|
return false;
|
||||||
if (flag != NULL)
|
|
||||||
*flag = 0;
|
value = value_as_long (var_val);
|
||||||
return 0;
|
return true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (flag != NULL)
|
|
||||||
*flag = 1;
|
|
||||||
return value_as_long (var_val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11725,11 +11715,8 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ok;
|
|
||||||
|
|
||||||
strcpy (name_buf + prefix_len, "___L");
|
strcpy (name_buf + prefix_len, "___L");
|
||||||
L = get_int_var_value (name_buf, &ok);
|
if (!get_int_var_value (name_buf, L))
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
lim_warning (_("Unknown lower bound, using 1."));
|
lim_warning (_("Unknown lower bound, using 1."));
|
||||||
L = 1;
|
L = 1;
|
||||||
|
@ -11744,11 +11731,8 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ok;
|
|
||||||
|
|
||||||
strcpy (name_buf + prefix_len, "___U");
|
strcpy (name_buf + prefix_len, "___U");
|
||||||
U = get_int_var_value (name_buf, &ok);
|
if (!get_int_var_value (name_buf, U))
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
lim_warning (_("Unknown upper bound, using %ld."), (long) L);
|
lim_warning (_("Unknown upper bound, using %ld."), (long) L);
|
||||||
U = L;
|
U = L;
|
||||||
|
|
|
@ -335,7 +335,7 @@ extern const char *ada_type_name (struct type *);
|
||||||
extern struct type *ada_find_parallel_type (struct type *,
|
extern struct type *ada_find_parallel_type (struct type *,
|
||||||
const char *suffix);
|
const char *suffix);
|
||||||
|
|
||||||
extern LONGEST get_int_var_value (char *, int *);
|
extern bool get_int_var_value (const char *, LONGEST &value);
|
||||||
|
|
||||||
extern struct symbol *ada_find_renaming_symbol (struct symbol *name_sym,
|
extern struct symbol *ada_find_renaming_symbol (struct symbol *name_sym,
|
||||||
const struct block *block);
|
const struct block *block);
|
||||||
|
|
|
@ -256,14 +256,12 @@ print_dynamic_range_bound (struct type *type, const char *name, int name_len,
|
||||||
static char *name_buf = NULL;
|
static char *name_buf = NULL;
|
||||||
static size_t name_buf_len = 0;
|
static size_t name_buf_len = 0;
|
||||||
LONGEST B;
|
LONGEST B;
|
||||||
int OK;
|
|
||||||
|
|
||||||
GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1);
|
GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1);
|
||||||
strncpy (name_buf, name, name_len);
|
strncpy (name_buf, name, name_len);
|
||||||
strcpy (name_buf + name_len, suffix);
|
strcpy (name_buf + name_len, suffix);
|
||||||
|
|
||||||
B = get_int_var_value (name_buf, &OK);
|
if (get_int_var_value (name_buf, B))
|
||||||
if (OK)
|
|
||||||
ada_print_scalar (type, B, stream);
|
ada_print_scalar (type, B, stream);
|
||||||
else
|
else
|
||||||
fprintf_filtered (stream, "?");
|
fprintf_filtered (stream, "?");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue