OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [jv-typeprint.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* Support for printing Java types for GDB, the GNU debugger.
/* Support for printing Java types for GDB, the GNU debugger.
   Copyright 1997-2000 Free Software Foundation, Inc.
   Copyright 1997-2000 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
 
 
#include "defs.h"
#include "defs.h"
#include "symtab.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "gdbtypes.h"
#include "value.h"
#include "value.h"
#include "demangle.h"
#include "demangle.h"
#include "jv-lang.h"
#include "jv-lang.h"
#include "gdb_string.h"
#include "gdb_string.h"
#include "typeprint.h"
#include "typeprint.h"
#include "c-lang.h"
#include "c-lang.h"
 
 
/* Local functions */
/* Local functions */
 
 
static void java_type_print_base (struct type * type,
static void java_type_print_base (struct type * type,
                                  struct ui_file *stream, int show,
                                  struct ui_file *stream, int show,
                                  int level);
                                  int level);
 
 
static void
static void
java_type_print_derivation_info (stream, type)
java_type_print_derivation_info (stream, type)
     struct ui_file *stream;
     struct ui_file *stream;
     struct type *type;
     struct type *type;
{
{
  char *name;
  char *name;
  int i;
  int i;
  int n_bases;
  int n_bases;
  int prev;
  int prev;
 
 
  n_bases = TYPE_N_BASECLASSES (type);
  n_bases = TYPE_N_BASECLASSES (type);
 
 
  for (i = 0, prev = 0; i < n_bases; i++)
  for (i = 0, prev = 0; i < n_bases; i++)
    {
    {
      int kind;
      int kind;
 
 
      kind = BASETYPE_VIA_VIRTUAL (type, i) ? 'I' : 'E';
      kind = BASETYPE_VIA_VIRTUAL (type, i) ? 'I' : 'E';
 
 
      fputs_filtered (kind == prev ? ", "
      fputs_filtered (kind == prev ? ", "
                      : kind == 'I' ? " implements "
                      : kind == 'I' ? " implements "
                      : " extends ",
                      : " extends ",
                      stream);
                      stream);
      prev = kind;
      prev = kind;
      name = type_name_no_tag (TYPE_BASECLASS (type, i));
      name = type_name_no_tag (TYPE_BASECLASS (type, i));
 
 
      fprintf_filtered (stream, "%s", name ? name : "(null)");
      fprintf_filtered (stream, "%s", name ? name : "(null)");
    }
    }
 
 
  if (i > 0)
  if (i > 0)
    fputs_filtered (" ", stream);
    fputs_filtered (" ", stream);
}
}
 
 
/* Print the name of the type (or the ultimate pointer target,
/* Print the name of the type (or the ultimate pointer target,
   function value or array element), or the description of a
   function value or array element), or the description of a
   structure or union.
   structure or union.
 
 
   SHOW positive means print details about the type (e.g. enum values),
   SHOW positive means print details about the type (e.g. enum values),
   and print structure elements passing SHOW - 1 for show.
   and print structure elements passing SHOW - 1 for show.
   SHOW negative means just print the type name or struct tag if there is one.
   SHOW negative means just print the type name or struct tag if there is one.
   If there is no name, print something sensible but concise like
   If there is no name, print something sensible but concise like
   "struct {...}".
   "struct {...}".
   SHOW zero means just print the type name or struct tag if there is one.
   SHOW zero means just print the type name or struct tag if there is one.
   If there is no name, print something sensible but not as concise like
   If there is no name, print something sensible but not as concise like
   "struct {int x; int y;}".
   "struct {int x; int y;}".
 
 
   LEVEL is the number of spaces to indent by.
   LEVEL is the number of spaces to indent by.
   We increase it for some recursive calls.  */
   We increase it for some recursive calls.  */
 
 
static void
static void
java_type_print_base (type, stream, show, level)
java_type_print_base (type, stream, show, level)
     struct type *type;
     struct type *type;
     struct ui_file *stream;
     struct ui_file *stream;
     int show;
     int show;
     int level;
     int level;
{
{
  register int i;
  register int i;
  register int len;
  register int len;
  char *mangled_name;
  char *mangled_name;
  char *demangled_name;
  char *demangled_name;
  QUIT;
  QUIT;
 
 
  wrap_here ("    ");
  wrap_here ("    ");
 
 
  if (type == NULL)
  if (type == NULL)
    {
    {
      fputs_filtered ("<type unknown>", stream);
      fputs_filtered ("<type unknown>", stream);
      return;
      return;
    }
    }
 
 
  /* When SHOW is zero or less, and there is a valid type name, then always
  /* When SHOW is zero or less, and there is a valid type name, then always
     just print the type name directly from the type.  */
     just print the type name directly from the type.  */
 
 
  if (show <= 0
  if (show <= 0
      && TYPE_NAME (type) != NULL)
      && TYPE_NAME (type) != NULL)
    {
    {
      fputs_filtered (TYPE_NAME (type), stream);
      fputs_filtered (TYPE_NAME (type), stream);
      return;
      return;
    }
    }
 
 
  CHECK_TYPEDEF (type);
  CHECK_TYPEDEF (type);
 
 
  switch (TYPE_CODE (type))
  switch (TYPE_CODE (type))
    {
    {
    case TYPE_CODE_PTR:
    case TYPE_CODE_PTR:
      java_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
      java_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
      break;
      break;
 
 
    case TYPE_CODE_STRUCT:
    case TYPE_CODE_STRUCT:
      if (TYPE_TAG_NAME (type) != NULL && TYPE_TAG_NAME (type)[0] == '[')
      if (TYPE_TAG_NAME (type) != NULL && TYPE_TAG_NAME (type)[0] == '[')
        {                       /* array type */
        {                       /* array type */
          char *name = java_demangle_type_signature (TYPE_TAG_NAME (type));
          char *name = java_demangle_type_signature (TYPE_TAG_NAME (type));
          fputs_filtered (name, stream);
          fputs_filtered (name, stream);
          free (name);
          free (name);
          break;
          break;
        }
        }
 
 
      if (show >= 0)
      if (show >= 0)
        fprintf_filtered (stream, "class ");
        fprintf_filtered (stream, "class ");
 
 
      if (TYPE_TAG_NAME (type) != NULL)
      if (TYPE_TAG_NAME (type) != NULL)
        {
        {
          fputs_filtered (TYPE_TAG_NAME (type), stream);
          fputs_filtered (TYPE_TAG_NAME (type), stream);
          if (show > 0)
          if (show > 0)
            fputs_filtered (" ", stream);
            fputs_filtered (" ", stream);
        }
        }
 
 
      wrap_here ("    ");
      wrap_here ("    ");
 
 
      if (show < 0)
      if (show < 0)
        {
        {
          /* If we just printed a tag name, no need to print anything else.  */
          /* If we just printed a tag name, no need to print anything else.  */
          if (TYPE_TAG_NAME (type) == NULL)
          if (TYPE_TAG_NAME (type) == NULL)
            fprintf_filtered (stream, "{...}");
            fprintf_filtered (stream, "{...}");
        }
        }
      else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
      else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
        {
        {
          java_type_print_derivation_info (stream, type);
          java_type_print_derivation_info (stream, type);
 
 
          fprintf_filtered (stream, "{\n");
          fprintf_filtered (stream, "{\n");
          if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
          if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
            {
            {
              if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
              if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
                fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
                fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
              else
              else
                fprintfi_filtered (level + 4, stream, "<no data fields>\n");
                fprintfi_filtered (level + 4, stream, "<no data fields>\n");
            }
            }
 
 
          /* If there is a base class for this type,
          /* If there is a base class for this type,
             do not print the field that it occupies.  */
             do not print the field that it occupies.  */
 
 
          len = TYPE_NFIELDS (type);
          len = TYPE_NFIELDS (type);
          for (i = TYPE_N_BASECLASSES (type); i < len; i++)
          for (i = TYPE_N_BASECLASSES (type); i < len; i++)
            {
            {
              QUIT;
              QUIT;
              /* Don't print out virtual function table.  */
              /* Don't print out virtual function table.  */
              if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
              if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
                  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
                  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
                continue;
                continue;
 
 
              /* Don't print the dummy field "class". */
              /* Don't print the dummy field "class". */
              if (STREQN (TYPE_FIELD_NAME (type, i), "class", 5))
              if (STREQN (TYPE_FIELD_NAME (type, i), "class", 5))
                continue;
                continue;
 
 
              print_spaces_filtered (level + 4, stream);
              print_spaces_filtered (level + 4, stream);
 
 
              if (HAVE_CPLUS_STRUCT (type))
              if (HAVE_CPLUS_STRUCT (type))
                {
                {
                  if (TYPE_FIELD_PROTECTED (type, i))
                  if (TYPE_FIELD_PROTECTED (type, i))
                    fprintf_filtered (stream, "protected ");
                    fprintf_filtered (stream, "protected ");
                  else if (TYPE_FIELD_PRIVATE (type, i))
                  else if (TYPE_FIELD_PRIVATE (type, i))
                    fprintf_filtered (stream, "private ");
                    fprintf_filtered (stream, "private ");
                  else
                  else
                    fprintf_filtered (stream, "public ");
                    fprintf_filtered (stream, "public ");
                }
                }
 
 
              if (TYPE_FIELD_STATIC (type, i))
              if (TYPE_FIELD_STATIC (type, i))
                fprintf_filtered (stream, "static ");
                fprintf_filtered (stream, "static ");
 
 
              java_print_type (TYPE_FIELD_TYPE (type, i),
              java_print_type (TYPE_FIELD_TYPE (type, i),
                               TYPE_FIELD_NAME (type, i),
                               TYPE_FIELD_NAME (type, i),
                               stream, show - 1, level + 4);
                               stream, show - 1, level + 4);
 
 
              fprintf_filtered (stream, ";\n");
              fprintf_filtered (stream, ";\n");
            }
            }
 
 
          /* If there are both fields and methods, put a space between. */
          /* If there are both fields and methods, put a space between. */
          len = TYPE_NFN_FIELDS (type);
          len = TYPE_NFN_FIELDS (type);
          if (len)
          if (len)
            fprintf_filtered (stream, "\n");
            fprintf_filtered (stream, "\n");
 
 
          /* Print out the methods */
          /* Print out the methods */
 
 
          for (i = 0; i < len; i++)
          for (i = 0; i < len; i++)
            {
            {
              struct fn_field *f;
              struct fn_field *f;
              int j;
              int j;
              char *method_name;
              char *method_name;
              char *name;
              char *name;
              int is_constructor;
              int is_constructor;
              int n_overloads;
              int n_overloads;
 
 
              f = TYPE_FN_FIELDLIST1 (type, i);
              f = TYPE_FN_FIELDLIST1 (type, i);
              n_overloads = TYPE_FN_FIELDLIST_LENGTH (type, i);
              n_overloads = TYPE_FN_FIELDLIST_LENGTH (type, i);
              method_name = TYPE_FN_FIELDLIST_NAME (type, i);
              method_name = TYPE_FN_FIELDLIST_NAME (type, i);
              name = type_name_no_tag (type);
              name = type_name_no_tag (type);
              is_constructor = name && STREQ (method_name, name);
              is_constructor = name && STREQ (method_name, name);
 
 
              for (j = 0; j < n_overloads; j++)
              for (j = 0; j < n_overloads; j++)
                {
                {
                  char *physname;
                  char *physname;
                  int is_full_physname_constructor;
                  int is_full_physname_constructor;
 
 
                  physname = TYPE_FN_FIELD_PHYSNAME (f, j);
                  physname = TYPE_FN_FIELD_PHYSNAME (f, j);
 
 
                  is_full_physname_constructor =
                  is_full_physname_constructor =
                    ((physname[0] == '_' && physname[1] == '_'
                    ((physname[0] == '_' && physname[1] == '_'
                      && strchr ("0123456789Qt", physname[2]))
                      && strchr ("0123456789Qt", physname[2]))
                     || STREQN (physname, "__ct__", 6)
                     || STREQN (physname, "__ct__", 6)
                     || DESTRUCTOR_PREFIX_P (physname)
                     || DESTRUCTOR_PREFIX_P (physname)
                     || STREQN (physname, "__dt__", 6));
                     || STREQN (physname, "__dt__", 6));
 
 
                  QUIT;
                  QUIT;
 
 
                  print_spaces_filtered (level + 4, stream);
                  print_spaces_filtered (level + 4, stream);
 
 
                  if (TYPE_FN_FIELD_PROTECTED (f, j))
                  if (TYPE_FN_FIELD_PROTECTED (f, j))
                    fprintf_filtered (stream, "protected ");
                    fprintf_filtered (stream, "protected ");
                  else if (TYPE_FN_FIELD_PRIVATE (f, j))
                  else if (TYPE_FN_FIELD_PRIVATE (f, j))
                    fprintf_filtered (stream, "private ");
                    fprintf_filtered (stream, "private ");
                  else if (TYPE_FN_FIELD_PUBLIC (f, j))
                  else if (TYPE_FN_FIELD_PUBLIC (f, j))
                    fprintf_filtered (stream, "public ");
                    fprintf_filtered (stream, "public ");
 
 
                  if (TYPE_FN_FIELD_ABSTRACT (f, j))
                  if (TYPE_FN_FIELD_ABSTRACT (f, j))
                    fprintf_filtered (stream, "abstract ");
                    fprintf_filtered (stream, "abstract ");
                  if (TYPE_FN_FIELD_STATIC (f, j))
                  if (TYPE_FN_FIELD_STATIC (f, j))
                    fprintf_filtered (stream, "static ");
                    fprintf_filtered (stream, "static ");
                  if (TYPE_FN_FIELD_FINAL (f, j))
                  if (TYPE_FN_FIELD_FINAL (f, j))
                    fprintf_filtered (stream, "final ");
                    fprintf_filtered (stream, "final ");
                  if (TYPE_FN_FIELD_SYNCHRONIZED (f, j))
                  if (TYPE_FN_FIELD_SYNCHRONIZED (f, j))
                    fprintf_filtered (stream, "synchronized ");
                    fprintf_filtered (stream, "synchronized ");
                  if (TYPE_FN_FIELD_NATIVE (f, j))
                  if (TYPE_FN_FIELD_NATIVE (f, j))
                    fprintf_filtered (stream, "native ");
                    fprintf_filtered (stream, "native ");
 
 
                  if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
                  if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
                    {
                    {
                      /* Keep GDB from crashing here.  */
                      /* Keep GDB from crashing here.  */
                      fprintf_filtered (stream, "<undefined type> %s;\n",
                      fprintf_filtered (stream, "<undefined type> %s;\n",
                                        TYPE_FN_FIELD_PHYSNAME (f, j));
                                        TYPE_FN_FIELD_PHYSNAME (f, j));
                      break;
                      break;
                    }
                    }
                  else if (!is_constructor && !is_full_physname_constructor)
                  else if (!is_constructor && !is_full_physname_constructor)
                    {
                    {
                      type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
                      type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
                                  "", stream, -1);
                                  "", stream, -1);
                      fputs_filtered (" ", stream);
                      fputs_filtered (" ", stream);
                    }
                    }
 
 
                  if (TYPE_FN_FIELD_STUB (f, j))
                  if (TYPE_FN_FIELD_STUB (f, j))
                    /* Build something we can demangle.  */
                    /* Build something we can demangle.  */
                    mangled_name = gdb_mangle_name (type, i, j);
                    mangled_name = gdb_mangle_name (type, i, j);
                  else
                  else
                    mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
                    mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
 
 
                  demangled_name =
                  demangled_name =
                    cplus_demangle (mangled_name,
                    cplus_demangle (mangled_name,
                                    DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
                                    DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
 
 
                  if (demangled_name == NULL)
                  if (demangled_name == NULL)
                    demangled_name = xstrdup (mangled_name);
                    demangled_name = xstrdup (mangled_name);
 
 
                  {
                  {
                    char *demangled_no_class;
                    char *demangled_no_class;
                    char *ptr;
                    char *ptr;
 
 
                    ptr = demangled_no_class = demangled_name;
                    ptr = demangled_no_class = demangled_name;
 
 
                    while (1)
                    while (1)
                      {
                      {
                        char c;
                        char c;
 
 
                        c = *ptr++;
                        c = *ptr++;
 
 
                        if (c == 0 || c == '(')
                        if (c == 0 || c == '(')
                          break;
                          break;
                        if (c == '.')
                        if (c == '.')
                          demangled_no_class = ptr;
                          demangled_no_class = ptr;
                      }
                      }
 
 
                    fputs_filtered (demangled_no_class, stream);
                    fputs_filtered (demangled_no_class, stream);
                    free (demangled_name);
                    free (demangled_name);
                  }
                  }
 
 
                  if (TYPE_FN_FIELD_STUB (f, j))
                  if (TYPE_FN_FIELD_STUB (f, j))
                    free (mangled_name);
                    free (mangled_name);
 
 
                  fprintf_filtered (stream, ";\n");
                  fprintf_filtered (stream, ";\n");
                }
                }
            }
            }
 
 
          fprintfi_filtered (level, stream, "}");
          fprintfi_filtered (level, stream, "}");
        }
        }
      break;
      break;
 
 
    default:
    default:
      c_type_print_base (type, stream, show, level);
      c_type_print_base (type, stream, show, level);
    }
    }
}
}
 
 
/* LEVEL is the depth to indent lines by.  */
/* LEVEL is the depth to indent lines by.  */
 
 
extern void c_type_print_varspec_suffix (struct type *, struct ui_file *,
extern void c_type_print_varspec_suffix (struct type *, struct ui_file *,
                                         int, int, int);
                                         int, int, int);
 
 
void
void
java_print_type (type, varstring, stream, show, level)
java_print_type (type, varstring, stream, show, level)
     struct type *type;
     struct type *type;
     char *varstring;
     char *varstring;
     struct ui_file *stream;
     struct ui_file *stream;
     int show;
     int show;
     int level;
     int level;
{
{
  int demangled_args;
  int demangled_args;
 
 
  java_type_print_base (type, stream, show, level);
  java_type_print_base (type, stream, show, level);
 
 
  if (varstring != NULL && *varstring != '\0')
  if (varstring != NULL && *varstring != '\0')
    {
    {
      fputs_filtered (" ", stream);
      fputs_filtered (" ", stream);
      fputs_filtered (varstring, stream);
      fputs_filtered (varstring, stream);
    }
    }
 
 
  /* For demangled function names, we have the arglist as part of the name,
  /* For demangled function names, we have the arglist as part of the name,
     so don't print an additional pair of ()'s */
     so don't print an additional pair of ()'s */
 
 
  demangled_args = strchr (varstring, '(') != NULL;
  demangled_args = strchr (varstring, '(') != NULL;
  c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
  c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.