GNU Octave  4.2.1
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
pt-funcall.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2017 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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "ov-fcn.h"
28 #include "pt-funcall.h"
29 #include "pt-walk.h"
30 
31 // Function call objects.
32 
33 void
34 tree_funcall::print (std::ostream& os, bool pr_as_read_syntax,
35  bool pr_orig_text)
36 {
37  print_raw (os, pr_as_read_syntax, pr_orig_text);
38 }
39 
40 void
41 tree_funcall::print_raw (std::ostream& os, bool pr_as_read_syntax,
42  bool pr_orig_text)
43 {
44  if (pr_orig_text)
45  {
46  os << original_text ();
47  }
48  else
49  {
51  std::string nm = fp ? fp->name () : std::string ("<invalid-function>");
52 
53  os << nm << " (";
54 
55  octave_idx_type n = args.length ();
56  for (octave_idx_type i = 0; i < n; i++)
57  {
58  args(i).print_raw (os, pr_as_read_syntax);
59 
60  if (i < n - 1)
61  os << ", ";
62  }
63 
64  os << ")";
65  }
66 }
67 
70 {
71  tree_funcall *new_fc = new tree_funcall (fcn, args, line (), column ());
72 
73  new_fc->copy_base (*new_fc);
74 
75  return new_fc;
76 }
77 
78 void
80 {
81  tw.visit_funcall (*this);
82 }
83 
86 {
88 
89  retval = feval (fcn.function_value (), args, nargout);
90 
91  if (retval.length () == 1 && retval(0).is_function ())
92  {
93  // The return object is a function. We may need to re-index it using the
94  // same logic as for identifier. This is primarily used for superclass
95  // references in classdef.
96 
97  octave_value val = retval(0);
98  octave_function *f = val.function_value (true);
99 
100  if (f && ! (is_postfix_indexed ()
102  {
103  octave_value_list tmp_args;
104 
105  retval = val.do_multi_index_op (nargout, tmp_args);
106  }
107  }
108 
109  return retval;
110 }
virtual std::string original_text(void) const
Definition: pt-exp.cc:78
octave_value_list rvalue(int nargout)
Definition: pt-funcall.cc:85
virtual bool is_postfix_index_handled(char type) const
Definition: ov-fcn.h:181
bool is_function(void) const
Definition: ov.h:711
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
octave_idx_type length(void) const
Definition: ovl.h:96
void print_raw(std::ostream &os, bool pr_as_read_syntax=false, bool pr_orig_txt=true)
Definition: pt-funcall.cc:41
std::string name(void) const
Definition: ov-fcn.h:163
octave_value_list args
Definition: pt-funcall.h:91
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
virtual void visit_funcall(tree_funcall &)=0
tree_funcall(const octave_value &f, const octave_value_list &a, int l=-1, int c=-1)
Definition: pt-funcall.h:43
bool is_postfix_indexed(void) const
Definition: pt-exp.h:92
JNIEnv void * args
Definition: ov-java.cc:67
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov.cc:1527
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
octave_value fcn
Definition: pt-funcall.h:88
void print(std::ostream &os, bool pr_as_read_syntax=false, bool pr_orig_txt=true)
Definition: pt-funcall.cc:34
octave_value retval
Definition: data.cc:6294
feval(ar{f}, 1) esult
Definition: oct-parse.cc:8829
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1705
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
void accept(tree_walker &tw)
Definition: pt-funcall.cc:79
tree_funcall * dup(symbol_table::scope_id, symbol_table::context_id context) const
Definition: pt-funcall.cc:69
char postfix_index(void) const
Definition: pt-exp.h:94
virtual int column(void) const
Definition: pt.h:51
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854