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) \ |
|
79 bool \ |
|
80 FS ## name (const octave_shlib& shl) \ |
|
81 { \ |
|
82 check_version (OCTAVE_VERSION, #name); \ |
|
83 install_dld_function (F ## name, #name, shl, doc); \ |
|
84 return error_state ? false : true; \ |
|
85 } |
|
86 |
3295
|
87 // MAKE_BUILTINS is defined to extract function names and related |
|
88 // information and create the *.df files that are eventually used to |
|
89 // create the builtins.cc file. |
|
90 |
|
91 #if defined (MAKE_BUILTINS) |
|
92 |
|
93 // Generate code to install name in the symbol table. The script |
|
94 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
3364
|
95 // or DEFUN_TEXT. |
3295
|
96 |
|
97 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
98 BEGIN_INSTALL_BUILTIN \ |
|
99 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
100 END_INSTALL_BUILTIN |
|
101 |
3743
|
102 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
103 is_text_fcn, doc) \ |
|
104 BEGIN_INSTALL_BUILTIN \ |
3744
|
105 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
106 END_INSTALL_BUILTIN |
|
107 |
3364
|
108 // Generate code to install name in the symbol table. The script |
|
109 // mkdefs will create a .def file for every .cc file that uses |
|
110 // DEFUN_DLD. |
|
111 |
|
112 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
113 BEGIN_INSTALL_BUILTIN \ |
|
114 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
115 END_INSTALL_BUILTIN |
|
116 |
3295
|
117 // Generate code for making another name for an existing function. |
|
118 |
|
119 #define DEFALIAS_INTERNAL(alias, name) \ |
|
120 BEGIN_INSTALL_BUILTIN \ |
|
121 XDEFALIAS_INTERNAL(alias, name) \ |
|
122 END_INSTALL_BUILTIN |
|
123 |
|
124 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
125 BEGIN_INSTALL_BUILTIN \ |
|
126 XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
127 END_INSTALL_BUILTIN |
|
128 |
3321
|
129 #define DEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
130 BEGIN_INSTALL_BUILTIN \ |
3321
|
131 XDEFCONST_INTERNAL(name, defn, doc) \ |
|
132 END_INSTALL_BUILTIN |
|
133 |
|
134 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
135 BEGIN_INSTALL_BUILTIN \ |
|
136 XDEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
137 END_INSTALL_BUILTIN |
|
138 |
|
139 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
140 d_c_map, c_c_map, lo, hi, \ |
|
141 can_ret_cmplx_for_real, doc) \ |
|
142 BEGIN_INSTALL_BUILTIN \ |
|
143 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
144 d_c_map, c_c_map, lo, hi, \ |
|
145 can_ret_cmplx_for_real, doc) \ |
|
146 END_INSTALL_BUILTIN |
|
147 |
|
148 #else /* ! MAKE_BUILTINS */ |
|
149 |
|
150 // Generate the first line of the function definition. This ensures |
|
151 // that the internal functions all have the same signature. |
|
152 |
|
153 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
154 DECLARE_FUN (name, args_name, nargout_name) |
|
155 |
3743
|
156 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
157 is_text_fcn, doc) \ |
|
158 DECLARE_FUNX (fname, args_name, nargout_name) |
|
159 |
3295
|
160 // No definition is required for an alias. |
|
161 |
|
162 #define DEFALIAS_INTERNAL(name, alias) |
|
163 |
2968
|
164 // How builtin variables are actually installed. |
|
165 |
3258
|
166 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
167 install_builtin_variable (name, octave_value (defn), protect, \ |
|
168 (chg_fcn != 0), chg_fcn, doc) |
|
169 |
|
170 // How builtin variables are actually installed. |
|
171 |
3321
|
172 #define INSTALL_CONST(name, sname, defn, protect, doc) \ |
3258
|
173 install_builtin_constant (name, octave_value (defn), protect, doc) |
2968
|
174 |
3528
|
175 #define UNDERSCORIFY(name) \ |
3741
|
176 "__" name "__" |
3528
|
177 |
3321
|
178 #define DEFCONST_INTERNAL(name, defn, doc) \ |
|
179 INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); \ |
3528
|
180 INSTALL_CONST (UNDERSCORIFY (#name), XSBV_ ## name, defn, true, doc) |
3321
|
181 |
|
182 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
183 INSTALL_CONST (name, sname, defn, false, doc); \ |
3528
|
184 INSTALL_CONST (UNDERSCORIFY (name), X ## sname, defn, true, doc) |
3321
|
185 |
2968
|
186 // How mapper functions are actually installed. |
|
187 |
3564
|
188 // XXX FIXME XXX -- Really want to avoid the following casts, since |
|
189 // (as always with casts) it may mask some real errors... |
|
190 |
3249
|
191 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
192 d_c_map, c_c_map, lo, hi, \ |
|
193 can_ret_cmplx_for_real, doc) \ |
2968
|
194 install_builtin_mapper \ |
3564
|
195 (new octave_mapper \ |
|
196 (X_CAST (octave_mapper::ch_mapper, ch_map), \ |
|
197 X_CAST (octave_mapper::d_b_mapper, d_b_map), \ |
|
198 X_CAST (octave_mapper::c_b_mapper, c_b_map), \ |
|
199 X_CAST (octave_mapper::d_d_mapper, d_d_map), \ |
|
200 X_CAST (octave_mapper::d_c_mapper, d_c_map), \ |
|
201 X_CAST (octave_mapper::c_c_mapper, c_c_map), \ |
|
202 lo, hi, can_ret_cmplx_for_real, #name)) |
525
|
203 |
3295
|
204 #endif /* ! MAKE_BUILTINS */ |
|
205 |
525
|
206 #endif |
|
207 |
|
208 /* |
|
209 ;;; Local Variables: *** |
|
210 ;;; mode: C++ *** |
|
211 ;;; End: *** |
|
212 */ |