changeset 23667:2d4a7ae1f6cd

store directory and package names in function when function is parsed * symtab.h, symtab.cc (symbol_table::scope::stash_dir_name_for_subfunctions): Delete obsolete function. * lex.h, lex.ll (lexical_feedback::dir_name, lexical_feedback::package_name): New data members. (lexical_feedback::lexical_feedback): Initialize. (lexical_feedback::reset): Reset. * oct-parse.in.yy (base_parser::frob_function): Store directory and package names in function when function is parsed. (F__parse_file__): Perform tilde expansion on file name.
author John W. Eaton <jwe@octave.org>
date Wed, 21 Jun 2017 11:29:41 -0400
parents a835c62d3001
children a6eef0626b2b
files libinterp/corefcn/symtab.cc libinterp/corefcn/symtab.h libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy
diffstat 5 files changed, 50 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symtab.cc	Wed Jun 21 10:26:29 2017 -0400
+++ b/libinterp/corefcn/symtab.cc	Wed Jun 21 11:29:41 2017 -0400
@@ -1806,18 +1806,6 @@
 }
 
 void
-symbol_table::scope::stash_dir_name_for_subfunctions (const std::string& dir_name)
-{
-  for (const auto& nm_sf : m_subfunctions)
-    {
-      octave_user_function *fcn = nm_sf.second.user_function_value ();
-
-      if (fcn)
-        fcn->stash_dir_name (dir_name);
-    }
-}
-
-void
 symbol_table::scope::mark_subfunctions_in_scope_as_private (const std::string& class_name)
 {
   for (auto& nm_sf : m_subfunctions)
--- a/libinterp/corefcn/symtab.h	Wed Jun 21 10:26:29 2017 -0400
+++ b/libinterp/corefcn/symtab.h	Wed Jun 21 11:29:41 2017 -0400
@@ -2006,8 +2006,6 @@
       m_subfunctions.clear ();
     }
 
-    void stash_dir_name_for_subfunctions (const std::string& dir_name);
-
     void mark_subfunctions_in_scope_as_private (const std::string& class_name);
 
     std::list<workspace_element> workspace_info (void) const;
--- a/libinterp/parse-tree/lex.h	Wed Jun 21 10:26:29 2017 -0400
+++ b/libinterp/parse-tree/lex.h	Wed Jun 21 11:29:41 2017 -0400
@@ -280,9 +280,10 @@
         block_comment_nesting_level (0), command_arg_paren_count (0),
         token_count (0), current_input_line (), comment_text (),
         help_text (), string_text (), string_line (0), string_column (0),
-        fcn_file_name (), fcn_file_full_name (), looking_at_object_index (),
-        parsed_function_name (), pending_local_variables (),
-        symtab_context (), nesting_level (), tokens ()
+        fcn_file_name (), fcn_file_full_name (), dir_name (),
+        package_name (), looking_at_object_index (), parsed_function_name (),
+        pending_local_variables (), symtab_context (), nesting_level (),
+        tokens ()
     {
       init ();
     }
@@ -439,6 +440,12 @@
     // Full name of file we are reading.
     std::string fcn_file_full_name;
 
+    // Directory name where this file was found.  May be relative.
+    std::string dir_name;
+
+    // Name of +package containing this file, if any.
+    std::string package_name;
+
     // if the front of the list is true, the closest paren, brace, or
     // bracket nesting is an index for an object.
     std::list<bool> looking_at_object_index;
--- a/libinterp/parse-tree/lex.ll	Wed Jun 21 10:26:29 2017 -0400
+++ b/libinterp/parse-tree/lex.ll	Wed Jun 21 11:29:41 2017 -0400
@@ -2179,6 +2179,8 @@
     string_column = 0;
     fcn_file_name = "";
     fcn_file_full_name = "";
+    dir_name = "";
+    package_name = "";
     looking_at_object_index.clear ();
     looking_at_object_index.push_front (false);
 
--- a/libinterp/parse-tree/oct-parse.in.yy	Wed Jun 21 10:26:29 2017 -0400
+++ b/libinterp/parse-tree/oct-parse.in.yy	Wed Jun 21 11:29:41 2017 -0400
@@ -3325,6 +3325,8 @@
 
         fcn->stash_fcn_file_name (lexer.fcn_file_full_name);
         fcn->stash_fcn_file_time (now);
+        fcn->stash_dir_name (lexer.dir_name);
+        fcn->stash_package_name (lexer.package_name);
         fcn->mark_as_system_fcn_file ();
 
         if (fcn_file_from_relative_lookup)
@@ -4378,10 +4380,10 @@
 
 static octave_value
 parse_fcn_file (const std::string& full_file, const std::string& file,
-                const std::string& dispatch_type,
-                const std::string& package_name,
-                bool require_file, bool force_script, bool autoload,
-                bool relative_lookup, const std::string& warn_for)
+                const std::string& dir_name, const std::string& dispatch_type,
+                const std::string& package_name, bool require_file,
+                bool force_script, bool autoload, bool relative_lookup,
+                const std::string& warn_for)
 {
   octave_value retval;
 
@@ -4422,6 +4424,8 @@
 
       parser.lexer.fcn_file_name = file;
       parser.lexer.fcn_file_full_name = full_file;
+      parser.lexer.dir_name = dir_name;
+      parser.lexer.package_name = package_name;
 
       int status = parser.run ();
 
@@ -4511,8 +4515,8 @@
         symbol_found = true;
 
         octave_value ov_fcn
-          = parse_fcn_file (full_file, file, "", "", true, false, false, false,
-                            "");
+          = parse_fcn_file (full_file, file, "", "", "", true,
+                            false, false, false, "");
 
         if (ov_fcn.is_defined ())
           {
@@ -4577,7 +4581,8 @@
   }
 
   octave_value
-  load_fcn_from_file (const std::string& file_name, const std::string& dir_name,
+  load_fcn_from_file (const std::string& file_name,
+                      const std::string& dir_name,
                       const std::string& dispatch_type,
                       const std::string& package_name,
                       const std::string& fcn_name, bool autoload)
@@ -4635,9 +4640,9 @@
         std::string doc_string;
 
         octave_value ov_fcn
-          = parse_fcn_file (file.substr (0, len - 2), nm, dispatch_type,
-                            package_name, false, autoload, autoload,
-                            relative_lookup, "");
+          = parse_fcn_file (file.substr (0, len - 2), nm, dir_name,
+                            dispatch_type, package_name, false,
+                            autoload, autoload, relative_lookup, "");
 
         if (ov_fcn.is_defined ())
           {
@@ -4659,27 +4664,9 @@
       }
     else if (len > 2)
       {
-        retval = parse_fcn_file (file, nm, dispatch_type, package_name, true,
-                                 autoload, autoload, relative_lookup, "");
-      }
-
-    if (retval.is_defined ())
-      {
-        octave_function *tmpfcn = retval.function_value ();
-
-        if (tmpfcn)
-          {
-            tmpfcn->stash_dir_name (dir_name);
-            tmpfcn->stash_package_name (package_name);
-
-            if (tmpfcn->is_user_function ())
-              {
-                symbol_table::scope *scope = tmpfcn->scope ();
-
-                if (scope)
-                  scope->stash_dir_name_for_subfunctions (dir_name);
-              }
-          }
+        retval = parse_fcn_file (file, nm, dir_name, dispatch_type,
+                                 package_name, true, autoload, autoload,
+                                 relative_lookup, "");
       }
 
     return retval;
@@ -4853,6 +4840,11 @@
     std::string file_full_name
       = octave::sys::file_ops::tilde_expand (file_name);
 
+    size_t pos
+      = file_full_name.find_last_of (octave::sys::file_ops::dir_sep_str ());
+
+    std::string dir_name = file_full_name.substr (0, pos);
+
     file_full_name = octave::sys::env::make_absolute (file_full_name);
 
     octave::unwind_protect frame;
@@ -4922,9 +4914,9 @@
       {
         try
           {
-            ov_code = parse_fcn_file (file_full_name, file_name, "", "",
-                                      require_file, true, false, false,
-                                      warn_for);
+            ov_code = parse_fcn_file (file_full_name, file_name, dir_name,
+                                      "", "", require_file, true, false,
+                                      false, warn_for);
           }
         catch (octave::execution_exception& e)
           {
@@ -5826,7 +5818,12 @@
 
   std::string file = args(0).xstring_value ("__parse_file__: expecting filename as argument");
 
-  std::string full_file = octave::sys::env::make_absolute (file);
+  std::string full_file
+      = octave::sys::file_ops::tilde_expand (file);
+
+  full_file = octave::sys::env::make_absolute (full_file);
+
+  std::string dir_name;
 
   size_t file_len = file.length ();
 
@@ -5839,15 +5836,18 @@
 
       size_t pos = file.find_last_of (octave::sys::file_ops::dir_sep_str ());
       if (pos != std::string::npos)
-        file = file.substr (pos+1);
+        {
+          dir_name = file.substr (0, pos);
+          file = file.substr (pos+1);
+        }
     }
 
   if (nargin == 2)
     octave_stdout << "parsing " << full_file << std::endl;
 
   octave_value ov_fcn
-    = parse_fcn_file (full_file, file, "", "", true, false, false,
-                      false, "__parse_file__");
+    = parse_fcn_file (full_file, file, dir_name, "", "", true, false,
+                      false, false, "__parse_file__");
 
   return retval;
 }