GNU Octave  6.2.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-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_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 
35 namespace octave
36 {
37  class comment_list;
38  class tree_statement_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  // No copying!
63 
65 
67 
69 
70  tree_identifier * identifier (void) { return m_expr_id; }
71 
72  tree_statement_list * body (void) { return m_try_code; }
73 
75 
77 
78  comment_list * middle_comment (void) { return m_mid_comm; }
79 
81 
82  void accept (tree_walker& tw)
83  {
84  tw.visit_try_catch_command (*this);
85  }
86 
87  private:
88 
89  // The first block of code to attempt to execute.
91 
92  // The code to execute if an error occurs in the first block.
94 
95  // Identifier to modify.
97 
98  // Comment preceding TRY token.
100 
101  // Comment preceding CATCH token.
103 
104  // Comment preceding END_TRY_CATCH token.
106  };
107 
108  // Simple exception handling.
109 
111  {
112  public:
113 
114  tree_unwind_protect_command (int l = -1, int c = -1)
115  : tree_command (l, c),
116  m_unwind_protect_code (nullptr), m_cleanup_code (nullptr),
117  m_lead_comm (nullptr), m_mid_comm (nullptr), m_trail_comm (nullptr)
118  { }
119 
122  comment_list *cl = nullptr,
123  comment_list *cm = nullptr,
124  comment_list *ct = nullptr,
125  int l = -1, int c = -1)
127  m_lead_comm (cl), m_mid_comm (cm), m_trail_comm (ct)
128  { }
129 
130  // No copying!
131 
133 
136 
138 
140 
142 
144 
146 
148 
149  void accept (tree_walker& tw)
150  {
151  tw.visit_unwind_protect_command (*this);
152  }
153 
154  private:
155 
156  // The first body of code to attempt to execute.
158 
159  // The body of code to execute no matter what happens in the first
160  // body of code.
162 
163  // Comment preceding UNWIND_PROTECT token.
165 
166  // Comment preceding UNWIND_PROTECT_CLEANUP token.
168 
169  // Comment preceding END_UNWIND_PROTECT token.
171  };
172 }
173 
174 #endif
comment_list * middle_comment(void)
Definition: pt-except.h:78
tree_statement_list * cleanup(void)
Definition: pt-except.h:74
tree_identifier * m_expr_id
Definition: pt-except.h:96
comment_list * trailing_comment(void)
Definition: pt-except.h:80
comment_list * leading_comment(void)
Definition: pt-except.h:76
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
comment_list * m_lead_comm
Definition: pt-except.h:99
tree_identifier * identifier(void)
Definition: pt-except.h:70
tree_statement_list * m_catch_code
Definition: pt-except.h:93
tree_try_catch_command & operator=(const tree_try_catch_command &)=delete
tree_try_catch_command(const tree_try_catch_command &)=delete
tree_try_catch_command(int l=-1, int c=-1)
Definition: pt-except.h:46
tree_statement_list * body(void)
Definition: pt-except.h:72
void accept(tree_walker &tw)
Definition: pt-except.h:82
tree_statement_list * m_try_code
Definition: pt-except.h:90
tree_statement_list * cleanup(void)
Definition: pt-except.h:141
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:120
tree_statement_list * m_cleanup_code
Definition: pt-except.h:161
tree_statement_list * body(void)
Definition: pt-except.h:139
tree_statement_list * m_unwind_protect_code
Definition: pt-except.h:157
void accept(tree_walker &tw)
Definition: pt-except.h:149
comment_list * middle_comment(void)
Definition: pt-except.h:145
tree_unwind_protect_command & operator=(const tree_unwind_protect_command &)=delete
comment_list * leading_comment(void)
Definition: pt-except.h:143
tree_unwind_protect_command(int l=-1, int c=-1)
Definition: pt-except.h:114
comment_list * trailing_comment(void)
Definition: pt-except.h:147
tree_unwind_protect_command(const tree_unwind_protect_command &)=delete
virtual void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-walk.cc:459
virtual void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-walk.cc:477