diff libinterp/octave-value/ov-usr-fcn.h @ 23728:b40b7243a782

new class for caching file contents for debug and echo * liboctave/util/file-info.h, liboctave/util/file-info.cc: New files. Move get_file_line function here from bp-table.h and bp-table.cc. * liboctave/util/module.mk: Update. * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::m_file_info, octave_user_code::get_code_line, octave_user_code::get_code_lines): New data member and functions. Change all uses of get_file_line to access code lines from info cached in function object.
author John W. Eaton <jwe@octave.org>
date Wed, 05 Jul 2017 09:44:01 -0400
parents ab8831d346c1
children 06b3d1d54054
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.h	Wed Jul 05 20:26:14 2017 +0200
+++ b/libinterp/octave-value/ov-usr-fcn.h	Wed Jul 05 09:44:01 2017 -0400
@@ -43,6 +43,7 @@
 
 namespace octave
 {
+  class file_info;
   class tree_parameter_list;
   class tree_statement_list;
   class tree_evaluator;
@@ -61,7 +62,9 @@
 
   octave_user_code (const std::string& nm,
                     const std::string& ds = "")
-    : octave_function (nm, ds) { }
+    : octave_function (nm, ds), curr_unwind_protect_frame (0),
+      m_file_info (0)
+  { }
 
 public:
 
@@ -74,13 +77,33 @@
 
   octave_user_code& operator = (const octave_user_code& f) = delete;
 
-  ~octave_user_code (void) = default;
+  ~octave_user_code (void);
 
   bool is_user_code (void) const { return true; }
 
+  octave::unwind_protect *
+  unwind_protect_frame (void)
+  {
+    return curr_unwind_protect_frame;
+  }
+
+  std::string get_code_line (size_t line);
+
+  std::deque<std::string> get_code_lines (size_t line, size_t num_lines);
+
+
   virtual std::map<std::string, octave_value> subfunctions (void) const;
 
   virtual octave::tree_statement_list * body (void) = 0;
+
+protected:
+
+  // pointer to the current unwind_protect frame of this function.
+  octave::unwind_protect *curr_unwind_protect_frame;
+
+  // Cached text of function or script code with line offsets
+  // calculated.
+  octave::file_info *m_file_info;
 };
 
 // Scripts.