GNU Octave 10.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-2025 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
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 comment_list leading_comments () const { return m_expr->leading_comments (); }
77
78 filepos beg_pos () const { return m_expr->beg_pos (); }
79 filepos end_pos () const;
80
81 tree_expression * expression () { return m_expr; }
82
83 std::list<tree_argument_list *> arg_lists () { return m_args; }
84
85 std::string type_tags () { return m_type; }
86
87 std::list<string_vector> arg_names () { return m_arg_nm; }
88
89 std::list<tree_expression *> dyn_fields () { return m_dyn_field; }
90
91 void mark_word_list_cmd () { m_word_list_cmd = true; }
92
93 bool is_word_list_cmd () const { return m_word_list_cmd; }
94
95 bool lvalue_ok () const { return m_expr->lvalue_ok (); }
96
97 bool rvalue_ok () const { return true; }
98
100
101 tree_index_expression * dup (symbol_scope& scope) const;
102
103 octave_value evaluate (tree_evaluator& tw, int nargout = 1)
104 {
105 octave_value_list retval = evaluate_n (tw, nargout);
106
107 return retval.length () > 0 ? retval(0) : octave_value ();
108 }
109
110 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
111
113 {
114 tw.visit_index_expression (*this);
115 }
116
117 std::string
119 (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm,
120 std::list<tree_expression *>::const_iterator p_dyn_field) const;
121
122private:
123
124 // The LHS of this index expression.
125 tree_expression *m_expr {nullptr};
126
127 // FIXME: maybe all the things in the list should be in a struct or
128 // class so we can more easily ensure that they remain synchronized.
129
130 // The indices (only valid if type == paren || type == brace).
131 std::list<tree_argument_list *> m_args;
132
133 // The type of this index expression.
134 std::string m_type;
135
136 // Record dot tokens for position and possible comment info.
137 std::list<token> m_dot_tok;
138
139 // The names of the arguments. Used for constant struct element
140 // references.
141 std::list<string_vector> m_arg_nm;
142
143 // The list of dynamic field names, if any.
144 std::list<tree_expression *> m_dyn_field;
145
146 // TRUE if this expression was parsed as a word list command.
147 bool m_word_list_cmd {false};
148
149 tree_index_expression () = default;
150
151 octave_map make_arg_struct () const;
152};
153
154OCTAVE_END_NAMESPACE(octave)
155
156#endif
octave_idx_type length() const
Definition ovl.h:111
Definition token.h:42
virtual bool lvalue_ok() const
Definition pt-exp.h:84
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-idx.cc:388
tree_expression * expression()
Definition pt-idx.h:81
void mark_word_list_cmd()
Definition pt-idx.h:91
bool rvalue_ok() const
Definition pt-idx.h:97
std::string type_tags()
Definition pt-idx.h:85
filepos end_pos() const
Definition pt-idx.cc:137
std::list< tree_expression * > dyn_fields()
Definition pt-idx.h:89
void accept(tree_walker &tw)
Definition pt-idx.h:112
std::list< tree_argument_list * > arg_lists()
Definition pt-idx.h:83
tree_index_expression * dup(symbol_scope &scope) const
Definition pt-idx.cc:287
bool lvalue_ok() const
Definition pt-idx.h:95
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-idx.h:103
std::string name() const
Definition pt-idx.cc:131
std::list< string_vector > arg_names()
Definition pt-idx.h:87
bool is_word_list_cmd() const
Definition pt-idx.h:93
std::string get_struct_index(tree_evaluator &tw, std::list< string_vector >::const_iterator p_arg_nm, std::list< tree_expression * >::const_iterator p_dyn_field) const
Definition pt-idx.cc:190
filepos beg_pos() const
Definition pt-idx.h:78
comment_list leading_comments() const
Definition pt-idx.h:76
octave_lvalue lvalue(tree_evaluator &tw)
Definition pt-idx.cc:214
tree_index_expression * append(const token &open_delim, tree_argument_list *lst, const token &close_delim, char t='(')
Definition pt-idx.cc:68
bool is_index_expression() const
Definition pt-idx.h:72
virtual void visit_index_expression(tree_index_expression &)
Definition pt-walk.cc:401
virtual filepos beg_pos() const =0
virtual comment_list leading_comments() const
Definition pt.cc:57
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn