Mercurial > hg > octave-lyh
annotate libinterp/interp-core/oct-lvalue.cc @ 16660:cbb1bb7a5c3d
Added tag ss-3-7-5 for changeset 608e307b4914
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 May 2013 05:23:53 -0400 |
parents | 302157614308 |
children |
rev | line source |
---|---|
2979 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1996-2012 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 | |
57 void | |
3203 | 58 octave_lvalue::do_unary_op (octave_value::unary_op op) |
59 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
60 if (! is_black_hole ()) |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
61 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
62 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
63 sym->do_non_const_unary_op (op); |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
64 else |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
65 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
|
66 } |
2979 | 67 } |
68 | |
5001 | 69 octave_value |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
70 octave_lvalue::value (void) const |
5001 | 71 { |
72 octave_value retval; | |
73 | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
74 if (! is_black_hole ()) |
5001 | 75 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
76 octave_value val = sym->varval (); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
77 |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
78 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
79 retval = val; |
5001 | 80 else |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
81 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
82 if (val.is_constant ()) |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
83 retval = val.subsref (type, idx); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
84 else |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
85 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
86 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
|
87 if (t.length () > 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 retval = t(0); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
89 } |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
90 } |
5001 | 91 } |
92 | |
93 return retval; | |
94 } |