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" |
|
29 #include "oct-obj.h" |
|
30 #include "ov-builtin.h" |
|
31 #include "ov.h" |
4748
|
32 #include "toplev.h" |
|
33 #include "unwind-prot.h" |
2974
|
34 |
3219
|
35 DEFINE_OCTAVE_ALLOCATOR (octave_builtin); |
2974
|
36 |
4612
|
37 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
|
38 "built-in function", |
|
39 "built-in function"); |
2974
|
40 |
|
41 octave_value_list |
4247
|
42 octave_builtin::subsref (const std::string& type, |
4219
|
43 const std::list<octave_value_list>& idx, |
3933
|
44 int nargout) |
|
45 { |
|
46 octave_value_list retval; |
|
47 |
|
48 switch (type[0]) |
|
49 { |
|
50 case '(': |
5154
|
51 { |
5155
|
52 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154
|
53 |
|
54 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
|
55 } |
3933
|
56 break; |
|
57 |
|
58 case '{': |
|
59 case '.': |
|
60 { |
|
61 std::string nm = type_name (); |
|
62 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
63 } |
|
64 break; |
|
65 |
|
66 default: |
|
67 panic_impossible (); |
|
68 } |
|
69 |
5775
|
70 // FIXME -- perhaps there should be an |
4059
|
71 // octave_value_list::next_subsref member function? See also |
|
72 // octave_user_function::subsref. |
|
73 // |
5775
|
74 // FIXME -- Note that if a function call returns multiple |
4059
|
75 // values, and there is further indexing to perform, then we are |
|
76 // ignoring all but the first value. Is this really what we want to |
|
77 // do? If it is not, then what should happen for stat("file").size, |
|
78 // for exmaple? |
3933
|
79 |
4219
|
80 if (idx.size () > 1) |
4994
|
81 retval = retval(0).next_subsref (nargout, type, idx); |
4059
|
82 |
|
83 return retval; |
3933
|
84 } |
|
85 |
|
86 octave_value_list |
3544
|
87 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974
|
88 { |
|
89 octave_value_list retval; |
|
90 |
|
91 if (error_state) |
|
92 return retval; |
|
93 |
5864
|
94 if (args.has_magic_colon ()) |
2974
|
95 ::error ("invalid use of colon in function argument list"); |
|
96 else |
4748
|
97 { |
4987
|
98 unwind_protect::begin_frame ("builtin_func_eval"); |
|
99 |
5743
|
100 octave_call_stack::push (this); |
4975
|
101 |
5743
|
102 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
4748
|
103 |
|
104 retval = (*f) (args, nargout); |
|
105 |
4987
|
106 unwind_protect::run_frame ("builtin_func_eval"); |
4748
|
107 } |
2974
|
108 |
|
109 return retval; |
|
110 } |
|
111 |
|
112 /* |
|
113 ;;; Local Variables: *** |
|
114 ;;; mode: C++ *** |
|
115 ;;; End: *** |
|
116 */ |