+Tue Mar 5 23:48:36 1996 Wilfried Moser (Alcatel) <moser@rtl.cygnus.com>
+
+ * ch-exp.c (parse_primval): Handle CARD, MAX, MIN.
+ (match_string_literal): Handle control sequence.
+ (match_character_literal): Deto.
+
+ * ch-lang.c (chill_printchar): Change formating of nonprintable
+ characters from C'xx' to ^(num).
+ (chill_printstr): Deto.
+ (value_chill_card, value_chill_max_min): New functions to process
+ Chill's CARD, MAX, MIN.
+ (evaluate_subexp_chill): Process UNOP_CARD, UNOP_CHMAX, UNOP_CHMIN.
+
+ * expression.h (exp_opcode): Add UNOP_CARD, UNOP_CHMAX, UNOP_CHMIN
+ for Chill's CARD, MAX, MIN.
+
+ * valarith.c (value_in): Add processing of TYPE_CODE_RANGE
+ and change return type from builtin_type_int to
+ builtin_type_chill_bool.
+
Tue Mar 5 18:54:04 1996 Stan Shebs <shebs@andros.cygnus.com>
* config/nm-nbsd.h (link_object, lo_name, etc): Move to here
write_exp_elt_type (builtin_type_int);
write_exp_elt_opcode (UNOP_CAST);
break;
+ case CARD:
+ parse_unary_call ();
+ write_exp_elt_opcode (UNOP_CARD);
+ break;
+ case MAX_TOKEN:
+ parse_unary_call ();
+ write_exp_elt_opcode (UNOP_CHMAX);
+ break;
+ case MIN_TOKEN:
+ parse_unary_call ();
+ write_exp_elt_opcode (UNOP_CHMIN);
+ break;
case PRED: op_name = "PRED"; goto unimplemented_unary_builtin;
case SUCC: op_name = "SUCC"; goto unimplemented_unary_builtin;
case ABS: op_name = "ABS"; goto unimplemented_unary_builtin;
- case CARD: op_name = "CARD"; goto unimplemented_unary_builtin;
- case MAX_TOKEN: op_name = "MAX"; goto unimplemented_unary_builtin;
- case MIN_TOKEN: op_name = "MIN"; goto unimplemented_unary_builtin;
unimplemented_unary_builtin:
parse_unary_call ();
error ("not implemented: %s builtin function", op_name);
match_string_literal ()
{
char *tokptr = lexptr;
+ int in_ctrlseq = 0;
+ LONGEST ival;
for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
{
CHECKBUF (1);
- if (*tokptr == *lexptr)
+ tryagain: ;
+ if (in_ctrlseq)
{
- if (*(tokptr + 1) == *lexptr)
+ /* skip possible whitespaces */
+ while ((*tokptr == ' ' || *tokptr == '\t') && *tokptr)
+ tokptr++;
+ if (*tokptr == ')')
{
+ in_ctrlseq = 0;
tokptr++;
+ goto tryagain;
+ }
+ else if (*tokptr != ',')
+ error ("Invalid control sequence");
+ tokptr++;
+ /* skip possible whitespaces */
+ while ((*tokptr == ' ' || *tokptr == '\t') && *tokptr)
+ tokptr++;
+ if (!decode_integer_literal (&ival, &tokptr))
+ error ("Invalid control sequence");
+ tokptr--;
+ }
+ else if (*tokptr == *lexptr)
+ {
+ if (*(tokptr + 1) == *lexptr)
+ {
+ ival = *tokptr++;
}
else
{
break;
}
}
- tempbuf[tempbufindex++] = *tokptr;
+ else if (*tokptr == '^')
+ {
+ if (*(tokptr + 1) == '(')
+ {
+ in_ctrlseq = 1;
+ tokptr += 2;
+ if (!decode_integer_literal (&ival, &tokptr))
+ error ("Invalid control sequence");
+ tokptr--;
+ }
+ else if (*(tokptr + 1) == '^')
+ ival = *tokptr++;
+ else
+ error ("Invalid control sequence");
+ }
+ else
+ ival = *tokptr;
+ tempbuf[tempbufindex++] = ival;
}
+ if (in_ctrlseq)
+ error ("Invalid control sequence");
+
if (*tokptr == '\0' /* no terminator */
|| (tempbufindex == 1 && *tokptr == '\'')) /* char literal */
{
Note that more than a single character, enclosed in single quotes, is
a string literal.
- Also note that the control sequence form is not in GNU Chill since it
- is ambiguous with the string literal form using single quotes. I.E.
- is '^(7)' a character literal or a string literal. In theory it it
- possible to tell by context, but GNU Chill doesn't accept the control
- sequence form, so neither do we (for now the code is disabled).
-
Returns CHARACTER_LITERAL if a match is found.
*/
/* Determine which form we have, either a control sequence or the
single character form. */
- if ((*tokptr == '^') && (*(tokptr + 1) == '('))
+ if (*tokptr == '^')
{
-#if 0 /* Disable, see note above. -fnf */
- /* Match and decode a control sequence. Return zero if we don't
- find a valid integer literal, or if the next unconsumed character
- after the integer literal is not the trailing ')'.
- FIXME: We currently don't handle the multiple integer literal
- form. */
- tokptr += 2;
- if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')'))
+ if (*(tokptr + 1) == '(')
{
- return (0);
+ /* Match and decode a control sequence. Return zero if we don't
+ find a valid integer literal, or if the next unconsumed character
+ after the integer literal is not the trailing ')'. */
+ tokptr += 2;
+ if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')'))
+ {
+ return (0);
+ }
}
-#else
- return (0);
-#endif
+ else if (*(tokptr + 1) == '^')
+ {
+ ival = *tokptr;
+ tokptr += 2;
+ }
+ else
+ /* fail */
+ error ("Invalid control sequence");
+ }
+ else if (*tokptr == '\'')
+ {
+ /* this must be duplicated */
+ ival = *tokptr;
+ tokptr += 2;
}
else
{
ival = *tokptr++;
}
-
+
/* The trailing quote has not yet been consumed. If we don't find
it, then we have no match. */
digit += 10;
break;
default:
- error ("Invalid character in bitstring or integer.");
+ /* this is not a bitstring literal, probably an integer */
+ return 0;
}
if (digit >= 1 << bits_per_char)
{
if (PRINT_LITERAL_FORM (c))
{
- fprintf_filtered (stream, "'%c'", c);
+ if (c == '\'' || c == '^')
+ fprintf_filtered (stream, "'%c%c'", c, c);
+ else
+ fprintf_filtered (stream, "'%c'", c);
}
else
{
- fprintf_filtered (stream, "C'%.2x'", (unsigned int) c);
+ fprintf_filtered (stream, "'^(%u)'", (unsigned int) c);
}
}
{
if (in_control_form || in_literal_form)
{
+ if (in_control_form)
+ fputs_filtered (")", stream);
fputs_filtered ("\"//", stream);
in_control_form = in_literal_form = 0;
}
}
else
{
+ if (! in_literal_form && ! in_control_form)
+ fputs_filtered ("\"", stream);
if (PRINT_LITERAL_FORM (c))
{
if (!in_literal_form)
{
if (in_control_form)
{
- fputs_filtered ("\"//", stream);
+ fputs_filtered (")", stream);
in_control_form = 0;
}
- fputs_filtered ("\"", stream);
in_literal_form = 1;
}
fprintf_filtered (stream, "%c", c);
+ if (c == '"' || c == '^')
+ /* duplicate this one as must be done at input */
+ fprintf_filtered (stream, "%c", c);
}
else
{
{
if (in_literal_form)
{
- fputs_filtered ("\"//", stream);
in_literal_form = 0;
}
- fputs_filtered ("c\"", stream);
+ fputs_filtered ("^(", stream);
in_control_form = 1;
}
- fprintf_filtered (stream, "%.2x", c);
+ else
+ fprintf_filtered (stream, ",");
+ c = c & 0xff;
+ fprintf_filtered (stream, "%u", (unsigned int) c);
}
++things_printed;
}
}
/* Terminate the quotes if necessary. */
+ if (in_control_form)
+ {
+ fputs_filtered (")", stream);
+ }
if (in_literal_form || in_control_form)
{
fputs_filtered ("\"", stream);
{"SIZE",UNOP_SIZEOF, PREC_BUILTIN_FUNCTION, 0},
{"LOWER",UNOP_LOWER, PREC_BUILTIN_FUNCTION, 0},
{"UPPER",UNOP_UPPER, PREC_BUILTIN_FUNCTION, 0},
- {"LOWER",UNOP_UPPER, PREC_BUILTIN_FUNCTION, 0},
+ {"CARD",UNOP_CARD, PREC_BUILTIN_FUNCTION, 0},
+ {"MAX",UNOP_CHMAX, PREC_BUILTIN_FUNCTION, 0},
+ {"MIN",UNOP_CHMIN, PREC_BUILTIN_FUNCTION, 0},
{":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
{"=", BINOP_EQUAL, PREC_EQUAL, 0},
{"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
return value_from_longest (builtin_type_int, tmp);
}
+static value_ptr
+value_chill_card (val)
+ value_ptr val;
+{
+ LONGEST tmp = 0;
+ struct type *type = VALUE_TYPE (val);
+ CHECK_TYPEDEF (type);
+
+ if (TYPE_CODE (type) == TYPE_CODE_SET)
+ {
+ struct type *range_type = TYPE_INDEX_TYPE (type);
+ LONGEST lower_bound, upper_bound;
+ int i;
+
+ get_discrete_bounds (range_type, &lower_bound, &upper_bound);
+ for (i = lower_bound; i <= upper_bound; i++)
+ if (value_bit_index (type, VALUE_CONTENTS (val), i) > 0)
+ tmp++;
+ }
+ else
+ error ("bad argument to CARD builtin");
+
+ return value_from_longest (builtin_type_int, tmp);
+}
+
+static value_ptr
+value_chill_max_min (op, val)
+ enum exp_opcode op;
+ value_ptr val;
+{
+ LONGEST tmp = 0;
+ struct type *type = VALUE_TYPE (val);
+ struct type *elttype;
+ CHECK_TYPEDEF (type);
+
+ if (TYPE_CODE (type) == TYPE_CODE_SET)
+ {
+ LONGEST lower_bound, upper_bound;
+ int i, empty = 1;
+
+ elttype = TYPE_INDEX_TYPE (type);
+ CHECK_TYPEDEF (elttype);
+ get_discrete_bounds (elttype, &lower_bound, &upper_bound);
+
+ if (op == UNOP_CHMAX)
+ {
+ for (i = upper_bound; i >= lower_bound; i--)
+ {
+ if (value_bit_index (type, VALUE_CONTENTS (val), i) > 0)
+ {
+ tmp = i;
+ empty = 0;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (i = lower_bound; i <= upper_bound; i++)
+ {
+ if (value_bit_index (type, VALUE_CONTENTS (val), i) > 0)
+ {
+ tmp = i;
+ empty = 0;
+ break;
+ }
+ }
+ }
+ if (empty)
+ error ("%s for empty powerset", op == UNOP_CHMAX ? "MAX" : "MIN");
+ }
+ else
+ error ("bad argument to %s builtin", op == UNOP_CHMAX ? "MAX" : "MIN");
+
+ return value_from_longest (TYPE_CODE (elttype) == TYPE_CODE_RANGE
+ ? TYPE_TARGET_TYPE (elttype)
+ : elttype,
+ tmp);
+}
+
static value_ptr
evaluate_subexp_chill (expect_type, exp, pos, noside)
struct type *expect_type;
arg1 = (*exp->language_defn->evaluate_exp) (NULL_TYPE, exp, pos, noside);
return value_chill_length (arg1);
+ case UNOP_CARD:
+ (*pos)++;
+ arg1 = (*exp->language_defn->evaluate_exp) (NULL_TYPE, exp, pos, noside);
+ return value_chill_card (arg1);
+
+ case UNOP_CHMAX:
+ case UNOP_CHMIN:
+ (*pos)++;
+ arg1 = (*exp->language_defn->evaluate_exp) (NULL_TYPE, exp, pos, noside);
+ return value_chill_max_min (op, arg1);
+
case BINOP_COMMA:
error ("',' operator used in invalid context");