OSDN Git Service

* c-format.c (maybe_read_dollar_number): Use safe-ctype macros
[pf3gnuchains/gcc-fork.git] / gcc / cp / xref.c
index 8a5551c..dd884db 100644 (file)
@@ -1,5 +1,6 @@
 /* Code for handling XREF output from GNU C++.
-   Copyright (C) 1992, 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   2000 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GNU CC.
@@ -25,8 +26,7 @@ Boston, MA 02111-1307, USA.  */
 #include "tree.h"
 #include "cp-tree.h"
 #include "input.h"
-
-extern char *getpwd PROTO((void));
+#include "toplev.h"
 
 /* The character(s) used to join a directory specification (obtained with
    getwd or equivalent) with a non-absolute file name.  */
@@ -57,13 +57,11 @@ int flag_gnu_xref;
 #define FALSE 0
 #endif
 
-#define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
+#define PALLOC(typ) ((typ *) xcalloc(1,sizeof(typ)))
 
 
 /* Return a malloc'd copy of STR.  */
-#define SALLOC(str) \
- ((char *) ((str) == NULL ? NULL       \
-           : (char *) strcpy ((char *) malloc (strlen ((str)) + 1), (str))))
+#define SALLOC(str) ((char *) ((str) == NULL ? NULL : xstrdup (str)))
 #define SFREE(str) (str != NULL && (free(str),0))
 
 #define STREQL(s1,s2) (strcmp((s1),(s2)) == 0)
@@ -85,8 +83,8 @@ typedef struct _XREF_SCOPE *  XREF_SCOPE;
 
 typedef struct _XREF_FILE
 {
-  char *name;
-  char *outname;
+  const char *name;
+  const char *outname;
   XREF_FILE next;
 } XREF_FILE_INFO;
 
@@ -120,20 +118,21 @@ static    tree            last_fndecl = NULL;
 /*     Forward definitions                                             */
 /*                                                                     */
 /************************************************************************/
-static void            gen_assign PROTO((XREF_FILE, tree));
-static XREF_FILE       find_file PROTO((char *));
-static char *          filename PROTO((XREF_FILE));
-static char *          fctname PROTO((tree));
-static char *          declname PROTO((tree));
-static void            simplify_type PROTO((char *));
-static char *          fixname PROTO((char *, char *));
-static void            open_xref_file PROTO((char *));
+static void            gen_assign PARAMS ((XREF_FILE, tree));
+static XREF_FILE       find_file PARAMS ((const char *));
+static const char *    filename PARAMS ((XREF_FILE));
+static const char *    fctname PARAMS ((tree));
+static const char *    declname PARAMS ((tree));
+static void            simplify_type PARAMS ((char *));
+static const char *    fixname PARAMS ((const char *, char *));
+static void            open_xref_file PARAMS ((const char *));
+static  const char *   classname PARAMS ((tree));
 
 /* Start cross referencing.  FILE is the name of the file we xref.  */
 
 void
 GNU_xref_begin (file)
-   char *file;
+   const char *file;
 {
   doing_xref = 1;
 
@@ -177,7 +176,7 @@ GNU_xref_end (ect)
 
 void
 GNU_xref_file (name)
-   char *name;
+   const char *name;
 {
   XREF_FILE xf;
 
@@ -206,14 +205,7 @@ GNU_xref_file (name)
   if (FILE_NAME_ABSOLUTE_P (name) || ! wd_name)
     xf->outname = xf->name;
   else
-    {
-      char *nmbuf
-       = (char *) malloc (strlen (wd_name) + strlen (FILE_NAME_JOINER)
-                          + strlen (name) + 1);
-      sprintf (nmbuf, "%s%s%s", wd_name, FILE_NAME_JOINER, name);
-      name = nmbuf;
-      xf->outname = nmbuf;
-    }
+    xf->outname = name = concat (wd_name, FILE_NAME_JOINER, name, NULL);
 
   fprintf (xref_file, "FIL %s %s 0\n", name, wd_name);
 
@@ -258,7 +250,7 @@ GNU_xref_end_scope (id,inid,prm,keep)
 {
   XREF_FILE xf;
   XREF_SCOPE xs,lxs,oxs;
-  char *stype;
+  const char *stype;
 
   if (!doing_xref) return;
   xf = find_file (input_filename);
@@ -285,8 +277,10 @@ GNU_xref_end_scope (id,inid,prm,keep)
   else if (keep == 2 || inid != 0) stype = "INTERN";
   else stype = "EXTERN";
 
-  fprintf (xref_file,"SCP %s %d %d %d %d %s\n",
-          filename (xf), xs->start, lineno,xs->lid, inid, stype);
+  fprintf (xref_file, "SCP %s %d %d %d ",
+          filename (xf), xs->start, lineno,xs->lid);
+  fprintf (xref_file, HOST_WIDE_INT_PRINT_DEC, inid);
+  fprintf (xref_file, " %s\n", stype);
 
   if (lxs == NULL) cur_scope = xs->outer;
   else lxs->outer = xs->outer;
@@ -299,7 +293,7 @@ GNU_xref_end_scope (id,inid,prm,keep)
 void
 GNU_xref_ref (fndecl,name)
    tree fndecl;
-   char *name;
+   const char *name;
 {
   XREF_FILE xf;
 
@@ -319,8 +313,8 @@ GNU_xref_decl (fndecl,decl)
    tree decl;
 {
   XREF_FILE xf,xf1;
-  char *cls = 0;
-  char *name;
+  const char *cls = 0;
+  const char *name;
   char buf[10240];
   int uselin;
 
@@ -363,7 +357,6 @@ GNU_xref_decl (fndecl,decl)
   else if (TREE_CODE (decl) == RECORD_TYPE)
     {
       if (CLASSTYPE_DECLARED_CLASS (decl)) cls = "CLASSID";
-      else if (IS_SIGNATURE (decl)) cls = "SIGNATUREID";
       else cls = "STRUCTID";
       decl = TYPE_NAME (decl);
       uselin = TRUE;
@@ -413,8 +406,7 @@ GNU_xref_decl (fndecl,decl)
           (cur_scope != NULL ? cur_scope->lid : 0),
           cls, fctname(fndecl), buf);
 
-  if (STREQL (cls, "STRUCTID") || STREQL (cls, "UNIONID")
-      || STREQL (cls, "SIGNATUREID"))
+  if (STREQL (cls, "STRUCTID") || STREQL (cls, "UNIONID"))
     {
       cls = "CLASSID";
       fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n",
@@ -429,11 +421,11 @@ GNU_xref_decl (fndecl,decl)
 void
 GNU_xref_call (fndecl, name)
    tree fndecl;
-   char *name;
+   const char *name;
 {
   XREF_FILE xf;
   char buf[1024];
-  char *s;
+  const char *s;
 
   if (!doing_xref) return;
   xf = find_file (input_filename);
@@ -505,7 +497,7 @@ gen_assign(xf, name)
    XREF_FILE xf;
    tree name;
 {
-  char *s;
+  const char *s;
 
   s = NULL;
 
@@ -538,6 +530,19 @@ gen_assign(xf, name)
     fprintf(xref_file, "ASG %s %d %s\n", filename(xf), lineno, s);
 }
 
+static const char *
+classname (cls)
+     tree cls;
+{
+  if (cls && TYPE_P (cls))
+    cls = TYPE_NAME (cls);
+  if (cls && DECL_P (cls))
+    cls = DECL_NAME (cls);
+  if (cls && TREE_CODE (cls) == IDENTIFIER_NODE)
+    return IDENTIFIER_POINTER (cls);
+  return "?";
+}
+
 /* Output cross-reference info about a class hierarchy.
    CLS is the class type of interest.  BASE is a baseclass
    for CLS.  PUB and VIRT give the access info about
@@ -548,8 +553,8 @@ gen_assign(xf, name)
 
 void
 GNU_xref_hier(cls, base, pub, virt, frnd)
-   char *cls;
-   char *base;
+   tree cls;
+   tree base;
    int pub;
    int virt;
    int frnd;
@@ -561,7 +566,8 @@ GNU_xref_hier(cls, base, pub, virt, frnd)
   if (xf == NULL) return;
 
   fprintf(xref_file, "HIE %s %d %s %s %d %d %d\n",
-         filename(xf), lineno, cls, base, pub, virt, frnd);
+         filename(xf), lineno, classname (cls), classname (base), 
+         pub, virt, frnd);
 }
 
 /* Output cross-reference info about class members.  CLS
@@ -573,9 +579,9 @@ GNU_xref_member(cls, fld)
    tree fld;
 {
   XREF_FILE xf;
-  char *prot;
+  const char *prot;
   int confg, pure;
-  char *d;
+  const char *d;
 #ifdef XREF_SHORT_MEMBER_NAMES
   int i;
 #endif
@@ -596,11 +602,11 @@ GNU_xref_member(cls, fld)
     confg = 1;
 
   pure = 0;
-  if (TREE_CODE (fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld))
+  if (TREE_CODE (fld) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P(fld))
     pure = 1;
 
   d = IDENTIFIER_POINTER(cls);
-  sprintf(buf, "%d%s", strlen(d), d);
+  sprintf(buf, "%d%s", (int) strlen(d), d);
 #ifdef XREF_SHORT_MEMBER_NAMES
   i = strlen(buf);
 #endif
@@ -609,11 +615,11 @@ GNU_xref_member(cls, fld)
 #ifdef XREF_SHORT_MEMBER_NAMES
   for (p = &bufa[1]; *p != 0; ++p)
     {
-      if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') {
+      if (p[0] == '_' && p[1] == '_' && ISDIGIT (p[2])) {
        if (strncmp(&p[2], buf, i) == 0) *p = 0;
        break;
       }
-      else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') {
+      else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && ISDIGIT (p[3])) {
        if (strncmp(&p[3], buf, i) == 0) *p = 0;
        break;
       }
@@ -634,7 +640,7 @@ GNU_xref_member(cls, fld)
 
 static XREF_FILE
 find_file(name)
-   char *name;
+   const char *name;
 {
   XREF_FILE xf;
 
@@ -647,7 +653,7 @@ find_file(name)
 
 /* Return filename for output purposes.  */
 
-static char *
+static const char *
 filename(xf)
    XREF_FILE xf;
 {
@@ -665,12 +671,12 @@ filename(xf)
 
 /* Return function name for output purposes.  */
 
-static char *
+static const char *
 fctname(fndecl)
    tree fndecl;
 {
   static char fctbuf[1024];
-  char *s;
+  const char *s;
 
   if (fndecl == NULL && last_fndecl == NULL) return "*";
 
@@ -692,7 +698,7 @@ fctname(fndecl)
 
 /* Return decl name for output purposes.  */
 
-static char *
+static const char *
 declname(dcl)
    tree dcl;
 {
@@ -714,7 +720,7 @@ simplify_type(typ)
   int lvl, i;
 
   i = strlen(typ);
-  while (i > 0 && isspace(typ[i-1])) typ[--i] = 0;
+  while (i > 0 && ISSPACE((unsigned char) typ[i-1])) typ[--i] = 0;
 
   if (i > 7 && STREQL(&typ[i-5], "const"))
     {
@@ -756,12 +762,13 @@ simplify_type(typ)
 
 /* Fixup a function name (take care of embedded spaces).  */
 
-static char *
+static const char *
 fixname(nam, buf)
-   char *nam;
+   const char *nam;
    char *buf;
 {
-  char *s, *t;
+  const char *s;
+  char *t;
   int fg;
 
   s = nam;
@@ -789,21 +796,22 @@ fixname(nam, buf)
 
 static void
 open_xref_file(file)
-   char *file;
+   const char *file;
 {
-  char *s, *t;
+  const char *s;
+  char *t;
 
 #ifdef XREF_FILE_NAME
   XREF_FILE_NAME (xref_name, file);
 #else
-  s = rindex (file, '/');
+  s = strrchr (file, '/');
   if (s == NULL)
     sprintf (xref_name, ".%s.gxref", file);
   else
     {
       ++s;
       strcpy (xref_name, file);
-      t = rindex (xref_name, '/');
+      t = strrchr (xref_name, '/');
       ++t;
       *t++ = '.';
       strcpy (t, s);