1
|
1 // Symbol table classes. -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 // Don't even think about moving the tree.h include to symtab.h... |
|
29 |
|
30 #include "symtab.h" |
|
31 #include "error.h" |
|
32 #include "variables.h" |
|
33 #include "utils.h" |
|
34 #include "tree.h" |
|
35 #include "tree-const.h" |
|
36 |
|
37 /* |
|
38 * Variables and functions. |
|
39 */ |
|
40 symbol_def::symbol_def (void) |
|
41 { |
|
42 help_string = (char *) NULL; |
|
43 type = unknown_type; |
|
44 lifespan = temporary; |
|
45 sym_class = read_write; |
|
46 definition = (tree *) NULL; |
|
47 } |
|
48 |
|
49 symbol_def::symbol_def (tree_constant *t) |
|
50 { |
|
51 help_string = (char *) NULL; |
|
52 type = variable; |
|
53 lifespan = temporary; |
|
54 sym_class = read_write; |
|
55 definition = t; |
|
56 } |
|
57 |
|
58 symbol_def::symbol_def (tree_builtin *t) |
|
59 { |
|
60 help_string = (char *) NULL; |
|
61 type = builtin_function; |
|
62 lifespan = temporary; |
|
63 sym_class = read_write; |
|
64 definition = t; |
|
65 } |
|
66 |
|
67 symbol_def::symbol_def (tree_function *t) |
|
68 { |
|
69 help_string = (char *) NULL; |
|
70 type = user_function; |
|
71 lifespan = temporary; |
|
72 sym_class = read_write; |
|
73 definition = t; |
|
74 } |
|
75 |
|
76 symbol_def::~symbol_def (void) |
|
77 { |
|
78 delete [] help_string; |
|
79 delete definition; |
|
80 } |
|
81 |
|
82 void |
|
83 symbol_def::define (tree_constant *t) |
|
84 { |
|
85 definition = t; |
|
86 type = variable; |
|
87 } |
|
88 |
|
89 void |
|
90 symbol_def::define (tree_builtin *t) |
|
91 { |
|
92 definition = t; |
|
93 type = builtin_function; |
|
94 } |
|
95 |
|
96 void |
|
97 symbol_def::define (tree_function *t) |
|
98 { |
|
99 definition = t; |
|
100 type = user_function; |
|
101 } |
|
102 |
|
103 tree * |
164
|
104 symbol_def::def (void) const |
1
|
105 { |
|
106 return definition; |
|
107 } |
|
108 |
|
109 char * |
164
|
110 symbol_def::help (void) const |
1
|
111 { |
|
112 return help_string; |
|
113 } |
|
114 |
|
115 void |
164
|
116 symbol_def::document (const char *h) |
1
|
117 { |
|
118 delete [] help_string; |
|
119 help_string = strsave (h); |
|
120 } |
|
121 |
|
122 int |
|
123 symbol_def::save (ostream& os, int mark_as_global) |
|
124 { |
|
125 return definition->save (os, mark_as_global); |
|
126 } |
|
127 |
|
128 /* |
|
129 * Individual records in a symbol table. |
|
130 */ |
|
131 symbol_record::symbol_record (void) |
|
132 { |
|
133 nm = (char *) NULL; |
|
134 formal_param = 0; |
122
|
135 forced_global = 0; |
1
|
136 var = (symbol_def *) NULL; |
|
137 fcn = (symbol_def *) NULL; |
|
138 sv_fcn = (sv_Function) NULL; |
|
139 next_elem = (symbol_record *) NULL; |
|
140 } |
|
141 |
164
|
142 symbol_record::symbol_record (const char *n) |
1
|
143 { |
|
144 nm = strsave (n); |
|
145 formal_param = 0; |
122
|
146 forced_global = 0; |
1
|
147 var = (symbol_def *) NULL; |
|
148 fcn = (symbol_def *) NULL; |
|
149 sv_fcn = (sv_Function) NULL; |
|
150 next_elem = (symbol_record *) NULL; |
|
151 } |
|
152 |
164
|
153 symbol_record::symbol_record (const char *n, symbol_record *nxt) |
1
|
154 { |
|
155 nm = strsave (n); |
|
156 formal_param = 0; |
122
|
157 forced_global = 0; |
1
|
158 var = (symbol_def *) NULL; |
|
159 fcn = (symbol_def *) NULL; |
|
160 sv_fcn = (sv_Function) NULL; |
|
161 next_elem = nxt; |
|
162 } |
|
163 |
|
164 symbol_record::~symbol_record (void) |
|
165 { |
|
166 delete [] nm; |
|
167 |
|
168 if (var != (symbol_def *) NULL && --var->count <= 0) |
|
169 delete var; |
|
170 |
|
171 if (fcn != (symbol_def *) NULL && --fcn->count <= 0) |
|
172 delete fcn; |
|
173 } |
|
174 |
|
175 char * |
164
|
176 symbol_record::name (void) const |
1
|
177 { |
|
178 return nm; |
|
179 } |
|
180 |
|
181 char * |
164
|
182 symbol_record::help (void) const |
1
|
183 { |
|
184 if (var != (symbol_def *) NULL) |
|
185 return var->help (); |
|
186 else if (fcn != (symbol_def *) NULL) |
|
187 return fcn->help (); |
|
188 else |
|
189 return (char *) NULL; |
|
190 } |
|
191 |
|
192 tree * |
164
|
193 symbol_record::def (void) const |
1
|
194 { |
|
195 if (var != (symbol_def *) NULL) |
|
196 return var->def (); |
|
197 else if (fcn != (symbol_def *) NULL) |
|
198 return fcn->def (); |
|
199 else |
|
200 return (tree *) NULL; |
|
201 } |
|
202 |
|
203 int |
164
|
204 symbol_record::is_function (void) const |
1
|
205 { |
|
206 return (var == (symbol_def *) NULL && fcn != (symbol_def *) NULL); |
|
207 } |
|
208 |
|
209 int |
164
|
210 symbol_record::is_variable (void) const |
1
|
211 { |
|
212 return (var != (symbol_def *) NULL); |
|
213 } |
|
214 |
|
215 int |
164
|
216 symbol_record::is_defined (void) const |
1
|
217 { |
|
218 return (var != (symbol_def *) NULL || fcn != (symbol_def *) NULL); |
|
219 } |
|
220 |
|
221 void |
|
222 symbol_record::set_sv_function (sv_Function f) |
|
223 { |
|
224 sv_fcn = f; |
|
225 } |
|
226 |
|
227 int |
|
228 symbol_record::var_read_only (void) |
|
229 { |
|
230 if (var != (symbol_def *) NULL |
|
231 && var->sym_class == symbol_def::read_only) |
|
232 { |
|
233 error ("can't assign to read only symbol `%s'", nm); |
|
234 return 1; |
|
235 } |
|
236 else |
|
237 return 0; |
|
238 } |
|
239 |
|
240 int |
|
241 symbol_record::read_only (void) |
|
242 { |
|
243 if ((var != (symbol_def *) NULL |
|
244 && var->sym_class == symbol_def::read_only) |
|
245 || (fcn != (symbol_def *) NULL |
|
246 && fcn->sym_class == symbol_def::read_only)) |
|
247 { |
|
248 error ("can't assign to read only symbol `%s'", nm); |
|
249 return 1; |
|
250 } |
|
251 else |
|
252 return 0; |
|
253 } |
|
254 |
|
255 int |
|
256 symbol_record::define (tree_constant *t) |
|
257 { |
|
258 if (var_read_only ()) |
|
259 return 0; |
|
260 |
|
261 tree_constant *saved_def = NULL_TREE_CONST; |
|
262 |
|
263 if (var != (symbol_def *) NULL) |
|
264 { |
|
265 saved_def = (tree_constant *) var->def (); // XXX FIXME XXX |
|
266 var->define (t); |
|
267 } |
|
268 else |
|
269 { |
|
270 var = new symbol_def (t); |
|
271 var->count = 1; |
|
272 } |
|
273 |
|
274 if (sv_fcn != (sv_Function) NULL && sv_fcn () < 0) |
|
275 { |
|
276 var->define (saved_def); |
|
277 delete t; |
|
278 return 0; |
|
279 } |
|
280 |
|
281 delete saved_def; |
|
282 |
|
283 return 1; |
|
284 } |
|
285 |
|
286 int |
|
287 symbol_record::define (tree_builtin *t) |
|
288 { |
|
289 if (read_only ()) |
|
290 return 0; |
|
291 |
|
292 if (var != (symbol_def *) NULL) |
|
293 { |
|
294 if (--var->count <= 0) |
|
295 delete var; |
|
296 var = (symbol_def *) NULL; |
|
297 } |
|
298 |
|
299 if (fcn != (symbol_def *) NULL) |
|
300 fcn->define (t); |
|
301 else |
|
302 { |
|
303 fcn = new symbol_def (t); |
|
304 fcn->count = 1; |
|
305 } |
|
306 |
|
307 return 1; |
|
308 } |
|
309 |
|
310 int |
|
311 symbol_record::define (tree_function *t) |
|
312 { |
|
313 if (read_only ()) |
|
314 return 0; |
|
315 |
|
316 if (var != (symbol_def *) NULL) |
|
317 { |
|
318 if (--var->count <= 0) |
|
319 delete var; |
|
320 var = (symbol_def *) NULL; |
|
321 } |
|
322 |
|
323 if (fcn != (symbol_def *) NULL) |
|
324 fcn->define (t); |
|
325 else |
|
326 { |
|
327 fcn = new symbol_def (t); |
|
328 fcn->count = 1; |
|
329 } |
|
330 |
|
331 return 1; |
|
332 } |
|
333 |
|
334 int |
|
335 symbol_record::define_as_fcn (tree_constant *t) |
|
336 { |
|
337 if (read_only ()) |
|
338 return 0; |
|
339 |
|
340 if (var != (symbol_def *) NULL) |
|
341 { |
|
342 if (--var->count <= 0) |
|
343 delete var; |
|
344 var = (symbol_def *) NULL; |
|
345 } |
|
346 |
|
347 if (fcn != (symbol_def *) NULL) |
|
348 fcn->define (t); |
|
349 else |
|
350 { |
|
351 fcn = new symbol_def (t); |
|
352 fcn->count = 1; |
|
353 } |
|
354 |
|
355 return 1; |
|
356 } |
|
357 |
|
358 void |
164
|
359 symbol_record::document (const char *h) |
1
|
360 { |
|
361 if (var != (symbol_def *) NULL) |
|
362 var->document (h); |
|
363 else if (fcn != (symbol_def *) NULL) |
|
364 fcn->document (h); |
|
365 else |
|
366 warning ("couldn't document undefined variable `%s'", nm); |
|
367 } |
|
368 |
|
369 void |
|
370 symbol_record::protect (void) |
|
371 { |
|
372 if (var != (symbol_def *) NULL) |
|
373 var->sym_class = symbol_def::read_only; |
|
374 else if (fcn != (symbol_def *) NULL) |
|
375 fcn->sym_class = symbol_def::read_only; |
|
376 else |
|
377 warning ("couldn't protect undefined variable `%s'", nm); |
|
378 } |
|
379 |
|
380 void |
|
381 symbol_record::unprotect (void) |
|
382 { |
|
383 if (var != (symbol_def *) NULL) |
|
384 var->sym_class = symbol_def::read_write; |
|
385 else if (fcn != (symbol_def *) NULL) |
|
386 fcn->sym_class = symbol_def::read_write; |
|
387 } |
|
388 |
|
389 void |
|
390 symbol_record::make_eternal (void) |
|
391 { |
|
392 if (var != (symbol_def *) NULL) |
|
393 var->lifespan = symbol_def::eternal; |
|
394 else if (fcn != (symbol_def *) NULL) |
|
395 fcn->lifespan = symbol_def::eternal; |
|
396 else |
|
397 warning ("couldn't give eternal life to the variable `%s'", nm); |
|
398 } |
|
399 |
|
400 int |
|
401 symbol_record::save (ostream& os, int mark_as_global = 0) |
|
402 { |
|
403 int status = 0; |
|
404 |
|
405 if (var != (symbol_def *) NULL && var->def () != (tree *) NULL) |
|
406 { |
|
407 // For now, eternal implies builtin. |
|
408 if (var->lifespan != symbol_def::eternal) |
|
409 { |
|
410 // Should we also save the help string? Maybe someday. |
|
411 os << "# name: " << nm << "\n"; |
|
412 status = var->save (os, mark_as_global); |
|
413 } |
|
414 } |
|
415 else if (fcn != (symbol_def *) NULL) |
|
416 message ("save", "sorry, can't save functions yet"); |
|
417 else |
111
|
418 { |
|
419 // Kludge! We probably don't want to print warnings for ans, but it |
|
420 // does seem reasonable to print them for other undefined variables. |
|
421 if (strcmp (nm, "ans") != 0) |
|
422 warning ("not saving undefined symbol `%s'", nm); |
|
423 } |
1
|
424 |
|
425 return status; |
|
426 } |
|
427 |
|
428 void |
|
429 symbol_record::clear_visible (void) |
|
430 { |
|
431 if (var != (symbol_def *) NULL && var->lifespan != symbol_def::eternal) |
|
432 { |
|
433 if (--var->count <= 0) |
|
434 delete var; |
|
435 var = (symbol_def *) NULL; |
122
|
436 forced_global = 0; |
1
|
437 } |
|
438 else if (fcn != (symbol_def *) NULL && fcn->lifespan != symbol_def::eternal) |
|
439 { |
|
440 if (--fcn->count <= 0) |
|
441 delete fcn; |
|
442 fcn = (symbol_def *) NULL; |
|
443 } |
|
444 } |
|
445 |
|
446 void |
|
447 symbol_record::clear_all (void) |
|
448 { |
|
449 if (var != (symbol_def *) NULL && var->lifespan != symbol_def::eternal) |
|
450 { |
|
451 if (--var->count <= 0) |
|
452 delete var; |
|
453 var = (symbol_def *) NULL; |
122
|
454 forced_global = 0; |
1
|
455 } |
|
456 |
|
457 if (fcn != (symbol_def *) NULL && fcn->lifespan != symbol_def::eternal) |
|
458 { |
|
459 if (--fcn->count <= 0) |
|
460 delete fcn; |
|
461 fcn = (symbol_def *) NULL; |
|
462 } |
|
463 } |
|
464 |
|
465 void |
|
466 symbol_record::mark_as_formal_parameter (void) |
|
467 { |
|
468 formal_param = 1; |
|
469 } |
|
470 |
|
471 int |
164
|
472 symbol_record::is_formal_parameter (void) const |
1
|
473 { |
|
474 return formal_param; |
|
475 } |
|
476 |
|
477 void |
122
|
478 symbol_record::mark_as_forced_global (void) |
|
479 { |
|
480 forced_global = 1; |
|
481 } |
|
482 |
|
483 int |
164
|
484 symbol_record::is_forced_global (void) const |
122
|
485 { |
|
486 return forced_global; |
|
487 } |
|
488 |
|
489 void |
1
|
490 symbol_record::alias (symbol_record *s, int force = 0) |
|
491 { |
|
492 sv_fcn = s->sv_fcn; // Maybe this should go in the var symbol_def? |
|
493 |
|
494 formal_param = s->formal_param; // Hmm. |
122
|
495 forced_global = s->forced_global; // Hmm. |
1
|
496 |
|
497 if (force && s->var == (symbol_def *) NULL |
|
498 && s->fcn == (symbol_def *) NULL) |
|
499 { |
|
500 s->var = new symbol_def (); |
|
501 var = s->var; |
|
502 var->count = 2; // Yes, this is correct. |
|
503 return; |
|
504 } |
|
505 |
|
506 if (s->var != (symbol_def *) NULL) |
|
507 { |
|
508 var = s->var; |
|
509 var->count++; |
|
510 } |
|
511 else if (s->fcn != (symbol_def *) NULL) |
|
512 { |
|
513 fcn = s->fcn; |
|
514 fcn->count++; |
|
515 } |
|
516 } |
|
517 |
|
518 symbol_record * |
164
|
519 symbol_record::next (void) const |
1
|
520 { |
|
521 return next_elem; |
|
522 } |
|
523 |
|
524 /* |
|
525 * A symbol table. |
|
526 */ |
|
527 |
|
528 symbol_table::symbol_table (void) |
|
529 { |
|
530 } |
|
531 |
|
532 symbol_record * |
164
|
533 symbol_table::lookup (const char *nm, int insert = 0, int warn = 0) |
1
|
534 { |
|
535 int index = hash (nm) & HASH_MASK; |
|
536 |
|
537 symbol_record *ptr = table[index].next (); |
|
538 |
|
539 while (ptr != (symbol_record *) NULL) |
|
540 { |
|
541 if (strcmp (ptr->name (), nm) == 0) |
|
542 return ptr; |
|
543 ptr = ptr->next (); |
|
544 } |
|
545 |
|
546 if (insert) |
|
547 { |
|
548 symbol_record *new_sym; |
|
549 new_sym = new symbol_record (nm, table[index].next ()); |
|
550 table[index].next_elem = new_sym; |
|
551 return new_sym; |
|
552 } |
|
553 else if (warn) |
|
554 message ("lookup", "symbol`%s' not found", nm); |
|
555 |
|
556 return (symbol_record *) NULL; |
|
557 } |
|
558 |
|
559 void |
|
560 symbol_table::clear (void) |
|
561 { |
|
562 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
563 { |
169
|
564 symbol_record *ptr = table[i].next (); |
1
|
565 |
169
|
566 while (ptr != (symbol_record *) NULL) |
|
567 { |
|
568 ptr->clear_all (); |
|
569 ptr = ptr->next (); |
1
|
570 } |
|
571 } |
|
572 } |
|
573 |
|
574 int |
164
|
575 symbol_table::clear (const char *nm) |
1
|
576 { |
|
577 int index = hash (nm) & HASH_MASK; |
|
578 |
|
579 symbol_record *prev = &table[index]; |
|
580 symbol_record *curr = prev->next (); |
|
581 |
|
582 while (curr != (symbol_record *) NULL) |
|
583 { |
|
584 if (strcmp (curr->name (), nm) == 0) |
|
585 { |
|
586 curr->clear_visible (); |
|
587 |
|
588 return 1; |
|
589 } |
|
590 prev = curr; |
|
591 curr = curr->next (); |
|
592 } |
|
593 |
|
594 return 0; |
|
595 } |
|
596 |
|
597 // Ugh. |
|
598 |
|
599 void |
|
600 symbol_table::bind_globals (void) |
|
601 { |
|
602 assert (this != global_sym_tab); |
|
603 |
|
604 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
605 { |
|
606 symbol_record *ptr = table[i].next (); |
|
607 |
|
608 while (ptr != (symbol_record *) NULL && ! ptr->formal_param) |
|
609 { |
|
610 char *nm = ptr->name (); |
|
611 symbol_record *sr = global_sym_tab->lookup (nm, 0, 0); |
|
612 if (sr != (symbol_record *) NULL) |
|
613 ptr->alias (sr, 1); |
|
614 ptr = ptr->next (); |
|
615 } |
|
616 } |
|
617 } |
|
618 |
|
619 int |
|
620 symbol_table::save (ostream& os, int mark_as_global = 0) |
|
621 { |
|
622 int status = 0; |
111
|
623 char **names = sorted_var_list (); |
|
624 if (names != (char **) NULL) |
1
|
625 { |
111
|
626 while (*names != (char *) NULL) |
|
627 { |
|
628 if (save (os, *names, mark_as_global)) |
|
629 status++; |
|
630 |
|
631 names++; |
|
632 } |
1
|
633 } |
|
634 return status; |
|
635 } |
|
636 |
|
637 int |
164
|
638 symbol_table::save (ostream& os, const char *name, int mark_as_global = 0) |
1
|
639 { |
|
640 int status = 0; |
|
641 symbol_record *sr = lookup (name, 0, 0); |
|
642 if (sr != (symbol_record *) NULL) |
|
643 status = sr->save (os, mark_as_global); |
|
644 return status; |
|
645 } |
|
646 |
|
647 int |
164
|
648 symbol_table::size (void) const |
1
|
649 { |
|
650 int count = 0; |
|
651 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
652 { |
|
653 symbol_record *ptr = table[i].next (); |
|
654 while (ptr != (symbol_record *) NULL) |
|
655 { |
|
656 count++; |
|
657 ptr = ptr->next (); |
|
658 } |
|
659 } |
|
660 return count; |
|
661 } |
|
662 |
|
663 char ** |
164
|
664 symbol_table::list (void) const |
1
|
665 { |
|
666 int count; |
|
667 return list (count); |
|
668 } |
|
669 |
|
670 char ** |
164
|
671 symbol_table::var_list (void) const |
1
|
672 { |
|
673 int count; |
|
674 return var_list (count); |
|
675 } |
|
676 |
|
677 char ** |
164
|
678 symbol_table::fcn_list (void) const |
1
|
679 { |
|
680 int count; |
|
681 return fcn_list (count); |
|
682 } |
|
683 |
|
684 char ** |
164
|
685 symbol_table::list (int& count) const |
1
|
686 { |
115
|
687 count = 0; |
1
|
688 int n = size (); |
|
689 if (n == 0) |
|
690 return (char **) NULL; |
|
691 |
|
692 char **symbols = new char * [n+1]; |
|
693 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
694 { |
|
695 symbol_record *ptr = table[i].next (); |
|
696 while (ptr != (symbol_record *) NULL) |
|
697 { |
|
698 assert (count < n); |
|
699 symbols[count++] = strsave (ptr->name ()); |
|
700 ptr = ptr->next (); |
|
701 } |
|
702 } |
|
703 symbols[count] = (char *) NULL; |
|
704 return symbols; |
|
705 } |
|
706 |
|
707 char ** |
164
|
708 symbol_table::var_list (int& count) const |
1
|
709 { |
115
|
710 count = 0; |
1
|
711 int n = size (); |
|
712 if (n == 0) |
|
713 return (char **) NULL; |
|
714 |
|
715 char **symbols = new char * [n+1]; |
|
716 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
717 { |
|
718 symbol_record *ptr = table[i].next (); |
|
719 while (ptr != (symbol_record *) NULL) |
|
720 { |
|
721 assert (count < n); |
|
722 if (ptr->is_variable ()) |
|
723 symbols[count++] = strsave (ptr->name ()); |
|
724 ptr = ptr->next (); |
|
725 } |
|
726 } |
|
727 symbols[count] = (char *) NULL; |
|
728 return symbols; |
|
729 } |
|
730 |
|
731 char ** |
164
|
732 symbol_table::fcn_list (int& count) const |
1
|
733 { |
115
|
734 count = 0; |
1
|
735 int n = size (); |
|
736 if (n == 0) |
|
737 return (char **) NULL; |
|
738 |
|
739 char **symbols = new char * [n+1]; |
|
740 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
|
741 { |
|
742 symbol_record *ptr = table[i].next (); |
|
743 while (ptr != (symbol_record *) NULL) |
|
744 { |
|
745 assert (count < n); |
|
746 if (ptr->is_function ()) |
|
747 symbols[count++] = strsave (ptr->name ()); |
|
748 ptr = ptr->next (); |
|
749 } |
|
750 } |
|
751 symbols[count] = (char *) NULL; |
|
752 return symbols; |
|
753 } |
|
754 |
|
755 static inline int |
|
756 pstrcmp (char **a, char **b) |
|
757 { |
|
758 return strcmp (*a, *b); |
|
759 } |
|
760 |
|
761 char ** |
164
|
762 symbol_table::sorted_list (void) const |
1
|
763 { |
|
764 int count = 0; |
|
765 return sorted_list (count); |
|
766 } |
|
767 |
|
768 char ** |
164
|
769 symbol_table::sorted_var_list (void) const |
1
|
770 { |
|
771 int count = 0; |
|
772 return sorted_var_list (count); |
|
773 } |
|
774 |
|
775 char ** |
164
|
776 symbol_table::sorted_fcn_list (void) const |
1
|
777 { |
|
778 int count = 0; |
|
779 return sorted_fcn_list (count); |
|
780 } |
|
781 |
|
782 char ** |
164
|
783 symbol_table::sorted_list (int& count) const |
1
|
784 { |
|
785 char **symbols = list (count); |
|
786 if (symbols != (char **) NULL) |
|
787 qsort ((void **) symbols, count, sizeof (char *), |
|
788 (int (*)(void*, void*)) pstrcmp); |
|
789 return symbols; |
|
790 } |
|
791 |
|
792 char ** |
164
|
793 symbol_table::sorted_var_list (int& count) const |
1
|
794 { |
|
795 char **symbols = var_list (count); |
|
796 if (symbols != (char **) NULL) |
|
797 qsort ((void **) symbols, count, sizeof (char *), |
|
798 (int (*)(void*, void*)) pstrcmp); |
|
799 return symbols; |
|
800 } |
|
801 |
|
802 char ** |
164
|
803 symbol_table::sorted_fcn_list (int& count) const |
1
|
804 { |
|
805 char **symbols = fcn_list (count); |
|
806 if (symbols != (char **) NULL) |
|
807 qsort ((void **) symbols, count, sizeof (char *), |
|
808 (int (*)(void*, void*)) pstrcmp); |
|
809 return symbols; |
|
810 } |
|
811 |
|
812 // Chris Torek's fave hash function. |
|
813 |
|
814 unsigned int |
|
815 symbol_table::hash (const char *str) |
|
816 { |
|
817 unsigned h = 0; |
|
818 while (*str) |
|
819 h = h * 33 + *str++; |
|
820 return h; |
|
821 } |
|
822 |
|
823 /* |
|
824 ;;; Local Variables: *** |
|
825 ;;; mode: C++ *** |
|
826 ;;; page-delimiter: "^/\\*" *** |
|
827 ;;; End: *** |
|
828 */ |