Mercurial > octave
annotate libinterp/parse-tree/oct-lvalue.cc @ 28426:9a3deb17b4ea stable
use shared_ptr for stack frames in call stack and for accesss and static links
* call-stack.h, call-stack.cc: Use std::shared_ptr<stack_frame>
instead of bare pointer for elements of call stack. Change all uses.
* stack-frame.h, stack-frame.cc (stack_frame::static_link,
stack_frame::access_link): Use std::shared_ptr<stack_frame>
instead of bare pointer. Change all uses.
(stack_frame::workspace): New function.
* ov-fcn-handle.h, ov-fcn-handle.cc
(octave_fcn_handle::m_closure_frames): Now a
std::shared_ptr<stack_frame> object instead of a list of copied stack
frames. Change all uses.
(octave_fcn_handle::push_closure_context): Simply store
std::shared_ptr to current stack frame.
(octave_fcn_handle::workspace): Call stack_frame::workspace to get
workspace info when we have closure frames.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 25 Apr 2020 13:17:11 -0400 |
parents | 56c209ff0a08 |
children | 70cdf8de553d 3719f5d452d4 |
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 { |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28193
diff
changeset
|
39 return ! is_black_hole () && m_frame->is_defined (m_sym); |
26661
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 { |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28193
diff
changeset
|
49 m_frame->assign (m_sym, v); |
26661
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 ()) |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28193
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 |
28193
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
83 bool octave_lvalue::index_is_colon (void) const |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
84 { |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
85 bool retval = false; |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
86 |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
87 if (m_idx.size () == 1) |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
88 { |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
89 octave_value_list tmp = m_idx.front (); |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
90 |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
91 retval = (tmp.length () == 1 && tmp(0).is_magic_colon ()); |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
92 } |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
93 |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
94 return retval; |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
95 } |
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
96 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
97 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
|
98 { |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
99 if (! is_black_hole ()) |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28193
diff
changeset
|
100 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
|
101 } |
2979 | 102 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
103 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
|
104 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
105 return (is_black_hole () |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28193
diff
changeset
|
106 ? 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
|
107 } |
5001 | 108 } |