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