/* Evaluate expressions for GDB.
- Copyright (C) 1986-2021 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "regcache.h"
#include "user-regs.h"
#include "valprint.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "objfiles.h"
#include "typeprint.h"
#include <ctype.h>
return;
if (is_fixed_point_type (type1) || is_fixed_point_type (type2))
- return;
+ return;
if (type1->code () == TYPE_CODE_DECFLOAT
|| type2->code () == TYPE_CODE_DECFLOAT)
if (noside != EVAL_AVOID_SIDE_EFFECTS)
throw;
- ret = value_zero (SYMBOL_TYPE (var), not_lval);
+ ret = value_zero (var->type (), not_lval);
}
return ret;
enum noside noside)
{
symbol *var = std::get<0> (m_storage).symbol;
- if (SYMBOL_TYPE (var)->code () == TYPE_CODE_ERROR)
+ if (var->type ()->code () == TYPE_CODE_ERROR)
error_unknown_type (var->print_name ());
return evaluate_var_value (noside, std::get<0> (m_storage).block, var);
}
NULL, std::get<0> (m_storage).symbol,
NULL, &symp, NULL, 0, noside);
- if (SYMBOL_TYPE (symp)->code () == TYPE_CODE_ERROR)
+ if (symp->type ()->code () == TYPE_CODE_ERROR)
error_unknown_type (symp->print_name ());
value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
symp);
enum noside noside, symbol *sym)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (SYMBOL_TYPE (sym), not_lval);
+ return value_zero (sym->type (), not_lval);
if (SYMBOL_COMPUTED_OPS (sym) == NULL
|| SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
return val;
}
-/* Helper function that implements the body of OP_STRING. */
+namespace expr
+{
-struct value *
-eval_op_string (struct type *expect_type, struct expression *exp,
- enum noside noside, int len, const char *string)
+value *
+string_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
{
+ const std::string &str = std::get<0> (m_storage);
struct type *type = language_string_char_type (exp->language_defn,
exp->gdbarch);
- return value_string (string, len, type);
+ return value_string (str.c_str (), str.size (), type);
}
+} /* namespace expr */
+
/* Helper function that implements the body of OP_OBJC_SELECTOR. */
struct value *
lookup_child_selector (exp->gdbarch, sel));
}
-/* Helper function that implements the body of BINOP_CONCAT. */
-
-struct value *
-eval_op_concat (struct type *expect_type, struct expression *exp,
- enum noside noside, struct value *arg1, struct value *arg2)
-{
- if (binop_user_defined_p (BINOP_CONCAT, arg1, arg2))
- return value_x_binop (arg1, arg2, BINOP_CONCAT, OP_NULL, noside);
- else
- return value_concat (arg1, arg2);
-}
-
/* A helper function for TERNOP_SLICE. */
struct value *
NON_METHOD,
nullptr, nullptr,
nullptr, &symp, nullptr, 0, noside);
- if (SYMBOL_TYPE (symp)->code () == TYPE_CODE_ERROR)
+ if (symp->type ()->code () == TYPE_CODE_ERROR)
error_unknown_type (symp->print_name ());
value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
return evaluate_subexp_do_call (exp, noside, callee, args,
val = value_cast (field_type, val);
bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
- bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
+ bitpos = struct_type->field (fieldno).loc_bitpos ();
addr = value_contents_writeable (struct_val).data () + bitpos / 8;
if (bitsize)
modify_field (struct_type, addr,
return value_array (tem2, tem3, argvec);
}
+value *
+unop_extract_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *old_value = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ struct type *type = get_type ();
+
+ if (TYPE_LENGTH (type) > TYPE_LENGTH (value_type (old_value)))
+ error (_("length type is larger than the value type"));
+
+ struct value *result = allocate_value (type);
+ value_contents_copy (result, 0, old_value, 0, TYPE_LENGTH (type));
+ return result;
+}
+
}
\f
/* C++: The "address" of a reference should yield the address
* of the object pointed to. Let value_addr() deal with it. */
- if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var)))
+ if (TYPE_IS_REFERENCE (var->type ()))
return operation::evaluate_for_address (exp, noside);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
- struct type *type = lookup_pointer_type (SYMBOL_TYPE (var));
- enum address_class sym_class = SYMBOL_CLASS (var);
+ struct type *type = lookup_pointer_type (var->type ());
+ enum address_class sym_class = var->aclass ();
if (sym_class == LOC_CONST
|| sym_class == LOC_CONST_BYTES
enum noside noside)
{
struct symbol *var = std::get<0> (m_storage).symbol;
- struct type *type = check_typedef (SYMBOL_TYPE (var));
+ struct type *type = check_typedef (var->type ());
if (type->code () == TYPE_CODE_ARRAY
&& !type->is_vector ()
&& CAST_IS_CONVERSION (exp->language_defn))
var_value_operation::evaluate_for_sizeof (struct expression *exp,
enum noside noside)
{
- struct type *type = SYMBOL_TYPE (std::get<0> (m_storage).symbol);
+ struct type *type = std::get<0> (m_storage).symbol->type ();
if (is_dynamic_type (type))
{
value *val = evaluate (nullptr, exp, EVAL_NORMAL);