GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-colon.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
33class octave_value;
35
36#include "pt-exp.h"
37#include "pt-walk.h"
38
40
41class symbol_scope;
42
43// Colon expressions.
44
46{
47public:
48
50 : m_base (base), m_colon_1_tok (colon_1_tok), m_limit (limit)
51 { }
52
54 : m_base (base), m_colon_1_tok (colon_1_tok), m_increment (increment), m_colon_2_tok (colon_2_tok), m_limit (limit)
55 { }
56
57 OCTAVE_DISABLE_COPY_MOVE (tree_colon_expression)
58
60 {
61 if (! m_save_base)
62 delete m_base;
63
64 delete m_limit;
65 delete m_increment;
66 }
67
68 filepos beg_pos () const { return m_base->beg_pos (); }
69 filepos end_pos () const { return m_limit->end_pos (); }
70
71 void preserve_base () { m_save_base = true; }
72
73 bool rvalue_ok () const { return true; }
74
75 void eval_error (const std::string& s) const;
76
77 tree_expression * base () { return m_base; }
78
79 tree_expression * limit () { return m_limit; }
80
81 tree_expression * increment () { return m_increment; }
82
83 tree_expression * dup (symbol_scope& scope) const;
84
85 bool is_colon_expression () const { return true; }
86
87 octave_value evaluate (tree_evaluator&, int nargout = 1);
88
90 {
91 return ovl (evaluate (tw, nargout));
92 }
93
95 {
96 tw.visit_colon_expression (*this);
97 }
98
99private:
100
101 // The components of the expression.
102 tree_expression *m_base;
103 token m_colon_1_tok;
104 tree_expression *m_increment {nullptr};
105 token m_colon_2_tok;
106 tree_expression *m_limit;
107
108 bool m_save_base {false};
109};
110
111OCTAVE_END_NAMESPACE(octave)
112
113#endif
Definition token.h:42
bool rvalue_ok() const
Definition pt-colon.h:73
bool is_colon_expression() const
Definition pt-colon.h:85
void eval_error(const std::string &s) const
tree_expression * limit()
Definition pt-colon.h:79
tree_colon_expression(tree_expression *base, const token &colon_1_tok, tree_expression *limit)
Definition pt-colon.h:49
tree_expression * base()
Definition pt-colon.h:77
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-colon.cc:55
filepos beg_pos() const
Definition pt-colon.h:68
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-colon.h:89
tree_expression * increment()
Definition pt-colon.h:81
tree_colon_expression(tree_expression *base, const token &colon_1_tok, tree_expression *increment, const token &colon_2_tok, tree_expression *limit)
Definition pt-colon.h:53
void accept(tree_walker &tw)
Definition pt-colon.h:94
tree_expression * dup(symbol_scope &scope) const
Definition pt-colon.cc:40
filepos end_pos() const
Definition pt-colon.h:69
virtual void visit_colon_expression(tree_colon_expression &)
Definition pt-walk.cc:174
virtual filepos end_pos() const =0
virtual filepos beg_pos() const =0
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:217