From f67834dd18859ed333c88360f4141a99dc7db5dd Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 28 May 2009 19:22:52 +0200 Subject: push for me --- ue4/mycpu/cprogram.h | 76 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 22 deletions(-) (limited to 'ue4/mycpu/cprogram.h') diff --git a/ue4/mycpu/cprogram.h b/ue4/mycpu/cprogram.h index d8f7d5e..6908db7 100644 --- a/ue4/mycpu/cprogram.h +++ b/ue4/mycpu/cprogram.h @@ -11,17 +11,43 @@ #include #include #include +#include #include #include #ifdef DEBUG # include # include #endif + +/** + * @class CProgramError + * + * Exception thrown by implemententations of CProgram + */ +class CProgramError + : public std::invalid_argument +{ + public: + /** + * @method CProgramError + * @brief Default exception ctor + * @param what message to pass along + * @return - + * @globalvars none + * @exception none + * @pre none + * @post none + */ + CProgramError(const std::string& what) + : std::invalid_argument(what) + {} +}; + #include "cinstruction.h" #include "instructions.h" /* forward declare CInstruction */ -template, int width=0> +template class CInstruction; /** @@ -30,9 +56,9 @@ class CInstruction; * CProgram extends std::vector and adds a method for parsing * programfile. This adds instances of CInstruction to CProgram itself. */ -template, int width=0> +template class CProgram - : public std::vector *> + : public std::vector *> { typedef typename std::set *>::iterator setiterator; typedef std::vector *> super; @@ -49,7 +75,8 @@ class CProgram * @return - * @globalvars none * @exception none - * @conditions none + * @pre none + * @post none */ CProgram(); @@ -60,7 +87,8 @@ class CProgram * @return - * @globalvars none * @exception none - * @conditions none + * @pre none + * @post none */ ~CProgram(); @@ -71,7 +99,8 @@ class CProgram * @return reference to labels map * @globalvars none * @exception none - * @conditions none + * @pre none + * @post none */ const std::map& getLabels() const { @@ -84,8 +113,9 @@ class CProgram * @param label name of label to search for * @return index of found label in program * @globalvars none - * @exception std::runtime_error - * @conditions none + * @exception CProgramError + * @pre none + * @post none */ unsigned findLabel(const std::string& label) const; @@ -95,8 +125,9 @@ class CProgram * @param in inputstream to read from * @return void * @globalvars none - * @exception std::runtime_error - * @conditions none + * @exception CProgramError + * @pre none + * @post none */ void compile(std::istream& in); @@ -108,7 +139,8 @@ class CProgram * @return void * @globalvars none * @exception none - * @conditions none + * @pre none + * @post none */ void dump(std::ostream& out); #endif @@ -122,7 +154,7 @@ class CProgram /*----------------------------------------------------------------------------*/ -template, int width=0> +template CProgram::CProgram() { m_instrset.insert(new CInstructionInc); @@ -143,7 +175,7 @@ CProgram::CProgram() /*----------------------------------------------------------------------------*/ -template, int width=0> +template CProgram::~CProgram() { /* free instruction set */ @@ -157,7 +189,7 @@ CProgram::~CProgram() /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CProgram::compile(std::istream& in) { if (!in.good()) @@ -200,7 +232,7 @@ void CProgram::compile(std::istream& in) { std::stringstream sstr; sstr << "Unknown instruction '" << instrname << "' on line " << i << "."; - throw std::runtime_error(sstr.str()); + throw CProgramError(sstr.str()); } /* create instruction */ @@ -219,20 +251,20 @@ void CProgram::compile(std::istream& in) if (instrname == "label") { if (instrparams.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); std::string label(instrparams.front()); if (label.length() < 2 || label[ label.length() - 1] != ':') - throw std::runtime_error("Label has invalid syntax"); + throw CInstructionError("Label has invalid syntax"); m_labels[ label.substr(0, label.length() - 1) ] = size(); } instr->compile(instrparams); } - catch(std::runtime_error& ex) + catch(CInstructionError& ex) { std::stringstream sstr; sstr << "Unable to compile instruction '" << instrname << "' (line " << i << "): " << ex.what(); - throw std::runtime_error(sstr.str()); + throw CProgramError(sstr.str()); } push_back(instr); @@ -241,20 +273,20 @@ void CProgram::compile(std::istream& in) /*----------------------------------------------------------------------------*/ -template, int width=0> +template unsigned CProgram::findLabel(const std::string& label) const { std::map::const_iterator it; it = m_labels.find(label); if (it == m_labels.end()) - throw std::runtime_error("Unknown label '" + label + "'"); + throw CProgramError("Unknown label '" + label + "'"); return it->second; } /*----------------------------------------------------------------------------*/ #if DEBUG -template, int width=0> +template void CProgram::dump(std::ostream& out) { out << "[PROGRAM DUMP]" << std::endl; -- cgit v1.2.3