diff options
| author | Francesco Potortì | 1994-01-14 17:02:11 +0000 |
|---|---|---|
| committer | Francesco Potortì | 1994-01-14 17:02:11 +0000 |
| commit | 42680d3c7cd1b06b57bde723612e674a81724d07 (patch) | |
| tree | 6dc4a211d2e1a31d94a4baa9dad6c1d4c5103d29 /lib-src | |
| parent | b97ad9eabe92e27970fa86289a4b2076e2d20286 (diff) | |
| download | emacs-42680d3c7cd1b06b57bde723612e674a81724d07.tar.gz emacs-42680d3c7cd1b06b57bde723612e674a81724d07.zip | |
* etags.c (stab_entry, stab_create, stab_find, stab_search,
stab_type, add_keyword, C_reate_stab, C_create_stabs): deleted.
Use gperf generated hash table instead of linked list.
(C_stab_entry, hash, in_word_set, get_C_stab, C_symtype): added.
Mostly code generated by gperf.
(consider_token): removed unused parameter `lp'.
(PF_funcs, getit): allow subroutine and similar declarations
to span multiple lines.
(C_entries): check for newline if inchar to avoid bus errors.
(process_file, find_entries): distinguish among nonexistent
and not regular file.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/etags.c | 448 |
1 files changed, 209 insertions, 239 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c index 423c3987d5a..5f8825f909f 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c | |||
| @@ -25,7 +25,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 25 | * Gnu Emacs TAGS format and modifications by RMS? | 25 | * Gnu Emacs TAGS format and modifications by RMS? |
| 26 | * Sam Kendall added C++. | 26 | * Sam Kendall added C++. |
| 27 | * | 27 | * |
| 28 | * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 9.8 | 28 | * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 10.6 |
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | #ifdef MSDOS | 31 | #ifdef MSDOS |
| @@ -183,10 +183,9 @@ void TEX_funcs (); | |||
| 183 | void add_node (); | 183 | void add_node (); |
| 184 | void error (); | 184 | void error (); |
| 185 | void fatal (); | 185 | void fatal (); |
| 186 | void find_entries (); | 186 | logical find_entries (); |
| 187 | void free_tree (); | 187 | void free_tree (); |
| 188 | void getit (); | 188 | void getit (); |
| 189 | void getline (); | ||
| 190 | void init (); | 189 | void init (); |
| 191 | void initbuffer (); | 190 | void initbuffer (); |
| 192 | void initbuffer (); | 191 | void initbuffer (); |
| @@ -203,127 +202,14 @@ void takeprec (); | |||
| 203 | * Type *xnew (int n, Type); | 202 | * Type *xnew (int n, Type); |
| 204 | */ | 203 | */ |
| 205 | #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) | 204 | #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) |
| 206 | |||
| 207 | |||
| 208 | 205 | ||
| 209 | /* | 206 | /* |
| 210 | * Symbol table stuff. | 207 | * Symbol table types. |
| 211 | * | ||
| 212 | * Should probably be implemented with hash table; linked list for now. | ||
| 213 | */ | 208 | */ |
| 214 | |||
| 215 | enum sym_type | 209 | enum sym_type |
| 216 | { | 210 | { |
| 217 | st_none, st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec | 211 | st_none, st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec |
| 218 | }; | 212 | }; |
| 219 | |||
| 220 | struct stab_entry | ||
| 221 | { | ||
| 222 | char *sym; | ||
| 223 | int symlen; | ||
| 224 | enum sym_type type; | ||
| 225 | struct stab_entry *next; | ||
| 226 | }; | ||
| 227 | |||
| 228 | typedef struct stab_entry Stab_entry; | ||
| 229 | typedef Stab_entry *Stab; | ||
| 230 | |||
| 231 | /* | ||
| 232 | * NAME | ||
| 233 | * Stab, Stab_entry, stab_create, stab_search, stab_find -- symbol table | ||
| 234 | * | ||
| 235 | * SYNOPSIS | ||
| 236 | * Types: Stab, Stab_entry, enum sym_type | ||
| 237 | * | ||
| 238 | * Stab * stab_create () | ||
| 239 | * | ||
| 240 | * Stab_entry * stab_find (stab, sym) | ||
| 241 | * Stab *stab; | ||
| 242 | * char *sym; | ||
| 243 | * | ||
| 244 | * Stab_entry * stab_search (stab, sym) | ||
| 245 | * Stab *stab; | ||
| 246 | * char *sym; | ||
| 247 | * | ||
| 248 | * DESCRIPTION | ||
| 249 | * stab_create creates a Stab, a symbol table object, and returns a | ||
| 250 | * pointer to it. stab_find finds a symbol in a Stab; it returns a | ||
| 251 | * pointer to the Stab_entry if found, otherwise NULL. stab_search | ||
| 252 | * is like stab_find, except that it creates a new Stab_entry, | ||
| 253 | * initialized with type = st_none, if one did not exist already | ||
| 254 | * (it never returns NULL). | ||
| 255 | * | ||
| 256 | * A Stab_entry is a structure that contains at least the following | ||
| 257 | * members: | ||
| 258 | * | ||
| 259 | * char *name; // must not be modified | ||
| 260 | * enum sym_type type; // should be set | ||
| 261 | * | ||
| 262 | * The type field is initially set to st_none; it should be set to | ||
| 263 | * something else by the caller of stab_search. Other possible values | ||
| 264 | * of an enum sym_type can be added. | ||
| 265 | */ | ||
| 266 | |||
| 267 | Stab * | ||
| 268 | stab_create () | ||
| 269 | { | ||
| 270 | Stab *sp; | ||
| 271 | sp = xnew (1, Stab); | ||
| 272 | *sp = NULL; /* a Stab starts out as a null Stab_entry* */ | ||
| 273 | return sp; | ||
| 274 | } | ||
| 275 | |||
| 276 | Stab_entry * | ||
| 277 | stab_find (stab, sym, symlen) | ||
| 278 | Stab *stab; | ||
| 279 | register char *sym; | ||
| 280 | register int symlen; | ||
| 281 | { | ||
| 282 | register Stab_entry *se; | ||
| 283 | for (se = *stab; se != NULL; se = se->next) | ||
| 284 | { | ||
| 285 | if (se->symlen == symlen && strneq (se->sym, sym, symlen)) | ||
| 286 | return se; | ||
| 287 | } | ||
| 288 | |||
| 289 | return NULL; | ||
| 290 | } | ||
| 291 | |||
| 292 | Stab_entry * | ||
| 293 | stab_search (stab, sym, symlen) | ||
| 294 | register Stab *stab; | ||
| 295 | char *sym; | ||
| 296 | int symlen; | ||
| 297 | { | ||
| 298 | register Stab_entry *se; | ||
| 299 | se = stab_find (stab, sym, symlen); | ||
| 300 | |||
| 301 | if (se == NULL) | ||
| 302 | { | ||
| 303 | /* make a new one */ | ||
| 304 | se = xnew (1, Stab_entry); | ||
| 305 | se->sym = savenstr (sym, symlen); | ||
| 306 | se->symlen = symlen; | ||
| 307 | se->type = st_none; | ||
| 308 | se->next = *stab; | ||
| 309 | *stab = se; | ||
| 310 | } | ||
| 311 | |||
| 312 | return se; | ||
| 313 | } | ||
| 314 | |||
| 315 | /* | ||
| 316 | * NAME | ||
| 317 | * stab_type -- type of a symbol table entry | ||
| 318 | * | ||
| 319 | * SYNOPSIS | ||
| 320 | * enum sym_type stab_type (Stab_entry *se); | ||
| 321 | * | ||
| 322 | * WARNING | ||
| 323 | * May evaluate its argument more than once. | ||
| 324 | */ | ||
| 325 | |||
| 326 | #define stab_type(se) ((se)==NULL ? st_none : (se)->type) | ||
| 327 | 213 | ||
| 328 | 214 | ||
| 329 | 215 | ||
| @@ -551,7 +437,7 @@ main (argc, argv) | |||
| 551 | #endif | 437 | #endif |
| 552 | 438 | ||
| 553 | #ifdef MSDOS | 439 | #ifdef MSDOS |
| 554 | _fmode = O_BINARY; /* all of files are treated as binary files */ | 440 | _fmode = O_BINARY; /* all of files are treated as binary files */ |
| 555 | #endif /* MSDOS */ | 441 | #endif /* MSDOS */ |
| 556 | 442 | ||
| 557 | progname = argv[0]; | 443 | progname = argv[0]; |
| @@ -724,11 +610,8 @@ main (argc, argv) | |||
| 724 | for (; optind < argc; optind++) | 610 | for (; optind < argc; optind++) |
| 725 | { | 611 | { |
| 726 | this_file = argv[optind]; | 612 | this_file = argv[optind]; |
| 727 | if (1) | ||
| 728 | { | ||
| 729 | #endif | 613 | #endif |
| 730 | /* Input file named "-" means read file names from stdin | 614 | /* Input file named "-" means read file names from stdin and use them. */ |
| 731 | and use them. */ | ||
| 732 | if (streq (this_file, "-")) | 615 | if (streq (this_file, "-")) |
| 733 | { | 616 | { |
| 734 | while (!feof (stdin)) | 617 | while (!feof (stdin)) |
| @@ -741,7 +624,6 @@ main (argc, argv) | |||
| 741 | else | 624 | else |
| 742 | process_file (this_file); | 625 | process_file (this_file); |
| 743 | } | 626 | } |
| 744 | } | ||
| 745 | 627 | ||
| 746 | if (emacs_tags_format) | 628 | if (emacs_tags_format) |
| 747 | { | 629 | { |
| @@ -796,18 +678,20 @@ process_file (file) | |||
| 796 | { | 678 | { |
| 797 | struct stat stat_buf; | 679 | struct stat stat_buf; |
| 798 | 680 | ||
| 799 | if (stat (file, &stat_buf) || !S_ISREG (stat_buf.st_mode)) | 681 | if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode)) |
| 800 | { | 682 | { |
| 801 | fprintf (stderr, "Skipping %s: it is not a regular file.\n", file); | 683 | fprintf (stderr, "Skipping %s: it is not a regular file.\n", file); |
| 802 | return; | 684 | return; |
| 803 | } | 685 | } |
| 804 | |||
| 805 | if (streq (file, outfile) && !streq (outfile, "-")) | 686 | if (streq (file, outfile) && !streq (outfile, "-")) |
| 806 | { | 687 | { |
| 807 | fprintf (stderr, "Skipping inclusion of %s in self.\n", file); | 688 | fprintf (stderr, "Skipping inclusion of %s in self.\n", file); |
| 808 | return; | 689 | return; |
| 809 | } | 690 | } |
| 810 | find_entries (file); | 691 | if (!find_entries (file)) |
| 692 | { | ||
| 693 | return; | ||
| 694 | } | ||
| 811 | if (emacs_tags_format) | 695 | if (emacs_tags_format) |
| 812 | { | 696 | { |
| 813 | fprintf (outf, "\f\n%s,%d\n", file, total_size_of_entries (head)); | 697 | fprintf (outf, "\f\n%s,%d\n", file, total_size_of_entries (head)); |
| @@ -851,7 +735,7 @@ init () | |||
| 851 | * This routine opens the specified file and calls the function | 735 | * This routine opens the specified file and calls the function |
| 852 | * which finds the function and type definitions. | 736 | * which finds the function and type definitions. |
| 853 | */ | 737 | */ |
| 854 | void | 738 | logical |
| 855 | find_entries (file) | 739 | find_entries (file) |
| 856 | char *file; | 740 | char *file; |
| 857 | { | 741 | { |
| @@ -862,7 +746,7 @@ find_entries (file) | |||
| 862 | if (inf == NULL) | 746 | if (inf == NULL) |
| 863 | { | 747 | { |
| 864 | perror (file); | 748 | perror (file); |
| 865 | return; | 749 | return FALSE; |
| 866 | } | 750 | } |
| 867 | curfile = savestr (file); | 751 | curfile = savestr (file); |
| 868 | cp = etags_rindex (file, '.'); | 752 | cp = etags_rindex (file, '.'); |
| @@ -902,8 +786,7 @@ find_entries (file) | |||
| 902 | && string_numeric_p (cp + 1)))) | 786 | && string_numeric_p (cp + 1)))) |
| 903 | { | 787 | { |
| 904 | Scheme_funcs (inf); | 788 | Scheme_funcs (inf); |
| 905 | fclose (inf); | 789 | goto close_and_return; |
| 906 | return; | ||
| 907 | } | 790 | } |
| 908 | /* Assume that ".s" or ".a" is assembly code. -wolfgang. | 791 | /* Assume that ".s" or ".a" is assembly code. -wolfgang. |
| 909 | Or even ".sa". */ | 792 | Or even ".sa". */ |
| @@ -912,8 +795,7 @@ find_entries (file) | |||
| 912 | || streq (cp + 1, "sa"))) | 795 | || streq (cp + 1, "sa"))) |
| 913 | { | 796 | { |
| 914 | Asm_funcs (inf); | 797 | Asm_funcs (inf); |
| 915 | fclose (inf); | 798 | goto close_and_return; |
| 916 | return; | ||
| 917 | } | 799 | } |
| 918 | /* .C or .H or .cxx or .hxx or .cc: a C++ file */ | 800 | /* .C or .H or .cxx or .hxx or .cc: a C++ file */ |
| 919 | if (cp && (streq (cp + 1, "C") | 801 | if (cp && (streq (cp + 1, "C") |
| @@ -955,7 +837,7 @@ find_entries (file) | |||
| 955 | if (cp && (streq (cp + 1, "f") | 837 | if (cp && (streq (cp + 1, "f") |
| 956 | || streq (cp + 1, "for"))) | 838 | || streq (cp + 1, "for"))) |
| 957 | { | 839 | { |
| 958 | PF_funcs (inf); | 840 | (void) PF_funcs (inf); |
| 959 | goto close_and_return; | 841 | goto close_and_return; |
| 960 | } | 842 | } |
| 961 | /* if not a .c or .h or .y file, try fortran */ | 843 | /* if not a .c or .h or .y file, try fortran */ |
| @@ -972,6 +854,7 @@ find_entries (file) | |||
| 972 | 854 | ||
| 973 | close_and_return: | 855 | close_and_return: |
| 974 | (void) fclose (inf); | 856 | (void) fclose (inf); |
| 857 | return TRUE; | ||
| 975 | } | 858 | } |
| 976 | 859 | ||
| 977 | /* Nonzero if string STR is composed of digits. */ | 860 | /* Nonzero if string STR is composed of digits. */ |
| @@ -1268,67 +1151,148 @@ total_size_of_entries (node) | |||
| 1268 | * The C symbol tables. | 1151 | * The C symbol tables. |
| 1269 | */ | 1152 | */ |
| 1270 | 1153 | ||
| 1271 | Stab *C_stab, *C_PLPL_stab, *C_STAR_stab; | 1154 | /* Feed stuff between (but not including) %[ and %] lines to: |
| 1272 | 1155 | gperf -c -k1,3 -o -p -r -t | |
| 1156 | %[ | ||
| 1157 | struct C_stab_entry { char *name; int c_ext; enum sym_type type; } | ||
| 1158 | %% | ||
| 1159 | class, C_PLPL, st_C_struct | ||
| 1160 | domain, C_STAR, st_C_struct | ||
| 1161 | union, 0, st_C_struct | ||
| 1162 | struct, 0, st_C_struct | ||
| 1163 | enum, 0, st_C_enum | ||
| 1164 | typedef, 0, st_C_typedef | ||
| 1165 | define, 0, st_C_define | ||
| 1166 | long, 0, st_C_typespec | ||
| 1167 | short, 0, st_C_typespec | ||
| 1168 | int, 0, st_C_typespec | ||
| 1169 | char, 0, st_C_typespec | ||
| 1170 | float, 0, st_C_typespec | ||
| 1171 | double, 0, st_C_typespec | ||
| 1172 | signed, 0, st_C_typespec | ||
| 1173 | unsigned, 0, st_C_typespec | ||
| 1174 | auto, 0, st_C_typespec | ||
| 1175 | void, 0, st_C_typespec | ||
| 1176 | extern, 0, st_C_typespec | ||
| 1177 | static, 0, st_C_typespec | ||
| 1178 | const, 0, st_C_typespec | ||
| 1179 | volatile, 0, st_C_typespec | ||
| 1180 | %] | ||
| 1181 | and replace lines between %< and %> with its output. */ | ||
| 1182 | /*%<*/ | ||
| 1183 | /* C code produced by gperf version 1.8.1 (K&R C version) */ | ||
| 1184 | /* Command-line: gperf -c -k1,3 -o -p -r -t */ | ||
| 1185 | |||
| 1186 | |||
| 1187 | struct C_stab_entry { char *name; int c_ext; enum sym_type type; }; | ||
| 1188 | |||
| 1189 | #define MIN_WORD_LENGTH 3 | ||
| 1190 | #define MAX_WORD_LENGTH 8 | ||
| 1191 | #define MIN_HASH_VALUE 10 | ||
| 1192 | #define MAX_HASH_VALUE 62 | ||
| 1273 | /* | 1193 | /* |
| 1274 | * SYNOPSIS | 1194 | 21 keywords |
| 1275 | * Stab *get_C_stab (int c_ext); | 1195 | 53 is the maximum key range |
| 1276 | */ | 1196 | */ |
| 1277 | #define get_C_stab(c_ext) ((c_ext & C_STAR) ? C_STAR_stab : \ | 1197 | |
| 1278 | (c_ext & C_PLPL) ? C_PLPL_stab : \ | 1198 | static int |
| 1279 | C_stab) | 1199 | hash (str, len) |
| 1200 | register char *str; | ||
| 1201 | register int len; | ||
| 1202 | { | ||
| 1203 | static unsigned char hash_table[] = | ||
| 1204 | { | ||
| 1205 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1206 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1207 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1208 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1209 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1210 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1211 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1212 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1213 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1214 | 62, 62, 62, 62, 62, 62, 62, 2, 62, 7, | ||
| 1215 | 6, 9, 15, 30, 62, 24, 62, 62, 1, 24, | ||
| 1216 | 7, 27, 13, 62, 19, 26, 18, 27, 1, 62, | ||
| 1217 | 62, 62, 62, 62, 62, 62, 62, 62, | ||
| 1218 | }; | ||
| 1219 | return len + hash_table[str[2]] + hash_table[str[0]]; | ||
| 1220 | } | ||
| 1280 | 1221 | ||
| 1281 | void | 1222 | struct C_stab_entry * |
| 1282 | add_keyword (stab, sym, type) | 1223 | in_word_set (str, len) |
| 1283 | Stab *stab; | 1224 | register char *str; |
| 1284 | char *sym; | 1225 | register int len; |
| 1285 | enum sym_type type; | 1226 | { |
| 1286 | { | 1227 | |
| 1287 | stab_search (stab, sym, strlen (sym))->type = type; | 1228 | static struct C_stab_entry wordlist[] = |
| 1229 | { | ||
| 1230 | {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | ||
| 1231 | {"",}, | ||
| 1232 | {"volatile", 0, st_C_typespec}, | ||
| 1233 | {"",}, | ||
| 1234 | {"long", 0, st_C_typespec}, | ||
| 1235 | {"char", 0, st_C_typespec}, | ||
| 1236 | {"class", C_PLPL, st_C_struct}, | ||
| 1237 | {"",}, {"",}, {"",}, {"",}, | ||
| 1238 | {"const", 0, st_C_typespec}, | ||
| 1239 | {"",}, {"",}, {"",}, {"",}, | ||
| 1240 | {"auto", 0, st_C_typespec}, | ||
| 1241 | {"",}, {"",}, | ||
| 1242 | {"define", 0, st_C_define}, | ||
| 1243 | {"",}, | ||
| 1244 | {"void", 0, st_C_typespec}, | ||
| 1245 | {"",}, {"",}, {"",}, | ||
| 1246 | {"extern", 0, st_C_typespec}, | ||
| 1247 | {"static", 0, st_C_typespec}, | ||
| 1248 | {"",}, | ||
| 1249 | {"domain", C_STAR, st_C_struct}, | ||
| 1250 | {"",}, | ||
| 1251 | {"typedef", 0, st_C_typedef}, | ||
| 1252 | {"double", 0, st_C_typespec}, | ||
| 1253 | {"enum", 0, st_C_enum}, | ||
| 1254 | {"",}, {"",}, {"",}, {"",}, | ||
| 1255 | {"int", 0, st_C_typespec}, | ||
| 1256 | {"",}, | ||
| 1257 | {"float", 0, st_C_typespec}, | ||
| 1258 | {"",}, {"",}, {"",}, | ||
| 1259 | {"struct", 0, st_C_struct}, | ||
| 1260 | {"",}, {"",}, {"",}, {"",}, | ||
| 1261 | {"union", 0, st_C_struct}, | ||
| 1262 | {"",}, | ||
| 1263 | {"short", 0, st_C_typespec}, | ||
| 1264 | {"",}, {"",}, | ||
| 1265 | {"unsigned", 0, st_C_typespec}, | ||
| 1266 | {"signed", 0, st_C_typespec}, | ||
| 1267 | }; | ||
| 1268 | |||
| 1269 | if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) | ||
| 1270 | { | ||
| 1271 | register int key = hash (str, len); | ||
| 1272 | |||
| 1273 | if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) | ||
| 1274 | { | ||
| 1275 | register char *s = wordlist[key].name; | ||
| 1276 | |||
| 1277 | if (*s == *str && !strncmp (str + 1, s + 1, len - 1)) | ||
| 1278 | return &wordlist[key]; | ||
| 1279 | } | ||
| 1280 | } | ||
| 1281 | return 0; | ||
| 1288 | } | 1282 | } |
| 1283 | /*%>*/ | ||
| 1289 | 1284 | ||
| 1290 | Stab * | 1285 | enum sym_type |
| 1291 | C_create_stab (c_ext) | 1286 | C_symtype(str, len, c_ext) |
| 1287 | char *str; | ||
| 1288 | int len; | ||
| 1292 | int c_ext; | 1289 | int c_ext; |
| 1293 | { | 1290 | { |
| 1294 | Stab *stab; | 1291 | register struct C_stab_entry *se = in_word_set(str, len); |
| 1295 | |||
| 1296 | stab = stab_create (); | ||
| 1297 | |||
| 1298 | /* C, C++ and C* */ | ||
| 1299 | if (c_ext & C_PLPL) | ||
| 1300 | add_keyword (stab, "class", st_C_struct); | ||
| 1301 | if (c_ext & C_STAR) | ||
| 1302 | add_keyword (stab, "domain", st_C_struct); | ||
| 1303 | add_keyword (stab, "union", st_C_struct); | ||
| 1304 | add_keyword (stab, "struct", st_C_struct); | ||
| 1305 | add_keyword (stab, "enum", st_C_enum); | ||
| 1306 | add_keyword (stab, "typedef", st_C_typedef); | ||
| 1307 | add_keyword (stab, "define", st_C_define); | ||
| 1308 | add_keyword (stab, "long", st_C_typespec); | ||
| 1309 | add_keyword (stab, "short", st_C_typespec); | ||
| 1310 | add_keyword (stab, "int", st_C_typespec); | ||
| 1311 | add_keyword (stab, "char", st_C_typespec); | ||
| 1312 | add_keyword (stab, "float", st_C_typespec); | ||
| 1313 | add_keyword (stab, "double", st_C_typespec); | ||
| 1314 | add_keyword (stab, "signed", st_C_typespec); | ||
| 1315 | add_keyword (stab, "unsigned", st_C_typespec); | ||
| 1316 | add_keyword (stab, "auto", st_C_typespec); | ||
| 1317 | add_keyword (stab, "void", st_C_typespec); | ||
| 1318 | add_keyword (stab, "extern", st_C_typespec); | ||
| 1319 | add_keyword (stab, "static", st_C_typespec); | ||
| 1320 | add_keyword (stab, "const", st_C_typespec); | ||
| 1321 | add_keyword (stab, "volatile", st_C_typespec); | ||
| 1322 | |||
| 1323 | return stab; | ||
| 1324 | } | ||
| 1325 | 1292 | ||
| 1326 | void | 1293 | if (se == NULL || (se->c_ext && !(c_ext & se->c_ext))) |
| 1327 | C_create_stabs () | 1294 | return st_none; |
| 1328 | { | 1295 | return se->type; |
| 1329 | C_stab = C_create_stab (0); | ||
| 1330 | C_PLPL_stab = C_create_stab (C_PLPL); | ||
| 1331 | C_STAR_stab = C_create_stab (C_STAR | C_PLPL); | ||
| 1332 | } | 1296 | } |
| 1333 | 1297 | ||
| 1334 | /* | 1298 | /* |
| @@ -1377,10 +1341,11 @@ typedef enum | |||
| 1377 | STRUCTST structdef; | 1341 | STRUCTST structdef; |
| 1378 | /* | 1342 | /* |
| 1379 | * When structdef is stagseen, scolonseen, or sinbody, structtag is the | 1343 | * When structdef is stagseen, scolonseen, or sinbody, structtag is the |
| 1380 | * struct tag, and structkey is the preceding struct-like keyword. | 1344 | * struct tag, and structtype is the type of the preceding struct-like |
| 1345 | * keyword. | ||
| 1381 | */ | 1346 | */ |
| 1382 | char structtag[BUFSIZ]; | 1347 | char structtag[BUFSIZ]; |
| 1383 | Stab_entry *structkey; | 1348 | enum sym_type structtype; |
| 1384 | 1349 | ||
| 1385 | /* | 1350 | /* |
| 1386 | * Yet another little state machine to deal with preprocessor lines. | 1351 | * Yet another little state machine to deal with preprocessor lines. |
| @@ -1467,7 +1432,6 @@ C_entries (c_ext) | |||
| 1467 | logical incomm, inquote, inchar, quotednl, midtoken; | 1432 | logical incomm, inquote, inchar, quotednl, midtoken; |
| 1468 | logical cplpl; | 1433 | logical cplpl; |
| 1469 | TOKEN savetok; /* saved token during preprocessor handling */ | 1434 | TOKEN savetok; /* saved token during preprocessor handling */ |
| 1470 | logical saveisfunc; | ||
| 1471 | char savenameb[BUFSIZ]; /* ouch! */ | 1435 | char savenameb[BUFSIZ]; /* ouch! */ |
| 1472 | 1436 | ||
| 1473 | savetok.lineno = 0; | 1437 | savetok.lineno = 0; |
| @@ -1484,8 +1448,6 @@ C_entries (c_ext) | |||
| 1484 | parlev = 0; | 1448 | parlev = 0; |
| 1485 | cplpl = c_ext & C_PLPL; | 1449 | cplpl = c_ext & C_PLPL; |
| 1486 | 1450 | ||
| 1487 | C_create_stabs (); | ||
| 1488 | |||
| 1489 | while (!feof (inf)) | 1451 | while (!feof (inf)) |
| 1490 | { | 1452 | { |
| 1491 | c = *lp++; | 1453 | c = *lp++; |
| @@ -1529,7 +1491,7 @@ C_entries (c_ext) | |||
| 1529 | inquote = FALSE; | 1491 | inquote = FALSE; |
| 1530 | break; | 1492 | break; |
| 1531 | case '\0': | 1493 | case '\0': |
| 1532 | /* Newlines inside strings, do not end macro definitions | 1494 | /* Newlines inside strings do not end macro definitions |
| 1533 | in traditional cpp, even though compilers don't | 1495 | in traditional cpp, even though compilers don't |
| 1534 | usually accept them. */ | 1496 | usually accept them. */ |
| 1535 | CNL_SAVE_DEFINEDEF; | 1497 | CNL_SAVE_DEFINEDEF; |
| @@ -1539,8 +1501,16 @@ C_entries (c_ext) | |||
| 1539 | } | 1501 | } |
| 1540 | else if (inchar) | 1502 | else if (inchar) |
| 1541 | { | 1503 | { |
| 1542 | if (c == '\'') | 1504 | switch (c) |
| 1505 | { | ||
| 1506 | case '\0': | ||
| 1507 | /* Hmmm, something went wrong. */ | ||
| 1508 | CNL; | ||
| 1509 | /* FALLTHRU */ | ||
| 1510 | case '\'': | ||
| 1543 | inchar = FALSE; | 1511 | inchar = FALSE; |
| 1512 | break; | ||
| 1513 | } | ||
| 1544 | continue; | 1514 | continue; |
| 1545 | } | 1515 | } |
| 1546 | else | 1516 | else |
| @@ -1621,8 +1591,7 @@ C_entries (c_ext) | |||
| 1621 | tok.len = toklen; | 1591 | tok.len = toklen; |
| 1622 | tok.named = FALSE; | 1592 | tok.named = FALSE; |
| 1623 | if (yacc_rules | 1593 | if (yacc_rules |
| 1624 | || consider_token (c, lp, &tok, | 1594 | || consider_token (c, &tok, c_ext, cblev, &is_func)) |
| 1625 | c_ext, cblev, &is_func)) | ||
| 1626 | { | 1595 | { |
| 1627 | if (structdef == sinbody | 1596 | if (structdef == sinbody |
| 1628 | && definedef == dnone | 1597 | && definedef == dnone |
| @@ -1838,20 +1807,8 @@ C_entries (c_ext) | |||
| 1838 | } | 1807 | } |
| 1839 | break; | 1808 | break; |
| 1840 | case '=': | 1809 | case '=': |
| 1841 | case '#': | 1810 | case '#': case '+': case '-': case '~': case '&': case '%': case '/': |
| 1842 | case '+': | 1811 | case '|': case '^': case '!': case '<': case '>': case '.': case '?': |
| 1843 | case '-': | ||
| 1844 | case '~': | ||
| 1845 | case '&': | ||
| 1846 | case '%': | ||
| 1847 | case '/': | ||
| 1848 | case '|': | ||
| 1849 | case '^': | ||
| 1850 | case '!': | ||
| 1851 | case '<': | ||
| 1852 | case '>': | ||
| 1853 | case '.': | ||
| 1854 | case '?': | ||
| 1855 | if (definedef != dnone) | 1812 | if (definedef != dnone) |
| 1856 | break; | 1813 | break; |
| 1857 | /* These surely cannot follow a function tag. */ | 1814 | /* These surely cannot follow a function tag. */ |
| @@ -1893,16 +1850,14 @@ C_entries (c_ext) | |||
| 1893 | */ | 1850 | */ |
| 1894 | 1851 | ||
| 1895 | logical | 1852 | logical |
| 1896 | consider_token (c, lp, tokp, c_ext, cblev, is_func) | 1853 | consider_token (c, tokp, c_ext, cblev, is_func) |
| 1897 | register char c; /* IN: first char after the token */ | 1854 | register char c; /* IN: first char after the token */ |
| 1898 | register char *lp; /* IN: lp points to 2nd char after the token */ | ||
| 1899 | register TOKEN *tokp; /* IN: token pointer */ | 1855 | register TOKEN *tokp; /* IN: token pointer */ |
| 1900 | int c_ext; /* IN: C extensions mask */ | 1856 | int c_ext; /* IN: C extensions mask */ |
| 1901 | int cblev; /* IN: curly brace level */ | 1857 | int cblev; /* IN: curly brace level */ |
| 1902 | logical *is_func; /* OUT */ | 1858 | logical *is_func; /* OUT */ |
| 1903 | { | 1859 | { |
| 1904 | Stab_entry *tokse = stab_find (get_C_stab (c_ext), tokp->p, tokp->len); | 1860 | enum sym_type toktype = C_symtype(tokp->p, tokp->len, c_ext); |
| 1905 | enum sym_type toktype = stab_type (tokse); | ||
| 1906 | 1861 | ||
| 1907 | /* | 1862 | /* |
| 1908 | * Advance the definedef state machine. | 1863 | * Advance the definedef state machine. |
| @@ -1998,13 +1953,13 @@ consider_token (c, lp, tokp, c_ext, cblev, is_func) | |||
| 1998 | || (typedefs_and_cplusplus && cblev == 0 && structdef == snone)) | 1953 | || (typedefs_and_cplusplus && cblev == 0 && structdef == snone)) |
| 1999 | { | 1954 | { |
| 2000 | structdef = skeyseen; | 1955 | structdef = skeyseen; |
| 2001 | structkey = tokse; | 1956 | structtype = toktype; |
| 2002 | } | 1957 | } |
| 2003 | return (FALSE); | 1958 | return (FALSE); |
| 2004 | } | 1959 | } |
| 2005 | if (structdef == skeyseen) | 1960 | if (structdef == skeyseen) |
| 2006 | { | 1961 | { |
| 2007 | if (stab_type (structkey) == st_C_struct) | 1962 | if (structtype == st_C_struct) |
| 2008 | { | 1963 | { |
| 2009 | (void) strncpy (structtag, tokp->p, tokp->len); | 1964 | (void) strncpy (structtag, tokp->p, tokp->len); |
| 2010 | structtag[tokp->len] = '\0'; /* for struct/union/class */ | 1965 | structtag[tokp->len] = '\0'; /* for struct/union/class */ |
| @@ -2131,24 +2086,24 @@ PF_funcs (fi) | |||
| 2131 | { | 2086 | { |
| 2132 | case 'f': | 2087 | case 'f': |
| 2133 | if (tail ("function")) | 2088 | if (tail ("function")) |
| 2134 | getit (); | 2089 | getit (fi); |
| 2135 | continue; | 2090 | continue; |
| 2136 | case 's': | 2091 | case 's': |
| 2137 | if (tail ("subroutine")) | 2092 | if (tail ("subroutine")) |
| 2138 | getit (); | 2093 | getit (fi); |
| 2139 | continue; | 2094 | continue; |
| 2140 | case 'e': | 2095 | case 'e': |
| 2141 | if (tail ("entry")) | 2096 | if (tail ("entry")) |
| 2142 | getit (); | 2097 | getit (fi); |
| 2143 | continue; | 2098 | continue; |
| 2144 | case 'p': | 2099 | case 'p': |
| 2145 | if (tail ("program")) | 2100 | if (tail ("program")) |
| 2146 | { | 2101 | { |
| 2147 | getit (); | 2102 | getit (fi); |
| 2148 | continue; | 2103 | continue; |
| 2149 | } | 2104 | } |
| 2150 | if (tail ("procedure")) | 2105 | if (tail ("procedure")) |
| 2151 | getit (); | 2106 | getit (fi); |
| 2152 | continue; | 2107 | continue; |
| 2153 | } | 2108 | } |
| 2154 | } | 2109 | } |
| @@ -2161,14 +2116,14 @@ tail (cp) | |||
| 2161 | { | 2116 | { |
| 2162 | register int len = 0; | 2117 | register int len = 0; |
| 2163 | 2118 | ||
| 2164 | while (*cp && (*cp & ~' ') == ((*(dbp + len)) & ~' ')) | 2119 | while (*cp && (*cp | ' ') == (dbp[len] | ' ')) |
| 2165 | cp++, len++; | 2120 | cp++, len++; |
| 2166 | if (*cp == 0) | 2121 | if (*cp == 0) |
| 2167 | { | 2122 | { |
| 2168 | dbp += len; | 2123 | dbp += len; |
| 2169 | return (1); | 2124 | return (TRUE); |
| 2170 | } | 2125 | } |
| 2171 | return (0); | 2126 | return (FALSE); |
| 2172 | } | 2127 | } |
| 2173 | 2128 | ||
| 2174 | void | 2129 | void |
| @@ -2192,7 +2147,8 @@ takeprec () | |||
| 2192 | } | 2147 | } |
| 2193 | 2148 | ||
| 2194 | void | 2149 | void |
| 2195 | getit () | 2150 | getit (fi) |
| 2151 | FILE *fi; | ||
| 2196 | { | 2152 | { |
| 2197 | register char *cp; | 2153 | register char *cp; |
| 2198 | char c; | 2154 | char c; |
| @@ -2200,19 +2156,33 @@ getit () | |||
| 2200 | 2156 | ||
| 2201 | while (isspace (*dbp)) | 2157 | while (isspace (*dbp)) |
| 2202 | dbp++; | 2158 | dbp++; |
| 2203 | if (*dbp == 0 | 2159 | if (*dbp == '\0') |
| 2204 | || (!isalpha (*dbp) | 2160 | { |
| 2161 | lineno++; | ||
| 2162 | linecharno = charno; | ||
| 2163 | charno += readline (&lb, fi); | ||
| 2164 | dbp = lb.buffer; | ||
| 2165 | if (dbp[5] != '&') | ||
| 2166 | return; | ||
| 2167 | dbp += 6; | ||
| 2168 | while (isspace (*dbp)) | ||
| 2169 | dbp++; | ||
| 2170 | } | ||
| 2171 | if (!isalpha (*dbp) | ||
| 2205 | && *dbp != '_' | 2172 | && *dbp != '_' |
| 2206 | && *dbp != '$')) | 2173 | && *dbp != '$') |
| 2207 | return; | 2174 | return; |
| 2208 | for (cp = dbp + 1; *cp && (isalpha (*cp) || isdigit (*cp) | 2175 | for (cp = dbp + 1; |
| 2209 | || (*cp == '_') || (*cp == '$')); cp++) | 2176 | (*cp |
| 2177 | && (isalpha (*cp) || isdigit (*cp) || (*cp == '_') || (*cp == '$'))); | ||
| 2178 | cp++) | ||
| 2210 | continue; | 2179 | continue; |
| 2211 | c = cp[0]; | 2180 | c = *cp; |
| 2212 | cp[0] = 0; | 2181 | *cp = '\0'; |
| 2213 | (void) strcpy (nambuf, dbp); | 2182 | (void) strcpy (nambuf, dbp); |
| 2214 | cp[0] = c; | 2183 | *cp = c; |
| 2215 | pfnote (nambuf, TRUE, FALSE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno); | 2184 | pfnote (nambuf, TRUE, FALSE, lb.buffer, |
| 2185 | cp - lb.buffer + 1, lineno, linecharno); | ||
| 2216 | pfcnt++; | 2186 | pfcnt++; |
| 2217 | } | 2187 | } |
| 2218 | 2188 | ||
| @@ -2240,7 +2210,7 @@ Asm_funcs (fi) | |||
| 2240 | ; | 2210 | ; |
| 2241 | 2211 | ||
| 2242 | if ((i > 0) && (c == ':')) | 2212 | if ((i > 0) && (c == ':')) |
| 2243 | getit (); | 2213 | getit (fi); |
| 2244 | } | 2214 | } |
| 2245 | } | 2215 | } |
| 2246 | 2216 | ||
| @@ -2999,10 +2969,10 @@ readline (linebuffer, stream) | |||
| 2999 | pend = buffer + linebuffer->size; | 2969 | pend = buffer + linebuffer->size; |
| 3000 | linebuffer->buffer = buffer; | 2970 | linebuffer->buffer = buffer; |
| 3001 | } | 2971 | } |
| 3002 | if (c < 0 || c == '\n') | 2972 | if (c == EOF || c == '\n') |
| 3003 | { | 2973 | { |
| 3004 | *p = 0; | 2974 | *p = 0; |
| 3005 | newline = (c == '\n' ? 1 : 0); | 2975 | newline = (c == '\n') ? 1 : 0; |
| 3006 | break; | 2976 | break; |
| 3007 | } | 2977 | } |
| 3008 | *p++ = c; | 2978 | *p++ = c; |
| @@ -3117,7 +3087,7 @@ concat (s1, s2, s3) | |||
| 3117 | 3087 | ||
| 3118 | char * | 3088 | char * |
| 3119 | xmalloc (size) | 3089 | xmalloc (size) |
| 3120 | int size; | 3090 | unsigned int size; |
| 3121 | { | 3091 | { |
| 3122 | char *result = malloc (size); | 3092 | char *result = malloc (size); |
| 3123 | if (!result) | 3093 | if (!result) |
| @@ -3128,7 +3098,7 @@ xmalloc (size) | |||
| 3128 | char * | 3098 | char * |
| 3129 | xrealloc (ptr, size) | 3099 | xrealloc (ptr, size) |
| 3130 | char *ptr; | 3100 | char *ptr; |
| 3131 | int size; | 3101 | unsigned int size; |
| 3132 | { | 3102 | { |
| 3133 | char *result = realloc (ptr, size); | 3103 | char *result = realloc (ptr, size); |
| 3134 | if (!result) | 3104 | if (!result) |