GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-colon.cc
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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "interpreter.h"
31 #include "parse.h"
32 #include "pt-colon.h"
33 #include "pt-eval.h"
34 
36 
37 // Colon expressions.
38 
41 {
42  tree_colon_expression *new_ce
43  = new tree_colon_expression (m_base ? m_base->dup (scope) : nullptr,
44  m_limit ? m_limit->dup (scope) : nullptr,
45  m_increment ? m_increment->dup (scope)
46  : nullptr,
47  line (), column ());
48 
49  new_ce->copy_base (*this);
50 
51  return new_ce;
52 }
53 
56 {
57  octave_value val;
58 
59  if (! m_base || ! m_limit)
60  return val;
61 
62  octave_value ov_base;
63  octave_value ov_increment;
64  octave_value ov_limit;
65 
66  if (m_increment)
67  {
68  ov_base = m_base->evaluate (tw);
69  ov_increment = m_increment->evaluate (tw);
70  ov_limit = m_limit->evaluate (tw);
71  }
72  else
73  {
74  ov_base = m_base->evaluate (tw);
75  ov_limit = m_limit->evaluate (tw);
76  }
77 
78  return colon_op (ov_base, ov_increment, ov_limit, is_for_cmd_expr ());
79 }
80 
81 OCTAVE_END_NAMESPACE(octave)
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:55
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual tree_expression * dup(symbol_scope &scope) const =0
bool is_for_cmd_expr() const
Definition: pt-exp.h:108
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:128
virtual int column() const
Definition: pt.h:58
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr=false)