Update cygnus copies of currently undistributed i860 files maintained by
[deliverable/binutils-gdb.git] / gdb / valarith.c
CommitLineData
bd5635a1 1/* Perform arithmetic and other operations on values, for GDB.
e17960fb 2 Copyright 1986, 1989, 1991, 1992 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
088c3a0b 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
088c3a0b
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
088c3a0b 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
088c3a0b
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
bd5635a1 20#include "defs.h"
bd5635a1 21#include "value.h"
088c3a0b 22#include "symtab.h"
51b57ded 23#include "gdbtypes.h"
bd5635a1
RP
24#include "expression.h"
25#include "target.h"
26#include <string.h>
27
088c3a0b
JG
28static value
29value_subscripted_rvalue PARAMS ((value, value));
bd5635a1 30
088c3a0b 31\f
bd5635a1
RP
32value
33value_add (arg1, arg2)
34 value arg1, arg2;
35{
088c3a0b 36 register value valint, valptr;
bd5635a1
RP
37 register int len;
38
39 COERCE_ARRAY (arg1);
40 COERCE_ARRAY (arg2);
41
42 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR
43 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR)
44 &&
45 (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT
46 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT))
47 /* Exactly one argument is a pointer, and one is an integer. */
48 {
49 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
50 {
51 valptr = arg1;
52 valint = arg2;
53 }
54 else
55 {
56 valptr = arg2;
57 valint = arg1;
58 }
59 len = TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (valptr)));
60 if (len == 0) len = 1; /* For (void *) */
088c3a0b
JG
61 return value_from_longest (VALUE_TYPE (valptr),
62 value_as_long (valptr)
63 + (len * value_as_long (valint)));
bd5635a1
RP
64 }
65
66 return value_binop (arg1, arg2, BINOP_ADD);
67}
68
69value
70value_sub (arg1, arg2)
71 value arg1, arg2;
72{
bd5635a1
RP
73
74 COERCE_ARRAY (arg1);
75 COERCE_ARRAY (arg2);
76
77 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
78 {
79 if (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT)
80 {
81 /* pointer - integer. */
088c3a0b
JG
82 return value_from_longest
83 (VALUE_TYPE (arg1),
bd5635a1
RP
84 value_as_long (arg1)
85 - (TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)))
86 * value_as_long (arg2)));
bd5635a1
RP
87 }
88 else if (VALUE_TYPE (arg1) == VALUE_TYPE (arg2))
89 {
90 /* pointer to <type x> - pointer to <type x>. */
088c3a0b
JG
91 return value_from_longest
92 (builtin_type_long, /* FIXME -- should be ptrdiff_t */
bd5635a1
RP
93 (value_as_long (arg1) - value_as_long (arg2))
94 / TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))));
bd5635a1
RP
95 }
96 else
97 {
98 error ("\
99First argument of `-' is a pointer and second argument is neither\n\
100an integer nor a pointer of the same type.");
101 }
102 }
103
104 return value_binop (arg1, arg2, BINOP_SUB);
105}
106
107/* Return the value of ARRAY[IDX]. */
108
109value
110value_subscript (array, idx)
111 value array, idx;
112{
113 if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY
114 && VALUE_LVAL (array) != lval_memory)
115 return value_subscripted_rvalue (array, idx);
116 else
117 return value_ind (value_add (array, idx));
118}
119
120/* Return the value of EXPR[IDX], expr an aggregate rvalue
121 (eg, a vector register). This routine used to promote floats
122 to doubles, but no longer does. */
123
088c3a0b 124static value
bd5635a1
RP
125value_subscripted_rvalue (array, idx)
126 value array, idx;
127{
128 struct type *elt_type = TYPE_TARGET_TYPE (VALUE_TYPE (array));
129 int elt_size = TYPE_LENGTH (elt_type);
088c3a0b 130 int elt_offs = elt_size * longest_to_int (value_as_long (idx));
bd5635a1
RP
131 value v;
132
133 if (elt_offs >= TYPE_LENGTH (VALUE_TYPE (array)))
134 error ("no such vector element");
135
136 v = allocate_value (elt_type);
51b57ded
FF
137 (void) memcpy (VALUE_CONTENTS (v), VALUE_CONTENTS (array) + elt_offs,
138 elt_size);
bd5635a1
RP
139
140 if (VALUE_LVAL (array) == lval_internalvar)
141 VALUE_LVAL (v) = lval_internalvar_component;
142 else
143 VALUE_LVAL (v) = not_lval;
144 VALUE_ADDRESS (v) = VALUE_ADDRESS (array);
145 VALUE_OFFSET (v) = VALUE_OFFSET (array) + elt_offs;
146 VALUE_BITSIZE (v) = elt_size * 8;
147 return v;
148}
149\f
150/* Check to see if either argument is a structure. This is called so
151 we know whether to go ahead with the normal binop or look for a
152 user defined function instead.
153
154 For now, we do not overload the `=' operator. */
155
156int
157binop_user_defined_p (op, arg1, arg2)
158 enum exp_opcode op;
159 value arg1, arg2;
160{
161 if (op == BINOP_ASSIGN)
162 return 0;
163 return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT
164 || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_STRUCT
165 || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
166 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT)
167 || (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_REF
168 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_STRUCT));
169}
170
171/* Check to see if argument is a structure. This is called so
172 we know whether to go ahead with the normal unop or look for a
173 user defined function instead.
174
175 For now, we do not overload the `&' operator. */
176
177int unop_user_defined_p (op, arg1)
178 enum exp_opcode op;
179 value arg1;
180{
181 if (op == UNOP_ADDR)
182 return 0;
183 return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT
184 || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
185 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT));
186}
187
188/* We know either arg1 or arg2 is a structure, so try to find the right
189 user defined function. Create an argument vector that calls
190 arg1.operator @ (arg1,arg2) and return that value (where '@' is any
088c3a0b
JG
191 binary operator which is legal for GNU C++).
192
193 OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
194 is the opcode saying how to modify it. Otherwise, OTHEROP is
195 unused. */
bd5635a1
RP
196
197value
198value_x_binop (arg1, arg2, op, otherop)
199 value arg1, arg2;
200 enum exp_opcode op, otherop;
201{
202 value * argvec;
203 char *ptr;
204 char tstr[13];
205 int static_memfuncp;
206
088c3a0b
JG
207 COERCE_REF (arg1);
208 COERCE_REF (arg2);
bd5635a1
RP
209 COERCE_ENUM (arg1);
210 COERCE_ENUM (arg2);
211
212 /* now we know that what we have to do is construct our
213 arg vector and find the right function to call it with. */
214
215 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT)
216 error ("Can't do that binary op on that type"); /* FIXME be explicit */
217
218 argvec = (value *) alloca (sizeof (value) * 4);
219 argvec[1] = value_addr (arg1);
220 argvec[2] = arg2;
221 argvec[3] = 0;
222
223 /* make the right function name up */
224 strcpy(tstr, "operator__");
225 ptr = tstr+8;
226 switch (op)
227 {
228 case BINOP_ADD: strcpy(ptr,"+"); break;
229 case BINOP_SUB: strcpy(ptr,"-"); break;
230 case BINOP_MUL: strcpy(ptr,"*"); break;
231 case BINOP_DIV: strcpy(ptr,"/"); break;
232 case BINOP_REM: strcpy(ptr,"%"); break;
233 case BINOP_LSH: strcpy(ptr,"<<"); break;
234 case BINOP_RSH: strcpy(ptr,">>"); break;
235 case BINOP_LOGAND: strcpy(ptr,"&"); break;
236 case BINOP_LOGIOR: strcpy(ptr,"|"); break;
237 case BINOP_LOGXOR: strcpy(ptr,"^"); break;
238 case BINOP_AND: strcpy(ptr,"&&"); break;
239 case BINOP_OR: strcpy(ptr,"||"); break;
240 case BINOP_MIN: strcpy(ptr,"<?"); break;
241 case BINOP_MAX: strcpy(ptr,">?"); break;
242 case BINOP_ASSIGN: strcpy(ptr,"="); break;
243 case BINOP_ASSIGN_MODIFY:
244 switch (otherop)
245 {
246 case BINOP_ADD: strcpy(ptr,"+="); break;
247 case BINOP_SUB: strcpy(ptr,"-="); break;
248 case BINOP_MUL: strcpy(ptr,"*="); break;
249 case BINOP_DIV: strcpy(ptr,"/="); break;
250 case BINOP_REM: strcpy(ptr,"%="); break;
251 case BINOP_LOGAND: strcpy(ptr,"&="); break;
252 case BINOP_LOGIOR: strcpy(ptr,"|="); break;
253 case BINOP_LOGXOR: strcpy(ptr,"^="); break;
254 default:
255 error ("Invalid binary operation specified.");
256 }
257 break;
258 case BINOP_SUBSCRIPT: strcpy(ptr,"[]"); break;
259 case BINOP_EQUAL: strcpy(ptr,"=="); break;
260 case BINOP_NOTEQUAL: strcpy(ptr,"!="); break;
261 case BINOP_LESS: strcpy(ptr,"<"); break;
262 case BINOP_GTR: strcpy(ptr,">"); break;
263 case BINOP_GEQ: strcpy(ptr,">="); break;
264 case BINOP_LEQ: strcpy(ptr,"<="); break;
265 default:
266 error ("Invalid binary operation specified.");
267 }
268 argvec[0] = value_struct_elt (&arg1, argvec+1, tstr, &static_memfuncp, "structure");
269 if (argvec[0])
270 {
271 if (static_memfuncp)
272 {
273 argvec[1] = argvec[0];
274 argvec++;
275 }
e17960fb 276 return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
bd5635a1
RP
277 }
278 error ("member function %s not found", tstr);
279#ifdef lint
e17960fb 280 return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
bd5635a1
RP
281#endif
282}
283
284/* We know that arg1 is a structure, so try to find a unary user
285 defined operator that matches the operator in question.
286 Create an argument vector that calls arg1.operator @ (arg1)
287 and return that value (where '@' is (almost) any unary operator which
288 is legal for GNU C++). */
289
290value
291value_x_unop (arg1, op)
292 value arg1;
293 enum exp_opcode op;
294{
295 value * argvec;
296 char *ptr;
297 char tstr[13];
298 int static_memfuncp;
299
300 COERCE_ENUM (arg1);
301
302 /* now we know that what we have to do is construct our
303 arg vector and find the right function to call it with. */
304
305 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT)
306 error ("Can't do that unary op on that type"); /* FIXME be explicit */
307
308 argvec = (value *) alloca (sizeof (value) * 3);
309 argvec[1] = value_addr (arg1);
310 argvec[2] = 0;
311
312 /* make the right function name up */
313 strcpy(tstr,"operator__");
314 ptr = tstr+8;
315 switch (op)
316 {
317 case UNOP_PREINCREMENT: strcpy(ptr,"++"); break;
318 case UNOP_PREDECREMENT: strcpy(ptr,"++"); break;
319 case UNOP_POSTINCREMENT: strcpy(ptr,"++"); break;
320 case UNOP_POSTDECREMENT: strcpy(ptr,"++"); break;
321 case UNOP_ZEROP: strcpy(ptr,"!"); break;
322 case UNOP_LOGNOT: strcpy(ptr,"~"); break;
323 case UNOP_NEG: strcpy(ptr,"-"); break;
324 default:
325 error ("Invalid binary operation specified.");
326 }
327 argvec[0] = value_struct_elt (&arg1, argvec+1, tstr, &static_memfuncp, "structure");
328 if (argvec[0])
329 {
330 if (static_memfuncp)
331 {
332 argvec[1] = argvec[0];
333 argvec++;
334 }
e17960fb 335 return call_function_by_hand (argvec[0], 1 - static_memfuncp, argvec + 1);
bd5635a1
RP
336 }
337 error ("member function %s not found", tstr);
338 return 0; /* For lint -- never reached */
339}
340\f
341/* Perform a binary operation on two integers or two floats.
342 Does not support addition and subtraction on pointers;
343 use value_add or value_sub if you want to handle those possibilities. */
344
345value
346value_binop (arg1, arg2, op)
347 value arg1, arg2;
088c3a0b 348 enum exp_opcode op;
bd5635a1
RP
349{
350 register value val;
351
352 COERCE_ENUM (arg1);
353 COERCE_ENUM (arg2);
354
355 if ((TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT
356 &&
357 TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT)
358 ||
359 (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_FLT
360 &&
361 TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT))
362 error ("Argument to arithmetic operation not a number.");
363
364 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT
365 ||
366 TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_FLT)
367 {
368 double v1, v2, v;
369 v1 = value_as_double (arg1);
370 v2 = value_as_double (arg2);
371 switch (op)
372 {
373 case BINOP_ADD:
374 v = v1 + v2;
375 break;
376
377 case BINOP_SUB:
378 v = v1 - v2;
379 break;
380
381 case BINOP_MUL:
382 v = v1 * v2;
383 break;
384
385 case BINOP_DIV:
386 v = v1 / v2;
387 break;
388
389 default:
390 error ("Integer-only operation on floating point number.");
391 }
392
393 val = allocate_value (builtin_type_double);
394 SWAP_TARGET_AND_HOST (&v, sizeof (v));
395 *(double *) VALUE_CONTENTS_RAW (val) = v;
396 }
397 else
398 /* Integral operations here. */
399 {
400 /* Should we promote to unsigned longest? */
401 if ((TYPE_UNSIGNED (VALUE_TYPE (arg1))
402 || TYPE_UNSIGNED (VALUE_TYPE (arg2)))
403 && (TYPE_LENGTH (VALUE_TYPE (arg1)) >= sizeof (unsigned LONGEST)
404 || TYPE_LENGTH (VALUE_TYPE (arg1)) >= sizeof (unsigned LONGEST)))
405 {
406 unsigned LONGEST v1, v2, v;
407 v1 = (unsigned LONGEST) value_as_long (arg1);
408 v2 = (unsigned LONGEST) value_as_long (arg2);
409
410 switch (op)
411 {
412 case BINOP_ADD:
413 v = v1 + v2;
414 break;
415
416 case BINOP_SUB:
417 v = v1 - v2;
418 break;
419
420 case BINOP_MUL:
421 v = v1 * v2;
422 break;
423
424 case BINOP_DIV:
425 v = v1 / v2;
426 break;
427
428 case BINOP_REM:
429 v = v1 % v2;
430 break;
431
432 case BINOP_LSH:
433 v = v1 << v2;
434 break;
435
436 case BINOP_RSH:
437 v = v1 >> v2;
438 break;
439
440 case BINOP_LOGAND:
441 v = v1 & v2;
442 break;
443
444 case BINOP_LOGIOR:
445 v = v1 | v2;
446 break;
447
448 case BINOP_LOGXOR:
449 v = v1 ^ v2;
450 break;
451
452 case BINOP_AND:
453 v = v1 && v2;
454 break;
455
456 case BINOP_OR:
457 v = v1 || v2;
458 break;
459
460 case BINOP_MIN:
461 v = v1 < v2 ? v1 : v2;
462 break;
463
464 case BINOP_MAX:
465 v = v1 > v2 ? v1 : v2;
466 break;
467
468 default:
469 error ("Invalid binary operation on numbers.");
470 }
471
472 val = allocate_value (BUILTIN_TYPE_UNSIGNED_LONGEST);
473 SWAP_TARGET_AND_HOST (&v, sizeof (v));
474 *(unsigned LONGEST *) VALUE_CONTENTS_RAW (val) = v;
475 }
476 else
477 {
478 LONGEST v1, v2, v;
479 v1 = value_as_long (arg1);
480 v2 = value_as_long (arg2);
481
482 switch (op)
483 {
484 case BINOP_ADD:
485 v = v1 + v2;
486 break;
487
488 case BINOP_SUB:
489 v = v1 - v2;
490 break;
491
492 case BINOP_MUL:
493 v = v1 * v2;
494 break;
495
496 case BINOP_DIV:
497 v = v1 / v2;
498 break;
499
500 case BINOP_REM:
501 v = v1 % v2;
502 break;
503
504 case BINOP_LSH:
505 v = v1 << v2;
506 break;
507
508 case BINOP_RSH:
509 v = v1 >> v2;
510 break;
511
512 case BINOP_LOGAND:
513 v = v1 & v2;
514 break;
515
516 case BINOP_LOGIOR:
517 v = v1 | v2;
518 break;
519
520 case BINOP_LOGXOR:
521 v = v1 ^ v2;
522 break;
523
524 case BINOP_AND:
525 v = v1 && v2;
526 break;
527
528 case BINOP_OR:
529 v = v1 || v2;
530 break;
531
532 case BINOP_MIN:
533 v = v1 < v2 ? v1 : v2;
534 break;
535
536 case BINOP_MAX:
537 v = v1 > v2 ? v1 : v2;
538 break;
539
540 default:
541 error ("Invalid binary operation on numbers.");
542 }
543
544 val = allocate_value (BUILTIN_TYPE_LONGEST);
545 SWAP_TARGET_AND_HOST (&v, sizeof (v));
546 *(LONGEST *) VALUE_CONTENTS_RAW (val) = v;
547 }
548 }
549
550 return val;
551}
552\f
51b57ded 553/* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
bd5635a1
RP
554
555int
556value_zerop (arg1)
557 value arg1;
558{
559 register int len;
560 register char *p;
561
562 COERCE_ARRAY (arg1);
563
51b57ded
FF
564 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT)
565 return 0 == value_as_double (arg1);
566
bd5635a1
RP
567 len = TYPE_LENGTH (VALUE_TYPE (arg1));
568 p = VALUE_CONTENTS (arg1);
569
570 while (--len >= 0)
571 {
572 if (*p++)
573 break;
574 }
575
576 return len < 0;
577}
578
579/* Simulate the C operator == by returning a 1
580 iff ARG1 and ARG2 have equal contents. */
581
582int
583value_equal (arg1, arg2)
584 register value arg1, arg2;
585
586{
587 register int len;
588 register char *p1, *p2;
589 enum type_code code1;
590 enum type_code code2;
591
592 COERCE_ARRAY (arg1);
593 COERCE_ARRAY (arg2);
594
595 code1 = TYPE_CODE (VALUE_TYPE (arg1));
596 code2 = TYPE_CODE (VALUE_TYPE (arg2));
597
598 if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT)
599 return value_as_long (arg1) == value_as_long (arg2);
600 else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT)
601 && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT))
602 return value_as_double (arg1) == value_as_double (arg2);
088c3a0b
JG
603
604 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
605 is bigger. */
606 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_INT)
607 return value_as_pointer (arg1) == (CORE_ADDR) value_as_long (arg2);
608 else if (code2 == TYPE_CODE_PTR && code1 == TYPE_CODE_INT)
609 return (CORE_ADDR) value_as_long (arg1) == value_as_pointer (arg2);
610
bd5635a1
RP
611 else if (code1 == code2
612 && ((len = TYPE_LENGTH (VALUE_TYPE (arg1)))
613 == TYPE_LENGTH (VALUE_TYPE (arg2))))
614 {
615 p1 = VALUE_CONTENTS (arg1);
616 p2 = VALUE_CONTENTS (arg2);
617 while (--len >= 0)
618 {
619 if (*p1++ != *p2++)
620 break;
621 }
622 return len < 0;
623 }
624 else
625 {
626 error ("Invalid type combination in equality test.");
627 return 0; /* For lint -- never reached */
628 }
629}
630
631/* Simulate the C operator < by returning 1
632 iff ARG1's contents are less than ARG2's. */
633
634int
635value_less (arg1, arg2)
636 register value arg1, arg2;
637{
638 register enum type_code code1;
639 register enum type_code code2;
640
641 COERCE_ARRAY (arg1);
642 COERCE_ARRAY (arg2);
643
644 code1 = TYPE_CODE (VALUE_TYPE (arg1));
645 code2 = TYPE_CODE (VALUE_TYPE (arg2));
646
647 if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT)
648 {
649 if (TYPE_UNSIGNED (VALUE_TYPE (arg1))
650 || TYPE_UNSIGNED (VALUE_TYPE (arg2)))
088c3a0b
JG
651 return ((unsigned LONGEST) value_as_long (arg1)
652 < (unsigned LONGEST) value_as_long (arg2));
bd5635a1
RP
653 else
654 return value_as_long (arg1) < value_as_long (arg2);
655 }
656 else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT)
657 && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT))
658 return value_as_double (arg1) < value_as_double (arg2);
088c3a0b
JG
659 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
660 return value_as_pointer (arg1) < value_as_pointer (arg2);
661
662 /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
663 is bigger. */
664 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_INT)
665 return value_as_pointer (arg1) < (CORE_ADDR) value_as_long (arg2);
666 else if (code2 == TYPE_CODE_PTR && code1 == TYPE_CODE_INT)
667 return (CORE_ADDR) value_as_long (arg1) < value_as_pointer (arg2);
668
bd5635a1
RP
669 else
670 {
671 error ("Invalid type combination in ordering comparison.");
672 return 0;
673 }
674}
675\f
676/* The unary operators - and ~. Both free the argument ARG1. */
677
678value
679value_neg (arg1)
680 register value arg1;
681{
682 register struct type *type;
683
684 COERCE_ENUM (arg1);
685
686 type = VALUE_TYPE (arg1);
687
688 if (TYPE_CODE (type) == TYPE_CODE_FLT)
689 return value_from_double (type, - value_as_double (arg1));
690 else if (TYPE_CODE (type) == TYPE_CODE_INT)
088c3a0b 691 return value_from_longest (type, - value_as_long (arg1));
bd5635a1
RP
692 else {
693 error ("Argument to negate operation not a number.");
694 return 0; /* For lint -- never reached */
695 }
696}
697
698value
699value_lognot (arg1)
700 register value arg1;
701{
702 COERCE_ENUM (arg1);
703
704 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT)
705 error ("Argument to complement operation not an integer.");
706
088c3a0b 707 return value_from_longest (VALUE_TYPE (arg1), ~ value_as_long (arg1));
bd5635a1
RP
708}
709\f
This page took 0.096595 seconds and 4 git commands to generate.