Mercurial > hg > octave-avbm
changeset 1277:db4f4009d6e8
[project @ 1995-04-24 20:35:06 by jwe]
author | jwe |
---|---|
date | Mon, 24 Apr 1995 20:35:06 +0000 |
parents | cbdf7db98554 |
children | 606361d34c74 |
files | src/data.cc src/pt-const.cc src/pt-const.h src/tc-rep.cc src/tc-rep.h src/variables.cc |
diffstat | 6 files changed, 86 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/data.cc +++ b/src/data.cc @@ -753,14 +753,11 @@ if (nargin == 2) { retval = 0.0; - if (args(0).is_map ()) + if (args(0).is_map () && args(1).is_string ()) { - if (args(1).is_string ()) - { - Octave_map m = args(0).map_value (); - char *s = args(1).string_value (); - retval = (double) (s && m.contains (s)); - } + char *s = args(1).string_value (); + tree_constant tmp = args(0).lookup_map_element (s, 0, 1); + retval = (double) tmp.is_defined (); } } else
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -25,6 +25,7 @@ #include <config.h> #endif +#include <string.h> #include <iostream.h> #include <strstream.h> @@ -109,7 +110,40 @@ } tree_constant -tree_constant::lookup_map_element (SLList<char*>& list) +tree_constant::lookup_map_element (const char *ref, int insert, + int silent) +{ + tree_constant retval; + + if (ref) + { + char *tmp = strsave (ref); + + SLList<char *> list; + + char *beg = tmp; + char *end = 0; + do + { + end = strchr (beg, '.'); + if (end) + *end = '\0'; + + list.append (strsave (beg)); + } + while (end && (beg = end + 1)); + + retval = lookup_map_element (list, insert, silent); + + delete [] tmp; + } + + return retval; +} + +tree_constant +tree_constant::lookup_map_element (SLList<char*>& list, int insert, + int silent) { tree_constant retval; @@ -122,7 +156,9 @@ list.next (p); - tree_constant tmp = tmp_rep->lookup_map_element (elt); + tree_constant tmp; + + tmp = tmp_rep->lookup_map_element (elt, insert, silent); if (error_state) break;
--- a/src/pt-const.h +++ b/src/pt-const.h @@ -255,10 +255,7 @@ // Is at least one of the dimensions of this constant zero? int is_empty (void) const - { - return ((! (is_magic_colon () || is_all_va_args () || is_unknown ())) - && (rows () == 0 || columns () == 0)); - } + { return rep->is_empty (); } // Are the dimensions of this constant zero by zero? @@ -290,7 +287,11 @@ Octave_map map_value (void) const; - tree_constant lookup_map_element (SLList<char*>& list); + tree_constant lookup_map_element (const char *ref, int insert = 0, + int silent = 0); + + tree_constant lookup_map_element (SLList<char*>& list, + int insert = 0, int silent = 0); ColumnVector vector_value (int force_string_conversion = 0, int force_vector_conversion = 0) const
--- a/src/tc-rep.cc +++ b/src/tc-rep.cc @@ -1081,7 +1081,7 @@ } tree_constant& -TC_REP::lookup_map_element (const char *name, int insert) +TC_REP::lookup_map_element (const char *name, int insert, int silent) { static tree_constant retval; @@ -1093,10 +1093,10 @@ return a_map->contents (idx); else if (insert) return (*a_map) [name]; - else + else if (! silent) error ("structure has no member `%s'", name); } - else + else if (! silent) error ("invalid structure access attempted"); return retval;
--- a/src/tc-rep.h +++ b/src/tc-rep.h @@ -176,6 +176,12 @@ int is_true (void) const; + int is_empty (void) const + { + return ((! (is_magic_colon () || is_all_va_args () || is_unknown ())) + && (rows () == 0 || columns () == 0)); + } + double double_value (int force_string_conversion = 0) const; Matrix matrix_value (int force_string_conversion = 0) const; Complex complex_value (int force_string_conversion = 0) const; @@ -184,7 +190,8 @@ Range range_value (void) const; Octave_map map_value (void) const; - tree_constant& lookup_map_element (const char *name, int insert = 0); + tree_constant& lookup_map_element (const char *name, int insert = 0, + int silent = 0); ColumnVector vector_value (int force_string_conversion = 0, int force_vector_conversion = 0) const;
--- a/src/variables.cc +++ b/src/variables.cc @@ -224,14 +224,22 @@ return retval; } - char *name = args(0).string_value (); + char *name = strsave (args(0).string_value ()); if (error_state) { error ("exist: expecting string argument"); + delete [] name; return retval; } + char *struct_elts = strchr (name, '.'); + if (struct_elts) + { + *struct_elts = '\0'; + struct_elts++; + } + symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); if (! sr) sr = global_sym_tab->lookup (name, 0, 0); @@ -239,7 +247,22 @@ retval = 0.0; if (sr && sr->is_variable () && sr->is_defined ()) - retval = 1.0; + { + retval = 1.0; + tree_fvc *def = sr->def (); + if (struct_elts) + { + retval = 0.0; + if (def->is_constant ()) + { + tree_constant *tmp = (tree_constant *) def; + tree_constant ult; + ult = tmp->lookup_map_element (struct_elts, 0, 1); + if (ult.is_defined ()) + retval = 1.0; + } + } + } else if (sr && sr->is_function ()) retval = 2.0; else @@ -258,6 +281,8 @@ } } + delete [] name; + return retval; }