From ca1a7bf19ae8ea9382a1cbce44e4e2e71e023752 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 13 Apr 2014 18:44:34 +0000 Subject: [PATCH] Core: Minor changes with ValueTypeError, Skylark: Fixed issue with witz error line number git-svn-id: svn://ultimatepp.org/upp/trunk@7243 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Defs.h | 6 ++++++ uppsrc/Core/Value.cpp | 10 ++-------- uppsrc/Core/Value.h | 10 ++-------- uppsrc/Core/Value.hpp | 13 ++++++------- uppsrc/Skylark/Compile.cpp | 2 +- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index 37f9d8581..bf971b4a9 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -790,3 +790,9 @@ inline void __LOGF__(const char *format, ...); template void IGNORE_RESULT(const T&) {} + +class Exc : public String { +public: + Exc() {} + Exc(const String& desc) : String(desc) {} +}; diff --git a/uppsrc/Core/Value.cpp b/uppsrc/Core/Value.cpp index 2604e2adf..26f4bf6e4 100644 --- a/uppsrc/Core/Value.cpp +++ b/uppsrc/Core/Value.cpp @@ -8,14 +8,8 @@ const Nuller Null; #define LTIMING(x) // RTIMING(x) -void ThrowValueTypeError(const String& text, const Value& src, int target) -{ - ValueTypeError err; - (String&)err = text; - err.src = text; - err.target = target; - throw err; -} +ValueTypeError::ValueTypeError(const String& text, const Value& src, int target) +: Exc(text), src(src), target(target) {} unsigned Value::GetOtherHashValue() const { if(IsNull()) diff --git a/uppsrc/Core/Value.h b/uppsrc/Core/Value.h index 23dac11c4..ee007df94 100644 --- a/uppsrc/Core/Value.h +++ b/uppsrc/Core/Value.h @@ -74,14 +74,6 @@ class AssignValueTypeNo : public ValueType {}; template dword GetValueTypeNo() { return ValueTypeNo((T*)NULL); } -class Exc : public String { -public: - Exc() {} - Exc(const String& desc) : String(desc) {} -}; - -void ThrowValueTypeError(const String& text, const Value& src, int target); - class Value : Moveable_ { public: class Void { @@ -271,6 +263,8 @@ public: struct ValueTypeError : Exc { Value src; int target; + + ValueTypeError(const String& text, const Value& src, int target); }; template bool FitsSvoValue() { return sizeof(T) <= 8; } diff --git a/uppsrc/Core/Value.hpp b/uppsrc/Core/Value.hpp index cbf4a4e18..1e2f99679 100644 --- a/uppsrc/Core/Value.hpp +++ b/uppsrc/Core/Value.hpp @@ -204,9 +204,9 @@ T& Value::GetSmall() const ASSERT(t < 255); if(Is((byte)t)) return GetSmallRaw(); - ThrowValueTypeError(String().Cat() << "Invalid value conversion: " - << GetName() << " -> " << typeid(T).name(), - *this, t); + throw ValueTypeError(String().Cat() << "Invalid value conversion: " + << GetName() << " -> " << typeid(T).name(), + *this, t); return *(T*)&data; // Silence compiler warning } @@ -249,10 +249,9 @@ inline const T& Value::To() const if(Is((byte)t)) return GetSmallRaw(); } - ThrowValueTypeError(String().Cat() << "Invalid value conversion: " - << GetName() << " -> " << typeid(T).name(), - *this, t); - return *(T*)&data; // Silence compiler warning + throw ValueTypeError(String().Cat() << "Invalid value conversion: " + << GetName() << " -> " << typeid(T).name(), + *this, t); } template diff --git a/uppsrc/Skylark/Compile.cpp b/uppsrc/Skylark/Compile.cpp index 3ca755464..4867408b7 100644 --- a/uppsrc/Skylark/Compile.cpp +++ b/uppsrc/Skylark/Compile.cpp @@ -356,7 +356,7 @@ One Compiler::Block() ExeBlock& blk = result.Create(); const char *s = p.GetSpacePtr(); const char *b = s; - int line = 1; + int line = p.GetLine(); while(*s) { if(*s == '$') { if(s[1] == '$') {