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 value_contents_copy (v
, value_embedded_offset (v
),
214 array
, value_embedded_offset (array
) + elt_offs
,
218 set_value_component_location (v
, array
);
219 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
220 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
221 set_value_offset (v
, value_offset (array
) + elt_offs
);
225 /* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */
228 value_bitstring_subscript (struct type
*type
,
229 struct value
*bitstring
, LONGEST index
)
232 struct type
*bitstring_type
, *range_type
;
234 int offset
, byte
, bit_index
;
235 LONGEST lowerbound
, upperbound
;
237 bitstring_type
= check_typedef (value_type (bitstring
));
238 gdb_assert (TYPE_CODE (bitstring_type
) == TYPE_CODE_BITSTRING
);
240 range_type
= TYPE_INDEX_TYPE (bitstring_type
);
241 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
242 if (index
< lowerbound
|| index
> upperbound
)
243 error (_("bitstring index out of range"));
246 offset
= index
/ TARGET_CHAR_BIT
;
247 byte
= *((char *) value_contents (bitstring
) + offset
);
249 bit_index
= index
% TARGET_CHAR_BIT
;
250 byte
>>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type
)) ?
251 TARGET_CHAR_BIT
- 1 - bit_index
: bit_index
);
253 v
= value_from_longest (type
, byte
& 1);
255 set_value_bitpos (v
, bit_index
);
256 set_value_bitsize (v
, 1);
257 set_value_component_location (v
, bitstring
);
258 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (bitstring
);
260 set_value_offset (v
, offset
+ value_offset (bitstring
));
266 /* Check to see if either argument is a structure, or a reference to
267 one. This is called so we know whether to go ahead with the normal
268 binop or look for a user defined function instead.
270 For now, we do not overload the `=' operator. */
273 binop_types_user_defined_p (enum exp_opcode op
,
274 struct type
*type1
, struct type
*type2
)
276 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
279 type1
= check_typedef (type1
);
280 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
281 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
283 type2
= check_typedef (type1
);
284 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
285 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
287 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
288 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
291 /* Check to see if either argument is a structure, or a reference to
292 one. This is called so we know whether to go ahead with the normal
293 binop or look for a user defined function instead.
295 For now, we do not overload the `=' operator. */
298 binop_user_defined_p (enum exp_opcode op
,
299 struct value
*arg1
, struct value
*arg2
)
301 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
304 /* Check to see if argument is a structure. This is called so
305 we know whether to go ahead with the normal unop or look for a
306 user defined function instead.
308 For now, we do not overload the `&' operator. */
311 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
317 type1
= check_typedef (value_type (arg1
));
320 if (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
)
322 else if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
323 type1
= TYPE_TARGET_TYPE (type1
);
329 /* Try to find an operator named OPERATOR which takes NARGS arguments
330 specified in ARGS. If the operator found is a static member operator
331 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
332 The search if performed through find_overload_match which will handle
333 member operators, non member operators, operators imported implicitly or
334 explicitly, and perform correct overload resolution in all of the above
335 situations or combinations thereof. */
337 static struct value
*
338 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *operator,
339 int *static_memfuncp
)
342 struct symbol
*symp
= NULL
;
343 struct value
*valp
= NULL
;
344 struct type
**arg_types
;
347 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
348 /* Prepare list of argument types for overload resolution. */
349 for (i
= 0; i
< nargs
; i
++)
350 arg_types
[i
] = value_type (args
[i
]);
352 find_overload_match (arg_types
, nargs
, operator, BOTH
/* could be method */,
353 0 /* strict match */, &args
[0], /* objp */
354 NULL
/* pass NULL symbol since symbol is unknown */,
355 &valp
, &symp
, static_memfuncp
, 0);
362 /* This is a non member function and does not
363 expect a reference as its first argument
364 rather the explicit structure. */
365 args
[0] = value_ind (args
[0]);
366 return value_of_variable (symp
, 0);
369 error (_("Could not find %s."), operator);
372 /* Lookup user defined operator NAME. Return a value representing the
373 function, otherwise return NULL. */
375 static struct value
*
376 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
377 int *static_memfuncp
, int nargs
)
379 struct value
*result
= NULL
;
381 if (current_language
->la_language
== language_cplus
)
382 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
);
384 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
390 /* We know either arg1 or arg2 is a structure, so try to find the right
391 user defined function. Create an argument vector that calls
392 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
393 binary operator which is legal for GNU C++).
395 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
396 is the opcode saying how to modify it. Otherwise, OTHEROP is
400 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
401 enum exp_opcode otherop
, enum noside noside
)
403 struct value
**argvec
;
408 arg1
= coerce_ref (arg1
);
409 arg2
= coerce_ref (arg2
);
411 /* now we know that what we have to do is construct our
412 arg vector and find the right function to call it with. */
414 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
415 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
417 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
418 argvec
[1] = value_addr (arg1
);
422 /* Make the right function name up. */
423 strcpy (tstr
, "operator__");
448 case BINOP_BITWISE_AND
:
451 case BINOP_BITWISE_IOR
:
454 case BINOP_BITWISE_XOR
:
457 case BINOP_LOGICAL_AND
:
460 case BINOP_LOGICAL_OR
:
472 case BINOP_ASSIGN_MODIFY
:
490 case BINOP_BITWISE_AND
:
493 case BINOP_BITWISE_IOR
:
496 case BINOP_BITWISE_XOR
:
499 case BINOP_MOD
: /* invalid */
501 error (_("Invalid binary operation specified."));
504 case BINOP_SUBSCRIPT
:
525 case BINOP_MOD
: /* invalid */
527 error (_("Invalid binary operation specified."));
530 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
531 &static_memfuncp
, 2);
537 argvec
[1] = argvec
[0];
540 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
542 struct type
*return_type
;
545 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
546 return value_zero (return_type
, VALUE_LVAL (arg1
));
548 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
,
551 throw_error (NOT_FOUND_ERROR
,
552 _("member function %s not found"), tstr
);
554 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
558 /* We know that arg1 is a structure, so try to find a unary user
559 defined operator that matches the operator in question.
560 Create an argument vector that calls arg1.operator @ (arg1)
561 and return that value (where '@' is (almost) any unary operator which
562 is legal for GNU C++). */
565 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
567 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
568 struct value
**argvec
;
569 char *ptr
, *mangle_ptr
;
570 char tstr
[13], mangle_tstr
[13];
571 int static_memfuncp
, nargs
;
573 arg1
= coerce_ref (arg1
);
575 /* now we know that what we have to do is construct our
576 arg vector and find the right function to call it with. */
578 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
579 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
581 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
582 argvec
[1] = value_addr (arg1
);
587 /* Make the right function name up. */
588 strcpy (tstr
, "operator__");
590 strcpy (mangle_tstr
, "__");
591 mangle_ptr
= mangle_tstr
+ 2;
594 case UNOP_PREINCREMENT
:
597 case UNOP_PREDECREMENT
:
600 case UNOP_POSTINCREMENT
:
602 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
606 case UNOP_POSTDECREMENT
:
608 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
612 case UNOP_LOGICAL_NOT
:
615 case UNOP_COMPLEMENT
:
631 error (_("Invalid unary operation specified."));
634 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
635 &static_memfuncp
, nargs
);
641 argvec
[1] = argvec
[0];
645 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
647 struct type
*return_type
;
650 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
651 return value_zero (return_type
, VALUE_LVAL (arg1
));
653 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
655 throw_error (NOT_FOUND_ERROR
,
656 _("member function %s not found"), tstr
);
658 return 0; /* For lint -- never reached */
662 /* Concatenate two values with the following conditions:
664 (1) Both values must be either bitstring values or character string
665 values and the resulting value consists of the concatenation of
666 ARG1 followed by ARG2.
670 One value must be an integer value and the other value must be
671 either a bitstring value or character string value, which is
672 to be repeated by the number of times specified by the integer
676 (2) Boolean values are also allowed and are treated as bit string
679 (3) Character values are also allowed and are treated as character
680 string values of length 1. */
683 value_concat (struct value
*arg1
, struct value
*arg2
)
685 struct value
*inval1
;
686 struct value
*inval2
;
687 struct value
*outval
= NULL
;
688 int inval1len
, inval2len
;
692 struct type
*type1
= check_typedef (value_type (arg1
));
693 struct type
*type2
= check_typedef (value_type (arg2
));
694 struct type
*char_type
;
696 /* First figure out if we are dealing with two values to be concatenated
697 or a repeat count and a value to be repeated. INVAL1 is set to the
698 first of two concatenated values, or the repeat count. INVAL2 is set
699 to the second of the two concatenated values or the value to be
702 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
704 struct type
*tmp
= type1
;
717 /* Now process the input values. */
719 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
721 /* We have a repeat count. Validate the second value and then
722 construct a value repeated that many times. */
723 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
724 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
726 count
= longest_to_int (value_as_long (inval1
));
727 inval2len
= TYPE_LENGTH (type2
);
728 ptr
= (char *) alloca (count
* inval2len
);
729 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
733 inchar
= (char) unpack_long (type2
,
734 value_contents (inval2
));
735 for (idx
= 0; idx
< count
; idx
++)
737 *(ptr
+ idx
) = inchar
;
742 char_type
= TYPE_TARGET_TYPE (type2
);
744 for (idx
= 0; idx
< count
; idx
++)
746 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
750 outval
= value_string (ptr
, count
* inval2len
, char_type
);
752 else if (TYPE_CODE (type2
) == TYPE_CODE_BITSTRING
753 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
755 error (_("unimplemented support for bitstring/boolean repeats"));
759 error (_("can't repeat values of that type"));
762 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
763 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
765 /* We have two character strings to concatenate. */
766 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
767 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
769 error (_("Strings can only be concatenated with other strings."));
771 inval1len
= TYPE_LENGTH (type1
);
772 inval2len
= TYPE_LENGTH (type2
);
773 ptr
= (char *) alloca (inval1len
+ inval2len
);
774 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
778 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
782 char_type
= TYPE_TARGET_TYPE (type1
);
784 memcpy (ptr
, value_contents (inval1
), inval1len
);
786 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
789 (char) unpack_long (type2
, value_contents (inval2
));
793 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
795 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
797 else if (TYPE_CODE (type1
) == TYPE_CODE_BITSTRING
798 || TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
800 /* We have two bitstrings to concatenate. */
801 if (TYPE_CODE (type2
) != TYPE_CODE_BITSTRING
802 && TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
804 error (_("Bitstrings or booleans can only be concatenated "
805 "with other bitstrings or booleans."));
807 error (_("unimplemented support for bitstring/boolean concatenation."));
811 /* We don't know how to concatenate these operands. */
812 error (_("illegal operands for concatenation."));
817 /* Integer exponentiation: V1**V2, where both arguments are
818 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
821 integer_pow (LONGEST v1
, LONGEST v2
)
826 error (_("Attempt to raise 0 to negative power."));
832 /* The Russian Peasant's Algorithm. */
848 /* Integer exponentiation: V1**V2, where both arguments are
849 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
852 uinteger_pow (ULONGEST v1
, LONGEST v2
)
857 error (_("Attempt to raise 0 to negative power."));
863 /* The Russian Peasant's Algorithm. */
879 /* Obtain decimal value of arguments for binary operation, converting from
880 other types if one of them is not decimal floating point. */
882 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
883 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
884 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
886 struct type
*type1
, *type2
;
888 type1
= check_typedef (value_type (arg1
));
889 type2
= check_typedef (value_type (arg2
));
891 /* At least one of the arguments must be of decimal float type. */
892 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
893 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
895 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
896 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
897 /* The DFP extension to the C language does not allow mixing of
898 * decimal float types with other float types in expressions
899 * (see WDTR 24732, page 12). */
900 error (_("Mixing decimal floating types with "
901 "other floating types is not allowed."));
903 /* Obtain decimal value of arg1, converting from other types
906 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
908 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
909 *len_x
= TYPE_LENGTH (type1
);
910 memcpy (x
, value_contents (arg1
), *len_x
);
912 else if (is_integral_type (type1
))
914 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
915 *len_x
= TYPE_LENGTH (type2
);
916 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
919 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
922 /* Obtain decimal value of arg2, converting from other types
925 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
927 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
928 *len_y
= TYPE_LENGTH (type2
);
929 memcpy (y
, value_contents (arg2
), *len_y
);
931 else if (is_integral_type (type2
))
933 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
934 *len_y
= TYPE_LENGTH (type1
);
935 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
938 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
942 /* Perform a binary operation on two operands which have reasonable
943 representations as integers or floats. This includes booleans,
944 characters, integers, or floats.
945 Does not support addition and subtraction on pointers;
946 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
948 static struct value
*
949 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
952 struct type
*type1
, *type2
, *result_type
;
954 arg1
= coerce_ref (arg1
);
955 arg2
= coerce_ref (arg2
);
957 type1
= check_typedef (value_type (arg1
));
958 type2
= check_typedef (value_type (arg2
));
960 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
961 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
962 && !is_integral_type (type1
))
963 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
964 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
965 && !is_integral_type (type2
)))
966 error (_("Argument to arithmetic operation not a number or boolean."));
968 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
969 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
971 int len_v1
, len_v2
, len_v
;
972 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
973 gdb_byte v1
[16], v2
[16];
976 /* If only one type is decimal float, use its type.
977 Otherwise use the bigger type. */
978 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
980 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
982 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
987 len_v
= TYPE_LENGTH (result_type
);
988 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
990 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
991 v2
, &len_v2
, &byte_order_v2
);
1000 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
1001 v2
, len_v2
, byte_order_v2
,
1002 v
, len_v
, byte_order_v
);
1006 error (_("Operation not valid for decimal floating point number."));
1009 val
= value_from_decfloat (result_type
, v
);
1011 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
1012 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
1014 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
1015 in target format. real.c in GCC probably has the necessary
1017 DOUBLEST v1
, v2
, v
= 0;
1019 v1
= value_as_double (arg1
);
1020 v2
= value_as_double (arg2
);
1044 error (_("Cannot perform exponentiation: %s"),
1045 safe_strerror (errno
));
1049 v
= v1
< v2
? v1
: v2
;
1053 v
= v1
> v2
? v1
: v2
;
1057 error (_("Integer-only operation on floating point number."));
1060 /* If only one type is float, use its type.
1061 Otherwise use the bigger type. */
1062 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1063 result_type
= type2
;
1064 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1065 result_type
= type1
;
1066 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1067 result_type
= type2
;
1069 result_type
= type1
;
1071 val
= allocate_value (result_type
);
1072 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1074 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1075 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1077 LONGEST v1
, v2
, v
= 0;
1079 v1
= value_as_long (arg1
);
1080 v2
= value_as_long (arg2
);
1084 case BINOP_BITWISE_AND
:
1088 case BINOP_BITWISE_IOR
:
1092 case BINOP_BITWISE_XOR
:
1100 case BINOP_NOTEQUAL
:
1105 error (_("Invalid operation on booleans."));
1108 result_type
= type1
;
1110 val
= allocate_value (result_type
);
1111 store_signed_integer (value_contents_raw (val
),
1112 TYPE_LENGTH (result_type
),
1113 gdbarch_byte_order (get_type_arch (result_type
)),
1117 /* Integral operations here. */
1119 /* Determine type length of the result, and if the operation should
1120 be done unsigned. For exponentiation and shift operators,
1121 use the length and type of the left operand. Otherwise,
1122 use the signedness of the operand with the greater length.
1123 If both operands are of equal length, use unsigned operation
1124 if one of the operands is unsigned. */
1125 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1126 result_type
= type1
;
1127 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1128 result_type
= type1
;
1129 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1130 result_type
= type2
;
1131 else if (TYPE_UNSIGNED (type1
))
1132 result_type
= type1
;
1133 else if (TYPE_UNSIGNED (type2
))
1134 result_type
= type2
;
1136 result_type
= type1
;
1138 if (TYPE_UNSIGNED (result_type
))
1140 LONGEST v2_signed
= value_as_long (arg2
);
1141 ULONGEST v1
, v2
, v
= 0;
1143 v1
= (ULONGEST
) value_as_long (arg1
);
1144 v2
= (ULONGEST
) v2_signed
;
1165 error (_("Division by zero"));
1169 v
= uinteger_pow (v1
, v2_signed
);
1176 error (_("Division by zero"));
1180 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1181 v1 mod 0 has a defined value, v1. */
1189 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1202 case BINOP_BITWISE_AND
:
1206 case BINOP_BITWISE_IOR
:
1210 case BINOP_BITWISE_XOR
:
1214 case BINOP_LOGICAL_AND
:
1218 case BINOP_LOGICAL_OR
:
1223 v
= v1
< v2
? v1
: v2
;
1227 v
= v1
> v2
? v1
: v2
;
1234 case BINOP_NOTEQUAL
:
1255 error (_("Invalid binary operation on numbers."));
1258 val
= allocate_value (result_type
);
1259 store_unsigned_integer (value_contents_raw (val
),
1260 TYPE_LENGTH (value_type (val
)),
1262 (get_type_arch (result_type
)),
1267 LONGEST v1
, v2
, v
= 0;
1269 v1
= value_as_long (arg1
);
1270 v2
= value_as_long (arg2
);
1291 error (_("Division by zero"));
1295 v
= integer_pow (v1
, v2
);
1302 error (_("Division by zero"));
1306 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1307 X mod 0 has a defined value, X. */
1315 /* Compute floor. */
1316 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1332 case BINOP_BITWISE_AND
:
1336 case BINOP_BITWISE_IOR
:
1340 case BINOP_BITWISE_XOR
:
1344 case BINOP_LOGICAL_AND
:
1348 case BINOP_LOGICAL_OR
:
1353 v
= v1
< v2
? v1
: v2
;
1357 v
= v1
> v2
? v1
: v2
;
1364 case BINOP_NOTEQUAL
:
1385 error (_("Invalid binary operation on numbers."));
1388 val
= allocate_value (result_type
);
1389 store_signed_integer (value_contents_raw (val
),
1390 TYPE_LENGTH (value_type (val
)),
1392 (get_type_arch (result_type
)),
1400 /* Performs a binary operation on two vector operands by calling scalar_binop
1401 for each pair of vector components. */
1403 static struct value
*
1404 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1406 struct value
*val
, *tmp
, *mark
;
1407 struct type
*type1
, *type2
, *eltype1
, *eltype2
, *result_type
;
1408 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1409 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1411 type1
= check_typedef (value_type (val1
));
1412 type2
= check_typedef (value_type (val2
));
1414 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1415 && TYPE_VECTOR (type1
)) ? 1 : 0;
1416 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1417 && TYPE_VECTOR (type2
)) ? 1 : 0;
1419 if (!t1_is_vec
|| !t2_is_vec
)
1420 error (_("Vector operations are only supported among vectors"));
1422 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1423 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1424 error (_("Could not determine the vector bounds"));
1426 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1427 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1428 elsize
= TYPE_LENGTH (eltype1
);
1430 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1431 || elsize
!= TYPE_LENGTH (eltype2
)
1432 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1433 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1434 error (_("Cannot perform operation on vectors with different types"));
1436 val
= allocate_value (type1
);
1437 mark
= value_mark ();
1438 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1440 tmp
= value_binop (value_subscript (val1
, i
),
1441 value_subscript (val2
, i
), op
);
1442 memcpy (value_contents_writeable (val
) + i
* elsize
,
1443 value_contents_all (tmp
),
1446 value_free_to_mark (mark
);
1451 /* Perform a binary operation on two operands. */
1454 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1457 struct type
*type1
= check_typedef (value_type (arg1
));
1458 struct type
*type2
= check_typedef (value_type (arg2
));
1459 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1460 && TYPE_VECTOR (type1
));
1461 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1462 && TYPE_VECTOR (type2
));
1464 if (!t1_is_vec
&& !t2_is_vec
)
1465 val
= scalar_binop (arg1
, arg2
, op
);
1466 else if (t1_is_vec
&& t2_is_vec
)
1467 val
= vector_binop (arg1
, arg2
, op
);
1470 /* Widen the scalar operand to a vector. */
1471 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1472 struct type
*t
= t1_is_vec
? type2
: type1
;
1474 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1475 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1476 && !is_integral_type (t
))
1477 error (_("Argument to operation not a number or boolean."));
1479 *v
= value_cast (t1_is_vec
? type1
: type2
, *v
);
1480 val
= vector_binop (arg1
, arg2
, op
);
1486 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1489 value_logical_not (struct value
*arg1
)
1495 arg1
= coerce_array (arg1
);
1496 type1
= check_typedef (value_type (arg1
));
1498 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1499 return 0 == value_as_double (arg1
);
1500 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1501 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1502 gdbarch_byte_order (get_type_arch (type1
)));
1504 len
= TYPE_LENGTH (type1
);
1505 p
= value_contents (arg1
);
1516 /* Perform a comparison on two string values (whose content are not
1517 necessarily null terminated) based on their length. */
1520 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1522 int len1
= TYPE_LENGTH (value_type (arg1
));
1523 int len2
= TYPE_LENGTH (value_type (arg2
));
1524 const gdb_byte
*s1
= value_contents (arg1
);
1525 const gdb_byte
*s2
= value_contents (arg2
);
1526 int i
, len
= len1
< len2
? len1
: len2
;
1528 for (i
= 0; i
< len
; i
++)
1532 else if (s1
[i
] > s2
[i
])
1540 else if (len1
> len2
)
1546 /* Simulate the C operator == by returning a 1
1547 iff ARG1 and ARG2 have equal contents. */
1550 value_equal (struct value
*arg1
, struct value
*arg2
)
1555 struct type
*type1
, *type2
;
1556 enum type_code code1
;
1557 enum type_code code2
;
1558 int is_int1
, is_int2
;
1560 arg1
= coerce_array (arg1
);
1561 arg2
= coerce_array (arg2
);
1563 type1
= check_typedef (value_type (arg1
));
1564 type2
= check_typedef (value_type (arg2
));
1565 code1
= TYPE_CODE (type1
);
1566 code2
= TYPE_CODE (type2
);
1567 is_int1
= is_integral_type (type1
);
1568 is_int2
= is_integral_type (type2
);
1570 if (is_int1
&& is_int2
)
1571 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1573 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1574 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1576 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1577 `long double' values are returned in static storage (m68k). */
1578 DOUBLEST d
= value_as_double (arg1
);
1580 return d
== value_as_double (arg2
);
1582 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1583 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1585 gdb_byte v1
[16], v2
[16];
1587 enum bfd_endian byte_order_v1
, byte_order_v2
;
1589 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1590 v2
, &len_v2
, &byte_order_v2
);
1592 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1593 v2
, len_v2
, byte_order_v2
) == 0;
1596 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1598 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1599 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1600 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1601 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1603 else if (code1
== code2
1604 && ((len
= (int) TYPE_LENGTH (type1
))
1605 == (int) TYPE_LENGTH (type2
)))
1607 p1
= value_contents (arg1
);
1608 p2
= value_contents (arg2
);
1616 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1618 return value_strcmp (arg1
, arg2
) == 0;
1622 error (_("Invalid type combination in equality test."));
1623 return 0; /* For lint -- never reached. */
1627 /* Compare values based on their raw contents. Useful for arrays since
1628 value_equal coerces them to pointers, thus comparing just the address
1629 of the array instead of its contents. */
1632 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1634 struct type
*type1
, *type2
;
1636 type1
= check_typedef (value_type (arg1
));
1637 type2
= check_typedef (value_type (arg2
));
1639 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1640 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1641 && memcmp (value_contents (arg1
), value_contents (arg2
),
1642 TYPE_LENGTH (type1
)) == 0);
1645 /* Simulate the C operator < by returning 1
1646 iff ARG1's contents are less than ARG2's. */
1649 value_less (struct value
*arg1
, struct value
*arg2
)
1651 enum type_code code1
;
1652 enum type_code code2
;
1653 struct type
*type1
, *type2
;
1654 int is_int1
, is_int2
;
1656 arg1
= coerce_array (arg1
);
1657 arg2
= coerce_array (arg2
);
1659 type1
= check_typedef (value_type (arg1
));
1660 type2
= check_typedef (value_type (arg2
));
1661 code1
= TYPE_CODE (type1
);
1662 code2
= TYPE_CODE (type2
);
1663 is_int1
= is_integral_type (type1
);
1664 is_int2
= is_integral_type (type2
);
1666 if (is_int1
&& is_int2
)
1667 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1669 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1670 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1672 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1673 `long double' values are returned in static storage (m68k). */
1674 DOUBLEST d
= value_as_double (arg1
);
1676 return d
< value_as_double (arg2
);
1678 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1679 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1681 gdb_byte v1
[16], v2
[16];
1683 enum bfd_endian byte_order_v1
, byte_order_v2
;
1685 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1686 v2
, &len_v2
, &byte_order_v2
);
1688 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1689 v2
, len_v2
, byte_order_v2
) == -1;
1691 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1692 return value_as_address (arg1
) < value_as_address (arg2
);
1694 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1696 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1697 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1698 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1699 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1700 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1701 return value_strcmp (arg1
, arg2
) < 0;
1704 error (_("Invalid type combination in ordering comparison."));
1709 /* The unary operators +, - and ~. They free the argument ARG1. */
1712 value_pos (struct value
*arg1
)
1716 arg1
= coerce_ref (arg1
);
1717 type
= check_typedef (value_type (arg1
));
1719 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1720 return value_from_double (type
, value_as_double (arg1
));
1721 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1722 return value_from_decfloat (type
, value_contents (arg1
));
1723 else if (is_integral_type (type
))
1725 return value_from_longest (type
, value_as_long (arg1
));
1727 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1729 struct value
*val
= allocate_value (type
);
1731 memcpy (value_contents_raw (val
), value_contents (arg1
),
1732 TYPE_LENGTH (type
));
1737 error (_("Argument to positive operation not a number."));
1738 return 0; /* For lint -- never reached. */
1743 value_neg (struct value
*arg1
)
1747 arg1
= coerce_ref (arg1
);
1748 type
= check_typedef (value_type (arg1
));
1750 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1752 struct value
*val
= allocate_value (type
);
1753 int len
= TYPE_LENGTH (type
);
1754 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1756 memcpy (decbytes
, value_contents (arg1
), len
);
1758 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1759 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1761 decbytes
[0] = decbytes
[0] | 0x80;
1763 memcpy (value_contents_raw (val
), decbytes
, len
);
1766 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1767 return value_from_double (type
, -value_as_double (arg1
));
1768 else if (is_integral_type (type
))
1770 return value_from_longest (type
, -value_as_long (arg1
));
1772 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1774 struct value
*tmp
, *val
= allocate_value (type
);
1775 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1777 LONGEST low_bound
, high_bound
;
1779 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1780 error (_("Could not determine the vector bounds"));
1782 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1784 tmp
= value_neg (value_subscript (arg1
, i
));
1785 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1786 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1792 error (_("Argument to negate operation not a number."));
1793 return 0; /* For lint -- never reached. */
1798 value_complement (struct value
*arg1
)
1803 arg1
= coerce_ref (arg1
);
1804 type
= check_typedef (value_type (arg1
));
1806 if (is_integral_type (type
))
1807 val
= value_from_longest (type
, ~value_as_long (arg1
));
1808 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1811 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1813 LONGEST low_bound
, high_bound
;
1815 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1816 error (_("Could not determine the vector bounds"));
1818 val
= allocate_value (type
);
1819 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1821 tmp
= value_complement (value_subscript (arg1
, i
));
1822 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1823 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1827 error (_("Argument to complement operation not an integer, boolean."));
1832 /* The INDEX'th bit of SET value whose value_type is TYPE,
1833 and whose value_contents is valaddr.
1834 Return -1 if out of range, -2 other error. */
1837 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1839 struct gdbarch
*gdbarch
= get_type_arch (type
);
1840 LONGEST low_bound
, high_bound
;
1843 struct type
*range
= TYPE_INDEX_TYPE (type
);
1845 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1847 if (index
< low_bound
|| index
> high_bound
)
1849 rel_index
= index
- low_bound
;
1850 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1851 gdbarch_byte_order (gdbarch
));
1852 rel_index
%= TARGET_CHAR_BIT
;
1853 if (gdbarch_bits_big_endian (gdbarch
))
1854 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1855 return (word
>> rel_index
) & 1;
1859 value_in (struct value
*element
, struct value
*set
)
1862 struct type
*settype
= check_typedef (value_type (set
));
1863 struct type
*eltype
= check_typedef (value_type (element
));
1865 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1866 eltype
= TYPE_TARGET_TYPE (eltype
);
1867 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1868 error (_("Second argument of 'IN' has wrong type"));
1869 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1870 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1871 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1872 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1873 error (_("First argument of 'IN' has wrong type"));
1874 member
= value_bit_index (settype
, value_contents (set
),
1875 value_as_long (element
));
1877 error (_("First argument of 'IN' not in range"));
1882 _initialize_valarith (void)
This page took 0.104164 seconds and 5 git commands to generate.