annotate libinterp/parse-tree/pt-arg-list.cc @ 23435:c452180ab672

begin refactoring parse tree evaluator * libinterp/parse-tree/pt-tm-const.cc, libinterp/parse-tree/pt-tm-const.h: New files, extracted from pt-mat.h and pt-mat.cc. * libinterp/parse-tree/module.mk: Update. * interpreter.cc, ov-class.cc, ov-classdef.cc, ov-classdef.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-usr-fcn.cc, oct-parse.in.yy, pt-arg-list.cc, pt-arg-list.h, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-classdef.cc, pt-classdef.h, pt-cmd.cc, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-funcall.cc, pt-funcall.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jit.cc, pt-jump.cc, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-select.cc, pt-select.h, pt-stmt.cc, pt-stmt.h, pt-unop.cc, pt-unop.h: Use tree_evaluator class to walk the parse tree instead of rvalue methods in the parse tree classes. Maintain a stack in the evaluator class to accumulate results. Pass pointer to evaluator to function objects and other classes as needed for evaluation. This is a work in progress that is not yet complete. The ultimate goal is to move all evaluation into the tree_evaluator class instead of spreading that work among many different classes. The global pointer to the current evaluator should also be eliminated.
author John W. Eaton <jwe@octave.org>
date Fri, 21 Apr 2017 18:07:40 -0400
parents 092078913d54
children c763214a8260
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
1 /*
20f5cec4f11c [project @ 1997-05-16 03:29:26 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
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
4
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
6
20f5cec4f11c [project @ 1997-05-16 03:29:26 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.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 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.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
16
20f5cec4f11c [project @ 1997-05-16 03:29:26 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: 5861
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: 5861
diff changeset
19 <http://www.gnu.org/licenses/>.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
20
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
21 */
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21660
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"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
25 #endif
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3162
diff changeset
27 #include <iostream>
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
28 #include <string>
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
29
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
30 #include "str-vec.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
31
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
32 #include "defun.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
33 #include "error.h"
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
34 #include "oct-lvalue.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20853
diff changeset
35 #include "ovl.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
36 #include "ov.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
37 #include "ov-usr-fcn.h"
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
38 #include "parse.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
39 #include "pt-arg-list.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
40 #include "pt-eval.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
41 #include "pt-exp.h"
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
42 #include "pt-id.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
43 #include "pt-idx.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
44 #include "pt-pr-code.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
45 #include "pt-walk.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
46 #include "interpreter.h"
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
47 #include "unwind-prot.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
48
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
49 namespace octave
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4265
diff changeset
50 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
51 // Argument lists.
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4265
diff changeset
52
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
53 tree_argument_list::~tree_argument_list (void)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
54 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
55 while (! empty ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
56 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
57 iterator p = begin ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
58 delete *p;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
59 erase (p);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
60 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
61 }
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4265
diff changeset
62
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
63 bool
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
64 tree_argument_list::has_magic_end (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
65 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
66 for (const tree_expression* elt : *this)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
67 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
68 if (elt && elt->has_magic_end ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
69 return true;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
70 }
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4265
diff changeset
71
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
72 return false;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
73 }
4258
b8a4496d7b24 [project @ 2003-01-02 03:45:53 by jwe]
jwe
parents: 4256
diff changeset
74
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
75 void
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
76 tree_argument_list::append (const element_type& s)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
77 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
78 octave::base_list<tree_expression *>::append (s);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
79
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
80 if (! list_includes_magic_end && s && s->has_magic_end ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
81 list_includes_magic_end = true;
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
82
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
83 if (! list_includes_magic_tilde && s && s->is_identifier ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
84 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
85 tree_identifier *id = dynamic_cast<tree_identifier *> (s);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
86 list_includes_magic_tilde = id && id->is_black_hole ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
87 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
88 }
4258
b8a4496d7b24 [project @ 2003-01-02 03:45:53 by jwe]
jwe
parents: 4256
diff changeset
89
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
90 bool
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
91 tree_argument_list::all_elements_are_constant (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
92 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
93 for (const tree_expression* elt : *this)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
94 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
95 if (! elt->is_constant ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
96 return false;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
97 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
98
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
99 return true;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
100 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
101
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
102 bool
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
103 tree_argument_list::is_valid_lvalue_list (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
104 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
105 bool retval = true;
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
106
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
107 for (const tree_expression* elt : *this)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
108 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
109 // There is no need for a separate check for the magic "~" because it
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
110 // is represented by tree_black_hole, and that is derived from
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
111 // tree_identifier.
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
112 if (! (elt->is_identifier () || elt->is_index_expression ()))
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
113 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
114 retval = false;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
115 break;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
116 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
117 }
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
118
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
119 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
120 }
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
121 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
122
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
123 static const octave_value *indexed_object = 0;
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
124 static int index_position = 0;
7751
7c020c067a60 F__end__: correctly handle fewer indices than dimensions
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
125 static int num_indices = 0;
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
126
22156
187b6727c75e build doc-cache without running Octave (bug #48508)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
127 // END is documented in op-kw-docs.
17355
f0edd6c752e9 don't convert "end" token to "__end__" for indexing
John W. Eaton <jwe@octave.org>
parents: 16755
diff changeset
128 DEFCONSTFUN (end, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
129 doc: /* -*- texinfo -*-
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
130 @deftypefn {} {} end
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
131 Last element of an array or the end of any @code{for}, @code{parfor},
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
132 @code{if}, @code{do}, @code{while}, @code{function}, @code{switch},
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
133 @code{try}, or @code{unwind_protect} block.
22156
187b6727c75e build doc-cache without running Octave (bug #48508)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
134
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
135 As an index of an array, the magic index @qcode{"end"} refers to the
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
136 last valid entry in an indexing operation.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
137
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
138 Example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
139
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
140 @example
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
141 @group
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
142 @var{x} = [ 1 2 3
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
143 4 5 6 ];
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
144 @var{x}(1,end)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
145 @result{} 3
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
146 @var{x}(end,1)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
147 @result{} 4
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
148 @var{x}(end,end)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
149 @result{} 6
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
150 @end group
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
151 @end example
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
152 @seealso{for, parfor, if, do, while, function, switch, try, unwind_protect}
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
153 @end deftypefn */)
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
154 {
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
155 octave_value retval;
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
156
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
157 if (! indexed_object)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
158 error ("invalid use of end");
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
159
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
160 if (indexed_object->is_object ())
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
161 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
162 octave_value_list args;
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
163
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
164 args(2) = num_indices;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
165 args(1) = index_position + 1;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
166 args(0) = *indexed_object;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
167
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
168 std::string class_name = indexed_object->class_name ();
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
169
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
170 octave_value meth = symbol_table::find_method ("end", class_name);
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
171
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
172 if (meth.is_defined ())
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
173 return octave::feval (meth.function_value (), args, 1);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
174 }
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
175
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
176 dim_vector dv = indexed_object->dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21547
diff changeset
177 int ndims = dv.ndims ();
8136
2b2ca62f8ab6 dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
178
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
179 if (num_indices < ndims)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
180 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
181 for (int i = num_indices; i < ndims; i++)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
182 dv(num_indices-1) *= dv(i);
4671
7a80bb43ea63 [project @ 2003-11-28 02:50:12 by jwe]
jwe
parents: 4432
diff changeset
183
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
184 if (num_indices == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10206
diff changeset
185 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
186 ndims = 2;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
187 dv.resize (ndims);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
188 dv(1) = 1;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
189 }
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
190 else
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
191 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
192 ndims = num_indices;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
193 dv.resize (ndims);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
194 }
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
195 }
4256
2b9c6dc25449 [project @ 2002-12-31 21:48:54 by jwe]
jwe
parents: 4255
diff changeset
196
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
197 if (index_position < ndims)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
198 retval = dv(index_position);
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
199 else
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
200 retval = 1;
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
201
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
202 return retval;
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
203 }
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
204
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
205 namespace octave
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
206 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
207 octave_value_list
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
208 tree_argument_list::convert_to_const_vector (tree_evaluator *tw,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
209 const octave_value *object)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
210 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
211 // END doesn't make sense for functions. Maybe we need a different
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
212 // way of asking an octave_value object this question?
4256
2b9c6dc25449 [project @ 2002-12-31 21:48:54 by jwe]
jwe
parents: 4255
diff changeset
213
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
214 bool stash_object = (list_includes_magic_end
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
215 && object
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
216 && ! (object->is_function ()
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
217 || object->is_function_handle ()));
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
218
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
219 octave::unwind_protect frame;
4256
2b9c6dc25449 [project @ 2002-12-31 21:48:54 by jwe]
jwe
parents: 4255
diff changeset
220
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
221 if (stash_object)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
222 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
223 frame.protect_var (indexed_object);
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
224
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
225 indexed_object = object;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
226 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
227
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
228 int len = length ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
229
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
230 std::list<octave_value_list> args;
4974
ff29117ce225 [project @ 2004-09-08 17:23:22 by jwe]
jwe
parents: 4671
diff changeset
231
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
232 iterator p = begin ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
233 for (int k = 0; k < len; k++)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
234 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
235 if (stash_object)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
236 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
237 frame.protect_var (index_position);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
238 frame.protect_var (num_indices);
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4219
diff changeset
239
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
240 index_position = k;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
241 num_indices = len;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
242 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
243
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
244 tree_expression *elt = *p++;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
245
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
246 if (elt)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
247 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
248 octave_value tmp = tw->evaluate (elt);
20586
22618d5fb6ad eliminate remaining uses of error_state in parse-tree files
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
249
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
250 if (tmp.is_cs_list ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
251 args.push_back (tmp.list_value ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
252 else if (tmp.is_defined ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
253 args.push_back (tmp);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
254 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
255 else
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
256 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
257 args.push_back (octave_value ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
258 break;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
259 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
260 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
261
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
262 return args;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
263 }
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
264
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
265 std::list<octave_lvalue>
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
266 tree_argument_list::lvalue_list (tree_evaluator *tw)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
267 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
268 std::list<octave_lvalue> retval;
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
269
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
270 for (tree_expression* elt : *this)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
271 retval.push_back (elt->lvalue (tw));
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
272
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
273 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
274 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
275
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
276 string_vector
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
277 tree_argument_list::get_arg_names (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
278 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
279 int len = length ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
280
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
281 string_vector retval (len);
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
282
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
283 int k = 0;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
284
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
285 for (tree_expression* elt : *this)
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents: 2982
diff changeset
286 retval(k++) = elt->str_print_code ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
287
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
288 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
289 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
290
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
291 std::list<std::string>
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
292 tree_argument_list::variable_names (void) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
293 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
294 std::list<std::string> retval;
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
295
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
296 for (tree_expression* elt : *this)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
297 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
298 if (elt->is_identifier ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
299 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
300 tree_identifier *id = dynamic_cast<tree_identifier *> (elt);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17756
diff changeset
301
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
302 retval.push_back (id->name ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
303 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
304 else if (elt->is_index_expression ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
305 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
306 tree_index_expression *idx_expr
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
307 = dynamic_cast<tree_index_expression *> (elt);
16755
787168f5f858 tag symbols in indexed assignments as variables (bug #39240)
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
308
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
309 retval.push_back (idx_expr->name ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
310 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
311 }
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
312
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
313 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
314 }
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
315
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
316 tree_argument_list *
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
317 tree_argument_list::dup (symbol_table::scope_id scope,
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
318 symbol_table::context_id context) const
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
319 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
320 tree_argument_list *new_list = new tree_argument_list ();
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
321
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
322 new_list->list_includes_magic_end = list_includes_magic_end;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
323 new_list->simple_assign_lhs = simple_assign_lhs;
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
324
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
325 for (const tree_expression* elt : *this)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
326 new_list->append (elt ? elt->dup (scope, context) : 0);
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
327
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
328 return new_list;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22872
diff changeset
329 }
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
330 }