pt-except.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_tree_except_h)
00024 #define octave_tree_except_h 1
00025 
00026 class tree_statement_list;
00027 
00028 class tree_walker;
00029 
00030 #include "comment-list.h"
00031 #include "pt-cmd.h"
00032 #include "symtab.h"
00033 
00034 // Simple exception handling.
00035 
00036 class
00037 tree_try_catch_command : public tree_command
00038 {
00039 public:
00040 
00041   tree_try_catch_command (int l = -1, int c = -1)
00042     : tree_command (l, c), try_code (0), catch_code (0), lead_comm (0),
00043       mid_comm (0), trail_comm (0) { }
00044 
00045   tree_try_catch_command (tree_statement_list *tc, tree_statement_list *cc,
00046                           octave_comment_list *cl = 0,
00047                           octave_comment_list *cm = 0,
00048                           octave_comment_list *ct = 0,
00049                           int l = -1, int c = -1)
00050     : tree_command (l, c), try_code (tc), catch_code (cc),
00051       lead_comm (cl), mid_comm (cm), trail_comm (ct) { }
00052 
00053   ~tree_try_catch_command (void);
00054 
00055   tree_statement_list *body (void) { return try_code; }
00056 
00057   tree_statement_list *cleanup (void) { return catch_code; }
00058 
00059   octave_comment_list *leading_comment (void) { return lead_comm; }
00060 
00061   octave_comment_list *middle_comment (void) { return mid_comm; }
00062 
00063   octave_comment_list *trailing_comment (void) { return trail_comm; }
00064 
00065   tree_command *dup (symbol_table::scope_id scope,
00066                      symbol_table::context_id context) const;
00067 
00068   void accept (tree_walker& tw);
00069 
00070 private:
00071 
00072   // The first block of code to attempt to execute.
00073   tree_statement_list *try_code;
00074 
00075   // The code to execute if an error occurs in the first block.
00076   tree_statement_list *catch_code;
00077 
00078   // Comment preceding TRY token.
00079   octave_comment_list *lead_comm;
00080 
00081   // Comment preceding CATCH token.
00082   octave_comment_list *mid_comm;
00083 
00084   // Comment preceding END_TRY_CATCH token.
00085   octave_comment_list *trail_comm;
00086 
00087   // No copying!
00088 
00089   tree_try_catch_command (const tree_try_catch_command&);
00090 
00091   tree_try_catch_command& operator = (const tree_try_catch_command&);
00092 };
00093 
00094 // Simple exception handling.
00095 
00096 class
00097 tree_unwind_protect_command : public tree_command
00098 {
00099 public:
00100 
00101   tree_unwind_protect_command (int l = -1, int c = -1)
00102     : tree_command (l, c), unwind_protect_code (0), cleanup_code (0),
00103       lead_comm (0), mid_comm (0), trail_comm (0) { }
00104 
00105   tree_unwind_protect_command (tree_statement_list *tc,
00106                                tree_statement_list *cc,
00107                                octave_comment_list *cl = 0,
00108                                octave_comment_list *cm = 0,
00109                                octave_comment_list *ct = 0,
00110                                int l = -1, int c = -1)
00111     : tree_command (l, c), unwind_protect_code (tc), cleanup_code (cc),
00112       lead_comm (cl), mid_comm (cm), trail_comm (ct) { }
00113 
00114   ~tree_unwind_protect_command (void);
00115 
00116   tree_statement_list *body (void) { return unwind_protect_code; }
00117 
00118   tree_statement_list *cleanup (void) { return cleanup_code; }
00119 
00120   octave_comment_list *leading_comment (void) { return lead_comm; }
00121 
00122   octave_comment_list *middle_comment (void) { return mid_comm; }
00123 
00124   octave_comment_list *trailing_comment (void) { return trail_comm; }
00125 
00126   tree_command *dup (symbol_table::scope_id scope,
00127                      symbol_table::context_id context) const;
00128 
00129   void accept (tree_walker& tw);
00130 
00131 private:
00132 
00133   // The first body of code to attempt to execute.
00134   tree_statement_list *unwind_protect_code;
00135 
00136   // The body of code to execute no matter what happens in the first
00137   // body of code.
00138   tree_statement_list *cleanup_code;
00139 
00140   // Comment preceding TRY token.
00141   octave_comment_list *lead_comm;
00142 
00143   // Comment preceding CATCH token.
00144   octave_comment_list *mid_comm;
00145 
00146   // Comment preceding END_TRY_CATCH token.
00147   octave_comment_list *trail_comm;
00148 
00149   // No copying!
00150 
00151   tree_unwind_protect_command (const tree_unwind_protect_command&);
00152 
00153   tree_unwind_protect_command& operator = (const tree_unwind_protect_command&);
00154 };
00155 
00156 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines