# HG changeset patch # User jwe # Date 1076135248 0 # Node ID 7b145222fea32654281ddc9f043b223ab85f7569 # Parent 3f28979bbe2c17f4a44cd76702c0b3e26c582203 [project @ 2004-02-07 06:27:27 by jwe] diff -r 3f28979bbe2c -r 7b145222fea3 src/ChangeLog --- a/src/ChangeLog Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ChangeLog Sat Feb 07 06:27:28 2004 +0000 @@ -1,3 +1,41 @@ +2004-02-06 John W. Eaton + + * 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 * ov-struct.cc (Fstruct): Use new Octave_map constructor to create diff -r 3f28979bbe2c -r 7b145222fea3 src/debug.cc --- a/src/debug.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/debug.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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 (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 (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"); } diff -r 3f28979bbe2c -r 7b145222fea3 src/error.cc --- a/src/error.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/error.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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 (); diff -r 3f28979bbe2c -r 7b145222fea3 src/ov-builtin.cc --- a/src/ov-builtin.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ov-builtin.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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; } diff -r 3f28979bbe2c -r 7b145222fea3 src/ov-fcn.h --- a/src/ov-fcn.h Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ov-fcn.h Sat Feb 07 06:27:28 2004 +0000 @@ -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; } diff -r 3f28979bbe2c -r 7b145222fea3 src/ov-mapper.cc --- a/src/ov-mapper.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ov-mapper.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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 ()); } diff -r 3f28979bbe2c -r 7b145222fea3 src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ov-usr-fcn.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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 (0)), t_checked (static_cast (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 diff -r 3f28979bbe2c -r 7b145222fea3 src/ov-usr-fcn.h --- a/src/ov-usr-fcn.h Fri Feb 06 23:56:46 2004 +0000 +++ b/src/ov-usr-fcn.h Sat Feb 07 06:27:28 2004 +0000 @@ -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; diff -r 3f28979bbe2c -r 7b145222fea3 src/pt-bp.h --- a/src/pt-bp.h Fri Feb 06 23:56:46 2004 +0000 +++ b/src/pt-bp.h Sat Feb 07 06:27:28 2004 +0000 @@ -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 () \ diff -r 3f28979bbe2c -r 7b145222fea3 src/pt-pr-code.cc --- a/src/pt-pr-code.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/pt-pr-code.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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) << " "; diff -r 3f28979bbe2c -r 7b145222fea3 src/pt.cc --- a/src/pt.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/pt.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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; diff -r 3f28979bbe2c -r 7b145222fea3 src/pt.h --- a/src/pt.h Fri Feb 06 23:56:46 2004 +0000 +++ b/src/pt.h Sat Feb 07 06:27:28 2004 +0000 @@ -31,7 +31,7 @@ #include -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; diff -r 3f28979bbe2c -r 7b145222fea3 src/toplev.cc --- a/src/toplev.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/toplev.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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) diff -r 3f28979bbe2c -r 7b145222fea3 src/toplev.h --- a/src/toplev.h Fri Feb 06 23:56:46 2004 +0000 +++ b/src/toplev.h Sat Feb 07 06:27:28 2004 +0000 @@ -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. diff -r 3f28979bbe2c -r 7b145222fea3 src/variables.cc --- a/src/variables.cc Fri Feb 06 23:56:46 2004 +0000 +++ b/src/variables.cc Sat Feb 07 06:27:28 2004 +0000 @@ -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"); }