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