GNU Octave  9.1.0
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-2024 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_except_h)
27 #define octave_pt_except_h 1
28 
29 #include "octave-config.h"
30 
31 #include "pt-cmd.h"
32 #include "pt-id.h"
33 #include "pt-walk.h"
34 
36 
37 class comment_list;
39 
40 // Simple exception handling.
41 
43 {
44 public:
45 
46  tree_try_catch_command (int l = -1, int c = -1)
47  : tree_command (l, c), m_try_code (nullptr), m_catch_code (nullptr),
48  m_expr_id (nullptr), m_lead_comm (nullptr), m_mid_comm (nullptr),
49  m_trail_comm (nullptr)
50  { }
51 
53  tree_identifier *id,
54  comment_list *cl = nullptr,
55  comment_list *cm = nullptr,
56  comment_list *ct = nullptr,
57  int l = -1, int c = -1)
58  : tree_command (l, c), m_try_code (tc), m_catch_code (cc),
59  m_expr_id (id), m_lead_comm (cl), m_mid_comm (cm), m_trail_comm (ct)
60  { }
61 
62  OCTAVE_DISABLE_COPY_MOVE (tree_try_catch_command)
63 
65 
66  tree_identifier * identifier () { return m_expr_id; }
67 
68  tree_statement_list * body () { return m_try_code; }
69 
70  tree_statement_list * cleanup () { return m_catch_code; }
71 
72  comment_list * leading_comment () { return m_lead_comm; }
73 
74  comment_list * middle_comment () { return m_mid_comm; }
75 
76  comment_list * trailing_comment () { return m_trail_comm; }
77 
78  void accept (tree_walker& tw)
79  {
80  tw.visit_try_catch_command (*this);
81  }
82 
83 private:
84 
85  // The first block of code to attempt to execute.
86  tree_statement_list *m_try_code;
87 
88  // The code to execute if an error occurs in the first block.
89  tree_statement_list *m_catch_code;
90 
91  // Identifier to modify.
92  tree_identifier *m_expr_id;
93 
94  // Comment preceding TRY token.
95  comment_list *m_lead_comm;
96 
97  // Comment preceding CATCH token.
98  comment_list *m_mid_comm;
99 
100  // Comment preceding END_TRY_CATCH token.
101  comment_list *m_trail_comm;
102 };
103 
104 // Simple exception handling.
105 
107 {
108 public:
109 
110  tree_unwind_protect_command (int l = -1, int c = -1)
111  : tree_command (l, c),
112  m_unwind_protect_code (nullptr), m_cleanup_code (nullptr),
113  m_lead_comm (nullptr), m_mid_comm (nullptr), m_trail_comm (nullptr)
114  { }
115 
118  comment_list *cl = nullptr,
119  comment_list *cm = nullptr,
120  comment_list *ct = nullptr,
121  int l = -1, int c = -1)
122  : tree_command (l, c), m_unwind_protect_code (tc), m_cleanup_code (cc),
123  m_lead_comm (cl), m_mid_comm (cm), m_trail_comm (ct)
124  { }
125 
126  OCTAVE_DISABLE_COPY_MOVE (tree_unwind_protect_command)
127 
129 
130  tree_statement_list * body () { return m_unwind_protect_code; }
131 
132  tree_statement_list * cleanup () { return m_cleanup_code; }
133 
134  comment_list * leading_comment () { return m_lead_comm; }
135 
136  comment_list * middle_comment () { return m_mid_comm; }
137 
138  comment_list * trailing_comment () { return m_trail_comm; }
139 
140  void accept (tree_walker& tw)
141  {
142  tw.visit_unwind_protect_command (*this);
143  }
144 
145 private:
146 
147  // The first body of code to attempt to execute.
148  tree_statement_list *m_unwind_protect_code;
149 
150  // The body of code to execute no matter what happens in the first
151  // body of code.
152  tree_statement_list *m_cleanup_code;
153 
154  // Comment preceding UNWIND_PROTECT token.
155  comment_list *m_lead_comm;
156 
157  // Comment preceding UNWIND_PROTECT_CLEANUP token.
158  comment_list *m_mid_comm;
159 
160  // Comment preceding END_UNWIND_PROTECT token.
161  comment_list *m_trail_comm;
162 };
163 
164 OCTAVE_END_NAMESPACE(octave)
165 
166 #endif
tree_statement_list * cleanup()
Definition: pt-except.h:70
tree_try_catch_command(int l=-1, int c=-1)
Definition: pt-except.h:46
void accept(tree_walker &tw)
Definition: pt-except.h:78
tree_identifier * identifier()
Definition: pt-except.h:66
tree_statement_list * body()
Definition: pt-except.h:68
comment_list * trailing_comment()
Definition: pt-except.h:76
comment_list * middle_comment()
Definition: pt-except.h:74
comment_list * leading_comment()
Definition: pt-except.h:72
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:52
tree_unwind_protect_command(int l=-1, int c=-1)
Definition: pt-except.h:110
comment_list * middle_comment()
Definition: pt-except.h:136
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:116
comment_list * trailing_comment()
Definition: pt-except.h:138
comment_list * leading_comment()
Definition: pt-except.h:134
void accept(tree_walker &tw)
Definition: pt-except.h:140
tree_statement_list * cleanup()
Definition: pt-except.h:132
tree_statement_list * body()
Definition: pt-except.h:130
virtual void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-walk.cc:612
virtual void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-walk.cc:593
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn