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_TRYBLOCK_H 00020 #define EDOC_TRYBLOCK_H 00021 00022 #include "EDoc/DictionarySpecific.h" 00023 #include "EDoc/CatchBlock.h" 00024 00025 #include <string> 00026 #include <ostream> 00027 #include <vector> 00028 #include <list> 00029 00030 namespace EDoc 00031 { 00032 class PersistenceIFace; 00033 class IndexedDictionary; 00034 class Dictionary; 00035 class CodeBlock; 00036 class PStack; 00037 class Function; 00038 00039 //=========================================================================== 00040 /** \brief Represents a try block in C++ code. 00041 * 00042 * An instance of this class is created for every try block encountered in 00043 * C++ code. It is also created for certain other constructs like a special 00044 * cases where no exceptions are allowed. This is a special usage of the try 00045 * block. 00046 * 00047 * In normal usage a TryBlock has a number of associated CatchBlock's in the 00048 * catch_blocks list. When an exception occurs in the try block it can be 00049 * handled in one of the catch blocks. A special usage of this however is 00050 * when the catch_blocks list is empty. This is used to represent a block of 00051 * code that MUST NOT THROW ANY EXCEPTIONS. This is a special construct 00052 * defined internally to GCC for certain situations. 00053 */ 00054 class TryBlock : public DictionarySpecific 00055 { 00056 public: 00057 00058 //------------------------------------------------------------------------ 00059 /** \brief See CodeBlock::CodeBlock(Dictionary* dict_in=NULL) 00060 */ 00061 TryBlock(Dictionary* dict_in=NULL); 00062 00063 //------------------------------------------------------------------------ 00064 /** \brief See CodeBlock::CodeBlock(const CodeBlock& right) 00065 */ 00066 TryBlock(const TryBlock& right); 00067 00068 //------------------------------------------------------------------------ 00069 /** \brief See CodeBlock::CodeBlock(const CodeBlock& right, 00070 * Dictionary& dict_in) 00071 */ 00072 TryBlock(const TryBlock& right, Dictionary& dict_in); 00073 00074 //------------------------------------------------------------------------ 00075 /** \brief See CodeBlock::operator=() 00076 */ 00077 TryBlock& operator=(const TryBlock& right); 00078 00079 //------------------------------------------------------------------------ 00080 /** \brief Destructor. 00081 */ 00082 ~TryBlock(); 00083 00084 //------------------------------------------------------------------------ 00085 /** \brief See CodeBlock::Read() 00086 */ 00087 void Read(PersistenceIFace& file, IndexedDictionary& idict); 00088 00089 //------------------------------------------------------------------------ 00090 /** \brief See CodeBlock::Write() 00091 */ 00092 void Write(PersistenceIFace& file) const; 00093 00094 //------------------------------------------------------------------------ 00095 /** \brief See DictionarySpecific::ReplaceReferences() 00096 */ 00097 virtual size_t ReplaceReferences(PStack& stack, 00098 void* remove, void* replace); 00099 00100 //------------------------------------------------------------------------ 00101 /** \brief See DictionarySpecific::Print() 00102 */ 00103 virtual std::ostream& Print(std::ostream& out, 00104 std::string prefix="") const; 00105 00106 //------------------------------------------------------------------------ 00107 /** \brief See DictionarySpecific::Validate() 00108 */ 00109 virtual void Validate(PStack& stack, const Dictionary& dict_in) const; 00110 00111 //------------------------------------------------------------------------ 00112 /** \brief Equivilance operator (Works across dictionaries). 00113 */ 00114 bool operator==(const TryBlock& right) const; 00115 00116 00117 00118 00119 00120 00121 00122 //------------------------------------------------------------------------ 00123 /** \brief See CodeBlock::ExpandCallGraph() as this is just a wrapper that 00124 * calls that in order to improve code readability. 00125 */ 00126 void ExpandCallGraph(Function& function); 00127 00128 00129 //------------------------------------------------------------------------ 00130 /** \brief A reference to the block of code executed inside the try block. 00131 * 00132 * Note: This is a pointer so we can have circular dependencies. It is 00133 * simplest to break the circular include chain by making CodeBlock an 00134 * incomplete type in both the CatchBlock and TryBlock classes. 00135 */ 00136 CodeBlock* try_block; 00137 00138 //------------------------------------------------------------------------ 00139 /** \brief A list of catch blocks in the order in which they are defined 00140 * in the C++ code. 00141 */ 00142 std::vector<CatchBlock> catch_blocks; 00143 00144 //------------------------------------------------------------------------ 00145 00146 }; 00147 //=========================================================================== 00148 typedef std::list<TryBlock> TryBlockList; 00149 00150 } 00151 00152 #endif // EDOC_TRYBLOCK_H