/************************************************************************/
/* Code for handling XREF output from g++ */
/************************************************************************/
/************************************************************************/
/************************************************************************/
#define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
#define SALLOC(str) ((String) ((str == NULL) ? NULL : (strcpy(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)
/************************************************************************/
/************************************************************************/
typedef struct _XREF_FILE
* XREF_FILE
;
typedef struct _XREF_SCOPE
* XREF_SCOPE
;
typedef struct _XREF_FILE
{
typedef struct _XREF_SCOPE
{
/************************************************************************/
/************************************************************************/
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_fct
= NULL
;
/************************************************************************/
/* Forward definitions */
/************************************************************************/
extern void FIELD_xref_begin();
extern void FIELD_xref_end();
extern void FIELD_xref_file();
extern void FIELD_xref_start_scope();
extern void FIELD_xref_end_scope();
extern void FIELD_xref_ref();
extern void FIELD_xref_decl();
extern void FIELD_xref_call();
extern void FIELD_xref_function();
extern void FIELD_xref_assign();
extern void FIELD_xref_hier();
extern void FIELD_xref_member();
static void gen_assign();
static XREF_FILE
find_file();
static String
filename();
static String
declname();
static void simplify_type();
static void open_xref_file();
extern char * type_as_string();
/************************************************************************/
/* FIELD_xref_begin -- start cross referencing */
/************************************************************************/
if (file
!= NULL
&& STRNEQ(file
,"-")) {
/************************************************************************/
/* FIELD_xref_end -- finish cross referencing */
/************************************************************************/
xf
= find_file(input_filename
);
while (cur_scope
!= NULL
) {
FIELD_xref_end_scope(cur_scope
->gid
,0,0,0,0);
if (xref_file
== NULL
) return;
if (ect
> 0) unlink(xref_name
);
/************************************************************************/
/* FIELD_xref_file -- handle file xrefing */
/************************************************************************/
if (!doing_xref
|| name
== NULL
) return;
fprintf(xref_file
,"SCP * 0 0 0 0 RESET\n");
xf
= PALLOC(XREF_FILE_INFO
);
fprintf(xref_file
,"FIL %s %s 0\n",name
,wd_name
);
/************************************************************************/
/* FIELD_xref_start_scope -- begin a scope */
/* FIELD_xref_end_scope -- finish a scope */
/************************************************************************/
FIELD_xref_start_scope(id
)
xf
= find_file(input_filename
);
xs
= PALLOC(XREF_SCOPE_INFO
);
if (xs
->start
<= 0) xs
->start
= 1;
FIELD_xref_end_scope(id
,inid
,prm
,keep
,trns
)
xf
= find_file(input_filename
);
for (xs
= cur_scope
; xs
!= NULL
; xs
= xs
->outer
) {
if (xs
->gid
== id
) break;
for (oxs
= cur_scope
; oxs
!= NULL
; oxs
= oxs
->outer
) {
if (oxs
->gid
== inid
) break;
if (prm
== 2) stype
= "SUE";
else if (prm
!= 0) stype
= "ARGS";
else if (keep
== 2 || inid
!= 0) stype
= "INTERN";
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
;
/************************************************************************/
/* FIELD_xref_ref -- handle reference */
/************************************************************************/
xf
= find_file(input_filename
);
fprintf(xref_file
,"REF %s %d %s %s\n",
filename(xf
),lineno
,fctname(fct
),name
);
/************************************************************************/
/* FIELD_xref_decl -- handle declaration */
/************************************************************************/
FIELD_xref_decl(fct
,decl
)
xf
= find_file(input_filename
);
if (DECL_NAME(decl
) == NULL
) return;
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 (fct
== NULL
&& TREE_STATIC(decl
) &&
TREE_READONLY(decl
) && DECL_INITIAL(decl
) != 0 &&
!TREE_PUBLIC(decl
) && !TREE_EXTERNAL(decl
) &&
DECL_MODE(decl
) != BLKmode
) cls
= "CONST";
else if (TREE_EXTERNAL(decl
)) cls
= "EXTERN";
else if (TREE_PUBLIC(decl
)) cls
= "EXTDEF";
else if (TREE_STATIC(decl
)) cls
= "STATIC";
else if (TREE_REGDECL(decl
)) cls
= "REGISTER";
else if (TREE_CODE(decl
) == PARM_DECL
) cls
= "PARAM";
else if (TREE_CODE(decl
) == FIELD_DECL
) cls
= "FIELD";
else if (TREE_CODE(decl
) == CONST_DECL
) cls
= "CONST";
else if (TREE_CODE(decl
) == FUNCTION_DECL
) {
if (TREE_EXTERNAL(decl
)) cls
= "EXTERN";
else if (TREE_PUBLIC(decl
)) cls
= "EFUNCTION";
else if (TREE_CODE(decl
) == LABEL_DECL
) cls
= "LABEL";
else if (TREE_CODE(decl
) == UNION_TYPE
) {
else if (TREE_CODE(decl
) == RECORD_TYPE
) {
if (CLASSTYPE_DECLARED_CLASS(decl
)) cls
= "CLASSID";
else if (TREE_CODE(decl
) == ENUMERAL_TYPE
) {
name
= IDENTIFIER_POINTER(DECL_NAME(decl
));
type_as_string(buf
,TREE_TYPE(decl
));
fprintf(xref_file
,"DCL %s %d %s %d %s %s %s\n",
filename(xf
),lineno
,name
,
(cur_scope
!= NULL
? cur_scope
->lid
: 0),
/************************************************************************/
/* FIELD_xref_call -- handle call */
/************************************************************************/
FIELD_xref_call(fct
,name
)
xf
= find_file(input_filename
);
name
= fixname(name
,buf
);
fprintf(xref_file
,"CAL %s %d %s %s\n",
filename(xf
),lineno
,name
,fctname(fct
));
/************************************************************************/
/* FIELD_xref_function -- handle functions */
/************************************************************************/
FIELD_xref_function(fct
,args
)
xf
= find_file(input_filename
);
if (args
== NULL
) args
= DECL_ARGUMENTS(fct
);
FIELD_xref_decl(NULL
,fct
);
for ( ; args
!= NULL
; args
= TREE_CHAIN(args
)) {
FIELD_xref_decl(fct
,args
);
if (ct
!= 0) strcat(buf
,",");
strcat(buf
,declname(args
));
fprintf(xref_file
,"PRC %s %d %s %d %d %s\n",
filename(xf
),lineno
,declname(fct
),
(cur_scope
!= NULL
? cur_scope
->lid
: 0),
/************************************************************************/
/* FIELD_xref_assign -- handle assignment */
/************************************************************************/
xf
= find_file(input_filename
);
switch (TREE_CODE(name
)) {
s
= IDENTIFIER_POINTER(name
);
gen_assign(xf
,TREE_OPERAND(name
,0));
gen_assign(xf
,TREE_OPERAND(name
,1));
gen_assign(xf
,TREE_OPERAND(name
,0));
gen_assign(xf
,TREE_OPERAND(name
,1));
fprintf(xref_file
,"ASG %s %d %s\n",filename(xf
),lineno
,s
);
/************************************************************************/
/* FIELD_xref_hier -- handle hierarchy */
/************************************************************************/
FIELD_xref_hier(cls
,base
,pub
,virt
,frnd
)
xf
= find_file(input_filename
);
fprintf(xref_file
,"HIE %s %d %s %s %d %d %d\n",
filename(xf
),lineno
,cls
,base
,pub
,virt
,frnd
);
/************************************************************************/
/* FIELD_xref_member -- handle member */
/************************************************************************/
FIELD_xref_member(cls
,fld
)
char buf
[1024],bufa
[1024];
xf
= find_file(fld
->decl
.filename
);
if (TREE_PRIVATE(fld
)) prot
= "PRIVATE";
else if (TREE_PROTECTED(fld
)) prot
= "PROTECTED";
if (TREE_CODE(fld
) == FUNCTION_DECL
&& DECL_CONST_MEMFUNC_P(fld
)) confg
= 1;
else if (TREE_CODE(fld
) == CONST_DECL
) confg
= 1;
if (TREE_CODE(fld
) == FUNCTION_DECL
&& DECL_ABSTRACT_VIRTUAL_P(fld
)) pure
= 1;
d
= IDENTIFIER_POINTER(cls
);
sprintf(buf
,"%d%s",strlen(d
),d
);
strcpy(bufa
,declname(fld
));
for (p
= &bufa
[1]; *p
!= 0; ++p
) {
if (p
[0] == '_' && p
[1] == '_' && p
[2] >= '0' && p
[2] <= '9') {
if (strncmp(&p
[2],buf
,i
) == 0) *p
= 0;
else if (p
[0] == '_' && p
[1] == '_' && p
[2] == 'C' && p
[3] >= '0' && p
[3] <= '9') {
if (strncmp(&p
[3],buf
,i
) == 0) *p
= 0;
fprintf(xref_file
,"MEM %s %d %s %s %s %d %d %d %d %d %d %d\n",
filename(xf
),fld
->decl
.linenum
,d
,
(TREE_CODE(fld
) == FUNCTION_DECL
? 0 : 1),
(TREE_INLINE(fld
) ? 1 : 0),
(DECL_FRIEND_P(fld
) ? 1 : 0),
(DECL_VIRTUAL_P(fld
) ? 1 : 0),
(TREE_STATIC(fld
) ? 1 : 0),
/************************************************************************/
/* find_file -- find file entry given name */
/************************************************************************/
for (xf
= all_files
; xf
!= NULL
; xf
= xf
->next
) {
if (STREQL(name
,xf
->name
)) break;
/************************************************************************/
/* filename -- return name for output */
/************************************************************************/
if (last_file
== xf
) return "*";
/************************************************************************/
/* fctname -- return name for function */
/************************************************************************/
extern char * declname();
static char fctbuf
[1024];
if (fct
== NULL
&& last_fct
== NULL
) return "*";
if (fct
== last_fct
) return "*";
/************************************************************************/
/* declname -- print name for declaration */
/************************************************************************/
if (DECL_NAME(dcl
) == NULL
) return "?";
return IDENTIFIER_POINTER (DECL_NAME (dcl
));
/************************************************************************/
/* simplify_type -- simplify a type string */
/************************************************************************/
while (i
> 0 && isspace(typ
[i
-1])) typ
[--i
] = 0;
if (i
> 7 && STREQL(&typ
[i
-5],"const")) {
if (typ
[i
-1] != ')') return;
if (*s
!= 0 && s
[-1] == ')') {
/************************************************************************/
/* fixname -- fixup a function name (take care of embedded spaces */
/************************************************************************/
/************************************************************************/
/* open_xref_file -- open file for xrefing */
/************************************************************************/
if (s
== NULL
) sprintf(xref_name
,".%s.gxref",file
);
t
= rindex(xref_name
,'/');
xref_file
= fopen(xref_name
,"w");
error("Can't create cross-reference file `%s'",xref_name
);
/* end of cplus-field.c */