1 /*- 2 * Copyright (c) 2004 - 2011 CTPP Team 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 4. Neither the name of the CTPP Team nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * CTPP2VMStackException.hpp 29 * 30 * $CTPP$ 31 */ 32 #ifndef _CTPP2_VM_STACK_EXCEPTION_HPP__ 33 #define _CTPP2_VM_STACK_EXCEPTION_HPP__ 1 34 35 #include "CTPP2VMException.hpp" 36 37 /** 38 @file VMStackException.hpp 39 @brief Virtual machine stack exceptions 40 */ 41 42 namespace CTPP // C++ Template Engine 43 { 44 45 /** 46 @class StackOverflow CTPP2VMStackException.hpp <CTPP2VMStackException.hpp> 47 @brief Stack overflow error 48 */ 49 class StackOverflow: 50 public VMException 51 { 52 public: 53 /** 54 @brief Constructor 55 @param iIIP - instruction pointer 56 @param iIDebugInfo - debug information 57 @param szISourceName - source file name 58 */ StackOverflow(const UINT_32 iIIP,const UINT_64 iIDebugInfo=0,CCHAR_P szISourceName=NULL)59 inline StackOverflow(const UINT_32 iIIP, 60 const UINT_64 iIDebugInfo = 0, 61 CCHAR_P szISourceName = NULL): iIP(iIIP), 62 iDebugInfo(iIDebugInfo), 63 szSourceName(NULL) 64 { 65 if (szISourceName != NULL) { szSourceName = strdup(szISourceName); } 66 } 67 68 69 /** @return A asciz string describing the general cause of error */ what() const70 inline CCHAR_P what() const throw() { return "Stack overflow"; } 71 72 /** 73 @brief Get instruction pointer 74 @return Instruction pointer 75 */ GetIP() const76 inline UINT_32 GetIP() const throw() { return iIP; } 77 78 /** 79 @brief Get debug information 80 @return Packed VMDebugInfo object 81 */ GetDebugInfo() const82 inline UINT_64 GetDebugInfo() const throw() { return iDebugInfo; } 83 84 /** 85 @brief Get name of template 86 @return Template name, asciz string 87 */ GetSourceName() const88 virtual CCHAR_P GetSourceName() const throw() { return szSourceName; } 89 90 /** @brief A destructor */ ~StackOverflow()91 inline ~StackOverflow() throw() 92 { 93 free(szSourceName); 94 } 95 private: 96 /** Instruction pointer */ 97 const UINT_32 iIP; 98 /** Debug information */ 99 const UINT_64 iDebugInfo; 100 /** Template source name */ 101 CHAR_P szSourceName; 102 }; 103 104 /** 105 @class StackUnderflow CTPP2VMStackException.hpp <CTPP2VMStackException.hpp> 106 @brief Stack underflow; throws when pop method called on empty stack 107 */ 108 class StackUnderflow: 109 public VMException 110 { 111 public: 112 /** 113 @brief Constructor 114 @param iIIP - instruction pointer 115 @param iIDebugInfo - debug information 116 @param szISourceName - source file name 117 */ StackUnderflow(const UINT_32 iIIP,const UINT_64 iIDebugInfo=0,CCHAR_P szISourceName=NULL)118 inline StackUnderflow(const UINT_32 iIIP, 119 const UINT_64 iIDebugInfo = 0, 120 CCHAR_P szISourceName = NULL): iIP(iIIP), 121 iDebugInfo(iIDebugInfo), 122 szSourceName(NULL) 123 { 124 if (szISourceName != NULL) { szSourceName = strdup(szISourceName); } 125 } 126 127 128 /** @return A asciz string describing the general cause of error */ what() const129 inline CCHAR_P what() const throw() { return "Stack underflow"; } 130 131 /** 132 @brief Get instruction pointer 133 @return Instruction pointer 134 */ GetIP() const135 inline UINT_32 GetIP() const throw() { return iIP; } 136 137 /** 138 @brief Get debug information 139 @return Packed VMDebugInfo object 140 */ GetDebugInfo() const141 inline UINT_64 GetDebugInfo() const throw() { return iDebugInfo; } 142 143 /** 144 @brief Get name of template 145 @return Template name, asciz string 146 */ GetSourceName() const147 virtual CCHAR_P GetSourceName() const throw() { return szSourceName; } 148 149 /** @brief A destructor */ ~StackUnderflow()150 inline ~StackUnderflow() throw() 151 { 152 free(szSourceName); 153 } 154 155 private: 156 /** Instruction pointer */ 157 const UINT_32 iIP; 158 /** Debug information */ 159 const UINT_64 iDebugInfo; 160 /** Template source name */ 161 CHAR_P szSourceName; 162 }; 163 164 } // namespace CTPP 165 #endif // _CTPP2_VM_STACK_EXCEPTION_HPP__ 166 // End. 167