1 /* Perform arithmetic and other operations on values, for GDB.
3 Copyright (C) 1986-2017 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"
29 #include "target-float.h"
33 /* Define whether or not the C operator '/' truncates towards zero for
34 differently signed operands (truncation direction is undefined in C). */
36 #ifndef TRUNCATION_TOWARDS_ZERO
37 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
40 /* Given a pointer, return the size of its target.
41 If the pointer type is void *, then return 1.
42 If the target type is incomplete, then error out.
43 This isn't a general purpose function, but just a
44 helper for value_ptradd. */
47 find_size_for_pointer_math (struct type
*ptr_type
)
50 struct type
*ptr_target
;
52 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
53 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
55 sz
= type_length_units (ptr_target
);
58 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
64 name
= TYPE_NAME (ptr_target
);
66 name
= TYPE_TAG_NAME (ptr_target
);
68 error (_("Cannot perform pointer math on incomplete types, "
69 "try casting to a known type, or void *."));
71 error (_("Cannot perform pointer math on incomplete type \"%s\", "
72 "try casting to a known type, or void *."), name
);
78 /* Given a pointer ARG1 and an integral value ARG2, return the
79 result of C-style pointer arithmetic ARG1 + ARG2. */
82 value_ptradd (struct value
*arg1
, LONGEST arg2
)
84 struct type
*valptrtype
;
88 arg1
= coerce_array (arg1
);
89 valptrtype
= check_typedef (value_type (arg1
));
90 sz
= find_size_for_pointer_math (valptrtype
);
92 result
= value_from_pointer (valptrtype
,
93 value_as_address (arg1
) + sz
* arg2
);
94 if (VALUE_LVAL (result
) != lval_internalvar
)
95 set_value_component_location (result
, arg1
);
99 /* Given two compatible pointer values ARG1 and ARG2, return the
100 result of C-style pointer arithmetic ARG1 - ARG2. */
103 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
105 struct type
*type1
, *type2
;
108 arg1
= coerce_array (arg1
);
109 arg2
= coerce_array (arg2
);
110 type1
= check_typedef (value_type (arg1
));
111 type2
= check_typedef (value_type (arg2
));
113 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
114 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
116 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
117 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
118 error (_("First argument of `-' is a pointer and "
119 "second argument is neither\n"
120 "an integer nor a pointer of the same type."));
122 sz
= type_length_units (check_typedef (TYPE_TARGET_TYPE (type1
)));
125 warning (_("Type size unknown, assuming 1. "
126 "Try casting to a known type, or void *."));
130 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
133 /* Return the value of ARRAY[IDX].
135 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
136 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
138 See comments in value_coerce_array() for rationale for reason for
139 doing lower bounds adjustment here rather than there.
140 FIXME: Perhaps we should validate that the index is valid and if
141 verbosity is set, warn about invalid indices (but still use them). */
144 value_subscript (struct value
*array
, LONGEST index
)
146 int c_style
= current_language
->c_style_arrays
;
149 array
= coerce_ref (array
);
150 tarray
= check_typedef (value_type (array
));
152 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
153 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
155 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
156 LONGEST lowerbound
, upperbound
;
158 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
159 if (VALUE_LVAL (array
) != lval_memory
)
160 return value_subscripted_rvalue (array
, index
, lowerbound
);
164 if (index
>= lowerbound
&& index
<= upperbound
)
165 return value_subscripted_rvalue (array
, index
, lowerbound
);
166 /* Emit warning unless we have an array of unknown size.
167 An array of unknown size has lowerbound 0 and upperbound -1. */
169 warning (_("array or string index out of range"));
170 /* fall doing C stuff */
175 array
= value_coerce_array (array
);
179 return value_ind (value_ptradd (array
, index
));
181 error (_("not an array or string"));
184 /* Return the value of EXPR[IDX], expr an aggregate rvalue
185 (eg, a vector register). This routine used to promote floats
186 to doubles, but no longer does. */
189 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
191 struct type
*array_type
= check_typedef (value_type (array
));
192 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
193 ULONGEST elt_size
= type_length_units (elt_type
);
194 ULONGEST elt_offs
= elt_size
* (index
- lowerbound
);
196 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
197 && elt_offs
>= type_length_units (array_type
)))
199 if (type_not_associated (array_type
))
200 error (_("no such vector element (vector not associated)"));
201 else if (type_not_allocated (array_type
))
202 error (_("no such vector element (vector not allocated)"));
204 error (_("no such vector element"));
207 if (is_dynamic_type (elt_type
))
211 address
= value_address (array
) + elt_offs
;
212 elt_type
= resolve_dynamic_type (elt_type
, NULL
, address
);
215 return value_from_component (array
, elt_type
, elt_offs
);
219 /* Check to see if either argument is a structure, or a reference to
220 one. This is called so we know whether to go ahead with the normal
221 binop or look for a user defined function instead.
223 For now, we do not overload the `=' operator. */
226 binop_types_user_defined_p (enum exp_opcode op
,
227 struct type
*type1
, struct type
*type2
)
229 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
232 type1
= check_typedef (type1
);
233 if (TYPE_IS_REFERENCE (type1
))
234 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
236 type2
= check_typedef (type2
);
237 if (TYPE_IS_REFERENCE (type2
))
238 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
240 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
241 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
244 /* Check to see if either argument is a structure, or a reference to
245 one. This is called so we know whether to go ahead with the normal
246 binop or look for a user defined function instead.
248 For now, we do not overload the `=' operator. */
251 binop_user_defined_p (enum exp_opcode op
,
252 struct value
*arg1
, struct value
*arg2
)
254 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
257 /* Check to see if argument is a structure. This is called so
258 we know whether to go ahead with the normal unop or look for a
259 user defined function instead.
261 For now, we do not overload the `&' operator. */
264 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
270 type1
= check_typedef (value_type (arg1
));
271 if (TYPE_IS_REFERENCE (type1
))
272 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
273 return TYPE_CODE (type1
) == TYPE_CODE_STRUCT
;
276 /* Try to find an operator named OPERATOR which takes NARGS arguments
277 specified in ARGS. If the operator found is a static member operator
278 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
279 The search if performed through find_overload_match which will handle
280 member operators, non member operators, operators imported implicitly or
281 explicitly, and perform correct overload resolution in all of the above
282 situations or combinations thereof. */
284 static struct value
*
285 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *oper
,
286 int *static_memfuncp
, enum noside noside
)
289 struct symbol
*symp
= NULL
;
290 struct value
*valp
= NULL
;
292 find_overload_match (args
, nargs
, oper
, BOTH
/* could be method */,
294 NULL
/* pass NULL symbol since symbol is unknown */,
295 &valp
, &symp
, static_memfuncp
, 0, noside
);
302 /* This is a non member function and does not
303 expect a reference as its first argument
304 rather the explicit structure. */
305 args
[0] = value_ind (args
[0]);
306 return value_of_variable (symp
, 0);
309 error (_("Could not find %s."), oper
);
312 /* Lookup user defined operator NAME. Return a value representing the
313 function, otherwise return NULL. */
315 static struct value
*
316 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
317 int *static_memfuncp
, int nargs
, enum noside noside
)
319 struct value
*result
= NULL
;
321 if (current_language
->la_language
== language_cplus
)
323 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
,
327 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
333 /* We know either arg1 or arg2 is a structure, so try to find the right
334 user defined function. Create an argument vector that calls
335 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
336 binary operator which is legal for GNU C++).
338 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
339 is the opcode saying how to modify it. Otherwise, OTHEROP is
343 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
344 enum exp_opcode otherop
, enum noside noside
)
346 struct value
**argvec
;
351 arg1
= coerce_ref (arg1
);
352 arg2
= coerce_ref (arg2
);
354 /* now we know that what we have to do is construct our
355 arg vector and find the right function to call it with. */
357 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
358 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
360 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
361 argvec
[1] = value_addr (arg1
);
365 /* Make the right function name up. */
366 strcpy (tstr
, "operator__");
391 case BINOP_BITWISE_AND
:
394 case BINOP_BITWISE_IOR
:
397 case BINOP_BITWISE_XOR
:
400 case BINOP_LOGICAL_AND
:
403 case BINOP_LOGICAL_OR
:
415 case BINOP_ASSIGN_MODIFY
:
433 case BINOP_BITWISE_AND
:
436 case BINOP_BITWISE_IOR
:
439 case BINOP_BITWISE_XOR
:
442 case BINOP_MOD
: /* invalid */
444 error (_("Invalid binary operation specified."));
447 case BINOP_SUBSCRIPT
:
468 case BINOP_MOD
: /* invalid */
470 error (_("Invalid binary operation specified."));
473 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
474 &static_memfuncp
, 2, noside
);
480 argvec
[1] = argvec
[0];
483 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
485 /* Static xmethods are not supported yet. */
486 gdb_assert (static_memfuncp
== 0);
487 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
489 struct type
*return_type
490 = result_type_of_xmethod (argvec
[0], 2, argvec
+ 1);
492 if (return_type
== NULL
)
493 error (_("Xmethod is missing return type."));
494 return value_zero (return_type
, VALUE_LVAL (arg1
));
496 return call_xmethod (argvec
[0], 2, argvec
+ 1);
498 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
500 struct type
*return_type
;
503 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
504 return value_zero (return_type
, VALUE_LVAL (arg1
));
506 return call_function_by_hand (argvec
[0], NULL
, 2 - static_memfuncp
,
509 throw_error (NOT_FOUND_ERROR
,
510 _("member function %s not found"), tstr
);
512 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
516 /* We know that arg1 is a structure, so try to find a unary user
517 defined operator that matches the operator in question.
518 Create an argument vector that calls arg1.operator @ (arg1)
519 and return that value (where '@' is (almost) any unary operator which
520 is legal for GNU C++). */
523 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
525 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
526 struct value
**argvec
;
528 char tstr
[13], mangle_tstr
[13];
529 int static_memfuncp
, nargs
;
531 arg1
= coerce_ref (arg1
);
533 /* now we know that what we have to do is construct our
534 arg vector and find the right function to call it with. */
536 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
537 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
539 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
540 argvec
[1] = value_addr (arg1
);
545 /* Make the right function name up. */
546 strcpy (tstr
, "operator__");
548 strcpy (mangle_tstr
, "__");
551 case UNOP_PREINCREMENT
:
554 case UNOP_PREDECREMENT
:
557 case UNOP_POSTINCREMENT
:
559 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
563 case UNOP_POSTDECREMENT
:
565 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
569 case UNOP_LOGICAL_NOT
:
572 case UNOP_COMPLEMENT
:
588 error (_("Invalid unary operation specified."));
591 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
592 &static_memfuncp
, nargs
, noside
);
598 argvec
[1] = argvec
[0];
602 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
604 /* Static xmethods are not supported yet. */
605 gdb_assert (static_memfuncp
== 0);
606 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
608 struct type
*return_type
609 = result_type_of_xmethod (argvec
[0], 1, argvec
+ 1);
611 if (return_type
== NULL
)
612 error (_("Xmethod is missing return type."));
613 return value_zero (return_type
, VALUE_LVAL (arg1
));
615 return call_xmethod (argvec
[0], 1, argvec
+ 1);
617 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
619 struct type
*return_type
;
622 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
623 return value_zero (return_type
, VALUE_LVAL (arg1
));
625 return call_function_by_hand (argvec
[0], NULL
, nargs
, argvec
+ 1);
627 throw_error (NOT_FOUND_ERROR
,
628 _("member function %s not found"), tstr
);
630 return 0; /* For lint -- never reached */
634 /* Concatenate two values with the following conditions:
636 (1) Both values must be either bitstring values or character string
637 values and the resulting value consists of the concatenation of
638 ARG1 followed by ARG2.
642 One value must be an integer value and the other value must be
643 either a bitstring value or character string value, which is
644 to be repeated by the number of times specified by the integer
648 (2) Boolean values are also allowed and are treated as bit string
651 (3) Character values are also allowed and are treated as character
652 string values of length 1. */
655 value_concat (struct value
*arg1
, struct value
*arg2
)
657 struct value
*inval1
;
658 struct value
*inval2
;
659 struct value
*outval
= NULL
;
660 int inval1len
, inval2len
;
664 struct type
*type1
= check_typedef (value_type (arg1
));
665 struct type
*type2
= check_typedef (value_type (arg2
));
666 struct type
*char_type
;
668 /* First figure out if we are dealing with two values to be concatenated
669 or a repeat count and a value to be repeated. INVAL1 is set to the
670 first of two concatenated values, or the repeat count. INVAL2 is set
671 to the second of the two concatenated values or the value to be
674 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
676 struct type
*tmp
= type1
;
689 /* Now process the input values. */
691 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
693 /* We have a repeat count. Validate the second value and then
694 construct a value repeated that many times. */
695 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
696 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
698 count
= longest_to_int (value_as_long (inval1
));
699 inval2len
= TYPE_LENGTH (type2
);
700 std::vector
<char> ptr (count
* inval2len
);
701 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
705 inchar
= (char) unpack_long (type2
,
706 value_contents (inval2
));
707 for (idx
= 0; idx
< count
; idx
++)
714 char_type
= TYPE_TARGET_TYPE (type2
);
716 for (idx
= 0; idx
< count
; idx
++)
718 memcpy (&ptr
[idx
* inval2len
], value_contents (inval2
),
722 outval
= value_string (ptr
.data (), count
* inval2len
, char_type
);
724 else if (TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
726 error (_("unimplemented support for boolean repeats"));
730 error (_("can't repeat values of that type"));
733 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
734 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
736 /* We have two character strings to concatenate. */
737 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
738 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
740 error (_("Strings can only be concatenated with other strings."));
742 inval1len
= TYPE_LENGTH (type1
);
743 inval2len
= TYPE_LENGTH (type2
);
744 std::vector
<char> ptr (inval1len
+ inval2len
);
745 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
749 ptr
[0] = (char) unpack_long (type1
, value_contents (inval1
));
753 char_type
= TYPE_TARGET_TYPE (type1
);
755 memcpy (ptr
.data (), value_contents (inval1
), inval1len
);
757 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
760 (char) unpack_long (type2
, value_contents (inval2
));
764 memcpy (&ptr
[inval1len
], value_contents (inval2
), inval2len
);
766 outval
= value_string (ptr
.data (), inval1len
+ inval2len
, char_type
);
768 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
770 /* We have two bitstrings to concatenate. */
771 if (TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
773 error (_("Booleans can only be concatenated "
774 "with other bitstrings or booleans."));
776 error (_("unimplemented support for boolean concatenation."));
780 /* We don't know how to concatenate these operands. */
781 error (_("illegal operands for concatenation."));
786 /* Integer exponentiation: V1**V2, where both arguments are
787 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
790 integer_pow (LONGEST v1
, LONGEST v2
)
795 error (_("Attempt to raise 0 to negative power."));
801 /* The Russian Peasant's Algorithm. */
817 /* Integer exponentiation: V1**V2, where both arguments are
818 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
821 uinteger_pow (ULONGEST v1
, LONGEST v2
)
826 error (_("Attempt to raise 0 to negative power."));
832 /* The Russian Peasant's Algorithm. */
848 /* Obtain decimal value of arguments for binary operation, converting from
849 other types if one of them is not decimal floating point. */
851 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
852 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
853 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
855 struct type
*type1
, *type2
;
857 type1
= check_typedef (value_type (arg1
));
858 type2
= check_typedef (value_type (arg2
));
860 /* At least one of the arguments must be of decimal float type. */
861 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
862 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
864 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
865 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
866 /* The DFP extension to the C language does not allow mixing of
867 * decimal float types with other float types in expressions
868 * (see WDTR 24732, page 12). */
869 error (_("Mixing decimal floating types with "
870 "other floating types is not allowed."));
872 /* Obtain decimal value of arg1, converting from other types
875 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
877 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
878 *len_x
= TYPE_LENGTH (type1
);
879 memcpy (x
, value_contents (arg1
), *len_x
);
881 else if (is_integral_type (type1
))
883 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
884 *len_x
= TYPE_LENGTH (type2
);
885 if (TYPE_UNSIGNED (type1
))
886 decimal_from_ulongest (value_as_long (arg1
), x
, *len_x
, *byte_order_x
);
888 decimal_from_longest (value_as_long (arg1
), x
, *len_x
, *byte_order_x
);
891 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
894 /* Obtain decimal value of arg2, converting from other types
897 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
899 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
900 *len_y
= TYPE_LENGTH (type2
);
901 memcpy (y
, value_contents (arg2
), *len_y
);
903 else if (is_integral_type (type2
))
905 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
906 *len_y
= TYPE_LENGTH (type1
);
907 if (TYPE_UNSIGNED (type2
))
908 decimal_from_ulongest (value_as_long (arg2
), y
, *len_y
, *byte_order_y
);
910 decimal_from_longest (value_as_long (arg2
), y
, *len_y
, *byte_order_y
);
913 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
917 /* Perform a binary operation on two operands which have reasonable
918 representations as integers or floats. This includes booleans,
919 characters, integers, or floats.
920 Does not support addition and subtraction on pointers;
921 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
923 static struct value
*
924 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
927 struct type
*type1
, *type2
, *result_type
;
929 arg1
= coerce_ref (arg1
);
930 arg2
= coerce_ref (arg2
);
932 type1
= check_typedef (value_type (arg1
));
933 type2
= check_typedef (value_type (arg2
));
935 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
936 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
937 && !is_integral_type (type1
))
938 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
939 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
940 && !is_integral_type (type2
)))
941 error (_("Argument to arithmetic operation not a number or boolean."));
943 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
944 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
946 int len_v1
, len_v2
, len_v
;
947 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
948 gdb_byte v1
[16], v2
[16];
951 /* If only one type is decimal float, use its type.
952 Otherwise use the bigger type. */
953 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
955 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
957 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
962 len_v
= TYPE_LENGTH (result_type
);
963 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
965 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
966 v2
, &len_v2
, &byte_order_v2
);
975 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
976 v2
, len_v2
, byte_order_v2
,
977 v
, len_v
, byte_order_v
);
981 error (_("Operation not valid for decimal floating point number."));
984 val
= value_from_decfloat (result_type
, v
);
986 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
987 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
989 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
990 in target format. real.c in GCC probably has the necessary
992 DOUBLEST v1
, v2
, v
= 0;
994 v1
= value_as_double (arg1
);
995 v2
= value_as_double (arg2
);
1019 error (_("Cannot perform exponentiation: %s"),
1020 safe_strerror (errno
));
1024 v
= v1
< v2
? v1
: v2
;
1028 v
= v1
> v2
? v1
: v2
;
1032 error (_("Integer-only operation on floating point number."));
1035 /* If only one type is float, use its type.
1036 Otherwise use the bigger type. */
1037 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1038 result_type
= type2
;
1039 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1040 result_type
= type1
;
1041 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1042 result_type
= type2
;
1044 result_type
= type1
;
1046 val
= allocate_value (result_type
);
1047 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1049 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1050 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1052 LONGEST v1
, v2
, v
= 0;
1054 v1
= value_as_long (arg1
);
1055 v2
= value_as_long (arg2
);
1059 case BINOP_BITWISE_AND
:
1063 case BINOP_BITWISE_IOR
:
1067 case BINOP_BITWISE_XOR
:
1075 case BINOP_NOTEQUAL
:
1080 error (_("Invalid operation on booleans."));
1083 result_type
= type1
;
1085 val
= allocate_value (result_type
);
1086 store_signed_integer (value_contents_raw (val
),
1087 TYPE_LENGTH (result_type
),
1088 gdbarch_byte_order (get_type_arch (result_type
)),
1092 /* Integral operations here. */
1094 /* Determine type length of the result, and if the operation should
1095 be done unsigned. For exponentiation and shift operators,
1096 use the length and type of the left operand. Otherwise,
1097 use the signedness of the operand with the greater length.
1098 If both operands are of equal length, use unsigned operation
1099 if one of the operands is unsigned. */
1100 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1101 result_type
= type1
;
1102 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1103 result_type
= type1
;
1104 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1105 result_type
= type2
;
1106 else if (TYPE_UNSIGNED (type1
))
1107 result_type
= type1
;
1108 else if (TYPE_UNSIGNED (type2
))
1109 result_type
= type2
;
1111 result_type
= type1
;
1113 if (TYPE_UNSIGNED (result_type
))
1115 LONGEST v2_signed
= value_as_long (arg2
);
1116 ULONGEST v1
, v2
, v
= 0;
1118 v1
= (ULONGEST
) value_as_long (arg1
);
1119 v2
= (ULONGEST
) v2_signed
;
1140 error (_("Division by zero"));
1144 v
= uinteger_pow (v1
, v2_signed
);
1151 error (_("Division by zero"));
1155 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1156 v1 mod 0 has a defined value, v1. */
1164 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1177 case BINOP_BITWISE_AND
:
1181 case BINOP_BITWISE_IOR
:
1185 case BINOP_BITWISE_XOR
:
1189 case BINOP_LOGICAL_AND
:
1193 case BINOP_LOGICAL_OR
:
1198 v
= v1
< v2
? v1
: v2
;
1202 v
= v1
> v2
? v1
: v2
;
1209 case BINOP_NOTEQUAL
:
1230 error (_("Invalid binary operation on numbers."));
1233 val
= allocate_value (result_type
);
1234 store_unsigned_integer (value_contents_raw (val
),
1235 TYPE_LENGTH (value_type (val
)),
1237 (get_type_arch (result_type
)),
1242 LONGEST v1
, v2
, v
= 0;
1244 v1
= value_as_long (arg1
);
1245 v2
= value_as_long (arg2
);
1266 error (_("Division by zero"));
1270 v
= integer_pow (v1
, v2
);
1277 error (_("Division by zero"));
1281 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1282 X mod 0 has a defined value, X. */
1290 /* Compute floor. */
1291 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1307 case BINOP_BITWISE_AND
:
1311 case BINOP_BITWISE_IOR
:
1315 case BINOP_BITWISE_XOR
:
1319 case BINOP_LOGICAL_AND
:
1323 case BINOP_LOGICAL_OR
:
1328 v
= v1
< v2
? v1
: v2
;
1332 v
= v1
> v2
? v1
: v2
;
1339 case BINOP_NOTEQUAL
:
1360 error (_("Invalid binary operation on numbers."));
1363 val
= allocate_value (result_type
);
1364 store_signed_integer (value_contents_raw (val
),
1365 TYPE_LENGTH (value_type (val
)),
1367 (get_type_arch (result_type
)),
1375 /* Widen a scalar value SCALAR_VALUE to vector type VECTOR_TYPE by
1376 replicating SCALAR_VALUE for each element of the vector. Only scalar
1377 types that can be cast to the type of one element of the vector are
1378 acceptable. The newly created vector value is returned upon success,
1379 otherwise an error is thrown. */
1382 value_vector_widen (struct value
*scalar_value
, struct type
*vector_type
)
1384 /* Widen the scalar to a vector. */
1385 struct type
*eltype
, *scalar_type
;
1386 struct value
*val
, *elval
;
1387 LONGEST low_bound
, high_bound
;
1390 vector_type
= check_typedef (vector_type
);
1392 gdb_assert (TYPE_CODE (vector_type
) == TYPE_CODE_ARRAY
1393 && TYPE_VECTOR (vector_type
));
1395 if (!get_array_bounds (vector_type
, &low_bound
, &high_bound
))
1396 error (_("Could not determine the vector bounds"));
1398 eltype
= check_typedef (TYPE_TARGET_TYPE (vector_type
));
1399 elval
= value_cast (eltype
, scalar_value
);
1401 scalar_type
= check_typedef (value_type (scalar_value
));
1403 /* If we reduced the length of the scalar then check we didn't loose any
1405 if (TYPE_LENGTH (eltype
) < TYPE_LENGTH (scalar_type
)
1406 && !value_equal (elval
, scalar_value
))
1407 error (_("conversion of scalar to vector involves truncation"));
1409 val
= allocate_value (vector_type
);
1410 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1411 /* Duplicate the contents of elval into the destination vector. */
1412 memcpy (value_contents_writeable (val
) + (i
* TYPE_LENGTH (eltype
)),
1413 value_contents_all (elval
), TYPE_LENGTH (eltype
));
1418 /* Performs a binary operation on two vector operands by calling scalar_binop
1419 for each pair of vector components. */
1421 static struct value
*
1422 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1424 struct value
*val
, *tmp
, *mark
;
1425 struct type
*type1
, *type2
, *eltype1
, *eltype2
;
1426 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1427 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1429 type1
= check_typedef (value_type (val1
));
1430 type2
= check_typedef (value_type (val2
));
1432 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1433 && TYPE_VECTOR (type1
)) ? 1 : 0;
1434 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1435 && TYPE_VECTOR (type2
)) ? 1 : 0;
1437 if (!t1_is_vec
|| !t2_is_vec
)
1438 error (_("Vector operations are only supported among vectors"));
1440 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1441 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1442 error (_("Could not determine the vector bounds"));
1444 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1445 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1446 elsize
= TYPE_LENGTH (eltype1
);
1448 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1449 || elsize
!= TYPE_LENGTH (eltype2
)
1450 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1451 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1452 error (_("Cannot perform operation on vectors with different types"));
1454 val
= allocate_value (type1
);
1455 mark
= value_mark ();
1456 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1458 tmp
= value_binop (value_subscript (val1
, i
),
1459 value_subscript (val2
, i
), op
);
1460 memcpy (value_contents_writeable (val
) + i
* elsize
,
1461 value_contents_all (tmp
),
1464 value_free_to_mark (mark
);
1469 /* Perform a binary operation on two operands. */
1472 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1475 struct type
*type1
= check_typedef (value_type (arg1
));
1476 struct type
*type2
= check_typedef (value_type (arg2
));
1477 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1478 && TYPE_VECTOR (type1
));
1479 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1480 && TYPE_VECTOR (type2
));
1482 if (!t1_is_vec
&& !t2_is_vec
)
1483 val
= scalar_binop (arg1
, arg2
, op
);
1484 else if (t1_is_vec
&& t2_is_vec
)
1485 val
= vector_binop (arg1
, arg2
, op
);
1488 /* Widen the scalar operand to a vector. */
1489 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1490 struct type
*t
= t1_is_vec
? type2
: type1
;
1492 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1493 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1494 && !is_integral_type (t
))
1495 error (_("Argument to operation not a number or boolean."));
1497 /* Replicate the scalar value to make a vector value. */
1498 *v
= value_vector_widen (*v
, t1_is_vec
? type1
: type2
);
1500 val
= vector_binop (arg1
, arg2
, op
);
1506 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1509 value_logical_not (struct value
*arg1
)
1515 arg1
= coerce_array (arg1
);
1516 type1
= check_typedef (value_type (arg1
));
1518 if (is_floating_value (arg1
))
1519 return target_float_is_zero (value_contents (arg1
), type1
);
1521 len
= TYPE_LENGTH (type1
);
1522 p
= value_contents (arg1
);
1533 /* Perform a comparison on two string values (whose content are not
1534 necessarily null terminated) based on their length. */
1537 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1539 int len1
= TYPE_LENGTH (value_type (arg1
));
1540 int len2
= TYPE_LENGTH (value_type (arg2
));
1541 const gdb_byte
*s1
= value_contents (arg1
);
1542 const gdb_byte
*s2
= value_contents (arg2
);
1543 int i
, len
= len1
< len2
? len1
: len2
;
1545 for (i
= 0; i
< len
; i
++)
1549 else if (s1
[i
] > s2
[i
])
1557 else if (len1
> len2
)
1563 /* Simulate the C operator == by returning a 1
1564 iff ARG1 and ARG2 have equal contents. */
1567 value_equal (struct value
*arg1
, struct value
*arg2
)
1572 struct type
*type1
, *type2
;
1573 enum type_code code1
;
1574 enum type_code code2
;
1575 int is_int1
, is_int2
;
1577 arg1
= coerce_array (arg1
);
1578 arg2
= coerce_array (arg2
);
1580 type1
= check_typedef (value_type (arg1
));
1581 type2
= check_typedef (value_type (arg2
));
1582 code1
= TYPE_CODE (type1
);
1583 code2
= TYPE_CODE (type2
);
1584 is_int1
= is_integral_type (type1
);
1585 is_int2
= is_integral_type (type2
);
1587 if (is_int1
&& is_int2
)
1588 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1590 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1591 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1593 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1594 `long double' values are returned in static storage (m68k). */
1595 DOUBLEST d
= value_as_double (arg1
);
1597 return d
== value_as_double (arg2
);
1599 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1600 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1602 gdb_byte v1
[16], v2
[16];
1604 enum bfd_endian byte_order_v1
, byte_order_v2
;
1606 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1607 v2
, &len_v2
, &byte_order_v2
);
1609 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1610 v2
, len_v2
, byte_order_v2
) == 0;
1613 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1615 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1616 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1617 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1618 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1620 else if (code1
== code2
1621 && ((len
= (int) TYPE_LENGTH (type1
))
1622 == (int) TYPE_LENGTH (type2
)))
1624 p1
= value_contents (arg1
);
1625 p2
= value_contents (arg2
);
1633 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1635 return value_strcmp (arg1
, arg2
) == 0;
1639 error (_("Invalid type combination in equality test."));
1640 return 0; /* For lint -- never reached. */
1644 /* Compare values based on their raw contents. Useful for arrays since
1645 value_equal coerces them to pointers, thus comparing just the address
1646 of the array instead of its contents. */
1649 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1651 struct type
*type1
, *type2
;
1653 type1
= check_typedef (value_type (arg1
));
1654 type2
= check_typedef (value_type (arg2
));
1656 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1657 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1658 && memcmp (value_contents (arg1
), value_contents (arg2
),
1659 TYPE_LENGTH (type1
)) == 0);
1662 /* Simulate the C operator < by returning 1
1663 iff ARG1's contents are less than ARG2's. */
1666 value_less (struct value
*arg1
, struct value
*arg2
)
1668 enum type_code code1
;
1669 enum type_code code2
;
1670 struct type
*type1
, *type2
;
1671 int is_int1
, is_int2
;
1673 arg1
= coerce_array (arg1
);
1674 arg2
= coerce_array (arg2
);
1676 type1
= check_typedef (value_type (arg1
));
1677 type2
= check_typedef (value_type (arg2
));
1678 code1
= TYPE_CODE (type1
);
1679 code2
= TYPE_CODE (type2
);
1680 is_int1
= is_integral_type (type1
);
1681 is_int2
= is_integral_type (type2
);
1683 if (is_int1
&& is_int2
)
1684 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1686 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1687 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1689 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1690 `long double' values are returned in static storage (m68k). */
1691 DOUBLEST d
= value_as_double (arg1
);
1693 return d
< value_as_double (arg2
);
1695 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1696 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1698 gdb_byte v1
[16], v2
[16];
1700 enum bfd_endian byte_order_v1
, byte_order_v2
;
1702 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1703 v2
, &len_v2
, &byte_order_v2
);
1705 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1706 v2
, len_v2
, byte_order_v2
) == -1;
1708 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1709 return value_as_address (arg1
) < value_as_address (arg2
);
1711 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1713 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1714 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1715 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1716 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1717 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1718 return value_strcmp (arg1
, arg2
) < 0;
1721 error (_("Invalid type combination in ordering comparison."));
1726 /* The unary operators +, - and ~. They free the argument ARG1. */
1729 value_pos (struct value
*arg1
)
1733 arg1
= coerce_ref (arg1
);
1734 type
= check_typedef (value_type (arg1
));
1736 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1737 return value_from_double (type
, value_as_double (arg1
));
1738 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1739 return value_from_decfloat (type
, value_contents (arg1
));
1740 else if (is_integral_type (type
))
1742 return value_from_longest (type
, value_as_long (arg1
));
1744 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1746 struct value
*val
= allocate_value (type
);
1748 memcpy (value_contents_raw (val
), value_contents (arg1
),
1749 TYPE_LENGTH (type
));
1754 error (_("Argument to positive operation not a number."));
1755 return 0; /* For lint -- never reached. */
1760 value_neg (struct value
*arg1
)
1764 arg1
= coerce_ref (arg1
);
1765 type
= check_typedef (value_type (arg1
));
1767 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1769 struct value
*val
= allocate_value (type
);
1770 int len
= TYPE_LENGTH (type
);
1771 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1773 memcpy (decbytes
, value_contents (arg1
), len
);
1775 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1776 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1778 decbytes
[0] = decbytes
[0] | 0x80;
1780 memcpy (value_contents_raw (val
), decbytes
, len
);
1783 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1784 return value_from_double (type
, -value_as_double (arg1
));
1785 else if (is_integral_type (type
))
1787 return value_from_longest (type
, -value_as_long (arg1
));
1789 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1791 struct value
*tmp
, *val
= allocate_value (type
);
1792 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1794 LONGEST low_bound
, high_bound
;
1796 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1797 error (_("Could not determine the vector bounds"));
1799 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1801 tmp
= value_neg (value_subscript (arg1
, i
));
1802 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1803 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1809 error (_("Argument to negate operation not a number."));
1810 return 0; /* For lint -- never reached. */
1815 value_complement (struct value
*arg1
)
1820 arg1
= coerce_ref (arg1
);
1821 type
= check_typedef (value_type (arg1
));
1823 if (is_integral_type (type
))
1824 val
= value_from_longest (type
, ~value_as_long (arg1
));
1825 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1828 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1830 LONGEST low_bound
, high_bound
;
1832 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1833 error (_("Could not determine the vector bounds"));
1835 val
= allocate_value (type
);
1836 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1838 tmp
= value_complement (value_subscript (arg1
, i
));
1839 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1840 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1844 error (_("Argument to complement operation not an integer, boolean."));
1849 /* The INDEX'th bit of SET value whose value_type is TYPE,
1850 and whose value_contents is valaddr.
1851 Return -1 if out of range, -2 other error. */
1854 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1856 struct gdbarch
*gdbarch
= get_type_arch (type
);
1857 LONGEST low_bound
, high_bound
;
1860 struct type
*range
= TYPE_INDEX_TYPE (type
);
1862 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1864 if (index
< low_bound
|| index
> high_bound
)
1866 rel_index
= index
- low_bound
;
1867 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1868 gdbarch_byte_order (gdbarch
));
1869 rel_index
%= TARGET_CHAR_BIT
;
1870 if (gdbarch_bits_big_endian (gdbarch
))
1871 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1872 return (word
>> rel_index
) & 1;
1876 value_in (struct value
*element
, struct value
*set
)
1879 struct type
*settype
= check_typedef (value_type (set
));
1880 struct type
*eltype
= check_typedef (value_type (element
));
1882 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1883 eltype
= TYPE_TARGET_TYPE (eltype
);
1884 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1885 error (_("Second argument of 'IN' has wrong type"));
1886 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1887 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1888 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1889 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1890 error (_("First argument of 'IN' has wrong type"));
1891 member
= value_bit_index (settype
, value_contents (set
),
1892 value_as_long (element
));
1894 error (_("First argument of 'IN' not in range"));
1899 _initialize_valarith (void)
This page took 0.073029 seconds and 4 git commands to generate.