1 /* Perform arithmetic and other operations on values, for GDB.
3 Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
5 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
29 #include "gdb_string.h"
34 #include "exceptions.h"
36 /* Define whether or not the C operator '/' truncates towards zero for
37 differently signed operands (truncation direction is undefined in C). */
39 #ifndef TRUNCATION_TOWARDS_ZERO
40 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
43 void _initialize_valarith (void);
46 /* Given a pointer, return the size of its target.
47 If the pointer type is void *, then return 1.
48 If the target type is incomplete, then error out.
49 This isn't a general purpose function, but just a
50 helper for value_ptradd. */
53 find_size_for_pointer_math (struct type
*ptr_type
)
56 struct type
*ptr_target
;
58 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
59 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
61 sz
= TYPE_LENGTH (ptr_target
);
64 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
70 name
= TYPE_NAME (ptr_target
);
72 name
= TYPE_TAG_NAME (ptr_target
);
74 error (_("Cannot perform pointer math on incomplete types, "
75 "try casting to a known type, or void *."));
77 error (_("Cannot perform pointer math on incomplete type \"%s\", "
78 "try casting to a known type, or void *."), name
);
84 /* Given a pointer ARG1 and an integral value ARG2, return the
85 result of C-style pointer arithmetic ARG1 + ARG2. */
88 value_ptradd (struct value
*arg1
, LONGEST arg2
)
90 struct type
*valptrtype
;
94 arg1
= coerce_array (arg1
);
95 valptrtype
= check_typedef (value_type (arg1
));
96 sz
= find_size_for_pointer_math (valptrtype
);
98 result
= value_from_pointer (valptrtype
,
99 value_as_address (arg1
) + sz
* arg2
);
100 if (VALUE_LVAL (result
) != lval_internalvar
)
101 set_value_component_location (result
, arg1
);
105 /* Given two compatible pointer values ARG1 and ARG2, return the
106 result of C-style pointer arithmetic ARG1 - ARG2. */
109 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
111 struct type
*type1
, *type2
;
114 arg1
= coerce_array (arg1
);
115 arg2
= coerce_array (arg2
);
116 type1
= check_typedef (value_type (arg1
));
117 type2
= check_typedef (value_type (arg2
));
119 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
120 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
122 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
123 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
124 error (_("First argument of `-' is a pointer and "
125 "second argument is neither\n"
126 "an integer nor a pointer of the same type."));
128 sz
= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)));
131 warning (_("Type size unknown, assuming 1. "
132 "Try casting to a known type, or void *."));
136 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
139 /* Return the value of ARRAY[IDX].
141 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
142 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
143 To access TYPE_CODE_BITSTRING values, use value_bitstring_subscript.
145 See comments in value_coerce_array() for rationale for reason for
146 doing lower bounds adjustment here rather than there.
147 FIXME: Perhaps we should validate that the index is valid and if
148 verbosity is set, warn about invalid indices (but still use them). */
151 value_subscript (struct value
*array
, LONGEST index
)
153 int c_style
= current_language
->c_style_arrays
;
156 array
= coerce_ref (array
);
157 tarray
= check_typedef (value_type (array
));
159 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
160 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
162 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
163 LONGEST lowerbound
, upperbound
;
165 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
166 if (VALUE_LVAL (array
) != lval_memory
)
167 return value_subscripted_rvalue (array
, index
, lowerbound
);
171 if (index
>= lowerbound
&& index
<= upperbound
)
172 return value_subscripted_rvalue (array
, index
, lowerbound
);
173 /* Emit warning unless we have an array of unknown size.
174 An array of unknown size has lowerbound 0 and upperbound -1. */
176 warning (_("array or string index out of range"));
177 /* fall doing C stuff */
182 array
= value_coerce_array (array
);
186 return value_ind (value_ptradd (array
, index
));
188 error (_("not an array or string"));
191 /* Return the value of EXPR[IDX], expr an aggregate rvalue
192 (eg, a vector register). This routine used to promote floats
193 to doubles, but no longer does. */
196 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
198 struct type
*array_type
= check_typedef (value_type (array
));
199 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
200 unsigned int elt_size
= TYPE_LENGTH (elt_type
);
201 unsigned int elt_offs
= elt_size
* longest_to_int (index
- lowerbound
);
204 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
205 && elt_offs
>= TYPE_LENGTH (array_type
)))
206 error (_("no such vector element"));
208 if (VALUE_LVAL (array
) == lval_memory
&& value_lazy (array
))
209 v
= allocate_value_lazy (elt_type
);
212 v
= allocate_value (elt_type
);
213 memcpy (value_contents_writeable (v
),
214 value_contents (array
) + elt_offs
, elt_size
);
217 set_value_component_location (v
, array
);
218 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
219 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
220 set_value_offset (v
, value_offset (array
) + elt_offs
);
224 /* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */
227 value_bitstring_subscript (struct type
*type
,
228 struct value
*bitstring
, LONGEST index
)
231 struct type
*bitstring_type
, *range_type
;
233 int offset
, byte
, bit_index
;
234 LONGEST lowerbound
, upperbound
;
236 bitstring_type
= check_typedef (value_type (bitstring
));
237 gdb_assert (TYPE_CODE (bitstring_type
) == TYPE_CODE_BITSTRING
);
239 range_type
= TYPE_INDEX_TYPE (bitstring_type
);
240 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
241 if (index
< lowerbound
|| index
> upperbound
)
242 error (_("bitstring index out of range"));
245 offset
= index
/ TARGET_CHAR_BIT
;
246 byte
= *((char *) value_contents (bitstring
) + offset
);
248 bit_index
= index
% TARGET_CHAR_BIT
;
249 byte
>>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type
)) ?
250 TARGET_CHAR_BIT
- 1 - bit_index
: bit_index
);
252 v
= value_from_longest (type
, byte
& 1);
254 set_value_bitpos (v
, bit_index
);
255 set_value_bitsize (v
, 1);
256 set_value_component_location (v
, bitstring
);
257 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (bitstring
);
259 set_value_offset (v
, offset
+ value_offset (bitstring
));
265 /* Check to see if either argument is a structure, or a reference to
266 one. This is called so we know whether to go ahead with the normal
267 binop or look for a user defined function instead.
269 For now, we do not overload the `=' operator. */
272 binop_types_user_defined_p (enum exp_opcode op
,
273 struct type
*type1
, struct type
*type2
)
275 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
278 type1
= check_typedef (type1
);
279 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
280 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
282 type2
= check_typedef (type1
);
283 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
284 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
286 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
287 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
290 /* Check to see if either argument is a structure, or a reference to
291 one. This is called so we know whether to go ahead with the normal
292 binop or look for a user defined function instead.
294 For now, we do not overload the `=' operator. */
297 binop_user_defined_p (enum exp_opcode op
,
298 struct value
*arg1
, struct value
*arg2
)
300 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
303 /* Check to see if argument is a structure. This is called so
304 we know whether to go ahead with the normal unop or look for a
305 user defined function instead.
307 For now, we do not overload the `&' operator. */
310 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
316 type1
= check_typedef (value_type (arg1
));
319 if (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
)
321 else if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
322 type1
= TYPE_TARGET_TYPE (type1
);
328 /* Try to find an operator named OPERATOR which takes NARGS arguments
329 specified in ARGS. If the operator found is a static member operator
330 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
331 The search if performed through find_overload_match which will handle
332 member operators, non member operators, operators imported implicitly or
333 explicitly, and perform correct overload resolution in all of the above
334 situations or combinations thereof. */
336 static struct value
*
337 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *operator,
338 int *static_memfuncp
)
341 struct symbol
*symp
= NULL
;
342 struct value
*valp
= NULL
;
343 struct type
**arg_types
;
346 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
347 /* Prepare list of argument types for overload resolution. */
348 for (i
= 0; i
< nargs
; i
++)
349 arg_types
[i
] = value_type (args
[i
]);
351 find_overload_match (arg_types
, nargs
, operator, BOTH
/* could be method */,
352 0 /* strict match */, &args
[0], /* objp */
353 NULL
/* pass NULL symbol since symbol is unknown */,
354 &valp
, &symp
, static_memfuncp
, 0);
361 /* This is a non member function and does not
362 expect a reference as its first argument
363 rather the explicit structure. */
364 args
[0] = value_ind (args
[0]);
365 return value_of_variable (symp
, 0);
368 error (_("Could not find %s."), operator);
371 /* Lookup user defined operator NAME. Return a value representing the
372 function, otherwise return NULL. */
374 static struct value
*
375 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
376 int *static_memfuncp
, int nargs
)
378 struct value
*result
= NULL
;
380 if (current_language
->la_language
== language_cplus
)
381 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
);
383 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
389 /* We know either arg1 or arg2 is a structure, so try to find the right
390 user defined function. Create an argument vector that calls
391 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
392 binary operator which is legal for GNU C++).
394 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
395 is the opcode saying how to modify it. Otherwise, OTHEROP is
399 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
400 enum exp_opcode otherop
, enum noside noside
)
402 struct value
**argvec
;
407 arg1
= coerce_ref (arg1
);
408 arg2
= coerce_ref (arg2
);
410 /* now we know that what we have to do is construct our
411 arg vector and find the right function to call it with. */
413 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
414 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
416 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
417 argvec
[1] = value_addr (arg1
);
421 /* Make the right function name up. */
422 strcpy (tstr
, "operator__");
447 case BINOP_BITWISE_AND
:
450 case BINOP_BITWISE_IOR
:
453 case BINOP_BITWISE_XOR
:
456 case BINOP_LOGICAL_AND
:
459 case BINOP_LOGICAL_OR
:
471 case BINOP_ASSIGN_MODIFY
:
489 case BINOP_BITWISE_AND
:
492 case BINOP_BITWISE_IOR
:
495 case BINOP_BITWISE_XOR
:
498 case BINOP_MOD
: /* invalid */
500 error (_("Invalid binary operation specified."));
503 case BINOP_SUBSCRIPT
:
524 case BINOP_MOD
: /* invalid */
526 error (_("Invalid binary operation specified."));
529 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
530 &static_memfuncp
, 2);
536 argvec
[1] = argvec
[0];
539 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
541 struct type
*return_type
;
544 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
545 return value_zero (return_type
, VALUE_LVAL (arg1
));
547 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
,
550 throw_error (NOT_FOUND_ERROR
,
551 _("member function %s not found"), tstr
);
553 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
557 /* We know that arg1 is a structure, so try to find a unary user
558 defined operator that matches the operator in question.
559 Create an argument vector that calls arg1.operator @ (arg1)
560 and return that value (where '@' is (almost) any unary operator which
561 is legal for GNU C++). */
564 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
566 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
567 struct value
**argvec
;
568 char *ptr
, *mangle_ptr
;
569 char tstr
[13], mangle_tstr
[13];
570 int static_memfuncp
, nargs
;
572 arg1
= coerce_ref (arg1
);
574 /* now we know that what we have to do is construct our
575 arg vector and find the right function to call it with. */
577 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
578 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
580 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
581 argvec
[1] = value_addr (arg1
);
586 /* Make the right function name up. */
587 strcpy (tstr
, "operator__");
589 strcpy (mangle_tstr
, "__");
590 mangle_ptr
= mangle_tstr
+ 2;
593 case UNOP_PREINCREMENT
:
596 case UNOP_PREDECREMENT
:
599 case UNOP_POSTINCREMENT
:
601 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
605 case UNOP_POSTDECREMENT
:
607 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
611 case UNOP_LOGICAL_NOT
:
614 case UNOP_COMPLEMENT
:
630 error (_("Invalid unary operation specified."));
633 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
634 &static_memfuncp
, nargs
);
640 argvec
[1] = argvec
[0];
644 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
646 struct type
*return_type
;
649 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
650 return value_zero (return_type
, VALUE_LVAL (arg1
));
652 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
654 throw_error (NOT_FOUND_ERROR
,
655 _("member function %s not found"), tstr
);
657 return 0; /* For lint -- never reached */
661 /* Concatenate two values with the following conditions:
663 (1) Both values must be either bitstring values or character string
664 values and the resulting value consists of the concatenation of
665 ARG1 followed by ARG2.
669 One value must be an integer value and the other value must be
670 either a bitstring value or character string value, which is
671 to be repeated by the number of times specified by the integer
675 (2) Boolean values are also allowed and are treated as bit string
678 (3) Character values are also allowed and are treated as character
679 string values of length 1. */
682 value_concat (struct value
*arg1
, struct value
*arg2
)
684 struct value
*inval1
;
685 struct value
*inval2
;
686 struct value
*outval
= NULL
;
687 int inval1len
, inval2len
;
691 struct type
*type1
= check_typedef (value_type (arg1
));
692 struct type
*type2
= check_typedef (value_type (arg2
));
693 struct type
*char_type
;
695 /* First figure out if we are dealing with two values to be concatenated
696 or a repeat count and a value to be repeated. INVAL1 is set to the
697 first of two concatenated values, or the repeat count. INVAL2 is set
698 to the second of the two concatenated values or the value to be
701 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
703 struct type
*tmp
= type1
;
716 /* Now process the input values. */
718 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
720 /* We have a repeat count. Validate the second value and then
721 construct a value repeated that many times. */
722 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
723 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
725 count
= longest_to_int (value_as_long (inval1
));
726 inval2len
= TYPE_LENGTH (type2
);
727 ptr
= (char *) alloca (count
* inval2len
);
728 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
732 inchar
= (char) unpack_long (type2
,
733 value_contents (inval2
));
734 for (idx
= 0; idx
< count
; idx
++)
736 *(ptr
+ idx
) = inchar
;
741 char_type
= TYPE_TARGET_TYPE (type2
);
743 for (idx
= 0; idx
< count
; idx
++)
745 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
749 outval
= value_string (ptr
, count
* inval2len
, char_type
);
751 else if (TYPE_CODE (type2
) == TYPE_CODE_BITSTRING
752 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
754 error (_("unimplemented support for bitstring/boolean repeats"));
758 error (_("can't repeat values of that type"));
761 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
762 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
764 /* We have two character strings to concatenate. */
765 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
766 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
768 error (_("Strings can only be concatenated with other strings."));
770 inval1len
= TYPE_LENGTH (type1
);
771 inval2len
= TYPE_LENGTH (type2
);
772 ptr
= (char *) alloca (inval1len
+ inval2len
);
773 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
777 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
781 char_type
= TYPE_TARGET_TYPE (type1
);
783 memcpy (ptr
, value_contents (inval1
), inval1len
);
785 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
788 (char) unpack_long (type2
, value_contents (inval2
));
792 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
794 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
796 else if (TYPE_CODE (type1
) == TYPE_CODE_BITSTRING
797 || TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
799 /* We have two bitstrings to concatenate. */
800 if (TYPE_CODE (type2
) != TYPE_CODE_BITSTRING
801 && TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
803 error (_("Bitstrings or booleans can only be concatenated "
804 "with other bitstrings or booleans."));
806 error (_("unimplemented support for bitstring/boolean concatenation."));
810 /* We don't know how to concatenate these operands. */
811 error (_("illegal operands for concatenation."));
816 /* Integer exponentiation: V1**V2, where both arguments are
817 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
820 integer_pow (LONGEST v1
, LONGEST v2
)
825 error (_("Attempt to raise 0 to negative power."));
831 /* The Russian Peasant's Algorithm. */
847 /* Integer exponentiation: V1**V2, where both arguments are
848 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
851 uinteger_pow (ULONGEST v1
, LONGEST v2
)
856 error (_("Attempt to raise 0 to negative power."));
862 /* The Russian Peasant's Algorithm. */
878 /* Obtain decimal value of arguments for binary operation, converting from
879 other types if one of them is not decimal floating point. */
881 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
882 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
883 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
885 struct type
*type1
, *type2
;
887 type1
= check_typedef (value_type (arg1
));
888 type2
= check_typedef (value_type (arg2
));
890 /* At least one of the arguments must be of decimal float type. */
891 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
892 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
894 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
895 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
896 /* The DFP extension to the C language does not allow mixing of
897 * decimal float types with other float types in expressions
898 * (see WDTR 24732, page 12). */
899 error (_("Mixing decimal floating types with "
900 "other floating types is not allowed."));
902 /* Obtain decimal value of arg1, converting from other types
905 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
907 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
908 *len_x
= TYPE_LENGTH (type1
);
909 memcpy (x
, value_contents (arg1
), *len_x
);
911 else if (is_integral_type (type1
))
913 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
914 *len_x
= TYPE_LENGTH (type2
);
915 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
918 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
921 /* Obtain decimal value of arg2, converting from other types
924 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
926 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
927 *len_y
= TYPE_LENGTH (type2
);
928 memcpy (y
, value_contents (arg2
), *len_y
);
930 else if (is_integral_type (type2
))
932 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
933 *len_y
= TYPE_LENGTH (type1
);
934 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
937 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
941 /* Perform a binary operation on two operands which have reasonable
942 representations as integers or floats. This includes booleans,
943 characters, integers, or floats.
944 Does not support addition and subtraction on pointers;
945 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
947 static struct value
*
948 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
951 struct type
*type1
, *type2
, *result_type
;
953 arg1
= coerce_ref (arg1
);
954 arg2
= coerce_ref (arg2
);
956 type1
= check_typedef (value_type (arg1
));
957 type2
= check_typedef (value_type (arg2
));
959 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
960 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
961 && !is_integral_type (type1
))
962 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
963 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
964 && !is_integral_type (type2
)))
965 error (_("Argument to arithmetic operation not a number or boolean."));
967 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
968 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
970 int len_v1
, len_v2
, len_v
;
971 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
972 gdb_byte v1
[16], v2
[16];
975 /* If only one type is decimal float, use its type.
976 Otherwise use the bigger type. */
977 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
979 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
981 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
986 len_v
= TYPE_LENGTH (result_type
);
987 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
989 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
990 v2
, &len_v2
, &byte_order_v2
);
999 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
1000 v2
, len_v2
, byte_order_v2
,
1001 v
, len_v
, byte_order_v
);
1005 error (_("Operation not valid for decimal floating point number."));
1008 val
= value_from_decfloat (result_type
, v
);
1010 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
1011 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
1013 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
1014 in target format. real.c in GCC probably has the necessary
1016 DOUBLEST v1
, v2
, v
= 0;
1018 v1
= value_as_double (arg1
);
1019 v2
= value_as_double (arg2
);
1043 error (_("Cannot perform exponentiation: %s"),
1044 safe_strerror (errno
));
1048 v
= v1
< v2
? v1
: v2
;
1052 v
= v1
> v2
? v1
: v2
;
1056 error (_("Integer-only operation on floating point number."));
1059 /* If only one type is float, use its type.
1060 Otherwise use the bigger type. */
1061 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1062 result_type
= type2
;
1063 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1064 result_type
= type1
;
1065 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1066 result_type
= type2
;
1068 result_type
= type1
;
1070 val
= allocate_value (result_type
);
1071 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1073 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1074 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1076 LONGEST v1
, v2
, v
= 0;
1078 v1
= value_as_long (arg1
);
1079 v2
= value_as_long (arg2
);
1083 case BINOP_BITWISE_AND
:
1087 case BINOP_BITWISE_IOR
:
1091 case BINOP_BITWISE_XOR
:
1099 case BINOP_NOTEQUAL
:
1104 error (_("Invalid operation on booleans."));
1107 result_type
= type1
;
1109 val
= allocate_value (result_type
);
1110 store_signed_integer (value_contents_raw (val
),
1111 TYPE_LENGTH (result_type
),
1112 gdbarch_byte_order (get_type_arch (result_type
)),
1116 /* Integral operations here. */
1118 /* Determine type length of the result, and if the operation should
1119 be done unsigned. For exponentiation and shift operators,
1120 use the length and type of the left operand. Otherwise,
1121 use the signedness of the operand with the greater length.
1122 If both operands are of equal length, use unsigned operation
1123 if one of the operands is unsigned. */
1124 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1125 result_type
= type1
;
1126 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1127 result_type
= type1
;
1128 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1129 result_type
= type2
;
1130 else if (TYPE_UNSIGNED (type1
))
1131 result_type
= type1
;
1132 else if (TYPE_UNSIGNED (type2
))
1133 result_type
= type2
;
1135 result_type
= type1
;
1137 if (TYPE_UNSIGNED (result_type
))
1139 LONGEST v2_signed
= value_as_long (arg2
);
1140 ULONGEST v1
, v2
, v
= 0;
1142 v1
= (ULONGEST
) value_as_long (arg1
);
1143 v2
= (ULONGEST
) v2_signed
;
1164 error (_("Division by zero"));
1168 v
= uinteger_pow (v1
, v2_signed
);
1175 error (_("Division by zero"));
1179 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1180 v1 mod 0 has a defined value, v1. */
1188 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1201 case BINOP_BITWISE_AND
:
1205 case BINOP_BITWISE_IOR
:
1209 case BINOP_BITWISE_XOR
:
1213 case BINOP_LOGICAL_AND
:
1217 case BINOP_LOGICAL_OR
:
1222 v
= v1
< v2
? v1
: v2
;
1226 v
= v1
> v2
? v1
: v2
;
1233 case BINOP_NOTEQUAL
:
1254 error (_("Invalid binary operation on numbers."));
1257 val
= allocate_value (result_type
);
1258 store_unsigned_integer (value_contents_raw (val
),
1259 TYPE_LENGTH (value_type (val
)),
1261 (get_type_arch (result_type
)),
1266 LONGEST v1
, v2
, v
= 0;
1268 v1
= value_as_long (arg1
);
1269 v2
= value_as_long (arg2
);
1290 error (_("Division by zero"));
1294 v
= integer_pow (v1
, v2
);
1301 error (_("Division by zero"));
1305 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1306 X mod 0 has a defined value, X. */
1314 /* Compute floor. */
1315 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1331 case BINOP_BITWISE_AND
:
1335 case BINOP_BITWISE_IOR
:
1339 case BINOP_BITWISE_XOR
:
1343 case BINOP_LOGICAL_AND
:
1347 case BINOP_LOGICAL_OR
:
1352 v
= v1
< v2
? v1
: v2
;
1356 v
= v1
> v2
? v1
: v2
;
1363 case BINOP_NOTEQUAL
:
1384 error (_("Invalid binary operation on numbers."));
1387 val
= allocate_value (result_type
);
1388 store_signed_integer (value_contents_raw (val
),
1389 TYPE_LENGTH (value_type (val
)),
1391 (get_type_arch (result_type
)),
1399 /* Performs a binary operation on two vector operands by calling scalar_binop
1400 for each pair of vector components. */
1402 static struct value
*
1403 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1405 struct value
*val
, *tmp
, *mark
;
1406 struct type
*type1
, *type2
, *eltype1
, *eltype2
, *result_type
;
1407 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1408 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1410 type1
= check_typedef (value_type (val1
));
1411 type2
= check_typedef (value_type (val2
));
1413 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1414 && TYPE_VECTOR (type1
)) ? 1 : 0;
1415 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1416 && TYPE_VECTOR (type2
)) ? 1 : 0;
1418 if (!t1_is_vec
|| !t2_is_vec
)
1419 error (_("Vector operations are only supported among vectors"));
1421 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1422 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1423 error (_("Could not determine the vector bounds"));
1425 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1426 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1427 elsize
= TYPE_LENGTH (eltype1
);
1429 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1430 || elsize
!= TYPE_LENGTH (eltype2
)
1431 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1432 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1433 error (_("Cannot perform operation on vectors with different types"));
1435 val
= allocate_value (type1
);
1436 mark
= value_mark ();
1437 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1439 tmp
= value_binop (value_subscript (val1
, i
),
1440 value_subscript (val2
, i
), op
);
1441 memcpy (value_contents_writeable (val
) + i
* elsize
,
1442 value_contents_all (tmp
),
1445 value_free_to_mark (mark
);
1450 /* Perform a binary operation on two operands. */
1453 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1456 struct type
*type1
= check_typedef (value_type (arg1
));
1457 struct type
*type2
= check_typedef (value_type (arg2
));
1458 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1459 && TYPE_VECTOR (type1
));
1460 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1461 && TYPE_VECTOR (type2
));
1463 if (!t1_is_vec
&& !t2_is_vec
)
1464 val
= scalar_binop (arg1
, arg2
, op
);
1465 else if (t1_is_vec
&& t2_is_vec
)
1466 val
= vector_binop (arg1
, arg2
, op
);
1469 /* Widen the scalar operand to a vector. */
1470 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1471 struct type
*t
= t1_is_vec
? type2
: type1
;
1473 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1474 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1475 && !is_integral_type (t
))
1476 error (_("Argument to operation not a number or boolean."));
1478 *v
= value_cast (t1_is_vec
? type1
: type2
, *v
);
1479 val
= vector_binop (arg1
, arg2
, op
);
1485 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1488 value_logical_not (struct value
*arg1
)
1494 arg1
= coerce_array (arg1
);
1495 type1
= check_typedef (value_type (arg1
));
1497 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1498 return 0 == value_as_double (arg1
);
1499 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1500 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1501 gdbarch_byte_order (get_type_arch (type1
)));
1503 len
= TYPE_LENGTH (type1
);
1504 p
= value_contents (arg1
);
1515 /* Perform a comparison on two string values (whose content are not
1516 necessarily null terminated) based on their length. */
1519 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1521 int len1
= TYPE_LENGTH (value_type (arg1
));
1522 int len2
= TYPE_LENGTH (value_type (arg2
));
1523 const gdb_byte
*s1
= value_contents (arg1
);
1524 const gdb_byte
*s2
= value_contents (arg2
);
1525 int i
, len
= len1
< len2
? len1
: len2
;
1527 for (i
= 0; i
< len
; i
++)
1531 else if (s1
[i
] > s2
[i
])
1539 else if (len1
> len2
)
1545 /* Simulate the C operator == by returning a 1
1546 iff ARG1 and ARG2 have equal contents. */
1549 value_equal (struct value
*arg1
, struct value
*arg2
)
1554 struct type
*type1
, *type2
;
1555 enum type_code code1
;
1556 enum type_code code2
;
1557 int is_int1
, is_int2
;
1559 arg1
= coerce_array (arg1
);
1560 arg2
= coerce_array (arg2
);
1562 type1
= check_typedef (value_type (arg1
));
1563 type2
= check_typedef (value_type (arg2
));
1564 code1
= TYPE_CODE (type1
);
1565 code2
= TYPE_CODE (type2
);
1566 is_int1
= is_integral_type (type1
);
1567 is_int2
= is_integral_type (type2
);
1569 if (is_int1
&& is_int2
)
1570 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1572 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1573 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1575 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1576 `long double' values are returned in static storage (m68k). */
1577 DOUBLEST d
= value_as_double (arg1
);
1579 return d
== value_as_double (arg2
);
1581 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1582 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1584 gdb_byte v1
[16], v2
[16];
1586 enum bfd_endian byte_order_v1
, byte_order_v2
;
1588 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1589 v2
, &len_v2
, &byte_order_v2
);
1591 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1592 v2
, len_v2
, byte_order_v2
) == 0;
1595 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1597 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1598 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1599 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1600 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1602 else if (code1
== code2
1603 && ((len
= (int) TYPE_LENGTH (type1
))
1604 == (int) TYPE_LENGTH (type2
)))
1606 p1
= value_contents (arg1
);
1607 p2
= value_contents (arg2
);
1615 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1617 return value_strcmp (arg1
, arg2
) == 0;
1621 error (_("Invalid type combination in equality test."));
1622 return 0; /* For lint -- never reached. */
1626 /* Compare values based on their raw contents. Useful for arrays since
1627 value_equal coerces them to pointers, thus comparing just the address
1628 of the array instead of its contents. */
1631 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1633 struct type
*type1
, *type2
;
1635 type1
= check_typedef (value_type (arg1
));
1636 type2
= check_typedef (value_type (arg2
));
1638 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1639 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1640 && memcmp (value_contents (arg1
), value_contents (arg2
),
1641 TYPE_LENGTH (type1
)) == 0);
1644 /* Simulate the C operator < by returning 1
1645 iff ARG1's contents are less than ARG2's. */
1648 value_less (struct value
*arg1
, struct value
*arg2
)
1650 enum type_code code1
;
1651 enum type_code code2
;
1652 struct type
*type1
, *type2
;
1653 int is_int1
, is_int2
;
1655 arg1
= coerce_array (arg1
);
1656 arg2
= coerce_array (arg2
);
1658 type1
= check_typedef (value_type (arg1
));
1659 type2
= check_typedef (value_type (arg2
));
1660 code1
= TYPE_CODE (type1
);
1661 code2
= TYPE_CODE (type2
);
1662 is_int1
= is_integral_type (type1
);
1663 is_int2
= is_integral_type (type2
);
1665 if (is_int1
&& is_int2
)
1666 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1668 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1669 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1671 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1672 `long double' values are returned in static storage (m68k). */
1673 DOUBLEST d
= value_as_double (arg1
);
1675 return d
< value_as_double (arg2
);
1677 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1678 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1680 gdb_byte v1
[16], v2
[16];
1682 enum bfd_endian byte_order_v1
, byte_order_v2
;
1684 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1685 v2
, &len_v2
, &byte_order_v2
);
1687 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1688 v2
, len_v2
, byte_order_v2
) == -1;
1690 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1691 return value_as_address (arg1
) < value_as_address (arg2
);
1693 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1695 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1696 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1697 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1698 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1699 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1700 return value_strcmp (arg1
, arg2
) < 0;
1703 error (_("Invalid type combination in ordering comparison."));
1708 /* The unary operators +, - and ~. They free the argument ARG1. */
1711 value_pos (struct value
*arg1
)
1715 arg1
= coerce_ref (arg1
);
1716 type
= check_typedef (value_type (arg1
));
1718 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1719 return value_from_double (type
, value_as_double (arg1
));
1720 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1721 return value_from_decfloat (type
, value_contents (arg1
));
1722 else if (is_integral_type (type
))
1724 return value_from_longest (type
, value_as_long (arg1
));
1726 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1728 struct value
*val
= allocate_value (type
);
1730 memcpy (value_contents_raw (val
), value_contents (arg1
),
1731 TYPE_LENGTH (type
));
1736 error (_("Argument to positive operation not a number."));
1737 return 0; /* For lint -- never reached. */
1742 value_neg (struct value
*arg1
)
1746 arg1
= coerce_ref (arg1
);
1747 type
= check_typedef (value_type (arg1
));
1749 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1751 struct value
*val
= allocate_value (type
);
1752 int len
= TYPE_LENGTH (type
);
1753 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1755 memcpy (decbytes
, value_contents (arg1
), len
);
1757 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1758 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1760 decbytes
[0] = decbytes
[0] | 0x80;
1762 memcpy (value_contents_raw (val
), decbytes
, len
);
1765 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1766 return value_from_double (type
, -value_as_double (arg1
));
1767 else if (is_integral_type (type
))
1769 return value_from_longest (type
, -value_as_long (arg1
));
1771 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1773 struct value
*tmp
, *val
= allocate_value (type
);
1774 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1776 LONGEST low_bound
, high_bound
;
1778 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1779 error (_("Could not determine the vector bounds"));
1781 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1783 tmp
= value_neg (value_subscript (arg1
, i
));
1784 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1785 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1791 error (_("Argument to negate operation not a number."));
1792 return 0; /* For lint -- never reached. */
1797 value_complement (struct value
*arg1
)
1802 arg1
= coerce_ref (arg1
);
1803 type
= check_typedef (value_type (arg1
));
1805 if (is_integral_type (type
))
1806 val
= value_from_longest (type
, ~value_as_long (arg1
));
1807 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1810 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1812 LONGEST low_bound
, high_bound
;
1814 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1815 error (_("Could not determine the vector bounds"));
1817 val
= allocate_value (type
);
1818 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1820 tmp
= value_complement (value_subscript (arg1
, i
));
1821 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1822 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1826 error (_("Argument to complement operation not an integer, boolean."));
1831 /* The INDEX'th bit of SET value whose value_type is TYPE,
1832 and whose value_contents is valaddr.
1833 Return -1 if out of range, -2 other error. */
1836 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1838 struct gdbarch
*gdbarch
= get_type_arch (type
);
1839 LONGEST low_bound
, high_bound
;
1842 struct type
*range
= TYPE_INDEX_TYPE (type
);
1844 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1846 if (index
< low_bound
|| index
> high_bound
)
1848 rel_index
= index
- low_bound
;
1849 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1850 gdbarch_byte_order (gdbarch
));
1851 rel_index
%= TARGET_CHAR_BIT
;
1852 if (gdbarch_bits_big_endian (gdbarch
))
1853 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1854 return (word
>> rel_index
) & 1;
1858 value_in (struct value
*element
, struct value
*set
)
1861 struct type
*settype
= check_typedef (value_type (set
));
1862 struct type
*eltype
= check_typedef (value_type (element
));
1864 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1865 eltype
= TYPE_TARGET_TYPE (eltype
);
1866 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1867 error (_("Second argument of 'IN' has wrong type"));
1868 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1869 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1870 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1871 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1872 error (_("First argument of 'IN' has wrong type"));
1873 member
= value_bit_index (settype
, value_contents (set
),
1874 value_as_long (element
));
1876 error (_("First argument of 'IN' not in range"));
1881 _initialize_valarith (void)
This page took 0.070306 seconds and 4 git commands to generate.