libs/EDoc/CatchBlock.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/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 }

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