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
148 QWeakPointer<
const QQmlJSScope> type = {})
152 m_typeQualifier(typeQualifier)
157 void setName(
const QString &name) { m_name = name; }
159 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
161 void setType(QWeakPointer<
const QQmlJSScope> type) { m_type = type; }
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(),
190 QWeakPointer<
const QQmlJSScope> m_type;
192 bool m_isPointer =
false;
193 bool m_isList =
false;
206
207
208
209
210
214
215
216
217
218
239 void setReturnType(QWeakPointer<
const QQmlJSScope> type) { m_returnType.setType(type); }
388 QQmlJS::SourceLocation m_sourceLocation;
391 QList<QQmlJSMetaParameter> m_parameters;
392 QList<QQmlJSAnnotation> m_annotations;
399 bool m_isCloned =
false;
400 bool m_isConstructor =
false;
401 bool m_isJavaScriptFunction =
false;
402 bool m_isImplicitQmlPropertyChangeSignal =
false;
403 bool m_isConst =
false;
408 QString m_propertyName;
415 QString m_privateClass;
417 QString m_aliasTargetName;
418 QWeakPointer<
const QQmlJSScope> m_aliasTargetScope;
420 QQmlJS::SourceLocation m_sourceLocation;
421 QList<QQmlJSAnnotation> m_annotations;
422 bool m_isList =
false;
423 bool m_isWritable =
false;
424 bool m_isPointer =
false;
425 bool m_isTypeConstant =
false;
426 bool m_isFinal =
false;
427 bool m_isVirtual =
false;
428 bool m_isOverride =
false;
429 bool m_isPropertyConstant =
false;
439 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
442 void setRead(
const QString &read) { m_read = read; }
445 void setWrite(
const QString &write) { m_write = write; }
448 void setReset(
const QString &reset) { m_reset = reset; }
451 void setBindable(
const QString &bindable) { m_bindable = bindable; }
454 void setNotify(
const QString ¬ify) { m_notify = notify; }
459 bool isPrivate()
const {
return !m_privateClass.isEmpty(); }
461 void setType(
const QDeferredSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
465 { m_sourceLocation = newSourceLocation; }
468 void setAnnotations(
const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
485 bool isAlias()
const {
return !m_aliasExpr.isEmpty(); }
492 m_aliasTargetScope = scope;
496 return m_aliasTargetScope.toStrongRef();
515 int index()
const {
return m_index; }
517 bool isValid()
const {
return !m_propertyName.isEmpty(); }
521 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
522 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
523 && a.m_type == b.m_type && a.m_isList == b.m_isList
524 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
525 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
526 && a.m_isFinal == b.m_isFinal;
536 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
537 prop.m_type.owner_hash(), prop.m_isList, prop.m_isWritable,
538 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
545 using BindingType = QQmlSA::BindingType;
546 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
550 using Invalid = std::monostate;
553 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
554 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
556 struct NumberLiteral {
558 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
559 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
560 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
561 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
566 struct StringLiteral {
567 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
568 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
571 struct RegexpLiteral {
572 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
573 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
577 friend bool operator==(Null , Null ) {
return true; }
578 friend bool operator!=(Null a, Null b) {
return !(a == b); }
580 struct TranslationString {
581 friend bool operator==(TranslationString a, TranslationString b)
583 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
585 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
591 struct TranslationById {
592 friend bool operator==(TranslationById a, TranslationById b)
594 return a.id == b.id && a.number == b.number;
596 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
601 friend bool operator==(Script a, Script b)
603 return a.index == b.index && a.kind == b.kind;
605 friend bool operator!=(Script a, Script b) {
return !(a == b); }
606 QQmlJSMetaMethod::RelativeFunctionIndex index =
607 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
608 ScriptBindingKind kind = ScriptBindingKind::Invalid;
609 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
612 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
613 friend bool operator!=(Object a, Object b) {
return !(a == b); }
615 QWeakPointer<
const QQmlJSScope> value;
618 friend bool operator==(Interceptor a, Interceptor b)
620 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
622 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
624 QWeakPointer<
const QQmlJSScope> value;
627 friend bool operator==(ValueSource a, ValueSource b)
629 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
631 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
633 QWeakPointer<
const QQmlJSScope> value;
635 struct AttachedProperty {
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656 friend bool operator==(AttachedProperty a, AttachedProperty b)
658 return a.value.owner_equal(b.value);
660 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
661 QWeakPointer<
const QQmlJSScope> value;
663 struct GroupProperty {
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679 QWeakPointer<
const QQmlJSScope> groupScope;
680 friend bool operator==(GroupProperty a, GroupProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
681 friend bool operator!=(GroupProperty a, GroupProperty b) {
return !(a == b); }
683 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
684 RegexpLiteral, Null, TranslationString,
685 TranslationById, Script, Object, Interceptor,
686 ValueSource, AttachedProperty, GroupProperty
689 using BindingContent = Content::type;
691 QQmlJS::SourceLocation m_sourceLocation;
692 QString m_propertyName;
693 BindingContent m_bindingContent;
695 void ensureSetBindingTypeOnce()
697 Q_ASSERT(bindingType() == BindingType::Invalid);
700 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
704 static bool isLiteralBinding(BindingType type)
706 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
707 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
708 || type == BindingType::Null;
711 QQmlJSMetaPropertyBinding();
712 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
713 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
714 : m_sourceLocation(location), m_propertyName(propName)
717 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
718 const QQmlJSMetaProperty &prop)
719 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
723 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
724 QString propertyName()
const {
return m_propertyName; }
726 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
728 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
730 bool isValid()
const;
732 void setStringLiteral(QAnyStringView value)
734 ensureSetBindingTypeOnce();
735 m_bindingContent = Content::StringLiteral { value.toString() };
739 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
740 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
742 ensureSetBindingTypeOnce();
743 m_bindingContent = Content::Script { value, kind, valueType };
746 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
748 ensureSetBindingTypeOnce();
749 m_bindingContent = Content::GroupProperty { groupScope };
752 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
754 ensureSetBindingTypeOnce();
755 m_bindingContent = Content::AttachedProperty { attachingScope };
758 void setBoolLiteral(
bool value)
760 ensureSetBindingTypeOnce();
761 m_bindingContent = Content::BoolLiteral { value };
764 void setNullLiteral()
766 ensureSetBindingTypeOnce();
767 m_bindingContent = Content::Null {};
770 void setNumberLiteral(
double value)
772 ensureSetBindingTypeOnce();
773 m_bindingContent = Content::NumberLiteral { value };
776 void setRegexpLiteral(QAnyStringView value)
778 ensureSetBindingTypeOnce();
779 m_bindingContent = Content::RegexpLiteral { value.toString() };
782 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
784 ensureSetBindingTypeOnce();
786 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
789 void setTranslationId(QStringView id,
int number)
791 ensureSetBindingTypeOnce();
792 m_bindingContent = Content::TranslationById{ id.toString(), number };
795 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
797 ensureSetBindingTypeOnce();
798 m_bindingContent = Content::Object { typeName, type };
801 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
803 ensureSetBindingTypeOnce();
804 m_bindingContent = Content::Interceptor { typeName, type };
807 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
809 ensureSetBindingTypeOnce();
810 m_bindingContent = Content::ValueSource { typeName, type };
814 bool boolValue()
const;
816 double numberValue()
const;
818 QString stringValue()
const;
820 QString regExpValue()
const;
822 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
824 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
826 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
828 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
829 return script->index;
831 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
834 ScriptBindingKind scriptKind()
const
836 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
839 return ScriptBindingKind::Invalid;
842 ScriptBindingValueType scriptValueType()
const
844 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
845 return script->valueType;
847 return ScriptBindingValueType::ScriptValue_Unknown;
850 QString objectTypeName()
const
852 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
853 return object->typeName;
857 QSharedPointer<
const QQmlJSScope> objectType()
const
859 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
860 return object->value.lock();
865 QString interceptorTypeName()
const
867 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
868 return interceptor->typeName;
872 QSharedPointer<
const QQmlJSScope> interceptorType()
const
874 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
875 return interceptor->value.lock();
880 QString valueSourceTypeName()
const
882 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
883 return valueSource->typeName;
887 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
889 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
890 return valueSource->value.lock();
895 QSharedPointer<
const QQmlJSScope> groupType()
const
897 if (
auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
898 return group->groupScope.lock();
903 QSharedPointer<
const QQmlJSScope> attachedType()
const
905 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
906 return attached->value.lock();
911 bool hasLiteral()
const
914 return isLiteralBinding();
916 bool hasObject()
const {
return bindingType() == BindingType::Object; }
917 bool hasInterceptor()
const
919 return bindingType() == BindingType::Interceptor;
921 bool hasValueSource()
const
923 return bindingType() == BindingType::ValueSource;
926 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
928 return a.m_propertyName == b.m_propertyName
929 && a.m_bindingContent == b.m_bindingContent
930 && a.m_sourceLocation == b.m_sourceLocation;
933 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
938 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
941 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
942 binding.bindingType());
948 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)