libs/EDoc/PropogatingException.cpp

Go to the documentation of this file.
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 #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       // Cant copy propogating exception objects across dictionary boundaries.
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       // Cant copy propogating exception objects across dictionary boundaries.
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       // If it was constructed from a "Possible" function call then it is
00117       // mandatory that it also be defined as possible. It may however be that
00118       // it was constructed from a non-possible function call but propogated up
00119       // as a possible exception so it is not necessary that if func.possible is
00120       // false that this.possible will be false.
00121       if (func.possible)
00122       {
00123          EDOC_ASSERT(possible, "");
00124       }
00125    }
00126    //===========================================================================
00127    bool PropogatingException::operator==(
00128       const PropogatingException& right) const
00129    {
00130       // NOTE: Does not look at the rethrow list for equality.
00131       
00132       // @@@Brendon Performing pointer equality.
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       // Display the original Exception object.
00164       exception->Print(out, prefix + INDENT_STR + "Exception: ");
00165       
00166       // Display the function location.
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 

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1