GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-except.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-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_except_h)
24 #define octave_pt_except_h 1
25 
26 #include "octave-config.h"
27 
28 #include "pt-cmd.h"
29 #include "pt-id.h"
30 #include "pt-walk.h"
31 
32 namespace octave
33 {
34  class comment_list;
35  class tree_statement_list;
36 
37  // Simple exception handling.
38 
40  {
41  public:
42 
43  tree_try_catch_command (int l = -1, int c = -1)
44  : tree_command (l, c), m_try_code (nullptr), m_catch_code (nullptr),
45  m_expr_id (nullptr), m_lead_comm (nullptr), m_mid_comm (nullptr),
46  m_trail_comm (nullptr)
47  { }
48 
50  tree_identifier *id,
51  comment_list *cl = nullptr,
52  comment_list *cm = nullptr,
53  comment_list *ct = nullptr,
54  int l = -1, int c = -1)
55  : tree_command (l, c), m_try_code (tc), m_catch_code (cc),
56  m_expr_id (id), m_lead_comm (cl), m_mid_comm (cm), m_trail_comm (ct)
57  { }
58 
59  // No copying!
60 
62 
64 
66 
67  tree_identifier * identifier (void) { return m_expr_id; }
68 
69  tree_statement_list * body (void) { return m_try_code; }
70 
72 
74 
75  comment_list * middle_comment (void) { return m_mid_comm; }
76 
78 
79  void accept (tree_walker& tw)
80  {
81  tw.visit_try_catch_command (*this);
82  }
83 
84  private:
85 
86  // The first block of code to attempt to execute.
88 
89  // The code to execute if an error occurs in the first block.
91 
92  // Identifier to modify.
94 
95  // Comment preceding TRY token.
97 
98  // Comment preceding CATCH token.
100 
101  // Comment preceding END_TRY_CATCH token.
103  };
104 
105  // Simple exception handling.
106 
108  {
109  public:
110 
111  tree_unwind_protect_command (int l = -1, int c = -1)
112  : tree_command (l, c),
113  m_unwind_protect_code (nullptr), m_cleanup_code (nullptr),
114  m_lead_comm (nullptr), m_mid_comm (nullptr), m_trail_comm (nullptr)
115  { }
116 
119  comment_list *cl = nullptr,
120  comment_list *cm = nullptr,
121  comment_list *ct = nullptr,
122  int l = -1, int c = -1)
124  m_lead_comm (cl), m_mid_comm (cm), m_trail_comm (ct)
125  { }
126 
127  // No copying!
128 
130 
132  operator = (const tree_unwind_protect_command&) = delete;
133 
135 
137 
139 
141 
143 
145 
146  void accept (tree_walker& tw)
147  {
148  tw.visit_unwind_protect_command (*this);
149  }
150 
151  private:
152 
153  // The first body of code to attempt to execute.
155 
156  // The body of code to execute no matter what happens in the first
157  // body of code.
159 
160  // Comment preceding UNWIND_PROTECT token.
162 
163  // Comment preceding UNWIND_PROTECT_CLEANUP token.
165 
166  // Comment preceding END_UNWIND_PROTECT token.
168  };
169 }
170 
171 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
172 
173 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_try_catch_command' instead")
174 typedef octave::tree_try_catch_command tree_try_catch_command;
175 
176 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_unwind_protect_command' instead")
177 typedef octave::tree_unwind_protect_command tree_unwind_protect_command;
178 
179 #endif
180 
181 #endif
uint32_t id
Definition: graphics.cc:12193
tree_unwind_protect_command(int l=-1, int c=-1)
Definition: pt-except.h:111
tree_try_catch_command(int l=-1, int c=-1)
Definition: pt-except.h:43
void accept(tree_walker &tw)
Definition: pt-except.h:79
tree_statement_list * cleanup(void)
Definition: pt-except.h:138
tree_identifier * m_expr_id
Definition: pt-except.h:93
void accept(tree_walker &tw)
Definition: pt-except.h:146
virtual void visit_try_catch_command(tree_try_catch_command &)=0
tree_statement_list * m_cleanup_code
Definition: pt-except.h:158
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
tree_statement_list * m_catch_code
Definition: pt-except.h:90
comment_list * trailing_comment(void)
Definition: pt-except.h:144
comment_list * middle_comment(void)
Definition: pt-except.h:75
comment_list * leading_comment(void)
Definition: pt-except.h:73
tree_unwind_protect_command & operator=(const tree_unwind_protect_command &)=delete
tree_try_catch_command & operator=(const tree_try_catch_command &)=delete
tree_unwind_protect_command(tree_statement_list *tc, tree_statement_list *cc, comment_list *cl=nullptr, comment_list *cm=nullptr, comment_list *ct=nullptr, int l=-1, int c=-1)
Definition: pt-except.h:117
comment_list * trailing_comment(void)
Definition: pt-except.h:77
tree_statement_list * cleanup(void)
Definition: pt-except.h:71
tree_statement_list * m_unwind_protect_code
Definition: pt-except.h:154
comment_list * middle_comment(void)
Definition: pt-except.h:142
comment_list * m_lead_comm
Definition: pt-except.h:96
tree_statement_list * body(void)
Definition: pt-except.h:136
virtual void visit_unwind_protect_command(tree_unwind_protect_command &)=0
comment_list * leading_comment(void)
Definition: pt-except.h:140
tree_try_catch_command(tree_statement_list *tc, tree_statement_list *cc, tree_identifier *id, comment_list *cl=nullptr, comment_list *cm=nullptr, comment_list *ct=nullptr, int l=-1, int c=-1)
Definition: pt-except.h:49
tree_statement_list * body(void)
Definition: pt-except.h:69
tree_statement_list * m_try_code
Definition: pt-except.h:87
tree_identifier * identifier(void)
Definition: pt-except.h:67