* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[deliverable/binutils-gdb.git] / gdb / ch-lang.c
index 5c041d74f71400ade01cc9ba67a3947c90eecda2..c54e8bb3619319eb69bb1e16547a9b280ea09ddc 100644 (file)
@@ -26,6 +26,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "language.h"
 #include "ch-lang.h"
 
+static value_ptr
+evaluate_subexp_chill PARAMS ((struct type *, struct expression *, int *, enum noside));
+
+static value_ptr
+value_chill_max_min PARAMS ((enum exp_opcode, value_ptr));
+
+static value_ptr
+value_chill_card PARAMS ((value_ptr));
+
+static value_ptr
+ value_chill_length PARAMS ((value_ptr));
+
+static struct type *
+chill_create_fundamental_type PARAMS ((struct objfile *, int));
+
+static void
+chill_printstr PARAMS ((GDB_FILE *stream, char *string, unsigned int length, int width, int force_ellipses));
+
+static void
+chill_printchar PARAMS ((int, GDB_FILE *));
 
 /* For now, Chill uses a simple mangling algorithm whereby you simply
    discard everything after the occurance of two successive CPLUS_MARKER
@@ -68,11 +88,14 @@ chill_printchar (c, stream)
 
   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);
     }
 }
 
@@ -88,10 +111,11 @@ chill_printchar (c, stream)
   */
 
 static void
-chill_printstr (stream, string, length, force_ellipses)
+chill_printstr (stream, string, length, width, force_ellipses)
      GDB_FILE *stream;
      char *string;
      unsigned int length;
+     int width;
      int force_ellipses;
 {
   register unsigned int i;
@@ -138,6 +162,8 @@ chill_printstr (stream, string, length, force_ellipses)
        {
          if (in_control_form || in_literal_form)
            {
+             if (in_control_form)
+               fputs_filtered (")", stream);
              fputs_filtered ("\"//", stream);
              in_control_form = in_literal_form = 0;
            }
@@ -149,19 +175,23 @@ chill_printstr (stream, string, length, force_ellipses)
        }
       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
            {
@@ -169,19 +199,25 @@ chill_printstr (stream, string, length, force_ellipses)
                {
                  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);
@@ -265,7 +301,9 @@ static const struct op_print chill_op_print_tab[] = {
     {"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},
@@ -293,7 +331,7 @@ struct type *builtin_type_chill_long;
 struct type *builtin_type_chill_ulong;
 struct type *builtin_type_chill_real;
 
-struct type ** const (chill_builtin_types[]) = 
+struct type ** CONST_PTR (chill_builtin_types[]) = 
 {
   &builtin_type_chill_bool,
   &builtin_type_chill_char,
@@ -390,6 +428,86 @@ value_chill_length (val)
   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;
@@ -424,7 +542,7 @@ evaluate_subexp_chill (expect_type, exp, pos, noside)
        {
        case TYPE_CODE_PTR:
          type = check_typedef (TYPE_TARGET_TYPE (type));
-         if (!type || TYPE_CODE (type) || TYPE_CODE_FUNC)
+         if (!type || TYPE_CODE (type) != TYPE_CODE_FUNC)
            error ("reference value used as function");
          /* ... fall through ... */
        case TYPE_CODE_FUNC:
@@ -477,6 +595,17 @@ evaluate_subexp_chill (expect_type, exp, pos, noside)
       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");
 
@@ -500,6 +629,7 @@ const struct language_defn chill_language_defn = {
   evaluate_subexp_chill,
   chill_printchar,             /* print a character constant */
   chill_printstr,              /* function to print a string constant */
+  NULL,                                /* Function to print a single char */
   chill_create_fundamental_type,/* Create fundamental type in this language */
   chill_print_type,            /* Print a type using appropriate syntax */
   chill_val_print,             /* Print a value using appropriate syntax */
This page took 0.039865 seconds and 4 git commands to generate.