GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-fcn-handle.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2003-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_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
42
43#include "ov.h"
44#include "ov-usr-fcn.h"
45
47
49{
50public:
51
52 tree_fcn_handle (const token& tok) : m_token (tok), m_name (m_token.text ()) { }
53
54 OCTAVE_DISABLE_COPY_MOVE (tree_fcn_handle)
55
56 ~tree_fcn_handle () = default;
57
58 filepos beg_pos () const { return m_token.beg_pos (); }
59 filepos end_pos () const { return m_token.end_pos (); }
60
61 void print (std::ostream& os, bool pr_as_read_syntax = false,
62 bool pr_orig_txt = true);
63
64 void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
65 bool pr_orig_txt = true);
66
67 std::string name () const { return m_name; }
68
69 bool rvalue_ok () const { return true; }
70
71 tree_expression * dup (symbol_scope& scope) const;
72
73 octave_value evaluate (tree_evaluator& tw, int nargout = 1);
74
76 {
77 return ovl (evaluate (tw, nargout));
78 }
79
81 {
82 tw.visit_fcn_handle (*this);
83 }
84
85private:
86
87 token m_token;
88
89 // The name of this function handle.
90 std::string m_name;
91};
92
94{
95public:
96
98 : m_at_tok (at_tok), m_parameter_list (pl), m_expression (ex), m_scope (scope), m_parent_scope (parent_scope)
99 { }
100
101 OCTAVE_DISABLE_COPY_MOVE (tree_anon_fcn_handle)
102
104
105 filepos beg_pos () const { return m_at_tok.beg_pos (); }
106 filepos end_pos () const { return m_expression->end_pos (); }
107
108 bool rvalue_ok () const { return true; }
109
111 {
112 return m_parameter_list;
113 }
114
115 tree_expression * expression () const { return m_expression; }
116
117 symbol_scope scope () const { return m_scope; }
118
119 symbol_scope parent_scope () const { return m_parent_scope; }
120
121 bool has_parent_scope () const { return m_parent_scope.is_valid (); }
122
124
125 octave_value evaluate (tree_evaluator& tw, int nargout = 1);
126
128 {
129 return ovl (evaluate (tw, nargout));
130 }
131
132 void accept (tree_walker& tw) { tw.visit_anon_fcn_handle (*this); }
133
134 void stash_file_name (const std::string& file) { m_file_name = file; }
135
136 std::string file_name () const { return m_file_name; }
137
138private:
139
140 token m_at_tok;
141
142 // Inputs parameters.
143 tree_parameter_list *m_parameter_list;
144
145 // Function body, limited to a single expression.
146 tree_expression *m_expression;
147
148 // Function scope.
149 symbol_scope m_scope;
150
151 // Parent scope, or an invalid scope if none.
152 symbol_scope m_parent_scope;
153
154 // Filename where the handle was defined.
155 std::string m_file_name;
156};
157
158OCTAVE_END_NAMESPACE(octave)
159
160#endif
bool is_valid() const
Definition symscope.h:410
Definition token.h:42
filepos beg_pos() const
Definition token.h:128
octave_value evaluate(tree_evaluator &tw, int nargout=1)
tree_parameter_list * parameter_list() const
symbol_scope scope() const
symbol_scope parent_scope() const
filepos beg_pos() const
bool has_parent_scope() const
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
tree_anon_fcn_handle(const token &at_tok, tree_parameter_list *pl, tree_expression *ex, const symbol_scope &scope, const symbol_scope &parent_scope)
tree_expression * expression() const
filepos end_pos() const
void accept(tree_walker &tw)
std::string file_name() const
void stash_file_name(const std::string &file)
tree_expression * dup(symbol_scope &scope) const
tree_fcn_handle(const token &tok)
std::string name() const
~tree_fcn_handle()=default
bool rvalue_ok() const
filepos beg_pos() const
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
filepos end_pos() const
void accept(tree_walker &tw)
virtual void visit_fcn_handle(tree_fcn_handle &)
Definition pt-walk.cc:509
virtual void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition pt-walk.cc:34
virtual filepos end_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