diff options
Diffstat (limited to 'src/qmlcompiler/qqmljsmetatypes_p.h')
-rw-r--r-- | src/qmlcompiler/qqmljsmetatypes_p.h | 191 |
1 files changed, 107 insertions, 84 deletions
diff --git a/src/qmlcompiler/qqmljsmetatypes_p.h b/src/qmlcompiler/qqmljsmetatypes_p.h index 47945558b7..0ea7020a2d 100644 --- a/src/qmlcompiler/qqmljsmetatypes_p.h +++ b/src/qmlcompiler/qqmljsmetatypes_p.h @@ -14,7 +14,7 @@ // // We mean it. -#include <private/qtqmlcompilerexports_p.h> +#include <qtqmlcompilerexports.h> #include <QtCore/qstring.h> #include <QtCore/qstringlist.h> @@ -23,9 +23,10 @@ #include <QtCore/qhash.h> #include <QtQml/private/qqmljssourcelocation_p.h> - #include <QtQml/private/qqmltranslation_p.h> +#include "qqmlsaconstants.h" +#include "qqmlsa.h" #include "qqmljsannotation_p.h" // MetaMethod and MetaProperty have both type names and actual QQmlJSScope types. @@ -40,6 +41,13 @@ QT_BEGIN_NAMESPACE +enum ScriptBindingValueType : unsigned int { + ScriptValue_Unknown, + ScriptValue_Undefined // property int p: undefined +}; + +using QQmlJSMetaMethodType = QQmlSA::MethodType; + class QQmlJSTypeResolver; class QQmlJSScope; class QQmlJSMetaEnum @@ -48,9 +56,11 @@ class QQmlJSMetaEnum QList<int> m_values; // empty if values unknown. QString m_name; QString m_alias; + QString m_typeName; QSharedPointer<const QQmlJSScope> m_type; bool m_isFlag = false; - bool m_scoped = true; + bool m_isScoped = false; + bool m_isQml = false; public: QQmlJSMetaEnum() = default; @@ -67,8 +77,11 @@ public: bool isFlag() const { return m_isFlag; } void setIsFlag(bool isFlag) { m_isFlag = isFlag; } - bool isScoped() const { return m_scoped; } - void setScoped(bool v) { m_scoped = v; } + bool isScoped() const { return m_isScoped; } + void setIsScoped(bool v) { m_isScoped = v; } + + bool isQml() const { return m_isQml; } + void setIsQml(bool v) { m_isQml = v; } void addKey(const QString &key) { m_keys.append(key); } QStringList keys() const { return m_keys; } @@ -80,6 +93,9 @@ public: int value(const QString &key) const { return m_values.value(m_keys.indexOf(key)); } bool hasKey(const QString &key) const { return m_keys.indexOf(key) != -1; } + QString typeName() const { return m_typeName; } + void setTypeName(const QString &typeName) { m_typeName = typeName; } + QSharedPointer<const QQmlJSScope> type() const { return m_type; } void setType(const QSharedPointer<const QQmlJSScope> &type) { m_type = type; } @@ -90,7 +106,8 @@ public: && a.m_name == b.m_name && a.m_alias == b.m_alias && a.m_isFlag == b.m_isFlag - && a.m_type == b.m_type; + && a.m_type == b.m_type + && a.m_isScoped == b.m_isScoped; } friend bool operator!=(const QQmlJSMetaEnum &a, const QQmlJSMetaEnum &b) @@ -100,7 +117,8 @@ public: friend size_t qHash(const QQmlJSMetaEnum &e, size_t seed = 0) { - return qHashMulti(seed, e.m_keys, e.m_values, e.m_name, e.m_alias, e.m_isFlag, e.m_type); + return qHashMulti( + seed, e.m_keys, e.m_values, e.m_name, e.m_alias, e.m_isFlag, e.m_type, e.m_isScoped); } }; @@ -118,10 +136,13 @@ public: Const, }; - QQmlJSMetaParameter(const QString &name, const QString &typeName, + QQmlJSMetaParameter(QString name = QString(), QString typeName = QString(), Constness typeQualifier = NonConst, QWeakPointer<const QQmlJSScope> type = {}) - : m_name(name), m_typeName(typeName), m_type(type), m_typeQualifier(typeQualifier) + : m_name(std::move(name)), + m_typeName(std::move(typeName)), + m_type(type), + m_typeQualifier(typeQualifier) { } @@ -135,11 +156,13 @@ public: void setTypeQualifier(Constness typeQualifier) { m_typeQualifier = typeQualifier; } bool isPointer() const { return m_isPointer; } void setIsPointer(bool isPointer) { m_isPointer = isPointer; } + bool isList() const { return m_isList; } + void setIsList(bool isList) { m_isList = isList; } friend bool operator==(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b) { return a.m_name == b.m_name && a.m_typeName == b.m_typeName - && a.m_type.toStrongRef().data() == b.m_type.toStrongRef().data() + && a.m_type.owner_equal(b.m_type) && a.m_typeQualifier == b.m_typeQualifier; } @@ -150,7 +173,7 @@ public: friend size_t qHash(const QQmlJSMetaParameter &e, size_t seed = 0) { - return qHashMulti(seed, e.m_name, e.m_typeName, e.m_type.toStrongRef().data(), + return qHashMulti(seed, e.m_name, e.m_typeName, e.m_type.owner_hash(), e.m_typeQualifier); } @@ -160,14 +183,16 @@ private: QWeakPointer<const QQmlJSScope> m_type; Constness m_typeQualifier = NonConst; bool m_isPointer = false; + bool m_isList = false; }; +using QQmlJSMetaReturnType = QQmlJSMetaParameter; + class QQmlJSMetaMethod { public: - enum Type { Signal, Slot, Method, StaticMethod }; - enum Access { Private, Protected, Public }; + using MethodType = QQmlJSMetaMethodType; public: /*! \internal @@ -188,23 +213,30 @@ public: QQmlJSMetaMethod() = default; explicit QQmlJSMetaMethod(QString name, QString returnType = QString()) - : m_name(std::move(name)) - , m_returnTypeName(std::move(returnType)) - , m_methodType(Method) + : m_name(std::move(name)), + m_returnType(QString(), std::move(returnType)), + m_methodType(MethodType::Method) {} QString methodName() const { return m_name; } void setMethodName(const QString &name) { m_name = name; } - QString returnTypeName() const { return m_returnTypeName; } - QSharedPointer<const QQmlJSScope> returnType() const { return m_returnType.toStrongRef(); } - void setReturnTypeName(const QString &type) { m_returnTypeName = type; } - void setReturnType(const QSharedPointer<const QQmlJSScope> &type) - { - m_returnType = type; - } + QQmlJS::SourceLocation sourceLocation() const { return m_sourceLocation; } + void setSourceLocation(QQmlJS::SourceLocation location) { m_sourceLocation = location; } + + QQmlJSMetaReturnType returnValue() const { return m_returnType; } + void setReturnValue(const QQmlJSMetaReturnType returnValue) { m_returnType = returnValue; } + QString returnTypeName() const { return m_returnType.typeName(); } + void setReturnTypeName(const QString &typeName) { m_returnType.setTypeName(typeName); } + QSharedPointer<const QQmlJSScope> returnType() const { return m_returnType.type(); } + void setReturnType(QWeakPointer<const QQmlJSScope> type) { m_returnType.setType(type); } QList<QQmlJSMetaParameter> parameters() const { return m_parameters; } + QPair<QList<QQmlJSMetaParameter>::iterator, QList<QQmlJSMetaParameter>::iterator> + mutableParametersRange() + { + return { m_parameters.begin(), m_parameters.end() }; + } QStringList parameterNames() const { @@ -219,8 +251,8 @@ public: void addParameter(const QQmlJSMetaParameter &p) { m_parameters.append(p); } - int methodType() const { return m_methodType; } - void setMethodType(Type methodType) { m_methodType = methodType; } + QQmlJSMetaMethodType methodType() const { return m_methodType; } + void setMethodType(MethodType methodType) { m_methodType = methodType; } Access access() const { return m_methodAccess; } @@ -250,16 +282,36 @@ public: const QVector<QQmlJSAnnotation>& annotations() const { return m_annotations; } void setAnnotations(QVector<QQmlJSAnnotation> annotations) { m_annotations = annotations; } - void setJsFunctionIndex(RelativeFunctionIndex index) { m_jsFunctionIndex = index; } - RelativeFunctionIndex jsFunctionIndex() const { return m_jsFunctionIndex; } + void setJsFunctionIndex(RelativeFunctionIndex index) + { + Q_ASSERT(!m_isConstructor); + m_relativeFunctionIndex = index; + } + + RelativeFunctionIndex jsFunctionIndex() const + { + Q_ASSERT(!m_isConstructor); + return m_relativeFunctionIndex; + } + + void setConstructorIndex(RelativeFunctionIndex index) + { + Q_ASSERT(m_isConstructor); + m_relativeFunctionIndex = index; + } + + RelativeFunctionIndex constructorIndex() const + { + Q_ASSERT(m_isConstructor); + return m_relativeFunctionIndex; + } friend bool operator==(const QQmlJSMetaMethod &a, const QQmlJSMetaMethod &b) { - return a.m_name == b.m_name && a.m_returnTypeName == b.m_returnTypeName - && a.m_returnType == b.m_returnType && a.m_parameters == b.m_parameters - && a.m_annotations == b.m_annotations && a.m_methodType == b.m_methodType - && a.m_methodAccess == b.m_methodAccess && a.m_revision == b.m_revision - && a.m_isConstructor == b.m_isConstructor; + return a.m_name == b.m_name && a.m_returnType == b.m_returnType + && a.m_parameters == b.m_parameters && a.m_annotations == b.m_annotations + && a.m_methodType == b.m_methodType && a.m_methodAccess == b.m_methodAccess + && a.m_revision == b.m_revision && a.m_isConstructor == b.m_isConstructor; } friend bool operator!=(const QQmlJSMetaMethod &a, const QQmlJSMetaMethod &b) @@ -272,8 +324,7 @@ public: QtPrivate::QHashCombine combine; seed = combine(seed, method.m_name); - seed = combine(seed, method.m_returnTypeName); - seed = combine(seed, method.m_returnType.toStrongRef().data()); + seed = combine(seed, method.m_returnType); seed = combine(seed, method.m_annotations); seed = combine(seed, method.m_methodType); seed = combine(seed, method.m_methodAccess); @@ -289,16 +340,17 @@ public: private: QString m_name; - QString m_returnTypeName; - QWeakPointer<const QQmlJSScope> m_returnType; + QQmlJS::SourceLocation m_sourceLocation; + + QQmlJSMetaReturnType m_returnType; QList<QQmlJSMetaParameter> m_parameters; QList<QQmlJSAnnotation> m_annotations; - Type m_methodType = Signal; + MethodType m_methodType = MethodType::Signal; Access m_methodAccess = Public; int m_revision = 0; - RelativeFunctionIndex m_jsFunctionIndex = RelativeFunctionIndex::Invalid; + RelativeFunctionIndex m_relativeFunctionIndex = RelativeFunctionIndex::Invalid; bool m_isCloned = false; bool m_isConstructor = false; bool m_isJavaScriptFunction = false; @@ -391,7 +443,7 @@ public: { return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable - && a.m_type == b.m_type && a.m_isList == b.m_isList + && a.m_type.owner_equal(b.m_type) && a.m_isList == b.m_isList && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision && a.m_isFinal == b.m_isFinal; @@ -420,39 +472,10 @@ public: create a new binding, you know all the details of it already, so you should just set all the data at once. */ -class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSMetaPropertyBinding +class Q_QMLCOMPILER_EXPORT QQmlJSMetaPropertyBinding { -public: - enum BindingType : unsigned int { - Invalid, - BoolLiteral, - NumberLiteral, - StringLiteral, - RegExpLiteral, - Null, - Translation, - TranslationById, - Script, - Object, - Interceptor, - ValueSource, - AttachedProperty, - GroupProperty, - }; - - enum ScriptBindingKind : unsigned int { - Script_Invalid, - Script_PropertyBinding, // property int p: 1 + 1 - Script_SignalHandler, // onSignal: { ... } - Script_ChangeHandler, // onXChanged: { ... } - }; - - enum ScriptBindingValueType : unsigned int { - ScriptValue_Unknown, - ScriptValue_Undefined // property int p: undefined - }; - -private: + using BindingType = QQmlSA::BindingType; + using ScriptBindingKind = QQmlSA::ScriptBindingKind; // needs to be kept in sync with the BindingType enum struct Content { @@ -514,11 +537,11 @@ private: friend bool operator!=(Script a, Script b) { return !(a == b); } QQmlJSMetaMethod::RelativeFunctionIndex index = QQmlJSMetaMethod::RelativeFunctionIndex::Invalid; - ScriptBindingKind kind = Script_Invalid; - ScriptBindingValueType valueType = ScriptValue_Unknown; + ScriptBindingKind kind = ScriptBindingKind::Invalid; + ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown; }; struct Object { - friend bool operator==(Object a, Object b) { return a.value == b.value && a.typeName == b.typeName; } + friend bool operator==(Object a, Object b) { return a.value.owner_equal(b.value) && a.typeName == b.typeName; } friend bool operator!=(Object a, Object b) { return !(a == b); } QString typeName; QWeakPointer<const QQmlJSScope> value; @@ -526,7 +549,7 @@ private: struct Interceptor { friend bool operator==(Interceptor a, Interceptor b) { - return a.value == b.value && a.typeName == b.typeName; + return a.value.owner_equal(b.value) && a.typeName == b.typeName; } friend bool operator!=(Interceptor a, Interceptor b) { return !(a == b); } QString typeName; @@ -535,7 +558,7 @@ private: struct ValueSource { friend bool operator==(ValueSource a, ValueSource b) { - return a.value == b.value && a.typeName == b.typeName; + return a.value.owner_equal(b.value) && a.typeName == b.typeName; } friend bool operator!=(ValueSource a, ValueSource b) { return !(a == b); } QString typeName; @@ -564,7 +587,7 @@ private: */ friend bool operator==(AttachedProperty a, AttachedProperty b) { - return a.value == b.value; + return a.value.owner_equal(b.value); } friend bool operator!=(AttachedProperty a, AttachedProperty b) { return !(a == b); } QWeakPointer<const QQmlJSScope> value; @@ -586,7 +609,7 @@ private: ### TODO: Obtaining the effective binding result requires some resolving function */ QWeakPointer<const QQmlJSScope> groupScope; - friend bool operator==(GroupProperty a, GroupProperty b) { return a.groupScope == b.groupScope; } + friend bool operator==(GroupProperty a, GroupProperty b) { return a.groupScope.owner_equal(b.groupScope); } friend bool operator!=(GroupProperty a, GroupProperty b) { return !(a == b); } }; using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral, @@ -617,6 +640,7 @@ public: || type == BindingType::Null; // special. we record it as literal } + QQmlJSMetaPropertyBinding(); QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { } explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location, const QString &propName) : m_sourceLocation(location), m_propertyName(propName) @@ -643,8 +667,9 @@ public: m_bindingContent = Content::StringLiteral { value.toString() }; } - void setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind, - ScriptBindingValueType valueType = ScriptValue_Unknown) + void + setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind, + ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown) { ensureSetBindingTypeOnce(); m_bindingContent = Content::Script { value, kind, valueType }; @@ -717,8 +742,6 @@ public: m_bindingContent = Content::ValueSource { typeName, type }; } - QString literalTypeName() const; - // ### TODO: here and below: Introduce an allowConversion parameter, if yes, enable conversions e.g. bool -> number? bool boolValue() const; @@ -745,7 +768,7 @@ public: if (auto *script = std::get_if<Content::Script>(&m_bindingContent)) return script->kind; // warn - return ScriptBindingKind::Script_Invalid; + return ScriptBindingKind::Invalid; } ScriptBindingValueType scriptValueType() const @@ -852,7 +875,7 @@ public: } }; -struct Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSMetaSignalHandler +struct Q_QMLCOMPILER_EXPORT QQmlJSMetaSignalHandler { QStringList signalParameters; bool isMultiline; |