Mercurial > hg > octave-nkf
changeset 10242:4acae5e46738
warn when core functions are shadowed
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 01 Feb 2010 10:44:32 +0100 |
parents | a277ba5da4dc |
children | 8cea060a6c85 |
files | src/ChangeLog src/load-path.cc |
diffstat | 2 files changed, 47 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-02-01 Jaroslav Hajek <highegg@gmail.com> + + * load-path.cc (load_path::add_to_fcn_map): Warn when core library or + built-in functions are being shadowed. + (load_path::do_add): Pass at_end to add_to_fcn_map, add_to_method_map. + Don't abort when "." not yet included. + (load_path::do_clear): Don't append "." here. + (load_path::do_set): Always prepend "." here. + (load_path::initialize): Don't explicitly include "." here. + 2010-02-02 John W. Eaton <jwe@octave.org> * DLD-FUNCTIONS/filter.cc (filter (MArray<T>&, MArray<T>&,
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -500,13 +500,17 @@ if (tpath.empty ()) tpath = octave_env::getenv ("OCTAVE_PATH"); - std::string xpath = "."; + std::string xpath; if (! tpath.empty ()) - xpath += dir_path::path_sep_str () + tpath; - - if (! sys_path.empty ()) - xpath += dir_path::path_sep_str () + sys_path; + { + xpath = tpath; + + if (! sys_path.empty ()) + xpath += dir_path::path_sep_str () + sys_path; + } + else + xpath = sys_path; do_set (xpath, false); } @@ -518,8 +522,6 @@ fcn_map.clear (); private_fcn_map.clear (); method_map.clear (); - - do_append (".", false); } static std::list<std::string> @@ -584,6 +586,9 @@ if (add_hook) add_hook (i->dir_name); } + + // Always prepend current directory. + do_prepend (".", warn); } void @@ -632,11 +637,11 @@ else dir_info_list.push_front (di); - add_to_fcn_map (di, true); + add_to_fcn_map (di, at_end); add_to_private_fcn_map (di); - add_to_method_map (di, true); + add_to_method_map (di, at_end); if (add_hook) add_hook (dir); @@ -658,8 +663,6 @@ if (i != dir_info_list.end ()) move (i, false); - else - panic_impossible (); } void @@ -1672,7 +1675,29 @@ if (at_end) file_info_list.push_back (fi); else - file_info_list.push_front (fi); + { + // Warn if a built-in or library function is being shadowed. + if (! file_info_list.empty ()) + { + file_info& old = file_info_list.front (); + if (sys_path.find (old.dir_name) != std::string::npos) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning_with_id ("Octave:shadowed-function", + "function %s shadows a core library function", + fcn_path.c_str ()); + } + } + else if (symbol_table::is_built_in_function_name (base)) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning_with_id ("Octave:shadowed-function", + "function %s shadows a built-in function", + fcn_path.c_str ()); + } + + file_info_list.push_front (fi); + } } else {