Mercurial > octave-nkf
annotate src/ov-builtin.cc @ 8011:3100283874d7
improve backtrace error messages
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 05 Aug 2008 23:09:32 -0400 |
parents | 1e01db14700b |
children | 283989f2da9b |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
2974 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2974 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2974 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7487
diff
changeset
|
29 #include "gripes.h" |
2974 | 30 #include "oct-obj.h" |
31 #include "ov-builtin.h" | |
32 #include "ov.h" | |
4748 | 33 #include "toplev.h" |
34 #include "unwind-prot.h" | |
2974 | 35 |
3219 | 36 DEFINE_OCTAVE_ALLOCATOR (octave_builtin); |
2974 | 37 |
4612 | 38 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
39 "built-in function", | |
40 "built-in function"); | |
2974 | 41 |
42 octave_value_list | |
4247 | 43 octave_builtin::subsref (const std::string& type, |
4219 | 44 const std::list<octave_value_list>& idx, |
3933 | 45 int nargout) |
46 { | |
47 octave_value_list retval; | |
48 | |
49 switch (type[0]) | |
50 { | |
51 case '(': | |
5154 | 52 { |
5155 | 53 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 54 |
55 retval = do_multi_index_op (tmp_nargout, idx.front ()); | |
56 } | |
3933 | 57 break; |
58 | |
59 case '{': | |
60 case '.': | |
61 { | |
62 std::string nm = type_name (); | |
63 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); | |
64 } | |
65 break; | |
66 | |
67 default: | |
68 panic_impossible (); | |
69 } | |
70 | |
5775 | 71 // FIXME -- perhaps there should be an |
4059 | 72 // octave_value_list::next_subsref member function? See also |
73 // octave_user_function::subsref. | |
74 // | |
5775 | 75 // FIXME -- Note that if a function call returns multiple |
4059 | 76 // values, and there is further indexing to perform, then we are |
77 // ignoring all but the first value. Is this really what we want to | |
78 // do? If it is not, then what should happen for stat("file").size, | |
79 // for exmaple? | |
3933 | 80 |
4219 | 81 if (idx.size () > 1) |
4994 | 82 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 83 |
84 return retval; | |
3933 | 85 } |
86 | |
87 octave_value_list | |
3544 | 88 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974 | 89 { |
90 octave_value_list retval; | |
91 | |
92 if (error_state) | |
93 return retval; | |
94 | |
5864 | 95 if (args.has_magic_colon ()) |
2974 | 96 ::error ("invalid use of colon in function argument list"); |
97 else | |
4748 | 98 { |
4987 | 99 unwind_protect::begin_frame ("builtin_func_eval"); |
100 | |
5743 | 101 octave_call_stack::push (this); |
4975 | 102 |
5743 | 103 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
4748 | 104 |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 retval = (*f) (args, nargout); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7487
diff
changeset
|
111 gripe_library_execution_error (); |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
112 } |
4748 | 113 |
4987 | 114 unwind_protect::run_frame ("builtin_func_eval"); |
4748 | 115 } |
2974 | 116 |
117 return retval; | |
118 } | |
119 | |
120 /* | |
121 ;;; Local Variables: *** | |
122 ;;; mode: C++ *** | |
123 ;;; End: *** | |
124 */ |