Mercurial > hg > octave-nkf
changeset 6215:516d3071b34c
[project @ 2006-12-15 03:24:12 by jwe]
author | jwe |
---|---|
date | Fri, 15 Dec 2006 03:24:13 +0000 |
parents | 4685a6a76229 |
children | 74ca56e4414c |
files | src/ChangeLog src/parse.y src/pt-bp.cc src/pt-check.cc src/pt-decl.cc src/pt-decl.h src/pt-misc.cc src/pt-misc.h src/pt-pr-code.cc |
diffstat | 9 files changed, 108 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,36 @@ +2006-12-14 John W. Eaton <jwe@octave.org> + + * pt-decl.cc (tree_decl_elt::eval): New function. + * pt-decl.h (tree_decl_elt::eval): Provide decl. + (tree_decl_elt::is_defined, tree_decl_elt::lvalue_ok, + tree_decl_elt::mark_as_formal_parameter, tree_decl_elt::rvalue, + tree_decl_elt::lvalue): New functions. + + * pt-misc.h (class tree_parameter_list): Derive from + octave_base_list<tree_decl_elt *> instead of + octave_base_list<tree_identifier *>. + (tree_parameter_list::tree_parameter_list (tree_identifier *)): Delete. + (tree_parameter_list::tree_parameter_list (tree_decl_elt *)): + New function. + * pt-misc.cc (tree_parameter_list::mark_as_formal_parameters, + tree_parameter_list::initialize_undefined_elements, + tree_parameter_list::undefine, tree_parameter_list::dup, + tree_parameter_list::convert_to_const_vector, + tree_parameter_list::is_defined): Handle argument list elements + as tree_decl_list objects instead of tree_identifier objects. + (tree_parameter_list::define_from_arg_vector): Likewise. + Always process entire list, setting default values if possible. + Accept ":" to mean "use default argument". + + * parse.y (param_list2): Use decl2 to recognize + "identifier '=' expression" in addition to "identifier". + + * parse.y (return_list1, make_anon_fcn_handle, finish_function): + Adapt to new definition of tree_parameter_list. + * pt-bp.cc (tree_breakpoint::visit_parameter_list): Likewise. + * pt-check.cc (tree_checker::visit_parameter_list): Likewise. + * pt-pr-code.cc (tree_print_code::visit_parameter_list): Likewise. + 2006-12-08 John W. Eaton <jwe@octave.org> * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::array_value,
--- a/src/parse.y +++ b/src/parse.y @@ -1165,9 +1165,9 @@ } ; -param_list2 : identifier +param_list2 : decl2 { $$ = new tree_parameter_list ($1); } - | param_list2 ',' identifier + | param_list2 ',' decl2 { $1->append ($3); $$ = $1; @@ -1214,10 +1214,10 @@ ; return_list1 : identifier - { $$ = new tree_parameter_list ($1); } + { $$ = new tree_parameter_list (new tree_decl_elt ($1)); } | return_list1 ',' identifier { - $1->append ($3); + $1->append (new tree_decl_elt ($3)); $$ = $1; } ; @@ -1796,8 +1796,9 @@ // created so we don't have to create a new statement at all. id = new tree_identifier (sr); - - ret_list = new tree_parameter_list (id); + tree_decl_elt *elt = new tree_decl_elt (id); + + ret_list = new tree_parameter_list (elt); } tree_statement_list *body = new tree_statement_list (stmt); @@ -2585,7 +2586,9 @@ finish_function (tree_identifier *id, octave_user_function *fcn, octave_comment_list *lc) { - tree_parameter_list *tpl = new tree_parameter_list (id); + tree_decl_elt *tmp = new tree_decl_elt (id); + + tree_parameter_list *tpl = new tree_parameter_list (tmp); tpl->mark_as_formal_parameters ();
--- a/src/pt-bp.cc +++ b/src/pt-bp.cc @@ -470,7 +470,7 @@ while (p != lst.end ()) { - tree_identifier *elt = *p++; + tree_decl_elt *elt = *p++; if (elt) elt->accept (*this);
--- a/src/pt-check.cc +++ b/src/pt-check.cc @@ -327,7 +327,7 @@ while (p != lst.end ()) { - tree_identifier *elt = *p++; + tree_decl_elt *elt = *p++; if (elt) elt->accept (*this);
--- a/src/pt-decl.cc +++ b/src/pt-decl.cc @@ -45,6 +45,28 @@ delete expr; } +bool +tree_decl_elt::eval (void) +{ + bool retval = false; + + if (id && expr) + { + octave_lvalue ult = id->lvalue (); + + octave_value init_val = expr->rvalue (); + + if (! error_state) + { + ult.assign (octave_value::op_asn_eq, init_val); + + retval = true; + } + } + + return retval; +} + tree_decl_elt * tree_decl_elt::dup (symbol_table *sym_tab) {
--- a/src/pt-decl.h +++ b/src/pt-decl.h @@ -32,7 +32,9 @@ #include <string> #include "base-list.h" +#include "oct-lvalue.h" #include "pt-cmd.h" +#include "pt-id.h" // List of expressions that make up a declaration statement. @@ -48,7 +50,26 @@ ~tree_decl_elt (void); - void eval (void); + bool eval (void); + + bool is_defined (void) { return id ? id->is_defined () : false; } + + void mark_as_formal_parameter (void) + { + if (id) + id->mark_as_formal_parameter (); + } + + bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } + + octave_value rvalue (void) { return id ? id->rvalue () : octave_value (); } + + octave_value_list rvalue (int nargout) + { + return id ? id->rvalue (nargout) : octave_value_list (); + } + + octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } tree_identifier *ident (void) { return id; }
--- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -54,7 +54,7 @@ { for (iterator p = begin (); p != end (); p++) { - tree_identifier *elt = *p; + tree_decl_elt *elt = *p; elt->mark_as_formal_parameter (); } } @@ -73,7 +73,7 @@ if (++count > nargout) break; - tree_identifier *elt = *p; + tree_decl_elt *elt = *p; if (! elt->is_defined ()) { @@ -99,16 +99,13 @@ { int nargin = args.length (); - if (nargin <= 0) - return; - int expected_nargin = length (); iterator p = begin (); for (int i = 0; i < expected_nargin; i++) { - tree_identifier *elt = *p++; + tree_decl_elt *elt = *p++; octave_lvalue ref = elt->lvalue (); @@ -116,14 +113,17 @@ { if (args(i).is_defined () && args(i).is_magic_colon ()) { - ::error ("invalid use of colon in function argument list"); - return; + if (! elt->eval ()) + { + ::error ("no default value for argument %d\n", i+1); + return; + } } - - ref.assign (octave_value::op_asn_eq, args(i)); + else + ref.assign (octave_value::op_asn_eq, args(i)); } else - ref.assign (octave_value::op_asn_eq, octave_value ()); + elt->eval (); } } @@ -136,7 +136,7 @@ for (int i = 0; i < len; i++) { - tree_identifier *elt = *p++; + tree_decl_elt *elt = *p++; octave_lvalue ref = elt->lvalue (); @@ -157,7 +157,7 @@ for (iterator p = begin (); p != end (); p++) { - tree_identifier *elt = *p; + tree_decl_elt *elt = *p; retval(i++) = elt->is_defined () ? elt->rvalue () : octave_value (); } @@ -175,7 +175,7 @@ for (iterator p = begin (); p != end (); p++) { - tree_identifier *elt = *p; + tree_decl_elt *elt = *p; if (! elt->is_defined ()) { @@ -197,7 +197,7 @@ for (iterator p = begin (); p != end (); p++) { - tree_identifier *elt = *p; + tree_decl_elt *elt = *p; new_list->append (elt->dup (sym_tab)); }
--- a/src/pt-misc.h +++ b/src/pt-misc.h @@ -36,20 +36,21 @@ class tree_walker; #include "base-list.h" +#include "pt-decl.h" // Parameter lists. Used to hold the list of input and output // parameters in a function definition. Elements are identifiers // only. class -tree_parameter_list : public octave_base_list<tree_identifier *> +tree_parameter_list : public octave_base_list<tree_decl_elt *> { public: tree_parameter_list (void) : marked_for_varargs (0) { } - tree_parameter_list (tree_identifier *t) + tree_parameter_list (tree_decl_elt *t) : marked_for_varargs (0) { append (t); } ~tree_parameter_list (void);