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, |
|
45 const std::string& doc, bool is_text_fcn = false); |
2968
|
46 |
|
47 extern void |
3523
|
48 install_builtin_variable (const std::string& n, const octave_value& v, |
3258
|
49 bool p, bool e, |
3145
|
50 symbol_record::change_function chg_fcn, |
3523
|
51 const std::string& h); |
2968
|
52 |
|
53 extern void |
3523
|
54 install_builtin_constant (const std::string& n, const octave_value& v, |
|
55 bool p, const std::string& h); |
3258
|
56 |
|
57 extern void |
3523
|
58 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
59 const octave_shlib& shl, |
3523
|
60 const std::string& doc, bool is_text_fcn = false); |
703
|
61 |
3325
|
62 extern void |
3523
|
63 alias_builtin (const std::string& alias, const std::string& name); |
703
|
64 |
3743
|
65 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
2968
|
66 octave_value_list \ |
3743
|
67 name (const octave_value_list& args_name, int nargout_name) |
|
68 |
|
69 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
70 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
71 |
3325
|
72 // Define the code that will be used to insert the new function into |
|
73 // the symbol table. We look for this name instead of the actual |
3523
|
74 // function so that we can easily install the doc std::string too. |
3325
|
75 |
|
76 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&); |
|
77 |
|
78 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
79 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
80 |
|
81 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
82 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
83 |
|
84 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
|
85 extern "C" \ |
3325
|
86 bool \ |
3842
|
87 FS ## name ## _ ## cxx_abi (const octave_shlib& shl) \ |
3325
|
88 { \ |
|
89 check_version (OCTAVE_VERSION, #name); \ |
|
90 install_dld_function (F ## name, #name, shl, doc); \ |
|
91 return error_state ? false : true; \ |
|
92 } |
|
93 |
3842
|
94 |
3295
|
95 // MAKE_BUILTINS is defined to extract function names and related |
|
96 // information and create the *.df files that are eventually used to |
|
97 // create the builtins.cc file. |
|
98 |
|
99 #if defined (MAKE_BUILTINS) |
|
100 |
|
101 // Generate code to install name in the symbol table. The script |
|
102 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
3364
|
103 // or DEFUN_TEXT. |
3295
|
104 |
|
105 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
106 BEGIN_INSTALL_BUILTIN \ |
|
107 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
108 END_INSTALL_BUILTIN |
|
109 |
3743
|
110 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
111 is_text_fcn, doc) \ |
|
112 BEGIN_INSTALL_BUILTIN \ |
3744
|
113 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
114 END_INSTALL_BUILTIN |
|
115 |
3364
|
116 // Generate code to install name in the symbol table. The script |
|
117 // mkdefs will create a .def file for every .cc file that uses |
|
118 // DEFUN_DLD. |
|
119 |
|
120 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
121 BEGIN_INSTALL_BUILTIN \ |
|
122 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
123 END_INSTALL_BUILTIN |
|
124 |
3295
|
125 // Generate code for making another name for an existing function. |
|
126 |
|
127 #define DEFALIAS_INTERNAL(alias, name) \ |
|
128 BEGIN_INSTALL_BUILTIN \ |
|
129 XDEFALIAS_INTERNAL(alias, name) \ |
|
130 END_INSTALL_BUILTIN |
|
131 |
|
132 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
133 BEGIN_INSTALL_BUILTIN \ |
|
134 XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
135 END_INSTALL_BUILTIN |
|
136 |
3321
|
137 #define DEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
138 BEGIN_INSTALL_BUILTIN \ |
3321
|
139 XDEFCONST_INTERNAL(name, defn, doc) \ |
|
140 END_INSTALL_BUILTIN |
|
141 |
|
142 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
143 BEGIN_INSTALL_BUILTIN \ |
|
144 XDEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
145 END_INSTALL_BUILTIN |
|
146 |
|
147 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
148 d_c_map, c_c_map, lo, hi, \ |
|
149 can_ret_cmplx_for_real, doc) \ |
|
150 BEGIN_INSTALL_BUILTIN \ |
|
151 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
152 d_c_map, c_c_map, lo, hi, \ |
|
153 can_ret_cmplx_for_real, doc) \ |
|
154 END_INSTALL_BUILTIN |
|
155 |
|
156 #else /* ! MAKE_BUILTINS */ |
|
157 |
|
158 // Generate the first line of the function definition. This ensures |
|
159 // that the internal functions all have the same signature. |
|
160 |
|
161 #define DEFUN_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 |
|
170 #define DEFALIAS_INTERNAL(name, alias) |
|
171 |
2968
|
172 // How builtin variables are actually installed. |
|
173 |
3258
|
174 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
175 install_builtin_variable (name, octave_value (defn), protect, \ |
|
176 (chg_fcn != 0), chg_fcn, doc) |
|
177 |
|
178 // How builtin variables are actually installed. |
|
179 |
3321
|
180 #define INSTALL_CONST(name, sname, defn, protect, doc) \ |
3258
|
181 install_builtin_constant (name, octave_value (defn), protect, doc) |
2968
|
182 |
3321
|
183 #define DEFCONST_INTERNAL(name, defn, doc) \ |
4011
|
184 INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); |
3321
|
185 |
|
186 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
4011
|
187 INSTALL_CONST (name, sname, defn, false, doc); |
3321
|
188 |
2968
|
189 // How mapper functions are actually installed. |
|
190 |
3564
|
191 // XXX FIXME XXX -- Really want to avoid the following casts, since |
|
192 // (as always with casts) it may mask some real errors... |
|
193 |
3249
|
194 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
195 d_c_map, c_c_map, lo, hi, \ |
|
196 can_ret_cmplx_for_real, doc) \ |
2968
|
197 install_builtin_mapper \ |
3564
|
198 (new octave_mapper \ |
|
199 (X_CAST (octave_mapper::ch_mapper, ch_map), \ |
|
200 X_CAST (octave_mapper::d_b_mapper, d_b_map), \ |
|
201 X_CAST (octave_mapper::c_b_mapper, c_b_map), \ |
|
202 X_CAST (octave_mapper::d_d_mapper, d_d_map), \ |
|
203 X_CAST (octave_mapper::d_c_mapper, d_c_map), \ |
|
204 X_CAST (octave_mapper::c_c_mapper, c_c_map), \ |
|
205 lo, hi, can_ret_cmplx_for_real, #name)) |
525
|
206 |
3295
|
207 #endif /* ! MAKE_BUILTINS */ |
|
208 |
525
|
209 #endif |
|
210 |
|
211 /* |
|
212 ;;; Local Variables: *** |
|
213 ;;; mode: C++ *** |
|
214 ;;; End: *** |
|
215 */ |