Joel Sherrill (joel@OARcorp.com)
[deliverable/binutils-gdb.git] / gdb / c-lang.c
index bdeb8c73c5682018a7bd914f57a67b12b440bddd..e7aa05574caecfae1f49fa1838d6aa657146cc8d 100644 (file)
@@ -1,5 +1,5 @@
 /* C language support routines for GDB, the GNU debugger.
-   Copyright 1992 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -15,7 +15,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "symtab.h"
@@ -25,17 +25,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "language.h"
 #include "c-lang.h"
 
+static void c_emit_char PARAMS ((int c, GDB_FILE *stream, int quoter));
+
 /* Print the character C on STREAM as part of the contents of a literal
    string whose delimiter is QUOTER.  Note that that format for printing
    characters and strings is language specific. */
 
 static void
-emit_char (c, stream, quoter)
+c_emit_char (c, stream, quoter)
      register int c;
-     FILE *stream;
+     GDB_FILE *stream;
      int quoter;
 {
-
   c &= 0xFF;                   /* Avoid sign bit follies */
 
   if (PRINT_LITERAL_FORM (c))
@@ -78,26 +79,28 @@ emit_char (c, stream, quoter)
     }
 }
 
-static void
+void
 c_printchar (c, stream)
      int c;
-     FILE *stream;
+     GDB_FILE *stream;
 {
-  fputs_filtered ("'", stream);
-  emit_char (c, stream, '\'');
-  fputs_filtered ("'", stream);
+  fputc_filtered ('\'', stream);
+  LA_EMIT_CHAR (c, stream, '\'');
+  fputc_filtered ('\'', stream);
 }
 
 /* Print the character string STRING, printing at most LENGTH characters.
-   Printing stops early if the number hits print_max; repeat counts
-   are printed as appropriate.  Print ellipses at the end if we
-   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
+   LENGTH is -1 if the string is nul terminated.  Each character is WIDTH bytes
+   long.  Printing stops early if the number hits print_max; repeat counts are
+   printed as appropriate.  Print ellipses at the end if we had to stop before
+   printing LENGTH characters, or if FORCE_ELLIPSES.  */
 
-static void
-c_printstr (stream, string, length, force_ellipses)
-     FILE *stream;
+void
+c_printstr (stream, string, length, width, force_ellipses)
+     GDB_FILE *stream;
      char *string;
      unsigned int length;
+     int width;
      int force_ellipses;
 {
   register unsigned int i;
@@ -108,9 +111,17 @@ c_printstr (stream, string, length, force_ellipses)
   extern int repeat_count_threshold;
   extern int print_max;
 
+  /* If the string was not truncated due to `set print elements', and
+     the last byte of it is a null, we don't print that, in traditional C
+     style.  */
+  if (!force_ellipses
+      && length > 0
+      && extract_unsigned_integer (string + (length - 1) * width, width) == '\0')
+    length--;
+
   if (length == 0)
     {
-      fputs_filtered ("\"\"", stdout);
+      fputs_filtered ("\"\"", stream);
       return;
     }
 
@@ -121,6 +132,7 @@ c_printstr (stream, string, length, force_ellipses)
       unsigned int rep1;
       /* Number of repetitions we have detected so far.  */
       unsigned int reps;
+      unsigned long current_char;
 
       QUIT;
 
@@ -130,9 +142,13 @@ c_printstr (stream, string, length, force_ellipses)
          need_comma = 0;
        }
 
+      current_char = extract_unsigned_integer (string + i * width, width);
+
       rep1 = i + 1;
       reps = 1;
-      while (rep1 < length && string[rep1] == string[i])
+      while (rep1 < length
+            && extract_unsigned_integer (string + rep1 * width, width)
+               == current_char)
        {
          ++rep1;
          ++reps;
@@ -148,7 +164,7 @@ c_printstr (stream, string, length, force_ellipses)
                fputs_filtered ("\", ", stream);
              in_quotes = 0;
            }
-         c_printchar (string[i], stream);
+         LA_PRINT_CHAR (current_char, stream);
          fprintf_filtered (stream, " <repeats %u times>", reps);
          i = rep1 - 1;
          things_printed += repeat_count_threshold;
@@ -164,7 +180,7 @@ c_printstr (stream, string, length, force_ellipses)
                fputs_filtered ("\"", stream);
              in_quotes = 1;
            }
-         emit_char (string[i], stream, '"');
+         LA_EMIT_CHAR (current_char, stream, '"');
          ++things_printed;
        }
     }
@@ -205,13 +221,12 @@ c_printstr (stream, string, length, force_ellipses)
    starts taking it's fundamental type information directly from the
    debugging information supplied by the compiler.  fnf@cygnus.com */
 
-static struct type *
+struct type *
 c_create_fundamental_type (objfile, typeid)
      struct objfile *objfile;
      int typeid;
 {
   register struct type *type = NULL;
-  register int nbytes;
 
   switch (typeid)
     {
@@ -230,15 +245,22 @@ c_create_fundamental_type (objfile, typeid)
                          TARGET_CHAR_BIT / TARGET_CHAR_BIT,
                          0, "void", objfile);
        break;
+      case FT_BOOLEAN:
+        type = init_type (TYPE_CODE_BOOL,
+                         TARGET_CHAR_BIT / TARGET_CHAR_BIT,
+                          0, "bool", objfile);
+                          
+        break;
       case FT_CHAR:
        type = init_type (TYPE_CODE_INT,
                          TARGET_CHAR_BIT / TARGET_CHAR_BIT,
                          0, "char", objfile);
+        TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
        break;
       case FT_SIGNED_CHAR:
        type = init_type (TYPE_CODE_INT,
                          TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                         TYPE_FLAG_SIGNED, "signed char", objfile);
+                         0, "signed char", objfile);
        break;
       case FT_UNSIGNED_CHAR:
        type = init_type (TYPE_CODE_INT,
@@ -253,7 +275,7 @@ c_create_fundamental_type (objfile, typeid)
       case FT_SIGNED_SHORT:
        type = init_type (TYPE_CODE_INT,
                          TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-                         TYPE_FLAG_SIGNED, "short", objfile);  /* FIXME-fnf */
+                         0, "short", objfile); /* FIXME-fnf */
        break;
       case FT_UNSIGNED_SHORT:
        type = init_type (TYPE_CODE_INT,
@@ -268,7 +290,7 @@ c_create_fundamental_type (objfile, typeid)
       case FT_SIGNED_INTEGER:
        type = init_type (TYPE_CODE_INT,
                          TARGET_INT_BIT / TARGET_CHAR_BIT,
-                         TYPE_FLAG_SIGNED, "int", objfile); /* FIXME -fnf */
+                         0, "int", objfile); /* FIXME -fnf */
        break;
       case FT_UNSIGNED_INTEGER:
        type = init_type (TYPE_CODE_INT,
@@ -283,7 +305,7 @@ c_create_fundamental_type (objfile, typeid)
       case FT_SIGNED_LONG:
        type = init_type (TYPE_CODE_INT,
                          TARGET_LONG_BIT / TARGET_CHAR_BIT,
-                         TYPE_FLAG_SIGNED, "long", objfile); /* FIXME -fnf */
+                         0, "long", objfile); /* FIXME -fnf */
        break;
       case FT_UNSIGNED_LONG:
        type = init_type (TYPE_CODE_INT,
@@ -298,7 +320,7 @@ c_create_fundamental_type (objfile, typeid)
       case FT_SIGNED_LONG_LONG:
        type = init_type (TYPE_CODE_INT,
                          TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-                         TYPE_FLAG_SIGNED, "signed long long", objfile);
+                         0, "signed long long", objfile);
        break;
       case FT_UNSIGNED_LONG_LONG:
        type = init_type (TYPE_CODE_INT,
@@ -319,6 +341,12 @@ c_create_fundamental_type (objfile, typeid)
        type = init_type (TYPE_CODE_FLT,
                          TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
                          0, "long double", objfile);
+        break;
+      case FT_TEMPLATE_ARG:
+        type = init_type (TYPE_CODE_TEMPLATE_ARG,
+                         0,
+                         0, "<template arg>", objfile);
+
        break;
       }
   return (type);
@@ -328,7 +356,7 @@ c_create_fundamental_type (objfile, typeid)
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
 
-const static struct op_print c_op_print_tab[] =
+const struct op_print c_op_print_tab[] =
   {
     {",",  BINOP_COMMA, PREC_COMMA, 0},
     {"=",  BINOP_ASSIGN, PREC_ASSIGN, 1},
@@ -364,28 +392,7 @@ const static struct op_print c_op_print_tab[] =
     {NULL, 0, 0, 0}
 };
 \f
-/* These variables point to the objects
-   representing the predefined C data types.  */
-
-struct type *builtin_type_void;
-struct type *builtin_type_char;
-struct type *builtin_type_short;
-struct type *builtin_type_int;
-struct type *builtin_type_long;
-struct type *builtin_type_long_long;
-struct type *builtin_type_signed_char;
-struct type *builtin_type_unsigned_char;
-struct type *builtin_type_unsigned_short;
-struct type *builtin_type_unsigned_int;
-struct type *builtin_type_unsigned_long;
-struct type *builtin_type_unsigned_long_long;
-struct type *builtin_type_float;
-struct type *builtin_type_double;
-struct type *builtin_type_long_double;
-struct type *builtin_type_complex;
-struct type *builtin_type_double_complex;
-
-struct type ** const (c_builtin_types[]) = 
+struct type ** CONST_PTR (c_builtin_types[]) = 
 {
   &builtin_type_int,
   &builtin_type_long,
@@ -415,114 +422,106 @@ const struct language_defn c_language_defn = {
   type_check_off,
   c_parse,
   c_error,
+  evaluate_subexp_standard,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
+  c_emit_char,                 /* Print a single char */
   c_create_fundamental_type,   /* Create fundamental type in this language */
-  &BUILTIN_TYPE_LONGEST,       /* longest signed   integral type */
-  &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
-  &builtin_type_double,                /* longest floating point type */ /*FIXME*/
+  c_print_type,                        /* Print a type using appropriate syntax */
+  c_val_print,                 /* Print a value using appropriate syntax */
+  c_value_print,               /* Print a top-level value */
   {"",     "",    "",  ""},    /* Binary format info */
-  {"0%o",  "0",   "o", ""},    /* Octal format info */
-  {"%d",   "",    "d", ""},    /* Decimal format info */
-  {"0x%x", "0x",  "x", ""},    /* Hex format info */
+  {"0%lo",  "0",   "o", ""},   /* Octal format info */
+  {"%ld",   "",    "d", ""},   /* Decimal format info */
+  {"0x%lx", "0x",  "x", ""},   /* Hex format info */
   c_op_print_tab,              /* expression operators for printing */
+  1,                           /* c-style arrays */
+  0,                           /* String lower bound */
+  &builtin_type_char,          /* Type of string elements */ 
   LANG_MAGIC
 };
 
+struct type ** const (cplus_builtin_types[]) = 
+{
+  &builtin_type_int,
+  &builtin_type_long,
+  &builtin_type_short,
+  &builtin_type_char,
+  &builtin_type_float,
+  &builtin_type_double,
+  &builtin_type_void,
+  &builtin_type_long_long,
+  &builtin_type_signed_char,
+  &builtin_type_unsigned_char,
+  &builtin_type_unsigned_short,
+  &builtin_type_unsigned_int,
+  &builtin_type_unsigned_long,
+  &builtin_type_unsigned_long_long,
+  &builtin_type_long_double,
+  &builtin_type_complex,
+  &builtin_type_double_complex,
+  &builtin_type_bool,
+  0
+};
+
 const struct language_defn cplus_language_defn = {
   "c++",                               /* Language name */
   language_cplus,
-  c_builtin_types,
+  cplus_builtin_types,
   range_check_off,
   type_check_off,
   c_parse,
   c_error,
+  evaluate_subexp_standard,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
+  c_emit_char,                 /* Print a single char */
   c_create_fundamental_type,   /* Create fundamental type in this language */
-  &BUILTIN_TYPE_LONGEST,        /* longest signed   integral type */
-  &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
-  &builtin_type_double,                /* longest floating point type */ /*FIXME*/
+  c_print_type,                        /* Print a type using appropriate syntax */
+  c_val_print,                 /* Print a value using appropriate syntax */
+  c_value_print,               /* Print a top-level value */
   {"",      "",    "",   ""},  /* Binary format info */
-  {"0%o",   "0",   "o",  ""},  /* Octal format info */
-  {"%d",    "",    "d",  ""},  /* Decimal format info */
-  {"0x%x",  "0x",  "x",  ""},  /* Hex format info */
+  {"0%lo",   "0",   "o",  ""}, /* Octal format info */
+  {"%ld",    "",    "d",  ""}, /* Decimal format info */
+  {"0x%lx",  "0x",  "x",  ""}, /* Hex format info */
   c_op_print_tab,              /* expression operators for printing */
+  1,                           /* c-style arrays */
+  0,                           /* String lower bound */
+  &builtin_type_char,          /* Type of string elements */ 
+  LANG_MAGIC
+};
+
+const struct language_defn asm_language_defn = {
+  "asm",                       /* Language name */
+  language_asm,
+  c_builtin_types,
+  range_check_off,
+  type_check_off,
+  c_parse,
+  c_error,
+  evaluate_subexp_standard,
+  c_printchar,                 /* Print a character constant */
+  c_printstr,                  /* Function to print string constant */
+  c_emit_char,                 /* Print a single char */
+  c_create_fundamental_type,   /* Create fundamental type in this language */
+  c_print_type,                        /* Print a type using appropriate syntax */
+  c_val_print,                 /* Print a value using appropriate syntax */
+  c_value_print,               /* Print a top-level value */
+  {"",     "",    "",  ""},    /* Binary format info */
+  {"0%lo",  "0",   "o", ""},   /* Octal format info */
+  {"%ld",   "",    "d", ""},   /* Decimal format info */
+  {"0x%lx", "0x",  "x", ""},   /* Hex format info */
+  c_op_print_tab,              /* expression operators for printing */
+  1,                           /* c-style arrays */
+  0,                           /* String lower bound */
+  &builtin_type_char,          /* Type of string elements */ 
   LANG_MAGIC
 };
 
 void
 _initialize_c_language ()
 {
-  builtin_type_void =
-    init_type (TYPE_CODE_VOID, 1,
-              0,
-              "void", (struct objfile *) NULL);
-  builtin_type_char =
-    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-              0,
-              "char", (struct objfile *) NULL);
-  builtin_type_signed_char =
-    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_SIGNED,
-              "signed char", (struct objfile *) NULL);
-  builtin_type_unsigned_char =
-    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_UNSIGNED,
-              "unsigned char", (struct objfile *) NULL);
-  builtin_type_short =
-    init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-              0,
-              "short", (struct objfile *) NULL);
-  builtin_type_unsigned_short =
-    init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_UNSIGNED,
-              "unsigned short", (struct objfile *) NULL);
-  builtin_type_int =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
-              0,
-              "int", (struct objfile *) NULL);
-  builtin_type_unsigned_int =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_UNSIGNED,
-              "unsigned int", (struct objfile *) NULL);
-  builtin_type_long =
-    init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
-              0,
-              "long", (struct objfile *) NULL);
-  builtin_type_unsigned_long =
-    init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_UNSIGNED,
-              "unsigned long", (struct objfile *) NULL);
-  builtin_type_long_long =
-    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-              0,
-              "long long", (struct objfile *) NULL);
-  builtin_type_unsigned_long_long = 
-    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-              TYPE_FLAG_UNSIGNED,
-              "unsigned long long", (struct objfile *) NULL);
-  builtin_type_float =
-    init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
-              0,
-              "float", (struct objfile *) NULL);
-  builtin_type_double =
-    init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
-              0,
-              "double", (struct objfile *) NULL);
-  builtin_type_long_double =
-    init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
-              0,
-              "long double", (struct objfile *) NULL);
-  builtin_type_complex =
-    init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
-              0,
-              "complex", (struct objfile *) NULL);
-  builtin_type_double_complex =
-    init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
-              0,
-              "double complex", (struct objfile *) NULL);
-
   add_language (&c_language_defn);
   add_language (&cplus_language_defn);
+  add_language (&asm_language_defn);
 }
This page took 0.028787 seconds and 4 git commands to generate.