Mercurial > octave-nkf
annotate libinterp/corefcn/oct-lvalue.cc @ 20614:10ec79b47808
use new string_value method to handle value extraction errors
* __voronoi__.cc, chol.cc, colamd.cc, fftw.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 18:15:56 -0400 |
parents | 011a364b4d78 |
children |
rev | line source |
---|---|
2979 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2979 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2979 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2979 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3203 | 27 #include "error.h" |
2979 | 28 #include "oct-obj.h" |
29 #include "oct-lvalue.h" | |
30 #include "ov.h" | |
31 | |
32 void | |
33 octave_lvalue::assign (octave_value::assign_op op, const octave_value& rhs) | |
34 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
35 if (! is_black_hole ()) |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
36 { |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
37 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
38 sym->assign (op, rhs); |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
39 else |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
40 sym->assign (op, type, idx, rhs); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
41 } |
3203 | 42 } |
43 | |
44 void | |
3933 | 45 octave_lvalue::set_index (const std::string& t, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10227
diff
changeset
|
46 const std::list<octave_value_list>& i) |
3357 | 47 { |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
48 if (idx.empty ()) |
3357 | 49 { |
3933 | 50 type = t; |
3357 | 51 idx = i; |
52 } | |
53 else | |
54 error ("invalid index expression in assignment"); | |
55 } | |
56 | |
20283
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
57 bool |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
58 octave_lvalue::index_is_empty (void) const |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
59 { |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
60 bool retval = false; |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
61 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
62 if (idx.size () == 1) |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
63 { |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
64 octave_value_list tmp = idx.front (); |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
65 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
66 retval = (tmp.length () == 1 && tmp(0).is_empty ()); |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
67 } |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
68 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
69 return retval; |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
70 } |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
71 |
3357 | 72 void |
3203 | 73 octave_lvalue::do_unary_op (octave_value::unary_op op) |
74 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
75 if (! is_black_hole ()) |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
76 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
77 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
78 sym->do_non_const_unary_op (op); |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
79 else |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
80 sym->do_non_const_unary_op (op, type, idx); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
81 } |
2979 | 82 } |
83 | |
5001 | 84 octave_value |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
85 octave_lvalue::value (void) const |
5001 | 86 { |
87 octave_value retval; | |
88 | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
89 if (! is_black_hole ()) |
5001 | 90 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
91 octave_value val = sym->varval (); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
92 |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
93 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
94 retval = val; |
5001 | 95 else |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
96 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
97 if (val.is_constant ()) |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
98 retval = val.subsref (type, idx); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
99 else |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
100 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
101 octave_value_list t = val.subsref (type, idx, 1); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
102 if (t.length () > 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 retval = t(0); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
104 } |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
105 } |
5001 | 106 } |
107 | |
108 return retval; | |
109 } |