annotate src/pt-colon.cc @ 8913:35cd375d4bb3

make tree::dup functions const
author John W. Eaton <jwe@octave.org>
date Thu, 05 Mar 2009 13:50:25 -0500
parents 73c4516fae10
children eb63fbe60fab
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
5
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
7
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
11 option) any later version.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
12
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
16 for more details.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
17
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
18 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
19 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
20 <http://www.gnu.org/licenses/>.
2980
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 */
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
23
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
26 #endif
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
27
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
28 #include "error.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
29 #include "oct-obj.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
30 #include "pager.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
31 #include "ov.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3523
diff changeset
32 #include "pt-bp.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
33 #include "pt-colon.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
34 #include "pt-walk.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
35
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
36 // Colon expressions.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
37
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
38 tree_colon_expression *
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
39 tree_colon_expression::append (tree_expression *t)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
40 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
41 tree_colon_expression *retval = 0;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
42
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
43 if (op_base)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
44 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
45 if (op_limit)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
46 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
47 if (op_increment)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
48 ::error ("invalid colon expression");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
49 else
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
50 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
51 // Stupid syntax:
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
52 //
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
53 // base : limit
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
54 // base : increment : limit
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
55
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
56 op_increment = op_limit;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
57 op_limit = t;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
58 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
59 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
60 else
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
61 op_limit = t;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
62
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
63 retval = this;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
64 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
65 else
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
66 ::error ("invalid colon expression");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
67
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
68 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
69 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
70
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
71 octave_value_list
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
72 tree_colon_expression::rvalue (int nargout)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
73 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
74 octave_value_list retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
75
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
76 if (nargout > 1)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
77 error ("invalid number of output arguments for colon expression");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
78 else
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
79 retval = rvalue1 (nargout);
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
80
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
81 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
82 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
83
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
84 octave_value
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
85 tree_colon_expression::make_range (const Matrix& m_base,
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
86 const Matrix& m_limit,
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
87 const Matrix& m_increment,
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
88 bool result_is_str, bool dq_str) const
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
89 {
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
90 octave_value retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
91
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
92 bool base_empty = m_base.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
93 bool limit_empty = m_limit.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
94 bool increment_empty = m_increment.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
95
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
96 if (base_empty || limit_empty || increment_empty)
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
97 retval = Range ();
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
98 else
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
99 {
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
100 retval = Range (m_base(0), m_limit(0), m_increment(0));
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
101
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
102 if (result_is_str)
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
103 retval = retval.convert_to_str (false, true, dq_str ? '"' : '\'');
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
104 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
105
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
106 return retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
107 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
108
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
109 octave_value
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
110 tree_colon_expression::make_range (const octave_value& ov_base,
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
111 const octave_value& ov_limit,
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
112 const octave_value& ov_increment) const
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
113 {
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
114 octave_value retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
115
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
116 if (ov_base.is_object () || ov_limit.is_object () ||
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
117 ov_increment.is_object ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
118 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
119 octave_value_list tmp1;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
120 tmp1(2) = ov_limit;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
121 tmp1(1) = ov_increment;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
122 tmp1(0) = ov_base;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
123
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
124 octave_value fcn = symbol_table::find_function ("colon", tmp1);
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
125
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
126 if (fcn.is_defined ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
127 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
128 octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
129
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
130 if (! error_state)
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
131 retval = tmp2 (0);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
132 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
133 else
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
134 ::error ("can not find overloaded colon function");
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
135 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
136 else
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
137 {
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
138 bool result_is_str = (ov_base.is_string () && ov_limit.is_string ());
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
139 bool dq_str = (ov_base.is_dq_string () || ov_limit.is_dq_string ());
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
140
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
141 Matrix m_base = ov_base.matrix_value (true);
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
142
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
143 if (error_state)
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
144 eval_error ("invalid base value in colon expression");
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
145 else
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
146 {
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
147 Matrix m_limit = ov_limit.matrix_value (true);
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
148
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
149 if (error_state)
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
150 eval_error ("invalid limit value in colon expression");
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
151 else
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
152 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
153 Matrix m_increment = ov_increment.matrix_value (true);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
154
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
155 if (error_state)
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
156 eval_error ("invalid increment value in colon expression");
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
157 else
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
158 retval = make_range (m_base, m_limit, m_increment,
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
159 result_is_str, dq_str);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
160 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
161 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
162 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
163
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
164 return retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
165 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
166
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
167 octave_value
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
168 tree_colon_expression::rvalue1 (int)
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
169 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
170 octave_value retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
171
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
172 if (error_state || ! op_base || ! op_limit)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
173 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
174
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
175 octave_value ov_base = op_base->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
176
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
177 if (error_state || ov_base.is_undefined ())
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
178 eval_error ("invalid base value in colon expression");
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
179 else
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
180 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
181 octave_value ov_limit = op_limit->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
182
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
183 if (error_state || ov_limit.is_undefined ())
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
184 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
185 else if (ov_base.is_object () || ov_limit.is_object ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
186 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
187 octave_value_list tmp1;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
188
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
189 if (op_increment)
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
190 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
191 octave_value ov_increment = op_increment->rvalue1 ();
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
192
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
193 if (error_state || ov_increment.is_undefined ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
194 eval_error ("invalid increment value in colon expression");
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
195 else
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
196 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
197 tmp1(2) = ov_limit;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
198 tmp1(1) = ov_increment;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
199 tmp1(0) = ov_base;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
200 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
201 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
202 else
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
203 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
204 tmp1(1) = ov_limit;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
205 tmp1(0) = ov_base;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
206 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
207
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
208 if (!error_state)
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
209 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
210 octave_value fcn = symbol_table::find_function ("colon", tmp1);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
211
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
212 if (fcn.is_defined ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
213 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
214 octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
215
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
216 if (! error_state)
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
217 retval = tmp2 (0);
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
218 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
219 else
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
220 ::error ("can not find overloaded colon function");
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
221 }
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
222 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
223 else
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
224 {
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
225 octave_value ov_increment = 1.0;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
226
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
227 if (op_increment)
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
228 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
229 ov_increment = op_increment->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
230
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
231 if (error_state || ov_increment.is_undefined ())
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
232 eval_error ("invalid increment value in colon expression");
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
233 }
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
234
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
235 if (! error_state)
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
236 retval = make_range (ov_base, ov_limit, ov_increment);
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
237 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
238 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
239
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
240 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
241 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
242
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
243 void
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
244 tree_colon_expression::eval_error (const std::string& s) const
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
245 {
8011
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
246 ::error ("%s", s.c_str ());
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
247 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
248
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
249 int
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
250 tree_colon_expression::line (void) const
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
251 {
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
252 return (op_base ? op_base->line ()
5067
50f9e343a3ff [project @ 2004-11-04 20:48:03 by jwe]
jwe
parents: 5066
diff changeset
253 : (op_increment ? op_increment->line ()
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
254 : (op_limit ? op_limit->line ()
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
255 : -1)));
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
256 }
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
257
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
258 int
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
259 tree_colon_expression::column (void) const
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
260 {
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
261 return (op_base ? op_base->column ()
5067
50f9e343a3ff [project @ 2004-11-04 20:48:03 by jwe]
jwe
parents: 5066
diff changeset
262 : (op_increment ? op_increment->column ()
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
263 : (op_limit ? op_limit->column ()
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
264 : -1)));
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
265 }
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
266
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
267 tree_expression *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
268 tree_colon_expression::dup (symbol_table::scope_id scope,
8913
35cd375d4bb3 make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
269 symbol_table::context_id context) const
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
270 {
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
271 tree_colon_expression *new_ce = new
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
272 tree_colon_expression (op_base ? op_base->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
273 op_limit ? op_limit->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
274 op_increment ? op_increment->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
275 line (), column ());
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
276
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
277 new_ce->copy_base (*new_ce);
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
278
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
279 return new_ce;
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
280 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
281
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
282 void
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
283 tree_colon_expression::accept (tree_walker& tw)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
284 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
285 tw.visit_colon_expression (*this);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
286 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
287
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
288 /*
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
289 ;;; Local Variables: ***
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
290 ;;; mode: C++ ***
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
291 ;;; End: ***
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
292 */