Mercurial > octave
annotate libinterp/parse-tree/oct-lvalue.h @ 28804:3719f5d452d4 stable
refactor implementation of END indexing in interpreter (bug #58953)
* oct-lvalue.h, oct-lvalue.cc (octave_lvalue::eval_for_numel): New function.
(octave_lvalue::m_nel): Delete data member.
(octave_lvalue::numel (octave_idx_type)): Delete.
(octave_lvalue::numel (void) const): Compute result instead of
returning cached value.
* pt-eval.h, pt-eval.cc (tree_evaluator::convert_to_const_vector):
Simplify.
(Fend): Call tree_evaluator::evaluate_end_expression to do the real work.
(tree_evaluator::make_value_list): Don't check for magic_end here.
(end_value, tree_evaluator::evaluate_end_expression): New functions.
(tree_evaluator::m_index_list, tree_evaluator::m_index_type): New data members.
(tree_evaluator::set_indexed_object, tree_evaluator::index_list,
tree_evaluator::set_index_list, tree_evaluator::clear_index_list,
tree_evaluator::append_index_list, tree_evaluator::index_type):
New functions.
* pt-idx.cc (make_value_list): Delete.
(tree_index_expression::lvalue, tree_index_expression::evaluate_n):
Refactor to avoid evaluating partial expressions to obtain values for
the END function. Instead, cache info necessary to do that job as
needed and inside the END function itself.
author | John W. Eaton <jwe@octave.org> and Fernando Alvarruiz |
---|---|
date | Mon, 21 Sep 2020 10:45:18 -0400 |
parents | 9a3deb17b4ea |
children | d5efdf5cfc56 0a5b15007766 |
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 |
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 | 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 | 31 #include <string> |
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 | 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 | 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 |
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
|
43 octave_lvalue (const symbol_record& sr, |
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
|
44 const std::shared_ptr<stack_frame>& frame) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
45 : m_sym (sr), m_frame (frame), m_black_hole (false), |
28804
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
46 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
|
47 { } |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
48 |
24991
831389905438
omit argument name from default copy ctors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
49 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
|
50 |
27024
0dd80c6d2e3c
explicitly delete octave_lvalue copy assignment operator
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
51 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
|
52 |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
53 ~octave_lvalue (void) = default; |
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 bool is_black_hole (void) const { return m_black_hole; } |
2979 | 56 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
57 void mark_black_hole (void) { m_black_hole = true; } |
2979 | 58 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
59 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
|
60 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
61 bool is_undefined (void) const; |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
62 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
63 bool isstruct (void) const { return value().isstruct (); } |
2979 | 64 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
65 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
|
66 |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
67 void assign (octave_value::assign_op, const octave_value&); |
2979 | 68 |
28804
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
69 octave_idx_type numel (void) const; |
2979 | 70 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
71 void set_index (const std::string& t, const std::list<octave_value_list>& i); |
2979 | 72 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
73 void clear_index (void) { m_type = ""; m_idx.clear (); } |
5846 | 74 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
75 std::string index_type (void) const { return m_type; } |
5846 | 76 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
77 bool index_is_empty (void) const; |
2984 | 78 |
28193
56c209ff0a08
improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
79 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
|
80 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
81 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
|
82 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
83 octave_value value (void) const; |
20248
011a364b4d78
improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
84 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
85 private: |
2979 | 86 |
28804
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
87 octave_value |
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
88 eval_for_numel (const std::string& type, |
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
89 const std::list<octave_value_list>& idx) const; |
3719f5d452d4
refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents:
28426
diff
changeset
|
90 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
91 symbol_record m_sym; |
2979 | 92 |
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
|
93 std::shared_ptr<stack_frame> m_frame; |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24355
diff
changeset
|
94 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
95 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
|
96 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
97 std::string m_type; |
2979 | 98 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
99 std::list<octave_value_list> m_idx; |
2979 | 100 |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
101 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
|
102 }; |
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24350
diff
changeset
|
103 } |
2979 | 104 |
105 #endif |