Mercurial > hg > octave-nkf
changeset 17731:f79bf671a493
eliminate global LEXER variable
* input.h, input.cc (octave_base_reader::lexer): New member variable.
(octave_base_reader::octave_base_reader): Initialize lexer.
(octave_base_reader::octave_base_reader (const octave_base_reader&)):
Also copy pflag and lexer.
(octave_base_reader::reading_fcn_file,
octave_base_reader::reading_classdef_file,
octave_base_reader::reading_script_file): New functions.
(octave_base_reader::do_input_echo): Call reading_script file instead
of using global LEXER variable.
(get_user_input): Don't user global LEXER variable. Only check
interactive and forced_interactive to decide whether to temporarily
set forced_interactive to true.
(octave_terminal_reader::octave_terminal_reader,
octave_file_reader::octave_file_reader,
octave_eval_string_reader::octave_eval_string_reader,
octave_input_reader::octave_input_reader):
New optional arg, lexer.
* toplev.cc (main_loop): Don't user global LEXER variable. Eliminate
unused unwind_protect frame.
* lex.h, lex.ll (octave_base_lexer::cleanup): Delete unused function.
(octave_lexer::octave_lexer): Pass this to input_reader initializer.
* parse.h, oct-parse.in.yy (octave_base_parser::init):
Delete unneded function.
(octave_base_parser::octave_base_parser, octave_push_parser::init, octave_push_parser::octave_push_parser):
Don't call octave_base_parser::init.
(eval_string): Don't use global LEXER variable. Eliminate unused
unwind_protect frame.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 22 Oct 2013 18:43:36 -0400 |
parents | 580990c2ce04 |
children | dcc88366f94b |
files | libinterp/corefcn/input.cc libinterp/corefcn/input.h libinterp/corefcn/toplev.cc libinterp/parse-tree/lex.h libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h |
diffstat | 6 files changed, 53 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc +++ b/libinterp/corefcn/input.cc @@ -147,7 +147,7 @@ void octave_base_reader::do_input_echo (const std::string& input_string) const { - int do_echo = (LEXER && LEXER->reading_script_file) ? + int do_echo = reading_script_file () ? (Vecho_executing_commands & ECHO_SCRIPTS) : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive; @@ -295,6 +295,24 @@ return retval; } +bool +octave_base_reader::reading_fcn_file (void) const +{ + return lexer ? lexer->reading_fcn_file : false; +} + +bool +octave_base_reader::reading_classdef_file (void) const +{ + return lexer ? lexer->reading_classdef_file : false; +} + +bool +octave_base_reader::reading_script_file (void) const +{ + return lexer ? lexer->reading_script_file : false; +} + // Fix things up so that input can come from the standard input. This // may need to become much more complicated, which is why it's in a // separate function. @@ -553,19 +571,12 @@ frame.protect_var (VPS1); VPS1 = prompt; - if (! (interactive || forced_interactive) - || (LEXER && (LEXER->reading_fcn_file - || LEXER->reading_classdef_file - || LEXER->reading_script_file - || LEXER->input_from_eval_string ()))) + if (! (interactive || forced_interactive)) { frame.protect_var (forced_interactive); forced_interactive = true; } - // octave_parser constructor sets this for us. - frame.protect_var (LEXER); - octave_parser curr_parser; while (Vdebugging)
--- a/libinterp/corefcn/input.h +++ b/libinterp/corefcn/input.h @@ -34,6 +34,7 @@ #include "pager.h" class octave_value; +class octave_base_lexer; extern OCTINTERP_API FILE *get_input_from_stdin (void); @@ -86,9 +87,13 @@ friend class octave_input_reader; - octave_base_reader (void) : count (1), pflag (0) { } + octave_base_reader (octave_base_lexer *lxr) + : count (1), pflag (0), lexer (lxr) + { } - octave_base_reader (const octave_base_reader&) : count (1) { } + octave_base_reader (const octave_base_reader& x) + : count (1), pflag (x.pflag), lexer (x.lexer) + { } virtual ~octave_base_reader (void) { } @@ -113,12 +118,20 @@ std::string octave_gets (bool& eof); + virtual bool reading_fcn_file (void) const; + + virtual bool reading_classdef_file (void) const; + + virtual bool reading_script_file (void) const; + private: int count; int pflag; + octave_base_lexer *lexer; + void do_input_echo (const std::string&) const; static const std::string in_src; @@ -129,7 +142,9 @@ { public: - octave_terminal_reader (void) : octave_base_reader () { } + octave_terminal_reader (octave_base_lexer *lxr = 0) + : octave_base_reader (lxr) + { } std::string get_input (bool& eof); @@ -145,8 +160,8 @@ { public: - octave_file_reader (FILE *f_arg) - : octave_base_reader (), file (f_arg) { } + octave_file_reader (FILE *f_arg, octave_base_lexer *lxr = 0) + : octave_base_reader (lxr), file (f_arg) { } std::string get_input (bool& eof); @@ -164,8 +179,9 @@ { public: - octave_eval_string_reader (const std::string& str) - : octave_base_reader (), eval_string (str) + octave_eval_string_reader (const std::string& str, + octave_base_lexer *lxr = 0) + : octave_base_reader (lxr), eval_string (str) { } std::string get_input (bool& eof); @@ -183,16 +199,16 @@ octave_input_reader { public: - octave_input_reader (void) - : rep (new octave_terminal_reader ()) + octave_input_reader (octave_base_lexer *lxr = 0) + : rep (new octave_terminal_reader (lxr)) { } - octave_input_reader (FILE *file) - : rep (new octave_file_reader (file)) + octave_input_reader (FILE *file, octave_base_lexer *lxr = 0) + : rep (new octave_file_reader (file, lxr)) { } - octave_input_reader (const std::string& str) - : rep (new octave_eval_string_reader (str)) + octave_input_reader (const std::string& str, octave_base_lexer *lxr = 0) + : rep (new octave_eval_string_reader (str, lxr)) { } octave_input_reader (const octave_input_reader& ir)
--- a/libinterp/corefcn/toplev.cc +++ b/libinterp/corefcn/toplev.cc @@ -539,11 +539,6 @@ // The big loop. - unwind_protect frame; - - // octave_parser constructor sets this for us. - frame.protect_var (LEXER); - octave_lexer *lxr = ((interactive || forced_interactive) ? new octave_lexer () : new octave_lexer (stdin)); @@ -555,8 +550,6 @@ { try { - unwind_protect inner_frame; - reset_error_handler (); parser.reset ();
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -682,9 +682,6 @@ int show_token (int tok); - // For unwind protect. - static void cleanup (octave_base_lexer *lexer) { delete lexer; } - protected: std::stack<int> start_state_stack; @@ -702,15 +699,15 @@ public: octave_lexer (void) - : octave_base_lexer (), input_reader () + : octave_base_lexer (), input_reader (this) { } octave_lexer (FILE *file) - : octave_base_lexer (), input_reader (file) + : octave_base_lexer (), input_reader (file, this) { } octave_lexer (const std::string& eval_string) - : octave_base_lexer (), input_reader (eval_string) + : octave_base_lexer (), input_reader (eval_string, this) { } void reset (void)
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -1644,11 +1644,6 @@ delete &lexer; } -void octave_base_parser::init (void) -{ - LEXER = &lexer; -} - void octave_base_parser::reset (void) { @@ -3424,8 +3419,6 @@ octave_push_parser::init (void) { parser_state = yypstate_new (); - - octave_base_parser::init (); } // Parse input from INPUT. Pass TRUE for EOF if the end of INPUT should @@ -4241,11 +4234,6 @@ { octave_value_list retval; - unwind_protect frame; - - // octave_base_parser constructor sets this for us. - frame.protect_var (LEXER); - octave_parser parser (eval_str); do @@ -4254,9 +4242,6 @@ parse_status = parser.run (); - // Unmark forced variables. - frame.run (1); - if (parse_status == 0) { if (parser.stmt_list)
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -138,14 +138,10 @@ curr_class_name (), function_scopes (), primary_fcn_ptr (0), subfunction_names (), stmt_list (0), lexer (lxr) - { - init (); - } + { } ~octave_base_parser (void); - void init (void); - void reset (void); // Error mesages for mismatched end tokens.