Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008,
- 2009 Free Software Foundation, Inc.
+ 2009, 2010 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 "objfiles.h"
#include "python/python.h"
#include "gdb_assert.h"
bitpos += TYPE_FIELD_BITPOS (substruct_type, subfieldno);
addr = value_contents_writeable (struct_val) + bitpos / 8;
if (bitsize)
- modify_field (addr, value_as_long (val),
- bitpos % 8, bitsize);
+ modify_field (struct_type, addr,
+ value_as_long (val), bitpos % 8, bitsize);
else
memcpy (addr, value_contents (val),
TYPE_LENGTH (value_type (val)));
}
}
+/* Constructs a fake method with the given parameter types.
+ This function is used by the parser to construct an "expected"
+ type for method overload resolution. */
+
+static struct type *
+make_params (int num_types, struct type **param_types)
+{
+ struct type *type = XZALLOC (struct type);
+ TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
+ TYPE_LENGTH (type) = 1;
+ TYPE_CODE (type) = TYPE_CODE_METHOD;
+ TYPE_VPTR_FIELDNO (type) = -1;
+ TYPE_CHAIN (type) = type;
+ TYPE_NFIELDS (type) = num_types;
+ TYPE_FIELDS (type) = (struct field *)
+ TYPE_ZALLOC (type, sizeof (struct field) * num_types);
+
+ while (num_types-- > 0)
+ TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
+
+ return type;
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
goto nosideret;
arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
&exp->elts[pc + 3].string,
- 0, noside);
+ expect_type, 0, noside);
if (arg1 == NULL)
error (_("There is no field named %s"), &exp->elts[pc + 3].string);
return arg1;
case OP_INTERNALVAR:
(*pos) += 2;
- return value_of_internalvar (exp->elts[pc + 1].internalvar);
+ return value_of_internalvar (exp->gdbarch,
+ exp->elts[pc + 1].internalvar);
case OP_STRING:
tem = longest_to_int (exp->elts[pc + 1].longconst);
+= 3 + BYTES_TO_EXP_ELEM ((tem + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
if (noside == EVAL_SKIP)
goto nosideret;
- return value_bitstring (&exp->elts[pc + 2].string, tem);
+ return value_bitstring (&exp->elts[pc + 2].string, tem,
+ builtin_type (exp->gdbarch)->builtin_int);
break;
case OP_ARRAY:
LONGEST low_bound, high_bound;
/* get targettype of elementtype */
- while (TYPE_CODE (check_type) == TYPE_CODE_RANGE ||
- TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
+ while (TYPE_CODE (check_type) == TYPE_CODE_RANGE
+ || TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
check_type = TYPE_TARGET_TYPE (check_type);
if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
range_low_type = TYPE_TARGET_TYPE (range_low_type);
if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
range_high_type = TYPE_TARGET_TYPE (range_high_type);
- if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type)) ||
- (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM &&
- (range_low_type != range_high_type)))
+ if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type))
+ || (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM
+ && (range_low_type != range_high_type)))
/* different element modes */
error (_("POWERSET tuple elements of different mode"));
- if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type)) ||
- (TYPE_CODE (check_type) == TYPE_CODE_ENUM &&
- range_low_type != check_type))
+ if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type))
+ || (TYPE_CODE (check_type) == TYPE_CODE_ENUM
+ && range_low_type != check_type))
error (_("incompatible POWERSET tuple elements"));
if (range_low > range_high)
{
if (addr)
{
struct symbol *sym = NULL;
- /* Is it a high_level symbol? */
+ /* The address might point to a function descriptor;
+ resolve it to the actual code address instead. */
+ addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
+ ¤t_target);
+
+ /* Is it a high_level symbol? */
sym = find_pc_function (addr);
if (sym != NULL)
method = value_of_variable (sym, 0);
{
if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
error (_("method address has symbol information with non-function type; skipping"));
+
+ /* Create a function pointer of the appropriate type, and replace
+ its value with the value of msg_send or msg_send_stret. We must
+ use a pointer here, as msg_send and msg_send_stret are of pointer
+ type, and the representation may be different on systems that use
+ function descriptors. */
if (struct_return)
- set_value_address (method, value_as_address (msg_send_stret));
+ called_method
+ = value_from_pointer (lookup_pointer_type (value_type (method)),
+ value_as_address (msg_send_stret));
else
- set_value_address (method, value_as_address (msg_send));
- called_method = method;
+ called_method
+ = value_from_pointer (lookup_pointer_type (value_type (method)),
+ value_as_address (msg_send));
}
else
{
{
/* Function objc_msg_lookup returns a pointer. */
deprecated_set_value_type (argvec[0],
- lookup_function_type (lookup_pointer_type (value_type (argvec[0]))));
+ lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
argvec[0] = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
}
gdb isn't asked for it's opinion (ie. through "whatis"),
it won't offer it. */
- struct type *ftype =
- TYPE_TARGET_TYPE (value_type (argvec[0]));
+ struct type *ftype = value_type (argvec[0]);
- if (ftype)
- return allocate_value (TYPE_TARGET_TYPE (value_type (argvec[0])));
+ if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
+ {
+ /* We don't know anything about what the internal
+ function might return, but we have to return
+ something. */
+ return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ not_lval);
+ }
+ else if (TYPE_TARGET_TYPE (ftype))
+ return allocate_value (TYPE_TARGET_TYPE (ftype));
else
error (_("Expression of type other than \"Function returning ...\" used as function"));
}
if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_INTERNAL_FUNCTION)
- return call_internal_function (argvec[0], nargs, argvec + 1);
+ return call_internal_function (exp->gdbarch, exp->language_defn,
+ argvec[0], nargs, argvec + 1);
return call_function_by_hand (argvec[0], nargs, argvec + 1);
/* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
else
{
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
}
case TYPE_CODE_PTR:
struct value_print_options opts;
get_user_print_options (&opts);
- if (opts.objectprint && TYPE_TARGET_TYPE(type) &&
- (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
+ if (opts.objectprint && TYPE_TARGET_TYPE(type)
+ && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
{
real_type = value_rtti_target_type (arg1, &full, &top, &using_enc);
if (real_type)
error (_("non-pointer-to-member value used in pointer-to-member construct"));
}
+ case TYPE_INSTANCE:
+ nargs = longest_to_int (exp->elts[pc + 1].longconst);
+ arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
+ for (ix = 0; ix < nargs; ++ix)
+ arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
+
+ expect_type = make_params (nargs, arg_types);
+ *(pos) += 3 + nargs;
+ arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
+ xfree (TYPE_FIELDS (expect_type));
+ xfree (TYPE_MAIN_TYPE (expect_type));
+ xfree (expect_type);
+ return arg1;
+
case BINOP_CONCAT:
arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
op = exp->elts[pc + 1].opcode;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
- else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
- else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ arg2 = value_ptradd (arg1, value_as_long (arg2));
+ else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ arg2 = value_ptradd (arg1, - value_as_long (arg2));
else
{
struct value *tmp = arg1;
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1)))
- return value_ptradd (arg1, arg2);
- else if (ptrmath_type_p (value_type (arg2)))
- return value_ptradd (arg2, arg1);
+ else if (ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ return value_ptradd (arg1, value_as_long (arg2));
+ else if (ptrmath_type_p (value_type (arg2))
+ && is_integral_type (value_type (arg1)))
+ return value_ptradd (arg2, value_as_long (arg1));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1)))
+ else if (ptrmath_type_p (value_type (arg1))
+ && ptrmath_type_p (value_type (arg2)))
{
- if (ptrmath_type_p (value_type (arg2)))
- {
- /* FIXME -- should be ptrdiff_t */
- type = builtin_type (exp->gdbarch)->builtin_long;
- return value_from_longest (type, value_ptrdiff (arg1, arg2));
- }
- else
- return value_ptrsub (arg1, arg2);
+ /* FIXME -- should be ptrdiff_t */
+ type = builtin_type (exp->gdbarch)->builtin_long;
+ return value_from_longest (type, value_ptrdiff (arg1, arg2));
}
+ else if (ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ return value_ptradd (arg1, - value_as_long (arg2));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
else
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
}
case BINOP_IN:
case TYPE_CODE_PTR:
case TYPE_CODE_ARRAY:
case TYPE_CODE_STRING:
- arg1 = value_subscript (arg1, arg2);
+ arg1 = value_subscript (arg1, value_as_long (arg2));
break;
case TYPE_CODE_BITSTRING:
type = language_bool_type (exp->language_defn, exp->gdbarch);
- arg1 = value_bitstring_subscript (type, arg1, arg2);
+ arg1 = value_bitstring_subscript (type, arg1,
+ value_as_long (arg2));
break;
default:
offset_item =
array_size_array[i - 1] * offset_item + subscript_array[i - 1];
- /* Construct a value node with the value of the offset */
-
- arg2 = value_from_longest (builtin_type_int32, offset_item);
-
/* Let us now play a dirty trick: we will take arg1
which is a value node pointing to the topmost level
of the multidimensional array-set and pretend
returns the correct type value */
deprecated_set_value_type (arg1, tmp_type);
- return value_subscripted_rvalue (arg1, arg2, 0);
+ return value_subscripted_rvalue (arg1, offset_item, 0);
}
case BINOP_LOGICAL_AND:
arg1 = value_cast (type, arg1);
return arg1;
+ case UNOP_DYNAMIC_CAST:
+ (*pos) += 2;
+ type = exp->elts[pc + 1].type;
+ arg1 = evaluate_subexp (type, exp, pos, noside);
+ if (noside == EVAL_SKIP)
+ goto nosideret;
+ return value_dynamic_cast (type, arg1);
+
+ case UNOP_REINTERPRET_CAST:
+ (*pos) += 2;
+ type = exp->elts[pc + 1].type;
+ arg1 = evaluate_subexp (type, exp, pos, noside);
+ if (noside == EVAL_SKIP)
+ goto nosideret;
+ return value_reinterpret_cast (type, arg1);
+
case UNOP_MEMVAL:
(*pos) += 2;
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
+ arg2 = value_ptradd (arg1, 1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_ADD);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ arg2 = value_ptradd (arg1, -1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_SUB);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
+ arg2 = value_ptradd (arg1, 1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_ADD);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ arg2 = value_ptradd (arg1, -1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_SUB);
}
}
nosideret:
- return value_from_longest (builtin_type_int8, (LONGEST) 1);
+ return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
}
\f
/* Evaluate a subexpression of EXP, at index *POS,
goto default_case_after_eval;
}
- return x;
+ return coerce_array (x);
case UNOP_MEMVAL:
(*pos) += 3;
(*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
x = value_aggregate_elt (exp->elts[pc + 1].type,
&exp->elts[pc + 3].string,
- 1, noside);
+ NULL, 1, noside);
if (x == NULL)
error (_("There is no field named %s"), &exp->elts[pc + 3].string);
return x;