static void parse_operand6 PARAMS ((void));
static void parse_primval PARAMS ((void));
static void parse_tuple PARAMS ((struct type *));
-static void parse_opt_element_list PARAMS ((void));
-static void parse_tuple_element PARAMS ((void));
+static void parse_opt_element_list PARAMS ((struct type *));
+static void parse_tuple_element PARAMS ((struct type *));
static void parse_named_record_element PARAMS ((void));
static void parse_call PARAMS ((void));
static struct type *parse_mode_or_normal_call PARAMS ((void));
write_exp_elt_opcode (OP_LABELED);
}
-/* Returns one or nore TREE_LIST nodes, in reverse order. */
+/* Returns one or more TREE_LIST nodes, in reverse order. */
static void
-parse_tuple_element ()
+parse_tuple_element (type)
+ struct type *type;
{
if (PEEK_TOKEN () == FIELD_NAME)
{
if (check_token ('*'))
{
expect (')', "missing ')' after '*' case label list");
- error ("(*) not implemented in case label list");
+ if (type)
+ {
+ if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+ {
+ /* do this as a range from low to high */
+ struct type *range_type = TYPE_FIELD_TYPE (type, 0);
+ LONGEST low_bound, high_bound;
+ if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ error ("cannot determine bounds for (*)");
+ /* lower bound */
+ write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_type (range_type);
+ write_exp_elt_longcst (low_bound);
+ write_exp_elt_opcode (OP_LONG);
+ /* upper bound */
+ write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_type (range_type);
+ write_exp_elt_longcst (high_bound);
+ write_exp_elt_opcode (OP_LONG);
+ write_exp_elt_opcode (BINOP_RANGE);
+ }
+ else
+ error ("(*) in invalid context");
+ }
+ else
+ error ("(*) only possible with modename in front of tuple (mode[..])");
}
else
{
/* Matches: a COMMA-separated list of tuple elements.
Returns a list (of TREE_LIST nodes). */
static void
-parse_opt_element_list ()
+parse_opt_element_list (type)
+ struct type *type;
{
arglist_len = 0;
if (PEEK_TOKEN () == ']')
return;
for (;;)
{
- parse_tuple_element ();
+ parse_tuple_element (type);
arglist_len++;
if (PEEK_TOKEN () == ']')
break;
parse_tuple (mode)
struct type *mode;
{
+ struct type *type;
+ if (mode)
+ type = check_typedef (mode);
+ else
+ type = 0;
require ('[');
start_arglist ();
- parse_opt_element_list ();
+ parse_opt_element_list (type);
expect (']', "missing ']' after tuple");
write_exp_elt_opcode (OP_ARRAY);
write_exp_elt_longcst ((LONGEST) 0);
write_exp_elt_longcst ((LONGEST) end_arglist () - 1);
write_exp_elt_opcode (OP_ARRAY);
- if (mode)
+ if (type)
{
- struct type *type = check_typedef (mode);
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_SET)
/* Evaluate expressions for GDB.
- Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996
Free Software Foundation, Inc.
This file is part of GDB.
static value_ptr evaluate_subexp_for_address PARAMS ((struct expression *,
int *, enum noside));
+static value_ptr evaluate_subexp PARAMS ((struct type *, struct expression *,
+ int *, enum noside));
+
+static char *get_label PARAMS ((struct expression *, int *));
+
+static value_ptr
+evaluate_struct_tuple PARAMS ((value_ptr, struct expression *, int *,
+ enum noside, int));
+
+static LONGEST
+init_array_element PARAMS ((value_ptr, value_ptr, struct expression *,
+ int *, enum noside, LONGEST, LONGEST));
+
#ifdef __GNUC__
inline
#endif
register struct expression *exp;
register int *pos;
enum noside noside;
+ LONGEST low_bound, high_bound;
{
LONGEST index;
int element_size = TYPE_LENGTH (VALUE_TYPE (element));
low_bound = 0;
high_bound = (TYPE_LENGTH (type) / element_size) - 1;
}
+ if (nargs > (high_bound - low_bound + 1))
+ /* to avoid memory corruption */
+ error ("Too many array elements");
index = low_bound;
memset (VALUE_CONTENTS_RAW (array), 0, TYPE_LENGTH (expect_type));
for (tem = nargs; --nargs >= 0; )
if (noside == EVAL_SKIP)
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
return value_concat (arg1, arg2);
if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
return arg1;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
return value_assign (arg1, arg2);
return arg1;
op = exp->elts[pc + 1].opcode;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op);
+ return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
else if (op == BINOP_ADD)
arg2 = value_add (arg1, arg2);
else if (op == BINOP_SUB)
if (noside == EVAL_SKIP)
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
return value_add (arg1, arg2);
if (noside == EVAL_SKIP)
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
return value_sub (arg1, arg2);
if (noside == EVAL_SKIP)
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
if (noside == EVAL_AVOID_SIDE_EFFECTS
&& (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
if (noside == EVAL_SKIP)
goto nosideret;
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
- {
- /* If the user attempts to subscript something that has no target
- type (like a plain int variable for example), then report this
- as an error. */
-
- type = TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1)));
- if (type)
- return value_zero (type, VALUE_LVAL (arg1));
- else
- error ("cannot subscript something of type `%s'",
- TYPE_NAME (VALUE_TYPE (arg1)));
- }
-
if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
else
- return value_subscript (arg1, arg2);
+ {
+ /* If the user attempts to subscript something that is not an
+ array or pointer type (like a plain int variable for example),
+ then report this as an error. */
+
+ COERCE_REF (arg1);
+ type = check_typedef (VALUE_TYPE (arg1));
+ if (TYPE_CODE (type) != TYPE_CODE_ARRAY
+ && TYPE_CODE (type) != TYPE_CODE_PTR)
+ {
+ if (TYPE_NAME (type))
+ error ("cannot subscript something of type `%s'",
+ TYPE_NAME (type));
+ else
+ error ("cannot subscript requested type");
+ }
+
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
+ else
+ return value_subscript (arg1, arg2);
+ }
case BINOP_IN:
arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
if (binop_user_defined_p (op, arg1, arg2))
{
- arg1 = value_x_binop (arg1, arg2, op, OP_NULL);
+ arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
if (binop_user_defined_p (op, arg1, arg2))
{
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
if (binop_user_defined_p (op, arg1, arg2))
{
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
{
- return value_x_binop (arg1, arg2, op, OP_NULL);
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
if (noside == EVAL_SKIP)
goto nosideret;
if (unop_user_defined_p (op, arg1))
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
else
return value_neg (arg1);
if (noside == EVAL_SKIP)
goto nosideret;
if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
- return value_x_unop (arg1, UNOP_COMPLEMENT);
+ return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
else
return value_complement (arg1);
if (noside == EVAL_SKIP)
goto nosideret;
if (unop_user_defined_p (op, arg1))
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
else
return value_from_longest (builtin_type_int,
(LONGEST) value_logical_not (arg1));
return arg1;
else if (unop_user_defined_p (op, arg1))
{
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
}
else
{
return arg1;
else if (unop_user_defined_p (op, arg1))
{
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
}
else
{
return arg1;
else if (unop_user_defined_p (op, arg1))
{
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
}
else
{
return arg1;
else if (unop_user_defined_p (op, arg1))
{
- return value_x_unop (arg1, op);
+ return value_x_unop (arg1, op, noside);
}
else
{
/* Definitions for values of C expressions, for GDB.
- Copyright 1986, 1987, 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+ Copyright 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996
+ Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if !defined (VALUE_H)
#define VALUE_H 1
char *myaddr;
} substring_addr;
- /* If an lval is forced to repeat, a new value is created with
- these fields set. The new value is not an lval. */
- short repeated;
- short repetitions;
/* Register number if the value is from a register. Is not kept
if you take a field of a structure that is stored in a
register. Shouldn't it be? */
#define VALUE_BITSIZE(val) (val)->bitsize
#define VALUE_BITPOS(val) (val)->bitpos
#define VALUE_NEXT(val) (val)->next
-#define VALUE_REPEATED(val) (val)->repeated
-#define VALUE_REPETITIONS(val) (val)->repetitions
#define VALUE_REGNO(val) (val)->regno
#define VALUE_OPTIMIZED_OUT(val) ((val)->optimized_out)
/* Convert a REF to the object referenced. */
#define COERCE_REF(arg) \
-{ if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \
- arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)), \
- unpack_long (VALUE_TYPE (arg), \
- VALUE_CONTENTS (arg)));}
+do { CHECK_TYPEDEF (VALUE_TYPE (arg)); \
+ if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \
+ arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)), \
+ unpack_long (VALUE_TYPE (arg), \
+ VALUE_CONTENTS (arg))); \
+} while (0)
/* If ARG is an array, convert it to a pointer.
If ARG is an enum, convert it to an integer.
References are dereferenced. */
#define COERCE_ARRAY(arg) \
-{ COERCE_REF(arg); \
+do { COERCE_REF(arg); \
if (current_language->c_style_arrays \
- && (VALUE_REPEATED (arg) \
- || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY)) \
+ && TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY) \
arg = value_coerce_array (arg); \
if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC) \
arg = value_coerce_function (arg); \
- if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
- arg = value_cast (builtin_type_unsigned_int, arg); \
-}
+} while (0)
+
+#define COERCE_NUMBER(arg) \
+ do { COERCE_ARRAY(arg); COERCE_ENUM(arg); } while (0)
-#define COERCE_VARYING_ARRAY(arg) \
-{ if (chill_varying_type (VALUE_TYPE (arg))) arg = varying_to_slice (arg); }
+#define COERCE_VARYING_ARRAY(arg, real_arg_type) \
+{ if (chill_varying_type (real_arg_type)) \
+ arg = varying_to_slice (arg), real_arg_type = VALUE_TYPE (arg); }
/* If ARG is an enum, convert it to an integer. */
-#define COERCE_ENUM(arg) \
-{ COERCE_REF (arg); \
+#define COERCE_ENUM(arg) { \
if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
arg = value_cast (builtin_type_unsigned_int, arg); \
}
extern LONGEST value_as_long PARAMS ((value_ptr val));
-extern double value_as_double PARAMS ((value_ptr val));
+extern DOUBLEST value_as_double PARAMS ((value_ptr val));
extern CORE_ADDR value_as_pointer PARAMS ((value_ptr val));
extern LONGEST unpack_long PARAMS ((struct type *type, char *valaddr));
-extern double unpack_double PARAMS ((struct type *type, char *valaddr,
- int *invp));
+extern DOUBLEST unpack_double PARAMS ((struct type *type, char *valaddr,
+ int *invp));
extern CORE_ADDR unpack_pointer PARAMS ((struct type *type, char *valaddr));
extern value_ptr value_from_longest PARAMS ((struct type *type, LONGEST num));
-extern value_ptr value_from_double PARAMS ((struct type *type, double num));
+extern value_ptr value_from_double PARAMS ((struct type *type, DOUBLEST num));
extern value_ptr value_at PARAMS ((struct type *type, CORE_ADDR addr));
extern value_ptr evaluate_type PARAMS ((struct expression *exp));
+extern value_ptr evaluate_subexp_with_coercion PARAMS ((struct expression *,
+ int *, enum noside));
+
extern value_ptr parse_and_eval PARAMS ((char *exp));
extern value_ptr parse_to_comma_and_eval PARAMS ((char **expp));
extern value_ptr value_x_binop PARAMS ((value_ptr arg1, value_ptr arg2,
enum exp_opcode op,
- enum exp_opcode otherop));
+ enum exp_opcode otherop,
+ enum noside noside));
-extern value_ptr value_x_unop PARAMS ((value_ptr arg1, enum exp_opcode op));
+extern value_ptr value_x_unop PARAMS ((value_ptr arg1, enum exp_opcode op,
+ enum noside noside));
extern value_ptr value_fn_field PARAMS ((value_ptr *arg1p, struct fn_field *f,
int j,
extern value_ptr value_copy PARAMS ((value_ptr));
-extern int baseclass_offset PARAMS ((struct type *, int, value_ptr, int));
+extern int baseclass_offset PARAMS ((struct type *, int, char *, CORE_ADDR));
/* From valops.c */
extern value_ptr value_literal_complex PARAMS ((value_ptr, value_ptr, struct type*));
+extern value_ptr find_function_in_inferior PARAMS ((char *));
+
+extern value_ptr value_allocate_space_in_inferior PARAMS ((int));
+
#endif /* !defined (VALUE_H) */