Mercurial > octave
annotate libinterp/parse-tree/pt-idx.h @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | 2219b0ed8754 |
children | 3c2dee80b542 |
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 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28805
diff
changeset
|
3 // Copyright (C) 1996-2021 The Octave Project Developers |
27923
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 //////////////////////////////////////////////////////////////////////// |
2980 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 #if ! defined (octave_pt_idx_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_pt_idx_h 1 |
2980 | 28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
30 |
4219 | 31 #include <list> |
32 | |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
33 class octave_map; |
2980 | 34 class octave_value; |
35 class octave_value_list; | |
36 | |
37 #include "str-vec.h" | |
38 | |
39 #include "pt-exp.h" | |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
40 #include "pt-walk.h" |
2980 | 41 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
42 namespace octave |
2980 | 43 { |
24355
cc3b3ceb155c
update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
44 class octave_lvalue; |
24362
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24355
diff
changeset
|
45 class symbol_scope; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
46 class tree_argument_list; |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
47 class tree_evaluator; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
48 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
49 // Index expressions. |
2980 | 50 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
51 class tree_index_expression : public tree_expression |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
52 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
53 public: |
3930 | 54 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
55 tree_index_expression (tree_expression *e = nullptr, |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
56 tree_argument_list *lst = nullptr, |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
57 int l = -1, int c = -1, char t = '('); |
4131 | 58 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
59 tree_index_expression (tree_expression *e, const std::string& n, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
60 int l = -1, int c = -1); |
2980 | 61 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
62 tree_index_expression (tree_expression *e, tree_expression *df, |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
63 int l = -1, int c = -1); |
4267 | 64 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
65 // No copying! |
3930 | 66 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
67 tree_index_expression (const tree_index_expression&) = delete; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
68 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
69 tree_index_expression& operator = (const tree_index_expression&) = delete; |
3933 | 70 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
71 ~tree_index_expression (void); |
4131 | 72 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
73 void append (tree_argument_list *lst = nullptr, char t = '('); |
2991 | 74 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
75 void append (const std::string& n); |
3930 | 76 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
77 void append (tree_expression *df); |
2980 | 78 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
79 bool is_index_expression (void) const { return true; } |
3930 | 80 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
81 std::string name (void) const; |
2980 | 82 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
83 tree_expression * expression (void) { return m_expr; } |
2980 | 84 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
85 std::list<tree_argument_list *> arg_lists (void) { return m_args; } |
3010 | 86 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
87 std::string type_tags (void) { return m_type; } |
2980 | 88 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
89 std::list<string_vector> arg_names (void) { return m_arg_nm; } |
2980 | 90 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
91 std::list<tree_expression *> dyn_fields (void) { return m_dyn_field; } |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
92 |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
93 void mark_word_list_cmd (void) { m_word_list_cmd = true; } |
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
94 |
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
95 bool is_word_list_cmd (void) const { return m_word_list_cmd; } |
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
96 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
97 bool lvalue_ok (void) const { return m_expr->lvalue_ok (); } |
2980 | 98 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
99 bool rvalue_ok (void) const { return true; } |
2980 | 100 |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
101 octave_lvalue lvalue (tree_evaluator& tw); |
5861 | 102 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
103 tree_index_expression * dup (symbol_scope& scope) const; |
2980 | 104 |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
105 octave_value evaluate (tree_evaluator& tw, int nargout = 1) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
106 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
107 octave_value_list retval = evaluate_n (tw, nargout); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
108 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
109 return retval.length () > 0 ? retval(0) : octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
110 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
111 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
112 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
113 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
114 void accept (tree_walker& tw) |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
115 { |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
116 tw.visit_index_expression (*this); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
117 } |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
118 |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
119 std::string |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
120 get_struct_index |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
121 (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm, |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
122 std::list<tree_expression *>::const_iterator p_dyn_field) const; |
2980 | 123 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
124 private: |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
125 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
126 // The LHS of this index expression. |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
127 tree_expression *m_expr; |
2980 | 128 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
129 // The indices (only valid if type == paren || type == brace). |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
130 std::list<tree_argument_list *> m_args; |
2980 | 131 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
132 // The type of this index expression. |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
133 std::string m_type; |
3929 | 134 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
135 // The names of the arguments. Used for constant struct element |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
136 // references. |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
137 std::list<string_vector> m_arg_nm; |
3933 | 138 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
139 // The list of dynamic field names, if any. |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
140 std::list<tree_expression *> m_dyn_field; |
4131 | 141 |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
142 // TRUE if this expression was parsed as a word list command. |
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
143 bool m_word_list_cmd; |
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
144 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
145 tree_index_expression (int l, int c); |
5861 | 146 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
147 octave_map make_arg_struct (void) const; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
148 }; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
149 } |
2988 | 150 |
2980 | 151 #endif |