Mercurial > octave
comparison src/symtab.cc @ 7752:40c428ea3408
initial implementation of dbup and dbdown
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 03:42:19 -0400 |
parents | 0ff0fc033f28 |
children | 5adeea5de26c |
comparison
equal
deleted
inserted
replaced
7751:7c020c067a60 | 7752:40c428ea3408 |
---|---|
45 | 45 |
46 symbol_table *symbol_table::instance = 0; | 46 symbol_table *symbol_table::instance = 0; |
47 | 47 |
48 std::map<symbol_table::scope_id, symbol_table*> symbol_table::all_instances; | 48 std::map<symbol_table::scope_id, symbol_table*> symbol_table::all_instances; |
49 | 49 |
50 std::map<std::string, octave_value> symbol_table::global_table; | |
51 | |
50 std::map<std::string, symbol_table::fcn_info> symbol_table::fcn_table; | 52 std::map<std::string, symbol_table::fcn_info> symbol_table::fcn_table; |
51 | 53 |
52 const symbol_table::scope_id symbol_table::xglobal_scope = 0; | 54 const symbol_table::scope_id symbol_table::xglobal_scope = 0; |
53 const symbol_table::scope_id symbol_table::xtop_scope = 1; | 55 const symbol_table::scope_id symbol_table::xtop_scope = 1; |
54 | 56 |
60 std::deque<symbol_table::scope_id> symbol_table::scope_stack; | 62 std::deque<symbol_table::scope_id> symbol_table::scope_stack; |
61 | 63 |
62 symbol_table::scope_id symbol_table::next_available_scope = 2; | 64 symbol_table::scope_id symbol_table::next_available_scope = 2; |
63 std::set<symbol_table::scope_id> symbol_table::scope_ids_in_use; | 65 std::set<symbol_table::scope_id> symbol_table::scope_ids_in_use; |
64 std::set<symbol_table::scope_id> symbol_table::scope_ids_free_list; | 66 std::set<symbol_table::scope_id> symbol_table::scope_ids_free_list; |
67 | |
68 symbol_table::context_id symbol_table::xcurrent_context = 0; | |
65 | 69 |
66 // Should Octave always check to see if function files have changed | 70 // Should Octave always check to see if function files have changed |
67 // since they were last compiled? | 71 // since they were last compiled? |
68 static int Vignore_function_time_stamp = 1; | 72 static int Vignore_function_time_stamp = 1; |
69 | 73 |
74 bool& args_evaluated) const | 78 bool& args_evaluated) const |
75 { | 79 { |
76 octave_value retval; | 80 octave_value retval; |
77 | 81 |
78 if (is_global ()) | 82 if (is_global ()) |
79 return symbol_table::varref (name (), symbol_table::xglobal_scope); | 83 return symbol_table::global_varref (name ()); |
80 else | 84 else |
81 { | 85 { |
82 octave_value val = varval (); | 86 octave_value val = varval (); |
83 | 87 |
84 if (val.is_defined ()) | 88 if (val.is_defined ()) |
364 // example, before returning from tree_index_expression::rvalue). | 368 // example, before returning from tree_index_expression::rvalue). |
365 | 369 |
366 octave_value | 370 octave_value |
367 symbol_table::fcn_info::fcn_info_rep::find | 371 symbol_table::fcn_info::fcn_info_rep::find |
368 (tree_argument_list *args, const string_vector& arg_names, | 372 (tree_argument_list *args, const string_vector& arg_names, |
369 octave_value_list& evaluated_args, bool& args_evaluated, | 373 octave_value_list& evaluated_args, bool& args_evaluated) |
370 scope_id scope) | |
371 { | 374 { |
372 static bool deja_vu = false; | 375 static bool deja_vu = false; |
373 | 376 |
374 // Subfunction. I think it only makes sense to check for | 377 // Subfunction. I think it only makes sense to check for |
375 // subfunctions if we are currently executing a function defined | 378 // subfunctions if we are currently executing a function defined |
376 // from a .m file. | 379 // from a .m file. |
377 | 380 |
378 scope_val_iterator r = subfunctions.find (scope); | 381 scope_val_iterator r = subfunctions.find (xcurrent_scope); |
379 | 382 |
380 if (r != subfunctions.end ()) | 383 if (r != subfunctions.end ()) |
381 { | 384 { |
382 // FIXME -- out-of-date check here. | 385 // FIXME -- out-of-date check here. |
383 | 386 |
523 if (p != dispatch_map.end ()) | 526 if (p != dispatch_map.end ()) |
524 { | 527 { |
525 fname = p->second; | 528 fname = p->second; |
526 | 529 |
527 octave_value fcn | 530 octave_value fcn |
528 = symbol_table::find_function (fname, evaluated_args, scope); | 531 = symbol_table::find_function (fname, evaluated_args); |
529 | 532 |
530 if (fcn.is_defined ()) | 533 if (fcn.is_defined ()) |
531 return fcn; | 534 return fcn; |
532 } | 535 } |
533 } | 536 } |
566 { | 569 { |
567 load_path::update (); | 570 load_path::update (); |
568 | 571 |
569 deja_vu = true; | 572 deja_vu = true; |
570 | 573 |
571 retval = find (args, arg_names, evaluated_args, args_evaluated, scope); | 574 retval = find (args, arg_names, evaluated_args, args_evaluated); |
572 } | 575 } |
573 | 576 |
574 deja_vu = false; | 577 deja_vu = false; |
575 | 578 |
576 return retval; | 579 return retval; |
670 | 673 |
671 octave_value | 674 octave_value |
672 symbol_table::fcn_info::find (tree_argument_list *args, | 675 symbol_table::fcn_info::find (tree_argument_list *args, |
673 const string_vector& arg_names, | 676 const string_vector& arg_names, |
674 octave_value_list& evaluated_args, | 677 octave_value_list& evaluated_args, |
675 bool& args_evaluated, scope_id scope) | 678 bool& args_evaluated) |
676 { | 679 { |
677 return rep->find (args, arg_names, evaluated_args, args_evaluated, scope); | 680 return rep->find (args, arg_names, evaluated_args, args_evaluated); |
678 } | 681 } |
679 | 682 |
680 octave_value | 683 octave_value |
681 symbol_table::find (const std::string& name, tree_argument_list *args, | 684 symbol_table::find (const std::string& name, tree_argument_list *args, |
682 const string_vector& arg_names, | 685 const string_vector& arg_names, |
683 octave_value_list& evaluated_args, bool& args_evaluated, | 686 octave_value_list& evaluated_args, bool& args_evaluated, |
684 symbol_table::scope_id scope, bool skip_variables) | 687 bool skip_variables) |
685 { | 688 { |
686 symbol_table *inst = get_instance (scope); | 689 symbol_table *inst = get_instance (xcurrent_scope); |
687 | 690 |
688 return inst | 691 return inst |
689 ? inst->do_find (name, args, arg_names, evaluated_args, | 692 ? inst->do_find (name, args, arg_names, evaluated_args, |
690 args_evaluated, scope, skip_variables) | 693 args_evaluated, skip_variables) |
691 : octave_value (); | 694 : octave_value (); |
692 } | 695 } |
693 | 696 |
694 octave_value | 697 octave_value |
695 symbol_table::find_function (const std::string& name, tree_argument_list *args, | 698 symbol_table::find_function (const std::string& name, tree_argument_list *args, |
696 const string_vector& arg_names, | 699 const string_vector& arg_names, |
697 octave_value_list& evaluated_args, | 700 octave_value_list& evaluated_args, |
698 bool& args_evaluated, scope_id scope) | 701 bool& args_evaluated) |
699 { | 702 { |
700 return find (name, args, arg_names, evaluated_args, args_evaluated, | 703 return find (name, args, arg_names, evaluated_args, args_evaluated, true); |
701 scope, true); | |
702 } | 704 } |
703 | 705 |
704 octave_value | 706 octave_value |
705 symbol_table::do_find (const std::string& name, tree_argument_list *args, | 707 symbol_table::do_find (const std::string& name, tree_argument_list *args, |
706 const string_vector& arg_names, | 708 const string_vector& arg_names, |
707 octave_value_list& evaluated_args, | 709 octave_value_list& evaluated_args, |
708 bool& args_evaluated, scope_id scope, | 710 bool& args_evaluated, bool skip_variables) |
709 bool skip_variables) | |
710 { | 711 { |
711 octave_value retval; | 712 octave_value retval; |
712 | 713 |
713 // Variable. | 714 // Variable. |
714 | 715 |
721 symbol_record& sr = p->second; | 722 symbol_record& sr = p->second; |
722 | 723 |
723 // FIXME -- should we be using something other than varref here? | 724 // FIXME -- should we be using something other than varref here? |
724 | 725 |
725 if (sr.is_global ()) | 726 if (sr.is_global ()) |
726 return symbol_table::varref (name, xglobal_scope); | 727 return symbol_table::global_varref (name); |
727 else | 728 else |
728 { | 729 { |
729 octave_value& val = sr.varref (); | 730 octave_value& val = sr.varref (); |
730 | 731 |
731 if (val.is_defined ()) | 732 if (val.is_defined ()) |
739 if (p != fcn_table.end ()) | 740 if (p != fcn_table.end ()) |
740 { | 741 { |
741 evaluated_args = octave_value_list (); | 742 evaluated_args = octave_value_list (); |
742 args_evaluated = false; | 743 args_evaluated = false; |
743 | 744 |
744 return p->second.find (args, arg_names, evaluated_args, args_evaluated, | 745 return p->second.find (args, arg_names, evaluated_args, args_evaluated); |
745 scope); | |
746 } | 746 } |
747 else | 747 else |
748 { | 748 { |
749 fcn_info finfo (name); | 749 fcn_info finfo (name); |
750 | 750 |
751 octave_value fcn = finfo.find (args, arg_names, evaluated_args, | 751 octave_value fcn = finfo.find (args, arg_names, evaluated_args, |
752 args_evaluated, scope); | 752 args_evaluated); |
753 | 753 |
754 if (fcn.is_defined ()) | 754 if (fcn.is_defined ()) |
755 fcn_table[name] = finfo; | 755 fcn_table[name] = finfo; |
756 | 756 |
757 return fcn; | 757 return fcn; |