5#ifndef QQMLJSMETATYPES_P_H
6#define QQMLJSMETATYPES_P_H
18#include <qtqmlcompilerexports.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qstringlist.h>
22#include <QtCore/qsharedpointer.h>
23#include <QtCore/qvariant.h>
24#include <QtCore/qhash.h>
26#include <QtQml/private/qqmljssourcelocation_p.h>
27#include <QtQml/private/qqmltranslation_p.h>
53class QQmlJSTypeResolver;
62 QSharedPointer<
const QQmlJSScope> m_type;
64 bool m_isFlag =
false;
65 bool m_isScoped =
false;
72 bool isValid()
const {
return !m_name.isEmpty(); }
75 void setName(
const QString &name) { m_name = name; }
78 void setAlias(
const QString &alias) { m_alias = alias; }
80 bool isFlag()
const {
return m_isFlag; }
86 bool isQml()
const {
return m_isQml; }
89 void addKey(
const QString &key) { m_keys.append(key); }
92 void addValue(
int value) { m_values.append(value); }
95 bool hasValues()
const {
return !m_values.isEmpty(); }
96 int value(
const QString &key)
const {
return m_values.value(m_keys.indexOf(key)); }
97 bool hasKey(
const QString &key)
const {
return m_keys.indexOf(key) != -1; }
100 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
103 void setType(
const QSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
110 return a.m_keys == b.m_keys
111 && a.m_values == b.m_values
112 && a.m_name == b.m_name
113 && a.m_alias == b.m_alias
114 && a.m_isFlag == b.m_isFlag
115 && a.m_type == b.m_type
116 && a.m_isScoped == b.m_isScoped;
127 seed, e.m_keys, e.m_values, e.m_name, e.m_alias, e.m_isFlag, e.m_type, e.m_isScoped);
135
136
137
138
139
147 QWeakPointer<
const QQmlJSScope> type = {})
151 m_typeQualifier(typeQualifier)
156 void setName(
const QString &name) { m_name = name; }
158 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
160 void setType(QWeakPointer<
const QQmlJSScope> type) { m_type = type; }
170 return a.m_name == b.m_name && a.m_typeName == b.m_typeName
171 && a.m_type.owner_equal(b.m_type)
172 && a.m_typeQualifier == b.m_typeQualifier;
182 return qHashMulti(seed, e.m_name, e.m_typeName, e.m_type.owner_hash(),
189 QWeakPointer<
const QQmlJSScope> m_type;
191 bool m_isPointer =
false;
192 bool m_isList =
false;
205
206
207
208
209
213
214
215
216
217
238 void setReturnType(QWeakPointer<
const QQmlJSScope> type) { m_returnType.setType(type); }
373 QQmlJS::SourceLocation m_sourceLocation;
376 QList<QQmlJSMetaParameter> m_parameters;
377 QList<QQmlJSAnnotation> m_annotations;
383 bool m_isCloned =
false;
384 bool m_isConstructor =
false;
385 bool m_isJavaScriptFunction =
false;
386 bool m_isImplicitQmlPropertyChangeSignal =
false;
387 bool m_isConst =
false;
392 QString m_propertyName;
399 QString m_privateClass;
401 QString m_aliasTargetName;
402 QWeakPointer<
const QQmlJSScope> m_aliasTargetScope;
403 QWeakPointer<
const QQmlJSScope> m_type;
404 QQmlJS::SourceLocation m_sourceLocation;
405 QVector<QQmlJSAnnotation> m_annotations;
406 bool m_isList =
false;
407 bool m_isWritable =
false;
408 bool m_isPointer =
false;
409 bool m_isTypeConstant =
false;
410 bool m_isFinal =
false;
411 bool m_isPropertyConstant =
false;
421 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
424 void setRead(
const QString &read) { m_read = read; }
427 void setWrite(
const QString &write) { m_write = write; }
430 void setReset(
const QString &reset) { m_reset = reset; }
433 void setBindable(
const QString &bindable) { m_bindable = bindable; }
436 void setNotify(
const QString ¬ify) { m_notify = notify; }
441 bool isPrivate()
const {
return !m_privateClass.isEmpty(); }
443 void setType(
const QSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
447 { m_sourceLocation = newSourceLocation; }
450 void setAnnotations(
const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
467 bool isAlias()
const {
return !m_aliasExpr.isEmpty(); }
474 m_aliasTargetScope = scope;
478 return m_aliasTargetScope.toStrongRef();
491 int index()
const {
return m_index; }
493 bool isValid()
const {
return !m_propertyName.isEmpty(); }
497 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
498 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
499 && a.m_type.owner_equal(b.m_type) && a.m_isList == b.m_isList
500 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
501 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
502 && a.m_isFinal == b.m_isFinal;
512 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
513 prop.m_type.toStrongRef().data(), prop.m_isList, prop.m_isWritable,
514 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
521 using BindingType = QQmlSA::BindingType;
522 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
526 using Invalid = std::monostate;
529 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
530 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
532 struct NumberLiteral {
534 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
535 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
536 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
537 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
542 struct StringLiteral {
543 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
544 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
547 struct RegexpLiteral {
548 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
549 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
553 friend bool operator==(Null , Null ) {
return true; }
554 friend bool operator!=(Null a, Null b) {
return !(a == b); }
556 struct TranslationString {
557 friend bool operator==(TranslationString a, TranslationString b)
559 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
561 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
567 struct TranslationById {
568 friend bool operator==(TranslationById a, TranslationById b)
570 return a.id == b.id && a.number == b.number;
572 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
577 friend bool operator==(Script a, Script b)
579 return a.index == b.index && a.kind == b.kind;
581 friend bool operator!=(Script a, Script b) {
return !(a == b); }
582 QQmlJSMetaMethod::RelativeFunctionIndex index =
583 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
584 ScriptBindingKind kind = ScriptBindingKind::Invalid;
585 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
588 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
589 friend bool operator!=(Object a, Object b) {
return !(a == b); }
591 QWeakPointer<
const QQmlJSScope> value;
594 friend bool operator==(Interceptor a, Interceptor b)
596 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
598 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
600 QWeakPointer<
const QQmlJSScope> value;
603 friend bool operator==(ValueSource a, ValueSource b)
605 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
607 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
609 QWeakPointer<
const QQmlJSScope> value;
611 struct AttachedProperty {
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632 friend bool operator==(AttachedProperty a, AttachedProperty b)
634 return a.value.owner_equal(b.value);
636 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
637 QWeakPointer<
const QQmlJSScope> value;
639 struct GroupProperty {
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655 QWeakPointer<
const QQmlJSScope> groupScope;
656 friend bool operator==(GroupProperty a, GroupProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
657 friend bool operator!=(GroupProperty a, GroupProperty b) {
return !(a == b); }
659 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
660 RegexpLiteral, Null, TranslationString,
661 TranslationById, Script, Object, Interceptor,
662 ValueSource, AttachedProperty, GroupProperty
665 using BindingContent = Content::type;
667 QQmlJS::SourceLocation m_sourceLocation;
668 QString m_propertyName;
669 BindingContent m_bindingContent;
671 void ensureSetBindingTypeOnce()
673 Q_ASSERT(bindingType() == BindingType::Invalid);
676 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
680 static bool isLiteralBinding(BindingType type)
682 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
683 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
684 || type == BindingType::Null;
687 QQmlJSMetaPropertyBinding();
688 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
689 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
690 : m_sourceLocation(location), m_propertyName(propName)
693 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
694 const QQmlJSMetaProperty &prop)
695 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
699 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
700 QString propertyName()
const {
return m_propertyName; }
702 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
704 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
706 bool isValid()
const;
708 void setStringLiteral(QAnyStringView value)
710 ensureSetBindingTypeOnce();
711 m_bindingContent = Content::StringLiteral { value.toString() };
715 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
716 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
718 ensureSetBindingTypeOnce();
719 m_bindingContent = Content::Script { value, kind, valueType };
722 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
724 ensureSetBindingTypeOnce();
725 m_bindingContent = Content::GroupProperty { groupScope };
728 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
730 ensureSetBindingTypeOnce();
731 m_bindingContent = Content::AttachedProperty { attachingScope };
734 void setBoolLiteral(
bool value)
736 ensureSetBindingTypeOnce();
737 m_bindingContent = Content::BoolLiteral { value };
740 void setNullLiteral()
742 ensureSetBindingTypeOnce();
743 m_bindingContent = Content::Null {};
746 void setNumberLiteral(
double value)
748 ensureSetBindingTypeOnce();
749 m_bindingContent = Content::NumberLiteral { value };
752 void setRegexpLiteral(QAnyStringView value)
754 ensureSetBindingTypeOnce();
755 m_bindingContent = Content::RegexpLiteral { value.toString() };
758 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
760 ensureSetBindingTypeOnce();
762 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
765 void setTranslationId(QStringView id,
int number)
767 ensureSetBindingTypeOnce();
768 m_bindingContent = Content::TranslationById{ id.toString(), number };
771 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
773 ensureSetBindingTypeOnce();
774 m_bindingContent = Content::Object { typeName, type };
777 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
779 ensureSetBindingTypeOnce();
780 m_bindingContent = Content::Interceptor { typeName, type };
783 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
785 ensureSetBindingTypeOnce();
786 m_bindingContent = Content::ValueSource { typeName, type };
790 bool boolValue()
const;
792 double numberValue()
const;
794 QString stringValue()
const;
796 QString regExpValue()
const;
798 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
800 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
802 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
804 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
805 return script->index;
807 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
810 ScriptBindingKind scriptKind()
const
812 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
815 return ScriptBindingKind::Invalid;
818 ScriptBindingValueType scriptValueType()
const
820 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
821 return script->valueType;
823 return ScriptBindingValueType::ScriptValue_Unknown;
826 QString objectTypeName()
const
828 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
829 return object->typeName;
833 QSharedPointer<
const QQmlJSScope> objectType()
const
835 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
836 return object->value.lock();
841 QString interceptorTypeName()
const
843 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
844 return interceptor->typeName;
848 QSharedPointer<
const QQmlJSScope> interceptorType()
const
850 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
851 return interceptor->value.lock();
856 QString valueSourceTypeName()
const
858 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
859 return valueSource->typeName;
863 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
865 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
866 return valueSource->value.lock();
871 QSharedPointer<
const QQmlJSScope> groupType()
const
873 if (
auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
874 return group->groupScope.lock();
879 QSharedPointer<
const QQmlJSScope> attachedType()
const
881 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
882 return attached->value.lock();
887 bool hasLiteral()
const
890 return isLiteralBinding();
892 bool hasObject()
const {
return bindingType() == BindingType::Object; }
893 bool hasInterceptor()
const
895 return bindingType() == BindingType::Interceptor;
897 bool hasValueSource()
const
899 return bindingType() == BindingType::ValueSource;
902 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
904 return a.m_propertyName == b.m_propertyName
905 && a.m_bindingContent == b.m_bindingContent
906 && a.m_sourceLocation == b.m_sourceLocation;
909 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
914 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
917 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
918 binding.bindingType());
924 QStringList signalParameters;
Combined button and popup list for selecting options.
static QString toNumericString(double value)
static QString messageTypeForMethod(const QString &method)
static QString derefContentPointer(const QString &contentPointer)
static bool canTypeBeAffectedBySideEffects(const QQmlJSTypeResolver *typeResolver, const QQmlJSRegisterContent &baseType)
#define BYTECODE_UNIMPLEMENTED()
#define INJECT_TRACE_INFO(function)
static QString registerName(int registerIndex, int offset)
static QString minExpression(int argc)
static QString maxExpression(int argc)
static bool isTypeStorable(const QQmlJSTypeResolver *resolver, const QQmlJSScope::ConstPtr &type)