525
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
|
4 2003, 2004, 2005, 2006, 2007 John W. Eaton |
525
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
525
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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 "symtab.h" |
3015
|
32 #include "version.h" |
|
33 |
2968
|
34 class octave_value; |
|
35 |
6109
|
36 extern OCTINTERP_API void print_usage (void); |
|
37 extern OCTINTERP_API void print_usage (const std::string&) GCC_ATTR_DEPRECATED; |
3014
|
38 |
6109
|
39 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn); |
3015
|
40 |
6109
|
41 extern OCTINTERP_API void |
3523
|
42 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
43 const std::string& doc, bool is_text_fcn = false, |
|
44 bool can_hide_function = true); |
2968
|
45 |
6109
|
46 extern OCTINTERP_API void |
3523
|
47 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
48 const octave_shlib& shl, |
6323
|
49 const std::string& doc, bool is_text_fcn = false, |
|
50 bool relative = false); |
703
|
51 |
6109
|
52 extern OCTINTERP_API void |
5864
|
53 install_mex_function (void *fptr, bool fmex, const std::string& name, |
6323
|
54 const octave_shlib& shl, bool is_text_fcn = false, |
|
55 bool relative = false); |
5864
|
56 |
6109
|
57 extern OCTINTERP_API void |
3523
|
58 alias_builtin (const std::string& alias, const std::string& name); |
703
|
59 |
3743
|
60 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
6109
|
61 OCTAVE_EXPORT octave_value_list \ |
3743
|
62 name (const octave_value_list& args_name, int nargout_name) |
|
63 |
|
64 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
65 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
66 |
3325
|
67 // Define the code that will be used to insert the new function into |
|
68 // the symbol table. We look for this name instead of the actual |
3523
|
69 // function so that we can easily install the doc std::string too. |
3325
|
70 |
6323
|
71 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative); |
3325
|
72 |
7336
|
73 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative); |
|
74 |
3325
|
75 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
76 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
77 |
|
78 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
79 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
80 |
|
81 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
7336
|
82 DEFINE_FUNX_INSTALLER_FUN3(#name, F ## name, FS ## name, G ## name, doc, cxx_abi) |
5796
|
83 |
7336
|
84 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, fsname, gname, doc) \ |
|
85 DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, CXX_ABI) |
5796
|
86 |
7336
|
87 #define DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, cxx_abi) \ |
|
88 DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi) |
5796
|
89 |
7336
|
90 #define DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi) \ |
3842
|
91 extern "C" \ |
6109
|
92 OCTAVE_EXPORT \ |
3325
|
93 bool \ |
6323
|
94 fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
3325
|
95 { \ |
7101
|
96 bool retval = true; \ |
|
97 \ |
5796
|
98 check_version (OCTAVE_API_VERSION, name); \ |
7101
|
99 \ |
|
100 if (error_state) \ |
|
101 retval = false; \ |
|
102 else \ |
|
103 install_dld_function (fname, name, shl, doc, false, relative); \ |
|
104 \ |
|
105 return retval; \ |
7336
|
106 } \ |
|
107 \ |
|
108 extern "C" \ |
|
109 OCTAVE_EXPORT \ |
|
110 octave_function * \ |
|
111 gname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ |
|
112 { \ |
|
113 octave_function *retval = 0; \ |
|
114 \ |
|
115 check_version (OCTAVE_API_VERSION, name); \ |
|
116 \ |
|
117 if (! error_state) \ |
|
118 { \ |
7349
|
119 octave_dld_function *fcn = octave_dld_function::create (fname, shl, name, doc); \ |
7336
|
120 \ |
|
121 if (relative) \ |
|
122 fcn->mark_relative (); \ |
|
123 \ |
|
124 retval = fcn; \ |
|
125 } \ |
|
126 \ |
|
127 return retval; \ |
3325
|
128 } |
|
129 |
3295
|
130 // MAKE_BUILTINS is defined to extract function names and related |
|
131 // information and create the *.df files that are eventually used to |
|
132 // create the builtins.cc file. |
|
133 |
|
134 #if defined (MAKE_BUILTINS) |
|
135 |
|
136 // Generate code to install name in the symbol table. The script |
|
137 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
4208
|
138 // or DEFCMD. |
3295
|
139 |
|
140 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
141 BEGIN_INSTALL_BUILTIN \ |
|
142 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
143 END_INSTALL_BUILTIN |
|
144 |
4234
|
145 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
146 BEGIN_INSTALL_BUILTIN \ |
|
147 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
148 END_INSTALL_BUILTIN |
|
149 |
3743
|
150 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
151 is_text_fcn, doc) \ |
|
152 BEGIN_INSTALL_BUILTIN \ |
3744
|
153 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
154 END_INSTALL_BUILTIN |
|
155 |
3364
|
156 // Generate code to install name in the symbol table. The script |
|
157 // mkdefs will create a .def file for every .cc file that uses |
|
158 // DEFUN_DLD. |
|
159 |
|
160 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
161 BEGIN_INSTALL_BUILTIN \ |
|
162 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
163 END_INSTALL_BUILTIN |
|
164 |
5796
|
165 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, \ |
|
166 is_text_fcn, doc) \ |
|
167 BEGIN_INSTALL_BUILTIN \ |
|
168 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
|
169 END_INSTALL_BUILTIN |
|
170 |
3295
|
171 // Generate code for making another name for an existing function. |
|
172 |
|
173 #define DEFALIAS_INTERNAL(alias, name) \ |
|
174 BEGIN_INSTALL_BUILTIN \ |
|
175 XDEFALIAS_INTERNAL(alias, name) \ |
|
176 END_INSTALL_BUILTIN |
|
177 |
|
178 #else /* ! MAKE_BUILTINS */ |
|
179 |
|
180 // Generate the first line of the function definition. This ensures |
|
181 // that the internal functions all have the same signature. |
|
182 |
|
183 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
184 DECLARE_FUN (name, args_name, nargout_name) |
|
185 |
4234
|
186 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
187 DECLARE_FUN (name, args_name, nargout_name) |
|
188 |
3743
|
189 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
190 is_text_fcn, doc) \ |
|
191 DECLARE_FUNX (fname, args_name, nargout_name) |
|
192 |
3295
|
193 // No definition is required for an alias. |
|
194 |
4699
|
195 #define DEFALIAS_INTERNAL(alias, name) |
3295
|
196 |
|
197 #endif /* ! MAKE_BUILTINS */ |
|
198 |
525
|
199 #endif |
|
200 |
|
201 /* |
|
202 ;;; Local Variables: *** |
|
203 ;;; mode: C++ *** |
|
204 ;;; End: *** |
|
205 */ |