annotate libinterp/parse-tree/pt.cc @ 27474:3fec8e9fa2aa

make recover_from_exception a member function * interpreter.h, interpreter.cc (interpreter::recover_from_exception): Now a member function. Change all uses.
author John W. Eaton <jwe@octave.org>
date Fri, 04 Oct 2019 16:40:30 -0400
parents fd32c1a9b1bd
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
1 /*
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3 Copyright (C) 1996-2019 John W. Eaton
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
4
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
16
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5765
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
19 <https://www.gnu.org/licenses/>.
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
20
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
21 */
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
25 #endif
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
26
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5388
diff changeset
27 #include <sstream>
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
28 #include <string>
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
29
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27121
diff changeset
30 #include "interpreter.h"
4748
7b145222fea3 [project @ 2004-02-07 06:27:27 by jwe]
jwe
parents: 4192
diff changeset
31 #include "ov-fcn.h"
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
32 #include "pt.h"
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
33 #include "pt-eval.h"
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
34 #include "pt-pr-code.h"
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
35 #include "unwind-prot.h"
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
36
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
37 namespace octave
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
38 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
39 // Hide the details of the string buffer so that we are less likely to
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
40 // create a memory leak.
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
41
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
42 std::string
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
43 tree::str_print_code (void)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
44 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
45 std::ostringstream buf;
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
46
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
47 tree_print_code tpc (buf);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
48
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
49 accept (tpc);
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
50
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
51 std::string retval = buf.str ();
2991
fc751d2a99fd [project @ 1997-05-16 21:00:48 by jwe]
jwe
parents:
diff changeset
52
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
53 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
54 }
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
55
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
56 // Is the current breakpoint condition met?
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
57
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
58 bool
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
59 tree::meets_bp_condition (tree_evaluator& tw) const
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
60 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
61 bool retval;
24846
7620f1f5290d use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
62 if (m_bp_cond == nullptr)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
63 retval = false;
24846
7620f1f5290d use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 else if (m_bp_cond->empty ()) // empty condition always met
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
65 retval = true;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
66 else
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
67 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
68 int parse_status = 0;
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
69
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
70 unwind_protect frame;
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
71
27121
a7c570394f1d use interpreter_try instead of accessing error settings directly
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
72 interpreter_try (frame);
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
73
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
74 retval = true; // default to stopping if any error
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
75 try
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 {
24846
7620f1f5290d use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
77 octave_value_list val
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
78 = tw.eval_string (*m_bp_cond, 1, parse_status, 1);
24846
7620f1f5290d use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
80 if (parse_status == 0)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
81 {
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
82 if (! val(0).is_scalar_type ())
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
83 warning ("Breakpoint condition must be a scalar, not size %s",
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
84 val(0).dims ().str ('x').c_str ());
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
85 else
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
86 retval = val(0).bool_value ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
87 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
88 else
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
89 warning ("Error parsing breakpoint condition");
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
90 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
91 catch (const execution_exception& e)
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
92 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
93 interpreter& interp = tw.get_interpreter ();
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
94
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
95 interp.recover_from_exception ();
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27121
diff changeset
96
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27160
diff changeset
97 std::string tmp = e.message ();
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27121
diff changeset
98
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
99 warning ("Error evaluating breakpoint condition:\n %s",
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27121
diff changeset
100 tmp.c_str ());
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
101 }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
102 }
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
103
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
104 return retval;
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
105 }
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
106 }