aboutsummaryrefslogtreecommitdiff
path: root/gdb/valarith.c
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1992-11-15 17:28:02 +0000
committerFred Fish <fnf@specifix.com>1992-11-15 17:28:02 +0000
commite58de8a23021ce9bbdee715ac79745ebb93437a8 (patch)
tree008503bb278b756abfe43212bf412ab003eb6e7c /gdb/valarith.c
parentc1878f87886dd7ae9af9d2aafe8dcf075ecfaa9c (diff)
downloadgdb-e58de8a23021ce9bbdee715ac79745ebb93437a8.zip
gdb-e58de8a23021ce9bbdee715ac79745ebb93437a8.tar.gz
gdb-e58de8a23021ce9bbdee715ac79745ebb93437a8.tar.bz2
* Makefile.in (SFILES_MAINDIR): Add ch-exp.y.
* Makefile.in (YYFILES): Add ch-exp.tab.c. * Makefile.in (YYOBJ): Add ch-exp.tab.o. * Makefile.in (saber_gdb): Add unload of ch-exp.y and load of ch-exp.tab.c. * Makefile.in (distclean): Add target ch-exp.tab.c. * Makefile.in (realclean): Add rm of ch-exp.tab.c. * Makefile.in (c-exp.tab.c, m2-exp.tab.c): Add dependency on Makefile since it contains sed patterns used in generation. Add sed pattern to also delete #include of any malloc.h. * Makefile.in (ch-exp.tab.o, ch-exp.tab.c): New targets. * ch-exp.y: New expression parser, for GNU-Chill. * c-exp.y, expr.c, expression.h, language.c, m2-exp.y, parser-defs.h, valarith.c, valops.c, value.h: Remap macros and function names to conform to K&R terminology with respect to logical and bitwise operators: UNOP_ZEROP => UNOP_LOGICAL_NOT UNOP_LOGNOT => UNOP_COMPLEMENT BINOP_LOGAND => BINOP_BITWISE_AND BINOP_LOGXOR => BINOP_BITWISE_XOR BINOP_LOGIOR => BINOP_BITWISE_IOR BINOP_AND => BINOP_LOGICAL_AND BINOP_OR => BINOP_LOGICAL_OR PREC_OR => PREC_LOGICAL_OR PREC_AND => PREC_LOGICAL_AND PREC_LOGIOR => PREC_BITWISE_IOR PREC_LOGXOR => PREC_BITWISE_XOR PREC_LOGAND => PREC_BITWISE_AND value_zerop() => value_logical_not() value_lognot() => value_complement() * c-exp.y (c_op_print_tab): Add explicit empty terminator. * m2-exp.y (m2_op_print_tab): Add explicit empty terminator. * defs.h (enum language): Add language_chill. * dwarfread.c (set_cu_language): Add LANG_CHILL case and make LANG_MODULA2 a recognized language. * eval.c (evaluate_subexp): Add OP_BOOL case. * expprint.c (print_subexp): Add OP_BOOL case. * gdbtypes.h (enum_typecode): Note TYPE_CODE_BOOL used for Chill as well as Modula-2. * gdbtypes.y (builtin_type_chill_bool, builtin_type_chill_long, builtin_type_chill_ulong, builtin_type_chill_real): Add. * i387-tdep.c (sys/dir.h): Remove, appears to be unnecessary and is nonexistant in some SVR4 based systems. * language.c (DEFAULT_ALLOCSIZE): Change from 3 => 4. * language.c (set_language_command): Add chill. * language.c (binop_result_type, integral_type, character_type, boolean_type, structured_type, value_true, binop_type_check): Add language_chill cases. * language.h (_LANG_chill): Define. * m2-exp.y (number_sign, modblock): Make static, #ifdef out unused modblock. * m2-exp.y (ANDAND): Rename to LOGICAL_AND. * source.c (source_info): Fix minor nits, print "1 line" rather than "1 lines", and "language is <lang>". * symfile.c (deduce_language_from_filename): Recognize the filename extensions ".chill", ".c186", and ".c286" for Chill. * valarith.c (value_binop): Handle TYPE_CODE_BOOL as well as TYPE_CODE_INT and TYPE_CODE_FLOAT. * valprint.c (val_print): Print TYPE_CODE_BOOL type values as "TRUE" or "FALSE". * valprint.c (typedef_print): Add case for language_chill. * values.c (value_from_longest): Handle TYPE_CODE_BOOL.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r--gdb/valarith.c120
1 files changed, 77 insertions, 43 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 4c0706b..7db4681 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -134,8 +134,7 @@ value_subscripted_rvalue (array, idx)
error ("no such vector element");
v = allocate_value (elt_type);
- (void) memcpy (VALUE_CONTENTS (v), VALUE_CONTENTS (array) + elt_offs,
- elt_size);
+ memcpy (VALUE_CONTENTS (v), VALUE_CONTENTS (array) + elt_offs, elt_size);
if (VALUE_LVAL (array) == lval_internalvar)
VALUE_LVAL (v) = lval_internalvar_component;
@@ -225,32 +224,32 @@ value_x_binop (arg1, arg2, op, otherop)
ptr = tstr+8;
switch (op)
{
- case BINOP_ADD: strcpy(ptr,"+"); break;
- case BINOP_SUB: strcpy(ptr,"-"); break;
- case BINOP_MUL: strcpy(ptr,"*"); break;
- case BINOP_DIV: strcpy(ptr,"/"); break;
- case BINOP_REM: strcpy(ptr,"%"); break;
- case BINOP_LSH: strcpy(ptr,"<<"); break;
- case BINOP_RSH: strcpy(ptr,">>"); break;
- case BINOP_LOGAND: strcpy(ptr,"&"); break;
- case BINOP_LOGIOR: strcpy(ptr,"|"); break;
- case BINOP_LOGXOR: strcpy(ptr,"^"); break;
- case BINOP_AND: strcpy(ptr,"&&"); break;
- case BINOP_OR: strcpy(ptr,"||"); break;
- case BINOP_MIN: strcpy(ptr,"<?"); break;
- case BINOP_MAX: strcpy(ptr,">?"); break;
- case BINOP_ASSIGN: strcpy(ptr,"="); break;
+ case BINOP_ADD: strcpy(ptr,"+"); break;
+ case BINOP_SUB: strcpy(ptr,"-"); break;
+ case BINOP_MUL: strcpy(ptr,"*"); break;
+ case BINOP_DIV: strcpy(ptr,"/"); break;
+ case BINOP_REM: strcpy(ptr,"%"); break;
+ case BINOP_LSH: strcpy(ptr,"<<"); break;
+ case BINOP_RSH: strcpy(ptr,">>"); break;
+ case BINOP_BITWISE_AND: strcpy(ptr,"&"); break;
+ case BINOP_BITWISE_IOR: strcpy(ptr,"|"); break;
+ case BINOP_BITWISE_XOR: strcpy(ptr,"^"); break;
+ case BINOP_LOGICAL_AND: strcpy(ptr,"&&"); break;
+ case BINOP_LOGICAL_OR: strcpy(ptr,"||"); break;
+ case BINOP_MIN: strcpy(ptr,"<?"); break;
+ case BINOP_MAX: strcpy(ptr,">?"); break;
+ case BINOP_ASSIGN: strcpy(ptr,"="); break;
case BINOP_ASSIGN_MODIFY:
switch (otherop)
{
- case BINOP_ADD: strcpy(ptr,"+="); break;
- case BINOP_SUB: strcpy(ptr,"-="); break;
- case BINOP_MUL: strcpy(ptr,"*="); break;
- case BINOP_DIV: strcpy(ptr,"/="); break;
- case BINOP_REM: strcpy(ptr,"%="); break;
- case BINOP_LOGAND: strcpy(ptr,"&="); break;
- case BINOP_LOGIOR: strcpy(ptr,"|="); break;
- case BINOP_LOGXOR: strcpy(ptr,"^="); break;
+ case BINOP_ADD: strcpy(ptr,"+="); break;
+ case BINOP_SUB: strcpy(ptr,"-="); break;
+ case BINOP_MUL: strcpy(ptr,"*="); break;
+ case BINOP_DIV: strcpy(ptr,"/="); break;
+ case BINOP_REM: strcpy(ptr,"%="); break;
+ case BINOP_BITWISE_AND: strcpy(ptr,"&="); break;
+ case BINOP_BITWISE_IOR: strcpy(ptr,"|="); break;
+ case BINOP_BITWISE_XOR: strcpy(ptr,"^="); break;
default:
error ("Invalid binary operation specified.");
}
@@ -318,9 +317,9 @@ value_x_unop (arg1, op)
case UNOP_PREDECREMENT: strcpy(ptr,"++"); break;
case UNOP_POSTINCREMENT: strcpy(ptr,"++"); break;
case UNOP_POSTDECREMENT: strcpy(ptr,"++"); break;
- case UNOP_ZEROP: strcpy(ptr,"!"); break;
- case UNOP_LOGNOT: strcpy(ptr,"~"); break;
- case UNOP_NEG: strcpy(ptr,"-"); break;
+ case UNOP_LOGICAL_NOT: strcpy(ptr,"!"); break;
+ case UNOP_COMPLEMENT: strcpy(ptr,"~"); break;
+ case UNOP_NEG: strcpy(ptr,"-"); break;
default:
error ("Invalid binary operation specified.");
}
@@ -354,12 +353,16 @@ value_binop (arg1, arg2, op)
if ((TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT
&&
- TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT)
+ TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT
+ &&
+ TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_BOOL)
||
(TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_FLT
&&
- TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT))
- error ("Argument to arithmetic operation not a number.");
+ TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT
+ &&
+ TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_BOOL))
+ error ("Argument to arithmetic operation not a number or boolean.");
if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT
||
@@ -394,8 +397,39 @@ value_binop (arg1, arg2, op)
SWAP_TARGET_AND_HOST (&v, sizeof (v));
*(double *) VALUE_CONTENTS_RAW (val) = v;
}
+ else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_BOOL
+ &&
+ TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_BOOL)
+ {
+ LONGEST v1, v2, v;
+ v1 = value_as_long (arg1);
+ v2 = value_as_long (arg2);
+
+ switch (op)
+ {
+ case BINOP_BITWISE_AND:
+ v = v1 & v2;
+ break;
+
+ case BINOP_BITWISE_IOR:
+ v = v1 | v2;
+ break;
+
+ case BINOP_BITWISE_XOR:
+ v = v1 ^ v2;
+ break;
+
+ default:
+ error ("Invalid operation on booleans.");
+ }
+
+ val = allocate_value (builtin_type_chill_bool);
+ SWAP_TARGET_AND_HOST (&v, sizeof (v));
+ *(LONGEST *) VALUE_CONTENTS_RAW (val) = v;
+ }
else
/* Integral operations here. */
+ /* FIXME: Also mixed integral/booleans, with result an integer. */
{
/* Should we promote to unsigned longest? */
if ((TYPE_UNSIGNED (VALUE_TYPE (arg1))
@@ -437,23 +471,23 @@ value_binop (arg1, arg2, op)
v = v1 >> v2;
break;
- case BINOP_LOGAND:
+ case BINOP_BITWISE_AND:
v = v1 & v2;
break;
- case BINOP_LOGIOR:
+ case BINOP_BITWISE_IOR:
v = v1 | v2;
break;
- case BINOP_LOGXOR:
+ case BINOP_BITWISE_XOR:
v = v1 ^ v2;
break;
- case BINOP_AND:
+ case BINOP_LOGICAL_AND:
v = v1 && v2;
break;
- case BINOP_OR:
+ case BINOP_LOGICAL_OR:
v = v1 || v2;
break;
@@ -509,23 +543,23 @@ value_binop (arg1, arg2, op)
v = v1 >> v2;
break;
- case BINOP_LOGAND:
+ case BINOP_BITWISE_AND:
v = v1 & v2;
break;
- case BINOP_LOGIOR:
+ case BINOP_BITWISE_IOR:
v = v1 | v2;
break;
- case BINOP_LOGXOR:
+ case BINOP_BITWISE_XOR:
v = v1 ^ v2;
break;
- case BINOP_AND:
+ case BINOP_LOGICAL_AND:
v = v1 && v2;
break;
- case BINOP_OR:
+ case BINOP_LOGICAL_OR:
v = v1 || v2;
break;
@@ -553,7 +587,7 @@ value_binop (arg1, arg2, op)
/* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
int
-value_zerop (arg1)
+value_logical_not (arg1)
value arg1;
{
register int len;
@@ -696,7 +730,7 @@ value_neg (arg1)
}
value
-value_lognot (arg1)
+value_complement (arg1)
register value arg1;
{
COERCE_ENUM (arg1);