Mercurial > octave
annotate libinterp/parse-tree/pt-cell.cc @ 22872:551ac93c984c
maint: Use C++ range feature to simplify some for loops in libinterp/parse-tree
* lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc,
pt-bp.cc, pt-cell.cc, pt-check.cc, pt-decl.cc, pt-eval.cc, pt-idx.cc,
pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc:
Use C++ range feature to simplify some for loops.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 08 Dec 2016 14:50:52 -0800 |
parents | 3a2b891d0b33 |
children | 4e3d47dc7e25 |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3 Copyright (C) 1999-2016 John W. Eaton |
3353 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
3353 | 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. |
3353 | 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/>. | |
3353 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
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" |
3353 | 25 #endif |
26 | |
3503 | 27 #include <iostream> |
3353 | 28 |
29 #include "Cell.h" | |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20832
diff
changeset
|
30 #include "ovl.h" |
3353 | 31 #include "pt-arg-list.h" |
32 #include "pt-exp.h" | |
33 #include "pt-cell.h" | |
34 #include "pt-walk.h" | |
35 #include "ov.h" | |
36 | |
37 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8588
diff
changeset
|
38 tree_cell::rvalue1 (int) |
3353 | 39 { |
40 octave_value retval; | |
41 | |
5275 | 42 octave_idx_type nr = length (); |
43 octave_idx_type nc = -1; | |
3353 | 44 |
4501 | 45 Cell val; |
3353 | 46 |
19451
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 octave_idx_type i = 0; |
3353 | 48 |
22872
551ac93c984c
maint: Use C++ range feature to simplify some for loops in libinterp/parse-tree
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
49 for (tree_argument_list* elt : *this) |
3353 | 50 { |
51 octave_value_list row = elt->convert_to_const_vector (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 |
8588
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
53 if (nr == 1) |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
54 // Optimize the single row case. |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
55 val = row.cell_value (); |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
56 else if (nc < 0) |
10315
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 nc = row.length (); |
4501 | 59 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 val = Cell (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
61 } |
4501 | 62 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
63 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 octave_idx_type this_nc = row.length (); |
4501 | 65 |
19451
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 if (this_nc != nc) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
67 { |
19451
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 if (this_nc == 0) |
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 continue; // blank line |
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 else |
20832
3951d420556c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
71 error ("number of columns must match"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 } |
4501 | 74 |
5275 | 75 for (octave_idx_type j = 0; j < nc; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 val(i,j) = row(j); |
3353 | 77 |
78 i++; | |
79 } | |
80 | |
19451
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 if (i < nr) |
e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 val.resize (dim_vector (i, nc)); // there were blank rows |
3353 | 83 retval = val; |
84 | |
85 return retval; | |
86 } | |
87 | |
3556 | 88 octave_value_list |
89 tree_cell::rvalue (int nargout) | |
90 { | |
91 if (nargout > 1) | |
92 error ("invalid number of output arguments for cell array"); | |
93 | |
20832
3951d420556c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
94 return rvalue1 (nargout); |
3556 | 95 } |
96 | |
5861 | 97 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
98 tree_cell::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 symbol_table::context_id context) const |
5861 | 100 { |
101 tree_cell *new_cell = new tree_cell (0, line (), column ()); | |
102 | |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
103 new_cell->copy_base (*this, scope, context); |
5861 | 104 |
105 return new_cell; | |
106 } | |
107 | |
3353 | 108 void |
109 tree_cell::accept (tree_walker& tw) | |
110 { | |
111 tw.visit_cell (*this); | |
112 } | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
113 |