changeset 25359:b93522e36446

move common function and script data to octave_user_code class * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::file_name, octave_user_code::t_parsed, octave_user_code::t_checked, octave_user_code::call_depth, octave_user_code::cmd_list): Move data members and associated functions here from octave_user_script and octave_user_function classes. Delete cmd_list in octave_user_code destructor. (octave_user_code::dump): New function. (octave_user_function::dump): Use it to dump base class info.
author John W. Eaton <jwe@octave.org>
date Fri, 04 May 2018 16:18:30 -0400
parents 8cac064e6623
children bc5f225bc578
files libinterp/octave-value/ov-usr-fcn.cc libinterp/octave-value/ov-usr-fcn.h
diffstat 2 files changed, 71 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.cc	Sun May 06 17:33:02 2018 -0700
+++ b/libinterp/octave-value/ov-usr-fcn.cc	Fri May 04 16:18:30 2018 -0400
@@ -64,14 +64,17 @@
 
 octave_user_code::~octave_user_code (void)
 {
+  // FIXME: shouldn't this happen automatically when deleting cmd_list?
+  if (cmd_list)
+    cmd_list->remove_all_breakpoints (file_name);
+
+  delete cmd_list;
   delete m_file_info;
 }
 
 void
 octave_user_code::get_file_info (void)
 {
-  std::string file_name = fcn_file_name ();
-
   m_file_info = new octave::file_info (file_name);
 
   octave::sys::file_stat fs (file_name);
@@ -118,6 +121,20 @@
   return std::map<std::string, octave_value> ();
 }
 
+octave_value
+octave_user_code::dump (void) const
+{
+  std::map<std::string, octave_value> m
+    = {{ "scope_info", m_scope ? m_scope.dump () : "0x0" },
+       { "file_name", file_name },
+       { "time_parsed", t_parsed },
+       { "time_checked", t_checked },
+       { "call_depth", call_depth }};
+
+  return octave_value (m);
+}
+
+
 // User defined scripts.
 
 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_script,
@@ -125,20 +142,14 @@
                                      "user-defined script");
 
 octave_user_script::octave_user_script (void)
-  : octave_user_code (), cmd_list (nullptr), file_name (),
-    t_parsed (static_cast<time_t> (0)),
-    t_checked (static_cast<time_t> (0)),
-    call_depth (-1)
+  : octave_user_code ()
 { }
 
 octave_user_script::octave_user_script
   (const std::string& fnm, const std::string& nm,
    const octave::symbol_scope& scope, octave::tree_statement_list *cmds,
    const std::string& ds)
-  : octave_user_code (nm, scope, ds), cmd_list (cmds), file_name (fnm),
-    t_parsed (static_cast<time_t> (0)),
-    t_checked (static_cast<time_t> (0)),
-    call_depth (-1)
+  : octave_user_code (fnm, nm, scope, cmds, ds)
 {
   if (cmd_list)
     cmd_list->mark_as_script_body ();
@@ -147,20 +158,9 @@
 octave_user_script::octave_user_script
   (const std::string& fnm, const std::string& nm,
    const octave::symbol_scope& scope, const std::string& ds)
-  : octave_user_code (nm, scope, ds), cmd_list (nullptr), file_name (fnm),
-    t_parsed (static_cast<time_t> (0)),
-    t_checked (static_cast<time_t> (0)),
-    call_depth (-1)
+    : octave_user_code (fnm, nm, scope, nullptr, ds)
 { }
 
-octave_user_script::~octave_user_script (void)
-{
-  if (cmd_list)
-    cmd_list->remove_all_breakpoints (file_name);
-
-  delete cmd_list;
-}
-
 octave_value_list
 octave_user_script::call (octave::tree_evaluator& tw, int nargout,
                           const octave_value_list& args)
@@ -242,13 +242,11 @@
 octave_user_function::octave_user_function
   (const octave::symbol_scope& scope, octave::tree_parameter_list *pl,
    octave::tree_parameter_list *rl, octave::tree_statement_list *cl)
-  : octave_user_code ("", scope, ""),
-    param_list (pl), ret_list (rl), cmd_list (cl),
-    lead_comm (), trail_comm (), file_name (),
+  : octave_user_code ("", "", scope, cl, ""),
+    param_list (pl), ret_list (rl),
+    lead_comm (), trail_comm (),
     location_line (0), location_column (0),
-    parent_name (), t_parsed (static_cast<time_t> (0)),
-    t_checked (static_cast<time_t> (0)),
-    system_fcn_file (false), call_depth (-1),
+    parent_name (), system_fcn_file (false),
     num_named_args (param_list ? param_list->length () : 0),
     subfunction (false), inline_function (false),
     anonymous_function (false), nested_function (false),
@@ -266,13 +264,8 @@
 
 octave_user_function::~octave_user_function (void)
 {
-  // FIXME: shouldn't this happen automatically when deleting cmd_list?
-  if (cmd_list)
-    cmd_list->remove_all_breakpoints (file_name);
-
   delete param_list;
   delete ret_list;
-  delete cmd_list;
   delete lead_comm;
   delete trail_comm;
 
@@ -289,12 +282,6 @@
   return this;
 }
 
-void
-octave_user_function::stash_fcn_file_name (const std::string& nm)
-{
-  file_name = nm;
-}
-
 // If there is no explicit end statement at the end of the function,
 // relocate the no_op that was generated for the end of file condition
 // to appear on the next line after the last statement in the file, or
@@ -742,24 +729,20 @@
 octave_user_function::dump (void) const
 {
   std::map<std::string, octave_value> m
-    = {{ "file_name", file_name },
+    = {{ "user_code", octave_user_code::dump () },
        { "line", location_line },
        { "col", location_column },
        { "end_line", end_location_line },
        { "end_col", end_location_column },
-       { "time_parsed", t_parsed },
-       { "time_checked", t_checked },
        { "parent_name", parent_name },
        { "system_fcn_file", system_fcn_file },
-       { "call_depth", call_depth },
        { "num_named_args", num_named_args },
        { "subfunction", subfunction },
        { "inline_function", inline_function },
        { "anonymous_function", anonymous_function },
        { "nested_function", nested_function },
        { "ctor_type", ctor_type_str () },
-       { "class_method", class_method },
-       { "scope_info", m_scope ? m_scope.dump () : "0x0" }};
+       { "class_method", class_method }};
 
   return octave_value (m);
 }
--- a/libinterp/octave-value/ov-usr-fcn.h	Sun May 06 17:33:02 2018 -0700
+++ b/libinterp/octave-value/ov-usr-fcn.h	Fri May 04 16:18:30 2018 -0400
@@ -60,20 +60,19 @@
 {
 protected:
 
-  octave_user_code (const std::string& nm,
+  octave_user_code (const std::string& fnm = "", const std::string& nm = "",
                     const octave::symbol_scope& scope = octave::symbol_scope (),
+                    octave::tree_statement_list *cmds = nullptr,
                     const std::string& ds = "")
-    : octave_function (nm, ds), m_scope (scope), m_file_info (nullptr),
-      curr_unwind_protect_frame (nullptr)
+    : octave_function (nm, ds), m_scope (scope), file_name (fnm),
+      t_parsed (static_cast<time_t> (0)),
+      t_checked (static_cast<time_t> (0)),
+      call_depth (-1), m_file_info (nullptr),
+      curr_unwind_protect_frame (nullptr), cmd_list (cmds)
   { }
 
 public:
 
-  octave_user_code (void)
-    : octave_function (), m_scope (), m_file_info (nullptr),
-      curr_unwind_protect_frame (nullptr)
-  { }
-
   // No copying!
 
   octave_user_code (const octave_user_code& f) = delete;
@@ -99,9 +98,27 @@
 
   octave::symbol_scope scope (void) { return m_scope; }
 
+  void stash_fcn_file_name (const std::string& nm) { file_name = nm; }
+
+  void mark_fcn_file_up_to_date (const octave::sys::time& t) { t_checked = t; }
+
+  void stash_fcn_file_time (const octave::sys::time& t)
+  {
+    t_parsed = t;
+    mark_fcn_file_up_to_date (t);
+  }
+
+  std::string fcn_file_name (void) const { return file_name; }
+
+  octave::sys::time time_parsed (void) const { return t_parsed; }
+
+  octave::sys::time time_checked (void) const { return t_checked; }
+
   virtual std::map<std::string, octave_value> subfunctions (void) const;
 
-  virtual octave::tree_statement_list * body (void) = 0;
+  octave::tree_statement_list * body (void) { return cmd_list; }
+
+  octave_value dump (void) const;
 
 protected:
 
@@ -110,12 +127,28 @@
   // Our symbol table scope.
   octave::symbol_scope m_scope;
 
+  // The name of the file we parsed.
+  std::string file_name;
+
+  // The time the file was parsed.
+  octave::sys::time t_parsed;
+
+  // The time the file was last checked to see if it needs to be
+  // parsed again.
+  octave::sys::time t_checked;
+
+  // Used to keep track of recursion depth.
+  int call_depth;
+
   // Cached text of function or script code with line offsets
   // calculated.
   octave::file_info *m_file_info;
 
   // pointer to the current unwind_protect frame of this function.
   octave::unwind_protect *curr_unwind_protect_frame;
+
+  // The list of commands that make up the body of this function.
+  octave::tree_statement_list *cmd_list;
 };
 
 // Scripts.
@@ -142,7 +175,7 @@
 
   octave_user_script& operator = (const octave_user_script& f) = delete;
 
-  ~octave_user_script (void);
+  ~octave_user_script (void) = default;
 
   octave_function * function_value (bool = false) { return this; }
 
@@ -155,48 +188,14 @@
 
   bool is_user_script (void) const { return true; }
 
-  void stash_fcn_file_name (const std::string& nm) { file_name = nm; }
-
-  void mark_fcn_file_up_to_date (const octave::sys::time& t) { t_checked = t; }
-
-  void stash_fcn_file_time (const octave::sys::time& t)
-  {
-    t_parsed = t;
-    mark_fcn_file_up_to_date (t);
-  }
-
-  std::string fcn_file_name (void) const { return file_name; }
-
-  octave::sys::time time_parsed (void) const { return t_parsed; }
-
-  octave::sys::time time_checked (void) const { return t_checked; }
-
   octave_value_list
   call (octave::tree_evaluator& tw, int nargout = 0,
         const octave_value_list& args = octave_value_list ());
 
-  octave::tree_statement_list * body (void) { return cmd_list; }
-
   void accept (octave::tree_walker& tw);
 
 private:
 
-  // The list of commands that make up the body of this function.
-  octave::tree_statement_list *cmd_list;
-
-  // The name of the file we parsed.
-  std::string file_name;
-
-  // The time the file was parsed.
-  octave::sys::time t_parsed;
-
-  // The time the file was last checked to see if it needs to be
-  // parsed again.
-  octave::sys::time t_checked;
-
-  // Used to keep track of recursion depth.
-  int call_depth;
-
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };
 
@@ -236,8 +235,6 @@
 
   octave_user_function * define_ret_list (octave::tree_parameter_list *t);
 
-  void stash_fcn_file_name (const std::string& nm);
-
   void stash_fcn_location (int line, int col)
   {
     location_line = line;
@@ -266,24 +263,10 @@
 
   void stash_trailing_comment (octave::comment_list *tc) { trail_comm = tc; }
 
-  void mark_fcn_file_up_to_date (const octave::sys::time& t) { t_checked = t; }
-
-  void stash_fcn_file_time (const octave::sys::time& t)
-  {
-    t_parsed = t;
-    mark_fcn_file_up_to_date (t);
-  }
-
-  std::string fcn_file_name (void) const { return file_name; }
-
   std::string profiler_name (void) const;
 
   std::string parent_fcn_name (void) const { return parent_name; }
 
-  octave::sys::time time_parsed (void) const { return t_parsed; }
-
-  octave::sys::time time_checked (void) const { return t_checked; }
-
   void mark_as_system_fcn_file (void);
 
   bool is_system_fcn_file (void) const { return system_fcn_file; }
@@ -380,8 +363,6 @@
 
   octave::tree_parameter_list * return_list (void) { return ret_list; }
 
-  octave::tree_statement_list * body (void) { return cmd_list; }
-
   octave::comment_list * leading_comment (void) { return lead_comm; }
 
   octave::comment_list * trailing_comment (void) { return trail_comm; }
@@ -420,18 +401,12 @@
   // this function.
   octave::tree_parameter_list *ret_list;
 
-  // The list of commands that make up the body of this function.
-  octave::tree_statement_list *cmd_list;
-
   // The comments preceding the FUNCTION token.
   octave::comment_list *lead_comm;
 
   // The comments preceding the ENDFUNCTION token.
   octave::comment_list *trail_comm;
 
-  // The name of the file we parsed.
-  std::string file_name;
-
   // Location where this function was defined.
   int location_line;
   int location_column;
@@ -441,21 +416,11 @@
   // The name of the parent function, if any.
   std::string parent_name;
 
-  // The time the file was parsed.
-  octave::sys::time t_parsed;
-
-  // The time the file was last checked to see if it needs to be
-  // parsed again.
-  octave::sys::time t_checked;
-
   // True if this function came from a file that is considered to be a
   // system function.  This affects whether we check the time stamp
   // on the file to see if it has changed.
   bool system_fcn_file;
 
-  // Used to keep track of recursion depth.
-  int call_depth;
-
   // The number of arguments that have names.
   int num_named_args;