GNU Octave 10.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-2025 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
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 tree_identifier * identifier () { return m_expr_id; }
58
59 tree_statement_list * body () { return m_try_code; }
60
61 tree_statement_list * cleanup () { return m_catch_code; }
62
64 {
65 tw.visit_try_catch_command (*this);
66 }
67
68private:
69
70 token m_try_tok;
71
72 // The first block of code to attempt to execute.
73 tree_statement_list *m_try_code;
74
75 token m_catch_tok;
76
77 // Identifier to modify.
78 tree_identifier *m_expr_id;
79
80 // The code to execute if an error occurs in the first block.
81 tree_statement_list *m_catch_code;
82
83 token m_end_tok;
84};
85
86// Simple exception handling.
87
89{
90public:
91
92 tree_unwind_protect_command (const token& unwind_tok, tree_statement_list *tc, const token& cleanup_tok, tree_statement_list *cc, const token& end_tok)
93 : m_unwind_tok (unwind_tok), m_unwind_protect_code (tc), m_cleanup_tok (cleanup_tok), m_cleanup_code (cc), m_end_tok (end_tok)
94 { }
95
96 OCTAVE_DISABLE_COPY_MOVE (tree_unwind_protect_command)
97
99
100 filepos beg_pos () const { return m_unwind_tok.beg_pos (); }
101 filepos end_pos () const { return m_end_tok.end_pos (); }
102
103 tree_statement_list * body () { return m_unwind_protect_code; }
104
105 tree_statement_list * cleanup () { return m_cleanup_code; }
106
108 {
110 }
111
112private:
113
114 token m_unwind_tok;
115
116 // The first body of code to attempt to execute.
117 tree_statement_list *m_unwind_protect_code;
118
119 token m_cleanup_tok;
120
121 // The body of code to execute no matter what happens in the first
122 // body of code.
123 tree_statement_list *m_cleanup_code;
124
125 token m_end_tok;
126};
127
128OCTAVE_END_NAMESPACE(octave)
129
130#endif
Definition token.h:42
filepos end_pos() const
Definition token.h:129
filepos beg_pos() const
Definition token.h:128
tree_identifier * identifier()
Definition pt-except.h:57
void accept(tree_walker &tw)
Definition pt-except.h:63
tree_statement_list * cleanup()
Definition pt-except.h:61
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:59
filepos end_pos() const
Definition pt-except.h:55
tree_statement_list * cleanup()
Definition pt-except.h:105
filepos end_pos() const
Definition pt-except.h: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)
Definition pt-except.h:92
void accept(tree_walker &tw)
Definition pt-except.h:107
filepos beg_pos() const
Definition pt-except.h:100
tree_statement_list * body()
Definition pt-except.h:103
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