GNU Octave  8.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-2023 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  // No copying!
64 
66 
68 
70  {
71  if (! m_save_base)
72  delete m_base;
73 
74  delete m_limit;
75  delete m_increment;
76  }
77 
78  void preserve_base (void) { m_save_base = true; }
79 
80  bool rvalue_ok (void) const { return true; }
81 
82  void eval_error (const std::string& s) const;
83 
84  tree_expression * base (void) { return m_base; }
85 
86  tree_expression * limit (void) { return m_limit; }
87 
88  tree_expression * increment (void) { return m_increment; }
89 
90  tree_expression * dup (symbol_scope& scope) const;
91 
92  bool is_colon_expression (void) const { return true; }
93 
94  octave_value evaluate (tree_evaluator&, int nargout = 1);
95 
97  {
98  return ovl (evaluate (tw, nargout));
99  }
100 
101  void accept (tree_walker& tw)
102  {
103  tw.visit_colon_expression (*this);
104  }
105 
106 private:
107 
108  // The components of the expression.
112 
114 };
115 
117 
118 #endif
OCTAVE_END_NAMESPACE(octave)
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
tree_colon_expression & operator=(const tree_colon_expression &)=delete
bool rvalue_ok(void) const
Definition: pt-colon.h:80
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:54
tree_expression * limit(void)
Definition: pt-colon.h:86
tree_expression * increment(void)
Definition: pt-colon.h:88
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-colon.h:96
tree_colon_expression(const tree_colon_expression &)=delete
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_expression * m_base
Definition: pt-colon.h:109
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 * base(void)
Definition: pt-colon.h:84
~tree_colon_expression(void)
Definition: pt-colon.h:69
tree_expression * m_limit
Definition: pt-colon.h:110
void accept(tree_walker &tw)
Definition: pt-colon.h:101
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
bool is_colon_expression(void) const
Definition: pt-colon.h:92
void preserve_base(void)
Definition: pt-colon.h:78
tree_expression * m_increment
Definition: pt-colon.h:111
virtual void visit_colon_expression(tree_colon_expression &)
Definition: pt-walk.cc:162
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:211