1 /* Perform arithmetic and other operations on values, for GDB.
2 Copyright 1986, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "expression.h"
29 /* Define whether or not the C operator '/' truncates towards zero for
30 differently signed operands (truncation direction is undefined in C). */
32 #ifndef TRUNCATION_TOWARDS_ZERO
33 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
37 value_subscripted_rvalue PARAMS ((value, value));
41 value_add (arg1, arg2)
44 register value valint, valptr;
50 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR
51 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR)
53 (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT
54 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT))
55 /* Exactly one argument is a pointer, and one is an integer. */
57 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
67 len = TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (valptr)));
68 if (len == 0) len = 1; /* For (void *) */
69 return value_from_longest (VALUE_TYPE (valptr),
70 value_as_long (valptr)
71 + (len * value_as_long (valint)));
74 return value_binop (arg1, arg2, BINOP_ADD);
78 value_sub (arg1, arg2)
85 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
87 if (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT)
89 /* pointer - integer. */
90 return value_from_longest
93 - (TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)))
94 * value_as_long (arg2)));
96 else if (VALUE_TYPE (arg1) == VALUE_TYPE (arg2))
98 /* pointer to <type x> - pointer to <type x>. */
99 return value_from_longest
100 (builtin_type_long, /* FIXME -- should be ptrdiff_t */
101 (value_as_long (arg1) - value_as_long (arg2))
102 / TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))));
107 First argument of `-' is a pointer and second argument is neither\n\
108 an integer nor a pointer of the same type.");
112 return value_binop (arg1, arg2, BINOP_SUB);
115 /* Return the value of ARRAY[IDX].
116 See comments in value_coerce_array() for rationale for reason for
117 doing lower bounds adjustment here rather than there.
118 FIXME: Perhaps we should validate that the index is valid and if
119 verbosity is set, warn about invalid indices (but still use them). */
122 value_subscript (array, idx)
127 struct type *range_type;
129 if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY)
131 range_type = TYPE_FIELD_TYPE (VALUE_TYPE (array), 0);
132 lowerbound = TYPE_FIELD_BITPOS (range_type, 0);
135 bound = value_from_longest (builtin_type_int, (LONGEST) lowerbound);
136 idx = value_sub (idx, bound);
138 if (VALUE_LVAL (array) != lval_memory)
140 return value_subscripted_rvalue (array, idx);
143 return value_ind (value_add (array, idx));
146 /* Return the value of EXPR[IDX], expr an aggregate rvalue
147 (eg, a vector register). This routine used to promote floats
148 to doubles, but no longer does. */
151 value_subscripted_rvalue (array, idx)
154 struct type *elt_type = TYPE_TARGET_TYPE (VALUE_TYPE (array));
155 int elt_size = TYPE_LENGTH (elt_type);
156 int elt_offs = elt_size * longest_to_int (value_as_long (idx));
159 if (elt_offs >= TYPE_LENGTH (VALUE_TYPE (array)))
160 error ("no such vector element");
162 v = allocate_value (elt_type);
163 memcpy (VALUE_CONTENTS (v), VALUE_CONTENTS (array) + elt_offs, elt_size);
165 if (VALUE_LVAL (array) == lval_internalvar)
166 VALUE_LVAL (v) = lval_internalvar_component;
168 VALUE_LVAL (v) = not_lval;
169 VALUE_ADDRESS (v) = VALUE_ADDRESS (array);
170 VALUE_OFFSET (v) = VALUE_OFFSET (array) + elt_offs;
171 VALUE_BITSIZE (v) = elt_size * 8;
175 /* Check to see if either argument is a structure. This is called so
176 we know whether to go ahead with the normal binop or look for a
177 user defined function instead.
179 For now, we do not overload the `=' operator. */
182 binop_user_defined_p (op, arg1, arg2)
186 if (op == BINOP_ASSIGN)
188 return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT
189 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_STRUCT
190 || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
191 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT)
192 || (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_REF
193 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_STRUCT));
196 /* Check to see if argument is a structure. This is called so
197 we know whether to go ahead with the normal unop or look for a
198 user defined function instead.
200 For now, we do not overload the `&' operator. */
202 int unop_user_defined_p (op, arg1)
208 return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT
209 || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
210 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT));
213 /* We know either arg1 or arg2 is a structure, so try to find the right
214 user defined function. Create an argument vector that calls
215 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
216 binary operator which is legal for GNU C++).
218 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
219 is the opcode saying how to modify it. Otherwise, OTHEROP is
223 value_x_binop (arg1, arg2, op, otherop)
225 enum exp_opcode op, otherop;
237 /* now we know that what we have to do is construct our
238 arg vector and find the right function to call it with. */
240 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT)
241 error ("Can't do that binary op on that type"); /* FIXME be explicit */
243 argvec = (value *) alloca (sizeof (value) * 4);
244 argvec[1] = value_addr (arg1);
248 /* make the right function name up */
249 strcpy(tstr, "operator__");
253 case BINOP_ADD: strcpy(ptr,"+"); break;
254 case BINOP_SUB: strcpy(ptr,"-"); break;
255 case BINOP_MUL: strcpy(ptr,"*"); break;
256 case BINOP_DIV: strcpy(ptr,"/"); break;
257 case BINOP_REM: strcpy(ptr,"%"); break;
258 case BINOP_LSH: strcpy(ptr,"<<"); break;
259 case BINOP_RSH: strcpy(ptr,">>"); break;
260 case BINOP_BITWISE_AND: strcpy(ptr,"&"); break;
261 case BINOP_BITWISE_IOR: strcpy(ptr,"|"); break;
262 case BINOP_BITWISE_XOR: strcpy(ptr,"^"); break;
263 case BINOP_LOGICAL_AND: strcpy(ptr,"&&"); break;
264 case BINOP_LOGICAL_OR: strcpy(ptr,"||"); break;
265 case BINOP_MIN: strcpy(ptr,"<?"); break;
266 case BINOP_MAX: strcpy(ptr,">?"); break;
267 case BINOP_ASSIGN: strcpy(ptr,"="); break;
268 case BINOP_ASSIGN_MODIFY:
271 case BINOP_ADD: strcpy(ptr,"+="); break;
272 case BINOP_SUB: strcpy(ptr,"-="); break;
273 case BINOP_MUL: strcpy(ptr,"*="); break;
274 case BINOP_DIV: strcpy(ptr,"/="); break;
275 case BINOP_REM: strcpy(ptr,"%="); break;
276 case BINOP_BITWISE_AND: strcpy(ptr,"&="); break;
277 case BINOP_BITWISE_IOR: strcpy(ptr,"|="); break;
278 case BINOP_BITWISE_XOR: strcpy(ptr,"^="); break;
279 case BINOP_MOD: /* invalid */
281 error ("Invalid binary operation specified.");
284 case BINOP_SUBSCRIPT: strcpy(ptr,"[]"); break;
285 case BINOP_EQUAL: strcpy(ptr,"=="); break;
286 case BINOP_NOTEQUAL: strcpy(ptr,"!="); break;
287 case BINOP_LESS: strcpy(ptr,"<"); break;
288 case BINOP_GTR: strcpy(ptr,">"); break;
289 case BINOP_GEQ: strcpy(ptr,">="); break;
290 case BINOP_LEQ: strcpy(ptr,"<="); break;
291 case BINOP_MOD: /* invalid */
293 error ("Invalid binary operation specified.");
295 argvec[0] = value_struct_elt (&arg1, argvec+1, tstr, &static_memfuncp, "structure");
300 argvec[1] = argvec[0];
303 return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
305 error ("member function %s not found", tstr);
307 return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
311 /* We know that arg1 is a structure, so try to find a unary user
312 defined operator that matches the operator in question.
313 Create an argument vector that calls arg1.operator @ (arg1)
314 and return that value (where '@' is (almost) any unary operator which
315 is legal for GNU C++). */
318 value_x_unop (arg1, op)
329 /* now we know that what we have to do is construct our
330 arg vector and find the right function to call it with. */
332 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT)
333 error ("Can't do that unary op on that type"); /* FIXME be explicit */
335 argvec = (value *) alloca (sizeof (value) * 3);
336 argvec[1] = value_addr (arg1);
339 /* make the right function name up */
340 strcpy(tstr,"operator__");
344 case UNOP_PREINCREMENT: strcpy(ptr,"++"); break;
345 case UNOP_PREDECREMENT: strcpy(ptr,"++"); break;
346 case UNOP_POSTINCREMENT: strcpy(ptr,"++"); break;
347 case UNOP_POSTDECREMENT: strcpy(ptr,"++"); break;
348 case UNOP_LOGICAL_NOT: strcpy(ptr,"!"); break;
349 case UNOP_COMPLEMENT: strcpy(ptr,"~"); break;
350 case UNOP_NEG: strcpy(ptr,"-"); break;
352 error ("Invalid binary operation specified.");
354 argvec[0] = value_struct_elt (&arg1, argvec+1, tstr, &static_memfuncp, "structure");
359 argvec[1] = argvec[0];
362 return call_function_by_hand (argvec[0], 1 - static_memfuncp, argvec + 1);
364 error ("member function %s not found", tstr);
365 return 0; /* For lint -- never reached */
369 /* Concatenate two values with the following conditions:
371 (1) Both values must be either bitstring values or character string
372 values and the resulting value consists of the concatenation of
373 ARG1 followed by ARG2.
377 One value must be an integer value and the other value must be
378 either a bitstring value or character string value, which is
379 to be repeated by the number of times specified by the integer
383 (2) Boolean values are also allowed and are treated as bit string
386 (3) Character values are also allowed and are treated as character
387 string values of length 1.
391 value_concat (arg1, arg2)
394 register value inval1, inval2, outval;
395 int inval1len, inval2len;
400 /* First figure out if we are dealing with two values to be concatenated
401 or a repeat count and a value to be repeated. INVAL1 is set to the
402 first of two concatenated values, or the repeat count. INVAL2 is set
403 to the second of the two concatenated values or the value to be
406 if (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT)
417 /* Now process the input values. */
419 if (TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_INT)
421 /* We have a repeat count. Validate the second value and then
422 construct a value repeated that many times. */
423 if (TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_STRING
424 || TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_CHAR)
426 count = longest_to_int (value_as_long (inval1));
427 inval2len = TYPE_LENGTH (VALUE_TYPE (inval2));
428 ptr = (char *) alloca (count * inval2len);
429 if (TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_CHAR)
431 inchar = (char) unpack_long (VALUE_TYPE (inval2),
432 VALUE_CONTENTS (inval2));
433 for (idx = 0; idx < count; idx++)
435 *(ptr + idx) = inchar;
440 for (idx = 0; idx < count; idx++)
442 memcpy (ptr + (idx * inval2len), VALUE_CONTENTS (inval2),
446 outval = value_string (ptr, count * inval2len);
448 else if (TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_BITSTRING
449 || TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_BOOL)
451 error ("unimplemented support for bitstring/boolean repeats");
455 error ("can't repeat values of that type");
458 else if (TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_STRING
459 || TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_CHAR)
461 /* We have two character strings to concatenate. */
462 if (TYPE_CODE (VALUE_TYPE (inval2)) != TYPE_CODE_STRING
463 && TYPE_CODE (VALUE_TYPE (inval2)) != TYPE_CODE_CHAR)
465 error ("Strings can only be concatenated with other strings.");
467 inval1len = TYPE_LENGTH (VALUE_TYPE (inval1));
468 inval2len = TYPE_LENGTH (VALUE_TYPE (inval2));
469 ptr = (char *) alloca (inval1len + inval2len);
470 if (TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_CHAR)
472 *ptr = (char) unpack_long (VALUE_TYPE (inval1), VALUE_CONTENTS (inval1));
476 memcpy (ptr, VALUE_CONTENTS (inval1), inval1len);
478 if (TYPE_CODE (VALUE_TYPE (inval2)) == TYPE_CODE_CHAR)
481 (char) unpack_long (VALUE_TYPE (inval2), VALUE_CONTENTS (inval2));
485 memcpy (ptr + inval1len, VALUE_CONTENTS (inval2), inval2len);
487 outval = value_string (ptr, inval1len + inval2len);
489 else if (TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_BITSTRING
490 || TYPE_CODE (VALUE_TYPE (inval1)) == TYPE_CODE_BOOL)
492 /* We have two bitstrings to concatenate. */
493 if (TYPE_CODE (VALUE_TYPE (inval2)) != TYPE_CODE_BITSTRING
494 && TYPE_CODE (VALUE_TYPE (inval2)) != TYPE_CODE_BOOL)
496 error ("Bitstrings or booleans can only be concatenated with other bitstrings or booleans.");
498 error ("unimplemented support for bitstring/boolean concatenation.");
502 /* We don't know how to concatenate these operands. */
503 error ("illegal operands for concatenation.");
509 /* Perform a binary operation on two operands which have reasonable
510 representations as integers or floats. This includes booleans,
511 characters, integers, or floats.
512 Does not support addition and subtraction on pointers;
513 use value_add or value_sub if you want to handle those possibilities. */
516 value_binop (arg1, arg2, op)
525 if ((TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT
527 TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_CHAR
529 TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT
531 TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_BOOL)
533 (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_FLT
535 TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_CHAR
537 TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT
539 TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_BOOL))
540 error ("Argument to arithmetic operation not a number or boolean.");
542 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT
544 TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_FLT)
547 v1 = value_as_double (arg1);
548 v2 = value_as_double (arg2);
568 error ("Integer-only operation on floating point number.");
571 val = allocate_value (builtin_type_double);
572 SWAP_TARGET_AND_HOST (&v, sizeof (v));
573 *(double *) VALUE_CONTENTS_RAW (val) = v;
575 else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_BOOL
577 TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_BOOL)
580 v1 = value_as_long (arg1);
581 v2 = value_as_long (arg2);
585 case BINOP_BITWISE_AND:
589 case BINOP_BITWISE_IOR:
593 case BINOP_BITWISE_XOR:
598 error ("Invalid operation on booleans.");
601 /* start-sanitize-chill (FIXME!) */
602 val = allocate_value (builtin_type_chill_bool);
603 /* end-sanitize-chill */
604 SWAP_TARGET_AND_HOST (&v, sizeof (v));
605 *(LONGEST *) VALUE_CONTENTS_RAW (val) = v;
608 /* Integral operations here. */
609 /* FIXME: Also mixed integral/booleans, with result an integer. */
611 /* Should we promote to unsigned longest? */
612 if ((TYPE_UNSIGNED (VALUE_TYPE (arg1))
613 || TYPE_UNSIGNED (VALUE_TYPE (arg2)))
614 && (TYPE_LENGTH (VALUE_TYPE (arg1)) >= sizeof (unsigned LONGEST)
615 || TYPE_LENGTH (VALUE_TYPE (arg1)) >= sizeof (unsigned LONGEST)))
617 unsigned LONGEST v1, v2, v;
618 v1 = (unsigned LONGEST) value_as_long (arg1);
619 v2 = (unsigned LONGEST) value_as_long (arg2);
644 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
645 v1 mod 0 has a defined value, v1. */
646 /* start-sanitize-chill */
647 /* Chill specifies that v2 must be > 0, so check for that. */
648 if (current_language -> la_language == language_chill
649 && value_as_long (arg2) <= 0)
651 error ("Second operand of MOD must be greater than zero.");
653 /* end-sanitize-chill */
661 /* Note floor(v1/v2) == v1/v2 for unsigned. */
674 case BINOP_BITWISE_AND:
678 case BINOP_BITWISE_IOR:
682 case BINOP_BITWISE_XOR:
686 case BINOP_LOGICAL_AND:
690 case BINOP_LOGICAL_OR:
695 v = v1 < v2 ? v1 : v2;
699 v = v1 > v2 ? v1 : v2;
703 error ("Invalid binary operation on numbers.");
706 val = allocate_value (BUILTIN_TYPE_UNSIGNED_LONGEST);
707 SWAP_TARGET_AND_HOST (&v, sizeof (v));
708 *(unsigned LONGEST *) VALUE_CONTENTS_RAW (val) = v;
713 v1 = value_as_long (arg1);
714 v2 = value_as_long (arg2);
739 /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
740 X mod 0 has a defined value, X. */
741 /* start-sanitize-chill */
742 /* Chill specifies that v2 must be > 0, so check for that. */
743 if (current_language -> la_language == language_chill
746 error ("Second operand of MOD must be greater than zero.");
748 /* end-sanitize-chill */
757 if (TRUNCATION_TOWARDS_ZERO && (v < 0) && ((v1 % v2) != 0))
773 case BINOP_BITWISE_AND:
777 case BINOP_BITWISE_IOR:
781 case BINOP_BITWISE_XOR:
785 case BINOP_LOGICAL_AND:
789 case BINOP_LOGICAL_OR:
794 v = v1 < v2 ? v1 : v2;
798 v = v1 > v2 ? v1 : v2;
802 error ("Invalid binary operation on numbers.");
805 val = allocate_value (BUILTIN_TYPE_LONGEST);
806 SWAP_TARGET_AND_HOST (&v, sizeof (v));
807 *(LONGEST *) VALUE_CONTENTS_RAW (val) = v;
814 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
817 value_logical_not (arg1)
825 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT)
826 return 0 == value_as_double (arg1);
828 len = TYPE_LENGTH (VALUE_TYPE (arg1));
829 p = VALUE_CONTENTS (arg1);
840 /* Simulate the C operator == by returning a 1
841 iff ARG1 and ARG2 have equal contents. */
844 value_equal (arg1, arg2)
845 register value arg1, arg2;
849 register char *p1, *p2;
850 enum type_code code1;
851 enum type_code code2;
856 code1 = TYPE_CODE (VALUE_TYPE (arg1));
857 code2 = TYPE_CODE (VALUE_TYPE (arg2));
859 if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT)
860 return value_as_long (arg1) == value_as_long (arg2);
861 else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT)
862 && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT))
863 return value_as_double (arg1) == value_as_double (arg2);
865 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
867 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_INT)
868 return value_as_pointer (arg1) == (CORE_ADDR) value_as_long (arg2);
869 else if (code2 == TYPE_CODE_PTR && code1 == TYPE_CODE_INT)
870 return (CORE_ADDR) value_as_long (arg1) == value_as_pointer (arg2);
872 else if (code1 == code2
873 && ((len = TYPE_LENGTH (VALUE_TYPE (arg1)))
874 == TYPE_LENGTH (VALUE_TYPE (arg2))))
876 p1 = VALUE_CONTENTS (arg1);
877 p2 = VALUE_CONTENTS (arg2);
887 error ("Invalid type combination in equality test.");
888 return 0; /* For lint -- never reached */
892 /* Simulate the C operator < by returning 1
893 iff ARG1's contents are less than ARG2's. */
896 value_less (arg1, arg2)
897 register value arg1, arg2;
899 register enum type_code code1;
900 register enum type_code code2;
905 code1 = TYPE_CODE (VALUE_TYPE (arg1));
906 code2 = TYPE_CODE (VALUE_TYPE (arg2));
908 if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT)
910 if (TYPE_UNSIGNED (VALUE_TYPE (arg1))
911 || TYPE_UNSIGNED (VALUE_TYPE (arg2)))
912 return ((unsigned LONGEST) value_as_long (arg1)
913 < (unsigned LONGEST) value_as_long (arg2));
915 return value_as_long (arg1) < value_as_long (arg2);
917 else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT)
918 && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT))
919 return value_as_double (arg1) < value_as_double (arg2);
920 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
921 return value_as_pointer (arg1) < value_as_pointer (arg2);
923 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
925 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_INT)
926 return value_as_pointer (arg1) < (CORE_ADDR) value_as_long (arg2);
927 else if (code2 == TYPE_CODE_PTR && code1 == TYPE_CODE_INT)
928 return (CORE_ADDR) value_as_long (arg1) < value_as_pointer (arg2);
932 error ("Invalid type combination in ordering comparison.");
937 /* The unary operators - and ~. Both free the argument ARG1. */
943 register struct type *type;
947 type = VALUE_TYPE (arg1);
949 if (TYPE_CODE (type) == TYPE_CODE_FLT)
950 return value_from_double (type, - value_as_double (arg1));
951 else if (TYPE_CODE (type) == TYPE_CODE_INT)
952 return value_from_longest (type, - value_as_long (arg1));
954 error ("Argument to negate operation not a number.");
955 return 0; /* For lint -- never reached */
960 value_complement (arg1)
965 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT)
966 error ("Argument to complement operation not an integer.");
968 return value_from_longest (VALUE_TYPE (arg1), ~ value_as_long (arg1));