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 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.
54 find_size_for_pointer_math (struct type
*ptr_type
)
57 struct type
*ptr_target
;
59 gdb_assert (TYPE_CODE (ptr_type
) == TYPE_CODE_PTR
);
60 ptr_target
= check_typedef (TYPE_TARGET_TYPE (ptr_type
));
62 sz
= TYPE_LENGTH (ptr_target
);
65 if (TYPE_CODE (ptr_type
) == TYPE_CODE_VOID
)
71 name
= TYPE_NAME (ptr_target
);
73 name
= TYPE_TAG_NAME (ptr_target
);
75 error (_("Cannot perform pointer math on incomplete types, "
76 "try casting to a known type, or void *."));
78 error (_("Cannot perform pointer math on incomplete type \"%s\", "
79 "try casting to a known type, or void *."), name
);
85 /* Given a pointer ARG1 and an integral value ARG2, return the
86 result of C-style pointer arithmetic ARG1 + ARG2. */
89 value_ptradd (struct value
*arg1
, LONGEST arg2
)
91 struct type
*valptrtype
;
94 arg1
= coerce_array (arg1
);
95 valptrtype
= check_typedef (value_type (arg1
));
96 sz
= find_size_for_pointer_math (valptrtype
);
98 return value_from_pointer (valptrtype
,
99 value_as_address (arg1
) + sz
* arg2
);
102 /* Given two compatible pointer values ARG1 and ARG2, return the
103 result of C-style pointer arithmetic ARG1 - ARG2. */
106 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
108 struct type
*type1
, *type2
;
111 arg1
= coerce_array (arg1
);
112 arg2
= coerce_array (arg2
);
113 type1
= check_typedef (value_type (arg1
));
114 type2
= check_typedef (value_type (arg2
));
116 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
117 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
119 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
120 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
122 First argument of `-' is a pointer and second argument is neither\n\
123 an integer nor a pointer of the same type."));
125 sz
= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)));
128 warning (_("Type size unknown, assuming 1. "
129 "Try casting to a known type, or void *."));
133 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
136 /* Return the value of ARRAY[IDX].
138 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
139 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
140 To access TYPE_CODE_BITSTRING values, use value_bitstring_subscript.
142 See comments in value_coerce_array() for rationale for reason for
143 doing lower bounds adjustment here rather than there.
144 FIXME: Perhaps we should validate that the index is valid and if
145 verbosity is set, warn about invalid indices (but still use them). */
148 value_subscript (struct value
*array
, LONGEST index
)
150 int c_style
= current_language
->c_style_arrays
;
153 array
= coerce_ref (array
);
154 tarray
= check_typedef (value_type (array
));
156 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
157 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
159 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
160 LONGEST lowerbound
, upperbound
;
162 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
163 if (VALUE_LVAL (array
) != lval_memory
)
164 return value_subscripted_rvalue (array
, index
, lowerbound
);
168 if (index
>= lowerbound
&& index
<= upperbound
)
169 return value_subscripted_rvalue (array
, index
, lowerbound
);
170 /* Emit warning unless we have an array of unknown size.
171 An array of unknown size has lowerbound 0 and upperbound -1. */
173 warning (_("array or string index out of range"));
174 /* fall doing C stuff */
179 array
= value_coerce_array (array
);
183 return value_ind (value_ptradd (array
, index
));
185 error (_("not an array or string"));
188 /* Return the value of EXPR[IDX], expr an aggregate rvalue
189 (eg, a vector register). This routine used to promote floats
190 to doubles, but no longer does. */
193 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
195 struct type
*array_type
= check_typedef (value_type (array
));
196 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
197 unsigned int elt_size
= TYPE_LENGTH (elt_type
);
198 unsigned int elt_offs
= elt_size
* longest_to_int (index
- lowerbound
);
201 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
202 && elt_offs
>= TYPE_LENGTH (array_type
)))
203 error (_("no such vector element"));
205 v
= allocate_value (elt_type
);
206 if (VALUE_LVAL (array
) == lval_memory
&& value_lazy (array
))
207 set_value_lazy (v
, 1);
209 memcpy (value_contents_writeable (v
),
210 value_contents (array
) + elt_offs
, elt_size
);
212 set_value_component_location (v
, array
);
213 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
214 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
215 set_value_offset (v
, value_offset (array
) + elt_offs
);
219 /* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */
222 value_bitstring_subscript (struct type
*type
,
223 struct value
*bitstring
, LONGEST index
)
226 struct type
*bitstring_type
, *range_type
;
228 int offset
, byte
, bit_index
;
229 LONGEST lowerbound
, upperbound
;
231 bitstring_type
= check_typedef (value_type (bitstring
));
232 gdb_assert (TYPE_CODE (bitstring_type
) == TYPE_CODE_BITSTRING
);
234 range_type
= TYPE_INDEX_TYPE (bitstring_type
);
235 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
236 if (index
< lowerbound
|| index
> upperbound
)
237 error (_("bitstring index out of range"));
240 offset
= index
/ TARGET_CHAR_BIT
;
241 byte
= *((char *) value_contents (bitstring
) + offset
);
243 bit_index
= index
% TARGET_CHAR_BIT
;
244 byte
>>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type
)) ?
245 TARGET_CHAR_BIT
- 1 - bit_index
: bit_index
);
247 v
= value_from_longest (type
, byte
& 1);
249 set_value_bitpos (v
, bit_index
);
250 set_value_bitsize (v
, 1);
251 set_value_component_location (v
, bitstring
);
252 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (bitstring
);
254 set_value_offset (v
, offset
+ value_offset (bitstring
));
260 /* Check to see if either argument is a structure, or a reference to
261 one. This is called so we know whether to go ahead with the normal
262 binop or look for a user defined function instead.
264 For now, we do not overload the `=' operator. */
267 binop_types_user_defined_p (enum exp_opcode op
,
268 struct type
*type1
, struct type
*type2
)
270 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
273 type1
= check_typedef (type1
);
274 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
275 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
277 type2
= check_typedef (type1
);
278 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
279 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
281 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
282 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
285 /* Check to see if either argument is a structure, or a reference to
286 one. This is called so we know whether to go ahead with the normal
287 binop or look for a user defined function instead.
289 For now, we do not overload the `=' operator. */
292 binop_user_defined_p (enum exp_opcode op
,
293 struct value
*arg1
, struct value
*arg2
)
295 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
298 /* Check to see if argument is a structure. This is called so
299 we know whether to go ahead with the normal unop or look for a
300 user defined function instead.
302 For now, we do not overload the `&' operator. */
305 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
311 type1
= check_typedef (value_type (arg1
));
314 if (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
)
316 else if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
317 type1
= TYPE_TARGET_TYPE (type1
);
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
;
338 struct type
**arg_types
;
341 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
342 /* Prepare list of argument types for overload resolution */
343 for (i
= 0; i
< nargs
; i
++)
344 arg_types
[i
] = value_type (args
[i
]);
346 find_overload_match (arg_types
, nargs
, operator, BOTH
/* could be method */,
347 0 /* strict match */, &args
[0], /* objp */
348 NULL
/* pass NULL symbol since symbol is unknown */,
349 &valp
, &symp
, static_memfuncp
, 0);
356 /* This is a non member function and does not
357 expect a reference as its first argument
358 rather the explicit structure. */
359 args
[0] = value_ind (args
[0]);
360 return value_of_variable (symp
, 0);
363 error (_("Could not find %s."), operator);
366 /* Lookup user defined operator NAME. Return a value representing the
367 function, otherwise return NULL. */
369 static struct value
*
370 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
371 int *static_memfuncp
, int nargs
)
373 struct value
*result
= NULL
;
375 if (current_language
->la_language
== language_cplus
)
376 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
);
378 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
384 /* We know either arg1 or arg2 is a structure, so try to find the right
385 user defined function. Create an argument vector that calls
386 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
387 binary operator which is legal for GNU C++).
389 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
390 is the opcode saying how to modify it. Otherwise, OTHEROP is
394 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
395 enum exp_opcode otherop
, enum noside noside
)
397 struct value
**argvec
;
402 arg1
= coerce_ref (arg1
);
403 arg2
= coerce_ref (arg2
);
405 /* now we know that what we have to do is construct our
406 arg vector and find the right function to call it with. */
408 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
409 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
411 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
412 argvec
[1] = value_addr (arg1
);
416 /* make the right function name up */
417 strcpy (tstr
, "operator__");
442 case BINOP_BITWISE_AND
:
445 case BINOP_BITWISE_IOR
:
448 case BINOP_BITWISE_XOR
:
451 case BINOP_LOGICAL_AND
:
454 case BINOP_LOGICAL_OR
:
466 case BINOP_ASSIGN_MODIFY
:
484 case BINOP_BITWISE_AND
:
487 case BINOP_BITWISE_IOR
:
490 case BINOP_BITWISE_XOR
:
493 case BINOP_MOD
: /* invalid */
495 error (_("Invalid binary operation specified."));
498 case BINOP_SUBSCRIPT
:
519 case BINOP_MOD
: /* invalid */
521 error (_("Invalid binary operation specified."));
524 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
525 &static_memfuncp
, 2);
531 argvec
[1] = argvec
[0];
534 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
536 struct type
*return_type
;
539 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
540 return value_zero (return_type
, VALUE_LVAL (arg1
));
542 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
544 throw_error (NOT_FOUND_ERROR
,
545 _("member function %s not found"), tstr
);
547 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
551 /* We know that arg1 is a structure, so try to find a unary user
552 defined operator that matches the operator in question.
553 Create an argument vector that calls arg1.operator @ (arg1)
554 and return that value (where '@' is (almost) any unary operator which
555 is legal for GNU C++). */
558 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
560 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
561 struct value
**argvec
;
562 char *ptr
, *mangle_ptr
;
563 char tstr
[13], mangle_tstr
[13];
564 int static_memfuncp
, nargs
;
566 arg1
= coerce_ref (arg1
);
568 /* now we know that what we have to do is construct our
569 arg vector and find the right function to call it with. */
571 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
572 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
574 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
575 argvec
[1] = value_addr (arg1
);
580 /* make the right function name up */
581 strcpy (tstr
, "operator__");
583 strcpy (mangle_tstr
, "__");
584 mangle_ptr
= mangle_tstr
+ 2;
587 case UNOP_PREINCREMENT
:
590 case UNOP_PREDECREMENT
:
593 case UNOP_POSTINCREMENT
:
595 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
599 case UNOP_POSTDECREMENT
:
601 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
605 case UNOP_LOGICAL_NOT
:
608 case UNOP_COMPLEMENT
:
624 error (_("Invalid unary operation specified."));
627 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
628 &static_memfuncp
, nargs
);
634 argvec
[1] = argvec
[0];
638 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
640 struct type
*return_type
;
643 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
644 return value_zero (return_type
, VALUE_LVAL (arg1
));
646 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
648 throw_error (NOT_FOUND_ERROR
,
649 _("member function %s not found"), tstr
);
651 return 0; /* For lint -- never reached */
655 /* Concatenate two values with the following conditions:
657 (1) Both values must be either bitstring values or character string
658 values and the resulting value consists of the concatenation of
659 ARG1 followed by ARG2.
663 One value must be an integer value and the other value must be
664 either a bitstring value or character string value, which is
665 to be repeated by the number of times specified by the integer
669 (2) Boolean values are also allowed and are treated as bit string
672 (3) Character values are also allowed and are treated as character
673 string values of length 1.
677 value_concat (struct value
*arg1
, struct value
*arg2
)
679 struct value
*inval1
;
680 struct value
*inval2
;
681 struct value
*outval
= NULL
;
682 int inval1len
, inval2len
;
686 struct type
*type1
= check_typedef (value_type (arg1
));
687 struct type
*type2
= check_typedef (value_type (arg2
));
688 struct type
*char_type
;
690 /* First figure out if we are dealing with two values to be concatenated
691 or a repeat count and a value to be repeated. INVAL1 is set to the
692 first of two concatenated values, or the repeat count. INVAL2 is set
693 to the second of the two concatenated values or the value to be
696 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
698 struct type
*tmp
= type1
;
711 /* Now process the input values. */
713 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
715 /* We have a repeat count. Validate the second value and then
716 construct a value repeated that many times. */
717 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
718 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
720 count
= longest_to_int (value_as_long (inval1
));
721 inval2len
= TYPE_LENGTH (type2
);
722 ptr
= (char *) alloca (count
* inval2len
);
723 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
727 inchar
= (char) unpack_long (type2
,
728 value_contents (inval2
));
729 for (idx
= 0; idx
< count
; idx
++)
731 *(ptr
+ idx
) = inchar
;
736 char_type
= TYPE_TARGET_TYPE (type2
);
738 for (idx
= 0; idx
< count
; idx
++)
740 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
744 outval
= value_string (ptr
, count
* inval2len
, char_type
);
746 else if (TYPE_CODE (type2
) == TYPE_CODE_BITSTRING
747 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
749 error (_("unimplemented support for bitstring/boolean repeats"));
753 error (_("can't repeat values of that type"));
756 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
757 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
759 /* We have two character strings to concatenate. */
760 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
761 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
763 error (_("Strings can only be concatenated with other strings."));
765 inval1len
= TYPE_LENGTH (type1
);
766 inval2len
= TYPE_LENGTH (type2
);
767 ptr
= (char *) alloca (inval1len
+ inval2len
);
768 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
772 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
776 char_type
= TYPE_TARGET_TYPE (type1
);
778 memcpy (ptr
, value_contents (inval1
), inval1len
);
780 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
783 (char) unpack_long (type2
, value_contents (inval2
));
787 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
789 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
791 else if (TYPE_CODE (type1
) == TYPE_CODE_BITSTRING
792 || TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
794 /* We have two bitstrings to concatenate. */
795 if (TYPE_CODE (type2
) != TYPE_CODE_BITSTRING
796 && TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
798 error (_("Bitstrings or booleans can only be concatenated with other bitstrings or booleans."));
800 error (_("unimplemented support for bitstring/boolean concatenation."));
804 /* We don't know how to concatenate these operands. */
805 error (_("illegal operands for concatenation."));
810 /* Integer exponentiation: V1**V2, where both arguments are
811 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
813 integer_pow (LONGEST v1
, LONGEST v2
)
818 error (_("Attempt to raise 0 to negative power."));
824 /* The Russian Peasant's Algorithm */
840 /* Integer exponentiation: V1**V2, where both arguments are
841 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
843 uinteger_pow (ULONGEST v1
, LONGEST v2
)
848 error (_("Attempt to raise 0 to negative power."));
854 /* The Russian Peasant's Algorithm */
870 /* Obtain decimal value of arguments for binary operation, converting from
871 other types if one of them is not decimal floating point. */
873 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
874 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
875 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
877 struct type
*type1
, *type2
;
879 type1
= check_typedef (value_type (arg1
));
880 type2
= check_typedef (value_type (arg2
));
882 /* At least one of the arguments must be of decimal float type. */
883 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
884 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
886 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
887 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
888 /* The DFP extension to the C language does not allow mixing of
889 * decimal float types with other float types in expressions
890 * (see WDTR 24732, page 12). */
891 error (_("Mixing decimal floating types with other floating types is not allowed."));
893 /* Obtain decimal value of arg1, converting from other types
896 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
898 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
899 *len_x
= TYPE_LENGTH (type1
);
900 memcpy (x
, value_contents (arg1
), *len_x
);
902 else if (is_integral_type (type1
))
904 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
905 *len_x
= TYPE_LENGTH (type2
);
906 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
909 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
912 /* Obtain decimal value of arg2, converting from other types
915 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
917 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
918 *len_y
= TYPE_LENGTH (type2
);
919 memcpy (y
, value_contents (arg2
), *len_y
);
921 else if (is_integral_type (type2
))
923 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
924 *len_y
= TYPE_LENGTH (type1
);
925 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
928 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
932 /* Perform a binary operation on two operands which have reasonable
933 representations as integers or floats. This includes booleans,
934 characters, integers, or floats.
935 Does not support addition and subtraction on pointers;
936 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
938 static struct value
*
939 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
942 struct type
*type1
, *type2
, *result_type
;
944 arg1
= coerce_ref (arg1
);
945 arg2
= coerce_ref (arg2
);
947 type1
= check_typedef (value_type (arg1
));
948 type2
= check_typedef (value_type (arg2
));
950 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
951 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
952 && !is_integral_type (type1
))
953 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
954 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
955 && !is_integral_type (type2
)))
956 error (_("Argument to arithmetic operation not a number or boolean."));
958 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
959 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
961 int len_v1
, len_v2
, len_v
;
962 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
963 gdb_byte v1
[16], v2
[16];
966 /* If only one type is decimal float, use its type.
967 Otherwise use the bigger type. */
968 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
970 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
972 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
977 len_v
= TYPE_LENGTH (result_type
);
978 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
980 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
981 v2
, &len_v2
, &byte_order_v2
);
990 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
991 v2
, len_v2
, byte_order_v2
,
992 v
, len_v
, byte_order_v
);
996 error (_("Operation not valid for decimal floating point number."));
999 val
= value_from_decfloat (result_type
, v
);
1001 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
1002 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
1004 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
1005 in target format. real.c in GCC probably has the necessary
1007 DOUBLEST v1
, v2
, v
= 0;
1009 v1
= value_as_double (arg1
);
1010 v2
= value_as_double (arg2
);
1034 error (_("Cannot perform exponentiation: %s"), safe_strerror (errno
));
1038 v
= v1
< v2
? v1
: v2
;
1042 v
= v1
> v2
? v1
: v2
;
1046 error (_("Integer-only operation on floating point number."));
1049 /* If only one type is float, use its type.
1050 Otherwise use the bigger type. */
1051 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1052 result_type
= type2
;
1053 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1054 result_type
= type1
;
1055 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1056 result_type
= type2
;
1058 result_type
= type1
;
1060 val
= allocate_value (result_type
);
1061 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1063 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1064 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1066 LONGEST v1
, v2
, v
= 0;
1068 v1
= value_as_long (arg1
);
1069 v2
= value_as_long (arg2
);
1073 case BINOP_BITWISE_AND
:
1077 case BINOP_BITWISE_IOR
:
1081 case BINOP_BITWISE_XOR
:
1089 case BINOP_NOTEQUAL
:
1094 error (_("Invalid operation on booleans."));
1097 result_type
= type1
;
1099 val
= allocate_value (result_type
);
1100 store_signed_integer (value_contents_raw (val
),
1101 TYPE_LENGTH (result_type
),
1102 gdbarch_byte_order (get_type_arch (result_type
)),
1106 /* Integral operations here. */
1108 /* Determine type length of the result, and if the operation should
1109 be done unsigned. For exponentiation and shift operators,
1110 use the length and type of the left operand. Otherwise,
1111 use the signedness of the operand with the greater length.
1112 If both operands are of equal length, use unsigned operation
1113 if one of the operands is unsigned. */
1114 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1115 result_type
= type1
;
1116 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1117 result_type
= type1
;
1118 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1119 result_type
= type2
;
1120 else if (TYPE_UNSIGNED (type1
))
1121 result_type
= type1
;
1122 else if (TYPE_UNSIGNED (type2
))
1123 result_type
= type2
;
1125 result_type
= type1
;
1127 if (TYPE_UNSIGNED (result_type
))
1129 LONGEST v2_signed
= value_as_long (arg2
);
1130 ULONGEST v1
, v2
, v
= 0;
1132 v1
= (ULONGEST
) value_as_long (arg1
);
1133 v2
= (ULONGEST
) v2_signed
;
1154 error (_("Division by zero"));
1158 v
= uinteger_pow (v1
, v2_signed
);
1165 error (_("Division by zero"));
1169 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1170 v1 mod 0 has a defined value, v1. */
1178 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1191 case BINOP_BITWISE_AND
:
1195 case BINOP_BITWISE_IOR
:
1199 case BINOP_BITWISE_XOR
:
1203 case BINOP_LOGICAL_AND
:
1207 case BINOP_LOGICAL_OR
:
1212 v
= v1
< v2
? v1
: v2
;
1216 v
= v1
> v2
? v1
: v2
;
1223 case BINOP_NOTEQUAL
:
1244 error (_("Invalid binary operation on numbers."));
1247 val
= allocate_value (result_type
);
1248 store_unsigned_integer (value_contents_raw (val
),
1249 TYPE_LENGTH (value_type (val
)),
1251 (get_type_arch (result_type
)),
1256 LONGEST v1
, v2
, v
= 0;
1258 v1
= value_as_long (arg1
);
1259 v2
= value_as_long (arg2
);
1280 error (_("Division by zero"));
1284 v
= integer_pow (v1
, v2
);
1291 error (_("Division by zero"));
1295 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1296 X mod 0 has a defined value, X. */
1304 /* Compute floor. */
1305 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1321 case BINOP_BITWISE_AND
:
1325 case BINOP_BITWISE_IOR
:
1329 case BINOP_BITWISE_XOR
:
1333 case BINOP_LOGICAL_AND
:
1337 case BINOP_LOGICAL_OR
:
1342 v
= v1
< v2
? v1
: v2
;
1346 v
= v1
> v2
? v1
: v2
;
1353 case BINOP_NOTEQUAL
:
1374 error (_("Invalid binary operation on numbers."));
1377 val
= allocate_value (result_type
);
1378 store_signed_integer (value_contents_raw (val
),
1379 TYPE_LENGTH (value_type (val
)),
1381 (get_type_arch (result_type
)),
1389 /* Performs a binary operation on two vector operands by calling scalar_binop
1390 for each pair of vector components. */
1392 static struct value
*
1393 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1395 struct value
*val
, *tmp
, *mark
;
1396 struct type
*type1
, *type2
, *eltype1
, *eltype2
, *result_type
;
1397 int t1_is_vec
, t2_is_vec
, elsize
, n
, i
;
1399 type1
= check_typedef (value_type (val1
));
1400 type2
= check_typedef (value_type (val2
));
1402 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1403 && TYPE_VECTOR (type1
)) ? 1 : 0;
1404 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1405 && TYPE_VECTOR (type2
)) ? 1 : 0;
1407 if (!t1_is_vec
|| !t2_is_vec
)
1408 error (_("Vector operations are only supported among vectors"));
1410 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1411 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1413 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1414 || TYPE_LENGTH (eltype1
) != TYPE_LENGTH (eltype2
)
1415 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
))
1416 error (_("Cannot perform operation on vectors with different types"));
1418 elsize
= TYPE_LENGTH (eltype1
);
1419 n
= TYPE_LENGTH (type1
) / elsize
;
1421 if (n
!= TYPE_LENGTH (type2
) / TYPE_LENGTH (eltype2
))
1422 error (_("Cannot perform operation on vectors with different sizes"));
1424 val
= allocate_value (type1
);
1425 mark
= value_mark ();
1426 for (i
= 0; i
< n
; i
++)
1428 tmp
= value_binop (value_subscript (val1
, i
),
1429 value_subscript (val2
, i
), op
);
1430 memcpy (value_contents_writeable (val
) + i
* elsize
,
1431 value_contents_all (tmp
),
1434 value_free_to_mark (mark
);
1439 /* Perform a binary operation on two operands. */
1442 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1445 struct type
*type1
= check_typedef (value_type (arg1
));
1446 struct type
*type2
= check_typedef (value_type (arg2
));
1447 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1448 && TYPE_VECTOR (type1
));
1449 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1450 && TYPE_VECTOR (type2
));
1452 if (!t1_is_vec
&& !t2_is_vec
)
1453 val
= scalar_binop (arg1
, arg2
, op
);
1454 else if (t1_is_vec
&& t2_is_vec
)
1455 val
= vector_binop (arg1
, arg2
, op
);
1458 /* Widen the scalar operand to a vector. */
1459 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1460 struct type
*t
= t1_is_vec
? type2
: type1
;
1462 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1463 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1464 && !is_integral_type (t
))
1465 error (_("Argument to operation not a number or boolean."));
1467 *v
= value_cast (t1_is_vec
? type1
: type2
, *v
);
1468 val
= vector_binop (arg1
, arg2
, op
);
1474 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1477 value_logical_not (struct value
*arg1
)
1483 arg1
= coerce_array (arg1
);
1484 type1
= check_typedef (value_type (arg1
));
1486 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1487 return 0 == value_as_double (arg1
);
1488 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1489 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1490 gdbarch_byte_order (get_type_arch (type1
)));
1492 len
= TYPE_LENGTH (type1
);
1493 p
= value_contents (arg1
);
1504 /* Perform a comparison on two string values (whose content are not
1505 necessarily null terminated) based on their length */
1508 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1510 int len1
= TYPE_LENGTH (value_type (arg1
));
1511 int len2
= TYPE_LENGTH (value_type (arg2
));
1512 const gdb_byte
*s1
= value_contents (arg1
);
1513 const gdb_byte
*s2
= value_contents (arg2
);
1514 int i
, len
= len1
< len2
? len1
: len2
;
1516 for (i
= 0; i
< len
; i
++)
1520 else if (s1
[i
] > s2
[i
])
1528 else if (len1
> len2
)
1534 /* Simulate the C operator == by returning a 1
1535 iff ARG1 and ARG2 have equal contents. */
1538 value_equal (struct value
*arg1
, struct value
*arg2
)
1543 struct type
*type1
, *type2
;
1544 enum type_code code1
;
1545 enum type_code code2
;
1546 int is_int1
, is_int2
;
1548 arg1
= coerce_array (arg1
);
1549 arg2
= coerce_array (arg2
);
1551 type1
= check_typedef (value_type (arg1
));
1552 type2
= check_typedef (value_type (arg2
));
1553 code1
= TYPE_CODE (type1
);
1554 code2
= TYPE_CODE (type2
);
1555 is_int1
= is_integral_type (type1
);
1556 is_int2
= is_integral_type (type2
);
1558 if (is_int1
&& is_int2
)
1559 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1561 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1562 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1564 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1565 `long double' values are returned in static storage (m68k). */
1566 DOUBLEST d
= value_as_double (arg1
);
1568 return d
== value_as_double (arg2
);
1570 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1571 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1573 gdb_byte v1
[16], v2
[16];
1575 enum bfd_endian byte_order_v1
, byte_order_v2
;
1577 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1578 v2
, &len_v2
, &byte_order_v2
);
1580 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1581 v2
, len_v2
, byte_order_v2
) == 0;
1584 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1586 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1587 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1588 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1589 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1591 else if (code1
== code2
1592 && ((len
= (int) TYPE_LENGTH (type1
))
1593 == (int) TYPE_LENGTH (type2
)))
1595 p1
= value_contents (arg1
);
1596 p2
= value_contents (arg2
);
1604 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1606 return value_strcmp (arg1
, arg2
) == 0;
1610 error (_("Invalid type combination in equality test."));
1611 return 0; /* For lint -- never reached */
1615 /* Compare values based on their raw contents. Useful for arrays since
1616 value_equal coerces them to pointers, thus comparing just the address
1617 of the array instead of its contents. */
1620 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1622 struct type
*type1
, *type2
;
1624 type1
= check_typedef (value_type (arg1
));
1625 type2
= check_typedef (value_type (arg2
));
1627 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1628 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1629 && memcmp (value_contents (arg1
), value_contents (arg2
),
1630 TYPE_LENGTH (type1
)) == 0);
1633 /* Simulate the C operator < by returning 1
1634 iff ARG1's contents are less than ARG2's. */
1637 value_less (struct value
*arg1
, struct value
*arg2
)
1639 enum type_code code1
;
1640 enum type_code code2
;
1641 struct type
*type1
, *type2
;
1642 int is_int1
, is_int2
;
1644 arg1
= coerce_array (arg1
);
1645 arg2
= coerce_array (arg2
);
1647 type1
= check_typedef (value_type (arg1
));
1648 type2
= check_typedef (value_type (arg2
));
1649 code1
= TYPE_CODE (type1
);
1650 code2
= TYPE_CODE (type2
);
1651 is_int1
= is_integral_type (type1
);
1652 is_int2
= is_integral_type (type2
);
1654 if (is_int1
&& is_int2
)
1655 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1657 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1658 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1660 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1661 `long double' values are returned in static storage (m68k). */
1662 DOUBLEST d
= value_as_double (arg1
);
1664 return d
< value_as_double (arg2
);
1666 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1667 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1669 gdb_byte v1
[16], v2
[16];
1671 enum bfd_endian byte_order_v1
, byte_order_v2
;
1673 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1674 v2
, &len_v2
, &byte_order_v2
);
1676 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1677 v2
, len_v2
, byte_order_v2
) == -1;
1679 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1680 return value_as_address (arg1
) < value_as_address (arg2
);
1682 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1684 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1685 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1686 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1687 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1688 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1689 return value_strcmp (arg1
, arg2
) < 0;
1692 error (_("Invalid type combination in ordering comparison."));
1697 /* The unary operators +, - and ~. They free the argument ARG1. */
1700 value_pos (struct value
*arg1
)
1704 arg1
= coerce_ref (arg1
);
1705 type
= check_typedef (value_type (arg1
));
1707 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1708 return value_from_double (type
, value_as_double (arg1
));
1709 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1710 return value_from_decfloat (type
, value_contents (arg1
));
1711 else if (is_integral_type (type
))
1713 return value_from_longest (type
, value_as_long (arg1
));
1715 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1717 struct value
*val
= allocate_value (type
);
1719 memcpy (value_contents_raw (val
), value_contents (arg1
),
1720 TYPE_LENGTH (type
));
1725 error ("Argument to positive operation not a number.");
1726 return 0; /* For lint -- never reached */
1731 value_neg (struct value
*arg1
)
1735 arg1
= coerce_ref (arg1
);
1736 type
= check_typedef (value_type (arg1
));
1738 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1740 struct value
*val
= allocate_value (type
);
1741 int len
= TYPE_LENGTH (type
);
1742 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long */
1744 memcpy (decbytes
, value_contents (arg1
), len
);
1746 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1747 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1749 decbytes
[0] = decbytes
[0] | 0x80;
1751 memcpy (value_contents_raw (val
), decbytes
, len
);
1754 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1755 return value_from_double (type
, -value_as_double (arg1
));
1756 else if (is_integral_type (type
))
1758 return value_from_longest (type
, -value_as_long (arg1
));
1760 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1762 struct value
*tmp
, *val
= allocate_value (type
);
1763 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1764 int i
, n
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1766 for (i
= 0; i
< n
; i
++)
1768 tmp
= value_neg (value_subscript (arg1
, i
));
1769 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1770 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1776 error (_("Argument to negate operation not a number."));
1777 return 0; /* For lint -- never reached */
1782 value_complement (struct value
*arg1
)
1787 arg1
= coerce_ref (arg1
);
1788 type
= check_typedef (value_type (arg1
));
1790 if (is_integral_type (type
))
1791 val
= value_from_longest (type
, ~value_as_long (arg1
));
1792 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1795 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1796 int i
, n
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1798 val
= allocate_value (type
);
1799 for (i
= 0; i
< n
; i
++)
1801 tmp
= value_complement (value_subscript (arg1
, i
));
1802 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1803 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1807 error (_("Argument to complement operation not an integer, boolean."));
1812 /* The INDEX'th bit of SET value whose value_type is TYPE,
1813 and whose value_contents is valaddr.
1814 Return -1 if out of range, -2 other error. */
1817 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1819 struct gdbarch
*gdbarch
= get_type_arch (type
);
1820 LONGEST low_bound
, high_bound
;
1823 struct type
*range
= TYPE_INDEX_TYPE (type
);
1825 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1827 if (index
< low_bound
|| index
> high_bound
)
1829 rel_index
= index
- low_bound
;
1830 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1831 gdbarch_byte_order (gdbarch
));
1832 rel_index
%= TARGET_CHAR_BIT
;
1833 if (gdbarch_bits_big_endian (gdbarch
))
1834 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1835 return (word
>> rel_index
) & 1;
1839 value_in (struct value
*element
, struct value
*set
)
1842 struct type
*settype
= check_typedef (value_type (set
));
1843 struct type
*eltype
= check_typedef (value_type (element
));
1845 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1846 eltype
= TYPE_TARGET_TYPE (eltype
);
1847 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1848 error (_("Second argument of 'IN' has wrong type"));
1849 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1850 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1851 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1852 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1853 error (_("First argument of 'IN' has wrong type"));
1854 member
= value_bit_index (settype
, value_contents (set
),
1855 value_as_long (element
));
1857 error (_("First argument of 'IN' not in range"));
1862 _initialize_valarith (void)
This page took 0.066857 seconds and 5 git commands to generate.