GNU Octave  6.2.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-2021 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 
42 namespace 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 
73  void append (tree_argument_list *lst = nullptr, char t = '(');
74 
75  void append (const std::string& n);
76 
77  void append (tree_expression *df);
78 
79  bool is_index_expression (void) const { return true; }
80 
81  std::string name (void) const;
82 
83  tree_expression * expression (void) { return m_expr; }
84 
85  std::list<tree_argument_list *> arg_lists (void) { return m_args; }
86 
87  std::string type_tags (void) { return m_type; }
88 
89  std::list<string_vector> arg_names (void) { return m_arg_nm; }
90 
91  std::list<tree_expression *> dyn_fields (void) { return m_dyn_field; }
92 
93  void mark_word_list_cmd (void) { m_word_list_cmd = true; }
94 
95  bool is_word_list_cmd (void) const { return m_word_list_cmd; }
96 
97  bool lvalue_ok (void) const { return m_expr->lvalue_ok (); }
98 
99  bool rvalue_ok (void) const { return true; }
100 
102 
103  tree_index_expression * dup (symbol_scope& scope) const;
104 
105  octave_value evaluate (tree_evaluator& tw, int nargout = 1)
106  {
107  octave_value_list retval = evaluate_n (tw, nargout);
108 
109  return retval.length () > 0 ? retval(0) : octave_value ();
110  }
111 
112  octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
113 
114  void accept (tree_walker& tw)
115  {
116  tw.visit_index_expression (*this);
117  }
118 
119  std::string
121  (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm,
122  std::list<tree_expression *>::const_iterator p_dyn_field) const;
123 
124  private:
125 
126  // The LHS of this index expression.
128 
129  // The indices (only valid if type == paren || type == brace).
130  std::list<tree_argument_list *> m_args;
131 
132  // The type of this index expression.
133  std::string m_type;
134 
135  // The names of the arguments. Used for constant struct element
136  // references.
137  std::list<string_vector> m_arg_nm;
138 
139  // The list of dynamic field names, if any.
140  std::list<tree_expression *> m_dyn_field;
141 
142  // TRUE if this expression was parsed as a word list command.
144 
145  tree_index_expression (int l, int c);
146 
148  };
149 }
150 
151 #endif
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:84
bool is_word_list_cmd(void) const
Definition: pt-idx.h:95
tree_index_expression * dup(symbol_scope &scope) const
Definition: pt-idx.cc:237
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:140
tree_index_expression & operator=(const tree_index_expression &)=delete
tree_index_expression(const tree_index_expression &)=delete
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.h:105
std::list< string_vector > arg_names(void)
Definition: pt-idx.h:89
std::string type_tags(void)
Definition: pt-idx.h:87
void accept(tree_walker &tw)
Definition: pt-idx.h:114
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:99
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-idx.cc:164
bool is_index_expression(void) const
Definition: pt-idx.h:79
std::list< tree_expression * > m_dyn_field
Definition: pt-idx.h:140
tree_expression * m_expr
Definition: pt-idx.h:127
std::string name(void) const
Definition: pt-idx.cc:133
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-idx.cc:339
void mark_word_list_cmd(void)
Definition: pt-idx.h:93
octave_map make_arg_struct(void) const
std::list< tree_argument_list * > arg_lists(void)
Definition: pt-idx.h:85
std::list< tree_argument_list * > m_args
Definition: pt-idx.h:130
std::list< string_vector > m_arg_nm
Definition: pt-idx.h:137
void append(tree_argument_list *lst=nullptr, char t='(')
Definition: pt-idx.cc:81
std::list< tree_expression * > dyn_fields(void)
Definition: pt-idx.h:91
bool lvalue_ok(void) const
Definition: pt-idx.h:97
tree_expression * expression(void)
Definition: pt-idx.h:83
virtual void visit_index_expression(tree_index_expression &)
Definition: pt-walk.cc:281
octave_idx_type n
Definition: mx-inlines.cc:753
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811