# HG changeset patch # User jwe # Date 1118994748 0 # Node ID b12c0f920da0783b05e7e43c460f2842f1785548 # Parent 983bf1f4bab52d34f03b7d40f7abafe3b1097a90 [project @ 2005-06-17 07:52:28 by jwe] diff -r 983bf1f4bab5 -r b12c0f920da0 src/ChangeLog --- a/src/ChangeLog Fri Jun 17 04:10:53 2005 +0000 +++ b/src/ChangeLog Fri Jun 17 07:52:28 2005 +0000 @@ -1,5 +1,52 @@ +2005-06-17 John W. Eaton + + * symtab.h (symbol_record::alias): New arg, mark_to_clear. + (symbol_record::aliases_to_clear): New data member. + (symbol_record::push_alias_to_clear): New function. + * symtab.cc (symbol_record::alias): If mark_to_clear is true, push + this pointer on aliases_to_clear stack for s. + (symbol_record::clear): Also clear aliases_to_clear_stack. + + * defun.cc (install_dld_function): Create full file name alias in + fbi_sym_tab and hide it from view. + Don't call protect or make_eternal on sym_rec. + + * variables.cc (fcn_out_of_date): New function. + (symbol_out_of_date): Also check for symbol using full function + file name. + + * symtab.h (symbol_record::symbol_def::visible): New data member. + (symbol_record::symbol_def::hide, symbol_record::symbol_def::show, + symbol_record::symbol_def::is_visible): New functions. + (symbol_record::hide, symbol_record::show, symbol_record::is_visible): + New functions. + + * symtab.h (symbol_record::maybe_delete_def): New private function. + * symtab.cc (symbol_record::clear, symbol_record::alias, + symbol_record::pop_context, + symbol_record::define (octave_function *, unsigned int)): Use it. + (symbol_table::symbol_list): Only include visible symbols in list. + + * parse.y (frob_function): Hide nested function names. + + * parse.y (frob_function): Create full file name alias in + fbi_sym_tab and hide it from view. + * defun.cc (install_dld_function): Likewise. + 2005-06-16 John W. Eaton + * ov-dld-fcn.cc (octave_dld_function): Check Voct_file_dir to see + if function is system file, Vfcn_file_dir. + * defaults.cc (set_default_oct_file_dir): New function. + (install_defaults): Call it. + (Voct_file_dir): New global variable. + * defaults.h.in (Voct_file_dir): Provide decl. + + * variables.cc (function_out_of_date_internal): Use + Vignore_function_time_stamp only to avoid calling stat. + (symbol_out_of_date): Don't check Vignore_function_time_stamp here. + (function_out_of_date): Rename from function_out_of_date_internal. + * defaults.cc (loadpath): Don't do anything if value is unchanged. If loadpath changes, also update Vlast_prompt_time. diff -r 983bf1f4bab5 -r b12c0f920da0 src/defaults.cc --- a/src/defaults.cc Fri Jun 17 04:10:53 2005 +0000 +++ b/src/defaults.cc Fri Jun 17 07:52:28 2005 +0000 @@ -67,6 +67,7 @@ std::string Vlocal_arch_lib_dir; std::string Vlocal_ver_arch_lib_dir; std::string Vfcn_file_dir; +std::string Voct_file_dir; // The default path that will be searched for programs that we // execute (in addition to the user-specified --exec-path). @@ -248,6 +249,12 @@ } static void +set_default_oct_file_dir (void) +{ + Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); +} + +static void set_default_bin_dir (void) { Vbin_dir = subst_octave_home (OCTAVE_BINDIR); @@ -404,6 +411,8 @@ set_default_fcn_file_dir (); + set_default_oct_file_dir (); + set_default_bin_dir (); set_default_default_exec_path (); diff -r 983bf1f4bab5 -r b12c0f920da0 src/defaults.h.in --- a/src/defaults.h.in Fri Jun 17 04:10:53 2005 +0000 +++ b/src/defaults.h.in Fri Jun 17 07:52:28 2005 +0000 @@ -179,6 +179,7 @@ extern std::string Vlocal_arch_lib_dir; extern std::string Vlocal_ver_arch_lib_dir; extern std::string Vfcn_file_dir; +extern std::string Voct_file_dir; // The path that will be searched for programs that we execute. // (--exec-path path) diff -r 983bf1f4bab5 -r b12c0f920da0 src/defun.cc --- a/src/defun.cc Fri Jun 17 04:10:53 2005 +0000 +++ b/src/defun.cc Fri Jun 17 07:52:28 2005 +0000 @@ -154,8 +154,14 @@ sym_rec->unprotect (); sym_rec->define (new octave_dld_function (f, shl, name, doc), t); sym_rec->document (doc); - sym_rec->make_eternal (); - sym_rec->protect (); + + // Also insert the full name in the symbol table. This way, we can + // properly cope with changes to LOADPATH. + + symbol_record *full_sr = fbi_sym_tab->lookup (shl.file_name (), true); + + full_sr->alias (sym_rec, true); + full_sr->hide (); } void diff -r 983bf1f4bab5 -r b12c0f920da0 src/ov-dld-fcn.cc --- a/src/ov-dld-fcn.cc Fri Jun 17 04:10:53 2005 +0000 +++ b/src/ov-dld-fcn.cc Fri Jun 17 07:52:28 2005 +0000 @@ -52,7 +52,7 @@ system_fcn_file = (! file_name.empty () - && Vfcn_file_dir == file_name.substr (0, Vfcn_file_dir.length ())); + && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ())); } octave_dld_function::~octave_dld_function (void) diff -r 983bf1f4bab5 -r b12c0f920da0 src/parse.y --- a/src/parse.y Fri Jun 17 04:10:53 2005 +0000 +++ b/src/parse.y Fri Jun 17 07:52:28 2005 +0000 @@ -2567,7 +2567,10 @@ fcn->stash_symtab_ptr (sr); if (lexer_flags.parsing_nested_function) - fcn->mark_as_nested_function (); + { + fcn->mark_as_nested_function (); + sr->hide (); + } } else panic_impossible (); @@ -2580,6 +2583,18 @@ help_buf.pop (); } + // Also insert the full name in the symbol table. This way, we can + // properly cope with changes to LOADPATH. + + if (reading_fcn_file) + { + symbol_record *full_sr + = fbi_sym_tab->lookup (curr_fcn_file_full_name, true); + + full_sr->alias (sr, true); + full_sr->hide (); + } + if (lexer_flags.parsing_nested_function < 0) lexer_flags.parsing_nested_function = 0; diff -r 983bf1f4bab5 -r b12c0f920da0 src/symtab.cc --- a/src/symtab.cc Fri Jun 17 04:10:53 2005 +0000 +++ b/src/symtab.cc Fri Jun 17 07:52:28 2005 +0000 @@ -248,12 +248,11 @@ if (! read_only_error ("redefine")) { + maybe_delete_def (); + octave_value tmp (f); - if (! definition) - definition = new symbol_def (tmp, sym_type); - else - definition->define (tmp, sym_type); + definition = new symbol_def (tmp, sym_type); retval = true; } @@ -268,8 +267,14 @@ { if (! tagged_static) { - if (--definition->count <= 0) - delete definition; + while (! aliases_to_clear.empty ()) + { + symbol_record *sr = aliases_to_clear.top (); + aliases_to_clear.pop (); + sr->clear (); + } + + maybe_delete_def (); definition = new symbol_def (); } @@ -280,14 +285,16 @@ } void -symbol_record::alias (symbol_record *s) +symbol_record::alias (symbol_record *s, bool mark_to_clear) { chg_fcn = s->chg_fcn; - if (--definition->count <= 0) - delete definition; + maybe_delete_def (); - definition = (s->definition); + if (mark_to_clear) + s->push_alias_to_clear (this); + + definition = s->definition; definition->count++; } @@ -402,8 +409,7 @@ if (! context.empty ()) { - if (--definition->count <= 0) - delete definition; + maybe_delete_def (); definition = context.top (); context.pop (); @@ -868,6 +874,7 @@ if (ptr->name () == nm) { ptr->clear (); + return true; } ptr = ptr->next (); @@ -1147,17 +1154,20 @@ while (ptr) { - assert (count < n); + if (true || ptr->is_visible ()) + { + assert (count < n); - unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky... - - unsigned int my_type = ptr->type (); + unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky... - std::string my_name = ptr->name (); + unsigned int my_type = ptr->type (); + + std::string my_name = ptr->name (); - if ((type & my_type) && (scope & my_scope) && (matches_patterns (my_name, pats))) - symbols(count++) = ptr; - + if ((type & my_type) && (scope & my_scope) && (matches_patterns (my_name, pats))) + symbols(count++) = ptr; + } + ptr = ptr->next (); } } diff -r 983bf1f4bab5 -r b12c0f920da0 src/symtab.h --- a/src/symtab.h Fri Jun 17 04:10:53 2005 +0000 +++ b/src/symtab.h Fri Jun 17 07:52:28 2005 +0000 @@ -90,7 +90,7 @@ symbol_def (const octave_value& val = octave_value (), unsigned int sym_type = 0) : symbol_type (sym_type), eternal (0), read_only (0), help_string (), - definition (val), count (1) { } + definition (val), visible (true), count (1) { } ~symbol_def (void) { } @@ -209,6 +209,10 @@ void make_eternal (void) { eternal = 1; } + void hide (void) { visible = false; } + void show (void) { visible = true; } + bool is_visible (void) const { return visible; } + octave_value& def (void) { return definition; } std::string help (void) const { return help_string; } @@ -240,6 +244,9 @@ // The value of this definition. See ov.h and related files. octave_value definition; + // Should this symbol show up in listings? + bool visible; + // Reference count. int count; @@ -349,6 +356,10 @@ void make_eternal (void) { definition->make_eternal (); } + void hide (void) { definition->hide (); } + void show (void) { definition->show (); } + bool is_visible (void) const { return definition->is_visible (); } + void set_change_function (change_function f) { chg_fcn = f; } void define (const octave_value& v, unsigned int sym_type = USER_VARIABLE); @@ -363,7 +374,7 @@ void clear (void); - void alias (symbol_record *s); + void alias (symbol_record *s, bool mark_to_clear = false); void mark_as_formal_parameter (void); bool is_formal_parameter (void) const { return formal_param; } @@ -444,10 +455,21 @@ std::stack context; std::stack global_link_context; + std::stack aliases_to_clear; + + void push_alias_to_clear (symbol_record *s) + { aliases_to_clear.push (s); } + bool read_only_error (const char *action); void link_to_builtin_variable (void); + void maybe_delete_def (void) + { + if (--definition->count <= 0) + delete definition; + } + // No copying! symbol_record (const symbol_record& s); diff -r 983bf1f4bab5 -r b12c0f920da0 src/variables.cc --- a/src/variables.cc Fri Jun 17 04:10:53 2005 +0000 +++ b/src/variables.cc Fri Jun 17 07:52:28 2005 +0000 @@ -975,84 +975,112 @@ return (f_fs.ino () == g_fs.ino () && f_fs.dev () == g_fs.dev ()); } -// Is there a corresponding function file that is newer than the -// symbol definition? - static bool -function_out_of_date_internal (octave_function *fcn) +fcn_out_of_date (octave_function *fcn, const std::string& ff, time_t tp) { bool retval = false; - if (fcn) + fcn->mark_fcn_file_up_to_date (octave_time ()); + + if (! (Vignore_function_time_stamp == 2 + || (Vignore_function_time_stamp && fcn->is_system_fcn_file ()))) { - std::string ff = fcn->fcn_file_name (); - - if (! (ff.empty () - || (Vignore_function_time_stamp - && fcn->is_system_fcn_file ()))) - { - if (fcn->time_checked () < Vlast_prompt_time) - { - time_t tp = fcn->time_parsed (); - - std::string nm = fcn->name (); - - string_vector names (2); - - names[0] = nm + ".oct"; - names[1] = nm + ".m"; - - std::string file = octave_env::make_absolute - (Vload_path_dir_path.find_first_of (names), - octave_env::getcwd ()); - - if (same_file (file, ff)) - { - fcn->mark_fcn_file_up_to_date (octave_time ()); - - file_stat fs (ff); - - if (fs && fs.is_newer (tp)) - retval = true; - } - else - retval = true; - } - } + file_stat fs (ff); + + if (fs && fs.is_newer (tp)) + retval = true; } return retval; } +// Is there a corresponding function file that is newer than the +// symbol definition? + static bool symbol_out_of_date (symbol_record *sr) { bool retval = false; - if (Vignore_function_time_stamp != 2 && sr) + if (sr) { octave_value ans = sr->def (); - octave_function *tmp = ans.function_value (true); - - retval = function_out_of_date_internal (tmp); + octave_function *fcn = ans.function_value (true); + + if (fcn) + { + std::string ff = fcn->fcn_file_name (); + + if (! ff.empty ()) + { + if (fcn->time_checked () < Vlast_prompt_time) + { + time_t tp = fcn->time_parsed (); + + std::string nm = fcn->name (); + + string_vector names (2); + + names[0] = nm + ".oct"; + names[1] = nm + ".m"; + + std::string file = octave_env::make_absolute + (Vload_path_dir_path.find_first_of (names), + octave_env::getcwd ()); + + if (same_file (file, ff)) + { + retval = fcn_out_of_date (fcn, ff, tp); + } + else + { + // Check the full function name. Maybe we alrady + // parsed it. + + symbol_record *full_sr = fbi_sym_tab->lookup (file); + + if (full_sr) + { + octave_value v = full_sr->def (); + + if (v.is_function ()) + { + // OK, swap the aliases around. + + // XXX FIXME XXX -- this is a bit + // tricky, so maybe some refactoring is + // in order here too... + + symbol_record *short_sr = fbi_sym_tab->lookup (nm); + + if (short_sr) + short_sr->alias (full_sr); + + // Make local symbol table entry point + // to correct global function too. + + sr->alias (full_sr); + + fcn = v.function_value (); + + retval = fcn_out_of_date (fcn, file, tp); + } + else + retval = true; + } + else + retval = true; + } + } + } + } } return retval; } bool -function_out_of_date (octave_function *fcn) -{ - bool retval = false; - - if (Vignore_function_time_stamp != 2) - retval = function_out_of_date_internal (fcn); - - return retval; -} - -bool lookup (symbol_record *sym_rec, bool exec_script) { bool script_executed = false; diff -r 983bf1f4bab5 -r b12c0f920da0 src/variables.h --- a/src/variables.h Fri Jun 17 04:10:53 2005 +0000 +++ b/src/variables.h Fri Jun 17 07:52:28 2005 +0000 @@ -82,8 +82,6 @@ extern std::string unique_symbol_name (const std::string& basename); -extern bool function_out_of_date (octave_function *fcn); - extern bool lookup (symbol_record *s, bool exec_script = true); extern symbol_record *