This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
(patch) hpjyg16: valarith.c
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: (patch) hpjyg16: valarith.c
- From: Jimmy Guo <guo at cup dot hp dot com>
- Date: Tue, 9 Nov 1999 09:59:58 -0800 (PST)
This patch adds support for exponentiation, and (in)equality of boolean /
string.
ChangeLog:
1999-11-09 Jimmy Guo <guo@cup.hp.com>
* valarith.c (value_binop): Add support for exponentiation,
equal, not equal.
(my_strcmp): New function.
(value_equal,value_less): Add string equality comparison support.
Index: gdb/valarith.c
/opt/gnu/bin/diff -r -c -N /view/guo.wdb.c//CLO/Components/WDB/Src/gnu/gdb/valarith.c gdb/valarith.c
*** /view/guo.wdb.c//CLO/Components/WDB/Src/gnu/gdb/valarith.c Mon Nov 8 16:02:14 1999
--- gdb/valarith.c Mon Nov 8 16:07:05 1999
***************
*** 28,33 ****
--- 28,34 ----
#include "language.h"
#include "demangle.h"
#include "gdb_string.h"
+ #include <math.h>
/* Define whether or not the C operator '/' truncates towards zero for
differently signed operands (truncation direction is undefined in C). */
***************
*** 573,579 ****
value_concat (arg1, arg2)
value_ptr arg1, arg2;
{
! register value_ptr inval1, inval2, outval;
int inval1len, inval2len;
int count, idx;
char *ptr;
--- 574,580 ----
value_concat (arg1, arg2)
value_ptr arg1, arg2;
{
! register value_ptr inval1, inval2, outval = NULL;
int inval1len, inval2len;
int count, idx;
char *ptr;
***************
*** 738,744 ****
/* FIXME-if-picky-about-floating-accuracy: Should be doing this
in target format. real.c in GCC probably has the necessary
code. */
! DOUBLEST v1, v2, v;
v1 = value_as_double (arg1);
v2 = value_as_double (arg2);
switch (op)
--- 739,745 ----
/* FIXME-if-picky-about-floating-accuracy: Should be doing this
in target format. real.c in GCC probably has the necessary
code. */
! DOUBLEST v1, v2, v = 0;
v1 = value_as_double (arg1);
v2 = value_as_double (arg2);
switch (op)
***************
*** 759,764 ****
--- 760,771 ----
v = v1 / v2;
break;
+ case BINOP_EXP:
+ v = pow (v1, v2);
+ if (errno)
+ error ("Cannot perform exponentiation: %s", strerror (errno));
+ break;
+
default:
error ("Integer-only operation on floating point number.");
}
***************
*** 779,785 ****
&&
TYPE_CODE (type2) == TYPE_CODE_BOOL)
{
! LONGEST v1, v2, v;
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
--- 786,792 ----
&&
TYPE_CODE (type2) == TYPE_CODE_BOOL)
{
! LONGEST v1, v2, v = 0;
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
***************
*** 795,800 ****
--- 802,815 ----
case BINOP_BITWISE_XOR:
v = v1 ^ v2;
+ break;
+
+ case BINOP_EQUAL:
+ v = v1 == v2;
+ break;
+
+ case BINOP_NOTEQUAL:
+ v = v1 != v2;
break;
default:
***************
*** 855,861 ****
if (unsigned_operation)
{
! ULONGEST v1, v2, v;
v1 = (ULONGEST) value_as_long (arg1);
v2 = (ULONGEST) value_as_long (arg2);
--- 870,876 ----
if (unsigned_operation)
{
! ULONGEST v1, v2, v = 0;
v1 = (ULONGEST) value_as_long (arg1);
v2 = (ULONGEST) value_as_long (arg2);
***************
*** 884,889 ****
--- 899,910 ----
v = v1 / v2;
break;
+ case BINOP_EXP:
+ v = pow (v1, v2);
+ if (errno)
+ error ("Cannot perform exponentiation: %s", strerror (errno));
+ break;
+
case BINOP_REM:
v = v1 % v2;
break;
***************
*** 949,954 ****
--- 970,979 ----
v = v1 == v2;
break;
+ case BINOP_NOTEQUAL:
+ v = v1 != v2;
+ break;
+
case BINOP_LESS:
v = v1 < v2;
break;
***************
*** 976,982 ****
}
else
{
! LONGEST v1, v2, v;
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
--- 1001,1007 ----
}
else
{
! LONGEST v1, v2, v = 0;
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
***************
*** 996,1001 ****
--- 1021,1032 ----
case BINOP_DIV:
v = v1 / v2;
+ break;
+
+ case BINOP_EXP:
+ v = pow (v1, v2);
+ if (errno)
+ error ("Cannot perform exponentiation: %s", strerror (errno));
break;
case BINOP_REM:
***************
*** 1125,1130 ****
--- 1156,1192 ----
return len < 0;
}
+ /* Perform a comparison on two string values (whose content are not
+ necessarily null terminated) based on their length */
+
+ static int
+ my_strcmp (arg1, arg2)
+ register value_ptr arg1, arg2;
+ {
+ int len1 = TYPE_LENGTH (VALUE_TYPE (arg1));
+ int len2 = TYPE_LENGTH (VALUE_TYPE (arg2));
+ char *s1 = VALUE_CONTENTS (arg1);
+ char *s2 = VALUE_CONTENTS (arg2);
+ int i, len = len1 < len2 ? len1 : len2;
+
+ for (i = 0; i < len; i++)
+ {
+ if (s1[i] < s2[i])
+ return -1;
+ else if (s1[i] > s2[i])
+ return 1;
+ else
+ continue;
+ }
+
+ if (len1 < len2)
+ return -1;
+ else if (len1 > len2)
+ return 1;
+ else
+ return 0;
+ }
+
/* Simulate the C operator == by returning a 1
iff ARG1 and ARG2 have equal contents. */
***************
*** 1175,1180 ****
--- 1237,1246 ----
}
return len < 0;
}
+ else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
+ {
+ return my_strcmp (arg1, arg2) == 0;
+ }
else
{
error ("Invalid type combination in equality test.");
***************
*** 1217,1223 ****
return value_as_pointer (arg1) < (CORE_ADDR) value_as_long (arg2);
else if (code2 == TYPE_CODE_PTR && (code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL))
return (CORE_ADDR) value_as_long (arg1) < value_as_pointer (arg2);
!
else
{
error ("Invalid type combination in ordering comparison.");
--- 1283,1290 ----
return value_as_pointer (arg1) < (CORE_ADDR) value_as_long (arg2);
else if (code2 == TYPE_CODE_PTR && (code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL))
return (CORE_ADDR) value_as_long (arg1) < value_as_pointer (arg2);
! else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
! return my_strcmp (arg1, arg2) < 0;
else
{
error ("Invalid type combination in ordering comparison.");