defun-int.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_defun_int_h)
00024 #define octave_defun_int_h 1
00025 
00026 #include <string>
00027 
00028 #include "ov-builtin.h"
00029 #include "ov-dld-fcn.h"
00030 #include "symtab.h"
00031 #include "version.h"
00032 
00033 class octave_value;
00034 
00035 extern OCTINTERP_API void print_usage (void);
00036 extern OCTINTERP_API void print_usage (const std::string&);
00037 
00038 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn);
00039 
00040 extern OCTINTERP_API void
00041 install_builtin_function (octave_builtin::fcn f, const std::string& name,
00042                           const std::string& doc,
00043                           bool can_hide_function = true);
00044 
00045 extern OCTINTERP_API void
00046 install_dld_function (octave_dld_function::fcn f, const std::string& name,
00047                       const octave_shlib& shl, const std::string& doc,
00048                       bool relative = false);
00049 
00050 extern OCTINTERP_API void
00051 install_mex_function (void *fptr, bool fmex, const std::string& name,
00052                       const octave_shlib& shl, bool relative = false);
00053 
00054 extern OCTINTERP_API void
00055 alias_builtin (const std::string& alias, const std::string& name);
00056 
00057 // Gets the shlib of the currently executing DLD function, if any.
00058 extern OCTINTERP_API octave_shlib
00059 get_current_shlib (void);
00060 
00061 // This is a convenience class that calls the above function automatically at
00062 // construction time. When deriving new classes, you can either use it as a field
00063 // or as a parent (with multiple inheritance).
00064 
00065 class octave_auto_shlib : public octave_shlib
00066 {
00067 public:
00068   octave_auto_shlib (void)
00069     : octave_shlib (get_current_shlib ()) { }
00070   octave_auto_shlib (const octave_shlib& shl)
00071     : octave_shlib (shl) { }
00072 };
00073 
00074 extern OCTINTERP_API bool
00075 defun_isargout (int, int);
00076 
00077 extern OCTINTERP_API void
00078 defun_isargout (int, int, bool *);
00079 
00080 #define DECLARE_FUNX(name, args_name, nargout_name) \
00081   OCTAVE_EXPORT octave_value_list \
00082   name (const octave_value_list& args_name, int nargout_name)
00083 
00084 #define DECLARE_FUN(name, args_name, nargout_name) \
00085   DECLARE_FUNX (F ## name, args_name, nargout_name)
00086 
00087 // Define the code that will be used to insert the new function into
00088 // the symbol table.  We look for this name instead of the actual
00089 // function so that we can easily install the doc std::string too.
00090 
00091 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative);
00092 
00093 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative);
00094 
00095 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \
00096   DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc)
00097 
00098 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \
00099   extern "C" \
00100   OCTAVE_EXPORT \
00101   octave_function * \
00102   gname (const octave_shlib& shl, bool relative) \
00103   { \
00104     octave_function *retval = 0; \
00105  \
00106     check_version (OCTAVE_API_VERSION, name); \
00107  \
00108     if (! error_state) \
00109       { \
00110         octave_dld_function *fcn = octave_dld_function::create (fname, shl, name, doc); \
00111  \
00112         if (relative) \
00113           fcn->mark_relative (); \
00114  \
00115         retval = fcn; \
00116       } \
00117  \
00118     return retval; \
00119   }
00120 
00121 // MAKE_BUILTINS is defined to extract function names and related
00122 // information and create the *.df files that are eventually used to
00123 // create the builtins.cc file.
00124 
00125 #if defined (MAKE_BUILTINS)
00126 
00127 // Generate code to install name in the symbol table.  The script
00128 // mkdefs will create a .def file for every .cc file that uses DEFUN,
00129 // or DEFCMD.
00130 
00131 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \
00132   BEGIN_INSTALL_BUILTIN \
00133     XDEFUN_INTERNAL (name, args_name, nargout_name, doc) \
00134   END_INSTALL_BUILTIN
00135 
00136 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \
00137   BEGIN_INSTALL_BUILTIN \
00138     XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, doc) \
00139   END_INSTALL_BUILTIN
00140 
00141 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \
00142   BEGIN_INSTALL_BUILTIN \
00143     XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, doc) \
00144   END_INSTALL_BUILTIN
00145 
00146 // Generate code to install name in the symbol table.  The script
00147 // mkdefs will create a .def file for every .cc file that uses
00148 // DEFUN_DLD.
00149 
00150 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, doc) \
00151   BEGIN_INSTALL_BUILTIN \
00152     XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, doc) \
00153   END_INSTALL_BUILTIN
00154 
00155 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, doc) \
00156   BEGIN_INSTALL_BUILTIN \
00157     XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, doc) \
00158   END_INSTALL_BUILTIN
00159 
00160 // Generate code for making another name for an existing function.
00161 
00162 #define DEFALIAS_INTERNAL(alias, name) \
00163   BEGIN_INSTALL_BUILTIN \
00164     XDEFALIAS_INTERNAL(alias, name) \
00165   END_INSTALL_BUILTIN
00166 
00167 #else /* ! MAKE_BUILTINS */
00168 
00169 // Generate the first line of the function definition.  This ensures
00170 // that the internal functions all have the same signature.
00171 
00172 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \
00173   DECLARE_FUN (name, args_name, nargout_name)
00174 
00175 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \
00176   DECLARE_FUN (name, args_name, nargout_name)
00177 
00178 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \
00179   DECLARE_FUNX (fname, args_name, nargout_name)
00180 
00181 // No definition is required for an alias.
00182 
00183 #define DEFALIAS_INTERNAL(alias, name)
00184 
00185 #endif /* ! MAKE_BUILTINS */
00186 
00187 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines