GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-idx.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pt_idx_h)
27#define octave_pt_idx_h 1
28
29#include "octave-config.h"
30
31#include <list>
32
33class octave_map;
34class octave_value;
36
37#include "str-vec.h"
38
39#include "pt-exp.h"
40#include "pt-walk.h"
41
43
44class octave_lvalue;
45class symbol_scope;
47class tree_evaluator;
48
49// Index expressions.
50
51class OCTINTERP_API tree_index_expression : public tree_expression
52{
53public:
54
55 tree_index_expression (tree_expression *e, const token& open_delim, tree_argument_list *lst, const token& close_delim, char t);
56
57 tree_index_expression (tree_expression *e, const token& dot_tok, const token& struct_elt_tok);
58
59 tree_index_expression (tree_expression *e, const token& dot_tok, const token& open_paren, tree_expression *df, const token& close_paren);
60
61 OCTAVE_DISABLE_COPY_MOVE (tree_index_expression)
62
64
66 append (const token& open_delim, tree_argument_list *lst, const token& close_delim, char t = '(');
67
68 tree_index_expression * append (const token& dot_tok, const token& struct_elt_tok);
69
70 tree_index_expression * append (const token& dot_tok, const token& open_paren, tree_expression *df, const token& close_paren);
71
72 bool is_index_expression () const { return true; }
73
74 std::string name () const;
75
76 filepos beg_pos () const { return m_expr->beg_pos (); }
77 filepos end_pos () const;
78
79 comment_list leading_comments () const { return m_expr->leading_comments (); }
81
82 tree_expression * expression () { return m_expr; }
83
84 std::list<tree_argument_list *> arg_lists () { return m_args; }
85
86 std::string type_tags () { return m_type; }
87
88 std::list<token> dot_tokens () const { return m_dot_tok; }
89
90 std::list<string_vector> arg_names () { return m_arg_nm; }
91
92 std::list<tree_expression *> dyn_fields () { return m_dyn_field; }
93
94 void mark_word_list_cmd () { m_word_list_cmd = true; }
95
96 bool is_word_list_cmd () const { return m_word_list_cmd; }
97
98 bool lvalue_ok () const { return m_expr->lvalue_ok (); }
99
100 bool rvalue_ok () const { return true; }
101
103
104 tree_index_expression * dup (symbol_scope& scope) const;
105
106 octave_value evaluate (tree_evaluator& tw, int nargout = 1)
107 {
108 octave_value_list retval = evaluate_n (tw, nargout);
109
110 return retval.length () > 0 ? retval(0) : octave_value ();
111 }
112
113 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
114
116 {
117 tw.visit_index_expression (*this);
118 }
119
120 std::string
121 get_struct_index
122 (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm,
123 std::list<tree_expression *>::const_iterator p_dyn_field) const;
124
125private:
126
127 tree_index_expression () = default;
128
129 octave_map make_arg_struct () const;
130
131 //--------
132
133 // The LHS of this index expression.
134 tree_expression *m_expr {nullptr};
135
136 // FIXME: maybe all the things in the list should be in a struct or
137 // class so we can more easily ensure that they remain synchronized.
138
139 // The indices (only valid if type == paren || type == brace).
140 std::list<tree_argument_list *> m_args;
141
142 // The type of this index expression.
143 std::string m_type;
144
145 // Record dot tokens for position and possible comment info.
146 std::list<token> m_dot_tok;
147
148 // The names of the arguments. Used for constant struct element
149 // references.
150 std::list<string_vector> m_arg_nm;
151
152 // The list of dynamic field names, if any.
153 std::list<tree_expression *> m_dyn_field;
154
155 // TRUE if this expression was parsed as a word list command.
156 bool m_word_list_cmd {false};
157};
158
159OCTAVE_END_NAMESPACE(octave)
160
161#endif
octave_idx_type length() const
Definition ovl.h:111
Definition token.h:42
virtual std::string name() const
Definition pt-exp.h:114
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual octave_lvalue lvalue(tree_evaluator &)
Definition pt-exp.cc:43
virtual octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)=0
tree_expression * expression()
Definition pt-idx.h:82
void mark_word_list_cmd()
Definition pt-idx.h:94
bool rvalue_ok() const
Definition pt-idx.h:100
std::string type_tags()
Definition pt-idx.h:86
std::list< tree_expression * > dyn_fields()
Definition pt-idx.h:92
void accept(tree_walker &tw)
Definition pt-idx.h:115
std::list< tree_argument_list * > arg_lists()
Definition pt-idx.h:84
bool lvalue_ok() const
Definition pt-idx.h:98
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-idx.h:106
std::list< string_vector > arg_names()
Definition pt-idx.h:90
bool is_word_list_cmd() const
Definition pt-idx.h:96
filepos beg_pos() const
Definition pt-idx.h:76
comment_list leading_comments() const
Definition pt-idx.h:79
bool is_index_expression() const
Definition pt-idx.h:72
std::list< token > dot_tokens() const
Definition pt-idx.h:88
virtual void visit_index_expression(tree_index_expression &)
Definition pt-walk.cc:401
virtual filepos end_pos() const =0
virtual comment_list trailing_comments() const =0
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn