2974
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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 // Are any of the arguments `:'? |
|
42 |
|
43 static bool |
|
44 any_arg_is_magic_colon (const octave_value_list& args) |
|
45 { |
|
46 int nargin = args.length (); |
|
47 |
|
48 for (int i = 0; i < nargin; i++) |
|
49 if (args(i).is_magic_colon ()) |
3325
|
50 return true; |
2974
|
51 |
|
52 return false; |
|
53 } |
|
54 |
|
55 octave_value_list |
4247
|
56 octave_builtin::subsref (const std::string& type, |
4219
|
57 const std::list<octave_value_list>& idx, |
3933
|
58 int nargout) |
|
59 { |
|
60 octave_value_list retval; |
|
61 |
|
62 switch (type[0]) |
|
63 { |
|
64 case '(': |
5154
|
65 { |
5155
|
66 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154
|
67 |
|
68 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
|
69 } |
3933
|
70 break; |
|
71 |
|
72 case '{': |
|
73 case '.': |
|
74 { |
|
75 std::string nm = type_name (); |
|
76 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
77 } |
|
78 break; |
|
79 |
|
80 default: |
|
81 panic_impossible (); |
|
82 } |
|
83 |
4059
|
84 // XXX FIXME XXX -- perhaps there should be an |
|
85 // octave_value_list::next_subsref member function? See also |
|
86 // octave_user_function::subsref. |
|
87 // |
|
88 // XXX FIXME XXX -- Note that if a function call returns multiple |
|
89 // values, and there is further indexing to perform, then we are |
|
90 // ignoring all but the first value. Is this really what we want to |
|
91 // do? If it is not, then what should happen for stat("file").size, |
|
92 // for exmaple? |
3933
|
93 |
4219
|
94 if (idx.size () > 1) |
4994
|
95 retval = retval(0).next_subsref (nargout, type, idx); |
4059
|
96 |
|
97 return retval; |
3933
|
98 } |
|
99 |
|
100 octave_value_list |
3544
|
101 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974
|
102 { |
|
103 octave_value_list retval; |
|
104 |
|
105 if (error_state) |
|
106 return retval; |
|
107 |
|
108 if (any_arg_is_magic_colon (args)) |
|
109 ::error ("invalid use of colon in function argument list"); |
|
110 else |
4748
|
111 { |
4987
|
112 unwind_protect::begin_frame ("builtin_func_eval"); |
|
113 |
5743
|
114 octave_call_stack::push (this); |
4975
|
115 |
5743
|
116 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
4748
|
117 |
|
118 retval = (*f) (args, nargout); |
|
119 |
4987
|
120 unwind_protect::run_frame ("builtin_func_eval"); |
4748
|
121 } |
2974
|
122 |
|
123 return retval; |
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |