/* Definitions for expressions in GDB
- Copyright (C) 2020 Free Software Foundation, Inc.
+ Copyright (C) 2020-2022 Free Software Foundation, Inc.
This file is part of GDB.
extern struct value *eval_op_register (struct type *expect_type,
struct expression *exp,
enum noside noside, const char *name);
-extern struct value *eval_op_string (struct type *expect_type,
- struct expression *exp,
- enum noside noside, int len,
- const char *string);
extern struct value *eval_op_ternop (struct type *expect_type,
struct expression *exp,
enum noside noside,
struct expression *exp,
enum noside noside,
struct value *arg1, struct value *arg2);
-extern struct value *eval_op_concat (struct type *expect_type,
- struct expression *exp,
- enum noside noside,
- struct value *arg1, struct value *arg2);
extern struct value *eval_op_add (struct type *expect_type,
struct expression *exp,
enum noside noside,
return exp_objfile == objfile;
}
-static inline bool
+static inline bool
check_objfile (struct type *type, struct objfile *objfile)
{
struct objfile *ty_objfile = type->objfile_owner ();
return false;
}
-static inline bool
+static inline bool
check_objfile (struct symbol *sym, struct objfile *objfile)
{
return check_objfile (symbol_objfile (sym), objfile);
}
-static inline bool
+static inline bool
check_objfile (const struct block *block, struct objfile *objfile)
{
return check_objfile (block_objfile (block), objfile);
}
+static inline bool
+check_objfile (const block_symbol &sym, struct objfile *objfile)
+{
+ return (check_objfile (sym.symbol, objfile)
+ || check_objfile (sym.block, objfile));
+}
+
static inline bool
check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
{
return false;
}
-static inline bool
+static inline bool
check_objfile (const operation_up &op, struct objfile *objfile)
{
return op->uses_objfile (objfile);
}
template<typename T>
-static inline bool
+static inline bool
check_objfile (const std::vector<T> &collection, struct objfile *objfile)
{
for (const auto &item : collection)
}
template<typename S, typename T>
-static inline bool
+static inline bool
check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
{
return (check_objfile (item.first, objfile)
internalvar *ivar);
extern void dump_for_expression (struct ui_file *stream, int depth,
symbol *sym);
+extern void dump_for_expression (struct ui_file *stream, int depth,
+ const block_symbol &sym);
extern void dump_for_expression (struct ui_file *stream, int depth,
bound_minimal_symbol msym);
extern void dump_for_expression (struct ui_file *stream, int depth,
dump_for_expression (struct ui_file *stream, int depth,
const std::vector<T> &vals)
{
- fprintf_filtered (stream, _("%*sVector:\n"), depth, "");
+ gdb_printf (stream, _("%*sVector:\n"), depth, "");
for (auto &item : vals)
dump_for_expression (stream, depth + 1, item);
}
static inline bool
check_constant (struct symbol *sym)
{
- enum address_class sc = SYMBOL_CLASS (sym);
+ enum address_class sc = sym->aclass ();
return (sc == LOC_BLOCK
|| sc == LOC_CONST
|| sc == LOC_CONST_BYTES
|| sc == LOC_LABEL);
}
+static inline bool
+check_constant (const block_symbol &sym)
+{
+ /* We know the block is constant, so we only need to check the
+ symbol. */
+ return check_constant (sym.symbol);
+}
+
template<typename T>
static inline bool
check_constant (const std::vector<T> &collection)
/* Compute the value of a variable. */
class var_value_operation
- : public maybe_constant_operation<symbol *, const block *>
+ : public maybe_constant_operation<block_symbol>
{
public:
/* Return the symbol referenced by this object. */
symbol *get_symbol () const
{
- return std::get<0> (m_storage);
+ return std::get<0> (m_storage).symbol;
}
protected:
value *evaluate (struct type *expect_type,
struct expression *exp,
- enum noside noside) override
- {
- const std::string &str = std::get<0> (m_storage);
- return eval_op_string (expect_type, exp, noside,
- str.size (), str.c_str ());
- }
+ enum noside noside) override;
enum exp_opcode opcode () const override
{ return OP_STRING; }
= std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
value *rhs
= std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
- return eval_op_concat (expect_type, exp, noside, lhs, rhs);
+ return value_concat (lhs, rhs);
}
enum exp_opcode opcode () const override
override;
};
+/* Not a cast! Extract a value of a given type from the contents of a
+ value. The new value is extracted from the least significant bytes
+ of the old value. The new value's type must be no bigger than the
+ old values type. */
+class unop_extract_operation
+ : public maybe_constant_operation<operation_up, struct type *>
+{
+public:
+
+ using maybe_constant_operation::maybe_constant_operation;
+
+ value *evaluate (struct type *expect_type, struct expression *exp,
+ enum noside noside) override;
+
+ enum exp_opcode opcode () const override
+ { return UNOP_EXTRACT; }
+
+ /* Return the type referenced by this object. */
+ struct type *get_type () const
+ {
+ return std::get<1> (m_storage);
+ }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type) override;
+};
+
/* A type cast. */
class unop_cast_operation
: public maybe_constant_operation<operation_up, struct type *>