diff options
| author | Gerd Moellmann | 2001-10-01 07:25:14 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2001-10-01 07:25:14 +0000 |
| commit | 407094f443d71c6d481d830f1e186f9a6f08b58e (patch) | |
| tree | 14602ff54ce7b0e7e73eaf8f00ac0d9e5674bd31 /lib-src | |
| parent | e0c2126682d4bc2423642ee2399f09927f909054 (diff) | |
| download | emacs-407094f443d71c6d481d830f1e186f9a6f08b58e.tar.gz emacs-407094f443d71c6d481d830f1e186f9a6f08b58e.zip | |
(struct alias): Add two new struct members: NAMESP and
ALIASEE to help work with namespace aliases.
(struct sym): Remove struct member NAMESP_ALIASES.
(namespace_alias_table): New variable.
(make_namespace): Add parameter CONTEXT.
(check_namespace): New function.
(find_namespace): Add parameter CONTEXT.
(check_namespace_alias): New function.
(register_namespace_alias): Change type of parameter
OLD_NAME. Search for already defined alias in
NAMESPACE_ALIAS_TABLE.
(check_namespace): New function.
(enter_namespace): Call find_namespace with CONTEXT parameter.
(match_qualified_namespace_alias): New function.
(parse_qualified_ident_or_type): Fixed typo in comment. While
parsing qualified ident or type update namespace context and
restore it on exit.
(parse_qualified_param_ident_or_type): Fixed typo in comment.
(globals): Changed handling of namespace aliases.
(version): Added year 2001.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ebrowse.c | 175 |
1 files changed, 139 insertions, 36 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 38a9b65987c..34b02e3df4f 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c | |||
| @@ -279,6 +279,8 @@ struct link | |||
| 279 | struct alias | 279 | struct alias |
| 280 | { | 280 | { |
| 281 | struct alias *next; /* Next in list. */ | 281 | struct alias *next; /* Next in list. */ |
| 282 | struct sym *namesp; /* Namespace in which defined. */ | ||
| 283 | struct link *aliasee; /* List of aliased namespaces (A::B::C...). */ | ||
| 282 | char name[1]; /* Alias name. */ | 284 | char name[1]; /* Alias name. */ |
| 283 | }; | 285 | }; |
| 284 | 286 | ||
| @@ -303,7 +305,6 @@ struct sym | |||
| 303 | char *filename; /* File in which it can be found. */ | 305 | char *filename; /* File in which it can be found. */ |
| 304 | char *sfilename; /* File in which members can be found. */ | 306 | char *sfilename; /* File in which members can be found. */ |
| 305 | struct sym *namesp; /* Namespace in which defined. . */ | 307 | struct sym *namesp; /* Namespace in which defined. . */ |
| 306 | struct alias *namesp_aliases; /* List of aliases for namespaces. */ | ||
| 307 | char name[1]; /* Name of the class. */ | 308 | char name[1]; /* Name of the class. */ |
| 308 | }; | 309 | }; |
| 309 | 310 | ||
| @@ -420,6 +421,10 @@ struct sym *class_table[TABLE_SIZE]; | |||
| 420 | 421 | ||
| 421 | struct member *member_table[TABLE_SIZE]; | 422 | struct member *member_table[TABLE_SIZE]; |
| 422 | 423 | ||
| 424 | /* Hash table for namespace aliases */ | ||
| 425 | |||
| 426 | struct alias *namespace_alias_table[TABLE_SIZE]; | ||
| 427 | |||
| 423 | /* The special class symbol used to hold global functions, | 428 | /* The special class symbol used to hold global functions, |
| 424 | variables etc. */ | 429 | variables etc. */ |
| 425 | 430 | ||
| @@ -491,7 +496,7 @@ void add_define P_ ((char *, char *, int)); | |||
| 491 | void mark_inherited_virtual P_ ((void)); | 496 | void mark_inherited_virtual P_ ((void)); |
| 492 | void leave_namespace P_ ((void)); | 497 | void leave_namespace P_ ((void)); |
| 493 | void enter_namespace P_ ((char *)); | 498 | void enter_namespace P_ ((char *)); |
| 494 | void register_namespace_alias P_ ((char *, char *)); | 499 | void register_namespace_alias P_ ((char *, struct link *)); |
| 495 | void insert_keyword P_ ((char *, int)); | 500 | void insert_keyword P_ ((char *, int)); |
| 496 | void re_init_scanner P_ ((void)); | 501 | void re_init_scanner P_ ((void)); |
| 497 | void init_scanner P_ ((void)); | 502 | void init_scanner P_ ((void)); |
| @@ -508,7 +513,7 @@ struct member *find_member P_ ((struct sym *, char *, int, int, unsigned)); | |||
| 508 | struct member *add_member P_ ((struct sym *, char *, int, int, unsigned)); | 513 | struct member *add_member P_ ((struct sym *, char *, int, int, unsigned)); |
| 509 | void mark_virtual P_ ((struct sym *)); | 514 | void mark_virtual P_ ((struct sym *)); |
| 510 | void mark_virtual P_ ((struct sym *)); | 515 | void mark_virtual P_ ((struct sym *)); |
| 511 | struct sym *make_namespace P_ ((char *)); | 516 | struct sym *make_namespace P_ ((char *, struct sym *)); |
| 512 | char *sym_scope P_ ((struct sym *)); | 517 | char *sym_scope P_ ((struct sym *)); |
| 513 | char *sym_scope_1 P_ ((struct sym *)); | 518 | char *sym_scope_1 P_ ((struct sym *)); |
| 514 | int skip_to P_ ((int)); | 519 | int skip_to P_ ((int)); |
| @@ -1085,68 +1090,107 @@ mark_inherited_virtual () | |||
| 1085 | /* Create and return a symbol for a namespace with name NAME. */ | 1090 | /* Create and return a symbol for a namespace with name NAME. */ |
| 1086 | 1091 | ||
| 1087 | struct sym * | 1092 | struct sym * |
| 1088 | make_namespace (name) | 1093 | make_namespace (name, context) |
| 1089 | char *name; | 1094 | char *name; |
| 1095 | struct sym *context; | ||
| 1090 | { | 1096 | { |
| 1091 | struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name)); | 1097 | struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name)); |
| 1092 | bzero (s, sizeof *s); | 1098 | bzero (s, sizeof *s); |
| 1093 | strcpy (s->name, name); | 1099 | strcpy (s->name, name); |
| 1094 | s->next = all_namespaces; | 1100 | s->next = all_namespaces; |
| 1095 | s->namesp = current_namespace; | 1101 | s->namesp = context; |
| 1096 | all_namespaces = s; | 1102 | all_namespaces = s; |
| 1097 | return s; | 1103 | return s; |
| 1098 | } | 1104 | } |
| 1099 | 1105 | ||
| 1100 | 1106 | ||
| 1101 | /* Find the symbol for namespace NAME. If not found, add a new symbol | 1107 | /* Find the symbol for namespace NAME. If not found, retrun NULL */ |
| 1102 | for NAME to all_namespaces. */ | ||
| 1103 | 1108 | ||
| 1104 | struct sym * | 1109 | struct sym * |
| 1105 | find_namespace (name) | 1110 | check_namespace (name, context) |
| 1106 | char *name; | 1111 | char *name; |
| 1112 | struct sym *context; | ||
| 1107 | { | 1113 | { |
| 1108 | struct sym *p; | 1114 | struct sym *p = NULL; |
| 1109 | 1115 | ||
| 1110 | for (p = all_namespaces; p; p = p->next) | 1116 | for (p = all_namespaces; p; p = p->next) |
| 1111 | { | 1117 | { |
| 1112 | if (streq (p->name, name)) | 1118 | if (streq (p->name, name) && (p->namesp == context)) |
| 1113 | break; | ||
| 1114 | else | ||
| 1115 | { | ||
| 1116 | struct alias *p2; | ||
| 1117 | for (p2 = p->namesp_aliases; p2; p2 = p2->next) | ||
| 1118 | if (streq (p2->name, name)) | ||
| 1119 | break; | ||
| 1120 | if (p2) | ||
| 1121 | break; | 1119 | break; |
| 1122 | } | 1120 | } |
| 1121 | |||
| 1122 | return p; | ||
| 1123 | } | 1123 | } |
| 1124 | 1124 | ||
| 1125 | /* Find the symbol for namespace NAME. If not found, add a new symbol | ||
| 1126 | for NAME to all_namespaces. */ | ||
| 1127 | |||
| 1128 | struct sym * | ||
| 1129 | find_namespace (name, context) | ||
| 1130 | char *name; | ||
| 1131 | struct sym *context; | ||
| 1132 | { | ||
| 1133 | struct sym *p = check_namespace (name, context); | ||
| 1134 | |||
| 1125 | if (p == NULL) | 1135 | if (p == NULL) |
| 1126 | p = make_namespace (name); | 1136 | p = make_namespace (name, context); |
| 1127 | 1137 | ||
| 1128 | return p; | 1138 | return p; |
| 1129 | } | 1139 | } |
| 1130 | 1140 | ||
| 1131 | 1141 | ||
| 1132 | /* Register the name NEW_NAME as an alias for namespace OLD_NAME. */ | 1142 | /* Find namespace alias with name NAME. If not found return NULL. */ |
| 1143 | |||
| 1144 | struct link * | ||
| 1145 | check_namespace_alias (name) | ||
| 1146 | char *name; | ||
| 1147 | { | ||
| 1148 | struct link *p = NULL; | ||
| 1149 | struct alias *al; | ||
| 1150 | unsigned h; | ||
| 1151 | char *s; | ||
| 1152 | |||
| 1153 | for (s = name, h = 0; *s; ++s) | ||
| 1154 | h = (h << 1) ^ *s; | ||
| 1155 | h %= TABLE_SIZE; | ||
| 1156 | |||
| 1157 | for (al = namespace_alias_table[h]; al; al = al->next) | ||
| 1158 | if (streq (name, al->name) && (al->namesp == current_namespace)) | ||
| 1159 | { | ||
| 1160 | p = al->aliasee; | ||
| 1161 | break; | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | return p; | ||
| 1165 | } | ||
| 1166 | |||
| 1167 | /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */ | ||
| 1133 | 1168 | ||
| 1134 | void | 1169 | void |
| 1135 | register_namespace_alias (new_name, old_name) | 1170 | register_namespace_alias (new_name, old_name) |
| 1136 | char *new_name, *old_name; | 1171 | char *new_name; |
| 1172 | struct link *old_name; | ||
| 1137 | { | 1173 | { |
| 1138 | struct sym *p = find_namespace (old_name); | 1174 | unsigned h; |
| 1175 | char *s; | ||
| 1139 | struct alias *al; | 1176 | struct alias *al; |
| 1140 | 1177 | ||
| 1141 | /* Is it already in the list of aliases? */ | 1178 | for (s = new_name, h = 0; *s; ++s) |
| 1142 | for (al = p->namesp_aliases; al; al = al->next) | 1179 | h = (h << 1) ^ *s; |
| 1143 | if (streq (new_name, p->name)) | 1180 | h %= TABLE_SIZE; |
| 1181 | |||
| 1182 | |||
| 1183 | /* Is it already in the table of aliases? */ | ||
| 1184 | for (al = namespace_alias_table[h]; al; al = al->next) | ||
| 1185 | if (streq (new_name, al->name) && (al->namesp == current_namespace)) | ||
| 1144 | return; | 1186 | return; |
| 1145 | 1187 | ||
| 1146 | al = (struct alias *) xmalloc (sizeof *al + strlen (new_name)); | 1188 | al = (struct alias *) xmalloc (sizeof *al + strlen (new_name)); |
| 1147 | strcpy (al->name, new_name); | 1189 | strcpy (al->name, new_name); |
| 1148 | al->next = p->namesp_aliases; | 1190 | al->next = namespace_alias_table[h]; |
| 1149 | p->namesp_aliases = al; | 1191 | al->namesp = current_namespace; |
| 1192 | al->aliasee = old_name; | ||
| 1193 | namespace_alias_table[h] = al; | ||
| 1150 | } | 1194 | } |
| 1151 | 1195 | ||
| 1152 | 1196 | ||
| @@ -1156,7 +1200,7 @@ void | |||
| 1156 | enter_namespace (name) | 1200 | enter_namespace (name) |
| 1157 | char *name; | 1201 | char *name; |
| 1158 | { | 1202 | { |
| 1159 | struct sym *p = find_namespace (name); | 1203 | struct sym *p = find_namespace (name, current_namespace); |
| 1160 | 1204 | ||
| 1161 | if (namespace_sp == namespace_stack_size) | 1205 | if (namespace_sp == namespace_stack_size) |
| 1162 | { | 1206 | { |
| @@ -2329,7 +2373,6 @@ skip_to (token) | |||
| 2329 | return tk; | 2373 | return tk; |
| 2330 | } | 2374 | } |
| 2331 | 2375 | ||
| 2332 | |||
| 2333 | /* Skip over pairs of tokens (parentheses, square brackets, | 2376 | /* Skip over pairs of tokens (parentheses, square brackets, |
| 2334 | angle brackets, curly brackets) matching the current lookahead. */ | 2377 | angle brackets, curly brackets) matching the current lookahead. */ |
| 2335 | 2378 | ||
| @@ -2377,6 +2420,43 @@ skip_matching () | |||
| 2377 | } | 2420 | } |
| 2378 | 2421 | ||
| 2379 | 2422 | ||
| 2423 | /* Build qualified namespace alias (A::B::c) and return it. */ | ||
| 2424 | |||
| 2425 | struct link * | ||
| 2426 | match_qualified_namespace_alias () | ||
| 2427 | { | ||
| 2428 | struct link *head = NULL; | ||
| 2429 | struct link *cur = NULL; | ||
| 2430 | struct link *tmp = NULL; | ||
| 2431 | |||
| 2432 | for (;;) | ||
| 2433 | { | ||
| 2434 | MATCH (); | ||
| 2435 | switch (LA1) | ||
| 2436 | { | ||
| 2437 | case IDENT: | ||
| 2438 | tmp = (struct link *) xmalloc (sizeof *cur); | ||
| 2439 | tmp->sym = find_namespace (yytext, cur); | ||
| 2440 | tmp->next = NULL; | ||
| 2441 | if (head) | ||
| 2442 | { | ||
| 2443 | cur = cur->next = tmp; | ||
| 2444 | } | ||
| 2445 | else | ||
| 2446 | { | ||
| 2447 | head = cur = tmp; | ||
| 2448 | } | ||
| 2449 | break; | ||
| 2450 | case DCOLON: | ||
| 2451 | /* Just skip */ | ||
| 2452 | break; | ||
| 2453 | default: | ||
| 2454 | return head; | ||
| 2455 | break; | ||
| 2456 | } | ||
| 2457 | } | ||
| 2458 | } | ||
| 2459 | |||
| 2380 | /* Re-initialize the parser by resetting the lookahead token. */ | 2460 | /* Re-initialize the parser by resetting the lookahead token. */ |
| 2381 | 2461 | ||
| 2382 | void | 2462 | void |
| @@ -2913,7 +2993,7 @@ operator_name (sc) | |||
| 2913 | 2993 | ||
| 2914 | 2994 | ||
| 2915 | /* This one consumes the last IDENT of a qualified member name like | 2995 | /* This one consumes the last IDENT of a qualified member name like |
| 2916 | `X::Y::z'. This IDENT is returned in LAST_ID. Value if the | 2996 | `X::Y::z'. This IDENT is returned in LAST_ID. Value is the |
| 2917 | symbol structure for the ident. */ | 2997 | symbol structure for the ident. */ |
| 2918 | 2998 | ||
| 2919 | struct sym * | 2999 | struct sym * |
| @@ -2923,6 +3003,7 @@ parse_qualified_ident_or_type (last_id) | |||
| 2923 | struct sym *cls = NULL; | 3003 | struct sym *cls = NULL; |
| 2924 | char *id = NULL; | 3004 | char *id = NULL; |
| 2925 | size_t id_size = 0; | 3005 | size_t id_size = 0; |
| 3006 | int enter = 0; | ||
| 2926 | 3007 | ||
| 2927 | while (LOOKING_AT (IDENT)) | 3008 | while (LOOKING_AT (IDENT)) |
| 2928 | { | 3009 | { |
| @@ -2940,7 +3021,26 @@ parse_qualified_ident_or_type (last_id) | |||
| 2940 | 3021 | ||
| 2941 | if (LOOKING_AT (DCOLON)) | 3022 | if (LOOKING_AT (DCOLON)) |
| 2942 | { | 3023 | { |
| 2943 | cls = add_sym (id, cls); | 3024 | struct sym *pcn = NULL; |
| 3025 | struct link *pna = check_namespace_alias (id); | ||
| 3026 | if (pna) | ||
| 3027 | { | ||
| 3028 | do | ||
| 3029 | { | ||
| 3030 | enter_namespace (pna->sym->name); | ||
| 3031 | enter++; | ||
| 3032 | pna = pna->next; | ||
| 3033 | } | ||
| 3034 | while (pna); | ||
| 3035 | } | ||
| 3036 | else if ((pcn = check_namespace (id, current_namespace))) | ||
| 3037 | { | ||
| 3038 | enter_namespace (pcn->name); | ||
| 3039 | enter++; | ||
| 3040 | } | ||
| 3041 | else | ||
| 3042 | cls = add_sym (id, cls); | ||
| 3043 | |||
| 2944 | *last_id = NULL; | 3044 | *last_id = NULL; |
| 2945 | xfree (id); | 3045 | xfree (id); |
| 2946 | id = NULL; | 3046 | id = NULL; |
| @@ -2951,12 +3051,15 @@ parse_qualified_ident_or_type (last_id) | |||
| 2951 | break; | 3051 | break; |
| 2952 | } | 3052 | } |
| 2953 | 3053 | ||
| 3054 | while (enter--) | ||
| 3055 | leave_namespace(); | ||
| 3056 | |||
| 2954 | return cls; | 3057 | return cls; |
| 2955 | } | 3058 | } |
| 2956 | 3059 | ||
| 2957 | 3060 | ||
| 2958 | /* This one consumes the last IDENT of a qualified member name like | 3061 | /* This one consumes the last IDENT of a qualified member name like |
| 2959 | `X::Y::z'. This IDENT is returned in LAST_ID. Value if the | 3062 | `X::Y::z'. This IDENT is returned in LAST_ID. Value is the |
| 2960 | symbol structure for the ident. */ | 3063 | symbol structure for the ident. */ |
| 2961 | 3064 | ||
| 2962 | void | 3065 | void |
| @@ -3310,9 +3413,9 @@ globals (start_flags) | |||
| 3310 | 3413 | ||
| 3311 | if (LOOKING_AT ('=')) | 3414 | if (LOOKING_AT ('=')) |
| 3312 | { | 3415 | { |
| 3313 | MATCH (); | 3416 | struct link *qna = match_qualified_namespace_alias (); |
| 3314 | if (LOOKING_AT (IDENT)) | 3417 | if (qna) |
| 3315 | register_namespace_alias (namespace_name, yytext); | 3418 | register_namespace_alias (namespace_name, qna); |
| 3316 | 3419 | ||
| 3317 | if (skip_to (';') == ';') | 3420 | if (skip_to (';') == ';') |
| 3318 | MATCH (); | 3421 | MATCH (); |
| @@ -3536,7 +3639,7 @@ void | |||
| 3536 | version () | 3639 | version () |
| 3537 | { | 3640 | { |
| 3538 | printf ("ebrowse %s\n", VERSION); | 3641 | printf ("ebrowse %s\n", VERSION); |
| 3539 | puts ("Copyright (C) 1992-1999, 2000 Free Software Foundation, Inc."); | 3642 | puts ("Copyright (C) 1992-1999, 2000, 2001 Free Software Foundation, Inc."); |
| 3540 | puts ("This program is distributed under the same terms as Emacs."); | 3643 | puts ("This program is distributed under the same terms as Emacs."); |
| 3541 | exit (0); | 3644 | exit (0); |
| 3542 | } | 3645 | } |