1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-1999, 2000 Free Software Foundation Inc.
5 Author: Gerd Moellmann <gerd@gnu.org>
8 This file is part of GNU Emacs.
10 GNU Emacs is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
35 /* Conditionalize function prototypes. */
37 #ifdef PROTOTYPES /* From config.h. */
43 /* Value is non-zero if strings X and Y compare equal. */
45 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
47 /* The ubiquitous `max' and `min' macros. */
50 #define max(X, Y) ((X) > (Y) ? (X) : (Y))
51 #define min(X, Y) ((X) < (Y) ? (X) : (Y))
54 /* Files are read in chunks of this number of bytes. */
56 #define READ_CHUNK_SIZE (100 * 1024)
58 /* The character used as a separator in path lists (like $PATH). */
60 #if defined(__MSDOS__)
61 #define PATH_LIST_SEPARATOR ';'
62 #define FILENAME_EQ(X,Y) (strcasecmp(X,Y) == 0)
64 #if defined(WINDOWSNT)
65 #define PATH_LIST_SEPARATOR ';'
66 #define FILENAME_EQ(X,Y) (stricmp(X,Y) == 0)
68 #define PATH_LIST_SEPARATOR ':'
69 #define FILENAME_EQ(X,Y) (streq(X,Y))
72 /* The default output file name. */
74 #define DEFAULT_OUTFILE "BROWSE"
76 /* A version string written to the output file. Change this whenever
77 the structure of the output file changes. */
79 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
81 /* The output file consists of a tree of Lisp objects, with major
82 nodes built out of Lisp structures. These are the heads of the
83 Lisp structs with symbols identifying their type. */
85 #define TREE_HEADER_STRUCT "[ebrowse-hs "
86 #define TREE_STRUCT "[ebrowse-ts "
87 #define MEMBER_STRUCT "[ebrowse-ms "
88 #define BROWSE_STRUCT "[ebrowse-bs "
89 #define CLASS_STRUCT "[ebrowse-cs "
91 /* The name of the symbol table entry for global functions, variables,
92 defines etc. This name also appears in the browser display. */
94 #define GLOBALS_NAME "*Globals*"
96 /* Token definitions. */
100 YYEOF
= 0, /* end of file */
101 CSTRING
= 256, /* string constant */
102 CCHAR
, /* character constant */
103 CINT
, /* integral constant */
104 CFLOAT
, /* real constant */
107 LSHIFTASGN
, /* <<= */
108 RSHIFTASGN
, /* >>= */
110 IDENT
, /* identifier */
133 /* Keywords. The undef's are there because these
134 three symbols are very likely to be defined somewhere. */
147 CONTINUE
, /* continue */
148 DEFAULT
, /* default */
160 T_INLINE
, /* inline */
164 OPERATOR
, /* operator */
165 PRIVATE
, /* private */
166 PROTECTED
, /* protected */
168 REGISTER
, /* register */
176 TEMPLATE
, /* template */
180 TYPEDEF
, /* typedef */
182 UNSIGNED
, /* unsigned */
183 VIRTUAL
, /* virtual */
185 VOLATILE
, /* volatile */
187 MUTABLE
, /* mutable */
191 SIGNATURE
, /* signature (GNU extension) */
192 NAMESPACE
, /* namespace */
193 EXPLICIT
, /* explicit */
194 TYPENAME
, /* typename */
195 CONST_CAST
, /* const_cast */
196 DYNAMIC_CAST
, /* dynamic_cast */
197 REINTERPRET_CAST
, /* reinterpret_cast */
198 STATIC_CAST
, /* static_cast */
204 /* Storage classes, in a wider sense. */
209 SC_MEMBER
, /* Is an instance member. */
210 SC_STATIC
, /* Is static member. */
211 SC_FRIEND
, /* Is friend function. */
212 SC_TYPE
/* Is a type definition. */
215 /* Member visibility. */
226 #define F_VIRTUAL 1 /* Is virtual function. */
227 #define F_INLINE 2 /* Is inline function. */
228 #define F_CONST 4 /* Is const. */
229 #define F_PURE 8 /* Is pure virtual function. */
230 #define F_MUTABLE 16 /* Is mutable. */
231 #define F_TEMPLATE 32 /* Is a template. */
232 #define F_EXPLICIT 64 /* Is explicit constructor. */
233 #define F_THROW 128 /* Has a throw specification. */
234 #define F_EXTERNC 256 /* Is declared extern "C". */
235 #define F_DEFINE 512 /* Is a #define. */
237 /* Two macros to set and test a bit in an int. */
239 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
240 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
242 /* Structure describing a class member. */
246 struct member
*next
; /* Next in list of members. */
247 struct member
*anext
; /* Collision chain in member_table. */
248 struct member
**list
; /* Pointer to list in class. */
249 unsigned param_hash
; /* Hash value for parameter types. */
250 int vis
; /* Visibility (public, ...). */
251 int flags
; /* See F_* above. */
252 char *regexp
; /* Matching regular expression. */
253 char *filename
; /* Don't free this shared string. */
254 int pos
; /* Buffer position of occurrence. */
255 char *def_regexp
; /* Regular expression matching definition. */
256 char *def_filename
; /* File name of definition. */
257 int def_pos
; /* Buffer position of definition. */
258 char name
[1]; /* Member name. */
261 /* Structures of this type are used to connect class structures with
262 their super and subclasses. */
266 struct sym
*sym
; /* The super or subclass. */
267 struct link
*next
; /* Next in list or NULL. */
270 /* Structure used to record namespace aliases. */
274 struct alias
*next
; /* Next in list. */
275 char name
[1]; /* Alias name. */
278 /* The structure used to describe a class in the symbol table,
279 or a namespace in all_namespaces. */
283 int flags
; /* Is class a template class?. */
284 unsigned char visited
; /* Used to find circles. */
285 struct sym
*next
; /* Hash collision list. */
286 struct link
*subs
; /* List of subclasses. */
287 struct link
*supers
; /* List of superclasses. */
288 struct member
*vars
; /* List of instance variables. */
289 struct member
*fns
; /* List of instance functions. */
290 struct member
*static_vars
; /* List of static variables. */
291 struct member
*static_fns
; /* List of static functions. */
292 struct member
*friends
; /* List of friend functions. */
293 struct member
*types
; /* List of local types. */
294 char *regexp
; /* Matching regular expression. */
295 int pos
; /* Buffer position. */
296 char *filename
; /* File in which it can be found. */
297 char *sfilename
; /* File in which members can be found. */
298 struct sym
*namesp
; /* Namespace in which defined. . */
299 struct alias
*namesp_aliases
; /* List of aliases for namespaces. */
300 char name
[1]; /* Name of the class. */
303 /* Experimental: Print info for `--position-info'. We print
304 '(CLASS-NAME SCOPE MEMBER-NAME). */
310 struct sym
*info_cls
= NULL
;
311 struct member
*info_member
= NULL
;
313 /* Experimental. For option `--position-info', the buffer position we
314 are interested in. When this position is reached, print out
315 information about what we know about that point. */
317 int info_position
= -1;
319 /* Command line options structure for getopt_long. */
321 struct option options
[] =
323 {"append", no_argument
, NULL
, 'a'},
324 {"files", required_argument
, NULL
, 'f'},
325 {"help", no_argument
, NULL
, -2},
326 {"min-regexp-length", required_argument
, NULL
, 'm'},
327 {"max-regexp-length", required_argument
, NULL
, 'M'},
328 {"no-nested-classes", no_argument
, NULL
, 'n'},
329 {"no-regexps", no_argument
, NULL
, 'x'},
330 {"no-structs-or-unions", no_argument
, NULL
, 's'},
331 {"output-file", required_argument
, NULL
, 'o'},
332 {"position-info", required_argument
, NULL
, 'p'},
333 {"search-path", required_argument
, NULL
, 'I'},
334 {"verbose", no_argument
, NULL
, 'v'},
335 {"version", no_argument
, NULL
, -3},
336 {"very-verbose", no_argument
, NULL
, 'V'},
340 /* Semantic values of tokens. Set by yylex.. */
342 unsigned yyival
; /* Set for token CINT. */
343 char *yytext
; /* Set for token IDENT. */
350 /* Current line number. */
354 /* The name of the current input file. */
358 /* Three character class vectors, and macros to test membership
365 #define IDENTP(C) is_ident[(unsigned char) (C)]
366 #define DIGITP(C) is_digit[(unsigned char) (C)]
367 #define WHITEP(C) is_white[(unsigned char) (C)]
369 /* Command line flags. */
376 int f_nested_classes
= 1;
378 /* Maximum and minimum lengths of regular expressions matching a
379 member, class etc., for writing them to the output file. These are
380 overridable from the command line. */
391 /* Return the current buffer position in the input file. */
393 #define BUFFER_POS() (in - inbuffer)
395 /* If current lookahead is CSTRING, the following points to the
396 first character in the string constant. Used for recognizing
401 /* The size of the hash tables for classes.and members. Should be
404 #define TABLE_SIZE 1001
406 /* The hash table for class symbols. */
408 struct sym
*class_table
[TABLE_SIZE
];
410 /* Hash table containing all member structures. This is generally
411 faster for member lookup than traversing the member lists of a
414 struct member
*member_table
[TABLE_SIZE
];
416 /* The special class symbol used to hold global functions,
419 struct sym
*global_symbols
;
421 /* The current namespace. */
423 struct sym
*current_namespace
;
425 /* The list of all known namespaces. */
427 struct sym
*all_namespaces
;
429 /* Stack of namespaces we're currently nested in, during the parse. */
431 struct sym
**namespace_stack
;
432 int namespace_stack_size
;
435 /* The current lookahead token. */
439 /* Structure describing a keyword. */
443 char *name
; /* Spelling. */
444 int tk
; /* Token value. */
445 struct kw
*next
; /* Next in collision chain. */
448 /* Keywords are lookup up in a hash table of their own. */
450 #define KEYWORD_TABLE_SIZE 1001
451 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
458 struct search_path
*next
;
461 struct search_path
*search_path
;
462 struct search_path
*search_path_tail
;
464 /* Function prototypes. */
466 int yylex
P_ ((void));
467 void yyparse
P_ ((void));
468 void re_init_parser
P_ ((void));
469 char *token_string
P_ ((int));
470 char *matching_regexp
P_ ((void));
471 void init_sym
P_ ((void));
472 struct sym
*add_sym
P_ ((char *, struct sym
*));
473 void add_link
P_ ((struct sym
*, struct sym
*));
474 void add_member_defn
P_ ((struct sym
*, char *, char *,
475 int, unsigned, int, int, int));
476 void add_member_decl
P_ ((struct sym
*, char *, char *, int,
477 unsigned, int, int, int, int));
478 void dump_roots
P_ ((FILE *));
479 void *xmalloc
P_ ((int));
480 void add_global_defn
P_ ((char *, char *, int, unsigned, int, int, int));
481 void add_global_decl
P_ ((char *, char *, int, unsigned, int, int, int));
482 void add_define
P_ ((char *, char *, int));
483 void mark_inherited_virtual
P_ ((void));
484 void leave_namespace
P_ ((void));
485 void enter_namespace
P_ ((char *));
486 void register_namespace_alias
P_ ((char *, char *));
487 void insert_keyword
P_ ((char *, int));
488 void re_init_scanner
P_ ((void));
489 void init_scanner
P_ ((void));
490 void usage
P_ ((int));
491 void version
P_ ((void));
492 void process_file
P_ ((char *));
493 void add_search_path
P_ ((char *));
494 FILE *open_file
P_ ((char *));
495 int process_pp_line
P_ ((void));
496 int dump_members
P_ ((FILE *, struct member
*));
497 void dump_sym
P_ ((FILE *, struct sym
*));
498 int dump_tree
P_ ((FILE *, struct sym
*));
499 struct member
*find_member
P_ ((struct sym
*, char *, int, int, unsigned));
500 struct member
*add_member
P_ ((struct sym
*, char *, int, int, unsigned));
501 void mark_virtual
P_ ((struct sym
*));
502 void mark_virtual
P_ ((struct sym
*));
503 struct sym
*make_namespace
P_ ((char *));
504 char *sym_scope
P_ ((struct sym
*));
505 char *sym_scope_1
P_ ((struct sym
*));
506 int skip_to
P_ ((int));
507 void skip_matching
P_ ((void));
508 void member
P_ ((struct sym
*, int));
509 void class_body
P_ ((struct sym
*, int));
510 void class_definition
P_ ((struct sym
*, int, int, int));
511 void declaration
P_ ((int));
512 unsigned parm_list
P_ ((int *));
513 char *operator_name
P_ ((int *));
514 struct sym
*parse_classname
P_ ((void));
515 struct sym
*parse_qualified_ident_or_type
P_ ((char **));
516 void parse_qualified_param_ident_or_type
P_ ((char **));
517 int globals
P_ ((int));
521 /***********************************************************************
523 ***********************************************************************/
525 /* Print an error in a printf-like style with the current input file
526 name and line number. */
529 yyerror (format
, a1
, a2
, a3
, a4
, a5
)
531 int a1
, a2
, a3
, a4
, a5
;
533 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
534 fprintf (stderr
, format
, a1
, a2
, a3
, a4
, a5
);
539 /* Like malloc but print an error and exit if not enough memory is
546 void *p
= malloc (nbytes
);
549 yyerror ("out of memory");
556 /* Like realloc but print an error and exit if out of memory. */
566 yyerror ("out of memory");
573 /* Like strdup, but print an error and exit if not enough memory is
574 available.. If S is null, return null. */
581 s
= strcpy (xmalloc (strlen (s
) + 1), s
);
587 /***********************************************************************
589 ***********************************************************************/
591 /* Initialize the symbol table. This currently only sets up the
592 special symbol for globals (`*Globals*'). */
597 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
601 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
602 is the class in which class NAME was found. If it is null,
603 this means the scope of NAME is the current namespace.
605 If a symbol for NAME already exists, return that. Otherwise
606 create a new symbol and set it to default values. */
609 add_sym (name
, nested_in_class
)
611 struct sym
*nested_in_class
;
616 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
618 for (s
= name
, h
= 0; *s
; ++s
)
622 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
623 if (streq (name
, sym
->name
) && sym
->namesp
== scope
)
634 sym
= (struct sym
*) xmalloc (sizeof *sym
+ strlen (name
));
635 bzero (sym
, sizeof *sym
);
636 strcpy (sym
->name
, name
);
638 sym
->next
= class_table
[h
];
639 class_table
[h
] = sym
;
646 /* Add links between superclass SUPER and subclass SUB. */
649 add_link (super
, sub
)
650 struct sym
*super
, *sub
;
652 struct link
*lnk
, *lnk2
, *p
, *prev
;
654 /* See if a link already exists. */
655 for (p
= super
->subs
, prev
= NULL
;
656 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
657 prev
= p
, p
= p
->next
)
660 /* Avoid duplicates. */
661 if (p
== NULL
|| p
->sym
!= sub
)
663 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
664 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
675 lnk2
->next
= sub
->supers
;
681 /* Find in class CLS member NAME.
683 VAR non-zero means look for a member variable; otherwise a function
684 is searched. SC specifies what kind of member is searched---a
685 static, or per-instance member etc. HASH is a hash code for the
686 parameter types of functions. Value is a pointer to the member
687 found or null if not found. */
690 find_member (cls
, name
, var
, sc
, hash
)
696 struct member
**list
;
698 unsigned name_hash
= 0;
705 list
= &cls
->friends
;
713 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
717 list
= var
? &cls
->vars
: &cls
->fns
;
721 for (s
= name
; *s
; ++s
)
722 name_hash
= (name_hash
<< 1) ^ *s
;
723 i
= name_hash
% TABLE_SIZE
;
725 for (p
= member_table
[i
]; p
; p
= p
->anext
)
726 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
733 /* Add to class CLS information for the declaration of member NAME.
734 REGEXP is a regexp matching the declaration, if non-null. POS is
735 the position in the source where the declaration is found. HASH is
736 a hash code for the parameter list of the member, if it's a
737 function. VAR non-zero means member is a variable or type. SC
738 specifies the type of member (instance member, static, ...). VIS
739 is the member's visibility (public, protected, private). FLAGS is
740 a bit set giving additional information about the member (see the
744 add_member_decl (cls
, name
, regexp
, pos
, hash
, var
, sc
, vis
, flags
)
757 m
= find_member (cls
, name
, var
, sc
, hash
);
759 m
= add_member (cls
, name
, var
, sc
, hash
);
761 /* Have we seen a new filename? If so record that. */
762 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
763 m
->filename
= filename
;
776 m
->vis
= V_PROTECTED
;
790 /* Add to class CLS information for the definition of member NAME.
791 REGEXP is a regexp matching the declaration, if non-null. POS is
792 the position in the source where the declaration is found. HASH is
793 a hash code for the parameter list of the member, if it's a
794 function. VAR non-zero means member is a variable or type. SC
795 specifies the type of member (instance member, static, ...). VIS
796 is the member's visibility (public, protected, private). FLAGS is
797 a bit set giving additional information about the member (see the
801 add_member_defn (cls
, name
, regexp
, pos
, hash
, var
, sc
, flags
)
813 if (sc
== SC_UNKNOWN
)
815 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
818 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
820 m
= add_member (cls
, name
, var
, sc
, hash
);
825 m
= find_member (cls
, name
, var
, sc
, hash
);
827 m
= add_member (cls
, name
, var
, sc
, hash
);
831 cls
->sfilename
= filename
;
833 if (!FILENAME_EQ (cls
->sfilename
, filename
))
834 m
->def_filename
= filename
;
836 m
->def_regexp
= regexp
;
846 /* Add a symbol for a define named NAME to the symbol table.
847 REGEXP is a regular expression matching the define in the source,
848 if it is non-null. POS is the position in the file. */
851 add_define (name
, regexp
, pos
)
855 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
856 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
860 /* Add information for the global definition of NAME.
861 REGEXP is a regexp matching the declaration, if non-null. POS is
862 the position in the source where the declaration is found. HASH is
863 a hash code for the parameter list of the member, if it's a
864 function. VAR non-zero means member is a variable or type. SC
865 specifies the type of member (instance member, static, ...). VIS
866 is the member's visibility (public, protected, private). FLAGS is
867 a bit set giving additional information about the member (see the
871 add_global_defn (name
, regexp
, pos
, hash
, var
, sc
, flags
)
882 /* Try to find out for which classes a function is a friend, and add
883 what we know about it to them. */
885 for (i
= 0; i
< TABLE_SIZE
; ++i
)
886 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
887 if (sym
!= global_symbols
&& sym
->friends
)
888 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
889 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
892 /* Add to global symbols. */
893 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
897 /* Add information for the global declaration of NAME.
898 REGEXP is a regexp matching the declaration, if non-null. POS is
899 the position in the source where the declaration is found. HASH is
900 a hash code for the parameter list of the member, if it's a
901 function. VAR non-zero means member is a variable or type. SC
902 specifies the type of member (instance member, static, ...). VIS
903 is the member's visibility (public, protected, private). FLAGS is
904 a bit set giving additional information about the member (see the
908 add_global_decl (name
, regexp
, pos
, hash
, var
, sc
, flags
)
916 /* Add declaration only if not already declared. Header files must
917 be processed before source files for this to have the right effect.
918 I do not want to handle implicit declarations at the moment. */
920 struct member
*found
;
922 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
924 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
926 /* Definition already seen => probably last declaration implicit.
927 Override. This means that declarations must always be added to
928 the symbol table before definitions. */
931 if (!global_symbols
->filename
932 || !FILENAME_EQ (global_symbols
->filename
, filename
))
933 m
->filename
= filename
;
941 info_cls
= global_symbols
;
947 /* Add a symbol for member NAME to class CLS.
948 VAR non-zero means it's a variable. SC specifies the kind of
949 member. HASH is a hash code for the parameter types of a function.
950 Value is a pointer to the member's structure. */
953 add_member (cls
, name
, var
, sc
, hash
)
960 struct member
*m
= (struct member
*) xmalloc (sizeof *m
+ strlen (name
));
961 struct member
**list
;
964 unsigned name_hash
= 0;
968 strcpy (m
->name
, name
);
969 m
->param_hash
= hash
;
976 m
->def_regexp
= NULL
;
977 m
->def_filename
= NULL
;
980 assert (cls
!= NULL
);
985 list
= &cls
->friends
;
993 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
997 list
= var
? &cls
->vars
: &cls
->fns
;
1001 for (s
= name
; *s
; ++s
)
1002 name_hash
= (name_hash
<< 1) ^ *s
;
1003 i
= name_hash
% TABLE_SIZE
;
1004 m
->anext
= member_table
[i
];
1005 member_table
[i
] = m
;
1008 /* Keep the member list sorted. It's cheaper to do it here than to
1009 sort them in Lisp. */
1010 for (prev
= NULL
, p
= *list
;
1011 p
&& strcmp (name
, p
->name
) > 0;
1012 prev
= p
, p
= p
->next
)
1024 /* Given the root R of a class tree, step through all subclasses
1025 recursively, marking functions as virtual that are declared virtual
1033 struct member
*m
, *m2
;
1035 for (p
= r
->subs
; p
; p
= p
->next
)
1037 for (m
= r
->fns
; m
; m
= m
->next
)
1038 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
1040 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
1041 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
1042 SET_FLAG (m2
->flags
, F_VIRTUAL
);
1045 mark_virtual (p
->sym
);
1050 /* For all roots of the class tree, mark functions as virtual that
1051 are virtual because of a virtual declaration in a base class. */
1054 mark_inherited_virtual ()
1059 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1060 for (r
= class_table
[i
]; r
; r
= r
->next
)
1061 if (r
->supers
== NULL
)
1066 /* Create and return a symbol for a namespace with name NAME. */
1069 make_namespace (name
)
1072 struct sym
*s
= (struct sym
*) xmalloc (sizeof *s
+ strlen (name
));
1073 bzero (s
, sizeof *s
);
1074 strcpy (s
->name
, name
);
1075 s
->next
= all_namespaces
;
1076 s
->namesp
= current_namespace
;
1082 /* Find the symbol for namespace NAME. If not found, add a new symbol
1083 for NAME to all_namespaces. */
1086 find_namespace (name
)
1091 for (p
= all_namespaces
; p
; p
= p
->next
)
1093 if (streq (p
->name
, name
))
1098 for (p2
= p
->namesp_aliases
; p2
; p2
= p2
->next
)
1099 if (streq (p2
->name
, name
))
1107 p
= make_namespace (name
);
1113 /* Register the name NEW_NAME as an alias for namespace OLD_NAME. */
1116 register_namespace_alias (new_name
, old_name
)
1117 char *new_name
, *old_name
;
1119 struct sym
*p
= find_namespace (old_name
);
1122 /* Is it already in the list of aliases? */
1123 for (al
= p
->namesp_aliases
; al
; al
= al
->next
)
1124 if (streq (new_name
, p
->name
))
1127 al
= (struct alias
*) xmalloc (sizeof *al
+ strlen (new_name
));
1128 strcpy (al
->name
, new_name
);
1129 al
->next
= p
->namesp_aliases
;
1130 p
->namesp_aliases
= al
;
1134 /* Enter namespace with name NAME. */
1137 enter_namespace (name
)
1140 struct sym
*p
= find_namespace (name
);
1142 if (namespace_sp
== namespace_stack_size
)
1144 int size
= max (10, 2 * namespace_stack_size
);
1145 namespace_stack
= (struct sym
**) xrealloc (namespace_stack
, size
);
1146 namespace_stack_size
= size
;
1149 namespace_stack
[namespace_sp
++] = current_namespace
;
1150 current_namespace
= p
;
1154 /* Leave the current namespace. */
1159 assert (namespace_sp
> 0);
1160 current_namespace
= namespace_stack
[--namespace_sp
];
1165 /***********************************************************************
1166 Writing the Output File
1167 ***********************************************************************/
1169 /* Write string S to the output file FP in a Lisp-readable form.
1170 If S is null, write out `()'. */
1172 #define PUTSTR(s, fp) \
1189 /* A dynamically allocated buffer for constructing a scope name. */
1192 int scope_buffer_size
;
1193 int scope_buffer_len
;
1196 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1199 ensure_scope_buffer_room (len
)
1202 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1204 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1205 scope_buffer
= (char *) xrealloc (new_size
);
1206 scope_buffer_size
= new_size
;
1211 /* Recursively add the scope names of symbol P and the scopes of its
1212 namespaces to scope_buffer. Value is a pointer to the complete
1213 scope name constructed. */
1222 sym_scope_1 (p
->namesp
);
1226 ensure_scope_buffer_room (3);
1227 strcat (scope_buffer
, "::");
1228 scope_buffer_len
+= 2;
1231 len
= strlen (p
->name
);
1232 ensure_scope_buffer_room (len
+ 1);
1233 strcat (scope_buffer
, p
->name
);
1234 scope_buffer_len
+= len
;
1236 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1238 ensure_scope_buffer_room (3);
1239 strcat (scope_buffer
, "<>");
1240 scope_buffer_len
+= 2;
1243 return scope_buffer
;
1247 /* Return the scope of symbol P in printed representation, i.e.
1248 as it would appear in a C*+ source file. */
1256 scope_buffer_size
= 1024;
1257 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1260 *scope_buffer
= '\0';
1261 scope_buffer_len
= 0;
1264 sym_scope_1 (p
->namesp
);
1266 return scope_buffer
;
1270 /* Dump the list of members M to file FP. Value is the length of the
1274 dump_members (fp
, m
)
1282 for (n
= 0; m
; m
= m
->next
, ++n
)
1284 fputs (MEMBER_STRUCT
, fp
);
1285 PUTSTR (m
->name
, fp
);
1286 PUTSTR (NULL
, fp
); /* FIXME? scope for globals */
1287 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1288 PUTSTR (m
->filename
, fp
);
1289 PUTSTR (m
->regexp
, fp
);
1290 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1291 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1293 PUTSTR (m
->def_filename
, fp
);
1294 PUTSTR (m
->def_regexp
, fp
);
1295 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1306 /* Dump class ROOT to stream FP. */
1313 fputs (CLASS_STRUCT
, fp
);
1314 PUTSTR (root
->name
, fp
);
1316 /* Print scope, if any. */
1318 PUTSTR (sym_scope (root
), fp
);
1323 fprintf (fp
, "%u", root
->flags
);
1324 PUTSTR (root
->filename
, fp
);
1325 PUTSTR (root
->regexp
, fp
);
1326 fprintf (fp
, "%u", (unsigned) root
->pos
);
1327 PUTSTR (root
->sfilename
, fp
);
1333 /* Dump class ROOT and its subclasses to file FP. Value is the
1334 number of classes written. */
1337 dump_tree (fp
, root
)
1344 dump_sym (fp
, root
);
1354 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1356 fputs (TREE_STRUCT
, fp
);
1357 n
+= dump_tree (fp
, lk
->sym
);
1363 dump_members (fp
, root
->vars
);
1364 n
+= dump_members (fp
, root
->fns
);
1365 dump_members (fp
, root
->static_vars
);
1366 n
+= dump_members (fp
, root
->static_fns
);
1367 n
+= dump_members (fp
, root
->friends
);
1368 dump_members (fp
, root
->types
);
1383 /* Dump the entire class tree to file FP. */
1392 /* Output file header containing version string, command line
1396 fputs (TREE_HEADER_STRUCT
, fp
);
1397 PUTSTR (EBROWSE_FILE_VERSION
, fp
);
1410 /* Mark functions as virtual that are so because of functions
1411 declared virtual in base classes. */
1412 mark_inherited_virtual ();
1414 /* Dump the roots of the graph. */
1415 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1416 for (r
= class_table
[i
]; r
; r
= r
->next
)
1419 fputs (TREE_STRUCT
, fp
);
1420 n
+= dump_tree (fp
, r
);
1430 /***********************************************************************
1432 ***********************************************************************/
1435 #define INCREMENT_LINENO \
1437 if (f_very_verbose) \
1440 printf ("%d:\n", yyline); \
1446 #define INCREMENT_LINENO ++yyline
1449 /* Define two macros for accessing the input buffer (current input
1450 file). GET(C) sets C to the next input character and advances the
1451 input pointer. UNGET retracts the input pointer. */
1453 #define GET(C) ((C) = *in++)
1454 #define UNGET() (--in)
1457 /* Process a preprocessor line. Value is the next character from the
1458 input buffer not consumed. */
1463 int in_comment
= 0, in_string
= 0;
1467 /* Skip over white space. The `#' has been consumed already. */
1468 while (WHITEP (GET (c
)))
1471 /* Read the preprocessor command (if any). */
1478 /* Is it a `define'? */
1481 if (*yytext
&& streq (yytext
, "define"))
1496 char *regexp
= matching_regexp ();
1497 int pos
= BUFFER_POS ();
1498 add_define (yytext
, regexp
, pos
);
1502 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1506 else if (c
== '/' && !in_comment
)
1511 else if (c
== '*' && in_comment
)
1517 in_string
= !in_string
;
1529 /* Value is the next token from the input buffer. */
1540 while (WHITEP (GET (c
)))
1562 /* String and character constants. */
1565 while (GET (c
) && c
!= end_char
)
1570 /* Escape sequences. */
1573 if (end_char
== '\'')
1574 yyerror ("EOF in character constant");
1576 yyerror ("EOF in string constant");
1594 /* Hexadecimal escape sequence. */
1596 for (i
= 0; i
< 2; ++i
)
1600 if (c
>= '0' && c
<= '7')
1602 else if (c
>= 'a' && c
<= 'f')
1604 else if (c
>= 'A' && c
<= 'F')
1617 /* Octal escape sequence. */
1619 for (i
= 0; i
< 3; ++i
)
1623 if (c
>= '0' && c
<= '7')
1640 if (end_char
== '\'')
1641 yyerror ("newline in character constant");
1643 yyerror ("newline in string constant");
1653 return end_char
== '\'' ? CCHAR
: CSTRING
;
1655 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1656 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1657 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1658 case 'v': case 'w': case 'x': case 'y': case 'z':
1659 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1660 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1661 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1662 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1664 /* Identifier and keywords. */
1671 while (IDENTP (GET (*p
)))
1673 hash
= (hash
<< 1) ^ *p
++;
1674 if (p
== yytext_end
- 1)
1676 int size
= yytext_end
- yytext
;
1677 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1678 yytext_end
= yytext
+ 2 * size
;
1679 p
= yytext
+ size
- 1;
1686 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1687 if (streq (k
->name
, yytext
))
1694 /* C and C++ comments, '/' and '/='. */
1722 while (GET (c
) && c
!= '\n')
1797 yyerror ("invalid token '..' ('...' assumed)");
1801 else if (!DIGITP (c
))
1855 c
= process_pp_line ();
1860 case '(': case ')': case '[': case ']': case '{': case '}':
1861 case ';': case ',': case '?': case '~':
1867 if (GET (c
) == 'x' || c
== 'X')
1872 yyival
= yyival
* 16 + c
- '0';
1873 else if (c
>= 'a' && c
<= 'f')
1874 yyival
= yyival
* 16 + c
- 'a' + 10;
1875 else if (c
>= 'A' && c
<= 'F')
1876 yyival
= yyival
* 16 + c
- 'A' + 10;
1886 while (c
>= '0' && c
<= '7')
1888 yyival
= (yyival
<< 3) + c
- '0';
1893 /* Integer suffixes. */
1899 case '1': case '2': case '3': case '4': case '5': case '6':
1900 case '7': case '8': case '9':
1901 /* Integer or floating constant, part before '.'. */
1904 while (GET (c
) && DIGITP (c
))
1905 yyival
= 10 * yyival
+ c
- '0';
1911 /* Digits following '.'. */
1915 /* Optional exponent. */
1916 if (c
== 'E' || c
== 'e')
1918 if (GET (c
) == '-' || c
== '+')
1925 /* Optional type suffixes. */
1938 /* Value is the string from the start of the line to the current
1939 position in the input buffer, or maybe a bit more if that string is
1940 shorter than min_regexp. */
1948 static char *buffer
, *end_buf
;
1955 buffer
= (char *) xmalloc (max_regexp
);
1956 end_buf
= &buffer
[max_regexp
] - 1;
1959 /* Scan back to previous newline of buffer start. */
1960 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1965 while (in
- p
< min_regexp
&& p
> inbuffer
)
1967 /* Line probably not significant enough */
1968 for (--p
; p
>= inbuffer
&& *p
!= '\n'; --p
)
1975 /* Copy from end to make sure significant portions are included.
1976 This implies that in the browser a regular expressing of the form
1977 `^.*{regexp}' has to be used. */
1978 for (s
= end_buf
- 1, t
= in
; s
> buffer
&& t
> p
;)
1986 *(end_buf
- 1) = '\0';
1991 /* Return a printable representation of token T. */
2001 case CSTRING
: return "string constant";
2002 case CCHAR
: return "char constant";
2003 case CINT
: return "int constant";
2004 case CFLOAT
: return "floating constant";
2005 case ELLIPSIS
: return "...";
2006 case LSHIFTASGN
: return "<<=";
2007 case RSHIFTASGN
: return ">>=";
2008 case ARROWSTAR
: return "->*";
2009 case IDENT
: return "identifier";
2010 case DIVASGN
: return "/=";
2011 case INC
: return "++";
2012 case ADDASGN
: return "+=";
2013 case DEC
: return "--";
2014 case ARROW
: return "->";
2015 case SUBASGN
: return "-=";
2016 case MULASGN
: return "*=";
2017 case MODASGN
: return "%=";
2018 case LOR
: return "||";
2019 case ORASGN
: return "|=";
2020 case LAND
: return "&&";
2021 case ANDASGN
: return "&=";
2022 case XORASGN
: return "^=";
2023 case POINTSTAR
: return ".*";
2024 case DCOLON
: return "::";
2025 case EQ
: return "==";
2026 case NE
: return "!=";
2027 case LE
: return "<=";
2028 case LSHIFT
: return "<<";
2029 case GE
: return ">=";
2030 case RSHIFT
: return ">>";
2031 case ASM
: return "asm";
2032 case AUTO
: return "auto";
2033 case BREAK
: return "break";
2034 case CASE
: return "case";
2035 case CATCH
: return "catch";
2036 case CHAR
: return "char";
2037 case CLASS
: return "class";
2038 case CONST
: return "const";
2039 case CONTINUE
: return "continue";
2040 case DEFAULT
: return "default";
2041 case DELETE
: return "delete";
2042 case DO
: return "do";
2043 case DOUBLE
: return "double";
2044 case ELSE
: return "else";
2045 case ENUM
: return "enum";
2046 case EXTERN
: return "extern";
2047 case FLOAT
: return "float";
2048 case FOR
: return "for";
2049 case FRIEND
: return "friend";
2050 case GOTO
: return "goto";
2051 case IF
: return "if";
2052 case T_INLINE
: return "inline";
2053 case INT
: return "int";
2054 case LONG
: return "long";
2055 case NEW
: return "new";
2056 case OPERATOR
: return "operator";
2057 case PRIVATE
: return "private";
2058 case PROTECTED
: return "protected";
2059 case PUBLIC
: return "public";
2060 case REGISTER
: return "register";
2061 case RETURN
: return "return";
2062 case SHORT
: return "short";
2063 case SIGNED
: return "signed";
2064 case SIZEOF
: return "sizeof";
2065 case STATIC
: return "static";
2066 case STRUCT
: return "struct";
2067 case SWITCH
: return "switch";
2068 case TEMPLATE
: return "template";
2069 case THIS
: return "this";
2070 case THROW
: return "throw";
2071 case TRY
: return "try";
2072 case TYPEDEF
: return "typedef";
2073 case UNION
: return "union";
2074 case UNSIGNED
: return "unsigned";
2075 case VIRTUAL
: return "virtual";
2076 case VOID
: return "void";
2077 case VOLATILE
: return "volatile";
2078 case WHILE
: return "while";
2079 case MUTABLE
: return "mutable";
2080 case BOOL
: return "bool";
2081 case TRUE
: return "true";
2082 case FALSE
: return "false";
2083 case SIGNATURE
: return "signature";
2084 case NAMESPACE
: return "namespace";
2085 case EXPLICIT
: return "explicit";
2086 case TYPENAME
: return "typename";
2087 case CONST_CAST
: return "const_cast";
2088 case DYNAMIC_CAST
: return "dynamic_cast";
2089 case REINTERPRET_CAST
: return "reinterpret_cast";
2090 case STATIC_CAST
: return "static_cast";
2091 case TYPEID
: return "typeid";
2092 case USING
: return "using";
2093 case WCHAR
: return "wchar_t";
2094 case YYEOF
: return "EOF";
2109 /* Reinitialize the scanner for a new input file. */
2120 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2121 yytext_end
= yytext
+ size
;
2126 /* Insert a keyword NAME with token value TK into the keyword hash
2130 insert_keyword (name
, tk
)
2136 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2138 for (s
= name
; *s
; ++s
)
2141 h
%= KEYWORD_TABLE_SIZE
;
2144 k
->next
= keyword_table
[h
];
2145 keyword_table
[h
] = k
;
2149 /* Initialize the scanner for the first file. This sets up the
2150 character class vectors and fills the keyword hash table. */
2157 /* Allocate the input buffer */
2158 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2159 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2162 /* Set up character class vectors. */
2163 for (i
= 0; i
< sizeof is_ident
; ++i
)
2165 if (i
== '_' || isalnum (i
))
2168 if (i
>= '0' && i
<= '9')
2171 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2175 /* Fill keyword hash table. */
2176 insert_keyword ("and", LAND
);
2177 insert_keyword ("and_eq", ANDASGN
);
2178 insert_keyword ("asm", ASM
);
2179 insert_keyword ("auto", AUTO
);
2180 insert_keyword ("bitand", '&');
2181 insert_keyword ("bitor", '|');
2182 insert_keyword ("bool", BOOL
);
2183 insert_keyword ("break", BREAK
);
2184 insert_keyword ("case", CASE
);
2185 insert_keyword ("catch", CATCH
);
2186 insert_keyword ("char", CHAR
);
2187 insert_keyword ("class", CLASS
);
2188 insert_keyword ("compl", '~');
2189 insert_keyword ("const", CONST
);
2190 insert_keyword ("const_cast", CONST_CAST
);
2191 insert_keyword ("continue", CONTINUE
);
2192 insert_keyword ("default", DEFAULT
);
2193 insert_keyword ("delete", DELETE
);
2194 insert_keyword ("do", DO
);
2195 insert_keyword ("double", DOUBLE
);
2196 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2197 insert_keyword ("else", ELSE
);
2198 insert_keyword ("enum", ENUM
);
2199 insert_keyword ("explicit", EXPLICIT
);
2200 insert_keyword ("extern", EXTERN
);
2201 insert_keyword ("false", FALSE
);
2202 insert_keyword ("float", FLOAT
);
2203 insert_keyword ("for", FOR
);
2204 insert_keyword ("friend", FRIEND
);
2205 insert_keyword ("goto", GOTO
);
2206 insert_keyword ("if", IF
);
2207 insert_keyword ("inline", T_INLINE
);
2208 insert_keyword ("int", INT
);
2209 insert_keyword ("long", LONG
);
2210 insert_keyword ("mutable", MUTABLE
);
2211 insert_keyword ("namespace", NAMESPACE
);
2212 insert_keyword ("new", NEW
);
2213 insert_keyword ("not", '!');
2214 insert_keyword ("not_eq", NE
);
2215 insert_keyword ("operator", OPERATOR
);
2216 insert_keyword ("or", LOR
);
2217 insert_keyword ("or_eq", ORASGN
);
2218 insert_keyword ("private", PRIVATE
);
2219 insert_keyword ("protected", PROTECTED
);
2220 insert_keyword ("public", PUBLIC
);
2221 insert_keyword ("register", REGISTER
);
2222 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2223 insert_keyword ("return", RETURN
);
2224 insert_keyword ("short", SHORT
);
2225 insert_keyword ("signed", SIGNED
);
2226 insert_keyword ("sizeof", SIZEOF
);
2227 insert_keyword ("static", STATIC
);
2228 insert_keyword ("static_cast", STATIC_CAST
);
2229 insert_keyword ("struct", STRUCT
);
2230 insert_keyword ("switch", SWITCH
);
2231 insert_keyword ("template", TEMPLATE
);
2232 insert_keyword ("this", THIS
);
2233 insert_keyword ("throw", THROW
);
2234 insert_keyword ("true", TRUE
);
2235 insert_keyword ("try", TRY
);
2236 insert_keyword ("typedef", TYPEDEF
);
2237 insert_keyword ("typeid", TYPEID
);
2238 insert_keyword ("typename", TYPENAME
);
2239 insert_keyword ("union", UNION
);
2240 insert_keyword ("unsigned", UNSIGNED
);
2241 insert_keyword ("using", USING
);
2242 insert_keyword ("virtual", VIRTUAL
);
2243 insert_keyword ("void", VOID
);
2244 insert_keyword ("volatile", VOLATILE
);
2245 insert_keyword ("wchar_t", WCHAR
);
2246 insert_keyword ("while", WHILE
);
2247 insert_keyword ("xor", '^');
2248 insert_keyword ("xor_eq", XORASGN
);
2253 /***********************************************************************
2255 ***********************************************************************/
2257 /* Match the current lookahead token and set it to the next token. */
2259 #define MATCH() (tk = yylex ())
2261 /* Return the lookahead token. If current lookahead token is cleared,
2262 read a new token. */
2264 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2266 /* Is the current lookahead equal to the token T? */
2268 #define LOOKING_AT(T) (tk == (T))
2270 /* Is the current lookahead one of T1 or T2? */
2272 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2274 /* Is the current lookahead one of T1, T2 or T3? */
2276 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2278 /* Is the current lookahead one of T1...T4? */
2280 #define LOOKING_AT4(T1, T2, T3, T4) \
2281 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2283 /* Match token T if current lookahead is T. */
2285 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2287 /* Skip to matching token if current token is T. */
2289 #define SKIP_MATCHING_IF(T) \
2290 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2293 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2294 the current lookahead token after skipping. */
2300 while (!LOOKING_AT2 (YYEOF
, token
))
2306 /* Skip over pairs of tokens (parentheses, square brackets,
2307 angle brackets, curly brackets) matching the current lookahead. */
2338 if (LOOKING_AT (open
))
2340 else if (LOOKING_AT (close
))
2342 else if (LOOKING_AT (YYEOF
))
2353 /* Re-initialize the parser by resetting the lookahead token. */
2362 /* Parse a parameter list, including the const-specifier,
2363 pure-specifier, and throw-list that may follow a parameter list.
2364 Return in FLAGS what was seen following the parameter list.
2365 Returns a hash code for the parameter types. This value is used to
2366 distinguish between overloaded functions. */
2375 while (!LOOKING_AT2 (YYEOF
, ')'))
2379 /* Skip over grouping parens or parameter lists in parameter
2385 /* Next parameter. */
2391 /* Ignore the scope part of types, if any. This is because
2392 some types need scopes when defined outside of a class body,
2393 and don't need them inside the class body. This means that
2394 we have to look for the last IDENT in a sequence of
2395 IDENT::IDENT::... */
2400 unsigned ident_type_hash
= 0;
2402 parse_qualified_param_ident_or_type (&last_id
);
2405 /* LAST_ID null means something like `X::*'. */
2406 for (; *last_id
; ++last_id
)
2407 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2408 hash
= (hash
<< 1) ^ ident_type_hash
;
2417 /* This distinction is made to make `func (void)' equivalent
2421 if (!LOOKING_AT (')'))
2422 hash
= (hash
<< 1) ^ VOID
;
2425 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2426 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2427 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2428 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2431 hash
= (hash
<< 1) ^ LA1
;
2435 case '*': case '&': case '[': case ']':
2436 hash
= (hash
<< 1) ^ LA1
;
2446 if (LOOKING_AT (')'))
2450 if (LOOKING_AT (CONST
))
2452 /* We can overload the same function on `const' */
2453 hash
= (hash
<< 1) ^ CONST
;
2454 SET_FLAG (*flags
, F_CONST
);
2458 if (LOOKING_AT (THROW
))
2461 SKIP_MATCHING_IF ('(');
2462 SET_FLAG (*flags
, F_THROW
);
2465 if (LOOKING_AT ('='))
2468 if (LOOKING_AT (CINT
) && yyival
== 0)
2471 SET_FLAG (*flags
, F_PURE
);
2480 /* Print position info to stdout. */
2485 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2487 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2488 info_cls
->name
, sym_scope (info_cls
),
2489 info_member
->name
, info_where
);
2493 /* Parse a member declaration within the class body of CLS. VIS is
2494 the access specifier for the member (private, protected,
2504 char *regexp
= NULL
;
2515 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2523 /* A function or class may follow. */
2526 SET_FLAG (flags
, F_TEMPLATE
);
2527 /* Skip over template argument list */
2528 SKIP_MATCHING_IF ('<');
2532 SET_FLAG (flags
, F_EXPLICIT
);
2536 SET_FLAG (flags
, F_MUTABLE
);
2540 SET_FLAG (flags
, F_INLINE
);
2544 SET_FLAG (flags
, F_VIRTUAL
);
2573 /* Remember IDENTS seen so far. Among these will be the member
2575 id
= (char *) alloca (strlen (yytext
) + 2);
2579 strcpy (id
+ 1, yytext
);
2582 strcpy (id
, yytext
);
2587 id
= operator_name (&sc
);
2591 /* Most probably the beginning of a parameter list. */
2597 if (!(is_constructor
= streq (id
, cls
->name
)))
2598 regexp
= matching_regexp ();
2603 pos
= BUFFER_POS ();
2604 hash
= parm_list (&flags
);
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
))
2615 if (LOOKING_AT ('{') && id
&& cls
)
2616 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2622 case STRUCT
: case UNION
: case CLASS
:
2629 /* More than one ident here to allow for MS-DOS specialties
2630 like `_export class' etc. The last IDENT seen counts
2631 as the class name. */
2632 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2634 if (LOOKING_AT (IDENT
))
2639 if (LOOKING_AT2 (':', '{'))
2640 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2645 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2646 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2647 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2656 if (LOOKING_AT (';'))
2658 /* The end of a member variable, a friend declaration or an access
2659 declaration. We don't want to add friend classes as members. */
2660 if (id
&& sc
!= SC_FRIEND
&& cls
)
2662 regexp
= matching_regexp ();
2663 pos
= BUFFER_POS ();
2667 if (type_seen
|| !paren_seen
)
2668 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2670 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2677 else if (LOOKING_AT ('{'))
2680 if (sc
== SC_TYPE
&& id
&& cls
)
2682 regexp
= matching_regexp ();
2683 pos
= BUFFER_POS ();
2687 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2688 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2698 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2702 class_body (cls
, tag
)
2706 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2709 while (!LOOKING_AT2 (YYEOF
, '}'))
2713 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2717 if (LOOKING_AT (':'))
2724 /* Probably conditional compilation for inheritance list.
2725 We don't known whether there comes more of this.
2726 This is only a crude fix that works most of the time. */
2731 while (LOOKING_AT2 (IDENT
, ',')
2732 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2741 /* Try to synchronize */
2742 case CHAR
: case CLASS
: case CONST
:
2743 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2744 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2745 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2746 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2747 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2748 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2760 /* Parse a qualified identifier. Current lookahead is IDENT. A
2761 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2762 symbol for that class. */
2767 struct sym
*last_class
= NULL
;
2769 while (LOOKING_AT (IDENT
))
2771 last_class
= add_sym (yytext
, last_class
);
2774 if (LOOKING_AT ('<'))
2777 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2780 if (!LOOKING_AT (DCOLON
))
2790 /* Parse an operator name. Add the `static' flag to *SC if an
2791 implicitly static operator has been parsed. Value is a pointer to
2792 a static buffer holding the constructed operator name string. */
2798 static int id_size
= 0;
2799 static char *id
= NULL
;
2805 if (LOOKING_AT2 (NEW
, DELETE
))
2807 /* `new' and `delete' are implicitly static. */
2808 if (*sc
!= SC_FRIEND
)
2811 s
= token_string (LA1
);
2814 len
= strlen (s
) + 10;
2817 int new_size
= max (len
, 2 * id_size
);
2818 id
= (char *) xrealloc (id
, new_size
);
2823 /* Vector new or delete? */
2824 if (LOOKING_AT ('['))
2829 if (LOOKING_AT (']'))
2838 int tokens_matched
= 0;
2843 int new_size
= max (len
, 2 * id_size
);
2844 id
= (char *) xrealloc (id
, new_size
);
2847 strcpy (id
, "operator");
2849 /* Beware access declarations of the form "X::f;" Beware of
2850 `operator () ()'. Yet another difficulty is found in
2851 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2852 while (!(LOOKING_AT ('(') && tokens_matched
)
2853 && !LOOKING_AT2 (';', YYEOF
))
2855 s
= token_string (LA1
);
2856 len
+= strlen (s
) + 2;
2859 int new_size
= max (len
, 2 * id_size
);
2860 id
= (char *) xrealloc (id
, new_size
);
2864 if (*s
!= ')' && *s
!= ']')
2869 /* If this is a simple operator like `+', stop now. */
2870 if (!isalpha (*s
) && *s
!= '(' && *s
!= '[')
2881 /* This one consumes the last IDENT of a qualified member name like
2882 `X::Y::z'. This IDENT is returned in LAST_ID. Value if the
2883 symbol structure for the ident. */
2886 parse_qualified_ident_or_type (last_id
)
2889 struct sym
*cls
= NULL
;
2890 static char *id
= NULL
;
2891 static int id_size
= 0;
2893 while (LOOKING_AT (IDENT
))
2895 int len
= strlen (yytext
) + 1;
2898 id
= (char *) xrealloc (id
, len
);
2901 strcpy (id
, yytext
);
2905 SKIP_MATCHING_IF ('<');
2907 if (LOOKING_AT (DCOLON
))
2909 cls
= add_sym (id
, cls
);
2921 /* This one consumes the last IDENT of a qualified member name like
2922 `X::Y::z'. This IDENT is returned in LAST_ID. Value if the
2923 symbol structure for the ident. */
2926 parse_qualified_param_ident_or_type (last_id
)
2929 struct sym
*cls
= NULL
;
2930 static char *id
= NULL
;
2931 static int id_size
= 0;
2933 while (LOOKING_AT (IDENT
))
2935 int len
= strlen (yytext
) + 1;
2938 id
= (char *) xrealloc (id
, len
);
2941 strcpy (id
, yytext
);
2945 SKIP_MATCHING_IF ('<');
2947 if (LOOKING_AT (DCOLON
))
2949 cls
= add_sym (id
, cls
);
2959 /* Parse a class definition.
2961 CONTAINING is the class containing the class being parsed or null.
2962 This may also be null if NESTED != 0 if the containing class is
2963 anonymous. TAG is the tag of the class (struct, union, class).
2964 NESTED is non-zero if we are parsing a nested class.
2966 Current lookahead is the class name. */
2969 class_definition (containing
, tag
, flags
, nested
)
2970 struct sym
*containing
;
2975 struct sym
*current
;
2976 struct sym
*base_class
;
2978 /* Set CURRENT to null if no entry has to be made for the class
2979 parsed. This is the case for certain command line flag
2981 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
2985 current
= add_sym (yytext
, containing
);
2986 current
->pos
= BUFFER_POS ();
2987 current
->regexp
= matching_regexp ();
2988 current
->filename
= filename
;
2989 current
->flags
= flags
;
2992 /* If at ':', base class list follows. */
2993 if (LOOKING_AT (':'))
3002 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3007 base_class
= parse_classname ();
3008 if (base_class
&& current
&& base_class
!= current
)
3009 add_link (base_class
, current
);
3012 /* The `,' between base classes or the end of the base
3013 class list. Add the previously found base class.
3014 It's done this way to skip over sequences of
3015 `A::B::C' until we reach the end.
3017 FIXME: it is now possible to handle `class X : public B::X'
3018 because we have enough information. */
3024 /* A syntax error, possibly due to preprocessor constructs
3030 class A : private B.
3032 MATCH until we see something like `;' or `{'. */
3033 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3044 /* Parse the class body if there is one. */
3045 if (LOOKING_AT ('{'))
3047 if (tag
!= CLASS
&& !f_structs
)
3052 class_body (current
, tag
);
3054 if (LOOKING_AT ('}'))
3057 if (LOOKING_AT (';') && !nested
)
3065 /* Parse a declaration. */
3072 struct sym
*cls
= NULL
;
3073 char *regexp
= NULL
;
3079 while (!LOOKING_AT3 (';', '{', YYEOF
))
3102 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3103 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3104 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3108 case CLASS
: case STRUCT
: case UNION
:
3109 /* This is for the case `STARTWRAP class X : ...' or
3110 `declare (X, Y)\n class A : ...'. */
3115 /* Assumed to be the start of an initialization in this context.
3116 Skip over everything up to ';'. */
3121 id
= operator_name (&sc
);
3125 SET_FLAG (flags
, F_INLINE
);
3131 if (LOOKING_AT (IDENT
))
3133 id
= (char *) alloca (strlen (yytext
) + 2);
3135 strcpy (id
+ 1, yytext
);
3141 cls
= parse_qualified_ident_or_type (&id
);
3145 /* Most probably the beginning of a parameter list. */
3152 if (!(is_constructor
= streq (id
, cls
->name
)))
3153 regexp
= matching_regexp ();
3158 pos
= BUFFER_POS ();
3159 hash
= parm_list (&flags
);
3162 regexp
= matching_regexp ();
3165 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3170 /* This may be a C functions, but also a macro
3171 call of the form `declare (A, B)' --- such macros
3172 can be found in some class libraries. */
3177 regexp
= matching_regexp ();
3178 pos
= BUFFER_POS ();
3179 hash
= parm_list (&flags
);
3180 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3183 /* This is for the case that the function really is
3184 a macro with no `;' following it. If a CLASS directly
3185 follows, we would miss it otherwise. */
3186 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3190 while (!LOOKING_AT3 (';', '{', YYEOF
))
3193 if (!cls
&& id
&& LOOKING_AT ('{'))
3194 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3200 if (LOOKING_AT (';'))
3202 /* The end of a member variable or of an access declaration
3203 `X::f'. To distinguish between them we have to know whether
3204 type information has been seen. */
3207 char *regexp
= matching_regexp ();
3208 int pos
= BUFFER_POS ();
3211 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3213 add_global_defn (id
, regexp
, pos
, 0, 1, sc
, flags
);
3219 else if (LOOKING_AT ('{'))
3221 if (sc
== SC_TYPE
&& id
)
3223 /* A named enumeration. */
3224 regexp
= matching_regexp ();
3225 pos
= BUFFER_POS ();
3226 add_global_defn (id
, regexp
, pos
, 0, 1, sc
, flags
);
3235 /* Parse a list of top-level declarations/definitions. START_FLAGS
3236 says in which context we are parsing. If it is F_EXTERNC, we are
3237 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3241 globals (start_flags
)
3246 int flags
= start_flags
;
3258 if (LOOKING_AT (IDENT
))
3260 char *namespace_name
3261 = (char *) alloca (strlen (yytext
) + 1);
3262 strcpy (namespace_name
, yytext
);
3265 if (LOOKING_AT ('='))
3267 if (skip_to (';') == ';')
3269 register_namespace_alias (namespace_name
, yytext
);
3271 else if (LOOKING_AT ('{'))
3274 enter_namespace (namespace_name
);
3285 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3286 && *(string_start
+ 1) == '"')
3288 /* This is `extern "C"'. */
3291 if (LOOKING_AT ('{'))
3294 globals (F_EXTERNC
);
3298 SET_FLAG (flags
, F_EXTERNC
);
3304 SKIP_MATCHING_IF ('<');
3305 SET_FLAG (flags
, F_TEMPLATE
);
3308 case CLASS
: case STRUCT
: case UNION
:
3313 /* More than one ident here to allow for MS-DOS and OS/2
3314 specialties like `far', `_Export' etc. Some C++ libs
3315 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3316 of the class name. */
3317 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3319 if (LOOKING_AT (IDENT
))
3324 /* Don't add anonymous unions. */
3325 if (LOOKING_AT2 (':', '{') && !anonymous
)
3326 class_definition (NULL
, class_tk
, flags
, 0);
3329 if (skip_to (';') == ';')
3333 flags
= start_flags
;
3343 declaration (flags
);
3344 flags
= start_flags
;
3349 yyerror ("parse error");
3354 /* Parse the current input file. */
3359 while (globals (0) == 0)
3365 /***********************************************************************
3367 ***********************************************************************/
3369 /* Add the list of paths PATH_LIST to the current search path for
3373 add_search_path (path_list
)
3378 char *start
= path_list
;
3379 struct search_path
*p
;
3381 while (*path_list
&& *path_list
!= PATH_LIST_SEPARATOR
)
3384 p
= (struct search_path
*) xmalloc (sizeof *p
);
3385 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3386 memcpy (p
->path
, start
, path_list
- start
);
3387 p
->path
[path_list
- start
] = '\0';
3390 if (search_path_tail
)
3392 search_path_tail
->next
= p
;
3393 search_path_tail
= p
;
3396 search_path
= search_path_tail
= p
;
3398 while (*path_list
== PATH_LIST_SEPARATOR
)
3404 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3405 opened. Try to find FILE in search_path first, then try the
3406 unchanged file name. */
3413 static char *buffer
;
3414 static int buffer_size
;
3415 struct search_path
*path
;
3416 int flen
= strlen (file
) + 1; /* +1 for the slash */
3418 filename
= xstrdup (file
);
3420 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3422 int len
= strlen (path
->path
) + flen
;
3424 if (len
+ 1 >= buffer_size
)
3426 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3427 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3430 strcpy (buffer
, path
->path
);
3431 strcat (buffer
, "/");
3432 strcat (buffer
, file
);
3433 fp
= fopen (buffer
, "r");
3436 /* Try the original file name. */
3438 fp
= fopen (file
, "r");
3441 yyerror ("cannot open");
3447 /* Display usage information and exit program. */
3450 Usage: ebrowse [options] {files}\n\
3452 -a, --append append output\n\
3453 -f, --files=FILES read input file names from FILE\n\
3454 -I, --search-path=LIST set search path for input files\n\
3455 -m, --min-regexp-length=N set minimum regexp length to N\n\
3456 -M, --max-regexp-length=N set maximum regexp length to N\n\
3457 -n, --no-nested-classes exclude nested classes\n\
3458 -o, --output-file=FILE set output file name to FILE\n\
3459 -p, --position-info print info about position in file\n\
3460 -s, --no-structs-or-unions don't record structs or unions\n\
3461 -v, --verbose be verbose\n\
3462 -V, --very-verbose be very verbose\n\
3463 -x, --no-regexps don't record regular expressions\n\
3464 --help display this help\n\
3465 --version display version info\n\
3473 exit (error
? 1 : 0);
3477 /* Display version and copyright info. The VERSION macro is set
3478 from the Makefile and contains the Emacs version. */
3483 printf ("ebrowse %s\n", VERSION
);
3484 puts ("Copyright (C) 1992-1999, 2000 Free Software Foundation, Inc.");
3485 puts ("This program is distributed under the same terms as Emacs.");
3490 /* Parse one input file FILE, adding classes and members to the symbol
3499 fp
= open_file (file
);
3504 /* Give a progress indication if needed. */
3516 /* Read file to inbuffer. */
3519 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3521 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3522 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3525 nbytes
= fread (inbuffer
+ nread
, 1, READ_CHUNK_SIZE
, fp
);
3532 inbuffer
[nread
] = '\0';
3534 /* Reinitialize scanner and parser for the new input file. */
3538 /* Parse it and close the file. */
3545 /* Read a line from stream FP and return a pointer to a static buffer
3546 containing its contents without the terminating newline. Value
3547 is null when EOF is reached. */
3553 static char *buffer
;
3554 static int buffer_size
;
3557 while ((c
= getc (fp
)) != EOF
&& c
!= '\n')
3559 if (i
>= buffer_size
)
3561 buffer_size
= max (100, buffer_size
* 2);
3562 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3568 if (c
== EOF
&& i
== 0)
3571 if (i
== buffer_size
)
3573 buffer_size
= max (100, buffer_size
* 2);
3574 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3582 /* Main entry point. */
3590 int any_inputfiles
= 0;
3591 static char *out_filename
= DEFAULT_OUTFILE
;
3592 static char **input_filenames
= NULL
;
3593 static int input_filenames_size
= 0;
3594 static int n_input_files
;
3596 filename
= "command line";
3599 while ((i
= getopt_long (argc
, argv
, "af:I:m:M:no:p:svVx",
3600 options
, NULL
)) != EOF
)
3606 info_position
= atoi (optarg
);
3610 f_nested_classes
= 0;
3617 /* Add the name of a file containing more input files. */
3619 if (n_input_files
== input_filenames_size
)
3621 input_filenames_size
= max (10, 2 * input_filenames_size
);
3622 input_filenames
= (char **) xrealloc (input_filenames
,
3623 input_filenames_size
);
3625 input_filenames
[n_input_files
++] = xstrdup (optarg
);
3628 /* Append new output to output file instead of truncating it. */
3633 /* Include structs in the output */
3638 /* Be verbose (give a progress indication). */
3643 /* Be very verbose (print file names as they are processed). */
3649 /* Change the name of the output file. */
3651 out_filename
= optarg
;
3654 /* Set minimum length for regular expression strings
3655 when recorded in the output file. */
3657 min_regexp
= atoi (optarg
);
3660 /* Set maximum length for regular expression strings
3661 when recorded in the output file. */
3663 max_regexp
= atoi (optarg
);
3666 /* Add to search path. */
3668 add_search_path (optarg
);
3682 /* Call init_scanner after command line flags have been processed to be
3683 able to add keywords depending on command line (not yet
3688 /* Open output file */
3691 yyout
= fopen (out_filename
, f_append
? "a" : "w");
3694 yyerror ("cannot open output file `%s'", out_filename
);
3699 /* Process input files specified on the command line. */
3700 while (optind
< argc
)
3702 process_file (argv
[optind
++]);
3706 /* Process files given on stdin if no files specified. */
3707 if (!any_inputfiles
&& n_input_files
== 0)
3710 while ((file
= read_line (stdin
)) != NULL
)
3711 process_file (file
);
3715 /* Process files from `--files=FILE'. Every line in FILE names
3716 one input file to process. */
3717 for (i
= 0; i
< n_input_files
; ++i
)
3719 FILE *fp
= fopen (input_filenames
[i
], "r");
3722 yyerror ("cannot open input file `%s'", input_filenames
[i
]);
3726 while ((file
= read_line (fp
)) != NULL
)
3727 process_file (file
);
3733 /* Write output file. */
3736 /* Close output file. */
3737 if (yyout
!= stdout
)
3744 /* ebrowse.c ends here. */