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>
54class QQmlJSTypeResolver;
63 QSharedPointer<
const QQmlJSScope> m_type;
65 bool m_isFlag =
false;
66 bool m_isScoped =
false;
73 bool isValid()
const {
return !m_name.isEmpty(); }
76 void setName(
const QString &name) { m_name = name; }
79 void setAlias(
const QString &alias) { m_alias = alias; }
81 bool isFlag()
const {
return m_isFlag; }
87 bool isQml()
const {
return m_isQml; }
90 void addKey(
const QString &key) { m_keys.append(key); }
93 void addValue(
int value) { m_values.append(value); }
96 bool hasValues()
const {
return !m_values.isEmpty(); }
97 int value(
const QString &key)
const {
return m_values.value(m_keys.indexOf(key)); }
98 bool hasKey(
const QString &key)
const {
return m_keys.indexOf(key) != -1; }
101 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
104 void setType(
const QSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
111 return a.m_keys == b.m_keys
112 && a.m_values == b.m_values
113 && a.m_name == b.m_name
114 && a.m_alias == b.m_alias
115 && a.m_isFlag == b.m_isFlag
116 && a.m_type == b.m_type
117 && a.m_isScoped == b.m_isScoped;
128 seed, e.m_keys, e.m_values, e.m_name, e.m_alias, e.m_isFlag, e.m_type, e.m_isScoped);
136
137
138
139
140
152 m_typeQualifier(typeQualifier)
157 void setName(
const QString &name) { m_name = name; }
159 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
171 return a.m_name == b.m_name && a.m_typeName == b.m_typeName
172 && a.m_type.owner_equal(b.m_type)
173 && a.m_typeQualifier == b.m_typeQualifier;
183 return qHashMulti(seed, e.m_name, e.m_typeName, e.m_type.owner_hash(),
192 bool m_isPointer =
false;
193 bool m_isList =
false;
206
207
208
209
210
214
215
216
217
218
376 QQmlJS::SourceLocation m_sourceLocation;
379 QList<QQmlJSMetaParameter> m_parameters;
380 QList<QQmlJSAnnotation> m_annotations;
389 bool m_isCloned =
false;
390 bool m_isConstructor =
false;
391 bool m_isJavaScriptFunction =
false;
392 bool m_isImplicitQmlPropertyChangeSignal =
false;
393 bool m_isConst =
false;
398 QString m_propertyName;
405 QString m_privateClass;
407 QString m_aliasTargetName;
408 QWeakPointer<
const QQmlJSScope> m_aliasTargetScope;
410 QQmlJS::SourceLocation m_sourceLocation;
411 QList<QQmlJSAnnotation> m_annotations;
412 bool m_isList =
false;
413 bool m_isWritable =
false;
414 bool m_isPointer =
false;
415 bool m_isTypeConstant =
false;
416 bool m_isFinal =
false;
417 bool m_isVirtual =
false;
418 bool m_isOverride =
false;
419 bool m_isPropertyConstant =
false;
429 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
432 void setRead(
const QString &read) { m_read = read; }
435 void setWrite(
const QString &write) { m_write = write; }
438 void setReset(
const QString &reset) { m_reset = reset; }
441 void setBindable(
const QString &bindable) { m_bindable = bindable; }
444 void setNotify(
const QString ¬ify) { m_notify = notify; }
449 bool isPrivate()
const {
return !m_privateClass.isEmpty(); }
451 void setType(
const QDeferredSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
455 { m_sourceLocation = newSourceLocation; }
458 void setAnnotations(
const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
475 bool isAlias()
const {
return !m_aliasExpr.isEmpty(); }
482 m_aliasTargetScope = scope;
486 return m_aliasTargetScope.toStrongRef();
505 int index()
const {
return m_index; }
507 bool isValid()
const {
return !m_propertyName.isEmpty(); }
511 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
512 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
513 && a.m_type == b.m_type && a.m_isList == b.m_isList
514 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
515 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
516 && a.m_isFinal == b.m_isFinal;
526 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
527 prop.m_type.owner_hash(), prop.m_isList, prop.m_isWritable,
528 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
535 using BindingType = QQmlSA::BindingType;
536 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
540 using Invalid = std::monostate;
543 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
544 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
546 struct NumberLiteral {
548 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
549 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
550 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
551 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
556 struct StringLiteral {
557 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
558 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
561 struct RegexpLiteral {
562 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
563 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
567 friend bool operator==(Null , Null ) {
return true; }
568 friend bool operator!=(Null a, Null b) {
return !(a == b); }
570 struct TranslationString {
571 friend bool operator==(TranslationString a, TranslationString b)
573 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
575 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
581 struct TranslationById {
582 friend bool operator==(TranslationById a, TranslationById b)
584 return a.id == b.id && a.number == b.number;
586 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
591 friend bool operator==(Script a, Script b)
593 return a.index == b.index && a.kind == b.kind;
595 friend bool operator!=(Script a, Script b) {
return !(a == b); }
596 QQmlJSMetaMethod::RelativeFunctionIndex index =
597 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
598 ScriptBindingKind kind = ScriptBindingKind::Invalid;
599 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
602 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
603 friend bool operator!=(Object a, Object b) {
return !(a == b); }
605 QWeakPointer<
const QQmlJSScope> value;
608 friend bool operator==(Interceptor a, Interceptor b)
610 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
612 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
614 QWeakPointer<
const QQmlJSScope> value;
617 friend bool operator==(ValueSource a, ValueSource b)
619 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
621 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
623 QWeakPointer<
const QQmlJSScope> value;
625 struct AttachedProperty {
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646 friend bool operator==(AttachedProperty a, AttachedProperty b)
648 return a.value.owner_equal(b.value);
650 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
651 QWeakPointer<
const QQmlJSScope> value;
653 struct GroupedProperty {
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669 QWeakPointer<
const QQmlJSScope> groupScope;
670 friend bool operator==(GroupedProperty a, GroupedProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
671 friend bool operator!=(GroupedProperty a, GroupedProperty b) {
return !(a == b); }
673 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
674 RegexpLiteral, Null, TranslationString,
675 TranslationById, Script, Object, Interceptor,
676 ValueSource, AttachedProperty, GroupedProperty
679 using BindingContent = Content::type;
681 QQmlJS::SourceLocation m_sourceLocation;
682 QString m_propertyName;
683 BindingContent m_bindingContent;
685 void ensureSetBindingTypeOnce()
687 Q_ASSERT(bindingType() == BindingType::Invalid);
690 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
694 static bool isLiteralBinding(BindingType type)
696 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
697 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
698 || type == BindingType::Null;
701 QQmlJSMetaPropertyBinding();
702 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
703 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
704 : m_sourceLocation(location), m_propertyName(propName)
707 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
708 const QQmlJSMetaProperty &prop)
709 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
713 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
714 QString propertyName()
const {
return m_propertyName; }
716 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
718 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
720 bool isValid()
const;
722 void setStringLiteral(QAnyStringView value)
724 ensureSetBindingTypeOnce();
725 m_bindingContent = Content::StringLiteral { value.toString() };
729 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
730 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
732 ensureSetBindingTypeOnce();
733 m_bindingContent = Content::Script { value, kind, valueType };
736 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
738 ensureSetBindingTypeOnce();
739 m_bindingContent = Content::GroupedProperty { groupScope };
742 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
744 ensureSetBindingTypeOnce();
745 m_bindingContent = Content::AttachedProperty { attachingScope };
748 void setBoolLiteral(
bool value)
750 ensureSetBindingTypeOnce();
751 m_bindingContent = Content::BoolLiteral { value };
754 void setNullLiteral()
756 ensureSetBindingTypeOnce();
757 m_bindingContent = Content::Null {};
760 void setNumberLiteral(
double value)
762 ensureSetBindingTypeOnce();
763 m_bindingContent = Content::NumberLiteral { value };
766 void setRegexpLiteral(QAnyStringView value)
768 ensureSetBindingTypeOnce();
769 m_bindingContent = Content::RegexpLiteral { value.toString() };
772 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
774 ensureSetBindingTypeOnce();
776 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
779 void setTranslationId(QStringView id,
int number)
781 ensureSetBindingTypeOnce();
782 m_bindingContent = Content::TranslationById{ id.toString(), number };
785 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
787 ensureSetBindingTypeOnce();
788 m_bindingContent = Content::Object { typeName, type };
791 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
793 ensureSetBindingTypeOnce();
794 m_bindingContent = Content::Interceptor { typeName, type };
797 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
799 ensureSetBindingTypeOnce();
800 m_bindingContent = Content::ValueSource { typeName, type };
804 bool boolValue()
const;
806 double numberValue()
const;
808 QString stringValue()
const;
810 QString regExpValue()
const;
812 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
814 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
816 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
818 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
819 return script->index;
821 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
824 ScriptBindingKind scriptKind()
const
826 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
829 return ScriptBindingKind::Invalid;
832 ScriptBindingValueType scriptValueType()
const
834 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
835 return script->valueType;
837 return ScriptBindingValueType::ScriptValue_Unknown;
840 QString objectTypeName()
const
842 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
843 return object->typeName;
847 QSharedPointer<
const QQmlJSScope> objectType()
const
849 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
850 return object->value.lock();
855 QString interceptorTypeName()
const
857 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
858 return interceptor->typeName;
862 QSharedPointer<
const QQmlJSScope> interceptorType()
const
864 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
865 return interceptor->value.lock();
870 QString valueSourceTypeName()
const
872 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
873 return valueSource->typeName;
877 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
879 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
880 return valueSource->value.lock();
885 QSharedPointer<
const QQmlJSScope> groupType()
const
887 if (
auto *group = std::get_if<Content::GroupedProperty>(&m_bindingContent))
888 return group->groupScope.lock();
893 QSharedPointer<
const QQmlJSScope> attachedType()
const
895 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
896 return attached->value.lock();
901 bool hasLiteral()
const
904 return isLiteralBinding();
906 bool hasObject()
const {
return bindingType() == BindingType::Object; }
907 bool hasInterceptor()
const
909 return bindingType() == BindingType::Interceptor;
911 bool hasValueSource()
const
913 return bindingType() == BindingType::ValueSource;
916 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
918 return a.m_propertyName == b.m_propertyName
919 && a.m_bindingContent == b.m_bindingContent
920 && a.m_sourceLocation == b.m_sourceLocation;
923 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
928 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
931 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
932 binding.bindingType());
938 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)