00001 /******************************************************************************* 00002 00003 Copyright (C) 2007 by Brendon Costa 00004 00005 This library is free software; you can redistribute it and/or modify 00006 it under the terms of the "LGPL Like" License defined in the file COPYING 00007 that should have been distributed along with this source. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 You should have received a copy of the "LGPL Like" License 00014 along with this library; see the file COPYING. if not, it can be 00015 obtained from the EDoc++ website: 00016 http://edoc.sourceforge.net/license.html 00017 00018 *******************************************************************************/ 00019 #ifndef EDOC_CATCHBLOCK_H 00020 #define EDOC_CATCHBLOCK_H 00021 00022 #include "EDoc/DictionarySpecific.h" 00023 #include "EDoc/TypeLoc.h" 00024 #include "EDoc/stdint.h" 00025 00026 #include <string> 00027 #include <ostream> 00028 #include <sstream> 00029 #include <vector> 00030 00031 namespace EDoc 00032 { 00033 class PersistenceIFace; 00034 class IndexedDictionary; 00035 class Dictionary; 00036 class Type; 00037 class CodeBlock; 00038 class PStack; 00039 class Function; 00040 typedef CodeBlock* CodeBlockPtr; 00041 00042 //=========================================================================== 00043 /** \brief Represents a catch statement in a block of code. 00044 * 00045 * Every catch block should be asssociated with a try block. It contains 00046 * information about the catch type, and stores a CodeBlock instance that 00047 * contains the code executed if an exception is encountered which matches 00048 * the catch_type. 00049 * 00050 * The following code will produce 2 CatchBlock instances one for the 00051 * catch(int) and the other for the catch(...) 00052 * 00053 * \code 00054 * try 00055 * { 00056 * ...code... 00057 * } 00058 * catch(int i) 00059 * { 00060 * ...code... 00061 * } 00062 * catch(...) 00063 * { 00064 * ...code... 00065 * } 00066 * 00067 * \endcode 00068 * 00069 */ 00070 class CatchBlock : public DictionarySpecific 00071 { 00072 public: 00073 00074 //------------------------------------------------------------------------ 00075 /** \brief See CodeBlock::CodeBlock(Dictionary* dict_in=NULL) 00076 */ 00077 CatchBlock(Dictionary* dict_in=NULL); 00078 00079 //------------------------------------------------------------------------ 00080 /** \brief See CodeBlock::CodeBlock(const CodeBlock& right) 00081 */ 00082 CatchBlock(const CatchBlock& right); 00083 00084 //------------------------------------------------------------------------ 00085 /** \brief See CodeBlock::CodeBlock(const CodeBlock& right, 00086 * Dictionary& dict_in) 00087 */ 00088 CatchBlock(const CatchBlock& right, Dictionary& dict_in); 00089 00090 //------------------------------------------------------------------------ 00091 /** \brief See CodeBlock::operator=() 00092 */ 00093 CatchBlock& operator=(const CatchBlock& right); 00094 00095 //------------------------------------------------------------------------ 00096 /** \brief Destructor. 00097 */ 00098 ~CatchBlock(); 00099 00100 //------------------------------------------------------------------------ 00101 /** \brief See CodeBlock::Read() 00102 */ 00103 void Read(PersistenceIFace& file, IndexedDictionary& idict); 00104 00105 //------------------------------------------------------------------------ 00106 /** \brief See CodeBlock::Write() 00107 */ 00108 void Write(PersistenceIFace& file) const; 00109 00110 //------------------------------------------------------------------------ 00111 /** \brief See DictionarySpecific::ReplaceReferences() 00112 */ 00113 virtual size_t ReplaceReferences(PStack& stack, 00114 void* remove, void* replace); 00115 00116 //------------------------------------------------------------------------ 00117 /** \brief See DictionarySpecific::Print() 00118 */ 00119 virtual std::ostream& Print(std::ostream& out, 00120 std::string prefix="") const; 00121 00122 //------------------------------------------------------------------------ 00123 /** \brief See DictionarySpecific::Validate() 00124 */ 00125 virtual void Validate(PStack& stack, const Dictionary& dict_in) const; 00126 00127 //------------------------------------------------------------------------ 00128 /** \brief Equivilance operator (Works across dictionaries). 00129 */ 00130 bool operator==(const CatchBlock& right) const; 00131 00132 00133 00134 00135 //------------------------------------------------------------------------ 00136 /** \brief See CodeBlock::ExpandCallGraph() as this is just a wrapper that 00137 * calls that in order to improve code readability. 00138 */ 00139 void ExpandCallGraph(Function& function); 00140 00141 00142 00143 //------------------------------------------------------------------------ 00144 // Public Primary Data values. 00145 //------------------------------------------------------------------------ 00146 00147 //------------------------------------------------------------------------ 00148 /** \brief The type of exception this object will catch. 00149 * 00150 * This is the type "..." for a catch all. 00151 */ 00152 TypeLoc catch_type; 00153 00154 //------------------------------------------------------------------------ 00155 /** \brief The code that is executed upon this catch block handling 00156 * an exception. 00157 * 00158 * Note: This is a pointer so we can have circular dependencies. It is 00159 * simplest to break the circular include chain by making CodeBlock an 00160 * incomplete type in both the CatchBlock and TryBlock classes. 00161 */ 00162 CodeBlockPtr catch_code; 00163 00164 //------------------------------------------------------------------------ 00165 }; 00166 //=========================================================================== 00167 typedef std::vector<CatchBlock> CatchBlockVec; 00168 } 00169 00170 #endif // EDOC_CATCHBLOCK_H