comparison src/load-path.cc @ 10334:db540cb0e959

improve shadowed function checking
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 18 Feb 2010 08:40:17 +0100
parents 97b4bd6f0925
children ba932ad87a04
comparison
equal deleted inserted replaced
10333:0c42b6b7da24 10334:db540cb0e959
1615 os << "\n"; 1615 os << "\n";
1616 1616
1617 #endif 1617 #endif
1618 } 1618 }
1619 1619
1620 // True if a path is contained in a path list separated by path_sep_char
1621 static bool
1622 in_path_list (const std::string& path_list, const std::string& path)
1623 {
1624 size_t ps = path.size (), pls = path_list.size (), pos = path_list.find (path);
1625 char psc = dir_path::path_sep_char ();
1626 while (pos != std::string::npos)
1627 {
1628 if ((pos == 0 || path_list[pos-1] == psc)
1629 && (pos + ps == pls || path_list[pos + ps] == psc))
1630 return true;
1631 else
1632 pos = path_list.find (path, pos + 1);
1633 }
1634
1635 return false;
1636 }
1637
1620 void 1638 void
1621 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const 1639 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const
1622 { 1640 {
1623 std::string dir_name = di.dir_name; 1641 std::string dir_name = di.dir_name;
1624 1642
1672 // Warn if a built-in or library function is being shadowed. 1690 // Warn if a built-in or library function is being shadowed.
1673 if (! file_info_list.empty ()) 1691 if (! file_info_list.empty ())
1674 { 1692 {
1675 file_info& old = file_info_list.front (); 1693 file_info& old = file_info_list.front ();
1676 if (sys_path.find (old.dir_name) != std::string::npos) 1694 if (sys_path.find (old.dir_name) != std::string::npos)
1695 if (in_path_list (sys_path, old.dir_name))
1677 { 1696 {
1678 std::string fcn_path = file_ops::concat (dir_name, fname); 1697 std::string fcn_path = file_ops::concat (dir_name, fname);
1679 warning_with_id ("Octave:shadowed-function", 1698 warning_with_id ("Octave:shadowed-function",
1680 "function %s shadows a core library function", 1699 "function %s shadows a core library function",
1681 fcn_path.c_str ()); 1700 fcn_path.c_str ());