Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljsmetatypes_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLJSMETATYPES_P_H
6#define QQMLJSMETATYPES_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <qtqmlcompilerexports.h>
19
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>
25
26#include <QtQml/private/qqmljssourcelocation_p.h>
27#include <QtQml/private/qqmltranslation_p.h>
28
31#include "qqmlsa.h"
33
34// MetaMethod and MetaProperty have both type names and actual QQmlJSScope types.
35// When parsing the information from the relevant QML or qmltypes files, we only
36// see the names and don't have a complete picture of the types, yet. In a second
37// pass we typically fill in the types. The types may have multiple exported names
38// and the the name property of MetaProperty and MetaMethod still carries some
39// significance regarding which name was chosen to refer to the type. In a third
40// pass we may further specify the type if the context provides additional information.
41// The parent of an Item, for example, is typically not just a QtObject, but rather
42// some other Item with custom properties.
43
45
46enum ScriptBindingValueType : unsigned int {
48 ScriptValue_Function, // binding to a function, arrow, lambda or a {}-block
49 ScriptValue_Undefined // property int p: undefined
50};
51
53
54class QQmlJSTypeResolver;
55class QQmlJSScope;
57{
58 QStringList m_keys;
59 QList<int> m_values; // empty if values unknown.
60 QString m_name;
61 QString m_alias;
62 QString m_typeName;
63 QSharedPointer<const QQmlJSScope> m_type;
64 int m_lineNumber = 0;
65 bool m_isFlag = false;
66 bool m_isScoped = false;
67 bool m_isQml = false;
68
69public:
70 QQmlJSMetaEnum() = default;
71 explicit QQmlJSMetaEnum(QString name) : m_name(std::move(name)) {}
72
73 bool isValid() const { return !m_name.isEmpty(); }
74
75 QString name() const { return m_name; }
76 void setName(const QString &name) { m_name = name; }
77
78 QString alias() const { return m_alias; }
79 void setAlias(const QString &alias) { m_alias = alias; }
80
81 bool isFlag() const { return m_isFlag; }
82 void setIsFlag(bool isFlag) { m_isFlag = isFlag; }
83
84 bool isScoped() const { return m_isScoped; }
85 void setIsScoped(bool v) { m_isScoped = v; }
86
87 bool isQml() const { return m_isQml; }
88 void setIsQml(bool v) { m_isQml = v; }
89
90 void addKey(const QString &key) { m_keys.append(key); }
91 QStringList keys() const { return m_keys; }
92
93 void addValue(int value) { m_values.append(value); }
94 QList<int> values() const { return m_values; }
95
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; }
99
100 QString typeName() const { return m_typeName; }
101 void setTypeName(const QString &typeName) { m_typeName = typeName; }
102
103 QSharedPointer<const QQmlJSScope> type() const { return m_type; }
104 void setType(const QSharedPointer<const QQmlJSScope> &type) { m_type = type; }
105
106 int lineNumber() const { return m_lineNumber; }
107 void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
108
109 friend bool operator==(const QQmlJSMetaEnum &a, const QQmlJSMetaEnum &b)
110 {
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;
118 }
119
120 friend bool operator!=(const QQmlJSMetaEnum &a, const QQmlJSMetaEnum &b)
121 {
122 return !(a == b);
123 }
124
125 friend size_t qHash(const QQmlJSMetaEnum &e, size_t seed = 0)
126 {
127 return qHashMulti(
128 seed, e.m_keys, e.m_values, e.m_name, e.m_alias, e.m_isFlag, e.m_type, e.m_isScoped);
129 }
130};
131
133{
134public:
135 /*!
136 \internal
137 A non-const parameter is passed either by pointer or by value, depending on its access
138 semantics. For types with reference access semantics, they can be const and will be passed
139 then as const pointer. Const references are treated like values (i.e. non-const).
140 */
144 };
145
146 QQmlJSMetaParameter(QString name = QString(), QString typeName = QString(),
147 Constness typeQualifier = NonConst,
148 QWeakPointer<const QQmlJSScope> type = {})
149 : m_name(std::move(name)),
151 m_type(type),
152 m_typeQualifier(typeQualifier)
153 {
154 }
155
156 QString name() const { return m_name; }
157 void setName(const QString &name) { m_name = name; }
158 QString typeName() const { return m_typeName; }
159 void setTypeName(const QString &typeName) { m_typeName = typeName; }
160 QSharedPointer<const QQmlJSScope> type() const { return m_type.toStrongRef(); }
161 void setType(QWeakPointer<const QQmlJSScope> type) { m_type = type; }
162 Constness typeQualifier() const { return m_typeQualifier; }
163 void setTypeQualifier(Constness typeQualifier) { m_typeQualifier = typeQualifier; }
164 bool isPointer() const { return m_isPointer; }
165 void setIsPointer(bool isPointer) { m_isPointer = isPointer; }
166 bool isList() const { return m_isList; }
167 void setIsList(bool isList) { m_isList = isList; }
168
169 friend bool operator==(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b)
170 {
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;
174 }
175
176 friend bool operator!=(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b)
177 {
178 return !(a == b);
179 }
180
181 friend size_t qHash(const QQmlJSMetaParameter &e, size_t seed = 0)
182 {
183 return qHashMulti(seed, e.m_name, e.m_typeName, e.m_type.owner_hash(),
184 e.m_typeQualifier);
185 }
186
187private:
188 QString m_name;
189 QString m_typeName;
190 QWeakPointer<const QQmlJSScope> m_type;
191 Constness m_typeQualifier = NonConst;
192 bool m_isPointer = false;
193 bool m_isList = false;
194};
195
197
199{
200public:
203
204public:
205 /*! \internal
206
207 Represents a relative JavaScript function/expression index within a type
208 in a QML document. Used as a typed alternative to int with an explicit
209 invalid state.
210 */
211 enum class RelativeFunctionIndex : int { Invalid = -1 };
212
213 /*! \internal
214
215 Represents an absolute JavaScript function/expression index pointing
216 into the QV4::ExecutableCompilationUnit::runtimeFunctions array. Used as
217 a typed alternative to int with an explicit invalid state.
218 */
219 enum class AbsoluteFunctionIndex : int { Invalid = -1 };
220
221 QQmlJSMetaMethod() = default;
222 explicit QQmlJSMetaMethod(QString name, QString returnType = QString())
223 : m_name(std::move(name)),
225 m_methodType(MethodType::Method)
226 {}
227
228 QString methodName() const { return m_name; }
229 void setMethodName(const QString &name) { m_name = name; }
230
231 QQmlJS::SourceLocation sourceLocation() const { return m_sourceLocation; }
232 void setSourceLocation(QQmlJS::SourceLocation location) { m_sourceLocation = location; }
233
234 QQmlJSMetaReturnType returnValue() const { return m_returnType; }
235 void setReturnValue(const QQmlJSMetaReturnType returnValue) { m_returnType = returnValue; }
236 QString returnTypeName() const { return m_returnType.typeName(); }
237 void setReturnTypeName(const QString &typeName) { m_returnType.setTypeName(typeName); }
238 QSharedPointer<const QQmlJSScope> returnType() const { return m_returnType.type(); }
239 void setReturnType(QWeakPointer<const QQmlJSScope> type) { m_returnType.setType(type); }
240
241 QList<QQmlJSMetaParameter> parameters() const { return m_parameters; }
244 {
245 return { m_parameters.begin(), m_parameters.end() };
246 }
247
249 {
251 for (const auto &p : m_parameters)
252 names.append(p.name());
253
254 return names;
255 }
256
258
260
263
264 Access access() const { return m_methodAccess; }
265
266 int revision() const { return m_revision; }
267 void setRevision(int r) { m_revision = r; }
268
269 bool isCloned() const { return m_isCloned; }
271
272 bool isConstructor() const { return m_isConstructor; }
274
280
286
287 bool isConst() const { return m_isConst; }
289
290 bool isValid() const { return !m_name.isEmpty(); }
291
294
300
306
312
318
324
330
336
342
356
357 friend bool operator!=(const QQmlJSMetaMethod &a, const QQmlJSMetaMethod &b)
358 {
359 return !(a == b);
360 }
361
384
385private:
387
388 QQmlJS::SourceLocation m_sourceLocation;
389
390 QQmlJSMetaReturnType m_returnType;
391 QList<QQmlJSMetaParameter> m_parameters;
392 QList<QQmlJSAnnotation> m_annotations;
393
394 MethodType m_methodType = MethodType::Signal;
395 Access m_methodAccess = Public;
396 int m_revision = 0;
398 RelativeFunctionIndex m_otherFunctionIndex = RelativeFunctionIndex::Invalid; // TODO remove QTBUG-147141
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;
404};
405
407{
408 QString m_propertyName;
409 QString m_typeName;
410 QString m_read;
411 QString m_write;
412 QString m_reset;
413 QString m_bindable;
414 QString m_notify;
415 QString m_privateClass;
416 QString m_aliasExpr;
417 QString m_aliasTargetName;
418 QWeakPointer<const QQmlJSScope> m_aliasTargetScope;
419 QDeferredWeakPointer<const QQmlJSScope> m_type;
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;
430 int m_revision = 0;
431 int m_index = -1; // relative property index within owning QQmlJSScope
432
433public:
435
436 void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
437 QString propertyName() const { return m_propertyName; }
438
439 void setTypeName(const QString &typeName) { m_typeName = typeName; }
440 QString typeName() const { return m_typeName; }
441
442 void setRead(const QString &read) { m_read = read; }
443 QString read() const { return m_read; }
444
445 void setWrite(const QString &write) { m_write = write; }
446 QString write() const { return m_write; }
447
448 void setReset(const QString &reset) { m_reset = reset; }
449 QString reset() const { return m_reset; }
450
451 void setBindable(const QString &bindable) { m_bindable = bindable; }
452 QString bindable() const { return m_bindable; }
453
454 void setNotify(const QString &notify) { m_notify = notify; }
455 QString notify() const { return m_notify; }
456
457 void setPrivateClass(const QString &privateClass) { m_privateClass = privateClass; }
458 QString privateClass() const { return m_privateClass; }
459 bool isPrivate() const { return !m_privateClass.isEmpty(); } // exists for convenience
460
461 void setType(const QDeferredSharedPointer<const QQmlJSScope> &type) { m_type = type; }
462 QDeferredSharedPointer<const QQmlJSScope> type() const { return m_type; }
463
464 void setSourceLocation(const QQmlJS::SourceLocation &newSourceLocation)
465 { m_sourceLocation = newSourceLocation; }
466 QQmlJS::SourceLocation sourceLocation() const { return m_sourceLocation; }
467
468 void setAnnotations(const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
469 const QList<QQmlJSAnnotation> &annotations() const { return m_annotations; }
470
471 void setIsList(bool isList) { m_isList = isList; }
472 bool isList() const { return m_isList; }
473
474 void setIsWritable(bool isWritable) { m_isWritable = isWritable; }
475 bool isWritable() const { return m_isWritable; }
476
477 void setIsPointer(bool isPointer) { m_isPointer = isPointer; }
478 bool isPointer() const { return m_isPointer; }
479
480 void setIsTypeConstant(bool isTypeConstant) { m_isTypeConstant = isTypeConstant; }
481 bool isTypeConstant() const { return m_isTypeConstant; }
482
483 void setAliasExpression(const QString &aliasString) { m_aliasExpr = aliasString; }
484 QString aliasExpression() const { return m_aliasExpr; }
485 bool isAlias() const { return !m_aliasExpr.isEmpty(); } // exists for convenience
486
487 void setAliasTargetName(const QString &name) { m_aliasTargetName = name; }
488 QString aliasTargetName() const { return m_aliasTargetName; }
489
490 void setAliasTargetScope(const QSharedPointer<const QQmlJSScope> &scope)
491 {
492 m_aliasTargetScope = scope;
493 }
495 {
496 return m_aliasTargetScope.toStrongRef();
497 }
498
499 void setIsFinal(bool isFinal) { m_isFinal = isFinal; }
500 bool isFinal() const { return m_isFinal; }
501
502 void setIsOverride(bool isOverride) { m_isOverride = isOverride; }
503 bool isOverride() const { return m_isOverride; }
504
505 void setIsVirtual(bool isVirtual) { m_isVirtual = isVirtual; }
506 bool isVirtual() const { return m_isVirtual; }
507
508 void setIsPropertyConstant(bool isPropertyConstant) { m_isPropertyConstant = isPropertyConstant; }
509 bool isPropertyConstant() const { return m_isPropertyConstant; }
510
511 void setRevision(int revision) { m_revision = revision; }
512 int revision() const { return m_revision; }
513
514 void setIndex(int index) { m_index = index; }
515 int index() const { return m_index; }
516
517 bool isValid() const { return !m_propertyName.isEmpty(); }
518
519 friend bool operator==(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
520 {
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;
527 }
528
529 friend bool operator!=(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
530 {
531 return !(a == b);
532 }
533
534 friend size_t qHash(const QQmlJSMetaProperty &prop, size_t seed = 0)
535 {
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,
539 prop.m_index);
540 }
541};
542
543class Q_QMLCOMPILER_EXPORT QQmlJSMetaPropertyBinding
544{
545 using BindingType = QQmlSA::BindingType;
546 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
547
548 // needs to be kept in sync with the BindingType enum
549 struct Content {
550 using Invalid = std::monostate;
551 struct BoolLiteral {
552 bool value;
553 friend bool operator==(BoolLiteral a, BoolLiteral b) { return a.value == b.value; }
554 friend bool operator!=(BoolLiteral a, BoolLiteral b) { return !(a == b); }
555 };
556 struct NumberLiteral {
557 QT_WARNING_PUSH
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); }
562 QT_WARNING_POP
563
564 double value; // ### TODO: int?
565 };
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); }
569 QString value;
570 };
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); }
574 QString value;
575 };
576 struct Null {
577 friend bool operator==(Null , Null ) { return true; }
578 friend bool operator!=(Null a, Null b) { return !(a == b); }
579 };
580 struct TranslationString {
581 friend bool operator==(TranslationString a, TranslationString b)
582 {
583 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
584 }
585 friend bool operator!=(TranslationString a, TranslationString b) { return !(a == b); }
586 QString text;
587 QString comment;
588 QString context;
589 int number;
590 };
591 struct TranslationById {
592 friend bool operator==(TranslationById a, TranslationById b)
593 {
594 return a.id == b.id && a.number == b.number;
595 }
596 friend bool operator!=(TranslationById a, TranslationById b) { return !(a == b); }
597 QString id;
598 int number;
599 };
600 struct Script {
601 friend bool operator==(Script a, Script b)
602 {
603 return a.index == b.index && a.kind == b.kind;
604 }
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;
610 };
611 struct Object {
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); }
614 QString typeName;
615 QWeakPointer<const QQmlJSScope> value;
616 };
617 struct Interceptor {
618 friend bool operator==(Interceptor a, Interceptor b)
619 {
620 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
621 }
622 friend bool operator!=(Interceptor a, Interceptor b) { return !(a == b); }
623 QString typeName;
624 QWeakPointer<const QQmlJSScope> value;
625 };
626 struct ValueSource {
627 friend bool operator==(ValueSource a, ValueSource b)
628 {
629 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
630 }
631 friend bool operator!=(ValueSource a, ValueSource b) { return !(a == b); }
632 QString typeName;
633 QWeakPointer<const QQmlJSScope> value;
634 };
635 struct AttachedProperty {
636 /*
637 AttachedProperty binding is a grouping for a series of bindings
638 belonging to the same scope(QQmlJSScope::AttachedPropertyScope).
639 Thus, the attached property binding itself only exposes the
640 attaching type object. Such object is unique per the enclosing
641 scope, so attaching types attached to different QML scopes are
642 different (think of them as objects in C++ terms).
643
644 An attaching type object, being a QQmlJSScope, has bindings
645 itself. For instance:
646 ```
647 Type {
648 Keys.enabled: true
649 }
650 ```
651 tells us that "Type" has an AttachedProperty binding with
652 property name "Keys". The attaching object of that binding
653 (binding.attachedType()) has type "Keys" and a BoolLiteral
654 binding with property name "enabled".
655 */
656 friend bool operator==(AttachedProperty a, AttachedProperty b)
657 {
658 return a.value.owner_equal(b.value);
659 }
660 friend bool operator!=(AttachedProperty a, AttachedProperty b) { return !(a == b); }
661 QWeakPointer<const QQmlJSScope> value;
662 };
663 struct GroupProperty {
664 /* Given a group property declaration like
665 anchors.left: root.left
666 the QQmlJSMetaPropertyBinding will have name "anchors", and a m_bindingContent
667 of type GroupProperty, with groupScope pointing to the scope introudced by anchors
668 In that scope, there will be another QQmlJSMetaPropertyBinding, with name "left" and
669 m_bindingContent Script (for root.left).
670 There should never be more than one GroupProperty for the same name in the same
671 scope, though: If the scope also contains anchors.top: root.top that should reuse the
672 GroupProperty content (and add a top: root.top binding in it). There might however
673 still be an additional object or script binding ( anchors: {left: foo, right: bar };
674 anchors: root.someFunction() ) or another binding to the property in a "derived"
675 type.
676
677 ### TODO: Obtaining the effective binding result requires some resolving function
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); }
682 };
683 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
684 RegexpLiteral, Null, TranslationString,
685 TranslationById, Script, Object, Interceptor,
686 ValueSource, AttachedProperty, GroupProperty
687 >;
688 };
689 using BindingContent = Content::type;
690
691 QQmlJS::SourceLocation m_sourceLocation;
692 QString m_propertyName; // TODO: this is a debug-only information
693 BindingContent m_bindingContent;
694
695 void ensureSetBindingTypeOnce()
696 {
697 Q_ASSERT(bindingType() == BindingType::Invalid);
698 }
699
700 bool isLiteralBinding() const { return isLiteralBinding(bindingType()); }
701
702
703public:
704 static bool isLiteralBinding(BindingType type)
705 {
706 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
707 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
708 || type == BindingType::Null; // special. we record it as literal
709 }
710
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)
715 {
716 }
717 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
718 const QQmlJSMetaProperty &prop)
719 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
720 {
721 }
722
723 void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
724 QString propertyName() const { return m_propertyName; }
725
726 const QQmlJS::SourceLocation &sourceLocation() const { return m_sourceLocation; }
727
728 BindingType bindingType() const { return BindingType(m_bindingContent.index()); }
729
730 bool isValid() const;
731
732 void setStringLiteral(QAnyStringView value)
733 {
734 ensureSetBindingTypeOnce();
735 m_bindingContent = Content::StringLiteral { value.toString() };
736 }
737
738 void
739 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
740 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
741 {
742 ensureSetBindingTypeOnce();
743 m_bindingContent = Content::Script { value, kind, valueType };
744 }
745
746 void setGroupBinding(const QSharedPointer<const QQmlJSScope> &groupScope)
747 {
748 ensureSetBindingTypeOnce();
749 m_bindingContent = Content::GroupProperty { groupScope };
750 }
751
752 void setAttachedBinding(const QSharedPointer<const QQmlJSScope> &attachingScope)
753 {
754 ensureSetBindingTypeOnce();
755 m_bindingContent = Content::AttachedProperty { attachingScope };
756 }
757
758 void setBoolLiteral(bool value)
759 {
760 ensureSetBindingTypeOnce();
761 m_bindingContent = Content::BoolLiteral { value };
762 }
763
764 void setNullLiteral()
765 {
766 ensureSetBindingTypeOnce();
767 m_bindingContent = Content::Null {};
768 }
769
770 void setNumberLiteral(double value)
771 {
772 ensureSetBindingTypeOnce();
773 m_bindingContent = Content::NumberLiteral { value };
774 }
775
776 void setRegexpLiteral(QAnyStringView value)
777 {
778 ensureSetBindingTypeOnce();
779 m_bindingContent = Content::RegexpLiteral { value.toString() };
780 }
781
782 void setTranslation(QStringView text, QStringView comment, QStringView context, int number)
783 {
784 ensureSetBindingTypeOnce();
785 m_bindingContent =
786 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
787 }
788
789 void setTranslationId(QStringView id, int number)
790 {
791 ensureSetBindingTypeOnce();
792 m_bindingContent = Content::TranslationById{ id.toString(), number };
793 }
794
795 void setObject(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
796 {
797 ensureSetBindingTypeOnce();
798 m_bindingContent = Content::Object { typeName, type };
799 }
800
801 void setInterceptor(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
802 {
803 ensureSetBindingTypeOnce();
804 m_bindingContent = Content::Interceptor { typeName, type };
805 }
806
807 void setValueSource(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
808 {
809 ensureSetBindingTypeOnce();
810 m_bindingContent = Content::ValueSource { typeName, type };
811 }
812
813 // ### TODO: here and below: Introduce an allowConversion parameter, if yes, enable conversions e.g. bool -> number?
814 bool boolValue() const;
815
816 double numberValue() const;
817
818 QString stringValue() const;
819
820 QString regExpValue() const;
821
822 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString()) const;
823
824 QSharedPointer<const QQmlJSScope> literalType(const QQmlJSTypeResolver *resolver) const;
825
826 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex() const
827 {
828 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
829 return script->index;
830 // warn
831 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
832 }
833
834 ScriptBindingKind scriptKind() const
835 {
836 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
837 return script->kind;
838 // warn
839 return ScriptBindingKind::Invalid;
840 }
841
842 ScriptBindingValueType scriptValueType() const
843 {
844 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
845 return script->valueType;
846 // warn
847 return ScriptBindingValueType::ScriptValue_Unknown;
848 }
849
850 QString objectTypeName() const
851 {
852 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
853 return object->typeName;
854 // warn
855 return {};
856 }
857 QSharedPointer<const QQmlJSScope> objectType() const
858 {
859 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
860 return object->value.lock();
861 // warn
862 return {};
863 }
864
865 QString interceptorTypeName() const
866 {
867 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
868 return interceptor->typeName;
869 // warn
870 return {};
871 }
872 QSharedPointer<const QQmlJSScope> interceptorType() const
873 {
874 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
875 return interceptor->value.lock();
876 // warn
877 return {};
878 }
879
880 QString valueSourceTypeName() const
881 {
882 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
883 return valueSource->typeName;
884 // warn
885 return {};
886 }
887 QSharedPointer<const QQmlJSScope> valueSourceType() const
888 {
889 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
890 return valueSource->value.lock();
891 // warn
892 return {};
893 }
894
895 QSharedPointer<const QQmlJSScope> groupType() const
896 {
897 if (auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
898 return group->groupScope.lock();
899 // warn
900 return {};
901 }
902
903 QSharedPointer<const QQmlJSScope> attachedType() const
904 {
905 if (auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
906 return attached->value.lock();
907 // warn
908 return {};
909 }
910
911 bool hasLiteral() const
912 {
913 // TODO: Assumption: if the type is literal, we must have one
914 return isLiteralBinding();
915 }
916 bool hasObject() const { return bindingType() == BindingType::Object; }
917 bool hasInterceptor() const
918 {
919 return bindingType() == BindingType::Interceptor;
920 }
921 bool hasValueSource() const
922 {
923 return bindingType() == BindingType::ValueSource;
924 }
925
926 friend bool operator==(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
927 {
928 return a.m_propertyName == b.m_propertyName
929 && a.m_bindingContent == b.m_bindingContent
930 && a.m_sourceLocation == b.m_sourceLocation;
931 }
932
933 friend bool operator!=(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
934 {
935 return !(a == b);
936 }
937
938 friend size_t qHash(const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
939 {
940 // we don't need to care about the actual binding content when hashing
941 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
942 binding.bindingType());
943 }
944};
945
946struct Q_QMLCOMPILER_EXPORT QQmlJSMetaSignalHandler
947{
948 QStringList signalParameters;
949 bool isMultiline;
950};
951
952QT_END_NAMESPACE
953
954#endif // QQMLJSMETATYPES_P_H
QString typeName() const
void setIsFlag(bool isFlag)
void setLineNumber(int lineNumber)
friend bool operator!=(const QQmlJSMetaEnum &a, const QQmlJSMetaEnum &b)
void setName(const QString &name)
QQmlJSMetaEnum()=default
int lineNumber() const
friend size_t qHash(const QQmlJSMetaEnum &e, size_t seed=0)
friend bool operator==(const QQmlJSMetaEnum &a, const QQmlJSMetaEnum &b)
void setTypeName(const QString &typeName)
bool hasKey(const QString &key) const
void setIsScoped(bool v)
void setType(const QSharedPointer< const QQmlJSScope > &type)
QSharedPointer< const QQmlJSScope > type() const
int value(const QString &key) const
bool isQml() const
void setIsQml(bool v)
void addValue(int value)
bool isScoped() const
QList< int > values() const
bool isFlag() const
QString alias() const
QStringList keys() const
bool isValid() const
void addKey(const QString &key)
void setAlias(const QString &alias)
QString name() const
QQmlJSMetaEnum(QString name)
bool hasValues() const
QQmlJSMetaReturnType returnValue() const
QQmlJSMetaMethod()=default
void setReturnType(QWeakPointer< const QQmlJSScope > type)
void setSourceLocation(QQmlJS::SourceLocation location)
QQmlJS::SourceLocation sourceLocation() const
QString methodName() const
QQmlJSMetaMethodType MethodType
void setMethodName(const QString &name)
void setReturnTypeName(const QString &typeName)
QString returnTypeName() const
QQmlJSMetaMethod(QString name, QString returnType=QString())
QList< QQmlJSMetaParameter > parameters() const
void setReturnValue(const QQmlJSMetaReturnType returnValue)
QSharedPointer< const QQmlJSScope > returnType() const
void setIsPointer(bool isPointer)
void setType(QWeakPointer< const QQmlJSScope > type)
void setIsList(bool isList)
friend bool operator!=(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b)
friend size_t qHash(const QQmlJSMetaParameter &e, size_t seed=0)
void setName(const QString &name)
void setTypeName(const QString &typeName)
void setTypeQualifier(Constness typeQualifier)
Constness typeQualifier() const
QString typeName() const
QQmlJSMetaParameter(QString name=QString(), QString typeName=QString(), Constness typeQualifier=NonConst, QWeakPointer< const QQmlJSScope > type={})
friend bool operator==(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b)
QSharedPointer< const QQmlJSScope > type() const
\inmodule QtQmlCompiler
friend bool operator!=(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
QString notify() const
QSharedPointer< const QQmlJSScope > aliasTargetScope() const
void setType(const QDeferredSharedPointer< const QQmlJSScope > &type)
QString aliasExpression() const
friend bool operator==(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
void setIsOverride(bool isOverride)
void setPropertyName(const QString &propertyName)
QString aliasTargetName() const
void setAnnotations(const QList< QQmlJSAnnotation > &annotation)
void setIsList(bool isList)
QString bindable() const
void setPrivateClass(const QString &privateClass)
void setRead(const QString &read)
friend size_t qHash(const QQmlJSMetaProperty &prop, size_t seed=0)
void setBindable(const QString &bindable)
void setWrite(const QString &write)
void setIsPropertyConstant(bool isPropertyConstant)
QString reset() const
void setRevision(int revision)
void setIsFinal(bool isFinal)
QDeferredSharedPointer< const QQmlJSScope > type() const
QString typeName() const
void setAliasTargetScope(const QSharedPointer< const QQmlJSScope > &scope)
void setSourceLocation(const QQmlJS::SourceLocation &newSourceLocation)
QString write() const
void setIsTypeConstant(bool isTypeConstant)
const QList< QQmlJSAnnotation > & annotations() const
QQmlJS::SourceLocation sourceLocation() const
void setTypeName(const QString &typeName)
QQmlJSMetaProperty()=default
void setReset(const QString &reset)
QString privateClass() const
void setIsVirtual(bool isVirtual)
void setIsWritable(bool isWritable)
void setAliasExpression(const QString &aliasString)
void setAliasTargetName(const QString &name)
void setIndex(int index)
void setNotify(const QString &notify)
bool isPropertyConstant() const
bool isTypeConstant() const
QString propertyName() const
void setIsPointer(bool isPointer)
\inmodule QtQmlCompiler
MethodType
Definition qqmlsa.h:49
AccessSemantics
Definition qqmlsa.h:50
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)
#define REJECT
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)
QQmlSA::MethodType QQmlJSMetaMethodType
QQmlJSMetaParameter QQmlJSMetaReturnType
ScriptBindingValueType
@ ScriptValue_Function
@ ScriptValue_Unknown
@ ScriptValue_Undefined