Mercurial > octave
annotate libinterp/parse-tree/oct-lvalue.cc @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | 56c209ff0a08 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2979 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
2979 | 28 #endif |
29 | |
3203 | 30 #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
|
31 #include "ovl.h" |
2979 | 32 #include "oct-lvalue.h" |
33 #include "ov.h" | |
34 | |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
35 namespace octave |
2979 | 36 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
37 bool octave_lvalue::is_defined (void) const |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
38 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
39 return ! is_black_hole () && m_frame.is_defined (m_sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
40 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
41 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
42 bool octave_lvalue::is_undefined (void) const |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
43 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
44 return ! is_defined (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
45 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
46 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
47 void octave_lvalue::define (const octave_value& v) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
48 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
49 m_frame.assign (m_sym, v); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
50 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
51 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
52 void octave_lvalue::assign (octave_value::assign_op op, |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
53 const octave_value& rhs) |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
54 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
55 if (! is_black_hole ()) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
56 m_frame.assign (op, m_sym, m_type, m_idx, rhs); |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
57 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
58 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
59 void octave_lvalue::set_index (const std::string& t, |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
60 const std::list<octave_value_list>& i) |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
61 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
62 if (! m_idx.empty ()) |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
63 error ("invalid index expression in assignment"); |
3357 | 64 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
65 m_type = t; |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
66 m_idx = i; |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
67 } |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
68 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
69 bool octave_lvalue::index_is_empty (void) const |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
70 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
71 bool retval = false; |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
72 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
73 if (m_idx.size () == 1) |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
74 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
75 octave_value_list tmp = m_idx.front (); |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
76 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
77 retval = (tmp.length () == 1 && tmp(0).isempty ()); |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
78 } |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
79 |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
80 return retval; |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
81 } |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
82 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
83 void octave_lvalue::do_unary_op (octave_value::unary_op op) |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
84 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
85 if (! is_black_hole ()) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
86 m_frame.do_non_const_unary_op (op, m_sym, m_type, m_idx); |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
87 } |
2979 | 88 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
89 octave_value octave_lvalue::value (void) const |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
90 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
91 return (is_black_hole () |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
92 ? octave_value () : m_frame.value (m_sym, m_type, m_idx)); |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
93 } |
5001 | 94 } |