GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-builtin.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "gripes.h"
29 #include "oct-obj.h"
30 #include "ov-builtin.h"
31 #include "ov.h"
32 #include "profiler.h"
33 #include "toplev.h"
34 #include "unwind-prot.h"
35 
37 
39  "built-in function",
40  "built-in function");
41 
43 octave_builtin::subsref (const std::string& type,
44  const std::list<octave_value_list>& idx,
45  int nargout)
46 {
47  return octave_builtin::subsref (type, idx, nargout, 0);
48 }
49 
51 octave_builtin::subsref (const std::string& type,
52  const std::list<octave_value_list>& idx,
53  int nargout,
54  const std::list<octave_lvalue>* lvalue_list)
55 {
56  octave_value_list retval;
57 
58  switch (type[0])
59  {
60  case '(':
61  {
62  int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
63 
64  retval = do_multi_index_op (tmp_nargout, idx.front (),
65  idx.size () == 1 ? lvalue_list : 0);
66  }
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:
79  }
80 
81  // FIXME: perhaps there should be an
82  // octave_value_list::next_subsref member function? See also
83  // octave_user_function::subsref.
84  //
85  // FIXME: 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?
90 
91  if (idx.size () > 1)
92  retval = retval(0).next_subsref (nargout, type, idx);
93 
94  return retval;
95 }
96 
99 {
100  return octave_builtin::do_multi_index_op (nargout, args, 0);
101 }
102 
105  const std::list<octave_lvalue> *lvalue_list)
106 {
107  octave_value_list retval;
108 
109  if (error_state)
110  return retval;
111 
112  if (args.has_magic_colon ())
113  ::error ("invalid use of colon in function argument list");
114  else
115  {
116  unwind_protect frame;
117 
119 
121 
122  if (lvalue_list || curr_lvalue_list)
123  {
125  curr_lvalue_list = lvalue_list;
126  }
127 
128  try
129  {
131 
132  retval = (*f) (args, nargout);
133  // Do not allow null values to be returned from functions.
134  // FIXME: perhaps true builtins should be allowed?
135  retval.make_storable_values ();
136  // Fix the case of a single undefined value.
137  // This happens when a compiled function uses
138  // octave_value retval;
139  // instead of
140  // octave_value_list retval;
141  // the idiom is very common, so we solve that here.
142  if (retval.length () == 1 && retval.xelem (0).is_undefined ())
143  retval.clear ();
144 
146  }
147  catch (octave_execution_exception)
148  {
150  }
151  }
152 
153  return retval;
154 }
155 
156 jit_type *
158 {
159  return jtype;
160 }
161 
162 void
164 {
165  jtype = &type;
166 }
167 
170 {
171  return f;
172 }
173 
174 const std::list<octave_lvalue> *octave_builtin::curr_lvalue_list = 0;