GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-cmd.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1994-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_cmd_h)
27#define octave_pt_cmd_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "comment-list.h"
34#include "ov-fcn.h"
35#include "pt.h"
36#include "pt-bp.h"
37#include "pt-walk.h"
38#include "panic.h"
39#include "token.h"
40
42
43// A base class for commands.
44
45class tree_command : public tree
46{
47public:
48
49 tree_command () = default;
50
51 OCTAVE_DISABLE_COPY_MOVE (tree_command)
52
53 virtual ~tree_command () = default;
54
55 virtual void update_end_pos (const filepos&)
56 {
57 error ("unexpected call to tree_command::update_end_pos - please report this bug");
58 }
59};
60
61// No-op.
62
64{
65public:
66
67 tree_no_op_command (const std::string& cmd, bool eof, const token& tok)
68 : m_eof (eof), m_tok (tok), m_orig_cmd (cmd)
69 { }
70
71 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_no_op_command)
72
73 ~tree_no_op_command () = default;
74
75 filepos beg_pos () const { return m_tok.beg_pos (); }
76 filepos end_pos () const { return m_tok.end_pos (); }
77
78 void update_end_pos (const filepos& pos)
79 {
81 m_tok.end_pos (pos);
82 else
83 error ("unexpected call to tree_no_op_command::update_end_pos - please report this bug");
84 }
85
86 comment_list leading_comments () const { return m_tok.leading_comments (); }
87
89 {
90 m_tok.trailing_comments (lst);
91 }
92
94 {
95 return m_tok.trailing_comments ();
96 }
97
99 {
100 tw.visit_no_op_command (*this);
101 }
102
104 {
105 return (m_orig_cmd == "endfunction" || m_orig_cmd == "endscript");
106 }
107
108 bool is_end_of_file () const { return m_eof; }
109
110 std::string original_command () { return m_orig_cmd; }
111
112private:
113
114 bool m_eof;
115
116 // If defined, may be END token or EOF.
117 token m_tok;
118
119 std::string m_orig_cmd;
120};
121
122// Function definition.
123
125{
126public:
127
129
130 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_function_def)
131
132 ~tree_function_def () = default;
133
135 {
136 octave_function *f = m_fcn.function_value ();
137 return f->beg_pos ();
138 }
139
141 {
142 octave_function *f = m_fcn.function_value ();
143 return f->end_pos ();
144 }
145
147 {
148 tw.visit_function_def (*this);
149 }
150
151 octave_value function () { return m_fcn; }
152
153private:
154
155 octave_value m_fcn;
156
157 tree_function_def (const octave_value& v) : m_fcn (v) { }
158};
159
160OCTAVE_END_NAMESPACE(octave)
161
162#endif
virtual octave::filepos beg_pos() const
Definition ov-fcn.cc:55
virtual octave::filepos end_pos() const
Definition ov-fcn.cc:61
octave_function * function_value(bool silent=false) const
Definition token.h:42
filepos end_pos() const
Definition token.h:129
comment_list leading_comments() const
Definition token.h:134
comment_list trailing_comments() const
Definition token.h:135
filepos beg_pos() const
Definition token.h:128
tree_command()=default
tree_function_def(octave_function *f)
Definition pt-cmd.h:128
void accept(tree_walker &tw)
Definition pt-cmd.h:146
~tree_function_def()=default
filepos beg_pos() const
Definition pt-cmd.h:134
octave_value function()
Definition pt-cmd.h:151
filepos end_pos() const
Definition pt-cmd.h:140
void update_end_pos(const filepos &pos)
Definition pt-cmd.h:78
comment_list trailing_comments() const
Definition pt-cmd.h:93
filepos end_pos() const
Definition pt-cmd.h:76
filepos beg_pos() const
Definition pt-cmd.h:75
std::string original_command()
Definition pt-cmd.h:110
comment_list leading_comments() const
Definition pt-cmd.h:86
void attach_trailing_comments(const comment_list &lst)
Definition pt-cmd.h:88
bool is_end_of_fcn_or_script() const
Definition pt-cmd.h:103
void accept(tree_walker &tw)
Definition pt-cmd.h:98
tree_no_op_command(const std::string &cmd, bool eof, const token &tok)
Definition pt-cmd.h:67
~tree_no_op_command()=default
bool is_end_of_file() const
Definition pt-cmd.h:108
virtual void visit_no_op_command(tree_no_op_command &)
Definition pt-walk.cc:497
virtual void visit_function_def(tree_function_def &)
Definition pt-walk.cc:305
Definition pt.h:47
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
F77_RET_T const F77_DBLE const F77_DBLE * f