File: pt-except.h

package info (click to toggle)
octave 11.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 148,828 kB
  • sloc: cpp: 347,638; ansic: 85,112; fortran: 20,693; objc: 10,276; sh: 8,747; lex: 4,496; yacc: 4,406; perl: 1,549; java: 1,365; awk: 1,282; makefile: 666; xml: 193
file content (148 lines) | stat: -rw-r--r-- 4,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1996-2026 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING.  If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if ! defined (octave_pt_except_h)
#define octave_pt_except_h 1

#include "octave-config.h"

#include "pt-cmd.h"
#include "pt-id.h"
#include "pt-walk.h"

OCTAVE_BEGIN_NAMESPACE(octave)

class comment_list;
class tree_statement_list;

// Simple exception handling.

class OCTINTERP_API tree_try_catch_command : public tree_command
{
public:

  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)
    : 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)
  { }

  OCTAVE_DISABLE_COPY_MOVE (tree_try_catch_command)

  ~tree_try_catch_command ();

  filepos beg_pos () const { return m_try_tok.beg_pos (); }
  filepos end_pos () const { return m_end_tok.end_pos (); }

  comment_list leading_comments () const { return m_try_tok.leading_comments (); }
  comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }

  token try_token () const { return m_try_tok; }

  tree_statement_list * body () { return m_try_code; }

  token catch_token () const { return m_catch_tok; }

  tree_identifier * identifier () { return m_expr_id; }

  tree_statement_list * cleanup () { return m_catch_code; }

  token end_token () const { return m_end_tok; }

  void accept (tree_walker& tw)
  {
    tw.visit_try_catch_command (*this);
  }

private:

  token m_try_tok;

  // The first block of code to attempt to execute.
  tree_statement_list *m_try_code;

  token m_catch_tok;

  // Identifier to modify.
  tree_identifier *m_expr_id;

  // The code to execute if an error occurs in the first block.
  tree_statement_list *m_catch_code;

  token m_end_tok;
};

// Simple exception handling.

class OCTINTERP_API tree_unwind_protect_command : public tree_command
{
public:

  tree_unwind_protect_command (const token& unwind_tok, tree_statement_list *tc, const token& cleanup_tok, tree_statement_list *cc, const token& end_tok)
    : m_unwind_tok (unwind_tok), m_unwind_protect_code (tc), m_cleanup_tok (cleanup_tok), m_cleanup_code (cc), m_end_tok (end_tok)
  { }

  OCTAVE_DISABLE_COPY_MOVE (tree_unwind_protect_command)

  ~tree_unwind_protect_command ();

  filepos beg_pos () const { return m_unwind_tok.beg_pos (); }
  filepos end_pos () const { return m_end_tok.end_pos (); }

  comment_list leading_comments () const { return m_unwind_tok.leading_comments (); }
  comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }

  token unwind_token () const { return m_unwind_tok; }

  tree_statement_list * body () { return m_unwind_protect_code; }

  token cleanup_token () { return m_cleanup_tok; }

  tree_statement_list * cleanup () { return m_cleanup_code; }

  token end_token () { return m_end_tok; }

  void accept (tree_walker& tw)
  {
    tw.visit_unwind_protect_command (*this);
  }

private:

  token m_unwind_tok;

  // The first body of code to attempt to execute.
  tree_statement_list *m_unwind_protect_code;

  token m_cleanup_tok;

  // The body of code to execute no matter what happens in the first
  // body of code.
  tree_statement_list *m_cleanup_code;

  token m_end_tok;
};

OCTAVE_END_NAMESPACE(octave)

#endif