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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
1 /*
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
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
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
4
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
6
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 option) any later version.
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
11
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
15 for more details.
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
16
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
19 <http://www.gnu.org/licenses/>.
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
20
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
21 */
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
22
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
25 #endif
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
26
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
27 #include "error.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
28 #include "oct-obj.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
29 #include "oct-lvalue.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
30 #include "ov.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
31
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
32 void
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
33 octave_lvalue::assign (octave_value::assign_op op, const octave_value& rhs)
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
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
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
42 }
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
43
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
44 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3929
diff changeset
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
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
47 {
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
48 if (idx.empty ())
3357
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
49 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3929
diff changeset
50 type = t;
3357
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
51 idx = i;
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
52 }
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
53 else
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
54 error ("invalid index expression in assignment");
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
55 }
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
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
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
72 void
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
73 octave_lvalue::do_unary_op (octave_value::unary_op op)
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
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
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
82 }
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
83
5001
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
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
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
86 {
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
87 octave_value retval;
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
88
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
89 if (! is_black_hole ())
5001
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
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
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
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
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
106 }
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
107
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
108 return retval;
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
109 }