1 /* Perform arithmetic and other operations on values, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
32 /* Define whether or not the C operator '/' truncates towards zero for
33 differently signed operands (truncation direction is undefined in C). */
35 #ifndef TRUNCATION_TOWARDS_ZERO
36 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
39 void _initialize_valarith (void);
42 /* Given a pointer, return the size of its target.
43 If the pointer type is void *, then return 1.
44 If the target type is incomplete, then error out.
45 This isn't a general purpose function, but just a
46 helper for value_ptradd. */
49 find_size_for_pointer_math (struct type
*ptr_type
)
52 struct type
*ptr_target
;
54 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
55 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
57 sz
= TYPE_LENGTH (ptr_target
);
60 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
66 name
= TYPE_NAME (ptr_target
);
68 name
= TYPE_TAG_NAME (ptr_target
);
70 error (_("Cannot perform pointer math on incomplete types, "
71 "try casting to a known type, or void *."));
73 error (_("Cannot perform pointer math on incomplete type \"%s\", "
74 "try casting to a known type, or void *."), name
);
80 /* Given a pointer ARG1 and an integral value ARG2, return the
81 result of C-style pointer arithmetic ARG1 + ARG2. */
84 value_ptradd (struct value
*arg1
, LONGEST arg2
)
86 struct type
*valptrtype
;
90 arg1
= coerce_array (arg1
);
91 valptrtype
= check_typedef (value_type (arg1
));
92 sz
= find_size_for_pointer_math (valptrtype
);
94 result
= value_from_pointer (valptrtype
,
95 value_as_address (arg1
) + sz
* arg2
);
96 if (VALUE_LVAL (result
) != lval_internalvar
)
97 set_value_component_location (result
, arg1
);
101 /* Given two compatible pointer values ARG1 and ARG2, return the
102 result of C-style pointer arithmetic ARG1 - ARG2. */
105 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
107 struct type
*type1
, *type2
;
110 arg1
= coerce_array (arg1
);
111 arg2
= coerce_array (arg2
);
112 type1
= check_typedef (value_type (arg1
));
113 type2
= check_typedef (value_type (arg2
));
115 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
116 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
118 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
119 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
120 error (_("First argument of `-' is a pointer and "
121 "second argument is neither\n"
122 "an integer nor a pointer of the same type."));
124 sz
= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)));
127 warning (_("Type size unknown, assuming 1. "
128 "Try casting to a known type, or void *."));
132 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
135 /* Return the value of ARRAY[IDX].
137 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
138 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
140 See comments in value_coerce_array() for rationale for reason for
141 doing lower bounds adjustment here rather than there.
142 FIXME: Perhaps we should validate that the index is valid and if
143 verbosity is set, warn about invalid indices (but still use them). */
146 value_subscript (struct value
*array
, LONGEST index
)
148 int c_style
= current_language
->c_style_arrays
;
151 array
= coerce_ref (array
);
152 tarray
= check_typedef (value_type (array
));
154 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
155 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
157 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
158 LONGEST lowerbound
, upperbound
;
160 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
161 if (VALUE_LVAL (array
) != lval_memory
)
162 return value_subscripted_rvalue (array
, index
, lowerbound
);
166 if (index
>= lowerbound
&& index
<= upperbound
)
167 return value_subscripted_rvalue (array
, index
, lowerbound
);
168 /* Emit warning unless we have an array of unknown size.
169 An array of unknown size has lowerbound 0 and upperbound -1. */
171 warning (_("array or string index out of range"));
172 /* fall doing C stuff */
177 array
= value_coerce_array (array
);
181 return value_ind (value_ptradd (array
, index
));
183 error (_("not an array or string"));
186 /* Return the value of EXPR[IDX], expr an aggregate rvalue
187 (eg, a vector register). This routine used to promote floats
188 to doubles, but no longer does. */
191 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
193 struct type
*array_type
= check_typedef (value_type (array
));
194 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
195 unsigned int elt_size
= TYPE_LENGTH (elt_type
);
196 unsigned int elt_offs
= elt_size
* longest_to_int (index
- lowerbound
);
199 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
200 && elt_offs
>= TYPE_LENGTH (array_type
)))
201 error (_("no such vector element"));
203 if (VALUE_LVAL (array
) == lval_memory
&& value_lazy (array
))
204 v
= allocate_value_lazy (elt_type
);
207 v
= allocate_value (elt_type
);
208 value_contents_copy (v
, value_embedded_offset (v
),
209 array
, value_embedded_offset (array
) + elt_offs
,
213 set_value_component_location (v
, array
);
214 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
215 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
216 set_value_offset (v
, value_offset (array
) + elt_offs
);
221 /* Check to see if either argument is a structure, or a reference to
222 one. This is called so we know whether to go ahead with the normal
223 binop or look for a user defined function instead.
225 For now, we do not overload the `=' operator. */
228 binop_types_user_defined_p (enum exp_opcode op
,
229 struct type
*type1
, struct type
*type2
)
231 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
234 type1
= check_typedef (type1
);
235 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
236 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
238 type2
= check_typedef (type2
);
239 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
240 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
242 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
243 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
246 /* Check to see if either argument is a structure, or a reference to
247 one. This is called so we know whether to go ahead with the normal
248 binop or look for a user defined function instead.
250 For now, we do not overload the `=' operator. */
253 binop_user_defined_p (enum exp_opcode op
,
254 struct value
*arg1
, struct value
*arg2
)
256 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
259 /* Check to see if argument is a structure. This is called so
260 we know whether to go ahead with the normal unop or look for a
261 user defined function instead.
263 For now, we do not overload the `&' operator. */
266 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
272 type1
= check_typedef (value_type (arg1
));
273 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
274 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
275 return TYPE_CODE (type1
) == TYPE_CODE_STRUCT
;
278 /* Try to find an operator named OPERATOR which takes NARGS arguments
279 specified in ARGS. If the operator found is a static member operator
280 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
281 The search if performed through find_overload_match which will handle
282 member operators, non member operators, operators imported implicitly or
283 explicitly, and perform correct overload resolution in all of the above
284 situations or combinations thereof. */
286 static struct value
*
287 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *oper
,
288 int *static_memfuncp
, enum noside noside
)
291 struct symbol
*symp
= NULL
;
292 struct value
*valp
= NULL
;
294 find_overload_match (args
, nargs
, oper
, BOTH
/* could be method */,
296 NULL
/* pass NULL symbol since symbol is unknown */,
297 &valp
, &symp
, static_memfuncp
, 0, noside
);
304 /* This is a non member function and does not
305 expect a reference as its first argument
306 rather the explicit structure. */
307 args
[0] = value_ind (args
[0]);
308 return value_of_variable (symp
, 0);
311 error (_("Could not find %s."), oper
);
314 /* Lookup user defined operator NAME. Return a value representing the
315 function, otherwise return NULL. */
317 static struct value
*
318 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
319 int *static_memfuncp
, int nargs
, enum noside noside
)
321 struct value
*result
= NULL
;
323 if (current_language
->la_language
== language_cplus
)
325 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
,
329 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
335 /* We know either arg1 or arg2 is a structure, so try to find the right
336 user defined function. Create an argument vector that calls
337 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
338 binary operator which is legal for GNU C++).
340 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
341 is the opcode saying how to modify it. Otherwise, OTHEROP is
345 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
346 enum exp_opcode otherop
, enum noside noside
)
348 struct value
**argvec
;
353 arg1
= coerce_ref (arg1
);
354 arg2
= coerce_ref (arg2
);
356 /* now we know that what we have to do is construct our
357 arg vector and find the right function to call it with. */
359 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
360 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
362 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
363 argvec
[1] = value_addr (arg1
);
367 /* Make the right function name up. */
368 strcpy (tstr
, "operator__");
393 case BINOP_BITWISE_AND
:
396 case BINOP_BITWISE_IOR
:
399 case BINOP_BITWISE_XOR
:
402 case BINOP_LOGICAL_AND
:
405 case BINOP_LOGICAL_OR
:
417 case BINOP_ASSIGN_MODIFY
:
435 case BINOP_BITWISE_AND
:
438 case BINOP_BITWISE_IOR
:
441 case BINOP_BITWISE_XOR
:
444 case BINOP_MOD
: /* invalid */
446 error (_("Invalid binary operation specified."));
449 case BINOP_SUBSCRIPT
:
470 case BINOP_MOD
: /* invalid */
472 error (_("Invalid binary operation specified."));
475 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
476 &static_memfuncp
, 2, noside
);
482 argvec
[1] = argvec
[0];
485 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
487 struct type
*return_type
;
490 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
491 return value_zero (return_type
, VALUE_LVAL (arg1
));
494 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
496 /* Static xmethods are not supported yet. */
497 gdb_assert (static_memfuncp
== 0);
498 return call_xmethod (argvec
[0], 2, argvec
+ 1);
501 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
,
504 throw_error (NOT_FOUND_ERROR
,
505 _("member function %s not found"), tstr
);
507 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
511 /* We know that arg1 is a structure, so try to find a unary user
512 defined operator that matches the operator in question.
513 Create an argument vector that calls arg1.operator @ (arg1)
514 and return that value (where '@' is (almost) any unary operator which
515 is legal for GNU C++). */
518 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
520 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
521 struct value
**argvec
;
523 char tstr
[13], mangle_tstr
[13];
524 int static_memfuncp
, nargs
;
526 arg1
= coerce_ref (arg1
);
528 /* now we know that what we have to do is construct our
529 arg vector and find the right function to call it with. */
531 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
532 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
534 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
535 argvec
[1] = value_addr (arg1
);
540 /* Make the right function name up. */
541 strcpy (tstr
, "operator__");
543 strcpy (mangle_tstr
, "__");
546 case UNOP_PREINCREMENT
:
549 case UNOP_PREDECREMENT
:
552 case UNOP_POSTINCREMENT
:
554 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
558 case UNOP_POSTDECREMENT
:
560 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
564 case UNOP_LOGICAL_NOT
:
567 case UNOP_COMPLEMENT
:
583 error (_("Invalid unary operation specified."));
586 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
587 &static_memfuncp
, nargs
, noside
);
593 argvec
[1] = argvec
[0];
597 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
599 struct type
*return_type
;
602 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
603 return value_zero (return_type
, VALUE_LVAL (arg1
));
605 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
607 /* Static xmethods are not supported yet. */
608 gdb_assert (static_memfuncp
== 0);
609 return call_xmethod (argvec
[0], 1, argvec
+ 1);
612 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
614 throw_error (NOT_FOUND_ERROR
,
615 _("member function %s not found"), tstr
);
617 return 0; /* For lint -- never reached */
621 /* Concatenate two values with the following conditions:
623 (1) Both values must be either bitstring values or character string
624 values and the resulting value consists of the concatenation of
625 ARG1 followed by ARG2.
629 One value must be an integer value and the other value must be
630 either a bitstring value or character string value, which is
631 to be repeated by the number of times specified by the integer
635 (2) Boolean values are also allowed and are treated as bit string
638 (3) Character values are also allowed and are treated as character
639 string values of length 1. */
642 value_concat (struct value
*arg1
, struct value
*arg2
)
644 struct value
*inval1
;
645 struct value
*inval2
;
646 struct value
*outval
= NULL
;
647 int inval1len
, inval2len
;
651 struct type
*type1
= check_typedef (value_type (arg1
));
652 struct type
*type2
= check_typedef (value_type (arg2
));
653 struct type
*char_type
;
655 /* First figure out if we are dealing with two values to be concatenated
656 or a repeat count and a value to be repeated. INVAL1 is set to the
657 first of two concatenated values, or the repeat count. INVAL2 is set
658 to the second of the two concatenated values or the value to be
661 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
663 struct type
*tmp
= type1
;
676 /* Now process the input values. */
678 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
680 /* We have a repeat count. Validate the second value and then
681 construct a value repeated that many times. */
682 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
683 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
685 struct cleanup
*back_to
;
687 count
= longest_to_int (value_as_long (inval1
));
688 inval2len
= TYPE_LENGTH (type2
);
689 ptr
= (char *) xmalloc (count
* inval2len
);
690 back_to
= make_cleanup (xfree
, ptr
);
691 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
695 inchar
= (char) unpack_long (type2
,
696 value_contents (inval2
));
697 for (idx
= 0; idx
< count
; idx
++)
699 *(ptr
+ idx
) = inchar
;
704 char_type
= TYPE_TARGET_TYPE (type2
);
706 for (idx
= 0; idx
< count
; idx
++)
708 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
712 outval
= value_string (ptr
, count
* inval2len
, char_type
);
713 do_cleanups (back_to
);
715 else if (TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
717 error (_("unimplemented support for boolean repeats"));
721 error (_("can't repeat values of that type"));
724 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
725 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
727 struct cleanup
*back_to
;
729 /* We have two character strings to concatenate. */
730 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
731 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
733 error (_("Strings can only be concatenated with other strings."));
735 inval1len
= TYPE_LENGTH (type1
);
736 inval2len
= TYPE_LENGTH (type2
);
737 ptr
= (char *) xmalloc (inval1len
+ inval2len
);
738 back_to
= make_cleanup (xfree
, ptr
);
739 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
743 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
747 char_type
= TYPE_TARGET_TYPE (type1
);
749 memcpy (ptr
, value_contents (inval1
), inval1len
);
751 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
754 (char) unpack_long (type2
, value_contents (inval2
));
758 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
760 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
761 do_cleanups (back_to
);
763 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
765 /* We have two bitstrings to concatenate. */
766 if (TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
768 error (_("Booleans can only be concatenated "
769 "with other bitstrings or booleans."));
771 error (_("unimplemented support for boolean concatenation."));
775 /* We don't know how to concatenate these operands. */
776 error (_("illegal operands for concatenation."));
781 /* Integer exponentiation: V1**V2, where both arguments are
782 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
785 integer_pow (LONGEST v1
, LONGEST v2
)
790 error (_("Attempt to raise 0 to negative power."));
796 /* The Russian Peasant's Algorithm. */
812 /* Integer exponentiation: V1**V2, where both arguments are
813 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
816 uinteger_pow (ULONGEST v1
, LONGEST v2
)
821 error (_("Attempt to raise 0 to negative power."));
827 /* The Russian Peasant's Algorithm. */
843 /* Obtain decimal value of arguments for binary operation, converting from
844 other types if one of them is not decimal floating point. */
846 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
847 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
848 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
850 struct type
*type1
, *type2
;
852 type1
= check_typedef (value_type (arg1
));
853 type2
= check_typedef (value_type (arg2
));
855 /* At least one of the arguments must be of decimal float type. */
856 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
857 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
859 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
860 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
861 /* The DFP extension to the C language does not allow mixing of
862 * decimal float types with other float types in expressions
863 * (see WDTR 24732, page 12). */
864 error (_("Mixing decimal floating types with "
865 "other floating types is not allowed."));
867 /* Obtain decimal value of arg1, converting from other types
870 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
872 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
873 *len_x
= TYPE_LENGTH (type1
);
874 memcpy (x
, value_contents (arg1
), *len_x
);
876 else if (is_integral_type (type1
))
878 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
879 *len_x
= TYPE_LENGTH (type2
);
880 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
883 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
886 /* Obtain decimal value of arg2, converting from other types
889 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
891 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
892 *len_y
= TYPE_LENGTH (type2
);
893 memcpy (y
, value_contents (arg2
), *len_y
);
895 else if (is_integral_type (type2
))
897 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
898 *len_y
= TYPE_LENGTH (type1
);
899 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
902 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
906 /* Perform a binary operation on two operands which have reasonable
907 representations as integers or floats. This includes booleans,
908 characters, integers, or floats.
909 Does not support addition and subtraction on pointers;
910 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
912 static struct value
*
913 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
916 struct type
*type1
, *type2
, *result_type
;
918 arg1
= coerce_ref (arg1
);
919 arg2
= coerce_ref (arg2
);
921 type1
= check_typedef (value_type (arg1
));
922 type2
= check_typedef (value_type (arg2
));
924 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
925 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
926 && !is_integral_type (type1
))
927 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
928 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
929 && !is_integral_type (type2
)))
930 error (_("Argument to arithmetic operation not a number or boolean."));
932 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
933 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
935 int len_v1
, len_v2
, len_v
;
936 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
937 gdb_byte v1
[16], v2
[16];
940 /* If only one type is decimal float, use its type.
941 Otherwise use the bigger type. */
942 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
944 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
946 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
951 len_v
= TYPE_LENGTH (result_type
);
952 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
954 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
955 v2
, &len_v2
, &byte_order_v2
);
964 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
965 v2
, len_v2
, byte_order_v2
,
966 v
, len_v
, byte_order_v
);
970 error (_("Operation not valid for decimal floating point number."));
973 val
= value_from_decfloat (result_type
, v
);
975 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
976 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
978 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
979 in target format. real.c in GCC probably has the necessary
981 DOUBLEST v1
, v2
, v
= 0;
983 v1
= value_as_double (arg1
);
984 v2
= value_as_double (arg2
);
1008 error (_("Cannot perform exponentiation: %s"),
1009 safe_strerror (errno
));
1013 v
= v1
< v2
? v1
: v2
;
1017 v
= v1
> v2
? v1
: v2
;
1021 error (_("Integer-only operation on floating point number."));
1024 /* If only one type is float, use its type.
1025 Otherwise use the bigger type. */
1026 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1027 result_type
= type2
;
1028 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1029 result_type
= type1
;
1030 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1031 result_type
= type2
;
1033 result_type
= type1
;
1035 val
= allocate_value (result_type
);
1036 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1038 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1039 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1041 LONGEST v1
, v2
, v
= 0;
1043 v1
= value_as_long (arg1
);
1044 v2
= value_as_long (arg2
);
1048 case BINOP_BITWISE_AND
:
1052 case BINOP_BITWISE_IOR
:
1056 case BINOP_BITWISE_XOR
:
1064 case BINOP_NOTEQUAL
:
1069 error (_("Invalid operation on booleans."));
1072 result_type
= type1
;
1074 val
= allocate_value (result_type
);
1075 store_signed_integer (value_contents_raw (val
),
1076 TYPE_LENGTH (result_type
),
1077 gdbarch_byte_order (get_type_arch (result_type
)),
1081 /* Integral operations here. */
1083 /* Determine type length of the result, and if the operation should
1084 be done unsigned. For exponentiation and shift operators,
1085 use the length and type of the left operand. Otherwise,
1086 use the signedness of the operand with the greater length.
1087 If both operands are of equal length, use unsigned operation
1088 if one of the operands is unsigned. */
1089 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1090 result_type
= type1
;
1091 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1092 result_type
= type1
;
1093 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1094 result_type
= type2
;
1095 else if (TYPE_UNSIGNED (type1
))
1096 result_type
= type1
;
1097 else if (TYPE_UNSIGNED (type2
))
1098 result_type
= type2
;
1100 result_type
= type1
;
1102 if (TYPE_UNSIGNED (result_type
))
1104 LONGEST v2_signed
= value_as_long (arg2
);
1105 ULONGEST v1
, v2
, v
= 0;
1107 v1
= (ULONGEST
) value_as_long (arg1
);
1108 v2
= (ULONGEST
) v2_signed
;
1129 error (_("Division by zero"));
1133 v
= uinteger_pow (v1
, v2_signed
);
1140 error (_("Division by zero"));
1144 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1145 v1 mod 0 has a defined value, v1. */
1153 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1166 case BINOP_BITWISE_AND
:
1170 case BINOP_BITWISE_IOR
:
1174 case BINOP_BITWISE_XOR
:
1178 case BINOP_LOGICAL_AND
:
1182 case BINOP_LOGICAL_OR
:
1187 v
= v1
< v2
? v1
: v2
;
1191 v
= v1
> v2
? v1
: v2
;
1198 case BINOP_NOTEQUAL
:
1219 error (_("Invalid binary operation on numbers."));
1222 val
= allocate_value (result_type
);
1223 store_unsigned_integer (value_contents_raw (val
),
1224 TYPE_LENGTH (value_type (val
)),
1226 (get_type_arch (result_type
)),
1231 LONGEST v1
, v2
, v
= 0;
1233 v1
= value_as_long (arg1
);
1234 v2
= value_as_long (arg2
);
1255 error (_("Division by zero"));
1259 v
= integer_pow (v1
, v2
);
1266 error (_("Division by zero"));
1270 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1271 X mod 0 has a defined value, X. */
1279 /* Compute floor. */
1280 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1296 case BINOP_BITWISE_AND
:
1300 case BINOP_BITWISE_IOR
:
1304 case BINOP_BITWISE_XOR
:
1308 case BINOP_LOGICAL_AND
:
1312 case BINOP_LOGICAL_OR
:
1317 v
= v1
< v2
? v1
: v2
;
1321 v
= v1
> v2
? v1
: v2
;
1328 case BINOP_NOTEQUAL
:
1349 error (_("Invalid binary operation on numbers."));
1352 val
= allocate_value (result_type
);
1353 store_signed_integer (value_contents_raw (val
),
1354 TYPE_LENGTH (value_type (val
)),
1356 (get_type_arch (result_type
)),
1364 /* Widen a scalar value SCALAR_VALUE to vector type VECTOR_TYPE by
1365 replicating SCALAR_VALUE for each element of the vector. Only scalar
1366 types that can be cast to the type of one element of the vector are
1367 acceptable. The newly created vector value is returned upon success,
1368 otherwise an error is thrown. */
1371 value_vector_widen (struct value
*scalar_value
, struct type
*vector_type
)
1373 /* Widen the scalar to a vector. */
1374 struct type
*eltype
, *scalar_type
;
1375 struct value
*val
, *elval
;
1376 LONGEST low_bound
, high_bound
;
1379 CHECK_TYPEDEF (vector_type
);
1381 gdb_assert (TYPE_CODE (vector_type
) == TYPE_CODE_ARRAY
1382 && TYPE_VECTOR (vector_type
));
1384 if (!get_array_bounds (vector_type
, &low_bound
, &high_bound
))
1385 error (_("Could not determine the vector bounds"));
1387 eltype
= check_typedef (TYPE_TARGET_TYPE (vector_type
));
1388 elval
= value_cast (eltype
, scalar_value
);
1390 scalar_type
= check_typedef (value_type (scalar_value
));
1392 /* If we reduced the length of the scalar then check we didn't loose any
1394 if (TYPE_LENGTH (eltype
) < TYPE_LENGTH (scalar_type
)
1395 && !value_equal (elval
, scalar_value
))
1396 error (_("conversion of scalar to vector involves truncation"));
1398 val
= allocate_value (vector_type
);
1399 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1400 /* Duplicate the contents of elval into the destination vector. */
1401 memcpy (value_contents_writeable (val
) + (i
* TYPE_LENGTH (eltype
)),
1402 value_contents_all (elval
), TYPE_LENGTH (eltype
));
1407 /* Performs a binary operation on two vector operands by calling scalar_binop
1408 for each pair of vector components. */
1410 static struct value
*
1411 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1413 struct value
*val
, *tmp
, *mark
;
1414 struct type
*type1
, *type2
, *eltype1
, *eltype2
;
1415 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1416 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1418 type1
= check_typedef (value_type (val1
));
1419 type2
= check_typedef (value_type (val2
));
1421 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1422 && TYPE_VECTOR (type1
)) ? 1 : 0;
1423 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1424 && TYPE_VECTOR (type2
)) ? 1 : 0;
1426 if (!t1_is_vec
|| !t2_is_vec
)
1427 error (_("Vector operations are only supported among vectors"));
1429 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1430 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1431 error (_("Could not determine the vector bounds"));
1433 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1434 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1435 elsize
= TYPE_LENGTH (eltype1
);
1437 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1438 || elsize
!= TYPE_LENGTH (eltype2
)
1439 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1440 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1441 error (_("Cannot perform operation on vectors with different types"));
1443 val
= allocate_value (type1
);
1444 mark
= value_mark ();
1445 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1447 tmp
= value_binop (value_subscript (val1
, i
),
1448 value_subscript (val2
, i
), op
);
1449 memcpy (value_contents_writeable (val
) + i
* elsize
,
1450 value_contents_all (tmp
),
1453 value_free_to_mark (mark
);
1458 /* Perform a binary operation on two operands. */
1461 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1464 struct type
*type1
= check_typedef (value_type (arg1
));
1465 struct type
*type2
= check_typedef (value_type (arg2
));
1466 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1467 && TYPE_VECTOR (type1
));
1468 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1469 && TYPE_VECTOR (type2
));
1471 if (!t1_is_vec
&& !t2_is_vec
)
1472 val
= scalar_binop (arg1
, arg2
, op
);
1473 else if (t1_is_vec
&& t2_is_vec
)
1474 val
= vector_binop (arg1
, arg2
, op
);
1477 /* Widen the scalar operand to a vector. */
1478 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1479 struct type
*t
= t1_is_vec
? type2
: type1
;
1481 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1482 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1483 && !is_integral_type (t
))
1484 error (_("Argument to operation not a number or boolean."));
1486 /* Replicate the scalar value to make a vector value. */
1487 *v
= value_vector_widen (*v
, t1_is_vec
? type1
: type2
);
1489 val
= vector_binop (arg1
, arg2
, op
);
1495 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1498 value_logical_not (struct value
*arg1
)
1504 arg1
= coerce_array (arg1
);
1505 type1
= check_typedef (value_type (arg1
));
1507 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1508 return 0 == value_as_double (arg1
);
1509 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1510 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1511 gdbarch_byte_order (get_type_arch (type1
)));
1513 len
= TYPE_LENGTH (type1
);
1514 p
= value_contents (arg1
);
1525 /* Perform a comparison on two string values (whose content are not
1526 necessarily null terminated) based on their length. */
1529 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1531 int len1
= TYPE_LENGTH (value_type (arg1
));
1532 int len2
= TYPE_LENGTH (value_type (arg2
));
1533 const gdb_byte
*s1
= value_contents (arg1
);
1534 const gdb_byte
*s2
= value_contents (arg2
);
1535 int i
, len
= len1
< len2
? len1
: len2
;
1537 for (i
= 0; i
< len
; i
++)
1541 else if (s1
[i
] > s2
[i
])
1549 else if (len1
> len2
)
1555 /* Simulate the C operator == by returning a 1
1556 iff ARG1 and ARG2 have equal contents. */
1559 value_equal (struct value
*arg1
, struct value
*arg2
)
1564 struct type
*type1
, *type2
;
1565 enum type_code code1
;
1566 enum type_code code2
;
1567 int is_int1
, is_int2
;
1569 arg1
= coerce_array (arg1
);
1570 arg2
= coerce_array (arg2
);
1572 type1
= check_typedef (value_type (arg1
));
1573 type2
= check_typedef (value_type (arg2
));
1574 code1
= TYPE_CODE (type1
);
1575 code2
= TYPE_CODE (type2
);
1576 is_int1
= is_integral_type (type1
);
1577 is_int2
= is_integral_type (type2
);
1579 if (is_int1
&& is_int2
)
1580 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1582 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1583 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1585 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1586 `long double' values are returned in static storage (m68k). */
1587 DOUBLEST d
= value_as_double (arg1
);
1589 return d
== value_as_double (arg2
);
1591 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1592 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1594 gdb_byte v1
[16], v2
[16];
1596 enum bfd_endian byte_order_v1
, byte_order_v2
;
1598 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1599 v2
, &len_v2
, &byte_order_v2
);
1601 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1602 v2
, len_v2
, byte_order_v2
) == 0;
1605 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1607 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1608 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1609 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1610 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1612 else if (code1
== code2
1613 && ((len
= (int) TYPE_LENGTH (type1
))
1614 == (int) TYPE_LENGTH (type2
)))
1616 p1
= value_contents (arg1
);
1617 p2
= value_contents (arg2
);
1625 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1627 return value_strcmp (arg1
, arg2
) == 0;
1631 error (_("Invalid type combination in equality test."));
1632 return 0; /* For lint -- never reached. */
1636 /* Compare values based on their raw contents. Useful for arrays since
1637 value_equal coerces them to pointers, thus comparing just the address
1638 of the array instead of its contents. */
1641 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1643 struct type
*type1
, *type2
;
1645 type1
= check_typedef (value_type (arg1
));
1646 type2
= check_typedef (value_type (arg2
));
1648 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1649 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1650 && memcmp (value_contents (arg1
), value_contents (arg2
),
1651 TYPE_LENGTH (type1
)) == 0);
1654 /* Simulate the C operator < by returning 1
1655 iff ARG1's contents are less than ARG2's. */
1658 value_less (struct value
*arg1
, struct value
*arg2
)
1660 enum type_code code1
;
1661 enum type_code code2
;
1662 struct type
*type1
, *type2
;
1663 int is_int1
, is_int2
;
1665 arg1
= coerce_array (arg1
);
1666 arg2
= coerce_array (arg2
);
1668 type1
= check_typedef (value_type (arg1
));
1669 type2
= check_typedef (value_type (arg2
));
1670 code1
= TYPE_CODE (type1
);
1671 code2
= TYPE_CODE (type2
);
1672 is_int1
= is_integral_type (type1
);
1673 is_int2
= is_integral_type (type2
);
1675 if (is_int1
&& is_int2
)
1676 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1678 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1679 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1681 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1682 `long double' values are returned in static storage (m68k). */
1683 DOUBLEST d
= value_as_double (arg1
);
1685 return d
< value_as_double (arg2
);
1687 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1688 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1690 gdb_byte v1
[16], v2
[16];
1692 enum bfd_endian byte_order_v1
, byte_order_v2
;
1694 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1695 v2
, &len_v2
, &byte_order_v2
);
1697 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1698 v2
, len_v2
, byte_order_v2
) == -1;
1700 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1701 return value_as_address (arg1
) < value_as_address (arg2
);
1703 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1705 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1706 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1707 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1708 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1709 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1710 return value_strcmp (arg1
, arg2
) < 0;
1713 error (_("Invalid type combination in ordering comparison."));
1718 /* The unary operators +, - and ~. They free the argument ARG1. */
1721 value_pos (struct value
*arg1
)
1725 arg1
= coerce_ref (arg1
);
1726 type
= check_typedef (value_type (arg1
));
1728 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1729 return value_from_double (type
, value_as_double (arg1
));
1730 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1731 return value_from_decfloat (type
, value_contents (arg1
));
1732 else if (is_integral_type (type
))
1734 return value_from_longest (type
, value_as_long (arg1
));
1736 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1738 struct value
*val
= allocate_value (type
);
1740 memcpy (value_contents_raw (val
), value_contents (arg1
),
1741 TYPE_LENGTH (type
));
1746 error (_("Argument to positive operation not a number."));
1747 return 0; /* For lint -- never reached. */
1752 value_neg (struct value
*arg1
)
1756 arg1
= coerce_ref (arg1
);
1757 type
= check_typedef (value_type (arg1
));
1759 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1761 struct value
*val
= allocate_value (type
);
1762 int len
= TYPE_LENGTH (type
);
1763 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1765 memcpy (decbytes
, value_contents (arg1
), len
);
1767 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1768 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1770 decbytes
[0] = decbytes
[0] | 0x80;
1772 memcpy (value_contents_raw (val
), decbytes
, len
);
1775 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1776 return value_from_double (type
, -value_as_double (arg1
));
1777 else if (is_integral_type (type
))
1779 return value_from_longest (type
, -value_as_long (arg1
));
1781 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1783 struct value
*tmp
, *val
= allocate_value (type
);
1784 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1786 LONGEST low_bound
, high_bound
;
1788 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1789 error (_("Could not determine the vector bounds"));
1791 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1793 tmp
= value_neg (value_subscript (arg1
, i
));
1794 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1795 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1801 error (_("Argument to negate operation not a number."));
1802 return 0; /* For lint -- never reached. */
1807 value_complement (struct value
*arg1
)
1812 arg1
= coerce_ref (arg1
);
1813 type
= check_typedef (value_type (arg1
));
1815 if (is_integral_type (type
))
1816 val
= value_from_longest (type
, ~value_as_long (arg1
));
1817 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1820 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1822 LONGEST low_bound
, high_bound
;
1824 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1825 error (_("Could not determine the vector bounds"));
1827 val
= allocate_value (type
);
1828 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1830 tmp
= value_complement (value_subscript (arg1
, i
));
1831 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1832 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1836 error (_("Argument to complement operation not an integer, boolean."));
1841 /* The INDEX'th bit of SET value whose value_type is TYPE,
1842 and whose value_contents is valaddr.
1843 Return -1 if out of range, -2 other error. */
1846 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1848 struct gdbarch
*gdbarch
= get_type_arch (type
);
1849 LONGEST low_bound
, high_bound
;
1852 struct type
*range
= TYPE_INDEX_TYPE (type
);
1854 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1856 if (index
< low_bound
|| index
> high_bound
)
1858 rel_index
= index
- low_bound
;
1859 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1860 gdbarch_byte_order (gdbarch
));
1861 rel_index
%= TARGET_CHAR_BIT
;
1862 if (gdbarch_bits_big_endian (gdbarch
))
1863 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1864 return (word
>> rel_index
) & 1;
1868 value_in (struct value
*element
, struct value
*set
)
1871 struct type
*settype
= check_typedef (value_type (set
));
1872 struct type
*eltype
= check_typedef (value_type (element
));
1874 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1875 eltype
= TYPE_TARGET_TYPE (eltype
);
1876 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1877 error (_("Second argument of 'IN' has wrong type"));
1878 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1879 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1880 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1881 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1882 error (_("First argument of 'IN' has wrong type"));
1883 member
= value_bit_index (settype
, value_contents (set
),
1884 value_as_long (element
));
1886 error (_("First argument of 'IN' not in range"));
1891 _initialize_valarith (void)
This page took 0.066947 seconds and 4 git commands to generate.