annotate libinterp/parse-tree/pt-assign.cc @ 23602:214cb58ccc1c

use pointer to scope instead of scope id Eliminate symbol table scope ID and the global list of all scopes indexed by numeric ID. Function scope data is now only accessible from the function itself, or by asking a scope for its parent scope (if it exists). The top-level and global scopes are now regular data members of the symbol table class instead of being static. Symbol table scopes are now created in the lexer when parsing a function begins and stored in the function object when finishing the construction of function object. If an error occurs while parsing a function, the list of any pending scopes is deleted.
author John W. Eaton <jwe@octave.org>
date Wed, 14 Jun 2017 11:53:34 -0400
parents c452180ab672
children 609658f98feb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
1 /*
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1996-2017 John W. Eaton
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
4
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
6
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
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
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
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.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
16
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
19 <http://www.gnu.org/licenses/>.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
20
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
21 */
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
25 #endif
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3448
diff changeset
27 #include <iostream>
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
28 #include <set>
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
29
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
30 #include "defun.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
31 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20977
diff changeset
32 #include "errwarn.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
33 #include "input.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20832
diff changeset
34 #include "ovl.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
35 #include "oct-lvalue.h"
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
36 #include "ov.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
37 #include "pager.h"
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
38 #include "parse.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2980
diff changeset
39 #include "pt-arg-list.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3536
diff changeset
40 #include "pt-bp.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
41 #include "pt-assign.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
42 #include "pt-walk.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
43 #include "utils.h"
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
44 #include "variables.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
45
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
46 namespace octave
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
47 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
48 // Simple assignment expressions.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
49
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
50 tree_simple_assignment::tree_simple_assignment
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
51 (tree_expression *le, tree_expression *re,
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
52 bool plhs, int l, int c, octave_value::assign_op t)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
53 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), etype (t)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
54 { }
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
55
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
56 tree_simple_assignment::~tree_simple_assignment (void)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
57 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
58 if (! preserve)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
59 delete lhs;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
60
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
61 delete rhs;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
62 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
63
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
64 std::string
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
65 tree_simple_assignment::oper (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
66 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
67 return octave_value::assign_op_as_string (etype);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
68 }
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
69
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
70 tree_expression *
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
71 tree_simple_assignment::dup (symbol_table::scope&) const
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
72 {
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
73 panic_impossible ();
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
74 return 0;
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
75 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
76
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
77 // Multi-valued assignment expressions.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
78
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
79 tree_multi_assignment::tree_multi_assignment
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
80 (tree_argument_list *lst, tree_expression *r,
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
81 bool plhs, int l, int c)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
82 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
83 { }
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
84
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
85 tree_multi_assignment::~tree_multi_assignment (void)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
86 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
87 if (! preserve)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
88 delete lhs;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
89
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
90 delete rhs;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
91 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
92
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
93 std::string
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
94 tree_multi_assignment::oper (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
95 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
96 return octave_value::assign_op_as_string (op_type ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
97 }
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
98
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
99 tree_expression *
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
100 tree_multi_assignment::dup (symbol_table::scope&) const
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
101 {
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
102 panic_impossible ();
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
103 return 0;
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
104 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
105 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
106
14572
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
107 /*
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
108 %!function varargout = f ()
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
109 %! varargout{1} = nargout;
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
110 %!endfunction
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
111 %!
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
112 %!test
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
113 %! [a, ~] = f ();
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
114 %! assert (a, 2);
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
115 %!test
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
116 %! [a, ~, ~, ~, ~] = f ();
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
117 %! assert (a, 5);
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
118 */