pt-fcn-handle.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2003-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_tree_fcn_handle_h)
00024 #define octave_fcn_handle_h 1
00025 
00026 #include <iosfwd>
00027 #include <string>
00028 
00029 #include "pt-bp.h"
00030 #include "pt-exp.h"
00031 #include "pt-misc.h"
00032 #include "pt-stmt.h"
00033 #include "symtab.h"
00034 
00035 class octave_value_list;
00036 
00037 class tree_walker;
00038 
00039 #include "ov.h"
00040 #include "ov-usr-fcn.h"
00041 #include "symtab.h"
00042 
00043 class
00044 tree_fcn_handle : public tree_expression
00045 {
00046 public:
00047 
00048   tree_fcn_handle (int l = -1, int c = -1)
00049     : tree_expression (l, c), nm () { }
00050 
00051   tree_fcn_handle (const std::string& n, int l = -1, int c = -1)
00052     : tree_expression (l, c), nm (n) { }
00053 
00054   ~tree_fcn_handle (void) { }
00055 
00056   bool has_magic_end (void) const { return false; }
00057 
00058   void print (std::ostream& os, bool pr_as_read_syntax = false,
00059               bool pr_orig_txt = true);
00060 
00061   void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
00062                   bool pr_orig_txt = true);
00063 
00064   std::string name (void) const { return nm; }
00065 
00066   bool rvalue_ok (void) const { return true; }
00067 
00068   octave_value rvalue1 (int nargout = 1);
00069 
00070   octave_value_list rvalue (int nargout);
00071 
00072   tree_expression *dup (symbol_table::scope_id scope,
00073                         symbol_table::context_id context) const;
00074 
00075   void accept (tree_walker& tw);
00076 
00077 private:
00078 
00079   // The name of this function handle.
00080   std::string nm;
00081 
00082   // No copying!
00083 
00084   tree_fcn_handle (const tree_fcn_handle&);
00085 
00086   tree_fcn_handle& operator = (const tree_fcn_handle&);
00087 };
00088 
00089 class
00090 tree_anon_fcn_handle : public tree_expression
00091 {
00092 public:
00093 
00094   tree_anon_fcn_handle (int l = -1, int c = -1)
00095     : tree_expression (l, c), fcn (0), file_name () { }
00096 
00097   tree_anon_fcn_handle (tree_parameter_list *pl, tree_parameter_list *rl,
00098                         tree_statement_list *cl, symbol_table::scope_id sid,
00099                         int l = -1, int c = -1)
00100     : tree_expression (l, c),
00101       fcn (new octave_user_function (sid, pl, rl, cl)),
00102       file_name () { }
00103 
00104   ~tree_anon_fcn_handle (void) { delete fcn; }
00105 
00106   bool has_magic_end (void) const { return false; }
00107 
00108   bool rvalue_ok (void) const { return true; }
00109 
00110   octave_value rvalue1 (int nargout = 1);
00111 
00112   octave_value_list rvalue (int nargout);
00113 
00114   tree_parameter_list *parameter_list (void) const
00115   {
00116     return fcn ? fcn->parameter_list () : 0;
00117   }
00118 
00119   tree_parameter_list *return_list (void) const
00120   {
00121     return fcn ? fcn->return_list () : 0;
00122   }
00123 
00124   tree_statement_list *body (void) const
00125   {
00126     return fcn ? fcn->body () : 0;
00127   }
00128 
00129   symbol_table::scope_id scope (void) const
00130   {
00131     return fcn ? fcn->scope () : -1;
00132   }
00133 
00134   tree_expression *dup (symbol_table::scope_id scope,
00135                         symbol_table::context_id context) const;
00136 
00137   void accept (tree_walker& tw);
00138 
00139   void stash_file_name (const std::string& file) { file_name = file; }
00140 
00141 private:
00142 
00143   // The function.
00144   octave_user_function *fcn;
00145 
00146   // Filename where the handle was defined.
00147   std::string file_name;
00148 
00149   // No copying!
00150 
00151   tree_anon_fcn_handle (const tree_anon_fcn_handle&);
00152 
00153   tree_anon_fcn_handle& operator = (const tree_anon_fcn_handle&);
00154 };
00155 
00156 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines