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,
520
521
522
523
524
525
526
527
530 using BindingType = QQmlSA::BindingType;
531 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
535 using Invalid = std::monostate;
538 friend bool operator==(BoolLiteral a, BoolLiteral b) {
return a.value == b.value; }
539 friend bool operator!=(BoolLiteral a, BoolLiteral b) {
return !(a == b); }
541 struct NumberLiteral {
543 QT_WARNING_DISABLE_CLANG(
"-Wfloat-equal")
544 QT_WARNING_DISABLE_GCC(
"-Wfloat-equal")
545 friend bool operator==(NumberLiteral a, NumberLiteral b) {
return a.value == b.value; }
546 friend bool operator!=(NumberLiteral a, NumberLiteral b) {
return !(a == b); }
551 struct StringLiteral {
552 friend bool operator==(StringLiteral a, StringLiteral b) {
return a.value == b.value; }
553 friend bool operator!=(StringLiteral a, StringLiteral b) {
return !(a == b); }
556 struct RegexpLiteral {
557 friend bool operator==(RegexpLiteral a, RegexpLiteral b) {
return a.value == b.value; }
558 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) {
return !(a == b); }
562 friend bool operator==(Null , Null ) {
return true; }
563 friend bool operator!=(Null a, Null b) {
return !(a == b); }
565 struct TranslationString {
566 friend bool operator==(TranslationString a, TranslationString b)
568 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
570 friend bool operator!=(TranslationString a, TranslationString b) {
return !(a == b); }
576 struct TranslationById {
577 friend bool operator==(TranslationById a, TranslationById b)
579 return a.id == b.id && a.number == b.number;
581 friend bool operator!=(TranslationById a, TranslationById b) {
return !(a == b); }
586 friend bool operator==(Script a, Script b)
588 return a.index == b.index && a.kind == b.kind;
590 friend bool operator!=(Script a, Script b) {
return !(a == b); }
591 QQmlJSMetaMethod::RelativeFunctionIndex index =
592 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
593 ScriptBindingKind kind = ScriptBindingKind::Invalid;
594 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
597 friend bool operator==(Object a, Object b) {
return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
598 friend bool operator!=(Object a, Object b) {
return !(a == b); }
600 QWeakPointer<
const QQmlJSScope> value;
603 friend bool operator==(Interceptor a, Interceptor b)
605 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
607 friend bool operator!=(Interceptor a, Interceptor b) {
return !(a == b); }
609 QWeakPointer<
const QQmlJSScope> value;
612 friend bool operator==(ValueSource a, ValueSource b)
614 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
616 friend bool operator!=(ValueSource a, ValueSource b) {
return !(a == b); }
618 QWeakPointer<
const QQmlJSScope> value;
620 struct AttachedProperty {
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641 friend bool operator==(AttachedProperty a, AttachedProperty b)
643 return a.value.owner_equal(b.value);
645 friend bool operator!=(AttachedProperty a, AttachedProperty b) {
return !(a == b); }
646 QWeakPointer<
const QQmlJSScope> value;
648 struct GroupProperty {
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664 QWeakPointer<
const QQmlJSScope> groupScope;
665 friend bool operator==(GroupProperty a, GroupProperty b) {
return a.groupScope.owner_equal(b.groupScope); }
666 friend bool operator!=(GroupProperty a, GroupProperty b) {
return !(a == b); }
668 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
669 RegexpLiteral, Null, TranslationString,
670 TranslationById, Script, Object, Interceptor,
671 ValueSource, AttachedProperty, GroupProperty
674 using BindingContent = Content::type;
676 QQmlJS::SourceLocation m_sourceLocation;
677 QString m_propertyName;
678 BindingContent m_bindingContent;
680 void ensureSetBindingTypeOnce()
682 Q_ASSERT(bindingType() == BindingType::Invalid);
685 bool isLiteralBinding()
const {
return isLiteralBinding(bindingType()); }
689 static bool isLiteralBinding(BindingType type)
691 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
692 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
693 || type == BindingType::Null;
696 QQmlJSMetaPropertyBinding();
697 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
698 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
const QString &propName)
699 : m_sourceLocation(location), m_propertyName(propName)
702 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
703 const QQmlJSMetaProperty &prop)
704 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
708 void setPropertyName(
const QString &propertyName) { m_propertyName = propertyName; }
709 QString propertyName()
const {
return m_propertyName; }
711 const QQmlJS::SourceLocation &sourceLocation()
const {
return m_sourceLocation; }
713 BindingType bindingType()
const {
return BindingType(m_bindingContent.index()); }
715 bool isValid()
const;
717 void setStringLiteral(QAnyStringView value)
719 ensureSetBindingTypeOnce();
720 m_bindingContent = Content::StringLiteral { value.toString() };
724 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
725 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
727 ensureSetBindingTypeOnce();
728 m_bindingContent = Content::Script { value, kind, valueType };
731 void setGroupBinding(
const QSharedPointer<
const QQmlJSScope> &groupScope)
733 ensureSetBindingTypeOnce();
734 m_bindingContent = Content::GroupProperty { groupScope };
737 void setAttachedBinding(
const QSharedPointer<
const QQmlJSScope> &attachingScope)
739 ensureSetBindingTypeOnce();
740 m_bindingContent = Content::AttachedProperty { attachingScope };
743 void setBoolLiteral(
bool value)
745 ensureSetBindingTypeOnce();
746 m_bindingContent = Content::BoolLiteral { value };
749 void setNullLiteral()
751 ensureSetBindingTypeOnce();
752 m_bindingContent = Content::Null {};
755 void setNumberLiteral(
double value)
757 ensureSetBindingTypeOnce();
758 m_bindingContent = Content::NumberLiteral { value };
761 void setRegexpLiteral(QAnyStringView value)
763 ensureSetBindingTypeOnce();
764 m_bindingContent = Content::RegexpLiteral { value.toString() };
767 void setTranslation(QStringView text, QStringView comment, QStringView context,
int number)
769 ensureSetBindingTypeOnce();
771 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
774 void setTranslationId(QStringView id,
int number)
776 ensureSetBindingTypeOnce();
777 m_bindingContent = Content::TranslationById{ id.toString(), number };
780 void setObject(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
782 ensureSetBindingTypeOnce();
783 m_bindingContent = Content::Object { typeName, type };
786 void setInterceptor(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
788 ensureSetBindingTypeOnce();
789 m_bindingContent = Content::Interceptor { typeName, type };
792 void setValueSource(
const QString &typeName,
const QSharedPointer<
const QQmlJSScope> &type)
794 ensureSetBindingTypeOnce();
795 m_bindingContent = Content::ValueSource { typeName, type };
799 bool boolValue()
const;
801 double numberValue()
const;
803 QString stringValue()
const;
805 QString regExpValue()
const;
807 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString())
const;
809 QSharedPointer<
const QQmlJSScope> literalType(
const QQmlJSTypeResolver *resolver)
const;
811 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex()
const
813 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
814 return script->index;
816 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
819 ScriptBindingKind scriptKind()
const
821 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
824 return ScriptBindingKind::Invalid;
827 ScriptBindingValueType scriptValueType()
const
829 if (
auto *script = std::get_if<Content::Script>(&m_bindingContent))
830 return script->valueType;
832 return ScriptBindingValueType::ScriptValue_Unknown;
835 QString objectTypeName()
const
837 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
838 return object->typeName;
842 QSharedPointer<
const QQmlJSScope> objectType()
const
844 if (
auto *object = std::get_if<Content::Object>(&m_bindingContent))
845 return object->value.lock();
850 QString interceptorTypeName()
const
852 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
853 return interceptor->typeName;
857 QSharedPointer<
const QQmlJSScope> interceptorType()
const
859 if (
auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
860 return interceptor->value.lock();
865 QString valueSourceTypeName()
const
867 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
868 return valueSource->typeName;
872 QSharedPointer<
const QQmlJSScope> valueSourceType()
const
874 if (
auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
875 return valueSource->value.lock();
880 QSharedPointer<
const QQmlJSScope> groupType()
const
882 if (
auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
883 return group->groupScope.lock();
888 QSharedPointer<
const QQmlJSScope> attachedType()
const
890 if (
auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
891 return attached->value.lock();
896 bool hasLiteral()
const
899 return isLiteralBinding();
901 bool hasObject()
const {
return bindingType() == BindingType::Object; }
902 bool hasInterceptor()
const
904 return bindingType() == BindingType::Interceptor;
906 bool hasValueSource()
const
908 return bindingType() == BindingType::ValueSource;
911 friend bool operator==(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
913 return a.m_propertyName == b.m_propertyName
914 && a.m_bindingContent == b.m_bindingContent
915 && a.m_sourceLocation == b.m_sourceLocation;
918 friend bool operator!=(
const QQmlJSMetaPropertyBinding &a,
const QQmlJSMetaPropertyBinding &b)
923 friend size_t qHash(
const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
926 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
927 binding.bindingType());
933 QStringList signalParameters;
static QString toNumericString(double value)
static QString messageTypeForMethod(const QString &method)
static QString derefContentPointer(const QString &contentPointer)
#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)