Mercurial > octave
annotate libinterp/interp-core/defun-int.h @ 15398:2e5ba861898f
default arg values for DEFUN functions
* defun-int.h (DECLARE_FUNXX, DECLARE_FUNX_NO_DEFAULTS,
DECLARE_FUN_NO_DEFAULTS): New macros.
(DECLARE_FUNX): Define using DECLARE_FUNXX. Provide default argument
values.
* defun-dld.h (DEFUN_DLD, DEFUNX_DLD): Use DECLARE_FUNX_NO_DEFAULTS
instead of DECLARE_FUNX.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 17 Sep 2012 22:35:38 -0400 |
parents | 2fc554ffbc28 |
children | cd6ce11b9c57 |
rev | line source |
---|---|
525 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1994-2012 John W. Eaton |
525 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
525 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
525 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_defun_int_h) | |
24 #define octave_defun_int_h 1 | |
25 | |
2968 | 26 #include <string> |
27 | |
3145 | 28 #include "ov-builtin.h" |
3325 | 29 #include "ov-dld-fcn.h" |
3145 | 30 #include "symtab.h" |
3015 | 31 #include "version.h" |
32 | |
2968 | 33 class octave_value; |
34 | |
6109 | 35 extern OCTINTERP_API void print_usage (void); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
7996
diff
changeset
|
36 extern OCTINTERP_API void print_usage (const std::string&); |
3014 | 37 |
6109 | 38 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn); |
3015 | 39 |
6109 | 40 extern OCTINTERP_API void |
3523 | 41 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
15004
ea6997657614
which: provide source file name for built-in functions
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
42 const std::string& file, const std::string& doc, |
10313 | 43 bool can_hide_function = true); |
2968 | 44 |
6109 | 45 extern OCTINTERP_API void |
3523 | 46 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
47 const octave_shlib& shl, const std::string& doc, |
10313 | 48 bool relative = false); |
703 | 49 |
6109 | 50 extern OCTINTERP_API void |
5864 | 51 install_mex_function (void *fptr, bool fmex, const std::string& name, |
10313 | 52 const octave_shlib& shl, bool relative = false); |
5864 | 53 |
6109 | 54 extern OCTINTERP_API void |
3523 | 55 alias_builtin (const std::string& alias, const std::string& name); |
703 | 56 |
9960
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
57 // Gets the shlib of the currently executing DLD function, if any. |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
58 extern OCTINTERP_API octave_shlib |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
59 get_current_shlib (void); |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
60 |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
61 // This is a convenience class that calls the above function automatically at |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
62 // construction time. When deriving new classes, you can either use it as a field |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
63 // or as a parent (with multiple inheritance). |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
64 |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
65 class octave_auto_shlib : public octave_shlib |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 { |
10641
ed6969880316
preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
67 public: |
9960
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
68 octave_auto_shlib (void) |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
69 : octave_shlib (get_current_shlib ()) { } |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
70 octave_auto_shlib (const octave_shlib& shl) |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
71 : octave_shlib (shl) { } |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
72 }; |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
73 |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
74 extern OCTINTERP_API bool |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
75 defun_isargout (int, int); |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
76 |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
77 extern OCTINTERP_API void |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
78 defun_isargout (int, int, bool *); |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10641
diff
changeset
|
79 |
15398
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
80 #define DECLARE_FUNXX(name, args_decl, nargout_decl) \ |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
81 OCTAVE_EXPORT octave_value_list name (args_decl, nargout_decl) |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
82 |
3743 | 83 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
15398
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
84 DECLARE_FUNXX (name, \ |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
85 const octave_value_list& args_name = octave_value_list (), \ |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
86 int nargout_name = 0) |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
87 |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
88 #define DECLARE_FUNX_NO_DEFAULTS(name, args_name, nargout_name) \ |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
89 DECLARE_FUNXX (name, const octave_value_list& args_name, int nargout_name) |
3743 | 90 |
91 #define DECLARE_FUN(name, args_name, nargout_name) \ | |
92 DECLARE_FUNX (F ## name, args_name, nargout_name) | |
2968 | 93 |
15398
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
94 #define DECLARE_FUN_NO_DEFAULTS(name, args_name, nargout_name) \ |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
95 DECLARE_FUNX_NO_DEFAULTS (F ## name, args_name, nargout_name) |
2e5ba861898f
default arg values for DEFUN functions
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
96 |
3325 | 97 // Define the code that will be used to insert the new function into |
98 // the symbol table. We look for this name instead of the actual | |
3523 | 99 // function so that we can easily install the doc std::string too. |
3325 | 100 |
6323 | 101 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative); |
3325 | 102 |
7336 | 103 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative); |
104 | |
3325 | 105 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
106 DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc) |
5796 | 107 |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
108 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \ |
7336 | 109 extern "C" \ |
110 OCTAVE_EXPORT \ | |
111 octave_function * \ | |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
112 gname (const octave_shlib& shl, bool relative) \ |
7336 | 113 { \ |
114 octave_function *retval = 0; \ | |
115 \ | |
116 check_version (OCTAVE_API_VERSION, name); \ | |
117 \ | |
118 if (! error_state) \ | |
119 { \ | |
10313 | 120 octave_dld_function *fcn = octave_dld_function::create (fname, shl, name, doc); \ |
7336 | 121 \ |
122 if (relative) \ | |
123 fcn->mark_relative (); \ | |
124 \ | |
125 retval = fcn; \ | |
126 } \ | |
127 \ | |
128 return retval; \ | |
3325 | 129 } |
130 | |
3295 | 131 // MAKE_BUILTINS is defined to extract function names and related |
132 // information and create the *.df files that are eventually used to | |
133 // create the builtins.cc file. | |
134 | |
135 #if defined (MAKE_BUILTINS) | |
136 | |
137 // Generate code to install name in the symbol table. The script | |
138 // mkdefs will create a .def file for every .cc file that uses DEFUN, | |
4208 | 139 // or DEFCMD. |
3295 | 140 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
141 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
3295 | 142 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
143 XDEFUN_INTERNAL (name, args_name, nargout_name, doc) \ |
3295 | 144 END_INSTALL_BUILTIN |
145 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
146 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
4234 | 147 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
148 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, doc) \ |
4234 | 149 END_INSTALL_BUILTIN |
150 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
151 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
3743 | 152 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
153 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, doc) \ |
3743 | 154 END_INSTALL_BUILTIN |
155 | |
3364 | 156 // Generate code to install name in the symbol table. The script |
157 // mkdefs will create a .def file for every .cc file that uses | |
158 // DEFUN_DLD. | |
159 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
160 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, doc) \ |
3364 | 161 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
162 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, doc) \ |
3364 | 163 END_INSTALL_BUILTIN |
164 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
165 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
5796 | 166 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
167 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, doc) \ |
5796 | 168 END_INSTALL_BUILTIN |
169 | |
3295 | 170 // Generate code for making another name for an existing function. |
171 | |
172 #define DEFALIAS_INTERNAL(alias, name) \ | |
173 BEGIN_INSTALL_BUILTIN \ | |
174 XDEFALIAS_INTERNAL(alias, name) \ | |
175 END_INSTALL_BUILTIN | |
176 | |
177 #else /* ! MAKE_BUILTINS */ | |
178 | |
179 // Generate the first line of the function definition. This ensures | |
180 // that the internal functions all have the same signature. | |
181 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
182 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
3295 | 183 DECLARE_FUN (name, args_name, nargout_name) |
184 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
185 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
4234 | 186 DECLARE_FUN (name, args_name, nargout_name) |
187 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
188 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
3743 | 189 DECLARE_FUNX (fname, args_name, nargout_name) |
190 | |
3295 | 191 // No definition is required for an alias. |
192 | |
4699 | 193 #define DEFALIAS_INTERNAL(alias, name) |
3295 | 194 |
195 #endif /* ! MAKE_BUILTINS */ | |
196 | |
525 | 197 #endif |