1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
29 /* The SunOS compiler doesn't have SEEK_END. */
34 /* Conditionalize function prototypes. */
36 /* Value is non-zero if strings X and Y compare equal. */
38 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
42 /* Files are read in chunks of this number of bytes. */
44 #define READ_CHUNK_SIZE (100 * 1024)
46 #if defined (__MSDOS__)
47 #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0)
49 #if defined (WINDOWSNT)
50 #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0)
52 #define FILENAME_EQ(X,Y) (streq (X,Y))
55 /* The default output file name. */
57 #define DEFAULT_OUTFILE "BROWSE"
59 /* A version string written to the output file. Change this whenever
60 the structure of the output file changes. */
62 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
64 /* The output file consists of a tree of Lisp objects, with major
65 nodes built out of Lisp structures. These are the heads of the
66 Lisp structs with symbols identifying their type. */
68 #define TREE_HEADER_STRUCT "[ebrowse-hs "
69 #define TREE_STRUCT "[ebrowse-ts "
70 #define MEMBER_STRUCT "[ebrowse-ms "
71 #define CLASS_STRUCT "[ebrowse-cs "
73 /* The name of the symbol table entry for global functions, variables,
74 defines etc. This name also appears in the browser display. */
76 #define GLOBALS_NAME "*Globals*"
78 /* Token definitions. */
82 YYEOF
= 0, /* end of file */
83 CSTRING
= 256, /* string constant */
84 CCHAR
, /* character constant */
85 CINT
, /* integral constant */
86 CFLOAT
, /* real constant */
92 IDENT
, /* identifier */
115 /* Keywords. The undef's are there because these
116 three symbols are very likely to be defined somewhere. */
129 CONTINUE
, /* continue */
130 DEFAULT
, /* default */
142 T_INLINE
, /* inline */
146 OPERATOR
, /* operator */
147 PRIVATE
, /* private */
148 PROTECTED
, /* protected */
150 REGISTER
, /* register */
158 TEMPLATE
, /* template */
162 TYPEDEF
, /* typedef */
164 UNSIGNED
, /* unsigned */
165 VIRTUAL
, /* virtual */
167 VOLATILE
, /* volatile */
169 MUTABLE
, /* mutable */
173 SIGNATURE
, /* signature (GNU extension) */
174 NAMESPACE
, /* namespace */
175 EXPLICIT
, /* explicit */
176 TYPENAME
, /* typename */
177 CONST_CAST
, /* const_cast */
178 DYNAMIC_CAST
, /* dynamic_cast */
179 REINTERPRET_CAST
, /* reinterpret_cast */
180 STATIC_CAST
, /* static_cast */
186 /* Storage classes, in a wider sense. */
191 SC_MEMBER
, /* Is an instance member. */
192 SC_STATIC
, /* Is static member. */
193 SC_FRIEND
, /* Is friend function. */
194 SC_TYPE
/* Is a type definition. */
197 /* Member visibility. */
208 #define F_VIRTUAL 1 /* Is virtual function. */
209 #define F_INLINE 2 /* Is inline function. */
210 #define F_CONST 4 /* Is const. */
211 #define F_PURE 8 /* Is pure virtual function. */
212 #define F_MUTABLE 16 /* Is mutable. */
213 #define F_TEMPLATE 32 /* Is a template. */
214 #define F_EXPLICIT 64 /* Is explicit constructor. */
215 #define F_THROW 128 /* Has a throw specification. */
216 #define F_EXTERNC 256 /* Is declared extern "C". */
217 #define F_DEFINE 512 /* Is a #define. */
219 /* Two macros to set and test a bit in an int. */
221 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
222 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
224 /* Structure describing a class member. */
228 struct member
*next
; /* Next in list of members. */
229 struct member
*anext
; /* Collision chain in member_table. */
230 struct member
**list
; /* Pointer to list in class. */
231 unsigned param_hash
; /* Hash value for parameter types. */
232 int vis
; /* Visibility (public, ...). */
233 int flags
; /* See F_* above. */
234 char *regexp
; /* Matching regular expression. */
235 const char *filename
; /* Don't free this shared string. */
236 int pos
; /* Buffer position of occurrence. */
237 char *def_regexp
; /* Regular expression matching definition. */
238 const char *def_filename
; /* File name of definition. */
239 int def_pos
; /* Buffer position of definition. */
240 char name
[1]; /* Member name. */
243 /* Structures of this type are used to connect class structures with
244 their super and subclasses. */
248 struct sym
*sym
; /* The super or subclass. */
249 struct link
*next
; /* Next in list or NULL. */
252 /* Structure used to record namespace aliases. */
256 struct alias
*next
; /* Next in list. */
257 struct sym
*namesp
; /* Namespace in which defined. */
258 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
259 char name
[1]; /* Alias name. */
262 /* The structure used to describe a class in the symbol table,
263 or a namespace in all_namespaces. */
267 int flags
; /* Is class a template class?. */
268 unsigned char visited
; /* Used to find circles. */
269 struct sym
*next
; /* Hash collision list. */
270 struct link
*subs
; /* List of subclasses. */
271 struct link
*supers
; /* List of superclasses. */
272 struct member
*vars
; /* List of instance variables. */
273 struct member
*fns
; /* List of instance functions. */
274 struct member
*static_vars
; /* List of static variables. */
275 struct member
*static_fns
; /* List of static functions. */
276 struct member
*friends
; /* List of friend functions. */
277 struct member
*types
; /* List of local types. */
278 char *regexp
; /* Matching regular expression. */
279 int pos
; /* Buffer position. */
280 const char *filename
; /* File in which it can be found. */
281 const char *sfilename
; /* File in which members can be found. */
282 struct sym
*namesp
; /* Namespace in which defined. . */
283 char name
[1]; /* Name of the class. */
286 /* Experimental: Print info for `--position-info'. We print
287 '(CLASS-NAME SCOPE MEMBER-NAME). */
293 struct sym
*info_cls
= NULL
;
294 struct member
*info_member
= NULL
;
296 /* Experimental. For option `--position-info', the buffer position we
297 are interested in. When this position is reached, print out
298 information about what we know about that point. */
300 int info_position
= -1;
302 /* Command line options structure for getopt_long. */
304 struct option options
[] =
306 {"append", no_argument
, NULL
, 'a'},
307 {"files", required_argument
, NULL
, 'f'},
308 {"help", no_argument
, NULL
, -2},
309 {"min-regexp-length", required_argument
, NULL
, 'm'},
310 {"max-regexp-length", required_argument
, NULL
, 'M'},
311 {"no-nested-classes", no_argument
, NULL
, 'n'},
312 {"no-regexps", no_argument
, NULL
, 'x'},
313 {"no-structs-or-unions", no_argument
, NULL
, 's'},
314 {"output-file", required_argument
, NULL
, 'o'},
315 {"position-info", required_argument
, NULL
, 'p'},
316 {"search-path", required_argument
, NULL
, 'I'},
317 {"verbose", no_argument
, NULL
, 'v'},
318 {"version", no_argument
, NULL
, -3},
319 {"very-verbose", no_argument
, NULL
, 'V'},
323 /* Semantic values of tokens. Set by yylex.. */
325 unsigned yyival
; /* Set for token CINT. */
326 char *yytext
; /* Set for token IDENT. */
333 /* Current line number. */
337 /* The name of the current input file. */
339 const char *filename
;
341 /* Three character class vectors, and macros to test membership
348 #define IDENTP(C) is_ident[(unsigned char) (C)]
349 #define DIGITP(C) is_digit[(unsigned char) (C)]
350 #define WHITEP(C) is_white[(unsigned char) (C)]
352 /* Command line flags. */
359 int f_nested_classes
= 1;
361 /* Maximum and minimum lengths of regular expressions matching a
362 member, class etc., for writing them to the output file. These are
363 overridable from the command line. */
372 size_t inbuffer_size
;
374 /* Return the current buffer position in the input file. */
376 #define BUFFER_POS() (in - inbuffer)
378 /* If current lookahead is CSTRING, the following points to the
379 first character in the string constant. Used for recognizing
384 /* The size of the hash tables for classes.and members. Should be
387 #define TABLE_SIZE 1001
389 /* The hash table for class symbols. */
391 struct sym
*class_table
[TABLE_SIZE
];
393 /* Hash table containing all member structures. This is generally
394 faster for member lookup than traversing the member lists of a
397 struct member
*member_table
[TABLE_SIZE
];
399 /* Hash table for namespace aliases */
401 struct alias
*namespace_alias_table
[TABLE_SIZE
];
403 /* The special class symbol used to hold global functions,
406 struct sym
*global_symbols
;
408 /* The current namespace. */
410 struct sym
*current_namespace
;
412 /* The list of all known namespaces. */
414 struct sym
*all_namespaces
;
416 /* Stack of namespaces we're currently nested in, during the parse. */
418 struct sym
**namespace_stack
;
419 int namespace_stack_size
;
422 /* The current lookahead token. */
426 /* Structure describing a keyword. */
430 const char *name
; /* Spelling. */
431 int tk
; /* Token value. */
432 struct kw
*next
; /* Next in collision chain. */
435 /* Keywords are lookup up in a hash table of their own. */
437 #define KEYWORD_TABLE_SIZE 1001
438 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
445 struct search_path
*next
;
448 struct search_path
*search_path
;
449 struct search_path
*search_path_tail
;
451 /* Function prototypes. */
453 static char *matching_regexp (void);
454 static struct sym
*add_sym (const char *, struct sym
*);
455 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
456 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
457 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
458 static void class_definition (struct sym
*, int, int, int);
459 static char *operator_name (int *);
460 static void parse_qualified_param_ident_or_type (char **);
462 /***********************************************************************
464 ***********************************************************************/
466 /* Print an error in a printf-like style with the current input file
467 name and line number. */
470 yyerror (const char *format
, const char *s
)
472 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
473 fprintf (stderr
, format
, s
);
478 /* Like malloc but print an error and exit if not enough memory is
482 xmalloc (size_t nbytes
)
484 void *p
= malloc (nbytes
);
487 yyerror ("out of memory", NULL
);
494 /* Like realloc but print an error and exit if out of memory. */
497 xrealloc (void *p
, size_t sz
)
502 yyerror ("out of memory", NULL
);
509 /* Like strdup, but print an error and exit if not enough memory is
510 available.. If S is null, return null. */
516 s
= strcpy (xmalloc (strlen (s
) + 1), s
);
522 /***********************************************************************
524 ***********************************************************************/
526 /* Initialize the symbol table. This currently only sets up the
527 special symbol for globals (`*Globals*'). */
532 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
536 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
537 is the class in which class NAME was found. If it is null,
538 this means the scope of NAME is the current namespace.
540 If a symbol for NAME already exists, return that. Otherwise
541 create a new symbol and set it to default values. */
544 add_sym (const char *name
, struct sym
*nested_in_class
)
549 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
551 for (s
= name
, h
= 0; *s
; ++s
)
555 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
556 if (streq (name
, sym
->name
)
557 && ((!sym
->namesp
&& !scope
)
558 || (sym
->namesp
&& scope
559 && streq (sym
->namesp
->name
, scope
->name
))))
570 sym
= (struct sym
*) xmalloc (sizeof *sym
+ strlen (name
));
571 memset (sym
, 0, sizeof *sym
);
572 strcpy (sym
->name
, name
);
574 sym
->next
= class_table
[h
];
575 class_table
[h
] = sym
;
582 /* Add links between superclass SUPER and subclass SUB. */
585 add_link (struct sym
*super
, struct sym
*sub
)
587 struct link
*lnk
, *lnk2
, *p
, *prev
;
589 /* See if a link already exists. */
590 for (p
= super
->subs
, prev
= NULL
;
591 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
592 prev
= p
, p
= p
->next
)
595 /* Avoid duplicates. */
596 if (p
== NULL
|| p
->sym
!= sub
)
598 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
599 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
610 lnk2
->next
= sub
->supers
;
616 /* Find in class CLS member NAME.
618 VAR non-zero means look for a member variable; otherwise a function
619 is searched. SC specifies what kind of member is searched---a
620 static, or per-instance member etc. HASH is a hash code for the
621 parameter types of functions. Value is a pointer to the member
622 found or null if not found. */
624 static struct member
*
625 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
627 struct member
**list
;
629 unsigned name_hash
= 0;
636 list
= &cls
->friends
;
644 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
648 list
= var
? &cls
->vars
: &cls
->fns
;
652 for (s
= name
; *s
; ++s
)
653 name_hash
= (name_hash
<< 1) ^ *s
;
654 i
= name_hash
% TABLE_SIZE
;
656 for (p
= member_table
[i
]; p
; p
= p
->anext
)
657 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
664 /* Add to class CLS information for the declaration of member NAME.
665 REGEXP is a regexp matching the declaration, if non-null. POS is
666 the position in the source where the declaration is found. HASH is
667 a hash code for the parameter list of the member, if it's a
668 function. VAR non-zero means member is a variable or type. SC
669 specifies the type of member (instance member, static, ...). VIS
670 is the member's visibility (public, protected, private). FLAGS is
671 a bit set giving additional information about the member (see the
675 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
679 m
= find_member (cls
, name
, var
, sc
, hash
);
681 m
= add_member (cls
, name
, var
, sc
, hash
);
683 /* Have we seen a new filename? If so record that. */
684 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
685 m
->filename
= filename
;
698 m
->vis
= V_PROTECTED
;
712 /* Add to class CLS information for the definition of member NAME.
713 REGEXP is a regexp matching the declaration, if non-null. POS is
714 the position in the source where the declaration is found. HASH is
715 a hash code for the parameter list of the member, if it's a
716 function. VAR non-zero means member is a variable or type. SC
717 specifies the type of member (instance member, static, ...). VIS
718 is the member's visibility (public, protected, private). FLAGS is
719 a bit set giving additional information about the member (see the
723 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
727 if (sc
== SC_UNKNOWN
)
729 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
732 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
734 m
= add_member (cls
, name
, var
, sc
, hash
);
739 m
= find_member (cls
, name
, var
, sc
, hash
);
741 m
= add_member (cls
, name
, var
, sc
, hash
);
745 cls
->sfilename
= filename
;
747 if (!FILENAME_EQ (cls
->sfilename
, filename
))
748 m
->def_filename
= filename
;
750 m
->def_regexp
= regexp
;
760 /* Add a symbol for a define named NAME to the symbol table.
761 REGEXP is a regular expression matching the define in the source,
762 if it is non-null. POS is the position in the file. */
765 add_define (char *name
, char *regexp
, int pos
)
767 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
768 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
772 /* Add information for the global definition of NAME.
773 REGEXP is a regexp matching the declaration, if non-null. POS is
774 the position in the source where the declaration is found. HASH is
775 a hash code for the parameter list of the member, if it's a
776 function. VAR non-zero means member is a variable or type. SC
777 specifies the type of member (instance member, static, ...). VIS
778 is the member's visibility (public, protected, private). FLAGS is
779 a bit set giving additional information about the member (see the
783 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
788 /* Try to find out for which classes a function is a friend, and add
789 what we know about it to them. */
791 for (i
= 0; i
< TABLE_SIZE
; ++i
)
792 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
793 if (sym
!= global_symbols
&& sym
->friends
)
794 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
795 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
798 /* Add to global symbols. */
799 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
803 /* Add information for the global declaration of NAME.
804 REGEXP is a regexp matching the declaration, if non-null. POS is
805 the position in the source where the declaration is found. HASH is
806 a hash code for the parameter list of the member, if it's a
807 function. VAR non-zero means member is a variable or type. SC
808 specifies the type of member (instance member, static, ...). VIS
809 is the member's visibility (public, protected, private). FLAGS is
810 a bit set giving additional information about the member (see the
814 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
816 /* Add declaration only if not already declared. Header files must
817 be processed before source files for this to have the right effect.
818 I do not want to handle implicit declarations at the moment. */
820 struct member
*found
;
822 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
824 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
826 /* Definition already seen => probably last declaration implicit.
827 Override. This means that declarations must always be added to
828 the symbol table before definitions. */
831 if (!global_symbols
->filename
832 || !FILENAME_EQ (global_symbols
->filename
, filename
))
833 m
->filename
= filename
;
841 info_cls
= global_symbols
;
847 /* Add a symbol for member NAME to class CLS.
848 VAR non-zero means it's a variable. SC specifies the kind of
849 member. HASH is a hash code for the parameter types of a function.
850 Value is a pointer to the member's structure. */
852 static struct member
*
853 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
855 struct member
*m
= (struct member
*) xmalloc (sizeof *m
+ strlen (name
));
856 struct member
**list
;
859 unsigned name_hash
= 0;
863 strcpy (m
->name
, name
);
864 m
->param_hash
= hash
;
871 m
->def_regexp
= NULL
;
872 m
->def_filename
= NULL
;
875 assert (cls
!= NULL
);
880 list
= &cls
->friends
;
888 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
892 list
= var
? &cls
->vars
: &cls
->fns
;
896 for (s
= name
; *s
; ++s
)
897 name_hash
= (name_hash
<< 1) ^ *s
;
898 i
= name_hash
% TABLE_SIZE
;
899 m
->anext
= member_table
[i
];
903 /* Keep the member list sorted. It's cheaper to do it here than to
904 sort them in Lisp. */
905 for (prev
= NULL
, p
= *list
;
906 p
&& strcmp (name
, p
->name
) > 0;
907 prev
= p
, p
= p
->next
)
919 /* Given the root R of a class tree, step through all subclasses
920 recursively, marking functions as virtual that are declared virtual
924 mark_virtual (struct sym
*r
)
927 struct member
*m
, *m2
;
929 for (p
= r
->subs
; p
; p
= p
->next
)
931 for (m
= r
->fns
; m
; m
= m
->next
)
932 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
934 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
935 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
936 SET_FLAG (m2
->flags
, F_VIRTUAL
);
939 mark_virtual (p
->sym
);
944 /* For all roots of the class tree, mark functions as virtual that
945 are virtual because of a virtual declaration in a base class. */
948 mark_inherited_virtual (void)
953 for (i
= 0; i
< TABLE_SIZE
; ++i
)
954 for (r
= class_table
[i
]; r
; r
= r
->next
)
955 if (r
->supers
== NULL
)
960 /* Create and return a symbol for a namespace with name NAME. */
963 make_namespace (char *name
, struct sym
*context
)
965 struct sym
*s
= (struct sym
*) xmalloc (sizeof *s
+ strlen (name
));
966 memset (s
, 0, sizeof *s
);
967 strcpy (s
->name
, name
);
968 s
->next
= all_namespaces
;
975 /* Find the symbol for namespace NAME. If not found, return NULL */
978 check_namespace (char *name
, struct sym
*context
)
980 struct sym
*p
= NULL
;
982 for (p
= all_namespaces
; p
; p
= p
->next
)
984 if (streq (p
->name
, name
) && (p
->namesp
== context
))
991 /* Find the symbol for namespace NAME. If not found, add a new symbol
992 for NAME to all_namespaces. */
995 find_namespace (char *name
, struct sym
*context
)
997 struct sym
*p
= check_namespace (name
, context
);
1000 p
= make_namespace (name
, context
);
1006 /* Find namespace alias with name NAME. If not found return NULL. */
1008 static struct link
*
1009 check_namespace_alias (char *name
)
1011 struct link
*p
= NULL
;
1016 for (s
= name
, h
= 0; *s
; ++s
)
1020 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1021 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1030 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1033 register_namespace_alias (char *new_name
, struct link
*old_name
)
1039 for (s
= new_name
, h
= 0; *s
; ++s
)
1044 /* Is it already in the table of aliases? */
1045 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1046 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1049 al
= (struct alias
*) xmalloc (sizeof *al
+ strlen (new_name
));
1050 strcpy (al
->name
, new_name
);
1051 al
->next
= namespace_alias_table
[h
];
1052 al
->namesp
= current_namespace
;
1053 al
->aliasee
= old_name
;
1054 namespace_alias_table
[h
] = al
;
1058 /* Enter namespace with name NAME. */
1061 enter_namespace (char *name
)
1063 struct sym
*p
= find_namespace (name
, current_namespace
);
1065 if (namespace_sp
== namespace_stack_size
)
1067 int size
= max (10, 2 * namespace_stack_size
);
1069 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1070 size
* sizeof *namespace_stack
);
1071 namespace_stack_size
= size
;
1074 namespace_stack
[namespace_sp
++] = current_namespace
;
1075 current_namespace
= p
;
1079 /* Leave the current namespace. */
1082 leave_namespace (void)
1084 assert (namespace_sp
> 0);
1085 current_namespace
= namespace_stack
[--namespace_sp
];
1090 /***********************************************************************
1091 Writing the Output File
1092 ***********************************************************************/
1094 /* Write string S to the output file FP in a Lisp-readable form.
1095 If S is null, write out `()'. */
1098 putstr (const char *s
, FILE *fp
)
1115 /* A dynamically allocated buffer for constructing a scope name. */
1118 int scope_buffer_size
;
1119 int scope_buffer_len
;
1122 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1125 ensure_scope_buffer_room (int len
)
1127 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1129 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1130 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1131 scope_buffer_size
= new_size
;
1136 /* Recursively add the scope names of symbol P and the scopes of its
1137 namespaces to scope_buffer. Value is a pointer to the complete
1138 scope name constructed. */
1141 sym_scope_1 (struct sym
*p
)
1146 sym_scope_1 (p
->namesp
);
1150 ensure_scope_buffer_room (3);
1151 strcat (scope_buffer
, "::");
1152 scope_buffer_len
+= 2;
1155 len
= strlen (p
->name
);
1156 ensure_scope_buffer_room (len
+ 1);
1157 strcat (scope_buffer
, p
->name
);
1158 scope_buffer_len
+= len
;
1160 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1162 ensure_scope_buffer_room (3);
1163 strcat (scope_buffer
, "<>");
1164 scope_buffer_len
+= 2;
1167 return scope_buffer
;
1171 /* Return the scope of symbol P in printed representation, i.e.
1172 as it would appear in a C*+ source file. */
1175 sym_scope (struct sym
*p
)
1179 scope_buffer_size
= 1024;
1180 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1183 *scope_buffer
= '\0';
1184 scope_buffer_len
= 0;
1187 sym_scope_1 (p
->namesp
);
1189 return scope_buffer
;
1193 /* Dump the list of members M to file FP. Value is the length of the
1197 dump_members (FILE *fp
, struct member
*m
)
1203 for (n
= 0; m
; m
= m
->next
, ++n
)
1205 fputs (MEMBER_STRUCT
, fp
);
1206 putstr (m
->name
, fp
);
1207 putstr (NULL
, fp
); /* FIXME? scope for globals */
1208 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1209 putstr (m
->filename
, fp
);
1210 putstr (m
->regexp
, fp
);
1211 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1212 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1214 putstr (m
->def_filename
, fp
);
1215 putstr (m
->def_regexp
, fp
);
1216 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1227 /* Dump class ROOT to stream FP. */
1230 dump_sym (FILE *fp
, struct sym
*root
)
1232 fputs (CLASS_STRUCT
, fp
);
1233 putstr (root
->name
, fp
);
1235 /* Print scope, if any. */
1237 putstr (sym_scope (root
), fp
);
1242 fprintf (fp
, "%u", root
->flags
);
1243 putstr (root
->filename
, fp
);
1244 putstr (root
->regexp
, fp
);
1245 fprintf (fp
, "%u", (unsigned) root
->pos
);
1246 putstr (root
->sfilename
, fp
);
1252 /* Dump class ROOT and its subclasses to file FP. Value is the
1253 number of classes written. */
1256 dump_tree (FILE *fp
, struct sym
*root
)
1261 dump_sym (fp
, root
);
1271 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1273 fputs (TREE_STRUCT
, fp
);
1274 n
+= dump_tree (fp
, lk
->sym
);
1280 dump_members (fp
, root
->vars
);
1281 n
+= dump_members (fp
, root
->fns
);
1282 dump_members (fp
, root
->static_vars
);
1283 n
+= dump_members (fp
, root
->static_fns
);
1284 n
+= dump_members (fp
, root
->friends
);
1285 dump_members (fp
, root
->types
);
1300 /* Dump the entire class tree to file FP. */
1303 dump_roots (FILE *fp
)
1308 /* Output file header containing version string, command line
1312 fputs (TREE_HEADER_STRUCT
, fp
);
1313 putstr (EBROWSE_FILE_VERSION
, fp
);
1326 /* Mark functions as virtual that are so because of functions
1327 declared virtual in base classes. */
1328 mark_inherited_virtual ();
1330 /* Dump the roots of the graph. */
1331 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1332 for (r
= class_table
[i
]; r
; r
= r
->next
)
1335 fputs (TREE_STRUCT
, fp
);
1336 n
+= dump_tree (fp
, r
);
1346 /***********************************************************************
1348 ***********************************************************************/
1351 #define INCREMENT_LINENO \
1353 if (f_very_verbose) \
1356 printf ("%d:\n", yyline); \
1362 #define INCREMENT_LINENO ++yyline
1365 /* Define two macros for accessing the input buffer (current input
1366 file). GET(C) sets C to the next input character and advances the
1367 input pointer. UNGET retracts the input pointer. */
1369 #define GET(C) ((C) = *in++)
1370 #define UNGET() (--in)
1373 /* Process a preprocessor line. Value is the next character from the
1374 input buffer not consumed. */
1377 process_pp_line (void)
1379 int in_comment
= 0, in_string
= 0;
1383 /* Skip over white space. The `#' has been consumed already. */
1384 while (WHITEP (GET (c
)))
1387 /* Read the preprocessor command (if any). */
1394 /* Is it a `define'? */
1397 if (*yytext
&& streq (yytext
, "define"))
1412 char *regexp
= matching_regexp ();
1413 int pos
= BUFFER_POS ();
1414 add_define (yytext
, regexp
, pos
);
1418 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1422 else if (c
== '/' && !in_comment
)
1427 else if (c
== '*' && in_comment
)
1433 in_string
= !in_string
;
1445 /* Value is the next token from the input buffer. */
1456 while (WHITEP (GET (c
)))
1478 /* String and character constants. */
1481 while (GET (c
) && c
!= end_char
)
1486 /* Escape sequences. */
1489 if (end_char
== '\'')
1490 yyerror ("EOF in character constant", NULL
);
1492 yyerror ("EOF in string constant", NULL
);
1510 /* Hexadecimal escape sequence. */
1512 for (i
= 0; i
< 2; ++i
)
1516 if (c
>= '0' && c
<= '7')
1518 else if (c
>= 'a' && c
<= 'f')
1520 else if (c
>= 'A' && c
<= 'F')
1533 /* Octal escape sequence. */
1535 for (i
= 0; i
< 3; ++i
)
1539 if (c
>= '0' && c
<= '7')
1556 if (end_char
== '\'')
1557 yyerror ("newline in character constant", NULL
);
1559 yyerror ("newline in string constant", NULL
);
1569 return end_char
== '\'' ? CCHAR
: CSTRING
;
1571 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1572 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1573 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1574 case 'v': case 'w': case 'x': case 'y': case 'z':
1575 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1576 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1577 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1578 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1580 /* Identifier and keywords. */
1587 while (IDENTP (GET (*p
)))
1589 hash
= (hash
<< 1) ^ *p
++;
1590 if (p
== yytext_end
- 1)
1592 int size
= yytext_end
- yytext
;
1593 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1594 yytext_end
= yytext
+ 2 * size
;
1595 p
= yytext
+ size
- 1;
1602 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1603 if (streq (k
->name
, yytext
))
1610 /* C and C++ comments, '/' and '/='. */
1638 while (GET (c
) && c
!= '\n')
1640 /* Don't try to read past the end of the input buffer if
1641 the file ends in a C++ comment without a newline. */
1718 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1722 else if (!DIGITP (c
))
1776 c
= process_pp_line ();
1781 case '(': case ')': case '[': case ']': case '{': case '}':
1782 case ';': case ',': case '?': case '~':
1788 if (GET (c
) == 'x' || c
== 'X')
1793 yyival
= yyival
* 16 + c
- '0';
1794 else if (c
>= 'a' && c
<= 'f')
1795 yyival
= yyival
* 16 + c
- 'a' + 10;
1796 else if (c
>= 'A' && c
<= 'F')
1797 yyival
= yyival
* 16 + c
- 'A' + 10;
1807 while (c
>= '0' && c
<= '7')
1809 yyival
= (yyival
<< 3) + c
- '0';
1814 /* Integer suffixes. */
1820 case '1': case '2': case '3': case '4': case '5': case '6':
1821 case '7': case '8': case '9':
1822 /* Integer or floating constant, part before '.'. */
1825 while (GET (c
) && DIGITP (c
))
1826 yyival
= 10 * yyival
+ c
- '0';
1832 /* Digits following '.'. */
1836 /* Optional exponent. */
1837 if (c
== 'E' || c
== 'e')
1839 if (GET (c
) == '-' || c
== '+')
1846 /* Optional type suffixes. */
1859 /* Actually local to matching_regexp. These variables must be in
1860 global scope for the case that `static' get's defined away. */
1862 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1865 /* Value is the string from the start of the line to the current
1866 position in the input buffer, or maybe a bit more if that string is
1867 shorter than min_regexp. */
1870 matching_regexp (void)
1879 if (matching_regexp_buffer
== NULL
)
1881 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1882 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1885 /* Scan back to previous newline of buffer start. */
1886 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1891 while (in
- p
< min_regexp
&& p
> inbuffer
)
1893 /* Line probably not significant enough */
1894 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1901 /* Copy from end to make sure significant portions are included.
1902 This implies that in the browser a regular expressing of the form
1903 `^.*{regexp}' has to be used. */
1904 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1905 s
> matching_regexp_buffer
&& t
> p
;)
1909 if (*s
== '"' || *s
== '\\')
1913 *(matching_regexp_end_buf
- 1) = '\0';
1918 /* Return a printable representation of token T. */
1921 token_string (int t
)
1927 case CSTRING
: return "string constant";
1928 case CCHAR
: return "char constant";
1929 case CINT
: return "int constant";
1930 case CFLOAT
: return "floating constant";
1931 case ELLIPSIS
: return "...";
1932 case LSHIFTASGN
: return "<<=";
1933 case RSHIFTASGN
: return ">>=";
1934 case ARROWSTAR
: return "->*";
1935 case IDENT
: return "identifier";
1936 case DIVASGN
: return "/=";
1937 case INC
: return "++";
1938 case ADDASGN
: return "+=";
1939 case DEC
: return "--";
1940 case ARROW
: return "->";
1941 case SUBASGN
: return "-=";
1942 case MULASGN
: return "*=";
1943 case MODASGN
: return "%=";
1944 case LOR
: return "||";
1945 case ORASGN
: return "|=";
1946 case LAND
: return "&&";
1947 case ANDASGN
: return "&=";
1948 case XORASGN
: return "^=";
1949 case POINTSTAR
: return ".*";
1950 case DCOLON
: return "::";
1951 case EQ
: return "==";
1952 case NE
: return "!=";
1953 case LE
: return "<=";
1954 case LSHIFT
: return "<<";
1955 case GE
: return ">=";
1956 case RSHIFT
: return ">>";
1957 case ASM
: return "asm";
1958 case AUTO
: return "auto";
1959 case BREAK
: return "break";
1960 case CASE
: return "case";
1961 case CATCH
: return "catch";
1962 case CHAR
: return "char";
1963 case CLASS
: return "class";
1964 case CONST
: return "const";
1965 case CONTINUE
: return "continue";
1966 case DEFAULT
: return "default";
1967 case DELETE
: return "delete";
1968 case DO
: return "do";
1969 case DOUBLE
: return "double";
1970 case ELSE
: return "else";
1971 case ENUM
: return "enum";
1972 case EXTERN
: return "extern";
1973 case FLOAT
: return "float";
1974 case FOR
: return "for";
1975 case FRIEND
: return "friend";
1976 case GOTO
: return "goto";
1977 case IF
: return "if";
1978 case T_INLINE
: return "inline";
1979 case INT
: return "int";
1980 case LONG
: return "long";
1981 case NEW
: return "new";
1982 case OPERATOR
: return "operator";
1983 case PRIVATE
: return "private";
1984 case PROTECTED
: return "protected";
1985 case PUBLIC
: return "public";
1986 case REGISTER
: return "register";
1987 case RETURN
: return "return";
1988 case SHORT
: return "short";
1989 case SIGNED
: return "signed";
1990 case SIZEOF
: return "sizeof";
1991 case STATIC
: return "static";
1992 case STRUCT
: return "struct";
1993 case SWITCH
: return "switch";
1994 case TEMPLATE
: return "template";
1995 case THIS
: return "this";
1996 case THROW
: return "throw";
1997 case TRY
: return "try";
1998 case TYPEDEF
: return "typedef";
1999 case UNION
: return "union";
2000 case UNSIGNED
: return "unsigned";
2001 case VIRTUAL
: return "virtual";
2002 case VOID
: return "void";
2003 case VOLATILE
: return "volatile";
2004 case WHILE
: return "while";
2005 case MUTABLE
: return "mutable";
2006 case BOOL
: return "bool";
2007 case TRUE
: return "true";
2008 case FALSE
: return "false";
2009 case SIGNATURE
: return "signature";
2010 case NAMESPACE
: return "namespace";
2011 case EXPLICIT
: return "explicit";
2012 case TYPENAME
: return "typename";
2013 case CONST_CAST
: return "const_cast";
2014 case DYNAMIC_CAST
: return "dynamic_cast";
2015 case REINTERPRET_CAST
: return "reinterpret_cast";
2016 case STATIC_CAST
: return "static_cast";
2017 case TYPEID
: return "typeid";
2018 case USING
: return "using";
2019 case WCHAR
: return "wchar_t";
2020 case YYEOF
: return "EOF";
2035 /* Reinitialize the scanner for a new input file. */
2038 re_init_scanner (void)
2046 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2047 yytext_end
= yytext
+ size
;
2052 /* Insert a keyword NAME with token value TKV into the keyword hash
2056 insert_keyword (const char *name
, int tkv
)
2060 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2062 for (s
= name
; *s
; ++s
)
2065 h
%= KEYWORD_TABLE_SIZE
;
2068 k
->next
= keyword_table
[h
];
2069 keyword_table
[h
] = k
;
2073 /* Initialize the scanner for the first file. This sets up the
2074 character class vectors and fills the keyword hash table. */
2081 /* Allocate the input buffer */
2082 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2083 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2086 /* Set up character class vectors. */
2087 for (i
= 0; i
< sizeof is_ident
; ++i
)
2089 if (i
== '_' || isalnum (i
))
2092 if (i
>= '0' && i
<= '9')
2095 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2099 /* Fill keyword hash table. */
2100 insert_keyword ("and", LAND
);
2101 insert_keyword ("and_eq", ANDASGN
);
2102 insert_keyword ("asm", ASM
);
2103 insert_keyword ("auto", AUTO
);
2104 insert_keyword ("bitand", '&');
2105 insert_keyword ("bitor", '|');
2106 insert_keyword ("bool", BOOL
);
2107 insert_keyword ("break", BREAK
);
2108 insert_keyword ("case", CASE
);
2109 insert_keyword ("catch", CATCH
);
2110 insert_keyword ("char", CHAR
);
2111 insert_keyword ("class", CLASS
);
2112 insert_keyword ("compl", '~');
2113 insert_keyword ("const", CONST
);
2114 insert_keyword ("const_cast", CONST_CAST
);
2115 insert_keyword ("continue", CONTINUE
);
2116 insert_keyword ("default", DEFAULT
);
2117 insert_keyword ("delete", DELETE
);
2118 insert_keyword ("do", DO
);
2119 insert_keyword ("double", DOUBLE
);
2120 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2121 insert_keyword ("else", ELSE
);
2122 insert_keyword ("enum", ENUM
);
2123 insert_keyword ("explicit", EXPLICIT
);
2124 insert_keyword ("extern", EXTERN
);
2125 insert_keyword ("false", FALSE
);
2126 insert_keyword ("float", FLOAT
);
2127 insert_keyword ("for", FOR
);
2128 insert_keyword ("friend", FRIEND
);
2129 insert_keyword ("goto", GOTO
);
2130 insert_keyword ("if", IF
);
2131 insert_keyword ("inline", T_INLINE
);
2132 insert_keyword ("int", INT
);
2133 insert_keyword ("long", LONG
);
2134 insert_keyword ("mutable", MUTABLE
);
2135 insert_keyword ("namespace", NAMESPACE
);
2136 insert_keyword ("new", NEW
);
2137 insert_keyword ("not", '!');
2138 insert_keyword ("not_eq", NE
);
2139 insert_keyword ("operator", OPERATOR
);
2140 insert_keyword ("or", LOR
);
2141 insert_keyword ("or_eq", ORASGN
);
2142 insert_keyword ("private", PRIVATE
);
2143 insert_keyword ("protected", PROTECTED
);
2144 insert_keyword ("public", PUBLIC
);
2145 insert_keyword ("register", REGISTER
);
2146 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2147 insert_keyword ("return", RETURN
);
2148 insert_keyword ("short", SHORT
);
2149 insert_keyword ("signed", SIGNED
);
2150 insert_keyword ("sizeof", SIZEOF
);
2151 insert_keyword ("static", STATIC
);
2152 insert_keyword ("static_cast", STATIC_CAST
);
2153 insert_keyword ("struct", STRUCT
);
2154 insert_keyword ("switch", SWITCH
);
2155 insert_keyword ("template", TEMPLATE
);
2156 insert_keyword ("this", THIS
);
2157 insert_keyword ("throw", THROW
);
2158 insert_keyword ("true", TRUE
);
2159 insert_keyword ("try", TRY
);
2160 insert_keyword ("typedef", TYPEDEF
);
2161 insert_keyword ("typeid", TYPEID
);
2162 insert_keyword ("typename", TYPENAME
);
2163 insert_keyword ("union", UNION
);
2164 insert_keyword ("unsigned", UNSIGNED
);
2165 insert_keyword ("using", USING
);
2166 insert_keyword ("virtual", VIRTUAL
);
2167 insert_keyword ("void", VOID
);
2168 insert_keyword ("volatile", VOLATILE
);
2169 insert_keyword ("wchar_t", WCHAR
);
2170 insert_keyword ("while", WHILE
);
2171 insert_keyword ("xor", '^');
2172 insert_keyword ("xor_eq", XORASGN
);
2177 /***********************************************************************
2179 ***********************************************************************/
2181 /* Match the current lookahead token and set it to the next token. */
2183 #define MATCH() (tk = yylex ())
2185 /* Return the lookahead token. If current lookahead token is cleared,
2186 read a new token. */
2188 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2190 /* Is the current lookahead equal to the token T? */
2192 #define LOOKING_AT(T) (tk == (T))
2194 /* Is the current lookahead one of T1 or T2? */
2196 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2198 /* Is the current lookahead one of T1, T2 or T3? */
2200 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2202 /* Is the current lookahead one of T1...T4? */
2204 #define LOOKING_AT4(T1, T2, T3, T4) \
2205 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2207 /* Match token T if current lookahead is T. */
2209 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2211 /* Skip to matching token if current token is T. */
2213 #define SKIP_MATCHING_IF(T) \
2214 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2217 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2218 the current lookahead token after skipping. */
2223 while (!LOOKING_AT2 (YYEOF
, token
))
2228 /* Skip over pairs of tokens (parentheses, square brackets,
2229 angle brackets, curly brackets) matching the current lookahead. */
2232 skip_matching (void)
2260 if (LOOKING_AT (open
))
2262 else if (LOOKING_AT (close
))
2264 else if (LOOKING_AT (YYEOF
))
2275 skip_initializer (void)
2299 /* Build qualified namespace alias (A::B::c) and return it. */
2301 static struct link
*
2302 match_qualified_namespace_alias (void)
2304 struct link
*head
= NULL
;
2305 struct link
*cur
= NULL
;
2306 struct link
*tmp
= NULL
;
2314 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2315 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2319 cur
= cur
->next
= tmp
;
2336 /* Re-initialize the parser by resetting the lookahead token. */
2339 re_init_parser (void)
2345 /* Parse a parameter list, including the const-specifier,
2346 pure-specifier, and throw-list that may follow a parameter list.
2347 Return in FLAGS what was seen following the parameter list.
2348 Returns a hash code for the parameter types. This value is used to
2349 distinguish between overloaded functions. */
2352 parm_list (int *flags
)
2357 while (!LOOKING_AT2 (YYEOF
, ')'))
2361 /* Skip over grouping parens or parameter lists in parameter
2367 /* Next parameter. */
2373 /* Ignore the scope part of types, if any. This is because
2374 some types need scopes when defined outside of a class body,
2375 and don't need them inside the class body. This means that
2376 we have to look for the last IDENT in a sequence of
2377 IDENT::IDENT::... */
2382 unsigned ident_type_hash
= 0;
2384 parse_qualified_param_ident_or_type (&last_id
);
2387 /* LAST_ID null means something like `X::*'. */
2388 for (; *last_id
; ++last_id
)
2389 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2390 hash
= (hash
<< 1) ^ ident_type_hash
;
2399 /* This distinction is made to make `func (void)' equivalent
2403 if (!LOOKING_AT (')'))
2404 hash
= (hash
<< 1) ^ VOID
;
2407 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2408 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2409 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2410 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2413 hash
= (hash
<< 1) ^ LA1
;
2417 case '*': case '&': case '[': case ']':
2418 hash
= (hash
<< 1) ^ LA1
;
2428 if (LOOKING_AT (')'))
2432 if (LOOKING_AT (CONST
))
2434 /* We can overload the same function on `const' */
2435 hash
= (hash
<< 1) ^ CONST
;
2436 SET_FLAG (*flags
, F_CONST
);
2440 if (LOOKING_AT (THROW
))
2443 SKIP_MATCHING_IF ('(');
2444 SET_FLAG (*flags
, F_THROW
);
2447 if (LOOKING_AT ('='))
2450 if (LOOKING_AT (CINT
) && yyival
== 0)
2453 SET_FLAG (*flags
, F_PURE
);
2462 /* Print position info to stdout. */
2467 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2469 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2470 info_cls
->name
, sym_scope (info_cls
),
2471 info_member
->name
, info_where
);
2475 /* Parse a member declaration within the class body of CLS. VIS is
2476 the access specifier for the member (private, protected,
2480 member (struct sym
*cls
, int vis
)
2484 char *regexp
= NULL
;
2495 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2503 /* A function or class may follow. */
2506 SET_FLAG (flags
, F_TEMPLATE
);
2507 /* Skip over template argument list */
2508 SKIP_MATCHING_IF ('<');
2512 SET_FLAG (flags
, F_EXPLICIT
);
2516 SET_FLAG (flags
, F_MUTABLE
);
2520 SET_FLAG (flags
, F_INLINE
);
2524 SET_FLAG (flags
, F_VIRTUAL
);
2553 /* Remember IDENTS seen so far. Among these will be the member
2555 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2559 strcpy (id
+ 1, yytext
);
2562 strcpy (id
, yytext
);
2568 char *s
= operator_name (&sc
);
2569 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2575 /* Most probably the beginning of a parameter list. */
2581 if (!(is_constructor
= streq (id
, cls
->name
)))
2582 regexp
= matching_regexp ();
2587 pos
= BUFFER_POS ();
2588 hash
= parm_list (&flags
);
2591 regexp
= matching_regexp ();
2593 if (id
&& cls
!= NULL
)
2594 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2596 while (!LOOKING_AT3 (';', '{', YYEOF
))
2599 if (LOOKING_AT ('{') && id
&& cls
)
2600 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2607 case STRUCT
: case UNION
: case CLASS
:
2614 /* More than one ident here to allow for MS-DOS specialties
2615 like `_export class' etc. The last IDENT seen counts
2616 as the class name. */
2617 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2619 if (LOOKING_AT (IDENT
))
2624 if (LOOKING_AT2 (':', '{'))
2625 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2630 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2631 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2632 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2641 if (LOOKING_AT (';'))
2643 /* The end of a member variable, a friend declaration or an access
2644 declaration. We don't want to add friend classes as members. */
2645 if (id
&& sc
!= SC_FRIEND
&& cls
)
2647 regexp
= matching_regexp ();
2648 pos
= BUFFER_POS ();
2652 if (type_seen
|| !paren_seen
)
2653 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2655 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2662 else if (LOOKING_AT ('{'))
2665 if (sc
== SC_TYPE
&& id
&& cls
)
2667 regexp
= matching_regexp ();
2668 pos
= BUFFER_POS ();
2672 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2673 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2685 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2689 class_body (struct sym
*cls
, int tag
)
2691 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2694 while (!LOOKING_AT2 (YYEOF
, '}'))
2698 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2702 if (LOOKING_AT (':'))
2709 /* Probably conditional compilation for inheritance list.
2710 We don't known whether there comes more of this.
2711 This is only a crude fix that works most of the time. */
2716 while (LOOKING_AT2 (IDENT
, ',')
2717 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2726 /* Try to synchronize */
2727 case CHAR
: case CLASS
: case CONST
:
2728 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2729 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2730 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2731 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2732 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2733 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2745 /* Parse a qualified identifier. Current lookahead is IDENT. A
2746 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2747 symbol for that class. */
2750 parse_classname (void)
2752 struct sym
*last_class
= NULL
;
2754 while (LOOKING_AT (IDENT
))
2756 last_class
= add_sym (yytext
, last_class
);
2759 if (LOOKING_AT ('<'))
2762 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2765 if (!LOOKING_AT (DCOLON
))
2775 /* Parse an operator name. Add the `static' flag to *SC if an
2776 implicitly static operator has been parsed. Value is a pointer to
2777 a static buffer holding the constructed operator name string. */
2780 operator_name (int *sc
)
2782 static size_t id_size
= 0;
2783 static char *id
= NULL
;
2789 if (LOOKING_AT2 (NEW
, DELETE
))
2791 /* `new' and `delete' are implicitly static. */
2792 if (*sc
!= SC_FRIEND
)
2795 s
= token_string (LA1
);
2798 len
= strlen (s
) + 10;
2801 size_t new_size
= max (len
, 2 * id_size
);
2802 id
= (char *) xrealloc (id
, new_size
);
2807 /* Vector new or delete? */
2808 if (LOOKING_AT ('['))
2813 if (LOOKING_AT (']'))
2822 size_t tokens_matched
= 0;
2827 int new_size
= max (len
, 2 * id_size
);
2828 id
= (char *) xrealloc (id
, new_size
);
2831 strcpy (id
, "operator");
2833 /* Beware access declarations of the form "X::f;" Beware of
2834 `operator () ()'. Yet another difficulty is found in
2835 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2836 while (!(LOOKING_AT ('(') && tokens_matched
)
2837 && !LOOKING_AT2 (';', YYEOF
))
2839 s
= token_string (LA1
);
2840 len
+= strlen (s
) + 2;
2843 size_t new_size
= max (len
, 2 * id_size
);
2844 id
= (char *) xrealloc (id
, new_size
);
2848 if (*s
!= ')' && *s
!= ']')
2853 /* If this is a simple operator like `+', stop now. */
2854 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2865 /* This one consumes the last IDENT of a qualified member name like
2866 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2867 symbol structure for the ident. */
2870 parse_qualified_ident_or_type (char **last_id
)
2872 struct sym
*cls
= NULL
;
2877 while (LOOKING_AT (IDENT
))
2879 int len
= strlen (yytext
) + 1;
2882 id
= (char *) xrealloc (id
, len
);
2885 strcpy (id
, yytext
);
2889 SKIP_MATCHING_IF ('<');
2891 if (LOOKING_AT (DCOLON
))
2893 struct sym
*pcn
= NULL
;
2894 struct link
*pna
= check_namespace_alias (id
);
2899 enter_namespace (pna
->sym
->name
);
2905 else if ((pcn
= check_namespace (id
, current_namespace
)))
2907 enter_namespace (pcn
->name
);
2911 cls
= add_sym (id
, cls
);
2930 /* This one consumes the last IDENT of a qualified member name like
2931 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2932 symbol structure for the ident. */
2935 parse_qualified_param_ident_or_type (char **last_id
)
2937 struct sym
*cls
= NULL
;
2938 static char *id
= NULL
;
2939 static int id_size
= 0;
2941 assert (LOOKING_AT (IDENT
));
2945 int len
= strlen (yytext
) + 1;
2948 id
= (char *) xrealloc (id
, len
);
2951 strcpy (id
, yytext
);
2955 SKIP_MATCHING_IF ('<');
2957 if (LOOKING_AT (DCOLON
))
2959 cls
= add_sym (id
, cls
);
2966 while (LOOKING_AT (IDENT
));
2970 /* Parse a class definition.
2972 CONTAINING is the class containing the class being parsed or null.
2973 This may also be null if NESTED != 0 if the containing class is
2974 anonymous. TAG is the tag of the class (struct, union, class).
2975 NESTED is non-zero if we are parsing a nested class.
2977 Current lookahead is the class name. */
2980 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
2982 struct sym
*current
;
2983 struct sym
*base_class
;
2985 /* Set CURRENT to null if no entry has to be made for the class
2986 parsed. This is the case for certain command line flag
2988 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
2992 current
= add_sym (yytext
, containing
);
2993 current
->pos
= BUFFER_POS ();
2994 current
->regexp
= matching_regexp ();
2995 current
->filename
= filename
;
2996 current
->flags
= flags
;
2999 /* If at ':', base class list follows. */
3000 if (LOOKING_AT (':'))
3009 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3014 base_class
= parse_classname ();
3015 if (base_class
&& current
&& base_class
!= current
)
3016 add_link (base_class
, current
);
3019 /* The `,' between base classes or the end of the base
3020 class list. Add the previously found base class.
3021 It's done this way to skip over sequences of
3022 `A::B::C' until we reach the end.
3024 FIXME: it is now possible to handle `class X : public B::X'
3025 because we have enough information. */
3031 /* A syntax error, possibly due to preprocessor constructs
3037 class A : private B.
3039 MATCH until we see something like `;' or `{'. */
3040 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3051 /* Parse the class body if there is one. */
3052 if (LOOKING_AT ('{'))
3054 if (tag
!= CLASS
&& !f_structs
)
3059 class_body (current
, tag
);
3061 if (LOOKING_AT ('}'))
3064 if (LOOKING_AT (';') && !nested
)
3071 /* Add to class *CLS information for the declaration of variable or
3072 type *ID. If *CLS is null, this means a global declaration. SC is
3073 the storage class of *ID. FLAGS is a bit set giving additional
3074 information about the member (see the F_* defines). */
3077 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3079 if (LOOKING_AT2 (';', ','))
3081 /* The end of a member variable or of an access declaration
3082 `X::f'. To distinguish between them we have to know whether
3083 type information has been seen. */
3086 char *regexp
= matching_regexp ();
3087 int pos
= BUFFER_POS ();
3090 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3092 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3098 else if (LOOKING_AT ('{'))
3100 if (sc
== SC_TYPE
&& *id
)
3102 /* A named enumeration. */
3103 char *regexp
= matching_regexp ();
3104 int pos
= BUFFER_POS ();
3105 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3117 /* Parse a declaration. */
3120 declaration (int flags
)
3123 struct sym
*cls
= NULL
;
3124 char *regexp
= NULL
;
3130 while (!LOOKING_AT3 (';', '{', YYEOF
))
3153 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3154 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3155 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3159 case CLASS
: case STRUCT
: case UNION
:
3160 /* This is for the case `STARTWRAP class X : ...' or
3161 `declare (X, Y)\n class A : ...'. */
3169 /* Assumed to be the start of an initialization in this
3171 skip_initializer ();
3175 add_declarator (&cls
, &id
, flags
, sc
);
3180 char *s
= operator_name (&sc
);
3181 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3187 SET_FLAG (flags
, F_INLINE
);
3193 if (LOOKING_AT (IDENT
))
3195 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3197 strcpy (id
+ 1, yytext
);
3203 cls
= parse_qualified_ident_or_type (&id
);
3207 /* Most probably the beginning of a parameter list. */
3214 if (!(is_constructor
= streq (id
, cls
->name
)))
3215 regexp
= matching_regexp ();
3220 pos
= BUFFER_POS ();
3221 hash
= parm_list (&flags
);
3224 regexp
= matching_regexp ();
3227 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3232 /* This may be a C functions, but also a macro
3233 call of the form `declare (A, B)' --- such macros
3234 can be found in some class libraries. */
3239 regexp
= matching_regexp ();
3240 pos
= BUFFER_POS ();
3241 hash
= parm_list (&flags
);
3242 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3245 /* This is for the case that the function really is
3246 a macro with no `;' following it. If a CLASS directly
3247 follows, we would miss it otherwise. */
3248 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3252 while (!LOOKING_AT3 (';', '{', YYEOF
))
3255 if (!cls
&& id
&& LOOKING_AT ('{'))
3256 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3264 add_declarator (&cls
, &id
, flags
, sc
);
3268 /* Parse a list of top-level declarations/definitions. START_FLAGS
3269 says in which context we are parsing. If it is F_EXTERNC, we are
3270 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3274 globals (int start_flags
)
3278 int flags
= start_flags
;
3290 if (LOOKING_AT (IDENT
))
3292 char *namespace_name
= xstrdup (yytext
);
3295 if (LOOKING_AT ('='))
3297 struct link
*qna
= match_qualified_namespace_alias ();
3299 register_namespace_alias (namespace_name
, qna
);
3301 if (skip_to (';') == ';')
3304 else if (LOOKING_AT ('{'))
3307 enter_namespace (namespace_name
);
3313 free (namespace_name
);
3320 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3321 && *(string_start
+ 1) == '"')
3323 /* This is `extern "C"'. */
3326 if (LOOKING_AT ('{'))
3329 globals (F_EXTERNC
);
3333 SET_FLAG (flags
, F_EXTERNC
);
3339 SKIP_MATCHING_IF ('<');
3340 SET_FLAG (flags
, F_TEMPLATE
);
3343 case CLASS
: case STRUCT
: case UNION
:
3348 /* More than one ident here to allow for MS-DOS and OS/2
3349 specialties like `far', `_Export' etc. Some C++ libs
3350 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3351 of the class name. */
3352 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3354 if (LOOKING_AT (IDENT
))
3359 /* Don't add anonymous unions. */
3360 if (LOOKING_AT2 (':', '{') && !anonymous
)
3361 class_definition (NULL
, class_tk
, flags
, 0);
3364 if (skip_to (';') == ';')
3368 flags
= start_flags
;
3378 declaration (flags
);
3379 flags
= start_flags
;
3384 yyerror ("parse error", NULL
);
3389 /* Parse the current input file. */
3394 while (globals (0) == 0)
3400 /***********************************************************************
3402 ***********************************************************************/
3404 /* Add the list of paths PATH_LIST to the current search path for
3408 add_search_path (char *path_list
)
3412 char *start
= path_list
;
3413 struct search_path
*p
;
3415 while (*path_list
&& *path_list
!= SEPCHAR
)
3418 p
= (struct search_path
*) xmalloc (sizeof *p
);
3419 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3420 memcpy (p
->path
, start
, path_list
- start
);
3421 p
->path
[path_list
- start
] = '\0';
3424 if (search_path_tail
)
3426 search_path_tail
->next
= p
;
3427 search_path_tail
= p
;
3430 search_path
= search_path_tail
= p
;
3432 while (*path_list
== SEPCHAR
)
3438 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3439 opened. Try to find FILE in search_path first, then try the
3440 unchanged file name. */
3443 open_file (char *file
)
3446 static char *buffer
;
3447 static int buffer_size
;
3448 struct search_path
*path
;
3449 int flen
= strlen (file
) + 1; /* +1 for the slash */
3451 filename
= xstrdup (file
);
3453 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3455 int len
= strlen (path
->path
) + flen
;
3457 if (len
+ 1 >= buffer_size
)
3459 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3460 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3463 strcpy (buffer
, path
->path
);
3464 strcat (buffer
, "/");
3465 strcat (buffer
, file
);
3466 fp
= fopen (buffer
, "r");
3469 /* Try the original file name. */
3471 fp
= fopen (file
, "r");
3474 yyerror ("cannot open", NULL
);
3480 /* Display usage information and exit program. */
3483 Usage: ebrowse [options] {files}\n\
3485 -a, --append append output to existing file\n\
3486 -f, --files=FILES read input file names from FILE\n\
3487 -I, --search-path=LIST set search path for input files\n\
3488 -m, --min-regexp-length=N set minimum regexp length to N\n\
3489 -M, --max-regexp-length=N set maximum regexp length to N\n\
3490 -n, --no-nested-classes exclude nested classes\n\
3491 -o, --output-file=FILE set output file name to FILE\n\
3492 -p, --position-info print info about position in file\n\
3493 -s, --no-structs-or-unions don't record structs or unions\n\
3494 -v, --verbose be verbose\n\
3495 -V, --very-verbose be very verbose\n\
3496 -x, --no-regexps don't record regular expressions\n\
3497 --help display this help\n\
3498 --version display version info\n\
3501 static _Noreturn
void
3505 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3509 /* Display version and copyright info. The VERSION macro is set
3510 from config.h and contains the Emacs version. */
3513 # define VERSION "21"
3516 static _Noreturn
void
3519 char emacs_copyright
[] = COPYRIGHT
;
3521 printf ("ebrowse %s\n", VERSION
);
3522 puts (emacs_copyright
);
3523 puts ("This program is distributed under the same terms as Emacs.");
3524 exit (EXIT_SUCCESS
);
3528 /* Parse one input file FILE, adding classes and members to the symbol
3532 process_file (char *file
)
3536 fp
= open_file (file
);
3539 size_t nread
, nbytes
;
3541 /* Give a progress indication if needed. */
3553 /* Read file to inbuffer. */
3556 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3558 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3559 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3562 nbytes
= fread (inbuffer
+ nread
, 1, READ_CHUNK_SIZE
, fp
);
3567 inbuffer
[nread
] = '\0';
3569 /* Reinitialize scanner and parser for the new input file. */
3573 /* Parse it and close the file. */
3580 /* Read a line from stream FP and return a pointer to a static buffer
3581 containing its contents without the terminating newline. Value
3582 is null when EOF is reached. */
3585 read_line (FILE *fp
)
3587 static char *buffer
;
3588 static int buffer_size
;
3591 while ((c
= getc (fp
)) != EOF
&& c
!= '\n')
3593 if (i
>= buffer_size
)
3595 buffer_size
= max (100, buffer_size
* 2);
3596 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3602 if (c
== EOF
&& i
== 0)
3605 if (i
== buffer_size
)
3607 buffer_size
= max (100, buffer_size
* 2);
3608 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3612 if (i
> 0 && buffer
[i
- 1] == '\r')
3613 buffer
[i
- 1] = '\0';
3618 /* Main entry point. */
3621 main (int argc
, char **argv
)
3624 int any_inputfiles
= 0;
3625 static const char *out_filename
= DEFAULT_OUTFILE
;
3626 static char **input_filenames
= NULL
;
3627 static int input_filenames_size
= 0;
3628 static int n_input_files
;
3630 filename
= "command line";
3633 while ((i
= getopt_long (argc
, argv
, "af:I:m:M:no:p:svVx",
3634 options
, NULL
)) != EOF
)
3640 info_position
= atoi (optarg
);
3644 f_nested_classes
= 0;
3651 /* Add the name of a file containing more input files. */
3653 if (n_input_files
== input_filenames_size
)
3655 input_filenames_size
= max (10, 2 * input_filenames_size
);
3656 input_filenames
= (char **) xrealloc ((void *)input_filenames
,
3657 input_filenames_size
);
3659 input_filenames
[n_input_files
++] = xstrdup (optarg
);
3662 /* Append new output to output file instead of truncating it. */
3667 /* Include structs in the output */
3672 /* Be verbose (give a progress indication). */
3677 /* Be very verbose (print file names as they are processed). */
3683 /* Change the name of the output file. */
3685 out_filename
= optarg
;
3688 /* Set minimum length for regular expression strings
3689 when recorded in the output file. */
3691 min_regexp
= atoi (optarg
);
3694 /* Set maximum length for regular expression strings
3695 when recorded in the output file. */
3697 max_regexp
= atoi (optarg
);
3700 /* Add to search path. */
3702 add_search_path (optarg
);
3716 /* Call init_scanner after command line flags have been processed to be
3717 able to add keywords depending on command line (not yet
3722 /* Open output file */
3727 /* Check that the file to append to exists, and is not
3728 empty. More specifically, it should be a valid file
3729 produced by a previous run of ebrowse, but that's too
3730 difficult to check. */
3734 fp
= fopen (out_filename
, "r");
3737 yyerror ("file `%s' must exist for --append", out_filename
);
3738 exit (EXIT_FAILURE
);
3741 rc
= fseek (fp
, 0, SEEK_END
);
3744 yyerror ("error seeking in file `%s'", out_filename
);
3745 exit (EXIT_FAILURE
);
3751 yyerror ("error getting size of file `%s'", out_filename
);
3752 exit (EXIT_FAILURE
);
3757 yyerror ("file `%s' is empty", out_filename
);
3758 /* It may be ok to use an empty file for appending.
3759 exit (EXIT_FAILURE); */
3765 yyout
= fopen (out_filename
, f_append
? "a" : "w");
3768 yyerror ("cannot open output file `%s'", out_filename
);
3769 exit (EXIT_FAILURE
);
3773 /* Process input files specified on the command line. */
3774 while (optind
< argc
)
3776 process_file (argv
[optind
++]);
3780 /* Process files given on stdin if no files specified. */
3781 if (!any_inputfiles
&& n_input_files
== 0)
3784 while ((file
= read_line (stdin
)) != NULL
)
3785 process_file (file
);
3789 /* Process files from `--files=FILE'. Every line in FILE names
3790 one input file to process. */
3791 for (i
= 0; i
< n_input_files
; ++i
)
3793 FILE *fp
= fopen (input_filenames
[i
], "r");
3796 yyerror ("cannot open input file `%s'", input_filenames
[i
]);
3800 while ((file
= read_line (fp
)) != NULL
)
3801 process_file (file
);
3807 /* Write output file. */
3810 /* Close output file. */
3811 if (yyout
!= stdout
)
3814 return EXIT_SUCCESS
;
3817 /* ebrowse.c ends here */