GNU Octave  6.2.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-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_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 
39 namespace octave
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  octave_value evaluate (tree_evaluator&, int nargout = 1);
93 
95  {
96  return ovl (evaluate (tw, nargout));
97  }
98 
99  void accept (tree_walker& tw)
100  {
101  tw.visit_colon_expression (*this);
102  }
103 
104  private:
105 
106  // The components of the expression.
110 
112  };
113 }
114 
115 #endif
tree_expression * m_limit
Definition: pt-colon.h:108
void accept(tree_walker &tw)
Definition: pt-colon.h:99
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_expression * m_increment
Definition: pt-colon.h:109
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_expression * m_base
Definition: pt-colon.h:107
tree_expression * increment(void)
Definition: pt-colon.h:88
bool rvalue_ok(void) const
Definition: pt-colon.h:80
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-colon.h:94
tree_colon_expression(const tree_colon_expression &)=delete
tree_colon_expression(tree_expression *bas, tree_expression *lim, tree_expression *inc, int l=-1, int c=-1)
Definition: pt-colon.h:58
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:53
tree_colon_expression & operator=(const tree_colon_expression &)=delete
tree_expression * limit(void)
Definition: pt-colon.h:86
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
tree_expression * base(void)
Definition: pt-colon.h:84
virtual void visit_colon_expression(tree_colon_expression &)
Definition: pt-walk.cc:80
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211