GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
defun-int.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_defun_int_h)
24 #define octave_defun_int_h 1
25 
26 #include <string>
27 
28 #include "ov-builtin.h"
29 #include "ov-dld-fcn.h"
30 #include "symtab.h"
31 #include "version.h"
32 
33 class octave_value;
34 
35 extern OCTINTERP_API void print_usage (void);
36 extern OCTINTERP_API void print_usage (const std::string&);
37 
38 extern OCTINTERP_API void check_version (const std::string& version,
39  const std::string& fcn);
40 
41 extern OCTINTERP_API void
42 install_builtin_function (octave_builtin::fcn f, const std::string& name,
43  const std::string& file, const std::string& doc,
44  bool can_hide_function = true);
45 
46 extern OCTINTERP_API void
47 install_dld_function (octave_dld_function::fcn f, const std::string& name,
48  const octave_shlib& shl, const std::string& doc,
49  bool relative = false);
50 
51 extern OCTINTERP_API void
52 install_mex_function (void *fptr, bool fmex, const std::string& name,
53  const octave_shlib& shl, bool relative = false);
54 
55 extern OCTINTERP_API void
56 alias_builtin (const std::string& alias, const std::string& name);
57 
58 // Gets the shlib of the currently executing DLD function, if any.
60 get_current_shlib (void);
61 
62 // This is a convenience class that calls the above function automatically at
63 // construction time. When deriving new classes, you can either use it as a
64 // field or as a parent (with multiple inheritance).
65 
67 {
68 public:
72  : octave_shlib (shl) { }
73 };
74 
75 extern OCTINTERP_API bool
76 defun_isargout (int, int);
77 
78 extern OCTINTERP_API void
79 defun_isargout (int, int, bool *);
80 
81 #define DECLARE_FUNX(name, args_name, nargout_name) \
82  OCTAVE_EXPORT octave_value_list \
83  name (const octave_value_list& args_name, int nargout_name)
84 
85 #define DECLARE_FUN(name, args_name, nargout_name) \
86  DECLARE_FUNX (F ## name, args_name, nargout_name)
87 
88 // Define the code that will be used to insert the new function into
89 // the symbol table. We look for this name instead of the actual
90 // function so that we can easily install the doc std::string too.
91 
92 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative);
93 
94 typedef octave_function *
95  (*octave_dld_fcn_getter) (const octave_shlib&, bool relative);
96 
97 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \
98  DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc)
99 
100 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \
101  extern "C" \
102  OCTAVE_EXPORT \
103  octave_function * \
104  gname (const octave_shlib& shl, bool relative) \
105  { \
106  octave_function *retval = 0; \
107  \
108  check_version (OCTAVE_API_VERSION, name); \
109  \
110  if (! error_state) \
111  { \
112  octave_dld_function *fcn = octave_dld_function::create (fname, shl, name, doc); \
113  \
114  if (relative) \
115  fcn->mark_relative (); \
116  \
117  retval = fcn; \
118  } \
119  \
120  return retval; \
121  }
122 
123 // MAKE_BUILTINS is defined to extract function names and related
124 // information and create the *.df files that are eventually used to
125 // create the builtins.cc file.
126 
127 #if defined (MAKE_BUILTINS)
128 
129 // Generate code to install name in the symbol table. The script
130 // mkdefs will create a .def file for every .cc file that uses DEFUN,
131 // or DEFCMD.
132 
133 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \
134  BEGIN_INSTALL_BUILTIN \
135  XDEFUN_INTERNAL (name, args_name, nargout_name, doc) \
136  END_INSTALL_BUILTIN
137 
138 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \
139  BEGIN_INSTALL_BUILTIN \
140  XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, doc) \
141  END_INSTALL_BUILTIN
142 
143 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \
144  BEGIN_INSTALL_BUILTIN \
145  XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, doc) \
146  END_INSTALL_BUILTIN
147 
148 // Generate code to install name in the symbol table. The script
149 // mkdefs will create a .def file for every .cc file that uses
150 // DEFUN_DLD.
151 
152 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, doc) \
153  BEGIN_INSTALL_BUILTIN \
154  XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, doc) \
155  END_INSTALL_BUILTIN
156 
157 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, doc) \
158  BEGIN_INSTALL_BUILTIN \
159  XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, doc) \
160  END_INSTALL_BUILTIN
161 
162 // Generate code for making another name for an existing function.
163 
164 #define DEFALIAS_INTERNAL(alias, name) \
165  BEGIN_INSTALL_BUILTIN \
166  XDEFALIAS_INTERNAL(alias, name) \
167  END_INSTALL_BUILTIN
168 
169 #else /* ! MAKE_BUILTINS */
170 
171 // Generate the first line of the function definition. This ensures
172 // that the internal functions all have the same signature.
173 
174 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \
175  DECLARE_FUN (name, args_name, nargout_name)
176 
177 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \
178  DECLARE_FUN (name, args_name, nargout_name)
179 
180 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \
181  DECLARE_FUNX (fname, args_name, nargout_name)
182 
183 // No definition is required for an alias.
184 
185 #define DEFALIAS_INTERNAL(alias, name)
186 
187 #endif /* ! MAKE_BUILTINS */
188 
189 #endif