* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Fix (bug#19704)
[emacs.git] / lib-src / ebrowse.c
blobc59181f9464e05339da699c2eb37c2e3727eed97
1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2016 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 <min-max.h>
37 /* Files are read in chunks of this number of bytes. */
39 enum { READ_CHUNK_SIZE = 100 * 1024 };
41 /* Value is true if strings X and Y compare equal. */
43 static bool
44 streq (char const *x, char const *y)
46 return strcmp (x, y) == 0;
49 static bool
50 filename_eq (char const *x, char const *y)
52 #ifdef __MSDOS__
53 return strcasecmp (x, y) == 0;
54 #elif defined WINDOWSNT
55 return stricmp (x, y) == 0;
56 #else
57 return streq (x, y);
58 #endif
61 /* The default output file name. */
63 #define DEFAULT_OUTFILE "BROWSE"
65 /* A version string written to the output file. Change this whenever
66 the structure of the output file changes. */
68 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
70 /* The output file consists of a tree of Lisp objects, with major
71 nodes built out of Lisp structures. These are the heads of the
72 Lisp structs with symbols identifying their type. */
74 #define TREE_HEADER_STRUCT "[ebrowse-hs "
75 #define TREE_STRUCT "[ebrowse-ts "
76 #define MEMBER_STRUCT "[ebrowse-ms "
77 #define CLASS_STRUCT "[ebrowse-cs "
79 /* The name of the symbol table entry for global functions, variables,
80 defines etc. This name also appears in the browser display. */
82 #define GLOBALS_NAME "*Globals*"
84 /* Token definitions. */
86 enum token
88 YYEOF = 0, /* end of file */
89 CSTRING = 256, /* string constant */
90 CCHAR, /* character constant */
91 CINT, /* integral constant */
92 CFLOAT, /* real constant */
94 ELLIPSIS, /* ... */
95 LSHIFTASGN, /* <<= */
96 RSHIFTASGN, /* >>= */
97 ARROWSTAR, /* ->* */
98 IDENT, /* identifier */
99 DIVASGN, /* /= */
100 INC, /* ++ */
101 ADDASGN, /* += */
102 DEC, /* -- */
103 ARROW, /* -> */
104 SUBASGN, /* -= */
105 MULASGN, /* *= */
106 MODASGN, /* %= */
107 LOR, /* || */
108 ORASGN, /* |= */
109 LAND, /* && */
110 ANDASGN, /* &= */
111 XORASGN, /* ^= */
112 POINTSTAR, /* .* */
113 DCOLON, /* :: */
114 EQ, /* == */
115 NE, /* != */
116 LE, /* <= */
117 LSHIFT, /* << */
118 GE, /* >= */
119 RSHIFT, /* >> */
121 /* Keywords. The undef's are there because these
122 three symbols are very likely to be defined somewhere. */
123 #undef BOOL
124 #undef TRUE
125 #undef FALSE
127 ASM, /* asm */
128 AUTO, /* auto */
129 BREAK, /* break */
130 CASE, /* case */
131 CATCH, /* catch */
132 CHAR, /* char */
133 CLASS, /* class */
134 CONST, /* const */
135 CONTINUE, /* continue */
136 DEFAULT, /* default */
137 DELETE, /* delete */
138 DO, /* do */
139 DOUBLE, /* double */
140 ELSE, /* else */
141 ENUM, /* enum */
142 EXTERN, /* extern */
143 FLOAT, /* float */
144 FOR, /* for */
145 FRIEND, /* friend */
146 GOTO, /* goto */
147 IF, /* if */
148 T_INLINE, /* inline */
149 INT, /* int */
150 LONG, /* long */
151 NEW, /* new */
152 OPERATOR, /* operator */
153 PRIVATE, /* private */
154 PROTECTED, /* protected */
155 PUBLIC, /* public */
156 REGISTER, /* register */
157 RETURN, /* return */
158 SHORT, /* short */
159 SIGNED, /* signed */
160 SIZEOF, /* sizeof */
161 STATIC, /* static */
162 STRUCT, /* struct */
163 SWITCH, /* switch */
164 TEMPLATE, /* template */
165 THIS, /* this */
166 THROW, /* throw */
167 TRY, /* try */
168 TYPEDEF, /* typedef */
169 UNION, /* union */
170 UNSIGNED, /* unsigned */
171 VIRTUAL, /* virtual */
172 VOID, /* void */
173 VOLATILE, /* volatile */
174 WHILE, /* while */
175 MUTABLE, /* mutable */
176 BOOL, /* bool */
177 TRUE, /* true */
178 FALSE, /* false */
179 SIGNATURE, /* signature (GNU extension) */
180 NAMESPACE, /* namespace */
181 EXPLICIT, /* explicit */
182 TYPENAME, /* typename */
183 CONST_CAST, /* const_cast */
184 DYNAMIC_CAST, /* dynamic_cast */
185 REINTERPRET_CAST, /* reinterpret_cast */
186 STATIC_CAST, /* static_cast */
187 TYPEID, /* typeid */
188 USING, /* using */
189 WCHAR /* wchar_t */
192 /* Storage classes, in a wider sense. */
194 enum sc
196 SC_UNKNOWN,
197 SC_MEMBER, /* Is an instance member. */
198 SC_STATIC, /* Is static member. */
199 SC_FRIEND, /* Is friend function. */
200 SC_TYPE /* Is a type definition. */
203 /* Member visibility. */
205 enum visibility
207 V_PUBLIC,
208 V_PROTECTED,
209 V_PRIVATE
212 /* Member flags. */
214 #define F_VIRTUAL 1 /* Is virtual function. */
215 #define F_INLINE 2 /* Is inline function. */
216 #define F_CONST 4 /* Is const. */
217 #define F_PURE 8 /* Is pure virtual function. */
218 #define F_MUTABLE 16 /* Is mutable. */
219 #define F_TEMPLATE 32 /* Is a template. */
220 #define F_EXPLICIT 64 /* Is explicit constructor. */
221 #define F_THROW 128 /* Has a throw specification. */
222 #define F_EXTERNC 256 /* Is declared extern "C". */
223 #define F_DEFINE 512 /* Is a #define. */
225 /* Set and test a bit in an int. */
227 static void
228 set_flag (int *f, int flag)
230 *f |= flag;
233 static bool
234 has_flag (int f, int flag)
236 return (f & flag) != 0;
239 /* Structure describing a class member. */
241 struct member
243 struct member *next; /* Next in list of members. */
244 struct member *anext; /* Collision chain in member_table. */
245 struct member **list; /* Pointer to list in class. */
246 unsigned param_hash; /* Hash value for parameter types. */
247 int vis; /* Visibility (public, ...). */
248 int flags; /* See F_* above. */
249 char *regexp; /* Matching regular expression. */
250 const char *filename; /* Don't free this shared string. */
251 int pos; /* Buffer position of occurrence. */
252 char *def_regexp; /* Regular expression matching definition. */
253 const char *def_filename; /* File name of definition. */
254 int def_pos; /* Buffer position of definition. */
255 char name[FLEXIBLE_ARRAY_MEMBER]; /* Member name. */
258 /* Structures of this type are used to connect class structures with
259 their super and subclasses. */
261 struct link
263 struct sym *sym; /* The super or subclass. */
264 struct link *next; /* Next in list or NULL. */
267 /* Structure used to record namespace aliases. */
269 struct alias
271 struct alias *next; /* Next in list. */
272 struct sym *namesp; /* Namespace in which defined. */
273 struct link *aliasee; /* List of aliased namespaces (A::B::C...). */
274 char name[FLEXIBLE_ARRAY_MEMBER]; /* Alias name. */
277 /* The structure used to describe a class in the symbol table,
278 or a namespace in all_namespaces. */
280 struct sym
282 int flags; /* Is class a template class?. */
283 unsigned char visited; /* Used to find circles. */
284 struct sym *next; /* Hash collision list. */
285 struct link *subs; /* List of subclasses. */
286 struct link *supers; /* List of superclasses. */
287 struct member *vars; /* List of instance variables. */
288 struct member *fns; /* List of instance functions. */
289 struct member *static_vars; /* List of static variables. */
290 struct member *static_fns; /* List of static functions. */
291 struct member *friends; /* List of friend functions. */
292 struct member *types; /* List of local types. */
293 char *regexp; /* Matching regular expression. */
294 int pos; /* Buffer position. */
295 const char *filename; /* File in which it can be found. */
296 const char *sfilename; /* File in which members can be found. */
297 struct sym *namesp; /* Namespace in which defined. . */
298 char name[FLEXIBLE_ARRAY_MEMBER]; /* Name of the class. */
301 /* Experimental: Print info for `--position-info'. We print
302 '(CLASS-NAME SCOPE MEMBER-NAME). */
304 #define P_DEFN 1
305 #define P_DECL 2
307 int info_where;
308 struct sym *info_cls = NULL;
309 struct member *info_member = NULL;
311 /* Experimental. For option `--position-info', the buffer position we
312 are interested in. When this position is reached, print out
313 information about what we know about that point. */
315 int info_position = -1;
317 /* Command line options structure for getopt_long. */
319 struct option options[] =
321 {"append", no_argument, NULL, 'a'},
322 {"files", required_argument, NULL, 'f'},
323 {"help", no_argument, NULL, -2},
324 {"min-regexp-length", required_argument, NULL, 'm'},
325 {"max-regexp-length", required_argument, NULL, 'M'},
326 {"no-nested-classes", no_argument, NULL, 'n'},
327 {"no-regexps", no_argument, NULL, 'x'},
328 {"no-structs-or-unions", no_argument, NULL, 's'},
329 {"output-file", required_argument, NULL, 'o'},
330 {"position-info", required_argument, NULL, 'p'},
331 {"search-path", required_argument, NULL, 'I'},
332 {"verbose", no_argument, NULL, 'v'},
333 {"version", no_argument, NULL, -3},
334 {"very-verbose", no_argument, NULL, 'V'},
335 {NULL, 0, NULL, 0}
338 /* Semantic values of tokens. Set by yylex.. */
340 unsigned yyival; /* Set for token CINT. */
341 char *yytext; /* Set for token IDENT. */
342 char *yytext_end;
344 /* Output file. */
346 FILE *yyout;
348 /* Current line number. */
350 int yyline;
352 /* The name of the current input file. */
354 const char *filename;
356 /* Three character class vectors, and macros to test membership
357 of characters. */
359 char is_ident[255];
360 char is_digit[255];
361 char is_white[255];
363 #define IDENTP(C) is_ident[(unsigned char) (C)]
364 #define DIGITP(C) is_digit[(unsigned char) (C)]
365 #define WHITEP(C) is_white[(unsigned char) (C)]
367 /* Command line flags. */
369 int f_append;
370 int f_verbose;
371 int f_very_verbose;
372 int f_structs = 1;
373 int f_regexps = 1;
374 int f_nested_classes = 1;
376 /* Maximum and minimum lengths of regular expressions matching a
377 member, class etc., for writing them to the output file. These are
378 overridable from the command line. */
380 int min_regexp = 5;
381 int max_regexp = 50;
383 /* Input buffer. */
385 char *inbuffer;
386 char *in;
387 size_t inbuffer_size;
389 /* Return the current buffer position in the input file. */
391 #define BUFFER_POS() (in - inbuffer)
393 /* If current lookahead is CSTRING, the following points to the
394 first character in the string constant. Used for recognizing
395 extern "C". */
397 char *string_start;
399 /* The size of the hash tables for classes.and members. Should be
400 prime. */
402 #define TABLE_SIZE 1001
404 /* The hash table for class symbols. */
406 struct sym *class_table[TABLE_SIZE];
408 /* Hash table containing all member structures. This is generally
409 faster for member lookup than traversing the member lists of a
410 `struct sym'. */
412 struct member *member_table[TABLE_SIZE];
414 /* Hash table for namespace aliases */
416 struct alias *namespace_alias_table[TABLE_SIZE];
418 /* The special class symbol used to hold global functions,
419 variables etc. */
421 struct sym *global_symbols;
423 /* The current namespace. */
425 struct sym *current_namespace;
427 /* The list of all known namespaces. */
429 struct sym *all_namespaces;
431 /* Stack of namespaces we're currently nested in, during the parse. */
433 struct sym **namespace_stack;
434 int namespace_stack_size;
435 int namespace_sp;
437 /* The current lookahead token. */
439 int tk = -1;
441 /* Structure describing a keyword. */
443 struct kw
445 const char *name; /* Spelling. */
446 int tk; /* Token value. */
447 struct kw *next; /* Next in collision chain. */
450 /* Keywords are lookup up in a hash table of their own. */
452 #define KEYWORD_TABLE_SIZE 1001
453 struct kw *keyword_table[KEYWORD_TABLE_SIZE];
455 /* Search path. */
457 struct search_path
459 char *path;
460 struct search_path *next;
463 struct search_path *search_path;
464 struct search_path *search_path_tail;
466 /* Function prototypes. */
468 static char *matching_regexp (void);
469 static struct sym *add_sym (const char *, struct sym *);
470 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
471 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
472 static struct member *add_member (struct sym *, char *, int, int, unsigned);
473 static void class_definition (struct sym *, int, int, int);
474 static char *operator_name (int *);
475 static void parse_qualified_param_ident_or_type (char **);
477 /***********************************************************************
478 Utilities
479 ***********************************************************************/
481 /* Print an error in a printf-like style with the current input file
482 name and line number. */
484 static void
485 yyerror (const char *format, const char *s)
487 fprintf (stderr, "%s:%d: ", filename, yyline);
488 fprintf (stderr, format, s);
489 putc ('\n', stderr);
493 /* Like malloc but print an error and exit if not enough memory is
494 available. */
496 static void *
497 xmalloc (size_t nbytes)
499 void *p = malloc (nbytes);
500 if (p == NULL)
502 yyerror ("out of memory", NULL);
503 exit (EXIT_FAILURE);
505 return p;
509 /* Like realloc but print an error and exit if out of memory. */
511 static void *
512 xrealloc (void *p, size_t sz)
514 p = realloc (p, sz);
515 if (p == NULL)
517 yyerror ("out of memory", NULL);
518 exit (EXIT_FAILURE);
520 return p;
524 /* Like strdup, but print an error and exit if not enough memory is
525 available.. If S is null, return null. */
527 static char *
528 xstrdup (char *s)
530 if (s)
531 return strcpy (xmalloc (strlen (s) + 1), s);
532 return s;
537 /***********************************************************************
538 Symbols
539 ***********************************************************************/
541 /* Initialize the symbol table. This currently only sets up the
542 special symbol for globals (`*Globals*'). */
544 static void
545 init_sym (void)
547 global_symbols = add_sym (GLOBALS_NAME, NULL);
551 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
552 is the class in which class NAME was found. If it is null,
553 this means the scope of NAME is the current namespace.
555 If a symbol for NAME already exists, return that. Otherwise
556 create a new symbol and set it to default values. */
558 static struct sym *
559 add_sym (const char *name, struct sym *nested_in_class)
561 struct sym *sym;
562 unsigned h;
563 const char *s;
564 struct sym *scope = nested_in_class ? nested_in_class : current_namespace;
566 for (s = name, h = 0; *s; ++s)
567 h = (h << 1) ^ *s;
568 h %= TABLE_SIZE;
570 for (sym = class_table[h]; sym; sym = sym->next)
571 if (streq (name, sym->name)
572 && ((!sym->namesp && !scope)
573 || (sym->namesp && scope
574 && streq (sym->namesp->name, scope->name))))
575 break;
577 if (sym == NULL)
579 if (f_very_verbose)
581 putchar ('\t');
582 puts (name);
585 sym = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
586 memset (sym, 0, offsetof (struct sym, name));
587 strcpy (sym->name, name);
588 sym->namesp = scope;
589 sym->next = class_table[h];
590 class_table[h] = sym;
593 return sym;
597 /* Add links between superclass SUPER and subclass SUB. */
599 static void
600 add_link (struct sym *super, struct sym *sub)
602 struct link *lnk, *lnk2, *p, *prev;
604 /* See if a link already exists. */
605 for (p = super->subs, prev = NULL;
606 p && strcmp (sub->name, p->sym->name) > 0;
607 prev = p, p = p->next)
610 /* Avoid duplicates. */
611 if (p == NULL || p->sym != sub)
613 lnk = (struct link *) xmalloc (sizeof *lnk);
614 lnk2 = (struct link *) xmalloc (sizeof *lnk2);
616 lnk->sym = sub;
617 lnk->next = p;
619 if (prev)
620 prev->next = lnk;
621 else
622 super->subs = lnk;
624 lnk2->sym = super;
625 lnk2->next = sub->supers;
626 sub->supers = lnk2;
631 /* Find in class CLS member NAME.
633 VAR non-zero means look for a member variable; otherwise a function
634 is searched. SC specifies what kind of member is searched---a
635 static, or per-instance member etc. HASH is a hash code for the
636 parameter types of functions. Value is a pointer to the member
637 found or null if not found. */
639 static struct member *
640 find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
642 struct member **list;
643 struct member *p;
644 unsigned name_hash = 0;
645 char *s;
646 int i;
648 switch (sc)
650 case SC_FRIEND:
651 list = &cls->friends;
652 break;
654 case SC_TYPE:
655 list = &cls->types;
656 break;
658 case SC_STATIC:
659 list = var ? &cls->static_vars : &cls->static_fns;
660 break;
662 default:
663 list = var ? &cls->vars : &cls->fns;
664 break;
667 for (s = name; *s; ++s)
668 name_hash = (name_hash << 1) ^ *s;
669 i = name_hash % TABLE_SIZE;
671 for (p = member_table[i]; p; p = p->anext)
672 if (p->list == list && p->param_hash == hash && streq (name, p->name))
673 break;
675 return p;
679 /* Add to class CLS information for the declaration of member NAME.
680 REGEXP is a regexp matching the declaration, if non-null. POS is
681 the position in the source where the declaration is found. HASH is
682 a hash code for the parameter list of the member, if it's a
683 function. VAR non-zero means member is a variable or type. SC
684 specifies the type of member (instance member, static, ...). VIS
685 is the member's visibility (public, protected, private). FLAGS is
686 a bit set giving additional information about the member (see the
687 F_* defines). */
689 static void
690 add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags)
692 struct member *m;
694 m = find_member (cls, name, var, sc, hash);
695 if (m == NULL)
696 m = add_member (cls, name, var, sc, hash);
698 /* Have we seen a new filename? If so record that. */
699 if (!cls->filename || !filename_eq (cls->filename, filename))
700 m->filename = filename;
702 m->regexp = regexp;
703 m->pos = pos;
704 m->flags = flags;
706 switch (vis)
708 case PRIVATE:
709 m->vis = V_PRIVATE;
710 break;
712 case PROTECTED:
713 m->vis = V_PROTECTED;
714 break;
716 case PUBLIC:
717 m->vis = V_PUBLIC;
718 break;
721 info_where = P_DECL;
722 info_cls = cls;
723 info_member = m;
727 /* Add to class CLS information for the definition of member NAME.
728 REGEXP is a regexp matching the declaration, if non-null. POS is
729 the position in the source where the declaration is found. HASH is
730 a hash code for the parameter list of the member, if it's a
731 function. VAR non-zero means member is a variable or type. SC
732 specifies the type of member (instance member, static, ...). VIS
733 is the member's visibility (public, protected, private). FLAGS is
734 a bit set giving additional information about the member (see the
735 F_* defines). */
737 static void
738 add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
740 struct member *m;
742 if (sc == SC_UNKNOWN)
744 m = find_member (cls, name, var, SC_MEMBER, hash);
745 if (m == NULL)
747 m = find_member (cls, name, var, SC_STATIC, hash);
748 if (m == NULL)
749 m = add_member (cls, name, var, sc, hash);
752 else
754 m = find_member (cls, name, var, sc, hash);
755 if (m == NULL)
756 m = add_member (cls, name, var, sc, hash);
759 if (!cls->sfilename)
760 cls->sfilename = filename;
762 if (!filename_eq (cls->sfilename, filename))
763 m->def_filename = filename;
765 m->def_regexp = regexp;
766 m->def_pos = pos;
767 m->flags |= flags;
769 info_where = P_DEFN;
770 info_cls = cls;
771 info_member = m;
775 /* Add a symbol for a define named NAME to the symbol table.
776 REGEXP is a regular expression matching the define in the source,
777 if it is non-null. POS is the position in the file. */
779 static void
780 add_define (char *name, char *regexp, int pos)
782 add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
783 add_global_decl (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
787 /* Add information for the global definition of NAME.
788 REGEXP is a regexp matching the declaration, if non-null. POS is
789 the position in the source where the declaration is found. HASH is
790 a hash code for the parameter list of the member, if it's a
791 function. VAR non-zero means member is a variable or type. SC
792 specifies the type of member (instance member, static, ...). VIS
793 is the member's visibility (public, protected, private). FLAGS is
794 a bit set giving additional information about the member (see the
795 F_* defines). */
797 static void
798 add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
800 int i;
801 struct sym *sym;
803 /* Try to find out for which classes a function is a friend, and add
804 what we know about it to them. */
805 if (!var)
806 for (i = 0; i < TABLE_SIZE; ++i)
807 for (sym = class_table[i]; sym; sym = sym->next)
808 if (sym != global_symbols && sym->friends)
809 if (find_member (sym, name, 0, SC_FRIEND, hash))
810 add_member_defn (sym, name, regexp, pos, hash, 0,
811 SC_FRIEND, flags);
813 /* Add to global symbols. */
814 add_member_defn (global_symbols, name, regexp, pos, hash, var, sc, flags);
818 /* Add information for the global declaration of NAME.
819 REGEXP is a regexp matching the declaration, if non-null. POS is
820 the position in the source where the declaration is found. HASH is
821 a hash code for the parameter list of the member, if it's a
822 function. VAR non-zero means member is a variable or type. SC
823 specifies the type of member (instance member, static, ...). VIS
824 is the member's visibility (public, protected, private). FLAGS is
825 a bit set giving additional information about the member (see the
826 F_* defines). */
828 static void
829 add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
831 /* Add declaration only if not already declared. Header files must
832 be processed before source files for this to have the right effect.
833 I do not want to handle implicit declarations at the moment. */
834 struct member *m;
835 struct member *found;
837 m = found = find_member (global_symbols, name, var, sc, hash);
838 if (m == NULL)
839 m = add_member (global_symbols, name, var, sc, hash);
841 /* Definition already seen => probably last declaration implicit.
842 Override. This means that declarations must always be added to
843 the symbol table before definitions. */
844 if (!found)
846 if (!global_symbols->filename
847 || !filename_eq (global_symbols->filename, filename))
848 m->filename = filename;
850 m->regexp = regexp;
851 m->pos = pos;
852 m->vis = V_PUBLIC;
853 m->flags = flags;
855 info_where = P_DECL;
856 info_cls = global_symbols;
857 info_member = m;
862 /* Add a symbol for member NAME to class CLS.
863 VAR non-zero means it's a variable. SC specifies the kind of
864 member. HASH is a hash code for the parameter types of a function.
865 Value is a pointer to the member's structure. */
867 static struct member *
868 add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
870 struct member *m = xmalloc (offsetof (struct member, name)
871 + strlen (name) + 1);
872 struct member **list;
873 struct member *p;
874 struct member *prev;
875 unsigned name_hash = 0;
876 int i;
877 char *s;
879 strcpy (m->name, name);
880 m->param_hash = hash;
882 m->vis = 0;
883 m->flags = 0;
884 m->regexp = NULL;
885 m->filename = NULL;
886 m->pos = 0;
887 m->def_regexp = NULL;
888 m->def_filename = NULL;
889 m->def_pos = 0;
891 assert (cls != NULL);
893 switch (sc)
895 case SC_FRIEND:
896 list = &cls->friends;
897 break;
899 case SC_TYPE:
900 list = &cls->types;
901 break;
903 case SC_STATIC:
904 list = var ? &cls->static_vars : &cls->static_fns;
905 break;
907 default:
908 list = var ? &cls->vars : &cls->fns;
909 break;
912 for (s = name; *s; ++s)
913 name_hash = (name_hash << 1) ^ *s;
914 i = name_hash % TABLE_SIZE;
915 m->anext = member_table[i];
916 member_table[i] = m;
917 m->list = list;
919 /* Keep the member list sorted. It's cheaper to do it here than to
920 sort them in Lisp. */
921 for (prev = NULL, p = *list;
922 p && strcmp (name, p->name) > 0;
923 prev = p, p = p->next)
926 m->next = p;
927 if (prev)
928 prev->next = m;
929 else
930 *list = m;
931 return m;
935 /* Given the root R of a class tree, step through all subclasses
936 recursively, marking functions as virtual that are declared virtual
937 in base classes. */
939 static void
940 mark_virtual (struct sym *r)
942 struct link *p;
943 struct member *m, *m2;
945 for (p = r->subs; p; p = p->next)
947 for (m = r->fns; m; m = m->next)
948 if (has_flag (m->flags, F_VIRTUAL))
950 for (m2 = p->sym->fns; m2; m2 = m2->next)
951 if (m->param_hash == m2->param_hash && streq (m->name, m2->name))
952 set_flag (&m2->flags, F_VIRTUAL);
955 mark_virtual (p->sym);
960 /* For all roots of the class tree, mark functions as virtual that
961 are virtual because of a virtual declaration in a base class. */
963 static void
964 mark_inherited_virtual (void)
966 struct sym *r;
967 int i;
969 for (i = 0; i < TABLE_SIZE; ++i)
970 for (r = class_table[i]; r; r = r->next)
971 if (r->supers == NULL)
972 mark_virtual (r);
976 /* Create and return a symbol for a namespace with name NAME. */
978 static struct sym *
979 make_namespace (char *name, struct sym *context)
981 struct sym *s = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
982 memset (s, 0, offsetof (struct sym, name));
983 strcpy (s->name, name);
984 s->next = all_namespaces;
985 s->namesp = context;
986 all_namespaces = s;
987 return s;
991 /* Find the symbol for namespace NAME. If not found, return NULL */
993 static struct sym *
994 check_namespace (char *name, struct sym *context)
996 struct sym *p = NULL;
998 for (p = all_namespaces; p; p = p->next)
1000 if (streq (p->name, name) && (p->namesp == context))
1001 break;
1004 return p;
1007 /* Find the symbol for namespace NAME. If not found, add a new symbol
1008 for NAME to all_namespaces. */
1010 static struct sym *
1011 find_namespace (char *name, struct sym *context)
1013 struct sym *p = check_namespace (name, context);
1015 if (p == NULL)
1016 p = make_namespace (name, context);
1018 return p;
1022 /* Find namespace alias with name NAME. If not found return NULL. */
1024 static struct link *
1025 check_namespace_alias (char *name)
1027 struct link *p = NULL;
1028 struct alias *al;
1029 unsigned h;
1030 char *s;
1032 for (s = name, h = 0; *s; ++s)
1033 h = (h << 1) ^ *s;
1034 h %= TABLE_SIZE;
1036 for (al = namespace_alias_table[h]; al; al = al->next)
1037 if (streq (name, al->name) && (al->namesp == current_namespace))
1039 p = al->aliasee;
1040 break;
1043 return p;
1046 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1048 static void
1049 register_namespace_alias (char *new_name, struct link *old_name)
1051 unsigned h;
1052 char *s;
1053 struct alias *al;
1055 for (s = new_name, h = 0; *s; ++s)
1056 h = (h << 1) ^ *s;
1057 h %= TABLE_SIZE;
1060 /* Is it already in the table of aliases? */
1061 for (al = namespace_alias_table[h]; al; al = al->next)
1062 if (streq (new_name, al->name) && (al->namesp == current_namespace))
1063 return;
1065 al = xmalloc (offsetof (struct alias, name) + strlen (new_name) + 1);
1066 strcpy (al->name, new_name);
1067 al->next = namespace_alias_table[h];
1068 al->namesp = current_namespace;
1069 al->aliasee = old_name;
1070 namespace_alias_table[h] = al;
1074 /* Enter namespace with name NAME. */
1076 static void
1077 enter_namespace (char *name)
1079 struct sym *p = find_namespace (name, current_namespace);
1081 if (namespace_sp == namespace_stack_size)
1083 int size = max (10, 2 * namespace_stack_size);
1084 namespace_stack
1085 = (struct sym **) xrealloc ((void *)namespace_stack,
1086 size * sizeof *namespace_stack);
1087 namespace_stack_size = size;
1090 namespace_stack[namespace_sp++] = current_namespace;
1091 current_namespace = p;
1095 /* Leave the current namespace. */
1097 static void
1098 leave_namespace (void)
1100 assert (namespace_sp > 0);
1101 current_namespace = namespace_stack[--namespace_sp];
1106 /***********************************************************************
1107 Writing the Output File
1108 ***********************************************************************/
1110 /* Write string S to the output file FP in a Lisp-readable form.
1111 If S is null, write out `()'. */
1113 static void
1114 putstr (const char *s, FILE *fp)
1116 if (!s)
1118 putc ('(', fp);
1119 putc (')', fp);
1120 putc (' ', fp);
1122 else
1124 putc ('"', fp);
1125 fputs (s, fp);
1126 putc ('"', fp);
1127 putc (' ', fp);
1131 /* A dynamically allocated buffer for constructing a scope name. */
1133 char *scope_buffer;
1134 int scope_buffer_size;
1135 int scope_buffer_len;
1138 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1140 static void
1141 ensure_scope_buffer_room (int len)
1143 if (scope_buffer_len + len >= scope_buffer_size)
1145 int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
1146 scope_buffer = (char *) xrealloc (scope_buffer, new_size);
1147 scope_buffer_size = new_size;
1152 /* Recursively add the scope names of symbol P and the scopes of its
1153 namespaces to scope_buffer. Value is a pointer to the complete
1154 scope name constructed. */
1156 static char *
1157 sym_scope_1 (struct sym *p)
1159 int len;
1161 if (p->namesp)
1162 sym_scope_1 (p->namesp);
1164 if (*scope_buffer)
1166 ensure_scope_buffer_room (3);
1167 strcpy (scope_buffer + scope_buffer_len, "::");
1168 scope_buffer_len += 2;
1171 len = strlen (p->name);
1172 ensure_scope_buffer_room (len + 1);
1173 strcpy (scope_buffer + scope_buffer_len, p->name);
1174 scope_buffer_len += len;
1176 if (has_flag (p->flags, F_TEMPLATE))
1178 ensure_scope_buffer_room (3);
1179 strcpy (scope_buffer + scope_buffer_len, "<>");
1180 scope_buffer_len += 2;
1183 return scope_buffer;
1187 /* Return the scope of symbol P in printed representation, i.e.
1188 as it would appear in a C*+ source file. */
1190 static char *
1191 sym_scope (struct sym *p)
1193 if (!scope_buffer)
1195 scope_buffer_size = 1024;
1196 scope_buffer = (char *) xmalloc (scope_buffer_size);
1199 *scope_buffer = '\0';
1200 scope_buffer_len = 0;
1202 if (p->namesp)
1203 sym_scope_1 (p->namesp);
1205 return scope_buffer;
1209 /* Dump the list of members M to file FP. Value is the length of the
1210 list. */
1212 static int
1213 dump_members (FILE *fp, struct member *m)
1215 int n;
1217 putc ('(', fp);
1219 for (n = 0; m; m = m->next, ++n)
1221 fputs (MEMBER_STRUCT, fp);
1222 putstr (m->name, fp);
1223 putstr (NULL, fp); /* FIXME? scope for globals */
1224 fprintf (fp, "%u ", (unsigned) m->flags);
1225 putstr (m->filename, fp);
1226 putstr (m->regexp, fp);
1227 fprintf (fp, "%u ", (unsigned) m->pos);
1228 fprintf (fp, "%u ", (unsigned) m->vis);
1229 putc (' ', fp);
1230 putstr (m->def_filename, fp);
1231 putstr (m->def_regexp, fp);
1232 fprintf (fp, "%u", (unsigned) m->def_pos);
1233 putc (']', fp);
1234 putc ('\n', fp);
1237 putc (')', fp);
1238 putc ('\n', fp);
1239 return n;
1243 /* Dump class ROOT to stream FP. */
1245 static void
1246 dump_sym (FILE *fp, struct sym *root)
1248 fputs (CLASS_STRUCT, fp);
1249 putstr (root->name, fp);
1251 /* Print scope, if any. */
1252 if (root->namesp)
1253 putstr (sym_scope (root), fp);
1254 else
1255 putstr (NULL, fp);
1257 /* Print flags. */
1258 fprintf (fp, "%d", root->flags);
1259 putstr (root->filename, fp);
1260 putstr (root->regexp, fp);
1261 fprintf (fp, "%u", (unsigned) root->pos);
1262 putstr (root->sfilename, fp);
1263 putc (']', fp);
1264 putc ('\n', fp);
1268 /* Dump class ROOT and its subclasses to file FP. Value is the
1269 number of classes written. */
1271 static int
1272 dump_tree (FILE *fp, struct sym *root)
1274 struct link *lk;
1275 unsigned n = 0;
1277 dump_sym (fp, root);
1279 if (f_verbose)
1281 putchar ('+');
1282 fflush (stdout);
1285 putc ('(', fp);
1287 for (lk = root->subs; lk; lk = lk->next)
1289 fputs (TREE_STRUCT, fp);
1290 n += dump_tree (fp, lk->sym);
1291 putc (']', fp);
1294 putc (')', fp);
1296 dump_members (fp, root->vars);
1297 n += dump_members (fp, root->fns);
1298 dump_members (fp, root->static_vars);
1299 n += dump_members (fp, root->static_fns);
1300 n += dump_members (fp, root->friends);
1301 dump_members (fp, root->types);
1303 /* Superclasses. */
1304 putc ('(', fp);
1305 putc (')', fp);
1307 /* Mark slot. */
1308 putc ('(', fp);
1309 putc (')', fp);
1311 putc ('\n', fp);
1312 return n;
1316 /* Dump the entire class tree to file FP. */
1318 static void
1319 dump_roots (FILE *fp)
1321 int i, n = 0;
1322 struct sym *r;
1324 /* Output file header containing version string, command line
1325 options etc. */
1326 if (!f_append)
1328 fputs (TREE_HEADER_STRUCT, fp);
1329 putstr (EBROWSE_FILE_VERSION, fp);
1331 putc ('\"', fp);
1332 if (!f_structs)
1333 fputs (" -s", fp);
1334 if (f_regexps)
1335 fputs (" -x", fp);
1336 putc ('\"', fp);
1337 fputs (" ()", fp);
1338 fputs (" ()", fp);
1339 putc (']', fp);
1342 /* Mark functions as virtual that are so because of functions
1343 declared virtual in base classes. */
1344 mark_inherited_virtual ();
1346 /* Dump the roots of the graph. */
1347 for (i = 0; i < TABLE_SIZE; ++i)
1348 for (r = class_table[i]; r; r = r->next)
1349 if (!r->supers)
1351 fputs (TREE_STRUCT, fp);
1352 n += dump_tree (fp, r);
1353 putc (']', fp);
1356 if (f_verbose)
1357 putchar ('\n');
1362 /***********************************************************************
1363 Scanner
1364 ***********************************************************************/
1366 #ifdef DEBUG
1367 #define INCREMENT_LINENO \
1368 do { \
1369 if (f_very_verbose) \
1371 ++yyline; \
1372 printf ("%d:\n", yyline); \
1374 else \
1375 ++yyline; \
1376 } while (0)
1377 #else
1378 #define INCREMENT_LINENO ++yyline
1379 #endif
1381 /* Define two macros for accessing the input buffer (current input
1382 file). GET(C) sets C to the next input character and advances the
1383 input pointer. UNGET retracts the input pointer. */
1385 #define GET(C) ((C) = *in++)
1386 #define UNGET() (--in)
1389 /* Process a preprocessor line. Value is the next character from the
1390 input buffer not consumed. */
1392 static int
1393 process_pp_line (void)
1395 int in_comment = 0, in_string = 0;
1396 int c;
1397 char *p = yytext;
1399 /* Skip over white space. The `#' has been consumed already. */
1400 while (WHITEP (GET (c)))
1403 /* Read the preprocessor command (if any). */
1404 while (IDENTP (c))
1406 *p++ = c;
1407 GET (c);
1410 /* Is it a `define'? */
1411 *p = '\0';
1413 if (*yytext && streq (yytext, "define"))
1415 p = yytext;
1416 while (WHITEP (c))
1417 GET (c);
1418 while (IDENTP (c))
1420 *p++ = c;
1421 GET (c);
1424 *p = '\0';
1426 if (*yytext)
1428 char *regexp = matching_regexp ();
1429 int pos = BUFFER_POS ();
1430 add_define (yytext, regexp, pos);
1434 while (c && (c != '\n' || in_comment || in_string))
1436 if (c == '\\')
1437 GET (c);
1438 else if (c == '/' && !in_comment)
1440 if (GET (c) == '*')
1441 in_comment = 1;
1443 else if (c == '*' && in_comment)
1445 if (GET (c) == '/')
1446 in_comment = 0;
1448 else if (c == '"')
1449 in_string = !in_string;
1451 if (c == '\n')
1452 INCREMENT_LINENO;
1454 GET (c);
1457 return c;
1461 /* Value is the next token from the input buffer. */
1463 static int
1464 yylex (void)
1466 int c;
1467 char end_char;
1468 char *p;
1470 for (;;)
1472 while (WHITEP (GET (c)))
1475 switch (c)
1477 case '\n':
1478 INCREMENT_LINENO;
1479 break;
1481 case '\r':
1482 break;
1484 case 0:
1485 /* End of file. */
1486 return YYEOF;
1488 case '\\':
1489 GET (c);
1490 break;
1492 case '"':
1493 case '\'':
1494 /* String and character constants. */
1495 end_char = c;
1496 string_start = in;
1497 while (GET (c) && c != end_char)
1499 switch (c)
1501 case '\\':
1502 /* Escape sequences. */
1503 if (!GET (c))
1505 if (end_char == '\'')
1506 yyerror ("EOF in character constant", NULL);
1507 else
1508 yyerror ("EOF in string constant", NULL);
1509 goto end_string;
1511 else switch (c)
1513 case '\n':
1514 INCREMENT_LINENO;
1515 case 'a':
1516 case 'b':
1517 case 'f':
1518 case 'n':
1519 case 'r':
1520 case 't':
1521 case 'v':
1522 break;
1524 case 'x':
1526 /* Hexadecimal escape sequence. */
1527 int i;
1528 for (i = 0; i < 2; ++i)
1530 GET (c);
1532 if (c >= '0' && c <= '7')
1534 else if (c >= 'a' && c <= 'f')
1536 else if (c >= 'A' && c <= 'F')
1538 else
1540 UNGET ();
1541 break;
1545 break;
1547 case '0':
1549 /* Octal escape sequence. */
1550 int i;
1551 for (i = 0; i < 3; ++i)
1553 GET (c);
1555 if (c >= '0' && c <= '7')
1557 else
1559 UNGET ();
1560 break;
1564 break;
1566 default:
1567 break;
1569 break;
1571 case '\n':
1572 if (end_char == '\'')
1573 yyerror ("newline in character constant", NULL);
1574 else
1575 yyerror ("newline in string constant", NULL);
1576 INCREMENT_LINENO;
1577 break;
1579 default:
1580 break;
1584 end_string:
1585 return end_char == '\'' ? CCHAR : CSTRING;
1587 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1588 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1589 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1590 case 'v': case 'w': case 'x': case 'y': case 'z':
1591 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1592 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1593 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1594 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1596 /* Identifier and keywords. */
1597 unsigned hash;
1598 struct kw *k;
1600 p = yytext;
1601 *p++ = hash = c;
1603 while (IDENTP (GET (*p)))
1605 hash = (hash << 1) ^ *p++;
1606 if (p == yytext_end - 1)
1608 int size = yytext_end - yytext;
1609 yytext = (char *) xrealloc (yytext, 2 * size);
1610 yytext_end = yytext + 2 * size;
1611 p = yytext + size - 1;
1615 UNGET ();
1616 *p = 0;
1618 for (k = keyword_table[hash % KEYWORD_TABLE_SIZE]; k; k = k->next)
1619 if (streq (k->name, yytext))
1620 return k->tk;
1622 return IDENT;
1625 case '/':
1626 /* C and C++ comments, '/' and '/='. */
1627 switch (GET (c))
1629 case '*':
1630 while (GET (c))
1632 switch (c)
1634 case '*':
1635 if (GET (c) == '/')
1636 goto comment_end;
1637 UNGET ();
1638 break;
1639 case '\\':
1640 GET (c);
1641 break;
1642 case '\n':
1643 INCREMENT_LINENO;
1644 break;
1647 comment_end:;
1648 break;
1650 case '=':
1651 return DIVASGN;
1653 case '/':
1654 while (GET (c) && c != '\n')
1656 /* Don't try to read past the end of the input buffer if
1657 the file ends in a C++ comment without a newline. */
1658 if (c == 0)
1659 return YYEOF;
1661 INCREMENT_LINENO;
1662 break;
1664 default:
1665 UNGET ();
1666 return '/';
1668 break;
1670 case '+':
1671 if (GET (c) == '+')
1672 return INC;
1673 else if (c == '=')
1674 return ADDASGN;
1675 UNGET ();
1676 return '+';
1678 case '-':
1679 switch (GET (c))
1681 case '-':
1682 return DEC;
1683 case '>':
1684 if (GET (c) == '*')
1685 return ARROWSTAR;
1686 UNGET ();
1687 return ARROW;
1688 case '=':
1689 return SUBASGN;
1691 UNGET ();
1692 return '-';
1694 case '*':
1695 if (GET (c) == '=')
1696 return MULASGN;
1697 UNGET ();
1698 return '*';
1700 case '%':
1701 if (GET (c) == '=')
1702 return MODASGN;
1703 UNGET ();
1704 return '%';
1706 case '|':
1707 if (GET (c) == '|')
1708 return LOR;
1709 else if (c == '=')
1710 return ORASGN;
1711 UNGET ();
1712 return '|';
1714 case '&':
1715 if (GET (c) == '&')
1716 return LAND;
1717 else if (c == '=')
1718 return ANDASGN;
1719 UNGET ();
1720 return '&';
1722 case '^':
1723 if (GET (c) == '=')
1724 return XORASGN;
1725 UNGET ();
1726 return '^';
1728 case '.':
1729 if (GET (c) == '*')
1730 return POINTSTAR;
1731 else if (c == '.')
1733 if (GET (c) != '.')
1734 yyerror ("invalid token '..' ('...' assumed)", NULL);
1735 UNGET ();
1736 return ELLIPSIS;
1738 else if (!DIGITP (c))
1740 UNGET ();
1741 return '.';
1743 goto mantissa;
1745 case ':':
1746 if (GET (c) == ':')
1747 return DCOLON;
1748 UNGET ();
1749 return ':';
1751 case '=':
1752 if (GET (c) == '=')
1753 return EQ;
1754 UNGET ();
1755 return '=';
1757 case '!':
1758 if (GET (c) == '=')
1759 return NE;
1760 UNGET ();
1761 return '!';
1763 case '<':
1764 switch (GET (c))
1766 case '=':
1767 return LE;
1768 case '<':
1769 if (GET (c) == '=')
1770 return LSHIFTASGN;
1771 UNGET ();
1772 return LSHIFT;
1774 UNGET ();
1775 return '<';
1777 case '>':
1778 switch (GET (c))
1780 case '=':
1781 return GE;
1782 case '>':
1783 if (GET (c) == '=')
1784 return RSHIFTASGN;
1785 UNGET ();
1786 return RSHIFT;
1788 UNGET ();
1789 return '>';
1791 case '#':
1792 c = process_pp_line ();
1793 if (c == 0)
1794 return YYEOF;
1795 break;
1797 case '(': case ')': case '[': case ']': case '{': case '}':
1798 case ';': case ',': case '?': case '~':
1799 return c;
1801 case '0':
1802 yyival = 0;
1804 if (GET (c) == 'x' || c == 'X')
1806 while (GET (c))
1808 if (DIGITP (c))
1809 yyival = yyival * 16 + c - '0';
1810 else if (c >= 'a' && c <= 'f')
1811 yyival = yyival * 16 + c - 'a' + 10;
1812 else if (c >= 'A' && c <= 'F')
1813 yyival = yyival * 16 + c - 'A' + 10;
1814 else
1815 break;
1818 goto int_suffixes;
1820 else if (c == '.')
1821 goto mantissa;
1823 while (c >= '0' && c <= '7')
1825 yyival = (yyival << 3) + c - '0';
1826 GET (c);
1829 int_suffixes:
1830 /* Integer suffixes. */
1831 while (isalpha (c))
1832 GET (c);
1833 UNGET ();
1834 return CINT;
1836 case '1': case '2': case '3': case '4': case '5': case '6':
1837 case '7': case '8': case '9':
1838 /* Integer or floating constant, part before '.'. */
1839 yyival = c - '0';
1841 while (GET (c) && DIGITP (c))
1842 yyival = 10 * yyival + c - '0';
1844 if (c != '.')
1845 goto int_suffixes;
1847 mantissa:
1848 /* Digits following '.'. */
1849 while (DIGITP (c))
1850 GET (c);
1852 /* Optional exponent. */
1853 if (c == 'E' || c == 'e')
1855 if (GET (c) == '-' || c == '+')
1856 GET (c);
1858 while (DIGITP (c))
1859 GET (c);
1862 /* Optional type suffixes. */
1863 while (isalpha (c))
1864 GET (c);
1865 UNGET ();
1866 return CFLOAT;
1868 default:
1869 break;
1875 /* Actually local to matching_regexp. These variables must be in
1876 global scope for the case that `static' get's defined away. */
1878 static char *matching_regexp_buffer, *matching_regexp_end_buf;
1881 /* Value is the string from the start of the line to the current
1882 position in the input buffer, or maybe a bit more if that string is
1883 shorter than min_regexp. */
1885 static char *
1886 matching_regexp (void)
1888 char *p;
1889 char *s;
1890 char *t;
1892 if (!f_regexps)
1893 return NULL;
1895 if (matching_regexp_buffer == NULL)
1897 matching_regexp_buffer = (char *) xmalloc (max_regexp);
1898 matching_regexp_end_buf = &matching_regexp_buffer[max_regexp] - 1;
1901 /* Scan back to previous newline of buffer start. */
1902 for (p = in - 1; p > inbuffer && *p != '\n'; --p)
1905 if (*p == '\n')
1907 while (in - p < min_regexp && p > inbuffer)
1909 /* Line probably not significant enough */
1910 for (--p; p > inbuffer && *p != '\n'; --p)
1913 if (*p == '\n')
1914 ++p;
1917 /* Copy from end to make sure significant portions are included.
1918 This implies that in the browser a regular expressing of the form
1919 `^.*{regexp}' has to be used. */
1920 for (s = matching_regexp_end_buf - 1, t = in;
1921 s > matching_regexp_buffer && t > p;)
1923 *--s = *--t;
1925 if (*s == '"' || *s == '\\')
1926 *--s = '\\';
1929 *(matching_regexp_end_buf - 1) = '\0';
1930 return xstrdup (s);
1934 /* Return a printable representation of token T. */
1936 static const char *
1937 token_string (int t)
1939 static char b[3];
1941 switch (t)
1943 case CSTRING: return "string constant";
1944 case CCHAR: return "char constant";
1945 case CINT: return "int constant";
1946 case CFLOAT: return "floating constant";
1947 case ELLIPSIS: return "...";
1948 case LSHIFTASGN: return "<<=";
1949 case RSHIFTASGN: return ">>=";
1950 case ARROWSTAR: return "->*";
1951 case IDENT: return "identifier";
1952 case DIVASGN: return "/=";
1953 case INC: return "++";
1954 case ADDASGN: return "+=";
1955 case DEC: return "--";
1956 case ARROW: return "->";
1957 case SUBASGN: return "-=";
1958 case MULASGN: return "*=";
1959 case MODASGN: return "%=";
1960 case LOR: return "||";
1961 case ORASGN: return "|=";
1962 case LAND: return "&&";
1963 case ANDASGN: return "&=";
1964 case XORASGN: return "^=";
1965 case POINTSTAR: return ".*";
1966 case DCOLON: return "::";
1967 case EQ: return "==";
1968 case NE: return "!=";
1969 case LE: return "<=";
1970 case LSHIFT: return "<<";
1971 case GE: return ">=";
1972 case RSHIFT: return ">>";
1973 case ASM: return "asm";
1974 case AUTO: return "auto";
1975 case BREAK: return "break";
1976 case CASE: return "case";
1977 case CATCH: return "catch";
1978 case CHAR: return "char";
1979 case CLASS: return "class";
1980 case CONST: return "const";
1981 case CONTINUE: return "continue";
1982 case DEFAULT: return "default";
1983 case DELETE: return "delete";
1984 case DO: return "do";
1985 case DOUBLE: return "double";
1986 case ELSE: return "else";
1987 case ENUM: return "enum";
1988 case EXTERN: return "extern";
1989 case FLOAT: return "float";
1990 case FOR: return "for";
1991 case FRIEND: return "friend";
1992 case GOTO: return "goto";
1993 case IF: return "if";
1994 case T_INLINE: return "inline";
1995 case INT: return "int";
1996 case LONG: return "long";
1997 case NEW: return "new";
1998 case OPERATOR: return "operator";
1999 case PRIVATE: return "private";
2000 case PROTECTED: return "protected";
2001 case PUBLIC: return "public";
2002 case REGISTER: return "register";
2003 case RETURN: return "return";
2004 case SHORT: return "short";
2005 case SIGNED: return "signed";
2006 case SIZEOF: return "sizeof";
2007 case STATIC: return "static";
2008 case STRUCT: return "struct";
2009 case SWITCH: return "switch";
2010 case TEMPLATE: return "template";
2011 case THIS: return "this";
2012 case THROW: return "throw";
2013 case TRY: return "try";
2014 case TYPEDEF: return "typedef";
2015 case UNION: return "union";
2016 case UNSIGNED: return "unsigned";
2017 case VIRTUAL: return "virtual";
2018 case VOID: return "void";
2019 case VOLATILE: return "volatile";
2020 case WHILE: return "while";
2021 case MUTABLE: return "mutable";
2022 case BOOL: return "bool";
2023 case TRUE: return "true";
2024 case FALSE: return "false";
2025 case SIGNATURE: return "signature";
2026 case NAMESPACE: return "namespace";
2027 case EXPLICIT: return "explicit";
2028 case TYPENAME: return "typename";
2029 case CONST_CAST: return "const_cast";
2030 case DYNAMIC_CAST: return "dynamic_cast";
2031 case REINTERPRET_CAST: return "reinterpret_cast";
2032 case STATIC_CAST: return "static_cast";
2033 case TYPEID: return "typeid";
2034 case USING: return "using";
2035 case WCHAR: return "wchar_t";
2036 case YYEOF: return "EOF";
2038 default:
2039 if (t < 255)
2041 b[0] = t;
2042 b[1] = '\0';
2043 return b;
2045 else
2046 return "???";
2051 /* Reinitialize the scanner for a new input file. */
2053 static void
2054 re_init_scanner (void)
2056 in = inbuffer;
2057 yyline = 1;
2059 if (yytext == NULL)
2061 int size = 256;
2062 yytext = (char *) xmalloc (size * sizeof *yytext);
2063 yytext_end = yytext + size;
2068 /* Insert a keyword NAME with token value TKV into the keyword hash
2069 table. */
2071 static void
2072 insert_keyword (const char *name, int tkv)
2074 const char *s;
2075 unsigned h = 0;
2076 struct kw *k = (struct kw *) xmalloc (sizeof *k);
2078 for (s = name; *s; ++s)
2079 h = (h << 1) ^ *s;
2081 h %= KEYWORD_TABLE_SIZE;
2082 k->name = name;
2083 k->tk = tkv;
2084 k->next = keyword_table[h];
2085 keyword_table[h] = k;
2089 /* Initialize the scanner for the first file. This sets up the
2090 character class vectors and fills the keyword hash table. */
2092 static void
2093 init_scanner (void)
2095 int i;
2097 /* Allocate the input buffer */
2098 inbuffer_size = READ_CHUNK_SIZE + 1;
2099 inbuffer = in = (char *) xmalloc (inbuffer_size);
2100 yyline = 1;
2102 /* Set up character class vectors. */
2103 for (i = 0; i < sizeof is_ident; ++i)
2105 if (i == '_' || isalnum (i))
2106 is_ident[i] = 1;
2108 if (i >= '0' && i <= '9')
2109 is_digit[i] = 1;
2111 if (i == ' ' || i == '\t' || i == '\f' || i == '\v')
2112 is_white[i] = 1;
2115 /* Fill keyword hash table. */
2116 insert_keyword ("and", LAND);
2117 insert_keyword ("and_eq", ANDASGN);
2118 insert_keyword ("asm", ASM);
2119 insert_keyword ("auto", AUTO);
2120 insert_keyword ("bitand", '&');
2121 insert_keyword ("bitor", '|');
2122 insert_keyword ("bool", BOOL);
2123 insert_keyword ("break", BREAK);
2124 insert_keyword ("case", CASE);
2125 insert_keyword ("catch", CATCH);
2126 insert_keyword ("char", CHAR);
2127 insert_keyword ("class", CLASS);
2128 insert_keyword ("compl", '~');
2129 insert_keyword ("const", CONST);
2130 insert_keyword ("const_cast", CONST_CAST);
2131 insert_keyword ("continue", CONTINUE);
2132 insert_keyword ("default", DEFAULT);
2133 insert_keyword ("delete", DELETE);
2134 insert_keyword ("do", DO);
2135 insert_keyword ("double", DOUBLE);
2136 insert_keyword ("dynamic_cast", DYNAMIC_CAST);
2137 insert_keyword ("else", ELSE);
2138 insert_keyword ("enum", ENUM);
2139 insert_keyword ("explicit", EXPLICIT);
2140 insert_keyword ("extern", EXTERN);
2141 insert_keyword ("false", FALSE);
2142 insert_keyword ("float", FLOAT);
2143 insert_keyword ("for", FOR);
2144 insert_keyword ("friend", FRIEND);
2145 insert_keyword ("goto", GOTO);
2146 insert_keyword ("if", IF);
2147 insert_keyword ("inline", T_INLINE);
2148 insert_keyword ("int", INT);
2149 insert_keyword ("long", LONG);
2150 insert_keyword ("mutable", MUTABLE);
2151 insert_keyword ("namespace", NAMESPACE);
2152 insert_keyword ("new", NEW);
2153 insert_keyword ("not", '!');
2154 insert_keyword ("not_eq", NE);
2155 insert_keyword ("operator", OPERATOR);
2156 insert_keyword ("or", LOR);
2157 insert_keyword ("or_eq", ORASGN);
2158 insert_keyword ("private", PRIVATE);
2159 insert_keyword ("protected", PROTECTED);
2160 insert_keyword ("public", PUBLIC);
2161 insert_keyword ("register", REGISTER);
2162 insert_keyword ("reinterpret_cast", REINTERPRET_CAST);
2163 insert_keyword ("return", RETURN);
2164 insert_keyword ("short", SHORT);
2165 insert_keyword ("signed", SIGNED);
2166 insert_keyword ("sizeof", SIZEOF);
2167 insert_keyword ("static", STATIC);
2168 insert_keyword ("static_cast", STATIC_CAST);
2169 insert_keyword ("struct", STRUCT);
2170 insert_keyword ("switch", SWITCH);
2171 insert_keyword ("template", TEMPLATE);
2172 insert_keyword ("this", THIS);
2173 insert_keyword ("throw", THROW);
2174 insert_keyword ("true", TRUE);
2175 insert_keyword ("try", TRY);
2176 insert_keyword ("typedef", TYPEDEF);
2177 insert_keyword ("typeid", TYPEID);
2178 insert_keyword ("typename", TYPENAME);
2179 insert_keyword ("union", UNION);
2180 insert_keyword ("unsigned", UNSIGNED);
2181 insert_keyword ("using", USING);
2182 insert_keyword ("virtual", VIRTUAL);
2183 insert_keyword ("void", VOID);
2184 insert_keyword ("volatile", VOLATILE);
2185 insert_keyword ("wchar_t", WCHAR);
2186 insert_keyword ("while", WHILE);
2187 insert_keyword ("xor", '^');
2188 insert_keyword ("xor_eq", XORASGN);
2193 /***********************************************************************
2194 Parser
2195 ***********************************************************************/
2197 /* Match the current lookahead token and set it to the next token. */
2199 #define MATCH() (tk = yylex ())
2201 /* Return the lookahead token. If current lookahead token is cleared,
2202 read a new token. */
2204 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2206 /* Is the current lookahead equal to the token T? */
2208 #define LOOKING_AT(T) (tk == (T))
2210 /* Is the current lookahead one of T1 or T2? */
2212 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2214 /* Is the current lookahead one of T1, T2 or T3? */
2216 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2218 /* Is the current lookahead one of T1...T4? */
2220 #define LOOKING_AT4(T1, T2, T3, T4) \
2221 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2223 /* Match token T if current lookahead is T. */
2225 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2227 /* Skip to matching token if current token is T. */
2229 #define SKIP_MATCHING_IF(T) \
2230 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2233 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2234 the current lookahead token after skipping. */
2236 static int
2237 skip_to (int token)
2239 while (!LOOKING_AT2 (YYEOF, token))
2240 MATCH ();
2241 return tk;
2244 /* Skip over pairs of tokens (parentheses, square brackets,
2245 angle brackets, curly brackets) matching the current lookahead. */
2247 static void
2248 skip_matching (void)
2250 int open, close, n;
2252 switch (open = LA1)
2254 case '{':
2255 close = '}';
2256 break;
2258 case '(':
2259 close = ')';
2260 break;
2262 case '<':
2263 close = '>';
2264 break;
2266 case '[':
2267 close = ']';
2268 break;
2270 default:
2271 abort ();
2274 for (n = 0;;)
2276 if (LOOKING_AT (open))
2277 ++n;
2278 else if (LOOKING_AT (close))
2279 --n;
2280 else if (LOOKING_AT (YYEOF))
2281 break;
2283 MATCH ();
2285 if (n == 0)
2286 break;
2290 static void
2291 skip_initializer (void)
2293 for (;;)
2295 switch (LA1)
2297 case ';':
2298 case ',':
2299 case YYEOF:
2300 return;
2302 case '{':
2303 case '[':
2304 case '(':
2305 skip_matching ();
2306 break;
2308 default:
2309 MATCH ();
2310 break;
2315 /* Build qualified namespace alias (A::B::c) and return it. */
2317 static struct link *
2318 match_qualified_namespace_alias (void)
2320 struct link *head = NULL;
2321 struct link *cur = NULL;
2322 struct link *tmp = NULL;
2324 for (;;)
2326 MATCH ();
2327 switch (LA1)
2329 case IDENT:
2330 tmp = (struct link *) xmalloc (sizeof *cur);
2331 tmp->sym = find_namespace (yytext, cur ? cur->sym : NULL);
2332 tmp->next = NULL;
2333 if (head)
2335 cur = cur->next = tmp;
2337 else
2339 head = cur = tmp;
2341 break;
2342 case DCOLON:
2343 /* Just skip */
2344 break;
2345 default:
2346 return head;
2347 break;
2352 /* Re-initialize the parser by resetting the lookahead token. */
2354 static void
2355 re_init_parser (void)
2357 tk = -1;
2361 /* Parse a parameter list, including the const-specifier,
2362 pure-specifier, and throw-list that may follow a parameter list.
2363 Return in FLAGS what was seen following the parameter list.
2364 Returns a hash code for the parameter types. This value is used to
2365 distinguish between overloaded functions. */
2367 static unsigned
2368 parm_list (int *flags)
2370 unsigned hash = 0;
2371 int type_seen = 0;
2373 while (!LOOKING_AT2 (YYEOF, ')'))
2375 switch (LA1)
2377 /* Skip over grouping parens or parameter lists in parameter
2378 declarations. */
2379 case '(':
2380 skip_matching ();
2381 break;
2383 /* Next parameter. */
2384 case ',':
2385 MATCH ();
2386 type_seen = 0;
2387 break;
2389 /* Ignore the scope part of types, if any. This is because
2390 some types need scopes when defined outside of a class body,
2391 and don't need them inside the class body. This means that
2392 we have to look for the last IDENT in a sequence of
2393 IDENT::IDENT::... */
2394 case IDENT:
2395 if (!type_seen)
2397 char *last_id;
2398 unsigned ident_type_hash = 0;
2400 parse_qualified_param_ident_or_type (&last_id);
2401 if (last_id)
2403 /* LAST_ID null means something like `X::*'. */
2404 for (; *last_id; ++last_id)
2405 ident_type_hash = (ident_type_hash << 1) ^ *last_id;
2406 hash = (hash << 1) ^ ident_type_hash;
2407 type_seen = 1;
2410 else
2411 MATCH ();
2412 break;
2414 case VOID:
2415 /* This distinction is made to make `func (void)' equivalent
2416 to `func ()'. */
2417 type_seen = 1;
2418 MATCH ();
2419 if (!LOOKING_AT (')'))
2420 hash = (hash << 1) ^ VOID;
2421 break;
2423 case BOOL: case CHAR: case CLASS: case CONST:
2424 case DOUBLE: case ENUM: case FLOAT: case INT:
2425 case LONG: case SHORT: case SIGNED: case STRUCT:
2426 case UNION: case UNSIGNED: case VOLATILE: case WCHAR:
2427 case ELLIPSIS:
2428 type_seen = 1;
2429 hash = (hash << 1) ^ LA1;
2430 MATCH ();
2431 break;
2433 case '*': case '&': case '[': case ']':
2434 hash = (hash << 1) ^ LA1;
2435 MATCH ();
2436 break;
2438 default:
2439 MATCH ();
2440 break;
2444 if (LOOKING_AT (')'))
2446 MATCH ();
2448 if (LOOKING_AT (CONST))
2450 /* We can overload the same function on `const' */
2451 hash = (hash << 1) ^ CONST;
2452 set_flag (flags, F_CONST);
2453 MATCH ();
2456 if (LOOKING_AT (THROW))
2458 MATCH ();
2459 SKIP_MATCHING_IF ('(');
2460 set_flag (flags, F_THROW);
2463 if (LOOKING_AT ('='))
2465 MATCH ();
2466 if (LOOKING_AT (CINT) && yyival == 0)
2468 MATCH ();
2469 set_flag (flags, F_PURE);
2474 return hash;
2478 /* Print position info to stdout. */
2480 static void
2481 print_info (void)
2483 if (info_position >= 0 && BUFFER_POS () <= info_position)
2484 if (info_cls)
2485 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2486 info_cls->name, sym_scope (info_cls),
2487 info_member->name, info_where);
2491 /* Parse a member declaration within the class body of CLS. VIS is
2492 the access specifier for the member (private, protected,
2493 public). */
2495 static void
2496 member (struct sym *cls, int vis)
2498 char *id = NULL;
2499 int sc = SC_MEMBER;
2500 char *regexp = NULL;
2501 int pos;
2502 int is_constructor;
2503 int anonymous = 0;
2504 int flags = 0;
2505 int class_tag;
2506 int type_seen = 0;
2507 int paren_seen = 0;
2508 unsigned hash = 0;
2509 int tilde = 0;
2511 while (!LOOKING_AT4 (';', '{', '}', YYEOF))
2513 switch (LA1)
2515 default:
2516 MATCH ();
2517 break;
2519 /* A function or class may follow. */
2520 case TEMPLATE:
2521 MATCH ();
2522 set_flag (&flags, F_TEMPLATE);
2523 /* Skip over template argument list */
2524 SKIP_MATCHING_IF ('<');
2525 break;
2527 case EXPLICIT:
2528 set_flag (&flags, F_EXPLICIT);
2529 goto typeseen;
2531 case MUTABLE:
2532 set_flag (&flags, F_MUTABLE);
2533 goto typeseen;
2535 case T_INLINE:
2536 set_flag (&flags, F_INLINE);
2537 goto typeseen;
2539 case VIRTUAL:
2540 set_flag (&flags, F_VIRTUAL);
2541 goto typeseen;
2543 case '[':
2544 skip_matching ();
2545 break;
2547 case ENUM:
2548 sc = SC_TYPE;
2549 goto typeseen;
2551 case TYPEDEF:
2552 sc = SC_TYPE;
2553 goto typeseen;
2555 case FRIEND:
2556 sc = SC_FRIEND;
2557 goto typeseen;
2559 case STATIC:
2560 sc = SC_STATIC;
2561 goto typeseen;
2563 case '~':
2564 tilde = 1;
2565 MATCH ();
2566 break;
2568 case IDENT:
2569 /* Remember IDENTS seen so far. Among these will be the member
2570 name. */
2571 id = (char *) xrealloc (id, strlen (yytext) + 2);
2572 if (tilde)
2574 *id = '~';
2575 strcpy (id + 1, yytext);
2577 else
2578 strcpy (id, yytext);
2579 MATCH ();
2580 break;
2582 case OPERATOR:
2584 char *s = operator_name (&sc);
2585 id = (char *) xrealloc (id, strlen (s) + 1);
2586 strcpy (id, s);
2588 break;
2590 case '(':
2591 /* Most probably the beginning of a parameter list. */
2592 MATCH ();
2593 paren_seen = 1;
2595 if (id && cls)
2597 if (!(is_constructor = streq (id, cls->name)))
2598 regexp = matching_regexp ();
2600 else
2601 is_constructor = 0;
2603 pos = BUFFER_POS ();
2604 hash = parm_list (&flags);
2606 if (is_constructor)
2607 regexp = matching_regexp ();
2609 if (id && cls != NULL)
2610 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, flags);
2612 while (!LOOKING_AT3 (';', '{', YYEOF))
2613 MATCH ();
2615 if (LOOKING_AT ('{') && id && cls)
2616 add_member_defn (cls, id, regexp, pos, hash, 0, sc, flags);
2618 free (id);
2619 id = NULL;
2620 sc = SC_MEMBER;
2621 break;
2623 case STRUCT: case UNION: case CLASS:
2624 /* Nested class */
2625 class_tag = LA1;
2626 type_seen = 1;
2627 MATCH ();
2628 anonymous = 1;
2630 /* More than one ident here to allow for MS-DOS specialties
2631 like `_export class' etc. The last IDENT seen counts
2632 as the class name. */
2633 while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
2635 if (LOOKING_AT (IDENT))
2636 anonymous = 0;
2637 MATCH ();
2640 if (LOOKING_AT2 (':', '{'))
2641 class_definition (anonymous ? NULL : cls, class_tag, flags, 1);
2642 else
2643 skip_to (';');
2644 break;
2646 case INT: case CHAR: case LONG: case UNSIGNED:
2647 case SIGNED: case CONST: case DOUBLE: case VOID:
2648 case SHORT: case VOLATILE: case BOOL: case WCHAR:
2649 case TYPENAME:
2650 typeseen:
2651 type_seen = 1;
2652 MATCH ();
2653 break;
2657 if (LOOKING_AT (';'))
2659 /* The end of a member variable, a friend declaration or an access
2660 declaration. We don't want to add friend classes as members. */
2661 if (id && sc != SC_FRIEND && cls)
2663 regexp = matching_regexp ();
2664 pos = BUFFER_POS ();
2666 if (cls != NULL)
2668 if (type_seen || !paren_seen)
2669 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2670 else
2671 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0);
2675 MATCH ();
2676 print_info ();
2678 else if (LOOKING_AT ('{'))
2680 /* A named enum. */
2681 if (sc == SC_TYPE && id && cls)
2683 regexp = matching_regexp ();
2684 pos = BUFFER_POS ();
2686 if (cls != NULL)
2688 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2689 add_member_defn (cls, id, regexp, pos, 0, 1, sc, 0);
2693 skip_matching ();
2694 print_info ();
2697 free (id);
2701 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2702 union, class). */
2704 static void
2705 class_body (struct sym *cls, int tag)
2707 int vis = tag == CLASS ? PRIVATE : PUBLIC;
2708 int temp;
2710 while (!LOOKING_AT2 (YYEOF, '}'))
2712 switch (LA1)
2714 case PRIVATE: case PROTECTED: case PUBLIC:
2715 temp = LA1;
2716 MATCH ();
2718 if (LOOKING_AT (':'))
2720 vis = temp;
2721 MATCH ();
2723 else
2725 /* Probably conditional compilation for inheritance list.
2726 We don't known whether there comes more of this.
2727 This is only a crude fix that works most of the time. */
2730 MATCH ();
2732 while (LOOKING_AT2 (IDENT, ',')
2733 || LOOKING_AT3 (PUBLIC, PROTECTED, PRIVATE));
2735 break;
2737 case TYPENAME:
2738 case USING:
2739 skip_to (';');
2740 break;
2742 /* Try to synchronize */
2743 case CHAR: case CLASS: case CONST:
2744 case DOUBLE: case ENUM: case FLOAT: case INT:
2745 case LONG: case SHORT: case SIGNED: case STRUCT:
2746 case UNION: case UNSIGNED: case VOID: case VOLATILE:
2747 case TYPEDEF: case STATIC: case T_INLINE: case FRIEND:
2748 case VIRTUAL: case TEMPLATE: case IDENT: case '~':
2749 case BOOL: case WCHAR: case EXPLICIT: case MUTABLE:
2750 member (cls, vis);
2751 break;
2753 default:
2754 MATCH ();
2755 break;
2761 /* Parse a qualified identifier. Current lookahead is IDENT. A
2762 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2763 symbol for that class. */
2765 static struct sym *
2766 parse_classname (void)
2768 struct sym *last_class = NULL;
2770 while (LOOKING_AT (IDENT))
2772 last_class = add_sym (yytext, last_class);
2773 MATCH ();
2775 if (LOOKING_AT ('<'))
2777 skip_matching ();
2778 set_flag (&last_class->flags, F_TEMPLATE);
2781 if (!LOOKING_AT (DCOLON))
2782 break;
2784 MATCH ();
2787 return last_class;
2791 /* Parse an operator name. Add the `static' flag to *SC if an
2792 implicitly static operator has been parsed. Value is a pointer to
2793 a static buffer holding the constructed operator name string. */
2795 static char *
2796 operator_name (int *sc)
2798 static size_t id_size = 0;
2799 static char *id = NULL;
2800 const char *s;
2801 size_t len;
2803 MATCH ();
2805 if (LOOKING_AT2 (NEW, DELETE))
2807 /* `new' and `delete' are implicitly static. */
2808 if (*sc != SC_FRIEND)
2809 *sc = SC_STATIC;
2811 s = token_string (LA1);
2812 MATCH ();
2814 ptrdiff_t slen = strlen (s);
2815 len = slen + 10;
2816 if (len > id_size)
2818 size_t new_size = max (len, 2 * id_size);
2819 id = (char *) xrealloc (id, new_size);
2820 id_size = new_size;
2822 char *z = stpcpy (id, s);
2824 /* Vector new or delete? */
2825 if (LOOKING_AT ('['))
2827 z = stpcpy (z, "[");
2828 MATCH ();
2830 if (LOOKING_AT (']'))
2832 strcpy (z, "]");
2833 MATCH ();
2837 else
2839 size_t tokens_matched = 0;
2841 len = 20;
2842 if (len > id_size)
2844 int new_size = max (len, 2 * id_size);
2845 id = (char *) xrealloc (id, new_size);
2846 id_size = new_size;
2848 char *z = stpcpy (id, "operator");
2850 /* Beware access declarations of the form "X::f;" Beware of
2851 `operator () ()'. Yet another difficulty is found in
2852 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2853 while (!(LOOKING_AT ('(') && tokens_matched)
2854 && !LOOKING_AT2 (';', YYEOF))
2856 s = token_string (LA1);
2857 len += strlen (s) + 2;
2858 if (len > id_size)
2860 ptrdiff_t idlen = z - id;
2861 size_t new_size = max (len, 2 * id_size);
2862 id = (char *) xrealloc (id, new_size);
2863 id_size = new_size;
2864 z = id + idlen;
2867 if (*s != ')' && *s != ']')
2868 *z++ = ' ';
2869 z = stpcpy (z, s);
2870 MATCH ();
2872 /* If this is a simple operator like `+', stop now. */
2873 if (!isalpha ((unsigned char) *s) && *s != '(' && *s != '[')
2874 break;
2876 ++tokens_matched;
2880 return id;
2884 /* This one consumes the last IDENT of a qualified member name like
2885 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2886 symbol structure for the ident. */
2888 static struct sym *
2889 parse_qualified_ident_or_type (char **last_id)
2891 struct sym *cls = NULL;
2892 char *id = NULL;
2893 size_t id_size = 0;
2894 int enter = 0;
2896 while (LOOKING_AT (IDENT))
2898 int len = strlen (yytext) + 1;
2899 if (len > id_size)
2901 id = (char *) xrealloc (id, len);
2902 id_size = len;
2904 strcpy (id, yytext);
2905 *last_id = id;
2906 MATCH ();
2908 SKIP_MATCHING_IF ('<');
2910 if (LOOKING_AT (DCOLON))
2912 struct sym *pcn = NULL;
2913 struct link *pna = check_namespace_alias (id);
2914 if (pna)
2918 enter_namespace (pna->sym->name);
2919 enter++;
2920 pna = pna->next;
2922 while (pna);
2924 else if ((pcn = check_namespace (id, current_namespace)))
2926 enter_namespace (pcn->name);
2927 enter++;
2929 else
2930 cls = add_sym (id, cls);
2932 *last_id = NULL;
2933 free (id);
2934 id = NULL;
2935 id_size = 0;
2936 MATCH ();
2938 else
2939 break;
2942 while (enter--)
2943 leave_namespace ();
2945 return cls;
2949 /* This one consumes the last IDENT of a qualified member name like
2950 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2951 symbol structure for the ident. */
2953 static void
2954 parse_qualified_param_ident_or_type (char **last_id)
2956 struct sym *cls = NULL;
2957 static char *id = NULL;
2958 static int id_size = 0;
2960 assert (LOOKING_AT (IDENT));
2964 int len = strlen (yytext) + 1;
2965 if (len > id_size)
2967 id = (char *) xrealloc (id, len);
2968 id_size = len;
2970 strcpy (id, yytext);
2971 *last_id = id;
2972 MATCH ();
2974 SKIP_MATCHING_IF ('<');
2976 if (LOOKING_AT (DCOLON))
2978 cls = add_sym (id, cls);
2979 *last_id = NULL;
2980 MATCH ();
2982 else
2983 break;
2985 while (LOOKING_AT (IDENT));
2989 /* Parse a class definition.
2991 CONTAINING is the class containing the class being parsed or null.
2992 This may also be null if NESTED != 0 if the containing class is
2993 anonymous. TAG is the tag of the class (struct, union, class).
2994 NESTED is non-zero if we are parsing a nested class.
2996 Current lookahead is the class name. */
2998 static void
2999 class_definition (struct sym *containing, int tag, int flags, int nested)
3001 struct sym *current;
3002 struct sym *base_class;
3004 /* Set CURRENT to null if no entry has to be made for the class
3005 parsed. This is the case for certain command line flag
3006 settings. */
3007 if ((tag != CLASS && !f_structs) || (nested && !f_nested_classes))
3008 current = NULL;
3009 else
3011 current = add_sym (yytext, containing);
3012 current->pos = BUFFER_POS ();
3013 current->regexp = matching_regexp ();
3014 current->filename = filename;
3015 current->flags = flags;
3018 /* If at ':', base class list follows. */
3019 if (LOOKING_AT (':'))
3021 int done = 0;
3022 MATCH ();
3024 while (!done)
3026 switch (LA1)
3028 case VIRTUAL: case PUBLIC: case PROTECTED: case PRIVATE:
3029 MATCH ();
3030 break;
3032 case IDENT:
3033 base_class = parse_classname ();
3034 if (base_class && current && base_class != current)
3035 add_link (base_class, current);
3036 break;
3038 /* The `,' between base classes or the end of the base
3039 class list. Add the previously found base class.
3040 It's done this way to skip over sequences of
3041 `A::B::C' until we reach the end.
3043 FIXME: it is now possible to handle `class X : public B::X'
3044 because we have enough information. */
3045 case ',':
3046 MATCH ();
3047 break;
3049 default:
3050 /* A syntax error, possibly due to preprocessor constructs
3051 like
3053 #ifdef SOMETHING
3054 class A : public B
3055 #else
3056 class A : private B.
3058 MATCH until we see something like `;' or `{'. */
3059 while (!LOOKING_AT3 (';', YYEOF, '{'))
3060 MATCH ();
3061 done = 1;
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;
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 */