GNU Octave  9.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-2024 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 
33 class octave_map;
34 class octave_value;
35 class octave_value_list;
36 
37 #include "str-vec.h"
38 
39 #include "pt-exp.h"
40 #include "pt-walk.h"
41 
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  OCTAVE_DISABLE_COPY_MOVE (tree_index_expression)
66 
68 
70  append (tree_argument_list *lst = nullptr, char t = '(');
71 
72  tree_index_expression * append (const std::string& n);
73 
75 
76  bool is_index_expression () const { return true; }
77 
78  std::string name () const;
79 
80  tree_expression * expression () { return m_expr; }
81 
82  std::list<tree_argument_list *> arg_lists () { return m_args; }
83 
84  std::string type_tags () { return m_type; }
85 
86  std::list<string_vector> arg_names () { return m_arg_nm; }
87 
88  std::list<tree_expression *> dyn_fields () { return m_dyn_field; }
89 
90  void mark_word_list_cmd () { m_word_list_cmd = true; }
91 
92  bool is_word_list_cmd () const { return m_word_list_cmd; }
93 
94  bool lvalue_ok () const { return m_expr->lvalue_ok (); }
95 
96  bool rvalue_ok () const { return true; }
97 
99 
100  tree_index_expression * dup (symbol_scope& scope) const;
101 
102  octave_value evaluate (tree_evaluator& tw, int nargout = 1)
103  {
104  octave_value_list retval = evaluate_n (tw, nargout);
105 
106  return retval.length () > 0 ? retval(0) : octave_value ();
107  }
108 
109  octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
110 
111  void accept (tree_walker& tw)
112  {
113  tw.visit_index_expression (*this);
114  }
115 
116  std::string
118  (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm,
119  std::list<tree_expression *>::const_iterator p_dyn_field) const;
120 
121 private:
122 
123  // The LHS of this index expression.
124  tree_expression *m_expr;
125 
126  // The indices (only valid if type == paren || type == brace).
127  std::list<tree_argument_list *> m_args;
128 
129  // The type of this index expression.
130  std::string m_type;
131 
132  // The names of the arguments. Used for constant struct element
133  // references.
134  std::list<string_vector> m_arg_nm;
135 
136  // The list of dynamic field names, if any.
137  std::list<tree_expression *> m_dyn_field;
138 
139  // TRUE if this expression was parsed as a word list command.
140  bool m_word_list_cmd;
141 
142  tree_index_expression (int l, int c);
143 
144  octave_map make_arg_struct () const;
145 };
146 
147 OCTAVE_END_NAMESPACE(octave)
148 
149 #endif
octave_idx_type length() const
Definition: ovl.h:113
virtual bool lvalue_ok() const
Definition: pt-exp.h:82
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.cc:345
void mark_word_list_cmd()
Definition: pt-idx.h:90
tree_expression * expression()
Definition: pt-idx.h:80
bool rvalue_ok() const
Definition: pt-idx.h:96
std::string type_tags()
Definition: pt-idx.h:84
std::list< tree_argument_list * > arg_lists()
Definition: pt-idx.h:82
void accept(tree_walker &tw)
Definition: pt-idx.h:111
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
tree_index_expression * dup(symbol_scope &scope) const
Definition: pt-idx.cc:243
bool lvalue_ok() const
Definition: pt-idx.h:94
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.h:102
std::string name() const
Definition: pt-idx.cc:139
bool is_word_list_cmd() const
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
std::list< string_vector > arg_names()
Definition: pt-idx.h:86
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-idx.cc:170
tree_index_expression * append(tree_argument_list *lst=nullptr, char t='(')
Definition: pt-idx.cc:81
std::list< tree_expression * > dyn_fields()
Definition: pt-idx.h:88
bool is_index_expression() const
Definition: pt-idx.h:76
virtual void visit_index_expression(tree_index_expression &)
Definition: pt-walk.cc:401
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_idx_type n
Definition: mx-inlines.cc:761
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))