diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-01-26 17:46:51 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 10:43:54 +0100 |
commit | 694c083c0f83f02558f148c3b648d35efd9ed3c0 (patch) | |
tree | 90ce8de0017ba70949d702f83199b1aff832e7b1 | |
parent | d30c86f3fb3ed1dee9d7f30783ab228d948d38ee (diff) |
Move Referenced together with Managed
The two classes belong logically together (as the Managed base
type and a generic pointer to a Managed object).
Change-Id: I65691669a7169a4514cadf7ab3e744c090851c6b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r-- | src/qml/jsruntime/qv4managed_p.h | 85 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 86 |
2 files changed, 90 insertions, 81 deletions
diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index a26a211ae8..aa9fb0d0fb 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -353,6 +353,91 @@ private: friend struct ObjectIterator; }; +template<typename T> +struct Referenced { + // Important: Do NOT add a copy constructor to this class + // adding a copy constructor actually changes the calling convention, ie. + // is not even binary compatible. Adding it would break assumptions made + // in the jit'ed code. + Referenced(const Scoped<T> &v); + Referenced(TypedValue<T> &v) { ptr = &v; } + Referenced(Value &v) { + ptr = value_cast<T>(v) ? &v : 0; + } + static Referenced fromValuePointer(Value *s) { + return Referenced(s); + } + + Referenced &operator=(const Referenced &o) + { *ptr = *o.ptr; return *this; } + Referenced &operator=(T *t) + { +#if QT_POINTER_SIZE == 4 + ptr->tag = Value::Managed_Type; +#endif + ptr->m = t; + return *this; + } + Referenced &operator=(Returned<T> *t) { +#if QT_POINTER_SIZE == 4 + ptr->tag = Value::Managed_Type; +#endif + ptr->m = t->getPointer(); + return *this; + } + + operator const T *() const { + return ptr ? static_cast<T*>(ptr->managed()) : 0; + } + const T *operator->() const { + return static_cast<T*>(ptr->managed()); + } + + operator T *() { + return ptr ? static_cast<T*>(ptr->managed()) : 0; + } + T *operator->() { + return static_cast<T*>(ptr->managed()); + } + + T *getPointer() const { + return static_cast<T *>(ptr->managed()); + } + ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); } + operator Returned<T> *() const { return ptr ? Returned<T>::create(getPointer()) : 0; } + + bool operator==(const Referenced<T> &other) { + if (ptr == other.ptr) + return true; + return ptr && other.ptr && ptr->m == other.ptr->m; + } + bool operator!=(const Referenced<T> &other) { + if (ptr == other.ptr) + return false; + return !ptr || ptr->m != other.ptr->m; + } + bool operator!() const { return !ptr || !ptr->managed(); } + + static Referenced null() { return Referenced(Null); } + bool isNull() const { return !ptr; } +private: + Referenced(Value *v) { + ptr = v; +#if QT_POINTER_SIZE == 8 + ptr->val = 0; +#else + *ptr = Value::fromManaged(0); +#endif + } + enum _Null { Null }; + Referenced(_Null) { ptr = 0; } + Value *ptr; +}; + + +typedef Referenced<Managed> ManagedRef; + + template<> inline Managed *value_cast(const Value &v) { return v.asManaged(); diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index deb52c3605..ce21404a53 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -378,87 +378,6 @@ struct ScopedCallData { CallData *ptr; }; -template<typename T> -struct Referenced { - // Important: Do NOT add a copy constructor to this class - // adding a copy constructor actually changes the calling convention, ie. - // is not even binary compatible. Adding it would break assumptions made - // in the jit'ed code. - Referenced(const Scoped<T> &v) - : ptr(v.ptr) {} - Referenced(TypedValue<T> &v) { ptr = &v; } - Referenced(Value &v) { - ptr = value_cast<T>(v) ? &v : 0; - } - static Referenced fromValuePointer(Value *s) { - return Referenced(s); - } - - Referenced &operator=(const Referenced &o) - { *ptr = *o.ptr; return *this; } - Referenced &operator=(T *t) - { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif - ptr->m = t; - return *this; - } - Referenced &operator=(Returned<T> *t) { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif - ptr->m = t->getPointer(); - return *this; - } - - operator const T *() const { - return ptr ? static_cast<T*>(ptr->managed()) : 0; - } - const T *operator->() const { - return static_cast<T*>(ptr->managed()); - } - - operator T *() { - return ptr ? static_cast<T*>(ptr->managed()) : 0; - } - T *operator->() { - return static_cast<T*>(ptr->managed()); - } - - T *getPointer() const { - return static_cast<T *>(ptr->managed()); - } - ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); } - operator Returned<T> *() const { return ptr ? Returned<T>::create(getPointer()) : 0; } - - bool operator==(const Referenced<T> &other) { - if (ptr == other.ptr) - return true; - return ptr && other.ptr && ptr->m == other.ptr->m; - } - bool operator!=(const Referenced<T> &other) { - if (ptr == other.ptr) - return false; - return !ptr || ptr->m != other.ptr->m; - } - bool operator!() const { return !ptr || !ptr->managed(); } - - static Referenced null() { return Referenced(Null); } - bool isNull() const { return !ptr; } -private: - Referenced(Value *v) { - ptr = v; -#if QT_POINTER_SIZE == 8 - ptr->val = 0; -#else - *ptr = Value::fromManaged(0); -#endif - } - enum _Null { Null }; - Referenced(_Null) { ptr = 0; } - Value *ptr; -}; typedef Referenced<String> StringRef; typedef Referenced<Object> ObjectRef; @@ -658,6 +577,11 @@ inline ValueRef &ValueRef::operator=(const ScopedValue &o) return *this; } +template<typename T> +Referenced<T>::Referenced(const Scoped<T> &v) + : ptr(v.ptr) +{} + struct ScopedProperty { ScopedProperty(Scope &scope) |