Mercurial > octave
annotate libinterp/parse-tree/pt-decl.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 |
---|---|
2982 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3 Copyright (C) 1996-2016 John W. Eaton |
2982 | 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. |
2982 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2982 | 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/>. | |
2982 | 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" |
2982 | 25 #endif |
26 | |
3156 | 27 #include "defun.h" |
2982 | 28 #include "error.h" |
29 #include "pt-cmd.h" | |
30 #include "ov.h" | |
31 #include "oct-lvalue.h" | |
7205 | 32 #include "pt-bp.h" |
2982 | 33 #include "pt-decl.h" |
34 #include "pt-exp.h" | |
35 #include "pt-id.h" | |
36 #include "pt-walk.h" | |
3156 | 37 #include "utils.h" |
38 #include "variables.h" | |
39 | |
2982 | 40 // Declarations (global, static, etc.). |
41 | |
42 tree_decl_elt::~tree_decl_elt (void) | |
43 { | |
44 delete id; | |
45 delete expr; | |
46 } | |
47 | |
6215 | 48 bool |
49 tree_decl_elt::eval (void) | |
50 { | |
51 bool retval = false; | |
52 | |
53 if (id && expr) | |
54 { | |
55 octave_lvalue ult = id->lvalue (); | |
56 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
57 octave_value init_val = expr->rvalue1 (); |
6215 | 58 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
59 ult.assign (octave_value::op_asn_eq, init_val); |
6215 | 60 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
61 retval = true; |
6215 | 62 } |
63 | |
64 return retval; | |
65 } | |
66 | |
5861 | 67 tree_decl_elt * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
68 tree_decl_elt::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 symbol_table::context_id context) const |
5861 | 70 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
71 return new tree_decl_elt (id ? id->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 expr ? expr->dup (scope, context) : 0); |
5861 | 73 } |
74 | |
2982 | 75 void |
76 tree_decl_elt::accept (tree_walker& tw) | |
77 { | |
78 tw.visit_decl_elt (*this); | |
79 } | |
80 | |
81 // Initializer lists for declaration statements. | |
82 | |
5861 | 83 tree_decl_init_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
84 tree_decl_init_list::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 symbol_table::context_id context) const |
5861 | 86 { |
87 tree_decl_init_list *new_dil = new tree_decl_init_list (); | |
88 | |
22872
551ac93c984c
maint: Use C++ range feature to simplify some for loops in libinterp/parse-tree
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
89 for (const tree_decl_elt* elt : *this) |
551ac93c984c
maint: Use C++ range feature to simplify some for loops in libinterp/parse-tree
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
90 new_dil->append (elt ? elt->dup (scope, context) : 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
91 |
5861 | 92 return new_dil; |
93 } | |
94 | |
2982 | 95 void |
96 tree_decl_init_list::accept (tree_walker& tw) | |
97 { | |
98 tw.visit_decl_init_list (*this); | |
99 } | |
100 | |
101 // Base class for declaration commands (global, static). | |
102 | |
103 tree_decl_command::~tree_decl_command (void) | |
104 { | |
105 delete init_list; | |
106 } | |
107 | |
108 // Global. | |
109 | |
5861 | 110 tree_command * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
111 tree_global_command::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 symbol_table::context_id context) const |
5861 | 113 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
114 return |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
115 new tree_global_command (init_list ? init_list->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 line (), column ()); |
5861 | 117 } |
118 | |
2989 | 119 void |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
120 tree_global_command::accept (tree_walker& tw) |
2982 | 121 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
122 tw.visit_global_command (*this); |
2982 | 123 } |
124 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
125 // Static. |
2982 | 126 |
5861 | 127 tree_command * |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
128 tree_persistent_command::dup (symbol_table::scope_id scope, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
129 symbol_table::context_id context) const |
5861 | 130 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
131 return |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 new tree_persistent_command (init_list ? init_list->dup (scope, context) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 : 0, |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
134 line (), column ()); |
5861 | 135 } |
136 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
137 void |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
138 tree_persistent_command::accept (tree_walker& tw) |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
139 { |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
140 tw.visit_persistent_command (*this); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
141 } |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
142 |