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
;
95 arg1
= coerce_array (arg1
);
96 valptrtype
= check_typedef (value_type (arg1
));
97 sz
= find_size_for_pointer_math (valptrtype
);
99 result
= value_from_pointer (valptrtype
,
100 value_as_address (arg1
) + sz
* arg2
);
101 if (VALUE_LVAL (result
) != lval_internalvar
)
102 set_value_component_location (result
, arg1
);
106 /* Given two compatible pointer values ARG1 and ARG2, return the
107 result of C-style pointer arithmetic ARG1 - ARG2. */
110 value_ptrdiff (struct value
*arg1
, struct value
*arg2
)
112 struct type
*type1
, *type2
;
115 arg1
= coerce_array (arg1
);
116 arg2
= coerce_array (arg2
);
117 type1
= check_typedef (value_type (arg1
));
118 type2
= check_typedef (value_type (arg2
));
120 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_PTR
);
121 gdb_assert (TYPE_CODE (type2
) == TYPE_CODE_PTR
);
123 if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)))
124 != TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2
))))
126 First argument of `-' is a pointer and second argument is neither\n\
127 an integer nor a pointer of the same type."));
129 sz
= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1
)));
132 warning (_("Type size unknown, assuming 1. "
133 "Try casting to a known type, or void *."));
137 return (value_as_long (arg1
) - value_as_long (arg2
)) / sz
;
140 /* Return the value of ARRAY[IDX].
142 ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
143 current language supports C-style arrays, it may also be TYPE_CODE_PTR.
144 To access TYPE_CODE_BITSTRING values, use value_bitstring_subscript.
146 See comments in value_coerce_array() for rationale for reason for
147 doing lower bounds adjustment here rather than there.
148 FIXME: Perhaps we should validate that the index is valid and if
149 verbosity is set, warn about invalid indices (but still use them). */
152 value_subscript (struct value
*array
, LONGEST index
)
154 int c_style
= current_language
->c_style_arrays
;
157 array
= coerce_ref (array
);
158 tarray
= check_typedef (value_type (array
));
160 if (TYPE_CODE (tarray
) == TYPE_CODE_ARRAY
161 || TYPE_CODE (tarray
) == TYPE_CODE_STRING
)
163 struct type
*range_type
= TYPE_INDEX_TYPE (tarray
);
164 LONGEST lowerbound
, upperbound
;
166 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
167 if (VALUE_LVAL (array
) != lval_memory
)
168 return value_subscripted_rvalue (array
, index
, lowerbound
);
172 if (index
>= lowerbound
&& index
<= upperbound
)
173 return value_subscripted_rvalue (array
, index
, lowerbound
);
174 /* Emit warning unless we have an array of unknown size.
175 An array of unknown size has lowerbound 0 and upperbound -1. */
177 warning (_("array or string index out of range"));
178 /* fall doing C stuff */
183 array
= value_coerce_array (array
);
187 return value_ind (value_ptradd (array
, index
));
189 error (_("not an array or string"));
192 /* Return the value of EXPR[IDX], expr an aggregate rvalue
193 (eg, a vector register). This routine used to promote floats
194 to doubles, but no longer does. */
197 value_subscripted_rvalue (struct value
*array
, LONGEST index
, int lowerbound
)
199 struct type
*array_type
= check_typedef (value_type (array
));
200 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (array_type
));
201 unsigned int elt_size
= TYPE_LENGTH (elt_type
);
202 unsigned int elt_offs
= elt_size
* longest_to_int (index
- lowerbound
);
205 if (index
< lowerbound
|| (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type
)
206 && elt_offs
>= TYPE_LENGTH (array_type
)))
207 error (_("no such vector element"));
209 v
= allocate_value (elt_type
);
210 if (VALUE_LVAL (array
) == lval_memory
&& value_lazy (array
))
211 set_value_lazy (v
, 1);
213 memcpy (value_contents_writeable (v
),
214 value_contents (array
) + elt_offs
, elt_size
);
216 set_value_component_location (v
, array
);
217 VALUE_REGNUM (v
) = VALUE_REGNUM (array
);
218 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (array
);
219 set_value_offset (v
, value_offset (array
) + elt_offs
);
223 /* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */
226 value_bitstring_subscript (struct type
*type
,
227 struct value
*bitstring
, LONGEST index
)
230 struct type
*bitstring_type
, *range_type
;
232 int offset
, byte
, bit_index
;
233 LONGEST lowerbound
, upperbound
;
235 bitstring_type
= check_typedef (value_type (bitstring
));
236 gdb_assert (TYPE_CODE (bitstring_type
) == TYPE_CODE_BITSTRING
);
238 range_type
= TYPE_INDEX_TYPE (bitstring_type
);
239 get_discrete_bounds (range_type
, &lowerbound
, &upperbound
);
240 if (index
< lowerbound
|| index
> upperbound
)
241 error (_("bitstring index out of range"));
244 offset
= index
/ TARGET_CHAR_BIT
;
245 byte
= *((char *) value_contents (bitstring
) + offset
);
247 bit_index
= index
% TARGET_CHAR_BIT
;
248 byte
>>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type
)) ?
249 TARGET_CHAR_BIT
- 1 - bit_index
: bit_index
);
251 v
= value_from_longest (type
, byte
& 1);
253 set_value_bitpos (v
, bit_index
);
254 set_value_bitsize (v
, 1);
255 set_value_component_location (v
, bitstring
);
256 VALUE_FRAME_ID (v
) = VALUE_FRAME_ID (bitstring
);
258 set_value_offset (v
, offset
+ value_offset (bitstring
));
264 /* Check to see if either argument is a structure, or a reference to
265 one. This is called so we know whether to go ahead with the normal
266 binop or look for a user defined function instead.
268 For now, we do not overload the `=' operator. */
271 binop_types_user_defined_p (enum exp_opcode op
,
272 struct type
*type1
, struct type
*type2
)
274 if (op
== BINOP_ASSIGN
|| op
== BINOP_CONCAT
)
277 type1
= check_typedef (type1
);
278 if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
279 type1
= check_typedef (TYPE_TARGET_TYPE (type1
));
281 type2
= check_typedef (type1
);
282 if (TYPE_CODE (type2
) == TYPE_CODE_REF
)
283 type2
= check_typedef (TYPE_TARGET_TYPE (type2
));
285 return (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
286 || TYPE_CODE (type2
) == TYPE_CODE_STRUCT
);
289 /* Check to see if either argument is a structure, or a reference to
290 one. This is called so we know whether to go ahead with the normal
291 binop or look for a user defined function instead.
293 For now, we do not overload the `=' operator. */
296 binop_user_defined_p (enum exp_opcode op
,
297 struct value
*arg1
, struct value
*arg2
)
299 return binop_types_user_defined_p (op
, value_type (arg1
), value_type (arg2
));
302 /* Check to see if argument is a structure. This is called so
303 we know whether to go ahead with the normal unop or look for a
304 user defined function instead.
306 For now, we do not overload the `&' operator. */
309 unop_user_defined_p (enum exp_opcode op
, struct value
*arg1
)
315 type1
= check_typedef (value_type (arg1
));
318 if (TYPE_CODE (type1
) == TYPE_CODE_STRUCT
)
320 else if (TYPE_CODE (type1
) == TYPE_CODE_REF
)
321 type1
= TYPE_TARGET_TYPE (type1
);
327 /* Try to find an operator named OPERATOR which takes NARGS arguments
328 specified in ARGS. If the operator found is a static member operator
329 *STATIC_MEMFUNP will be set to 1, and otherwise 0.
330 The search if performed through find_overload_match which will handle
331 member operators, non member operators, operators imported implicitly or
332 explicitly, and perform correct overload resolution in all of the above
333 situations or combinations thereof. */
335 static struct value
*
336 value_user_defined_cpp_op (struct value
**args
, int nargs
, char *operator,
337 int *static_memfuncp
)
340 struct symbol
*symp
= NULL
;
341 struct value
*valp
= NULL
;
342 struct type
**arg_types
;
345 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
346 /* Prepare list of argument types for overload resolution */
347 for (i
= 0; i
< nargs
; i
++)
348 arg_types
[i
] = value_type (args
[i
]);
350 find_overload_match (arg_types
, nargs
, operator, BOTH
/* could be method */,
351 0 /* strict match */, &args
[0], /* objp */
352 NULL
/* pass NULL symbol since symbol is unknown */,
353 &valp
, &symp
, static_memfuncp
, 0);
360 /* This is a non member function and does not
361 expect a reference as its first argument
362 rather the explicit structure. */
363 args
[0] = value_ind (args
[0]);
364 return value_of_variable (symp
, 0);
367 error (_("Could not find %s."), operator);
370 /* Lookup user defined operator NAME. Return a value representing the
371 function, otherwise return NULL. */
373 static struct value
*
374 value_user_defined_op (struct value
**argp
, struct value
**args
, char *name
,
375 int *static_memfuncp
, int nargs
)
377 struct value
*result
= NULL
;
379 if (current_language
->la_language
== language_cplus
)
380 result
= value_user_defined_cpp_op (args
, nargs
, name
, static_memfuncp
);
382 result
= value_struct_elt (argp
, args
, name
, static_memfuncp
,
388 /* We know either arg1 or arg2 is a structure, so try to find the right
389 user defined function. Create an argument vector that calls
390 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
391 binary operator which is legal for GNU C++).
393 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
394 is the opcode saying how to modify it. Otherwise, OTHEROP is
398 value_x_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
,
399 enum exp_opcode otherop
, enum noside noside
)
401 struct value
**argvec
;
406 arg1
= coerce_ref (arg1
);
407 arg2
= coerce_ref (arg2
);
409 /* now we know that what we have to do is construct our
410 arg vector and find the right function to call it with. */
412 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
413 error (_("Can't do that binary op on that type")); /* FIXME be explicit */
415 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
416 argvec
[1] = value_addr (arg1
);
420 /* make the right function name up */
421 strcpy (tstr
, "operator__");
446 case BINOP_BITWISE_AND
:
449 case BINOP_BITWISE_IOR
:
452 case BINOP_BITWISE_XOR
:
455 case BINOP_LOGICAL_AND
:
458 case BINOP_LOGICAL_OR
:
470 case BINOP_ASSIGN_MODIFY
:
488 case BINOP_BITWISE_AND
:
491 case BINOP_BITWISE_IOR
:
494 case BINOP_BITWISE_XOR
:
497 case BINOP_MOD
: /* invalid */
499 error (_("Invalid binary operation specified."));
502 case BINOP_SUBSCRIPT
:
523 case BINOP_MOD
: /* invalid */
525 error (_("Invalid binary operation specified."));
528 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
529 &static_memfuncp
, 2);
535 argvec
[1] = argvec
[0];
538 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
540 struct type
*return_type
;
543 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
544 return value_zero (return_type
, VALUE_LVAL (arg1
));
546 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
548 throw_error (NOT_FOUND_ERROR
,
549 _("member function %s not found"), tstr
);
551 return call_function_by_hand (argvec
[0], 2 - static_memfuncp
, argvec
+ 1);
555 /* We know that arg1 is a structure, so try to find a unary user
556 defined operator that matches the operator in question.
557 Create an argument vector that calls arg1.operator @ (arg1)
558 and return that value (where '@' is (almost) any unary operator which
559 is legal for GNU C++). */
562 value_x_unop (struct value
*arg1
, enum exp_opcode op
, enum noside noside
)
564 struct gdbarch
*gdbarch
= get_type_arch (value_type (arg1
));
565 struct value
**argvec
;
566 char *ptr
, *mangle_ptr
;
567 char tstr
[13], mangle_tstr
[13];
568 int static_memfuncp
, nargs
;
570 arg1
= coerce_ref (arg1
);
572 /* now we know that what we have to do is construct our
573 arg vector and find the right function to call it with. */
575 if (TYPE_CODE (check_typedef (value_type (arg1
))) != TYPE_CODE_STRUCT
)
576 error (_("Can't do that unary op on that type")); /* FIXME be explicit */
578 argvec
= (struct value
**) alloca (sizeof (struct value
*) * 4);
579 argvec
[1] = value_addr (arg1
);
584 /* make the right function name up */
585 strcpy (tstr
, "operator__");
587 strcpy (mangle_tstr
, "__");
588 mangle_ptr
= mangle_tstr
+ 2;
591 case UNOP_PREINCREMENT
:
594 case UNOP_PREDECREMENT
:
597 case UNOP_POSTINCREMENT
:
599 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
603 case UNOP_POSTDECREMENT
:
605 argvec
[2] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, 0);
609 case UNOP_LOGICAL_NOT
:
612 case UNOP_COMPLEMENT
:
628 error (_("Invalid unary operation specified."));
631 argvec
[0] = value_user_defined_op (&arg1
, argvec
+ 1, tstr
,
632 &static_memfuncp
, nargs
);
638 argvec
[1] = argvec
[0];
642 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
644 struct type
*return_type
;
647 = TYPE_TARGET_TYPE (check_typedef (value_type (argvec
[0])));
648 return value_zero (return_type
, VALUE_LVAL (arg1
));
650 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
652 throw_error (NOT_FOUND_ERROR
,
653 _("member function %s not found"), tstr
);
655 return 0; /* For lint -- never reached */
659 /* Concatenate two values with the following conditions:
661 (1) Both values must be either bitstring values or character string
662 values and the resulting value consists of the concatenation of
663 ARG1 followed by ARG2.
667 One value must be an integer value and the other value must be
668 either a bitstring value or character string value, which is
669 to be repeated by the number of times specified by the integer
673 (2) Boolean values are also allowed and are treated as bit string
676 (3) Character values are also allowed and are treated as character
677 string values of length 1.
681 value_concat (struct value
*arg1
, struct value
*arg2
)
683 struct value
*inval1
;
684 struct value
*inval2
;
685 struct value
*outval
= NULL
;
686 int inval1len
, inval2len
;
690 struct type
*type1
= check_typedef (value_type (arg1
));
691 struct type
*type2
= check_typedef (value_type (arg2
));
692 struct type
*char_type
;
694 /* First figure out if we are dealing with two values to be concatenated
695 or a repeat count and a value to be repeated. INVAL1 is set to the
696 first of two concatenated values, or the repeat count. INVAL2 is set
697 to the second of the two concatenated values or the value to be
700 if (TYPE_CODE (type2
) == TYPE_CODE_INT
)
702 struct type
*tmp
= type1
;
715 /* Now process the input values. */
717 if (TYPE_CODE (type1
) == TYPE_CODE_INT
)
719 /* We have a repeat count. Validate the second value and then
720 construct a value repeated that many times. */
721 if (TYPE_CODE (type2
) == TYPE_CODE_STRING
722 || TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
724 count
= longest_to_int (value_as_long (inval1
));
725 inval2len
= TYPE_LENGTH (type2
);
726 ptr
= (char *) alloca (count
* inval2len
);
727 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
731 inchar
= (char) unpack_long (type2
,
732 value_contents (inval2
));
733 for (idx
= 0; idx
< count
; idx
++)
735 *(ptr
+ idx
) = inchar
;
740 char_type
= TYPE_TARGET_TYPE (type2
);
742 for (idx
= 0; idx
< count
; idx
++)
744 memcpy (ptr
+ (idx
* inval2len
), value_contents (inval2
),
748 outval
= value_string (ptr
, count
* inval2len
, char_type
);
750 else if (TYPE_CODE (type2
) == TYPE_CODE_BITSTRING
751 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
753 error (_("unimplemented support for bitstring/boolean repeats"));
757 error (_("can't repeat values of that type"));
760 else if (TYPE_CODE (type1
) == TYPE_CODE_STRING
761 || TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
763 /* We have two character strings to concatenate. */
764 if (TYPE_CODE (type2
) != TYPE_CODE_STRING
765 && TYPE_CODE (type2
) != TYPE_CODE_CHAR
)
767 error (_("Strings can only be concatenated with other strings."));
769 inval1len
= TYPE_LENGTH (type1
);
770 inval2len
= TYPE_LENGTH (type2
);
771 ptr
= (char *) alloca (inval1len
+ inval2len
);
772 if (TYPE_CODE (type1
) == TYPE_CODE_CHAR
)
776 *ptr
= (char) unpack_long (type1
, value_contents (inval1
));
780 char_type
= TYPE_TARGET_TYPE (type1
);
782 memcpy (ptr
, value_contents (inval1
), inval1len
);
784 if (TYPE_CODE (type2
) == TYPE_CODE_CHAR
)
787 (char) unpack_long (type2
, value_contents (inval2
));
791 memcpy (ptr
+ inval1len
, value_contents (inval2
), inval2len
);
793 outval
= value_string (ptr
, inval1len
+ inval2len
, char_type
);
795 else if (TYPE_CODE (type1
) == TYPE_CODE_BITSTRING
796 || TYPE_CODE (type1
) == TYPE_CODE_BOOL
)
798 /* We have two bitstrings to concatenate. */
799 if (TYPE_CODE (type2
) != TYPE_CODE_BITSTRING
800 && TYPE_CODE (type2
) != TYPE_CODE_BOOL
)
802 error (_("Bitstrings or booleans can only be concatenated with other bitstrings or booleans."));
804 error (_("unimplemented support for bitstring/boolean concatenation."));
808 /* We don't know how to concatenate these operands. */
809 error (_("illegal operands for concatenation."));
814 /* Integer exponentiation: V1**V2, where both arguments are
815 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
817 integer_pow (LONGEST v1
, LONGEST v2
)
822 error (_("Attempt to raise 0 to negative power."));
828 /* The Russian Peasant's Algorithm */
844 /* Integer exponentiation: V1**V2, where both arguments are
845 integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
847 uinteger_pow (ULONGEST v1
, LONGEST v2
)
852 error (_("Attempt to raise 0 to negative power."));
858 /* The Russian Peasant's Algorithm */
874 /* Obtain decimal value of arguments for binary operation, converting from
875 other types if one of them is not decimal floating point. */
877 value_args_as_decimal (struct value
*arg1
, struct value
*arg2
,
878 gdb_byte
*x
, int *len_x
, enum bfd_endian
*byte_order_x
,
879 gdb_byte
*y
, int *len_y
, enum bfd_endian
*byte_order_y
)
881 struct type
*type1
, *type2
;
883 type1
= check_typedef (value_type (arg1
));
884 type2
= check_typedef (value_type (arg2
));
886 /* At least one of the arguments must be of decimal float type. */
887 gdb_assert (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
888 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
);
890 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
891 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
892 /* The DFP extension to the C language does not allow mixing of
893 * decimal float types with other float types in expressions
894 * (see WDTR 24732, page 12). */
895 error (_("Mixing decimal floating types with other floating types is not allowed."));
897 /* Obtain decimal value of arg1, converting from other types
900 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
902 *byte_order_x
= gdbarch_byte_order (get_type_arch (type1
));
903 *len_x
= TYPE_LENGTH (type1
);
904 memcpy (x
, value_contents (arg1
), *len_x
);
906 else if (is_integral_type (type1
))
908 *byte_order_x
= gdbarch_byte_order (get_type_arch (type2
));
909 *len_x
= TYPE_LENGTH (type2
);
910 decimal_from_integral (arg1
, x
, *len_x
, *byte_order_x
);
913 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
916 /* Obtain decimal value of arg2, converting from other types
919 if (TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
921 *byte_order_y
= gdbarch_byte_order (get_type_arch (type2
));
922 *len_y
= TYPE_LENGTH (type2
);
923 memcpy (y
, value_contents (arg2
), *len_y
);
925 else if (is_integral_type (type2
))
927 *byte_order_y
= gdbarch_byte_order (get_type_arch (type1
));
928 *len_y
= TYPE_LENGTH (type1
);
929 decimal_from_integral (arg2
, y
, *len_y
, *byte_order_y
);
932 error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1
),
936 /* Perform a binary operation on two operands which have reasonable
937 representations as integers or floats. This includes booleans,
938 characters, integers, or floats.
939 Does not support addition and subtraction on pointers;
940 use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
942 static struct value
*
943 scalar_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
946 struct type
*type1
, *type2
, *result_type
;
948 arg1
= coerce_ref (arg1
);
949 arg2
= coerce_ref (arg2
);
951 type1
= check_typedef (value_type (arg1
));
952 type2
= check_typedef (value_type (arg2
));
954 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
955 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
956 && !is_integral_type (type1
))
957 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
958 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
959 && !is_integral_type (type2
)))
960 error (_("Argument to arithmetic operation not a number or boolean."));
962 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
963 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
965 int len_v1
, len_v2
, len_v
;
966 enum bfd_endian byte_order_v1
, byte_order_v2
, byte_order_v
;
967 gdb_byte v1
[16], v2
[16];
970 /* If only one type is decimal float, use its type.
971 Otherwise use the bigger type. */
972 if (TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
)
974 else if (TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
)
976 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
981 len_v
= TYPE_LENGTH (result_type
);
982 byte_order_v
= gdbarch_byte_order (get_type_arch (result_type
));
984 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
985 v2
, &len_v2
, &byte_order_v2
);
994 decimal_binop (op
, v1
, len_v1
, byte_order_v1
,
995 v2
, len_v2
, byte_order_v2
,
996 v
, len_v
, byte_order_v
);
1000 error (_("Operation not valid for decimal floating point number."));
1003 val
= value_from_decfloat (result_type
, v
);
1005 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
1006 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
1008 /* FIXME-if-picky-about-floating-accuracy: Should be doing this
1009 in target format. real.c in GCC probably has the necessary
1011 DOUBLEST v1
, v2
, v
= 0;
1013 v1
= value_as_double (arg1
);
1014 v2
= value_as_double (arg2
);
1038 error (_("Cannot perform exponentiation: %s"), safe_strerror (errno
));
1042 v
= v1
< v2
? v1
: v2
;
1046 v
= v1
> v2
? v1
: v2
;
1050 error (_("Integer-only operation on floating point number."));
1053 /* If only one type is float, use its type.
1054 Otherwise use the bigger type. */
1055 if (TYPE_CODE (type1
) != TYPE_CODE_FLT
)
1056 result_type
= type2
;
1057 else if (TYPE_CODE (type2
) != TYPE_CODE_FLT
)
1058 result_type
= type1
;
1059 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1060 result_type
= type2
;
1062 result_type
= type1
;
1064 val
= allocate_value (result_type
);
1065 store_typed_floating (value_contents_raw (val
), value_type (val
), v
);
1067 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
1068 || TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
1070 LONGEST v1
, v2
, v
= 0;
1072 v1
= value_as_long (arg1
);
1073 v2
= value_as_long (arg2
);
1077 case BINOP_BITWISE_AND
:
1081 case BINOP_BITWISE_IOR
:
1085 case BINOP_BITWISE_XOR
:
1093 case BINOP_NOTEQUAL
:
1098 error (_("Invalid operation on booleans."));
1101 result_type
= type1
;
1103 val
= allocate_value (result_type
);
1104 store_signed_integer (value_contents_raw (val
),
1105 TYPE_LENGTH (result_type
),
1106 gdbarch_byte_order (get_type_arch (result_type
)),
1110 /* Integral operations here. */
1112 /* Determine type length of the result, and if the operation should
1113 be done unsigned. For exponentiation and shift operators,
1114 use the length and type of the left operand. Otherwise,
1115 use the signedness of the operand with the greater length.
1116 If both operands are of equal length, use unsigned operation
1117 if one of the operands is unsigned. */
1118 if (op
== BINOP_RSH
|| op
== BINOP_LSH
|| op
== BINOP_EXP
)
1119 result_type
= type1
;
1120 else if (TYPE_LENGTH (type1
) > TYPE_LENGTH (type2
))
1121 result_type
= type1
;
1122 else if (TYPE_LENGTH (type2
) > TYPE_LENGTH (type1
))
1123 result_type
= type2
;
1124 else if (TYPE_UNSIGNED (type1
))
1125 result_type
= type1
;
1126 else if (TYPE_UNSIGNED (type2
))
1127 result_type
= type2
;
1129 result_type
= type1
;
1131 if (TYPE_UNSIGNED (result_type
))
1133 LONGEST v2_signed
= value_as_long (arg2
);
1134 ULONGEST v1
, v2
, v
= 0;
1136 v1
= (ULONGEST
) value_as_long (arg1
);
1137 v2
= (ULONGEST
) v2_signed
;
1158 error (_("Division by zero"));
1162 v
= uinteger_pow (v1
, v2_signed
);
1169 error (_("Division by zero"));
1173 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1174 v1 mod 0 has a defined value, v1. */
1182 /* Note floor(v1/v2) == v1/v2 for unsigned. */
1195 case BINOP_BITWISE_AND
:
1199 case BINOP_BITWISE_IOR
:
1203 case BINOP_BITWISE_XOR
:
1207 case BINOP_LOGICAL_AND
:
1211 case BINOP_LOGICAL_OR
:
1216 v
= v1
< v2
? v1
: v2
;
1220 v
= v1
> v2
? v1
: v2
;
1227 case BINOP_NOTEQUAL
:
1248 error (_("Invalid binary operation on numbers."));
1251 val
= allocate_value (result_type
);
1252 store_unsigned_integer (value_contents_raw (val
),
1253 TYPE_LENGTH (value_type (val
)),
1255 (get_type_arch (result_type
)),
1260 LONGEST v1
, v2
, v
= 0;
1262 v1
= value_as_long (arg1
);
1263 v2
= value_as_long (arg2
);
1284 error (_("Division by zero"));
1288 v
= integer_pow (v1
, v2
);
1295 error (_("Division by zero"));
1299 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1300 X mod 0 has a defined value, X. */
1308 /* Compute floor. */
1309 if (TRUNCATION_TOWARDS_ZERO
&& (v
< 0) && ((v1
% v2
) != 0))
1325 case BINOP_BITWISE_AND
:
1329 case BINOP_BITWISE_IOR
:
1333 case BINOP_BITWISE_XOR
:
1337 case BINOP_LOGICAL_AND
:
1341 case BINOP_LOGICAL_OR
:
1346 v
= v1
< v2
? v1
: v2
;
1350 v
= v1
> v2
? v1
: v2
;
1357 case BINOP_NOTEQUAL
:
1378 error (_("Invalid binary operation on numbers."));
1381 val
= allocate_value (result_type
);
1382 store_signed_integer (value_contents_raw (val
),
1383 TYPE_LENGTH (value_type (val
)),
1385 (get_type_arch (result_type
)),
1393 /* Performs a binary operation on two vector operands by calling scalar_binop
1394 for each pair of vector components. */
1396 static struct value
*
1397 vector_binop (struct value
*val1
, struct value
*val2
, enum exp_opcode op
)
1399 struct value
*val
, *tmp
, *mark
;
1400 struct type
*type1
, *type2
, *eltype1
, *eltype2
, *result_type
;
1401 int t1_is_vec
, t2_is_vec
, elsize
, i
;
1402 LONGEST low_bound1
, high_bound1
, low_bound2
, high_bound2
;
1404 type1
= check_typedef (value_type (val1
));
1405 type2
= check_typedef (value_type (val2
));
1407 t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1408 && TYPE_VECTOR (type1
)) ? 1 : 0;
1409 t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1410 && TYPE_VECTOR (type2
)) ? 1 : 0;
1412 if (!t1_is_vec
|| !t2_is_vec
)
1413 error (_("Vector operations are only supported among vectors"));
1415 if (!get_array_bounds (type1
, &low_bound1
, &high_bound1
)
1416 || !get_array_bounds (type2
, &low_bound2
, &high_bound2
))
1417 error (_("Could not determine the vector bounds"));
1419 eltype1
= check_typedef (TYPE_TARGET_TYPE (type1
));
1420 eltype2
= check_typedef (TYPE_TARGET_TYPE (type2
));
1421 elsize
= TYPE_LENGTH (eltype1
);
1423 if (TYPE_CODE (eltype1
) != TYPE_CODE (eltype2
)
1424 || elsize
!= TYPE_LENGTH (eltype2
)
1425 || TYPE_UNSIGNED (eltype1
) != TYPE_UNSIGNED (eltype2
)
1426 || low_bound1
!= low_bound2
|| high_bound1
!= high_bound2
)
1427 error (_("Cannot perform operation on vectors with different types"));
1429 val
= allocate_value (type1
);
1430 mark
= value_mark ();
1431 for (i
= 0; i
< high_bound1
- low_bound1
+ 1; i
++)
1433 tmp
= value_binop (value_subscript (val1
, i
),
1434 value_subscript (val2
, i
), op
);
1435 memcpy (value_contents_writeable (val
) + i
* elsize
,
1436 value_contents_all (tmp
),
1439 value_free_to_mark (mark
);
1444 /* Perform a binary operation on two operands. */
1447 value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
1450 struct type
*type1
= check_typedef (value_type (arg1
));
1451 struct type
*type2
= check_typedef (value_type (arg2
));
1452 int t1_is_vec
= (TYPE_CODE (type1
) == TYPE_CODE_ARRAY
1453 && TYPE_VECTOR (type1
));
1454 int t2_is_vec
= (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
1455 && TYPE_VECTOR (type2
));
1457 if (!t1_is_vec
&& !t2_is_vec
)
1458 val
= scalar_binop (arg1
, arg2
, op
);
1459 else if (t1_is_vec
&& t2_is_vec
)
1460 val
= vector_binop (arg1
, arg2
, op
);
1463 /* Widen the scalar operand to a vector. */
1464 struct value
**v
= t1_is_vec
? &arg2
: &arg1
;
1465 struct type
*t
= t1_is_vec
? type2
: type1
;
1467 if (TYPE_CODE (t
) != TYPE_CODE_FLT
1468 && TYPE_CODE (t
) != TYPE_CODE_DECFLOAT
1469 && !is_integral_type (t
))
1470 error (_("Argument to operation not a number or boolean."));
1472 *v
= value_cast (t1_is_vec
? type1
: type2
, *v
);
1473 val
= vector_binop (arg1
, arg2
, op
);
1479 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1482 value_logical_not (struct value
*arg1
)
1488 arg1
= coerce_array (arg1
);
1489 type1
= check_typedef (value_type (arg1
));
1491 if (TYPE_CODE (type1
) == TYPE_CODE_FLT
)
1492 return 0 == value_as_double (arg1
);
1493 else if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
)
1494 return decimal_is_zero (value_contents (arg1
), TYPE_LENGTH (type1
),
1495 gdbarch_byte_order (get_type_arch (type1
)));
1497 len
= TYPE_LENGTH (type1
);
1498 p
= value_contents (arg1
);
1509 /* Perform a comparison on two string values (whose content are not
1510 necessarily null terminated) based on their length */
1513 value_strcmp (struct value
*arg1
, struct value
*arg2
)
1515 int len1
= TYPE_LENGTH (value_type (arg1
));
1516 int len2
= TYPE_LENGTH (value_type (arg2
));
1517 const gdb_byte
*s1
= value_contents (arg1
);
1518 const gdb_byte
*s2
= value_contents (arg2
);
1519 int i
, len
= len1
< len2
? len1
: len2
;
1521 for (i
= 0; i
< len
; i
++)
1525 else if (s1
[i
] > s2
[i
])
1533 else if (len1
> len2
)
1539 /* Simulate the C operator == by returning a 1
1540 iff ARG1 and ARG2 have equal contents. */
1543 value_equal (struct value
*arg1
, struct value
*arg2
)
1548 struct type
*type1
, *type2
;
1549 enum type_code code1
;
1550 enum type_code code2
;
1551 int is_int1
, is_int2
;
1553 arg1
= coerce_array (arg1
);
1554 arg2
= coerce_array (arg2
);
1556 type1
= check_typedef (value_type (arg1
));
1557 type2
= check_typedef (value_type (arg2
));
1558 code1
= TYPE_CODE (type1
);
1559 code2
= TYPE_CODE (type2
);
1560 is_int1
= is_integral_type (type1
);
1561 is_int2
= is_integral_type (type2
);
1563 if (is_int1
&& is_int2
)
1564 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1566 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1567 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1569 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1570 `long double' values are returned in static storage (m68k). */
1571 DOUBLEST d
= value_as_double (arg1
);
1573 return d
== value_as_double (arg2
);
1575 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1576 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1578 gdb_byte v1
[16], v2
[16];
1580 enum bfd_endian byte_order_v1
, byte_order_v2
;
1582 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1583 v2
, &len_v2
, &byte_order_v2
);
1585 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1586 v2
, len_v2
, byte_order_v2
) == 0;
1589 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1591 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1592 return value_as_address (arg1
) == (CORE_ADDR
) value_as_long (arg2
);
1593 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1594 return (CORE_ADDR
) value_as_long (arg1
) == value_as_address (arg2
);
1596 else if (code1
== code2
1597 && ((len
= (int) TYPE_LENGTH (type1
))
1598 == (int) TYPE_LENGTH (type2
)))
1600 p1
= value_contents (arg1
);
1601 p2
= value_contents (arg2
);
1609 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1611 return value_strcmp (arg1
, arg2
) == 0;
1615 error (_("Invalid type combination in equality test."));
1616 return 0; /* For lint -- never reached */
1620 /* Compare values based on their raw contents. Useful for arrays since
1621 value_equal coerces them to pointers, thus comparing just the address
1622 of the array instead of its contents. */
1625 value_equal_contents (struct value
*arg1
, struct value
*arg2
)
1627 struct type
*type1
, *type2
;
1629 type1
= check_typedef (value_type (arg1
));
1630 type2
= check_typedef (value_type (arg2
));
1632 return (TYPE_CODE (type1
) == TYPE_CODE (type2
)
1633 && TYPE_LENGTH (type1
) == TYPE_LENGTH (type2
)
1634 && memcmp (value_contents (arg1
), value_contents (arg2
),
1635 TYPE_LENGTH (type1
)) == 0);
1638 /* Simulate the C operator < by returning 1
1639 iff ARG1's contents are less than ARG2's. */
1642 value_less (struct value
*arg1
, struct value
*arg2
)
1644 enum type_code code1
;
1645 enum type_code code2
;
1646 struct type
*type1
, *type2
;
1647 int is_int1
, is_int2
;
1649 arg1
= coerce_array (arg1
);
1650 arg2
= coerce_array (arg2
);
1652 type1
= check_typedef (value_type (arg1
));
1653 type2
= check_typedef (value_type (arg2
));
1654 code1
= TYPE_CODE (type1
);
1655 code2
= TYPE_CODE (type2
);
1656 is_int1
= is_integral_type (type1
);
1657 is_int2
= is_integral_type (type2
);
1659 if (is_int1
&& is_int2
)
1660 return longest_to_int (value_as_long (value_binop (arg1
, arg2
,
1662 else if ((code1
== TYPE_CODE_FLT
|| is_int1
)
1663 && (code2
== TYPE_CODE_FLT
|| is_int2
))
1665 /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1666 `long double' values are returned in static storage (m68k). */
1667 DOUBLEST d
= value_as_double (arg1
);
1669 return d
< value_as_double (arg2
);
1671 else if ((code1
== TYPE_CODE_DECFLOAT
|| is_int1
)
1672 && (code2
== TYPE_CODE_DECFLOAT
|| is_int2
))
1674 gdb_byte v1
[16], v2
[16];
1676 enum bfd_endian byte_order_v1
, byte_order_v2
;
1678 value_args_as_decimal (arg1
, arg2
, v1
, &len_v1
, &byte_order_v1
,
1679 v2
, &len_v2
, &byte_order_v2
);
1681 return decimal_compare (v1
, len_v1
, byte_order_v1
,
1682 v2
, len_v2
, byte_order_v2
) == -1;
1684 else if (code1
== TYPE_CODE_PTR
&& code2
== TYPE_CODE_PTR
)
1685 return value_as_address (arg1
) < value_as_address (arg2
);
1687 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1689 else if (code1
== TYPE_CODE_PTR
&& is_int2
)
1690 return value_as_address (arg1
) < (CORE_ADDR
) value_as_long (arg2
);
1691 else if (code2
== TYPE_CODE_PTR
&& is_int1
)
1692 return (CORE_ADDR
) value_as_long (arg1
) < value_as_address (arg2
);
1693 else if (code1
== TYPE_CODE_STRING
&& code2
== TYPE_CODE_STRING
)
1694 return value_strcmp (arg1
, arg2
) < 0;
1697 error (_("Invalid type combination in ordering comparison."));
1702 /* The unary operators +, - and ~. They free the argument ARG1. */
1705 value_pos (struct value
*arg1
)
1709 arg1
= coerce_ref (arg1
);
1710 type
= check_typedef (value_type (arg1
));
1712 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1713 return value_from_double (type
, value_as_double (arg1
));
1714 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1715 return value_from_decfloat (type
, value_contents (arg1
));
1716 else if (is_integral_type (type
))
1718 return value_from_longest (type
, value_as_long (arg1
));
1720 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1722 struct value
*val
= allocate_value (type
);
1724 memcpy (value_contents_raw (val
), value_contents (arg1
),
1725 TYPE_LENGTH (type
));
1730 error ("Argument to positive operation not a number.");
1731 return 0; /* For lint -- never reached */
1736 value_neg (struct value
*arg1
)
1740 arg1
= coerce_ref (arg1
);
1741 type
= check_typedef (value_type (arg1
));
1743 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1745 struct value
*val
= allocate_value (type
);
1746 int len
= TYPE_LENGTH (type
);
1747 gdb_byte decbytes
[16]; /* a decfloat is at most 128 bits long */
1749 memcpy (decbytes
, value_contents (arg1
), len
);
1751 if (gdbarch_byte_order (get_type_arch (type
)) == BFD_ENDIAN_LITTLE
)
1752 decbytes
[len
-1] = decbytes
[len
- 1] | 0x80;
1754 decbytes
[0] = decbytes
[0] | 0x80;
1756 memcpy (value_contents_raw (val
), decbytes
, len
);
1759 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1760 return value_from_double (type
, -value_as_double (arg1
));
1761 else if (is_integral_type (type
))
1763 return value_from_longest (type
, -value_as_long (arg1
));
1765 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1767 struct value
*tmp
, *val
= allocate_value (type
);
1768 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1770 LONGEST low_bound
, high_bound
;
1772 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1773 error (_("Could not determine the vector bounds"));
1775 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1777 tmp
= value_neg (value_subscript (arg1
, i
));
1778 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1779 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1785 error (_("Argument to negate operation not a number."));
1786 return 0; /* For lint -- never reached */
1791 value_complement (struct value
*arg1
)
1796 arg1
= coerce_ref (arg1
);
1797 type
= check_typedef (value_type (arg1
));
1799 if (is_integral_type (type
))
1800 val
= value_from_longest (type
, ~value_as_long (arg1
));
1801 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
))
1804 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1806 LONGEST low_bound
, high_bound
;
1808 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1809 error (_("Could not determine the vector bounds"));
1811 val
= allocate_value (type
);
1812 for (i
= 0; i
< high_bound
- low_bound
+ 1; i
++)
1814 tmp
= value_complement (value_subscript (arg1
, i
));
1815 memcpy (value_contents_writeable (val
) + i
* TYPE_LENGTH (eltype
),
1816 value_contents_all (tmp
), TYPE_LENGTH (eltype
));
1820 error (_("Argument to complement operation not an integer, boolean."));
1825 /* The INDEX'th bit of SET value whose value_type is TYPE,
1826 and whose value_contents is valaddr.
1827 Return -1 if out of range, -2 other error. */
1830 value_bit_index (struct type
*type
, const gdb_byte
*valaddr
, int index
)
1832 struct gdbarch
*gdbarch
= get_type_arch (type
);
1833 LONGEST low_bound
, high_bound
;
1836 struct type
*range
= TYPE_INDEX_TYPE (type
);
1838 if (get_discrete_bounds (range
, &low_bound
, &high_bound
) < 0)
1840 if (index
< low_bound
|| index
> high_bound
)
1842 rel_index
= index
- low_bound
;
1843 word
= extract_unsigned_integer (valaddr
+ (rel_index
/ TARGET_CHAR_BIT
), 1,
1844 gdbarch_byte_order (gdbarch
));
1845 rel_index
%= TARGET_CHAR_BIT
;
1846 if (gdbarch_bits_big_endian (gdbarch
))
1847 rel_index
= TARGET_CHAR_BIT
- 1 - rel_index
;
1848 return (word
>> rel_index
) & 1;
1852 value_in (struct value
*element
, struct value
*set
)
1855 struct type
*settype
= check_typedef (value_type (set
));
1856 struct type
*eltype
= check_typedef (value_type (element
));
1858 if (TYPE_CODE (eltype
) == TYPE_CODE_RANGE
)
1859 eltype
= TYPE_TARGET_TYPE (eltype
);
1860 if (TYPE_CODE (settype
) != TYPE_CODE_SET
)
1861 error (_("Second argument of 'IN' has wrong type"));
1862 if (TYPE_CODE (eltype
) != TYPE_CODE_INT
1863 && TYPE_CODE (eltype
) != TYPE_CODE_CHAR
1864 && TYPE_CODE (eltype
) != TYPE_CODE_ENUM
1865 && TYPE_CODE (eltype
) != TYPE_CODE_BOOL
)
1866 error (_("First argument of 'IN' has wrong type"));
1867 member
= value_bit_index (settype
, value_contents (set
),
1868 value_as_long (element
));
1870 error (_("First argument of 'IN' not in range"));
1875 _initialize_valarith (void)
This page took 0.077421 seconds and 4 git commands to generate.