changeset 25443:2fa7cd178c4a

new class for miscellaneous interpreter settings * libgui/src/editor-settings.h: Rename from octave-settings.h. Change all uses. * libgui/src/module.mk: Update. * settings.h, settings.cc: New files for miscellaneous interpreter settings and access functions. * libinterp/corefcn/module.mk: Update. * lex.h, lex.ll: Move static variables Vdisplay_tokens, Vtoken_count, and lexer_debug_flag to new settings class. Change all uses. (base_lexer::debug_flag, base_lexer::display_tokens, base_lexer::increment_token_count, base_lexer::lexer_debug): New functions. (F__display_tokens__, F__token_count__, F__lexer_debug_flag__): Move to settings.cc. * interpreter.h, interpreter.cc (interpreter::m_settings, interpreter::settings): New data member and access function.
author John W. Eaton <jwe@octave.org>
date Fri, 08 Jun 2018 18:04:18 -0400
parents 47a3e4b9b6fe
children 37132909ac91
files libgui/src/editor-settings.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/octave-qscintilla.cc libgui/src/module.mk libgui/src/octave-settings.h libgui/src/settings-dialog.h libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h libinterp/corefcn/module.mk libinterp/corefcn/settings.cc libinterp/corefcn/settings.h libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll
diffstat 13 files changed, 285 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/editor-settings.h	Fri Jun 08 18:04:18 2018 -0400
@@ -0,0 +1,44 @@
+/*
+
+Copyright (C) 2017-2018 Torsten <mttl@mailbox.de>
+
+This file is part of Octave.
+
+Octave is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<https://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_editor_settings_h)
+#define octave_editor_settings_h 1
+
+//#if defined (HAVE_CONFIG_H)
+//#  include "config.h"
+//#endif
+
+#include <QStringList>
+
+// Octave comment strings
+const QString oct_comment_str_old ("editor/octave_comment_string");
+const int oct_comment_str_old_d = 0;
+
+const QString oct_comment_str ("editor/oct_comment_str");
+const QString oct_uncomment_str ("editor/oct_uncomment_str");
+const QString oct_last_comment_str ("editor/oct_last_comment_str");
+const QStringList oct_comment_strings (QStringList () << "##" << "#" << "%"<< "%%" << "%!");
+const int oct_comment_strings_count = 5;
+const int oct_comment_str_d = 0;
+const int oct_uncomment_str_d = 1 + 2 + 4 + 8;
+
+#endif
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Jun 08 18:34:26 2018 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Fri Jun 08 18:04:18 2018 -0400
@@ -60,7 +60,9 @@
 #include <QDialogButtonBox>
 #include <QPushButton>
 
+#include "editor-settings.h"
 #include "resource-manager.h"
+
 #include "file-editor-tab.h"
 #include "file-editor.h"
 #include "octave-txt-lexer.h"
@@ -79,7 +81,6 @@
 #include "unwind-prot.h"
 #include "utils.h"
 #include "version.h"
-#include "octave-settings.h"
 
 namespace octave
 {
--- a/libgui/src/m-editor/octave-qscintilla.cc	Fri Jun 08 18:34:26 2018 -0400
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Fri Jun 08 18:04:18 2018 -0400
@@ -50,14 +50,14 @@
 #include <QToolTip>
 #include <QVBoxLayout>
 
-// FIXME: hardwired marker numbers?
-#include "marker.h"
+#include "editor-settings.h"
+#include "resource-manager.h"
+#include "shortcut-manager.h"
 
 #include "octave-qscintilla.h"
 #include "file-editor-tab.h"
-#include "shortcut-manager.h"
-#include "resource-manager.h"
-#include "octave-settings.h"
+// FIXME: hardwired marker numbers?
+#include "marker.h"
 
 // Return true if CANDIDATE is a "closing" that matches OPENING,
 // such as "end" or "endif" for "if", or "catch" for "try".
--- a/libgui/src/module.mk	Fri Jun 08 18:34:26 2018 -0400
+++ b/libgui/src/module.mk	Fri Jun 08 18:04:18 2018 -0400
@@ -157,6 +157,7 @@
   %reldir%/documentation-dock-widget.h \
   %reldir%/documentation.h \
   %reldir%/dw-main-window.h \
+  %reldir%/editor-settings.h \
   %reldir%/external-editor-interface.h \
   %reldir%/files-dock-widget.h \
   %reldir%/history-dock-widget.h \
@@ -171,7 +172,6 @@
   %reldir%/octave-gui.h \
   %reldir%/octave-cmd.h \
   %reldir%/octave-qt-link.h \
-  %reldir%/octave-settings.h \
   %reldir%/qtinfo/texinfo-parser.h \
   %reldir%/qtinfo/webinfo.h \
   %reldir%/resource-manager.h \
--- a/libgui/src/octave-settings.h	Fri Jun 08 18:34:26 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
-
-Copyright (C) 2017-2018 Torsten <mttl@mailbox.de>
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_settings_h)
-#define octave_settings_h 1
-
-//#if defined (HAVE_CONFIG_H)
-//#  include "config.h"
-//#endif
-
-#include <QStringList>
-
-// Octave comment strings
-const QString oct_comment_str_old ("editor/octave_comment_string");
-const int oct_comment_str_old_d = 0;
-
-const QString oct_comment_str ("editor/oct_comment_str");
-const QString oct_uncomment_str ("editor/oct_uncomment_str");
-const QString oct_last_comment_str ("editor/oct_last_comment_str");
-const QStringList oct_comment_strings (QStringList () << "##" << "#" << "%"<< "%%" << "%!");
-const int oct_comment_strings_count = 5;
-const int oct_comment_str_d = 0;
-const int oct_uncomment_str_d = 1 + 2 + 4 + 8;
-
-#endif
--- a/libgui/src/settings-dialog.h	Fri Jun 08 18:34:26 2018 -0400
+++ b/libgui/src/settings-dialog.h	Fri Jun 08 18:04:18 2018 -0400
@@ -29,7 +29,7 @@
 #include <QRadioButton>
 
 #include "color-picker.h"
-#include "octave-settings.h"
+#include "editor-settings.h"
 
 namespace Ui
 {
--- a/libinterp/corefcn/interpreter.cc	Fri Jun 08 18:34:26 2018 -0400
+++ b/libinterp/corefcn/interpreter.cc	Fri Jun 08 18:04:18 2018 -0400
@@ -65,6 +65,7 @@
 #include "pt-eval.h"
 #include "pt-jump.h"
 #include "pt-stmt.h"
+#include "settings.h"
 #include "sighandlers.h"
 #include "sysdep.h"
 #include "unwind-prot.h"
@@ -317,6 +318,7 @@
     : m_app_context (app_context),
       m_installation_data (),
       m_environment (*this),
+      m_settings (),
       m_help_system (*this),
       m_input_system (*this),
       m_output_system (*this),
--- a/libinterp/corefcn/interpreter.h	Fri Jun 08 18:34:26 2018 -0400
+++ b/libinterp/corefcn/interpreter.h	Fri Jun 08 18:04:18 2018 -0400
@@ -43,6 +43,7 @@
 #include "ov-typeinfo.h"
 #include "pager.h"
 #include "pt-eval.h"
+#include "settings.h"
 #include "symtab.h"
 #include "url-handle-manager.h"
 
@@ -159,6 +160,11 @@
       return m_environment;
     }
 
+    settings& get_settings (void)
+    {
+      return m_settings;
+    }
+
     help_system& get_help_system (void)
     {
       return m_help_system;
@@ -268,6 +274,8 @@
 
     environment m_environment;
 
+    settings m_settings;
+
     help_system m_help_system;
 
     input_system m_input_system;
--- a/libinterp/corefcn/module.mk	Fri Jun 08 18:34:26 2018 -0400
+++ b/libinterp/corefcn/module.mk	Fri Jun 08 18:04:18 2018 -0400
@@ -78,6 +78,7 @@
   %reldir%/pr-flt-fmt.h \
   %reldir%/pr-output.h \
   %reldir%/procstream.h \
+  %reldir%/settings.h \
   %reldir%/sighandlers.h \
   %reldir%/sparse-xdiv.h \
   %reldir%/sparse-xpow.h \
@@ -222,6 +223,7 @@
   %reldir%/rcond.cc \
   %reldir%/regexp.cc \
   %reldir%/schur.cc \
+  %reldir%/settings.cc \
   %reldir%/sighandlers.cc \
   %reldir%/sparse-xdiv.cc \
   %reldir%/sparse-xpow.cc \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/settings.cc	Fri Jun 08 18:04:18 2018 -0400
@@ -0,0 +1,93 @@
+/*
+
+Copyright (C) 2018 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<https://www.gnu.org/licenses/>.
+
+*/
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include "defun.h"
+#include "interpreter.h"
+#include "ov.h"
+#include "ovl.h"
+#include "settings.h"
+#include "variables.h"
+
+namespace octave
+{
+  settings::settings (void)
+    : m_display_tokens (false), m_token_count (0),
+      m_lexer_debug_flag (false)
+  { }
+
+  octave_value settings::display_tokens (const octave_value_list& args,
+                                         int nargout)
+  {
+    return set_internal_variable (m_display_tokens, args, nargout,
+                                  "__display_tokens__");
+  }
+
+  octave_value settings::lexer_debug_flag (const octave_value_list& args,
+                                           int nargout)
+  {
+    return set_internal_variable (m_lexer_debug_flag, args, nargout,
+                                  "__lexer_debug_flag__");
+  }
+}
+
+DEFMETHOD (__display_tokens__, interp, args, nargout,
+           doc: /* -*- texinfo -*-
+@deftypefn {} {} __display_tokens__ ()
+Query or set the internal variable that determines whether Octave's
+lexer displays tokens as they are read.
+@seealso{__lexer_debug_flag__, __token_count__}
+@end deftypefn */)
+{
+  octave::settings& stgs = interp.get_settings ();
+
+  return stgs.display_tokens (args, nargout);
+}
+
+DEFMETHOD (__token_count__, interp, , ,
+           doc: /* -*- texinfo -*-
+@deftypefn {} {} __token_count__ ()
+Return the number of language tokens processed since Octave startup.
+@seealso{__lexer_debug_flag__, __display_tokens__}
+@end deftypefn */)
+{
+  octave::settings& stgs = interp.get_settings ();
+
+  return octave_value (stgs.token_count ());
+}
+
+DEFMETHOD (__lexer_debug_flag__, interp, args, nargout,
+           doc: /* -*- texinfo -*-
+@deftypefn  {} {@var{val} =} __lexer_debug_flag__ ()
+@deftypefnx {} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val})
+Query or set the internal flag that determines whether Octave's lexer prints
+debug information as it processes an expression.
+@seealso{__display_tokens__, __token_count__, __parse_debug_flag__}
+@end deftypefn */)
+{
+  octave::settings& stgs = interp.get_settings ();
+
+  return stgs.lexer_debug_flag (args, nargout);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/settings.h	Fri Jun 08 18:04:18 2018 -0400
@@ -0,0 +1,90 @@
+/*
+
+Copyright (C) 2018 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<https://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_settings_h)
+#define octave_settings_h 1
+
+#include "octave-config.h"
+
+class octave_value_list;
+
+namespace octave
+{
+  // Most settings for the interpreter are stored in the classes which
+  // they affect (intput_system, output_system, load_path, etc.  Some
+  // don't really fit anywhere else.  For example, there is no single
+  // lexer or parser object, so we store settings for those things
+  // here.
+
+  class settings
+  {
+  public:
+
+    settings (void);
+
+    settings (const settings&) = delete;
+
+    settings& operator = (const settings&) = delete;
+
+    ~settings (void) = default;
+
+    octave_value display_tokens (const octave_value_list& args, int nargout);
+
+    bool display_tokens (void) const { return m_display_tokens; }
+
+    bool display_tokens (bool flag)
+    {
+      bool val = m_display_tokens;
+      m_display_tokens = flag;
+      return val;
+    }
+
+    // Read only.
+    size_t token_count (void) const { return m_token_count; }
+
+    void increment_token_count (void) { ++m_token_count; }
+
+    octave_value lexer_debug_flag (const octave_value_list& args, int nargout);
+
+    bool lexer_debug_flag (void) const { return m_lexer_debug_flag; }
+
+    bool lexer_debug_flag (bool flag)
+    {
+      bool val = m_lexer_debug_flag;
+      m_lexer_debug_flag = flag;
+      return val;
+    }
+
+  private:
+
+    // Display tokens as they are processed, for debugging.
+    bool m_display_tokens = false;
+
+    // Number of tokens processed since interpreter startup.
+    size_t m_token_count = 0;
+
+    // Internal variable for lexer debugging state.
+    bool m_lexer_debug_flag = false;
+  };
+}
+
+#endif
--- a/libinterp/parse-tree/lex.h	Fri Jun 08 18:34:26 2018 -0400
+++ b/libinterp/parse-tree/lex.h	Fri Jun 08 18:04:18 2018 -0400
@@ -675,6 +675,12 @@
 
     void fatal_error (const char *msg);
 
+    bool debug_flag (void) const;
+
+    bool display_tokens (void) const;
+
+    void increment_token_count (void);
+
     void lexer_debug (const char *pattern);
 
     // Internal state of the flex-generated lexer.
--- a/libinterp/parse-tree/lex.ll	Fri Jun 08 18:34:26 2018 -0400
+++ b/libinterp/parse-tree/lex.ll	Fri Jun 08 18:04:18 2018 -0400
@@ -323,13 +323,6 @@
      }                                                                  \
    while (0)
 
-static bool Vdisplay_tokens = false;
-
-static unsigned int Vtoken_count = 0;
-
-// Internal variable for lexer debugging state.
-static bool lexer_debug_flag = false;
-
 %}
 
 D       [0-9]
@@ -2036,44 +2029,6 @@
 
 */
 
-DEFUN (__display_tokens__, args, nargout,
-       doc: /* -*- texinfo -*-
-@deftypefn {} {} __display_tokens__ ()
-Query or set the internal variable that determines whether Octave's
-lexer displays tokens as they are read.
-@seealso{__lexer_debug_flag__, __token_count__}
-@end deftypefn */)
-{
-  return SET_INTERNAL_VARIABLE (display_tokens);
-}
-
-DEFUN (__token_count__, , ,
-       doc: /* -*- texinfo -*-
-@deftypefn {} {} __token_count__ ()
-Return the number of language tokens processed since Octave startup.
-@seealso{__lexer_debug_flag__, __display_tokens__}
-@end deftypefn */)
-{
-  return octave_value (Vtoken_count);
-}
-
-DEFUN (__lexer_debug_flag__, args, nargout,
-       doc: /* -*- texinfo -*-
-@deftypefn  {} {@var{val} =} __lexer_debug_flag__ ()
-@deftypefnx {} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val})
-Query or set the internal flag that determines whether Octave's lexer prints
-debug information as it processes an expression.
-@seealso{__display_tokens__, __token_count__, __parse_debug_flag__}
-@end deftypefn */)
-{
-  octave_value retval;
-
-  retval = set_internal_variable (lexer_debug_flag, args, nargout,
-                                  "__lexer_debug_flag__");
-
-  return retval;
-}
-
 namespace octave
 {
   void
@@ -2438,7 +2393,7 @@
   {
     int c = yyinput (m_scanner);
 
-    if (lexer_debug_flag)
+    if (debug_flag ())
       {
         std::cerr << "I: ";
         display_character (c);
@@ -2451,7 +2406,7 @@
       {
         c = yyinput (m_scanner);
 
-        if (lexer_debug_flag)
+        if (debug_flag ())
           {
             std::cerr << "I: ";
             display_character (c);
@@ -2473,7 +2428,7 @@
   {
     if (c != EOF)
       {
-        if (lexer_debug_flag)
+        if (debug_flag ())
           {
             std::cerr << "U: ";
             display_character (c);
@@ -3407,10 +3362,33 @@
     error ("fatal lexer error: %s", msg);
   }
 
+  bool
+  base_lexer::debug_flag (void) const
+  {
+    settings& stgs = m_interpreter.get_settings ();
+    return stgs.lexer_debug_flag ();
+  }
+
+  bool
+  base_lexer::display_tokens (void) const
+  {
+    settings& stgs = m_interpreter.get_settings ();
+    return stgs.display_tokens ();
+  }
+
+  void
+  base_lexer::increment_token_count (void)
+  {
+    settings& stgs = m_interpreter.get_settings ();
+    stgs.increment_token_count ();
+
+    m_token_count++;
+  }
+
   void
   base_lexer::lexer_debug (const char *pattern)
   {
-    if (lexer_debug_flag)
+    if (debug_flag ())
       {
         std::cerr << std::endl;
 
@@ -3600,10 +3578,7 @@
   base_lexer::count_token_internal (int tok)
   {
     if (tok != '\n')
-      {
-        Vtoken_count++;
-        m_token_count++;
-      }
+      increment_token_count ();
 
     return show_token (tok);
   }
@@ -3611,10 +3586,11 @@
   int
   base_lexer::show_token (int tok)
   {
-    if (Vdisplay_tokens)
+
+    if (display_tokens ())
       display_token (tok);
 
-    if (lexer_debug_flag)
+    if (debug_flag ())
       {
         std::cerr << "R: ";
         display_token (tok);