GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-idx.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 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
42namespace octave
43{
44 class octave_lvalue;
45 class symbol_scope;
46 class tree_argument_list;
47 class tree_evaluator;
48
49 // Index expressions.
50
52 {
53 public:
54
56 tree_argument_list *lst = nullptr,
57 int l = -1, int c = -1, char t = '(');
58
59 tree_index_expression (tree_expression *e, const std::string& n,
60 int l = -1, int c = -1);
61
63 int l = -1, int c = -1);
64
65 // No copying!
66
68
70
72
74 append (tree_argument_list *lst = nullptr, char t = '(');
75
76 tree_index_expression * append (const std::string& n);
77
79
80 bool is_index_expression (void) const { return true; }
81
82 std::string name (void) const;
83
84 tree_expression * expression (void) { return m_expr; }
85
86 std::list<tree_argument_list *> arg_lists (void) { return m_args; }
87
88 std::string type_tags (void) { return m_type; }
89
90 std::list<string_vector> arg_names (void) { return m_arg_nm; }
91
92 std::list<tree_expression *> dyn_fields (void) { return m_dyn_field; }
93
94 void mark_word_list_cmd (void) { m_word_list_cmd = true; }
95
96 bool is_word_list_cmd (void) const { return m_word_list_cmd; }
97
98 bool lvalue_ok (void) const { return m_expr->lvalue_ok (); }
99
100 bool rvalue_ok (void) 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
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
125 private:
126
127 // The LHS of this index expression.
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 // The names of the arguments. Used for constant struct element
137 // references.
138 std::list<string_vector> m_arg_nm;
139
140 // The list of dynamic field names, if any.
141 std::list<tree_expression *> m_dyn_field;
142
143 // TRUE if this expression was parsed as a word list command.
145
146 tree_index_expression (int l, int c);
147
149 };
150}
151
152#endif
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:86
bool is_word_list_cmd(void) const
Definition: pt-idx.h:96
tree_index_expression * dup(symbol_scope &scope) const
Definition: pt-idx.cc:243
std::list< tree_expression * > dyn_fields(void)
Definition: pt-idx.h:92
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:146
tree_index_expression(const tree_index_expression &)=delete
std::list< tree_argument_list * > arg_lists(void)
Definition: pt-idx.h:86
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.h:106
std::string type_tags(void)
Definition: pt-idx.h:88
void accept(tree_walker &tw)
Definition: pt-idx.h:115
tree_index_expression(tree_expression *e=nullptr, tree_argument_list *lst=nullptr, int l=-1, int c=-1, char t='(')
Definition: pt-idx.cc:53
bool rvalue_ok(void) const
Definition: pt-idx.h:100
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-idx.cc:170
bool is_index_expression(void) const
Definition: pt-idx.h:80
tree_index_expression * append(tree_argument_list *lst=nullptr, char t='(')
Definition: pt-idx.cc:81
std::list< tree_expression * > m_dyn_field
Definition: pt-idx.h:141
tree_expression * m_expr
Definition: pt-idx.h:128
std::list< string_vector > arg_names(void)
Definition: pt-idx.h:90
tree_index_expression & operator=(const tree_index_expression &)=delete
tree_expression * expression(void)
Definition: pt-idx.h:84
std::string name(void) const
Definition: pt-idx.cc:139
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.cc:345
void mark_word_list_cmd(void)
Definition: pt-idx.h:94
octave_map make_arg_struct(void) const
std::list< tree_argument_list * > m_args
Definition: pt-idx.h:131
std::list< string_vector > m_arg_nm
Definition: pt-idx.h:138
bool lvalue_ok(void) const
Definition: pt-idx.h:98
virtual void visit_index_expression(tree_index_expression &)
Definition: pt-walk.cc:371
octave_idx_type length(void) const
Definition: ovl.h:113
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))