Mercurial > hg > octave-avbm
comparison src/symtab.cc @ 2856:8c516da3c1f7
[project @ 1997-03-31 06:37:21 by jwe]
author | jwe |
---|---|
date | Mon, 31 Mar 1997 06:39:28 +0000 |
parents | 8b262e771614 |
children | 55cca18e943a |
comparison
equal
deleted
inserted
replaced
2855:1bb7dc230a4b | 2856:8c516da3c1f7 |
---|---|
84 symbol_def::~symbol_def (void) | 84 symbol_def::~symbol_def (void) |
85 { | 85 { |
86 delete definition; | 86 delete definition; |
87 } | 87 } |
88 | 88 |
89 int | 89 bool |
90 symbol_def::is_variable (void) const | 90 symbol_def::is_variable (void) const |
91 { | 91 { |
92 return (type & USER_VARIABLE || type & BUILTIN_VARIABLE); | 92 return (type & USER_VARIABLE || type & BUILTIN_VARIABLE); |
93 } | 93 } |
94 | 94 |
95 int | 95 bool |
96 symbol_def::is_function (void) const | 96 symbol_def::is_function (void) const |
97 { | 97 { |
98 return (type & USER_FUNCTION || type & BUILTIN_FUNCTION); | 98 return (type & USER_FUNCTION || type & BUILTIN_FUNCTION); |
99 } | 99 } |
100 | 100 |
101 int | 101 bool |
102 symbol_def::is_user_variable (void) const | 102 symbol_def::is_user_variable (void) const |
103 { | 103 { |
104 return (type & USER_VARIABLE); | 104 return (type & USER_VARIABLE); |
105 } | 105 } |
106 | 106 |
107 int | 107 bool |
108 symbol_def::is_text_function (void) const | 108 symbol_def::is_text_function (void) const |
109 { | 109 { |
110 return (type & TEXT_FUNCTION); | 110 return (type & TEXT_FUNCTION); |
111 } | 111 } |
112 | 112 |
113 int | 113 bool |
114 symbol_def::is_mapper_function (void) const | 114 symbol_def::is_mapper_function (void) const |
115 { | 115 { |
116 return (type & MAPPER_FUNCTION); | 116 return (type & MAPPER_FUNCTION); |
117 } | 117 } |
118 | 118 |
119 int | 119 bool |
120 symbol_def::is_user_function (void) const | 120 symbol_def::is_user_function (void) const |
121 { | 121 { |
122 return (type & USER_FUNCTION); | 122 return (type & USER_FUNCTION); |
123 } | 123 } |
124 | 124 |
125 int | 125 bool |
126 symbol_def::is_builtin_variable (void) const | 126 symbol_def::is_builtin_variable (void) const |
127 { | 127 { |
128 return (type & BUILTIN_VARIABLE); | 128 return (type & BUILTIN_VARIABLE); |
129 } | 129 } |
130 | 130 |
131 int | 131 bool |
132 symbol_def::is_builtin_function (void) const | 132 symbol_def::is_builtin_function (void) const |
133 { | 133 { |
134 return (type & BUILTIN_FUNCTION); | 134 return (type & BUILTIN_FUNCTION); |
135 } | 135 } |
136 | 136 |
137 // XXX FIXME XXX | 137 // XXX FIXME XXX |
138 int | 138 bool |
139 symbol_def::is_map_element (const string& /* elts */) const | 139 symbol_def::is_map_element (const string& /* elts */) const |
140 { | 140 { |
141 return 0; | 141 return 0; |
142 } | 142 } |
143 | 143 |
259 } | 259 } |
260 | 260 |
261 tree_fvc * | 261 tree_fvc * |
262 symbol_record::def (void) const | 262 symbol_record::def (void) const |
263 { | 263 { |
264 return definition ? definition->def () : 0; | 264 return definition ? definition->def () : false; |
265 } | 265 } |
266 | 266 |
267 void | 267 void |
268 symbol_record::rename (const string& new_name) | 268 symbol_record::rename (const string& new_name) |
269 { | 269 { |
270 if (! read_only_error ("rename")) | 270 if (! read_only_error ("rename")) |
271 nm = new_name; | 271 nm = new_name; |
272 } | 272 } |
273 | 273 |
274 int | 274 bool |
275 symbol_record::is_function (void) const | 275 symbol_record::is_function (void) const |
276 { | 276 { |
277 return definition ? definition->is_function () : 0; | 277 return definition ? definition->is_function () : false; |
278 } | 278 } |
279 | 279 |
280 int | 280 bool |
281 symbol_record::is_text_function (void) const | 281 symbol_record::is_text_function (void) const |
282 { | 282 { |
283 return definition ? definition->is_text_function () : 0; | 283 return definition ? definition->is_text_function () : false; |
284 } | 284 } |
285 | 285 |
286 int | 286 bool |
287 symbol_record::is_mapper_function (void) const | 287 symbol_record::is_mapper_function (void) const |
288 { | 288 { |
289 return definition ? definition->is_mapper_function () : 0; | 289 return definition ? definition->is_mapper_function () : false; |
290 } | 290 } |
291 | 291 |
292 int | 292 bool |
293 symbol_record::is_user_function (void) const | 293 symbol_record::is_user_function (void) const |
294 { | 294 { |
295 return definition ? definition->is_user_function () : 0; | 295 return definition ? definition->is_user_function () : false; |
296 } | 296 } |
297 | 297 |
298 int | 298 bool |
299 symbol_record::is_builtin_function (void) const | 299 symbol_record::is_builtin_function (void) const |
300 { | 300 { |
301 return definition ? definition->is_builtin_function () : 0; | 301 return definition ? definition->is_builtin_function () : false; |
302 } | 302 } |
303 | 303 |
304 int | 304 bool |
305 symbol_record::is_variable (void) const | 305 symbol_record::is_variable (void) const |
306 { | 306 { |
307 return definition ? definition->is_variable () : 0; | 307 return definition ? definition->is_variable () : false; |
308 } | 308 } |
309 | 309 |
310 int | 310 bool |
311 symbol_record::is_user_variable (void) const | 311 symbol_record::is_user_variable (void) const |
312 { | 312 { |
313 return definition ? definition->is_user_variable () : 0; | 313 return definition ? definition->is_user_variable () : false; |
314 } | 314 } |
315 | 315 |
316 int | 316 bool |
317 symbol_record::is_builtin_variable (void) const | 317 symbol_record::is_builtin_variable (void) const |
318 { | 318 { |
319 return definition ? definition->is_builtin_variable () : 0; | 319 return definition ? definition->is_builtin_variable () : false; |
320 } | 320 } |
321 | 321 |
322 int | 322 bool |
323 symbol_record::is_map_element (const string& elts) const | 323 symbol_record::is_map_element (const string& elts) const |
324 { | 324 { |
325 return definition ? definition->is_map_element (elts) : 0; | 325 return definition ? definition->is_map_element (elts) : false; |
326 } | 326 } |
327 | 327 |
328 unsigned | 328 unsigned |
329 symbol_record::type (void) const | 329 symbol_record::type (void) const |
330 { | 330 { |
331 return definition ? definition->type : 0; | 331 return definition ? definition->type : false; |
332 } | 332 } |
333 | 333 |
334 int | 334 bool |
335 symbol_record::is_defined (void) const | 335 symbol_record::is_defined (void) const |
336 { | 336 { |
337 return definition ? (definition->def () != 0) : 0; | 337 return definition ? (definition->def () != 0) : false; |
338 } | 338 } |
339 | 339 |
340 int | 340 bool |
341 symbol_record::is_read_only (void) const | 341 symbol_record::is_read_only (void) const |
342 { | 342 { |
343 return definition ? definition->read_only : 0; | 343 return definition ? definition->read_only : false; |
344 } | 344 } |
345 | 345 |
346 int | 346 bool |
347 symbol_record::is_eternal (void) const | 347 symbol_record::is_eternal (void) const |
348 { | 348 { |
349 return definition ? definition->eternal : 0; | 349 return definition ? definition->eternal : false; |
350 } | 350 } |
351 | 351 |
352 void | 352 void |
353 symbol_record::protect (void) | 353 symbol_record::protect (void) |
354 { | 354 { |
431 tree_constant *t = new tree_constant (v); | 431 tree_constant *t = new tree_constant (v); |
432 return define (t); | 432 return define (t); |
433 } | 433 } |
434 | 434 |
435 int | 435 int |
436 symbol_record::define (tree_builtin *t, int text_fcn) | 436 symbol_record::define (tree_builtin *t, bool text_fcn) |
437 { | 437 { |
438 if (read_only_error ("redefine")) | 438 if (read_only_error ("redefine")) |
439 return 0; | 439 return 0; |
440 | 440 |
441 if (is_variable ()) | 441 if (is_variable ()) |
460 | 460 |
461 return 1; | 461 return 1; |
462 } | 462 } |
463 | 463 |
464 int | 464 int |
465 symbol_record::define (tree_function *t, int text_fcn) | 465 symbol_record::define (tree_function *t, bool text_fcn) |
466 { | 466 { |
467 if (read_only_error ("redefine")) | 467 if (read_only_error ("redefine")) |
468 return 0; | 468 return 0; |
469 | 469 |
470 if (is_variable ()) | 470 if (is_variable ()) |
555 } | 555 } |
556 return count; | 556 return count; |
557 } | 557 } |
558 | 558 |
559 void | 559 void |
560 symbol_record::alias (symbol_record *s, int force) | 560 symbol_record::alias (symbol_record *s, bool force) |
561 { | 561 { |
562 sv_fcn = s->sv_fcn; | 562 sv_fcn = s->sv_fcn; |
563 | 563 |
564 if (force && ! s->definition) | 564 if (force && ! s->definition) |
565 { | 565 { |
578 symbol_record::mark_as_formal_parameter (void) | 578 symbol_record::mark_as_formal_parameter (void) |
579 { | 579 { |
580 formal_param = 1; | 580 formal_param = 1; |
581 } | 581 } |
582 | 582 |
583 int | 583 bool |
584 symbol_record::is_formal_parameter (void) const | 584 symbol_record::is_formal_parameter (void) const |
585 { | 585 { |
586 return formal_param; | 586 return formal_param; |
587 } | 587 } |
588 | 588 |
590 symbol_record::mark_as_linked_to_global (void) | 590 symbol_record::mark_as_linked_to_global (void) |
591 { | 591 { |
592 linked_to_global = 1; | 592 linked_to_global = 1; |
593 } | 593 } |
594 | 594 |
595 int | 595 bool |
596 symbol_record::is_linked_to_global (void) const | 596 symbol_record::is_linked_to_global (void) const |
597 { | 597 { |
598 return linked_to_global; | 598 return linked_to_global; |
599 } | 599 } |
600 | 600 |
607 error ("can't make formal parameter static"); | 607 error ("can't make formal parameter static"); |
608 else | 608 else |
609 tagged_static = 1; | 609 tagged_static = 1; |
610 } | 610 } |
611 | 611 |
612 int | 612 bool |
613 symbol_record::is_static (void) const | 613 symbol_record::is_static (void) const |
614 { | 614 { |
615 return tagged_static; | 615 return tagged_static; |
616 } | 616 } |
617 | 617 |
810 const_type = s.const_type; | 810 const_type = s.const_type; |
811 } | 811 } |
812 return *this; | 812 return *this; |
813 } | 813 } |
814 | 814 |
815 int | 815 bool |
816 symbol_record_info::is_defined (void) const | 816 symbol_record_info::is_defined (void) const |
817 { | 817 { |
818 return initialized; | 818 return initialized; |
819 } | 819 } |
820 | 820 |
821 int | 821 bool |
822 symbol_record_info::is_read_only (void) const | 822 symbol_record_info::is_read_only (void) const |
823 { | 823 { |
824 return read_only; | 824 return read_only; |
825 } | 825 } |
826 | 826 |
827 int | 827 bool |
828 symbol_record_info::is_eternal (void) const | 828 symbol_record_info::is_eternal (void) const |
829 { | 829 { |
830 return eternal; | 830 return eternal; |
831 } | 831 } |
832 | 832 |
833 int | 833 bool |
834 symbol_record_info::hides_fcn (void) const | 834 symbol_record_info::hides_fcn (void) const |
835 { | 835 { |
836 return (hides & SR_INFO_USER_FUNCTION); | 836 return (hides & SR_INFO_USER_FUNCTION); |
837 } | 837 } |
838 | 838 |
839 int | 839 bool |
840 symbol_record_info::hides_builtin (void) const | 840 symbol_record_info::hides_builtin (void) const |
841 { | 841 { |
842 return (hides & SR_INFO_BUILTIN_FUNCTION); | 842 return (hides & SR_INFO_BUILTIN_FUNCTION); |
843 } | 843 } |
844 | 844 |
862 retval = const_type; | 862 retval = const_type; |
863 | 863 |
864 return retval; | 864 return retval; |
865 } | 865 } |
866 | 866 |
867 int | 867 bool |
868 symbol_record_info::is_function (void) const | 868 symbol_record_info::is_function (void) const |
869 { | 869 { |
870 return (type == symbol_def::USER_FUNCTION | 870 return (type == symbol_def::USER_FUNCTION |
871 || type == symbol_def::BUILTIN_FUNCTION | 871 || type == symbol_def::BUILTIN_FUNCTION |
872 || symbol_def::TEXT_FUNCTION | 872 || symbol_def::TEXT_FUNCTION |
896 symbol_table::symbol_table (void) | 896 symbol_table::symbol_table (void) |
897 { | 897 { |
898 } | 898 } |
899 | 899 |
900 symbol_record * | 900 symbol_record * |
901 symbol_table::lookup (const string& nm, int insert, int warn) | 901 symbol_table::lookup (const string& nm, bool insert, bool warn) |
902 { | 902 { |
903 int index = hash (nm) & HASH_MASK; | 903 int index = hash (nm) & HASH_MASK; |
904 | 904 |
905 symbol_record *ptr = table[index].next (); | 905 symbol_record *ptr = table[index].next (); |
906 | 906 |
958 error ("unable to rename `%s' to `%s'", old_name.c_str (), | 958 error ("unable to rename `%s' to `%s'", old_name.c_str (), |
959 new_name.c_str ()); | 959 new_name.c_str ()); |
960 } | 960 } |
961 | 961 |
962 void | 962 void |
963 symbol_table::clear (int clear_user_functions) | 963 symbol_table::clear (bool clear_user_functions) |
964 { | 964 { |
965 for (int i = 0; i < HASH_TABLE_SIZE; i++) | 965 for (int i = 0; i < HASH_TABLE_SIZE; i++) |
966 { | 966 { |
967 symbol_record *ptr = table[i].next (); | 967 symbol_record *ptr = table[i].next (); |
968 | 968 |
978 } | 978 } |
979 } | 979 } |
980 } | 980 } |
981 | 981 |
982 int | 982 int |
983 symbol_table::clear (const string& nm, int clear_user_functions) | 983 symbol_table::clear (const string& nm, bool clear_user_functions) |
984 { | 984 { |
985 int index = hash (nm) & HASH_MASK; | 985 int index = hash (nm) & HASH_MASK; |
986 | 986 |
987 symbol_record *ptr = table[index].next (); | 987 symbol_record *ptr = table[index].next (); |
988 | 988 |
1045 // This function should probably share code with symbol_table::list. | 1045 // This function should probably share code with symbol_table::list. |
1046 // XXX FIXME XXX | 1046 // XXX FIXME XXX |
1047 | 1047 |
1048 symbol_record_info * | 1048 symbol_record_info * |
1049 symbol_table::long_list (int& count, const string_vector& pats, | 1049 symbol_table::long_list (int& count, const string_vector& pats, |
1050 int npats, int sort, unsigned type, | 1050 int npats, bool sort, unsigned type, |
1051 unsigned scope) const | 1051 unsigned scope) const |
1052 { | 1052 { |
1053 count = 0; | 1053 count = 0; |
1054 int n = size (); | 1054 int n = size (); |
1055 if (n == 0) | 1055 if (n == 0) |
1085 return symbols; | 1085 return symbols; |
1086 } | 1086 } |
1087 | 1087 |
1088 string_vector | 1088 string_vector |
1089 symbol_table::list (int& count, const string_vector& pats, int npats, | 1089 symbol_table::list (int& count, const string_vector& pats, int npats, |
1090 int sort, unsigned type, unsigned scope) const | 1090 bool sort, unsigned type, unsigned scope) const |
1091 { | 1091 { |
1092 count = 0; | 1092 count = 0; |
1093 int n = size (); | 1093 int n = size (); |
1094 if (n == 0) | 1094 if (n == 0) |
1095 return 0; | 1095 return 0; |
1203 return h; | 1203 return h; |
1204 } | 1204 } |
1205 | 1205 |
1206 // Return nonzero if S is a valid identifier. | 1206 // Return nonzero if S is a valid identifier. |
1207 | 1207 |
1208 int | 1208 bool |
1209 valid_identifier (const char *s) | 1209 valid_identifier (const char *s) |
1210 { | 1210 { |
1211 if (! s || ! (isalnum (*s) || *s == '_')) | 1211 if (! s || ! (isalnum (*s) || *s == '_')) |
1212 return 0; | 1212 return false; |
1213 | 1213 |
1214 while (*++s != '\0') | 1214 while (*++s != '\0') |
1215 if (! (isalnum (*s) || *s == '_')) | 1215 if (! (isalnum (*s) || *s == '_')) |
1216 return 0; | 1216 return false; |
1217 | 1217 |
1218 return 1; | 1218 return true; |
1219 } | 1219 } |
1220 | 1220 |
1221 int | 1221 bool |
1222 valid_identifier (const string& s) | 1222 valid_identifier (const string& s) |
1223 { | 1223 { |
1224 return valid_identifier (s.c_str ()); | 1224 return valid_identifier (s.c_str ()); |
1225 } | 1225 } |
1226 | 1226 |