15035
|
1 /* |
|
2 |
|
3 Copyright (C) 2012 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 (octave_tree_funcall_h) |
|
24 #define octave_tree_funcall_h 1 |
|
25 |
|
26 #include "ov.h" |
|
27 #include "oct-obj.h" |
|
28 #include "parse.h" |
|
29 #include "pt-exp.h" |
|
30 |
|
31 // Function call. This class only represents function calls that have |
|
32 // known functions (most useful for calls to built-in functions that |
|
33 // are generated by the parser) and fixed argument lists, known at |
|
34 // compile time. |
|
35 |
|
36 class |
|
37 tree_funcall : public tree_expression |
|
38 { |
|
39 public: |
|
40 |
|
41 tree_funcall (const octave_value& f, const octave_value_list& a, |
|
42 int l = -1, int c = -1) |
|
43 : tree_expression (l, c), fcn (f), args (a) |
|
44 { |
|
45 if (! fcn.is_function ()) |
|
46 error ("tree_funcall: invalid function"); |
|
47 } |
|
48 |
|
49 ~tree_funcall (void) { } |
|
50 |
|
51 bool has_magic_end (void) const { return false; } |
|
52 |
|
53 void print (std::ostream& os, bool pr_as_read_syntax = false, |
|
54 bool pr_orig_txt = true); |
|
55 |
|
56 void print_raw (std::ostream& os, bool pr_as_read_syntax = false, |
|
57 bool pr_orig_txt = true); |
|
58 |
|
59 tree_funcall *dup (symbol_table::scope_id, |
|
60 symbol_table::context_id context) const; |
|
61 |
|
62 octave_value rvalue1 (int nargout) |
|
63 { |
|
64 octave_value retval; |
|
65 |
|
66 const octave_value_list tmp = rvalue (nargout); |
|
67 |
|
68 if (! tmp.empty ()) |
|
69 retval = tmp(0); |
|
70 |
|
71 return retval; |
|
72 } |
|
73 |
|
74 octave_value_list rvalue (int nargout) |
|
75 { |
|
76 return feval (fcn.function_value (), args, nargout); |
|
77 } |
|
78 |
|
79 octave_value function (void) const { return fcn; } |
|
80 |
|
81 octave_value_list arguments (void) const { return args; } |
|
82 |
|
83 void accept (tree_walker& tw); |
|
84 |
|
85 private: |
|
86 |
|
87 // Function to call. Error if not a valid function at time of |
|
88 // construction. |
|
89 octave_value fcn; |
|
90 |
|
91 // Argument list. |
|
92 octave_value_list args; |
|
93 |
|
94 // No copying! |
|
95 |
|
96 tree_funcall (const tree_funcall&); |
|
97 |
|
98 tree_funcall& operator = (const tree_funcall&); |
|
99 }; |
|
100 |
|
101 #endif |