Don’t assume -g3 in .gdbinit
[emacs.git] / lib-src / ebrowse.c
blobe77b7c94ccafe1d73a4a814272dc3f125bc9b93a
1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2017 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 (at
10 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 <stddef.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <assert.h>
27 #include <getopt.h>
29 #include <flexmember.h>
30 #include <min-max.h>
31 #include <unlocked-io.h>
33 /* The SunOS compiler doesn't have SEEK_END. */
34 #ifndef SEEK_END
35 #define SEEK_END 2
36 #endif
38 /* Files are read in chunks of this number of bytes. */
40 enum { READ_CHUNK_SIZE = 100 * 1024 };
42 /* Value is true if strings X and Y compare equal. */
44 static bool
45 streq (char const *x, char const *y)
47 return strcmp (x, y) == 0;
50 static bool
51 filename_eq (char const *x, char const *y)
53 #ifdef __MSDOS__
54 return strcasecmp (x, y) == 0;
55 #elif defined WINDOWSNT
56 return stricmp (x, y) == 0;
57 #else
58 return streq (x, y);
59 #endif
62 /* The default output file name. */
64 #define DEFAULT_OUTFILE "BROWSE"
66 /* A version string written to the output file. Change this whenever
67 the structure of the output file changes. */
69 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
71 /* The output file consists of a tree of Lisp objects, with major
72 nodes built out of Lisp structures. These are the heads of the
73 Lisp structs with symbols identifying their type. */
75 #define TREE_HEADER_STRUCT "[ebrowse-hs "
76 #define TREE_STRUCT "[ebrowse-ts "
77 #define MEMBER_STRUCT "[ebrowse-ms "
78 #define CLASS_STRUCT "[ebrowse-cs "
80 /* The name of the symbol table entry for global functions, variables,
81 defines etc. This name also appears in the browser display. */
83 #define GLOBALS_NAME "*Globals*"
85 /* Token definitions. */
87 enum token
89 YYEOF = 0, /* end of file */
90 CSTRING = 256, /* string constant */
91 CCHAR, /* character constant */
92 CINT, /* integral constant */
93 CFLOAT, /* real constant */
95 ELLIPSIS, /* ... */
96 LSHIFTASGN, /* <<= */
97 RSHIFTASGN, /* >>= */
98 ARROWSTAR, /* ->* */
99 IDENT, /* identifier */
100 DIVASGN, /* /= */
101 INC, /* ++ */
102 ADDASGN, /* += */
103 DEC, /* -- */
104 ARROW, /* -> */
105 SUBASGN, /* -= */
106 MULASGN, /* *= */
107 MODASGN, /* %= */
108 LOR, /* || */
109 ORASGN, /* |= */
110 LAND, /* && */
111 ANDASGN, /* &= */
112 XORASGN, /* ^= */
113 POINTSTAR, /* .* */
114 DCOLON, /* :: */
115 EQ, /* == */
116 NE, /* != */
117 LE, /* <= */
118 LSHIFT, /* << */
119 GE, /* >= */
120 RSHIFT, /* >> */
122 /* Keywords. The undef's are there because these
123 three symbols are very likely to be defined somewhere. */
124 #undef BOOL
125 #undef TRUE
126 #undef FALSE
128 ASM, /* asm */
129 AUTO, /* auto */
130 BREAK, /* break */
131 CASE, /* case */
132 CATCH, /* catch */
133 CHAR, /* char */
134 CLASS, /* class */
135 CONST, /* const */
136 CONTINUE, /* continue */
137 DEFAULT, /* default */
138 DELETE, /* delete */
139 DO, /* do */
140 DOUBLE, /* double */
141 ELSE, /* else */
142 ENUM, /* enum */
143 EXTERN, /* extern */
144 FLOAT, /* float */
145 FOR, /* for */
146 FRIEND, /* friend */
147 GOTO, /* goto */
148 IF, /* if */
149 T_INLINE, /* inline */
150 INT, /* int */
151 LONG, /* long */
152 NEW, /* new */
153 OPERATOR, /* operator */
154 PRIVATE, /* private */
155 PROTECTED, /* protected */
156 PUBLIC, /* public */
157 REGISTER, /* register */
158 RETURN, /* return */
159 SHORT, /* short */
160 SIGNED, /* signed */
161 SIZEOF, /* sizeof */
162 STATIC, /* static */
163 STRUCT, /* struct */
164 SWITCH, /* switch */
165 TEMPLATE, /* template */
166 THIS, /* this */
167 THROW, /* throw */
168 TRY, /* try */
169 TYPEDEF, /* typedef */
170 UNION, /* union */
171 UNSIGNED, /* unsigned */
172 VIRTUAL, /* virtual */
173 VOID, /* void */
174 VOLATILE, /* volatile */
175 WHILE, /* while */
176 MUTABLE, /* mutable */
177 BOOL, /* bool */
178 TRUE, /* true */
179 FALSE, /* false */
180 SIGNATURE, /* signature (GNU extension) */
181 NAMESPACE, /* namespace */
182 EXPLICIT, /* explicit */
183 TYPENAME, /* typename */
184 CONST_CAST, /* const_cast */
185 DYNAMIC_CAST, /* dynamic_cast */
186 REINTERPRET_CAST, /* reinterpret_cast */
187 STATIC_CAST, /* static_cast */
188 TYPEID, /* typeid */
189 USING, /* using */
190 WCHAR /* wchar_t */
193 /* Storage classes, in a wider sense. */
195 enum sc
197 SC_UNKNOWN,
198 SC_MEMBER, /* Is an instance member. */
199 SC_STATIC, /* Is static member. */
200 SC_FRIEND, /* Is friend function. */
201 SC_TYPE /* Is a type definition. */
204 /* Member visibility. */
206 enum visibility
208 V_PUBLIC,
209 V_PROTECTED,
210 V_PRIVATE
213 /* Member flags. */
215 #define F_VIRTUAL 1 /* Is virtual function. */
216 #define F_INLINE 2 /* Is inline function. */
217 #define F_CONST 4 /* Is const. */
218 #define F_PURE 8 /* Is pure virtual function. */
219 #define F_MUTABLE 16 /* Is mutable. */
220 #define F_TEMPLATE 32 /* Is a template. */
221 #define F_EXPLICIT 64 /* Is explicit constructor. */
222 #define F_THROW 128 /* Has a throw specification. */
223 #define F_EXTERNC 256 /* Is declared extern "C". */
224 #define F_DEFINE 512 /* Is a #define. */
226 /* Set and test a bit in an int. */
228 static void
229 set_flag (int *f, int flag)
231 *f |= flag;
234 static bool
235 has_flag (int f, int flag)
237 return (f & flag) != 0;
240 /* Structure describing a class member. */
242 struct member
244 struct member *next; /* Next in list of members. */
245 struct member *anext; /* Collision chain in member_table. */
246 struct member **list; /* Pointer to list in class. */
247 unsigned param_hash; /* Hash value for parameter types. */
248 int vis; /* Visibility (public, ...). */
249 int flags; /* See F_* above. */
250 char *regexp; /* Matching regular expression. */
251 const char *filename; /* Don't free this shared string. */
252 int pos; /* Buffer position of occurrence. */
253 char *def_regexp; /* Regular expression matching definition. */
254 const char *def_filename; /* File name of definition. */
255 int def_pos; /* Buffer position of definition. */
256 char name[FLEXIBLE_ARRAY_MEMBER]; /* Member name. */
259 /* Structures of this type are used to connect class structures with
260 their super and subclasses. */
262 struct link
264 struct sym *sym; /* The super or subclass. */
265 struct link *next; /* Next in list or NULL. */
268 /* Structure used to record namespace aliases. */
270 struct alias
272 struct alias *next; /* Next in list. */
273 struct sym *namesp; /* Namespace in which defined. */
274 struct link *aliasee; /* List of aliased namespaces (A::B::C...). */
275 char name[FLEXIBLE_ARRAY_MEMBER]; /* Alias name. */
278 /* The structure used to describe a class in the symbol table,
279 or a namespace in all_namespaces. */
281 struct sym
283 int flags; /* Is class a template class?. */
284 unsigned char visited; /* Used to find circles. */
285 struct sym *next; /* Hash collision list. */
286 struct link *subs; /* List of subclasses. */
287 struct link *supers; /* List of superclasses. */
288 struct member *vars; /* List of instance variables. */
289 struct member *fns; /* List of instance functions. */
290 struct member *static_vars; /* List of static variables. */
291 struct member *static_fns; /* List of static functions. */
292 struct member *friends; /* List of friend functions. */
293 struct member *types; /* List of local types. */
294 char *regexp; /* Matching regular expression. */
295 int pos; /* Buffer position. */
296 const char *filename; /* File in which it can be found. */
297 const char *sfilename; /* File in which members can be found. */
298 struct sym *namesp; /* Namespace in which defined. . */
299 char name[FLEXIBLE_ARRAY_MEMBER]; /* Name of the class. */
302 /* Experimental: Print info for `--position-info'. We print
303 '(CLASS-NAME SCOPE MEMBER-NAME). */
305 #define P_DEFN 1
306 #define P_DECL 2
308 int info_where;
309 struct sym *info_cls = NULL;
310 struct member *info_member = NULL;
312 /* Experimental. For option `--position-info', the buffer position we
313 are interested in. When this position is reached, print out
314 information about what we know about that point. */
316 int info_position = -1;
318 /* Command line options structure for getopt_long. */
320 struct option options[] =
322 {"append", no_argument, NULL, 'a'},
323 {"files", required_argument, NULL, 'f'},
324 {"help", no_argument, NULL, -2},
325 {"min-regexp-length", required_argument, NULL, 'm'},
326 {"max-regexp-length", required_argument, NULL, 'M'},
327 {"no-nested-classes", no_argument, NULL, 'n'},
328 {"no-regexps", no_argument, NULL, 'x'},
329 {"no-structs-or-unions", no_argument, NULL, 's'},
330 {"output-file", required_argument, NULL, 'o'},
331 {"position-info", required_argument, NULL, 'p'},
332 {"search-path", required_argument, NULL, 'I'},
333 {"verbose", no_argument, NULL, 'v'},
334 {"version", no_argument, NULL, -3},
335 {"very-verbose", no_argument, NULL, 'V'},
336 {NULL, 0, NULL, 0}
339 /* Semantic values of tokens. Set by yylex.. */
341 unsigned yyival; /* Set for token CINT. */
342 char *yytext; /* Set for token IDENT. */
343 char *yytext_end;
345 /* Output file. */
347 FILE *yyout;
349 /* Current line number. */
351 int yyline;
353 /* The name of the current input file. */
355 const char *filename;
357 /* Three character class vectors, and macros to test membership
358 of characters. */
360 char is_ident[255];
361 char is_digit[255];
362 char is_white[255];
364 #define IDENTP(C) is_ident[(unsigned char) (C)]
365 #define DIGITP(C) is_digit[(unsigned char) (C)]
366 #define WHITEP(C) is_white[(unsigned char) (C)]
368 /* Command line flags. */
370 int f_append;
371 int f_verbose;
372 int f_very_verbose;
373 int f_structs = 1;
374 int f_regexps = 1;
375 int f_nested_classes = 1;
377 /* Maximum and minimum lengths of regular expressions matching a
378 member, class etc., for writing them to the output file. These are
379 overridable from the command line. */
381 int min_regexp = 5;
382 int max_regexp = 50;
384 /* Input buffer. */
386 char *inbuffer;
387 char *in;
388 size_t inbuffer_size;
390 /* Return the current buffer position in the input file. */
392 #define BUFFER_POS() (in - inbuffer)
394 /* If current lookahead is CSTRING, the following points to the
395 first character in the string constant. Used for recognizing
396 extern "C". */
398 char *string_start;
400 /* The size of the hash tables for classes.and members. Should be
401 prime. */
403 #define TABLE_SIZE 1001
405 /* The hash table for class symbols. */
407 struct sym *class_table[TABLE_SIZE];
409 /* Hash table containing all member structures. This is generally
410 faster for member lookup than traversing the member lists of a
411 `struct sym'. */
413 struct member *member_table[TABLE_SIZE];
415 /* Hash table for namespace aliases */
417 struct alias *namespace_alias_table[TABLE_SIZE];
419 /* The special class symbol used to hold global functions,
420 variables etc. */
422 struct sym *global_symbols;
424 /* The current namespace. */
426 struct sym *current_namespace;
428 /* The list of all known namespaces. */
430 struct sym *all_namespaces;
432 /* Stack of namespaces we're currently nested in, during the parse. */
434 struct sym **namespace_stack;
435 int namespace_stack_size;
436 int namespace_sp;
438 /* The current lookahead token. */
440 int tk = -1;
442 /* Structure describing a keyword. */
444 struct kw
446 const char *name; /* Spelling. */
447 int tk; /* Token value. */
448 struct kw *next; /* Next in collision chain. */
451 /* Keywords are lookup up in a hash table of their own. */
453 #define KEYWORD_TABLE_SIZE 1001
454 struct kw *keyword_table[KEYWORD_TABLE_SIZE];
456 /* Search path. */
458 struct search_path
460 char *path;
461 struct search_path *next;
464 struct search_path *search_path;
465 struct search_path *search_path_tail;
467 /* Function prototypes. */
469 static char *matching_regexp (void);
470 static struct sym *add_sym (const char *, struct sym *);
471 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
472 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
473 static struct member *add_member (struct sym *, char *, int, int, unsigned);
474 static void class_definition (struct sym *, int, int, int);
475 static char *operator_name (int *);
476 static void parse_qualified_param_ident_or_type (char **);
478 /***********************************************************************
479 Utilities
480 ***********************************************************************/
482 /* Print an error in a printf-like style with the current input file
483 name and line number. */
485 static void
486 yyerror (const char *format, const char *s)
488 fprintf (stderr, "%s:%d: ", filename, yyline);
489 fprintf (stderr, format, s);
490 putc ('\n', stderr);
494 /* Like malloc but print an error and exit if not enough memory is
495 available. */
497 static void *
498 xmalloc (size_t nbytes)
500 void *p = malloc (nbytes);
501 if (p == NULL)
503 yyerror ("out of memory", NULL);
504 exit (EXIT_FAILURE);
506 return p;
510 /* Like realloc but print an error and exit if out of memory. */
512 static void *
513 xrealloc (void *p, size_t sz)
515 p = realloc (p, sz);
516 if (p == NULL)
518 yyerror ("out of memory", NULL);
519 exit (EXIT_FAILURE);
521 return p;
525 /* Like strdup, but print an error and exit if not enough memory is
526 available.. If S is null, return null. */
528 static char *
529 xstrdup (char *s)
531 if (s)
532 return strcpy (xmalloc (strlen (s) + 1), s);
533 return s;
538 /***********************************************************************
539 Symbols
540 ***********************************************************************/
542 /* Initialize the symbol table. This currently only sets up the
543 special symbol for globals (`*Globals*'). */
545 static void
546 init_sym (void)
548 global_symbols = add_sym (GLOBALS_NAME, NULL);
552 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
553 is the class in which class NAME was found. If it is null,
554 this means the scope of NAME is the current namespace.
556 If a symbol for NAME already exists, return that. Otherwise
557 create a new symbol and set it to default values. */
559 static struct sym *
560 add_sym (const char *name, struct sym *nested_in_class)
562 struct sym *sym;
563 unsigned h;
564 const char *s;
565 struct sym *scope = nested_in_class ? nested_in_class : current_namespace;
567 for (s = name, h = 0; *s; ++s)
568 h = (h << 1) ^ *s;
569 h %= TABLE_SIZE;
571 for (sym = class_table[h]; sym; sym = sym->next)
572 if (streq (name, sym->name)
573 && ((!sym->namesp && !scope)
574 || (sym->namesp && scope
575 && streq (sym->namesp->name, scope->name))))
576 break;
578 if (sym == NULL)
580 if (f_very_verbose)
582 putchar ('\t');
583 puts (name);
586 sym = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1));
587 memset (sym, 0, offsetof (struct sym, name));
588 strcpy (sym->name, name);
589 sym->namesp = scope;
590 sym->next = class_table[h];
591 class_table[h] = sym;
594 return sym;
598 /* Add links between superclass SUPER and subclass SUB. */
600 static void
601 add_link (struct sym *super, struct sym *sub)
603 struct link *lnk, *lnk2, *p, *prev;
605 /* See if a link already exists. */
606 for (p = super->subs, prev = NULL;
607 p && strcmp (sub->name, p->sym->name) > 0;
608 prev = p, p = p->next)
611 /* Avoid duplicates. */
612 if (p == NULL || p->sym != sub)
614 lnk = (struct link *) xmalloc (sizeof *lnk);
615 lnk2 = (struct link *) xmalloc (sizeof *lnk2);
617 lnk->sym = sub;
618 lnk->next = p;
620 if (prev)
621 prev->next = lnk;
622 else
623 super->subs = lnk;
625 lnk2->sym = super;
626 lnk2->next = sub->supers;
627 sub->supers = lnk2;
632 /* Find in class CLS member NAME.
634 VAR non-zero means look for a member variable; otherwise a function
635 is searched. SC specifies what kind of member is searched---a
636 static, or per-instance member etc. HASH is a hash code for the
637 parameter types of functions. Value is a pointer to the member
638 found or null if not found. */
640 static struct member *
641 find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
643 struct member **list;
644 struct member *p;
645 unsigned name_hash = 0;
646 char *s;
647 int i;
649 switch (sc)
651 case SC_FRIEND:
652 list = &cls->friends;
653 break;
655 case SC_TYPE:
656 list = &cls->types;
657 break;
659 case SC_STATIC:
660 list = var ? &cls->static_vars : &cls->static_fns;
661 break;
663 default:
664 list = var ? &cls->vars : &cls->fns;
665 break;
668 for (s = name; *s; ++s)
669 name_hash = (name_hash << 1) ^ *s;
670 i = name_hash % TABLE_SIZE;
672 for (p = member_table[i]; p; p = p->anext)
673 if (p->list == list && p->param_hash == hash && streq (name, p->name))
674 break;
676 return p;
680 /* Add to class CLS information for the declaration of member NAME.
681 REGEXP is a regexp matching the declaration, if non-null. POS is
682 the position in the source where the declaration is found. HASH is
683 a hash code for the parameter list of the member, if it's a
684 function. VAR non-zero means member is a variable or type. SC
685 specifies the type of member (instance member, static, ...). VIS
686 is the member's visibility (public, protected, private). FLAGS is
687 a bit set giving additional information about the member (see the
688 F_* defines). */
690 static void
691 add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags)
693 struct member *m;
695 m = find_member (cls, name, var, sc, hash);
696 if (m == NULL)
697 m = add_member (cls, name, var, sc, hash);
699 /* Have we seen a new filename? If so record that. */
700 if (!cls->filename || !filename_eq (cls->filename, filename))
701 m->filename = filename;
703 m->regexp = regexp;
704 m->pos = pos;
705 m->flags = flags;
707 switch (vis)
709 case PRIVATE:
710 m->vis = V_PRIVATE;
711 break;
713 case PROTECTED:
714 m->vis = V_PROTECTED;
715 break;
717 case PUBLIC:
718 m->vis = V_PUBLIC;
719 break;
722 info_where = P_DECL;
723 info_cls = cls;
724 info_member = m;
728 /* Add to class CLS information for the definition of member NAME.
729 REGEXP is a regexp matching the declaration, if non-null. POS is
730 the position in the source where the declaration is found. HASH is
731 a hash code for the parameter list of the member, if it's a
732 function. VAR non-zero means member is a variable or type. SC
733 specifies the type of member (instance member, static, ...). VIS
734 is the member's visibility (public, protected, private). FLAGS is
735 a bit set giving additional information about the member (see the
736 F_* defines). */
738 static void
739 add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
741 struct member *m;
743 if (sc == SC_UNKNOWN)
745 m = find_member (cls, name, var, SC_MEMBER, hash);
746 if (m == NULL)
748 m = find_member (cls, name, var, SC_STATIC, hash);
749 if (m == NULL)
750 m = add_member (cls, name, var, sc, hash);
753 else
755 m = find_member (cls, name, var, sc, hash);
756 if (m == NULL)
757 m = add_member (cls, name, var, sc, hash);
760 if (!cls->sfilename)
761 cls->sfilename = filename;
763 if (!filename_eq (cls->sfilename, filename))
764 m->def_filename = filename;
766 m->def_regexp = regexp;
767 m->def_pos = pos;
768 m->flags |= flags;
770 info_where = P_DEFN;
771 info_cls = cls;
772 info_member = m;
776 /* Add a symbol for a define named NAME to the symbol table.
777 REGEXP is a regular expression matching the define in the source,
778 if it is non-null. POS is the position in the file. */
780 static void
781 add_define (char *name, char *regexp, int pos)
783 add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
784 add_global_decl (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
788 /* Add information for the global definition of NAME.
789 REGEXP is a regexp matching the declaration, if non-null. POS is
790 the position in the source where the declaration is found. HASH is
791 a hash code for the parameter list of the member, if it's a
792 function. VAR non-zero means member is a variable or type. SC
793 specifies the type of member (instance member, static, ...). VIS
794 is the member's visibility (public, protected, private). FLAGS is
795 a bit set giving additional information about the member (see the
796 F_* defines). */
798 static void
799 add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
801 int i;
802 struct sym *sym;
804 /* Try to find out for which classes a function is a friend, and add
805 what we know about it to them. */
806 if (!var)
807 for (i = 0; i < TABLE_SIZE; ++i)
808 for (sym = class_table[i]; sym; sym = sym->next)
809 if (sym != global_symbols && sym->friends)
810 if (find_member (sym, name, 0, SC_FRIEND, hash))
811 add_member_defn (sym, name, regexp, pos, hash, 0,
812 SC_FRIEND, flags);
814 /* Add to global symbols. */
815 add_member_defn (global_symbols, name, regexp, pos, hash, var, sc, flags);
819 /* Add information for the global declaration of NAME.
820 REGEXP is a regexp matching the declaration, if non-null. POS is
821 the position in the source where the declaration is found. HASH is
822 a hash code for the parameter list of the member, if it's a
823 function. VAR non-zero means member is a variable or type. SC
824 specifies the type of member (instance member, static, ...). VIS
825 is the member's visibility (public, protected, private). FLAGS is
826 a bit set giving additional information about the member (see the
827 F_* defines). */
829 static void
830 add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
832 /* Add declaration only if not already declared. Header files must
833 be processed before source files for this to have the right effect.
834 I do not want to handle implicit declarations at the moment. */
835 struct member *m;
836 struct member *found;
838 m = found = find_member (global_symbols, name, var, sc, hash);
839 if (m == NULL)
840 m = add_member (global_symbols, name, var, sc, hash);
842 /* Definition already seen => probably last declaration implicit.
843 Override. This means that declarations must always be added to
844 the symbol table before definitions. */
845 if (!found)
847 if (!global_symbols->filename
848 || !filename_eq (global_symbols->filename, filename))
849 m->filename = filename;
851 m->regexp = regexp;
852 m->pos = pos;
853 m->vis = V_PUBLIC;
854 m->flags = flags;
856 info_where = P_DECL;
857 info_cls = global_symbols;
858 info_member = m;
863 /* Add a symbol for member NAME to class CLS.
864 VAR non-zero means it's a variable. SC specifies the kind of
865 member. HASH is a hash code for the parameter types of a function.
866 Value is a pointer to the member's structure. */
868 static struct member *
869 add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
871 struct member *m = xmalloc (FLEXSIZEOF (struct member, name,
872 strlen (name) + 1));
873 struct member **list;
874 struct member *p;
875 struct member *prev;
876 unsigned name_hash = 0;
877 int i;
878 char *s;
880 strcpy (m->name, name);
881 m->param_hash = hash;
883 m->vis = 0;
884 m->flags = 0;
885 m->regexp = NULL;
886 m->filename = NULL;
887 m->pos = 0;
888 m->def_regexp = NULL;
889 m->def_filename = NULL;
890 m->def_pos = 0;
892 assert (cls != NULL);
894 switch (sc)
896 case SC_FRIEND:
897 list = &cls->friends;
898 break;
900 case SC_TYPE:
901 list = &cls->types;
902 break;
904 case SC_STATIC:
905 list = var ? &cls->static_vars : &cls->static_fns;
906 break;
908 default:
909 list = var ? &cls->vars : &cls->fns;
910 break;
913 for (s = name; *s; ++s)
914 name_hash = (name_hash << 1) ^ *s;
915 i = name_hash % TABLE_SIZE;
916 m->anext = member_table[i];
917 member_table[i] = m;
918 m->list = list;
920 /* Keep the member list sorted. It's cheaper to do it here than to
921 sort them in Lisp. */
922 for (prev = NULL, p = *list;
923 p && strcmp (name, p->name) > 0;
924 prev = p, p = p->next)
927 m->next = p;
928 if (prev)
929 prev->next = m;
930 else
931 *list = m;
932 return m;
936 /* Given the root R of a class tree, step through all subclasses
937 recursively, marking functions as virtual that are declared virtual
938 in base classes. */
940 static void
941 mark_virtual (struct sym *r)
943 struct link *p;
944 struct member *m, *m2;
946 for (p = r->subs; p; p = p->next)
948 for (m = r->fns; m; m = m->next)
949 if (has_flag (m->flags, F_VIRTUAL))
951 for (m2 = p->sym->fns; m2; m2 = m2->next)
952 if (m->param_hash == m2->param_hash && streq (m->name, m2->name))
953 set_flag (&m2->flags, F_VIRTUAL);
956 mark_virtual (p->sym);
961 /* For all roots of the class tree, mark functions as virtual that
962 are virtual because of a virtual declaration in a base class. */
964 static void
965 mark_inherited_virtual (void)
967 struct sym *r;
968 int i;
970 for (i = 0; i < TABLE_SIZE; ++i)
971 for (r = class_table[i]; r; r = r->next)
972 if (r->supers == NULL)
973 mark_virtual (r);
977 /* Create and return a symbol for a namespace with name NAME. */
979 static struct sym *
980 make_namespace (char *name, struct sym *context)
982 struct sym *s = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1));
983 memset (s, 0, offsetof (struct sym, name));
984 strcpy (s->name, name);
985 s->next = all_namespaces;
986 s->namesp = context;
987 all_namespaces = s;
988 return s;
992 /* Find the symbol for namespace NAME. If not found, return NULL */
994 static struct sym *
995 check_namespace (char *name, struct sym *context)
997 struct sym *p = NULL;
999 for (p = all_namespaces; p; p = p->next)
1001 if (streq (p->name, name) && (p->namesp == context))
1002 break;
1005 return p;
1008 /* Find the symbol for namespace NAME. If not found, add a new symbol
1009 for NAME to all_namespaces. */
1011 static struct sym *
1012 find_namespace (char *name, struct sym *context)
1014 struct sym *p = check_namespace (name, context);
1016 if (p == NULL)
1017 p = make_namespace (name, context);
1019 return p;
1023 /* Find namespace alias with name NAME. If not found return NULL. */
1025 static struct link *
1026 check_namespace_alias (char *name)
1028 struct link *p = NULL;
1029 struct alias *al;
1030 unsigned h;
1031 char *s;
1033 for (s = name, h = 0; *s; ++s)
1034 h = (h << 1) ^ *s;
1035 h %= TABLE_SIZE;
1037 for (al = namespace_alias_table[h]; al; al = al->next)
1038 if (streq (name, al->name) && (al->namesp == current_namespace))
1040 p = al->aliasee;
1041 break;
1044 return p;
1047 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1049 static void
1050 register_namespace_alias (char *new_name, struct link *old_name)
1052 unsigned h;
1053 char *s;
1054 struct alias *al;
1056 for (s = new_name, h = 0; *s; ++s)
1057 h = (h << 1) ^ *s;
1058 h %= TABLE_SIZE;
1061 /* Is it already in the table of aliases? */
1062 for (al = namespace_alias_table[h]; al; al = al->next)
1063 if (streq (new_name, al->name) && (al->namesp == current_namespace))
1064 return;
1066 al = xmalloc (FLEXSIZEOF (struct alias, name, strlen (new_name) + 1));
1067 strcpy (al->name, new_name);
1068 al->next = namespace_alias_table[h];
1069 al->namesp = current_namespace;
1070 al->aliasee = old_name;
1071 namespace_alias_table[h] = al;
1075 /* Enter namespace with name NAME. */
1077 static void
1078 enter_namespace (char *name)
1080 struct sym *p = find_namespace (name, current_namespace);
1082 if (namespace_sp == namespace_stack_size)
1084 int size = max (10, 2 * namespace_stack_size);
1085 namespace_stack
1086 = (struct sym **) xrealloc ((void *)namespace_stack,
1087 size * sizeof *namespace_stack);
1088 namespace_stack_size = size;
1091 namespace_stack[namespace_sp++] = current_namespace;
1092 current_namespace = p;
1096 /* Leave the current namespace. */
1098 static void
1099 leave_namespace (void)
1101 assert (namespace_sp > 0);
1102 current_namespace = namespace_stack[--namespace_sp];
1107 /***********************************************************************
1108 Writing the Output File
1109 ***********************************************************************/
1111 /* Write string S to the output file FP in a Lisp-readable form.
1112 If S is null, write out `()'. */
1114 static void
1115 putstr (const char *s, FILE *fp)
1117 if (!s)
1119 putc ('(', fp);
1120 putc (')', fp);
1121 putc (' ', fp);
1123 else
1125 putc ('"', fp);
1126 fputs (s, fp);
1127 putc ('"', fp);
1128 putc (' ', fp);
1132 /* A dynamically allocated buffer for constructing a scope name. */
1134 char *scope_buffer;
1135 int scope_buffer_size;
1136 int scope_buffer_len;
1139 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1141 static void
1142 ensure_scope_buffer_room (int len)
1144 if (scope_buffer_len + len >= scope_buffer_size)
1146 int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
1147 scope_buffer = (char *) xrealloc (scope_buffer, new_size);
1148 scope_buffer_size = new_size;
1153 /* Recursively add the scope names of symbol P and the scopes of its
1154 namespaces to scope_buffer. Value is a pointer to the complete
1155 scope name constructed. */
1157 static char *
1158 sym_scope_1 (struct sym *p)
1160 int len;
1162 if (p->namesp)
1163 sym_scope_1 (p->namesp);
1165 if (*scope_buffer)
1167 ensure_scope_buffer_room (3);
1168 strcpy (scope_buffer + scope_buffer_len, "::");
1169 scope_buffer_len += 2;
1172 len = strlen (p->name);
1173 ensure_scope_buffer_room (len + 1);
1174 strcpy (scope_buffer + scope_buffer_len, p->name);
1175 scope_buffer_len += len;
1177 if (has_flag (p->flags, F_TEMPLATE))
1179 ensure_scope_buffer_room (3);
1180 strcpy (scope_buffer + scope_buffer_len, "<>");
1181 scope_buffer_len += 2;
1184 return scope_buffer;
1188 /* Return the scope of symbol P in printed representation, i.e.
1189 as it would appear in a C*+ source file. */
1191 static char *
1192 sym_scope (struct sym *p)
1194 if (!scope_buffer)
1196 scope_buffer_size = 1024;
1197 scope_buffer = (char *) xmalloc (scope_buffer_size);
1200 *scope_buffer = '\0';
1201 scope_buffer_len = 0;
1203 if (p->namesp)
1204 sym_scope_1 (p->namesp);
1206 return scope_buffer;
1210 /* Dump the list of members M to file FP. Value is the length of the
1211 list. */
1213 static int
1214 dump_members (FILE *fp, struct member *m)
1216 int n;
1218 putc ('(', fp);
1220 for (n = 0; m; m = m->next, ++n)
1222 fputs (MEMBER_STRUCT, fp);
1223 putstr (m->name, fp);
1224 putstr (NULL, fp); /* FIXME? scope for globals */
1225 fprintf (fp, "%u ", (unsigned) m->flags);
1226 putstr (m->filename, fp);
1227 putstr (m->regexp, fp);
1228 fprintf (fp, "%u ", (unsigned) m->pos);
1229 fprintf (fp, "%u ", (unsigned) m->vis);
1230 putc (' ', fp);
1231 putstr (m->def_filename, fp);
1232 putstr (m->def_regexp, fp);
1233 fprintf (fp, "%u", (unsigned) m->def_pos);
1234 putc (']', fp);
1235 putc ('\n', fp);
1238 putc (')', fp);
1239 putc ('\n', fp);
1240 return n;
1244 /* Dump class ROOT to stream FP. */
1246 static void
1247 dump_sym (FILE *fp, struct sym *root)
1249 fputs (CLASS_STRUCT, fp);
1250 putstr (root->name, fp);
1252 /* Print scope, if any. */
1253 if (root->namesp)
1254 putstr (sym_scope (root), fp);
1255 else
1256 putstr (NULL, fp);
1258 /* Print flags. */
1259 fprintf (fp, "%d", root->flags);
1260 putstr (root->filename, fp);
1261 putstr (root->regexp, fp);
1262 fprintf (fp, "%u", (unsigned) root->pos);
1263 putstr (root->sfilename, fp);
1264 putc (']', fp);
1265 putc ('\n', fp);
1269 /* Dump class ROOT and its subclasses to file FP. Value is the
1270 number of classes written. */
1272 static int
1273 dump_tree (FILE *fp, struct sym *root)
1275 struct link *lk;
1276 unsigned n = 0;
1278 dump_sym (fp, root);
1280 if (f_verbose)
1282 putchar ('+');
1283 fflush (stdout);
1286 putc ('(', fp);
1288 for (lk = root->subs; lk; lk = lk->next)
1290 fputs (TREE_STRUCT, fp);
1291 n += dump_tree (fp, lk->sym);
1292 putc (']', fp);
1295 putc (')', fp);
1297 dump_members (fp, root->vars);
1298 n += dump_members (fp, root->fns);
1299 dump_members (fp, root->static_vars);
1300 n += dump_members (fp, root->static_fns);
1301 n += dump_members (fp, root->friends);
1302 dump_members (fp, root->types);
1304 /* Superclasses. */
1305 putc ('(', fp);
1306 putc (')', fp);
1308 /* Mark slot. */
1309 putc ('(', fp);
1310 putc (')', fp);
1312 putc ('\n', fp);
1313 return n;
1317 /* Dump the entire class tree to file FP. */
1319 static void
1320 dump_roots (FILE *fp)
1322 int i, n = 0;
1323 struct sym *r;
1325 /* Output file header containing version string, command line
1326 options etc. */
1327 if (!f_append)
1329 fputs (TREE_HEADER_STRUCT, fp);
1330 putstr (EBROWSE_FILE_VERSION, fp);
1332 putc ('\"', fp);
1333 if (!f_structs)
1334 fputs (" -s", fp);
1335 if (f_regexps)
1336 fputs (" -x", fp);
1337 putc ('\"', fp);
1338 fputs (" ()", fp);
1339 fputs (" ()", fp);
1340 putc (']', fp);
1343 /* Mark functions as virtual that are so because of functions
1344 declared virtual in base classes. */
1345 mark_inherited_virtual ();
1347 /* Dump the roots of the graph. */
1348 for (i = 0; i < TABLE_SIZE; ++i)
1349 for (r = class_table[i]; r; r = r->next)
1350 if (!r->supers)
1352 fputs (TREE_STRUCT, fp);
1353 n += dump_tree (fp, r);
1354 putc (']', fp);
1357 if (f_verbose)
1358 putchar ('\n');
1363 /***********************************************************************
1364 Scanner
1365 ***********************************************************************/
1367 #ifdef DEBUG
1368 #define INCREMENT_LINENO \
1369 do { \
1370 if (f_very_verbose) \
1372 ++yyline; \
1373 printf ("%d:\n", yyline); \
1375 else \
1376 ++yyline; \
1377 } while (0)
1378 #else
1379 #define INCREMENT_LINENO ++yyline
1380 #endif
1382 /* Define two macros for accessing the input buffer (current input
1383 file). GET(C) sets C to the next input character and advances the
1384 input pointer. UNGET retracts the input pointer. */
1386 #define GET(C) ((C) = *in++)
1387 #define UNGET() (--in)
1390 /* Process a preprocessor line. Value is the next character from the
1391 input buffer not consumed. */
1393 static int
1394 process_pp_line (void)
1396 int in_comment = 0, in_string = 0;
1397 int c;
1398 char *p = yytext;
1400 /* Skip over white space. The `#' has been consumed already. */
1401 while (WHITEP (GET (c)))
1404 /* Read the preprocessor command (if any). */
1405 while (IDENTP (c))
1407 *p++ = c;
1408 GET (c);
1411 /* Is it a `define'? */
1412 *p = '\0';
1414 if (*yytext && streq (yytext, "define"))
1416 p = yytext;
1417 while (WHITEP (c))
1418 GET (c);
1419 while (IDENTP (c))
1421 *p++ = c;
1422 GET (c);
1425 *p = '\0';
1427 if (*yytext)
1429 char *regexp = matching_regexp ();
1430 int pos = BUFFER_POS ();
1431 add_define (yytext, regexp, pos);
1435 while (c && (c != '\n' || in_comment || in_string))
1437 if (c == '\\')
1438 GET (c);
1439 else if (c == '/' && !in_comment)
1441 if (GET (c) == '*')
1442 in_comment = 1;
1444 else if (c == '*' && in_comment)
1446 if (GET (c) == '/')
1447 in_comment = 0;
1449 else if (c == '"')
1450 in_string = !in_string;
1452 if (c == '\n')
1453 INCREMENT_LINENO;
1455 GET (c);
1458 return c;
1462 /* Value is the next token from the input buffer. */
1464 static int
1465 yylex (void)
1467 int c;
1468 char end_char;
1469 char *p;
1471 for (;;)
1473 while (WHITEP (GET (c)))
1476 switch (c)
1478 case '\n':
1479 INCREMENT_LINENO;
1480 break;
1482 case '\r':
1483 break;
1485 case 0:
1486 /* End of file. */
1487 return YYEOF;
1489 case '\\':
1490 GET (c);
1491 break;
1493 case '"':
1494 case '\'':
1495 /* String and character constants. */
1496 end_char = c;
1497 string_start = in;
1498 while (GET (c) && c != end_char)
1500 switch (c)
1502 case '\\':
1503 /* Escape sequences. */
1504 if (!GET (c))
1506 if (end_char == '\'')
1507 yyerror ("EOF in character constant", NULL);
1508 else
1509 yyerror ("EOF in string constant", NULL);
1510 goto end_string;
1512 else switch (c)
1514 case '\n':
1515 INCREMENT_LINENO;
1516 case 'a':
1517 case 'b':
1518 case 'f':
1519 case 'n':
1520 case 'r':
1521 case 't':
1522 case 'v':
1523 break;
1525 case 'x':
1527 /* Hexadecimal escape sequence. */
1528 int i;
1529 for (i = 0; i < 2; ++i)
1531 GET (c);
1533 if (c >= '0' && c <= '7')
1535 else if (c >= 'a' && c <= 'f')
1537 else if (c >= 'A' && c <= 'F')
1539 else
1541 UNGET ();
1542 break;
1546 break;
1548 case '0':
1550 /* Octal escape sequence. */
1551 int i;
1552 for (i = 0; i < 3; ++i)
1554 GET (c);
1556 if (c >= '0' && c <= '7')
1558 else
1560 UNGET ();
1561 break;
1565 break;
1567 default:
1568 break;
1570 break;
1572 case '\n':
1573 if (end_char == '\'')
1574 yyerror ("newline in character constant", NULL);
1575 else
1576 yyerror ("newline in string constant", NULL);
1577 INCREMENT_LINENO;
1578 break;
1580 default:
1581 break;
1585 end_string:
1586 return end_char == '\'' ? CCHAR : CSTRING;
1588 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1589 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1590 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1591 case 'v': case 'w': case 'x': case 'y': case 'z':
1592 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1593 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1594 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1595 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1597 /* Identifier and keywords. */
1598 unsigned hash;
1599 struct kw *k;
1601 p = yytext;
1602 *p++ = hash = c;
1604 while (IDENTP (GET (*p)))
1606 hash = (hash << 1) ^ *p++;
1607 if (p == yytext_end - 1)
1609 int size = yytext_end - yytext;
1610 yytext = (char *) xrealloc (yytext, 2 * size);
1611 yytext_end = yytext + 2 * size;
1612 p = yytext + size - 1;
1616 UNGET ();
1617 *p = 0;
1619 for (k = keyword_table[hash % KEYWORD_TABLE_SIZE]; k; k = k->next)
1620 if (streq (k->name, yytext))
1621 return k->tk;
1623 return IDENT;
1626 case '/':
1627 /* C and C++ comments, '/' and '/='. */
1628 switch (GET (c))
1630 case '*':
1631 while (GET (c))
1633 switch (c)
1635 case '*':
1636 if (GET (c) == '/')
1637 goto comment_end;
1638 UNGET ();
1639 break;
1640 case '\\':
1641 GET (c);
1642 break;
1643 case '\n':
1644 INCREMENT_LINENO;
1645 break;
1648 comment_end:;
1649 break;
1651 case '=':
1652 return DIVASGN;
1654 case '/':
1655 while (GET (c) && c != '\n')
1657 /* Don't try to read past the end of the input buffer if
1658 the file ends in a C++ comment without a newline. */
1659 if (c == 0)
1660 return YYEOF;
1662 INCREMENT_LINENO;
1663 break;
1665 default:
1666 UNGET ();
1667 return '/';
1669 break;
1671 case '+':
1672 if (GET (c) == '+')
1673 return INC;
1674 else if (c == '=')
1675 return ADDASGN;
1676 UNGET ();
1677 return '+';
1679 case '-':
1680 switch (GET (c))
1682 case '-':
1683 return DEC;
1684 case '>':
1685 if (GET (c) == '*')
1686 return ARROWSTAR;
1687 UNGET ();
1688 return ARROW;
1689 case '=':
1690 return SUBASGN;
1692 UNGET ();
1693 return '-';
1695 case '*':
1696 if (GET (c) == '=')
1697 return MULASGN;
1698 UNGET ();
1699 return '*';
1701 case '%':
1702 if (GET (c) == '=')
1703 return MODASGN;
1704 UNGET ();
1705 return '%';
1707 case '|':
1708 if (GET (c) == '|')
1709 return LOR;
1710 else if (c == '=')
1711 return ORASGN;
1712 UNGET ();
1713 return '|';
1715 case '&':
1716 if (GET (c) == '&')
1717 return LAND;
1718 else if (c == '=')
1719 return ANDASGN;
1720 UNGET ();
1721 return '&';
1723 case '^':
1724 if (GET (c) == '=')
1725 return XORASGN;
1726 UNGET ();
1727 return '^';
1729 case '.':
1730 if (GET (c) == '*')
1731 return POINTSTAR;
1732 else if (c == '.')
1734 if (GET (c) != '.')
1735 yyerror ("invalid token '..' ('...' assumed)", NULL);
1736 UNGET ();
1737 return ELLIPSIS;
1739 else if (!DIGITP (c))
1741 UNGET ();
1742 return '.';
1744 goto mantissa;
1746 case ':':
1747 if (GET (c) == ':')
1748 return DCOLON;
1749 UNGET ();
1750 return ':';
1752 case '=':
1753 if (GET (c) == '=')
1754 return EQ;
1755 UNGET ();
1756 return '=';
1758 case '!':
1759 if (GET (c) == '=')
1760 return NE;
1761 UNGET ();
1762 return '!';
1764 case '<':
1765 switch (GET (c))
1767 case '=':
1768 return LE;
1769 case '<':
1770 if (GET (c) == '=')
1771 return LSHIFTASGN;
1772 UNGET ();
1773 return LSHIFT;
1775 UNGET ();
1776 return '<';
1778 case '>':
1779 switch (GET (c))
1781 case '=':
1782 return GE;
1783 case '>':
1784 if (GET (c) == '=')
1785 return RSHIFTASGN;
1786 UNGET ();
1787 return RSHIFT;
1789 UNGET ();
1790 return '>';
1792 case '#':
1793 c = process_pp_line ();
1794 if (c == 0)
1795 return YYEOF;
1796 break;
1798 case '(': case ')': case '[': case ']': case '{': case '}':
1799 case ';': case ',': case '?': case '~':
1800 return c;
1802 case '0':
1803 yyival = 0;
1805 if (GET (c) == 'x' || c == 'X')
1807 while (GET (c))
1809 if (DIGITP (c))
1810 yyival = yyival * 16 + c - '0';
1811 else if (c >= 'a' && c <= 'f')
1812 yyival = yyival * 16 + c - 'a' + 10;
1813 else if (c >= 'A' && c <= 'F')
1814 yyival = yyival * 16 + c - 'A' + 10;
1815 else
1816 break;
1819 goto int_suffixes;
1821 else if (c == '.')
1822 goto mantissa;
1824 while (c >= '0' && c <= '7')
1826 yyival = (yyival << 3) + c - '0';
1827 GET (c);
1830 int_suffixes:
1831 /* Integer suffixes. */
1832 while (isalpha (c))
1833 GET (c);
1834 UNGET ();
1835 return CINT;
1837 case '1': case '2': case '3': case '4': case '5': case '6':
1838 case '7': case '8': case '9':
1839 /* Integer or floating constant, part before '.'. */
1840 yyival = c - '0';
1842 while (GET (c) && DIGITP (c))
1843 yyival = 10 * yyival + c - '0';
1845 if (c != '.')
1846 goto int_suffixes;
1848 mantissa:
1849 /* Digits following '.'. */
1850 while (DIGITP (c))
1851 GET (c);
1853 /* Optional exponent. */
1854 if (c == 'E' || c == 'e')
1856 if (GET (c) == '-' || c == '+')
1857 GET (c);
1859 while (DIGITP (c))
1860 GET (c);
1863 /* Optional type suffixes. */
1864 while (isalpha (c))
1865 GET (c);
1866 UNGET ();
1867 return CFLOAT;
1869 default:
1870 break;
1876 /* Actually local to matching_regexp. These variables must be in
1877 global scope for the case that `static' get's defined away. */
1879 static char *matching_regexp_buffer, *matching_regexp_end_buf;
1882 /* Value is the string from the start of the line to the current
1883 position in the input buffer, or maybe a bit more if that string is
1884 shorter than min_regexp. */
1886 static char *
1887 matching_regexp (void)
1889 char *p;
1890 char *s;
1891 char *t;
1893 if (!f_regexps)
1894 return NULL;
1896 if (matching_regexp_buffer == NULL)
1898 matching_regexp_buffer = (char *) xmalloc (max_regexp);
1899 matching_regexp_end_buf = &matching_regexp_buffer[max_regexp] - 1;
1902 /* Scan back to previous newline of buffer start. */
1903 for (p = in - 1; p > inbuffer && *p != '\n'; --p)
1906 if (*p == '\n')
1908 while (in - p < min_regexp && p > inbuffer)
1910 /* Line probably not significant enough */
1911 for (--p; p > inbuffer && *p != '\n'; --p)
1914 if (*p == '\n')
1915 ++p;
1918 /* Copy from end to make sure significant portions are included.
1919 This implies that in the browser a regular expressing of the form
1920 `^.*{regexp}' has to be used. */
1921 for (s = matching_regexp_end_buf - 1, t = in;
1922 s > matching_regexp_buffer && t > p;)
1924 *--s = *--t;
1926 if (*s == '"' || *s == '\\')
1927 *--s = '\\';
1930 *(matching_regexp_end_buf - 1) = '\0';
1931 return xstrdup (s);
1935 /* Return a printable representation of token T. */
1937 static const char *
1938 token_string (int t)
1940 static char b[3];
1942 switch (t)
1944 case CSTRING: return "string constant";
1945 case CCHAR: return "char constant";
1946 case CINT: return "int constant";
1947 case CFLOAT: return "floating constant";
1948 case ELLIPSIS: return "...";
1949 case LSHIFTASGN: return "<<=";
1950 case RSHIFTASGN: return ">>=";
1951 case ARROWSTAR: return "->*";
1952 case IDENT: return "identifier";
1953 case DIVASGN: return "/=";
1954 case INC: return "++";
1955 case ADDASGN: return "+=";
1956 case DEC: return "--";
1957 case ARROW: return "->";
1958 case SUBASGN: return "-=";
1959 case MULASGN: return "*=";
1960 case MODASGN: return "%=";
1961 case LOR: return "||";
1962 case ORASGN: return "|=";
1963 case LAND: return "&&";
1964 case ANDASGN: return "&=";
1965 case XORASGN: return "^=";
1966 case POINTSTAR: return ".*";
1967 case DCOLON: return "::";
1968 case EQ: return "==";
1969 case NE: return "!=";
1970 case LE: return "<=";
1971 case LSHIFT: return "<<";
1972 case GE: return ">=";
1973 case RSHIFT: return ">>";
1974 case ASM: return "asm";
1975 case AUTO: return "auto";
1976 case BREAK: return "break";
1977 case CASE: return "case";
1978 case CATCH: return "catch";
1979 case CHAR: return "char";
1980 case CLASS: return "class";
1981 case CONST: return "const";
1982 case CONTINUE: return "continue";
1983 case DEFAULT: return "default";
1984 case DELETE: return "delete";
1985 case DO: return "do";
1986 case DOUBLE: return "double";
1987 case ELSE: return "else";
1988 case ENUM: return "enum";
1989 case EXTERN: return "extern";
1990 case FLOAT: return "float";
1991 case FOR: return "for";
1992 case FRIEND: return "friend";
1993 case GOTO: return "goto";
1994 case IF: return "if";
1995 case T_INLINE: return "inline";
1996 case INT: return "int";
1997 case LONG: return "long";
1998 case NEW: return "new";
1999 case OPERATOR: return "operator";
2000 case PRIVATE: return "private";
2001 case PROTECTED: return "protected";
2002 case PUBLIC: return "public";
2003 case REGISTER: return "register";
2004 case RETURN: return "return";
2005 case SHORT: return "short";
2006 case SIGNED: return "signed";
2007 case SIZEOF: return "sizeof";
2008 case STATIC: return "static";
2009 case STRUCT: return "struct";
2010 case SWITCH: return "switch";
2011 case TEMPLATE: return "template";
2012 case THIS: return "this";
2013 case THROW: return "throw";
2014 case TRY: return "try";
2015 case TYPEDEF: return "typedef";
2016 case UNION: return "union";
2017 case UNSIGNED: return "unsigned";
2018 case VIRTUAL: return "virtual";
2019 case VOID: return "void";
2020 case VOLATILE: return "volatile";
2021 case WHILE: return "while";
2022 case MUTABLE: return "mutable";
2023 case BOOL: return "bool";
2024 case TRUE: return "true";
2025 case FALSE: return "false";
2026 case SIGNATURE: return "signature";
2027 case NAMESPACE: return "namespace";
2028 case EXPLICIT: return "explicit";
2029 case TYPENAME: return "typename";
2030 case CONST_CAST: return "const_cast";
2031 case DYNAMIC_CAST: return "dynamic_cast";
2032 case REINTERPRET_CAST: return "reinterpret_cast";
2033 case STATIC_CAST: return "static_cast";
2034 case TYPEID: return "typeid";
2035 case USING: return "using";
2036 case WCHAR: return "wchar_t";
2037 case YYEOF: return "EOF";
2039 default:
2040 if (t < 255)
2042 b[0] = t;
2043 b[1] = '\0';
2044 return b;
2046 else
2047 return "???";
2052 /* Reinitialize the scanner for a new input file. */
2054 static void
2055 re_init_scanner (void)
2057 in = inbuffer;
2058 yyline = 1;
2060 if (yytext == NULL)
2062 int size = 256;
2063 yytext = (char *) xmalloc (size * sizeof *yytext);
2064 yytext_end = yytext + size;
2069 /* Insert a keyword NAME with token value TKV into the keyword hash
2070 table. */
2072 static void
2073 insert_keyword (const char *name, int tkv)
2075 const char *s;
2076 unsigned h = 0;
2077 struct kw *k = (struct kw *) xmalloc (sizeof *k);
2079 for (s = name; *s; ++s)
2080 h = (h << 1) ^ *s;
2082 h %= KEYWORD_TABLE_SIZE;
2083 k->name = name;
2084 k->tk = tkv;
2085 k->next = keyword_table[h];
2086 keyword_table[h] = k;
2090 /* Initialize the scanner for the first file. This sets up the
2091 character class vectors and fills the keyword hash table. */
2093 static void
2094 init_scanner (void)
2096 int i;
2098 /* Allocate the input buffer */
2099 inbuffer_size = READ_CHUNK_SIZE + 1;
2100 inbuffer = in = (char *) xmalloc (inbuffer_size);
2101 yyline = 1;
2103 /* Set up character class vectors. */
2104 for (i = 0; i < sizeof is_ident; ++i)
2106 if (i == '_' || isalnum (i))
2107 is_ident[i] = 1;
2109 if (i >= '0' && i <= '9')
2110 is_digit[i] = 1;
2112 if (i == ' ' || i == '\t' || i == '\f' || i == '\v')
2113 is_white[i] = 1;
2116 /* Fill keyword hash table. */
2117 insert_keyword ("and", LAND);
2118 insert_keyword ("and_eq", ANDASGN);
2119 insert_keyword ("asm", ASM);
2120 insert_keyword ("auto", AUTO);
2121 insert_keyword ("bitand", '&');
2122 insert_keyword ("bitor", '|');
2123 insert_keyword ("bool", BOOL);
2124 insert_keyword ("break", BREAK);
2125 insert_keyword ("case", CASE);
2126 insert_keyword ("catch", CATCH);
2127 insert_keyword ("char", CHAR);
2128 insert_keyword ("class", CLASS);
2129 insert_keyword ("compl", '~');
2130 insert_keyword ("const", CONST);
2131 insert_keyword ("const_cast", CONST_CAST);
2132 insert_keyword ("continue", CONTINUE);
2133 insert_keyword ("default", DEFAULT);
2134 insert_keyword ("delete", DELETE);
2135 insert_keyword ("do", DO);
2136 insert_keyword ("double", DOUBLE);
2137 insert_keyword ("dynamic_cast", DYNAMIC_CAST);
2138 insert_keyword ("else", ELSE);
2139 insert_keyword ("enum", ENUM);
2140 insert_keyword ("explicit", EXPLICIT);
2141 insert_keyword ("extern", EXTERN);
2142 insert_keyword ("false", FALSE);
2143 insert_keyword ("float", FLOAT);
2144 insert_keyword ("for", FOR);
2145 insert_keyword ("friend", FRIEND);
2146 insert_keyword ("goto", GOTO);
2147 insert_keyword ("if", IF);
2148 insert_keyword ("inline", T_INLINE);
2149 insert_keyword ("int", INT);
2150 insert_keyword ("long", LONG);
2151 insert_keyword ("mutable", MUTABLE);
2152 insert_keyword ("namespace", NAMESPACE);
2153 insert_keyword ("new", NEW);
2154 insert_keyword ("not", '!');
2155 insert_keyword ("not_eq", NE);
2156 insert_keyword ("operator", OPERATOR);
2157 insert_keyword ("or", LOR);
2158 insert_keyword ("or_eq", ORASGN);
2159 insert_keyword ("private", PRIVATE);
2160 insert_keyword ("protected", PROTECTED);
2161 insert_keyword ("public", PUBLIC);
2162 insert_keyword ("register", REGISTER);
2163 insert_keyword ("reinterpret_cast", REINTERPRET_CAST);
2164 insert_keyword ("return", RETURN);
2165 insert_keyword ("short", SHORT);
2166 insert_keyword ("signed", SIGNED);
2167 insert_keyword ("sizeof", SIZEOF);
2168 insert_keyword ("static", STATIC);
2169 insert_keyword ("static_cast", STATIC_CAST);
2170 insert_keyword ("struct", STRUCT);
2171 insert_keyword ("switch", SWITCH);
2172 insert_keyword ("template", TEMPLATE);
2173 insert_keyword ("this", THIS);
2174 insert_keyword ("throw", THROW);
2175 insert_keyword ("true", TRUE);
2176 insert_keyword ("try", TRY);
2177 insert_keyword ("typedef", TYPEDEF);
2178 insert_keyword ("typeid", TYPEID);
2179 insert_keyword ("typename", TYPENAME);
2180 insert_keyword ("union", UNION);
2181 insert_keyword ("unsigned", UNSIGNED);
2182 insert_keyword ("using", USING);
2183 insert_keyword ("virtual", VIRTUAL);
2184 insert_keyword ("void", VOID);
2185 insert_keyword ("volatile", VOLATILE);
2186 insert_keyword ("wchar_t", WCHAR);
2187 insert_keyword ("while", WHILE);
2188 insert_keyword ("xor", '^');
2189 insert_keyword ("xor_eq", XORASGN);
2194 /***********************************************************************
2195 Parser
2196 ***********************************************************************/
2198 /* Match the current lookahead token and set it to the next token. */
2200 #define MATCH() (tk = yylex ())
2202 /* Return the lookahead token. If current lookahead token is cleared,
2203 read a new token. */
2205 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2207 /* Is the current lookahead equal to the token T? */
2209 #define LOOKING_AT(T) (tk == (T))
2211 /* Is the current lookahead one of T1 or T2? */
2213 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2215 /* Is the current lookahead one of T1, T2 or T3? */
2217 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2219 /* Is the current lookahead one of T1...T4? */
2221 #define LOOKING_AT4(T1, T2, T3, T4) \
2222 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2224 /* Match token T if current lookahead is T. */
2226 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2228 /* Skip to matching token if current token is T. */
2230 #define SKIP_MATCHING_IF(T) \
2231 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2234 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2235 the current lookahead token after skipping. */
2237 static int
2238 skip_to (int token)
2240 while (!LOOKING_AT2 (YYEOF, token))
2241 MATCH ();
2242 return tk;
2245 /* Skip over pairs of tokens (parentheses, square brackets,
2246 angle brackets, curly brackets) matching the current lookahead. */
2248 static void
2249 skip_matching (void)
2251 int open, close, n;
2253 switch (open = LA1)
2255 case '{':
2256 close = '}';
2257 break;
2259 case '(':
2260 close = ')';
2261 break;
2263 case '<':
2264 close = '>';
2265 break;
2267 case '[':
2268 close = ']';
2269 break;
2271 default:
2272 abort ();
2275 for (n = 0;;)
2277 if (LOOKING_AT (open))
2278 ++n;
2279 else if (LOOKING_AT (close))
2280 --n;
2281 else if (LOOKING_AT (YYEOF))
2282 break;
2284 MATCH ();
2286 if (n == 0)
2287 break;
2291 static void
2292 skip_initializer (void)
2294 for (;;)
2296 switch (LA1)
2298 case ';':
2299 case ',':
2300 case YYEOF:
2301 return;
2303 case '{':
2304 case '[':
2305 case '(':
2306 skip_matching ();
2307 break;
2309 default:
2310 MATCH ();
2311 break;
2316 /* Build qualified namespace alias (A::B::c) and return it. */
2318 static struct link *
2319 match_qualified_namespace_alias (void)
2321 struct link *head = NULL;
2322 struct link *cur = NULL;
2323 struct link *tmp = NULL;
2325 for (;;)
2327 MATCH ();
2328 switch (LA1)
2330 case IDENT:
2331 tmp = (struct link *) xmalloc (sizeof *cur);
2332 tmp->sym = find_namespace (yytext, cur ? cur->sym : NULL);
2333 tmp->next = NULL;
2334 if (head)
2336 cur = cur->next = tmp;
2338 else
2340 head = cur = tmp;
2342 break;
2343 case DCOLON:
2344 /* Just skip */
2345 break;
2346 default:
2347 return head;
2348 break;
2353 /* Re-initialize the parser by resetting the lookahead token. */
2355 static void
2356 re_init_parser (void)
2358 tk = -1;
2362 /* Parse a parameter list, including the const-specifier,
2363 pure-specifier, and throw-list that may follow a parameter list.
2364 Return in FLAGS what was seen following the parameter list.
2365 Returns a hash code for the parameter types. This value is used to
2366 distinguish between overloaded functions. */
2368 static unsigned
2369 parm_list (int *flags)
2371 unsigned hash = 0;
2372 int type_seen = 0;
2374 while (!LOOKING_AT2 (YYEOF, ')'))
2376 switch (LA1)
2378 /* Skip over grouping parens or parameter lists in parameter
2379 declarations. */
2380 case '(':
2381 skip_matching ();
2382 break;
2384 /* Next parameter. */
2385 case ',':
2386 MATCH ();
2387 type_seen = 0;
2388 break;
2390 /* Ignore the scope part of types, if any. This is because
2391 some types need scopes when defined outside of a class body,
2392 and don't need them inside the class body. This means that
2393 we have to look for the last IDENT in a sequence of
2394 IDENT::IDENT::... */
2395 case IDENT:
2396 if (!type_seen)
2398 char *last_id;
2399 unsigned ident_type_hash = 0;
2401 parse_qualified_param_ident_or_type (&last_id);
2402 if (last_id)
2404 /* LAST_ID null means something like `X::*'. */
2405 for (; *last_id; ++last_id)
2406 ident_type_hash = (ident_type_hash << 1) ^ *last_id;
2407 hash = (hash << 1) ^ ident_type_hash;
2408 type_seen = 1;
2411 else
2412 MATCH ();
2413 break;
2415 case VOID:
2416 /* This distinction is made to make `func (void)' equivalent
2417 to `func ()'. */
2418 type_seen = 1;
2419 MATCH ();
2420 if (!LOOKING_AT (')'))
2421 hash = (hash << 1) ^ VOID;
2422 break;
2424 case BOOL: case CHAR: case CLASS: case CONST:
2425 case DOUBLE: case ENUM: case FLOAT: case INT:
2426 case LONG: case SHORT: case SIGNED: case STRUCT:
2427 case UNION: case UNSIGNED: case VOLATILE: case WCHAR:
2428 case ELLIPSIS:
2429 type_seen = 1;
2430 hash = (hash << 1) ^ LA1;
2431 MATCH ();
2432 break;
2434 case '*': case '&': case '[': case ']':
2435 hash = (hash << 1) ^ LA1;
2436 MATCH ();
2437 break;
2439 default:
2440 MATCH ();
2441 break;
2445 if (LOOKING_AT (')'))
2447 MATCH ();
2449 if (LOOKING_AT (CONST))
2451 /* We can overload the same function on `const' */
2452 hash = (hash << 1) ^ CONST;
2453 set_flag (flags, F_CONST);
2454 MATCH ();
2457 if (LOOKING_AT (THROW))
2459 MATCH ();
2460 SKIP_MATCHING_IF ('(');
2461 set_flag (flags, F_THROW);
2464 if (LOOKING_AT ('='))
2466 MATCH ();
2467 if (LOOKING_AT (CINT) && yyival == 0)
2469 MATCH ();
2470 set_flag (flags, F_PURE);
2475 return hash;
2479 /* Print position info to stdout. */
2481 static void
2482 print_info (void)
2484 if (info_position >= 0 && BUFFER_POS () <= info_position)
2485 if (info_cls)
2486 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2487 info_cls->name, sym_scope (info_cls),
2488 info_member->name, info_where);
2492 /* Parse a member declaration within the class body of CLS. VIS is
2493 the access specifier for the member (private, protected,
2494 public). */
2496 static void
2497 member (struct sym *cls, int vis)
2499 char *id = NULL;
2500 int sc = SC_MEMBER;
2501 char *regexp = NULL;
2502 int pos;
2503 int is_constructor;
2504 int anonymous = 0;
2505 int flags = 0;
2506 int class_tag;
2507 int type_seen = 0;
2508 int paren_seen = 0;
2509 unsigned hash = 0;
2510 int tilde = 0;
2512 while (!LOOKING_AT4 (';', '{', '}', YYEOF))
2514 switch (LA1)
2516 default:
2517 MATCH ();
2518 break;
2520 /* A function or class may follow. */
2521 case TEMPLATE:
2522 MATCH ();
2523 set_flag (&flags, F_TEMPLATE);
2524 /* Skip over template argument list */
2525 SKIP_MATCHING_IF ('<');
2526 break;
2528 case EXPLICIT:
2529 set_flag (&flags, F_EXPLICIT);
2530 goto typeseen;
2532 case MUTABLE:
2533 set_flag (&flags, F_MUTABLE);
2534 goto typeseen;
2536 case T_INLINE:
2537 set_flag (&flags, F_INLINE);
2538 goto typeseen;
2540 case VIRTUAL:
2541 set_flag (&flags, F_VIRTUAL);
2542 goto typeseen;
2544 case '[':
2545 skip_matching ();
2546 break;
2548 case ENUM:
2549 sc = SC_TYPE;
2550 goto typeseen;
2552 case TYPEDEF:
2553 sc = SC_TYPE;
2554 goto typeseen;
2556 case FRIEND:
2557 sc = SC_FRIEND;
2558 goto typeseen;
2560 case STATIC:
2561 sc = SC_STATIC;
2562 goto typeseen;
2564 case '~':
2565 tilde = 1;
2566 MATCH ();
2567 break;
2569 case IDENT:
2570 /* Remember IDENTS seen so far. Among these will be the member
2571 name. */
2572 id = (char *) xrealloc (id, strlen (yytext) + 2);
2573 if (tilde)
2575 *id = '~';
2576 strcpy (id + 1, yytext);
2578 else
2579 strcpy (id, yytext);
2580 MATCH ();
2581 break;
2583 case OPERATOR:
2585 char *s = operator_name (&sc);
2586 id = (char *) xrealloc (id, strlen (s) + 1);
2587 strcpy (id, s);
2589 break;
2591 case '(':
2592 /* Most probably the beginning of a parameter list. */
2593 MATCH ();
2594 paren_seen = 1;
2596 if (id && cls)
2598 if (!(is_constructor = streq (id, cls->name)))
2599 regexp = matching_regexp ();
2601 else
2602 is_constructor = 0;
2604 pos = BUFFER_POS ();
2605 hash = parm_list (&flags);
2607 if (is_constructor)
2608 regexp = matching_regexp ();
2610 if (id && cls != NULL)
2611 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, flags);
2613 while (!LOOKING_AT3 (';', '{', YYEOF))
2614 MATCH ();
2616 if (LOOKING_AT ('{') && id && cls)
2617 add_member_defn (cls, id, regexp, pos, hash, 0, sc, flags);
2619 free (id);
2620 id = NULL;
2621 sc = SC_MEMBER;
2622 break;
2624 case STRUCT: case UNION: case CLASS:
2625 /* Nested class */
2626 class_tag = LA1;
2627 type_seen = 1;
2628 MATCH ();
2629 anonymous = 1;
2631 /* More than one ident here to allow for MS-DOS specialties
2632 like `_export class' etc. The last IDENT seen counts
2633 as the class name. */
2634 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
2636 if (LOOKING_AT (IDENT))
2637 anonymous = 0;
2638 MATCH ();
2641 if (LOOKING_AT2 (':', '{'))
2642 class_definition (anonymous ? NULL : cls, class_tag, flags, 1);
2643 else
2644 skip_to (';');
2645 break;
2647 case INT: case CHAR: case LONG: case UNSIGNED:
2648 case SIGNED: case CONST: case DOUBLE: case VOID:
2649 case SHORT: case VOLATILE: case BOOL: case WCHAR:
2650 case TYPENAME:
2651 typeseen:
2652 type_seen = 1;
2653 MATCH ();
2654 break;
2658 if (LOOKING_AT (';'))
2660 /* The end of a member variable, a friend declaration or an access
2661 declaration. We don't want to add friend classes as members. */
2662 if (id && sc != SC_FRIEND && cls)
2664 regexp = matching_regexp ();
2665 pos = BUFFER_POS ();
2667 if (cls != NULL)
2669 if (type_seen || !paren_seen)
2670 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2671 else
2672 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0);
2676 MATCH ();
2677 print_info ();
2679 else if (LOOKING_AT ('{'))
2681 /* A named enum. */
2682 if (sc == SC_TYPE && id && cls)
2684 regexp = matching_regexp ();
2685 pos = BUFFER_POS ();
2687 if (cls != NULL)
2689 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2690 add_member_defn (cls, id, regexp, pos, 0, 1, sc, 0);
2694 skip_matching ();
2695 print_info ();
2698 free (id);
2702 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2703 union, class). */
2705 static void
2706 class_body (struct sym *cls, int tag)
2708 int vis = tag == CLASS ? PRIVATE : PUBLIC;
2709 int temp;
2711 while (!LOOKING_AT2 (YYEOF, '}'))
2713 switch (LA1)
2715 case PRIVATE: case PROTECTED: case PUBLIC:
2716 temp = LA1;
2717 MATCH ();
2719 if (LOOKING_AT (':'))
2721 vis = temp;
2722 MATCH ();
2724 else
2726 /* Probably conditional compilation for inheritance list.
2727 We don't known whether there comes more of this.
2728 This is only a crude fix that works most of the time. */
2731 MATCH ();
2733 while (LOOKING_AT2 (IDENT, ',')
2734 || LOOKING_AT3 (PUBLIC, PROTECTED, PRIVATE));
2736 break;
2738 case TYPENAME:
2739 case USING:
2740 skip_to (';');
2741 break;
2743 /* Try to synchronize */
2744 case CHAR: case CLASS: case CONST:
2745 case DOUBLE: case ENUM: case FLOAT: case INT:
2746 case LONG: case SHORT: case SIGNED: case STRUCT:
2747 case UNION: case UNSIGNED: case VOID: case VOLATILE:
2748 case TYPEDEF: case STATIC: case T_INLINE: case FRIEND:
2749 case VIRTUAL: case TEMPLATE: case IDENT: case '~':
2750 case BOOL: case WCHAR: case EXPLICIT: case MUTABLE:
2751 member (cls, vis);
2752 break;
2754 default:
2755 MATCH ();
2756 break;
2762 /* Parse a qualified identifier. Current lookahead is IDENT. A
2763 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2764 symbol for that class. */
2766 static struct sym *
2767 parse_classname (void)
2769 struct sym *last_class = NULL;
2771 while (LOOKING_AT (IDENT))
2773 last_class = add_sym (yytext, last_class);
2774 MATCH ();
2776 if (LOOKING_AT ('<'))
2778 skip_matching ();
2779 set_flag (&last_class->flags, F_TEMPLATE);
2782 if (!LOOKING_AT (DCOLON))
2783 break;
2785 MATCH ();
2788 return last_class;
2792 /* Parse an operator name. Add the `static' flag to *SC if an
2793 implicitly static operator has been parsed. Value is a pointer to
2794 a static buffer holding the constructed operator name string. */
2796 static char *
2797 operator_name (int *sc)
2799 static size_t id_size = 0;
2800 static char *id = NULL;
2801 const char *s;
2802 size_t len;
2804 MATCH ();
2806 if (LOOKING_AT2 (NEW, DELETE))
2808 /* `new' and `delete' are implicitly static. */
2809 if (*sc != SC_FRIEND)
2810 *sc = SC_STATIC;
2812 s = token_string (LA1);
2813 MATCH ();
2815 ptrdiff_t slen = strlen (s);
2816 len = slen + 10;
2817 if (len > id_size)
2819 size_t new_size = max (len, 2 * id_size);
2820 id = (char *) xrealloc (id, new_size);
2821 id_size = new_size;
2823 char *z = stpcpy (id, s);
2825 /* Vector new or delete? */
2826 if (LOOKING_AT ('['))
2828 z = stpcpy (z, "[");
2829 MATCH ();
2831 if (LOOKING_AT (']'))
2833 strcpy (z, "]");
2834 MATCH ();
2838 else
2840 size_t tokens_matched = 0;
2842 len = 20;
2843 if (len > id_size)
2845 int new_size = max (len, 2 * id_size);
2846 id = (char *) xrealloc (id, new_size);
2847 id_size = new_size;
2849 char *z = stpcpy (id, "operator");
2851 /* Beware access declarations of the form "X::f;" Beware of
2852 `operator () ()'. Yet another difficulty is found in
2853 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2854 while (!(LOOKING_AT ('(') && tokens_matched)
2855 && !LOOKING_AT2 (';', YYEOF))
2857 s = token_string (LA1);
2858 len += strlen (s) + 2;
2859 if (len > id_size)
2861 ptrdiff_t idlen = z - id;
2862 size_t new_size = max (len, 2 * id_size);
2863 id = (char *) xrealloc (id, new_size);
2864 id_size = new_size;
2865 z = id + idlen;
2868 if (*s != ')' && *s != ']')
2869 *z++ = ' ';
2870 z = stpcpy (z, s);
2871 MATCH ();
2873 /* If this is a simple operator like `+', stop now. */
2874 if (!isalpha ((unsigned char) *s) && *s != '(' && *s != '[')
2875 break;
2877 ++tokens_matched;
2881 return id;
2885 /* This one consumes the last IDENT of a qualified member name like
2886 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2887 symbol structure for the ident. */
2889 static struct sym *
2890 parse_qualified_ident_or_type (char **last_id)
2892 struct sym *cls = NULL;
2893 char *id = NULL;
2894 size_t id_size = 0;
2895 int enter = 0;
2897 while (LOOKING_AT (IDENT))
2899 int len = strlen (yytext) + 1;
2900 if (len > id_size)
2902 id = (char *) xrealloc (id, len);
2903 id_size = len;
2905 strcpy (id, yytext);
2906 *last_id = id;
2907 MATCH ();
2909 SKIP_MATCHING_IF ('<');
2911 if (LOOKING_AT (DCOLON))
2913 struct sym *pcn = NULL;
2914 struct link *pna = check_namespace_alias (id);
2915 if (pna)
2919 enter_namespace (pna->sym->name);
2920 enter++;
2921 pna = pna->next;
2923 while (pna);
2925 else if ((pcn = check_namespace (id, current_namespace)))
2927 enter_namespace (pcn->name);
2928 enter++;
2930 else
2931 cls = add_sym (id, cls);
2933 *last_id = NULL;
2934 free (id);
2935 id = NULL;
2936 id_size = 0;
2937 MATCH ();
2939 else
2940 break;
2943 while (enter--)
2944 leave_namespace ();
2946 return cls;
2950 /* This one consumes the last IDENT of a qualified member name like
2951 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2952 symbol structure for the ident. */
2954 static void
2955 parse_qualified_param_ident_or_type (char **last_id)
2957 struct sym *cls = NULL;
2958 static char *id = NULL;
2959 static int id_size = 0;
2961 assert (LOOKING_AT (IDENT));
2965 int len = strlen (yytext) + 1;
2966 if (len > id_size)
2968 id = (char *) xrealloc (id, len);
2969 id_size = len;
2971 strcpy (id, yytext);
2972 *last_id = id;
2973 MATCH ();
2975 SKIP_MATCHING_IF ('<');
2977 if (LOOKING_AT (DCOLON))
2979 cls = add_sym (id, cls);
2980 *last_id = NULL;
2981 MATCH ();
2983 else
2984 break;
2986 while (LOOKING_AT (IDENT));
2990 /* Parse a class definition.
2992 CONTAINING is the class containing the class being parsed or null.
2993 This may also be null if NESTED != 0 if the containing class is
2994 anonymous. TAG is the tag of the class (struct, union, class).
2995 NESTED is non-zero if we are parsing a nested class.
2997 Current lookahead is the class name. */
2999 static void
3000 class_definition (struct sym *containing, int tag, int flags, int nested)
3002 struct sym *current;
3003 struct sym *base_class;
3005 /* Set CURRENT to null if no entry has to be made for the class
3006 parsed. This is the case for certain command line flag
3007 settings. */
3008 if ((tag != CLASS && !f_structs) || (nested && !f_nested_classes))
3009 current = NULL;
3010 else
3012 current = add_sym (yytext, containing);
3013 current->pos = BUFFER_POS ();
3014 current->regexp = matching_regexp ();
3015 current->filename = filename;
3016 current->flags = flags;
3019 /* If at ':', base class list follows. */
3020 if (LOOKING_AT (':'))
3022 int done = 0;
3023 MATCH ();
3025 while (!done)
3027 switch (LA1)
3029 case VIRTUAL: case PUBLIC: case PROTECTED: case PRIVATE:
3030 MATCH ();
3031 break;
3033 case IDENT:
3034 base_class = parse_classname ();
3035 if (base_class && current && base_class != current)
3036 add_link (base_class, current);
3037 break;
3039 /* The `,' between base classes or the end of the base
3040 class list. Add the previously found base class.
3041 It's done this way to skip over sequences of
3042 `A::B::C' until we reach the end.
3044 FIXME: it is now possible to handle `class X : public B::X'
3045 because we have enough information. */
3046 case ',':
3047 MATCH ();
3048 break;
3050 default:
3051 /* A syntax error, possibly due to preprocessor constructs
3052 like
3054 #ifdef SOMETHING
3055 class A : public B
3056 #else
3057 class A : private B.
3059 MATCH until we see something like `;' or `{'. */
3060 while (!LOOKING_AT3 (';', YYEOF, '{'))
3061 MATCH ();
3062 FALLTHROUGH;
3063 case '{':
3064 done = 1;
3065 break;
3070 /* Parse the class body if there is one. */
3071 if (LOOKING_AT ('{'))
3073 if (tag != CLASS && !f_structs)
3074 skip_matching ();
3075 else
3077 MATCH ();
3078 class_body (current, tag);
3080 if (LOOKING_AT ('}'))
3082 MATCH ();
3083 if (LOOKING_AT (';') && !nested)
3084 MATCH ();
3090 /* Add to class *CLS information for the declaration of variable or
3091 type *ID. If *CLS is null, this means a global declaration. SC is
3092 the storage class of *ID. FLAGS is a bit set giving additional
3093 information about the member (see the F_* defines). */
3095 static void
3096 add_declarator (struct sym **cls, char **id, int flags, int sc)
3098 if (LOOKING_AT2 (';', ','))
3100 /* The end of a member variable or of an access declaration
3101 `X::f'. To distinguish between them we have to know whether
3102 type information has been seen. */
3103 if (*id)
3105 char *regexp = matching_regexp ();
3106 int pos = BUFFER_POS ();
3108 if (*cls)
3109 add_member_defn (*cls, *id, regexp, pos, 0, 1, SC_UNKNOWN, flags);
3110 else
3111 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3114 MATCH ();
3115 print_info ();
3117 else if (LOOKING_AT ('{'))
3119 if (sc == SC_TYPE && *id)
3121 /* A named enumeration. */
3122 char *regexp = matching_regexp ();
3123 int pos = BUFFER_POS ();
3124 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3127 skip_matching ();
3128 print_info ();
3131 free (*id);
3132 *id = NULL;
3133 *cls = NULL;
3136 /* Parse a declaration. */
3138 static void
3139 declaration (int flags)
3141 char *id = NULL;
3142 struct sym *cls = NULL;
3143 char *regexp = NULL;
3144 int pos = 0;
3145 unsigned hash = 0;
3146 int is_constructor;
3147 int sc = 0;
3149 while (!LOOKING_AT3 (';', '{', YYEOF))
3151 switch (LA1)
3153 default:
3154 MATCH ();
3155 break;
3157 case '[':
3158 skip_matching ();
3159 break;
3161 case ENUM:
3162 case TYPEDEF:
3163 sc = SC_TYPE;
3164 MATCH ();
3165 break;
3167 case STATIC:
3168 sc = SC_STATIC;
3169 MATCH ();
3170 break;
3172 case INT: case CHAR: case LONG: case UNSIGNED:
3173 case SIGNED: case CONST: case DOUBLE: case VOID:
3174 case SHORT: case VOLATILE: case BOOL: case WCHAR:
3175 MATCH ();
3176 break;
3178 case CLASS: case STRUCT: case UNION:
3179 /* This is for the case `STARTWRAP class X : ...' or
3180 `declare (X, Y)\n class A : ...'. */
3181 if (id)
3183 free (id);
3184 return;
3186 FALLTHROUGH;
3187 case '=':
3188 /* Assumed to be the start of an initialization in this
3189 context. */
3190 skip_initializer ();
3191 break;
3193 case ',':
3194 add_declarator (&cls, &id, flags, sc);
3195 break;
3197 case OPERATOR:
3199 char *s = operator_name (&sc);
3200 id = (char *) xrealloc (id, strlen (s) + 1);
3201 strcpy (id, s);
3203 break;
3205 case T_INLINE:
3206 set_flag (&flags, F_INLINE);
3207 MATCH ();
3208 break;
3210 case '~':
3211 MATCH ();
3212 if (LOOKING_AT (IDENT))
3214 id = (char *) xrealloc (id, strlen (yytext) + 2);
3215 *id = '~';
3216 strcpy (id + 1, yytext);
3217 MATCH ();
3219 break;
3221 case IDENT:
3222 cls = parse_qualified_ident_or_type (&id);
3223 break;
3225 case '(':
3226 /* Most probably the beginning of a parameter list. */
3227 if (cls)
3229 MATCH ();
3231 if (id && cls)
3233 if (!(is_constructor = streq (id, cls->name)))
3234 regexp = matching_regexp ();
3236 else
3237 is_constructor = 0;
3239 pos = BUFFER_POS ();
3240 hash = parm_list (&flags);
3242 if (is_constructor)
3243 regexp = matching_regexp ();
3245 if (id && cls)
3246 add_member_defn (cls, id, regexp, pos, hash, 0,
3247 SC_UNKNOWN, flags);
3249 else
3251 /* This may be a C functions, but also a macro
3252 call of the form `declare (A, B)' --- such macros
3253 can be found in some class libraries. */
3254 MATCH ();
3256 if (id)
3258 regexp = matching_regexp ();
3259 pos = BUFFER_POS ();
3260 hash = parm_list (&flags);
3261 add_global_decl (id, regexp, pos, hash, 0, sc, flags);
3264 /* This is for the case that the function really is
3265 a macro with no `;' following it. If a CLASS directly
3266 follows, we would miss it otherwise. */
3267 if (LOOKING_AT3 (CLASS, STRUCT, UNION))
3268 return;
3271 while (!LOOKING_AT3 (';', '{', YYEOF))
3272 MATCH ();
3274 if (!cls && id && LOOKING_AT ('{'))
3275 add_global_defn (id, regexp, pos, hash, 0, sc, flags);
3277 free (id);
3278 id = NULL;
3279 break;
3283 add_declarator (&cls, &id, flags, sc);
3287 /* Parse a list of top-level declarations/definitions. START_FLAGS
3288 says in which context we are parsing. If it is F_EXTERNC, we are
3289 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3290 otherwise. */
3292 static int
3293 globals (int start_flags)
3295 int anonymous;
3296 int class_tk;
3297 int flags = start_flags;
3299 for (;;)
3301 char *prev_in = in;
3303 switch (LA1)
3305 case NAMESPACE:
3307 MATCH ();
3309 if (LOOKING_AT (IDENT))
3311 char *namespace_name = xstrdup (yytext);
3312 MATCH ();
3314 if (LOOKING_AT ('='))
3316 struct link *qna = match_qualified_namespace_alias ();
3317 if (qna)
3318 register_namespace_alias (namespace_name, qna);
3320 if (skip_to (';') == ';')
3321 MATCH ();
3323 else if (LOOKING_AT ('{'))
3325 MATCH ();
3326 enter_namespace (namespace_name);
3327 globals (0);
3328 leave_namespace ();
3329 MATCH_IF ('}');
3332 free (namespace_name);
3335 break;
3337 case EXTERN:
3338 MATCH ();
3339 if (LOOKING_AT (CSTRING) && *string_start == 'C'
3340 && *(string_start + 1) == '"')
3342 /* This is `extern "C"'. */
3343 MATCH ();
3345 if (LOOKING_AT ('{'))
3347 MATCH ();
3348 globals (F_EXTERNC);
3349 MATCH_IF ('}');
3351 else
3352 set_flag (&flags, F_EXTERNC);
3354 break;
3356 case TEMPLATE:
3357 MATCH ();
3358 SKIP_MATCHING_IF ('<');
3359 set_flag (&flags, F_TEMPLATE);
3360 break;
3362 case CLASS: case STRUCT: case UNION:
3363 class_tk = LA1;
3364 MATCH ();
3365 anonymous = 1;
3367 /* More than one ident here to allow for MS-DOS and OS/2
3368 specialties like `far', `_Export' etc. Some C++ libs
3369 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3370 of the class name. */
3371 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
3373 if (LOOKING_AT (IDENT))
3374 anonymous = 0;
3375 MATCH ();
3378 /* Don't add anonymous unions. */
3379 if (LOOKING_AT2 (':', '{') && !anonymous)
3380 class_definition (NULL, class_tk, flags, 0);
3381 else
3383 if (skip_to (';') == ';')
3384 MATCH ();
3387 flags = start_flags;
3388 break;
3390 case YYEOF:
3391 return 1;
3393 case '}':
3394 return 0;
3396 default:
3397 declaration (flags);
3398 flags = start_flags;
3399 break;
3402 if (prev_in == in)
3403 yyerror ("parse error", NULL);
3408 /* Parse the current input file. */
3410 static void
3411 yyparse (void)
3413 while (globals (0) == 0)
3414 MATCH_IF ('}');
3419 /***********************************************************************
3420 Main Program
3421 ***********************************************************************/
3423 /* Add the list of paths PATH_LIST to the current search path for
3424 input files. */
3426 static void
3427 add_search_path (char *path_list)
3429 while (*path_list)
3431 char *start = path_list;
3432 struct search_path *p;
3434 while (*path_list && *path_list != SEPCHAR)
3435 ++path_list;
3437 p = (struct search_path *) xmalloc (sizeof *p);
3438 p->path = (char *) xmalloc (path_list - start + 1);
3439 memcpy (p->path, start, path_list - start);
3440 p->path[path_list - start] = '\0';
3441 p->next = NULL;
3443 if (search_path_tail)
3445 search_path_tail->next = p;
3446 search_path_tail = p;
3448 else
3449 search_path = search_path_tail = p;
3451 while (*path_list == SEPCHAR)
3452 ++path_list;
3457 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3458 opened. Try to find FILE in search_path first, then try the
3459 unchanged file name. */
3461 static FILE *
3462 open_file (char *file)
3464 FILE *fp = NULL;
3465 static char *buffer;
3466 static int buffer_size;
3467 struct search_path *path;
3468 int flen = strlen (file) + 1; /* +1 for the slash */
3470 filename = xstrdup (file);
3472 for (path = search_path; path && fp == NULL; path = path->next)
3474 int len = strlen (path->path) + flen;
3476 if (len + 1 >= buffer_size)
3478 buffer_size = max (len + 1, 2 * buffer_size);
3479 buffer = (char *) xrealloc (buffer, buffer_size);
3482 char *z = stpcpy (buffer, path->path);
3483 *z++ = '/';
3484 strcpy (z, file);
3485 fp = fopen (buffer, "r");
3488 /* Try the original file name. */
3489 if (fp == NULL)
3490 fp = fopen (file, "r");
3492 if (fp == NULL)
3493 yyerror ("cannot open", NULL);
3495 return fp;
3499 /* Display usage information and exit program. */
3501 static char const *const usage_message[] =
3504 Usage: ebrowse [options] {files}\n\
3506 -a, --append append output to existing file\n\
3507 -f, --files=FILES read input file names from FILE\n\
3508 -I, --search-path=LIST set search path for input files\n\
3509 -m, --min-regexp-length=N set minimum regexp length to N\n\
3510 -M, --max-regexp-length=N set maximum regexp length to N\n\
3513 -n, --no-nested-classes exclude nested classes\n\
3514 -o, --output-file=FILE set output file name to FILE\n\
3515 -p, --position-info print info about position in file\n\
3516 -s, --no-structs-or-unions don't record structs or unions\n\
3517 -v, --verbose be verbose\n\
3518 -V, --very-verbose be very verbose\n\
3519 -x, --no-regexps don't record regular expressions\n\
3520 --help display this help\n\
3521 --version display version info\n\
3526 static _Noreturn void
3527 usage (int error)
3529 int i;
3530 for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++)
3531 fputs (usage_message[i], stdout);
3532 exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
3536 /* Display version and copyright info. The VERSION macro is set
3537 from config.h and contains the Emacs version. */
3539 #ifndef VERSION
3540 # define VERSION "21"
3541 #endif
3543 static _Noreturn void
3544 version (void)
3546 char emacs_copyright[] = COPYRIGHT;
3548 printf ("ebrowse %s\n", VERSION);
3549 puts (emacs_copyright);
3550 puts ("This program is distributed under the same terms as Emacs.");
3551 exit (EXIT_SUCCESS);
3555 /* Parse one input file FILE, adding classes and members to the symbol
3556 table. */
3558 static void
3559 process_file (char *file)
3561 FILE *fp;
3563 fp = open_file (file);
3564 if (fp)
3566 size_t nread, nbytes;
3568 /* Give a progress indication if needed. */
3569 if (f_very_verbose)
3571 puts (filename);
3572 fflush (stdout);
3574 else if (f_verbose)
3576 putchar ('.');
3577 fflush (stdout);
3580 /* Read file to inbuffer. */
3581 for (nread = 0;;)
3583 if (nread + READ_CHUNK_SIZE >= inbuffer_size)
3585 inbuffer_size = nread + READ_CHUNK_SIZE + 1;
3586 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
3589 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3590 if (nbytes == 0)
3591 break;
3592 nread += nbytes;
3594 inbuffer[nread] = '\0';
3596 /* Reinitialize scanner and parser for the new input file. */
3597 re_init_scanner ();
3598 re_init_parser ();
3600 /* Parse it and close the file. */
3601 yyparse ();
3602 fclose (fp);
3607 /* Read a line from stream FP and return a pointer to a static buffer
3608 containing its contents without the terminating newline. Value
3609 is null when EOF is reached. */
3611 static char *
3612 read_line (FILE *fp)
3614 static char *buffer;
3615 static int buffer_size;
3616 int i = 0, c;
3618 while ((c = getc (fp)) != EOF && c != '\n')
3620 if (i >= buffer_size)
3622 buffer_size = max (100, buffer_size * 2);
3623 buffer = (char *) xrealloc (buffer, buffer_size);
3626 buffer[i++] = c;
3629 if (c == EOF && i == 0)
3630 return NULL;
3632 if (i == buffer_size)
3634 buffer_size = max (100, buffer_size * 2);
3635 buffer = (char *) xrealloc (buffer, buffer_size);
3638 buffer[i] = '\0';
3639 if (i > 0 && buffer[i - 1] == '\r')
3640 buffer[i - 1] = '\0';
3641 return buffer;
3645 /* Main entry point. */
3648 main (int argc, char **argv)
3650 int i;
3651 int any_inputfiles = 0;
3652 static const char *out_filename = DEFAULT_OUTFILE;
3653 static char **input_filenames = NULL;
3654 static int input_filenames_size = 0;
3655 static int n_input_files;
3657 filename = "command line";
3658 yyout = stdout;
3660 while ((i = getopt_long (argc, argv, "af:I:m:M:no:p:svVx",
3661 options, NULL)) != EOF)
3663 switch (i)
3665 /* Experimental. */
3666 case 'p':
3667 info_position = atoi (optarg);
3668 break;
3670 case 'n':
3671 f_nested_classes = 0;
3672 break;
3674 case 'x':
3675 f_regexps = 0;
3676 break;
3678 /* Add the name of a file containing more input files. */
3679 case 'f':
3680 if (n_input_files == input_filenames_size)
3682 input_filenames_size = max (10, 2 * input_filenames_size);
3683 input_filenames = (char **) xrealloc ((void *)input_filenames,
3684 input_filenames_size);
3686 input_filenames[n_input_files++] = xstrdup (optarg);
3687 break;
3689 /* Append new output to output file instead of truncating it. */
3690 case 'a':
3691 f_append = 1;
3692 break;
3694 /* Include structs in the output */
3695 case 's':
3696 f_structs = 0;
3697 break;
3699 /* Be verbose (give a progress indication). */
3700 case 'v':
3701 f_verbose = 1;
3702 break;
3704 /* Be very verbose (print file names as they are processed). */
3705 case 'V':
3706 f_verbose = 1;
3707 f_very_verbose = 1;
3708 break;
3710 /* Change the name of the output file. */
3711 case 'o':
3712 out_filename = optarg;
3713 break;
3715 /* Set minimum length for regular expression strings
3716 when recorded in the output file. */
3717 case 'm':
3718 min_regexp = atoi (optarg);
3719 break;
3721 /* Set maximum length for regular expression strings
3722 when recorded in the output file. */
3723 case 'M':
3724 max_regexp = atoi (optarg);
3725 break;
3727 /* Add to search path. */
3728 case 'I':
3729 add_search_path (optarg);
3730 break;
3732 /* Display help */
3733 case -2:
3734 usage (0);
3735 break;
3737 case -3:
3738 version ();
3739 break;
3743 /* Call init_scanner after command line flags have been processed to be
3744 able to add keywords depending on command line (not yet
3745 implemented). */
3746 init_scanner ();
3747 init_sym ();
3749 /* Open output file */
3750 if (*out_filename)
3752 if (f_append)
3754 /* Check that the file to append to exists, and is not
3755 empty. More specifically, it should be a valid file
3756 produced by a previous run of ebrowse, but that's too
3757 difficult to check. */
3758 FILE *fp;
3759 int rc;
3761 fp = fopen (out_filename, "r");
3762 if (fp == NULL)
3764 yyerror ("file '%s' must exist for --append", out_filename);
3765 exit (EXIT_FAILURE);
3768 rc = fseek (fp, 0, SEEK_END);
3769 if (rc == -1)
3771 yyerror ("error seeking in file '%s'", out_filename);
3772 exit (EXIT_FAILURE);
3775 rc = ftell (fp);
3776 if (rc == -1)
3778 yyerror ("error getting size of file '%s'", out_filename);
3779 exit (EXIT_FAILURE);
3782 else if (rc == 0)
3784 yyerror ("file '%s' is empty", out_filename);
3785 /* It may be ok to use an empty file for appending.
3786 exit (EXIT_FAILURE); */
3789 fclose (fp);
3792 yyout = fopen (out_filename, f_append ? "a" : "w");
3793 if (yyout == NULL)
3795 yyerror ("cannot open output file '%s'", out_filename);
3796 exit (EXIT_FAILURE);
3800 /* Process input files specified on the command line. */
3801 while (optind < argc)
3803 process_file (argv[optind++]);
3804 any_inputfiles = 1;
3807 /* Process files given on stdin if no files specified. */
3808 if (!any_inputfiles && n_input_files == 0)
3810 char *file;
3811 while ((file = read_line (stdin)) != NULL)
3812 process_file (file);
3814 else
3816 /* Process files from `--files=FILE'. Every line in FILE names
3817 one input file to process. */
3818 for (i = 0; i < n_input_files; ++i)
3820 FILE *fp = fopen (input_filenames[i], "r");
3822 if (fp == NULL)
3823 yyerror ("cannot open input file '%s'", input_filenames[i]);
3824 else
3826 char *file;
3827 while ((file = read_line (fp)) != NULL)
3828 process_file (file);
3829 fclose (fp);
3834 /* Write output file. */
3835 dump_roots (yyout);
3837 /* Close output file. */
3838 if (yyout != stdout)
3839 fclose (yyout);
3841 return EXIT_SUCCESS;
3844 /* ebrowse.c ends here */