changeset 31727:1f04951057bf

avoid some calls to get_input_system and get_evaluator Provide some convenience functions so that instead of writing things like input_system& input_sys = interp.get_input_system (); input_sys.PS1 (prompt); we can just write interp.PS1 (prompt); Although this a minor change, I think it will make writing extensions for Octave easier if we provide access to most features through the interpreter object itself instead of requiring users to first obtain access to an internal object. * interpreter.h, interpreter.cc (interpreter::PS1, interpreter::set_PS1, interpreter::PS2, interpreter::set_PS2, interpreter::PS4, interpreter::set_PS4): New convenience functions. Instead of getting a reference to the input_system or tree_evaluator object from the interpreter and then calling the PS1, PS2, etc. function through those references, just call through the reference to the interpreter object.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Jan 2023 21:45:45 -0500
parents eacd3dee4b01
children 59923ee35263
files libgui/src/command-widget.cc libgui/src/interpreter-qobject.cc libgui/src/main-window.cc libinterp/corefcn/input.cc libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h
diffstat 10 files changed, 97 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/command-widget.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libgui/src/command-widget.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -119,8 +119,7 @@
          if (this_cw.isNull ())
            return;
 
-         input_system& input_sys = interp.get_input_system ();
-         std::string prompt = input_sys.PS1 ();
+         std::string prompt = interp.PS1 ();
          std::string decoded_prompt
            = command_editor::decode_prompt_string (prompt);
 
@@ -168,10 +167,8 @@
          if (this_cw.isNull ())
            return;
 
-         input_system& input_sys = interp.get_input_system ();
-
          std::string prompt
-           = m_incomplete_parse ? input_sys.PS2 () : input_sys.PS1 ();
+           = m_incomplete_parse ? interp.PS2 () : interp.PS1 ();
 
          std::string decoded_prompt
            = command_editor::decode_prompt_string (prompt);
--- a/libgui/src/interpreter-qobject.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libgui/src/interpreter-qobject.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -67,10 +67,8 @@
         if (app_context.start_gui_p ()
             && ! m_octave_qobj.experimental_terminal_widget ())
           {
-            input_system& input_sys = interp.get_input_system ();
-
-            input_sys.PS1 (">> ");
-            input_sys.PS2 ("");
+            interp.PS1 (">> ");
+            interp.PS2 ("");
           }
 
         if (interp.initialized ())
--- a/libgui/src/main-window.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libgui/src/main-window.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -1800,10 +1800,8 @@
             if (this_mw.isNull ())
               return;
 
-            input_system& input_sys = interp.get_input_system ();
-
-            input_sys.PS1 (">> ");
-            std::string prompt = input_sys.PS1 ();
+            interp.PS1 (">> ");
+            std::string prompt = interp.PS1 ();
 
             std::string decoded_prompt
               = command_editor::decode_prompt_string (prompt);
--- a/libinterp/corefcn/input.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/corefcn/input.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -1496,9 +1496,7 @@
 @seealso{PS2, PS4}
 @end deftypefn */)
 {
-  input_system& input_sys = interp.get_input_system ();
-
-  return input_sys.PS1 (args, nargout);
+  return interp.PS1 (args, nargout);
 }
 
 DEFMETHOD (PS2, interp, args, nargout,
@@ -1520,9 +1518,7 @@
 @seealso{PS1, PS4}
 @end deftypefn */)
 {
-  input_system& input_sys = interp.get_input_system ();
-
-  return input_sys.PS2 (args, nargout);
+  return interp.PS2 (args, nargout);
 }
 
 DEFMETHOD (completion_append_char, interp, args, nargout,
--- a/libinterp/corefcn/interpreter.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/corefcn/interpreter.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -1898,6 +1898,66 @@
     m_evaluator.dbcont ();
 }
 
+octave_value interpreter::PS1 (const octave_value_list& args, int nargout)
+{
+  return m_input_system.PS1 (args, nargout);
+}
+
+std::string interpreter::PS1 (void) const
+{
+  return m_input_system.PS1 ();
+}
+
+std::string interpreter::PS1 (const std::string& s)
+{
+  return m_input_system.PS1 (s);
+}
+
+void interpreter::set_PS1 (const std::string& s)
+{
+  m_input_system.set_PS1 (s);
+}
+
+octave_value interpreter::PS2 (const octave_value_list& args, int nargout)
+{
+  return m_input_system.PS2 (args, nargout);
+}
+
+std::string interpreter::PS2 (void) const
+{
+  return m_input_system.PS2 ();
+}
+
+std::string interpreter::PS2 (const std::string& s)
+{
+  return m_input_system.PS2 (s);
+}
+
+void interpreter::set_PS2 (const std::string& s)
+{
+  m_input_system.set_PS2 (s);
+}
+
+octave_value interpreter::PS4 (const octave_value_list& args, int nargout)
+{
+  return m_evaluator.PS4 (args, nargout);
+}
+
+std::string interpreter::PS4 (void) const
+{
+  return m_evaluator.PS4 ();
+}
+
+std::string interpreter::PS4 (const std::string& s)
+{
+  return m_evaluator.PS4 (s);
+}
+
+void interpreter::set_PS4 (const std::string& s)
+{
+  m_evaluator.set_PS4 (s);
+}
+
 // Provided for convenience.  Will be removed once we eliminate the
 // old terminal widget.
 bool interpreter::experimental_terminal_widget (void) const
@@ -2037,10 +2097,9 @@
 
 void interpreter::maximum_braindamage (void)
 {
-  m_input_system.PS1 (">> ");
-  m_input_system.PS2 ("");
-
-  m_evaluator.PS4 ("");
+  PS1 (">> ");
+  PS2 ("");
+  PS4 ("");
 
   m_load_save_system.crash_dumps_octave_core (false);
   m_load_save_system.save_default_options ("-mat-binary");
--- a/libinterp/corefcn/interpreter.h	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/corefcn/interpreter.h	Wed Jan 11 21:45:45 2023 -0500
@@ -512,6 +512,21 @@
   // Resume interpreter execution if paused.
   void resume (void);
 
+  octave_value PS1 (const octave_value_list& args, int nargout);
+  std::string PS1 (void) const;
+  std::string PS1 (const std::string& s);
+  void set_PS1 (const std::string& s);
+
+  octave_value PS2 (const octave_value_list& args, int nargout);
+  std::string PS2 (void) const;
+  std::string PS2 (const std::string& s);
+  void set_PS2 (const std::string& s);
+
+  octave_value PS4 (const octave_value_list& args, int nargout);
+  std::string PS4 (void) const;
+  std::string PS4 (const std::string& s);
+  void set_PS4 (const std::string& s);
+
   // Provided for convenience.  Will be removed once we eliminate the
   // old terminal widget.
   bool experimental_terminal_widget (void) const;
--- a/libinterp/parse-tree/lex.ll	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/parse-tree/lex.ll	Wed Jan 11 21:45:45 2023 -0500
@@ -4010,10 +4010,8 @@
 
     if (m_input_buf.empty ())
       {
-        input_system& input_sys = m_interpreter.get_input_system ();
-
         std::string ps
-          = m_initial_input ? input_sys.PS1 () : input_sys.PS2 ();
+          = m_initial_input ? m_interpreter.PS1 () : m_interpreter.PS2 ();
 
         std::string prompt = command_editor::decode_prompt_string (ps);
 
--- a/libinterp/parse-tree/oct-parse.yy	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/parse-tree/oct-parse.yy	Wed Jan 11 21:45:45 2023 -0500
@@ -5735,10 +5735,8 @@
 
     int exit_status = 0;
 
-    input_system&  input_sys = m_interpreter.get_input_system ();
-
     std::string prompt
-      = command_editor::decode_prompt_string (input_sys.PS1 ());
+      = command_editor::decode_prompt_string (m_interpreter.PS1 ());
 
     do
       {
@@ -5760,7 +5758,7 @@
 
         exit_status = run (input_line, false);
 
-        prompt = command_editor::decode_prompt_string (input_sys.PS2 ());
+        prompt = command_editor::decode_prompt_string (m_interpreter.PS2 ());
       }
     while (exit_status < 0);
 
--- a/libinterp/parse-tree/pt-eval.cc	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Wed Jan 11 21:45:45 2023 -0500
@@ -365,8 +365,8 @@
         if (m_level > 0)
           tmp_prompt = "[" + std::to_string (m_level) + "]" + prompt_arg;
 
-        frame.add (&input_system::set_PS1, &input_sys, input_sys.PS1 ());
-        input_sys.PS1 (tmp_prompt);
+        frame.add (&interpreter::set_PS1, &m_interpreter, m_interpreter.PS1 ());
+        m_interpreter.PS1 (tmp_prompt);
 
         if (! m_interpreter.interactive ())
           {
@@ -439,7 +439,7 @@
 
                     retval = debug_parser.run (input_line, false);
 
-                    prompt = command_editor::decode_prompt_string (input_sys.PS2 ());
+                    prompt = command_editor::decode_prompt_string (m_interpreter.PS2 ());
                   }
                 while (retval < 0);
 
@@ -645,7 +645,6 @@
     bool evaluation_pending = false;
     bool exiting = false;
 
-    input_system& input_sys = m_interpreter.get_input_system ();
     event_manager& evmgr = m_interpreter.get_event_manager ();
 
     while (true)
@@ -654,7 +653,8 @@
         // so, then we need to disable idle event loop hook function
         // execution.
 
-        std::string ps = incomplete_parse ? input_sys.PS2 () : input_sys.PS1 ();
+        std::string ps
+          = incomplete_parse ? m_interpreter.PS2 () : m_interpreter.PS1 ();
 
         std::cout << command_editor::decode_prompt_string (ps);
 
@@ -5470,9 +5470,7 @@
 @seealso{echo, PS1, PS2}
 @end deftypefn */)
 {
-  tree_evaluator& tw = interp.get_evaluator ();
-
-  return tw.PS4 (args, nargout);
+  return interp.PS4 (args, nargout);
 }
 
 DEFMETHOD (echo, interp, args, nargout,
--- a/libinterp/parse-tree/pt-eval.h	Wed Jan 11 16:15:38 2023 -0500
+++ b/libinterp/parse-tree/pt-eval.h	Wed Jan 11 21:45:45 2023 -0500
@@ -712,6 +712,8 @@
     return val;
   }
 
+  void set_PS4 (const std::string& s) { m_PS4 = s; }
+
   octave_value indexed_object (void) const
   {
     return m_indexed_object;