GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-except.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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
37class comment_list;
39
40// Simple exception handling.
41
42class OCTINTERP_API tree_try_catch_command : public tree_command
43{
44public:
45
46 tree_try_catch_command (const token try_tok, tree_statement_list *tc, const token catch_tok, tree_identifier *id, tree_statement_list *cc, const token& end_tok)
47 : m_try_tok (try_tok), m_try_code (tc), m_catch_tok (catch_tok), m_expr_id (id), m_catch_code (cc), m_end_tok (end_tok)
48 { }
49
50 OCTAVE_DISABLE_COPY_MOVE (tree_try_catch_command)
51
53
54 filepos beg_pos () const { return m_try_tok.beg_pos (); }
55 filepos end_pos () const { return m_end_tok.end_pos (); }
56
57 comment_list leading_comments () const { return m_try_tok.leading_comments (); }
58 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
59
60 token try_token () const { return m_try_tok; }
61
62 tree_statement_list * body () { return m_try_code; }
63
64 token catch_token () const { return m_catch_tok; }
65
66 tree_identifier * identifier () { return m_expr_id; }
67
68 tree_statement_list * cleanup () { return m_catch_code; }
69
70 token end_token () const { return m_end_tok; }
71
73 {
74 tw.visit_try_catch_command (*this);
75 }
76
77private:
78
79 token m_try_tok;
80
81 // The first block of code to attempt to execute.
82 tree_statement_list *m_try_code;
83
84 token m_catch_tok;
85
86 // Identifier to modify.
87 tree_identifier *m_expr_id;
88
89 // The code to execute if an error occurs in the first block.
90 tree_statement_list *m_catch_code;
91
92 token m_end_tok;
93};
94
95// Simple exception handling.
96
97class OCTINTERP_API tree_unwind_protect_command : public tree_command
98{
99public:
100
101 tree_unwind_protect_command (const token& unwind_tok, tree_statement_list *tc, const token& cleanup_tok, tree_statement_list *cc, const token& end_tok)
102 : m_unwind_tok (unwind_tok), m_unwind_protect_code (tc), m_cleanup_tok (cleanup_tok), m_cleanup_code (cc), m_end_tok (end_tok)
103 { }
104
105 OCTAVE_DISABLE_COPY_MOVE (tree_unwind_protect_command)
106
108
109 filepos beg_pos () const { return m_unwind_tok.beg_pos (); }
110 filepos end_pos () const { return m_end_tok.end_pos (); }
111
112 comment_list leading_comments () const { return m_unwind_tok.leading_comments (); }
113 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
114
115 token unwind_token () const { return m_unwind_tok; }
116
117 tree_statement_list * body () { return m_unwind_protect_code; }
118
119 token cleanup_token () { return m_cleanup_tok; }
120
121 tree_statement_list * cleanup () { return m_cleanup_code; }
122
123 token end_token () { return m_end_tok; }
124
126 {
128 }
129
130private:
131
132 token m_unwind_tok;
133
134 // The first body of code to attempt to execute.
135 tree_statement_list *m_unwind_protect_code;
136
137 token m_cleanup_tok;
138
139 // The body of code to execute no matter what happens in the first
140 // body of code.
141 tree_statement_list *m_cleanup_code;
142
143 token m_end_tok;
144};
145
146OCTAVE_END_NAMESPACE(octave)
147
148#endif
Definition token.h:42
tree_identifier * identifier()
Definition pt-except.h:66
void accept(tree_walker &tw)
Definition pt-except.h:72
comment_list trailing_comments() const
Definition pt-except.h:58
tree_statement_list * cleanup()
Definition pt-except.h:68
comment_list leading_comments() const
Definition pt-except.h:57
token catch_token() const
Definition pt-except.h:64
token end_token() const
Definition pt-except.h:70
token try_token() const
Definition pt-except.h:60
tree_try_catch_command(const token try_tok, tree_statement_list *tc, const token catch_tok, tree_identifier *id, tree_statement_list *cc, const token &end_tok)
Definition pt-except.h:46
filepos beg_pos() const
Definition pt-except.h:54
tree_statement_list * body()
Definition pt-except.h:62
filepos end_pos() const
Definition pt-except.h:55
tree_statement_list * cleanup()
Definition pt-except.h:121
comment_list trailing_comments() const
Definition pt-except.h:113
filepos end_pos() const
Definition pt-except.h:110
tree_unwind_protect_command(const token &unwind_tok, tree_statement_list *tc, const token &cleanup_tok, tree_statement_list *cc, const token &end_tok)
Definition pt-except.h:101
void accept(tree_walker &tw)
Definition pt-except.h:125
filepos beg_pos() const
Definition pt-except.h:109
comment_list leading_comments() const
Definition pt-except.h:112
tree_statement_list * body()
Definition pt-except.h:117
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