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 |
3145
|
43 install_builtin_mapper (octave_mapper *mf); |
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 |
|
77 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
78 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
79 |
|
80 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
81 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
82 |
|
83 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
5796
|
84 DEFINE_FUNX_INSTALLER_FUN3(#name, F ## name, FS ## name, doc, cxx_abi) |
|
85 |
|
86 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, fsname, doc) \ |
|
87 DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, doc, CXX_ABI) |
|
88 |
|
89 #define DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, doc, cxx_abi) \ |
|
90 DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, doc, cxx_abi) |
|
91 |
|
92 #define DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, doc, cxx_abi) \ |
3842
|
93 extern "C" \ |
6109
|
94 OCTAVE_EXPORT \ |
3325
|
95 bool \ |
6323
|
96 fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
3325
|
97 { \ |
7101
|
98 bool retval = true; \ |
|
99 \ |
5796
|
100 check_version (OCTAVE_API_VERSION, name); \ |
7101
|
101 \ |
|
102 if (error_state) \ |
|
103 retval = false; \ |
|
104 else \ |
|
105 install_dld_function (fname, name, shl, doc, false, relative); \ |
|
106 \ |
|
107 return retval; \ |
3325
|
108 } |
|
109 |
3295
|
110 // MAKE_BUILTINS is defined to extract function names and related |
|
111 // information and create the *.df files that are eventually used to |
|
112 // create the builtins.cc file. |
|
113 |
|
114 #if defined (MAKE_BUILTINS) |
|
115 |
|
116 // Generate code to install name in the symbol table. The script |
|
117 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
4208
|
118 // or DEFCMD. |
3295
|
119 |
|
120 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
121 BEGIN_INSTALL_BUILTIN \ |
|
122 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
123 END_INSTALL_BUILTIN |
|
124 |
4234
|
125 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
126 BEGIN_INSTALL_BUILTIN \ |
|
127 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
128 END_INSTALL_BUILTIN |
|
129 |
3743
|
130 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
131 is_text_fcn, doc) \ |
|
132 BEGIN_INSTALL_BUILTIN \ |
3744
|
133 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
134 END_INSTALL_BUILTIN |
|
135 |
3364
|
136 // Generate code to install name in the symbol table. The script |
|
137 // mkdefs will create a .def file for every .cc file that uses |
|
138 // DEFUN_DLD. |
|
139 |
|
140 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
141 BEGIN_INSTALL_BUILTIN \ |
|
142 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
143 END_INSTALL_BUILTIN |
|
144 |
5796
|
145 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, \ |
|
146 is_text_fcn, doc) \ |
|
147 BEGIN_INSTALL_BUILTIN \ |
|
148 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
|
149 END_INSTALL_BUILTIN |
|
150 |
3295
|
151 // Generate code for making another name for an existing function. |
|
152 |
|
153 #define DEFALIAS_INTERNAL(alias, name) \ |
|
154 BEGIN_INSTALL_BUILTIN \ |
|
155 XDEFALIAS_INTERNAL(alias, name) \ |
|
156 END_INSTALL_BUILTIN |
|
157 |
|
158 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
159 d_c_map, c_c_map, lo, hi, \ |
4100
|
160 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
161 BEGIN_INSTALL_BUILTIN \ |
|
162 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
163 d_c_map, c_c_map, lo, hi, \ |
4100
|
164 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
165 END_INSTALL_BUILTIN |
|
166 |
|
167 #else /* ! MAKE_BUILTINS */ |
|
168 |
|
169 // Generate the first line of the function definition. This ensures |
|
170 // that the internal functions all have the same signature. |
|
171 |
|
172 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
173 DECLARE_FUN (name, args_name, nargout_name) |
|
174 |
4234
|
175 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
176 DECLARE_FUN (name, args_name, nargout_name) |
|
177 |
3743
|
178 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
179 is_text_fcn, doc) \ |
|
180 DECLARE_FUNX (fname, args_name, nargout_name) |
|
181 |
3295
|
182 // No definition is required for an alias. |
|
183 |
4699
|
184 #define DEFALIAS_INTERNAL(alias, name) |
3295
|
185 |
2968
|
186 // How mapper functions are actually installed. |
|
187 |
5775
|
188 // FIXME -- Really want to avoid the following casts, since |
3564
|
189 // (as always with casts) it may mask some real errors... |
|
190 |
3249
|
191 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
192 d_c_map, c_c_map, lo, hi, \ |
4100
|
193 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
2968
|
194 install_builtin_mapper \ |
3564
|
195 (new octave_mapper \ |
5261
|
196 (ch_map, d_b_map, c_b_map, d_d_map, d_c_map, c_c_map, \ |
4165
|
197 lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name, doc)) |
525
|
198 |
3295
|
199 #endif /* ! MAKE_BUILTINS */ |
|
200 |
525
|
201 #endif |
|
202 |
|
203 /* |
|
204 ;;; Local Variables: *** |
|
205 ;;; mode: C++ *** |
|
206 ;;; End: *** |
|
207 */ |