GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-fcn-handle.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_pt_fcn_handle_h)
24 #define octave_fcn_handle_h 1
25 
26 #include <iosfwd>
27 #include <string>
28 
29 #include "pt-bp.h"
30 #include "pt-exp.h"
31 #include "pt-misc.h"
32 #include "pt-stmt.h"
33 #include "symtab.h"
34 
35 class octave_value_list;
36 
37 class tree_walker;
38 
39 #include "ov.h"
40 #include "ov-usr-fcn.h"
41 #include "symtab.h"
42 
43 class
45 {
46 public:
47 
48  tree_fcn_handle (int l = -1, int c = -1)
49  : tree_expression (l, c), nm () { }
50 
51  tree_fcn_handle (const std::string& n, int l = -1, int c = -1)
52  : tree_expression (l, c), nm (n) { }
53 
54  ~tree_fcn_handle (void) { }
55 
56  bool has_magic_end (void) const { return false; }
57 
58  void print (std::ostream& os, bool pr_as_read_syntax = false,
59  bool pr_orig_txt = true);
60 
61  void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
62  bool pr_orig_txt = true);
63 
64  std::string name (void) const { return nm; }
65 
66  bool rvalue_ok (void) const { return true; }
67 
68  octave_value rvalue1 (int nargout = 1);
69 
70  octave_value_list rvalue (int nargout);
71 
74 
75  void accept (tree_walker& tw);
76 
77 private:
78 
79  // The name of this function handle.
80  std::string nm;
81 
82  // No copying!
83 
85 
87 };
88 
89 class
91 {
92 public:
93 
94  tree_anon_fcn_handle (int l = -1, int c = -1)
95  : tree_expression (l, c), fcn (0), file_name () { }
96 
99  int l = -1, int c = -1)
100  : tree_expression (l, c),
101  fcn (new octave_user_function (sid, pl, rl, cl)),
102  file_name () { }
103 
104  ~tree_anon_fcn_handle (void) { delete fcn; }
105 
106  bool has_magic_end (void) const { return false; }
107 
108  bool rvalue_ok (void) const { return true; }
109 
110  octave_value rvalue1 (int nargout = 1);
111 
112  octave_value_list rvalue (int nargout);
113 
115  {
116  return fcn ? fcn->parameter_list () : 0;
117  }
118 
120  {
121  return fcn ? fcn->return_list () : 0;
122  }
123 
124  tree_statement_list *body (void) const
125  {
126  return fcn ? fcn->body () : 0;
127  }
128 
130  {
131  return fcn ? fcn->scope () : -1;
132  }
133 
136 
137  void accept (tree_walker& tw);
138 
139  void stash_file_name (const std::string& file) { file_name = file; }
140 
141 private:
142 
143  // The function.
145 
146  // Filename where the handle was defined.
147  std::string file_name;
148 
149  // No copying!
150 
152 
154 };
155 
156 #endif
octave_user_function * fcn
tree_anon_fcn_handle(tree_parameter_list *pl, tree_parameter_list *rl, tree_statement_list *cl, symbol_table::scope_id sid, int l=-1, int c=-1)
Definition: pt-fcn-handle.h:97
~tree_fcn_handle(void)
Definition: pt-fcn-handle.h:54
bool rvalue_ok(void) const
Definition: pt-fcn-handle.h:66
bool has_magic_end(void) const
Definition: pt-fcn-handle.h:56
tree_fcn_handle(int l=-1, int c=-1)
Definition: pt-fcn-handle.h:48
tree_parameter_list * return_list(void) const
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
void stash_file_name(const std::string &file)
std::string name(void) const
Definition: pt-fcn-handle.h:64
symbol_table::scope_id scope(void) const
tree_statement_list * body(void) const
bool has_magic_end(void) const
tree_anon_fcn_handle(int l=-1, int c=-1)
Definition: pt-fcn-handle.h:94
tree_parameter_list * parameter_list(void) const
bool rvalue_ok(void) const
size_t context_id
Definition: symtab.h:51
tree_fcn_handle(const std::string &n, int l=-1, int c=-1)
Definition: pt-fcn-handle.h:51
tree_walker & operator=(const tree_walker &)
std::string nm
Definition: pt-fcn-handle.h:80