Mercurial > hg > octave-nkf
changeset 5848:415ae81d331b
[project @ 2006-06-08 20:37:29 by jwe]
author | jwe |
---|---|
date | Thu, 08 Jun 2006 20:37:29 +0000 |
parents | 62e7b9307d00 |
children | e89f8bae317b |
files | src/ChangeLog src/Makefile.in src/lex.l src/octave.gperf src/ov-fcn.h src/ov-usr-fcn.cc src/ov-usr-fcn.h src/ov-va-args.cc src/ov-va-args.h src/ov.cc src/ov.h src/parse.y src/pt-arg-list.cc src/pt-misc.cc src/pt-misc.h src/pt-pr-code.cc |
diffstat | 16 files changed, 76 insertions(+), 509 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,43 @@ 2006-06-08 John W. Eaton <jwe@octave.org> + * ov-usr-fcn.cc (function::do_multi_index_op): Append contents of + varargout to ret_list before calling convert_to_const_vector. + + * pt-arg-list.cc (tree_argument_list::convert_to_const_vector): + No need to handle all_va_args here. + + * ov-va-args.h, ov-va-args.cc: Delete files. + * Makefile.in (OV_INCLUDES, OV_SRC): Delete from the lists. + + * ov.cc (install_types): Don't register octave_all_va_args type. + * ov.h, ov.cc (octave_value::octave_value (octave_value::all_va_args)): + Delete. + * ov.h (octave_value::is_all_va_args): Delete. + (octave_value::enum all_va_args): Delete. + + * pt-pr-code.cc (tree_print_code::visit_octave_user_function_header): + Print "varargout" and "varargin" instead of "...". + + * pt-misc.h, pt-misc.cc (tree_parameter_list::convert_to_const_vector): + Arg is now const Cell& instead of tree_va_return_list*. + + * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::vr_list, + octave_user_function::curr_va_arg_number): + Delete variables and all uses. + (octave_function::octave_va_start, octave_function::octave_va_arg, + octave_function::octave_vr_val, octave_function::has_varargout): + Delete functions and all uses. + + * ov-fcn.h (octave_function::octave_va_start, + octave_function::octave_va_arg, octave_function::octave_vr_val, + octave_function::has_varargout): Delete. + + * ov-usr-fcn.cc (Fva_arg, Fva_start, Fvr_val): Delete. + + * lex.l ({EL}): Don't handle "..." as varargin or varargout. + * octave.gperf (all_va_args, ALL_VA_ARGS, all_va_args_kw): Delete. + * parse.y (ALL_VA_ARGS): Delete token and all uses. + * defaults.h.in (OCTAVE_DATAROOTDIR): Substitute here. * toplev.cc (octave_config_info): Add datarootdir to the struct.
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -76,7 +76,7 @@ ov-uint8.h ov-uint16.h ov-uint32.h ov-uint64.h OV_INCLUDES := ov-re-mat.h ov-cx-mat.h ov-ch-mat.h ov-cs-list.h ov-list.h \ - ov-struct.h ov-scalar.h ov-range.h ov-complex.h ov-va-args.h \ + ov-struct.h ov-scalar.h ov-range.h ov-complex.h \ ov-colon.h ov-base.h ov-base-mat.h ov-base-scalar.h \ ov-streamoff.h ov-str-mat.h ov-bool-mat.h ov-bool.h \ ov-cell.h ov.h ov-fcn.h ov-builtin.h ov-dld-fcn.h \ @@ -148,7 +148,7 @@ OV_SRC := ov-base.cc ov-ch-mat.cc \ ov-cs-list.cc ov-list.cc ov-re-mat.cc ov-cx-mat.cc \ ov-range.cc ov-scalar.cc ov-complex.cc ov-str-mat.cc \ - ov-streamoff.cc ov-struct.cc ov-va-args.cc \ + ov-streamoff.cc ov-struct.cc \ ov-colon.cc ov-bool-mat.cc ov-bool.cc ov-cell.cc \ ov.cc ov-fcn.cc ov-builtin.cc ov-dld-fcn.cc ov-mapper.cc \ ov-usr-fcn.cc ov-fcn-handle.cc ov-fcn-inline.cc ov-typeinfo.cc \
--- a/src/lex.l +++ b/src/lex.l @@ -540,26 +540,6 @@ } %{ -// An ellipsis not at the end of a line is not a continuation, but -// does have another meaning. -%} - -{EL} { - if (lexer_flags.looking_at_parameter_list) - { - warning ("`...' is deprecated; use varargin instead"); - COUNT_TOK_AND_RETURN (VARARGIN); - } - else if (lexer_flags.looking_at_return_list) - { - warning ("`...' is deprecated; use varargout instead"); - COUNT_TOK_AND_RETURN (VARARGOUT); - } - else - return LEXICAL_ERROR; - } - -%{ // End of file. %}
--- a/src/octave.gperf +++ b/src/octave.gperf @@ -41,7 +41,6 @@ struct octave_kw { const char *name; int tok; octave_kw_id kw_id; }; %% -all_va_args, ALL_VA_ARGS, all_va_args_kw break, BREAK, break_kw case, CASE, case_kw catch, CATCH, catch_kw
--- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -76,19 +76,8 @@ virtual bool takes_varargs (void) const { return false; } - virtual void octave_va_start (void) { } - - virtual octave_value octave_va_arg (void) { 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&) { } - - virtual bool has_varargout (void) const { return false; } - std::string name (void) const { return my_name; } void document (const std::string& ds) { doc = ds; }
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -78,15 +78,11 @@ t_checked (static_cast<time_t> (0)), system_fcn_file (false), call_depth (0), num_named_args (0), nested_function (false), - args_passed (), num_args_passed (0), - curr_va_arg_number (0), vr_list (0), symtab_entry (0), + args_passed (), num_args_passed (0), symtab_entry (0), argn_sr (0), nargin_sr (0), nargout_sr (0), varargin_sr (0) { if (param_list) - { - num_named_args = param_list->length (); - curr_va_arg_number = num_named_args; - } + num_named_args = param_list->length (); } octave_user_function::~octave_user_function (void) @@ -95,7 +91,6 @@ delete ret_list; delete sym_tab; delete cmd_list; - delete vr_list; delete lead_comm; delete trail_comm; } @@ -105,9 +100,6 @@ { ret_list = t; - if (ret_list && ret_list->takes_varargs ()) - vr_list = new tree_va_return_list; - return this; } @@ -146,18 +138,10 @@ return (param_list && param_list->takes_varargs ()); } -octave_value -octave_user_function::octave_va_arg (void) +bool +octave_user_function::takes_var_return (void) const { - octave_value retval; - - if (curr_va_arg_number < num_args_passed) - retval = args_passed (curr_va_arg_number++); - else - ::error ("va_arg: error getting arg number %d -- only %d provided", - curr_va_arg_number + 1, num_args_passed); - - return retval; + return (ret_list && ret_list->takes_varargs ()); } octave_value_list @@ -179,69 +163,6 @@ return retval; } -bool -octave_user_function::takes_var_return (void) const -{ - return (ret_list && ret_list->takes_varargs ()); -} - -void -octave_user_function::octave_vr_val (const octave_value& val) -{ - // Use != here to avoid possible conversion to int of smaller type - // than the vr_list pointer. - - assert (vr_list != 0); - - vr_list->append (val); -} - -void -octave_user_function::varargout_to_vr_val (void) -{ - assert (vr_list && vr_list->empty ()); - - symbol_record *sr = sym_tab->lookup ("varargout"); - - if (sr && sr->is_variable ()) - { - octave_value v = sr->def (); - - Cell c = v.cell_value (); - - if (! error_state) - { - // FIXME -- should varargout be required to be a - // cell array with a single row or column? If not, should - // we have a cleaner way of doing this operation? - - int n = c.length (); - - const octave_value *d = c.data (); - - for (int i = 0; i < n; i++) - vr_list->append (d[i]); - } - else - error ("expecting varargout to be a cell array object"); - } -} - -bool -octave_user_function::has_varargout (void) const -{ - bool retval = false; - - if (takes_var_return ()) - { - symbol_record *sr = sym_tab->lookup ("varargout"); - - retval = (sr && sr->is_variable ()); - } - - return retval; -} - // For unwind protect. static void @@ -252,14 +173,6 @@ } static void -delete_vr_list (void *list) -{ - tree_va_return_list *tmp = static_cast<tree_va_return_list *> (list); - tmp->clear (); - delete tmp; -} - -static void clear_symbol_table (void *table) { symbol_table *tmp = static_cast<symbol_table *> (table); @@ -366,24 +279,8 @@ { sym_tab->push_context (); unwind_protect::add (pop_symbol_table_context, sym_tab); - - if (vr_list) - { - // Push new vr_list. - - unwind_protect_ptr (vr_list); - vr_list = new tree_va_return_list; - - // Clear and delete the new one before restoring the old - // one. - - unwind_protect::add (delete_vr_list, vr_list); - } } - if (vr_list) - vr_list->clear (); - install_automatic_vars (); // Force symbols to be undefined again when this function exits. @@ -423,10 +320,6 @@ unwind_protect_int (num_args_passed); num_args_passed = nargin; - unwind_protect_int (curr_va_arg_number); - - curr_va_arg_number = num_named_args; - if (param_list && ! param_list->varargs_only ()) { param_list->define_from_arg_vector (args); @@ -491,10 +384,22 @@ { ret_list->initialize_undefined_elements (my_name, nargout, Matrix ()); - if (has_varargout ()) - varargout_to_vr_val (); + Cell varargout; + + symbol_record *sr = sym_tab->lookup ("varargout"); + + if (sr && sr->is_variable ()) + { + octave_value v = sr->def (); - retval = ret_list->convert_to_const_vector (vr_list); + varargout = v.cell_value (); + + if (error_state) + error ("expecting varargout to be a cell array object"); + } + + if (! error_state) + retval = ret_list->convert_to_const_vector (varargout); } } @@ -729,142 +634,6 @@ return retval; } -DEFUNX ("va_arg", Fva_arg, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} va_arg ()\n\ -Return the value of the next available argument and move the internal\n\ -pointer to the next argument. It is an error to call @code{va_arg}\n\ -when ther eare no more arguments available, or in a function that\n\ -has not been declared to take a variable number of parameters.\n\ -@end deftypefn") -{ - static bool warned = false; - - if (! warned) - { - ::warning ("va_arg is deprecated; use varargin instead"); - warned = true; - } - - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 0) - { - octave_user_function *fcn = octave_call_stack::caller_user_function (); - - if (fcn) - { - if (fcn->takes_varargs ()) - retval = fcn->octave_va_arg (); - else - { - ::error ("va_arg only valid within function taking variable"); - ::error ("number of arguments"); - } - } - else - ::error ("va_arg only valid within function body"); - } - else - print_usage (); - - return retval; -} - -DEFUN (va_start, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} va_start ()\n\ -Position an internal pointer to the first unnamed argument in\n\ -functions that have been declared to accept a variable number of\n\ -arguments. It is an error to call @code{va_start} in a function\n\ -that has not been declared to take a variable number of parameters.\n\ -@end deftypefn") -{ - static bool warned = false; - - if (! warned) - { - ::warning ("va_start is deprecated; use varargin instead"); - warned = true; - } - - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 0) - { - octave_user_function *fcn = octave_call_stack::caller_user_function (); - - if (fcn) - { - if (fcn->takes_varargs ()) - fcn->octave_va_start (); - else - { - ::error ("va_start only valid within function taking variable"); - ::error ("number of arguments"); - } - } - else - ::error ("va_start only valid within function body"); - } - else - print_usage (); - - return retval; -} - -DEFUN (vr_val, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} vr_val (@var{x})\n\ -Each time this function is called, it places the value of its argument\n\ -at the end of the list of values to return from the current\n\ -function. Once @code{vr_val} has been called, there is no way to go\n\ -back to the beginning of the list and rewrite any of the return\n\ -values. This function may only be called within functions that have\n\ -been declared to return an unspecified number of output arguments.\n\ -@end deftypefn") -{ - static bool warned = false; - - if (! warned) - { - ::warning ("vr_val is deprecated; use varargout instead"); - warned = true; - } - - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 1) - { - octave_user_function *fcn = octave_call_stack::caller_user_function (); - - if (fcn) - { - if (fcn->has_varargout ()) - ::error ("vr_val and varargout cannot both be used in the same function"); - else if (fcn->takes_var_return ()) - fcn->octave_vr_val (args(0)); - else - { - ::error ("vr_val only valid within function declared to"); - ::error ("produce a variable number of values"); - } - } - else - ::error ("vr_val only valid within function body"); - } - else - print_usage (); - - return retval; -} - DEFUN (max_recursion_depth, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -136,20 +136,10 @@ bool takes_varargs (void) const; - void octave_va_start (void) { curr_va_arg_number = num_named_args; } - - octave_value octave_va_arg (void); + bool takes_var_return (void) const; octave_value_list octave_all_va_args (void); - bool takes_var_return (void) const; - - void octave_vr_val (const octave_value& val); - - void varargout_to_vr_val (void); - - bool has_varargout (void) const; - void stash_function_name (const std::string& s) { my_name = s; } void mark_as_nested_function (void) { nested_function = true; } @@ -259,13 +249,6 @@ // The number of arguments passed in. int num_args_passed; - // Used to keep track of the current offset into the list of va_args. - int curr_va_arg_number; - - // The list of return values when an unspecified number can be - // returned. - tree_va_return_list *vr_list; - // The symbol record for this function. symbol_record *symtab_entry; @@ -290,7 +273,6 @@ void bind_automatic_vars (const string_vector& arg_names, int nargin, int nargout, const octave_value_list& va_args); - // No copying! octave_user_function (const octave_user_function& fn);
deleted file mode 100644 --- a/src/ov-va-args.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - -Copyright (C) 1996, 1997 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, write to the Free -Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <iostream> - -#include "error.h" -#include "pr-output.h" -#include "oct-obj.h" -#include "ov-va-args.h" - -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_all_va_args, "va-arg", "va-arg"); - -void -octave_all_va_args::print (std::ostream& os, bool) const -{ - indent (os); - print (os); -} - -void -octave_all_va_args::print_raw (std::ostream& os, bool) const -{ - os << "all_va_args"; -} - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/
deleted file mode 100644 --- a/src/ov-va-args.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - -Copyright (C) 1996, 1997 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, write to the Free -Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. - -*/ - -#if !defined (octave_all_va_args_h) -#define octave_all_va_args_h 1 - -#include <cstdlib> - -#include <iostream> -#include <string> - -#include "mx-base.h" -#include "str-vec.h" - -#include "error.h" -#include "ov-base.h" -#include "ov-typeinfo.h" - -class Octave_map; -class octave_value_list; - -class tree_walker; - -// A type to represent `all_va_args' as used in function calls. - -class -octave_all_va_args : public octave_base_value -{ -public: - - octave_all_va_args (void) - : octave_base_value () { } - - octave_all_va_args (const octave_all_va_args&) - : octave_base_value () { } - - ~octave_all_va_args (void) { } - - octave_base_value *clone (void) const { return new octave_all_va_args (*this); } - octave_base_value *empty_clone (void) const { return new octave_all_va_args (); } - - bool is_defined (void) const { return true; } - - bool is_all_va_args (void) const { return true; } - - void print (std::ostream& os, bool pr_as_read_syntax = false) const; - - void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - -private: - - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - -#endif - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/
--- a/src/ov.cc +++ b/src/ov.cc @@ -60,7 +60,6 @@ #include "ov-list.h" #include "ov-cs-list.h" #include "ov-colon.h" -#include "ov-va-args.h" #include "ov-builtin.h" #include "ov-mapper.h" #include "ov-dld-fcn.h" @@ -678,11 +677,6 @@ { } -octave_value::octave_value (octave_value::all_va_args) - : rep (new octave_all_va_args ()) -{ -} - octave_value::octave_value (octave_base_value *new_rep) : rep (new_rep) { @@ -1842,7 +1836,6 @@ octave_struct::register_type (); octave_list::register_type (); octave_cs_list::register_type (); - octave_all_va_args::register_type (); octave_magic_colon::register_type (); octave_builtin::register_type (); octave_mapper::register_type ();
--- a/src/ov.h +++ b/src/ov.h @@ -137,7 +137,6 @@ const octave_value& rhs = octave_value ()); enum magic_colon { magic_colon_t }; - enum all_va_args { all_va_args_t }; octave_value (void); octave_value (short int i); @@ -217,7 +216,6 @@ octave_value (const streamoff_array& off); octave_value (const octave_value_list& m, bool is_cs_list = false); octave_value (octave_value::magic_colon); - octave_value (octave_value::all_va_args); octave_value (octave_base_value *new_rep); @@ -435,9 +433,6 @@ bool is_magic_colon (void) const { return rep->is_magic_colon (); } - bool is_all_va_args (void) const - { return rep->is_all_va_args (); } - // Are any or all of the elements in this constant nonzero? octave_value all (int dim = 0) const
--- a/src/parse.y +++ b/src/parse.y @@ -394,7 +394,7 @@ // Other tokens. %token END_OF_INPUT LEXICAL_ERROR -%token FCN VARARGIN VARARGOUT ALL_VA_ARGS +%token FCN VARARGIN VARARGOUT %token CLOSE_BRACE // Nonterminals we construct. @@ -665,12 +665,6 @@ { $$ = new tree_argument_list ($1); } | magic_colon { $$ = new tree_argument_list ($1); } - | ALL_VA_ARGS - { - octave_value tmp (octave_value::all_va_args_t); - tree_constant *all_va_args = new tree_constant (tmp); - $$ = new tree_argument_list (all_va_args); - } | arg_list ',' magic_colon { $1->append ($3); @@ -681,13 +675,6 @@ $1->append ($3); $$ = $1; } - | arg_list ',' ALL_VA_ARGS - { - octave_value tmp (octave_value::all_va_args_t); - tree_constant *all_va_args = new tree_constant (tmp); - $1->append (all_va_args); - $$ = $1; - } ; indirect_ref_op : '.'
--- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -160,10 +160,6 @@ int len = length (); - // FIXME -- would be nice to know in advance how largs args - // needs to be even when we have a list containing an all_va_args - // token. - octave_value_list args; int args_len = len; args.resize (args_len); @@ -193,28 +189,7 @@ } else { - if (tmp.is_all_va_args ()) - { - octave_function *fcn = octave_call_stack::current (); - - if (fcn) - { - octave_value_list tva; - tva = fcn->octave_all_va_args (); - int n = tva.length (); - args_len += n - 1; - args.resize (args_len); - for (int i = 0; i < n; i++) - args(j++) = tva(i); - } - else - { - ::error ("all_va_args is only valid inside functions"); - args = octave_value_list (); - break; - } - } - else if (tmp.is_cs_list ()) + if (tmp.is_cs_list ()) { octave_value_list tl = tmp.list_value (); int n = tl.length ();
--- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include "Cell.h" + #include "defun.h" #include "error.h" #include "ov.h" @@ -143,15 +145,13 @@ } octave_value_list -tree_parameter_list::convert_to_const_vector (tree_va_return_list *vr_list) +tree_parameter_list::convert_to_const_vector (const Cell& varargout) { - int nout = length (); + octave_idx_type vlen = varargout.numel (); - if (vr_list) - nout += vr_list->length (); + int nout = length () + vlen; - octave_value_list retval; - retval.resize (nout); + octave_value_list retval (nout, octave_value ()); int i = 0; @@ -162,15 +162,8 @@ retval(i++) = elt->is_defined () ? elt->rvalue () : octave_value (); } - if (vr_list) - { - for (tree_va_return_list::iterator p = vr_list->begin (); - p != vr_list->end (); - p++) - { - retval(i++) = *p; - } - } + for (octave_idx_type j = 0; j < vlen; j++) + retval(i++) = varargout(j); return retval; }
--- a/src/pt-misc.h +++ b/src/pt-misc.h @@ -24,6 +24,8 @@ #if !defined (octave_tree_misc_h) #define octave_tree_misc_h 1 +class Cell; + class octave_value; class octave_value_list; @@ -71,7 +73,7 @@ bool is_defined (void); - octave_value_list convert_to_const_vector (tree_va_return_list *vr_list); + octave_value_list convert_to_const_vector (const Cell& varargout); void accept (tree_walker& tw);