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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
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 |
3523
|
36 extern void print_usage (const std::string& nm, bool just_usage = false); |
3014
|
37 |
3523
|
38 extern void check_version (const std::string& version, const std::string& fcn); |
3015
|
39 |
3145
|
40 extern void |
|
41 install_builtin_mapper (octave_mapper *mf); |
2968
|
42 |
|
43 extern void |
3523
|
44 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
45 const std::string& doc, bool is_text_fcn = false, |
|
46 bool can_hide_function = true); |
2968
|
47 |
|
48 extern void |
3523
|
49 install_builtin_variable (const std::string& n, const octave_value& v, |
3258
|
50 bool p, bool e, |
3145
|
51 symbol_record::change_function chg_fcn, |
3523
|
52 const std::string& h); |
2968
|
53 |
|
54 extern void |
3523
|
55 install_builtin_constant (const std::string& n, const octave_value& v, |
|
56 bool p, const std::string& h); |
3258
|
57 |
|
58 extern void |
3523
|
59 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
60 const octave_shlib& shl, |
3523
|
61 const std::string& doc, bool is_text_fcn = false); |
703
|
62 |
3325
|
63 extern void |
3523
|
64 alias_builtin (const std::string& alias, const std::string& name); |
703
|
65 |
3743
|
66 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
2968
|
67 octave_value_list \ |
3743
|
68 name (const octave_value_list& args_name, int nargout_name) |
|
69 |
|
70 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
71 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
72 |
3325
|
73 // Define the code that will be used to insert the new function into |
|
74 // the symbol table. We look for this name instead of the actual |
3523
|
75 // function so that we can easily install the doc std::string too. |
3325
|
76 |
|
77 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&); |
|
78 |
|
79 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
80 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
81 |
|
82 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
83 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
84 |
|
85 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
|
86 extern "C" \ |
3325
|
87 bool \ |
3842
|
88 FS ## name ## _ ## cxx_abi (const octave_shlib& shl) \ |
3325
|
89 { \ |
4448
|
90 check_version (OCTAVE_API_VERSION, #name); \ |
3325
|
91 install_dld_function (F ## name, #name, shl, doc); \ |
|
92 return error_state ? false : true; \ |
|
93 } |
|
94 |
3842
|
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 |
3295
|
131 // Generate code for making another name for an existing function. |
|
132 |
|
133 #define DEFALIAS_INTERNAL(alias, name) \ |
|
134 BEGIN_INSTALL_BUILTIN \ |
|
135 XDEFALIAS_INTERNAL(alias, name) \ |
|
136 END_INSTALL_BUILTIN |
|
137 |
|
138 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
139 BEGIN_INSTALL_BUILTIN \ |
|
140 XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
141 END_INSTALL_BUILTIN |
|
142 |
3321
|
143 #define DEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
144 BEGIN_INSTALL_BUILTIN \ |
3321
|
145 XDEFCONST_INTERNAL(name, defn, doc) \ |
|
146 END_INSTALL_BUILTIN |
|
147 |
|
148 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
149 BEGIN_INSTALL_BUILTIN \ |
|
150 XDEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
151 END_INSTALL_BUILTIN |
|
152 |
|
153 #define DEFUN_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 BEGIN_INSTALL_BUILTIN \ |
|
157 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
158 d_c_map, c_c_map, lo, hi, \ |
4100
|
159 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
160 END_INSTALL_BUILTIN |
|
161 |
|
162 #else /* ! MAKE_BUILTINS */ |
|
163 |
|
164 // Generate the first line of the function definition. This ensures |
|
165 // that the internal functions all have the same signature. |
|
166 |
|
167 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
168 DECLARE_FUN (name, args_name, nargout_name) |
|
169 |
4234
|
170 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
171 DECLARE_FUN (name, args_name, nargout_name) |
|
172 |
3743
|
173 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
174 is_text_fcn, doc) \ |
|
175 DECLARE_FUNX (fname, args_name, nargout_name) |
|
176 |
3295
|
177 // No definition is required for an alias. |
|
178 |
|
179 #define DEFALIAS_INTERNAL(name, alias) |
|
180 |
2968
|
181 // How builtin variables are actually installed. |
|
182 |
3258
|
183 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
184 install_builtin_variable (name, octave_value (defn), protect, \ |
|
185 (chg_fcn != 0), chg_fcn, doc) |
|
186 |
|
187 // How builtin variables are actually installed. |
|
188 |
3321
|
189 #define INSTALL_CONST(name, sname, defn, protect, doc) \ |
3258
|
190 install_builtin_constant (name, octave_value (defn), protect, doc) |
2968
|
191 |
3321
|
192 #define DEFCONST_INTERNAL(name, defn, doc) \ |
4011
|
193 INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); |
3321
|
194 |
|
195 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
4011
|
196 INSTALL_CONST (name, sname, defn, false, doc); |
3321
|
197 |
2968
|
198 // How mapper functions are actually installed. |
|
199 |
3564
|
200 // XXX FIXME XXX -- Really want to avoid the following casts, since |
|
201 // (as always with casts) it may mask some real errors... |
|
202 |
3249
|
203 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
204 d_c_map, c_c_map, lo, hi, \ |
4100
|
205 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
2968
|
206 install_builtin_mapper \ |
3564
|
207 (new octave_mapper \ |
|
208 (X_CAST (octave_mapper::ch_mapper, ch_map), \ |
|
209 X_CAST (octave_mapper::d_b_mapper, d_b_map), \ |
|
210 X_CAST (octave_mapper::c_b_mapper, c_b_map), \ |
|
211 X_CAST (octave_mapper::d_d_mapper, d_d_map), \ |
|
212 X_CAST (octave_mapper::d_c_mapper, d_c_map), \ |
|
213 X_CAST (octave_mapper::c_c_mapper, c_c_map), \ |
4165
|
214 lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name, doc)) |
525
|
215 |
3295
|
216 #endif /* ! MAKE_BUILTINS */ |
|
217 |
525
|
218 #endif |
|
219 |
|
220 /* |
|
221 ;;; Local Variables: *** |
|
222 ;;; mode: C++ *** |
|
223 ;;; End: *** |
|
224 */ |