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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2974
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 #include "ov-builtin.h" |
|
34 #include "ov.h" |
4748
|
35 #include "toplev.h" |
|
36 #include "unwind-prot.h" |
2974
|
37 |
3219
|
38 DEFINE_OCTAVE_ALLOCATOR (octave_builtin); |
2974
|
39 |
4612
|
40 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
|
41 "built-in function", |
|
42 "built-in function"); |
2974
|
43 |
|
44 // Are any of the arguments `:'? |
|
45 |
|
46 static bool |
|
47 any_arg_is_magic_colon (const octave_value_list& args) |
|
48 { |
|
49 int nargin = args.length (); |
|
50 |
|
51 for (int i = 0; i < nargin; i++) |
|
52 if (args(i).is_magic_colon ()) |
3325
|
53 return true; |
2974
|
54 |
|
55 return false; |
|
56 } |
|
57 |
|
58 octave_value_list |
4247
|
59 octave_builtin::subsref (const std::string& type, |
4219
|
60 const std::list<octave_value_list>& idx, |
3933
|
61 int nargout) |
|
62 { |
|
63 octave_value_list retval; |
|
64 |
|
65 switch (type[0]) |
|
66 { |
|
67 case '(': |
|
68 retval = do_multi_index_op (nargout, idx.front ()); |
|
69 break; |
|
70 |
|
71 case '{': |
|
72 case '.': |
|
73 { |
|
74 std::string nm = type_name (); |
|
75 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
76 } |
|
77 break; |
|
78 |
|
79 default: |
|
80 panic_impossible (); |
|
81 } |
|
82 |
4059
|
83 // XXX FIXME XXX -- perhaps there should be an |
|
84 // octave_value_list::next_subsref member function? See also |
|
85 // octave_user_function::subsref. |
|
86 // |
|
87 // XXX FIXME XXX -- Note that if a function call returns multiple |
|
88 // values, and there is further indexing to perform, then we are |
|
89 // ignoring all but the first value. Is this really what we want to |
|
90 // do? If it is not, then what should happen for stat("file").size, |
|
91 // for exmaple? |
3933
|
92 |
4219
|
93 if (idx.size () > 1) |
4059
|
94 retval = retval(0).next_subsref (type, idx); |
|
95 |
|
96 return retval; |
3933
|
97 } |
|
98 |
|
99 octave_value_list |
3544
|
100 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974
|
101 { |
|
102 octave_value_list retval; |
|
103 |
|
104 if (error_state) |
|
105 return retval; |
|
106 |
|
107 if (any_arg_is_magic_colon (args)) |
|
108 ::error ("invalid use of colon in function argument list"); |
|
109 else |
4748
|
110 { |
|
111 unwind_protect_ptr (curr_function); |
|
112 curr_function = this; |
|
113 |
|
114 retval = (*f) (args, nargout); |
|
115 |
|
116 unwind_protect::run (); |
|
117 } |
2974
|
118 |
|
119 return retval; |
|
120 } |
|
121 |
|
122 /* |
|
123 ;;; Local Variables: *** |
|
124 ;;; mode: C++ *** |
|
125 ;;; End: *** |
|
126 */ |