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); }
387 QQmlJS::SourceLocation m_sourceLocation;
390 QList<QQmlJSMetaParameter> m_parameters;
391 QList<QQmlJSAnnotation> m_annotations;
398 bool m_isCloned =
false;
399 bool m_isConstructor =
false;
400 bool m_isJavaScriptFunction =
false;
401 bool m_isImplicitQmlPropertyChangeSignal =
false;
402 bool m_isConst =
false;
407 QString m_propertyName;
414 QString m_privateClass;
416 QString m_aliasTargetName;
417 QWeakPointer<
const QQmlJSScope> m_aliasTargetScope;
418 QWeakPointer<
const QQmlJSScope> m_type;
419 QQmlJS::SourceLocation m_sourceLocation;
420 QList<QQmlJSAnnotation> m_annotations;
421 bool m_isList =
false;
422 bool m_isWritable =
false;
423 bool m_isPointer =
false;
424 bool m_isTypeConstant =
false;
425 bool m_isFinal =
false;
426 bool m_isVirtual =
false;
427 bool m_isOverride =
false;
428 bool m_isPropertyConstant =
false;
438 void setTypeName(
const QString &typeName) { m_typeName = typeName; }
441 void setRead(
const QString &read) { m_read = read; }
444 void setWrite(
const QString &write) { m_write = write; }
447 void setReset(
const QString &reset) { m_reset = reset; }
450 void setBindable(
const QString &bindable) { m_bindable = bindable; }
453 void setNotify(
const QString ¬ify) { m_notify = notify; }
458 bool isPrivate()
const {
return !m_privateClass.isEmpty(); }
460 void setType(
const QSharedPointer<
const QQmlJSScope> &type) { m_type = type; }
464 { m_sourceLocation = newSourceLocation; }
467 void setAnnotations(
const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
484 bool isAlias()
const {
return !m_aliasExpr.isEmpty(); }
491 m_aliasTargetScope = scope;
495 return m_aliasTargetScope.toStrongRef();
514 int index()
const {
return m_index; }
516 bool isValid()
const {
return !m_propertyName.isEmpty(); }
520 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
521 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
522 && a.m_type.owner_equal(b.m_type) && a.m_isList == b.m_isList
523 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
524 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
525 && a.m_isFinal == b.m_isFinal;
535 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
536 prop.m_type.toStrongRef().data(), prop.m_isList, prop.m_isWritable,
537 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
544 using BindingType = QQmlSA::BindingType;
545 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
549 using Invalid = std::monostate;
552 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
553 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
555 struct NumberLiteral {
557 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
558 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
559 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
560 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
565 struct StringLiteral {
566 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
567 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
570 struct RegexpLiteral {
571 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
572 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
576 friend bool operator==(Null , Null ) {
return true; }
577 friend bool operator!=(Null a, Null b) {
return !(a == b); }
579 struct TranslationString {
580 friend bool operator==(TranslationString a, TranslationString b)
582 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
584 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
590 struct TranslationById {
591 friend bool operator==(TranslationById a, TranslationById b)
593 return a.id == b.id && a.number == b.number;
595 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
600 friend bool operator==(Script a, Script b)
602 return a.index == b.index && a.kind == b.kind;
604 friend bool operator!=(Script a, Script b) {
return !(a == b); }
605 QQmlJSMetaMethod::RelativeFunctionIndex index =
606 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
607 ScriptBindingKind kind = ScriptBindingKind::Invalid;
608 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
611 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
612 friend bool operator!=(Object a, Object b) {
return !(a == b); }
614 QWeakPointer<
const QQmlJSScope> value;
617 friend bool operator==(Interceptor a, Interceptor b)
619 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
621 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
623 QWeakPointer<
const QQmlJSScope> value;
626 friend bool operator==(ValueSource a, ValueSource b)
628 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
630 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
632 QWeakPointer<
const QQmlJSScope> value;
634 struct AttachedProperty {
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655 friend bool operator==(AttachedProperty a, AttachedProperty b)
657 return a.value.owner_equal(b.value);
659 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
660 QWeakPointer<
const QQmlJSScope> value;
662 struct GroupProperty {
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678 QWeakPointer<
const QQmlJSScope> groupScope;
679 friend bool operator==(GroupProperty a, GroupProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
680 friend bool operator!=(GroupProperty a, GroupProperty b) {
return !(a == b); }
682 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
683 RegexpLiteral, Null, TranslationString,
684 TranslationById, Script, Object, Interceptor,
685 ValueSource, AttachedProperty, GroupProperty
688 using BindingContent = Content::type;
690 QQmlJS::SourceLocation m_sourceLocation;
691 QString m_propertyName;
692 BindingContent m_bindingContent;
694 void ensureSetBindingTypeOnce()
696 Q_ASSERT(bindingType() == BindingType::Invalid);
699 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
703 static bool isLiteralBinding(BindingType type)
705 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
706 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
707 || type == BindingType::Null;
710 QQmlJSMetaPropertyBinding();
711 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
712 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
713 : m_sourceLocation(location), m_propertyName(propName)
716 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
717 const QQmlJSMetaProperty &prop)
718 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
722 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
723 QString propertyName()
const {
return m_propertyName; }
725 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
727 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
729 bool isValid()
const;
731 void setStringLiteral(QAnyStringView value)
733 ensureSetBindingTypeOnce();
734 m_bindingContent = Content::StringLiteral { value.toString() };
738 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
739 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
741 ensureSetBindingTypeOnce();
742 m_bindingContent = Content::Script { value, kind, valueType };
745 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
747 ensureSetBindingTypeOnce();
748 m_bindingContent = Content::GroupProperty { groupScope };
751 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
753 ensureSetBindingTypeOnce();
754 m_bindingContent = Content::AttachedProperty { attachingScope };
757 void setBoolLiteral(
bool value)
759 ensureSetBindingTypeOnce();
760 m_bindingContent = Content::BoolLiteral { value };
763 void setNullLiteral()
765 ensureSetBindingTypeOnce();
766 m_bindingContent = Content::Null {};
769 void setNumberLiteral(
double value)
771 ensureSetBindingTypeOnce();
772 m_bindingContent = Content::NumberLiteral { value };
775 void setRegexpLiteral(QAnyStringView value)
777 ensureSetBindingTypeOnce();
778 m_bindingContent = Content::RegexpLiteral { value.toString() };
781 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
783 ensureSetBindingTypeOnce();
785 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
788 void setTranslationId(QStringView id,
int number)
790 ensureSetBindingTypeOnce();
791 m_bindingContent = Content::TranslationById{ id.toString(), number };
794 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
796 ensureSetBindingTypeOnce();
797 m_bindingContent = Content::Object { typeName, type };
800 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
802 ensureSetBindingTypeOnce();
803 m_bindingContent = Content::Interceptor { typeName, type };
806 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
808 ensureSetBindingTypeOnce();
809 m_bindingContent = Content::ValueSource { typeName, type };
813 bool boolValue()
const;
815 double numberValue()
const;
817 QString stringValue()
const;
819 QString regExpValue()
const;
821 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
823 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
825 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
827 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
828 return script->index;
830 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
833 ScriptBindingKind scriptKind()
const
835 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
838 return ScriptBindingKind::Invalid;
841 ScriptBindingValueType scriptValueType()
const
843 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
844 return script->valueType;
846 return ScriptBindingValueType::ScriptValue_Unknown;
849 QString objectTypeName()
const
851 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
852 return object->typeName;
856 QSharedPointer<
const QQmlJSScope> objectType()
const
858 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
859 return object->value.lock();
864 QString interceptorTypeName()
const
866 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
867 return interceptor->typeName;
871 QSharedPointer<
const QQmlJSScope> interceptorType()
const
873 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
874 return interceptor->value.lock();
879 QString valueSourceTypeName()
const
881 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
882 return valueSource->typeName;
886 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
888 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
889 return valueSource->value.lock();
894 QSharedPointer<
const QQmlJSScope> groupType()
const
896 if (
auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
897 return group->groupScope.lock();
902 QSharedPointer<
const QQmlJSScope> attachedType()
const
904 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
905 return attached->value.lock();
910 bool hasLiteral()
const
913 return isLiteralBinding();
915 bool hasObject()
const {
return bindingType() == BindingType::Object; }
916 bool hasInterceptor()
const
918 return bindingType() == BindingType::Interceptor;
920 bool hasValueSource()
const
922 return bindingType() == BindingType::ValueSource;
925 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
927 return a.m_propertyName == b.m_propertyName
928 && a.m_bindingContent == b.m_bindingContent
929 && a.m_sourceLocation == b.m_sourceLocation;
932 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
937 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
940 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
941 binding.bindingType());
947 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)