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/Exception.h"
00022 #include "EDoc/Dictionary.h"
00023 #include "EDoc/Function.h"
00024 #include "EDoc/PStack.h"
00025 #include "EDoc/StackRef.h"
00026 #include "EDoc/Dictionary.h"
00027 #include "EDoc/Type.h"
00028
00029 namespace EDoc
00030 {
00031
00032 Exception::Exception(Dictionary* dict_in) :
00033 DictionarySpecific(dict_in),
00034 type(dict_in),
00035 visible(true),
00036 auto_throw_spec(false),
00037 function(NULL)
00038 {
00039 }
00040
00041 Exception::Exception(const Exception& right) :
00042 DictionarySpecific(&right.dict),
00043 type(right.type),
00044 visible(right.visible),
00045 auto_throw_spec(right.auto_throw_spec),
00046 function(right.function)
00047 {
00048 }
00049
00050 Exception::Exception(const Exception& right, Dictionary& dict_in) :
00051 DictionarySpecific(&dict_in),
00052 type(right.type, dict_in),
00053 visible(right.visible),
00054 auto_throw_spec(right.auto_throw_spec),
00055 function(NULL)
00056 {
00057 if (right.function)
00058 {
00059 function = dict.functions.AlwaysGet(*right.function);
00060 }
00061 }
00062
00063 Exception& Exception::operator=(const Exception& right)
00064 {
00065 if (this == &right)
00066 {
00067 return *this;
00068 }
00069
00070 function = NULL;
00071 if (right.function)
00072 {
00073 function = dict.functions.AlwaysGet(*right.function);
00074 }
00075 type = right.type;
00076 visible = right.visible;
00077 auto_throw_spec = right.auto_throw_spec;
00078 return *this;
00079 }
00080
00081 void Exception::Validate(PStack& stack, const Dictionary& dict_in) const
00082 {
00083 StackRef ref(stack, this);
00084 if (!ref)
00085 {
00086 return;
00087 }
00088
00089 EDOC_ASSERT(&dict == &dict_in, "");
00090
00091 if (function)
00092 {
00093 function->Validate(stack, dict_in);
00094 }
00095
00096 type.Validate(stack, dict_in);
00097 }
00098
00099 void Exception::Read(PersistenceIFace& file, IndexedDictionary& idict)
00100 {
00101 type.Read(file, idict);
00102 }
00103
00104 void Exception::Write(PersistenceIFace& file) const
00105 {
00106 EDOC_ASSERT(!auto_throw_spec,
00107 "Auto generated exceptions should not be written to a merged file.");
00108 type.Write(file);
00109 }
00110
00111 bool Exception::operator==(const Exception& right) const
00112 {
00113 EDOC_Finer("function: " << function << ", right.function: "
00114 << right.function);
00115 return type == right.type && auto_throw_spec == right.auto_throw_spec;
00116 }
00117
00118
00119 #define EDOC_REPLACE(DataType, Data, From, To, Count) \
00120 if ((void*)Data == From) {Data = (DataType*)To; Count++;}
00121
00122 size_t Exception::ReplaceReferences(PStack& stack, void* remove,
00123 void* replace)
00124 {
00125 size_t count = 0;
00126 if (!stack.Push(this))
00127 {
00128 return count;
00129 }
00130
00131
00132 EDOC_REPLACE(Function, function, remove, replace, count);
00133
00134 count += type.ReplaceReferences(stack, remove, replace);
00135 return count;
00136 }
00137
00138 std::ostream& Exception::Print(std::ostream& out,
00139 std::string prefix) const
00140 {
00141 out << prefix << "Exception Type: "
00142 << type.value->GetKeyName() << std::endl;
00143 type.loc.Print(out, prefix + INDENT_STR);
00144 out << prefix << "Visible: " << (visible ? "True":"False") << std::endl;
00145 out << prefix << "Auto Generated: " << (auto_throw_spec ? "True":"False") << std::endl;
00146
00147 return out;
00148 }
00149
00150 }