525
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
|
4 2003, 2004, 2005, 2006, 2007 John W. Eaton |
525
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
525
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
525
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_defun_int_h) |
|
25 #define octave_defun_int_h 1 |
|
26 |
2968
|
27 #include <string> |
|
28 |
3145
|
29 #include "ov-builtin.h" |
3325
|
30 #include "ov-dld-fcn.h" |
3145
|
31 #include "ov-mapper.h" |
|
32 #include "symtab.h" |
3015
|
33 #include "version.h" |
|
34 |
2968
|
35 class octave_value; |
|
36 |
6109
|
37 extern OCTINTERP_API void print_usage (void); |
|
38 extern OCTINTERP_API void print_usage (const std::string&) GCC_ATTR_DEPRECATED; |
3014
|
39 |
6109
|
40 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn); |
3015
|
41 |
6109
|
42 extern OCTINTERP_API void |
7336
|
43 install_builtin_mapper (octave_mapper *mf, const std::string& name); |
2968
|
44 |
6109
|
45 extern OCTINTERP_API void |
3523
|
46 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
47 const std::string& doc, bool is_text_fcn = false, |
|
48 bool can_hide_function = true); |
2968
|
49 |
6109
|
50 extern OCTINTERP_API void |
3523
|
51 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
52 const octave_shlib& shl, |
6323
|
53 const std::string& doc, bool is_text_fcn = false, |
|
54 bool relative = false); |
703
|
55 |
6109
|
56 extern OCTINTERP_API void |
5864
|
57 install_mex_function (void *fptr, bool fmex, const std::string& name, |
6323
|
58 const octave_shlib& shl, bool is_text_fcn = false, |
|
59 bool relative = false); |
5864
|
60 |
6109
|
61 extern OCTINTERP_API void |
3523
|
62 alias_builtin (const std::string& alias, const std::string& name); |
703
|
63 |
3743
|
64 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
6109
|
65 OCTAVE_EXPORT octave_value_list \ |
3743
|
66 name (const octave_value_list& args_name, int nargout_name) |
|
67 |
|
68 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
69 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
70 |
3325
|
71 // Define the code that will be used to insert the new function into |
|
72 // the symbol table. We look for this name instead of the actual |
3523
|
73 // function so that we can easily install the doc std::string too. |
3325
|
74 |
6323
|
75 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative); |
3325
|
76 |
7336
|
77 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative); |
|
78 |
3325
|
79 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
80 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
81 |
|
82 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
83 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
84 |
|
85 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
7336
|
86 DEFINE_FUNX_INSTALLER_FUN3(#name, F ## name, FS ## name, G ## name, doc, cxx_abi) |
5796
|
87 |
7336
|
88 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, fsname, gname, doc) \ |
|
89 DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, CXX_ABI) |
5796
|
90 |
7336
|
91 #define DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, cxx_abi) \ |
|
92 DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi) |
5796
|
93 |
7336
|
94 #define DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi) \ |
3842
|
95 extern "C" \ |
6109
|
96 OCTAVE_EXPORT \ |
3325
|
97 bool \ |
6323
|
98 fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
3325
|
99 { \ |
7101
|
100 bool retval = true; \ |
|
101 \ |
5796
|
102 check_version (OCTAVE_API_VERSION, name); \ |
7101
|
103 \ |
|
104 if (error_state) \ |
|
105 retval = false; \ |
|
106 else \ |
|
107 install_dld_function (fname, name, shl, doc, false, relative); \ |
|
108 \ |
|
109 return retval; \ |
7336
|
110 } \ |
|
111 \ |
|
112 extern "C" \ |
|
113 OCTAVE_EXPORT \ |
|
114 octave_function * \ |
|
115 gname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
|
116 { \ |
|
117 octave_function *retval = 0; \ |
|
118 \ |
|
119 check_version (OCTAVE_API_VERSION, name); \ |
|
120 \ |
|
121 if (! error_state) \ |
|
122 { \ |
|
123 octave_dld_function *fcn = new octave_dld_function (fname, shl, name, doc); \ |
|
124 \ |
|
125 if (relative) \ |
|
126 fcn->mark_relative (); \ |
|
127 \ |
|
128 retval = fcn; \ |
|
129 } \ |
|
130 \ |
|
131 return retval; \ |
3325
|
132 } |
|
133 |
3295
|
134 // MAKE_BUILTINS is defined to extract function names and related |
|
135 // information and create the *.df files that are eventually used to |
|
136 // create the builtins.cc file. |
|
137 |
|
138 #if defined (MAKE_BUILTINS) |
|
139 |
|
140 // Generate code to install name in the symbol table. The script |
|
141 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
4208
|
142 // or DEFCMD. |
3295
|
143 |
|
144 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
145 BEGIN_INSTALL_BUILTIN \ |
|
146 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
147 END_INSTALL_BUILTIN |
|
148 |
4234
|
149 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
150 BEGIN_INSTALL_BUILTIN \ |
|
151 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
152 END_INSTALL_BUILTIN |
|
153 |
3743
|
154 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
155 is_text_fcn, doc) \ |
|
156 BEGIN_INSTALL_BUILTIN \ |
3744
|
157 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
158 END_INSTALL_BUILTIN |
|
159 |
3364
|
160 // Generate code to install name in the symbol table. The script |
|
161 // mkdefs will create a .def file for every .cc file that uses |
|
162 // DEFUN_DLD. |
|
163 |
|
164 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
165 BEGIN_INSTALL_BUILTIN \ |
|
166 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
167 END_INSTALL_BUILTIN |
|
168 |
5796
|
169 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, \ |
|
170 is_text_fcn, doc) \ |
|
171 BEGIN_INSTALL_BUILTIN \ |
|
172 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
|
173 END_INSTALL_BUILTIN |
|
174 |
3295
|
175 // Generate code for making another name for an existing function. |
|
176 |
|
177 #define DEFALIAS_INTERNAL(alias, name) \ |
|
178 BEGIN_INSTALL_BUILTIN \ |
|
179 XDEFALIAS_INTERNAL(alias, name) \ |
|
180 END_INSTALL_BUILTIN |
|
181 |
|
182 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
183 d_c_map, c_c_map, lo, hi, \ |
4100
|
184 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
185 BEGIN_INSTALL_BUILTIN \ |
|
186 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
187 d_c_map, c_c_map, lo, hi, \ |
4100
|
188 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
189 END_INSTALL_BUILTIN |
|
190 |
|
191 #else /* ! MAKE_BUILTINS */ |
|
192 |
|
193 // Generate the first line of the function definition. This ensures |
|
194 // that the internal functions all have the same signature. |
|
195 |
|
196 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
197 DECLARE_FUN (name, args_name, nargout_name) |
|
198 |
4234
|
199 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
200 DECLARE_FUN (name, args_name, nargout_name) |
|
201 |
3743
|
202 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
203 is_text_fcn, doc) \ |
|
204 DECLARE_FUNX (fname, args_name, nargout_name) |
|
205 |
3295
|
206 // No definition is required for an alias. |
|
207 |
4699
|
208 #define DEFALIAS_INTERNAL(alias, name) |
3295
|
209 |
2968
|
210 // How mapper functions are actually installed. |
|
211 |
5775
|
212 // FIXME -- Really want to avoid the following casts, since |
3564
|
213 // (as always with casts) it may mask some real errors... |
|
214 |
3249
|
215 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
216 d_c_map, c_c_map, lo, hi, \ |
4100
|
217 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
2968
|
218 install_builtin_mapper \ |
3564
|
219 (new octave_mapper \ |
7336
|
220 (ch_map, d_b_map, c_b_map, d_d_map, d_c_map, c_c_map, \ |
|
221 lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name, doc), \ |
|
222 #name) |
525
|
223 |
3295
|
224 #endif /* ! MAKE_BUILTINS */ |
|
225 |
525
|
226 #endif |
|
227 |
|
228 /* |
|
229 ;;; Local Variables: *** |
|
230 ;;; mode: C++ *** |
|
231 ;;; End: *** |
|
232 */ |