comparison src/load-path.cc @ 10242:4acae5e46738

warn when core functions are shadowed
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 01 Feb 2010 10:44:32 +0100
parents cd96d29c5efa
children 2d47356a7a1a
comparison
equal deleted inserted replaced
10241:a277ba5da4dc 10242:4acae5e46738
498 std::string tpath = load_path::command_line_path; 498 std::string tpath = load_path::command_line_path;
499 499
500 if (tpath.empty ()) 500 if (tpath.empty ())
501 tpath = octave_env::getenv ("OCTAVE_PATH"); 501 tpath = octave_env::getenv ("OCTAVE_PATH");
502 502
503 std::string xpath = "."; 503 std::string xpath;
504 504
505 if (! tpath.empty ()) 505 if (! tpath.empty ())
506 xpath += dir_path::path_sep_str () + tpath; 506 {
507 507 xpath = tpath;
508 if (! sys_path.empty ()) 508
509 xpath += dir_path::path_sep_str () + sys_path; 509 if (! sys_path.empty ())
510 xpath += dir_path::path_sep_str () + sys_path;
511 }
512 else
513 xpath = sys_path;
510 514
511 do_set (xpath, false); 515 do_set (xpath, false);
512 } 516 }
513 517
514 void 518 void
516 { 520 {
517 dir_info_list.clear (); 521 dir_info_list.clear ();
518 fcn_map.clear (); 522 fcn_map.clear ();
519 private_fcn_map.clear (); 523 private_fcn_map.clear ();
520 method_map.clear (); 524 method_map.clear ();
521
522 do_append (".", false);
523 } 525 }
524 526
525 static std::list<std::string> 527 static std::list<std::string>
526 split_path (const std::string& p) 528 split_path (const std::string& p)
527 { 529 {
582 i++) 584 i++)
583 { 585 {
584 if (add_hook) 586 if (add_hook)
585 add_hook (i->dir_name); 587 add_hook (i->dir_name);
586 } 588 }
589
590 // Always prepend current directory.
591 do_prepend (".", warn);
587 } 592 }
588 593
589 void 594 void
590 load_path::do_append (const std::string& dir, bool warn) 595 load_path::do_append (const std::string& dir, bool warn)
591 { 596 {
630 if (at_end) 635 if (at_end)
631 dir_info_list.push_back (di); 636 dir_info_list.push_back (di);
632 else 637 else
633 dir_info_list.push_front (di); 638 dir_info_list.push_front (di);
634 639
635 add_to_fcn_map (di, true); 640 add_to_fcn_map (di, at_end);
636 641
637 add_to_private_fcn_map (di); 642 add_to_private_fcn_map (di);
638 643
639 add_to_method_map (di, true); 644 add_to_method_map (di, at_end);
640 645
641 if (add_hook) 646 if (add_hook)
642 add_hook (dir); 647 add_hook (dir);
643 } 648 }
644 } 649 }
656 661
657 i = find_dir_info ("."); 662 i = find_dir_info (".");
658 663
659 if (i != dir_info_list.end ()) 664 if (i != dir_info_list.end ())
660 move (i, false); 665 move (i, false);
661 else
662 panic_impossible ();
663 } 666 }
664 667
665 void 668 void
666 load_path::remove_fcn_map (const std::string& dir, 669 load_path::remove_fcn_map (const std::string& dir,
667 const string_vector& fcn_files) 670 const string_vector& fcn_files)
1670 file_info fi (dir_name, t); 1673 file_info fi (dir_name, t);
1671 1674
1672 if (at_end) 1675 if (at_end)
1673 file_info_list.push_back (fi); 1676 file_info_list.push_back (fi);
1674 else 1677 else
1675 file_info_list.push_front (fi); 1678 {
1679 // Warn if a built-in or library function is being shadowed.
1680 if (! file_info_list.empty ())
1681 {
1682 file_info& old = file_info_list.front ();
1683 if (sys_path.find (old.dir_name) != std::string::npos)
1684 {
1685 std::string fcn_path = file_ops::concat (dir_name, fname);
1686 warning_with_id ("Octave:shadowed-function",
1687 "function %s shadows a core library function",
1688 fcn_path.c_str ());
1689 }
1690 }
1691 else if (symbol_table::is_built_in_function_name (base))
1692 {
1693 std::string fcn_path = file_ops::concat (dir_name, fname);
1694 warning_with_id ("Octave:shadowed-function",
1695 "function %s shadows a built-in function",
1696 fcn_path.c_str ());
1697 }
1698
1699 file_info_list.push_front (fi);
1700 }
1676 } 1701 }
1677 else 1702 else
1678 { 1703 {
1679 file_info& fi = *p; 1704 file_info& fi = *p;
1680 1705