pt-cmd.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_tree_cmd_h)
00024 #define octave_tree_cmd_h 1
00025 
00026 #include <string>
00027 
00028 class tree_walker;
00029 
00030 #include "ov-fcn.h"
00031 #include "pt.h"
00032 #include "pt-bp.h"
00033 #include "symtab.h"
00034 
00035 // A base class for commands.
00036 
00037 class
00038 tree_command : public tree
00039 {
00040 public:
00041 
00042   tree_command (int l = -1, int c = -1)
00043     : tree (l, c) { }
00044 
00045   virtual ~tree_command (void) { }
00046 
00047   virtual tree_command *dup (symbol_table::scope_id,
00048                              symbol_table::context_id context) const = 0;
00049 
00050 private:
00051 
00052   // No copying!
00053 
00054   tree_command (const tree_command&);
00055 
00056   tree_command& operator = (const tree_command&);
00057 };
00058 
00059 // No-op.
00060 
00061 class
00062 tree_no_op_command : public tree_command
00063 {
00064 public:
00065 
00066   tree_no_op_command (const std::string& cmd = "no_op", int l = -1, int c = -1)
00067     : tree_command (l, c), eof (cmd == "endfunction" || cmd == "endscript"),
00068       orig_cmd (cmd) { }
00069 
00070   ~tree_no_op_command (void) { }
00071 
00072   tree_command *dup (symbol_table::scope_id scope,
00073                      symbol_table::context_id context) const;
00074 
00075   void accept (tree_walker& tw);
00076 
00077   bool is_end_of_fcn_or_script (void) const { return eof; }
00078 
00079   std::string original_command (void) { return orig_cmd; }
00080 
00081 private:
00082 
00083   bool eof;
00084 
00085   std::string orig_cmd;
00086 
00087   // No copying!
00088 
00089   tree_no_op_command (const tree_no_op_command&);
00090 
00091   tree_no_op_command& operator = (const tree_no_op_command&);
00092 };
00093 
00094 // Function definition.
00095 
00096 class
00097 tree_function_def : public tree_command
00098 {
00099 public:
00100 
00101   tree_function_def (octave_function *f, int l = -1, int c = -1)
00102     : tree_command (l, c), fcn (f) { }
00103 
00104   ~tree_function_def (void) { }
00105 
00106   tree_command *dup (symbol_table::scope_id scope,
00107                      symbol_table::context_id context) const;
00108 
00109   void accept (tree_walker& tw);
00110 
00111   octave_value function (void) { return fcn; }
00112 
00113 private:
00114 
00115   octave_value fcn;
00116 
00117   tree_function_def (const octave_value& v, int l = -1, int c = -1)
00118     : tree_command (l, c), fcn (v) { }
00119 
00120   // No copying!
00121 
00122   tree_function_def (const tree_function_def&);
00123 
00124   tree_function_def& operator = (const tree_function_def&);
00125 };
00126 
00127 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines