# HG changeset patch # User John W. Eaton # Date 1447970199 18000 # Node ID bba1a5fd4d8c7a8cf70f9e29ffa5317546ffccc1 # Parent 9e8a6d6d6de919558e01c254a8be6f061b989359 eliminate more uses of error_state * ov-struct.cc: Eliminate remaining uses of error_state. diff -r 9e8a6d6d6de9 -r bba1a5fd4d8c libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Mon Nov 23 15:00:06 2015 -0500 +++ b/libinterp/octave-value/ov-struct.cc Thu Nov 19 16:56:39 2015 -0500 @@ -430,117 +430,15 @@ } } - if (! error_state) + switch (type[0]) { - switch (type[0]) - { - case '(': + case '(': + { + if (n > 1 && type[1] == '.') { - if (n > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; - octave_value_list idxf = idx.front (); - - assert (key_idx.length () == 1); - - std::string key = key_idx(0).string_value (); - - maybe_warn_invalid_field_name (key, "subsasgn"); - - if (! error_state) - { - if (t_rhs.is_cs_list ()) - { - Cell tmp_cell = Cell (t_rhs.list_value ()); - - // Inquire the proper shape of the RHS. - - dim_vector didx = dims ().redim (idxf.length ()); - for (octave_idx_type k = 0; k < idxf.length (); k++) - if (! idxf(k).is_magic_colon ()) - didx(k) = idxf(k).numel (); - - if (didx.numel () == tmp_cell.numel ()) - tmp_cell = tmp_cell.reshape (didx); - - - map.assign (idxf, key, tmp_cell); - - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - { - const octave_map& cmap = - const_cast (map); - // cast to const reference, avoid forced key insertion. - if (idxf.all_scalars () - || cmap.contents (key).index (idxf, true).numel () - <= 1) - { - map.assign (idxf, - key, Cell (t_rhs.storable_value ())); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else if (! error_state) - gripe_nonbraced_cs_list_assignment (); - } - } - else - gripe_failed_assignment (); - } - else - { - if (t_rhs.is_map () || t_rhs.is_object ()) - { - octave_map rhs_map = t_rhs.xmap_value ("invalid structure assignment"); - - map.assign (idx.front (), rhs_map); - - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - { - if (t_rhs.is_null_value ()) - { - map.delete_elements (idx.front ()); - - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid structure assignment"); - } - } - } - break; - - case '.': - { - octave_value_list key_idx = idx.front (); + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; + octave_value_list idxf = idx.front (); assert (key_idx.length () == 1); @@ -552,42 +450,110 @@ { Cell tmp_cell = Cell (t_rhs.list_value ()); - // The shape of the RHS is irrelevant, we just want - // the number of elements to agree and to preserve the - // shape of the left hand side of the assignment. - - if (numel () == tmp_cell.numel ()) - tmp_cell = tmp_cell.reshape (dims ()); - - map.setfield (key, tmp_cell); + // Inquire the proper shape of the RHS. + + dim_vector didx = dims ().redim (idxf.length ()); + for (octave_idx_type k = 0; k < idxf.length (); k++) + if (! idxf(k).is_magic_colon ()) + didx(k) = idxf(k).numel (); + + if (didx.numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (didx); + + + map.assign (idxf, key, tmp_cell); + + count++; + retval = octave_value (this); } else { - Cell tmp_cell(1, 1); - tmp_cell(0) = t_rhs.storable_value (); - map.setfield (key, tmp_cell); + const octave_map& cmap = + const_cast (map); + // cast to const reference, avoid forced key insertion. + if (idxf.all_scalars () + || cmap.contents (key).index (idxf, true).numel () + <= 1) + { + map.assign (idxf, + key, Cell (t_rhs.storable_value ())); + + count++; + retval = octave_value (this); + } + else + gripe_nonbraced_cs_list_assignment (); } - - if (! error_state) + } + else + { + if (t_rhs.is_map () || t_rhs.is_object ()) { + octave_map rhs_map = t_rhs.xmap_value ("invalid structure assignment"); + + map.assign (idx.front (), rhs_map); + count++; retval = octave_value (this); } else - gripe_failed_assignment (); + { + if (t_rhs.is_null_value ()) + { + map.delete_elements (idx.front ()); + + count++; + retval = octave_value (this); + } + else + error ("invalid structure assignment"); + } } - break; - - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; - - default: - panic_impossible (); - } + } + break; + + case '.': + { + octave_value_list key_idx = idx.front (); + + assert (key_idx.length () == 1); + + std::string key = key_idx(0).string_value (); + + maybe_warn_invalid_field_name (key, "subsasgn"); + + if (t_rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (t_rhs.list_value ()); + + // The shape of the RHS is irrelevant, we just want + // the number of elements to agree and to preserve the + // shape of the left hand side of the assignment. + + if (numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (dims ()); + + map.setfield (key, tmp_cell); + } + else + { + Cell tmp_cell(1, 1); + tmp_cell(0) = t_rhs.storable_value (); + map.setfield (key, tmp_cell); + } + + count++; + retval = octave_value (this); + } + break; + + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; + + default: + panic_impossible (); } - else - gripe_failed_assignment (); retval.maybe_mutate (); @@ -1267,10 +1233,7 @@ : tmp.subsasgn (next_type, next_idx, rhs)); } - if (! error_state) - map.setfield (key, t_rhs.storable_value ()); - else - gripe_failed_assignment (); + map.setfield (key, t_rhs.storable_value ()); count++; retval = this; @@ -1454,12 +1417,6 @@ if (!is) break; - if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } - m.setfield (nm, t2); } @@ -1544,12 +1501,6 @@ if (!is) break; - if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } - m.setfield (nm, t2); } @@ -1646,12 +1597,6 @@ { octave_value t2 = dsub.tc; - if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } - m.setfield (dsub.name, t2); }