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" |
|
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 // Are any of the arguments `:'? |
|
43 |
|
44 static bool |
|
45 any_arg_is_magic_colon (const octave_value_list& args) |
|
46 { |
|
47 int nargin = args.length (); |
|
48 |
|
49 for (int i = 0; i < nargin; i++) |
|
50 if (args(i).is_magic_colon ()) |
3325
|
51 return true; |
2974
|
52 |
|
53 return false; |
|
54 } |
|
55 |
|
56 octave_value_list |
4247
|
57 octave_builtin::subsref (const std::string& type, |
4219
|
58 const std::list<octave_value_list>& idx, |
3933
|
59 int nargout) |
|
60 { |
|
61 octave_value_list retval; |
|
62 |
|
63 switch (type[0]) |
|
64 { |
|
65 case '(': |
|
66 retval = do_multi_index_op (nargout, idx.front ()); |
|
67 break; |
|
68 |
|
69 case '{': |
|
70 case '.': |
|
71 { |
|
72 std::string nm = type_name (); |
|
73 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
74 } |
|
75 break; |
|
76 |
|
77 default: |
|
78 panic_impossible (); |
|
79 } |
|
80 |
4059
|
81 // XXX FIXME XXX -- perhaps there should be an |
|
82 // octave_value_list::next_subsref member function? See also |
|
83 // octave_user_function::subsref. |
|
84 // |
|
85 // XXX FIXME XXX -- Note that if a function call returns multiple |
|
86 // values, and there is further indexing to perform, then we are |
|
87 // ignoring all but the first value. Is this really what we want to |
|
88 // do? If it is not, then what should happen for stat("file").size, |
|
89 // for exmaple? |
3933
|
90 |
4219
|
91 if (idx.size () > 1) |
4059
|
92 retval = retval(0).next_subsref (type, idx); |
|
93 |
|
94 return retval; |
3933
|
95 } |
|
96 |
|
97 octave_value_list |
3544
|
98 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974
|
99 { |
|
100 octave_value_list retval; |
|
101 |
|
102 if (error_state) |
|
103 return retval; |
|
104 |
|
105 if (any_arg_is_magic_colon (args)) |
|
106 ::error ("invalid use of colon in function argument list"); |
|
107 else |
|
108 retval = (*f) (args, nargout); |
|
109 |
|
110 return retval; |
|
111 } |
|
112 |
|
113 /* |
|
114 ;;; Local Variables: *** |
|
115 ;;; mode: C++ *** |
|
116 ;;; End: *** |
|
117 */ |