#include <CastInstruction.h>
Inheritance diagram for CastCast< RESULT_T, SOURCE_T >:
Public Member Functions | |
CastCast (RegisterRef< RESULT_T > *result, RegisterRef< SOURCE_T > *op1, StandardTypeDescriptorOrdinal resultType, StandardTypeDescriptorOrdinal sourceType) | |
virtual | ~CastCast () |
virtual void | exec (TProgramCounter &pc) const |
void | describe (string &out, bool values) const |
Static Public Member Functions | |
static const char * | longName () |
static const char * | shortName () |
static int | numArgs () |
static InstructionSignature | signature (StandardTypeDescriptorOrdinal type1, StandardTypeDescriptorOrdinal type2) |
static Instruction * | create (InstructionSignature const &sig) |
Protected Member Functions | |
void | describeHelper (string &out, bool values, const char *longName, const char *shortName, RegisterReference *result, RegisterReference *op1, RegisterReference *op2) const |
Protected Attributes | |
RegisterRef< RESULT_T > * | mResult |
RegisterRef< SOURCE_T > * | mOp1 |
RegisterRef< SOURCE_T > * | mOp2 |
Friends | |
class | fennel::Calculator |
Definition at line 60 of file CastInstruction.h.
CastCast< RESULT_T, SOURCE_T >::CastCast | ( | RegisterRef< RESULT_T > * | result, | |
RegisterRef< SOURCE_T > * | op1, | |||
StandardTypeDescriptorOrdinal | resultType, | |||
StandardTypeDescriptorOrdinal | sourceType | |||
) | [inline, explicit] |
Definition at line 64 of file CastInstruction.h.
Referenced by CastCast< RESULT_T, SOURCE_T >::create().
00069 : CastInstruction<RESULT_T, SOURCE_T>( 00070 result, op1, resultType, sourceType) 00071 {}
virtual void CastCast< RESULT_T, SOURCE_T >::exec | ( | TProgramCounter & | pc | ) | const [inline, virtual] |
Implements Instruction.
Definition at line 76 of file CastInstruction.h.
00076 { 00077 // See SQL99 Part 2 Section 6.22 for specification of CAST() operator 00078 pc++; 00079 if (CastInstruction<RESULT_T, SOURCE_T>::mOp1->isNull()) { 00080 // SQL99 Part 2 Section 6.22 General Rule 2.c. 00081 CastInstruction<RESULT_T, SOURCE_T>::mResult->toNull(); 00082 } else { 00083 // TODO: Update Boost library to fix the following 00084 // TODO: problem: 00085 // TODO: See lists.boost.org/MailArchives/boost/msg63700.php 00086 // TODO: for details. In short, exceptions are thrown 00087 // TODO: for cases where data is lost and the target is 00088 // TODO: unsigned, but not thrown for lost data to signed. 00089 // TODO: Also some problems with approx being cast to exact. 00090 00091 // HACK: Add some extra tests before numeric_cast to try 00092 // HACK: to catch some of the more henious and obvious errors. 00093 00094 SOURCE_T src = CastInstruction<RESULT_T, SOURCE_T>::mOp1->value(); 00095 bool thr = false; 00096 bool resultSigned = numeric_limits<RESULT_T>::is_signed; 00097 bool sourceSigned = numeric_limits<SOURCE_T>::is_signed; 00098 00099 // Note: min() for approx type is the smallest positive 00100 // number, not the most negative number. 00101 RESULT_T min = (numeric_limits<RESULT_T>::is_integer ? 00102 numeric_limits<RESULT_T>::min() : 00103 - numeric_limits<RESULT_T>::max()); 00104 RESULT_T max = numeric_limits<RESULT_T>::max(); 00105 00106 if (resultSigned == sourceSigned) { 00107 // Both signed or both unsigned (including approx) 00108 if (max < src || min > src) { 00109 thr = true; 00110 } 00111 } else if (resultSigned && !sourceSigned) { 00112 // Unsigned to signed 00113 if (max < src) { 00114 thr = true; 00115 } 00116 } else { 00117 // Signed to unsigned 00118 // RESULT_T is unsigned, SOURCE is signed 00119 if (max < src || min > src) { 00120 thr = true; 00121 } 00122 } 00123 if (thr) { 00124 throw CalcMessage("22003", pc - 1); 00125 } 00126 // HACK: End. (Phew.) 00127 00128 try { 00129 CastInstruction<RESULT_T, SOURCE_T>::mResult->value( 00130 boost::numeric_cast<RESULT_T>( 00131 CastInstruction<RESULT_T, SOURCE_T>::mOp1->value())); 00132 } catch (boost::bad_numeric_cast) { 00133 // class contains no useful information about what went wrong 00134 // SQL99 Part 2 Section 6.2 General Rule 6.a.ii, 7.a.ii 00135 // 22003 - Data Exception -- Numeric Value Out of Range 00136 throw CalcMessage("22003", pc - 1); 00137 } 00138 } 00139 }
static const char* CastCast< RESULT_T, SOURCE_T >::longName | ( | ) | [inline, static] |
Definition at line 141 of file CastInstruction.h.
Referenced by CastCast< RESULT_T, SOURCE_T >::describe().
static const char* CastCast< RESULT_T, SOURCE_T >::shortName | ( | ) | [inline, static] |
Definition at line 146 of file CastInstruction.h.
Referenced by CastCast< RESULT_T, SOURCE_T >::describe(), and CastCast< RESULT_T, SOURCE_T >::signature().
static int CastCast< RESULT_T, SOURCE_T >::numArgs | ( | ) | [inline, static] |
Definition at line 151 of file CastInstruction.h.
Referenced by CastCast< RESULT_T, SOURCE_T >::create().
void CastCast< RESULT_T, SOURCE_T >::describe | ( | string & | out, | |
bool | values | |||
) | const [inline, virtual] |
Implements Instruction.
Definition at line 156 of file CastInstruction.h.
References Instruction::describeHelper(), dummy(), CastCast< RESULT_T, SOURCE_T >::longName(), and CastCast< RESULT_T, SOURCE_T >::shortName().
00156 { 00157 RegisterRef<char> dummy; 00158 describeHelper( 00159 out, values, longName(), shortName(), 00160 CastInstruction<RESULT_T, SOURCE_T>::mResult, 00161 CastInstruction<RESULT_T, SOURCE_T>::mOp1, 00162 CastInstruction<RESULT_T, SOURCE_T>::mOp2); 00163 }
static InstructionSignature CastCast< RESULT_T, SOURCE_T >::signature | ( | StandardTypeDescriptorOrdinal | type1, | |
StandardTypeDescriptorOrdinal | type2 | |||
) | [inline, static] |
Definition at line 166 of file CastInstruction.h.
References CastCast< RESULT_T, SOURCE_T >::shortName().
00169 { 00170 vector<StandardTypeDescriptorOrdinal> v; 00171 v.push_back(type1); 00172 v.push_back(type2); 00173 return InstructionSignature(shortName(), v); 00174 }
static Instruction* CastCast< RESULT_T, SOURCE_T >::create | ( | InstructionSignature const & | sig | ) | [inline, static] |
Definition at line 177 of file CastInstruction.h.
References CastCast< RESULT_T, SOURCE_T >::CastCast(), CastCast< RESULT_T, SOURCE_T >::numArgs(), and InstructionSignature::size().
00178 { 00179 assert(sig.size() == numArgs()); 00180 return new CastCast( 00181 static_cast<RegisterRef<RESULT_T>*> (sig[0]), 00182 static_cast<RegisterRef<SOURCE_T>*> (sig[1]), 00183 (sig[0])->type(), 00184 (sig[1])->type()); 00185 }
void Instruction::describeHelper | ( | string & | out, | |
bool | values, | |||
const char * | longName, | |||
const char * | shortName, | |||
RegisterReference * | result, | |||
RegisterReference * | op1, | |||
RegisterReference * | op2 | |||
) | const [inline, protected, inherited] |
Definition at line 68 of file Instruction.h.
References RegisterReference::isNull(), RegisterReference::isValid(), RegisterReference::toString(), and RegisterReference::valueToString().
Referenced by PointerToNull< PTR_TYPE >::describe(), PointerRef< PTR_TYPE >::describe(), PointerMove< PTR_TYPE >::describe(), PointerSub< PTR_TYPE >::describe(), PointerAdd< PTR_TYPE >::describe(), PointerPutSize< PTR_TYPE >::describe(), NativeToNull< TMPLT >::describe(), NativeRef< TMPLT >::describe(), NativeMove< TMPLT >::describe(), NativeRound< TMPLT >::describe(), NativeNeg< TMPLT >::describe(), NativeDiv< TMPLT >::describe(), NativeMul< TMPLT >::describe(), NativeSub< TMPLT >::describe(), NativeAdd< TMPLT >::describe(), PointerGetMaxSize< PTR_TYPE >::describe(), PointerGetSize< PTR_TYPE >::describe(), IntegralNativeShiftRight< TMPLT >::describe(), IntegralNativeShiftLeft< TMPLT >::describe(), IntegralNativeOr< TMPLT >::describe(), IntegralNativeAnd< TMPLT >::describe(), IntegralNativeMod< TMPLT >::describe(), CastCast< RESULT_T, SOURCE_T >::describe(), BoolPointerIsNotNull< PTR_TYPE >::describe(), BoolPointerIsNull< PTR_TYPE >::describe(), BoolPointerLessEqual< PTR_TYPE >::describe(), BoolPointerLess< PTR_TYPE >::describe(), BoolPointerGreaterEqual< PTR_TYPE >::describe(), BoolPointerGreater< PTR_TYPE >::describe(), BoolPointerNotEqual< PTR_TYPE >::describe(), BoolPointerEqual< PTR_TYPE >::describe(), BoolNativeIsNotNull< TMPLT >::describe(), BoolNativeIsNull< TMPLT >::describe(), BoolNativeLessEqual< TMPLT >::describe(), BoolNativeLess< TMPLT >::describe(), BoolNativeGreaterEqual< TMPLT >::describe(), BoolNativeGreater< TMPLT >::describe(), BoolNativeNotEqual< TMPLT >::describe(), BoolNativeEqual< TMPLT >::describe(), BoolToNull::describe(), BoolIsNotNull::describe(), BoolIsNull::describe(), BoolLessEqual::describe(), BoolLess::describe(), BoolGreaterEqual::describe(), BoolGreater::describe(), BoolNotEqual::describe(), BoolEqual::describe(), BoolIsNot::describe(), BoolIs::describe(), BoolRef::describe(), BoolMove::describe(), BoolNot::describe(), BoolAnd::describe(), and BoolOr::describe().
00076 { 00077 out = longName; 00078 out += ": "; 00079 out += result->toString(); 00080 if (values) { 00081 out += " ( "; 00082 if (result->isNull()) { 00083 out += "NULL"; 00084 } else { 00085 out += result->valueToString(); 00086 } 00087 out += " ) "; 00088 } 00089 out += " = "; 00090 00091 if (!op2 || !op2->isValid()) { // if < 2 operands 00092 out += " "; 00093 out += shortName; 00094 out += " "; 00095 } 00096 if (op1 && op1->isValid()) { // 1 or 2 operands 00097 out += op1->toString(); 00098 if (values) { 00099 out += " ( "; 00100 if (op1->isNull()) { 00101 out += "NULL"; 00102 } else { 00103 out += op1->valueToString(); 00104 } 00105 out += " ) "; 00106 } 00107 } 00108 if (op2 && op2->isValid()) { // 2 operands 00109 out += " "; 00110 out += shortName; 00111 out += " "; 00112 out += op2->toString(); 00113 if (values) { 00114 out += " ( "; 00115 if (op2->isNull()) { 00116 out += "NULL"; 00117 } else { 00118 out += op2->valueToString(); 00119 } 00120 out += " ) "; 00121 } 00122 } 00123 }
friend class fennel::Calculator [friend, inherited] |
Definition at line 64 of file Instruction.h.
RegisterRef<RESULT_T>* CastInstruction< RESULT_T, SOURCE_T >::mResult [protected, inherited] |
Definition at line 54 of file CastInstruction.h.
RegisterRef<SOURCE_T>* CastInstruction< RESULT_T, SOURCE_T >::mOp1 [protected, inherited] |
Definition at line 55 of file CastInstruction.h.
RegisterRef<SOURCE_T>* CastInstruction< RESULT_T, SOURCE_T >::mOp2 [protected, inherited] |
Definition at line 56 of file CastInstruction.h.