Mercurial > hg > octave-lyh
diff src/tc-assign.cc @ 143:7849db4b6dbc
[project @ 1993-10-04 02:36:45 by jwe]
author | jwe |
---|---|
date | Mon, 04 Oct 1993 02:36:58 +0000 |
parents | 78fd87e624cb |
children | 5167d307c1c9 |
line wrap: on
line diff
--- a/src/tc-assign.cc +++ b/src/tc-assign.cc @@ -88,7 +88,7 @@ else { error ("invalid assignment to scalar"); - jump_to_top_level (); + return; } } else @@ -106,12 +106,14 @@ else { error ("invalid assignment to scalar"); - jump_to_top_level (); + return; } } } else if (user_pref.resize_on_range_error) { + tree_constant_rep::constant_type old_type_tag = type_tag; + if (type_tag == complex_scalar_constant) { Complex *old_complex = complex_scalar; @@ -124,18 +126,30 @@ matrix = new Matrix (1, 1, scalar); type_tag = matrix_constant; } + +// If there is an error, the call to do_matrix_assignment should not +// destroy the current value. tree_constant_rep::eval(int) will take +// care of converting single element matrices back to scalars. + do_matrix_assignment (rhs, args, nargs); + +// I don't think there's any other way to revert back to unknown +// constant types, so here it is. + + if (old_type_tag == unknown_constant && error_state) + { + if (type_tag == matrix_constant) + delete matrix; + else if (type_tag == complex_matrix_constant) + delete complex_matrix; + + type_tag = unknown_constant; + } } else if (nargs > 3 || nargs < 2) - { - error ("invalid index expression for scalar type"); - jump_to_top_level (); - } + error ("invalid index expression for scalar type"); else - { - error ("index invalid or out of range for scalar type"); - jump_to_top_level (); - } + error ("index invalid or out of range for scalar type"); } void @@ -228,11 +242,12 @@ case scalar_constant: { int i = NINT (tmp_i.double_value ()); - index_check (i-1, ""); + if (index_check (i-1, "") < 0) + return; if (nr <= 1 || nc <= 1) maybe_resize (i-1); - else - range_max_check (i-1, nr * nc); + else if (range_max_check (i-1, nr * nc) < 0) + return; nr = rows (); nc = columns (); @@ -240,7 +255,7 @@ if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) { error ("for A(int) = X: X must be a scalar"); - jump_to_top_level (); + return; } int ii = fortran_row (i, nr) - 1; int jj = fortran_column (i, nr) - 1; @@ -257,14 +272,14 @@ if (nr <= 1 || nc <= 1) maybe_resize (imax-1); - else - range_max_check (imax-1, len); + else if (range_max_check (imax-1, len) < 0) + return; if (ii.capacity () != rhs_nr * rhs_nc) { error ("A(matrix) = X: X and matrix must have the same\ number of elements"); - jump_to_top_level (); + return; } fortran_style_matrix_assignment (rhs, ii); } @@ -303,7 +318,8 @@ case scalar_constant: { int i = tree_to_mat_idx (tmp_i.double_value ()); - index_check (i, ""); + if (index_check (i, "") < 0) + return; do_vector_assign (rhs, i); } break; @@ -329,7 +345,8 @@ else { int imax; - index_check (ri, imax, ""); + if (index_check (ri, imax, "") < 0) + return; do_vector_assign (rhs, ri, imax); } } @@ -342,7 +359,7 @@ if (! indexed_assign_conforms (nr, nc, rhs_nr, rhs_nc)) { error ("A(:) = X: X and A must have the same dimensions"); - jump_to_top_level (); + return; } do_matrix_assignment (rhs, magic_colon, magic_colon); } @@ -363,29 +380,20 @@ if (nr == 1 && nc == 1) // No orientation to preserve { if (! ( ilen == rhs_nr || ilen == rhs_nc)) - { - error ("A(%s) = X: X and %s must have the same number of\ + error ("A(%s) = X: X and %s must have the same number of\ elements", rm, rm); - jump_to_top_level (); - } } else if (nr == 1) // Preserve current row orientation { if (! (rhs_nr == 1 && rhs_nc == ilen)) - { - error ("A(%s) = X: where A is a row vector, X must also be a\ + error ("A(%s) = X: where A is a row vector, X must also be a\ row vector with the same number of elements as %s", rm, rm); - jump_to_top_level (); - } } else if (nc == 1) // Preserve current column orientation { if (! (rhs_nc == 1 && rhs_nr == ilen)) - { - error ("A(%s) = X: where A is a column vector, X must also\ + error ("A(%s) = X: where A is a column vector, X must also\ be a column vector with the same number of elements as %s", rm, rm); - jump_to_top_level (); - } } else panic_impossible (); @@ -400,7 +408,7 @@ if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) { error ("for A(int) = X: X must be a scalar"); - jump_to_top_level (); + return; } maybe_resize (i); @@ -530,7 +538,7 @@ else if (nr*nc != rhs_size) { error ("A(:) = X: X and A must have the same number of elements"); - jump_to_top_level (); + return; } if (rhs.const_type () == matrix_constant) @@ -588,10 +596,7 @@ } } else - { - error ("number of rows and columns must match for indexed assignment"); - jump_to_top_level (); - } + error ("number of rows and columns must match for indexed assignment"); } void @@ -603,16 +608,14 @@ tree_constant_rep::constant_type itype = tmp_i.const_type (); -// index_check() and matrix_to_index_vector() jump to the top level on -// errors. - switch (itype) { case complex_scalar_constant: case scalar_constant: { int i = tree_to_mat_idx (tmp_i.double_value ()); - index_check (i, "row"); + if (index_check (i, "row") < 0) + return; do_matrix_assignment (rhs, i, j_arg); } break; @@ -637,7 +640,8 @@ else { int imax; - index_check (ri, imax, "row"); + if (index_check (ri, imax, "row") < 0) + return; do_matrix_assignment (rhs, ri, imax, j_arg); } } @@ -662,20 +666,18 @@ int rhs_nr = rhs.rows (); int rhs_nc = rhs.columns (); -// index_check() and matrix_to_index_vector() jump to the top level on -// errors. - switch (jtype) { case complex_scalar_constant: case scalar_constant: { int j = tree_to_mat_idx (tmp_j.double_value ()); - index_check (j, "column"); + if (index_check (j, "column") < 0) + return; if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) { error ("A(int,int) = X, X must be a scalar"); - jump_to_top_level (); + return; } maybe_resize (i, j); do_matrix_assignment (rhs, i, j); @@ -691,7 +693,7 @@ { error ("A(int,matrix) = X: X must be a row vector with the\ same number of elements as matrix"); - jump_to_top_level (); + return; } maybe_resize (i, jv.max ()); do_matrix_assignment (rhs, i, jv); @@ -707,7 +709,7 @@ { error ("A(int,range) = X: X must be a row vector with the\ same number of elements as range"); - jump_to_top_level (); + return; } if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) { @@ -716,7 +718,8 @@ else { int jmax; - index_check (rj, jmax, "column"); + if (index_check (rj, jmax, "column") < 0) + return; maybe_resize (i, jmax); do_matrix_assignment (rhs, i, rj); } @@ -745,7 +748,7 @@ { error ("A(int,:) = X: X must be a row vector with the\ same number of columns as A"); - jump_to_top_level (); + return; } do_matrix_assignment (rhs, i, magic_colon); @@ -768,21 +771,19 @@ int rhs_nr = rhs.rows (); int rhs_nc = rhs.columns (); -// index_check() and matrix_to_index_vector() jump to the top level on -// errors. - switch (jtype) { case complex_scalar_constant: case scalar_constant: { int j = tree_to_mat_idx (tmp_j.double_value ()); - index_check (j, "column"); + if (index_check (j, "column") < 0) + return; if (! indexed_assign_conforms (iv.capacity (), 1, rhs_nr, rhs_nc)) { error ("A(matrix,int) = X: X must be a column vector with\ the same number of elements as matrix"); - jump_to_top_level (); + return; } maybe_resize (iv.max (), j); do_matrix_assignment (rhs, iv, j); @@ -800,7 +801,7 @@ error ("A(r_matrix,c_matrix) = X: the number of rows in X\ must match the number of elements in r_matrix and the number of\ columns in X must match the number of elements in c_matrix"); - jump_to_top_level (); + return; } maybe_resize (iv.max (), jv.max ()); do_matrix_assignment (rhs, iv, jv); @@ -818,7 +819,7 @@ error ("A(matrix,range) = X: the number of rows in X must\ match the number of elements in matrix and the number of columns in X\ must match the number of elements in range"); - jump_to_top_level (); + return; } if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) { @@ -827,7 +828,8 @@ else { int jmax; - index_check (rj, jmax, "column"); + if (index_check (rj, jmax, "column") < 0) + return; maybe_resize (iv.max (), jmax); do_matrix_assignment (rhs, iv, rj); } @@ -841,7 +843,7 @@ error ("A(matrix,:) = X: the number of rows in X must\ match the number of elements in matrix, and the number of columns in\ X must match the number of columns in A"); - jump_to_top_level (); + return; } maybe_resize (iv.max (), nc-1); do_matrix_assignment (rhs, iv, magic_colon); @@ -865,22 +867,19 @@ int rhs_nr = rhs.rows (); int rhs_nc = rhs.columns (); -// index_check() and matrix_to_index_vector() jump to the top level on -// errors. - switch (jtype) { case complex_scalar_constant: case scalar_constant: { int j = tree_to_mat_idx (tmp_j.double_value ()); - index_check (j, "column"); + if (index_check (j, "column") < 0) + return; if (! indexed_assign_conforms (ri.nelem (), 1, rhs_nr, rhs_nc)) { error ("A(range,int) = X: X must be a column vector with\ the same number of elements as range"); - jump_to_top_level (); - jump_to_top_level (); + return; } maybe_resize (imax, j); do_matrix_assignment (rhs, ri, j); @@ -898,7 +897,7 @@ error ("A(range,matrix) = X: the number of rows in X must\ match the number of elements in range and the number of columns in X\ must match the number of elements in matrix"); - jump_to_top_level (); + return; } maybe_resize (imax, jv.max ()); do_matrix_assignment (rhs, ri, jv); @@ -916,7 +915,7 @@ error ("A(r_range,c_range) = X: the number of rows in X\ must match the number of elements in r_range and the number of\ columns in X must match the number of elements in c_range\n"); - jump_to_top_level (); + return; } if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) { @@ -925,7 +924,8 @@ else { int jmax; - index_check (rj, jmax, "column"); + if (index_check (rj, jmax, "column") < 0) + return; maybe_resize (imax, jmax); do_matrix_assignment (rhs, ri, rj); } @@ -939,7 +939,7 @@ error ("A(range,:) = X: the number of rows in X must match\ the number of elements in range, and the number of columns in X must\ match the number of columns in A"); - jump_to_top_level (); + return; } maybe_resize (imax, nc-1); do_matrix_assignment (rhs, ri, magic_colon); @@ -963,16 +963,14 @@ int rhs_nr = rhs.rows (); int rhs_nc = rhs.columns (); -// index_check() and matrix_to_index_vector() jump to the top level on -// errors. - switch (jtype) { case complex_scalar_constant: case scalar_constant: { int j = tree_to_mat_idx (tmp_j.double_value ()); - index_check (j, "column"); + if (index_check (j, "column") < 0) + return; int nr = rows (); if (nr == 0 && columns () == 0 && rhs_nc == 1) { @@ -994,7 +992,7 @@ { error ("A(:,int) = X: X must be a column vector with the\ same number of rows as A"); - jump_to_top_level (); + return; } do_matrix_assignment (rhs, magic_colon, j); @@ -1012,7 +1010,7 @@ error ("A(:,matrix) = X: the number of rows in X must\ match the number of rows in A, and the number of columns in X must\ match the number of elements in matrix"); - jump_to_top_level (); + return; } maybe_resize (nr-1, jv.max ()); do_matrix_assignment (rhs, magic_colon, jv); @@ -1030,7 +1028,7 @@ error ("A(:,range) = X: the number of rows in X must match\ the number of rows in A, and the number of columns in X must match\ the number of elements in range"); - jump_to_top_level (); + return; } if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) { @@ -1039,7 +1037,8 @@ else { int jmax; - index_check (rj, jmax, "column"); + if (index_check (rj, jmax, "column") < 0) + return; maybe_resize (nr-1, jmax); do_matrix_assignment (rhs, magic_colon, rj); }