Mercurial > octave
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 |
rev | line source |
---|---|
2980 | 1 /* |
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 | 4 |
5 This file is part of Octave. | |
6 | |
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 | 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 | 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 |
19 <http://www.gnu.org/licenses/>. | |
2980 | 20 |
21 */ | |
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 | 25 #endif |
26 | |
3503 | 27 #include <iostream> |
6253 | 28 #include <set> |
2980 | 29 |
30 #include "defun.h" | |
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 | 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 | 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 | 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 | 39 #include "pt-arg-list.h" |
3770 | 40 #include "pt-bp.h" |
2980 | 41 #include "pt-assign.h" |
42 #include "pt-walk.h" | |
43 #include "utils.h" | |
5794 | 44 #include "variables.h" |
2980 | 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 | 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 | 51 (tree_expression *le, tree_expression *re, |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 105 } |
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 */ |