; * lisp/replace.el (how-many, flush-lines, keep-lines): Remove empty line.
[emacs.git] / lib-src / ebrowse.c
blob623911027cea4a441e8b71b167f2549cde289a32
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 <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <assert.h>
28 #include <getopt.h>
30 /* The SunOS compiler doesn't have SEEK_END. */
31 #ifndef SEEK_END
32 #define SEEK_END 2
33 #endif
35 #include <flexmember.h>
36 #include <min-max.h>
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 done = 1;
3064 case '{':
3065 done = 1;
3066 break;
3071 /* Parse the class body if there is one. */
3072 if (LOOKING_AT ('{'))
3074 if (tag != CLASS && !f_structs)
3075 skip_matching ();
3076 else
3078 MATCH ();
3079 class_body (current, tag);
3081 if (LOOKING_AT ('}'))
3083 MATCH ();
3084 if (LOOKING_AT (';') && !nested)
3085 MATCH ();
3091 /* Add to class *CLS information for the declaration of variable or
3092 type *ID. If *CLS is null, this means a global declaration. SC is
3093 the storage class of *ID. FLAGS is a bit set giving additional
3094 information about the member (see the F_* defines). */
3096 static void
3097 add_declarator (struct sym **cls, char **id, int flags, int sc)
3099 if (LOOKING_AT2 (';', ','))
3101 /* The end of a member variable or of an access declaration
3102 `X::f'. To distinguish between them we have to know whether
3103 type information has been seen. */
3104 if (*id)
3106 char *regexp = matching_regexp ();
3107 int pos = BUFFER_POS ();
3109 if (*cls)
3110 add_member_defn (*cls, *id, regexp, pos, 0, 1, SC_UNKNOWN, flags);
3111 else
3112 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3115 MATCH ();
3116 print_info ();
3118 else if (LOOKING_AT ('{'))
3120 if (sc == SC_TYPE && *id)
3122 /* A named enumeration. */
3123 char *regexp = matching_regexp ();
3124 int pos = BUFFER_POS ();
3125 add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
3128 skip_matching ();
3129 print_info ();
3132 free (*id);
3133 *id = NULL;
3134 *cls = NULL;
3137 /* Parse a declaration. */
3139 static void
3140 declaration (int flags)
3142 char *id = NULL;
3143 struct sym *cls = NULL;
3144 char *regexp = NULL;
3145 int pos = 0;
3146 unsigned hash = 0;
3147 int is_constructor;
3148 int sc = 0;
3150 while (!LOOKING_AT3 (';', '{', YYEOF))
3152 switch (LA1)
3154 default:
3155 MATCH ();
3156 break;
3158 case '[':
3159 skip_matching ();
3160 break;
3162 case ENUM:
3163 case TYPEDEF:
3164 sc = SC_TYPE;
3165 MATCH ();
3166 break;
3168 case STATIC:
3169 sc = SC_STATIC;
3170 MATCH ();
3171 break;
3173 case INT: case CHAR: case LONG: case UNSIGNED:
3174 case SIGNED: case CONST: case DOUBLE: case VOID:
3175 case SHORT: case VOLATILE: case BOOL: case WCHAR:
3176 MATCH ();
3177 break;
3179 case CLASS: case STRUCT: case UNION:
3180 /* This is for the case `STARTWRAP class X : ...' or
3181 `declare (X, Y)\n class A : ...'. */
3182 if (id)
3184 free (id);
3185 return;
3188 case '=':
3189 /* Assumed to be the start of an initialization in this
3190 context. */
3191 skip_initializer ();
3192 break;
3194 case ',':
3195 add_declarator (&cls, &id, flags, sc);
3196 break;
3198 case OPERATOR:
3200 char *s = operator_name (&sc);
3201 id = (char *) xrealloc (id, strlen (s) + 1);
3202 strcpy (id, s);
3204 break;
3206 case T_INLINE:
3207 set_flag (&flags, F_INLINE);
3208 MATCH ();
3209 break;
3211 case '~':
3212 MATCH ();
3213 if (LOOKING_AT (IDENT))
3215 id = (char *) xrealloc (id, strlen (yytext) + 2);
3216 *id = '~';
3217 strcpy (id + 1, yytext);
3218 MATCH ();
3220 break;
3222 case IDENT:
3223 cls = parse_qualified_ident_or_type (&id);
3224 break;
3226 case '(':
3227 /* Most probably the beginning of a parameter list. */
3228 if (cls)
3230 MATCH ();
3232 if (id && cls)
3234 if (!(is_constructor = streq (id, cls->name)))
3235 regexp = matching_regexp ();
3237 else
3238 is_constructor = 0;
3240 pos = BUFFER_POS ();
3241 hash = parm_list (&flags);
3243 if (is_constructor)
3244 regexp = matching_regexp ();
3246 if (id && cls)
3247 add_member_defn (cls, id, regexp, pos, hash, 0,
3248 SC_UNKNOWN, flags);
3250 else
3252 /* This may be a C functions, but also a macro
3253 call of the form `declare (A, B)' --- such macros
3254 can be found in some class libraries. */
3255 MATCH ();
3257 if (id)
3259 regexp = matching_regexp ();
3260 pos = BUFFER_POS ();
3261 hash = parm_list (&flags);
3262 add_global_decl (id, regexp, pos, hash, 0, sc, flags);
3265 /* This is for the case that the function really is
3266 a macro with no `;' following it. If a CLASS directly
3267 follows, we would miss it otherwise. */
3268 if (LOOKING_AT3 (CLASS, STRUCT, UNION))
3269 return;
3272 while (!LOOKING_AT3 (';', '{', YYEOF))
3273 MATCH ();
3275 if (!cls && id && LOOKING_AT ('{'))
3276 add_global_defn (id, regexp, pos, hash, 0, sc, flags);
3278 free (id);
3279 id = NULL;
3280 break;
3284 add_declarator (&cls, &id, flags, sc);
3288 /* Parse a list of top-level declarations/definitions. START_FLAGS
3289 says in which context we are parsing. If it is F_EXTERNC, we are
3290 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3291 otherwise. */
3293 static int
3294 globals (int start_flags)
3296 int anonymous;
3297 int class_tk;
3298 int flags = start_flags;
3300 for (;;)
3302 char *prev_in = in;
3304 switch (LA1)
3306 case NAMESPACE:
3308 MATCH ();
3310 if (LOOKING_AT (IDENT))
3312 char *namespace_name = xstrdup (yytext);
3313 MATCH ();
3315 if (LOOKING_AT ('='))
3317 struct link *qna = match_qualified_namespace_alias ();
3318 if (qna)
3319 register_namespace_alias (namespace_name, qna);
3321 if (skip_to (';') == ';')
3322 MATCH ();
3324 else if (LOOKING_AT ('{'))
3326 MATCH ();
3327 enter_namespace (namespace_name);
3328 globals (0);
3329 leave_namespace ();
3330 MATCH_IF ('}');
3333 free (namespace_name);
3336 break;
3338 case EXTERN:
3339 MATCH ();
3340 if (LOOKING_AT (CSTRING) && *string_start == 'C'
3341 && *(string_start + 1) == '"')
3343 /* This is `extern "C"'. */
3344 MATCH ();
3346 if (LOOKING_AT ('{'))
3348 MATCH ();
3349 globals (F_EXTERNC);
3350 MATCH_IF ('}');
3352 else
3353 set_flag (&flags, F_EXTERNC);
3355 break;
3357 case TEMPLATE:
3358 MATCH ();
3359 SKIP_MATCHING_IF ('<');
3360 set_flag (&flags, F_TEMPLATE);
3361 break;
3363 case CLASS: case STRUCT: case UNION:
3364 class_tk = LA1;
3365 MATCH ();
3366 anonymous = 1;
3368 /* More than one ident here to allow for MS-DOS and OS/2
3369 specialties like `far', `_Export' etc. Some C++ libs
3370 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3371 of the class name. */
3372 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
3374 if (LOOKING_AT (IDENT))
3375 anonymous = 0;
3376 MATCH ();
3379 /* Don't add anonymous unions. */
3380 if (LOOKING_AT2 (':', '{') && !anonymous)
3381 class_definition (NULL, class_tk, flags, 0);
3382 else
3384 if (skip_to (';') == ';')
3385 MATCH ();
3388 flags = start_flags;
3389 break;
3391 case YYEOF:
3392 return 1;
3394 case '}':
3395 return 0;
3397 default:
3398 declaration (flags);
3399 flags = start_flags;
3400 break;
3403 if (prev_in == in)
3404 yyerror ("parse error", NULL);
3409 /* Parse the current input file. */
3411 static void
3412 yyparse (void)
3414 while (globals (0) == 0)
3415 MATCH_IF ('}');
3420 /***********************************************************************
3421 Main Program
3422 ***********************************************************************/
3424 /* Add the list of paths PATH_LIST to the current search path for
3425 input files. */
3427 static void
3428 add_search_path (char *path_list)
3430 while (*path_list)
3432 char *start = path_list;
3433 struct search_path *p;
3435 while (*path_list && *path_list != SEPCHAR)
3436 ++path_list;
3438 p = (struct search_path *) xmalloc (sizeof *p);
3439 p->path = (char *) xmalloc (path_list - start + 1);
3440 memcpy (p->path, start, path_list - start);
3441 p->path[path_list - start] = '\0';
3442 p->next = NULL;
3444 if (search_path_tail)
3446 search_path_tail->next = p;
3447 search_path_tail = p;
3449 else
3450 search_path = search_path_tail = p;
3452 while (*path_list == SEPCHAR)
3453 ++path_list;
3458 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3459 opened. Try to find FILE in search_path first, then try the
3460 unchanged file name. */
3462 static FILE *
3463 open_file (char *file)
3465 FILE *fp = NULL;
3466 static char *buffer;
3467 static int buffer_size;
3468 struct search_path *path;
3469 int flen = strlen (file) + 1; /* +1 for the slash */
3471 filename = xstrdup (file);
3473 for (path = search_path; path && fp == NULL; path = path->next)
3475 int len = strlen (path->path) + flen;
3477 if (len + 1 >= buffer_size)
3479 buffer_size = max (len + 1, 2 * buffer_size);
3480 buffer = (char *) xrealloc (buffer, buffer_size);
3483 char *z = stpcpy (buffer, path->path);
3484 *z++ = '/';
3485 strcpy (z, file);
3486 fp = fopen (buffer, "r");
3489 /* Try the original file name. */
3490 if (fp == NULL)
3491 fp = fopen (file, "r");
3493 if (fp == NULL)
3494 yyerror ("cannot open", NULL);
3496 return fp;
3500 /* Display usage information and exit program. */
3502 static char const *const usage_message[] =
3505 Usage: ebrowse [options] {files}\n\
3507 -a, --append append output to existing file\n\
3508 -f, --files=FILES read input file names from FILE\n\
3509 -I, --search-path=LIST set search path for input files\n\
3510 -m, --min-regexp-length=N set minimum regexp length to N\n\
3511 -M, --max-regexp-length=N set maximum regexp length to N\n\
3514 -n, --no-nested-classes exclude nested classes\n\
3515 -o, --output-file=FILE set output file name to FILE\n\
3516 -p, --position-info print info about position in file\n\
3517 -s, --no-structs-or-unions don't record structs or unions\n\
3518 -v, --verbose be verbose\n\
3519 -V, --very-verbose be very verbose\n\
3520 -x, --no-regexps don't record regular expressions\n\
3521 --help display this help\n\
3522 --version display version info\n\
3527 static _Noreturn void
3528 usage (int error)
3530 int i;
3531 for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++)
3532 fputs (usage_message[i], stdout);
3533 exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
3537 /* Display version and copyright info. The VERSION macro is set
3538 from config.h and contains the Emacs version. */
3540 #ifndef VERSION
3541 # define VERSION "21"
3542 #endif
3544 static _Noreturn void
3545 version (void)
3547 char emacs_copyright[] = COPYRIGHT;
3549 printf ("ebrowse %s\n", VERSION);
3550 puts (emacs_copyright);
3551 puts ("This program is distributed under the same terms as Emacs.");
3552 exit (EXIT_SUCCESS);
3556 /* Parse one input file FILE, adding classes and members to the symbol
3557 table. */
3559 static void
3560 process_file (char *file)
3562 FILE *fp;
3564 fp = open_file (file);
3565 if (fp)
3567 size_t nread, nbytes;
3569 /* Give a progress indication if needed. */
3570 if (f_very_verbose)
3572 puts (filename);
3573 fflush (stdout);
3575 else if (f_verbose)
3577 putchar ('.');
3578 fflush (stdout);
3581 /* Read file to inbuffer. */
3582 for (nread = 0;;)
3584 if (nread + READ_CHUNK_SIZE >= inbuffer_size)
3586 inbuffer_size = nread + READ_CHUNK_SIZE + 1;
3587 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
3590 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3591 if (nbytes == 0)
3592 break;
3593 nread += nbytes;
3595 inbuffer[nread] = '\0';
3597 /* Reinitialize scanner and parser for the new input file. */
3598 re_init_scanner ();
3599 re_init_parser ();
3601 /* Parse it and close the file. */
3602 yyparse ();
3603 fclose (fp);
3608 /* Read a line from stream FP and return a pointer to a static buffer
3609 containing its contents without the terminating newline. Value
3610 is null when EOF is reached. */
3612 static char *
3613 read_line (FILE *fp)
3615 static char *buffer;
3616 static int buffer_size;
3617 int i = 0, c;
3619 while ((c = getc (fp)) != EOF && c != '\n')
3621 if (i >= buffer_size)
3623 buffer_size = max (100, buffer_size * 2);
3624 buffer = (char *) xrealloc (buffer, buffer_size);
3627 buffer[i++] = c;
3630 if (c == EOF && i == 0)
3631 return NULL;
3633 if (i == buffer_size)
3635 buffer_size = max (100, buffer_size * 2);
3636 buffer = (char *) xrealloc (buffer, buffer_size);
3639 buffer[i] = '\0';
3640 if (i > 0 && buffer[i - 1] == '\r')
3641 buffer[i - 1] = '\0';
3642 return buffer;
3646 /* Main entry point. */
3649 main (int argc, char **argv)
3651 int i;
3652 int any_inputfiles = 0;
3653 static const char *out_filename = DEFAULT_OUTFILE;
3654 static char **input_filenames = NULL;
3655 static int input_filenames_size = 0;
3656 static int n_input_files;
3658 filename = "command line";
3659 yyout = stdout;
3661 while ((i = getopt_long (argc, argv, "af:I:m:M:no:p:svVx",
3662 options, NULL)) != EOF)
3664 switch (i)
3666 /* Experimental. */
3667 case 'p':
3668 info_position = atoi (optarg);
3669 break;
3671 case 'n':
3672 f_nested_classes = 0;
3673 break;
3675 case 'x':
3676 f_regexps = 0;
3677 break;
3679 /* Add the name of a file containing more input files. */
3680 case 'f':
3681 if (n_input_files == input_filenames_size)
3683 input_filenames_size = max (10, 2 * input_filenames_size);
3684 input_filenames = (char **) xrealloc ((void *)input_filenames,
3685 input_filenames_size);
3687 input_filenames[n_input_files++] = xstrdup (optarg);
3688 break;
3690 /* Append new output to output file instead of truncating it. */
3691 case 'a':
3692 f_append = 1;
3693 break;
3695 /* Include structs in the output */
3696 case 's':
3697 f_structs = 0;
3698 break;
3700 /* Be verbose (give a progress indication). */
3701 case 'v':
3702 f_verbose = 1;
3703 break;
3705 /* Be very verbose (print file names as they are processed). */
3706 case 'V':
3707 f_verbose = 1;
3708 f_very_verbose = 1;
3709 break;
3711 /* Change the name of the output file. */
3712 case 'o':
3713 out_filename = optarg;
3714 break;
3716 /* Set minimum length for regular expression strings
3717 when recorded in the output file. */
3718 case 'm':
3719 min_regexp = atoi (optarg);
3720 break;
3722 /* Set maximum length for regular expression strings
3723 when recorded in the output file. */
3724 case 'M':
3725 max_regexp = atoi (optarg);
3726 break;
3728 /* Add to search path. */
3729 case 'I':
3730 add_search_path (optarg);
3731 break;
3733 /* Display help */
3734 case -2:
3735 usage (0);
3736 break;
3738 case -3:
3739 version ();
3740 break;
3744 /* Call init_scanner after command line flags have been processed to be
3745 able to add keywords depending on command line (not yet
3746 implemented). */
3747 init_scanner ();
3748 init_sym ();
3750 /* Open output file */
3751 if (*out_filename)
3753 if (f_append)
3755 /* Check that the file to append to exists, and is not
3756 empty. More specifically, it should be a valid file
3757 produced by a previous run of ebrowse, but that's too
3758 difficult to check. */
3759 FILE *fp;
3760 int rc;
3762 fp = fopen (out_filename, "r");
3763 if (fp == NULL)
3765 yyerror ("file '%s' must exist for --append", out_filename);
3766 exit (EXIT_FAILURE);
3769 rc = fseek (fp, 0, SEEK_END);
3770 if (rc == -1)
3772 yyerror ("error seeking in file '%s'", out_filename);
3773 exit (EXIT_FAILURE);
3776 rc = ftell (fp);
3777 if (rc == -1)
3779 yyerror ("error getting size of file '%s'", out_filename);
3780 exit (EXIT_FAILURE);
3783 else if (rc == 0)
3785 yyerror ("file '%s' is empty", out_filename);
3786 /* It may be ok to use an empty file for appending.
3787 exit (EXIT_FAILURE); */
3790 fclose (fp);
3793 yyout = fopen (out_filename, f_append ? "a" : "w");
3794 if (yyout == NULL)
3796 yyerror ("cannot open output file '%s'", out_filename);
3797 exit (EXIT_FAILURE);
3801 /* Process input files specified on the command line. */
3802 while (optind < argc)
3804 process_file (argv[optind++]);
3805 any_inputfiles = 1;
3808 /* Process files given on stdin if no files specified. */
3809 if (!any_inputfiles && n_input_files == 0)
3811 char *file;
3812 while ((file = read_line (stdin)) != NULL)
3813 process_file (file);
3815 else
3817 /* Process files from `--files=FILE'. Every line in FILE names
3818 one input file to process. */
3819 for (i = 0; i < n_input_files; ++i)
3821 FILE *fp = fopen (input_filenames[i], "r");
3823 if (fp == NULL)
3824 yyerror ("cannot open input file '%s'", input_filenames[i]);
3825 else
3827 char *file;
3828 while ((file = read_line (fp)) != NULL)
3829 process_file (file);
3830 fclose (fp);
3835 /* Write output file. */
3836 dump_roots (yyout);
3838 /* Close output file. */
3839 if (yyout != stdout)
3840 fclose (yyout);
3842 return EXIT_SUCCESS;
3845 /* ebrowse.c ends here */