GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-colon.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_colon_h)
27 #define octave_pt_colon_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 class octave_value;
34 class octave_value_list;
35 
36 #include "pt-exp.h"
37 #include "pt-walk.h"
38 
40 
41 class symbol_scope;
42 
43 // Colon expressions.
44 
46 {
47 public:
48 
49  tree_colon_expression (int l = -1, int c = -1)
50  : tree_expression (l, c), m_base (nullptr), m_limit (nullptr),
51  m_increment (nullptr), m_save_base (false) { }
52 
54  int l = -1, int c = -1)
55  : tree_expression (l, c), m_base (bas), m_limit (lim),
56  m_increment (nullptr), m_save_base (false) { }
57 
59  tree_expression *inc, int l = -1, int c = -1)
60  : tree_expression (l, c), m_base (bas), m_limit (lim),
61  m_increment (inc), m_save_base (false) { }
62 
63  OCTAVE_DISABLE_COPY_MOVE (tree_colon_expression)
64 
66  {
67  if (! m_save_base)
68  delete m_base;
69 
70  delete m_limit;
71  delete m_increment;
72  }
73 
74  void preserve_base () { m_save_base = true; }
75 
76  bool rvalue_ok () const { return true; }
77 
78  void eval_error (const std::string& s) const;
79 
80  tree_expression * base () { return m_base; }
81 
82  tree_expression * limit () { return m_limit; }
83 
84  tree_expression * increment () { return m_increment; }
85 
86  tree_expression * dup (symbol_scope& scope) const;
87 
88  bool is_colon_expression () const { return true; }
89 
90  octave_value evaluate (tree_evaluator&, int nargout = 1);
91 
93  {
94  return ovl (evaluate (tw, nargout));
95  }
96 
97  void accept (tree_walker& tw)
98  {
99  tw.visit_colon_expression (*this);
100  }
101 
102 private:
103 
104  // The components of the expression.
105  tree_expression *m_base;
106  tree_expression *m_limit;
107  tree_expression *m_increment;
108 
109  bool m_save_base;
110 };
111 
112 OCTAVE_END_NAMESPACE(octave)
113 
114 #endif
bool rvalue_ok() const
Definition: pt-colon.h:76
bool is_colon_expression() const
Definition: pt-colon.h:88
void eval_error(const std::string &s) const
tree_colon_expression(tree_expression *bas, tree_expression *lim, int l=-1, int c=-1)
Definition: pt-colon.h:53
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:55
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-colon.h:92
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_colon_expression(tree_expression *bas, tree_expression *lim, tree_expression *inc, int l=-1, int c=-1)
Definition: pt-colon.h:58
tree_expression * limit()
Definition: pt-colon.h:82
tree_expression * base()
Definition: pt-colon.h:80
tree_expression * increment()
Definition: pt-colon.h:84
void accept(tree_walker &tw)
Definition: pt-colon.h:97
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
virtual void visit_colon_expression(tree_colon_expression &)
Definition: pt-walk.cc:174
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219