Mercurial > octave
annotate libinterp/corefcn/oct-lvalue.cc @ 20962:3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
* cellfun.cc, data.cc, debug.cc, dirfns.cc, dynamic-ld.cc, file-io.cc,
gl2ps-renderer.cc, graphics.cc, graphics.in.h, hex2num.cc, load-save.cc,
ls-mat-ascii.cc, ls-oct-text.cc, oct-hist.cc, oct-lvalue.cc, oct-map.cc,
toplev.cc, __init_fltk__.cc, ov-base-int.cc, ov-bool-mat.cc, ov-cell.cc,
ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc,
ov-usr-fcn.cc, ov.cc, pt-arg-list.cc, pt-assign.cc, pt-colon.cc, pt-eval.cc,
pt-exp.cc:
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 22 Dec 2015 10:29:22 -0800 |
parents | 48b2ad5ee801 |
children | fcac5dbbf9ed |
rev | line source |
---|---|
2979 | 1 /* |
2 | |
19697
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" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20248
diff
changeset
|
28 #include "ovl.h" |
2979 | 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 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
48 if (! idx.empty ()) |
3357 | 49 error ("invalid index expression in assignment"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
50 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
51 type = t; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
52 idx = i; |
3357 | 53 } |
54 | |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
55 bool |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
56 octave_lvalue::index_is_empty (void) const |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
57 { |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
58 bool retval = false; |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
59 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
60 if (idx.size () == 1) |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
61 { |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
62 octave_value_list tmp = idx.front (); |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
63 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
64 retval = (tmp.length () == 1 && tmp(0).is_empty ()); |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
65 } |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
66 |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
67 return retval; |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
68 } |
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
69 |
3357 | 70 void |
3203 | 71 octave_lvalue::do_unary_op (octave_value::unary_op op) |
72 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
73 if (! is_black_hole ()) |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
74 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
75 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
76 sym->do_non_const_unary_op (op); |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
77 else |
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, type, idx); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
79 } |
2979 | 80 } |
81 | |
5001 | 82 octave_value |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
83 octave_lvalue::value (void) const |
5001 | 84 { |
85 octave_value retval; | |
86 | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
87 if (! is_black_hole ()) |
5001 | 88 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
89 octave_value val = sym->varval (); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
90 |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
91 if (idx.empty ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
92 retval = val; |
5001 | 93 else |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
94 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
95 if (val.is_constant ()) |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
96 retval = val.subsref (type, idx); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
97 else |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
98 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
99 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
|
100 if (t.length () > 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 retval = t(0); |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
102 } |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
103 } |
5001 | 104 } |
105 | |
106 return retval; | |
107 } |