Mercurial > octave
annotate libinterp/parse-tree/pt-colon.cc @ 23655:bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
Don't allow errors to be thrown during colon expression construction.
* pt-colon.h, pt-colon.cc (tree_colon_expression::tree_colon_expression):
Construct either two- or three-element expressions.
(tree_colon_expression::append): Delete.
(tree_colon_expression::line, tree_colon_expression::colum): Delete.
* parse.h, oct-parse.in.yy (base_parser::make_colon_expression):
New function.
(base_parser::finish_colon_expression): Delete.
(colon_expr1): Delete non-terminal
(tree_colon_expression_type): Delete.
(colon_expr): Construct two- or three-element expressions only.
(simple_expr): Handle single oper_expr separately here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jun 2017 10:25:54 -0400 |
parents | 214cb58ccc1c |
children | 980f39c3ab90 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 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 | |
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. |
2980 | 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. |
2980 | 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 | |
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" |
2980 | 25 #endif |
26 | |
27 #include "pt-colon.h" | |
28 | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
29 namespace octave |
2980 | 30 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
31 // Colon expressions. |
2980 | 32 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
33 tree_expression * |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
34 tree_colon_expression::dup (symbol_table::scope& scope) const |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
35 { |
23655
bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
36 tree_colon_expression *new_ce |
bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
37 = new tree_colon_expression (op_base ? op_base->dup (scope) : 0, |
bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
38 op_limit ? op_limit->dup (scope) : 0, |
bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
39 op_increment ? op_increment->dup (scope) : 0, |
bbcc1e08aaed
improve colon expression construction and avoid possible memory leak
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
40 line (), column ()); |
5861 | 41 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
42 new_ce->copy_base (*new_ce); |
5861 | 43 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
44 return new_ce; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
45 } |
2980 | 46 } |