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