Mercurial > octave
annotate libinterp/octave-value/ov-usr-fcn.h @ 26825:6e9034836239
allow handles to nested functions to work (bug #39257)
* stack-frame.h (stack_frame::set_closure_links): New function.
(usr_fcn_stack_frame::usr_fcn_stack_frame): New optional argument,
ACCESS_LINK, to allow access link to be set directly when creating
stack frames for handles to nested functions.
* call-stack.h, call-stack.cc (call_stack::push): New argument,
CLOSURE_FRAMES, in method to push user function objects on the call
stack to allow call stack context for handles to nested functions to
be set.
* symscope.h (symbol_scope::symbol_scope_rep::is_parent,
symbol_scope::is_parent): New functions.
* ov-fcn-handle.h, ov-fcn-handle.cc
(octave_fcn_handle::m_closure_frames, octave_fcn_handle::m_is_nested):
New data members.
(octave_fcn_handle::is_nested): New function.
(octave_fcn_handle::~octave_fcn_handle): Delete saved closure frames.
(octave_fcn_handle::octave_fcn_handle): Mark handles to nested
functions as nested instead of throwing error.
(octave_fcn_handle::push_closure_context,
octave_fcn_handle::workspace): New functions.
(Ffunctions): Handle nested functions.
(octave_fcn_handle::call): Pass pointer to first element of
closure_frames list to feval when executing a function.
* ov-fcn.h, ov-fcn.cc (octave_function::call): New overload with
pointer to closure_context stack frames as argument. Provide default
implementation.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::parent_function):
New member variable.
(octave_user_function::is_parent_function): New function.
(octave_user_function::call): Primary definition is now overload that
includes closure context. The other form now forwards to the new
version.
* pt-eval.cc (tree_evaluator::execute_user_function): New arg,
CLOSURE_FRAMES. Pass them to the call stack along with the user function.
Push current stack frame to any function handles returned from a
nested function or the parent of a nested function.
* test/nest/nst1.m, test/nest/nst2.m, test/nest/nst3.m: New files.
* test/nest/nest.tst: New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 03 Mar 2019 10:19:36 +0000 |
parents | 287eba9ed14b |
children | 9dd1d8973877 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26065
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2974 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2974 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2974 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2974 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
23 #if ! defined (octave_ov_usr_fcn_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_ov_usr_fcn_h 1 |
2974 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
27 |
2974 | 28 #include <ctime> |
29 | |
30 #include <string> | |
31 | |
3665 | 32 #include "comment-list.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
33 #include "ovl.h" |
2974 | 34 #include "ov-fcn.h" |
35 #include "ov-typeinfo.h" | |
24362
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24361
diff
changeset
|
36 #include "symscope.h" |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
37 #include "unwind-prot.h" |
2974 | 38 |
39 class string_vector; | |
40 | |
41 class octave_value; | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
42 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
43 namespace octave |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
44 { |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
45 class file_info; |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
46 class stack_frame; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
47 class tree_parameter_list; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
48 class tree_statement_list; |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
49 class tree_evaluator; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
50 class tree_expression; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
51 class tree_walker; |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
52 #if defined (HAVE_LLVM) |
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
53 class jit_function_info; |
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
54 #endif |
2974 | 55 |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
56 } |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
57 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
58 class |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
59 octave_user_code : public octave_function |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
60 { |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
61 protected: |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
62 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
63 octave_user_code (const std::string& fnm = "", const std::string& nm = "", |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
64 const octave::symbol_scope& scope = octave::symbol_scope (), |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
65 octave::tree_statement_list *cmds = nullptr, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
66 const std::string& ds = "") |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
67 : octave_function (nm, ds), m_scope (scope), file_name (fnm), |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
68 t_parsed (static_cast<time_t> (0)), |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
69 t_checked (static_cast<time_t> (0)), |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
70 m_file_info (nullptr), cmd_list (cmds) |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
71 { } |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
72 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
73 public: |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
74 |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
75 // No copying! |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
76 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
77 octave_user_code (const octave_user_code& f) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
78 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
79 octave_user_code& operator = (const octave_user_code& f) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
80 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
81 ~octave_user_code (void); |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
82 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
83 bool is_user_code (void) const { return true; } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
84 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
85 std::string get_code_line (size_t line); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
86 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
87 std::deque<std::string> get_code_lines (size_t line, size_t num_lines); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
88 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
89 void cache_function_text (const std::string& text, |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
90 const octave::sys::time& timestamp); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
91 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
92 octave::symbol_scope scope (void) { return m_scope; } |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23796
diff
changeset
|
93 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
94 void stash_fcn_file_name (const std::string& nm) { file_name = nm; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
95 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
96 void mark_fcn_file_up_to_date (const octave::sys::time& t) { t_checked = t; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
97 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
98 void stash_fcn_file_time (const octave::sys::time& t) |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
99 { |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
100 t_parsed = t; |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
101 mark_fcn_file_up_to_date (t); |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
102 } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
103 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
104 std::string fcn_file_name (void) const { return file_name; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
105 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
106 octave::sys::time time_parsed (void) const { return t_parsed; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
107 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
108 octave::sys::time time_checked (void) const { return t_checked; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
109 |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
110 virtual octave_value find_subfunction (const std::string&) const |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
111 { |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
112 return octave_value (); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
113 } |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
114 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
115 virtual std::map<std::string, octave_value> subfunctions (void) const; |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
116 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
117 octave::tree_statement_list * body (void) { return cmd_list; } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
118 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
119 octave_value dump (void) const; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
120 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
121 protected: |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
122 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
123 void get_file_info (void); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
124 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23796
diff
changeset
|
125 // Our symbol table scope. |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
126 octave::symbol_scope m_scope; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
127 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
128 // The name of the file we parsed. |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
129 std::string file_name; |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
130 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
131 // The time the file was parsed. |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
132 octave::sys::time t_parsed; |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
133 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
134 // The time the file was last checked to see if it needs to be |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
135 // parsed again. |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
136 octave::sys::time t_checked; |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
137 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
138 // Cached text of function or script code with line offsets |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
139 // calculated. |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
140 octave::file_info *m_file_info; |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23796
diff
changeset
|
141 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
142 // The list of commands that make up the body of this function. |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
143 octave::tree_statement_list *cmd_list; |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
144 }; |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
145 |
5744 | 146 // Scripts. |
147 | |
148 class | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
149 octave_user_script : public octave_user_code |
5744 | 150 { |
151 public: | |
152 | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
153 octave_user_script (void); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
154 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
155 octave_user_script (const std::string& fnm, const std::string& nm, |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
156 const octave::symbol_scope& scope = octave::symbol_scope (), |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23796
diff
changeset
|
157 octave::tree_statement_list *cmds = nullptr, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
158 const std::string& ds = ""); |
5744 | 159 |
160 octave_user_script (const std::string& fnm, const std::string& nm, | |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
161 const octave::symbol_scope& scope = octave::symbol_scope (), |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
162 const std::string& ds = ""); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
163 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
164 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
165 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
166 octave_user_script (const octave_user_script& f) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
167 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
168 octave_user_script& operator = (const octave_user_script& f) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
169 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
170 ~octave_user_script (void) = default; |
5744 | 171 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
172 octave_function * function_value (bool = false) { return this; } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
173 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
174 octave_user_script * user_script_value (bool = false) { return this; } |
5744 | 175 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
176 octave_user_code * user_code_value (bool = false) { return this; } |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
177 |
5744 | 178 // Scripts and user functions are both considered "scripts" because |
179 // they are written in Octave's scripting language. | |
180 | |
181 bool is_user_script (void) const { return true; } | |
182 | |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
183 octave_value_list |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
184 call (octave::tree_evaluator& tw, int nargout = 0, |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
185 const octave_value_list& args = octave_value_list ()); |
7336 | 186 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
187 void accept (octave::tree_walker& tw); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
188 |
5744 | 189 private: |
190 | |
191 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
192 }; | |
193 | |
194 // User-defined functions. | |
2974 | 195 |
196 class | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
197 octave_user_function : public octave_user_code |
2974 | 198 { |
199 public: | |
200 | |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
201 typedef std::map<std::string, octave_value> local_vars_map; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
202 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
203 octave_user_function (const octave::symbol_scope& scope = octave::symbol_scope (), |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
204 octave::tree_parameter_list *pl = nullptr, |
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
205 octave::tree_parameter_list *rl = nullptr, |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
206 octave::tree_statement_list *cl = nullptr, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
207 const local_vars_map& lviv = local_vars_map ()); |
2974 | 208 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
209 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
210 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
211 octave_user_function (const octave_user_function& fn) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
212 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
213 octave_user_function& operator = (const octave_user_function& fn) = delete; |
2974 | 214 |
215 ~octave_user_function (void); | |
216 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
217 octave_function * function_value (bool = false) { return this; } |
2974 | 218 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
219 octave_user_function * user_function_value (bool = false) { return this; } |
4700 | 220 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
221 octave_user_code * user_code_value (bool = false) { return this; } |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
222 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
223 octave_user_function * define_param_list (octave::tree_parameter_list *t); |
2974 | 224 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
225 octave_user_function * define_ret_list (octave::tree_parameter_list *t); |
2974 | 226 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
227 void stash_fcn_location (int line, int col) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
228 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
229 location_line = line; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
230 location_column = col; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 } |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
232 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
233 int beginning_line (void) const { return location_line; } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
234 int beginning_column (void) const { return location_column; } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
235 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
236 void stash_fcn_end_location (int line, int col) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
237 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
238 end_location_line = line; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 end_location_column = col; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
240 } |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
241 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
242 int ending_line (void) const { return end_location_line; } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
243 int ending_column (void) const { return end_location_column; } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
244 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
245 void maybe_relocate_end (void); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
246 |
6323 | 247 void stash_parent_fcn_name (const std::string& p) { parent_name = p; } |
248 | |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24285
diff
changeset
|
249 void stash_parent_fcn_scope (const octave::symbol_scope& ps); |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
250 |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
251 void stash_leading_comment (octave::comment_list *lc) { lead_comm = lc; } |
3665 | 252 |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
253 void stash_trailing_comment (octave::comment_list *tc) { trail_comm = tc; } |
3665 | 254 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
255 std::string profiler_name (void) const; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
256 |
6323 | 257 std::string parent_fcn_name (void) const { return parent_name; } |
258 | |
25394
9e39a53b4e00
make listing local functions for command completion work again (bug #53925)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
259 octave::symbol_scope parent_fcn_scope (void) const |
9e39a53b4e00
make listing local functions for command completion work again (bug #53925)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
260 { |
9e39a53b4e00
make listing local functions for command completion work again (bug #53925)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
261 return m_scope.parent_scope (); |
9e39a53b4e00
make listing local functions for command completion work again (bug #53925)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
262 } |
9e39a53b4e00
make listing local functions for command completion work again (bug #53925)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
263 |
2974 | 264 void mark_as_system_fcn_file (void); |
265 | |
4346 | 266 bool is_system_fcn_file (void) const { return system_fcn_file; } |
2974 | 267 |
4748 | 268 bool is_user_function (void) const { return true; } |
269 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
270 void erase_subfunctions (void); |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
271 |
2974 | 272 bool takes_varargs (void) const; |
273 | |
5848 | 274 bool takes_var_return (void) const; |
2974 | 275 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
276 void mark_as_private_function (const std::string& cname = ""); |
11445
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
277 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
278 void lock_subfunctions (void); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
279 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
280 void unlock_subfunctions (void); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
281 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
282 std::map<std::string, octave_value> subfunctions (void) const; |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
283 |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
284 octave_value find_subfunction (const std::string& subfuns) const; |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
285 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
286 bool has_subfunctions (void) const; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
287 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
288 void stash_subfunction_names (const std::list<std::string>& names); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
289 |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
290 std::list<std::string> subfunction_names (void) const; |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
291 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
292 octave_value_list all_va_args (const octave_value_list& args); |
2974 | 293 |
4748 | 294 void stash_function_name (const std::string& s) { my_name = s; } |
2974 | 295 |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11445
diff
changeset
|
296 void mark_as_subfunction (void) { subfunction = true; } |
4238 | 297 |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11445
diff
changeset
|
298 bool is_subfunction (void) const { return subfunction; } |
4238 | 299 |
6149 | 300 void mark_as_inline_function (void) { inline_function = true; } |
301 | |
302 bool is_inline_function (void) const { return inline_function; } | |
303 | |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
304 void mark_as_anonymous_function (void) { anonymous_function = true; } |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
305 |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
306 bool is_anonymous_function (void) const { return anonymous_function; } |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
307 |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
308 bool is_anonymous_function_of_class |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
309 (const std::string& cname = "") const |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
310 { |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
311 return anonymous_function |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
312 ? (cname.empty () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 ? (! dispatch_class ().empty ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
314 : cname == dispatch_class ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
315 : false; |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
316 } |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
317 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
318 // If we are a special expression, then the function body consists of exactly |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
319 // one expression. The expression's result is the return value of the |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
320 // function. |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
321 bool is_special_expr (void) const |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
322 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
323 return is_inline_function () || is_anonymous_function (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
324 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
325 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
326 void mark_as_nested_function (void) { nested_function = true; } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
327 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14138
diff
changeset
|
328 bool is_nested_function (void) const { return nested_function; } |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14138
diff
changeset
|
329 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
330 bool is_parent_function (void) const { return m_scope.is_parent (); } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
331 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
332 void mark_as_legacy_constructor (void) { class_constructor = legacy; } |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14138
diff
changeset
|
333 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
334 bool is_legacy_constructor (const std::string& cname = "") const |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
335 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
336 return (class_constructor == legacy |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
337 ? (cname.empty () ? true : cname == dispatch_class ()) : false); |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
338 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15427
diff
changeset
|
339 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15427
diff
changeset
|
340 void mark_as_classdef_constructor (void) { class_constructor = classdef; } |
7336 | 341 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
342 bool is_classdef_constructor (const std::string& cname = "") const |
17856
97e49b588f5d
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
343 { |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
344 return (class_constructor == classdef |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
345 ? (cname.empty () ? true : cname == dispatch_class ()) : false); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
346 } |
7336 | 347 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
348 void mark_as_legacy_method (void) { class_method = legacy; } |
7336 | 349 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
350 bool is_legacy_method (const std::string& cname = "") const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
351 { |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
352 return (class_method == legacy |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
353 ? (cname.empty () ? true : cname == dispatch_class ()) : false); |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
354 } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
355 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
356 void mark_as_classdef_method (void) { class_method = classdef; } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
357 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
358 bool is_classdef_method (const std::string& cname = "") const |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
359 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
360 return (class_method == classdef |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
361 ? (cname.empty () ? true : cname == dispatch_class ()) : false); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
362 } |
7336 | 363 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
364 octave_value_list |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
365 call (octave::tree_evaluator& tw, int nargout = 0, |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
366 const octave_value_list& args = octave_value_list ()) |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
367 { |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
368 return call (tw, nargout, args, nullptr); |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
369 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
370 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
371 octave_value_list |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
372 call (octave::tree_evaluator& tw, int nargout, |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
373 const octave_value_list& args, octave::stack_frame *); |
2974 | 374 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
375 octave::tree_parameter_list * parameter_list (void) { return param_list; } |
2974 | 376 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
377 octave::tree_parameter_list * return_list (void) { return ret_list; } |
2974 | 378 |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
379 octave::comment_list * leading_comment (void) { return lead_comm; } |
3665 | 380 |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
381 octave::comment_list * trailing_comment (void) { return trail_comm; } |
3665 | 382 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
383 const local_vars_map& local_var_init_vals (void) const |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
384 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
385 return m_local_var_init_vals; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
386 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
387 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
388 // If is_special_expr is true, retrieve the sigular expression that forms the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
389 // body. May be null (even if is_special_expr is true). |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
390 octave::tree_expression * special_expr (void); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
391 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
392 bool subsasgn_optimization_ok (void); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
393 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
394 void accept (octave::tree_walker& tw); |
2974 | 395 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
396 #if defined (HAVE_LLVM) |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
397 octave::jit_function_info * get_info (void) { return jit_info; } |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
398 |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
399 void stash_info (octave::jit_function_info *info) { jit_info = info; } |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
400 #endif |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
401 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23653
diff
changeset
|
402 octave_value dump (void) const; |
3933 | 403 |
2974 | 404 private: |
405 | |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
406 enum class_method_type |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
407 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
408 none, |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
409 legacy, |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
410 classdef |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
411 }; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15427
diff
changeset
|
412 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23653
diff
changeset
|
413 std::string ctor_type_str (void) const; |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
414 std::string method_type_str (void) const; |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23653
diff
changeset
|
415 |
2974 | 416 // List of arguments for this function. These are local variables. |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
417 octave::tree_parameter_list *param_list; |
2974 | 418 |
419 // List of parameters we return. These are also local variables in | |
420 // this function. | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
421 octave::tree_parameter_list *ret_list; |
2974 | 422 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
423 // For anonymous function values inherited from parent scope. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
424 local_vars_map m_local_var_init_vals; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
425 |
3665 | 426 // The comments preceding the FUNCTION token. |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
427 octave::comment_list *lead_comm; |
3665 | 428 |
429 // The comments preceding the ENDFUNCTION token. | |
23750
ea879bc55272
move comment_list and comment_elt classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
430 octave::comment_list *trail_comm; |
3665 | 431 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
432 // Location where this function was defined. |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
433 int location_line; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
434 int location_column; |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
435 int end_location_line; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
436 int end_location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
437 |
6323 | 438 // The name of the parent function, if any. |
439 std::string parent_name; | |
440 | |
2974 | 441 // True if this function came from a file that is considered to be a |
442 // system function. This affects whether we check the time stamp | |
443 // on the file to see if it has changed. | |
444 bool system_fcn_file; | |
445 | |
446 // The number of arguments that have names. | |
447 int num_named_args; | |
448 | |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
449 // TRUE means this is a subfunction of a primary function. |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11445
diff
changeset
|
450 bool subfunction; |
4238 | 451 |
6149 | 452 // TRUE means this is an inline function. |
453 bool inline_function; | |
454 | |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
455 // TRUE means this is an anonymous function. |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
456 bool anonymous_function; |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
457 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
458 // TRUE means this is a nested function. |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14138
diff
changeset
|
459 bool nested_function; |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14138
diff
changeset
|
460 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
461 // TRUE means this function contains a nested function. |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
462 bool parent_function; |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
463 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15427
diff
changeset
|
464 // Enum describing whether this function is the constructor for class object. |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
465 class_method_type class_constructor; |
7336 | 466 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
467 // Enum describing whether this function is a method for a class. |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
468 class_method_type class_method; |
7336 | 469 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
470 #if defined (HAVE_LLVM) |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
24037
diff
changeset
|
471 octave::jit_function_info *jit_info; |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
472 #endif |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
473 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
474 void maybe_relocate_end_internal (void); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16596
diff
changeset
|
475 |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23704
diff
changeset
|
476 void print_code_function_header (const std::string& prefix); |
2974 | 477 |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23704
diff
changeset
|
478 void print_code_function_trailer (const std::string& prefix); |
2974 | 479 |
25400
d423ce60f5c8
evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents:
25399
diff
changeset
|
480 // XXX FIXME (public) |
d423ce60f5c8
evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents:
25399
diff
changeset
|
481 public: |
d423ce60f5c8
evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents:
25399
diff
changeset
|
482 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
483 void restore_warning_states (void); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
484 |
4612 | 485 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2974 | 486 }; |
487 | |
488 #endif |