Mercurial > jwe > octave
changeset 20770:826a4771718b
warn about shadowed built ins with addpath -end (bug #46553)
* load-path.h, load-path.cc (load_path::add): New argument, UPDATING.
(load_path::loader::add): New argument UPDATING.
(load_path::loader::add_to_fcn_map): New argument UPDATING. Don't
emit shadowed function warnings if updating. Do warn about shadowed
built-in function names even when at_end is true.
(load_path::do_update): Pass updating=true to load_path::add.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 27 Nov 2015 14:10:35 -0500 |
parents | 58e79b0078e4 |
children | ed708a7ce0a2 |
files | libinterp/corefcn/load-path.cc libinterp/corefcn/load-path.h |
diffstat | 2 files changed, 33 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc Fri Nov 27 11:14:46 2015 -0500 +++ b/libinterp/corefcn/load-path.cc Fri Nov 27 14:10:35 2015 -0500 @@ -985,7 +985,7 @@ di.update (); - add (di, true); + add (di, true, "", true); } } @@ -1866,11 +1866,11 @@ void load_path::add (const dir_info& di, bool at_end, - const std::string& pname) const + const std::string& pname, bool updating) const { loader& l = get_loader (pname); - l.add (di, at_end); + l.add (di, at_end, updating); dir_info::package_dir_map_type package_dir_map = di.package_dir_map; @@ -1887,7 +1887,8 @@ } void -load_path::loader::add_to_fcn_map (const dir_info& di, bool at_end) +load_path::loader::add_to_fcn_map (const dir_info& di, bool at_end, + bool updating) { std::string dir_name = di.dir_name; @@ -1932,15 +1933,23 @@ if (p == file_info_list.end ()) { - file_info fi (dir_name, t); - - if (at_end) - file_info_list.push_back (fi); - else + // Warn if a built-in or library function is being shadowed, + // but not if we are just updating (rehashing) the list. + + if (! updating) { - // Warn if a built-in or library function is being shadowed. - - if (! file_info_list.empty ()) + if (file_info_list.empty ()) + { + 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 ()); + } + } + else if (! at_end) { file_info& old = file_info_list.front (); @@ -1962,16 +1971,14 @@ 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); } + + file_info fi (dir_name, t); + + if (at_end) + file_info_list.push_back (fi); + else + file_info_list.push_front (fi); } else {
--- a/libinterp/corefcn/load-path.h Fri Nov 27 11:14:46 2015 -0500 +++ b/libinterp/corefcn/load-path.h Fri Nov 27 14:10:35 2015 -0500 @@ -514,14 +514,14 @@ return *this; } - void add (const dir_info& di, bool at_end) + void add (const dir_info& di, bool at_end, bool updating) { if (at_end) dir_list.push_back (di.dir_name); else dir_list.push_front (di.dir_name); - add_to_fcn_map (di, at_end); + add_to_fcn_map (di, at_end, updating); add_to_private_fcn_map (di); @@ -565,7 +565,7 @@ string_vector fcn_names (void) const; private: - void add_to_fcn_map (const dir_info& di, bool at_end); + void add_to_fcn_map (const dir_info& di, bool at_end, bool updating); void add_to_private_fcn_map (const dir_info& di); @@ -722,7 +722,8 @@ { return command_line_path; } void add (const dir_info& di, bool at_end, - const std::string& pname = std::string ()) const; + const std::string& pname = std::string (), + bool updating = false) const; friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d); };