Mercurial > octave
annotate libinterp/parse-tree/pt-funcall.cc @ 23083:e9a0469dedd9 stable
maint: strip extra trailing newlines from files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 20 Jan 2017 12:19:08 -0500 |
parents | 34ce5be04942 |
children | ef4d915df748 3ac9f9ecfae5 |
rev | line source |
---|---|
15035 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3 Copyright (C) 2012-2016 John W. Eaton |
15035 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
15035 | 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 { | |
50 octave_function *fp = fcn.function_value (); | |
51 std::string nm = fp ? fp->name () : std::string ("<invalid-function>"); | |
52 | |
53 os << nm << " ("; | |
54 | |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
55 octave_idx_type n = args.length (); |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
56 for (octave_idx_type i = 0; i < n; i++) |
15035 | 57 { |
58 args(i).print_raw (os, pr_as_read_syntax); | |
59 | |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
60 if (i < n - 1) |
15035 | 61 os << ", "; |
62 } | |
63 | |
64 os << ")"; | |
65 } | |
66 } | |
67 | |
68 tree_funcall * | |
18522
bae00174787c
avoid GCC warnings
Lasse Schuirmann <lasse@schuirmann.net> and Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18355
diff
changeset
|
69 tree_funcall::dup (symbol_table::scope_id, symbol_table::context_id) const |
15035 | 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 | |
79 tree_funcall::accept (tree_walker& tw) | |
80 { | |
81 tw.visit_funcall (*this); | |
82 } | |
18355
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
83 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
84 octave_value_list |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
85 tree_funcall::rvalue (int nargout) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
86 { |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
87 octave_value_list retval; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
88 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
89 retval = feval (fcn.function_value (), args, nargout); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
90 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
91 if (retval.length () == 1 && retval(0).is_function ()) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
92 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
93 // The return object is a function. We may need to re-index it using the |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
94 // same logic as for identifier. This is primarily used for superclass |
18355
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
95 // references in classdef. |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
96 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
97 octave_value val = retval(0); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
98 octave_function *f = val.function_value (true); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
99 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
100 if (f && ! (is_postfix_indexed () |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
101 && f->is_postfix_index_handled (postfix_index ()))) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
102 { |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
103 octave_value_list tmp_args; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
104 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
105 retval = val.do_multi_index_op (nargout, tmp_args); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
106 } |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
107 } |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
108 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
109 return retval; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
110 } |