comparison libinterp/parse-tree/pt-except.h @ 17249:923ce8b42db2

improve try-catch-statement to save exception to a variable (bug #33217) * oct-parse.in.yy (except_command): Handle exception identifiers. * oct-parse.in.yy, parse.h (octave_base_parser::make_try_command): New arg, ID. * pt-except.cc, pt-except.h (tree_try_catch_command::expr_id): New data member. (tree_command::tree_command): Initialize it. (tree_command::~tree_command): Delete it. (tree_command::identifier): New function. * pt-check.cc (tree_checker::visit_try_catch_command): Check for valid expr_id. * pt-pr-code.cc (tree_print_code::visit_try_catch_command): Print expr_id. * pt-eval.cc (tree_evaluator::visit_try_catch_command): Assign message and identifier to variable. * try.tst: New test. * NEWS: Note change.
author Stefan Mahr <dac922@gmx.de>
date Tue, 13 Aug 2013 19:35:53 +0200
parents 2fc554ffbc28
children d63878346099
comparison
equal deleted inserted replaced
17248:0b2a0acd0315 17249:923ce8b42db2
27 27
28 class tree_walker; 28 class tree_walker;
29 29
30 #include "comment-list.h" 30 #include "comment-list.h"
31 #include "pt-cmd.h" 31 #include "pt-cmd.h"
32 #include "pt-id.h"
32 #include "symtab.h" 33 #include "symtab.h"
33 34
34 // Simple exception handling. 35 // Simple exception handling.
35 36
36 class 37 class
37 tree_try_catch_command : public tree_command 38 tree_try_catch_command : public tree_command
38 { 39 {
39 public: 40 public:
40 41
41 tree_try_catch_command (int l = -1, int c = -1) 42 tree_try_catch_command (int l = -1, int c = -1)
42 : tree_command (l, c), try_code (0), catch_code (0), lead_comm (0), 43 : tree_command (l, c), try_code (0), catch_code (0), expr_id (0), lead_comm (0),
43 mid_comm (0), trail_comm (0) { } 44 mid_comm (0), trail_comm (0) { }
44 45
45 tree_try_catch_command (tree_statement_list *tc, tree_statement_list *cc, 46 tree_try_catch_command (tree_statement_list *tc, tree_statement_list *cc,
47 tree_identifier *id,
46 octave_comment_list *cl = 0, 48 octave_comment_list *cl = 0,
47 octave_comment_list *cm = 0, 49 octave_comment_list *cm = 0,
48 octave_comment_list *ct = 0, 50 octave_comment_list *ct = 0,
49 int l = -1, int c = -1) 51 int l = -1, int c = -1)
50 : tree_command (l, c), try_code (tc), catch_code (cc), 52 : tree_command (l, c), try_code (tc), catch_code (cc), expr_id (id),
51 lead_comm (cl), mid_comm (cm), trail_comm (ct) { } 53 lead_comm (cl), mid_comm (cm), trail_comm (ct) { }
52 54
53 ~tree_try_catch_command (void); 55 ~tree_try_catch_command (void);
56
57 tree_identifier *identifier (void) { return expr_id; }
54 58
55 tree_statement_list *body (void) { return try_code; } 59 tree_statement_list *body (void) { return try_code; }
56 60
57 tree_statement_list *cleanup (void) { return catch_code; } 61 tree_statement_list *cleanup (void) { return catch_code; }
58 62
72 // The first block of code to attempt to execute. 76 // The first block of code to attempt to execute.
73 tree_statement_list *try_code; 77 tree_statement_list *try_code;
74 78
75 // The code to execute if an error occurs in the first block. 79 // The code to execute if an error occurs in the first block.
76 tree_statement_list *catch_code; 80 tree_statement_list *catch_code;
81
82 // Identifier to modify.
83 tree_identifier *expr_id;
77 84
78 // Comment preceding TRY token. 85 // Comment preceding TRY token.
79 octave_comment_list *lead_comm; 86 octave_comment_list *lead_comm;
80 87
81 // Comment preceding CATCH token. 88 // Comment preceding CATCH token.