Mercurial > hg > octave-lyh
changeset 15614:f2b8f90052fd
warn instead of throwing an error for invalid structure field names
* ov-struct.cc, ov-struct.h (maybe_warn_invalid_field_name):
New function.
(octave_struct::subsasgn, octave_scalar_struct::dotref,
octave_scalar_struct::subsasgn, Fstruct): Call
maybe_warn_invalid_field_name.
* pt-idx.cc (tree_index_expression::get_struct_index): Don't check for
valid structure field names here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Nov 2012 13:24:51 -0500 |
parents | 126285fce876 |
children | 808e4f13e220 |
files | libinterp/octave-value/ov-struct.cc libinterp/parse-tree/pt-idx.cc |
diffstat | 2 files changed, 49 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -116,6 +116,22 @@ error ("assignment to structure element failed"); } +static void +maybe_warn_invalid_field_name (const std::string& key, const char *who) +{ + if (! valid_identifier (key)) + { + if (who) + warning_with_id ("Octave:matlab-incompatible", + "%s: invalid structure field name '%s'", + who, key.c_str ()); + else + warning_with_id ("Octave:matlab-incompatible", + "invalid structure field name '%s'", + key.c_str ()); + } +} + octave_value_list octave_struct::subsref (const std::string& type, const std::list<octave_value_list>& idx, @@ -305,6 +321,11 @@ std::string key = key_idx(0).string_value (); + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (error_state) + return retval; + std::list<octave_value_list> next_idx (idx); // We handled two index elements, so subsasgn to @@ -363,6 +384,11 @@ std::string key = key_idx(0).string_value (); + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (error_state) + return retval; + std::list<octave_value_list> next_idx (idx); next_idx.erase (next_idx.begin ()); @@ -431,6 +457,11 @@ std::string key = key_idx(0).string_value (); + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (error_state) + return retval; + if (! error_state) { if (t_rhs.is_cs_list ()) @@ -530,6 +561,11 @@ std::string key = key_idx(0).string_value (); + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (error_state) + return retval; + if (t_rhs.is_cs_list ()) { Cell tmp_cell = Cell (t_rhs.list_value ()); @@ -1099,11 +1135,10 @@ std::string nm = idx(0).string_value (); - if (! valid_identifier (nm)) - { - error ("subsref: invalid structure field name '%s'", nm.c_str ()); - return retval; - } + maybe_warn_invalid_field_name (nm, "subsref"); + + if (error_state) + return retval; retval = map.getfield (nm); @@ -1226,11 +1261,10 @@ std::string key = key_idx(0).string_value (); - if (! valid_identifier (key)) - { - error ("subsasgn: invalid structure field name '%s'", key.c_str ()); - return retval; - } + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (error_state) + return retval; if (n > 1) { @@ -1819,11 +1853,10 @@ if (error_state) return retval; - if (! valid_identifier (key)) - { - error ("struct: invalid structure field name '%s'", key.c_str ()); - return retval; - } + maybe_warn_invalid_field_name (key, "struct"); + + if (error_state) + return retval; // Value may be v, { v }, or { v1, v2, ... } // In the first two cases, we need to create a cell array of
--- a/libinterp/parse-tree/pt-idx.cc +++ b/libinterp/parse-tree/pt-idx.cc @@ -216,12 +216,7 @@ octave_value t = df->rvalue1 (); if (! error_state) - { - fn = t.string_value (); - - if (! valid_identifier (fn)) - ::error ("invalid structure field name '%s'", fn.c_str ()); - } + fn = t.string_value (); } else panic_impossible ();