1 /* Perform arithmetic and other operations on values, for GDB.
3 Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
5 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
29 #include "gdb_string.h"
34 #include "exceptions.h"
36 /* Define whether or not the C operator '/' truncates towards zero for
37 differently signed operands (truncation direction is undefined in C). */
39 #ifndef TRUNCATION_TOWARDS_ZERO
40 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
43 void _initialize_valarith (void);
46 /* Given a pointer, return the size of its target.
47 If the pointer type is void *, then return 1.
48 If the target type is incomplete, then error out.
49 This isn't a general purpose function, but just a
50 helper for value_ptradd. */
53 find_size_for_pointer_math (struct type
*ptr_type
)
56 struct type
*ptr_target
;
58 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
59 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
61 sz
= TYPE_LENGTH (ptr_target
);
64 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
70 name
= TYPE_NAME (ptr_target
);
72 name
= TYPE_TAG_NAME (ptr_target
);
74 error (_("Cannot perform pointer math on incomplete types, "
75 "try casting to a known type, or void *."));
77 error (_("Cannot perform pointer math on incomplete type \"%s\", "
78 "try casting to a known type, or void *."), name
);
84 /* Given a pointer ARG1 and an integral value ARG2, return the
85 result of C-style pointer arithmetic ARG1 + ARG2. */
88 value_ptradd (struct value
*arg1
, LONGEST arg2
)
90 struct type
*valptrtype
;
94 arg1
= coerce_array (arg1
);
95 valptrtype
= check_typedef (value_type (arg1
));
96 sz
= find_size_for_pointer_math (valptrtype
);
98 result
= value_from_pointer (valptrtype
,
99 value_as_address (arg1
) + sz
* arg2
);
100 if (VALUE_LVAL (result
) != lval_internalvar
)
101 set_value_component_location (result
, arg1
);
105 /* Given two compatible pointer values ARG1 and ARG2, return the
106 result of C-style pointer arithmetic ARG1 - ARG2. */
109 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
111 struct type
*type1
, *type2
;
114 arg1
= coerce_array (arg1
);
115 arg2
= coerce_array (arg2
);
116 type1
= check_typedef (value_type (arg1
));
117 type2
= check_typedef (value_type (arg2
));
119 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
120 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
122 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
123 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
124 error (_("First argument of `-' is a pointer and "
125 "second argument is neither\n"
126 "an integer nor a pointer of the same type."));
128 sz
= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)));
131 warning (_("Type size unknown, assuming 1. "
132 "Try casting to a known type, or void *."));
136 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
139 /* Return the value of ARRAY[IDX].
141 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
142 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
143 To access TYPE_CODE_BITSTRING values, use value_bitstring_subscript.
145 See comments in value_coerce_array() for rationale for reason for
146 doing lower bounds adjustment here rather than there.
147 FIXME: Perhaps we should validate that the index is valid and if
148 verbosity is set, warn about invalid indices (but still use them). */
151 value_subscript (struct value
*array
, LONGEST index
)
153 int c_style
= current_language
->c_style_arrays
;
156 array
= coerce_ref (array
);
157 tarray
= check_typedef (value_type (array
));
159 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
160 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
162 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
163 LONGEST lowerbound
, upperbound
;
165 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
166 if (VALUE_LVAL (array
) != lval_memory
)
167 return value_subscripted_rvalue (array
, index
, lowerbound
);
171 if (index
>= lowerbound
&& index
<= upperbound
)
172 return value_subscripted_rvalue (array
, index
, lowerbound
);
173 /* Emit warning unless we have an array of unknown size.
174 An array of unknown size has lowerbound 0 and upperbound -1. */
176 warning (_("array or string index out of range"));
177 /* fall doing C stuff */
182 array
= value_coerce_array (array
);
186 return value_ind (value_ptradd (array
, index
));
188 error (_("not an array or string"));
191 /* Return the value of EXPR[IDX], expr an aggregate rvalue
192 (eg, a vector register). This routine used to promote floats
193 to doubles, but no longer does. */
196 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
198 struct type
*array_type
= check_typedef (value_type (array
));
199 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
200 unsigned int elt_size
= TYPE_LENGTH (elt_type
);
201 unsigned int elt_offs
= elt_size
* longest_to_int (index
- lowerbound
);
204 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
205 && elt_offs
>= TYPE_LENGTH (array_type
)))
206 error (_("no such vector element"));
208 if (VALUE_LVAL (array
) == lval_memory
&& value_lazy (array
))
209 v
= allocate_value_lazy (elt_type
);
212 v
= allocate_value (elt_type
);
213 value_contents_copy (v
, value_embedded_offset (v
),
214 array
, value_embedded_offset (array
) + elt_offs
,
218 set_value_component_location (v
, array
);
219 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
220 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
221 set_value_offset (v
, value_offset (array
) + elt_offs
);
225 /* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */
228 value_bitstring_subscript (struct type
*type
,
229 struct value
*bitstring
, LONGEST index
)
232 struct type
*bitstring_type
, *range_type
;
234 int offset
, byte
, bit_index
;
235 LONGEST lowerbound
, upperbound
;
237 bitstring_type
= check_typedef (value_type (bitstring
));
238 gdb_assert (TYPE_CODE (bitstring_type
) == TYPE_CODE_BITSTRING
);
240 range_type
= TYPE_INDEX_TYPE (bitstring_type
);
241 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
242 if (index
< lowerbound
|| index
> upperbound
)
243 error (_("bitstring index out of range"));
246 offset
= index
/ TARGET_CHAR_BIT
;
247 byte
= *((char *) value_contents (bitstring
) + offset
);
249 bit_index
= index
% TARGET_CHAR_BIT
;
250 byte
>>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type
)) ?
251 TARGET_CHAR_BIT
- 1 - bit_index
: bit_index
);
253 v
= value_from_longest (type
, byte
& 1);
255 set_value_bitpos (v
, bit_index
);
256 set_value_bitsize (v
, 1);
257 set_value_component_location (v
, bitstring
);
258 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (bitstring
);
260 set_value_offset (v
, offset
+ value_offset (bitstring
));
266 /* Check to see if either argument is a structure, or a reference to
267 one. This is called so we know whether to go ahead with the normal
268 binop or look for a user defined function instead.
270 For now, we do not overload the `=' operator. */
273 binop_types_user_defined_p (enum exp_opcode op
,
274 struct type
*type1
, struct type
*type2
)
276 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
279 type1
= check_typedef (type1
);
280 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
281 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
283 type2
= check_typedef (type1
);
284 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
285 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
287 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
288 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
291 /* Check to see if either argument is a structure, or a reference to
292 one. This is called so we know whether to go ahead with the normal
293 binop or look for a user defined function instead.
295 For now, we do not overload the `=' operator. */
298 binop_user_defined_p (enum exp_opcode op
,
299 struct value
*arg1
, struct value
*arg2
)
301 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
304 /* Check to see if argument is a structure. This is called so
305 we know whether to go ahead with the normal unop or look for a
306 user defined function instead.
308 For now, we do not overload the `&' operator. */
311 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
317 type1
= check_typedef (value_type (arg1
));
318 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
319 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
320 return TYPE_CODE (type1
) == TYPE_CODE_STRUCT
;
323 /* Try to find an operator named OPERATOR which takes NARGS arguments
324 specified in ARGS. If the operator found is a static member operator
325 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
326 The search if performed through find_overload_match which will handle
327 member operators, non member operators, operators imported implicitly or
328 explicitly, and perform correct overload resolution in all of the above
329 situations or combinations thereof. */
331 static struct value
*
332 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *operator,
333 int *static_memfuncp
)
336 struct symbol
*symp
= NULL
;
337 struct value
*valp
= NULL
;
339 find_overload_match (args
, nargs
, operator, BOTH
/* could be method */,
340 0 /* strict match */, &args
[0], /* objp */
341 NULL
/* pass NULL symbol since symbol is unknown */,
342 &valp
, &symp
, static_memfuncp
, 0);
349 /* This is a non member function and does not
350 expect a reference as its first argument
351 rather the explicit structure. */
352 args
[0] = value_ind (args
[0]);
353 return value_of_variable (symp
, 0);
356 error (_("Could not find %s."), operator);
359 /* Lookup user defined operator NAME. Return a value representing the
360 function, otherwise return NULL. */
362 static struct value
*
363 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
364 int *static_memfuncp
, int nargs
)
366 struct value
*result
= NULL
;
368 if (current_language
->la_language
== language_cplus
)
369 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
);
371 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
377 /* We know either arg1 or arg2 is a structure, so try to find the right
378 user defined function. Create an argument vector that calls
379 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
380 binary operator which is legal for GNU C++).
382 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
383 is the opcode saying how to modify it. Otherwise, OTHEROP is
387 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
388 enum exp_opcode otherop
, enum noside noside
)
390 struct value
**argvec
;
395 arg1
= coerce_ref (arg1
);
396 arg2
= coerce_ref (arg2
);
398 /* now we know that what we have to do is construct our
399 arg vector and find the right function to call it with. */
401 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
402 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
404 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
405 argvec
[1] = value_addr (arg1
);
409 /* Make the right function name up. */
410 strcpy (tstr
, "operator__");
435 case BINOP_BITWISE_AND
:
438 case BINOP_BITWISE_IOR
:
441 case BINOP_BITWISE_XOR
:
444 case BINOP_LOGICAL_AND
:
447 case BINOP_LOGICAL_OR
:
459 case BINOP_ASSIGN_MODIFY
:
477 case BINOP_BITWISE_AND
:
480 case BINOP_BITWISE_IOR
:
483 case BINOP_BITWISE_XOR
:
486 case BINOP_MOD
: /* invalid */
488 error (_("Invalid binary operation specified."));
491 case BINOP_SUBSCRIPT
:
512 case BINOP_MOD
: /* invalid */
514 error (_("Invalid binary operation specified."));
517 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
518 &static_memfuncp
, 2);
524 argvec
[1] = argvec
[0];
527 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
529 struct type
*return_type
;
532 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
533 return value_zero (return_type
, VALUE_LVAL (arg1
));
535 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
,
538 throw_error (NOT_FOUND_ERROR
,
539 _("member function %s not found"), tstr
);
541 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
545 /* We know that arg1 is a structure, so try to find a unary user
546 defined operator that matches the operator in question.
547 Create an argument vector that calls arg1.operator @ (arg1)
548 and return that value (where '@' is (almost) any unary operator which
549 is legal for GNU C++). */
552 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
554 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
555 struct value
**argvec
;
556 char *ptr
, *mangle_ptr
;
557 char tstr
[13], mangle_tstr
[13];
558 int static_memfuncp
, nargs
;
560 arg1
= coerce_ref (arg1
);
562 /* now we know that what we have to do is construct our
563 arg vector and find the right function to call it with. */
565 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
566 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
568 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
569 argvec
[1] = value_addr (arg1
);
574 /* Make the right function name up. */
575 strcpy (tstr
, "operator__");
577 strcpy (mangle_tstr
, "__");
578 mangle_ptr
= mangle_tstr
+ 2;
581 case UNOP_PREINCREMENT
:
584 case UNOP_PREDECREMENT
:
587 case UNOP_POSTINCREMENT
:
589 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
593 case UNOP_POSTDECREMENT
:
595 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
599 case UNOP_LOGICAL_NOT
:
602 case UNOP_COMPLEMENT
:
618 error (_("Invalid unary operation specified."));
621 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
622 &static_memfuncp
, nargs
);
628 argvec
[1] = argvec
[0];
632 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
634 struct type
*return_type
;
637 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
638 return value_zero (return_type
, VALUE_LVAL (arg1
));
640 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
642 throw_error (NOT_FOUND_ERROR
,
643 _("member function %s not found"), tstr
);
645 return 0; /* For lint -- never reached */
649 /* Concatenate two values with the following conditions:
651 (1) Both values must be either bitstring values or character string
652 values and the resulting value consists of the concatenation of
653 ARG1 followed by ARG2.
657 One value must be an integer value and the other value must be
658 either a bitstring value or character string value, which is
659 to be repeated by the number of times specified by the integer
663 (2) Boolean values are also allowed and are treated as bit string
666 (3) Character values are also allowed and are treated as character
667 string values of length 1. */
670 value_concat (struct value
*arg1
, struct value
*arg2
)
672 struct value
*inval1
;
673 struct value
*inval2
;
674 struct value
*outval
= NULL
;
675 int inval1len
, inval2len
;
679 struct type
*type1
= check_typedef (value_type (arg1
));
680 struct type
*type2
= check_typedef (value_type (arg2
));
681 struct type
*char_type
;
683 /* First figure out if we are dealing with two values to be concatenated
684 or a repeat count and a value to be repeated. INVAL1 is set to the
685 first of two concatenated values, or the repeat count. INVAL2 is set
686 to the second of the two concatenated values or the value to be
689 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
691 struct type
*tmp
= type1
;
704 /* Now process the input values. */
706 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
708 /* We have a repeat count. Validate the second value and then
709 construct a value repeated that many times. */
710 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
711 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
713 count
= longest_to_int (value_as_long (inval1
));
714 inval2len
= TYPE_LENGTH (type2
);
715 ptr
= (char *) alloca (count
* inval2len
);
716 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
720 inchar
= (char) unpack_long (type2
,
721 value_contents (inval2
));
722 for (idx
= 0; idx
< count
; idx
++)
724 *(ptr
+ idx
) = inchar
;
729 char_type
= TYPE_TARGET_TYPE (type2
);
731 for (idx
= 0; idx
< count
; idx
++)
733 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
737 outval
= value_string (ptr
, count
* inval2len
, char_type
);
739 else if (TYPE_CODE (type2
) == TYPE_CODE_BITSTRING
740 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
742 error (_("unimplemented support for bitstring/boolean repeats"));
746 error (_("can't repeat values of that type"));
749 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
750 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
752 /* We have two character strings to concatenate. */
753 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
754 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
756 error (_("Strings can only be concatenated with other strings."));
758 inval1len
= TYPE_LENGTH (type1
);
759 inval2len
= TYPE_LENGTH (type2
);
760 ptr
= (char *) alloca (inval1len
+ inval2len
);
761 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
765 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
769 char_type
= TYPE_TARGET_TYPE (type1
);
771 memcpy (ptr
, value_contents (inval1
), inval1len
);
773 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
776 (char) unpack_long (type2
, value_contents (inval2
));
780 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
782 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
784 else if (TYPE_CODE (type1
) == TYPE_CODE_BITSTRING
785 || TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
787 /* We have two bitstrings to concatenate. */
788 if (TYPE_CODE (type2
) != TYPE_CODE_BITSTRING
789 && TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
791 error (_("Bitstrings or booleans can only be concatenated "
792 "with other bitstrings or booleans."));
794 error (_("unimplemented support for bitstring/boolean concatenation."));
798 /* We don't know how to concatenate these operands. */
799 error (_("illegal operands for concatenation."));
804 /* Integer exponentiation: V1**V2, where both arguments are
805 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
808 integer_pow (LONGEST v1
, LONGEST v2
)
813 error (_("Attempt to raise 0 to negative power."));
819 /* The Russian Peasant's Algorithm. */
835 /* Integer exponentiation: V1**V2, where both arguments are
836 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
839 uinteger_pow (ULONGEST v1
, LONGEST v2
)
844 error (_("Attempt to raise 0 to negative power."));
850 /* The Russian Peasant's Algorithm. */
866 /* Obtain decimal value of arguments for binary operation, converting from
867 other types if one of them is not decimal floating point. */
869 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
870 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
871 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
873 struct type
*type1
, *type2
;
875 type1
= check_typedef (value_type (arg1
));
876 type2
= check_typedef (value_type (arg2
));
878 /* At least one of the arguments must be of decimal float type. */
879 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
880 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
882 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
883 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
884 /* The DFP extension to the C language does not allow mixing of
885 * decimal float types with other float types in expressions
886 * (see WDTR 24732, page 12). */
887 error (_("Mixing decimal floating types with "
888 "other floating types is not allowed."));
890 /* Obtain decimal value of arg1, converting from other types
893 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
895 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
896 *len_x
= TYPE_LENGTH (type1
);
897 memcpy (x
, value_contents (arg1
), *len_x
);
899 else if (is_integral_type (type1
))
901 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
902 *len_x
= TYPE_LENGTH (type2
);
903 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
906 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
909 /* Obtain decimal value of arg2, converting from other types
912 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
914 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
915 *len_y
= TYPE_LENGTH (type2
);
916 memcpy (y
, value_contents (arg2
), *len_y
);
918 else if (is_integral_type (type2
))
920 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
921 *len_y
= TYPE_LENGTH (type1
);
922 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
925 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
929 /* Perform a binary operation on two operands which have reasonable
930 representations as integers or floats. This includes booleans,
931 characters, integers, or floats.
932 Does not support addition and subtraction on pointers;
933 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
935 static struct value
*
936 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
939 struct type
*type1
, *type2
, *result_type
;
941 arg1
= coerce_ref (arg1
);
942 arg2
= coerce_ref (arg2
);
944 type1
= check_typedef (value_type (arg1
));
945 type2
= check_typedef (value_type (arg2
));
947 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
948 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
949 && !is_integral_type (type1
))
950 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
951 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
952 && !is_integral_type (type2
)))
953 error (_("Argument to arithmetic operation not a number or boolean."));
955 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
956 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
958 int len_v1
, len_v2
, len_v
;
959 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
960 gdb_byte v1
[16], v2
[16];
963 /* If only one type is decimal float, use its type.
964 Otherwise use the bigger type. */
965 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
967 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
969 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
974 len_v
= TYPE_LENGTH (result_type
);
975 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
977 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
978 v2
, &len_v2
, &byte_order_v2
);
987 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
988 v2
, len_v2
, byte_order_v2
,
989 v
, len_v
, byte_order_v
);
993 error (_("Operation not valid for decimal floating point number."));
996 val
= value_from_decfloat (result_type
, v
);
998 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
999 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
1001 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
1002 in target format. real.c in GCC probably has the necessary
1004 DOUBLEST v1
, v2
, v
= 0;
1006 v1
= value_as_double (arg1
);
1007 v2
= value_as_double (arg2
);
1031 error (_("Cannot perform exponentiation: %s"),
1032 safe_strerror (errno
));
1036 v
= v1
< v2
? v1
: v2
;
1040 v
= v1
> v2
? v1
: v2
;
1044 error (_("Integer-only operation on floating point number."));
1047 /* If only one type is float, use its type.
1048 Otherwise use the bigger type. */
1049 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1050 result_type
= type2
;
1051 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1052 result_type
= type1
;
1053 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1054 result_type
= type2
;
1056 result_type
= type1
;
1058 val
= allocate_value (result_type
);
1059 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1061 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1062 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1064 LONGEST v1
, v2
, v
= 0;
1066 v1
= value_as_long (arg1
);
1067 v2
= value_as_long (arg2
);
1071 case BINOP_BITWISE_AND
:
1075 case BINOP_BITWISE_IOR
:
1079 case BINOP_BITWISE_XOR
:
1087 case BINOP_NOTEQUAL
:
1092 error (_("Invalid operation on booleans."));
1095 result_type
= type1
;
1097 val
= allocate_value (result_type
);
1098 store_signed_integer (value_contents_raw (val
),
1099 TYPE_LENGTH (result_type
),
1100 gdbarch_byte_order (get_type_arch (result_type
)),
1104 /* Integral operations here. */
1106 /* Determine type length of the result, and if the operation should
1107 be done unsigned. For exponentiation and shift operators,
1108 use the length and type of the left operand. Otherwise,
1109 use the signedness of the operand with the greater length.
1110 If both operands are of equal length, use unsigned operation
1111 if one of the operands is unsigned. */
1112 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1113 result_type
= type1
;
1114 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1115 result_type
= type1
;
1116 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1117 result_type
= type2
;
1118 else if (TYPE_UNSIGNED (type1
))
1119 result_type
= type1
;
1120 else if (TYPE_UNSIGNED (type2
))
1121 result_type
= type2
;
1123 result_type
= type1
;
1125 if (TYPE_UNSIGNED (result_type
))
1127 LONGEST v2_signed
= value_as_long (arg2
);
1128 ULONGEST v1
, v2
, v
= 0;
1130 v1
= (ULONGEST
) value_as_long (arg1
);
1131 v2
= (ULONGEST
) v2_signed
;
1152 error (_("Division by zero"));
1156 v
= uinteger_pow (v1
, v2_signed
);
1163 error (_("Division by zero"));
1167 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1168 v1 mod 0 has a defined value, v1. */
1176 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1189 case BINOP_BITWISE_AND
:
1193 case BINOP_BITWISE_IOR
:
1197 case BINOP_BITWISE_XOR
:
1201 case BINOP_LOGICAL_AND
:
1205 case BINOP_LOGICAL_OR
:
1210 v
= v1
< v2
? v1
: v2
;
1214 v
= v1
> v2
? v1
: v2
;
1221 case BINOP_NOTEQUAL
:
1242 error (_("Invalid binary operation on numbers."));
1245 val
= allocate_value (result_type
);
1246 store_unsigned_integer (value_contents_raw (val
),
1247 TYPE_LENGTH (value_type (val
)),
1249 (get_type_arch (result_type
)),
1254 LONGEST v1
, v2
, v
= 0;
1256 v1
= value_as_long (arg1
);
1257 v2
= value_as_long (arg2
);
1278 error (_("Division by zero"));
1282 v
= integer_pow (v1
, v2
);
1289 error (_("Division by zero"));
1293 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1294 X mod 0 has a defined value, X. */
1302 /* Compute floor. */
1303 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1319 case BINOP_BITWISE_AND
:
1323 case BINOP_BITWISE_IOR
:
1327 case BINOP_BITWISE_XOR
:
1331 case BINOP_LOGICAL_AND
:
1335 case BINOP_LOGICAL_OR
:
1340 v
= v1
< v2
? v1
: v2
;
1344 v
= v1
> v2
? v1
: v2
;
1351 case BINOP_NOTEQUAL
:
1372 error (_("Invalid binary operation on numbers."));
1375 val
= allocate_value (result_type
);
1376 store_signed_integer (value_contents_raw (val
),
1377 TYPE_LENGTH (value_type (val
)),
1379 (get_type_arch (result_type
)),
1387 /* Performs a binary operation on two vector operands by calling scalar_binop
1388 for each pair of vector components. */
1390 static struct value
*
1391 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1393 struct value
*val
, *tmp
, *mark
;
1394 struct type
*type1
, *type2
, *eltype1
, *eltype2
, *result_type
;
1395 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1396 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1398 type1
= check_typedef (value_type (val1
));
1399 type2
= check_typedef (value_type (val2
));
1401 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1402 && TYPE_VECTOR (type1
)) ? 1 : 0;
1403 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1404 && TYPE_VECTOR (type2
)) ? 1 : 0;
1406 if (!t1_is_vec
|| !t2_is_vec
)
1407 error (_("Vector operations are only supported among vectors"));
1409 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1410 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1411 error (_("Could not determine the vector bounds"));
1413 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1414 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1415 elsize
= TYPE_LENGTH (eltype1
);
1417 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1418 || elsize
!= TYPE_LENGTH (eltype2
)
1419 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1420 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1421 error (_("Cannot perform operation on vectors with different types"));
1423 val
= allocate_value (type1
);
1424 mark
= value_mark ();
1425 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1427 tmp
= value_binop (value_subscript (val1
, i
),
1428 value_subscript (val2
, i
), op
);
1429 memcpy (value_contents_writeable (val
) + i
* elsize
,
1430 value_contents_all (tmp
),
1433 value_free_to_mark (mark
);
1438 /* Perform a binary operation on two operands. */
1441 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1444 struct type
*type1
= check_typedef (value_type (arg1
));
1445 struct type
*type2
= check_typedef (value_type (arg2
));
1446 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1447 && TYPE_VECTOR (type1
));
1448 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1449 && TYPE_VECTOR (type2
));
1451 if (!t1_is_vec
&& !t2_is_vec
)
1452 val
= scalar_binop (arg1
, arg2
, op
);
1453 else if (t1_is_vec
&& t2_is_vec
)
1454 val
= vector_binop (arg1
, arg2
, op
);
1457 /* Widen the scalar operand to a vector. */
1458 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1459 struct type
*t
= t1_is_vec
? type2
: type1
;
1461 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1462 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1463 && !is_integral_type (t
))
1464 error (_("Argument to operation not a number or boolean."));
1466 *v
= value_cast (t1_is_vec
? type1
: type2
, *v
);
1467 val
= vector_binop (arg1
, arg2
, op
);
1473 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1476 value_logical_not (struct value
*arg1
)
1482 arg1
= coerce_array (arg1
);
1483 type1
= check_typedef (value_type (arg1
));
1485 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1486 return 0 == value_as_double (arg1
);
1487 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1488 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1489 gdbarch_byte_order (get_type_arch (type1
)));
1491 len
= TYPE_LENGTH (type1
);
1492 p
= value_contents (arg1
);
1503 /* Perform a comparison on two string values (whose content are not
1504 necessarily null terminated) based on their length. */
1507 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1509 int len1
= TYPE_LENGTH (value_type (arg1
));
1510 int len2
= TYPE_LENGTH (value_type (arg2
));
1511 const gdb_byte
*s1
= value_contents (arg1
);
1512 const gdb_byte
*s2
= value_contents (arg2
);
1513 int i
, len
= len1
< len2
? len1
: len2
;
1515 for (i
= 0; i
< len
; i
++)
1519 else if (s1
[i
] > s2
[i
])
1527 else if (len1
> len2
)
1533 /* Simulate the C operator == by returning a 1
1534 iff ARG1 and ARG2 have equal contents. */
1537 value_equal (struct value
*arg1
, struct value
*arg2
)
1542 struct type
*type1
, *type2
;
1543 enum type_code code1
;
1544 enum type_code code2
;
1545 int is_int1
, is_int2
;
1547 arg1
= coerce_array (arg1
);
1548 arg2
= coerce_array (arg2
);
1550 type1
= check_typedef (value_type (arg1
));
1551 type2
= check_typedef (value_type (arg2
));
1552 code1
= TYPE_CODE (type1
);
1553 code2
= TYPE_CODE (type2
);
1554 is_int1
= is_integral_type (type1
);
1555 is_int2
= is_integral_type (type2
);
1557 if (is_int1
&& is_int2
)
1558 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1560 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1561 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1563 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1564 `long double' values are returned in static storage (m68k). */
1565 DOUBLEST d
= value_as_double (arg1
);
1567 return d
== value_as_double (arg2
);
1569 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1570 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1572 gdb_byte v1
[16], v2
[16];
1574 enum bfd_endian byte_order_v1
, byte_order_v2
;
1576 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1577 v2
, &len_v2
, &byte_order_v2
);
1579 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1580 v2
, len_v2
, byte_order_v2
) == 0;
1583 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1585 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1586 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1587 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1588 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1590 else if (code1
== code2
1591 && ((len
= (int) TYPE_LENGTH (type1
))
1592 == (int) TYPE_LENGTH (type2
)))
1594 p1
= value_contents (arg1
);
1595 p2
= value_contents (arg2
);
1603 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1605 return value_strcmp (arg1
, arg2
) == 0;
1609 error (_("Invalid type combination in equality test."));
1610 return 0; /* For lint -- never reached. */
1614 /* Compare values based on their raw contents. Useful for arrays since
1615 value_equal coerces them to pointers, thus comparing just the address
1616 of the array instead of its contents. */
1619 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1621 struct type
*type1
, *type2
;
1623 type1
= check_typedef (value_type (arg1
));
1624 type2
= check_typedef (value_type (arg2
));
1626 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1627 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1628 && memcmp (value_contents (arg1
), value_contents (arg2
),
1629 TYPE_LENGTH (type1
)) == 0);
1632 /* Simulate the C operator < by returning 1
1633 iff ARG1's contents are less than ARG2's. */
1636 value_less (struct value
*arg1
, struct value
*arg2
)
1638 enum type_code code1
;
1639 enum type_code code2
;
1640 struct type
*type1
, *type2
;
1641 int is_int1
, is_int2
;
1643 arg1
= coerce_array (arg1
);
1644 arg2
= coerce_array (arg2
);
1646 type1
= check_typedef (value_type (arg1
));
1647 type2
= check_typedef (value_type (arg2
));
1648 code1
= TYPE_CODE (type1
);
1649 code2
= TYPE_CODE (type2
);
1650 is_int1
= is_integral_type (type1
);
1651 is_int2
= is_integral_type (type2
);
1653 if (is_int1
&& is_int2
)
1654 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1656 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1657 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1659 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1660 `long double' values are returned in static storage (m68k). */
1661 DOUBLEST d
= value_as_double (arg1
);
1663 return d
< value_as_double (arg2
);
1665 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1666 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1668 gdb_byte v1
[16], v2
[16];
1670 enum bfd_endian byte_order_v1
, byte_order_v2
;
1672 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1673 v2
, &len_v2
, &byte_order_v2
);
1675 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1676 v2
, len_v2
, byte_order_v2
) == -1;
1678 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1679 return value_as_address (arg1
) < value_as_address (arg2
);
1681 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1683 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1684 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1685 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1686 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1687 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1688 return value_strcmp (arg1
, arg2
) < 0;
1691 error (_("Invalid type combination in ordering comparison."));
1696 /* The unary operators +, - and ~. They free the argument ARG1. */
1699 value_pos (struct value
*arg1
)
1703 arg1
= coerce_ref (arg1
);
1704 type
= check_typedef (value_type (arg1
));
1706 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1707 return value_from_double (type
, value_as_double (arg1
));
1708 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1709 return value_from_decfloat (type
, value_contents (arg1
));
1710 else if (is_integral_type (type
))
1712 return value_from_longest (type
, value_as_long (arg1
));
1714 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1716 struct value
*val
= allocate_value (type
);
1718 memcpy (value_contents_raw (val
), value_contents (arg1
),
1719 TYPE_LENGTH (type
));
1724 error (_("Argument to positive operation not a number."));
1725 return 0; /* For lint -- never reached. */
1730 value_neg (struct value
*arg1
)
1734 arg1
= coerce_ref (arg1
);
1735 type
= check_typedef (value_type (arg1
));
1737 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1739 struct value
*val
= allocate_value (type
);
1740 int len
= TYPE_LENGTH (type
);
1741 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long. */
1743 memcpy (decbytes
, value_contents (arg1
), len
);
1745 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1746 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1748 decbytes
[0] = decbytes
[0] | 0x80;
1750 memcpy (value_contents_raw (val
), decbytes
, len
);
1753 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1754 return value_from_double (type
, -value_as_double (arg1
));
1755 else if (is_integral_type (type
))
1757 return value_from_longest (type
, -value_as_long (arg1
));
1759 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1761 struct value
*tmp
, *val
= allocate_value (type
);
1762 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1764 LONGEST low_bound
, high_bound
;
1766 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1767 error (_("Could not determine the vector bounds"));
1769 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1771 tmp
= value_neg (value_subscript (arg1
, i
));
1772 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1773 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1779 error (_("Argument to negate operation not a number."));
1780 return 0; /* For lint -- never reached. */
1785 value_complement (struct value
*arg1
)
1790 arg1
= coerce_ref (arg1
);
1791 type
= check_typedef (value_type (arg1
));
1793 if (is_integral_type (type
))
1794 val
= value_from_longest (type
, ~value_as_long (arg1
));
1795 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1798 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1800 LONGEST low_bound
, high_bound
;
1802 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1803 error (_("Could not determine the vector bounds"));
1805 val
= allocate_value (type
);
1806 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1808 tmp
= value_complement (value_subscript (arg1
, i
));
1809 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1810 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1814 error (_("Argument to complement operation not an integer, boolean."));
1819 /* The INDEX'th bit of SET value whose value_type is TYPE,
1820 and whose value_contents is valaddr.
1821 Return -1 if out of range, -2 other error. */
1824 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1826 struct gdbarch
*gdbarch
= get_type_arch (type
);
1827 LONGEST low_bound
, high_bound
;
1830 struct type
*range
= TYPE_INDEX_TYPE (type
);
1832 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1834 if (index
< low_bound
|| index
> high_bound
)
1836 rel_index
= index
- low_bound
;
1837 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1838 gdbarch_byte_order (gdbarch
));
1839 rel_index
%= TARGET_CHAR_BIT
;
1840 if (gdbarch_bits_big_endian (gdbarch
))
1841 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1842 return (word
>> rel_index
) & 1;
1846 value_in (struct value
*element
, struct value
*set
)
1849 struct type
*settype
= check_typedef (value_type (set
));
1850 struct type
*eltype
= check_typedef (value_type (element
));
1852 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1853 eltype
= TYPE_TARGET_TYPE (eltype
);
1854 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1855 error (_("Second argument of 'IN' has wrong type"));
1856 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1857 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1858 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1859 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1860 error (_("First argument of 'IN' has wrong type"));
1861 member
= value_bit_index (settype
, value_contents (set
),
1862 value_as_long (element
));
1864 error (_("First argument of 'IN' not in range"));
1869 _initialize_valarith (void)
This page took 0.067455 seconds and 4 git commands to generate.