Mercurial > octave
diff src/pt-idx.cc @ 3930:61d4427c016e
[project @ 2002-05-07 00:47:31 by jwe]
author | jwe |
---|---|
date | Tue, 07 May 2002 00:47:31 +0000 |
parents | cc8ae49d6e79 |
children | f9ea3dcf58ee |
line wrap: on
line diff
--- a/src/pt-idx.cc Sat May 04 02:47:14 2002 +0000 +++ b/src/pt-idx.cc Tue May 07 00:47:31 2002 +0000 @@ -29,12 +29,17 @@ #endif #include "error.h" +#include "oct-map.h" #include "oct-obj.h" #include "oct-lvalue.h" #include "ov.h" +#include "pager.h" #include "pt-arg-list.h" +#include "pt-bp.h" #include "pt-idx.h" #include "pt-walk.h" +#include "utils.h" +#include "variables.h" // Index expressions. @@ -44,6 +49,12 @@ : tree_expression (l, c), expr (e), list (lst), itype (t), arg_nm (lst ? lst->get_arg_names () : string_vector ()) { } +tree_index_expression::tree_index_expression (tree_expression *e, + const std::string& n, + int l = -1, int c = -1) + : tree_expression (l, c), expr (e), list (0), itype (dot), + arg_nm (n) { } + tree_index_expression::~tree_index_expression (void) { delete expr; @@ -56,7 +67,10 @@ std::string tree_index_expression::name (void) const { - return expr->name (); + // ??? FIXME ??? + std::string xname = expr->name (); + + return (! dot || xname == "<unknown>") ? xname : xname + "." + arg_nm(0); } octave_value_list @@ -71,24 +85,63 @@ if (! error_state) { - octave_value_list args; - - if (list) - args = list->convert_to_const_vector (); - - if (! error_state) + if (itype == dot) { - if (! args.empty ()) - args.stash_name_tags (arg_nm); + MAYBE_DO_BREAKPOINT; + + if (nargout > 1) + error ("invalid number of output arguments for structure reference"); + else + { + octave_value_list tmp = expr->rvalue (nargout); + + if (tmp.empty ()) + eval_error (); + else + { + octave_value val = tmp(0).do_struct_elt_index_op (arg_nm(0)); + + if (print_result () && nargout == 0 && val.is_defined ()) + { + // ??? FIXME ??? + + std::string xname = name (); + + if (xname == "<unknown>") + bind_ans (val, true); + else + val.print_with_name (octave_stdout, xname); + } - // XXX FIXME XXX -- is this the right thing to do? - if (tmp.is_constant ()) - retval = tmp.do_index_op (args); + retval = val; + } + } + } + else if (itype == paren || itype == brace) + { + octave_value_list args; + + if (list) + args = list->convert_to_const_vector (); + + if (! error_state) + { + if (! args.empty ()) + args.stash_name_tags (arg_nm); + + // XXX FIXME XXX -- is this the right thing to do? + if (tmp.is_constant ()) + retval = tmp.do_index_op (args); + else + retval = tmp.do_multi_index_op (nargout, args); + } else - retval = tmp.do_multi_index_op (nargout, args); + eval_error (); } +#if 0 else - eval_error (); + panic_impossible (); +#endif } else eval_error (); @@ -116,16 +169,32 @@ if (! error_state) { - retval = expr->lvalue (); + if (itype == dot) + { + octave_lvalue tmp = expr->lvalue (); - if (! error_state) + if (tmp.is_undefined () || ! tmp.is_map ()) + tmp.define (Octave_map ()); + + retval = tmp.struct_elt_ref (arg_nm(0)); + } + else if (itype == paren || itype == brace) { - octave_value_list args; + retval = expr->lvalue (); + + if (! error_state) + { + octave_value_list args; - if (list) - args = list->convert_to_const_vector (); + if (list) + args = list->convert_to_const_vector (); - retval.set_index (args); + retval.set_index (args); + } +#if 0 + else + panic_impossible (); +#endif } } @@ -140,21 +209,19 @@ int l = line (); int c = column (); + const char *type_str; + + if (itype == dot) + type_str = "structure reference operator"; + else if (list) + type_str = "index expression"; + else + type_str = "expression"; + if (l != -1 && c != -1) - { - if (list) - ::error ("evaluating index expression near line %d, column %d", - l, c); - else - ::error ("evaluating expression near line %d, column %d", l, c); - } + ::error ("evaluating %s near line %d, column %d", type_str, l, c); else - { - if (list) - ::error ("evaluating index expression"); - else - ::error ("evaluating expression"); - } + ::error ("evaluating %s", type_str); } }