Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include "error.h"
00028 #include "gripes.h"
00029 #include "oct-obj.h"
00030 #include "ov-builtin.h"
00031 #include "ov.h"
00032 #include "profiler.h"
00033 #include "toplev.h"
00034 #include "unwind-prot.h"
00035
00036 DEFINE_OCTAVE_ALLOCATOR (octave_builtin);
00037
00038 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin,
00039 "built-in function",
00040 "built-in function");
00041
00042 octave_value_list
00043 octave_builtin::subsref (const std::string& type,
00044 const std::list<octave_value_list>& idx,
00045 int nargout)
00046 {
00047 return octave_builtin::subsref (type, idx, nargout, 0);
00048 }
00049
00050 octave_value_list
00051 octave_builtin::subsref (const std::string& type,
00052 const std::list<octave_value_list>& idx,
00053 int nargout, const std::list<octave_lvalue>* lvalue_list)
00054 {
00055 octave_value_list retval;
00056
00057 switch (type[0])
00058 {
00059 case '(':
00060 {
00061 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
00062
00063 retval = do_multi_index_op (tmp_nargout, idx.front (),
00064 idx.size () == 1 ? lvalue_list : 0);
00065 }
00066 break;
00067
00068 case '{':
00069 case '.':
00070 {
00071 std::string nm = type_name ();
00072 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
00073 }
00074 break;
00075
00076 default:
00077 panic_impossible ();
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 if (idx.size () > 1)
00091 retval = retval(0).next_subsref (nargout, type, idx);
00092
00093 return retval;
00094 }
00095
00096 octave_value_list
00097 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args)
00098 {
00099 return octave_builtin::do_multi_index_op (nargout, args, 0);
00100 }
00101
00102 octave_value_list
00103 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args,
00104 const std::list<octave_lvalue> *lvalue_list)
00105 {
00106 octave_value_list retval;
00107
00108 if (error_state)
00109 return retval;
00110
00111 if (args.has_magic_colon ())
00112 ::error ("invalid use of colon in function argument list");
00113 else
00114 {
00115 unwind_protect frame;
00116
00117 octave_call_stack::push (this);
00118
00119 frame.add_fcn (octave_call_stack::pop);
00120
00121 if (lvalue_list || curr_lvalue_list)
00122 {
00123 frame.protect_var (curr_lvalue_list);
00124 curr_lvalue_list = lvalue_list;
00125 }
00126
00127 try
00128 {
00129 BEGIN_PROFILER_BLOCK (profiler_name ())
00130
00131 retval = (*f) (args, nargout);
00132
00133
00134 retval.make_storable_values ();
00135
00136
00137
00138
00139
00140
00141 if (retval.length () == 1 && retval.xelem (0).is_undefined ())
00142 retval.clear ();
00143
00144 END_PROFILER_BLOCK
00145 }
00146 catch (octave_execution_exception)
00147 {
00148 gripe_library_execution_error ();
00149 }
00150 }
00151
00152 return retval;
00153 }
00154
00155
00156 const std::list<octave_lvalue> *octave_builtin::curr_lvalue_list = 0;