diff libinterp/parse-tree/parse.h @ 28698:d45d1b4bb919 stable

allow functions to be redefined in scripts (bug #52851) * parse.h, oct-parse.yy (base_parser::parent_scope_info::m_parser): New data member to allow access to parent parser object. Update constructor and use. (base_parser::parent_scope_info::name_ok): Only fail when a duplicate is found if parsing a subfunction, local function, or nested function. (base_parser::parsing_subfunctions, base_parser::curr_fcn_depth): Provide access to the corresponding member variables. * test/bug-52851/bug-52851.tst, test/bug-52851/script1.m, test/bug-52851/script2.m, test/bug-52851/script3.m, test/bug-52851/script4.m: New test files. * test/bug-52851/module.mk: New file. * test/module.mk b/test/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Wed, 09 Sep 2020 13:41:46 -0400
parents 59dfd9ed72a3
children 61a089ada620 45d958bc3437
line wrap: on
line diff
--- a/libinterp/parse-tree/parse.h	Tue Sep 08 22:41:19 2020 -0400
+++ b/libinterp/parse-tree/parse.h	Wed Sep 09 13:41:46 2020 -0400
@@ -112,7 +112,11 @@
       typedef std::deque<value_type>::reverse_iterator reverse_iterator;
       typedef std::deque<value_type>::const_reverse_iterator const_reverse_iterator;
 
-      parent_scope_info (void) = default;
+      parent_scope_info (void) = delete;
+
+      parent_scope_info (base_parser& parser)
+        : m_parser (parser), m_info (), m_all_names ()
+      { }
 
       parent_scope_info (const parent_scope_info&) = default;
 
@@ -140,6 +144,7 @@
 
     private:
 
+      base_parser& m_parser;
       std::deque<value_type> m_info;
       std::set<std::string> m_all_names;
     };
@@ -179,6 +184,16 @@
       return m_stmt_list;
     }
 
+    void parsing_subfunctions (bool flag)
+    {
+      m_parsing_subfunctions = flag;
+    }
+
+    bool parsing_subfunctions (void) const
+    {
+      return m_parsing_subfunctions;
+    }
+
     void parsing_local_functions (bool flag)
     {
       m_parsing_local_functions = flag;
@@ -189,6 +204,11 @@
       return m_parsing_local_functions;
     }
 
+    int curr_fcn_depth (void) const
+    {
+      return m_curr_fcn_depth;
+    }
+
     void endfunction_found (bool flag)
     {
       m_endfunction_found = flag;