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