GNU Octave  8.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-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 (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 
55 {
56  octave_value val;
57 
58  if (! m_base || ! m_limit)
59  return val;
60 
61  octave_value ov_base;
62  octave_value ov_increment;
63  octave_value ov_limit;
64 
65  if (m_increment)
66  {
67  ov_base = m_base->evaluate (tw);
68  ov_increment = m_increment->evaluate (tw);
69  ov_limit = m_limit->evaluate (tw);
70  }
71  else
72  {
73  ov_base = m_base->evaluate (tw);
74  ov_limit = m_limit->evaluate (tw);
75  }
76 
77  return colon_op (ov_base, ov_increment, ov_limit, is_for_cmd_expr ());
78 }
79 
OCTAVE_END_NAMESPACE(octave)
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:54
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_expression * m_base
Definition: pt-colon.h:109
tree_expression * m_limit
Definition: pt-colon.h:110
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
tree_expression * m_increment
Definition: pt-colon.h:111
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(void) const
Definition: pt-exp.h:112
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:132
virtual int column(void) const
Definition: pt.h:62
virtual int line(void) const
Definition: pt.h:60
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API octave_value colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr=false)