GNU Octave 11.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-2026 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
45class OCTINTERP_API tree_colon_expression : public tree_expression
46{
47public:
48
49 tree_colon_expression (tree_expression *base, const token& colon_1_tok, tree_expression *limit)
50 : m_base (base), m_colon_1_tok (colon_1_tok), m_limit (limit)
51 { }
52
53 tree_colon_expression (tree_expression *base, const token& colon_1_tok, tree_expression *increment, const token& colon_2_tok, tree_expression *limit)
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 comment_list leading_comments () const { return m_base->leading_comments (); }
72 comment_list trailing_comments () const { return m_limit->trailing_comments (); }
73
74 void preserve_base () { m_save_base = true; }
75
76 bool rvalue_ok () const { return true; }
77
78 void eval_error (const std::string& s) const;
79
80 tree_expression * base () { return m_base; }
81
82 token first_colon_token () const { return m_colon_1_tok; }
83
84 tree_expression * limit () { return m_limit; }
85
86 token second_colon_token () const { return m_colon_2_tok; }
87
88 tree_expression * increment () { return m_increment; }
89
90 tree_expression * dup (symbol_scope& scope) const;
91
92 bool is_colon_expression () const { return true; }
93
94 octave_value evaluate (tree_evaluator&, int nargout = 1);
95
97 {
98 return ovl (evaluate (tw, nargout));
99 }
100
102 {
103 tw.visit_colon_expression (*this);
104 }
105
106private:
107
108 // The components of the expression.
109 tree_expression *m_base;
110
111 token m_colon_1_tok;
112
113 tree_expression *m_increment {nullptr};
114
115 token m_colon_2_tok;
116
117 tree_expression *m_limit;
118
119 bool m_save_base {false};
120};
121
122OCTAVE_END_NAMESPACE(octave)
123
124#endif
Definition token.h:42
comment_list trailing_comments() const
Definition pt-colon.h:72
bool rvalue_ok() const
Definition pt-colon.h:76
bool is_colon_expression() const
Definition pt-colon.h:92
void eval_error(const std::string &s) const
comment_list leading_comments() const
Definition pt-colon.h:71
tree_expression * limit()
Definition pt-colon.h:84
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:80
token second_colon_token() const
Definition pt-colon.h:86
filepos beg_pos() const
Definition pt-colon.h:68
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-colon.h:96
tree_expression * increment()
Definition pt-colon.h:88
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:101
token first_colon_token() const
Definition pt-colon.h:82
filepos end_pos() const
Definition pt-colon.h:69
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual void visit_colon_expression(tree_colon_expression &)
Definition pt-walk.cc:174
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