Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-colon.cc @ 20750:3339c9bdfe6a
Activate FSAL property in dorpri timestepper
* scripts/ode/private/runge_kutta_45_dorpri.m: don't compute
first stage if values from previous iteration are passed.
* scripts/ode/private/integrate_adaptive.m: do not update
cmputed stages if timestep is rejected.
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Sat, 03 Oct 2015 07:32:50 +0200 |
parents | 7ac907da9fba |
children | f90c8372b7ba |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19589
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2980 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "error.h" | |
28 #include "oct-obj.h" | |
29 #include "pager.h" | |
30 #include "ov.h" | |
3770 | 31 #include "pt-bp.h" |
2980 | 32 #include "pt-colon.h" |
33 #include "pt-walk.h" | |
34 | |
35 // Colon expressions. | |
36 | |
37 tree_colon_expression * | |
38 tree_colon_expression::append (tree_expression *t) | |
39 { | |
40 tree_colon_expression *retval = 0; | |
41 | |
42 if (op_base) | |
43 { | |
44 if (op_limit) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
45 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
46 if (op_increment) |
20638
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
47 error ("invalid colon expression"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
48 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
49 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
50 // Stupid syntax: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
51 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
52 // base : limit |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
53 // base : increment : limit |
2980 | 54 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
55 op_increment = op_limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
56 op_limit = t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
57 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
58 } |
2980 | 59 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 op_limit = t; |
2980 | 61 |
62 retval = this; | |
63 } | |
64 else | |
20638
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
65 error ("invalid colon expression"); |
2980 | 66 |
67 return retval; | |
68 } | |
69 | |
70 octave_value_list | |
71 tree_colon_expression::rvalue (int nargout) | |
72 { | |
73 octave_value_list retval; | |
74 | |
75 if (nargout > 1) | |
76 error ("invalid number of output arguments for colon expression"); | |
77 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8213
diff
changeset
|
78 retval = rvalue1 (nargout); |
2980 | 79 |
80 return retval; | |
81 } | |
82 | |
83 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8213
diff
changeset
|
84 tree_colon_expression::rvalue1 (int) |
2980 | 85 { |
86 octave_value retval; | |
87 | |
88 if (error_state || ! op_base || ! op_limit) | |
89 return retval; | |
90 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8213
diff
changeset
|
91 octave_value ov_base = op_base->rvalue1 (); |
2980 | 92 |
5347 | 93 if (error_state || ov_base.is_undefined ()) |
94 eval_error ("invalid base value in colon expression"); | |
95 else | |
2980 | 96 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8213
diff
changeset
|
97 octave_value ov_limit = op_limit->rvalue1 (); |
2980 | 98 |
5347 | 99 if (error_state || ov_limit.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 eval_error ("invalid limit value in colon expression"); |
8213
d5e08881bba8
Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents:
8011
diff
changeset
|
101 else if (ov_base.is_object () || ov_limit.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 octave_value_list tmp1; |
8213
d5e08881bba8
Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents:
8011
diff
changeset
|
104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 if (op_increment) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
107 octave_value ov_increment = op_increment->rvalue1 (); |
8213
d5e08881bba8
Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents:
8011
diff
changeset
|
108 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 if (error_state || ov_increment.is_undefined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 eval_error ("invalid increment value in colon expression"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 tmp1(2) = ov_limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 tmp1(1) = ov_increment; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 tmp1(0) = ov_base; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 tmp1(1) = ov_limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 tmp1(0) = ov_base; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 } |
8213
d5e08881bba8
Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents:
8011
diff
changeset
|
123 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 if (!error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 octave_value fcn = symbol_table::find_function ("colon", tmp1); |
8213
d5e08881bba8
Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents:
8011
diff
changeset
|
127 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 if (fcn.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
131 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
133 retval = tmp2 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 else |
20638
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
136 error ("can not find overloaded colon function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 } |
5347 | 139 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 octave_value ov_increment = 1.0; |
2980 | 142 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 if (op_increment) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 ov_increment = op_increment->rvalue1 (); |
2980 | 146 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 if (error_state || ov_increment.is_undefined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 eval_error ("invalid increment value in colon expression"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 } |
5347 | 150 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 if (! error_state) |
19954
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
152 retval = do_colon_op (ov_base, ov_increment, ov_limit, |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
153 is_for_cmd_expr ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 } |
2980 | 155 } |
156 | |
157 return retval; | |
158 } | |
159 | |
160 void | |
5347 | 161 tree_colon_expression::eval_error (const std::string& s) const |
2980 | 162 { |
20638
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
163 error ("%s", s.c_str ()); |
2980 | 164 } |
165 | |
5066 | 166 int |
167 tree_colon_expression::line (void) const | |
168 { | |
169 return (op_base ? op_base->line () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 : (op_increment ? op_increment->line () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 : (op_limit ? op_limit->line () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 : -1))); |
5066 | 173 } |
174 | |
175 int | |
176 tree_colon_expression::column (void) const | |
177 { | |
178 return (op_base ? op_base->column () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 : (op_increment ? op_increment->column () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 : (op_limit ? op_limit->column () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 : -1))); |
5066 | 182 } |
183 | |
5861 | 184 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
185 tree_colon_expression::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
186 symbol_table::context_id context) const |
5861 | 187 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
188 tree_colon_expression *new_ce = new |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
189 tree_colon_expression (op_base ? op_base->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 op_limit ? op_limit->dup (scope, context) : 0, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 op_increment ? op_increment->dup (scope, context) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
192 : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 line (), column ()); |
5861 | 194 |
195 new_ce->copy_base (*new_ce); | |
196 | |
197 return new_ce; | |
198 } | |
199 | |
2980 | 200 void |
201 tree_colon_expression::accept (tree_walker& tw) | |
202 { | |
203 tw.visit_colon_expression (*this); | |
204 } |