annotate libinterp/parse-tree/oct-lvalue.h @ 28193:56c209ff0a08 stable

improve handling of ans assignment with wrapper functions * oct-lvalue.h, oct-lvalue.cc (octave_lvalue::index_is_colon): New function. * pt-assign.cc (tree_multi_assignment::evaluate_n): Also handle result value when LHS is [varargout{:}] and varargout is defined but empty. * args.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Apr 2020 14:56:27 -0400
parents bd51beb6205e
children 9a3deb17b4ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20248
diff changeset
26 #if ! defined (octave_oct_lvalue_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17787
diff changeset
27 #define octave_oct_lvalue_h 1
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
30
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
31 #include <string>
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
32
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20791
diff changeset
33 #include "ovl.h"
27000
711f23332204 eliminate some unnecessary include statements
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
34 #include "stack-frame.h"
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
35 #include "symrec.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
36
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
37 namespace octave
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
38 {
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
39 class octave_lvalue
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
40 {
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
41 public:
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
42
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
43 octave_lvalue (const symbol_record& sr, stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
44 : m_sym (sr), m_frame (frame), m_black_hole (false),
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24355
diff changeset
45 m_type (), m_idx (), m_nel (1)
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
46 { }
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
47
24991
831389905438 omit argument name from default copy ctors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
48 octave_lvalue (const octave_lvalue&) = default;
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
49
27024
0dd80c6d2e3c explicitly delete octave_lvalue copy assignment operator
John W. Eaton <jwe@octave.org>
parents: 27000
diff changeset
50 octave_lvalue& operator = (const octave_lvalue&) = delete;
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
51
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
52 ~octave_lvalue (void) = default;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
53
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
54 bool is_black_hole (void) const { return m_black_hole; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
55
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
56 void mark_black_hole (void) { m_black_hole = true; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
57
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
58 bool is_defined (void) const;
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
59
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
60 bool is_undefined (void) const;
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
61
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
62 bool isstruct (void) const { return value().isstruct (); }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
63
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
64 void define (const octave_value& v);
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
65
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
66 void assign (octave_value::assign_op, const octave_value&);
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
67
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
68 void numel (octave_idx_type n) { m_nel = n; }
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
69
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
70 octave_idx_type numel (void) const { return m_nel; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
71
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
72 void set_index (const std::string& t, const std::list<octave_value_list>& i);
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
73
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
74 void clear_index (void) { m_type = ""; m_idx.clear (); }
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
75
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
76 std::string index_type (void) const { return m_type; }
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
77
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
78 bool index_is_empty (void) const;
2984
84c33881d0bc [project @ 1997-05-16 05:14:33 by jwe]
jwe
parents: 2979
diff changeset
79
28193
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
80 bool index_is_colon (void) const;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
81
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
82 void do_unary_op (octave_value::unary_op op);
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
83
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
84 octave_value value (void) const;
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
85
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
86 private:
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
87
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
88 symbol_record m_sym;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
89
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
90 stack_frame& m_frame;
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24355
diff changeset
91
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
92 bool m_black_hole;
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
93
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
94 std::string m_type;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
95
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
96 std::list<octave_value_list> m_idx;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
97
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
98 octave_idx_type m_nel;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
99 };
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
100 }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
101
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
102 #endif