home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gcc-2.3.3-src.lha
/
GNU
/
src
/
amiga
/
gcc-2.3.3
/
cp-xref.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-06
|
18KB
|
831 lines
/* Code for handling XREF output from GNU C++.
Copyright (C) 1992 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "config.h"
#include "tree.h"
#include <stdio.h>
#include "cp-tree.h"
#include "input.h"
#include <ctype.h>
char *getpwd ();
extern char *index ();
extern char *rindex ();
/* The character(s) used to join a directory specification (obtained with
getwd or equivalent) with a non-absolute file name. */
#ifndef FILE_NAME_JOINER
#define FILE_NAME_JOINER "/"
#endif
/* Nonzero if NAME as a file name is absolute. */
#ifndef FILE_NAME_ABSOLUTE_P
#define FILE_NAME_ABSOLUTE_P(NAME) (NAME[0] == '/')
#endif
/* For cross referencing. */
int flag_gnu_xref;
/************************************************************************/
/* */
/* Common definitions */
/* */
/************************************************************************/
typedef int Integer;
typedef char * String;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
#define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
/* Return a malloc'd copy of STR. */
#define SALLOC(str) \
((String) ((str) == NULL ? NULL \
: strcpy ((String) malloc (strlen ((str)) + 1), (str))))
#define SFREE(str) (str != NULL && (free(str),0))
#define STREQL(s1,s2) (strcmp((s1),(s2)) == 0)
#define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0)
#define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0)
#define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0)
#define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0)
#define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0)
/************************************************************************/
/* */
/* Type definitions */
/* */
/************************************************************************/
typedef struct _XREF_FILE * XREF_FILE;
typedef struct _XREF_SCOPE * XREF_SCOPE;
typedef struct _XREF_FILE
{
String name;
String outname;
XREF_FILE next;
} XREF_FILE_INFO;
typedef struct _XREF_SCOPE
{
Integer gid;
Integer lid;
XREF_FILE file;
Integer start;
XREF_SCOPE outer;
} XREF_SCOPE_INFO;
/************************************************************************/
/* */
/* Local storage */
/* */
/************************************************************************/
static char doing_xref = 0;
static FILE * xref_file = NULL;
static char xref_name[1024];
static XREF_FILE all_files = NULL;
static String wd_name = NULL;
static XREF_SCOPE cur_scope = NULL;
static Integer scope_ctr = 0;
static XREF_FILE last_file = NULL;
static tree last_fndecl = NULL;
/************************************************************************/
/* */
/* Forward definitions */
/* */
/************************************************************************/
extern void GNU_xref_begin();
extern void GNU_xref_end();
extern void GNU_xref_file();
extern void GNU_xref_start_scope();
extern void GNU_xref_end_scope();
extern void GNU_xref_ref();
extern void GNU_xref_decl();
extern void GNU_xref_call();
extern void GNU_xref_function();
extern void GNU_xref_assign();
extern void GNU_xref_hier();
extern void GNU_xref_member();
static void gen_assign();
static XREF_FILE find_file();
static String filename();
static String fctname();
static String declname();
static void simplify_type();
static String fixname();
static void open_xref_file();
extern char * type_as_string();
/* Start cross referencing. FILE is the name of the file we xref. */
void
GNU_xref_begin (file)
String file;
{
doing_xref = 1;
if (file != NULL && STRNEQ (file,"-"))
{
open_xref_file(file);
GNU_xref_file(file);
}
}
/* Finish cross-referencing. ERRCNT is the number of errors
we encountered. */
void
GNU_xref_end (ect)
int ect;
{
XREF_FILE xf;
if (!doing_xref) return;
xf = find_file (input_filename);
if (xf == NULL) return;
while (cur_scope != NULL)
GNU_xref_end_scope(cur_scope->gid,0,0,0,0);
doing_xref = 0;
if (xref_file == NULL) return;
fclose (xref_file);
xref_file = NULL;
all_files = NULL;
if (ect > 0) unlink (xref_name);
}
/* Write out xref for file named NAME. */
void
GNU_xref_file (name)
String name;
{
XREF_FILE xf;
if (!doing_xref || name == NULL) return;
if (xref_file == NULL)
{
open_xref_file (name);
if (!doing_xref) return;
}
if (all_files == NULL)
fprintf(xref_file,"SCP * 0 0 0 0 RESET\n");
xf = find_file (name);
if (xf != NULL) return;
xf = PALLOC (XREF_FILE_INFO);
xf->name = SALLOC (name);
xf->next = all_files;
all_files = xf;
if (wd_name == NULL)
wd_name = getpwd ();
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;
}
fprintf (xref_file, "FIL %s %s 0\n", name, wd_name);
filename (xf);
fctname (NULL);
}
/* Start a scope identified at level ID. */
void
GNU_xref_start_scope (id)
Integer id;
{
XREF_SCOPE xs;
XREF_FILE xf;
if (!doing_xref) return;
xf = find_file (input_filename);
xs = PALLOC (XREF_SCOPE_INFO);
xs->file = xf;
xs->start = lineno;
if (xs->start <= 0) xs->start = 1;
xs->gid = id;
xs->lid = ++scope_ctr;
xs->outer = cur_scope;
cur_scope = xs;
}
/* Finish a scope at level ID.
INID is ???
PRM is ???
KEEP is nonzero iff this scope is retained (nonzero if it's
a compiler-generated invisible scope).
TRNS is ??? */
void
GNU_xref_end_scope (id,inid,prm,keep,trns)
Integer id;
Integer inid;
Integer prm,keep,trns;
{
XREF_FILE xf;
XREF_SCOPE xs,lxs,oxs;
String stype;
if (!doing_xref) return;
xf = find_file (input_filename);
if (xf == NULL) return;
lxs = NULL;
for (xs = cur_scope; xs != NULL; xs = xs->outer)
{
if (xs->gid == id) break;
lxs = xs;
}
if (xs == NULL) return;
if (inid != 0) {
for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) {
if (oxs->gid == inid) break;
}
if (oxs == NULL) return;
inid = oxs->lid;
}
if (prm == 2) stype = "SUE";
else if (prm != 0) stype = "ARGS";
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);
if (lxs == NULL) cur_scope = xs->outer;
else lxs->outer = xs->outer;
free (xs);
}
/* Output a reference to NAME in FNDECL. */
void
GNU_xref_ref (fndecl,name)
tree fndecl;
String name;
{
XREF_FILE xf;
if (!doing_xref) return;
xf = find_file (input_filename);
if (xf == NULL) return;
fprintf (xref_file, "REF %s %d %s %s\n",
filename (xf), lineno, fctname (fndecl), name);
}
/* Output a reference to DECL in FNDECL. */
void
GNU_xref_decl (fndecl,decl)
tree fndecl;
tree decl;
{
XREF_FILE xf,xf1;
String cls;
String name;
char buf[10240];
Integer uselin;
if (!doing_xref) return;
xf = find_file (input_filename);
if (xf == NULL) return;
uselin = FALSE;
if (TREE_CODE (decl) == TYPE_DECL) cls = "TYPEDEF";
else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD";
else if (TREE_CODE (decl) == VAR_DECL)
{
if (fndecl == NULL && TREE_STATIC(decl)
&& TREE_READONLY(decl) && DECL_IN