00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include "EDoc/CatchBlock.h"
00022 #include "EDoc/CodeBlock.h"
00023 #include "EDoc/Type.h"
00024 #include "EDoc/PStack.h"
00025 #include "EDoc/StackRef.h"
00026 #include "EDoc/Dictionary.h"
00027
00028 namespace EDoc
00029 {
00030
00031 CatchBlock::CatchBlock(Dictionary* dict_in) :
00032 DictionarySpecific(dict_in),
00033 catch_type(&dict),
00034 catch_code(NULL)
00035 {
00036 catch_code = new CodeBlock(dict_in);
00037 }
00038
00039 CatchBlock::CatchBlock(const CatchBlock& right) :
00040 DictionarySpecific(&right.dict),
00041 catch_type(right.catch_type),
00042 catch_code(NULL)
00043 {
00044 catch_code = new CodeBlock(*right.catch_code);
00045 }
00046
00047 CatchBlock::CatchBlock(const CatchBlock& right, Dictionary& dict_in) :
00048 DictionarySpecific(&dict_in),
00049 catch_type(right.catch_type, dict),
00050 catch_code(NULL)
00051 {
00052 catch_code = new CodeBlock(*right.catch_code, dict);
00053 }
00054
00055 CatchBlock::~CatchBlock()
00056 {
00057 delete catch_code;
00058 catch_code = NULL;
00059 }
00060
00061 CatchBlock& CatchBlock::operator=(const CatchBlock& right)
00062 {
00063 if (this == &right)
00064 {
00065 return *this;
00066 }
00067
00068 catch_type = right.catch_type;
00069 *catch_code = *right.catch_code;
00070
00071 return *this;
00072 }
00073
00074 void CatchBlock::Read(PersistenceIFace& file, IndexedDictionary& idict)
00075 {
00076 catch_type.Read(file, idict);
00077 catch_code->Read(file, idict);
00078 }
00079
00080 void CatchBlock::Write(PersistenceIFace& file) const
00081 {
00082 catch_type.Write(file);
00083 catch_code->Write(file);
00084 }
00085
00086 bool CatchBlock::operator==(const CatchBlock& right) const
00087 {
00088 return catch_type == right.catch_type && *catch_code == *right.catch_code;
00089 }
00090
00091 size_t CatchBlock::ReplaceReferences(PStack& stack, void* remove,
00092 void* replace)
00093 {
00094 size_t count = 0;
00095 if (!stack.Push(this))
00096 {
00097 return count;
00098 }
00099
00100 count += catch_type.ReplaceReferences(stack, remove, replace);
00101 count += catch_code->ReplaceReferences(stack, remove, replace);
00102
00103 return count;
00104 }
00105
00106 std::ostream& CatchBlock::Print(std::ostream& out, std::string prefix) const
00107 {
00108 out << prefix << "catch(" << catch_type.value->GetKeyName()
00109 << ")" << std::endl;
00110 return catch_code->Print(out, prefix);
00111 }
00112
00113 void CatchBlock::ExpandCallGraph(Function& function)
00114 {
00115 catch_code->ExpandCallGraph(function);
00116 }
00117
00118 void CatchBlock::Validate(PStack& stack, const Dictionary& dict_in) const
00119 {
00120 StackRef ref(stack, this);
00121 if (!ref)
00122 {
00123 return;
00124 }
00125
00126 EDOC_ASSERT(&dict == &dict_in, "");
00127
00128 catch_type.Validate(stack, dict_in);
00129 EDOC_ASSERT(
00130 catch_type.value->throw_type->external_linkage,
00131 "Throw type of a catch blocks type should ALWAYS have "
00132 "external linkage."
00133 << "\nCatch type is: " << catch_type.value->GetKeyName()
00134 << "\nThrow type is: " << catch_type.value->throw_type->GetKeyName());
00135 catch_code->Validate(stack, dict_in);
00136 }
00137
00138 }