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/PropogatingException.h"
00022 #include "EDoc/Exception.h"
00023 #include "EDoc/Function.h"
00024 #include "EDoc/exceptions.h"
00025 #include "EDoc/utils.h"
00026 #include "EDoc/PStack.h"
00027 #include "EDoc/StackRef.h"
00028 #include "EDoc/Type.h"
00029 #include "EDoc/Dictionary.h"
00030
00031 namespace EDoc
00032 {
00033
00034 PropogatingException::PropogatingException(Dictionary& dict_in,
00035 Exception* exception_in,
00036 FunctionLoc& func_in) :
00037
00038 DictionarySpecific(&dict_in),
00039 exception(exception_in),
00040 func(func_in),
00041 possible(func_in.possible),
00042 visible(true),
00043 orig_subst(false)
00044 {
00045 }
00046
00047 PropogatingException::PropogatingException(Dictionary* dict_in) :
00048 DictionarySpecific(dict_in),
00049 exception(NULL),
00050 func(NULL),
00051 possible(false),
00052 visible(true),
00053 orig_subst(false)
00054 {
00055 }
00056
00057 PropogatingException::PropogatingException(
00058 const PropogatingException& right) :
00059
00060 DictionarySpecific(&right.dict),
00061 exception(right.exception),
00062 func(right.func),
00063 rethrows(right.rethrows),
00064 possible(right.possible),
00065 visible(right.visible),
00066 orig_subst(right.orig_subst)
00067 {
00068
00069 EDOC_ASSERT(&exception->dict == &dict, "");
00070 }
00071
00072 PropogatingException& PropogatingException::operator=(
00073 const PropogatingException& right)
00074 {
00075 if (this == &right)
00076 {
00077 return *this;
00078 }
00079
00080
00081 EDOC_ASSERT(&dict == &right.dict, "");
00082
00083 exception = right.exception;
00084 func = right.func;
00085 rethrows = right.rethrows;
00086 possible = right.possible;
00087 visible = right.visible;
00088 orig_subst = right.orig_subst;
00089 return *this;
00090 }
00091
00092 void PropogatingException::Validate(PStack& stack,
00093 const Dictionary& dict_in) const
00094 {
00095 StackRef ref(stack, this);
00096 if (!ref)
00097 {
00098 return;
00099 }
00100
00101 EDOC_ASSERT(&dict == &dict_in, "");
00102
00103 exception->Validate(stack, dict_in);
00104 func.Validate(stack, dict_in);
00105 EDOC_FOREACH_CONST(ExcepPList, it, rethrows)
00106 {
00107 (*it)->Validate(stack, dict_in);
00108 EDOC_ASSERT((*it)->type.value->GetDeclaredName() == "...", "");
00109 }
00110
00111 if (orig_subst)
00112 {
00113 EDOC_ASSERT(exception->type.value->GetDeclaredName() == "....", "");
00114 }
00115
00116
00117
00118
00119
00120
00121 if (func.possible)
00122 {
00123 EDOC_ASSERT(possible, "");
00124 }
00125 }
00126
00127 bool PropogatingException::operator==(
00128 const PropogatingException& right) const
00129 {
00130
00131
00132
00133 return (exception == right.exception) && (func == right.func);
00134 }
00135
00136 size_t PropogatingException::ReplaceReferences(PStack& stack, void* remove,
00137 void* replace)
00138 {
00139 size_t count = 0;
00140 if (!stack.Push(this))
00141 {
00142 return count;
00143 }
00144
00145 count += exception->ReplaceReferences(stack, remove, replace);
00146 count += func.ReplaceReferences(stack, remove, replace);
00147
00148 EDOC_FOREACH_CONST(ExcepPList, it, rethrows)
00149 {
00150 count += (*it)->ReplaceReferences(stack, remove, replace);
00151 }
00152
00153 return count;
00154 }
00155
00156 std::ostream& PropogatingException::Print(std::ostream& out,
00157 std::string prefix) const
00158 {
00159 out << prefix << "Propogating Exception Type: "
00160 << exception->type.value->GetKeyName() << std::endl;
00161 out << prefix << "{" << std::endl;
00162
00163
00164 exception->Print(out, prefix + INDENT_STR + "Exception: ");
00165
00166
00167 func.Print(out, prefix + INDENT_STR + "FunctionLoc: ");
00168
00169 EDOC_FOREACH_CONST(ExcepPList, it, rethrows)
00170 {
00171 out << prefix << INDENT_STR << "Rethrown line: "
00172 << (*it)->type.loc.line << std::endl;
00173 }
00174
00175 out << prefix << "}" << std::endl;
00176
00177 return out;
00178 }
00179
00180 bool PropogatingException::IsVisible() const
00181 {
00182 return visible && exception->visible && exception->type.value->visible;
00183 }
00184
00185 }
00186