# HG changeset patch # User John W. Eaton # Date 1525377893 14400 # Node ID af3319d86a5f7fcceee40cd8a4dd1877076f07d2 # Parent dd416c31761efd9076984b3fb5730a6988dfff6a eliminate some global references to interpreter internals * bp-table.h, bp-table.cc (bp_table::m_interpreter): New data member. (get_user_code): Deprecate. * interpreter.h, interpreter.cc (interpreter::get_user_code): New function. Change all uses of global get_uesr_code to use interpreter::get_user_code instead. diff -r dd416c31761e -r af3319d86a5f libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Thu May 03 02:26:29 2018 -0400 +++ b/libinterp/corefcn/debug.cc Thu May 03 16:04:53 2018 -0400 @@ -390,7 +390,7 @@ /* if (Vdebugging) { - octave_user_code *dbg_fcn = get_user_code (); + octave_user_code *dbg_fcn = interp.get_user_code (); if (dbg_fcn) { symbol_name = dbg_fcn->name (); @@ -538,7 +538,7 @@ @seealso{dbstack, dblist, dbstatus, dbcont, dbstep, dbup, dbdown} @end deftypefn */) { - octave_user_code *dbg_fcn = octave::get_user_code (); + octave_user_code *dbg_fcn = interp.get_user_code (); if (! dbg_fcn) { @@ -607,8 +607,8 @@ os.flush (); } -DEFUN (dbtype, args, , - doc: /* -*- texinfo -*- +DEFMETHOD (dbtype, interp, args, , + doc: /* -*- texinfo -*- @deftypefn {} {} dbtype @deftypefnx {} {} dbtype @var{lineno} @deftypefnx {} {} dbtype @var{startl:endl} @@ -638,7 +638,7 @@ switch (args.length ()) { case 0: // dbtype - dbg_fcn = octave::get_user_code (); + dbg_fcn = interp.get_user_code (); if (! dbg_fcn) error ("dbtype: must be inside a user function to give no arguments to dbtype\n"); @@ -656,7 +656,7 @@ if (ind != std::string::npos) // (dbtype start:end) { - dbg_fcn = octave::get_user_code (); + dbg_fcn = interp.get_user_code (); if (dbg_fcn) { @@ -686,7 +686,7 @@ if (line == 0) // (dbtype func) { - dbg_fcn = octave::get_user_code (arg); + dbg_fcn = interp.get_user_code (arg); if (! dbg_fcn) error ("dbtype: function <%s> not found\n", arg.c_str ()); @@ -699,7 +699,7 @@ if (line <= 0) error ("dbtype: start and end lines must be >= 1\n"); - dbg_fcn = octave::get_user_code (); + dbg_fcn = interp.get_user_code (); if (dbg_fcn) do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (), @@ -711,7 +711,7 @@ case 2: // (dbtype func start:end) || (dbtype func start) { - dbg_fcn = octave::get_user_code (argv[1]); + dbg_fcn = interp.get_user_code (argv[1]); if (! dbg_fcn) error ("dbtype: function <%s> not found\n", argv[1].c_str ()); @@ -784,7 +784,7 @@ error ("dblist: N must be a non-negative integer"); } - octave_user_code *dbg_fcn = octave::get_user_code (); + octave_user_code *dbg_fcn = interp.get_user_code (); if (! dbg_fcn) error ("dblist: must be inside a user function to use dblist\n"); diff -r dd416c31761e -r af3319d86a5f libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc Thu May 03 02:26:29 2018 -0400 +++ b/libinterp/corefcn/interpreter.cc Thu May 03 16:04:53 2018 -0400 @@ -332,7 +332,7 @@ m_type_info (), m_symbol_table (), m_evaluator (*this), - m_bp_table (), + m_bp_table (*this), m_stream_list (*this), m_child_list (), m_url_handle_manager (), @@ -1182,6 +1182,46 @@ return m_evaluator.get_profiler (); } + // Return a pointer to the user-defined function FNAME. If FNAME is empty, + // search backward for the first user-defined function in the + // current call stack. + + octave_user_code * + interpreter::get_user_code (const std::string& fname) + { + octave_user_code *user_code = nullptr; + + if (fname.empty ()) + { + call_stack& cs = get_call_stack (); + + user_code = cs.debug_user_code (); + } + else + { + std::string name = fname; + + if (sys::file_ops::dir_sep_char () != '/' && name[0] == '@') + { + auto beg = name.begin () + 2; // never have @/method + auto end = name.end () - 1; // never have trailing '/' + std::replace (beg, end, '/', sys::file_ops::dir_sep_char ()); + } + + size_t name_len = name.length (); + + if (name_len > 2 && name.substr (name_len-2) == ".m") + name = name.substr (0, name_len-2); + + octave_value fcn = m_symbol_table.find_function (name); + + if (fcn.is_defined () && fcn.is_user_code ()) + user_code = fcn.user_code_value (); + } + + return user_code; + } + void interpreter::mlock (void) { call_stack& cs = get_call_stack (); diff -r dd416c31761e -r af3319d86a5f libinterp/corefcn/interpreter.h --- a/libinterp/corefcn/interpreter.h Thu May 03 02:26:29 2018 -0400 +++ b/libinterp/corefcn/interpreter.h Thu May 03 16:04:53 2018 -0400 @@ -53,6 +53,8 @@ // TRUE means we've processed all the init code and we are good to go. extern OCTINTERP_API bool octave_initialized; +class octave_user_code; + namespace octave { class profiler; @@ -209,6 +211,8 @@ return m_gtk_manager; } + octave_user_code * get_user_code (const std::string& fname = ""); + void mlock (void); void munlock (const std::string& nm); diff -r dd416c31761e -r af3319d86a5f libinterp/parse-tree/bp-table.cc --- a/libinterp/parse-tree/bp-table.cc Thu May 03 02:26:29 2018 -0400 +++ b/libinterp/parse-tree/bp-table.cc Thu May 03 16:04:53 2018 -0400 @@ -41,6 +41,7 @@ #include "defun-int.h" #include "call-stack.h" #include "error.h" +#include "interpreter.h" #include "interpreter-private.h" #include "oct-map.h" #include "octave-link.h" @@ -340,7 +341,8 @@ { // It was a line number. Get function name from debugger. if (Vdebugging) - symbol_name = get_user_code ()->profiler_name (); + symbol_name + = m_interpreter.get_user_code ()->profiler_name (); else error ("%s: function name must come before line number " "and 'if'", who); @@ -559,7 +561,7 @@ const bp_table::intmap& line, const std::string& condition) { - octave_user_code *main_fcn = get_user_code (fname); + octave_user_code *main_fcn = m_interpreter.get_user_code (fname); if (! main_fcn) error ("add_breakpoint: unable to find function '%s'\n", fname.c_str ()); @@ -657,7 +659,7 @@ } else { - octave_user_code *dbg_fcn = get_user_code (fname); + octave_user_code *dbg_fcn = m_interpreter.get_user_code (fname); if (! dbg_fcn) error ("remove_breakpoint: unable to find function %s\n", @@ -699,7 +701,7 @@ { intmap retval; - octave_user_code *dbg_fcn = get_user_code (fname); + octave_user_code *dbg_fcn = m_interpreter.get_user_code (fname); if (dbg_fcn) { @@ -769,7 +771,7 @@ if (fname_list.empty () || find_bkpt_list (fname_list, bp_fname) != "") { - octave_user_code *dbg_fcn = get_user_code (bp_fname); + octave_user_code *dbg_fcn = m_interpreter.get_user_code (bp_fname); if (dbg_fcn) { @@ -929,45 +931,11 @@ return retval; } - // Return a pointer to the user-defined function FNAME. If FNAME is empty, - // search backward for the first user-defined function in the - // current call stack. - octave_user_code * get_user_code (const std::string& fname) { - octave_user_code *dbg_fcn = nullptr; - - if (fname.empty ()) - { - call_stack& cs = __get_call_stack__ ("get_user_code"); - - dbg_fcn = cs.debug_user_code (); - } - else - { - std::string name = fname; + interpreter& interp = __get_interpreter__ ("get_user_code"); - if (sys::file_ops::dir_sep_char () != '/' && name[0] == '@') - { - auto beg = name.begin () + 2; // never have @/method - auto end = name.end () - 1; // never have trailing '/' - std::replace (beg, end, '/', sys::file_ops::dir_sep_char ()); - } - - size_t name_len = name.length (); - - if (name_len > 2 && name.substr (name_len-2) == ".m") - name = name.substr (0, name_len-2); - - symbol_table& symtab = __get_symbol_table__ ("get_user_code"); - - octave_value fcn = symtab.find_function (name); - - if (fcn.is_defined () && fcn.is_user_code ()) - dbg_fcn = fcn.user_code_value (); - } - - return dbg_fcn; + return interp.get_user_code (fname); } } diff -r dd416c31761e -r af3319d86a5f libinterp/parse-tree/bp-table.h --- a/libinterp/parse-tree/bp-table.h Thu May 03 02:26:29 2018 -0400 +++ b/libinterp/parse-tree/bp-table.h Thu May 03 16:04:53 2018 -0400 @@ -36,6 +36,8 @@ namespace octave { + class interpreter; + struct bp_type { int line; @@ -49,9 +51,9 @@ { public: - bp_table (void) - : m_bp_set (), m_errors_that_stop (), m_caught_that_stop (), - m_warnings_that_stop () + bp_table (interpreter& interp) + : m_interpreter (interp), m_bp_set (), m_errors_that_stop (), + m_caught_that_stop (), m_warnings_that_stop () { } ~bp_table (void) = default; @@ -128,6 +130,8 @@ typedef std::set::const_iterator const_bp_set_iterator; typedef std::set::iterator bp_set_iterator; + interpreter& m_interpreter; + // Set of function (.m file) names containing at least one breakpoint. std::set m_bp_set; @@ -149,6 +153,7 @@ const std::string& fname); }; + OCTAVE_DEPRECATED (5, "use 'octave::get_user_code' instead") extern octave_user_code * get_user_code (const std::string& fname = ""); }