GNU Octave 7.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-2022 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
35namespace octave
36{
37 // Colon expressions.
38
39 tree_expression *
41 {
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) : nullptr,
46 line (), column ());
47
48 new_ce->copy_base (*this);
49
50 return new_ce;
51 }
52
54 {
55 octave_value val;
56
57 if (! m_base || ! m_limit)
58 return val;
59
60 octave_value ov_base;
61 octave_value ov_increment;
62 octave_value ov_limit;
63
64 if (m_increment)
65 {
66 ov_base = m_base->evaluate (tw);
67 ov_increment = m_increment->evaluate (tw);
68 ov_limit = m_limit->evaluate (tw);
69 }
70 else
71 {
72 ov_base = m_base->evaluate (tw);
73 ov_limit = m_limit->evaluate (tw);
74 }
75
76 return colon_op (ov_base, ov_increment, ov_limit, is_for_cmd_expr ());
77 }
78}
tree_expression * m_limit
Definition: pt-colon.h:110
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:49
tree_expression * m_increment
Definition: pt-colon.h:111
tree_expression * m_base
Definition: pt-colon.h:109
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-colon.cc:53
tree_expression * dup(symbol_scope &scope) const
Definition: pt-colon.cc:40
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:133
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:113
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual int column(void) const
Definition: pt.h:62
virtual int line(void) const
Definition: pt.h:60
OCTINTERP_API octave_value colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr=false)