annotate src/pt-colon.cc @ 12770:3666e8e6f96e stable release-3-4-2

Version 3.4.2 released. * configure.ac (AC_INIT): Version is now 3.4.2. (OCTAVE_RELEASE_DATE): Now 2011-06-24.
author John W. Eaton <jwe@octave.org>
date Fri, 24 Jun 2011 10:36:40 -0400
parents 12df7854fa7c
children 72c96de7a403
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
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3 Copyright (C) 1996-2011 John W. Eaton
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
4
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
6
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
8 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
9 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
10 option) any later version.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
11
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
14 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
15 for more details.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
16
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 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/>.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
20
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
21 */
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
22
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
25 #endif
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
26
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
27 #include "error.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
28 #include "oct-obj.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
29 #include "pager.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
30 #include "ov.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3523
diff changeset
31 #include "pt-bp.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
32 #include "pt-colon.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
33 #include "pt-walk.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
34
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
35 // Colon expressions.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
36
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
37 tree_colon_expression *
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
38 tree_colon_expression::append (tree_expression *t)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
39 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
40 tree_colon_expression *retval = 0;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
41
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
42 if (op_base)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
43 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
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)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
47 ::error ("invalid colon expression");
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
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
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
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
59 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
60 op_limit = t;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
61
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
62 retval = this;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
63 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
64 else
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
65 ::error ("invalid colon expression");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
66
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
67 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
68 }
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 octave_value_list
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
71 tree_colon_expression::rvalue (int nargout)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
72 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
73 octave_value_list retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
74
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
75 if (nargout > 1)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
76 error ("invalid number of output arguments for colon expression");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
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
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
79
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
80 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
81 }
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 octave_value
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
84 tree_colon_expression::make_range (const Matrix& m_base,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
85 const Matrix& m_limit,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
86 const Matrix& m_increment,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
87 bool result_is_str, bool dq_str) const
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
88 {
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
89 octave_value retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
90
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
91 bool base_empty = m_base.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
92 bool limit_empty = m_limit.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
93 bool increment_empty = m_increment.is_empty ();
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
94
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
95 if (base_empty || limit_empty || increment_empty)
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
96 retval = Range ();
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
97 else
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
98 {
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
99 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
100
5358
cae8081f90f2 [project @ 2005-05-19 23:22:06 by jwe]
jwe
parents: 5347
diff changeset
101 if (result_is_str)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
102 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
103 }
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 return retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
106 }
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 octave_value
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
109 tree_colon_expression::make_range (const octave_value& ov_base,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
110 const octave_value& ov_limit,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
111 const octave_value& ov_increment) const
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
112 {
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
113 octave_value retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
114
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
115 if (ov_base.is_object () || ov_limit.is_object () ||
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
116 ov_increment.is_object ())
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
117 {
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
118 octave_value_list tmp1;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
119 tmp1(2) = ov_limit;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
120 tmp1(1) = ov_increment;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
121 tmp1(0) = ov_base;
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
122
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
123 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
124
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
125 if (fcn.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
126 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
127 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
128
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
129 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
130 retval = tmp2 (0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
131 }
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
132 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
133 ::error ("can not find overloaded colon function");
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
134 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
135 else
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
136 {
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
137 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
138 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
139
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
140 Matrix m_base = ov_base.matrix_value (true);
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
141
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
142 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
143 eval_error ("invalid base value in colon expression");
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
144 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
145 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
146 Matrix m_limit = ov_limit.matrix_value (true);
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
147
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
148 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
149 eval_error ("invalid limit value in colon expression");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
150 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
151 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
152 Matrix m_increment = ov_increment.matrix_value (true);
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
153
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
154 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
155 eval_error ("invalid increment value in colon expression");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
156 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
157 retval = make_range (m_base, m_limit, m_increment,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
158 result_is_str, dq_str);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
159 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
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 return retval;
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
164 }
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 octave_value
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
167 tree_colon_expression::rvalue1 (int)
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
168 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
169 octave_value retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
170
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
171 if (error_state || ! op_base || ! op_limit)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
172 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
173
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
174 octave_value ov_base = op_base->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
175
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
176 if (error_state || ov_base.is_undefined ())
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
177 eval_error ("invalid base value in colon expression");
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
178 else
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
179 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8213
diff changeset
180 octave_value ov_limit = op_limit->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
181
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
182 if (error_state || ov_limit.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
183 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
184 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
185 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
186 octave_value_list tmp1;
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
187
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
188 if (op_increment)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
189 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
190 octave_value ov_increment = op_increment->rvalue1 ();
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
191
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
192 if (error_state || ov_increment.is_undefined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
193 eval_error ("invalid increment value in colon expression");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
194 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
195 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
196 tmp1(2) = ov_limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
197 tmp1(1) = ov_increment;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
198 tmp1(0) = ov_base;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
199 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
200 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
201 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
202 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
203 tmp1(1) = ov_limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
204 tmp1(0) = ov_base;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
205 }
8213
d5e08881bba8 Add overloading of the colon operator
David Bateman <dbateman@free.fr>
parents: 8011
diff changeset
206
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
207 if (!error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
208 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
209 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
210
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
211 if (fcn.is_defined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
212 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
213 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
214
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
215 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
216 retval = tmp2 (0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
217 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
218 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
219 ::error ("can not find overloaded colon function");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
220 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
221 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
222 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
223 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
224 octave_value ov_increment = 1.0;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
225
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
226 if (op_increment)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
227 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
228 ov_increment = op_increment->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
229
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
230 if (error_state || ov_increment.is_undefined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
231 eval_error ("invalid increment value in colon expression");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
232 }
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
233
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
235 retval = make_range (ov_base, ov_limit, ov_increment);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
236 }
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 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
240 }
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 void
5347
679cc8fec408 [project @ 2005-05-11 16:34:11 by jwe]
jwe
parents: 5307
diff changeset
243 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
244 {
8011
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
245 ::error ("%s", s.c_str ());
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
246 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
247
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
248 int
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
249 tree_colon_expression::line (void) const
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
250 {
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
251 return (op_base ? op_base->line ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
252 : (op_increment ? op_increment->line ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
253 : (op_limit ? op_limit->line ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
254 : -1)));
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
255 }
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 int
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
258 tree_colon_expression::column (void) const
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
259 {
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
260 return (op_base ? op_base->column ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
261 : (op_increment ? op_increment->column ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
262 : (op_limit ? op_limit->column ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
263 : -1)));
5066
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
264 }
05e4d8c0a840 [project @ 2004-11-04 20:38:46 by jwe]
jwe
parents: 4876
diff changeset
265
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
266 tree_expression *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
267 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
268 symbol_table::context_id context) const
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
269 {
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
270 tree_colon_expression *new_ce = new
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
271 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
272 op_limit ? op_limit->dup (scope, context) : 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
273 op_increment ? op_increment->dup (scope, context) : 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
274 line (), column ());
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
275
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
276 new_ce->copy_base (*new_ce);
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
277
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
278 return new_ce;
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
279 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5358
diff changeset
280
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
281 void
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
282 tree_colon_expression::accept (tree_walker& tw)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
283 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
284 tw.visit_colon_expression (*this);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
285 }