Mercurial > octave
annotate libinterp/parse-tree/pt-anon-scopes.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
1 /* |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
2 |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 1996-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27725
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27725
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27725
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27725
diff
changeset
|
7 |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
8 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
9 This file is part of Octave. |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
10 |
26177
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
12 under the terms of the GNU General Public License as published by |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
14 (at your option) any later version. |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
15 |
26177
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
19 GNU General Public License for more details. |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
20 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
21 You should have received a copy of the GNU General Public License |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
22 along with Octave; see the file COPYING. If not, see |
26177
f2d795f07c84
maint: Use standard copyright phrasing in all files.
Rik <rik@octave.org>
parents:
25824
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
24 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
25 */ |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
26 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
27 #ifdef HAVE_CONFIG_H |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
28 #include <config.h> |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
29 #endif |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
30 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
31 #include "error.h" |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
32 #include "pt-all.h" |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
33 #include "pt-anon-scopes.h" |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
34 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
35 // TODO: make sure that if(f->scope()) is checked if necessary |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
36 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
37 namespace octave |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
38 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
39 tree_anon_scopes::tree_anon_scopes (tree_anon_fcn_handle& anon_fh) |
27725
6388a240de87
move some common actions into tree_walker base class
John W. Eaton <jwe@octave.org>
parents:
26686
diff
changeset
|
40 : tree_walker (), m_params (), m_vars () |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
41 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
42 visit_anon_fcn_handle (anon_fh); |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
43 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
44 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
45 void |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
46 tree_anon_scopes::visit_anon_fcn_handle (tree_anon_fcn_handle& afh) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
47 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
48 tree_parameter_list *param_list = afh.parameter_list (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
49 tree_expression *expr = afh.expression (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
50 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
51 // Collect names of parameters. |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
52 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
53 if (param_list) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
54 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
55 std::list<std::string> pnames = param_list->variable_names (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
56 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
57 for (const auto& nm : pnames) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
58 m_params.insert (nm); |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
59 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
60 // Hmm, should this be included in the list returned from |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
61 // tree_parameter_list::variable_names? |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
62 if (param_list->takes_varargs ()) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
63 m_params.insert ("varargin"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
64 } |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
65 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
66 // Further walk the tree to find free variables in this expression |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
67 // and any nested definitions of additional anonymous functions. |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
68 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
69 if (expr) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
70 expr->accept (*this); |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
71 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
72 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
73 // The rest of visit_... methods is only for walking the tree. Many of |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
74 // them, in particular all methods for commands, are not applicable to |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
75 // anonymous functions. Only parts of the tree are walked which could |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
76 // contain further (nested) anonymous function definitions (so |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
77 // e.g. identifiers and left hand sides of assignments are ignored). |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
78 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
79 void |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
80 tree_anon_scopes::visit_identifier (tree_identifier& id) |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
81 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
82 std::string nm = id.name (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
83 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
84 if (m_params.find (nm) == m_params.end ()) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
85 m_vars.insert (nm); |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
86 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
87 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
88 void |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
89 tree_anon_scopes::visit_parameter_list (tree_parameter_list&) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
90 { |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
91 // In visit_anon_fcn_handle we only accept/visit the body of |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
92 // anonymous function definitions, not the parameter list. |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
93 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
94 panic_impossible (); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
95 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
96 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
97 void |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
98 tree_anon_scopes::visit_statement (tree_statement& stmt) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
99 { |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
100 tree_command *cmd = stmt.command (); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
101 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
102 if (cmd) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
103 panic_impossible (); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
104 else |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
105 { |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
106 tree_expression *expr = stmt.expression (); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
107 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
108 if (expr) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
109 expr->accept (*this); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
110 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
111 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
112 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
113 void |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
114 tree_anon_scopes::visit_statement_list (tree_statement_list& lst) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
115 { |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
116 for (auto& p : lst) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
117 { |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
118 tree_statement *elt = p; |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
119 |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
120 if (elt) |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
121 elt->accept (*this); |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
122 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
123 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
124 } |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
diff
changeset
|
125 |