#include "gdbarch.h"
#include "infcall.h"
#include "objfiles.h"
-#include "psymtab.h"
#include "rust-lang.h"
#include "typeprint.h"
#include "valprint.h"
std::string
rust_crate_for_block (const struct block *block)
{
- const char *scope = block_scope (block);
+ const char *scope = block->scope ();
if (scope[0] == '\0')
return std::string ();
{
/* The active variant is simply the first non-artificial field. */
for (int i = 0; i < type->num_fields (); ++i)
- if (!TYPE_FIELD_ARTIFICIAL (type, i))
+ if (!type->field (i).is_artificial ())
return i;
/* Perhaps we could get here by trying to print an Ada variant
return false;
for (i = 0; i < type->num_fields (); ++i)
{
- if (!field_is_static (&type->field (i)))
+ if (!type->field (i).is_static ())
{
char buf[20];
struct type *array_type = lookup_array_range_type (elt_type, 0,
llen - 1);
struct value *array = value::allocate_lazy (array_type);
- VALUE_LVAL (array) = lval_memory;
+ array->set_lval (lval_memory);
array->set_address (value_as_address (base));
array->fetch_lazy ();
generic_value_print (array, stream, recurse, options,
first_field = 1;
for (i = 0; i < type->num_fields (); ++i)
{
- if (field_is_static (&type->field (i)))
+ if (type->field (i).is_static ())
continue;
if (!first_field)
gdb_assert (rust_enum_p (type));
gdb::array_view<const gdb_byte> view
- (value_contents_for_printing (val).data (),
+ (val->contents_for_printing ().data (),
val->type ()->length ());
type = resolve_dynamic_type (type, view, val->address ());
}
int variant_fieldno = rust_enum_variant (type);
- val = value_field (val, variant_fieldno);
+ val = val->primitive_field (0, variant_fieldno, type);
struct type *variant_type = type->field (variant_fieldno).type ();
int nfields = variant_type->num_fields ();
encoding. */
gdb_puts ("b", stream);
printstr (stream, type->target_type (),
- value_contents_for_printing (val).data (),
+ val->contents_for_printing ().data (),
high_bound - low_bound + 1, "ASCII", 0, &opts);
}
break;
std::vector<int> fields;
for (int i = 0; i < type->num_fields (); ++i)
{
- if (field_is_static (&type->field (i)))
+ if (type->field (i).is_static ())
continue;
- if (is_enum && TYPE_FIELD_ARTIFICIAL (type, i))
+ if (is_enum && type->field (i).is_artificial ())
continue;
fields.push_back (i);
}
{
QUIT;
- gdb_assert (!field_is_static (&type->field (i)));
- gdb_assert (! (is_enum && TYPE_FIELD_ARTIFICIAL (type, i)));
+ gdb_assert (!type->field (i).is_static ());
+ gdb_assert (! (is_enum && type->field (i).is_artificial ()));
if (flags->print_offsets)
podata->update (type, i, stream);
const char *field1, struct type *type1,
const char *field2, struct type *type2)
{
- struct type *result = alloc_type_copy (original);
+ struct type *result = type_allocator (original).new_type ();
int i, nfields, bitpos;
nfields = 0;
result->set_code (TYPE_CODE_STRUCT);
result->set_name (name);
- result->set_num_fields (nfields);
- result->set_fields
- ((struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field)));
+ result->alloc_fields (nfields);
i = 0;
bitpos = 0;
else
new_type = base_type;
- return value::zero (new_type, VALUE_LVAL (lhs));
+ return value::zero (new_type, lhs->lval ());
}
else
{
error (_("Array with negative number of elements"));
if (noside == EVAL_NORMAL)
- {
- int i;
- std::vector<struct value *> eltvec (copies);
-
- for (i = 0; i < copies; ++i)
- eltvec[i] = elt;
- return value_array (0, copies - 1, eltvec.data ());
- }
+ return value_array (0, std::vector<value *> (copies, elt));
else
{
struct type *arraytype
if (rust_enum_p (type))
{
- type = resolve_dynamic_type (type, value_contents (lhs),
+ type = resolve_dynamic_type (type, lhs->contents (),
lhs->address ());
if (rust_empty_enum_p (type))
field_number, type->name ());
int fieldno = rust_enum_variant (type);
- lhs = value_primitive_field (lhs, 0, fieldno, type);
+ lhs = lhs->primitive_field (0, fieldno, type);
outer_type = type;
type = lhs->type ();
}
field_number, type->name ());
}
- return value_primitive_field (lhs, 0, field_number, type);
+ return lhs->primitive_field (0, field_number, type);
}
else
error(_("Anonymous field access is only allowed on tuples, \
struct type *type = lhs->type ();
if (type->code () == TYPE_CODE_STRUCT && rust_enum_p (type))
{
- type = resolve_dynamic_type (type, value_contents (lhs),
+ type = resolve_dynamic_type (type, lhs->contents (),
lhs->address ());
if (rust_empty_enum_p (type))
field_name, type->name ());
int fieldno = rust_enum_variant (type);
- lhs = value_primitive_field (lhs, 0, fieldno, type);
+ lhs = lhs->primitive_field (0, fieldno, type);
struct type *outer_type = type;
type = lhs->type ();
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 (), result->lval ());
return result;
}
return t;
};
+ type_allocator alloc (gdbarch);
struct type *bool_type
- = add (arch_boolean_type (gdbarch, 8, 1, "bool"));
- add (arch_character_type (gdbarch, 32, 1, "char"));
- add (arch_integer_type (gdbarch, 8, 0, "i8"));
+ = add (init_boolean_type (alloc, 8, 1, "bool"));
+ add (init_character_type (alloc, 32, 1, "char"));
+ add (init_integer_type (alloc, 8, 0, "i8"));
struct type *u8_type
- = add (arch_integer_type (gdbarch, 8, 1, "u8"));
- add (arch_integer_type (gdbarch, 16, 0, "i16"));
- add (arch_integer_type (gdbarch, 16, 1, "u16"));
- add (arch_integer_type (gdbarch, 32, 0, "i32"));
- add (arch_integer_type (gdbarch, 32, 1, "u32"));
- add (arch_integer_type (gdbarch, 64, 0, "i64"));
- add (arch_integer_type (gdbarch, 64, 1, "u64"));
+ = add (init_integer_type (alloc, 8, 1, "u8"));
+ add (init_integer_type (alloc, 16, 0, "i16"));
+ add (init_integer_type (alloc, 16, 1, "u16"));
+ add (init_integer_type (alloc, 32, 0, "i32"));
+ add (init_integer_type (alloc, 32, 1, "u32"));
+ add (init_integer_type (alloc, 64, 0, "i64"));
+ add (init_integer_type (alloc, 64, 1, "u64"));
+ add (init_integer_type (alloc, 128, 0, "i128"));
+ add (init_integer_type (alloc, 128, 1, "u128"));
unsigned int length = 8 * builtin->builtin_data_ptr->length ();
- add (arch_integer_type (gdbarch, length, 0, "isize"));
+ add (init_integer_type (alloc, length, 0, "isize"));
struct type *usize_type
- = add (arch_integer_type (gdbarch, length, 1, "usize"));
+ = add (init_integer_type (alloc, length, 1, "usize"));
- add (arch_float_type (gdbarch, 32, "f32", floatformats_ieee_single));
- add (arch_float_type (gdbarch, 64, "f64", floatformats_ieee_double));
- add (arch_integer_type (gdbarch, 0, 1, "()"));
+ add (init_float_type (alloc, 32, "f32", floatformats_ieee_single));
+ add (init_float_type (alloc, 64, "f64", floatformats_ieee_double));
+ add (init_integer_type (alloc, 0, 1, "()"));
struct type *tem = make_cv_type (1, 0, u8_type, NULL);
add (rust_slice_type ("&str", tem, usize_type));
&& strcmp (type->name (), "&str") == 0));
}
+/* See language.h. */
+
+struct block_symbol
+rust_language::lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const
+{
+ struct block_symbol result = {};
+
+ const char *scope = block == nullptr ? "" : block->scope ();
+ symbol_lookup_debug_printf
+ ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)",
+ name, host_address_to_string (block), scope,
+ domain_name (domain));
+
+ /* Look up bare names in the block's scope. */
+ std::string scopedname;
+ if (name[cp_find_first_component (name)] == '\0')
+ {
+ if (scope[0] != '\0')
+ {
+ scopedname = std::string (scope) + "::" + name;
+ name = scopedname.c_str ();
+ }
+ else
+ name = NULL;
+ }
+
+ if (name != NULL)
+ {
+ result = lookup_symbol_in_static_block (name, block, domain);
+ if (result.symbol == NULL)
+ result = lookup_global_symbol (name, block, domain);
+ }
+ return result;
+}
+
/* Single instance of the Rust language class. */
static rust_language rust_language_defn;