1 //////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (C) 1996-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_ov_builtin_h) 27 #define octave_ov_builtin_h 1 28 29 #include "octave-config.h" 30 31 #include <list> 32 #include <set> 33 #include <string> 34 35 #include "ov-fcn.h" 36 #include "ov-typeinfo.h" 37 38 class octave_value; 39 class octave_value_list; 40 41 namespace octave 42 { 43 class tree_evaluator; 44 class interpreter; 45 class jit_type; 46 } 47 48 // Builtin functions. 49 50 class 51 OCTINTERP_API 52 octave_builtin : public octave_function 53 { 54 public: 55 octave_builtin(void)56 octave_builtin (void) : octave_function (), f (nullptr), m (nullptr), 57 file (), jtype (nullptr) 58 { } 59 60 typedef octave_value_list (*meth) (octave::interpreter&, 61 const octave_value_list&, int); 62 63 typedef octave_value_list (*fcn) (const octave_value_list&, int); 64 65 octave_builtin (fcn ff, const std::string& nm = "", 66 const std::string& ds = "") octave_function(nm,ds)67 : octave_function (nm, ds), f (ff), m (nullptr), file (), jtype (nullptr) 68 { } 69 70 octave_builtin (meth mm, const std::string& nm = "", 71 const std::string& ds = "") octave_function(nm,ds)72 : octave_function (nm, ds), f (nullptr), m (mm), file (), jtype (nullptr) 73 { } 74 octave_builtin(fcn ff,const std::string & nm,const std::string & fnm,const std::string & ds)75 octave_builtin (fcn ff, const std::string& nm, const std::string& fnm, 76 const std::string& ds) 77 : octave_function (nm, ds), f (ff), m (nullptr), file (fnm), jtype (nullptr) 78 { } 79 octave_builtin(meth mm,const std::string & nm,const std::string & fnm,const std::string & ds)80 octave_builtin (meth mm, const std::string& nm, const std::string& fnm, 81 const std::string& ds) 82 : octave_function (nm, ds), f (nullptr), m (mm), file (fnm), jtype (nullptr) 83 { } 84 85 // No copying! 86 87 octave_builtin (const octave_builtin& ob) = delete; 88 89 octave_builtin& operator = (const octave_builtin& ob) = delete; 90 91 ~octave_builtin (void) = default; 92 src_file_name(void)93 std::string src_file_name (void) const { return file; } 94 95 octave_function * function_value (bool = false) { return this; } 96 is_builtin_function(void)97 bool is_builtin_function (void) const { return true; } 98 99 octave_value_list 100 execute (octave::tree_evaluator& tw, int nargout = 0, 101 const octave_value_list& args = octave_value_list ()); 102 103 octave::jit_type * to_jit (void) const; 104 105 void stash_jit (octave::jit_type& type); 106 107 fcn function (void) const; 108 109 meth method (void) const; 110 111 void push_dispatch_class (const std::string& dispatch_type); 112 113 bool handles_dispatch_class (const std::string& dispatch_type) const; 114 115 protected: 116 117 // A pointer to the actual function. 118 fcn f; 119 meth m; 120 121 // The name of the file where this function was defined. 122 std::string file; 123 124 // The types this function has been declared to handle (if any). 125 std::set<std::string> dispatch_classes; 126 127 // A pointer to the jit type that represents the function. 128 octave::jit_type *jtype; 129 130 private: 131 132 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA 133 }; 134 135 #endif 136