changeset 24354:11d3603dd880

give names to anonymous function scopes * symscope.h (symbol_scope::dup): Also copy scope name. (octave_fcn_handle::load_ascii, octave_fcn_handle::load_binary, octave_fcn_handle::load_hdf5): Set scope name to text of anonymous function definition. * oct-parse.in.yy (push_fcn_symtab, param_list_beg, push_script_symtab): Set temporary name for new scope. (base_parser::make_anon_fcn_handle): Set scope name.
author John W. Eaton <jwe@octave.org>
date Sun, 03 Dec 2017 16:42:16 -0500
parents b153e3a70cfd
children cc3b3ceb155c
files libinterp/corefcn/symscope.h libinterp/octave-value/ov-fcn-handle.cc libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/pt-fcn-handle.cc
diffstat 4 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symscope.h	Thu Nov 30 16:31:55 2017 -0500
+++ b/libinterp/corefcn/symscope.h	Sun Dec 03 16:42:16 2017 -0500
@@ -96,7 +96,7 @@
 
     symbol_scope * dup (void) const
     {
-      symbol_scope *new_sid = new symbol_scope ();
+      symbol_scope *new_sid = new symbol_scope (m_name);
 
       for (const auto& nm_sr : m_symbols)
         new_sid->insert_symbol_record (nm_sr.second.dup (new_sid));
--- a/libinterp/octave-value/ov-fcn-handle.cc	Thu Nov 30 16:31:55 2017 -0500
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Sun Dec 03 16:42:16 2017 -0500
@@ -468,7 +468,7 @@
       octave::symbol_table& symtab
         = octave::__get_symbol_table__ ("octave_fcn_handle::load_ascii");
 
-      octave::symbol_scope local_scope;
+      octave::symbol_scope local_scope (buf);
 
       symtab.set_scope (&local_scope);
 
@@ -634,7 +634,7 @@
       octave::symbol_table& symtab
         = octave::__get_symbol_table__ ("octave_fcn_handle::load_binary");
 
-      octave::symbol_scope local_scope;
+      octave::symbol_scope local_scope (ctmp2);
 
       symtab.set_scope (&local_scope);
 
@@ -1136,7 +1136,7 @@
       octave::symbol_table& symtab
         = octave::__get_symbol_table__ ("octave_fcn_handle::load_hdf5");
 
-      octave::symbol_scope local_scope;
+      octave::symbol_scope local_scope (fcn_tmp);
 
       symtab.set_scope (&local_scope);
 
--- a/libinterp/parse-tree/oct-parse.in.yy	Thu Nov 30 16:31:55 2017 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Sun Dec 03 16:42:16 2017 -0500
@@ -1284,7 +1284,8 @@
                     if (parser.m_max_fcn_depth < parser.m_curr_fcn_depth)
                       parser.m_max_fcn_depth = parser.m_curr_fcn_depth;
 
-                    lexer.symtab_context.push (new octave::symbol_scope ());
+                    // Will get a real name later.
+                    lexer.symtab_context.push (new octave::symbol_scope ("parser:push_fcn_symtab"));
 
                     parser.m_function_scopes.push (lexer.symtab_context.curr_scope ());
 
@@ -1314,7 +1315,8 @@
 
                     if (lexer.looking_at_function_handle)
                       {
-                        lexer.symtab_context.push (new octave::symbol_scope ());
+                        // Will get a real name later.
+                        lexer.symtab_context.push (new octave::symbol_scope ("parser:param_lsit_beg"));
                         lexer.looking_at_function_handle--;
                         lexer.looking_at_anon_fcn_args = true;
                       }
@@ -1451,7 +1453,8 @@
                   {
                     $$ = 0;
 
-                    lexer.symtab_context.push (new octave::symbol_scope ());
+                    // Will get a real name later.
+                    lexer.symtab_context.push (new octave::symbol_scope ("parser:push_script_symtab"));
                   }
                 ;
 
@@ -2460,6 +2463,25 @@
       = new tree_anon_fcn_handle (param_list, expr, fcn_scope,
                                   parent_scope, l, c);
 
+    std::ostringstream buf;
+
+    tree_print_code tpc (buf);
+
+    retval->accept (tpc);
+
+    std::string file = m_lexer.fcn_file_full_name;
+    if (! file.empty ())
+      buf << ": file: " << file;
+    else if (m_lexer.input_from_terminal ())
+      buf << ": *terminal input*";
+    else if (m_lexer.input_from_eval_string ())
+      buf << ": *eval string*";
+    buf << ": line: " << l << " column: " << c;
+
+    std::string scope_name = buf.str ();
+
+    fcn_scope->cache_name (scope_name);
+
     // FIXME: Stash the filename.  This does not work and produces
     // errors when executed.
     //retval->stash_file_name (m_lexer.fcn_file_name);
--- a/libinterp/parse-tree/pt-fcn-handle.cc	Thu Nov 30 16:31:55 2017 -0500
+++ b/libinterp/parse-tree/pt-fcn-handle.cc	Sun Dec 03 16:42:16 2017 -0500
@@ -83,6 +83,8 @@
     if (new_scope)
       symtab.inherit (new_scope);
 
+    // FIXME: if new scope is nullptr, then we are in big trouble here...
+
     tree_anon_fcn_handle *new_afh = new
       tree_anon_fcn_handle (param_list ? param_list->dup (*new_scope) : nullptr,
                             expr ? expr->dup (*new_scope) : nullptr,