]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Code for handling XREF output from GNU C++. |
956d6950 | 2 | Copyright (C) 1992, 1993, 1994, 1995, 1997 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Contributed by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
6bc06b8f RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
21 | |
22 | ||
23 | #include "config.h" | |
8d052bc7 | 24 | #include "system.h" |
e7a587ef | 25 | #include "tree.h" |
8d08fdba MS |
26 | #include "cp-tree.h" |
27 | #include "input.h" | |
12027a89 | 28 | #include "toplev.h" |
8d08fdba | 29 | |
49c249e1 JM |
30 | extern char *getpwd PROTO((void)); |
31 | ||
8d08fdba MS |
32 | /* The character(s) used to join a directory specification (obtained with |
33 | getwd or equivalent) with a non-absolute file name. */ | |
34 | ||
35 | #ifndef FILE_NAME_JOINER | |
36 | #define FILE_NAME_JOINER "/" | |
37 | #endif | |
38 | ||
39 | /* Nonzero if NAME as a file name is absolute. */ | |
40 | #ifndef FILE_NAME_ABSOLUTE_P | |
41 | #define FILE_NAME_ABSOLUTE_P(NAME) (NAME[0] == '/') | |
42 | #endif | |
43 | ||
44 | /* For cross referencing. */ | |
45 | ||
46 | int flag_gnu_xref; | |
47 | ||
48 | /************************************************************************/ | |
49 | /* */ | |
50 | /* Common definitions */ | |
51 | /* */ | |
52 | /************************************************************************/ | |
53 | ||
54 | #ifndef TRUE | |
55 | #define TRUE 1 | |
56 | #endif | |
57 | #ifndef FALSE | |
58 | #define FALSE 0 | |
59 | #endif | |
8d08fdba MS |
60 | |
61 | #define PALLOC(typ) ((typ *) calloc(1,sizeof(typ))) | |
62 | ||
63 | ||
64 | /* Return a malloc'd copy of STR. */ | |
65 | #define SALLOC(str) \ | |
66 | ((char *) ((str) == NULL ? NULL \ | |
67 | : (char *) strcpy ((char *) malloc (strlen ((str)) + 1), (str)))) | |
68 | #define SFREE(str) (str != NULL && (free(str),0)) | |
69 | ||
70 | #define STREQL(s1,s2) (strcmp((s1),(s2)) == 0) | |
71 | #define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0) | |
72 | #define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0) | |
73 | #define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0) | |
74 | #define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0) | |
75 | #define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0) | |
76 | ||
77 | /************************************************************************/ | |
78 | /* */ | |
79 | /* Type definitions */ | |
80 | /* */ | |
81 | /************************************************************************/ | |
82 | ||
83 | ||
84 | typedef struct _XREF_FILE * XREF_FILE; | |
85 | typedef struct _XREF_SCOPE * XREF_SCOPE; | |
86 | ||
87 | typedef struct _XREF_FILE | |
88 | { | |
89 | char *name; | |
90 | char *outname; | |
91 | XREF_FILE next; | |
92 | } XREF_FILE_INFO; | |
93 | ||
94 | typedef struct _XREF_SCOPE | |
95 | { | |
96 | int gid; | |
97 | int lid; | |
98 | XREF_FILE file; | |
99 | int start; | |
100 | XREF_SCOPE outer; | |
101 | } XREF_SCOPE_INFO; | |
102 | ||
103 | /************************************************************************/ | |
104 | /* */ | |
105 | /* Local storage */ | |
106 | /* */ | |
107 | /************************************************************************/ | |
108 | ||
109 | static char doing_xref = 0; | |
110 | static FILE * xref_file = NULL; | |
111 | static char xref_name[1024]; | |
112 | static XREF_FILE all_files = NULL; | |
113 | static char * wd_name = NULL; | |
114 | static XREF_SCOPE cur_scope = NULL; | |
115 | static int scope_ctr = 0; | |
116 | static XREF_FILE last_file = NULL; | |
117 | static tree last_fndecl = NULL; | |
118 | ||
119 | /************************************************************************/ | |
120 | /* */ | |
121 | /* Forward definitions */ | |
122 | /* */ | |
123 | /************************************************************************/ | |
49c249e1 JM |
124 | static void gen_assign PROTO((XREF_FILE, tree)); |
125 | static XREF_FILE find_file PROTO((char *)); | |
126 | static char * filename PROTO((XREF_FILE)); | |
127 | static char * fctname PROTO((tree)); | |
128 | static char * declname PROTO((tree)); | |
129 | static void simplify_type PROTO((char *)); | |
130 | static char * fixname PROTO((char *, char *)); | |
131 | static void open_xref_file PROTO((char *)); | |
8d08fdba MS |
132 | |
133 | /* Start cross referencing. FILE is the name of the file we xref. */ | |
134 | ||
135 | void | |
136 | GNU_xref_begin (file) | |
137 | char *file; | |
138 | { | |
139 | doing_xref = 1; | |
140 | ||
141 | if (file != NULL && STRNEQ (file,"-")) | |
142 | { | |
143 | open_xref_file(file); | |
144 | GNU_xref_file(file); | |
145 | } | |
146 | } | |
147 | ||
148 | /* Finish cross-referencing. ERRCNT is the number of errors | |
149 | we encountered. */ | |
150 | ||
151 | void | |
152 | GNU_xref_end (ect) | |
153 | int ect; | |
154 | { | |
155 | XREF_FILE xf; | |
156 | ||
157 | if (!doing_xref) return; | |
158 | ||
159 | xf = find_file (input_filename); | |
160 | if (xf == NULL) return; | |
161 | ||
162 | while (cur_scope != NULL) | |
5566b478 | 163 | GNU_xref_end_scope(cur_scope->gid,0,0,0); |
8d08fdba MS |
164 | |
165 | doing_xref = 0; | |
166 | ||
167 | if (xref_file == NULL) return; | |
168 | ||
169 | fclose (xref_file); | |
170 | ||
171 | xref_file = NULL; | |
172 | all_files = NULL; | |
173 | ||
174 | if (ect > 0) unlink (xref_name); | |
175 | } | |
176 | ||
177 | /* Write out xref for file named NAME. */ | |
178 | ||
179 | void | |
180 | GNU_xref_file (name) | |
181 | char *name; | |
182 | { | |
183 | XREF_FILE xf; | |
184 | ||
185 | if (!doing_xref || name == NULL) return; | |
186 | ||
187 | if (xref_file == NULL) | |
188 | { | |
189 | open_xref_file (name); | |
190 | if (!doing_xref) return; | |
191 | } | |
192 | ||
193 | if (all_files == NULL) | |
194 | fprintf(xref_file,"SCP * 0 0 0 0 RESET\n"); | |
195 | ||
196 | xf = find_file (name); | |
197 | if (xf != NULL) return; | |
198 | ||
199 | xf = PALLOC (XREF_FILE_INFO); | |
200 | xf->name = SALLOC (name); | |
201 | xf->next = all_files; | |
202 | all_files = xf; | |
203 | ||
204 | if (wd_name == NULL) | |
205 | wd_name = getpwd (); | |
206 | ||
207 | if (FILE_NAME_ABSOLUTE_P (name) || ! wd_name) | |
208 | xf->outname = xf->name; | |
209 | else | |
210 | { | |
211 | char *nmbuf | |
212 | = (char *) malloc (strlen (wd_name) + strlen (FILE_NAME_JOINER) | |
213 | + strlen (name) + 1); | |
214 | sprintf (nmbuf, "%s%s%s", wd_name, FILE_NAME_JOINER, name); | |
215 | name = nmbuf; | |
216 | xf->outname = nmbuf; | |
217 | } | |
218 | ||
219 | fprintf (xref_file, "FIL %s %s 0\n", name, wd_name); | |
220 | ||
221 | filename (xf); | |
222 | fctname (NULL); | |
223 | } | |
224 | ||
225 | /* Start a scope identified at level ID. */ | |
226 | ||
227 | void | |
228 | GNU_xref_start_scope (id) | |
229 | HOST_WIDE_INT id; | |
230 | { | |
231 | XREF_SCOPE xs; | |
232 | XREF_FILE xf; | |
233 | ||
234 | if (!doing_xref) return; | |
235 | xf = find_file (input_filename); | |
236 | ||
237 | xs = PALLOC (XREF_SCOPE_INFO); | |
238 | xs->file = xf; | |
239 | xs->start = lineno; | |
240 | if (xs->start <= 0) xs->start = 1; | |
241 | xs->gid = id; | |
242 | xs->lid = ++scope_ctr; | |
243 | xs->outer = cur_scope; | |
244 | cur_scope = xs; | |
245 | } | |
246 | ||
247 | /* Finish a scope at level ID. | |
248 | INID is ??? | |
249 | PRM is ??? | |
250 | KEEP is nonzero iff this scope is retained (nonzero if it's | |
251 | a compiler-generated invisible scope). | |
252 | TRNS is ??? */ | |
253 | ||
254 | void | |
5566b478 | 255 | GNU_xref_end_scope (id,inid,prm,keep) |
8d08fdba MS |
256 | HOST_WIDE_INT id; |
257 | HOST_WIDE_INT inid; | |
5566b478 | 258 | int prm,keep; |
8d08fdba MS |
259 | { |
260 | XREF_FILE xf; | |
261 | XREF_SCOPE xs,lxs,oxs; | |
262 | char *stype; | |
263 | ||
264 | if (!doing_xref) return; | |
265 | xf = find_file (input_filename); | |
266 | if (xf == NULL) return; | |
267 | ||
268 | lxs = NULL; | |
269 | for (xs = cur_scope; xs != NULL; xs = xs->outer) | |
270 | { | |
271 | if (xs->gid == id) break; | |
272 | lxs = xs; | |
273 | } | |
274 | if (xs == NULL) return; | |
275 | ||
276 | if (inid != 0) { | |
277 | for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) { | |
278 | if (oxs->gid == inid) break; | |
279 | } | |
280 | if (oxs == NULL) return; | |
281 | inid = oxs->lid; | |
282 | } | |
283 | ||
284 | if (prm == 2) stype = "SUE"; | |
285 | else if (prm != 0) stype = "ARGS"; | |
286 | else if (keep == 2 || inid != 0) stype = "INTERN"; | |
287 | else stype = "EXTERN"; | |
288 | ||
289 | fprintf (xref_file,"SCP %s %d %d %d %d %s\n", | |
290 | filename (xf), xs->start, lineno,xs->lid, inid, stype); | |
291 | ||
292 | if (lxs == NULL) cur_scope = xs->outer; | |
293 | else lxs->outer = xs->outer; | |
294 | ||
295 | free (xs); | |
296 | } | |
297 | ||
298 | /* Output a reference to NAME in FNDECL. */ | |
299 | ||
300 | void | |
301 | GNU_xref_ref (fndecl,name) | |
302 | tree fndecl; | |
303 | char *name; | |
304 | { | |
305 | XREF_FILE xf; | |
306 | ||
307 | if (!doing_xref) return; | |
308 | xf = find_file (input_filename); | |
309 | if (xf == NULL) return; | |
310 | ||
311 | fprintf (xref_file, "REF %s %d %s %s\n", | |
312 | filename (xf), lineno, fctname (fndecl), name); | |
313 | } | |
314 | ||
315 | /* Output a reference to DECL in FNDECL. */ | |
316 | ||
317 | void | |
318 | GNU_xref_decl (fndecl,decl) | |
319 | tree fndecl; | |
320 | tree decl; | |
321 | { | |
322 | XREF_FILE xf,xf1; | |
a703fb38 | 323 | char *cls = 0; |
8d08fdba MS |
324 | char *name; |
325 | char buf[10240]; | |
326 | int uselin; | |
327 | ||
328 | if (!doing_xref) return; | |
329 | xf = find_file (input_filename); | |
330 | if (xf == NULL) return; | |
331 | ||
332 | uselin = FALSE; | |
333 | ||
334 | if (TREE_CODE (decl) == TYPE_DECL) cls = "TYPEDEF"; | |
335 | else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD"; | |
336 | else if (TREE_CODE (decl) == VAR_DECL) | |
337 | { | |
338 | if (fndecl == NULL && TREE_STATIC(decl) | |
339 | && TREE_READONLY(decl) && DECL_INITIAL(decl) != 0 | |
340 | && !TREE_PUBLIC(decl) && !DECL_EXTERNAL(decl) | |
341 | && DECL_MODE(decl) != BLKmode) cls = "CONST"; | |
342 | else if (DECL_EXTERNAL(decl)) cls = "EXTERN"; | |
343 | else if (TREE_PUBLIC(decl)) cls = "EXTDEF"; | |
344 | else if (TREE_STATIC(decl)) cls = "STATIC"; | |
345 | else if (DECL_REGISTER(decl)) cls = "REGISTER"; | |
346 | else cls = "AUTO"; | |
347 | } | |
348 | else if (TREE_CODE (decl) == PARM_DECL) cls = "PARAM"; | |
349 | else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD"; | |
350 | else if (TREE_CODE (decl) == CONST_DECL) cls = "CONST"; | |
351 | else if (TREE_CODE (decl) == FUNCTION_DECL) | |
352 | { | |
353 | if (DECL_EXTERNAL (decl)) cls = "EXTERN"; | |
354 | else if (TREE_PUBLIC (decl)) cls = "EFUNCTION"; | |
355 | else cls = "SFUNCTION"; | |
356 | } | |
357 | else if (TREE_CODE (decl) == LABEL_DECL) cls = "LABEL"; | |
358 | else if (TREE_CODE (decl) == UNION_TYPE) | |
359 | { | |
360 | cls = "UNIONID"; | |
361 | decl = TYPE_NAME (decl); | |
362 | uselin = TRUE; | |
363 | } | |
364 | else if (TREE_CODE (decl) == RECORD_TYPE) | |
365 | { | |
366 | if (CLASSTYPE_DECLARED_CLASS (decl)) cls = "CLASSID"; | |
367 | else if (IS_SIGNATURE (decl)) cls = "SIGNATUREID"; | |
368 | else cls = "STRUCTID"; | |
369 | decl = TYPE_NAME (decl); | |
370 | uselin = TRUE; | |
371 | } | |
372 | else if (TREE_CODE (decl) == ENUMERAL_TYPE) | |
373 | { | |
374 | cls = "ENUMID"; | |
375 | decl = TYPE_NAME (decl); | |
376 | uselin = TRUE; | |
377 | } | |
f0e01782 MS |
378 | else if (TREE_CODE (decl) == TEMPLATE_DECL) |
379 | { | |
5566b478 | 380 | if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL) |
f0e01782 MS |
381 | cls = "CLASSTEMP"; |
382 | else if (TREE_CODE (DECL_RESULT (decl)) == FUNCTION_DECL) | |
383 | cls = "FUNCTEMP"; | |
384 | else if (TREE_CODE (DECL_RESULT (decl)) == VAR_DECL) | |
385 | cls = "VARTEMP"; | |
386 | else | |
387 | my_friendly_abort (358); | |
388 | uselin = TRUE; | |
389 | } | |
8d08fdba MS |
390 | else cls = "UNKNOWN"; |
391 | ||
392 | if (decl == NULL || DECL_NAME (decl) == NULL) return; | |
393 | ||
394 | if (uselin && decl->decl.linenum > 0 && decl->decl.filename != NULL) | |
395 | { | |
396 | xf1 = find_file (decl->decl.filename); | |
397 | if (xf1 != NULL) | |
398 | { | |
399 | lineno = decl->decl.linenum; | |
400 | xf = xf1; | |
401 | } | |
402 | } | |
403 | ||
404 | if (DECL_ASSEMBLER_NAME (decl)) | |
405 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
406 | else | |
407 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
408 | ||
409 | strcpy (buf, type_as_string (TREE_TYPE (decl), 0)); | |
410 | simplify_type (buf); | |
411 | ||
412 | fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n", | |
413 | filename(xf), lineno, name, | |
414 | (cur_scope != NULL ? cur_scope->lid : 0), | |
415 | cls, fctname(fndecl), buf); | |
416 | ||
417 | if (STREQL (cls, "STRUCTID") || STREQL (cls, "UNIONID") | |
418 | || STREQL (cls, "SIGNATUREID")) | |
419 | { | |
420 | cls = "CLASSID"; | |
421 | fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n", | |
422 | filename(xf), lineno,name, | |
423 | (cur_scope != NULL ? cur_scope->lid : 0), | |
424 | cls, fctname(fndecl), buf); | |
425 | } | |
426 | } | |
427 | ||
428 | /* Output a reference to a call to NAME in FNDECL. */ | |
429 | ||
430 | void | |
431 | GNU_xref_call (fndecl, name) | |
432 | tree fndecl; | |
433 | char *name; | |
434 | { | |
435 | XREF_FILE xf; | |
436 | char buf[1024]; | |
437 | char *s; | |
438 | ||
439 | if (!doing_xref) return; | |
440 | xf = find_file (input_filename); | |
441 | if (xf == NULL) return; | |
442 | name = fixname (name, buf); | |
443 | ||
444 | for (s = name; *s != 0; ++s) | |
445 | if (*s == '_' && s[1] == '_') break; | |
446 | if (*s != 0) GNU_xref_ref (fndecl, name); | |
447 | ||
448 | fprintf (xref_file, "CAL %s %d %s %s\n", | |
449 | filename (xf), lineno, name, fctname (fndecl)); | |
450 | } | |
451 | ||
452 | /* Output cross-reference info about FNDECL. If non-NULL, | |
453 | ARGS are the arguments for the function (i.e., before the FUNCTION_DECL | |
454 | has been fully built). */ | |
455 | ||
456 | void | |
457 | GNU_xref_function (fndecl, args) | |
458 | tree fndecl; | |
459 | tree args; | |
460 | { | |
461 | XREF_FILE xf; | |
462 | int ct; | |
463 | char buf[1024]; | |
464 | ||
465 | if (!doing_xref) return; | |
466 | xf = find_file (input_filename); | |
467 | if (xf == NULL) return; | |
468 | ||
469 | ct = 0; | |
470 | buf[0] = 0; | |
471 | if (args == NULL) args = DECL_ARGUMENTS (fndecl); | |
472 | ||
473 | GNU_xref_decl (NULL, fndecl); | |
474 | ||
475 | for ( ; args != NULL; args = TREE_CHAIN (args)) | |
476 | { | |
477 | GNU_xref_decl (fndecl,args); | |
478 | if (ct != 0) strcat (buf,","); | |
479 | strcat (buf, declname (args)); | |
480 | ++ct; | |
481 | } | |
482 | ||
483 | fprintf (xref_file, "PRC %s %d %s %d %d %s\n", | |
484 | filename(xf), lineno, declname(fndecl), | |
485 | (cur_scope != NULL ? cur_scope->lid : 0), | |
486 | ct, buf); | |
487 | } | |
488 | ||
489 | /* Output cross-reference info about an assignment to NAME. */ | |
490 | ||
491 | void | |
492 | GNU_xref_assign(name) | |
493 | tree name; | |
494 | { | |
495 | XREF_FILE xf; | |
496 | ||
497 | if (!doing_xref) return; | |
498 | xf = find_file(input_filename); | |
499 | if (xf == NULL) return; | |
500 | ||
501 | gen_assign(xf, name); | |
502 | } | |
503 | ||
504 | static void | |
505 | gen_assign(xf, name) | |
506 | XREF_FILE xf; | |
507 | tree name; | |
508 | { | |
509 | char *s; | |
510 | ||
511 | s = NULL; | |
512 | ||
513 | switch (TREE_CODE (name)) | |
514 | { | |
515 | case IDENTIFIER_NODE : | |
516 | s = IDENTIFIER_POINTER(name); | |
517 | break; | |
518 | case VAR_DECL : | |
519 | s = declname(name); | |
520 | break; | |
521 | case COMPONENT_REF : | |
522 | gen_assign(xf, TREE_OPERAND(name, 0)); | |
523 | gen_assign(xf, TREE_OPERAND(name, 1)); | |
524 | break; | |
525 | case INDIRECT_REF : | |
526 | case OFFSET_REF : | |
527 | case ARRAY_REF : | |
528 | case BUFFER_REF : | |
529 | gen_assign(xf, TREE_OPERAND(name, 0)); | |
530 | break; | |
531 | case COMPOUND_EXPR : | |
532 | gen_assign(xf, TREE_OPERAND(name, 1)); | |
533 | break; | |
534 | default : | |
535 | break; | |
536 | } | |
537 | ||
538 | if (s != NULL) | |
539 | fprintf(xref_file, "ASG %s %d %s\n", filename(xf), lineno, s); | |
540 | } | |
541 | ||
542 | /* Output cross-reference info about a class hierarchy. | |
543 | CLS is the class type of interest. BASE is a baseclass | |
544 | for CLS. PUB and VIRT give the access info about | |
545 | the class derivation. FRND is nonzero iff BASE is a friend | |
546 | of CLS. | |
547 | ||
548 | ??? Needs to handle nested classes. */ | |
e92cc029 | 549 | |
8d08fdba MS |
550 | void |
551 | GNU_xref_hier(cls, base, pub, virt, frnd) | |
552 | char *cls; | |
553 | char *base; | |
554 | int pub; | |
555 | int virt; | |
556 | int frnd; | |
557 | { | |
558 | XREF_FILE xf; | |
559 | ||
560 | if (!doing_xref) return; | |
561 | xf = find_file(input_filename); | |
562 | if (xf == NULL) return; | |
563 | ||
564 | fprintf(xref_file, "HIE %s %d %s %s %d %d %d\n", | |
565 | filename(xf), lineno, cls, base, pub, virt, frnd); | |
566 | } | |
567 | ||
568 | /* Output cross-reference info about class members. CLS | |
569 | is the containing type; FLD is the class member. */ | |
570 | ||
571 | void | |
572 | GNU_xref_member(cls, fld) | |
573 | tree cls; | |
574 | tree fld; | |
575 | { | |
576 | XREF_FILE xf; | |
577 | char *prot; | |
578 | int confg, pure; | |
579 | char *d; | |
5566b478 | 580 | #ifdef XREF_SHORT_MEMBER_NAMES |
8d08fdba | 581 | int i; |
5566b478 | 582 | #endif |
8d08fdba MS |
583 | char buf[1024], bufa[1024]; |
584 | ||
585 | if (!doing_xref) return; | |
586 | xf = find_file(fld->decl.filename); | |
587 | if (xf == NULL) return; | |
588 | ||
589 | if (TREE_PRIVATE (fld)) prot = "PRIVATE"; | |
590 | else if (TREE_PROTECTED(fld)) prot = "PROTECTED"; | |
591 | else prot = "PUBLIC"; | |
592 | ||
593 | confg = 0; | |
594 | if (TREE_CODE (fld) == FUNCTION_DECL && DECL_CONST_MEMFUNC_P(fld)) | |
595 | confg = 1; | |
596 | else if (TREE_CODE (fld) == CONST_DECL) | |
597 | confg = 1; | |
598 | ||
599 | pure = 0; | |
600 | if (TREE_CODE (fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld)) | |
601 | pure = 1; | |
602 | ||
603 | d = IDENTIFIER_POINTER(cls); | |
604 | sprintf(buf, "%d%s", strlen(d), d); | |
5566b478 | 605 | #ifdef XREF_SHORT_MEMBER_NAMES |
8d08fdba | 606 | i = strlen(buf); |
5566b478 | 607 | #endif |
8d08fdba MS |
608 | strcpy(bufa, declname(fld)); |
609 | ||
610 | #ifdef XREF_SHORT_MEMBER_NAMES | |
611 | for (p = &bufa[1]; *p != 0; ++p) | |
612 | { | |
613 | if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') { | |
614 | if (strncmp(&p[2], buf, i) == 0) *p = 0; | |
615 | break; | |
616 | } | |
617 | else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') { | |
618 | if (strncmp(&p[3], buf, i) == 0) *p = 0; | |
619 | break; | |
620 | } | |
621 | } | |
622 | #endif | |
623 | ||
624 | fprintf(xref_file, "MEM %s %d %s %s %s %d %d %d %d %d %d %d\n", | |
625 | filename(xf), fld->decl.linenum, d, bufa, prot, | |
626 | (TREE_CODE (fld) == FUNCTION_DECL ? 0 : 1), | |
627 | (DECL_INLINE (fld) ? 1 : 0), | |
6633d636 | 628 | (DECL_LANG_SPECIFIC(fld) && DECL_FRIEND_P(fld) ? 1 : 0), |
8d08fdba MS |
629 | (DECL_VINDEX(fld) ? 1 : 0), |
630 | (TREE_STATIC(fld) ? 1 : 0), | |
631 | pure, confg); | |
632 | } | |
633 | ||
634 | /* Find file entry given name. */ | |
635 | ||
636 | static XREF_FILE | |
637 | find_file(name) | |
638 | char *name; | |
639 | { | |
640 | XREF_FILE xf; | |
641 | ||
642 | for (xf = all_files; xf != NULL; xf = xf->next) { | |
643 | if (STREQL(name, xf->name)) break; | |
644 | } | |
645 | ||
646 | return xf; | |
647 | } | |
648 | ||
649 | /* Return filename for output purposes. */ | |
650 | ||
651 | static char * | |
652 | filename(xf) | |
653 | XREF_FILE xf; | |
654 | { | |
655 | if (xf == NULL) { | |
656 | last_file = NULL; | |
657 | return "*"; | |
658 | } | |
659 | ||
660 | if (last_file == xf) return "*"; | |
661 | ||
662 | last_file = xf; | |
663 | ||
664 | return xf->outname; | |
665 | } | |
666 | ||
667 | /* Return function name for output purposes. */ | |
668 | ||
669 | static char * | |
670 | fctname(fndecl) | |
671 | tree fndecl; | |
672 | { | |
673 | static char fctbuf[1024]; | |
674 | char *s; | |
675 | ||
676 | if (fndecl == NULL && last_fndecl == NULL) return "*"; | |
677 | ||
678 | if (fndecl == NULL) | |
679 | { | |
680 | last_fndecl = NULL; | |
681 | return "*TOP*"; | |
682 | } | |
683 | ||
684 | if (fndecl == last_fndecl) return "*"; | |
685 | ||
686 | last_fndecl = fndecl; | |
687 | ||
688 | s = declname(fndecl); | |
689 | s = fixname(s, fctbuf); | |
690 | ||
691 | return s; | |
692 | } | |
693 | ||
694 | /* Return decl name for output purposes. */ | |
695 | ||
696 | static char * | |
697 | declname(dcl) | |
698 | tree dcl; | |
699 | { | |
700 | if (DECL_NAME (dcl) == NULL) return "?"; | |
701 | ||
702 | if (DECL_ASSEMBLER_NAME (dcl)) | |
703 | return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (dcl)); | |
704 | else | |
705 | return IDENTIFIER_POINTER (DECL_NAME (dcl)); | |
706 | } | |
707 | ||
708 | /* Simplify a type string by removing unneeded parenthesis. */ | |
709 | ||
710 | static void | |
711 | simplify_type(typ) | |
712 | char *typ; | |
713 | { | |
714 | char *s; | |
715 | int lvl, i; | |
716 | ||
717 | i = strlen(typ); | |
718 | while (i > 0 && isspace(typ[i-1])) typ[--i] = 0; | |
719 | ||
720 | if (i > 7 && STREQL(&typ[i-5], "const")) | |
721 | { | |
722 | typ[i-5] = 0; | |
723 | i -= 5; | |
724 | } | |
725 | ||
726 | if (typ[i-1] != ')') return; | |
727 | ||
728 | s = &typ[i-2]; | |
729 | lvl = 1; | |
730 | while (*s != 0) { | |
731 | if (*s == ')') ++lvl; | |
732 | else if (*s == '(') | |
733 | { | |
734 | --lvl; | |
735 | if (lvl == 0) | |
736 | { | |
737 | s[1] = ')'; | |
738 | s[2] = 0; | |
739 | break; | |
740 | } | |
741 | } | |
742 | --s; | |
743 | } | |
744 | ||
745 | if (*s != 0 && s[-1] == ')') | |
746 | { | |
747 | --s; | |
748 | --s; | |
749 | if (*s == '(') s[2] = 0; | |
750 | else if (*s == ':') { | |
751 | while (*s != '(') --s; | |
752 | s[1] = ')'; | |
753 | s[2] = 0; | |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | /* Fixup a function name (take care of embedded spaces). */ | |
759 | ||
760 | static char * | |
761 | fixname(nam, buf) | |
762 | char *nam; | |
763 | char *buf; | |
764 | { | |
765 | char *s, *t; | |
766 | int fg; | |
767 | ||
768 | s = nam; | |
769 | t = buf; | |
770 | fg = 0; | |
771 | ||
772 | while (*s != 0) | |
773 | { | |
774 | if (*s == ' ') | |
775 | { | |
776 | *t++ = '\36'; | |
777 | ++fg; | |
778 | } | |
779 | else *t++ = *s; | |
780 | ++s; | |
781 | } | |
782 | *t = 0; | |
783 | ||
784 | if (fg == 0) return nam; | |
785 | ||
786 | return buf; | |
787 | } | |
788 | ||
ddd5a7c1 | 789 | /* Open file for xreffing. */ |
8d08fdba MS |
790 | |
791 | static void | |
792 | open_xref_file(file) | |
793 | char *file; | |
794 | { | |
795 | char *s, *t; | |
796 | ||
797 | #ifdef XREF_FILE_NAME | |
798 | XREF_FILE_NAME (xref_name, file); | |
799 | #else | |
a8a63732 | 800 | s = rindex (file, '/'); |
8d08fdba MS |
801 | if (s == NULL) |
802 | sprintf (xref_name, ".%s.gxref", file); | |
803 | else | |
804 | { | |
805 | ++s; | |
806 | strcpy (xref_name, file); | |
a8a63732 | 807 | t = rindex (xref_name, '/'); |
8d08fdba MS |
808 | ++t; |
809 | *t++ = '.'; | |
810 | strcpy (t, s); | |
811 | strcat (t, ".gxref"); | |
812 | } | |
813 | #endif /* no XREF_FILE_NAME */ | |
814 | ||
815 | xref_file = fopen(xref_name, "w"); | |
816 | ||
817 | if (xref_file == NULL) | |
818 | { | |
819 | error("Can't create cross-reference file `%s'", xref_name); | |
820 | doing_xref = 0; | |
821 | } | |
822 | } |