Mercurial > hg > octave-nkf
changeset 16133:249d62b3fac8
new class for parser state
* oct-parse.yy, parse.h (octave_parser): New class
(curr_parser): New global variable.
* oct-parse.yy (eval_string, parse_fcn_file): Save curr_parser on
unwind_protect stack. Create new curr_parser and arrange for it to be
cleaned up.
* toplev.cc (main_loop): Likewise.
* input.cc (get_debug_input): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 20:10:00 -0500 |
parents | 43e6415393ff |
children | ec9c6222ef5a |
files | libinterp/interpfcn/input.cc libinterp/interpfcn/toplev.cc libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h |
diffstat | 4 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interpfcn/input.cc +++ b/libinterp/interpfcn/input.cc @@ -682,6 +682,10 @@ curr_lexer = new lexical_feedback (); frame.add_fcn (lexical_feedback::cleanup, curr_lexer); + frame.protect_var (curr_parser); + curr_parser = new octave_parser (); + frame.add_fcn (octave_parser::cleanup, curr_parser); + while (Vdebugging) { unwind_protect middle_frame;
--- a/libinterp/interpfcn/toplev.cc +++ b/libinterp/interpfcn/toplev.cc @@ -563,6 +563,10 @@ curr_lexer = new lexical_feedback (); frame.add_fcn (lexical_feedback::cleanup, curr_lexer); + frame.protect_var (curr_parser); + curr_parser = new octave_parser (); + frame.add_fcn (octave_parser::cleanup, curr_parser); + // The big loop. int retval = 0;
--- a/libinterp/parse-tree/oct-parse.yy +++ b/libinterp/parse-tree/oct-parse.yy @@ -86,6 +86,9 @@ #define malloc GNULIB_NAMESPACE::malloc #endif +// The state of the parser. +octave_parser *curr_parser = 0; + // Buffer for help text snagged from function files. std::stack<std::string> help_buf; @@ -3503,6 +3506,10 @@ curr_lexer = new lexical_feedback (); frame.add_fcn (lexical_feedback::cleanup, curr_lexer); + frame.protect_var (curr_parser); + curr_parser = new octave_parser (); + frame.add_fcn (octave_parser::cleanup, curr_parser); + curr_lexer->reset_parser (); std::string help_txt = gobble_leading_white_space (ffile, eof); @@ -4309,6 +4316,10 @@ curr_lexer = new lexical_feedback (); frame.add_fcn (lexical_feedback::cleanup, curr_lexer); + frame.protect_var (curr_parser); + curr_parser = new octave_parser (); + frame.add_fcn (octave_parser::cleanup, curr_parser); + frame.protect_var (get_input_from_eval_string); frame.protect_var (line_editing); frame.protect_var (current_eval_string);
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -107,4 +107,28 @@ extern OCTINTERP_API int octave_parse_input (void); +class +octave_parser +{ +public: + + octave_parser (void) { } + + ~octave_parser (void) { } + + // For unwind protect. + static void cleanup (octave_parser *parser) { delete parser; } + +private: + + // No copying! + + octave_parser (const octave_parser&); + + octave_parser& operator = (const octave_parser&); +}; + +// The current state of the parser. +extern octave_parser *curr_parser; + #endif