Mercurial > hg > octave-lojdl
changeset 4748:7b145222fea3
[project @ 2004-02-07 06:27:27 by jwe]
author | jwe |
---|---|
date | Sat, 07 Feb 2004 06:27:28 +0000 |
parents | 3f28979bbe2c |
children | a4bc7156bd60 |
files | src/ChangeLog src/debug.cc src/error.cc src/ov-builtin.cc src/ov-fcn.h src/ov-mapper.cc src/ov-usr-fcn.cc src/ov-usr-fcn.h src/pt-bp.h src/pt-pr-code.cc src/pt.cc src/pt.h src/toplev.cc src/toplev.h src/variables.cc |
diffstat | 15 files changed, 113 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,41 @@ +2004-02-06 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov-usr-fcn.h (octave_user_function::function_name): Delete. + (octave_user_function::fcn_name): Delete unused data member. + (octave_user_function::stash_function_name): Save name in + tree_function::my_name instead of fcn_name. + Change all uses of fcn_name to be my_name instead. + + * pt.h, pt.cc (tree::break_function): Now pointer to + octave_function rather than octave_user_function object. + + * pt-bp.h (MAYBE_DO_BREAKPOINT): Use name instead of function_name + to get name from curr_function. + * pt-pr-code.cc (tree_print_code::visit_octave_user_function_header): + likewise. + * debug.cc (Fdbwhere, Fdbtype, ): Likewise + * error.cc (pr_where): Likewise. + * variables.cc (Fmlock, Fmunlock, Fmislocked): Likewise. + (lookup_function, lookup_user_function, link_to_builtin_or_function): + Likewise, for curr_parent_function. + + * debug.cc (get_user_function, Fdbwhere): + Cast curr_function to pointer to octave_user_function. + + * ov-mapper.cc (octave_mapper::do_multi_index_op): + Save and restore curr_function here. + * ov-builtin.cc (octave_builtin::do_multi_index_op): Likewise. + + * toplev.h, toplev.cc (curr_function, curr_parent_function): Now + pointers to octave_function rather than octave_user_function objects. + + * ov-usr-fcn.h (octave_user_function::is_user_function): New function. + * ov-fcn.h (octave_function::takes_varargs, + octave_function::octave_va_start, octave_function::octave_va_arg, + octave_function::octave_all_va_args, + octave_function::takes_var_return, octave_function::octave_vr_val, + octave_function::is_user_function): New virtual functions. + 2004-02-05 John W. Eaton <jwe@bevo.che.wisc.edu> * ov-struct.cc (Fstruct): Use new Octave_map constructor to create
--- a/src/debug.cc +++ b/src/debug.cc @@ -73,8 +73,8 @@ } } } - else if (curr_function) - dbg_fcn = curr_function; + else if (curr_function && curr_function->is_user_function ()) + dbg_fcn = dynamic_cast<octave_user_function *> (curr_function); return dbg_fcn; } @@ -282,11 +282,14 @@ { octave_value retval; - octave_user_function *dbg_fcn = curr_function; + octave_user_function *dbg_fcn = 0; + + if (curr_function && curr_function->is_user_function ()) + dbg_fcn = dynamic_cast<octave_user_function *> (curr_function); if (dbg_fcn) { - std::string name = dbg_fcn->function_name (); + std::string name = dbg_fcn->name (); octave_stdout << name << ":"; @@ -369,7 +372,7 @@ dbg_fcn = get_user_function (); if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->function_name (), 0, INT_MAX); + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); else error ("dbtype: must be in a user function to give no arguments to dbtype\n"); break; @@ -378,7 +381,7 @@ dbg_fcn = get_user_function (argv[1]); if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->function_name (), 0, INT_MAX); + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); else { dbg_fcn = get_user_function (""); @@ -399,7 +402,7 @@ if (start < end) do_dbtype (octave_stdout, - dbg_fcn->function_name (), start, end); + dbg_fcn->name (), start, end); else error ("dbtype: the start line must be less than the end line\n"); } @@ -428,7 +431,7 @@ if (start < end) do_dbtype (octave_stdout, - dbg_fcn->function_name (), start, end); + dbg_fcn->name (), start, end); else error ("dbtype: the start line must be less than the end line\n"); }
--- a/src/error.cc +++ b/src/error.cc @@ -322,7 +322,7 @@ if (curr_function) { - std::string fcn_name = curr_function->function_name (); + std::string fcn_name = curr_function->name (); std::string file_name = curr_function->fcn_file_name (); f_nm = file_name.empty () ? fcn_name.c_str () : file_name.c_str ();
--- a/src/ov-builtin.cc +++ b/src/ov-builtin.cc @@ -32,6 +32,8 @@ #include "oct-obj.h" #include "ov-builtin.h" #include "ov.h" +#include "toplev.h" +#include "unwind-prot.h" DEFINE_OCTAVE_ALLOCATOR (octave_builtin); @@ -105,7 +107,14 @@ if (any_arg_is_magic_colon (args)) ::error ("invalid use of colon in function argument list"); else - retval = (*f) (args, nargout); + { + unwind_protect_ptr (curr_function); + curr_function = this; + + retval = (*f) (args, nargout); + + unwind_protect::run (); + } return retval; }
--- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -33,6 +33,7 @@ #include "str-vec.h" #include "oct-alloc.h" +#include "oct-obj.h" #include "ov-base.h" #include "ov-typeinfo.h" @@ -72,6 +73,23 @@ virtual bool is_nested_function (void) const { return false; } + virtual bool is_user_function (void) const { return false; } + + virtual bool takes_varargs (void) const { return false; } + + virtual void octave_va_start (void) { } + + virtual octave_value octave_va_arg (void) const { return octave_value (); } + + virtual octave_value_list octave_all_va_args (void) + { return octave_value_list (); } + + virtual bool takes_var_return (void) const { return false; } + + virtual void octave_vr_val (const octave_value& val) { } + + virtual bool has_varargout (void) const { return false; } + std::string name (void) const { return my_name; } std::string doc_string (void) const { return doc; }
--- a/src/ov-mapper.cc +++ b/src/ov-mapper.cc @@ -35,6 +35,8 @@ #include "oct-obj.h" #include "ov-mapper.h" #include "ov.h" +#include "toplev.h" +#include "unwind-prot.h" DEFINE_OCTAVE_ALLOCATOR (octave_mapper); @@ -284,7 +286,14 @@ else { if (args(0).is_defined ()) - retval = apply (args(0)); + { + unwind_protect_ptr (curr_function); + curr_function = this; + + retval = apply (args(0)); + + unwind_protect::run (); + } else ::error ("%s: argument undefined", name().c_str ()); }
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -70,8 +70,7 @@ tree_statement_list *cl, symbol_table *st) : octave_function (std::string (), std::string ()), param_list (pl), ret_list (rl), cmd_list (cl), - sym_tab (st), lead_comm (), trail_comm (), - file_name (), fcn_name (), + sym_tab (st), lead_comm (), trail_comm (), file_name (), t_parsed (static_cast<time_t> (0)), t_checked (static_cast<time_t> (0)), system_fcn_file (false), call_depth (0), @@ -242,12 +241,6 @@ return retval; } -void -octave_user_function::stash_function_name (const std::string& s) -{ - fcn_name = s; -} - // For unwind protect. static void @@ -485,8 +478,7 @@ if (ret_list) { - ret_list->initialize_undefined_elements (function_name (), - nargout, Matrix ()); + ret_list->initialize_undefined_elements (my_name, nargout, Matrix ()); if (has_varargout ()) varargout_to_vr_val (); @@ -507,7 +499,7 @@ if (error_state >= 0) error_state = -1; - if (fcn_name.empty ()) + if (my_name.empty ()) { if (file_name.empty ()) ::error ("called from `?unknown?'"); @@ -517,10 +509,10 @@ else { if (file_name.empty ()) - ::error ("called from `%s'", fcn_name.c_str ()); + ::error ("called from `%s'", my_name.c_str ()); else ::error ("called from `%s' in file `%s'", - fcn_name.c_str (), file_name.c_str ()); + my_name.c_str (), file_name.c_str ()); } } @@ -536,7 +528,7 @@ if (sym_tab) sym_tab->print_info (os); else - warning ("%s: no symbol table info!", fcn_name.c_str ()); + warning ("%s: no symbol table info!", my_name.c_str ()); } void
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -95,6 +95,8 @@ bool is_system_fcn_file (void) const { return system_fcn_file; } + bool is_user_function (void) const { return true; } + bool takes_varargs (void) const; void octave_va_start (void) { curr_va_arg_number = num_named_args; } @@ -111,9 +113,7 @@ bool has_varargout (void) const; - void stash_function_name (const std::string& s); - - std::string function_name (void) const { return fcn_name; } + void stash_function_name (const std::string& s) { my_name = s; } void mark_as_nested_function (void) { nested_function = true; } @@ -192,9 +192,6 @@ // The name of the file we parsed std::string file_name; - // The name of the function. - std::string fcn_name; - // The time the file was parsed. octave_time t_parsed;
--- a/src/pt-bp.h +++ b/src/pt-bp.h @@ -189,7 +189,7 @@ tree::break_next = false; \ \ if (curr_function) \ - octave_stdout << curr_function->function_name () << ": "; \ + octave_stdout << curr_function->name () << ": "; \ \ octave_stdout << "line " << line () << ", " \ << "column " << column () \
--- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -331,7 +331,7 @@ os << " = "; } - std::string fcn_name = fcn.function_name (); + std::string fcn_name = fcn.name (); os << (fcn_name.empty () ? std::string ("(empty)") : fcn_name) << " ";
--- a/src/pt.cc +++ b/src/pt.cc @@ -33,6 +33,7 @@ #include "lo-sstream.h" +#include "ov-fcn.h" #include "pt.h" #include "pt-pr-code.h" @@ -43,7 +44,7 @@ int tree::last_line = 0; // The function where the last breakpoint occurred. -const octave_user_function *tree::break_function = 0; +const octave_function *tree::break_function = 0; // The statement where the last breakpoint occurred. const tree *tree::break_statement = 0;
--- a/src/pt.h +++ b/src/pt.h @@ -31,7 +31,7 @@ #include <iostream> -class octave_user_function; +class octave_function; class tree_walker; // Base class for the parse tree. @@ -75,7 +75,7 @@ static int last_line; // The function where the last breakpoint occurred. - static const octave_user_function *break_function; + static const octave_function *break_function; // The statement where the last breakpoint occurred. static const tree *break_statement;
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -91,10 +91,10 @@ tree_statement_list *global_command = 0; // Pointer to function that is currently being evaluated. -octave_user_function *curr_function = 0; +octave_function *curr_function = 0; // Pointer to parent function that is currently being evaluated. -octave_user_function *curr_parent_function = 0; +octave_function *curr_parent_function = 0; static void recover_from_exception (void)
--- a/src/toplev.h +++ b/src/toplev.h @@ -46,10 +46,10 @@ extern tree_statement_list *global_command; // Pointer to function that is currently being evaluated. -extern octave_user_function *curr_function; +extern octave_function *curr_function; // Pointer to parent function that is currently being evaluated. -extern octave_user_function *curr_parent_function; +extern octave_function *curr_parent_function; // TRUE means we are ready to interpret commands, but not everything // is ready for interactive use.
--- a/src/variables.cc +++ b/src/variables.cc @@ -820,7 +820,7 @@ if (curr_parent_function) { - std::string parent = curr_parent_function->function_name (); + std::string parent = curr_parent_function->name (); sr = fbi_sym_tab->lookup (parent + ":" + nm); } @@ -853,7 +853,7 @@ if (curr_parent_function) { - std::string parent = curr_parent_function->function_name (); + std::string parent = curr_parent_function->name (); sr = fbi_sym_tab->lookup (parent + ":" + nm); } @@ -1027,7 +1027,7 @@ if (curr_parent_function) { - std::string parent = curr_parent_function->function_name (); + std::string parent = curr_parent_function->name (); tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); } @@ -1496,7 +1496,7 @@ else if (args.length () == 0) { if (curr_function) - mlock (curr_function->function_name ()); + mlock (curr_function->name ()); else error ("mlock: invalid use outside a function"); } @@ -1528,7 +1528,7 @@ else if (args.length () == 0) { if (curr_function) - mlock (curr_function->function_name ()); + mlock (curr_function->name ()); else error ("munlock: invalid use outside a function"); } @@ -1561,7 +1561,7 @@ else if (args.length () == 0) { if (curr_function) - retval = mislocked (curr_function->function_name ()); + retval = mislocked (curr_function->name ()); else error ("mislocked: invalid use outside a function"); }