std::get<1> (m_storage)->generate_ax (exp, ax, value, value_type (val));
}
+void
+var_value_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ gen_var_ref (ax, value, std::get<0> (m_storage));
+
+ if (value->optimized_out)
+ error (_("`%s' has been optimized out, cannot use"),
+ std::get<0> (m_storage)->print_name ());
+
+ if (value->type->code () == TYPE_CODE_ERROR)
+ {
+ if (cast_type == nullptr)
+ error_unknown_type (std::get<0> (m_storage)->print_name ());
+ value->type = cast_type;
+ }
+}
+
}
/* This handles the middle-to-right-side of code generation for binary
return ret;
}
+namespace expr
+
+{
+
+value *
+var_value_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ symbol *var = std::get<0> (m_storage);
+ if (SYMBOL_TYPE (var)->code () == TYPE_CODE_ERROR)
+ error_unknown_type (var->print_name ());
+ return evaluate_var_value (noside, std::get<1> (m_storage), var);
+}
+
+} /* namespace expr */
+
/* Helper for evaluating an OP_VAR_MSYM_VALUE. */
value *
}
}
+namespace expr
+{
+
+value *
+var_value_operation::evaluate_for_address (struct expression *exp,
+ enum noside noside)
+{
+ symbol *var = std::get<0> (m_storage);
+
+ /* 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)))
+ 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);
+
+ if (sym_class == LOC_CONST
+ || sym_class == LOC_CONST_BYTES
+ || sym_class == LOC_REGISTER)
+ error (_("Attempt to take address of register or constant."));
+
+ return value_zero (type, not_lval);
+ }
+ else
+ return address_of_variable (var, std::get<1> (m_storage));
+}
+
+value *
+var_value_operation::evaluate_with_coercion (struct expression *exp,
+ enum noside noside)
+{
+ struct symbol *var = std::get<0> (m_storage);
+ struct type *type = check_typedef (SYMBOL_TYPE (var));
+ if (type->code () == TYPE_CODE_ARRAY
+ && !type->is_vector ()
+ && CAST_IS_CONVERSION (exp->language_defn))
+ {
+ struct value *val = address_of_variable (var, std::get<1> (m_storage));
+ return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), val);
+ }
+ return evaluate (nullptr, exp, noside);
+}
+
+}
+
/* Helper function for evaluating the size of a type. */
static value *
return evaluate_subexp_for_sizeof_base (exp, value_type (typeval));
}
+value *
+var_value_operation::evaluate_for_sizeof (struct expression *exp,
+ enum noside noside)
+{
+ struct type *type = SYMBOL_TYPE (std::get<0> (m_storage));
+ if (is_dynamic_type (type))
+ {
+ value *val = evaluate (nullptr, exp, EVAL_NORMAL);
+ type = value_type (val);
+ if (type->code () == TYPE_CODE_ARRAY)
+ {
+ /* 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);
+ else if (is_dynamic_type (type->index_type ())
+ && type->bounds ()->high.kind () == PROP_UNDEFINED)
+ return allocate_optimized_out_value (size_type);
+ }
+ }
+ return evaluate_subexp_for_sizeof_base (exp, type);
+}
+
}
/* Evaluate a subexpression of EXP, at index *POS, and return a value
return val;
}
+value *
+var_value_operation::evaluate_for_cast (struct type *to_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *val = evaluate_var_value (noside,
+ std::get<1> (m_storage),
+ std::get<0> (m_storage));
+
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+
+ val = value_cast (to_type, val);
+
+ /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
+ if (VALUE_LVAL (val) == lval_memory)
+ {
+ if (value_lazy (val))
+ value_fetch_lazy (val);
+ VALUE_LVAL (val) = not_lval;
+ }
+ return val;
+}
+
}
/* Parse a type expression in the string [P..P+LENGTH). */
override;
};
+/* Compute the value of a variable. */
+class var_value_operation
+ : public maybe_constant_operation<symbol *, const block *>
+{
+public:
+
+ using maybe_constant_operation::maybe_constant_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override;
+
+ value *evaluate_with_coercion (struct expression *exp,
+ enum noside noside) override;
+
+ value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
+ override;
+
+ value *evaluate_for_cast (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override;
+
+ value *evaluate_for_address (struct expression *exp, enum noside noside)
+ override;
+
+ enum exp_opcode opcode () const override
+ { return OP_VAR_VALUE; }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+ override;
+};
+
class long_const_operation
: public tuple_holding_operation<struct type *, LONGEST>
{