ov-fcn.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-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_function_h)
00024 #define octave_function_h 1
00025 
00026 #include <string>
00027 
00028 #include "oct-time.h"
00029 #include "str-vec.h"
00030 
00031 #include "oct-alloc.h"
00032 #include "oct-obj.h"
00033 #include "ov-base.h"
00034 #include "ov-typeinfo.h"
00035 #include "symtab.h"
00036 
00037 class tree_walker;
00038 
00039 // Functions.
00040 
00041 class
00042 OCTINTERP_API
00043 octave_function : public octave_base_value
00044 {
00045 public:
00046 
00047   octave_function (void)
00048     : relative (false), locked (false), private_function (false),
00049       xdispatch_class (), my_name (), my_dir_name (), doc () { }
00050 
00051   ~octave_function (void) { }
00052 
00053   octave_base_value *clone (void) const;
00054   octave_base_value *empty_clone (void) const;
00055 
00056   bool is_defined (void) const { return true; }
00057 
00058   bool is_function (void) const { return true; }
00059 
00060   virtual bool is_system_fcn_file (void) const { return false; }
00061 
00062   virtual std::string fcn_file_name (void) const { return std::string (); }
00063 
00064   // The name to show in the profiler (also used as map-key).
00065   virtual std::string profiler_name (void) const { return name (); }
00066 
00067   virtual std::string parent_fcn_name (void) const { return std::string (); }
00068 
00069   virtual symbol_table::scope_id parent_fcn_scope (void) const { return -1; }
00070 
00071   virtual void mark_fcn_file_up_to_date (const octave_time&) { }
00072 
00073   virtual symbol_table::scope_id scope (void) { return -1; }
00074 
00075   virtual octave_time time_parsed (void) const
00076     { return octave_time (static_cast<time_t> (0)); }
00077 
00078   virtual octave_time time_checked (void) const
00079     { return octave_time (static_cast<time_t> (0)); }
00080 
00081   virtual bool is_subfunction (void) const { return false; }
00082 
00083   virtual bool is_class_constructor (const std::string& = std::string ()) const
00084     { return false; }
00085 
00086   virtual bool is_class_method (const std::string& = std::string ()) const
00087     { return false; }
00088 
00089   virtual bool takes_varargs (void) const { return false; }
00090 
00091   virtual bool takes_var_return (void) const { return false; }
00092 
00093   void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; }
00094 
00095   std::string dispatch_class (void) const { return xdispatch_class; }
00096 
00097   virtual void
00098   mark_as_private_function (const std::string& cname = std::string ())
00099   {
00100     private_function = true;
00101     xdispatch_class = cname;
00102   }
00103 
00104   bool is_private_function (void) const { return private_function; }
00105 
00106   bool is_private_function_of_class (const std::string& nm) const
00107     { return private_function && xdispatch_class == nm; }
00108 
00109   virtual bool
00110   is_anonymous_function_of_class (const std::string& = std::string ()) const
00111     { return false; }
00112 
00113   std::string dir_name (void) const { return my_dir_name; }
00114 
00115   void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
00116 
00117   void lock (void)
00118   {
00119     this->lock_subfunctions ();
00120     locked = true;
00121   }
00122 
00123   void unlock (void)
00124   {
00125     this->unlock_subfunctions ();
00126     locked = false;
00127   }
00128 
00129   bool islocked (void) const { return locked; }
00130 
00131   virtual void lock_subfunctions (void) { }
00132 
00133   virtual void unlock_subfunctions (void) { }
00134 
00135   void mark_relative (void) { relative = true; }
00136 
00137   bool is_relative (void) const { return relative; }
00138 
00139   std::string name (void) const { return my_name; }
00140 
00141   void document (const std::string& ds) { doc = ds; }
00142 
00143   std::string doc_string (void) const { return doc; }
00144 
00145   virtual void unload (void) { }
00146 
00147   virtual void accept (tree_walker&) { }
00148 
00149 protected:
00150 
00151   octave_function (const std::string& nm,
00152                    const std::string& ds = std::string ())
00153     : relative (false), locked (false), private_function (false),
00154       xdispatch_class (), my_name (nm), my_dir_name (), doc (ds) { }
00155 
00156   // TRUE if this function was found from a relative path element.
00157   bool relative;
00158 
00159   // TRUE if this function is tagged so that it can't be cleared.
00160   bool locked;
00161 
00162   // TRUE means this is a private function.
00163   bool private_function;
00164 
00165   // If this object is a class method or constructor, or a private
00166   // function inside a class directory, this is the name of the class
00167   // to which the method belongs.
00168   std::string xdispatch_class;
00169 
00170   // The name of this function.
00171   std::string my_name;
00172 
00173   // The name of the directory in the path where we found this
00174   // function.  May be relative.
00175   std::string my_dir_name;
00176 
00177   // The help text for this function.
00178   std::string doc;
00179 
00180 private:
00181 
00182   // No copying!
00183 
00184   octave_function (const octave_function& f);
00185 
00186   octave_function& operator = (const octave_function& f);
00187 
00188   DECLARE_OCTAVE_ALLOCATOR
00189 };
00190 
00191 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines