Mercurial > octave
changeset 23609:99989ab8f142
new convenience functions for accessing current scope
* interpreter.h, interpreter.cc (interpreter::get_current_scope,
interpreter::require_current_scope): New functions.
* interpreter-private.h, interpreter-private.cc
(__get_current_scope__): Use interpreter::get_current_scope.
(__require_current_scope__): New fucntion.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 15 Jun 2017 08:00:37 -0400 |
parents | 520c53706014 |
children | 2fe11412e785 |
files | libinterp/corefcn/interpreter-private.cc libinterp/corefcn/interpreter-private.h libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h |
diffstat | 4 files changed, 35 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter-private.cc Thu Jun 15 16:13:49 2017 -0700 +++ b/libinterp/corefcn/interpreter-private.cc Thu Jun 15 08:00:37 2017 -0400 @@ -64,9 +64,19 @@ symbol_table::scope *__get_current_scope__ (const std::string& who) { - symbol_table& symtab = __get_symbol_table__ (who); + interpreter& interp = __get_interpreter__ (who); + + return interp.get_current_scope (); + } - return symtab.current_scope (); + symbol_table::scope *__require_current_scope__ (const std::string& who) + { + symbol_table::scope *scope = __get_current_scope__ (who); + + if (! scope) + error ("%s: symbol table scope missing", who.c_str ()); + + return scope; } tree_evaluator& __get_evaluator__ (const std::string& who)
--- a/libinterp/corefcn/interpreter-private.h Thu Jun 15 16:13:49 2017 -0700 +++ b/libinterp/corefcn/interpreter-private.h Thu Jun 15 08:00:37 2017 -0400 @@ -44,6 +44,9 @@ extern symbol_table::scope *__get_current_scope__ (const std::string& who); + extern symbol_table::scope * + __require_current_scope__ (const std::string& who); + extern tree_evaluator& __get_evaluator__ (const std::string& who); extern call_stack& __get_call_stack__ (const std::string& who);
--- a/libinterp/corefcn/interpreter.cc Thu Jun 15 16:13:49 2017 -0700 +++ b/libinterp/corefcn/interpreter.cc Thu Jun 15 08:00:37 2017 -0400 @@ -1153,6 +1153,23 @@ return *m_evaluator; } + symbol_table::scope * + interpreter::get_current_scope (void) + { + return m_symbol_table.current_scope (); + } + + symbol_table::scope * + interpreter::require_current_scope (const std::string& who) + { + symbol_table::scope *scope = get_current_scope (); + + if (! scope) + error ("%s: symbol table scope missing", who.c_str ()); + + return scope; + } + call_stack& interpreter::get_call_stack (void) { return m_evaluator->get_call_stack ();
--- a/libinterp/corefcn/interpreter.h Thu Jun 15 16:13:49 2017 -0700 +++ b/libinterp/corefcn/interpreter.h Thu Jun 15 08:00:37 2017 -0400 @@ -144,6 +144,9 @@ return m_symbol_table; } + symbol_table::scope * get_current_scope (void); + symbol_table::scope * require_current_scope (const std::string& who); + call_stack& get_call_stack (void); tree_evaluator& get_evaluator (void);