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"
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 /* Given a pointer, return the size of its target.
40 If the pointer type is void *, then return 1.
41 If the target type is incomplete, then error out.
42 This isn't a general purpose function, but just a
43 helper for value_ptradd. */
46 find_size_for_pointer_math (struct type
*ptr_type
)
49 struct type
*ptr_target
;
51 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
52 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
54 sz
= type_length_units (ptr_target
);
57 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
63 name
= TYPE_NAME (ptr_target
);
65 name
= TYPE_TAG_NAME (ptr_target
);
67 error (_("Cannot perform pointer math on incomplete types, "
68 "try casting to a known type, or void *."));
70 error (_("Cannot perform pointer math on incomplete type \"%s\", "
71 "try casting to a known type, or void *."), name
);
77 /* Given a pointer ARG1 and an integral value ARG2, return the
78 result of C-style pointer arithmetic ARG1 + ARG2. */
81 value_ptradd (struct value
*arg1
, LONGEST arg2
)
83 struct type
*valptrtype
;
87 arg1
= coerce_array (arg1
);
88 valptrtype
= check_typedef (value_type (arg1
));
89 sz
= find_size_for_pointer_math (valptrtype
);
91 result
= value_from_pointer (valptrtype
,
92 value_as_address (arg1
) + sz
* arg2
);
93 if (VALUE_LVAL (result
) != lval_internalvar
)
94 set_value_component_location (result
, arg1
);
98 /* Given two compatible pointer values ARG1 and ARG2, return the
99 result of C-style pointer arithmetic ARG1 - ARG2. */
102 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
104 struct type
*type1
, *type2
;
107 arg1
= coerce_array (arg1
);
108 arg2
= coerce_array (arg2
);
109 type1
= check_typedef (value_type (arg1
));
110 type2
= check_typedef (value_type (arg2
));
112 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
113 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
115 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
116 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
117 error (_("First argument of `-' is a pointer and "
118 "second argument is neither\n"
119 "an integer nor a pointer of the same type."));
121 sz
= type_length_units (check_typedef (TYPE_TARGET_TYPE (type1
)));
124 warning (_("Type size unknown, assuming 1. "
125 "Try casting to a known type, or void *."));
129 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
132 /* Return the value of ARRAY[IDX].
134 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
135 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
137 See comments in value_coerce_array() for rationale for reason for
138 doing lower bounds adjustment here rather than there.
139 FIXME: Perhaps we should validate that the index is valid and if
140 verbosity is set, warn about invalid indices (but still use them). */
143 value_subscript (struct value
*array
, LONGEST index
)
145 int c_style
= current_language
->c_style_arrays
;
148 array
= coerce_ref (array
);
149 tarray
= check_typedef (value_type (array
));
151 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
152 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
154 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
155 LONGEST lowerbound
, upperbound
;
157 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
158 if (VALUE_LVAL (array
) != lval_memory
)
159 return value_subscripted_rvalue (array
, index
, lowerbound
);
163 if (index
>= lowerbound
&& index
<= upperbound
)
164 return value_subscripted_rvalue (array
, index
, lowerbound
);
165 /* Emit warning unless we have an array of unknown size.
166 An array of unknown size has lowerbound 0 and upperbound -1. */
168 warning (_("array or string index out of range"));
169 /* fall doing C stuff */
174 array
= value_coerce_array (array
);
178 return value_ind (value_ptradd (array
, index
));
180 error (_("not an array or string"));
183 /* Return the value of EXPR[IDX], expr an aggregate rvalue
184 (eg, a vector register). This routine used to promote floats
185 to doubles, but no longer does. */
188 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
190 struct type
*array_type
= check_typedef (value_type (array
));
191 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
192 ULONGEST elt_size
= type_length_units (elt_type
);
193 ULONGEST elt_offs
= elt_size
* (index
- lowerbound
);
195 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
196 && elt_offs
>= type_length_units (array_type
)))
198 if (type_not_associated (array_type
))
199 error (_("no such vector element (vector not associated)"));
200 else if (type_not_allocated (array_type
))
201 error (_("no such vector element (vector not allocated)"));
203 error (_("no such vector element"));
206 if (is_dynamic_type (elt_type
))
210 address
= value_address (array
) + elt_offs
;
211 elt_type
= resolve_dynamic_type (elt_type
, NULL
, address
);
214 return value_from_component (array
, elt_type
, elt_offs
);
218 /* Check to see if either argument is a structure, or a reference to
219 one. This is called so we know whether to go ahead with the normal
220 binop or look for a user defined function instead.
222 For now, we do not overload the `=' operator. */
225 binop_types_user_defined_p (enum exp_opcode op
,
226 struct type
*type1
, struct type
*type2
)
228 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
231 type1
= check_typedef (type1
);
232 if (TYPE_IS_REFERENCE (type1
))
233 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
235 type2
= check_typedef (type2
);
236 if (TYPE_IS_REFERENCE (type2
))
237 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
239 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
240 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
243 /* Check to see if either argument is a structure, or a reference to
244 one. This is called so we know whether to go ahead with the normal
245 binop or look for a user defined function instead.
247 For now, we do not overload the `=' operator. */
250 binop_user_defined_p (enum exp_opcode op
,
251 struct value
*arg1
, struct value
*arg2
)
253 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
256 /* Check to see if argument is a structure. This is called so
257 we know whether to go ahead with the normal unop or look for a
258 user defined function instead.
260 For now, we do not overload the `&' operator. */
263 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
269 type1
= check_typedef (value_type (arg1
));
270 if (TYPE_IS_REFERENCE (type1
))
271 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
272 return TYPE_CODE (type1
) == TYPE_CODE_STRUCT
;
275 /* Try to find an operator named OPERATOR which takes NARGS arguments
276 specified in ARGS. If the operator found is a static member operator
277 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
278 The search if performed through find_overload_match which will handle
279 member operators, non member operators, operators imported implicitly or
280 explicitly, and perform correct overload resolution in all of the above
281 situations or combinations thereof. */
283 static struct value
*
284 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *oper
,
285 int *static_memfuncp
, enum noside noside
)
288 struct symbol
*symp
= NULL
;
289 struct value
*valp
= NULL
;
291 find_overload_match (args
, nargs
, oper
, BOTH
/* could be method */,
293 NULL
/* pass NULL symbol since symbol is unknown */,
294 &valp
, &symp
, static_memfuncp
, 0, noside
);
301 /* This is a non member function and does not
302 expect a reference as its first argument
303 rather the explicit structure. */
304 args
[0] = value_ind (args
[0]);
305 return value_of_variable (symp
, 0);
308 error (_("Could not find %s."), oper
);
311 /* Lookup user defined operator NAME. Return a value representing the
312 function, otherwise return NULL. */
314 static struct value
*
315 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
316 int *static_memfuncp
, int nargs
, enum noside noside
)
318 struct value
*result
= NULL
;
320 if (current_language
->la_language
== language_cplus
)
322 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
,
326 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
332 /* We know either arg1 or arg2 is a structure, so try to find the right
333 user defined function. Create an argument vector that calls
334 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
335 binary operator which is legal for GNU C++).
337 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
338 is the opcode saying how to modify it. Otherwise, OTHEROP is
342 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
343 enum exp_opcode otherop
, enum noside noside
)
345 struct value
**argvec
;
350 arg1
= coerce_ref (arg1
);
351 arg2
= coerce_ref (arg2
);
353 /* now we know that what we have to do is construct our
354 arg vector and find the right function to call it with. */
356 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
357 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
359 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
360 argvec
[1] = value_addr (arg1
);
364 /* Make the right function name up. */
365 strcpy (tstr
, "operator__");
390 case BINOP_BITWISE_AND
:
393 case BINOP_BITWISE_IOR
:
396 case BINOP_BITWISE_XOR
:
399 case BINOP_LOGICAL_AND
:
402 case BINOP_LOGICAL_OR
:
414 case BINOP_ASSIGN_MODIFY
:
432 case BINOP_BITWISE_AND
:
435 case BINOP_BITWISE_IOR
:
438 case BINOP_BITWISE_XOR
:
441 case BINOP_MOD
: /* invalid */
443 error (_("Invalid binary operation specified."));
446 case BINOP_SUBSCRIPT
:
467 case BINOP_MOD
: /* invalid */
469 error (_("Invalid binary operation specified."));
472 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
473 &static_memfuncp
, 2, noside
);
479 argvec
[1] = argvec
[0];
482 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
484 /* Static xmethods are not supported yet. */
485 gdb_assert (static_memfuncp
== 0);
486 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
488 struct type
*return_type
489 = result_type_of_xmethod (argvec
[0], 2, argvec
+ 1);
491 if (return_type
== NULL
)
492 error (_("Xmethod is missing return type."));
493 return value_zero (return_type
, VALUE_LVAL (arg1
));
495 return call_xmethod (argvec
[0], 2, argvec
+ 1);
497 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
499 struct type
*return_type
;
502 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
503 return value_zero (return_type
, VALUE_LVAL (arg1
));
505 return call_function_by_hand (argvec
[0], NULL
, 2 - static_memfuncp
,
508 throw_error (NOT_FOUND_ERROR
,
509 _("member function %s not found"), tstr
);
511 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
515 /* We know that arg1 is a structure, so try to find a unary user
516 defined operator that matches the operator in question.
517 Create an argument vector that calls arg1.operator @ (arg1)
518 and return that value (where '@' is (almost) any unary operator which
519 is legal for GNU C++). */
522 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
524 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
525 struct value
**argvec
;
527 char tstr
[13], mangle_tstr
[13];
528 int static_memfuncp
, nargs
;
530 arg1
= coerce_ref (arg1
);
532 /* now we know that what we have to do is construct our
533 arg vector and find the right function to call it with. */
535 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
536 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
538 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
539 argvec
[1] = value_addr (arg1
);
544 /* Make the right function name up. */
545 strcpy (tstr
, "operator__");
547 strcpy (mangle_tstr
, "__");
550 case UNOP_PREINCREMENT
:
553 case UNOP_PREDECREMENT
:
556 case UNOP_POSTINCREMENT
:
558 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
562 case UNOP_POSTDECREMENT
:
564 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
568 case UNOP_LOGICAL_NOT
:
571 case UNOP_COMPLEMENT
:
587 error (_("Invalid unary operation specified."));
590 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
591 &static_memfuncp
, nargs
, noside
);
597 argvec
[1] = argvec
[0];
601 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_XMETHOD
)
603 /* Static xmethods are not supported yet. */
604 gdb_assert (static_memfuncp
== 0);
605 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
607 struct type
*return_type
608 = result_type_of_xmethod (argvec
[0], 1, argvec
+ 1);
610 if (return_type
== NULL
)
611 error (_("Xmethod is missing return type."));
612 return value_zero (return_type
, VALUE_LVAL (arg1
));
614 return call_xmethod (argvec
[0], 1, argvec
+ 1);
616 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
618 struct type
*return_type
;
621 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
622 return value_zero (return_type
, VALUE_LVAL (arg1
));
624 return call_function_by_hand (argvec
[0], NULL
, nargs
, argvec
+ 1);
626 throw_error (NOT_FOUND_ERROR
,
627 _("member function %s not found"), tstr
);
629 return 0; /* For lint -- never reached */
633 /* Concatenate two values with the following conditions:
635 (1) Both values must be either bitstring values or character string
636 values and the resulting value consists of the concatenation of
637 ARG1 followed by ARG2.
641 One value must be an integer value and the other value must be
642 either a bitstring value or character string value, which is
643 to be repeated by the number of times specified by the integer
647 (2) Boolean values are also allowed and are treated as bit string
650 (3) Character values are also allowed and are treated as character
651 string values of length 1. */
654 value_concat (struct value
*arg1
, struct value
*arg2
)
656 struct value
*inval1
;
657 struct value
*inval2
;
658 struct value
*outval
= NULL
;
659 int inval1len
, inval2len
;
663 struct type
*type1
= check_typedef (value_type (arg1
));
664 struct type
*type2
= check_typedef (value_type (arg2
));
665 struct type
*char_type
;
667 /* First figure out if we are dealing with two values to be concatenated
668 or a repeat count and a value to be repeated. INVAL1 is set to the
669 first of two concatenated values, or the repeat count. INVAL2 is set
670 to the second of the two concatenated values or the value to be
673 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
675 struct type
*tmp
= type1
;
688 /* Now process the input values. */
690 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
692 /* We have a repeat count. Validate the second value and then
693 construct a value repeated that many times. */
694 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
695 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
697 count
= longest_to_int (value_as_long (inval1
));
698 inval2len
= TYPE_LENGTH (type2
);
699 std::vector
<char> ptr (count
* inval2len
);
700 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
704 inchar
= (char) unpack_long (type2
,
705 value_contents (inval2
));
706 for (idx
= 0; idx
< count
; idx
++)
713 char_type
= TYPE_TARGET_TYPE (type2
);
715 for (idx
= 0; idx
< count
; idx
++)
717 memcpy (&ptr
[idx
* inval2len
], value_contents (inval2
),
721 outval
= value_string (ptr
.data (), count
* inval2len
, char_type
);
723 else if (TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
725 error (_("unimplemented support for boolean repeats"));
729 error (_("can't repeat values of that type"));
732 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
733 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
735 /* We have two character strings to concatenate. */
736 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
737 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
739 error (_("Strings can only be concatenated with other strings."));
741 inval1len
= TYPE_LENGTH (type1
);
742 inval2len
= TYPE_LENGTH (type2
);
743 std::vector
<char> ptr (inval1len
+ inval2len
);
744 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
748 ptr
[0] = (char) unpack_long (type1
, value_contents (inval1
));
752 char_type
= TYPE_TARGET_TYPE (type1
);
754 memcpy (ptr
.data (), value_contents (inval1
), inval1len
);
756 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
759 (char) unpack_long (type2
, value_contents (inval2
));
763 memcpy (&ptr
[inval1len
], value_contents (inval2
), inval2len
);
765 outval
= value_string (ptr
.data (), inval1len
+ inval2len
, char_type
);
767 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
769 /* We have two bitstrings to concatenate. */
770 if (TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
772 error (_("Booleans can only be concatenated "
773 "with other bitstrings or booleans."));
775 error (_("unimplemented support for boolean concatenation."));
779 /* We don't know how to concatenate these operands. */
780 error (_("illegal operands for concatenation."));
785 /* Integer exponentiation: V1**V2, where both arguments are
786 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
789 integer_pow (LONGEST v1
, LONGEST v2
)
794 error (_("Attempt to raise 0 to negative power."));
800 /* The Russian Peasant's Algorithm. */
816 /* Integer exponentiation: V1**V2, where both arguments are
817 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
820 uinteger_pow (ULONGEST v1
, LONGEST v2
)
825 error (_("Attempt to raise 0 to negative power."));
831 /* The Russian Peasant's Algorithm. */
847 /* Obtain decimal value of arguments for binary operation, converting from
848 other types if one of them is not decimal floating point. */
850 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
851 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
852 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
854 struct type
*type1
, *type2
;
856 type1
= check_typedef (value_type (arg1
));
857 type2
= check_typedef (value_type (arg2
));
859 /* At least one of the arguments must be of decimal float type. */
860 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
861 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
863 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
864 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
865 /* The DFP extension to the C language does not allow mixing of
866 * decimal float types with other float types in expressions
867 * (see WDTR 24732, page 12). */
868 error (_("Mixing decimal floating types with "
869 "other floating types is not allowed."));
871 /* Obtain decimal value of arg1, converting from other types
874 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
876 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
877 *len_x
= TYPE_LENGTH (type1
);
878 memcpy (x
, value_contents (arg1
), *len_x
);
880 else if (is_integral_type (type1
))
882 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
883 *len_x
= TYPE_LENGTH (type2
);
884 if (TYPE_UNSIGNED (type1
))
885 decimal_from_ulongest (value_as_long (arg1
), x
, *len_x
, *byte_order_x
);
887 decimal_from_longest (value_as_long (arg1
), x
, *len_x
, *byte_order_x
);
890 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
893 /* Obtain decimal value of arg2, converting from other types
896 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
898 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
899 *len_y
= TYPE_LENGTH (type2
);
900 memcpy (y
, value_contents (arg2
), *len_y
);
902 else if (is_integral_type (type2
))
904 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
905 *len_y
= TYPE_LENGTH (type1
);
906 if (TYPE_UNSIGNED (type2
))
907 decimal_from_ulongest (value_as_long (arg2
), y
, *len_y
, *byte_order_y
);
909 decimal_from_longest (value_as_long (arg2
), y
, *len_y
, *byte_order_y
);
912 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
916 /* Perform a binary operation on two operands which have reasonable
917 representations as integers or floats. This includes booleans,
918 characters, integers, or floats.
919 Does not support addition and subtraction on pointers;
920 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
922 static struct value
*
923 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
926 struct type
*type1
, *type2
, *result_type
;
928 arg1
= coerce_ref (arg1
);
929 arg2
= coerce_ref (arg2
);
931 type1
= check_typedef (value_type (arg1
));
932 type2
= check_typedef (value_type (arg2
));
934 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
935 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
936 && !is_integral_type (type1
))
937 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
938 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
939 && !is_integral_type (type2
)))
940 error (_("Argument to arithmetic operation not a number or boolean."));
942 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
943 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
945 int len_v1
, len_v2
, len_v
;
946 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
947 gdb_byte v1
[16], v2
[16];
950 /* If only one type is decimal float, use its type.
951 Otherwise use the bigger type. */
952 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
954 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
956 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
961 len_v
= TYPE_LENGTH (result_type
);
962 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
964 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
965 v2
, &len_v2
, &byte_order_v2
);
974 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
975 v2
, len_v2
, byte_order_v2
,
976 v
, len_v
, byte_order_v
);
980 error (_("Operation not valid for decimal floating point number."));
983 val
= value_from_decfloat (result_type
, v
);
985 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
986 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
988 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
989 in target format. real.c in GCC probably has the necessary
991 DOUBLEST v1
, v2
, v
= 0;
993 v1
= value_as_double (arg1
);
994 v2
= value_as_double (arg2
);
1018 error (_("Cannot perform exponentiation: %s"),
1019 safe_strerror (errno
));
1023 v
= v1
< v2
? v1
: v2
;
1027 v
= v1
> v2
? v1
: v2
;
1031 error (_("Integer-only operation on floating point number."));
1034 /* If only one type is float, use its type.
1035 Otherwise use the bigger type. */
1036 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1037 result_type
= type2
;
1038 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1039 result_type
= type1
;
1040 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1041 result_type
= type2
;
1043 result_type
= type1
;
1045 val
= allocate_value (result_type
);
1046 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1048 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1049 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1051 LONGEST v1
, v2
, v
= 0;
1053 v1
= value_as_long (arg1
);
1054 v2
= value_as_long (arg2
);
1058 case BINOP_BITWISE_AND
:
1062 case BINOP_BITWISE_IOR
:
1066 case BINOP_BITWISE_XOR
:
1074 case BINOP_NOTEQUAL
:
1079 error (_("Invalid operation on booleans."));
1082 result_type
= type1
;
1084 val
= allocate_value (result_type
);
1085 store_signed_integer (value_contents_raw (val
),
1086 TYPE_LENGTH (result_type
),
1087 gdbarch_byte_order (get_type_arch (result_type
)),
1091 /* Integral operations here. */
1093 /* Determine type length of the result, and if the operation should
1094 be done unsigned. For exponentiation and shift operators,
1095 use the length and type of the left operand. Otherwise,
1096 use the signedness of the operand with the greater length.
1097 If both operands are of equal length, use unsigned operation
1098 if one of the operands is unsigned. */
1099 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1100 result_type
= type1
;
1101 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1102 result_type
= type1
;
1103 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1104 result_type
= type2
;
1105 else if (TYPE_UNSIGNED (type1
))
1106 result_type
= type1
;
1107 else if (TYPE_UNSIGNED (type2
))
1108 result_type
= type2
;
1110 result_type
= type1
;
1112 if (TYPE_UNSIGNED (result_type
))
1114 LONGEST v2_signed
= value_as_long (arg2
);
1115 ULONGEST v1
, v2
, v
= 0;
1117 v1
= (ULONGEST
) value_as_long (arg1
);
1118 v2
= (ULONGEST
) v2_signed
;
1139 error (_("Division by zero"));
1143 v
= uinteger_pow (v1
, v2_signed
);
1150 error (_("Division by zero"));
1154 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1155 v1 mod 0 has a defined value, v1. */
1163 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1176 case BINOP_BITWISE_AND
:
1180 case BINOP_BITWISE_IOR
:
1184 case BINOP_BITWISE_XOR
:
1188 case BINOP_LOGICAL_AND
:
1192 case BINOP_LOGICAL_OR
:
1197 v
= v1
< v2
? v1
: v2
;
1201 v
= v1
> v2
? v1
: v2
;
1208 case BINOP_NOTEQUAL
:
1229 error (_("Invalid binary operation on numbers."));
1232 val
= allocate_value (result_type
);
1233 store_unsigned_integer (value_contents_raw (val
),
1234 TYPE_LENGTH (value_type (val
)),
1236 (get_type_arch (result_type
)),
1241 LONGEST v1
, v2
, v
= 0;
1243 v1
= value_as_long (arg1
);
1244 v2
= value_as_long (arg2
);
1265 error (_("Division by zero"));
1269 v
= integer_pow (v1
, v2
);
1276 error (_("Division by zero"));
1280 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1281 X mod 0 has a defined value, X. */
1289 /* Compute floor. */
1290 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1306 case BINOP_BITWISE_AND
:
1310 case BINOP_BITWISE_IOR
:
1314 case BINOP_BITWISE_XOR
:
1318 case BINOP_LOGICAL_AND
:
1322 case BINOP_LOGICAL_OR
:
1327 v
= v1
< v2
? v1
: v2
;
1331 v
= v1
> v2
? v1
: v2
;
1338 case BINOP_NOTEQUAL
:
1359 error (_("Invalid binary operation on numbers."));
1362 val
= allocate_value (result_type
);
1363 store_signed_integer (value_contents_raw (val
),
1364 TYPE_LENGTH (value_type (val
)),
1366 (get_type_arch (result_type
)),
1374 /* Widen a scalar value SCALAR_VALUE to vector type VECTOR_TYPE by
1375 replicating SCALAR_VALUE for each element of the vector. Only scalar
1376 types that can be cast to the type of one element of the vector are
1377 acceptable. The newly created vector value is returned upon success,
1378 otherwise an error is thrown. */
1381 value_vector_widen (struct value
*scalar_value
, struct type
*vector_type
)
1383 /* Widen the scalar to a vector. */
1384 struct type
*eltype
, *scalar_type
;
1385 struct value
*val
, *elval
;
1386 LONGEST low_bound
, high_bound
;
1389 vector_type
= check_typedef (vector_type
);
1391 gdb_assert (TYPE_CODE (vector_type
) == TYPE_CODE_ARRAY
1392 && TYPE_VECTOR (vector_type
));
1394 if (!get_array_bounds (vector_type
, &low_bound
, &high_bound
))
1395 error (_("Could not determine the vector bounds"));
1397 eltype
= check_typedef (TYPE_TARGET_TYPE (vector_type
));
1398 elval
= value_cast (eltype
, scalar_value
);
1400 scalar_type
= check_typedef (value_type (scalar_value
));
1402 /* If we reduced the length of the scalar then check we didn't loose any
1404 if (TYPE_LENGTH (eltype
) < TYPE_LENGTH (scalar_type
)
1405 && !value_equal (elval
, scalar_value
))
1406 error (_("conversion of scalar to vector involves truncation"));
1408 val
= allocate_value (vector_type
);
1409 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1410 /* Duplicate the contents of elval into the destination vector. */
1411 memcpy (value_contents_writeable (val
) + (i
* TYPE_LENGTH (eltype
)),
1412 value_contents_all (elval
), TYPE_LENGTH (eltype
));
1417 /* Performs a binary operation on two vector operands by calling scalar_binop
1418 for each pair of vector components. */
1420 static struct value
*
1421 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1423 struct value
*val
, *tmp
, *mark
;
1424 struct type
*type1
, *type2
, *eltype1
, *eltype2
;
1425 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1426 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1428 type1
= check_typedef (value_type (val1
));
1429 type2
= check_typedef (value_type (val2
));
1431 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1432 && TYPE_VECTOR (type1
)) ? 1 : 0;
1433 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1434 && TYPE_VECTOR (type2
)) ? 1 : 0;
1436 if (!t1_is_vec
|| !t2_is_vec
)
1437 error (_("Vector operations are only supported among vectors"));
1439 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1440 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1441 error (_("Could not determine the vector bounds"));
1443 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1444 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1445 elsize
= TYPE_LENGTH (eltype1
);
1447 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1448 || elsize
!= TYPE_LENGTH (eltype2
)
1449 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1450 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1451 error (_("Cannot perform operation on vectors with different types"));
1453 val
= allocate_value (type1
);
1454 mark
= value_mark ();
1455 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1457 tmp
= value_binop (value_subscript (val1
, i
),
1458 value_subscript (val2
, i
), op
);
1459 memcpy (value_contents_writeable (val
) + i
* elsize
,
1460 value_contents_all (tmp
),
1463 value_free_to_mark (mark
);
1468 /* Perform a binary operation on two operands. */
1471 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1474 struct type
*type1
= check_typedef (value_type (arg1
));
1475 struct type
*type2
= check_typedef (value_type (arg2
));
1476 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1477 && TYPE_VECTOR (type1
));
1478 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1479 && TYPE_VECTOR (type2
));
1481 if (!t1_is_vec
&& !t2_is_vec
)
1482 val
= scalar_binop (arg1
, arg2
, op
);
1483 else if (t1_is_vec
&& t2_is_vec
)
1484 val
= vector_binop (arg1
, arg2
, op
);
1487 /* Widen the scalar operand to a vector. */
1488 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1489 struct type
*t
= t1_is_vec
? type2
: type1
;
1491 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1492 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1493 && !is_integral_type (t
))
1494 error (_("Argument to operation not a number or boolean."));
1496 /* Replicate the scalar value to make a vector value. */
1497 *v
= value_vector_widen (*v
, t1_is_vec
? type1
: type2
);
1499 val
= vector_binop (arg1
, arg2
, op
);
1505 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1508 value_logical_not (struct value
*arg1
)
1514 arg1
= coerce_array (arg1
);
1515 type1
= check_typedef (value_type (arg1
));
1517 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1518 return 0 == value_as_double (arg1
);
1519 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1520 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1521 gdbarch_byte_order (get_type_arch (type1
)));
1523 len
= TYPE_LENGTH (type1
);
1524 p
= value_contents (arg1
);
1535 /* Perform a comparison on two string values (whose content are not
1536 necessarily null terminated) based on their length. */
1539 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1541 int len1
= TYPE_LENGTH (value_type (arg1
));
1542 int len2
= TYPE_LENGTH (value_type (arg2
));
1543 const gdb_byte
*s1
= value_contents (arg1
);
1544 const gdb_byte
*s2
= value_contents (arg2
);
1545 int i
, len
= len1
< len2
? len1
: len2
;
1547 for (i
= 0; i
< len
; i
++)
1551 else if (s1
[i
] > s2
[i
])
1559 else if (len1
> len2
)
1565 /* Simulate the C operator == by returning a 1
1566 iff ARG1 and ARG2 have equal contents. */
1569 value_equal (struct value
*arg1
, struct value
*arg2
)
1574 struct type
*type1
, *type2
;
1575 enum type_code code1
;
1576 enum type_code code2
;
1577 int is_int1
, is_int2
;
1579 arg1
= coerce_array (arg1
);
1580 arg2
= coerce_array (arg2
);
1582 type1
= check_typedef (value_type (arg1
));
1583 type2
= check_typedef (value_type (arg2
));
1584 code1
= TYPE_CODE (type1
);
1585 code2
= TYPE_CODE (type2
);
1586 is_int1
= is_integral_type (type1
);
1587 is_int2
= is_integral_type (type2
);
1589 if (is_int1
&& is_int2
)
1590 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1592 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1593 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1595 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1596 `long double' values are returned in static storage (m68k). */
1597 DOUBLEST d
= value_as_double (arg1
);
1599 return d
== value_as_double (arg2
);
1601 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1602 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1604 gdb_byte v1
[16], v2
[16];
1606 enum bfd_endian byte_order_v1
, byte_order_v2
;
1608 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1609 v2
, &len_v2
, &byte_order_v2
);
1611 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1612 v2
, len_v2
, byte_order_v2
) == 0;
1615 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1617 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1618 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1619 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1620 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1622 else if (code1
== code2
1623 && ((len
= (int) TYPE_LENGTH (type1
))
1624 == (int) TYPE_LENGTH (type2
)))
1626 p1
= value_contents (arg1
);
1627 p2
= value_contents (arg2
);
1635 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1637 return value_strcmp (arg1
, arg2
) == 0;
1641 error (_("Invalid type combination in equality test."));
1642 return 0; /* For lint -- never reached. */
1646 /* Compare values based on their raw contents. Useful for arrays since
1647 value_equal coerces them to pointers, thus comparing just the address
1648 of the array instead of its contents. */
1651 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1653 struct type
*type1
, *type2
;
1655 type1
= check_typedef (value_type (arg1
));
1656 type2
= check_typedef (value_type (arg2
));
1658 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1659 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1660 && memcmp (value_contents (arg1
), value_contents (arg2
),
1661 TYPE_LENGTH (type1
)) == 0);
1664 /* Simulate the C operator < by returning 1
1665 iff ARG1's contents are less than ARG2's. */
1668 value_less (struct value
*arg1
, struct value
*arg2
)
1670 enum type_code code1
;
1671 enum type_code code2
;
1672 struct type
*type1
, *type2
;
1673 int is_int1
, is_int2
;
1675 arg1
= coerce_array (arg1
);
1676 arg2
= coerce_array (arg2
);
1678 type1
= check_typedef (value_type (arg1
));
1679 type2
= check_typedef (value_type (arg2
));
1680 code1
= TYPE_CODE (type1
);
1681 code2
= TYPE_CODE (type2
);
1682 is_int1
= is_integral_type (type1
);
1683 is_int2
= is_integral_type (type2
);
1685 if (is_int1
&& is_int2
)
1686 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1688 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1689 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1691 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1692 `long double' values are returned in static storage (m68k). */
1693 DOUBLEST d
= value_as_double (arg1
);
1695 return d
< value_as_double (arg2
);
1697 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1698 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1700 gdb_byte v1
[16], v2
[16];
1702 enum bfd_endian byte_order_v1
, byte_order_v2
;
1704 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1705 v2
, &len_v2
, &byte_order_v2
);
1707 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1708 v2
, len_v2
, byte_order_v2
) == -1;
1710 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1711 return value_as_address (arg1
) < value_as_address (arg2
);
1713 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1715 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1716 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1717 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1718 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1719 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1720 return value_strcmp (arg1
, arg2
) < 0;
1723 error (_("Invalid type combination in ordering comparison."));
1728 /* The unary operators +, - and ~. They free the argument ARG1. */
1731 value_pos (struct value
*arg1
)
1735 arg1
= coerce_ref (arg1
);
1736 type
= check_typedef (value_type (arg1
));
1738 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1739 return value_from_double (type
, value_as_double (arg1
));
1740 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1741 return value_from_decfloat (type
, value_contents (arg1
));
1742 else if (is_integral_type (type
))
1744 return value_from_longest (type
, value_as_long (arg1
));
1746 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1748 struct value
*val
= allocate_value (type
);
1750 memcpy (value_contents_raw (val
), value_contents (arg1
),
1751 TYPE_LENGTH (type
));
1756 error (_("Argument to positive operation not a number."));
1757 return 0; /* For lint -- never reached. */
1762 value_neg (struct value
*arg1
)
1766 arg1
= coerce_ref (arg1
);
1767 type
= check_typedef (value_type (arg1
));
1769 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1771 struct value
*val
= allocate_value (type
);
1772 int len
= TYPE_LENGTH (type
);
1773 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1775 memcpy (decbytes
, value_contents (arg1
), len
);
1777 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1778 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1780 decbytes
[0] = decbytes
[0] | 0x80;
1782 memcpy (value_contents_raw (val
), decbytes
, len
);
1785 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1786 return value_from_double (type
, -value_as_double (arg1
));
1787 else if (is_integral_type (type
))
1789 return value_from_longest (type
, -value_as_long (arg1
));
1791 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1793 struct value
*tmp
, *val
= allocate_value (type
);
1794 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1796 LONGEST low_bound
, high_bound
;
1798 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1799 error (_("Could not determine the vector bounds"));
1801 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1803 tmp
= value_neg (value_subscript (arg1
, i
));
1804 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1805 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1811 error (_("Argument to negate operation not a number."));
1812 return 0; /* For lint -- never reached. */
1817 value_complement (struct value
*arg1
)
1822 arg1
= coerce_ref (arg1
);
1823 type
= check_typedef (value_type (arg1
));
1825 if (is_integral_type (type
))
1826 val
= value_from_longest (type
, ~value_as_long (arg1
));
1827 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1830 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1832 LONGEST low_bound
, high_bound
;
1834 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1835 error (_("Could not determine the vector bounds"));
1837 val
= allocate_value (type
);
1838 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1840 tmp
= value_complement (value_subscript (arg1
, i
));
1841 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1842 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1846 error (_("Argument to complement operation not an integer, boolean."));
1851 /* The INDEX'th bit of SET value whose value_type is TYPE,
1852 and whose value_contents is valaddr.
1853 Return -1 if out of range, -2 other error. */
1856 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1858 struct gdbarch
*gdbarch
= get_type_arch (type
);
1859 LONGEST low_bound
, high_bound
;
1862 struct type
*range
= TYPE_INDEX_TYPE (type
);
1864 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1866 if (index
< low_bound
|| index
> high_bound
)
1868 rel_index
= index
- low_bound
;
1869 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1870 gdbarch_byte_order (gdbarch
));
1871 rel_index
%= TARGET_CHAR_BIT
;
1872 if (gdbarch_bits_big_endian (gdbarch
))
1873 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1874 return (word
>> rel_index
) & 1;
1878 value_in (struct value
*element
, struct value
*set
)
1881 struct type
*settype
= check_typedef (value_type (set
));
1882 struct type
*eltype
= check_typedef (value_type (element
));
1884 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1885 eltype
= TYPE_TARGET_TYPE (eltype
);
1886 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1887 error (_("Second argument of 'IN' has wrong type"));
1888 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1889 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1890 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1891 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1892 error (_("First argument of 'IN' has wrong type"));
1893 member
= value_bit_index (settype
, value_contents (set
),
1894 value_as_long (element
));
1896 error (_("First argument of 'IN' not in range"));
1901 _initialize_valarith (void)
This page took 0.090057 seconds and 4 git commands to generate.