525
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 "ov-mapper.h" |
|
31 #include "symtab.h" |
3015
|
32 #include "version.h" |
|
33 |
2968
|
34 class octave_value; |
|
35 |
6109
|
36 extern OCTINTERP_API void print_usage (void); |
|
37 extern OCTINTERP_API void print_usage (const std::string&) GCC_ATTR_DEPRECATED; |
3014
|
38 |
6109
|
39 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn); |
3015
|
40 |
6109
|
41 extern OCTINTERP_API void |
3145
|
42 install_builtin_mapper (octave_mapper *mf); |
2968
|
43 |
6109
|
44 extern OCTINTERP_API void |
3523
|
45 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
46 const std::string& doc, bool is_text_fcn = false, |
|
47 bool can_hide_function = true); |
2968
|
48 |
6109
|
49 extern OCTINTERP_API void |
3523
|
50 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
51 const octave_shlib& shl, |
6323
|
52 const std::string& doc, bool is_text_fcn = false, |
|
53 bool relative = false); |
703
|
54 |
6109
|
55 extern OCTINTERP_API void |
5864
|
56 install_mex_function (void *fptr, bool fmex, const std::string& name, |
6323
|
57 const octave_shlib& shl, bool is_text_fcn = false, |
|
58 bool relative = false); |
5864
|
59 |
6109
|
60 extern OCTINTERP_API void |
3523
|
61 alias_builtin (const std::string& alias, const std::string& name); |
703
|
62 |
3743
|
63 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
6109
|
64 OCTAVE_EXPORT octave_value_list \ |
3743
|
65 name (const octave_value_list& args_name, int nargout_name) |
|
66 |
|
67 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
68 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
69 |
3325
|
70 // Define the code that will be used to insert the new function into |
|
71 // the symbol table. We look for this name instead of the actual |
3523
|
72 // function so that we can easily install the doc std::string too. |
3325
|
73 |
6323
|
74 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative); |
3325
|
75 |
|
76 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
77 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
78 |
|
79 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
80 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
81 |
|
82 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
5796
|
83 DEFINE_FUNX_INSTALLER_FUN3(#name, F ## name, FS ## name, doc, cxx_abi) |
|
84 |
|
85 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, fsname, doc) \ |
|
86 DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, doc, CXX_ABI) |
|
87 |
|
88 #define DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, doc, cxx_abi) \ |
|
89 DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, doc, cxx_abi) |
|
90 |
|
91 #define DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, doc, cxx_abi) \ |
3842
|
92 extern "C" \ |
6109
|
93 OCTAVE_EXPORT \ |
3325
|
94 bool \ |
6323
|
95 fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
3325
|
96 { \ |
5796
|
97 check_version (OCTAVE_API_VERSION, name); \ |
6323
|
98 install_dld_function (fname, name, shl, doc, false, relative); \ |
3325
|
99 return error_state ? false : true; \ |
|
100 } |
|
101 |
3295
|
102 // MAKE_BUILTINS is defined to extract function names and related |
|
103 // information and create the *.df files that are eventually used to |
|
104 // create the builtins.cc file. |
|
105 |
|
106 #if defined (MAKE_BUILTINS) |
|
107 |
|
108 // Generate code to install name in the symbol table. The script |
|
109 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
4208
|
110 // or DEFCMD. |
3295
|
111 |
|
112 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
113 BEGIN_INSTALL_BUILTIN \ |
|
114 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
115 END_INSTALL_BUILTIN |
|
116 |
4234
|
117 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
118 BEGIN_INSTALL_BUILTIN \ |
|
119 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
120 END_INSTALL_BUILTIN |
|
121 |
3743
|
122 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
123 is_text_fcn, doc) \ |
|
124 BEGIN_INSTALL_BUILTIN \ |
3744
|
125 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
126 END_INSTALL_BUILTIN |
|
127 |
3364
|
128 // Generate code to install name in the symbol table. The script |
|
129 // mkdefs will create a .def file for every .cc file that uses |
|
130 // DEFUN_DLD. |
|
131 |
|
132 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
133 BEGIN_INSTALL_BUILTIN \ |
|
134 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
135 END_INSTALL_BUILTIN |
|
136 |
5796
|
137 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, \ |
|
138 is_text_fcn, doc) \ |
|
139 BEGIN_INSTALL_BUILTIN \ |
|
140 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
|
141 END_INSTALL_BUILTIN |
|
142 |
3295
|
143 // Generate code for making another name for an existing function. |
|
144 |
|
145 #define DEFALIAS_INTERNAL(alias, name) \ |
|
146 BEGIN_INSTALL_BUILTIN \ |
|
147 XDEFALIAS_INTERNAL(alias, name) \ |
|
148 END_INSTALL_BUILTIN |
|
149 |
|
150 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
151 d_c_map, c_c_map, lo, hi, \ |
4100
|
152 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
153 BEGIN_INSTALL_BUILTIN \ |
|
154 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
155 d_c_map, c_c_map, lo, hi, \ |
4100
|
156 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
157 END_INSTALL_BUILTIN |
|
158 |
|
159 #else /* ! MAKE_BUILTINS */ |
|
160 |
|
161 // Generate the first line of the function definition. This ensures |
|
162 // that the internal functions all have the same signature. |
|
163 |
|
164 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
165 DECLARE_FUN (name, args_name, nargout_name) |
|
166 |
4234
|
167 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
168 DECLARE_FUN (name, args_name, nargout_name) |
|
169 |
3743
|
170 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
171 is_text_fcn, doc) \ |
|
172 DECLARE_FUNX (fname, args_name, nargout_name) |
|
173 |
3295
|
174 // No definition is required for an alias. |
|
175 |
4699
|
176 #define DEFALIAS_INTERNAL(alias, name) |
3295
|
177 |
2968
|
178 // How mapper functions are actually installed. |
|
179 |
5775
|
180 // FIXME -- Really want to avoid the following casts, since |
3564
|
181 // (as always with casts) it may mask some real errors... |
|
182 |
3249
|
183 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
184 d_c_map, c_c_map, lo, hi, \ |
4100
|
185 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
2968
|
186 install_builtin_mapper \ |
3564
|
187 (new octave_mapper \ |
5261
|
188 (ch_map, d_b_map, c_b_map, d_d_map, d_c_map, c_c_map, \ |
4165
|
189 lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name, doc)) |
525
|
190 |
3295
|
191 #endif /* ! MAKE_BUILTINS */ |
|
192 |
525
|
193 #endif |
|
194 |
|
195 /* |
|
196 ;;; Local Variables: *** |
|
197 ;;; mode: C++ *** |
|
198 ;;; End: *** |
|
199 */ |