2007-06-19 Markus Deuling <deuling@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / m2-lang.c
index 64e07cca44e57e0a49c76a8812a49e6ff923fc92..acb2de6d6c12e206b16d685992763135e0f02387 100644 (file)
@@ -1,5 +1,7 @@
 /* Modula 2 language support routines for GDB, the GNU debugger.
-   Copyright 1992, 2000 Free Software Foundation, Inc.
+
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2002, 2003, 2004,
+   2005, 2007 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -15,8 +17,8 @@
 
    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., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 #include "defs.h"
 #include "symtab.h"
 #include "c-lang.h"
 #include "valprint.h"
 
-extern void _initialize_m2_language PARAMS ((void));
-static struct type *m2_create_fundamental_type PARAMS ((struct objfile *, int));
-static void m2_printstr (struct ui_file * stream, char *string,
-                        unsigned int length, int width,
-                        int force_ellipses);
+extern void _initialize_m2_language (void);
+static struct type *m2_create_fundamental_type (struct objfile *, int);
 static void m2_printchar (int, struct ui_file *);
 static void m2_emit_char (int, struct ui_file *, int);
 
@@ -44,10 +43,7 @@ static void m2_emit_char (int, struct ui_file *, int);
  */
 
 static void
-m2_emit_char (c, stream, quoter)
-     register int c;
-     struct ui_file *stream;
-     int quoter;
+m2_emit_char (int c, struct ui_file *stream, int quoter)
 {
 
   c &= 0xFF;                   /* Avoid sign bit follies */
@@ -96,9 +92,7 @@ m2_emit_char (c, stream, quoter)
    be replaced with a true Modula version. */
 
 static void
-m2_printchar (c, stream)
-     int c;
-     struct ui_file *stream;
+m2_printchar (int c, struct ui_file *stream)
 {
   fputs_filtered ("'", stream);
   LA_EMIT_CHAR (c, stream, '\'');
@@ -113,18 +107,13 @@ m2_printchar (c, stream)
    be replaced with a true Modula version. */
 
 static void
-m2_printstr (stream, string, length, width, force_ellipses)
-     struct ui_file *stream;
-     char *string;
-     unsigned int length;
-     int width;
-     int force_ellipses;
+m2_printstr (struct ui_file *stream, const gdb_byte *string,
+            unsigned int length, int width, int force_ellipses)
 {
-  register unsigned int i;
+  unsigned int i;
   unsigned int things_printed = 0;
   int in_quotes = 0;
   int need_comma = 0;
-  extern int inspect_it;
 
   if (length == 0)
     {
@@ -205,11 +194,9 @@ m2_printstr (stream, string, length, width, force_ellipses)
    by an experienced Modula programmer. */
 
 static struct type *
-m2_create_fundamental_type (objfile, typeid)
-     struct objfile *objfile;
-     int typeid;
+m2_create_fundamental_type (struct objfile *objfile, int typeid)
 {
-  register struct type *type = NULL;
+  struct type *type = NULL;
 
   switch (typeid)
     {
@@ -219,9 +206,9 @@ m2_create_fundamental_type (objfile, typeid)
          name "<?type?>".  When all the dust settles from the type
          reconstruction work, this should probably become an error. */
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "<?type?>", objfile);
-      warning ("internal error: no Modula fundamental type %d", typeid);
+      warning (_("internal error: no Modula fundamental type %d"), typeid);
       break;
     case FT_VOID:
       type = init_type (TYPE_CODE_VOID,
@@ -255,106 +242,113 @@ m2_create_fundamental_type (objfile, typeid)
       break;
     case FT_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "short", objfile);
       break;
     case FT_SIGNED_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "short", objfile);   /* FIXME-fnf */
       break;
     case FT_UNSIGNED_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
       break;
     case FT_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "int", objfile);
       break;
     case FT_SIGNED_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "int", objfile);     /* FIXME -fnf */
       break;
     case FT_UNSIGNED_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
       break;
     case FT_FIXED_DECIMAL:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "fixed decimal", objfile);
       break;
     case FT_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "long", objfile);
       break;
     case FT_SIGNED_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "long", objfile);    /* FIXME -fnf */
       break;
     case FT_UNSIGNED_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
       break;
     case FT_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long long", objfile);
       break;
     case FT_SIGNED_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "signed long long", objfile);
       break;
     case FT_UNSIGNED_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
       break;
     case FT_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "float", objfile);
       break;
     case FT_DBL_PREC_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "double", objfile);
       break;
     case FT_FLOAT_DECIMAL:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "floating decimal", objfile);
       break;
     case FT_EXT_PREC_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long double", objfile);
       break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_float_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_FLOAT);
       break;
     case FT_DBL_PREC_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "double complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
       break;
     case FT_EXT_PREC_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_long_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long double complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
@@ -402,32 +396,51 @@ static const struct op_print m2_op_print_tab[] =
 \f
 /* The built-in types of Modula-2.  */
 
-struct type *builtin_type_m2_char;
-struct type *builtin_type_m2_int;
-struct type *builtin_type_m2_card;
-struct type *builtin_type_m2_real;
-struct type *builtin_type_m2_bool;
+enum m2_primitive_types {
+  m2_primitive_type_char,
+  m2_primitive_type_int,
+  m2_primitive_type_card,
+  m2_primitive_type_real,
+  m2_primitive_type_bool,
+  nr_m2_primitive_types
+};
 
-struct type **CONST_PTR (m2_builtin_types[]) =
+static void
+m2_language_arch_info (struct gdbarch *gdbarch,
+                      struct language_arch_info *lai)
 {
-  &builtin_type_m2_char,
-    &builtin_type_m2_int,
-    &builtin_type_m2_card,
-    &builtin_type_m2_real,
-    &builtin_type_m2_bool,
-    0
-};
+  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+  lai->string_char_type = builtin->builtin_char;
+  lai->primitive_type_vector
+    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
+                              struct type *);
+
+  lai->primitive_type_vector [m2_primitive_type_char]
+    = builtin->builtin_char;
+  lai->primitive_type_vector [m2_primitive_type_int]
+    = builtin->builtin_int;
+  lai->primitive_type_vector [m2_primitive_type_card]
+    = builtin->builtin_card;
+  lai->primitive_type_vector [m2_primitive_type_real]
+    = builtin->builtin_real;
+  lai->primitive_type_vector [m2_primitive_type_bool]
+    = builtin->builtin_bool;
+}
 
 const struct language_defn m2_language_defn =
 {
   "modula-2",
   language_m2,
-  m2_builtin_types,
+  NULL,
   range_check_on,
   type_check_on,
+  case_sensitive_on,
+  array_row_major,
+  &exp_descriptor_standard,
   m2_parse,                    /* parser */
   m2_error,                    /* parser error function */
-  evaluate_subexp_standard,
+  null_post_parser,
   m2_printchar,                        /* Print character constant */
   m2_printstr,                 /* function to print string constant */
   m2_emit_char,                        /* Function to print a single character */
@@ -435,43 +448,71 @@ const struct language_defn m2_language_defn =
   m2_print_type,               /* Print a type using appropriate syntax */
   m2_val_print,                        /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
-  {"", "", "", ""},            /* Binary format info */
-  {"%loB", "", "o", "B"},      /* Octal format info */
-  {"%ld", "", "d", ""},                /* Decimal format info */
-  {"0%lXH", "0", "X", "H"},    /* Hex format info */
+  NULL,                                /* Language specific skip_trampoline */
+  value_of_this,               /* value_of_this */
+  basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
+  basic_lookup_transparent_type,/* lookup_transparent_type */
+  NULL,                                /* Language specific symbol demangler */
+  NULL,                                /* Language specific class_name_from_physname */
   m2_op_print_tab,             /* expression operators for printing */
   0,                           /* arrays are first-class (not c-style) */
   0,                           /* String lower bound */
-  &builtin_type_m2_char,       /* Type of string elements */
+  NULL,
+  default_word_break_characters,
+  m2_language_arch_info,
+  default_print_array_index,
   LANG_MAGIC
 };
 
-/* Initialization for Modula-2 */
-
-void
-_initialize_m2_language ()
+static void *
+build_m2_types (struct gdbarch *gdbarch)
 {
+  struct builtin_m2_type *builtin_m2_type
+    = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_m2_type);
+
   /* Modula-2 "pervasive" types.  NOTE:  these can be redefined!!! */
-  builtin_type_m2_int =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
-              0,
-              "INTEGER", (struct objfile *) NULL);
-  builtin_type_m2_card =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_int =
+    init_type (TYPE_CODE_INT, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
+              0, "INTEGER", (struct objfile *) NULL);
+  builtin_m2_type->builtin_card =
+    init_type (TYPE_CODE_INT, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "CARDINAL", (struct objfile *) NULL);
-  builtin_type_m2_real =
-    init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_real =
+    init_type (TYPE_CODE_FLT,
+              gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
               0,
               "REAL", (struct objfile *) NULL);
-  builtin_type_m2_char =
+  builtin_m2_type->builtin_char =
     init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "CHAR", (struct objfile *) NULL);
-  builtin_type_m2_bool =
-    init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_bool =
+    init_type (TYPE_CODE_BOOL, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "BOOLEAN", (struct objfile *) NULL);
 
+  return builtin_m2_type;
+}
+
+static struct gdbarch_data *m2_type_data;
+
+const struct builtin_m2_type *
+builtin_m2_type (struct gdbarch *gdbarch)
+{
+  return gdbarch_data (gdbarch, m2_type_data);
+}
+
+
+/* Initialization for Modula-2 */
+
+void
+_initialize_m2_language (void)
+{
+  m2_type_data = gdbarch_data_register_post_init (build_m2_types);
+
   add_language (&m2_language_defn);
 }
This page took 0.02772 seconds and 4 git commands to generate.