62ebc682e41b2f2031fbd95af910f5f4518f6c09
[platform/upstream/binutils.git] / gdb / valarith.c
1 /* Perform arithmetic and other operations on values, for GDB.
2    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3    1996, 1997, 1998, 1999, 2000, 2001, 2002
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "value.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "expression.h"
28 #include "target.h"
29 #include "language.h"
30 #include "gdb_string.h"
31 #include "doublest.h"
32 #include <math.h>
33
34 /* Define whether or not the C operator '/' truncates towards zero for
35    differently signed operands (truncation direction is undefined in C). */
36
37 #ifndef TRUNCATION_TOWARDS_ZERO
38 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
39 #endif
40
41 static struct value *value_subscripted_rvalue (struct value *, struct value *, int);
42
43 void _initialize_valarith (void);
44 \f
45
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_sub & value_add.
51 */
52
53 static LONGEST
54 find_size_for_pointer_math (struct type *ptr_type)
55 {
56   LONGEST sz = -1;
57   struct type *ptr_target;
58
59   ptr_target = check_typedef (TYPE_TARGET_TYPE (ptr_type));
60
61   sz = TYPE_LENGTH (ptr_target);
62   if (sz == 0)
63     {
64       if (TYPE_CODE (ptr_type) == TYPE_CODE_VOID)
65         sz = 1;
66       else
67         {
68           char *name;
69           
70           name = TYPE_NAME (ptr_target);
71           if (name == NULL)
72             name = TYPE_TAG_NAME (ptr_target);
73           if (name == NULL)
74             error ("Cannot perform pointer math on incomplete types, "
75                    "try casting to a known type, or void *.");
76           else
77             error ("Cannot perform pointer math on incomplete type \"%s\", "
78                    "try casting to a known type, or void *.", name);
79         }
80     }
81   return sz;
82 }
83
84 struct value *
85 value_add (struct value *arg1, struct value *arg2)
86 {
87   struct value *valint;
88   struct value *valptr;
89   LONGEST sz;
90   struct type *type1, *type2, *valptrtype;
91
92   COERCE_NUMBER (arg1);
93   COERCE_NUMBER (arg2);
94   type1 = check_typedef (VALUE_TYPE (arg1));
95   type2 = check_typedef (VALUE_TYPE (arg2));
96
97   if ((TYPE_CODE (type1) == TYPE_CODE_PTR
98        || TYPE_CODE (type2) == TYPE_CODE_PTR)
99       &&
100       (TYPE_CODE (type1) == TYPE_CODE_INT
101        || TYPE_CODE (type2) == TYPE_CODE_INT))
102     /* Exactly one argument is a pointer, and one is an integer.  */
103     {
104       struct value *retval;
105
106       if (TYPE_CODE (type1) == TYPE_CODE_PTR)
107         {
108           valptr = arg1;
109           valint = arg2;
110           valptrtype = type1;
111         }
112       else
113         {
114           valptr = arg2;
115           valint = arg1;
116           valptrtype = type2;
117         }
118
119       sz = find_size_for_pointer_math (valptrtype);
120
121       retval = value_from_pointer (valptrtype,
122                                    value_as_address (valptr)
123                                    + (sz * value_as_long (valint)));
124       VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (valptr);
125       return retval;
126     }
127
128   return value_binop (arg1, arg2, BINOP_ADD);
129 }
130
131 struct value *
132 value_sub (struct value *arg1, struct value *arg2)
133 {
134   struct type *type1, *type2;
135   COERCE_NUMBER (arg1);
136   COERCE_NUMBER (arg2);
137   type1 = check_typedef (VALUE_TYPE (arg1));
138   type2 = check_typedef (VALUE_TYPE (arg2));
139
140   if (TYPE_CODE (type1) == TYPE_CODE_PTR)
141     {
142       if (TYPE_CODE (type2) == TYPE_CODE_INT)
143         {
144           /* pointer - integer.  */
145           LONGEST sz = find_size_for_pointer_math (type1);
146
147           return value_from_pointer (type1,
148                                      (value_as_address (arg1)
149                                       - (sz * value_as_long (arg2))));
150         }
151       else if (TYPE_CODE (type2) == TYPE_CODE_PTR
152                && TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)))
153                == TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2))))
154         {
155           /* pointer to <type x> - pointer to <type x>.  */
156           LONGEST sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)));
157           return value_from_longest
158             (builtin_type_long, /* FIXME -- should be ptrdiff_t */
159              (value_as_long (arg1) - value_as_long (arg2)) / sz);
160         }
161       else
162         {
163           error ("\
164 First argument of `-' is a pointer and second argument is neither\n\
165 an integer nor a pointer of the same type.");
166         }
167     }
168
169   return value_binop (arg1, arg2, BINOP_SUB);
170 }
171
172 /* Return the value of ARRAY[IDX].
173    See comments in value_coerce_array() for rationale for reason for
174    doing lower bounds adjustment here rather than there.
175    FIXME:  Perhaps we should validate that the index is valid and if
176    verbosity is set, warn about invalid indices (but still use them). */
177
178 struct value *
179 value_subscript (struct value *array, struct value *idx)
180 {
181   struct value *bound;
182   int c_style = current_language->c_style_arrays;
183   struct type *tarray;
184
185   COERCE_REF (array);
186   tarray = check_typedef (VALUE_TYPE (array));
187   COERCE_VARYING_ARRAY (array, tarray);
188
189   if (TYPE_CODE (tarray) == TYPE_CODE_ARRAY
190       || TYPE_CODE (tarray) == TYPE_CODE_STRING)
191     {
192       struct type *range_type = TYPE_INDEX_TYPE (tarray);
193       LONGEST lowerbound, upperbound;
194       get_discrete_bounds (range_type, &lowerbound, &upperbound);
195
196       if (VALUE_LVAL (array) != lval_memory)
197         return value_subscripted_rvalue (array, idx, lowerbound);
198
199       if (c_style == 0)
200         {
201           LONGEST index = value_as_long (idx);
202           if (index >= lowerbound && index <= upperbound)
203             return value_subscripted_rvalue (array, idx, lowerbound);
204           warning ("array or string index out of range");
205           /* fall doing C stuff */
206           c_style = 1;
207         }
208
209       if (lowerbound != 0)
210         {
211           bound = value_from_longest (builtin_type_int, (LONGEST) lowerbound);
212           idx = value_sub (idx, bound);
213         }
214
215       array = value_coerce_array (array);
216     }
217
218   if (TYPE_CODE (tarray) == TYPE_CODE_BITSTRING)
219     {
220       struct type *range_type = TYPE_INDEX_TYPE (tarray);
221       LONGEST index = value_as_long (idx);
222       struct value *v;
223       int offset, byte, bit_index;
224       LONGEST lowerbound, upperbound;
225       get_discrete_bounds (range_type, &lowerbound, &upperbound);
226       if (index < lowerbound || index > upperbound)
227         error ("bitstring index out of range");
228       index -= lowerbound;
229       offset = index / TARGET_CHAR_BIT;
230       byte = *((char *) VALUE_CONTENTS (array) + offset);
231       bit_index = index % TARGET_CHAR_BIT;
232       byte >>= (BITS_BIG_ENDIAN ? TARGET_CHAR_BIT - 1 - bit_index : bit_index);
233       v = value_from_longest (LA_BOOL_TYPE, byte & 1);
234       VALUE_BITPOS (v) = bit_index;
235       VALUE_BITSIZE (v) = 1;
236       VALUE_LVAL (v) = VALUE_LVAL (array);
237       if (VALUE_LVAL (array) == lval_internalvar)
238         VALUE_LVAL (v) = lval_internalvar_component;
239       VALUE_ADDRESS (v) = VALUE_ADDRESS (array);
240       VALUE_OFFSET (v) = offset + VALUE_OFFSET (array);
241       return v;
242     }
243
244   if (c_style)
245     return value_ind (value_add (array, idx));
246   else
247     error ("not an array or string");
248 }
249
250 /* Return the value of EXPR[IDX], expr an aggregate rvalue
251    (eg, a vector register).  This routine used to promote floats
252    to doubles, but no longer does.  */
253
254 static struct value *
255 value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound)
256 {
257   struct type *array_type = check_typedef (VALUE_TYPE (array));
258   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
259   unsigned int elt_size = TYPE_LENGTH (elt_type);
260   LONGEST index = value_as_long (idx);
261   unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
262   struct value *v;
263
264   if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
265     error ("no such vector element");
266
267   v = allocate_value (elt_type);
268   if (VALUE_LAZY (array))
269     VALUE_LAZY (v) = 1;
270   else
271     memcpy (VALUE_CONTENTS (v), VALUE_CONTENTS (array) + elt_offs, elt_size);
272
273   if (VALUE_LVAL (array) == lval_internalvar)
274     VALUE_LVAL (v) = lval_internalvar_component;
275   else
276     VALUE_LVAL (v) = VALUE_LVAL (array);
277   VALUE_ADDRESS (v) = VALUE_ADDRESS (array);
278   VALUE_OFFSET (v) = VALUE_OFFSET (array) + elt_offs;
279   return v;
280 }
281 \f
282 /* Check to see if either argument is a structure.  This is called so
283    we know whether to go ahead with the normal binop or look for a 
284    user defined function instead.
285
286    For now, we do not overload the `=' operator.  */
287
288 int
289 binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2)
290 {
291   struct type *type1, *type2;
292   if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
293     return 0;
294   type1 = check_typedef (VALUE_TYPE (arg1));
295   type2 = check_typedef (VALUE_TYPE (arg2));
296   return (TYPE_CODE (type1) == TYPE_CODE_STRUCT
297           || TYPE_CODE (type2) == TYPE_CODE_STRUCT
298           || (TYPE_CODE (type1) == TYPE_CODE_REF
299               && TYPE_CODE (TYPE_TARGET_TYPE (type1)) == TYPE_CODE_STRUCT)
300           || (TYPE_CODE (type2) == TYPE_CODE_REF
301               && TYPE_CODE (TYPE_TARGET_TYPE (type2)) == TYPE_CODE_STRUCT));
302 }
303
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.
307
308    For now, we do not overload the `&' operator.  */
309
310 int
311 unop_user_defined_p (enum exp_opcode op, struct value *arg1)
312 {
313   struct type *type1;
314   if (op == UNOP_ADDR)
315     return 0;
316   type1 = check_typedef (VALUE_TYPE (arg1));
317   for (;;)
318     {
319       if (TYPE_CODE (type1) == TYPE_CODE_STRUCT)
320         return 1;
321       else if (TYPE_CODE (type1) == TYPE_CODE_REF)
322         type1 = TYPE_TARGET_TYPE (type1);
323       else
324         return 0;
325     }
326 }
327
328 /* We know either arg1 or arg2 is a structure, so try to find the right
329    user defined function.  Create an argument vector that calls 
330    arg1.operator @ (arg1,arg2) and return that value (where '@' is any
331    binary operator which is legal for GNU C++).
332
333    OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
334    is the opcode saying how to modify it.  Otherwise, OTHEROP is
335    unused.  */
336
337 struct value *
338 value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
339                enum exp_opcode otherop, enum noside noside)
340 {
341   struct value **argvec;
342   char *ptr;
343   char tstr[13];
344   int static_memfuncp;
345
346   COERCE_REF (arg1);
347   COERCE_REF (arg2);
348   COERCE_ENUM (arg1);
349   COERCE_ENUM (arg2);
350
351   /* now we know that what we have to do is construct our
352      arg vector and find the right function to call it with.  */
353
354   if (TYPE_CODE (check_typedef (VALUE_TYPE (arg1))) != TYPE_CODE_STRUCT)
355     error ("Can't do that binary op on that type");     /* FIXME be explicit */
356
357   argvec = (struct value **) alloca (sizeof (struct value *) * 4);
358   argvec[1] = value_addr (arg1);
359   argvec[2] = arg2;
360   argvec[3] = 0;
361
362   /* make the right function name up */
363   strcpy (tstr, "operator__");
364   ptr = tstr + 8;
365   switch (op)
366     {
367     case BINOP_ADD:
368       strcpy (ptr, "+");
369       break;
370     case BINOP_SUB:
371       strcpy (ptr, "-");
372       break;
373     case BINOP_MUL:
374       strcpy (ptr, "*");
375       break;
376     case BINOP_DIV:
377       strcpy (ptr, "/");
378       break;
379     case BINOP_REM:
380       strcpy (ptr, "%");
381       break;
382     case BINOP_LSH:
383       strcpy (ptr, "<<");
384       break;
385     case BINOP_RSH:
386       strcpy (ptr, ">>");
387       break;
388     case BINOP_BITWISE_AND:
389       strcpy (ptr, "&");
390       break;
391     case BINOP_BITWISE_IOR:
392       strcpy (ptr, "|");
393       break;
394     case BINOP_BITWISE_XOR:
395       strcpy (ptr, "^");
396       break;
397     case BINOP_LOGICAL_AND:
398       strcpy (ptr, "&&");
399       break;
400     case BINOP_LOGICAL_OR:
401       strcpy (ptr, "||");
402       break;
403     case BINOP_MIN:
404       strcpy (ptr, "<?");
405       break;
406     case BINOP_MAX:
407       strcpy (ptr, ">?");
408       break;
409     case BINOP_ASSIGN:
410       strcpy (ptr, "=");
411       break;
412     case BINOP_ASSIGN_MODIFY:
413       switch (otherop)
414         {
415         case BINOP_ADD:
416           strcpy (ptr, "+=");
417           break;
418         case BINOP_SUB:
419           strcpy (ptr, "-=");
420           break;
421         case BINOP_MUL:
422           strcpy (ptr, "*=");
423           break;
424         case BINOP_DIV:
425           strcpy (ptr, "/=");
426           break;
427         case BINOP_REM:
428           strcpy (ptr, "%=");
429           break;
430         case BINOP_BITWISE_AND:
431           strcpy (ptr, "&=");
432           break;
433         case BINOP_BITWISE_IOR:
434           strcpy (ptr, "|=");
435           break;
436         case BINOP_BITWISE_XOR:
437           strcpy (ptr, "^=");
438           break;
439         case BINOP_MOD: /* invalid */
440         default:
441           error ("Invalid binary operation specified.");
442         }
443       break;
444     case BINOP_SUBSCRIPT:
445       strcpy (ptr, "[]");
446       break;
447     case BINOP_EQUAL:
448       strcpy (ptr, "==");
449       break;
450     case BINOP_NOTEQUAL:
451       strcpy (ptr, "!=");
452       break;
453     case BINOP_LESS:
454       strcpy (ptr, "<");
455       break;
456     case BINOP_GTR:
457       strcpy (ptr, ">");
458       break;
459     case BINOP_GEQ:
460       strcpy (ptr, ">=");
461       break;
462     case BINOP_LEQ:
463       strcpy (ptr, "<=");
464       break;
465     case BINOP_MOD:             /* invalid */
466     default:
467       error ("Invalid binary operation specified.");
468     }
469
470   argvec[0] = value_struct_elt (&arg1, argvec + 1, tstr, &static_memfuncp, "structure");
471
472   if (argvec[0])
473     {
474       if (static_memfuncp)
475         {
476           argvec[1] = argvec[0];
477           argvec++;
478         }
479       if (noside == EVAL_AVOID_SIDE_EFFECTS)
480         {
481           struct type *return_type;
482           return_type
483             = TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (argvec[0])));
484           return value_zero (return_type, VALUE_LVAL (arg1));
485         }
486       return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
487     }
488   error ("member function %s not found", tstr);
489 #ifdef lint
490   return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
491 #endif
492 }
493
494 /* We know that arg1 is a structure, so try to find a unary user
495    defined operator that matches the operator in question.  
496    Create an argument vector that calls arg1.operator @ (arg1)
497    and return that value (where '@' is (almost) any unary operator which
498    is legal for GNU C++).  */
499
500 struct value *
501 value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
502 {
503   struct value **argvec;
504   char *ptr, *mangle_ptr;
505   char tstr[13], mangle_tstr[13];
506   int static_memfuncp, nargs;
507
508   COERCE_REF (arg1);
509   COERCE_ENUM (arg1);
510
511   /* now we know that what we have to do is construct our
512      arg vector and find the right function to call it with.  */
513
514   if (TYPE_CODE (check_typedef (VALUE_TYPE (arg1))) != TYPE_CODE_STRUCT)
515     error ("Can't do that unary op on that type");      /* FIXME be explicit */
516
517   argvec = (struct value **) alloca (sizeof (struct value *) * 4);
518   argvec[1] = value_addr (arg1);
519   argvec[2] = 0;
520
521   nargs = 1;
522
523   /* make the right function name up */
524   strcpy (tstr, "operator__");
525   ptr = tstr + 8;
526   strcpy (mangle_tstr, "__");
527   mangle_ptr = mangle_tstr + 2;
528   switch (op)
529     {
530     case UNOP_PREINCREMENT:
531       strcpy (ptr, "++");
532       break;
533     case UNOP_PREDECREMENT:
534       strcpy (ptr, "--");
535       break;
536     case UNOP_POSTINCREMENT:
537       strcpy (ptr, "++");
538       argvec[2] = value_from_longest (builtin_type_int, 0);
539       argvec[3] = 0;
540       nargs ++;
541       break;
542     case UNOP_POSTDECREMENT:
543       strcpy (ptr, "--");
544       argvec[2] = value_from_longest (builtin_type_int, 0);
545       argvec[3] = 0;
546       nargs ++;
547       break;
548     case UNOP_LOGICAL_NOT:
549       strcpy (ptr, "!");
550       break;
551     case UNOP_COMPLEMENT:
552       strcpy (ptr, "~");
553       break;
554     case UNOP_NEG:
555       strcpy (ptr, "-");
556       break;
557     case UNOP_IND:
558       strcpy (ptr, "*");
559       break;
560     default:
561       error ("Invalid unary operation specified.");
562     }
563
564   argvec[0] = value_struct_elt (&arg1, argvec + 1, tstr, &static_memfuncp, "structure");
565
566   if (argvec[0])
567     {
568       if (static_memfuncp)
569         {
570           argvec[1] = argvec[0];
571           nargs --;
572           argvec++;
573         }
574       if (noside == EVAL_AVOID_SIDE_EFFECTS)
575         {
576           struct type *return_type;
577           return_type
578             = TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (argvec[0])));
579           return value_zero (return_type, VALUE_LVAL (arg1));
580         }
581       return call_function_by_hand (argvec[0], nargs, argvec + 1);
582     }
583   error ("member function %s not found", tstr);
584   return 0;                     /* For lint -- never reached */
585 }
586 \f
587
588 /* Concatenate two values with the following conditions:
589
590    (1)  Both values must be either bitstring values or character string
591    values and the resulting value consists of the concatenation of
592    ARG1 followed by ARG2.
593
594    or
595
596    One value must be an integer value and the other value must be
597    either a bitstring value or character string value, which is
598    to be repeated by the number of times specified by the integer
599    value.
600
601
602    (2)  Boolean values are also allowed and are treated as bit string
603    values of length 1.
604
605    (3)  Character values are also allowed and are treated as character
606    string values of length 1.
607  */
608
609 struct value *
610 value_concat (struct value *arg1, struct value *arg2)
611 {
612   struct value *inval1;
613   struct value *inval2;
614   struct value *outval = NULL;
615   int inval1len, inval2len;
616   int count, idx;
617   char *ptr;
618   char inchar;
619   struct type *type1 = check_typedef (VALUE_TYPE (arg1));
620   struct type *type2 = check_typedef (VALUE_TYPE (arg2));
621
622   COERCE_VARYING_ARRAY (arg1, type1);
623   COERCE_VARYING_ARRAY (arg2, type2);
624
625   /* First figure out if we are dealing with two values to be concatenated
626      or a repeat count and a value to be repeated.  INVAL1 is set to the
627      first of two concatenated values, or the repeat count.  INVAL2 is set
628      to the second of the two concatenated values or the value to be 
629      repeated. */
630
631   if (TYPE_CODE (type2) == TYPE_CODE_INT)
632     {
633       struct type *tmp = type1;
634       type1 = tmp;
635       tmp = type2;
636       inval1 = arg2;
637       inval2 = arg1;
638     }
639   else
640     {
641       inval1 = arg1;
642       inval2 = arg2;
643     }
644
645   /* Now process the input values. */
646
647   if (TYPE_CODE (type1) == TYPE_CODE_INT)
648     {
649       /* We have a repeat count.  Validate the second value and then
650          construct a value repeated that many times. */
651       if (TYPE_CODE (type2) == TYPE_CODE_STRING
652           || TYPE_CODE (type2) == TYPE_CODE_CHAR)
653         {
654           count = longest_to_int (value_as_long (inval1));
655           inval2len = TYPE_LENGTH (type2);
656           ptr = (char *) alloca (count * inval2len);
657           if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
658             {
659               inchar = (char) unpack_long (type2,
660                                            VALUE_CONTENTS (inval2));
661               for (idx = 0; idx < count; idx++)
662                 {
663                   *(ptr + idx) = inchar;
664                 }
665             }
666           else
667             {
668               for (idx = 0; idx < count; idx++)
669                 {
670                   memcpy (ptr + (idx * inval2len), VALUE_CONTENTS (inval2),
671                           inval2len);
672                 }
673             }
674           outval = value_string (ptr, count * inval2len);
675         }
676       else if (TYPE_CODE (type2) == TYPE_CODE_BITSTRING
677                || TYPE_CODE (type2) == TYPE_CODE_BOOL)
678         {
679           error ("unimplemented support for bitstring/boolean repeats");
680         }
681       else
682         {
683           error ("can't repeat values of that type");
684         }
685     }
686   else if (TYPE_CODE (type1) == TYPE_CODE_STRING
687            || TYPE_CODE (type1) == TYPE_CODE_CHAR)
688     {
689       /* We have two character strings to concatenate. */
690       if (TYPE_CODE (type2) != TYPE_CODE_STRING
691           && TYPE_CODE (type2) != TYPE_CODE_CHAR)
692         {
693           error ("Strings can only be concatenated with other strings.");
694         }
695       inval1len = TYPE_LENGTH (type1);
696       inval2len = TYPE_LENGTH (type2);
697       ptr = (char *) alloca (inval1len + inval2len);
698       if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
699         {
700           *ptr = (char) unpack_long (type1, VALUE_CONTENTS (inval1));
701         }
702       else
703         {
704           memcpy (ptr, VALUE_CONTENTS (inval1), inval1len);
705         }
706       if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
707         {
708           *(ptr + inval1len) =
709             (char) unpack_long (type2, VALUE_CONTENTS (inval2));
710         }
711       else
712         {
713           memcpy (ptr + inval1len, VALUE_CONTENTS (inval2), inval2len);
714         }
715       outval = value_string (ptr, inval1len + inval2len);
716     }
717   else if (TYPE_CODE (type1) == TYPE_CODE_BITSTRING
718            || TYPE_CODE (type1) == TYPE_CODE_BOOL)
719     {
720       /* We have two bitstrings to concatenate. */
721       if (TYPE_CODE (type2) != TYPE_CODE_BITSTRING
722           && TYPE_CODE (type2) != TYPE_CODE_BOOL)
723         {
724           error ("Bitstrings or booleans can only be concatenated with other bitstrings or booleans.");
725         }
726       error ("unimplemented support for bitstring/boolean concatenation.");
727     }
728   else
729     {
730       /* We don't know how to concatenate these operands. */
731       error ("illegal operands for concatenation.");
732     }
733   return (outval);
734 }
735 \f
736
737
738 /* Perform a binary operation on two operands which have reasonable
739    representations as integers or floats.  This includes booleans,
740    characters, integers, or floats.
741    Does not support addition and subtraction on pointers;
742    use value_add or value_sub if you want to handle those possibilities.  */
743
744 struct value *
745 value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
746 {
747   struct value *val;
748   struct type *type1, *type2;
749
750   COERCE_REF (arg1);
751   COERCE_REF (arg2);
752   COERCE_ENUM (arg1);
753   COERCE_ENUM (arg2);
754   type1 = check_typedef (VALUE_TYPE (arg1));
755   type2 = check_typedef (VALUE_TYPE (arg2));
756
757   if ((TYPE_CODE (type1) != TYPE_CODE_FLT
758        && TYPE_CODE (type1) != TYPE_CODE_CHAR
759        && TYPE_CODE (type1) != TYPE_CODE_INT
760        && TYPE_CODE (type1) != TYPE_CODE_BOOL
761        && TYPE_CODE (type1) != TYPE_CODE_RANGE)
762       ||
763       (TYPE_CODE (type2) != TYPE_CODE_FLT
764        && TYPE_CODE (type2) != TYPE_CODE_CHAR
765        && TYPE_CODE (type2) != TYPE_CODE_INT
766        && TYPE_CODE (type2) != TYPE_CODE_BOOL
767        && TYPE_CODE (type2) != TYPE_CODE_RANGE))
768     error ("Argument to arithmetic operation not a number or boolean.");
769
770   if (TYPE_CODE (type1) == TYPE_CODE_FLT
771       ||
772       TYPE_CODE (type2) == TYPE_CODE_FLT)
773     {
774       /* FIXME-if-picky-about-floating-accuracy: Should be doing this
775          in target format.  real.c in GCC probably has the necessary
776          code.  */
777       DOUBLEST v1, v2, v = 0;
778       v1 = value_as_double (arg1);
779       v2 = value_as_double (arg2);
780       switch (op)
781         {
782         case BINOP_ADD:
783           v = v1 + v2;
784           break;
785
786         case BINOP_SUB:
787           v = v1 - v2;
788           break;
789
790         case BINOP_MUL:
791           v = v1 * v2;
792           break;
793
794         case BINOP_DIV:
795           v = v1 / v2;
796           break;
797
798         case BINOP_EXP:
799           v = pow (v1, v2);
800           if (errno)
801             error ("Cannot perform exponentiation: %s", safe_strerror (errno));
802           break;
803
804         default:
805           error ("Integer-only operation on floating point number.");
806         }
807
808       /* If either arg was long double, make sure that value is also long
809          double.  */
810
811       if (TYPE_LENGTH (type1) * 8 > TARGET_DOUBLE_BIT
812           || TYPE_LENGTH (type2) * 8 > TARGET_DOUBLE_BIT)
813         val = allocate_value (builtin_type_long_double);
814       else
815         val = allocate_value (builtin_type_double);
816
817       store_typed_floating (VALUE_CONTENTS_RAW (val), VALUE_TYPE (val), v);
818     }
819   else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
820            &&
821            TYPE_CODE (type2) == TYPE_CODE_BOOL)
822     {
823       LONGEST v1, v2, v = 0;
824       v1 = value_as_long (arg1);
825       v2 = value_as_long (arg2);
826
827       switch (op)
828         {
829         case BINOP_BITWISE_AND:
830           v = v1 & v2;
831           break;
832
833         case BINOP_BITWISE_IOR:
834           v = v1 | v2;
835           break;
836
837         case BINOP_BITWISE_XOR:
838           v = v1 ^ v2;
839           break;
840               
841         case BINOP_EQUAL:
842           v = v1 == v2;
843           break;
844           
845         case BINOP_NOTEQUAL:
846           v = v1 != v2;
847           break;
848
849         default:
850           error ("Invalid operation on booleans.");
851         }
852
853       val = allocate_value (type1);
854       store_signed_integer (VALUE_CONTENTS_RAW (val),
855                             TYPE_LENGTH (type1),
856                             v);
857     }
858   else
859     /* Integral operations here.  */
860     /* FIXME:  Also mixed integral/booleans, with result an integer. */
861     /* FIXME: This implements ANSI C rules (also correct for C++).
862        What about FORTRAN and (the deleted) chill ?  */
863     {
864       unsigned int promoted_len1 = TYPE_LENGTH (type1);
865       unsigned int promoted_len2 = TYPE_LENGTH (type2);
866       int is_unsigned1 = TYPE_UNSIGNED (type1);
867       int is_unsigned2 = TYPE_UNSIGNED (type2);
868       unsigned int result_len;
869       int unsigned_operation;
870
871       /* Determine type length and signedness after promotion for
872          both operands.  */
873       if (promoted_len1 < TYPE_LENGTH (builtin_type_int))
874         {
875           is_unsigned1 = 0;
876           promoted_len1 = TYPE_LENGTH (builtin_type_int);
877         }
878       if (promoted_len2 < TYPE_LENGTH (builtin_type_int))
879         {
880           is_unsigned2 = 0;
881           promoted_len2 = TYPE_LENGTH (builtin_type_int);
882         }
883
884       /* Determine type length of the result, and if the operation should
885          be done unsigned.
886          Use the signedness of the operand with the greater length.
887          If both operands are of equal length, use unsigned operation
888          if one of the operands is unsigned.  */
889       if (promoted_len1 > promoted_len2)
890         {
891           unsigned_operation = is_unsigned1;
892           result_len = promoted_len1;
893         }
894       else if (promoted_len2 > promoted_len1)
895         {
896           unsigned_operation = is_unsigned2;
897           result_len = promoted_len2;
898         }
899       else
900         {
901           unsigned_operation = is_unsigned1 || is_unsigned2;
902           result_len = promoted_len1;
903         }
904
905       if (unsigned_operation)
906         {
907           ULONGEST v1, v2, v = 0;
908           v1 = (ULONGEST) value_as_long (arg1);
909           v2 = (ULONGEST) value_as_long (arg2);
910
911           /* Truncate values to the type length of the result.  */
912           if (result_len < sizeof (ULONGEST))
913             {
914               v1 &= ((LONGEST) 1 << HOST_CHAR_BIT * result_len) - 1;
915               v2 &= ((LONGEST) 1 << HOST_CHAR_BIT * result_len) - 1;
916             }
917
918           switch (op)
919             {
920             case BINOP_ADD:
921               v = v1 + v2;
922               break;
923
924             case BINOP_SUB:
925               v = v1 - v2;
926               break;
927
928             case BINOP_MUL:
929               v = v1 * v2;
930               break;
931
932             case BINOP_DIV:
933               v = v1 / v2;
934               break;
935
936             case BINOP_EXP:
937               v = pow (v1, v2);
938               if (errno)
939                 error ("Cannot perform exponentiation: %s", safe_strerror (errno));
940               break;
941
942             case BINOP_REM:
943               v = v1 % v2;
944               break;
945
946             case BINOP_MOD:
947               /* Knuth 1.2.4, integer only.  Note that unlike the C '%' op,
948                  v1 mod 0 has a defined value, v1. */
949               if (v2 == 0)
950                 {
951                   v = v1;
952                 }
953               else
954                 {
955                   v = v1 / v2;
956                   /* Note floor(v1/v2) == v1/v2 for unsigned. */
957                   v = v1 - (v2 * v);
958                 }
959               break;
960
961             case BINOP_LSH:
962               v = v1 << v2;
963               break;
964
965             case BINOP_RSH:
966               v = v1 >> v2;
967               break;
968
969             case BINOP_BITWISE_AND:
970               v = v1 & v2;
971               break;
972
973             case BINOP_BITWISE_IOR:
974               v = v1 | v2;
975               break;
976
977             case BINOP_BITWISE_XOR:
978               v = v1 ^ v2;
979               break;
980
981             case BINOP_LOGICAL_AND:
982               v = v1 && v2;
983               break;
984
985             case BINOP_LOGICAL_OR:
986               v = v1 || v2;
987               break;
988
989             case BINOP_MIN:
990               v = v1 < v2 ? v1 : v2;
991               break;
992
993             case BINOP_MAX:
994               v = v1 > v2 ? v1 : v2;
995               break;
996
997             case BINOP_EQUAL:
998               v = v1 == v2;
999               break;
1000
1001             case BINOP_NOTEQUAL:
1002               v = v1 != v2;
1003               break;
1004
1005             case BINOP_LESS:
1006               v = v1 < v2;
1007               break;
1008
1009             default:
1010               error ("Invalid binary operation on numbers.");
1011             }
1012
1013           /* This is a kludge to get around the fact that we don't
1014              know how to determine the result type from the types of
1015              the operands.  (I'm not really sure how much we feel the
1016              need to duplicate the exact rules of the current
1017              language.  They can get really hairy.  But not to do so
1018              makes it hard to document just what we *do* do).  */
1019
1020           /* Can't just call init_type because we wouldn't know what
1021              name to give the type.  */
1022           val = allocate_value
1023             (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
1024              ? builtin_type_unsigned_long_long
1025              : builtin_type_unsigned_long);
1026           store_unsigned_integer (VALUE_CONTENTS_RAW (val),
1027                                   TYPE_LENGTH (VALUE_TYPE (val)),
1028                                   v);
1029         }
1030       else
1031         {
1032           LONGEST v1, v2, v = 0;
1033           v1 = value_as_long (arg1);
1034           v2 = value_as_long (arg2);
1035
1036           switch (op)
1037             {
1038             case BINOP_ADD:
1039               v = v1 + v2;
1040               break;
1041
1042             case BINOP_SUB:
1043               v = v1 - v2;
1044               break;
1045
1046             case BINOP_MUL:
1047               v = v1 * v2;
1048               break;
1049
1050             case BINOP_DIV:
1051               v = v1 / v2;
1052               break;
1053
1054             case BINOP_EXP:
1055               v = pow (v1, v2);
1056               if (errno)
1057                 error ("Cannot perform exponentiation: %s", safe_strerror (errno));
1058               break;
1059
1060             case BINOP_REM:
1061               v = v1 % v2;
1062               break;
1063
1064             case BINOP_MOD:
1065               /* Knuth 1.2.4, integer only.  Note that unlike the C '%' op,
1066                  X mod 0 has a defined value, X. */
1067               if (v2 == 0)
1068                 {
1069                   v = v1;
1070                 }
1071               else
1072                 {
1073                   v = v1 / v2;
1074                   /* Compute floor. */
1075                   if (TRUNCATION_TOWARDS_ZERO && (v < 0) && ((v1 % v2) != 0))
1076                     {
1077                       v--;
1078                     }
1079                   v = v1 - (v2 * v);
1080                 }
1081               break;
1082
1083             case BINOP_LSH:
1084               v = v1 << v2;
1085               break;
1086
1087             case BINOP_RSH:
1088               v = v1 >> v2;
1089               break;
1090
1091             case BINOP_BITWISE_AND:
1092               v = v1 & v2;
1093               break;
1094
1095             case BINOP_BITWISE_IOR:
1096               v = v1 | v2;
1097               break;
1098
1099             case BINOP_BITWISE_XOR:
1100               v = v1 ^ v2;
1101               break;
1102
1103             case BINOP_LOGICAL_AND:
1104               v = v1 && v2;
1105               break;
1106
1107             case BINOP_LOGICAL_OR:
1108               v = v1 || v2;
1109               break;
1110
1111             case BINOP_MIN:
1112               v = v1 < v2 ? v1 : v2;
1113               break;
1114
1115             case BINOP_MAX:
1116               v = v1 > v2 ? v1 : v2;
1117               break;
1118
1119             case BINOP_EQUAL:
1120               v = v1 == v2;
1121               break;
1122
1123             case BINOP_LESS:
1124               v = v1 < v2;
1125               break;
1126
1127             default:
1128               error ("Invalid binary operation on numbers.");
1129             }
1130
1131           /* This is a kludge to get around the fact that we don't
1132              know how to determine the result type from the types of
1133              the operands.  (I'm not really sure how much we feel the
1134              need to duplicate the exact rules of the current
1135              language.  They can get really hairy.  But not to do so
1136              makes it hard to document just what we *do* do).  */
1137
1138           /* Can't just call init_type because we wouldn't know what
1139              name to give the type.  */
1140           val = allocate_value
1141             (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
1142              ? builtin_type_long_long
1143              : builtin_type_long);
1144           store_signed_integer (VALUE_CONTENTS_RAW (val),
1145                                 TYPE_LENGTH (VALUE_TYPE (val)),
1146                                 v);
1147         }
1148     }
1149
1150   return val;
1151 }
1152 \f
1153 /* Simulate the C operator ! -- return 1 if ARG1 contains zero.  */
1154
1155 int
1156 value_logical_not (struct value *arg1)
1157 {
1158   register int len;
1159   register char *p;
1160   struct type *type1;
1161
1162   COERCE_NUMBER (arg1);
1163   type1 = check_typedef (VALUE_TYPE (arg1));
1164
1165   if (TYPE_CODE (type1) == TYPE_CODE_FLT)
1166     return 0 == value_as_double (arg1);
1167
1168   len = TYPE_LENGTH (type1);
1169   p = VALUE_CONTENTS (arg1);
1170
1171   while (--len >= 0)
1172     {
1173       if (*p++)
1174         break;
1175     }
1176
1177   return len < 0;
1178 }
1179
1180 /* Perform a comparison on two string values (whose content are not
1181    necessarily null terminated) based on their length */
1182
1183 static int
1184 value_strcmp (struct value *arg1, struct value *arg2)
1185 {
1186   int len1 = TYPE_LENGTH (VALUE_TYPE (arg1));
1187   int len2 = TYPE_LENGTH (VALUE_TYPE (arg2));
1188   char *s1 = VALUE_CONTENTS (arg1);
1189   char *s2 = VALUE_CONTENTS (arg2);
1190   int i, len = len1 < len2 ? len1 : len2;
1191
1192   for (i = 0; i < len; i++)
1193     {
1194       if (s1[i] < s2[i])
1195         return -1;
1196       else if (s1[i] > s2[i])
1197         return 1;
1198       else
1199         continue;
1200     }
1201
1202   if (len1 < len2)
1203     return -1;
1204   else if (len1 > len2)
1205     return 1;
1206   else
1207     return 0;
1208 }
1209
1210 /* Simulate the C operator == by returning a 1
1211    iff ARG1 and ARG2 have equal contents.  */
1212
1213 int
1214 value_equal (struct value *arg1, struct value *arg2)
1215 {
1216   register int len;
1217   register char *p1, *p2;
1218   struct type *type1, *type2;
1219   enum type_code code1;
1220   enum type_code code2;
1221
1222   COERCE_NUMBER (arg1);
1223   COERCE_NUMBER (arg2);
1224
1225   type1 = check_typedef (VALUE_TYPE (arg1));
1226   type2 = check_typedef (VALUE_TYPE (arg2));
1227   code1 = TYPE_CODE (type1);
1228   code2 = TYPE_CODE (type2);
1229
1230   if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL) &&
1231       (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1232     return longest_to_int (value_as_long (value_binop (arg1, arg2,
1233                                                        BINOP_EQUAL)));
1234   else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL)
1235            && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1236     return value_as_double (arg1) == value_as_double (arg2);
1237
1238   /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1239      is bigger.  */
1240   else if (code1 == TYPE_CODE_PTR && (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1241     return value_as_address (arg1) == (CORE_ADDR) value_as_long (arg2);
1242   else if (code2 == TYPE_CODE_PTR && (code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL))
1243     return (CORE_ADDR) value_as_long (arg1) == value_as_address (arg2);
1244
1245   else if (code1 == code2
1246            && ((len = (int) TYPE_LENGTH (type1))
1247                == (int) TYPE_LENGTH (type2)))
1248     {
1249       p1 = VALUE_CONTENTS (arg1);
1250       p2 = VALUE_CONTENTS (arg2);
1251       while (--len >= 0)
1252         {
1253           if (*p1++ != *p2++)
1254             break;
1255         }
1256       return len < 0;
1257     }
1258   else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1259     {
1260       return value_strcmp (arg1, arg2) == 0;
1261     }
1262   else
1263     {
1264       error ("Invalid type combination in equality test.");
1265       return 0;                 /* For lint -- never reached */
1266     }
1267 }
1268
1269 /* Simulate the C operator < by returning 1
1270    iff ARG1's contents are less than ARG2's.  */
1271
1272 int
1273 value_less (struct value *arg1, struct value *arg2)
1274 {
1275   register enum type_code code1;
1276   register enum type_code code2;
1277   struct type *type1, *type2;
1278
1279   COERCE_NUMBER (arg1);
1280   COERCE_NUMBER (arg2);
1281
1282   type1 = check_typedef (VALUE_TYPE (arg1));
1283   type2 = check_typedef (VALUE_TYPE (arg2));
1284   code1 = TYPE_CODE (type1);
1285   code2 = TYPE_CODE (type2);
1286
1287   if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL) &&
1288       (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1289     return longest_to_int (value_as_long (value_binop (arg1, arg2,
1290                                                        BINOP_LESS)));
1291   else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL)
1292            && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1293     return value_as_double (arg1) < value_as_double (arg2);
1294   else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
1295     return value_as_address (arg1) < value_as_address (arg2);
1296
1297   /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1298      is bigger.  */
1299   else if (code1 == TYPE_CODE_PTR && (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
1300     return value_as_address (arg1) < (CORE_ADDR) value_as_long (arg2);
1301   else if (code2 == TYPE_CODE_PTR && (code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL))
1302     return (CORE_ADDR) value_as_long (arg1) < value_as_address (arg2);
1303   else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1304     return value_strcmp (arg1, arg2) < 0;
1305   else
1306     {
1307       error ("Invalid type combination in ordering comparison.");
1308       return 0;
1309     }
1310 }
1311 \f
1312 /* The unary operators - and ~.  Both free the argument ARG1.  */
1313
1314 struct value *
1315 value_neg (struct value *arg1)
1316 {
1317   register struct type *type;
1318   register struct type *result_type = VALUE_TYPE (arg1);
1319
1320   COERCE_REF (arg1);
1321   COERCE_ENUM (arg1);
1322
1323   type = check_typedef (VALUE_TYPE (arg1));
1324
1325   if (TYPE_CODE (type) == TYPE_CODE_FLT)
1326     return value_from_double (result_type, -value_as_double (arg1));
1327   else if (TYPE_CODE (type) == TYPE_CODE_INT || TYPE_CODE (type) == TYPE_CODE_BOOL)
1328     {
1329       /* Perform integral promotion for ANSI C/C++.  FIXME: What about
1330          FORTRAN and (the deleted) chill ?  */
1331       if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
1332         result_type = builtin_type_int;
1333
1334       return value_from_longest (result_type, -value_as_long (arg1));
1335     }
1336   else
1337     {
1338       error ("Argument to negate operation not a number.");
1339       return 0;                 /* For lint -- never reached */
1340     }
1341 }
1342
1343 struct value *
1344 value_complement (struct value *arg1)
1345 {
1346   register struct type *type;
1347   register struct type *result_type = VALUE_TYPE (arg1);
1348   int typecode;
1349
1350   COERCE_REF (arg1);
1351   COERCE_ENUM (arg1);
1352
1353   type = check_typedef (VALUE_TYPE (arg1));
1354
1355   typecode = TYPE_CODE (type);
1356   if ((typecode != TYPE_CODE_INT) && (typecode != TYPE_CODE_BOOL))
1357     error ("Argument to complement operation not an integer or boolean.");
1358
1359   /* Perform integral promotion for ANSI C/C++.
1360      FIXME: What about FORTRAN ?  */
1361   if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
1362     result_type = builtin_type_int;
1363
1364   return value_from_longest (result_type, ~value_as_long (arg1));
1365 }
1366 \f
1367 /* The INDEX'th bit of SET value whose VALUE_TYPE is TYPE,
1368    and whose VALUE_CONTENTS is valaddr.
1369    Return -1 if out of range, -2 other error. */
1370
1371 int
1372 value_bit_index (struct type *type, char *valaddr, int index)
1373 {
1374   LONGEST low_bound, high_bound;
1375   LONGEST word;
1376   unsigned rel_index;
1377   struct type *range = TYPE_FIELD_TYPE (type, 0);
1378   if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
1379     return -2;
1380   if (index < low_bound || index > high_bound)
1381     return -1;
1382   rel_index = index - low_bound;
1383   word = unpack_long (builtin_type_unsigned_char,
1384                       valaddr + (rel_index / TARGET_CHAR_BIT));
1385   rel_index %= TARGET_CHAR_BIT;
1386   if (BITS_BIG_ENDIAN)
1387     rel_index = TARGET_CHAR_BIT - 1 - rel_index;
1388   return (word >> rel_index) & 1;
1389 }
1390
1391 struct value *
1392 value_in (struct value *element, struct value *set)
1393 {
1394   int member;
1395   struct type *settype = check_typedef (VALUE_TYPE (set));
1396   struct type *eltype = check_typedef (VALUE_TYPE (element));
1397   if (TYPE_CODE (eltype) == TYPE_CODE_RANGE)
1398     eltype = TYPE_TARGET_TYPE (eltype);
1399   if (TYPE_CODE (settype) != TYPE_CODE_SET)
1400     error ("Second argument of 'IN' has wrong type");
1401   if (TYPE_CODE (eltype) != TYPE_CODE_INT
1402       && TYPE_CODE (eltype) != TYPE_CODE_CHAR
1403       && TYPE_CODE (eltype) != TYPE_CODE_ENUM
1404       && TYPE_CODE (eltype) != TYPE_CODE_BOOL)
1405     error ("First argument of 'IN' has wrong type");
1406   member = value_bit_index (settype, VALUE_CONTENTS (set),
1407                             value_as_long (element));
1408   if (member < 0)
1409     error ("First argument of 'IN' not in range");
1410   return value_from_longest (LA_BOOL_TYPE, member);
1411 }
1412
1413 void
1414 _initialize_valarith (void)
1415 {
1416 }