6 |
|
|
7 |
Author: Gerd Moellmann <gerd@gnu.org> |
Author: Gerd Moellmann <gerd@gnu.org> |
8 |
Maintainer: FSF |
Maintainer: FSF |
9 |
|
|
10 |
This file is part of GNU Emacs. |
This file is part of GNU Emacs. |
11 |
|
|
12 |
GNU Emacs is free software; you can redistribute it and/or modify |
GNU Emacs is free software; you can redistribute it and/or modify |
28 |
#endif |
#endif |
29 |
|
|
30 |
#include <stdio.h> |
#include <stdio.h> |
31 |
|
|
32 |
|
#ifdef HAVE_STDLIB_H |
33 |
#include <stdlib.h> |
#include <stdlib.h> |
34 |
|
#endif |
35 |
|
|
36 |
|
#ifdef HAVE_STRING_H |
37 |
#include <string.h> |
#include <string.h> |
38 |
|
#endif |
39 |
|
|
40 |
#include <ctype.h> |
#include <ctype.h> |
41 |
#include <assert.h> |
#include <assert.h> |
42 |
#include "getopt.h" |
#include "getopt.h" |
407 |
|
|
408 |
#define BUFFER_POS() (in - inbuffer) |
#define BUFFER_POS() (in - inbuffer) |
409 |
|
|
410 |
/* If current lookahead is CSTRING, the following points to the |
/* If current lookahead is CSTRING, the following points to the |
411 |
first character in the string constant. Used for recognizing |
first character in the string constant. Used for recognizing |
412 |
extern "C". */ |
extern "C". */ |
413 |
|
|
693 |
{ |
{ |
694 |
lnk = (struct link *) xmalloc (sizeof *lnk); |
lnk = (struct link *) xmalloc (sizeof *lnk); |
695 |
lnk2 = (struct link *) xmalloc (sizeof *lnk2); |
lnk2 = (struct link *) xmalloc (sizeof *lnk2); |
696 |
|
|
697 |
lnk->sym = sub; |
lnk->sym = sub; |
698 |
lnk->next = p; |
lnk->next = p; |
699 |
|
|
735 |
case SC_FRIEND: |
case SC_FRIEND: |
736 |
list = &cls->friends; |
list = &cls->friends; |
737 |
break; |
break; |
738 |
|
|
739 |
case SC_TYPE: |
case SC_TYPE: |
740 |
list = &cls->types; |
list = &cls->types; |
741 |
break; |
break; |
742 |
|
|
743 |
case SC_STATIC: |
case SC_STATIC: |
744 |
list = var ? &cls->static_vars : &cls->static_fns; |
list = var ? &cls->static_vars : &cls->static_fns; |
745 |
break; |
break; |
746 |
|
|
747 |
default: |
default: |
748 |
list = var ? &cls->vars : &cls->fns; |
list = var ? &cls->vars : &cls->fns; |
749 |
break; |
break; |
935 |
a bit set giving additional information about the member (see the |
a bit set giving additional information about the member (see the |
936 |
F_* defines). */ |
F_* defines). */ |
937 |
|
|
938 |
void |
void |
939 |
add_global_decl (name, regexp, pos, hash, var, sc, flags) |
add_global_decl (name, regexp, pos, hash, var, sc, flags) |
940 |
char *name, *regexp; |
char *name, *regexp; |
941 |
int pos; |
int pos; |
1015 |
case SC_FRIEND: |
case SC_FRIEND: |
1016 |
list = &cls->friends; |
list = &cls->friends; |
1017 |
break; |
break; |
1018 |
|
|
1019 |
case SC_TYPE: |
case SC_TYPE: |
1020 |
list = &cls->types; |
list = &cls->types; |
1021 |
break; |
break; |
1022 |
|
|
1023 |
case SC_STATIC: |
case SC_STATIC: |
1024 |
list = var ? &cls->static_vars : &cls->static_fns; |
list = var ? &cls->static_vars : &cls->static_fns; |
1025 |
break; |
break; |
1026 |
|
|
1027 |
default: |
default: |
1028 |
list = var ? &cls->vars : &cls->fns; |
list = var ? &cls->vars : &cls->fns; |
1029 |
break; |
break; |
1119 |
struct sym *context; |
struct sym *context; |
1120 |
{ |
{ |
1121 |
struct sym *p = NULL; |
struct sym *p = NULL; |
1122 |
|
|
1123 |
for (p = all_namespaces; p; p = p->next) |
for (p = all_namespaces; p; p = p->next) |
1124 |
{ |
{ |
1125 |
if (streq (p->name, name) && (p->namesp == context)) |
if (streq (p->name, name) && (p->namesp == context)) |
1144 |
|
|
1145 |
return p; |
return p; |
1146 |
} |
} |
1147 |
|
|
1148 |
|
|
1149 |
/* Find namespace alias with name NAME. If not found return NULL. */ |
/* Find namespace alias with name NAME. If not found return NULL. */ |
1150 |
|
|
1217 |
size * sizeof *namespace_stack); |
size * sizeof *namespace_stack); |
1218 |
namespace_stack_size = size; |
namespace_stack_size = size; |
1219 |
} |
} |
1220 |
|
|
1221 |
namespace_stack[namespace_sp++] = current_namespace; |
namespace_stack[namespace_sp++] = current_namespace; |
1222 |
current_namespace = p; |
current_namespace = p; |
1223 |
} |
} |
1289 |
struct sym *p; |
struct sym *p; |
1290 |
{ |
{ |
1291 |
int len; |
int len; |
1292 |
|
|
1293 |
if (p->namesp) |
if (p->namesp) |
1294 |
sym_scope_1 (p->namesp); |
sym_scope_1 (p->namesp); |
1295 |
|
|
1304 |
ensure_scope_buffer_room (len + 1); |
ensure_scope_buffer_room (len + 1); |
1305 |
strcat (scope_buffer, p->name); |
strcat (scope_buffer, p->name); |
1306 |
scope_buffer_len += len; |
scope_buffer_len += len; |
1307 |
|
|
1308 |
if (HAS_FLAG (p->flags, F_TEMPLATE)) |
if (HAS_FLAG (p->flags, F_TEMPLATE)) |
1309 |
{ |
{ |
1310 |
ensure_scope_buffer_room (3); |
ensure_scope_buffer_room (3); |
1311 |
strcat (scope_buffer, "<>"); |
strcat (scope_buffer, "<>"); |
1312 |
scope_buffer_len += 2; |
scope_buffer_len += 2; |
1313 |
} |
} |
1314 |
|
|
1315 |
return scope_buffer; |
return scope_buffer; |
1316 |
} |
} |
1317 |
|
|
1328 |
scope_buffer_size = 1024; |
scope_buffer_size = 1024; |
1329 |
scope_buffer = (char *) xmalloc (scope_buffer_size); |
scope_buffer = (char *) xmalloc (scope_buffer_size); |
1330 |
} |
} |
1331 |
|
|
1332 |
*scope_buffer = '\0'; |
*scope_buffer = '\0'; |
1333 |
scope_buffer_len = 0; |
scope_buffer_len = 0; |
1334 |
|
|
1335 |
if (p->namesp) |
if (p->namesp) |
1336 |
sym_scope_1 (p->namesp); |
sym_scope_1 (p->namesp); |
1337 |
|
|
1384 |
{ |
{ |
1385 |
fputs (CLASS_STRUCT, fp); |
fputs (CLASS_STRUCT, fp); |
1386 |
PUTSTR (root->name, fp); |
PUTSTR (root->name, fp); |
1387 |
|
|
1388 |
/* Print scope, if any. */ |
/* Print scope, if any. */ |
1389 |
if (root->namesp) |
if (root->namesp) |
1390 |
PUTSTR (sym_scope (root), fp); |
PUTSTR (sym_scope (root), fp); |
1391 |
else |
else |
1392 |
PUTSTR (NULL, fp); |
PUTSTR (NULL, fp); |
1393 |
|
|
1394 |
/* Print flags. */ |
/* Print flags. */ |
1395 |
fprintf (fp, "%u", root->flags); |
fprintf (fp, "%u", root->flags); |
1396 |
PUTSTR (root->filename, fp); |
PUTSTR (root->filename, fp); |
1570 |
add_define (yytext, regexp, pos); |
add_define (yytext, regexp, pos); |
1571 |
} |
} |
1572 |
} |
} |
1573 |
|
|
1574 |
while (c && (c != '\n' || in_comment || in_string)) |
while (c && (c != '\n' || in_comment || in_string)) |
1575 |
{ |
{ |
1576 |
if (c == '\\') |
if (c == '\\') |
1587 |
} |
} |
1588 |
else if (c == '"') |
else if (c == '"') |
1589 |
in_string = !in_string; |
in_string = !in_string; |
1590 |
|
|
1591 |
if (c == '\n') |
if (c == '\n') |
1592 |
INCREMENT_LINENO; |
INCREMENT_LINENO; |
1593 |
|
|
2191 |
{ |
{ |
2192 |
in = inbuffer; |
in = inbuffer; |
2193 |
yyline = 1; |
yyline = 1; |
2194 |
|
|
2195 |
if (yytext == NULL) |
if (yytext == NULL) |
2196 |
{ |
{ |
2197 |
int size = 256; |
int size = 256; |
2393 |
case '{': |
case '{': |
2394 |
close = '}'; |
close = '}'; |
2395 |
break; |
break; |
2396 |
|
|
2397 |
case '(': |
case '(': |
2398 |
close = ')'; |
close = ')'; |
2399 |
break; |
break; |
2400 |
|
|
2401 |
case '<': |
case '<': |
2402 |
close = '>'; |
close = '>'; |
2403 |
break; |
break; |
2404 |
|
|
2405 |
case '[': |
case '[': |
2406 |
close = ']'; |
close = ']'; |
2407 |
break; |
break; |
2408 |
|
|
2409 |
default: |
default: |
2410 |
abort (); |
abort (); |
2411 |
} |
} |
2512 |
{ |
{ |
2513 |
char *last_id; |
char *last_id; |
2514 |
unsigned ident_type_hash = 0; |
unsigned ident_type_hash = 0; |
2515 |
|
|
2516 |
parse_qualified_param_ident_or_type (&last_id); |
parse_qualified_param_ident_or_type (&last_id); |
2517 |
if (last_id) |
if (last_id) |
2518 |
{ |
{ |
2540 |
case DOUBLE: case ENUM: case FLOAT: case INT: |
case DOUBLE: case ENUM: case FLOAT: case INT: |
2541 |
case LONG: case SHORT: case SIGNED: case STRUCT: |
case LONG: case SHORT: case SIGNED: case STRUCT: |
2542 |
case UNION: case UNSIGNED: case VOLATILE: case WCHAR: |
case UNION: case UNSIGNED: case VOLATILE: case WCHAR: |
2543 |
case ELLIPSIS: |
case ELLIPSIS: |
2544 |
type_seen = 1; |
type_seen = 1; |
2545 |
hash = (hash << 1) ^ LA1; |
hash = (hash << 1) ^ LA1; |
2546 |
MATCH (); |
MATCH (); |
2560 |
if (LOOKING_AT (')')) |
if (LOOKING_AT (')')) |
2561 |
{ |
{ |
2562 |
MATCH (); |
MATCH (); |
2563 |
|
|
2564 |
if (LOOKING_AT (CONST)) |
if (LOOKING_AT (CONST)) |
2565 |
{ |
{ |
2566 |
/* We can overload the same function on `const' */ |
/* We can overload the same function on `const' */ |
2645 |
case EXPLICIT: |
case EXPLICIT: |
2646 |
SET_FLAG (flags, F_EXPLICIT); |
SET_FLAG (flags, F_EXPLICIT); |
2647 |
goto typeseen; |
goto typeseen; |
2648 |
|
|
2649 |
case MUTABLE: |
case MUTABLE: |
2650 |
SET_FLAG (flags, F_MUTABLE); |
SET_FLAG (flags, F_MUTABLE); |
2651 |
goto typeseen; |
goto typeseen; |
2780 |
{ |
{ |
2781 |
regexp = matching_regexp (); |
regexp = matching_regexp (); |
2782 |
pos = BUFFER_POS (); |
pos = BUFFER_POS (); |
2783 |
|
|
2784 |
if (cls != NULL) |
if (cls != NULL) |
2785 |
{ |
{ |
2786 |
if (type_seen || !paren_seen) |
if (type_seen || !paren_seen) |
2789 |
add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0); |
add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0); |
2790 |
} |
} |
2791 |
} |
} |
2792 |
|
|
2793 |
MATCH (); |
MATCH (); |
2794 |
print_info (); |
print_info (); |
2795 |
} |
} |
2886 |
parse_classname () |
parse_classname () |
2887 |
{ |
{ |
2888 |
struct sym *last_class = NULL; |
struct sym *last_class = NULL; |
2889 |
|
|
2890 |
while (LOOKING_AT (IDENT)) |
while (LOOKING_AT (IDENT)) |
2891 |
{ |
{ |
2892 |
last_class = add_sym (yytext, last_class); |
last_class = add_sym (yytext, last_class); |
2897 |
skip_matching (); |
skip_matching (); |
2898 |
SET_FLAG (last_class->flags, F_TEMPLATE); |
SET_FLAG (last_class->flags, F_TEMPLATE); |
2899 |
} |
} |
2900 |
|
|
2901 |
if (!LOOKING_AT (DCOLON)) |
if (!LOOKING_AT (DCOLON)) |
2902 |
break; |
break; |
2903 |
|
|
2904 |
MATCH (); |
MATCH (); |
2905 |
} |
} |
2906 |
|
|
2920 |
static char *id = NULL; |
static char *id = NULL; |
2921 |
char *s; |
char *s; |
2922 |
int len; |
int len; |
2923 |
|
|
2924 |
MATCH (); |
MATCH (); |
2925 |
|
|
2926 |
if (LOOKING_AT2 (NEW, DELETE)) |
if (LOOKING_AT2 (NEW, DELETE)) |
2931 |
|
|
2932 |
s = token_string (LA1); |
s = token_string (LA1); |
2933 |
MATCH (); |
MATCH (); |
2934 |
|
|
2935 |
len = strlen (s) + 10; |
len = strlen (s) + 10; |
2936 |
if (len > id_size) |
if (len > id_size) |
2937 |
{ |
{ |
2941 |
} |
} |
2942 |
strcpy (id, s); |
strcpy (id, s); |
2943 |
|
|
2944 |
/* Vector new or delete? */ |
/* Vector new or delete? */ |
2945 |
if (LOOKING_AT ('[')) |
if (LOOKING_AT ('[')) |
2946 |
{ |
{ |
2947 |
strcat (id, "["); |
strcat (id, "["); |
2948 |
MATCH (); |
MATCH (); |
2949 |
|
|
2950 |
if (LOOKING_AT (']')) |
if (LOOKING_AT (']')) |
2951 |
{ |
{ |
2952 |
strcat (id, "]"); |
strcat (id, "]"); |
3011 |
char *id = NULL; |
char *id = NULL; |
3012 |
size_t id_size = 0; |
size_t id_size = 0; |
3013 |
int enter = 0; |
int enter = 0; |
3014 |
|
|
3015 |
while (LOOKING_AT (IDENT)) |
while (LOOKING_AT (IDENT)) |
3016 |
{ |
{ |
3017 |
int len = strlen (yytext) + 1; |
int len = strlen (yytext) + 1; |
3240 |
sc = SC_TYPE; |
sc = SC_TYPE; |
3241 |
MATCH (); |
MATCH (); |
3242 |
break; |
break; |
3243 |
|
|
3244 |
case STATIC: |
case STATIC: |
3245 |
sc = SC_STATIC; |
sc = SC_STATIC; |
3246 |
MATCH (); |
MATCH (); |
3368 |
else |
else |
3369 |
add_global_defn (id, regexp, pos, 0, 1, sc, flags); |
add_global_defn (id, regexp, pos, 0, 1, sc, flags); |
3370 |
} |
} |
3371 |
|
|
3372 |
MATCH (); |
MATCH (); |
3373 |
print_info (); |
print_info (); |
3374 |
} |
} |
3406 |
for (;;) |
for (;;) |
3407 |
{ |
{ |
3408 |
char *prev_in = in; |
char *prev_in = in; |
3409 |
|
|
3410 |
switch (LA1) |
switch (LA1) |
3411 |
{ |
{ |
3412 |
case NAMESPACE: |
case NAMESPACE: |
3417 |
{ |
{ |
3418 |
char *namespace_name = xstrdup (yytext); |
char *namespace_name = xstrdup (yytext); |
3419 |
MATCH (); |
MATCH (); |
3420 |
|
|
3421 |
if (LOOKING_AT ('=')) |
if (LOOKING_AT ('=')) |
3422 |
{ |
{ |
3423 |
struct link *qna = match_qualified_namespace_alias (); |
struct link *qna = match_qualified_namespace_alias (); |
3424 |
if (qna) |
if (qna) |
3425 |
register_namespace_alias (namespace_name, qna); |
register_namespace_alias (namespace_name, qna); |
3426 |
|
|
3427 |
if (skip_to (';') == ';') |
if (skip_to (';') == ';') |
3428 |
MATCH (); |
MATCH (); |
3429 |
} |
} |
3448 |
{ |
{ |
3449 |
/* This is `extern "C"'. */ |
/* This is `extern "C"'. */ |
3450 |
MATCH (); |
MATCH (); |
3451 |
|
|
3452 |
if (LOOKING_AT ('{')) |
if (LOOKING_AT ('{')) |
3453 |
{ |
{ |
3454 |
MATCH (); |
MATCH (); |
3459 |
SET_FLAG (flags, F_EXTERNC); |
SET_FLAG (flags, F_EXTERNC); |
3460 |
} |
} |
3461 |
break; |
break; |
3462 |
|
|
3463 |
case TEMPLATE: |
case TEMPLATE: |
3464 |
MATCH (); |
MATCH (); |
3465 |
SKIP_MATCHING_IF ('<'); |
SKIP_MATCHING_IF ('<'); |
3499 |
|
|
3500 |
case '}': |
case '}': |
3501 |
return 0; |
return 0; |
3502 |
|
|
3503 |
default: |
default: |
3504 |
declaration (flags); |
declaration (flags); |
3505 |
flags = start_flags; |
flags = start_flags; |
3538 |
{ |
{ |
3539 |
char *start = path_list; |
char *start = path_list; |
3540 |
struct search_path *p; |
struct search_path *p; |
3541 |
|
|
3542 |
while (*path_list && *path_list != PATH_LIST_SEPARATOR) |
while (*path_list && *path_list != PATH_LIST_SEPARATOR) |
3543 |
++path_list; |
++path_list; |
3544 |
|
|
3545 |
p = (struct search_path *) xmalloc (sizeof *p); |
p = (struct search_path *) xmalloc (sizeof *p); |
3546 |
p->path = (char *) xmalloc (path_list - start + 1); |
p->path = (char *) xmalloc (path_list - start + 1); |
3547 |
memcpy (p->path, start, path_list - start); |
memcpy (p->path, start, path_list - start); |
3575 |
static int buffer_size; |
static int buffer_size; |
3576 |
struct search_path *path; |
struct search_path *path; |
3577 |
int flen = strlen (file) + 1; /* +1 for the slash */ |
int flen = strlen (file) + 1; /* +1 for the slash */ |
3578 |
|
|
3579 |
filename = xstrdup (file); |
filename = xstrdup (file); |
3580 |
|
|
3581 |
for (path = search_path; path && fp == NULL; path = path->next) |
for (path = search_path; path && fp == NULL; path = path->next) |
3587 |
buffer_size = max (len + 1, 2 * buffer_size); |
buffer_size = max (len + 1, 2 * buffer_size); |
3588 |
buffer = (char *) xrealloc (buffer, buffer_size); |
buffer = (char *) xrealloc (buffer, buffer_size); |
3589 |
} |
} |
3590 |
|
|
3591 |
strcpy (buffer, path->path); |
strcpy (buffer, path->path); |
3592 |
strcat (buffer, "/"); |
strcat (buffer, "/"); |
3593 |
strcat (buffer, file); |
strcat (buffer, file); |
3594 |
fp = fopen (buffer, "r"); |
fp = fopen (buffer, "r"); |
3595 |
} |
} |
3596 |
|
|
3597 |
/* Try the original file name. */ |
/* Try the original file name. */ |
3598 |
if (fp == NULL) |
if (fp == NULL) |
3599 |
fp = fopen (file, "r"); |
fp = fopen (file, "r"); |
3600 |
|
|
3601 |
if (fp == NULL) |
if (fp == NULL) |
3602 |
yyerror ("cannot open", NULL); |
yyerror ("cannot open", NULL); |
3603 |
|
|
3604 |
return fp; |
return fp; |
3605 |
} |
} |
3606 |
|
|
3660 |
char *file; |
char *file; |
3661 |
{ |
{ |
3662 |
FILE *fp; |
FILE *fp; |
3663 |
|
|
3664 |
fp = open_file (file); |
fp = open_file (file); |
3665 |
if (fp) |
if (fp) |
3666 |
{ |
{ |
3667 |
int nread, nbytes; |
int nread, nbytes; |
3668 |
|
|
3669 |
/* Give a progress indication if needed. */ |
/* Give a progress indication if needed. */ |
3686 |
inbuffer_size = nread + READ_CHUNK_SIZE + 1; |
inbuffer_size = nread + READ_CHUNK_SIZE + 1; |
3687 |
inbuffer = (char *) xrealloc (inbuffer, inbuffer_size); |
inbuffer = (char *) xrealloc (inbuffer, inbuffer_size); |
3688 |
} |
} |
3689 |
|
|
3690 |
nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); |
nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); |
3691 |
if (nbytes <= 0) |
if (nbytes <= 0) |
3692 |
break; |
break; |
3729 |
|
|
3730 |
buffer[i++] = c; |
buffer[i++] = c; |
3731 |
} |
} |
3732 |
|
|
3733 |
if (c == EOF && i == 0) |
if (c == EOF && i == 0) |
3734 |
return NULL; |
return NULL; |
3735 |
|
|
3736 |
if (i == buffer_size) |
if (i == buffer_size) |
3737 |
{ |
{ |
3738 |
buffer_size = max (100, buffer_size * 2); |
buffer_size = max (100, buffer_size * 2); |
3772 |
case 'p': |
case 'p': |
3773 |
info_position = atoi (optarg); |
info_position = atoi (optarg); |
3774 |
break; |
break; |
3775 |
|
|
3776 |
case 'n': |
case 'n': |
3777 |
f_nested_classes = 0; |
f_nested_classes = 0; |
3778 |
break; |
break; |
3780 |
case 'x': |
case 'x': |
3781 |
f_regexps = 0; |
f_regexps = 0; |
3782 |
break; |
break; |
3783 |
|
|
3784 |
/* Add the name of a file containing more input files. */ |
/* Add the name of a file containing more input files. */ |
3785 |
case 'f': |
case 'f': |
3786 |
if (n_input_files == input_filenames_size) |
if (n_input_files == input_filenames_size) |
3877 |
yyerror ("error getting size of file `%s'", out_filename); |
yyerror ("error getting size of file `%s'", out_filename); |
3878 |
else if (rc == 0) |
else if (rc == 0) |
3879 |
yyerror ("file `%s' is empty", out_filename); |
yyerror ("file `%s' is empty", out_filename); |
3880 |
|
|
3881 |
fclose (fp); |
fclose (fp); |
3882 |
} |
} |
3883 |
|
|
3884 |
yyout = fopen (out_filename, f_append ? "a" : "w"); |
yyout = fopen (out_filename, f_append ? "a" : "w"); |
3885 |
if (yyout == NULL) |
if (yyout == NULL) |
3886 |
{ |
{ |
3910 |
for (i = 0; i < n_input_files; ++i) |
for (i = 0; i < n_input_files; ++i) |
3911 |
{ |
{ |
3912 |
FILE *fp = fopen (input_filenames[i], "r"); |
FILE *fp = fopen (input_filenames[i], "r"); |
3913 |
|
|
3914 |
if (fp == NULL) |
if (fp == NULL) |
3915 |
yyerror ("cannot open input file `%s'", input_filenames[i]); |
yyerror ("cannot open input file `%s'", input_filenames[i]); |
3916 |
else |
else |