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