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 QList<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_isVirtual =
false;
412 bool m_isOverride =
false;
413 bool m_isPropertyConstant =
false;
423 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
426 void setRead(
const QString &read) { m_read = read; }
429 void setWrite(
const QString &write) { m_write = write; }
432 void setReset(
const QString &reset) { m_reset = reset; }
435 void setBindable(
const QString &bindable) { m_bindable = bindable; }
438 void setNotify(
const QString ¬ify) { m_notify = notify; }
443 bool isPrivate()
const {
return !m_privateClass.isEmpty(); }
445 void setType(
const QSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
449 { m_sourceLocation = newSourceLocation; }
452 void setAnnotations(
const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
469 bool isAlias()
const {
return !m_aliasExpr.isEmpty(); }
476 m_aliasTargetScope = scope;
480 return m_aliasTargetScope.toStrongRef();
499 int index()
const {
return m_index; }
501 bool isValid()
const {
return !m_propertyName.isEmpty(); }
505 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
506 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
507 && a.m_type.owner_equal(b.m_type) && a.m_isList == b.m_isList
508 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
509 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
510 && a.m_isFinal == b.m_isFinal;
520 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
521 prop.m_type.toStrongRef().data(), prop.m_isList, prop.m_isWritable,
522 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
529 using BindingType = QQmlSA::BindingType;
530 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
534 using Invalid = std::monostate;
537 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
538 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
540 struct NumberLiteral {
542 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
543 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
544 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
545 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
550 struct StringLiteral {
551 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
552 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
555 struct RegexpLiteral {
556 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
557 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
561 friend bool operator==(Null , Null ) {
return true; }
562 friend bool operator!=(Null a, Null b) {
return !(a == b); }
564 struct TranslationString {
565 friend bool operator==(TranslationString a, TranslationString b)
567 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
569 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
575 struct TranslationById {
576 friend bool operator==(TranslationById a, TranslationById b)
578 return a.id == b.id && a.number == b.number;
580 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
585 friend bool operator==(Script a, Script b)
587 return a.index == b.index && a.kind == b.kind;
589 friend bool operator!=(Script a, Script b) {
return !(a == b); }
590 QQmlJSMetaMethod::RelativeFunctionIndex index =
591 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
592 ScriptBindingKind kind = ScriptBindingKind::Invalid;
593 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
596 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
597 friend bool operator!=(Object a, Object b) {
return !(a == b); }
599 QWeakPointer<
const QQmlJSScope> value;
602 friend bool operator==(Interceptor a, Interceptor b)
604 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
606 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
608 QWeakPointer<
const QQmlJSScope> value;
611 friend bool operator==(ValueSource a, ValueSource b)
613 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
615 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
617 QWeakPointer<
const QQmlJSScope> value;
619 struct AttachedProperty {
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640 friend bool operator==(AttachedProperty a, AttachedProperty b)
642 return a.value.owner_equal(b.value);
644 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
645 QWeakPointer<
const QQmlJSScope> value;
647 struct GroupProperty {
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663 QWeakPointer<
const QQmlJSScope> groupScope;
664 friend bool operator==(GroupProperty a, GroupProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
665 friend bool operator!=(GroupProperty a, GroupProperty b) {
return !(a == b); }
667 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
668 RegexpLiteral, Null, TranslationString,
669 TranslationById, Script, Object, Interceptor,
670 ValueSource, AttachedProperty, GroupProperty
673 using BindingContent = Content::type;
675 QQmlJS::SourceLocation m_sourceLocation;
676 QString m_propertyName;
677 BindingContent m_bindingContent;
679 void ensureSetBindingTypeOnce()
681 Q_ASSERT(bindingType() == BindingType::Invalid);
684 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
688 static bool isLiteralBinding(BindingType type)
690 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
691 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
692 || type == BindingType::Null;
695 QQmlJSMetaPropertyBinding();
696 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
697 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
698 : m_sourceLocation(location), m_propertyName(propName)
701 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
702 const QQmlJSMetaProperty &prop)
703 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
707 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
708 QString propertyName()
const {
return m_propertyName; }
710 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
712 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
714 bool isValid()
const;
716 void setStringLiteral(QAnyStringView value)
718 ensureSetBindingTypeOnce();
719 m_bindingContent = Content::StringLiteral { value.toString() };
723 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
724 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
726 ensureSetBindingTypeOnce();
727 m_bindingContent = Content::Script { value, kind, valueType };
730 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
732 ensureSetBindingTypeOnce();
733 m_bindingContent = Content::GroupProperty { groupScope };
736 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
738 ensureSetBindingTypeOnce();
739 m_bindingContent = Content::AttachedProperty { attachingScope };
742 void setBoolLiteral(
bool value)
744 ensureSetBindingTypeOnce();
745 m_bindingContent = Content::BoolLiteral { value };
748 void setNullLiteral()
750 ensureSetBindingTypeOnce();
751 m_bindingContent = Content::Null {};
754 void setNumberLiteral(
double value)
756 ensureSetBindingTypeOnce();
757 m_bindingContent = Content::NumberLiteral { value };
760 void setRegexpLiteral(QAnyStringView value)
762 ensureSetBindingTypeOnce();
763 m_bindingContent = Content::RegexpLiteral { value.toString() };
766 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
768 ensureSetBindingTypeOnce();
770 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
773 void setTranslationId(QStringView id,
int number)
775 ensureSetBindingTypeOnce();
776 m_bindingContent = Content::TranslationById{ id.toString(), number };
779 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
781 ensureSetBindingTypeOnce();
782 m_bindingContent = Content::Object { typeName, type };
785 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
787 ensureSetBindingTypeOnce();
788 m_bindingContent = Content::Interceptor { typeName, type };
791 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
793 ensureSetBindingTypeOnce();
794 m_bindingContent = Content::ValueSource { typeName, type };
798 bool boolValue()
const;
800 double numberValue()
const;
802 QString stringValue()
const;
804 QString regExpValue()
const;
806 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
808 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
810 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
812 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
813 return script->index;
815 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
818 ScriptBindingKind scriptKind()
const
820 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
823 return ScriptBindingKind::Invalid;
826 ScriptBindingValueType scriptValueType()
const
828 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
829 return script->valueType;
831 return ScriptBindingValueType::ScriptValue_Unknown;
834 QString objectTypeName()
const
836 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
837 return object->typeName;
841 QSharedPointer<
const QQmlJSScope> objectType()
const
843 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
844 return object->value.lock();
849 QString interceptorTypeName()
const
851 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
852 return interceptor->typeName;
856 QSharedPointer<
const QQmlJSScope> interceptorType()
const
858 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
859 return interceptor->value.lock();
864 QString valueSourceTypeName()
const
866 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
867 return valueSource->typeName;
871 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
873 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
874 return valueSource->value.lock();
879 QSharedPointer<
const QQmlJSScope> groupType()
const
881 if (
auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
882 return group->groupScope.lock();
887 QSharedPointer<
const QQmlJSScope> attachedType()
const
889 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
890 return attached->value.lock();
895 bool hasLiteral()
const
898 return isLiteralBinding();
900 bool hasObject()
const {
return bindingType() == BindingType::Object; }
901 bool hasInterceptor()
const
903 return bindingType() == BindingType::Interceptor;
905 bool hasValueSource()
const
907 return bindingType() == BindingType::ValueSource;
910 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
912 return a.m_propertyName == b.m_propertyName
913 && a.m_bindingContent == b.m_bindingContent
914 && a.m_sourceLocation == b.m_sourceLocation;
917 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
922 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
925 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
926 binding.bindingType());
932 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)