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