comparison src/symtab.cc @ 4238:a5a68c0afe56

[project @ 2002-12-25 21:04:33 by jwe]
author jwe
date Wed, 25 Dec 2002 21:04:34 +0000
parents 90e44267e8cf
children bdaa0d3dfc0b
comparison
equal deleted inserted replaced
4237:9c8034434982 4238:a5a68c0afe56
45 #include "pt-pr-code.h" 45 #include "pt-pr-code.h"
46 #include "symtab.h" 46 #include "symtab.h"
47 #include "utils.h" 47 #include "utils.h"
48 #include "variables.h" 48 #include "variables.h"
49 49
50 unsigned long int symbol_table::symtab_count = 0;
51
50 // Should variables be allowed to hide functions of the same name? A 52 // Should variables be allowed to hide functions of the same name? A
51 // positive value means yes. A negative value means yes, but print a 53 // positive value means yes. A negative value means yes, but print a
52 // warning message. Zero means it should be considered an error. 54 // warning message. Zero means it should be considered an error.
53 static int Vvariables_can_hide_functions; 55 static int Vvariables_can_hide_functions;
56
57 // Nonzero means we print debugging info about symbol table lookups.
58 static int Vdebug_symtab_lookups;
54 59
55 octave_allocator 60 octave_allocator
56 symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def)); 61 symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def));
57 62
58 #define SYMBOL_DEF symbol_record::symbol_def 63 #define SYMBOL_DEF symbol_record::symbol_def
460 // A symbol table. 465 // A symbol table.
461 466
462 symbol_record * 467 symbol_record *
463 symbol_table::lookup (const std::string& nm, bool insert, bool warn) 468 symbol_table::lookup (const std::string& nm, bool insert, bool warn)
464 { 469 {
470 if (Vdebug_symtab_lookups)
471 {
472 std::cerr << (table_name.empty () ? "???" : table_name)
473 << " symtab::lookup ["
474 << (insert ? "I" : "-")
475 << (warn ? "W" : "-")
476 << "] \"" << nm << "\"\n";
477 }
478
465 unsigned int index = hash (nm); 479 unsigned int index = hash (nm);
466 480
467 symbol_record *ptr = table[index].next (); 481 symbol_record *ptr = table[index].next ();
468 482
469 while (ptr) 483 while (ptr)
489 } 503 }
490 504
491 void 505 void
492 symbol_table::rename (const std::string& old_name, const std::string& new_name) 506 symbol_table::rename (const std::string& old_name, const std::string& new_name)
493 { 507 {
508 if (Vdebug_symtab_lookups)
509 {
510 std::cerr << (table_name.empty () ? "???" : table_name)
511 << " symtab::rename "
512 << "\"" << old_name << "\""
513 << " to "
514 << "\"" << new_name << "\"\n";
515 }
516
494 unsigned int index = hash (old_name); 517 unsigned int index = hash (old_name);
495 518
496 symbol_record *prev = &table[index]; 519 symbol_record *prev = &table[index];
497 symbol_record *ptr = prev->next (); 520 symbol_record *ptr = prev->next ();
498 521
1066 static int 1089 static int
1067 variables_can_hide_functions (void) 1090 variables_can_hide_functions (void)
1068 { 1091 {
1069 Vvariables_can_hide_functions 1092 Vvariables_can_hide_functions
1070 = check_preference ("variables_can_hide_functions"); 1093 = check_preference ("variables_can_hide_functions");
1094
1095 return 0;
1096 }
1097
1098 static int
1099 debug_symtab_lookups (void)
1100 {
1101 Vdebug_symtab_lookups = check_preference ("debug_symtab_lookups");
1071 1102
1072 return 0; 1103 return 0;
1073 } 1104 }
1074 1105
1075 void 1106 void
1081 If the value of this variable is nonzero, assignments to variables may\n\ 1112 If the value of this variable is nonzero, assignments to variables may\n\
1082 hide previously defined functions of the same name. A negative value\n\ 1113 hide previously defined functions of the same name. A negative value\n\
1083 will cause Octave to print a warning, but allow the operation.\n\ 1114 will cause Octave to print a warning, but allow the operation.\n\
1084 @end defvr"); 1115 @end defvr");
1085 1116
1117 DEFVAR (debug_symtab_lookups, false, debug_symtab_lookups,
1118 "-*- texinfo -*-\n\
1119 @defvr debug_symtab_lookups\n\
1120 If the value of htis variable is nonzero, print debugging info when\n\
1121 searching for symbols in the symbol tables");
1086 } 1122 }
1087 1123
1088 1124
1089 /* 1125 /*
1090 ;;; Local Variables: *** 1126 ;;; Local Variables: ***