1 //////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (C) 1994-2021 The Octave Project Developers 4 // 5 // See the file COPYRIGHT.md in the top-level directory of this 6 // distribution or <https://octave.org/copyright/>. 7 // 8 // This file is part of Octave. 9 // 10 // Octave is free software: you can redistribute it and/or modify it 11 // under the terms of the GNU General Public License as published by 12 // the Free Software Foundation, either version 3 of the License, or 13 // (at your option) any later version. 14 // 15 // Octave is distributed in the hope that it will be useful, but 16 // WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of the GNU General Public License 21 // along with Octave; see the file COPYING. If not, see 22 // <https://www.gnu.org/licenses/>. 23 // 24 //////////////////////////////////////////////////////////////////////// 25 26 #if ! defined (octave_pt_cmd_h) 27 #define octave_pt_cmd_h 1 28 29 #include "octave-config.h" 30 31 #include <string> 32 33 #include "ov-fcn.h" 34 #include "pt.h" 35 #include "pt-bp.h" 36 #include "pt-walk.h" 37 38 namespace octave 39 { 40 // A base class for commands. 41 42 class tree_command : public tree 43 { 44 public: 45 46 tree_command (int l = -1, int c = -1) tree(l,c)47 : tree (l, c) { } 48 49 // No copying! 50 51 tree_command (const tree_command&) = delete; 52 53 tree_command& operator = (const tree_command&) = delete; 54 55 virtual ~tree_command (void) = default; 56 }; 57 58 // No-op. 59 60 class tree_no_op_command : public tree_command 61 { 62 public: 63 64 tree_no_op_command (const std::string& cmd = "no_op", bool e = false, 65 int l = -1, int c = -1) tree_command(l,c)66 : tree_command (l, c), m_eof (e), m_orig_cmd (cmd) { } 67 68 // No copying! 69 70 tree_no_op_command (const tree_no_op_command&) = delete; 71 72 tree_no_op_command& operator = (const tree_no_op_command&) = delete; 73 74 ~tree_no_op_command (void) = default; 75 accept(tree_walker & tw)76 void accept (tree_walker& tw) 77 { 78 tw.visit_no_op_command (*this); 79 } 80 is_end_of_fcn_or_script(void)81 bool is_end_of_fcn_or_script (void) const 82 { 83 return (m_orig_cmd == "endfunction" || m_orig_cmd == "endscript"); 84 } 85 is_end_of_file(void)86 bool is_end_of_file (void) const { return m_eof; } 87 original_command(void)88 std::string original_command (void) { return m_orig_cmd; } 89 90 private: 91 92 bool m_eof; 93 94 std::string m_orig_cmd; 95 }; 96 97 // Function definition. 98 99 class tree_function_def : public tree_command 100 { 101 public: 102 103 tree_function_def (octave_function *f, int l = -1, int c = -1) tree_command(l,c)104 : tree_command (l, c), m_fcn (f) { } 105 106 // No copying! 107 108 tree_function_def (const tree_function_def&) = delete; 109 110 tree_function_def& operator = (const tree_function_def&) = delete; 111 112 ~tree_function_def (void) = default; 113 accept(tree_walker & tw)114 void accept (tree_walker& tw) 115 { 116 tw.visit_function_def (*this); 117 } 118 function(void)119 octave_value function (void) { return m_fcn; } 120 121 private: 122 123 octave_value m_fcn; 124 125 tree_function_def (const octave_value& v, int l = -1, int c = -1) tree_command(l,c)126 : tree_command (l, c), m_fcn (v) { } 127 }; 128 } 129 130 #endif 131