ChangeLog fixes from M-x authors
[emacs.git] / lib-src / ebrowse.c
blob3a237daf5f8a6c96c50085180ec7e91ce7619553
1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs 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 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs 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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <assert.h>
27 #include <getopt.h>
29 /* The SunOS compiler doesn't have SEEK_END. */
30 #ifndef SEEK_END
31 #define SEEK_END 2
32 #endif
34 /* Conditionalize function prototypes. */
36 /* Value is non-zero if strings X and Y compare equal. */
38 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
40 #include <min-max.h>
42 /* Files are read in chunks of this number of bytes. */
44 #define READ_CHUNK_SIZE (100 * 1024)
46 #if defined (__MSDOS__)
47 #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0)
48 #else
49 #if defined (WINDOWSNT)
50 #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0)
51 #else
52 #define FILENAME_EQ(X,Y) (streq (X,Y))
53 #endif
54 #endif
55 /* The default output file name. */
57 #define DEFAULT_OUTFILE "BROWSE"
59 /* A version string written to the output file. Change this whenever
60 the structure of the output file changes. */
62 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
64 /* The output file consists of a tree of Lisp objects, with major
65 nodes built out of Lisp structures. These are the heads of the
66 Lisp structs with symbols identifying their type. */
68 #define TREE_HEADER_STRUCT "[ebrowse-hs "
69 #define TREE_STRUCT "[ebrowse-ts "
70 #define MEMBER_STRUCT "[ebrowse-ms "
71 #define CLASS_STRUCT "[ebrowse-cs "
73 /* The name of the symbol table entry for global functions, variables,
74 defines etc. This name also appears in the browser display. */
76 #define GLOBALS_NAME "*Globals*"
78 /* Token definitions. */
80 enum token
82 YYEOF = 0, /* end of file */
83 CSTRING = 256, /* string constant */
84 CCHAR, /* character constant */
85 CINT, /* integral constant */
86 CFLOAT, /* real constant */
88 ELLIPSIS, /* ... */
89 LSHIFTASGN, /* <<= */
90 RSHIFTASGN, /* >>= */
91 ARROWSTAR, /* ->* */
92 IDENT, /* identifier */
93 DIVASGN, /* /= */
94 INC, /* ++ */
95 ADDASGN, /* += */
96 DEC, /* -- */
97 ARROW, /* -> */
98 SUBASGN, /* -= */
99 MULASGN, /* *= */
100 MODASGN, /* %= */
101 LOR, /* || */
102 ORASGN, /* |= */
103 LAND, /* && */
104 ANDASGN, /* &= */
105 XORASGN, /* ^= */
106 POINTSTAR, /* .* */
107 DCOLON, /* :: */
108 EQ, /* == */
109 NE, /* != */
110 LE, /* <= */
111 LSHIFT, /* << */
112 GE, /* >= */
113 RSHIFT, /* >> */
115 /* Keywords. The undef's are there because these
116 three symbols are very likely to be defined somewhere. */
117 #undef BOOL
118 #undef TRUE
119 #undef FALSE
121 ASM, /* asm */
122 AUTO, /* auto */
123 BREAK, /* break */
124 CASE, /* case */
125 CATCH, /* catch */
126 CHAR, /* char */
127 CLASS, /* class */
128 CONST, /* const */
129 CONTINUE, /* continue */
130 DEFAULT, /* default */
131 DELETE, /* delete */
132 DO, /* do */
133 DOUBLE, /* double */
134 ELSE, /* else */
135 ENUM, /* enum */
136 EXTERN, /* extern */
137 FLOAT, /* float */
138 FOR, /* for */
139 FRIEND, /* friend */
140 GOTO, /* goto */
141 IF, /* if */
142 T_INLINE, /* inline */
143 INT, /* int */
144 LONG, /* long */
145 NEW, /* new */
146 OPERATOR, /* operator */
147 PRIVATE, /* private */
148 PROTECTED, /* protected */
149 PUBLIC, /* public */
150 REGISTER, /* register */
151 RETURN, /* return */
152 SHORT, /* short */
153 SIGNED, /* signed */
154 SIZEOF, /* sizeof */
155 STATIC, /* static */
156 STRUCT, /* struct */
157 SWITCH, /* switch */
158 TEMPLATE, /* template */
159 THIS, /* this */
160 THROW, /* throw */
161 TRY, /* try */
162 TYPEDEF, /* typedef */
163 UNION, /* union */
164 UNSIGNED, /* unsigned */
165 VIRTUAL, /* virtual */
166 VOID, /* void */
167 VOLATILE, /* volatile */
168 WHILE, /* while */
169 MUTABLE, /* mutable */
170 BOOL, /* bool */
171 TRUE, /* true */
172 FALSE, /* false */
173 SIGNATURE, /* signature (GNU extension) */
174 NAMESPACE, /* namespace */
175 EXPLICIT, /* explicit */
176 TYPENAME, /* typename */
177 CONST_CAST, /* const_cast */
178 DYNAMIC_CAST, /* dynamic_cast */
179 REINTERPRET_CAST, /* reinterpret_cast */
180 STATIC_CAST, /* static_cast */
181 TYPEID, /* typeid */
182 USING, /* using */
183 WCHAR /* wchar_t */
186 /* Storage classes, in a wider sense. */
188 enum sc
190 SC_UNKNOWN,
191 SC_MEMBER, /* Is an instance member. */
192 SC_STATIC, /* Is static member. */
193 SC_FRIEND, /* Is friend function. */
194 SC_TYPE /* Is a type definition. */
197 /* Member visibility. */
199 enum visibility
201 V_PUBLIC,
202 V_PROTECTED,
203 V_PRIVATE
206 /* Member flags. */
208 #define F_VIRTUAL 1 /* Is virtual function. */
209 #define F_INLINE 2 /* Is inline function. */
210 #define F_CONST 4 /* Is const. */
211 #define F_PURE 8 /* Is pure virtual function. */
212 #define F_MUTABLE 16 /* Is mutable. */
213 #define F_TEMPLATE 32 /* Is a template. */
214 #define F_EXPLICIT 64 /* Is explicit constructor. */
215 #define F_THROW 128 /* Has a throw specification. */
216 #define F_EXTERNC 256 /* Is declared extern "C". */
217 #define F_DEFINE 512 /* Is a #define. */
219 /* Two macros to set and test a bit in an int. */
221 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
222 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
224 /* Structure describing a class member. */
226 struct member
228 struct member *next; /* Next in list of members. */
229 struct member *anext; /* Collision chain in member_table. */
230 struct member **list; /* Pointer to list in class. */
231 unsigned param_hash; /* Hash value for parameter types. */
232 int vis; /* Visibility (public, ...). */
233 int flags; /* See F_* above. */
234 char *regexp; /* Matching regular expression. */
235 const char *filename; /* Don't free this shared string. */
236 int pos; /* Buffer position of occurrence. */
237 char *def_regexp; /* Regular expression matching definition. */
238 const char *def_filename; /* File name of definition. */
239 int def_pos; /* Buffer position of definition. */
240 char name[1]; /* Member name. */
243 /* Structures of this type are used to connect class structures with
244 their super and subclasses. */
246 struct link
248 struct sym *sym; /* The super or subclass. */
249 struct link *next; /* Next in list or NULL. */
252 /* Structure used to record namespace aliases. */
254 struct alias
256 struct alias *next; /* Next in list. */
257 struct sym *namesp; /* Namespace in which defined. */
258 struct link *aliasee; /* List of aliased namespaces (A::B::C...). */
259 char name[1]; /* Alias name. */
262 /* The structure used to describe a class in the symbol table,
263 or a namespace in all_namespaces. */
265 struct sym
267 int flags; /* Is class a template class?. */
268 unsigned char visited; /* Used to find circles. */
269 struct sym *next; /* Hash collision list. */
270 struct link *subs; /* List of subclasses. */
271 struct link *supers; /* List of superclasses. */
272 struct member *vars; /* List of instance variables. */
273 struct member *fns; /* List of instance functions. */
274 struct member *static_vars; /* List of static variables. */
275 struct member *static_fns; /* List of static functions. */
276 struct member *friends; /* List of friend functions. */
277 struct member *types; /* List of local types. */
278 char *regexp; /* Matching regular expression. */
279 int pos; /* Buffer position. */
280 const char *filename; /* File in which it can be found. */
281 const char *sfilename; /* File in which members can be found. */
282 struct sym *namesp; /* Namespace in which defined. . */
283 char name[1]; /* Name of the class. */
286 /* Experimental: Print info for `--position-info'. We print
287 '(CLASS-NAME SCOPE MEMBER-NAME). */
289 #define P_DEFN 1
290 #define P_DECL 2
292 int info_where;
293 struct sym *info_cls = NULL;
294 struct member *info_member = NULL;
296 /* Experimental. For option `--position-info', the buffer position we
297 are interested in. When this position is reached, print out
298 information about what we know about that point. */
300 int info_position = -1;
302 /* Command line options structure for getopt_long. */
304 struct option options[] =
306 {"append", no_argument, NULL, 'a'},
307 {"files", required_argument, NULL, 'f'},
308 {"help", no_argument, NULL, -2},
309 {"min-regexp-length", required_argument, NULL, 'm'},
310 {"max-regexp-length", required_argument, NULL, 'M'},
311 {"no-nested-classes", no_argument, NULL, 'n'},
312 {"no-regexps", no_argument, NULL, 'x'},
313 {"no-structs-or-unions", no_argument, NULL, 's'},
314 {"output-file", required_argument, NULL, 'o'},
315 {"position-info", required_argument, NULL, 'p'},
316 {"search-path", required_argument, NULL, 'I'},
317 {"verbose", no_argument, NULL, 'v'},
318 {"version", no_argument, NULL, -3},
319 {"very-verbose", no_argument, NULL, 'V'},
320 {NULL, 0, NULL, 0}
323 /* Semantic values of tokens. Set by yylex.. */
325 unsigned yyival; /* Set for token CINT. */
326 char *yytext; /* Set for token IDENT. */
327 char *yytext_end;
329 /* Output file. */
331 FILE *yyout;
333 /* Current line number. */
335 int yyline;
337 /* The name of the current input file. */
339 const char *filename;
341 /* Three character class vectors, and macros to test membership
342 of characters. */
344 char is_ident[255];
345 char is_digit[255];
346 char is_white[255];
348 #define IDENTP(C) is_ident[(unsigned char) (C)]
349 #define DIGITP(C) is_digit[(unsigned char) (C)]
350 #define WHITEP(C) is_white[(unsigned char) (C)]
352 /* Command line flags. */
354 int f_append;
355 int f_verbose;
356 int f_very_verbose;
357 int f_structs = 1;
358 int f_regexps = 1;
359 int f_nested_classes = 1;
361 /* Maximum and minimum lengths of regular expressions matching a
362 member, class etc., for writing them to the output file. These are
363 overridable from the command line. */
365 int min_regexp = 5;
366 int max_regexp = 50;
368 /* Input buffer. */
370 char *inbuffer;
371 char *in;
372 size_t inbuffer_size;
374 /* Return the current buffer position in the input file. */
376 #define BUFFER_POS() (in - inbuffer)
378 /* If current lookahead is CSTRING, the following points to the
379 first character in the string constant. Used for recognizing
380 extern "C". */
382 char *string_start;
384 /* The size of the hash tables for classes.and members. Should be
385 prime. */
387 #define TABLE_SIZE 1001
389 /* The hash table for class symbols. */
391 struct sym *class_table[TABLE_SIZE];
393 /* Hash table containing all member structures. This is generally
394 faster for member lookup than traversing the member lists of a
395 `struct sym'. */
397 struct member *member_table[TABLE_SIZE];
399 /* Hash table for namespace aliases */
401 struct alias *namespace_alias_table[TABLE_SIZE];
403 /* The special class symbol used to hold global functions,
404 variables etc. */
406 struct sym *global_symbols;
408 /* The current namespace. */
410 struct sym *current_namespace;
412 /* The list of all known namespaces. */
414 struct sym *all_namespaces;
416 /* Stack of namespaces we're currently nested in, during the parse. */
418 struct sym **namespace_stack;
419 int namespace_stack_size;
420 int namespace_sp;
422 /* The current lookahead token. */
424 int tk = -1;
426 /* Structure describing a keyword. */
428 struct kw
430 const char *name; /* Spelling. */
431 int tk; /* Token value. */
432 struct kw *next; /* Next in collision chain. */
435 /* Keywords are lookup up in a hash table of their own. */
437 #define KEYWORD_TABLE_SIZE 1001
438 struct kw *keyword_table[KEYWORD_TABLE_SIZE];
440 /* Search path. */
442 struct search_path
444 char *path;
445 struct search_path *next;
448 struct search_path *search_path;
449 struct search_path *search_path_tail;
451 /* Function prototypes. */
453 static char *matching_regexp (void);
454 static struct sym *add_sym (const char *, struct sym *);
455 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
456 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
457 static struct member *add_member (struct sym *, char *, int, int, unsigned);
458 static void class_definition (struct sym *, int, int, int);
459 static char *operator_name (int *);
460 static void parse_qualified_param_ident_or_type (char **);
462 /***********************************************************************
463 Utilities
464 ***********************************************************************/
466 /* Print an error in a printf-like style with the current input file
467 name and line number. */
469 static void
470 yyerror (const char *format, const char *s)
472 fprintf (stderr, "%s:%d: ", filename, yyline);
473 fprintf (stderr, format, s);
474 putc ('\n', stderr);
478 /* Like malloc but print an error and exit if not enough memory is
479 available. */
481 static void *
482 xmalloc (size_t nbytes)
484 void *p = malloc (nbytes);
485 if (p == NULL)
487 yyerror ("out of memory", NULL);
488 exit (EXIT_FAILURE);
490 return p;
494 /* Like realloc but print an error and exit if out of memory. */
496 static void *
497 xrealloc (void *p, size_t sz)
499 p = realloc (p, sz);
500 if (p == NULL)
502 yyerror ("out of memory", NULL);
503 exit (EXIT_FAILURE);
505 return p;
509 /* Like strdup, but print an error and exit if not enough memory is
510 available.. If S is null, return null. */
512 static char *
513 xstrdup (char *s)
515 if (s)
516 s = strcpy (xmalloc (strlen (s) + 1), s);
517 return s;
522 /***********************************************************************
523 Symbols
524 ***********************************************************************/
526 /* Initialize the symbol table. This currently only sets up the
527 special symbol for globals (`*Globals*'). */
529 static void
530 init_sym (void)
532 global_symbols = add_sym (GLOBALS_NAME, NULL);
536 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
537 is the class in which class NAME was found. If it is null,
538 this means the scope of NAME is the current namespace.
540 If a symbol for NAME already exists, return that. Otherwise
541 create a new symbol and set it to default values. */
543 static struct sym *
544 add_sym (const char *name, struct sym *nested_in_class)
546 struct sym *sym;
547 unsigned h;
548 const char *s;
549 struct sym *scope = nested_in_class ? nested_in_class : current_namespace;
551 for (s = name, h = 0; *s; ++s)
552 h = (h << 1) ^ *s;
553 h %= TABLE_SIZE;
555 for (sym = class_table[h]; sym; sym = sym->next)
556 if (streq (name, sym->name)
557 && ((!sym->namesp && !scope)
558 || (sym->namesp && scope
559 && streq (sym->namesp->name, scope->name))))
560 break;
562 if (sym == NULL)
564 if (f_very_verbose)
566 putchar ('\t');
567 puts (name);
570 sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
571 memset (sym, 0, sizeof *sym);
572 strcpy (sym->name, name);
573 sym->namesp = scope;
574 sym->next = class_table[h];
575 class_table[h] = sym;
578 return sym;
582 /* Add links between superclass SUPER and subclass SUB. */
584 static void
585 add_link (struct sym *super, struct sym *sub)
587 struct link *lnk, *lnk2, *p, *prev;
589 /* See if a link already exists. */
590 for (p = super->subs, prev = NULL;
591 p && strcmp (sub->name, p->sym->name) > 0;
592 prev = p, p = p->next)
595 /* Avoid duplicates. */
596 if (p == NULL || p->sym != sub)
598 lnk = (struct link *) xmalloc (sizeof *lnk);
599 lnk2 = (struct link *) xmalloc (sizeof *lnk2);
601 lnk->sym = sub;
602 lnk->next = p;
604 if (prev)
605 prev->next = lnk;
606 else
607 super->subs = lnk;
609 lnk2->sym = super;
610 lnk2->next = sub->supers;
611 sub->supers = lnk2;
616 /* Find in class CLS member NAME.
618 VAR non-zero means look for a member variable; otherwise a function
619 is searched. SC specifies what kind of member is searched---a
620 static, or per-instance member etc. HASH is a hash code for the
621 parameter types of functions. Value is a pointer to the member
622 found or null if not found. */
624 static struct member *
625 find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
627 struct member **list;
628 struct member *p;
629 unsigned name_hash = 0;
630 char *s;
631 int i;
633 switch (sc)
635 case SC_FRIEND:
636 list = &cls->friends;
637 break;
639 case SC_TYPE:
640 list = &cls->types;
641 break;
643 case SC_STATIC:
644 list = var ? &cls->static_vars : &cls->static_fns;
645 break;
647 default:
648 list = var ? &cls->vars : &cls->fns;
649 break;
652 for (s = name; *s; ++s)
653 name_hash = (name_hash << 1) ^ *s;
654 i = name_hash % TABLE_SIZE;
656 for (p = member_table[i]; p; p = p->anext)
657 if (p->list == list && p->param_hash == hash && streq (name, p->name))
658 break;
660 return p;
664 /* Add to class CLS information for the declaration of member NAME.
665 REGEXP is a regexp matching the declaration, if non-null. POS is
666 the position in the source where the declaration is found. HASH is
667 a hash code for the parameter list of the member, if it's a
668 function. VAR non-zero means member is a variable or type. SC
669 specifies the type of member (instance member, static, ...). VIS
670 is the member's visibility (public, protected, private). FLAGS is
671 a bit set giving additional information about the member (see the
672 F_* defines). */
674 static void
675 add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags)
677 struct member *m;
679 m = find_member (cls, name, var, sc, hash);
680 if (m == NULL)
681 m = add_member (cls, name, var, sc, hash);
683 /* Have we seen a new filename? If so record that. */
684 if (!cls->filename || !FILENAME_EQ (cls->filename, filename))
685 m->filename = filename;
687 m->regexp = regexp;
688 m->pos = pos;
689 m->flags = flags;
691 switch (vis)
693 case PRIVATE:
694 m->vis = V_PRIVATE;
695 break;
697 case PROTECTED:
698 m->vis = V_PROTECTED;
699 break;
701 case PUBLIC:
702 m->vis = V_PUBLIC;
703 break;
706 info_where = P_DECL;
707 info_cls = cls;
708 info_member = m;
712 /* Add to class CLS information for the definition of member NAME.
713 REGEXP is a regexp matching the declaration, if non-null. POS is
714 the position in the source where the declaration is found. HASH is
715 a hash code for the parameter list of the member, if it's a
716 function. VAR non-zero means member is a variable or type. SC
717 specifies the type of member (instance member, static, ...). VIS
718 is the member's visibility (public, protected, private). FLAGS is
719 a bit set giving additional information about the member (see the
720 F_* defines). */
722 static void
723 add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
725 struct member *m;
727 if (sc == SC_UNKNOWN)
729 m = find_member (cls, name, var, SC_MEMBER, hash);
730 if (m == NULL)
732 m = find_member (cls, name, var, SC_STATIC, hash);
733 if (m == NULL)
734 m = add_member (cls, name, var, sc, hash);
737 else
739 m = find_member (cls, name, var, sc, hash);
740 if (m == NULL)
741 m = add_member (cls, name, var, sc, hash);
744 if (!cls->sfilename)
745 cls->sfilename = filename;
747 if (!FILENAME_EQ (cls->sfilename, filename))
748 m->def_filename = filename;
750 m->def_regexp = regexp;
751 m->def_pos = pos;
752 m->flags |= flags;
754 info_where = P_DEFN;
755 info_cls = cls;
756 info_member = m;
760 /* Add a symbol for a define named NAME to the symbol table.
761 REGEXP is a regular expression matching the define in the source,
762 if it is non-null. POS is the position in the file. */
764 static void
765 add_define (char *name, char *regexp, int pos)
767 add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
768 add_global_decl (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
772 /* Add information for the global definition of NAME.
773 REGEXP is a regexp matching the declaration, if non-null. POS is
774 the position in the source where the declaration is found. HASH is
775 a hash code for the parameter list of the member, if it's a
776 function. VAR non-zero means member is a variable or type. SC
777 specifies the type of member (instance member, static, ...). VIS
778 is the member's visibility (public, protected, private). FLAGS is
779 a bit set giving additional information about the member (see the
780 F_* defines). */
782 static void
783 add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
785 int i;
786 struct sym *sym;
788 /* Try to find out for which classes a function is a friend, and add
789 what we know about it to them. */
790 if (!var)
791 for (i = 0; i < TABLE_SIZE; ++i)
792 for (sym = class_table[i]; sym; sym = sym->next)
793 if (sym != global_symbols && sym->friends)
794 if (find_member (sym, name, 0, SC_FRIEND, hash))
795 add_member_defn (sym, name, regexp, pos, hash, 0,
796 SC_FRIEND, flags);
798 /* Add to global symbols. */
799 add_member_defn (global_symbols, name, regexp, pos, hash, var, sc, flags);
803 /* Add information for the global declaration of NAME.
804 REGEXP is a regexp matching the declaration, if non-null. POS is
805 the position in the source where the declaration is found. HASH is
806 a hash code for the parameter list of the member, if it's a
807 function. VAR non-zero means member is a variable or type. SC
808 specifies the type of member (instance member, static, ...). VIS
809 is the member's visibility (public, protected, private). FLAGS is
810 a bit set giving additional information about the member (see the
811 F_* defines). */
813 static void
814 add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
816 /* Add declaration only if not already declared. Header files must
817 be processed before source files for this to have the right effect.
818 I do not want to handle implicit declarations at the moment. */
819 struct member *m;
820 struct member *found;
822 m = found = find_member (global_symbols, name, var, sc, hash);
823 if (m == NULL)
824 m = add_member (global_symbols, name, var, sc, hash);
826 /* Definition already seen => probably last declaration implicit.
827 Override. This means that declarations must always be added to
828 the symbol table before definitions. */
829 if (!found)
831 if (!global_symbols->filename
832 || !FILENAME_EQ (global_symbols->filename, filename))
833 m->filename = filename;
835 m->regexp = regexp;
836 m->pos = pos;
837 m->vis = V_PUBLIC;
838 m->flags = flags;
840 info_where = P_DECL;
841 info_cls = global_symbols;
842 info_member = m;
847 /* Add a symbol for member NAME to class CLS.
848 VAR non-zero means it's a variable. SC specifies the kind of
849 member. HASH is a hash code for the parameter types of a function.
850 Value is a pointer to the member's structure. */
852 static struct member *
853 add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
855 struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
856 struct member **list;
857 struct member *p;
858 struct member *prev;
859 unsigned name_hash = 0;
860 int i;
861 char *s;
863 strcpy (m->name, name);
864 m->param_hash = hash;
866 m->vis = 0;
867 m->flags = 0;
868 m->regexp = NULL;
869 m->filename = NULL;
870 m->pos = 0;
871 m->def_regexp = NULL;
872 m->def_filename = NULL;
873 m->def_pos = 0;
875 assert (cls != NULL);
877 switch (sc)
879 case SC_FRIEND:
880 list = &cls->friends;
881 break;
883 case SC_TYPE:
884 list = &cls->types;
885 break;
887 case SC_STATIC:
888 list = var ? &cls->static_vars : &cls->static_fns;
889 break;
891 default:
892 list = var ? &cls->vars : &cls->fns;
893 break;
896 for (s = name; *s; ++s)
897 name_hash = (name_hash << 1) ^ *s;
898 i = name_hash % TABLE_SIZE;
899 m->anext = member_table[i];
900 member_table[i] = m;
901 m->list = list;
903 /* Keep the member list sorted. It's cheaper to do it here than to
904 sort them in Lisp. */
905 for (prev = NULL, p = *list;
906 p && strcmp (name, p->name) > 0;
907 prev = p, p = p->next)
910 m->next = p;
911 if (prev)
912 prev->next = m;
913 else
914 *list = m;
915 return m;
919 /* Given the root R of a class tree, step through all subclasses
920 recursively, marking functions as virtual that are declared virtual
921 in base classes. */
923 static void
924 mark_virtual (struct sym *r)
926 struct link *p;
927 struct member *m, *m2;
929 for (p = r->subs; p; p = p->next)
931 for (m = r->fns; m; m = m->next)
932 if (HAS_FLAG (m->flags, F_VIRTUAL))
934 for (m2 = p->sym->fns; m2; m2 = m2->next)
935 if (m->param_hash == m2->param_hash && streq (m->name, m2->name))
936 SET_FLAG (m2->flags, F_VIRTUAL);
939 mark_virtual (p->sym);
944 /* For all roots of the class tree, mark functions as virtual that
945 are virtual because of a virtual declaration in a base class. */
947 static void
948 mark_inherited_virtual (void)
950 struct sym *r;
951 int i;
953 for (i = 0; i < TABLE_SIZE; ++i)
954 for (r = class_table[i]; r; r = r->next)
955 if (r->supers == NULL)
956 mark_virtual (r);
960 /* Create and return a symbol for a namespace with name NAME. */
962 static struct sym *
963 make_namespace (char *name, struct sym *context)
965 struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
966 memset (s, 0, sizeof *s);
967 strcpy (s->name, name);
968 s->next = all_namespaces;
969 s->namesp = context;
970 all_namespaces = s;
971 return s;
975 /* Find the symbol for namespace NAME. If not found, return NULL */
977 static struct sym *
978 check_namespace (char *name, struct sym *context)
980 struct sym *p = NULL;
982 for (p = all_namespaces; p; p = p->next)
984 if (streq (p->name, name) && (p->namesp == context))
985 break;
988 return p;
991 /* Find the symbol for namespace NAME. If not found, add a new symbol
992 for NAME to all_namespaces. */
994 static struct sym *
995 find_namespace (char *name, struct sym *context)
997 struct sym *p = check_namespace (name, context);
999 if (p == NULL)
1000 p = make_namespace (name, context);
1002 return p;
1006 /* Find namespace alias with name NAME. If not found return NULL. */
1008 static struct link *
1009 check_namespace_alias (char *name)
1011 struct link *p = NULL;
1012 struct alias *al;
1013 unsigned h;
1014 char *s;
1016 for (s = name, h = 0; *s; ++s)
1017 h = (h << 1) ^ *s;
1018 h %= TABLE_SIZE;
1020 for (al = namespace_alias_table[h]; al; al = al->next)
1021 if (streq (name, al->name) && (al->namesp == current_namespace))
1023 p = al->aliasee;
1024 break;
1027 return p;
1030 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1032 static void
1033 register_namespace_alias (char *new_name, struct link *old_name)
1035 unsigned h;
1036 char *s;
1037 struct alias *al;
1039 for (s = new_name, h = 0; *s; ++s)
1040 h = (h << 1) ^ *s;
1041 h %= TABLE_SIZE;
1044 /* Is it already in the table of aliases? */
1045 for (al = namespace_alias_table[h]; al; al = al->next)
1046 if (streq (new_name, al->name) && (al->namesp == current_namespace))
1047 return;
1049 al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
1050 strcpy (al->name, new_name);
1051 al->next = namespace_alias_table[h];
1052 al->namesp = current_namespace;
1053 al->aliasee = old_name;
1054 namespace_alias_table[h] = al;
1058 /* Enter namespace with name NAME. */
1060 static void
1061 enter_namespace (char *name)
1063 struct sym *p = find_namespace (name, current_namespace);
1065 if (namespace_sp == namespace_stack_size)
1067 int size = max (10, 2 * namespace_stack_size);
1068 namespace_stack
1069 = (struct sym **) xrealloc ((void *)namespace_stack,
1070 size * sizeof *namespace_stack);
1071 namespace_stack_size = size;
1074 namespace_stack[namespace_sp++] = current_namespace;
1075 current_namespace = p;
1079 /* Leave the current namespace. */
1081 static void
1082 leave_namespace (void)
1084 assert (namespace_sp > 0);
1085 current_namespace = namespace_stack[--namespace_sp];
1090 /***********************************************************************
1091 Writing the Output File
1092 ***********************************************************************/
1094 /* Write string S to the output file FP in a Lisp-readable form.
1095 If S is null, write out `()'. */
1097 static inline void
1098 putstr (const char *s, FILE *fp)
1100 if (!s)
1102 putc ('(', fp);
1103 putc (')', fp);
1104 putc (' ', fp);
1106 else
1108 putc ('"', fp);
1109 fputs (s, fp);
1110 putc ('"', fp);
1111 putc (' ', fp);
1115 /* A dynamically allocated buffer for constructing a scope name. */
1117 char *scope_buffer;
1118 int scope_buffer_size;
1119 int scope_buffer_len;
1122 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1124 static void
1125 ensure_scope_buffer_room (int len)
1127 if (scope_buffer_len + len >= scope_buffer_size)
1129 int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
1130 scope_buffer = (char *) xrealloc (scope_buffer, new_size);
1131 scope_buffer_size = new_size;
1136 /* Recursively add the scope names of symbol P and the scopes of its
1137 namespaces to scope_buffer. Value is a pointer to the complete
1138 scope name constructed. */
1140 static char *
1141 sym_scope_1 (struct sym *p)
1143 int len;
1145 if (p->namesp)
1146 sym_scope_1 (p->namesp);
1148 if (*scope_buffer)
1150 ensure_scope_buffer_room (3);
1151 strcat (scope_buffer, "::");
1152 scope_buffer_len += 2;
1155 len = strlen (p->name);
1156 ensure_scope_buffer_room (len + 1);
1157 strcat (scope_buffer, p->name);
1158 scope_buffer_len += len;
1160 if (HAS_FLAG (p->flags, F_TEMPLATE))
1162 ensure_scope_buffer_room (3);
1163 strcat (scope_buffer, "<>");
1164 scope_buffer_len += 2;
1167 return scope_buffer;
1171 /* Return the scope of symbol P in printed representation, i.e.
1172 as it would appear in a C*+ source file. */
1174 static char *
1175 sym_scope (struct sym *p)
1177 if (!scope_buffer)
1179 scope_buffer_size = 1024;
1180 scope_buffer = (char *) xmalloc (scope_buffer_size);
1183 *scope_buffer = '\0';
1184 scope_buffer_len = 0;
1186 if (p->namesp)
1187 sym_scope_1 (p->namesp);
1189 return scope_buffer;
1193 /* Dump the list of members M to file FP. Value is the length of the
1194 list. */
1196 static int
1197 dump_members (FILE *fp, struct member *m)
1199 int n;
1201 putc ('(', fp);
1203 for (n = 0; m; m = m->next, ++n)
1205 fputs (MEMBER_STRUCT, fp);
1206 putstr (m->name, fp);
1207 putstr (NULL, fp); /* FIXME? scope for globals */
1208 fprintf (fp, "%u ", (unsigned) m->flags);
1209 putstr (m->filename, fp);
1210 putstr (m->regexp, fp);
1211 fprintf (fp, "%u ", (unsigned) m->pos);
1212 fprintf (fp, "%u ", (unsigned) m->vis);
1213 putc (' ', fp);
1214 putstr (m->def_filename, fp);
1215 putstr (m->def_regexp, fp);
1216 fprintf (fp, "%u", (unsigned) m->def_pos);
1217 putc (']', fp);
1218 putc ('\n', fp);
1221 putc (')', fp);
1222 putc ('\n', fp);
1223 return n;
1227 /* Dump class ROOT to stream FP. */
1229 static void
1230 dump_sym (FILE *fp, struct sym *root)
1232 fputs (CLASS_STRUCT, fp);
1233 putstr (root->name, fp);
1235 /* Print scope, if any. */
1236 if (root->namesp)
1237 putstr (sym_scope (root), fp);
1238 else
1239 putstr (NULL, fp);
1241 /* Print flags. */
1242 fprintf (fp, "%u", root->flags);
1243 putstr (root->filename, fp);
1244 putstr (root->regexp, fp);
1245 fprintf (fp, "%u", (unsigned) root->pos);
1246 putstr (root->sfilename, fp);
1247 putc (']', fp);
1248 putc ('\n', fp);
1252 /* Dump class ROOT and its subclasses to file FP. Value is the
1253 number of classes written. */
1255 static int
1256 dump_tree (FILE *fp, struct sym *root)
1258 struct link *lk;
1259 unsigned n = 0;
1261 dump_sym (fp, root);
1263 if (f_verbose)
1265 putchar ('+');
1266 fflush (stdout);
1269 putc ('(', fp);
1271 for (lk = root->subs; lk; lk = lk->next)
1273 fputs (TREE_STRUCT, fp);
1274 n += dump_tree (fp, lk->sym);
1275 putc (']', fp);
1278 putc (')', fp);
1280 dump_members (fp, root->vars);
1281 n += dump_members (fp, root->fns);
1282 dump_members (fp, root->static_vars);
1283 n += dump_members (fp, root->static_fns);
1284 n += dump_members (fp, root->friends);
1285 dump_members (fp, root->types);
1287 /* Superclasses. */
1288 putc ('(', fp);
1289 putc (')', fp);
1291 /* Mark slot. */
1292 putc ('(', fp);
1293 putc (')', fp);
1295 putc ('\n', fp);
1296 return n;
1300 /* Dump the entire class tree to file FP. */
1302 static void
1303 dump_roots (FILE *fp)
1305 int i, n = 0;
1306 struct sym *r;
1308 /* Output file header containing version string, command line
1309 options etc. */
1310 if (!f_append)
1312 fputs (TREE_HEADER_STRUCT, fp);
1313 putstr (EBROWSE_FILE_VERSION, fp);
1315 putc ('\"', fp);
1316 if (!f_structs)
1317 fputs (" -s", fp);
1318 if (f_regexps)
1319 fputs (" -x", fp);
1320 putc ('\"', fp);
1321 fputs (" ()", fp);
1322 fputs (" ()", fp);
1323 putc (']', fp);
1326 /* Mark functions as virtual that are so because of functions
1327 declared virtual in base classes. */
1328 mark_inherited_virtual ();
1330 /* Dump the roots of the graph. */
1331 for (i = 0; i < TABLE_SIZE; ++i)
1332 for (r = class_table[i]; r; r = r->next)
1333 if (!r->supers)
1335 fputs (TREE_STRUCT, fp);
1336 n += dump_tree (fp, r);
1337 putc (']', fp);
1340 if (f_verbose)
1341 putchar ('\n');
1346 /***********************************************************************
1347 Scanner
1348 ***********************************************************************/
1350 #ifdef DEBUG
1351 #define INCREMENT_LINENO \
1352 do { \
1353 if (f_very_verbose) \
1355 ++yyline; \
1356 printf ("%d:\n", yyline); \
1358 else \
1359 ++yyline; \
1360 } while (0)
1361 #else
1362 #define INCREMENT_LINENO ++yyline
1363 #endif
1365 /* Define two macros for accessing the input buffer (current input
1366 file). GET(C) sets C to the next input character and advances the
1367 input pointer. UNGET retracts the input pointer. */
1369 #define GET(C) ((C) = *in++)
1370 #define UNGET() (--in)
1373 /* Process a preprocessor line. Value is the next character from the
1374 input buffer not consumed. */
1376 static int
1377 process_pp_line (void)
1379 int in_comment = 0, in_string = 0;
1380 int c;
1381 char *p = yytext;
1383 /* Skip over white space. The `#' has been consumed already. */
1384 while (WHITEP (GET (c)))
1387 /* Read the preprocessor command (if any). */
1388 while (IDENTP (c))
1390 *p++ = c;
1391 GET (c);
1394 /* Is it a `define'? */
1395 *p = '\0';
1397 if (*yytext && streq (yytext, "define"))
1399 p = yytext;
1400 while (WHITEP (c))
1401 GET (c);
1402 while (IDENTP (c))
1404 *p++ = c;
1405 GET (c);
1408 *p = '\0';
1410 if (*yytext)
1412 char *regexp = matching_regexp ();
1413 int pos = BUFFER_POS ();
1414 add_define (yytext, regexp, pos);
1418 while (c && (c != '\n' || in_comment || in_string))
1420 if (c == '\\')
1421 GET (c);
1422 else if (c == '/' && !in_comment)
1424 if (GET (c) == '*')
1425 in_comment = 1;
1427 else if (c == '*' && in_comment)
1429 if (GET (c) == '/')
1430 in_comment = 0;
1432 else if (c == '"')
1433 in_string = !in_string;
1435 if (c == '\n')
1436 INCREMENT_LINENO;
1438 GET (c);
1441 return c;
1445 /* Value is the next token from the input buffer. */
1447 static int
1448 yylex (void)
1450 int c;
1451 char end_char;
1452 char *p;
1454 for (;;)
1456 while (WHITEP (GET (c)))
1459 switch (c)
1461 case '\n':
1462 INCREMENT_LINENO;
1463 break;
1465 case '\r':
1466 break;
1468 case 0:
1469 /* End of file. */
1470 return YYEOF;
1472 case '\\':
1473 GET (c);
1474 break;
1476 case '"':
1477 case '\'':
1478 /* String and character constants. */
1479 end_char = c;
1480 string_start = in;
1481 while (GET (c) && c != end_char)
1483 switch (c)
1485 case '\\':
1486 /* Escape sequences. */
1487 if (!GET (c))
1489 if (end_char == '\'')
1490 yyerror ("EOF in character constant", NULL);
1491 else
1492 yyerror ("EOF in string constant", NULL);
1493 goto end_string;
1495 else switch (c)
1497 case '\n':
1498 INCREMENT_LINENO;
1499 case 'a':
1500 case 'b':
1501 case 'f':
1502 case 'n':
1503 case 'r':
1504 case 't':
1505 case 'v':
1506 break;
1508 case 'x':
1510 /* Hexadecimal escape sequence. */
1511 int i;
1512 for (i = 0; i < 2; ++i)
1514 GET (c);
1516 if (c >= '0' && c <= '7')
1518 else if (c >= 'a' && c <= 'f')
1520 else if (c >= 'A' && c <= 'F')
1522 else
1524 UNGET ();
1525 break;
1529 break;
1531 case '0':
1533 /* Octal escape sequence. */
1534 int i;
1535 for (i = 0; i < 3; ++i)
1537 GET (c);
1539 if (c >= '0' && c <= '7')
1541 else
1543 UNGET ();
1544 break;
1548 break;
1550 default:
1551 break;
1553 break;
1555 case '\n':
1556 if (end_char == '\'')
1557 yyerror ("newline in character constant", NULL);
1558 else
1559 yyerror ("newline in string constant", NULL);
1560 INCREMENT_LINENO;
1561 break;
1563 default:
1564 break;
1568 end_string:
1569 return end_char == '\'' ? CCHAR : CSTRING;
1571 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1572 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1573 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1574 case 'v': case 'w': case 'x': case 'y': case 'z':
1575 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1576 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1577 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1578 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1580 /* Identifier and keywords. */
1581 unsigned hash;
1582 struct kw *k;
1584 p = yytext;
1585 *p++ = hash = c;
1587 while (IDENTP (GET (*p)))
1589 hash = (hash << 1) ^ *p++;
1590 if (p == yytext_end - 1)
1592 int size = yytext_end - yytext;
1593 yytext = (char *) xrealloc (yytext, 2 * size);
1594 yytext_end = yytext + 2 * size;
1595 p = yytext + size - 1;
1599 UNGET ();
1600 *p = 0;
1602 for (k = keyword_table[hash % KEYWORD_TABLE_SIZE]; k; k = k->next)
1603 if (streq (k->name, yytext))
1604 return k->tk;
1606 return IDENT;
1609 case '/':
1610 /* C and C++ comments, '/' and '/='. */
1611 switch (GET (c))
1613 case '*':
1614 while (GET (c))
1616 switch (c)
1618 case '*':
1619 if (GET (c) == '/')
1620 goto comment_end;
1621 UNGET ();
1622 break;
1623 case '\\':
1624 GET (c);
1625 break;
1626 case '\n':
1627 INCREMENT_LINENO;
1628 break;
1631 comment_end:;
1632 break;
1634 case '=':
1635 return DIVASGN;
1637 case '/':
1638 while (GET (c) && c != '\n')
1640 /* Don't try to read past the end of the input buffer if
1641 the file ends in a C++ comment without a newline. */
1642 if (c == 0)
1643 return YYEOF;
1645 INCREMENT_LINENO;
1646 break;
1648 default:
1649 UNGET ();
1650 return '/';
1652 break;
1654 case '+':
1655 if (GET (c) == '+')
1656 return INC;
1657 else if (c == '=')
1658 return ADDASGN;
1659 UNGET ();
1660 return '+';
1662 case '-':
1663 switch (GET (c))
1665 case '-':
1666 return DEC;
1667 case '>':
1668 if (GET (c) == '*')
1669 return ARROWSTAR;
1670 UNGET ();
1671 return ARROW;
1672 case '=':
1673 return SUBASGN;
1675 UNGET ();
1676 return '-';
1678 case '*':
1679 if (GET (c) == '=')
1680 return MULASGN;
1681 UNGET ();
1682 return '*';
1684 case '%':
1685 if (GET (c) == '=')
1686 return MODASGN;
1687 UNGET ();
1688 return '%';
1690 case '|':
1691 if (GET (c) == '|')
1692 return LOR;
1693 else if (c == '=')
1694 return ORASGN;
1695 UNGET ();
1696 return '|';
1698 case '&':
1699 if (GET (c) == '&')
1700 return LAND;
1701 else if (c == '=')
1702 return ANDASGN;
1703 UNGET ();
1704 return '&';
1706 case '^':
1707 if (GET (c) == '=')
1708 return XORASGN;
1709 UNGET ();
1710 return '^';
1712 case '.':
1713 if (GET (c) == '*')
1714 return POINTSTAR;
1715 else if (c == '.')
1717 if (GET (c) != '.')
1718 yyerror ("invalid token '..' ('...' assumed)", NULL);
1719 UNGET ();
1720 return ELLIPSIS;
1722 else if (!DIGITP (c))
1724 UNGET ();
1725 return '.';
1727 goto mantissa;
1729 case ':':
1730 if (GET (c) == ':')
1731 return DCOLON;
1732 UNGET ();
1733 return ':';
1735 case '=':
1736 if (GET (c) == '=')
1737 return EQ;
1738 UNGET ();
1739 return '=';
1741 case '!':
1742 if (GET (c) == '=')
1743 return NE;
1744 UNGET ();
1745 return '!';
1747 case '<':
1748 switch (GET (c))
1750 case '=':
1751 return LE;
1752 case '<':
1753 if (GET (c) == '=')
1754 return LSHIFTASGN;
1755 UNGET ();
1756 return LSHIFT;
1758 UNGET ();
1759 return '<';
1761 case '>':
1762 switch (GET (c))
1764 case '=':
1765 return GE;
1766 case '>':
1767 if (GET (c) == '=')
1768 return RSHIFTASGN;
1769 UNGET ();
1770 return RSHIFT;
1772 UNGET ();
1773 return '>';
1775 case '#':
1776 c = process_pp_line ();
1777 if (c == 0)
1778 return YYEOF;
1779 break;
1781 case '(': case ')': case '[': case ']': case '{': case '}':
1782 case ';': case ',': case '?': case '~':
1783 return c;
1785 case '0':
1786 yyival = 0;
1788 if (GET (c) == 'x' || c == 'X')
1790 while (GET (c))
1792 if (DIGITP (c))
1793 yyival = yyival * 16 + c - '0';
1794 else if (c >= 'a' && c <= 'f')
1795 yyival = yyival * 16 + c - 'a' + 10;
1796 else if (c >= 'A' && c <= 'F')
1797 yyival = yyival * 16 + c - 'A' + 10;
1798 else
1799 break;
1802 goto int_suffixes;
1804 else if (c == '.')
1805 goto mantissa;
1807 while (c >= '0' && c <= '7')
1809 yyival = (yyival << 3) + c - '0';
1810 GET (c);
1813 int_suffixes:
1814 /* Integer suffixes. */
1815 while (isalpha (c))
1816 GET (c);
1817 UNGET ();
1818 return CINT;
1820 case '1': case '2': case '3': case '4': case '5': case '6':
1821 case '7': case '8': case '9':
1822 /* Integer or floating constant, part before '.'. */
1823 yyival = c - '0';
1825 while (GET (c) && DIGITP (c))
1826 yyival = 10 * yyival + c - '0';
1828 if (c != '.')
1829 goto int_suffixes;
1831 mantissa:
1832 /* Digits following '.'. */
1833 while (DIGITP (c))
1834 GET (c);
1836 /* Optional exponent. */
1837 if (c == 'E' || c == 'e')
1839 if (GET (c) == '-' || c == '+')
1840 GET (c);
1842 while (DIGITP (c))
1843 GET (c);
1846 /* Optional type suffixes. */
1847 while (isalpha (c))
1848 GET (c);
1849 UNGET ();
1850 return CFLOAT;
1852 default:
1853 break;
1859 /* Actually local to matching_regexp. These variables must be in
1860 global scope for the case that `static' get's defined away. */
1862 static char *matching_regexp_buffer, *matching_regexp_end_buf;
1865 /* Value is the string from the start of the line to the current
1866 position in the input buffer, or maybe a bit more if that string is
1867 shorter than min_regexp. */
1869 static char *
1870 matching_regexp (void)
1872 char *p;
1873 char *s;
1874 char *t;
1876 if (!f_regexps)
1877 return NULL;
1879 if (matching_regexp_buffer == NULL)
1881 matching_regexp_buffer = (char *) xmalloc (max_regexp);
1882 matching_regexp_end_buf = &matching_regexp_buffer[max_regexp] - 1;
1885 /* Scan back to previous newline of buffer start. */
1886 for (p = in - 1; p > inbuffer && *p != '\n'; --p)
1889 if (*p == '\n')
1891 while (in - p < min_regexp && p > inbuffer)
1893 /* Line probably not significant enough */
1894 for (--p; p > inbuffer && *p != '\n'; --p)
1897 if (*p == '\n')
1898 ++p;
1901 /* Copy from end to make sure significant portions are included.
1902 This implies that in the browser a regular expressing of the form
1903 `^.*{regexp}' has to be used. */
1904 for (s = matching_regexp_end_buf - 1, t = in;
1905 s > matching_regexp_buffer && t > p;)
1907 *--s = *--t;
1909 if (*s == '"' || *s == '\\')
1910 *--s = '\\';
1913 *(matching_regexp_end_buf - 1) = '\0';
1914 return xstrdup (s);
1918 /* Return a printable representation of token T. */
1920 static const char *
1921 token_string (int t)
1923 static char b[3];
1925 switch (t)
1927 case CSTRING: return "string constant";
1928 case CCHAR: return "char constant";
1929 case CINT: return "int constant";
1930 case CFLOAT: return "floating constant";
1931 case ELLIPSIS: return "...";
1932 case LSHIFTASGN: return "<<=";
1933 case RSHIFTASGN: return ">>=";
1934 case ARROWSTAR: return "->*";
1935 case IDENT: return "identifier";
1936 case DIVASGN: return "/=";
1937 case INC: return "++";
1938 case ADDASGN: return "+=";
1939 case DEC: return "--";
1940 case ARROW: return "->";
1941 case SUBASGN: return "-=";
1942 case MULASGN: return "*=";
1943 case MODASGN: return "%=";
1944 case LOR: return "||";
1945 case ORASGN: return "|=";
1946 case LAND: return "&&";
1947 case ANDASGN: return "&=";
1948 case XORASGN: return "^=";
1949 case POINTSTAR: return ".*";
1950 case DCOLON: return "::";
1951 case EQ: return "==";
1952 case NE: return "!=";
1953 case LE: return "<=";
1954 case LSHIFT: return "<<";
1955 case GE: return ">=";
1956 case RSHIFT: return ">>";
1957 case ASM: return "asm";
1958 case AUTO: return "auto";
1959 case BREAK: return "break";
1960 case CASE: return "case";
1961 case CATCH: return "catch";
1962 case CHAR: return "char";
1963 case CLASS: return "class";
1964 case CONST: return "const";
1965 case CONTINUE: return "continue";
1966 case DEFAULT: return "default";
1967 case DELETE: return "delete";
1968 case DO: return "do";
1969 case DOUBLE: return "double";
1970 case ELSE: return "else";
1971 case ENUM: return "enum";
1972 case EXTERN: return "extern";
1973 case FLOAT: return "float";
1974 case FOR: return "for";
1975 case FRIEND: return "friend";
1976 case GOTO: return "goto";
1977 case IF: return "if";
1978 case T_INLINE: return "inline";
1979 case INT: return "int";
1980 case LONG: return "long";
1981 case NEW: return "new";
1982 case OPERATOR: return "operator";
1983 case PRIVATE: return "private";
1984 case PROTECTED: return "protected";
1985 case PUBLIC: return "public";
1986 case REGISTER: return "register";
1987 case RETURN: return "return";
1988 case SHORT: return "short";
1989 case SIGNED: return "signed";
1990 case SIZEOF: return "sizeof";
1991 case STATIC: return "static";
1992 case STRUCT: return "struct";
1993 case SWITCH: return "switch";
1994 case TEMPLATE: return "template";
1995 case THIS: return "this";
1996 case THROW: return "throw";
1997 case TRY: return "try";
1998 case TYPEDEF: return "typedef";
1999 case UNION: return "union";
2000 case UNSIGNED: return "unsigned";
2001 case VIRTUAL: return "virtual";
2002 case VOID: return "void";
2003 case VOLATILE: return "volatile";
2004 case WHILE: return "while";
2005 case MUTABLE: return "mutable";
2006 case BOOL: return "bool";
2007 case TRUE: return "true";
2008 case FALSE: return "false";
2009 case SIGNATURE: return "signature";
2010 case NAMESPACE: return "namespace";
2011 case EXPLICIT: return "explicit";
2012 case TYPENAME: return "typename";
2013 case CONST_CAST: return "const_cast";
2014 case DYNAMIC_CAST: return "dynamic_cast";
2015 case REINTERPRET_CAST: return "reinterpret_cast";
2016 case STATIC_CAST: return "static_cast";
2017 case TYPEID: return "typeid";
2018 case USING: return "using";
2019 case WCHAR: return "wchar_t";
2020 case YYEOF: return "EOF";
2022 default:
2023 if (t < 255)
2025 b[0] = t;
2026 b[1] = '\0';
2027 return b;
2029 else
2030 return "???";
2035 /* Reinitialize the scanner for a new input file. */
2037 static void
2038 re_init_scanner (void)
2040 in = inbuffer;
2041 yyline = 1;
2043 if (yytext == NULL)
2045 int size = 256;
2046 yytext = (char *) xmalloc (size * sizeof *yytext);
2047 yytext_end = yytext + size;
2052 /* Insert a keyword NAME with token value TKV into the keyword hash
2053 table. */
2055 static void
2056 insert_keyword (const char *name, int tkv)
2058 const char *s;
2059 unsigned h = 0;
2060 struct kw *k = (struct kw *) xmalloc (sizeof *k);
2062 for (s = name; *s; ++s)
2063 h = (h << 1) ^ *s;
2065 h %= KEYWORD_TABLE_SIZE;
2066 k->name = name;
2067 k->tk = tkv;
2068 k->next = keyword_table[h];
2069 keyword_table[h] = k;
2073 /* Initialize the scanner for the first file. This sets up the
2074 character class vectors and fills the keyword hash table. */
2076 static void
2077 init_scanner (void)
2079 int i;
2081 /* Allocate the input buffer */
2082 inbuffer_size = READ_CHUNK_SIZE + 1;
2083 inbuffer = in = (char *) xmalloc (inbuffer_size);
2084 yyline = 1;
2086 /* Set up character class vectors. */
2087 for (i = 0; i < sizeof is_ident; ++i)
2089 if (i == '_' || isalnum (i))
2090 is_ident[i] = 1;
2092 if (i >= '0' && i <= '9')
2093 is_digit[i] = 1;
2095 if (i == ' ' || i == '\t' || i == '\f' || i == '\v')
2096 is_white[i] = 1;
2099 /* Fill keyword hash table. */
2100 insert_keyword ("and", LAND);
2101 insert_keyword ("and_eq", ANDASGN);
2102 insert_keyword ("asm", ASM);
2103 insert_keyword ("auto", AUTO);
2104 insert_keyword ("bitand", '&');
2105 insert_keyword ("bitor", '|');
2106 insert_keyword ("bool", BOOL);
2107 insert_keyword ("break", BREAK);
2108 insert_keyword ("case", CASE);
2109 insert_keyword ("catch", CATCH);
2110 insert_keyword ("char", CHAR);
2111 insert_keyword ("class", CLASS);
2112 insert_keyword ("compl", '~');
2113 insert_keyword ("const", CONST);
2114 insert_keyword ("const_cast", CONST_CAST);
2115 insert_keyword ("continue", CONTINUE);
2116 insert_keyword ("default", DEFAULT);
2117 insert_keyword ("delete", DELETE);
2118 insert_keyword ("do", DO);
2119 insert_keyword ("double", DOUBLE);
2120 insert_keyword ("dynamic_cast", DYNAMIC_CAST);
2121 insert_keyword ("else", ELSE);
2122 insert_keyword ("enum", ENUM);
2123 insert_keyword ("explicit", EXPLICIT);
2124 insert_keyword ("extern", EXTERN);
2125 insert_keyword ("false", FALSE);
2126 insert_keyword ("float", FLOAT);
2127 insert_keyword ("for", FOR);
2128 insert_keyword ("friend", FRIEND);
2129 insert_keyword ("goto", GOTO);
2130 insert_keyword ("if", IF);
2131 insert_keyword ("inline", T_INLINE);
2132 insert_keyword ("int", INT);
2133 insert_keyword ("long", LONG);
2134 insert_keyword ("mutable", MUTABLE);
2135 insert_keyword ("namespace", NAMESPACE);
2136 insert_keyword ("new", NEW);
2137 insert_keyword ("not", '!');
2138 insert_keyword ("not_eq", NE);
2139 insert_keyword ("operator", OPERATOR);
2140 insert_keyword ("or", LOR);
2141 insert_keyword ("or_eq", ORASGN);
2142 insert_keyword ("private", PRIVATE);
2143 insert_keyword ("protected", PROTECTED);
2144 insert_keyword ("public", PUBLIC);
2145 insert_keyword ("register", REGISTER);
2146 insert_keyword ("reinterpret_cast", REINTERPRET_CAST);
2147 insert_keyword ("return", RETURN);
2148 insert_keyword ("short", SHORT);
2149 insert_keyword ("signed", SIGNED);
2150 insert_keyword ("sizeof", SIZEOF);
2151 insert_keyword ("static", STATIC);
2152 insert_keyword ("static_cast", STATIC_CAST);
2153 insert_keyword ("struct", STRUCT);
2154 insert_keyword ("switch", SWITCH);
2155 insert_keyword ("template", TEMPLATE);
2156 insert_keyword ("this", THIS);
2157 insert_keyword ("throw", THROW);
2158 insert_keyword ("true", TRUE);
2159 insert_keyword ("try", TRY);
2160 insert_keyword ("typedef", TYPEDEF);
2161 insert_keyword ("typeid", TYPEID);
2162 insert_keyword ("typename", TYPENAME);
2163 insert_keyword ("union", UNION);
2164 insert_keyword ("unsigned", UNSIGNED);
2165 insert_keyword ("using", USING);
2166 insert_keyword ("virtual", VIRTUAL);
2167 insert_keyword ("void", VOID);
2168 insert_keyword ("volatile", VOLATILE);
2169 insert_keyword ("wchar_t", WCHAR);
2170 insert_keyword ("while", WHILE);
2171 insert_keyword ("xor", '^');
2172 insert_keyword ("xor_eq", XORASGN);
2177 /***********************************************************************
2178 Parser
2179 ***********************************************************************/
2181 /* Match the current lookahead token and set it to the next token. */
2183 #define MATCH() (tk = yylex ())
2185 /* Return the lookahead token. If current lookahead token is cleared,
2186 read a new token. */
2188 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2190 /* Is the current lookahead equal to the token T? */
2192 #define LOOKING_AT(T) (tk == (T))
2194 /* Is the current lookahead one of T1 or T2? */
2196 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2198 /* Is the current lookahead one of T1, T2 or T3? */
2200 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2202 /* Is the current lookahead one of T1...T4? */
2204 #define LOOKING_AT4(T1, T2, T3, T4) \
2205 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2207 /* Match token T if current lookahead is T. */
2209 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2211 /* Skip to matching token if current token is T. */
2213 #define SKIP_MATCHING_IF(T) \
2214 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2217 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2218 the current lookahead token after skipping. */
2220 static int
2221 skip_to (int token)
2223 while (!LOOKING_AT2 (YYEOF, token))
2224 MATCH ();
2225 return tk;
2228 /* Skip over pairs of tokens (parentheses, square brackets,
2229 angle brackets, curly brackets) matching the current lookahead. */
2231 static void
2232 skip_matching (void)
2234 int open, close, n;
2236 switch (open = LA1)
2238 case '{':
2239 close = '}';
2240 break;
2242 case '(':
2243 close = ')';
2244 break;
2246 case '<':
2247 close = '>';
2248 break;
2250 case '[':
2251 close = ']';
2252 break;
2254 default:
2255 abort ();
2258 for (n = 0;;)
2260 if (LOOKING_AT (open))
2261 ++n;
2262 else if (LOOKING_AT (close))
2263 --n;
2264 else if (LOOKING_AT (YYEOF))
2265 break;
2267 MATCH ();
2269 if (n == 0)
2270 break;
2274 static void
2275 skip_initializer (void)
2277 for (;;)
2279 switch (LA1)
2281 case ';':
2282 case ',':
2283 case YYEOF:
2284 return;
2286 case '{':
2287 case '[':
2288 case '(':
2289 skip_matching ();
2290 break;
2292 default:
2293 MATCH ();
2294 break;
2299 /* Build qualified namespace alias (A::B::c) and return it. */
2301 static struct link *
2302 match_qualified_namespace_alias (void)
2304 struct link *head = NULL;
2305 struct link *cur = NULL;
2306 struct link *tmp = NULL;
2308 for (;;)
2310 MATCH ();
2311 switch (LA1)
2313 case IDENT:
2314 tmp = (struct link *) xmalloc (sizeof *cur);
2315 tmp->sym = find_namespace (yytext, cur ? cur->sym : NULL);
2316 tmp->next = NULL;
2317 if (head)
2319 cur = cur->next = tmp;
2321 else
2323 head = cur = tmp;
2325 break;
2326 case DCOLON:
2327 /* Just skip */
2328 break;
2329 default:
2330 return head;
2331 break;
2336 /* Re-initialize the parser by resetting the lookahead token. */
2338 static void
2339 re_init_parser (void)
2341 tk = -1;
2345 /* Parse a parameter list, including the const-specifier,
2346 pure-specifier, and throw-list that may follow a parameter list.
2347 Return in FLAGS what was seen following the parameter list.
2348 Returns a hash code for the parameter types. This value is used to
2349 distinguish between overloaded functions. */
2351 static unsigned
2352 parm_list (int *flags)
2354 unsigned hash = 0;
2355 int type_seen = 0;
2357 while (!LOOKING_AT2 (YYEOF, ')'))
2359 switch (LA1)
2361 /* Skip over grouping parens or parameter lists in parameter
2362 declarations. */
2363 case '(':
2364 skip_matching ();
2365 break;
2367 /* Next parameter. */
2368 case ',':
2369 MATCH ();
2370 type_seen = 0;
2371 break;
2373 /* Ignore the scope part of types, if any. This is because
2374 some types need scopes when defined outside of a class body,
2375 and don't need them inside the class body. This means that
2376 we have to look for the last IDENT in a sequence of
2377 IDENT::IDENT::... */
2378 case IDENT:
2379 if (!type_seen)
2381 char *last_id;
2382 unsigned ident_type_hash = 0;
2384 parse_qualified_param_ident_or_type (&last_id);
2385 if (last_id)
2387 /* LAST_ID null means something like `X::*'. */
2388 for (; *last_id; ++last_id)
2389 ident_type_hash = (ident_type_hash << 1) ^ *last_id;
2390 hash = (hash << 1) ^ ident_type_hash;
2391 type_seen = 1;
2394 else
2395 MATCH ();
2396 break;
2398 case VOID:
2399 /* This distinction is made to make `func (void)' equivalent
2400 to `func ()'. */
2401 type_seen = 1;
2402 MATCH ();
2403 if (!LOOKING_AT (')'))
2404 hash = (hash << 1) ^ VOID;
2405 break;
2407 case BOOL: case CHAR: case CLASS: case CONST:
2408 case DOUBLE: case ENUM: case FLOAT: case INT:
2409 case LONG: case SHORT: case SIGNED: case STRUCT:
2410 case UNION: case UNSIGNED: case VOLATILE: case WCHAR:
2411 case ELLIPSIS:
2412 type_seen = 1;
2413 hash = (hash << 1) ^ LA1;
2414 MATCH ();
2415 break;
2417 case '*': case '&': case '[': case ']':
2418 hash = (hash << 1) ^ LA1;
2419 MATCH ();
2420 break;
2422 default:
2423 MATCH ();
2424 break;
2428 if (LOOKING_AT (')'))
2430 MATCH ();
2432 if (LOOKING_AT (CONST))
2434 /* We can overload the same function on `const' */
2435 hash = (hash << 1) ^ CONST;
2436 SET_FLAG (*flags, F_CONST);
2437 MATCH ();
2440 if (LOOKING_AT (THROW))
2442 MATCH ();
2443 SKIP_MATCHING_IF ('(');
2444 SET_FLAG (*flags, F_THROW);
2447 if (LOOKING_AT ('='))
2449 MATCH ();
2450 if (LOOKING_AT (CINT) && yyival == 0)
2452 MATCH ();
2453 SET_FLAG (*flags, F_PURE);
2458 return hash;
2462 /* Print position info to stdout. */
2464 static void
2465 print_info (void)
2467 if (info_position >= 0 && BUFFER_POS () <= info_position)
2468 if (info_cls)
2469 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2470 info_cls->name, sym_scope (info_cls),
2471 info_member->name, info_where);
2475 /* Parse a member declaration within the class body of CLS. VIS is
2476 the access specifier for the member (private, protected,
2477 public). */
2479 static void
2480 member (struct sym *cls, int vis)
2482 char *id = NULL;
2483 int sc = SC_MEMBER;
2484 char *regexp = NULL;
2485 int pos;
2486 int is_constructor;
2487 int anonymous = 0;
2488 int flags = 0;
2489 int class_tag;
2490 int type_seen = 0;
2491 int paren_seen = 0;
2492 unsigned hash = 0;
2493 int tilde = 0;
2495 while (!LOOKING_AT4 (';', '{', '}', YYEOF))
2497 switch (LA1)
2499 default:
2500 MATCH ();
2501 break;
2503 /* A function or class may follow. */
2504 case TEMPLATE:
2505 MATCH ();
2506 SET_FLAG (flags, F_TEMPLATE);
2507 /* Skip over template argument list */
2508 SKIP_MATCHING_IF ('<');
2509 break;
2511 case EXPLICIT:
2512 SET_FLAG (flags, F_EXPLICIT);
2513 goto typeseen;
2515 case MUTABLE:
2516 SET_FLAG (flags, F_MUTABLE);
2517 goto typeseen;
2519 case T_INLINE:
2520 SET_FLAG (flags, F_INLINE);
2521 goto typeseen;
2523 case VIRTUAL:
2524 SET_FLAG (flags, F_VIRTUAL);
2525 goto typeseen;
2527 case '[':
2528 skip_matching ();
2529 break;
2531 case ENUM:
2532 sc = SC_TYPE;
2533 goto typeseen;
2535 case TYPEDEF:
2536 sc = SC_TYPE;
2537 goto typeseen;
2539 case FRIEND:
2540 sc = SC_FRIEND;
2541 goto typeseen;
2543 case STATIC:
2544 sc = SC_STATIC;
2545 goto typeseen;
2547 case '~':
2548 tilde = 1;
2549 MATCH ();
2550 break;
2552 case IDENT:
2553 /* Remember IDENTS seen so far. Among these will be the member
2554 name. */
2555 id = (char *) xrealloc (id, strlen (yytext) + 2);
2556 if (tilde)
2558 *id = '~';
2559 strcpy (id + 1, yytext);
2561 else
2562 strcpy (id, yytext);
2563 MATCH ();
2564 break;
2566 case OPERATOR:
2568 char *s = operator_name (&sc);
2569 id = (char *) xrealloc (id, strlen (s) + 1);
2570 strcpy (id, s);
2572 break;
2574 case '(':
2575 /* Most probably the beginning of a parameter list. */
2576 MATCH ();
2577 paren_seen = 1;
2579 if (id && cls)
2581 if (!(is_constructor = streq (id, cls->name)))
2582 regexp = matching_regexp ();
2584 else
2585 is_constructor = 0;
2587 pos = BUFFER_POS ();
2588 hash = parm_list (&flags);
2590 if (is_constructor)
2591 regexp = matching_regexp ();
2593 if (id && cls != NULL)
2594 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, flags);
2596 while (!LOOKING_AT3 (';', '{', YYEOF))
2597 MATCH ();
2599 if (LOOKING_AT ('{') && id && cls)
2600 add_member_defn (cls, id, regexp, pos, hash, 0, sc, flags);
2602 free (id);
2603 id = NULL;
2604 sc = SC_MEMBER;
2605 break;
2607 case STRUCT: case UNION: case CLASS:
2608 /* Nested class */
2609 class_tag = LA1;
2610 type_seen = 1;
2611 MATCH ();
2612 anonymous = 1;
2614 /* More than one ident here to allow for MS-DOS specialties
2615 like `_export class' etc. The last IDENT seen counts
2616 as the class name. */
2617 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
2619 if (LOOKING_AT (IDENT))
2620 anonymous = 0;
2621 MATCH ();
2624 if (LOOKING_AT2 (':', '{'))
2625 class_definition (anonymous ? NULL : cls, class_tag, flags, 1);
2626 else
2627 skip_to (';');
2628 break;
2630 case INT: case CHAR: case LONG: case UNSIGNED:
2631 case SIGNED: case CONST: case DOUBLE: case VOID:
2632 case SHORT: case VOLATILE: case BOOL: case WCHAR:
2633 case TYPENAME:
2634 typeseen:
2635 type_seen = 1;
2636 MATCH ();
2637 break;
2641 if (LOOKING_AT (';'))
2643 /* The end of a member variable, a friend declaration or an access
2644 declaration. We don't want to add friend classes as members. */
2645 if (id && sc != SC_FRIEND && cls)
2647 regexp = matching_regexp ();
2648 pos = BUFFER_POS ();
2650 if (cls != NULL)
2652 if (type_seen || !paren_seen)
2653 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2654 else
2655 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0);
2659 MATCH ();
2660 print_info ();
2662 else if (LOOKING_AT ('{'))
2664 /* A named enum. */
2665 if (sc == SC_TYPE && id && cls)
2667 regexp = matching_regexp ();
2668 pos = BUFFER_POS ();
2670 if (cls != NULL)
2672 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2673 add_member_defn (cls, id, regexp, pos, 0, 1, sc, 0);
2677 skip_matching ();
2678 print_info ();
2681 free (id);
2685 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2686 union, class). */
2688 static void
2689 class_body (struct sym *cls, int tag)
2691 int vis = tag == CLASS ? PRIVATE : PUBLIC;
2692 int temp;
2694 while (!LOOKING_AT2 (YYEOF, '}'))
2696 switch (LA1)
2698 case PRIVATE: case PROTECTED: case PUBLIC:
2699 temp = LA1;
2700 MATCH ();
2702 if (LOOKING_AT (':'))
2704 vis = temp;
2705 MATCH ();
2707 else
2709 /* Probably conditional compilation for inheritance list.
2710 We don't known whether there comes more of this.
2711 This is only a crude fix that works most of the time. */
2714 MATCH ();
2716 while (LOOKING_AT2 (IDENT, ',')
2717 || LOOKING_AT3 (PUBLIC, PROTECTED, PRIVATE));
2719 break;
2721 case TYPENAME:
2722 case USING:
2723 skip_to (';');
2724 break;
2726 /* Try to synchronize */
2727 case CHAR: case CLASS: case CONST:
2728 case DOUBLE: case ENUM: case FLOAT: case INT:
2729 case LONG: case SHORT: case SIGNED: case STRUCT:
2730 case UNION: case UNSIGNED: case VOID: case VOLATILE:
2731 case TYPEDEF: case STATIC: case T_INLINE: case FRIEND:
2732 case VIRTUAL: case TEMPLATE: case IDENT: case '~':
2733 case BOOL: case WCHAR: case EXPLICIT: case MUTABLE:
2734 member (cls, vis);
2735 break;
2737 default:
2738 MATCH ();
2739 break;
2745 /* Parse a qualified identifier. Current lookahead is IDENT. A
2746 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2747 symbol for that class. */
2749 static struct sym *
2750 parse_classname (void)
2752 struct sym *last_class = NULL;
2754 while (LOOKING_AT (IDENT))
2756 last_class = add_sym (yytext, last_class);
2757 MATCH ();
2759 if (LOOKING_AT ('<'))
2761 skip_matching ();
2762 SET_FLAG (last_class->flags, F_TEMPLATE);
2765 if (!LOOKING_AT (DCOLON))
2766 break;
2768 MATCH ();
2771 return last_class;
2775 /* Parse an operator name. Add the `static' flag to *SC if an
2776 implicitly static operator has been parsed. Value is a pointer to
2777 a static buffer holding the constructed operator name string. */
2779 static char *
2780 operator_name (int *sc)
2782 static size_t id_size = 0;
2783 static char *id = NULL;
2784 const char *s;
2785 size_t len;
2787 MATCH ();
2789 if (LOOKING_AT2 (NEW, DELETE))
2791 /* `new' and `delete' are implicitly static. */
2792 if (*sc != SC_FRIEND)
2793 *sc = SC_STATIC;
2795 s = token_string (LA1);
2796 MATCH ();
2798 len = strlen (s) + 10;
2799 if (len > id_size)
2801 size_t new_size = max (len, 2 * id_size);
2802 id = (char *) xrealloc (id, new_size);
2803 id_size = new_size;
2805 strcpy (id, s);
2807 /* Vector new or delete? */
2808 if (LOOKING_AT ('['))
2810 strcat (id, "[");
2811 MATCH ();
2813 if (LOOKING_AT (']'))
2815 strcat (id, "]");
2816 MATCH ();
2820 else
2822 size_t tokens_matched = 0;
2824 len = 20;
2825 if (len > id_size)
2827 int new_size = max (len, 2 * id_size);
2828 id = (char *) xrealloc (id, new_size);
2829 id_size = new_size;
2831 strcpy (id, "operator");
2833 /* Beware access declarations of the form "X::f;" Beware of
2834 `operator () ()'. Yet another difficulty is found in
2835 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2836 while (!(LOOKING_AT ('(') && tokens_matched)
2837 && !LOOKING_AT2 (';', YYEOF))
2839 s = token_string (LA1);
2840 len += strlen (s) + 2;
2841 if (len > id_size)
2843 size_t new_size = max (len, 2 * id_size);
2844 id = (char *) xrealloc (id, new_size);
2845 id_size = new_size;
2848 if (*s != ')' && *s != ']')
2849 strcat (id, " ");
2850 strcat (id, s);
2851 MATCH ();
2853 /* If this is a simple operator like `+', stop now. */
2854 if (!isalpha ((unsigned char) *s) && *s != '(' && *s != '[')
2855 break;
2857 ++tokens_matched;
2861 return id;
2865 /* This one consumes the last IDENT of a qualified member name like
2866 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2867 symbol structure for the ident. */
2869 static struct sym *
2870 parse_qualified_ident_or_type (char **last_id)
2872 struct sym *cls = NULL;
2873 char *id = NULL;
2874 size_t id_size = 0;
2875 int enter = 0;
2877 while (LOOKING_AT (IDENT))
2879 int len = strlen (yytext) + 1;
2880 if (len > id_size)
2882 id = (char *) xrealloc (id, len);
2883 id_size = len;
2885 strcpy (id, yytext);
2886 *last_id = id;
2887 MATCH ();
2889 SKIP_MATCHING_IF ('<');
2891 if (LOOKING_AT (DCOLON))
2893 struct sym *pcn = NULL;
2894 struct link *pna = check_namespace_alias (id);
2895 if (pna)
2899 enter_namespace (pna->sym->name);
2900 enter++;
2901 pna = pna->next;
2903 while (pna);
2905 else if ((pcn = check_namespace (id, current_namespace)))
2907 enter_namespace (pcn->name);
2908 enter++;
2910 else
2911 cls = add_sym (id, cls);
2913 *last_id = NULL;
2914 free (id);
2915 id = NULL;
2916 id_size = 0;
2917 MATCH ();
2919 else
2920 break;
2923 while (enter--)
2924 leave_namespace ();
2926 return cls;
2930 /* This one consumes the last IDENT of a qualified member name like
2931 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2932 symbol structure for the ident. */
2934 static void
2935 parse_qualified_param_ident_or_type (char **last_id)
2937 struct sym *cls = NULL;
2938 static char *id = NULL;
2939 static int id_size = 0;
2941 assert (LOOKING_AT (IDENT));
2945 int len = strlen (yytext) + 1;
2946 if (len > id_size)
2948 id = (char *) xrealloc (id, len);
2949 id_size = len;
2951 strcpy (id, yytext);
2952 *last_id = id;
2953 MATCH ();
2955 SKIP_MATCHING_IF ('<');
2957 if (LOOKING_AT (DCOLON))
2959 cls = add_sym (id, cls);
2960 *last_id = NULL;
2961 MATCH ();
2963 else
2964 break;
2966 while (LOOKING_AT (IDENT));
2970 /* Parse a class definition.
2972 CONTAINING is the class containing the class being parsed or null.
2973 This may also be null if NESTED != 0 if the containing class is
2974 anonymous. TAG is the tag of the class (struct, union, class).
2975 NESTED is non-zero if we are parsing a nested class.
2977 Current lookahead is the class name. */
2979 static void
2980 class_definition (struct sym *containing, int tag, int flags, int nested)
2982 struct sym *current;
2983 struct sym *base_class;
2985 /* Set CURRENT to null if no entry has to be made for the class
2986 parsed. This is the case for certain command line flag
2987 settings. */
2988 if ((tag != CLASS && !f_structs) || (nested && !f_nested_classes))
2989 current = NULL;
2990 else
2992 current = add_sym (yytext, containing);
2993 current->pos = BUFFER_POS ();
2994 current->regexp = matching_regexp ();
2995 current->filename = filename;
2996 current->flags = flags;
2999 /* If at ':', base class list follows. */
3000 if (LOOKING_AT (':'))
3002 int done = 0;
3003 MATCH ();
3005 while (!done)
3007 switch (LA1)
3009 case VIRTUAL: case PUBLIC: case PROTECTED: case PRIVATE:
3010 MATCH ();
3011 break;
3013 case IDENT:
3014 base_class = parse_classname ();
3015 if (base_class && current && base_class != current)
3016 add_link (base_class, current);
3017 break;
3019 /* The `,' between base classes or the end of the base
3020 class list. Add the previously found base class.
3021 It's done this way to skip over sequences of
3022 `A::B::C' until we reach the end.
3024 FIXME: it is now possible to handle `class X : public B::X'
3025 because we have enough information. */
3026 case ',':
3027 MATCH ();
3028 break;
3030 default:
3031 /* A syntax error, possibly due to preprocessor constructs
3032 like
3034 #ifdef SOMETHING
3035 class A : public B
3036 #else
3037 class A : private B.
3039 MATCH until we see something like `;' or `{'. */
3040 while (!LOOKING_AT3 (';', YYEOF, '{'))
3041 MATCH ();
3042 done = 1;
3044 case '{':
3045 done = 1;
3046 break;
3051 /* Parse the class body if there is one. */
3052 if (LOOKING_AT ('{'))
3054 if (tag != CLASS && !f_structs)
3055 skip_matching ();
3056 else
3058 MATCH ();
3059 class_body (current, tag);
3061 if (LOOKING_AT ('}'))
3063 MATCH ();
3064 if (LOOKING_AT (';') && !nested)
3065 MATCH ();
3071 /* Add to class *CLS information for the declaration of variable or
3072 type *ID. If *CLS is null, this means a global declaration. SC is
3073 the storage class of *ID. FLAGS is a bit set giving additional
3074 information about the member (see the F_* defines). */
3076 static void
3077 add_declarator (struct sym **cls, char **id, int flags, int sc)
3079 if (LOOKING_AT2 (';', ','))
3081 /* The end of a member variable or of an access declaration
3082 `X::f'. To distinguish between them we have to know whether
3083 type information has been seen. */
3084 if (*id)
3086 char *regexp = matching_regexp ();
3087 int pos = BUFFER_POS ();
3089 if (*cls)
3090 add_member_defn (*cls, *id, regexp, pos, 0, 1, SC_UNKNOWN, flags);
3091 else
3092 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3095 MATCH ();
3096 print_info ();
3098 else if (LOOKING_AT ('{'))
3100 if (sc == SC_TYPE && *id)
3102 /* A named enumeration. */
3103 char *regexp = matching_regexp ();
3104 int pos = BUFFER_POS ();
3105 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3108 skip_matching ();
3109 print_info ();
3112 free (*id);
3113 *id = NULL;
3114 *cls = NULL;
3117 /* Parse a declaration. */
3119 static void
3120 declaration (int flags)
3122 char *id = NULL;
3123 struct sym *cls = NULL;
3124 char *regexp = NULL;
3125 int pos = 0;
3126 unsigned hash = 0;
3127 int is_constructor;
3128 int sc = 0;
3130 while (!LOOKING_AT3 (';', '{', YYEOF))
3132 switch (LA1)
3134 default:
3135 MATCH ();
3136 break;
3138 case '[':
3139 skip_matching ();
3140 break;
3142 case ENUM:
3143 case TYPEDEF:
3144 sc = SC_TYPE;
3145 MATCH ();
3146 break;
3148 case STATIC:
3149 sc = SC_STATIC;
3150 MATCH ();
3151 break;
3153 case INT: case CHAR: case LONG: case UNSIGNED:
3154 case SIGNED: case CONST: case DOUBLE: case VOID:
3155 case SHORT: case VOLATILE: case BOOL: case WCHAR:
3156 MATCH ();
3157 break;
3159 case CLASS: case STRUCT: case UNION:
3160 /* This is for the case `STARTWRAP class X : ...' or
3161 `declare (X, Y)\n class A : ...'. */
3162 if (id)
3164 free (id);
3165 return;
3168 case '=':
3169 /* Assumed to be the start of an initialization in this
3170 context. */
3171 skip_initializer ();
3172 break;
3174 case ',':
3175 add_declarator (&cls, &id, flags, sc);
3176 break;
3178 case OPERATOR:
3180 char *s = operator_name (&sc);
3181 id = (char *) xrealloc (id, strlen (s) + 1);
3182 strcpy (id, s);
3184 break;
3186 case T_INLINE:
3187 SET_FLAG (flags, F_INLINE);
3188 MATCH ();
3189 break;
3191 case '~':
3192 MATCH ();
3193 if (LOOKING_AT (IDENT))
3195 id = (char *) xrealloc (id, strlen (yytext) + 2);
3196 *id = '~';
3197 strcpy (id + 1, yytext);
3198 MATCH ();
3200 break;
3202 case IDENT:
3203 cls = parse_qualified_ident_or_type (&id);
3204 break;
3206 case '(':
3207 /* Most probably the beginning of a parameter list. */
3208 if (cls)
3210 MATCH ();
3212 if (id && cls)
3214 if (!(is_constructor = streq (id, cls->name)))
3215 regexp = matching_regexp ();
3217 else
3218 is_constructor = 0;
3220 pos = BUFFER_POS ();
3221 hash = parm_list (&flags);
3223 if (is_constructor)
3224 regexp = matching_regexp ();
3226 if (id && cls)
3227 add_member_defn (cls, id, regexp, pos, hash, 0,
3228 SC_UNKNOWN, flags);
3230 else
3232 /* This may be a C functions, but also a macro
3233 call of the form `declare (A, B)' --- such macros
3234 can be found in some class libraries. */
3235 MATCH ();
3237 if (id)
3239 regexp = matching_regexp ();
3240 pos = BUFFER_POS ();
3241 hash = parm_list (&flags);
3242 add_global_decl (id, regexp, pos, hash, 0, sc, flags);
3245 /* This is for the case that the function really is
3246 a macro with no `;' following it. If a CLASS directly
3247 follows, we would miss it otherwise. */
3248 if (LOOKING_AT3 (CLASS, STRUCT, UNION))
3249 return;
3252 while (!LOOKING_AT3 (';', '{', YYEOF))
3253 MATCH ();
3255 if (!cls && id && LOOKING_AT ('{'))
3256 add_global_defn (id, regexp, pos, hash, 0, sc, flags);
3258 free (id);
3259 id = NULL;
3260 break;
3264 add_declarator (&cls, &id, flags, sc);
3268 /* Parse a list of top-level declarations/definitions. START_FLAGS
3269 says in which context we are parsing. If it is F_EXTERNC, we are
3270 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3271 otherwise. */
3273 static int
3274 globals (int start_flags)
3276 int anonymous;
3277 int class_tk;
3278 int flags = start_flags;
3280 for (;;)
3282 char *prev_in = in;
3284 switch (LA1)
3286 case NAMESPACE:
3288 MATCH ();
3290 if (LOOKING_AT (IDENT))
3292 char *namespace_name = xstrdup (yytext);
3293 MATCH ();
3295 if (LOOKING_AT ('='))
3297 struct link *qna = match_qualified_namespace_alias ();
3298 if (qna)
3299 register_namespace_alias (namespace_name, qna);
3301 if (skip_to (';') == ';')
3302 MATCH ();
3304 else if (LOOKING_AT ('{'))
3306 MATCH ();
3307 enter_namespace (namespace_name);
3308 globals (0);
3309 leave_namespace ();
3310 MATCH_IF ('}');
3313 free (namespace_name);
3316 break;
3318 case EXTERN:
3319 MATCH ();
3320 if (LOOKING_AT (CSTRING) && *string_start == 'C'
3321 && *(string_start + 1) == '"')
3323 /* This is `extern "C"'. */
3324 MATCH ();
3326 if (LOOKING_AT ('{'))
3328 MATCH ();
3329 globals (F_EXTERNC);
3330 MATCH_IF ('}');
3332 else
3333 SET_FLAG (flags, F_EXTERNC);
3335 break;
3337 case TEMPLATE:
3338 MATCH ();
3339 SKIP_MATCHING_IF ('<');
3340 SET_FLAG (flags, F_TEMPLATE);
3341 break;
3343 case CLASS: case STRUCT: case UNION:
3344 class_tk = LA1;
3345 MATCH ();
3346 anonymous = 1;
3348 /* More than one ident here to allow for MS-DOS and OS/2
3349 specialties like `far', `_Export' etc. Some C++ libs
3350 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3351 of the class name. */
3352 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
3354 if (LOOKING_AT (IDENT))
3355 anonymous = 0;
3356 MATCH ();
3359 /* Don't add anonymous unions. */
3360 if (LOOKING_AT2 (':', '{') && !anonymous)
3361 class_definition (NULL, class_tk, flags, 0);
3362 else
3364 if (skip_to (';') == ';')
3365 MATCH ();
3368 flags = start_flags;
3369 break;
3371 case YYEOF:
3372 return 1;
3374 case '}':
3375 return 0;
3377 default:
3378 declaration (flags);
3379 flags = start_flags;
3380 break;
3383 if (prev_in == in)
3384 yyerror ("parse error", NULL);
3389 /* Parse the current input file. */
3391 static void
3392 yyparse (void)
3394 while (globals (0) == 0)
3395 MATCH_IF ('}');
3400 /***********************************************************************
3401 Main Program
3402 ***********************************************************************/
3404 /* Add the list of paths PATH_LIST to the current search path for
3405 input files. */
3407 static void
3408 add_search_path (char *path_list)
3410 while (*path_list)
3412 char *start = path_list;
3413 struct search_path *p;
3415 while (*path_list && *path_list != SEPCHAR)
3416 ++path_list;
3418 p = (struct search_path *) xmalloc (sizeof *p);
3419 p->path = (char *) xmalloc (path_list - start + 1);
3420 memcpy (p->path, start, path_list - start);
3421 p->path[path_list - start] = '\0';
3422 p->next = NULL;
3424 if (search_path_tail)
3426 search_path_tail->next = p;
3427 search_path_tail = p;
3429 else
3430 search_path = search_path_tail = p;
3432 while (*path_list == SEPCHAR)
3433 ++path_list;
3438 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3439 opened. Try to find FILE in search_path first, then try the
3440 unchanged file name. */
3442 static FILE *
3443 open_file (char *file)
3445 FILE *fp = NULL;
3446 static char *buffer;
3447 static int buffer_size;
3448 struct search_path *path;
3449 int flen = strlen (file) + 1; /* +1 for the slash */
3451 filename = xstrdup (file);
3453 for (path = search_path; path && fp == NULL; path = path->next)
3455 int len = strlen (path->path) + flen;
3457 if (len + 1 >= buffer_size)
3459 buffer_size = max (len + 1, 2 * buffer_size);
3460 buffer = (char *) xrealloc (buffer, buffer_size);
3463 strcpy (buffer, path->path);
3464 strcat (buffer, "/");
3465 strcat (buffer, file);
3466 fp = fopen (buffer, "r");
3469 /* Try the original file name. */
3470 if (fp == NULL)
3471 fp = fopen (file, "r");
3473 if (fp == NULL)
3474 yyerror ("cannot open", NULL);
3476 return fp;
3480 /* Display usage information and exit program. */
3482 #define USAGE "\
3483 Usage: ebrowse [options] {files}\n\
3485 -a, --append append output to existing file\n\
3486 -f, --files=FILES read input file names from FILE\n\
3487 -I, --search-path=LIST set search path for input files\n\
3488 -m, --min-regexp-length=N set minimum regexp length to N\n\
3489 -M, --max-regexp-length=N set maximum regexp length to N\n\
3490 -n, --no-nested-classes exclude nested classes\n\
3491 -o, --output-file=FILE set output file name to FILE\n\
3492 -p, --position-info print info about position in file\n\
3493 -s, --no-structs-or-unions don't record structs or unions\n\
3494 -v, --verbose be verbose\n\
3495 -V, --very-verbose be very verbose\n\
3496 -x, --no-regexps don't record regular expressions\n\
3497 --help display this help\n\
3498 --version display version info\n\
3501 static _Noreturn void
3502 usage (int error)
3504 puts (USAGE);
3505 exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
3509 /* Display version and copyright info. The VERSION macro is set
3510 from config.h and contains the Emacs version. */
3512 #ifndef VERSION
3513 # define VERSION "21"
3514 #endif
3516 static _Noreturn void
3517 version (void)
3519 char emacs_copyright[] = COPYRIGHT;
3521 printf ("ebrowse %s\n", VERSION);
3522 puts (emacs_copyright);
3523 puts ("This program is distributed under the same terms as Emacs.");
3524 exit (EXIT_SUCCESS);
3528 /* Parse one input file FILE, adding classes and members to the symbol
3529 table. */
3531 static void
3532 process_file (char *file)
3534 FILE *fp;
3536 fp = open_file (file);
3537 if (fp)
3539 size_t nread, nbytes;
3541 /* Give a progress indication if needed. */
3542 if (f_very_verbose)
3544 puts (filename);
3545 fflush (stdout);
3547 else if (f_verbose)
3549 putchar ('.');
3550 fflush (stdout);
3553 /* Read file to inbuffer. */
3554 for (nread = 0;;)
3556 if (nread + READ_CHUNK_SIZE >= inbuffer_size)
3558 inbuffer_size = nread + READ_CHUNK_SIZE + 1;
3559 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
3562 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3563 if (nbytes == 0)
3564 break;
3565 nread += nbytes;
3567 inbuffer[nread] = '\0';
3569 /* Reinitialize scanner and parser for the new input file. */
3570 re_init_scanner ();
3571 re_init_parser ();
3573 /* Parse it and close the file. */
3574 yyparse ();
3575 fclose (fp);
3580 /* Read a line from stream FP and return a pointer to a static buffer
3581 containing its contents without the terminating newline. Value
3582 is null when EOF is reached. */
3584 static char *
3585 read_line (FILE *fp)
3587 static char *buffer;
3588 static int buffer_size;
3589 int i = 0, c;
3591 while ((c = getc (fp)) != EOF && c != '\n')
3593 if (i >= buffer_size)
3595 buffer_size = max (100, buffer_size * 2);
3596 buffer = (char *) xrealloc (buffer, buffer_size);
3599 buffer[i++] = c;
3602 if (c == EOF && i == 0)
3603 return NULL;
3605 if (i == buffer_size)
3607 buffer_size = max (100, buffer_size * 2);
3608 buffer = (char *) xrealloc (buffer, buffer_size);
3611 buffer[i] = '\0';
3612 if (i > 0 && buffer[i - 1] == '\r')
3613 buffer[i - 1] = '\0';
3614 return buffer;
3618 /* Main entry point. */
3621 main (int argc, char **argv)
3623 int i;
3624 int any_inputfiles = 0;
3625 static const char *out_filename = DEFAULT_OUTFILE;
3626 static char **input_filenames = NULL;
3627 static int input_filenames_size = 0;
3628 static int n_input_files;
3630 filename = "command line";
3631 yyout = stdout;
3633 while ((i = getopt_long (argc, argv, "af:I:m:M:no:p:svVx",
3634 options, NULL)) != EOF)
3636 switch (i)
3638 /* Experimental. */
3639 case 'p':
3640 info_position = atoi (optarg);
3641 break;
3643 case 'n':
3644 f_nested_classes = 0;
3645 break;
3647 case 'x':
3648 f_regexps = 0;
3649 break;
3651 /* Add the name of a file containing more input files. */
3652 case 'f':
3653 if (n_input_files == input_filenames_size)
3655 input_filenames_size = max (10, 2 * input_filenames_size);
3656 input_filenames = (char **) xrealloc ((void *)input_filenames,
3657 input_filenames_size);
3659 input_filenames[n_input_files++] = xstrdup (optarg);
3660 break;
3662 /* Append new output to output file instead of truncating it. */
3663 case 'a':
3664 f_append = 1;
3665 break;
3667 /* Include structs in the output */
3668 case 's':
3669 f_structs = 0;
3670 break;
3672 /* Be verbose (give a progress indication). */
3673 case 'v':
3674 f_verbose = 1;
3675 break;
3677 /* Be very verbose (print file names as they are processed). */
3678 case 'V':
3679 f_verbose = 1;
3680 f_very_verbose = 1;
3681 break;
3683 /* Change the name of the output file. */
3684 case 'o':
3685 out_filename = optarg;
3686 break;
3688 /* Set minimum length for regular expression strings
3689 when recorded in the output file. */
3690 case 'm':
3691 min_regexp = atoi (optarg);
3692 break;
3694 /* Set maximum length for regular expression strings
3695 when recorded in the output file. */
3696 case 'M':
3697 max_regexp = atoi (optarg);
3698 break;
3700 /* Add to search path. */
3701 case 'I':
3702 add_search_path (optarg);
3703 break;
3705 /* Display help */
3706 case -2:
3707 usage (0);
3708 break;
3710 case -3:
3711 version ();
3712 break;
3716 /* Call init_scanner after command line flags have been processed to be
3717 able to add keywords depending on command line (not yet
3718 implemented). */
3719 init_scanner ();
3720 init_sym ();
3722 /* Open output file */
3723 if (*out_filename)
3725 if (f_append)
3727 /* Check that the file to append to exists, and is not
3728 empty. More specifically, it should be a valid file
3729 produced by a previous run of ebrowse, but that's too
3730 difficult to check. */
3731 FILE *fp;
3732 int rc;
3734 fp = fopen (out_filename, "r");
3735 if (fp == NULL)
3737 yyerror ("file `%s' must exist for --append", out_filename);
3738 exit (EXIT_FAILURE);
3741 rc = fseek (fp, 0, SEEK_END);
3742 if (rc == -1)
3744 yyerror ("error seeking in file `%s'", out_filename);
3745 exit (EXIT_FAILURE);
3748 rc = ftell (fp);
3749 if (rc == -1)
3751 yyerror ("error getting size of file `%s'", out_filename);
3752 exit (EXIT_FAILURE);
3755 else if (rc == 0)
3757 yyerror ("file `%s' is empty", out_filename);
3758 /* It may be ok to use an empty file for appending.
3759 exit (EXIT_FAILURE); */
3762 fclose (fp);
3765 yyout = fopen (out_filename, f_append ? "a" : "w");
3766 if (yyout == NULL)
3768 yyerror ("cannot open output file `%s'", out_filename);
3769 exit (EXIT_FAILURE);
3773 /* Process input files specified on the command line. */
3774 while (optind < argc)
3776 process_file (argv[optind++]);
3777 any_inputfiles = 1;
3780 /* Process files given on stdin if no files specified. */
3781 if (!any_inputfiles && n_input_files == 0)
3783 char *file;
3784 while ((file = read_line (stdin)) != NULL)
3785 process_file (file);
3787 else
3789 /* Process files from `--files=FILE'. Every line in FILE names
3790 one input file to process. */
3791 for (i = 0; i < n_input_files; ++i)
3793 FILE *fp = fopen (input_filenames[i], "r");
3795 if (fp == NULL)
3796 yyerror ("cannot open input file `%s'", input_filenames[i]);
3797 else
3799 char *file;
3800 while ((file = read_line (fp)) != NULL)
3801 process_file (file);
3802 fclose (fp);
3807 /* Write output file. */
3808 dump_roots (yyout);
3810 /* Close output file. */
3811 if (yyout != stdout)
3812 fclose (yyout);
3814 return EXIT_SUCCESS;
3817 /* ebrowse.c ends here */