GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-fcn-handle.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2003-2023 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_fcn_handle_h)
27 #define octave_pt_fcn_handle_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "pt-bp.h"
35 #include "pt-exp.h"
36 #include "pt-misc.h"
37 #include "pt-stmt.h"
38 #include "pt-walk.h"
39 #include "symscope.h"
40 
41 class octave_value_list;
42 
43 #include "ov.h"
44 #include "ov-usr-fcn.h"
45 
47 
49 {
50 public:
51 
52  tree_fcn_handle (int l = -1, int c = -1)
53  : tree_expression (l, c), m_name () { }
54 
55  tree_fcn_handle (const std::string& n, int l = -1, int c = -1)
56  : tree_expression (l, c), m_name (n) { }
57 
58  // No copying!
59 
60  tree_fcn_handle (const tree_fcn_handle&) = delete;
61 
63 
64  ~tree_fcn_handle (void) = default;
65 
66  void print (std::ostream& os, bool pr_as_read_syntax = false,
67  bool pr_orig_txt = true);
68 
69  void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
70  bool pr_orig_txt = true);
71 
72  std::string name (void) const { return m_name; }
73 
74  bool rvalue_ok (void) const { return true; }
75 
76  tree_expression * dup (symbol_scope& scope) const;
77 
78  octave_value evaluate (tree_evaluator& tw, int nargout = 1);
79 
81  {
82  return ovl (evaluate (tw, nargout));
83  }
84 
85  void accept (tree_walker& tw)
86  {
87  tw.visit_fcn_handle (*this);
88  }
89 
90 private:
91 
92  // The name of this function handle.
93  std::string m_name;
94 };
95 
97 {
98 public:
99 
100  tree_anon_fcn_handle (int l = -1, int c = -1)
101  : tree_expression (l, c), m_parameter_list (nullptr),
102  m_expression (nullptr), m_scope (), m_parent_scope (),
103  m_file_name ()
104  { }
105 
107  const symbol_scope& scope,
108  const symbol_scope& parent_scope,
109  int l = -1, int c = -1)
110  : tree_expression (l, c), m_parameter_list (pl), m_expression (ex),
112  { }
113 
114  // No copying!
115 
117 
119 
120  ~tree_anon_fcn_handle (void);
121 
122  bool rvalue_ok (void) const { return true; }
123 
125  {
126  return m_parameter_list;
127  }
128 
129  tree_expression * expression (void) const { return m_expression; }
130 
131  symbol_scope scope (void) const { return m_scope; }
132 
133  symbol_scope parent_scope (void) const { return m_parent_scope; }
134 
135  bool has_parent_scope (void) const { return m_parent_scope.is_valid (); }
136 
138 
139  octave_value evaluate (tree_evaluator& tw, int nargout = 1);
140 
142  {
143  return ovl (evaluate (tw, nargout));
144  }
145 
146  void accept (tree_walker& tw) { tw.visit_anon_fcn_handle (*this); }
147 
148  void stash_file_name (const std::string& file) { m_file_name = file; }
149 
150  std::string file_name (void) const { return m_file_name; }
151 
152 private:
153 
154  // Inputs parameters.
156 
157  // Function body, limited to a single expression.
159 
160  // Function scope.
162 
163  // Parent scope, or an invalid scope if none.
165 
166  // Filename where the handle was defined.
167  std::string m_file_name;
168 };
169 
171 
172 #endif
OCTAVE_END_NAMESPACE(octave)
octave_value_list & operator=(const octave_value_list &obj)=default
bool is_valid(void) const
Definition: symscope.h:395
octave_value evaluate(tree_evaluator &tw, int nargout=1)
bool rvalue_ok(void) const
bool has_parent_scope(void) const
symbol_scope m_scope
symbol_scope m_parent_scope
symbol_scope scope(void) const
tree_expression * expression(void) const
tree_anon_fcn_handle(int l=-1, int c=-1)
tree_anon_fcn_handle & operator=(const tree_anon_fcn_handle &)=delete
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
symbol_scope parent_scope(void) const
tree_anon_fcn_handle(tree_parameter_list *pl, tree_expression *ex, const symbol_scope &scope, const symbol_scope &parent_scope, int l=-1, int c=-1)
tree_parameter_list * m_parameter_list
void accept(tree_walker &tw)
tree_parameter_list * parameter_list(void) const
tree_anon_fcn_handle(const tree_anon_fcn_handle &)=delete
std::string file_name(void) const
std::string m_file_name
void stash_file_name(const std::string &file)
tree_expression * dup(symbol_scope &scope) const
tree_expression * m_expression
bool rvalue_ok(void) const
Definition: pt-fcn-handle.h:74
std::string m_name
Definition: pt-fcn-handle.h:93
tree_fcn_handle(int l=-1, int c=-1)
Definition: pt-fcn-handle.h:52
tree_fcn_handle(const tree_fcn_handle &)=delete
tree_fcn_handle(const std::string &n, int l=-1, int c=-1)
Definition: pt-fcn-handle.h:55
~tree_fcn_handle(void)=default
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-fcn-handle.h:80
void accept(tree_walker &tw)
Definition: pt-fcn-handle.h:85
std::string name(void) const
Definition: pt-fcn-handle.h:72
virtual void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-walk.cc:473
virtual void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-walk.cc:34
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_idx_type n
Definition: mx-inlines.cc:753
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211