Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-idx.h @ 20749:dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
* lo-array-gripes.h, lo-array-gripes.cc (index_exception):
New base class for indexing errors.
(invalid_index, out_of_range): New classes.
(gripe_index_out_of_range): New overloaded function.
(gripe_invalid_index): New overloaded functions.
Delete version with no arguments.
(gripe_invalid_assignment_size, gripe_assignment_dimension_mismatch):
Delete.
Change uses of gripe functions as needed.
* Cell.cc (Cell::index, Cell::assign, Cell::delete_elements): Use
exceptions to collect error info about and handle indexing errors.
* data.cc (Fnth_element, do_accumarray_sum, F__accumarray_sum__,
do_accumarray_minmax, do_accumarray_minmax_fun, F__accumdim_sum__):
Likewise.
* oct-map.cc (octave_map::index, octave_map::assign,
octave_map::delete_elements): Likewise.
* sparse.cc (Fsparse): Likewise.
* sub2ind.cc (Fsub2ind, Find2sub): Likewise. New tests.
* utils.cc (dims_to_numel): Likewise.
* ov-base-diag.cc (octave_base_diag<DMT, MT>::do_index_op,
octave_base_diag<DMT, MT>::subsasgn): Likewise.
* ov-base-mat.cc (octave_base_matrix<MT>::subsref,
octave_base_matrix<MT>::assign): Likewise.
* ov-base-sparse.cc (octave_base_sparse<T>::do_index_op,
octave_base_sparse<T>::assign,
octave_base_sparse<MT>::delete_elements): Likewise.
* ov-classdef.cc (cdef_object_array::subsref,
cdef_object_array::subsasgn): Likewise.
* ov-java.cc (make_java_index): Likewise.
* ov-perm.cc (octave_perm_matrix::do_index_op): Likewise.
* ov-range.cc (octave_range::do_index_op): Likewise.
* ov-re-diag.cc (octave_diag_matrix::do_index_op): Likewise.
* ov-str-mat.cc (octave_char_matrix_str::do_index_op_internal): Likewise.
* pt-assign.cc (tree_simple_assignment::rvalue1): Likewise.
* pt-idx.cc (tree_index_expression::rvalue,
tree_index_expression::lvalue): Likewise.
* Array-util.cc (sub2ind): Likewise.
* toplev.cc (main_loop): Also catch unhandled index_exception
exceptions.
* ov-base.cc (octave_base_value::index_vector): Improve error message.
* ov-re-sparse.cc (octave_sparse_matrix::index_vector): Likewise.
* ov-complex.cc (complex_index): New class.
(gripe_complex_index): New function.
(octave_complex::index_vector): Use it.
* pt-id.h, pt-id.cc (tree_identifier::is_variable,
tree_black_hole::is_variable): Now const.
* pt-idx.cc (final_index_error): New static function.
(tree_index_expression::rvalue, tree_index_expression::lvalue):
Use it.
* index.tst: New tests.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 15:07:37 -0400 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2980 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
23 #if !defined (octave_pt_idx_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_pt_idx_h 1 |
2980 | 25 |
4219 | 26 #include <list> |
27 | |
2980 | 28 class tree_argument_list; |
29 | |
30 class tree_walker; | |
31 | |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
32 class octave_map; |
2980 | 33 class octave_value; |
34 class octave_value_list; | |
35 class octave_lvalue; | |
36 | |
37 #include "str-vec.h" | |
38 | |
39 #include "pt-exp.h" | |
7336 | 40 #include "symtab.h" |
2980 | 41 |
42 // Index expressions. | |
43 | |
44 class | |
45 tree_index_expression : public tree_expression | |
46 { | |
47 public: | |
48 | |
49 tree_index_expression (tree_expression *e = 0, tree_argument_list *lst = 0, | |
10313 | 50 int l = -1, int c = -1, char t = '('); |
2980 | 51 |
3930 | 52 tree_index_expression (tree_expression *e, const std::string& n, |
10313 | 53 int l = -1, int c = -1); |
3930 | 54 |
4131 | 55 tree_index_expression (tree_expression *e, tree_expression* df, |
10313 | 56 int l = -1, int c = -1); |
4131 | 57 |
2980 | 58 ~tree_index_expression (void); |
59 | |
5099 | 60 bool has_magic_end (void) const; |
4267 | 61 |
3933 | 62 void append (tree_argument_list *lst = 0, char t = '('); |
3930 | 63 |
3933 | 64 void append (const std::string& n); |
65 | |
4131 | 66 void append (tree_expression *df); |
67 | |
3933 | 68 bool is_index_expression (void) const { return true; } |
2980 | 69 |
3523 | 70 std::string name (void) const; |
2991 | 71 |
3933 | 72 tree_expression *expression (void) { return expr; } |
3930 | 73 |
4219 | 74 std::list<tree_argument_list *> arg_lists (void) { return args; } |
3930 | 75 |
3933 | 76 std::string type_tags (void) { return type; } |
2980 | 77 |
4219 | 78 std::list<string_vector> arg_names (void) { return arg_nm; } |
2980 | 79 |
3933 | 80 bool lvalue_ok (void) const { return expr->lvalue_ok (); } |
3010 | 81 |
3933 | 82 bool rvalue_ok (void) const { return true; } |
2980 | 83 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
84 octave_value rvalue1 (int nargout = 1); |
2980 | 85 |
86 octave_value_list rvalue (int nargout); | |
87 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 octave_value_list rvalue (int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 const std::list<octave_lvalue> *lvalue_list); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
90 |
2980 | 91 octave_lvalue lvalue (void); |
92 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
93 tree_index_expression *dup (symbol_table::scope_id scope, |
10313 | 94 symbol_table::context_id context) const; |
5861 | 95 |
2980 | 96 void accept (tree_walker& tw); |
97 | |
98 private: | |
99 | |
3930 | 100 // The LHS of this index expression. |
2980 | 101 tree_expression *expr; |
102 | |
3933 | 103 // The indices (only valid if type == paren || type == brace). |
4219 | 104 std::list<tree_argument_list *> args; |
2980 | 105 |
3930 | 106 // The type of this index expression. |
3933 | 107 std::string type; |
3929 | 108 |
4131 | 109 // The names of the arguments. Used for constant struct element |
110 // references. | |
4219 | 111 std::list<string_vector> arg_nm; |
3933 | 112 |
4131 | 113 // The list of dynamic field names, if any. |
4219 | 114 std::list<tree_expression *> dyn_field; |
4131 | 115 |
7790
c23fab029f46
tree_index_expression constructor: delete default arg values
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
116 tree_index_expression (int l, int c); |
5861 | 117 |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
118 octave_map make_arg_struct (void) const; |
4131 | 119 |
4219 | 120 std::string |
121 get_struct_index | |
122 (std::list<string_vector>::const_iterator p_arg_nm, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
123 std::list<tree_expression *>::const_iterator p_dyn_field) const; |
2988 | 124 |
125 // No copying! | |
126 | |
127 tree_index_expression (const tree_index_expression&); | |
128 | |
129 tree_index_expression& operator = (const tree_index_expression&); | |
2980 | 130 }; |
131 | |
132 #endif |