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