GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-cmd.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2024 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 "ov-fcn.h"
34 #include "pt.h"
35 #include "pt-bp.h"
36 #include "pt-walk.h"
37 
39 
40 // A base class for commands.
41 
42 class tree_command : public tree
43 {
44 public:
45 
46  tree_command (int l = -1, int c = -1)
47  : tree (l, c) { }
48 
49  OCTAVE_DISABLE_COPY_MOVE (tree_command)
50 
51  virtual ~tree_command () = default;
52 };
53 
54 // No-op.
55 
57 {
58 public:
59 
60  tree_no_op_command (const std::string& cmd = "no_op", bool e = false,
61  int l = -1, int c = -1)
62  : tree_command (l, c), m_eof (e), m_orig_cmd (cmd) { }
63 
64  OCTAVE_DISABLE_COPY_MOVE (tree_no_op_command)
65 
66  ~tree_no_op_command () = default;
67 
68  void accept (tree_walker& tw)
69  {
70  tw.visit_no_op_command (*this);
71  }
72 
74  {
75  return (m_orig_cmd == "endfunction" || m_orig_cmd == "endscript");
76  }
77 
78  bool is_end_of_file () const { return m_eof; }
79 
80  std::string original_command () { return m_orig_cmd; }
81 
82 private:
83 
84  bool m_eof;
85 
86  std::string m_orig_cmd;
87 };
88 
89 // Function definition.
90 
92 {
93 public:
94 
95  tree_function_def (octave_function *f, int l = -1, int c = -1)
96  : tree_command (l, c), m_fcn (f) { }
97 
98  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_function_def)
99 
100  ~tree_function_def () = default;
101 
102  void accept (tree_walker& tw)
103  {
104  tw.visit_function_def (*this);
105  }
106 
107  octave_value function () { return m_fcn; }
108 
109 private:
110 
111  octave_value m_fcn;
112 
113  tree_function_def (const octave_value& v, int l = -1, int c = -1)
114  : tree_command (l, c), m_fcn (v) { }
115 };
116 
117 OCTAVE_END_NAMESPACE(octave)
118 
119 #endif
tree_command(int l=-1, int c=-1)
Definition: pt-cmd.h:46
void accept(tree_walker &tw)
Definition: pt-cmd.h:102
~tree_function_def()=default
tree_function_def(octave_function *f, int l=-1, int c=-1)
Definition: pt-cmd.h:95
tree_no_op_command(const std::string &cmd="no_op", bool e=false, int l=-1, int c=-1)
Definition: pt-cmd.h:60
std::string original_command()
Definition: pt-cmd.h:80
bool is_end_of_fcn_or_script() const
Definition: pt-cmd.h:73
void accept(tree_walker &tw)
Definition: pt-cmd.h:68
~tree_no_op_command()=default
bool is_end_of_file() const
Definition: pt-cmd.h:78
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:45
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE * f