GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-fcn-handle.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_fcn_handle_h)
24 #define octave_pt_fcn_handle_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "pt-bp.h"
32 #include "pt-exp.h"
33 #include "pt-misc.h"
34 #include "pt-stmt.h"
35 #include "pt-walk.h"
36 #include "symscope.h"
37 
38 class octave_value_list;
39 
40 #include "ov.h"
41 #include "ov-usr-fcn.h"
42 
43 namespace octave
44 {
46  {
47  public:
48 
49  tree_fcn_handle (int l = -1, int c = -1)
50  : tree_expression (l, c), m_name () { }
51 
52  tree_fcn_handle (const std::string& n, int l = -1, int c = -1)
53  : tree_expression (l, c), m_name (n) { }
54 
55  // No copying!
56 
57  tree_fcn_handle (const tree_fcn_handle&) = delete;
58 
60 
61  ~tree_fcn_handle (void) = default;
62 
63  bool has_magic_end (void) const { return false; }
64 
65  void print (std::ostream& os, bool pr_as_read_syntax = false,
66  bool pr_orig_txt = true);
67 
68  void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
69  bool pr_orig_txt = true);
70 
71  std::string name (void) const { return m_name; }
72 
73  bool rvalue_ok (void) const { return true; }
74 
75  tree_expression * dup (symbol_scope& scope) const;
76 
77  void accept (tree_walker& tw)
78  {
79  tw.visit_fcn_handle (*this);
80  }
81 
82  private:
83 
84  // The name of this function handle.
86  };
87 
89  {
90  public:
91 
92  tree_anon_fcn_handle (int l = -1, int c = -1)
93  : tree_expression (l, c), m_parameter_list (nullptr),
94  m_expression (nullptr), m_scope (), m_parent_scope (),
95  m_file_name ()
96  { }
97 
99  const symbol_scope& scope,
100  const symbol_scope& parent_scope,
101  int l = -1, int c = -1)
102  : tree_expression (l, c), m_parameter_list (pl), m_expression (ex),
104  { }
105 
106  // No copying!
107 
108  tree_anon_fcn_handle (const tree_anon_fcn_handle&) = delete;
109 
111 
112  ~tree_anon_fcn_handle (void);
113 
114  bool has_magic_end (void) const { return false; }
115 
116  bool rvalue_ok (void) const { return true; }
117 
119  {
120  return m_parameter_list;
121  }
122 
123  tree_expression * expression (void) const { return m_expression; }
124 
125  symbol_scope scope (void) const { return m_scope; }
126 
127  symbol_scope parent_scope (void) const { return m_parent_scope; }
128 
129  bool has_parent_scope (void) const { return m_parent_scope.is_valid (); }
130 
132 
133  void accept (tree_walker& tw) { tw.visit_anon_fcn_handle (*this); }
134 
136 
137  std::string file_name (void) const { return m_file_name; }
138 
139  private:
140 
141  // Inputs parameters.
143 
144  // Function body, limited to a single expression.
146 
147  // Function scope.
149 
150  // Parent scope, or an invalid scope if none.
152 
153  // Filename where the handle was defined.
155  };
156 }
157 
158 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
159 
160 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_fcn_handle' instead")
161 typedef octave::tree_fcn_handle tree_fcn_handle;
162 
163 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_anon_fcn_handle' instead")
164 typedef octave::tree_anon_fcn_handle tree_anon_fcn_handle;
165 
166 #endif
167 
168 #endif
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
symbol_scope scope(void) const
tree_expression * dup(symbol_scope &scope) const
virtual void visit_anon_fcn_handle(tree_anon_fcn_handle &)=0
tree_expression * dup(symbol_scope &scope) const
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
std::string file_name(void) const
bool has_magic_end(void) const
bool rvalue_ok(void) const
Definition: pt-fcn-handle.h:73
tree_anon_fcn_handle & operator=(const tree_anon_fcn_handle &)=delete
void stash_file_name(const std::string &file)
tree_parameter_list * parameter_list(void) const
bool is_valid(void) const
Definition: symscope.h:621
void print_raw(std::ostream &os, bool pr_as_read_syntax=false, bool pr_orig_txt=true)
tree_anon_fcn_handle(tree_parameter_list *pl, tree_expression *ex, const symbol_scope &scope, const symbol_scope &parent_scope, int l=-1, int c=-1)
Definition: pt-fcn-handle.h:98
tree_parameter_list * m_parameter_list
tree_expression * m_expression
void accept(tree_walker &tw)
void accept(tree_walker &tw)
Definition: pt-fcn-handle.h:77
bool has_parent_scope(void) const
tree_fcn_handle(const std::string &n, int l=-1, int c=-1)
Definition: pt-fcn-handle.h:52
std::string name(void) const
Definition: pt-fcn-handle.h:71
tree_expression * expression(void) const
tree_fcn_handle & operator=(const tree_fcn_handle &)=delete
virtual void visit_fcn_handle(tree_fcn_handle &)=0
tree_anon_fcn_handle(int l=-1, int c=-1)
Definition: pt-fcn-handle.h:92
symbol_scope parent_scope(void) const
tree_fcn_handle(int l=-1, int c=-1)
Definition: pt-fcn-handle.h:49
~tree_fcn_handle(void)=default
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
void print(std::ostream &os, bool pr_as_read_syntax=false, bool pr_orig_txt=true)
octave::stream os
Definition: file-io.cc:627
bool has_magic_end(void) const
Definition: pt-fcn-handle.h:63