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 QDeferredWeakPointer<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 QDeferredSharedPointer<const QQmlJSScope> type() const { return m_type.toStrongRef(); }
161 void setType(QDeferredWeakPointer<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 QDeferredWeakPointer<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 QDeferredSharedPointer<const QQmlJSScope> returnType() const { return m_returnType.type(); }
239 void setReturnType(QDeferredWeakPointer<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
344
345 friend bool operator!=(const QQmlJSMetaMethod &a, const QQmlJSMetaMethod &b)
346 {
347 return !(a == b);
348 }
349
372
373private:
375
376 QQmlJS::SourceLocation m_sourceLocation;
377
378 QQmlJSMetaReturnType m_returnType;
379 QList<QQmlJSMetaParameter> m_parameters;
380 QList<QQmlJSAnnotation> m_annotations;
381
382 MethodType m_methodType = MethodType::Signal;
383 Access m_methodAccess = Public;
384 int m_revision = 0;
385 // The index of the method on the type's metaobject
387 // The index of the compiled function within the owning scope's function table
389 bool m_isCloned = false;
390 bool m_isConstructor = false;
391 bool m_isJavaScriptFunction = false;
392 bool m_isImplicitQmlPropertyChangeSignal = false;
393 bool m_isConst = false;
394};
395
397{
398 QString m_propertyName;
399 QString m_typeName;
400 QString m_read;
401 QString m_write;
402 QString m_reset;
403 QString m_bindable;
404 QString m_notify;
405 QString m_privateClass;
406 QString m_aliasExpr;
407 QString m_aliasTargetName;
408 QWeakPointer<const QQmlJSScope> m_aliasTargetScope;
409 QDeferredWeakPointer<const QQmlJSScope> m_type;
410 QQmlJS::SourceLocation m_sourceLocation;
411 QList<QQmlJSAnnotation> m_annotations;
412 bool m_isList = false;
413 bool m_isWritable = false;
414 bool m_isPointer = false;
415 bool m_isTypeConstant = false;
416 bool m_isFinal = false;
417 bool m_isVirtual = false;
418 bool m_isOverride = false;
419 bool m_isPropertyConstant = false;
420 int m_revision = 0;
421 int m_index = -1; // relative property index within owning QQmlJSScope
422
423public:
425
426 void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
427 QString propertyName() const { return m_propertyName; }
428
429 void setTypeName(const QString &typeName) { m_typeName = typeName; }
430 QString typeName() const { return m_typeName; }
431
432 void setRead(const QString &read) { m_read = read; }
433 QString read() const { return m_read; }
434
435 void setWrite(const QString &write) { m_write = write; }
436 QString write() const { return m_write; }
437
438 void setReset(const QString &reset) { m_reset = reset; }
439 QString reset() const { return m_reset; }
440
441 void setBindable(const QString &bindable) { m_bindable = bindable; }
442 QString bindable() const { return m_bindable; }
443
444 void setNotify(const QString &notify) { m_notify = notify; }
445 QString notify() const { return m_notify; }
446
447 void setPrivateClass(const QString &privateClass) { m_privateClass = privateClass; }
448 QString privateClass() const { return m_privateClass; }
449 bool isPrivate() const { return !m_privateClass.isEmpty(); } // exists for convenience
450
451 void setType(const QDeferredSharedPointer<const QQmlJSScope> &type) { m_type = type; }
452 QDeferredSharedPointer<const QQmlJSScope> type() const { return m_type; }
453
454 void setSourceLocation(const QQmlJS::SourceLocation &newSourceLocation)
455 { m_sourceLocation = newSourceLocation; }
456 QQmlJS::SourceLocation sourceLocation() const { return m_sourceLocation; }
457
458 void setAnnotations(const QList<QQmlJSAnnotation> &annotation) { m_annotations = annotation; }
459 const QList<QQmlJSAnnotation> &annotations() const { return m_annotations; }
460
461 void setIsList(bool isList) { m_isList = isList; }
462 bool isList() const { return m_isList; }
463
464 void setIsWritable(bool isWritable) { m_isWritable = isWritable; }
465 bool isWritable() const { return m_isWritable; }
466
467 void setIsPointer(bool isPointer) { m_isPointer = isPointer; }
468 bool isPointer() const { return m_isPointer; }
469
470 void setIsTypeConstant(bool isTypeConstant) { m_isTypeConstant = isTypeConstant; }
471 bool isTypeConstant() const { return m_isTypeConstant; }
472
473 void setAliasExpression(const QString &aliasString) { m_aliasExpr = aliasString; }
474 QString aliasExpression() const { return m_aliasExpr; }
475 bool isAlias() const { return !m_aliasExpr.isEmpty(); } // exists for convenience
476
477 void setAliasTargetName(const QString &name) { m_aliasTargetName = name; }
478 QString aliasTargetName() const { return m_aliasTargetName; }
479
480 void setAliasTargetScope(const QSharedPointer<const QQmlJSScope> &scope)
481 {
482 m_aliasTargetScope = scope;
483 }
485 {
486 return m_aliasTargetScope.toStrongRef();
487 }
488
489 void setIsFinal(bool isFinal) { m_isFinal = isFinal; }
490 bool isFinal() const { return m_isFinal; }
491
492 void setIsOverride(bool isOverride) { m_isOverride = isOverride; }
493 bool isOverride() const { return m_isOverride; }
494
495 void setIsVirtual(bool isVirtual) { m_isVirtual = isVirtual; }
496 bool isVirtual() const { return m_isVirtual; }
497
498 void setIsPropertyConstant(bool isPropertyConstant) { m_isPropertyConstant = isPropertyConstant; }
499 bool isPropertyConstant() const { return m_isPropertyConstant; }
500
501 void setRevision(int revision) { m_revision = revision; }
502 int revision() const { return m_revision; }
503
504 void setIndex(int index) { m_index = index; }
505 int index() const { return m_index; }
506
507 bool isValid() const { return !m_propertyName.isEmpty(); }
508
509 friend bool operator==(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
510 {
511 return a.m_index == b.m_index && a.m_propertyName == b.m_propertyName
512 && a.m_typeName == b.m_typeName && a.m_bindable == b.m_bindable
513 && a.m_type == b.m_type && a.m_isList == b.m_isList
514 && a.m_isWritable == b.m_isWritable && a.m_isPointer == b.m_isPointer
515 && a.m_aliasExpr == b.m_aliasExpr && a.m_revision == b.m_revision
516 && a.m_isFinal == b.m_isFinal;
517 }
518
519 friend bool operator!=(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
520 {
521 return !(a == b);
522 }
523
524 friend size_t qHash(const QQmlJSMetaProperty &prop, size_t seed = 0)
525 {
526 return qHashMulti(seed, prop.m_propertyName, prop.m_typeName, prop.m_bindable,
527 prop.m_type.owner_hash(), prop.m_isList, prop.m_isWritable,
528 prop.m_isPointer, prop.m_aliasExpr, prop.m_revision, prop.m_isFinal,
529 prop.m_index);
530 }
531};
532
533class Q_QMLCOMPILER_EXPORT QQmlJSMetaPropertyBinding
534{
535 using BindingType = QQmlSA::BindingType;
536 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
537
538 // needs to be kept in sync with the BindingType enum
539 struct Content {
540 using Invalid = std::monostate;
541 struct BoolLiteral {
542 bool value;
543 friend bool operator==(BoolLiteral a, BoolLiteral b) { return a.value == b.value; }
544 friend bool operator!=(BoolLiteral a, BoolLiteral b) { return !(a == b); }
545 };
546 struct NumberLiteral {
547 QT_WARNING_PUSH
548 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
549 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
550 friend bool operator==(NumberLiteral a, NumberLiteral b) { return a.value == b.value; }
551 friend bool operator!=(NumberLiteral a, NumberLiteral b) { return !(a == b); }
552 QT_WARNING_POP
553
554 double value; // ### TODO: int?
555 };
556 struct StringLiteral {
557 friend bool operator==(StringLiteral a, StringLiteral b) { return a.value == b.value; }
558 friend bool operator!=(StringLiteral a, StringLiteral b) { return !(a == b); }
559 QString value;
560 };
561 struct RegexpLiteral {
562 friend bool operator==(RegexpLiteral a, RegexpLiteral b) { return a.value == b.value; }
563 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) { return !(a == b); }
564 QString value;
565 };
566 struct Null {
567 friend bool operator==(Null , Null ) { return true; }
568 friend bool operator!=(Null a, Null b) { return !(a == b); }
569 };
570 struct TranslationString {
571 friend bool operator==(TranslationString a, TranslationString b)
572 {
573 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
574 }
575 friend bool operator!=(TranslationString a, TranslationString b) { return !(a == b); }
576 QString text;
577 QString comment;
578 QString context;
579 int number;
580 };
581 struct TranslationById {
582 friend bool operator==(TranslationById a, TranslationById b)
583 {
584 return a.id == b.id && a.number == b.number;
585 }
586 friend bool operator!=(TranslationById a, TranslationById b) { return !(a == b); }
587 QString id;
588 int number;
589 };
590 struct Script {
591 friend bool operator==(Script a, Script b)
592 {
593 return a.index == b.index && a.kind == b.kind;
594 }
595 friend bool operator!=(Script a, Script b) { return !(a == b); }
596 QQmlJSMetaMethod::RelativeFunctionIndex index =
597 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
598 ScriptBindingKind kind = ScriptBindingKind::Invalid;
599 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
600 };
601 struct Object {
602 friend bool operator==(Object a, Object b) { return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
603 friend bool operator!=(Object a, Object b) { return !(a == b); }
604 QString typeName;
605 QWeakPointer<const QQmlJSScope> value;
606 };
607 struct Interceptor {
608 friend bool operator==(Interceptor a, Interceptor b)
609 {
610 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
611 }
612 friend bool operator!=(Interceptor a, Interceptor b) { return !(a == b); }
613 QString typeName;
614 QWeakPointer<const QQmlJSScope> value;
615 };
616 struct ValueSource {
617 friend bool operator==(ValueSource a, ValueSource b)
618 {
619 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
620 }
621 friend bool operator!=(ValueSource a, ValueSource b) { return !(a == b); }
622 QString typeName;
623 QWeakPointer<const QQmlJSScope> value;
624 };
625 struct AttachedProperty {
626 /*
627 AttachedProperty binding is a grouping for a series of bindings
628 belonging to the same scope(QQmlJSScope::AttachedPropertyScope).
629 Thus, the attached property binding itself only exposes the
630 attaching type object. Such object is unique per the enclosing
631 scope, so attaching types attached to different QML scopes are
632 different (think of them as objects in C++ terms).
633
634 An attaching type object, being a QQmlJSScope, has bindings
635 itself. For instance:
636 ```
637 Type {
638 Keys.enabled: true
639 }
640 ```
641 tells us that "Type" has an AttachedProperty binding with
642 property name "Keys". The attaching object of that binding
643 (binding.attachedType()) has type "Keys" and a BoolLiteral
644 binding with property name "enabled".
645 */
646 friend bool operator==(AttachedProperty a, AttachedProperty b)
647 {
648 return a.value.owner_equal(b.value);
649 }
650 friend bool operator!=(AttachedProperty a, AttachedProperty b) { return !(a == b); }
651 QWeakPointer<const QQmlJSScope> value;
652 };
653 struct GroupedProperty {
654 /* Given a grouped property declaration like
655 anchors.left: root.left
656 the QQmlJSMetaPropertyBinding will have name "anchors", and a m_bindingContent
657 of type GroupedProperty, with groupScope pointing to the scope introudced by anchors
658 In that scope, there will be another QQmlJSMetaPropertyBinding, with name "left" and
659 m_bindingContent Script (for root.left).
660 There should never be more than one GroupedProperty for the same name in the same
661 scope, though: If the scope also contains anchors.top: root.top that should reuse the
662 GroupedProperty content (and add a top: root.top binding in it). There might however
663 still be an additional object or script binding ( anchors: {left: foo, right: bar };
664 anchors: root.someFunction() ) or another binding to the property in a "derived"
665 type.
666
667 ### TODO: Obtaining the effective binding result requires some resolving function
668 */
669 QWeakPointer<const QQmlJSScope> groupScope;
670 friend bool operator==(GroupedProperty a, GroupedProperty b) { return a.groupScope.owner_equal(b.groupScope); }
671 friend bool operator!=(GroupedProperty a, GroupedProperty b) { return !(a == b); }
672 };
673 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
674 RegexpLiteral, Null, TranslationString,
675 TranslationById, Script, Object, Interceptor,
676 ValueSource, AttachedProperty, GroupedProperty
677 >;
678 };
679 using BindingContent = Content::type;
680
681 QQmlJS::SourceLocation m_sourceLocation;
682 QString m_propertyName; // TODO: this is a debug-only information
683 BindingContent m_bindingContent;
684
685 void ensureSetBindingTypeOnce()
686 {
687 Q_ASSERT(bindingType() == BindingType::Invalid);
688 }
689
690 bool isLiteralBinding() const { return isLiteralBinding(bindingType()); }
691
692
693public:
694 static bool isLiteralBinding(BindingType type)
695 {
696 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
697 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
698 || type == BindingType::Null; // special. we record it as literal
699 }
700
701 QQmlJSMetaPropertyBinding();
702 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
703 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location, const QString &propName)
704 : m_sourceLocation(location), m_propertyName(propName)
705 {
706 }
707 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
708 const QQmlJSMetaProperty &prop)
709 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
710 {
711 }
712
713 void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
714 QString propertyName() const { return m_propertyName; }
715
716 const QQmlJS::SourceLocation &sourceLocation() const { return m_sourceLocation; }
717
718 BindingType bindingType() const { return BindingType(m_bindingContent.index()); }
719
720 bool isValid() const;
721
722 void setStringLiteral(QAnyStringView value)
723 {
724 ensureSetBindingTypeOnce();
725 m_bindingContent = Content::StringLiteral { value.toString() };
726 }
727
728 void
729 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
730 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
731 {
732 ensureSetBindingTypeOnce();
733 m_bindingContent = Content::Script { value, kind, valueType };
734 }
735
736 void setGroupBinding(const QSharedPointer<const QQmlJSScope> &groupScope)
737 {
738 ensureSetBindingTypeOnce();
739 m_bindingContent = Content::GroupedProperty { groupScope };
740 }
741
742 void setAttachedBinding(const QSharedPointer<const QQmlJSScope> &attachingScope)
743 {
744 ensureSetBindingTypeOnce();
745 m_bindingContent = Content::AttachedProperty { attachingScope };
746 }
747
748 void setBoolLiteral(bool value)
749 {
750 ensureSetBindingTypeOnce();
751 m_bindingContent = Content::BoolLiteral { value };
752 }
753
754 void setNullLiteral()
755 {
756 ensureSetBindingTypeOnce();
757 m_bindingContent = Content::Null {};
758 }
759
760 void setNumberLiteral(double value)
761 {
762 ensureSetBindingTypeOnce();
763 m_bindingContent = Content::NumberLiteral { value };
764 }
765
766 void setRegexpLiteral(QAnyStringView value)
767 {
768 ensureSetBindingTypeOnce();
769 m_bindingContent = Content::RegexpLiteral { value.toString() };
770 }
771
772 void setTranslation(QStringView text, QStringView comment, QStringView context, int number)
773 {
774 ensureSetBindingTypeOnce();
775 m_bindingContent =
776 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
777 }
778
779 void setTranslationId(QStringView id, int number)
780 {
781 ensureSetBindingTypeOnce();
782 m_bindingContent = Content::TranslationById{ id.toString(), number };
783 }
784
785 void setObject(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
786 {
787 ensureSetBindingTypeOnce();
788 m_bindingContent = Content::Object { typeName, type };
789 }
790
791 void setInterceptor(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
792 {
793 ensureSetBindingTypeOnce();
794 m_bindingContent = Content::Interceptor { typeName, type };
795 }
796
797 void setValueSource(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
798 {
799 ensureSetBindingTypeOnce();
800 m_bindingContent = Content::ValueSource { typeName, type };
801 }
802
803 // ### TODO: here and below: Introduce an allowConversion parameter, if yes, enable conversions e.g. bool -> number?
804 bool boolValue() const;
805
806 double numberValue() const;
807
808 QString stringValue() const;
809
810 QString regExpValue() const;
811
812 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString()) const;
813
814 QSharedPointer<const QQmlJSScope> literalType(const QQmlJSTypeResolver *resolver) const;
815
816 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex() const
817 {
818 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
819 return script->index;
820 // warn
821 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
822 }
823
824 ScriptBindingKind scriptKind() const
825 {
826 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
827 return script->kind;
828 // warn
829 return ScriptBindingKind::Invalid;
830 }
831
832 ScriptBindingValueType scriptValueType() const
833 {
834 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
835 return script->valueType;
836 // warn
837 return ScriptBindingValueType::ScriptValue_Unknown;
838 }
839
840 QString objectTypeName() const
841 {
842 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
843 return object->typeName;
844 // warn
845 return {};
846 }
847 QSharedPointer<const QQmlJSScope> objectType() const
848 {
849 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
850 return object->value.lock();
851 // warn
852 return {};
853 }
854
855 QString interceptorTypeName() const
856 {
857 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
858 return interceptor->typeName;
859 // warn
860 return {};
861 }
862 QSharedPointer<const QQmlJSScope> interceptorType() const
863 {
864 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
865 return interceptor->value.lock();
866 // warn
867 return {};
868 }
869
870 QString valueSourceTypeName() const
871 {
872 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
873 return valueSource->typeName;
874 // warn
875 return {};
876 }
877 QSharedPointer<const QQmlJSScope> valueSourceType() const
878 {
879 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
880 return valueSource->value.lock();
881 // warn
882 return {};
883 }
884
885 QSharedPointer<const QQmlJSScope> groupType() const
886 {
887 if (auto *group = std::get_if<Content::GroupedProperty>(&m_bindingContent))
888 return group->groupScope.lock();
889 // warn
890 return {};
891 }
892
893 QSharedPointer<const QQmlJSScope> attachedType() const
894 {
895 if (auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
896 return attached->value.lock();
897 // warn
898 return {};
899 }
900
901 bool hasLiteral() const
902 {
903 // TODO: Assumption: if the type is literal, we must have one
904 return isLiteralBinding();
905 }
906 bool hasObject() const { return bindingType() == BindingType::Object; }
907 bool hasInterceptor() const
908 {
909 return bindingType() == BindingType::Interceptor;
910 }
911 bool hasValueSource() const
912 {
913 return bindingType() == BindingType::ValueSource;
914 }
915
916 friend bool operator==(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
917 {
918 return a.m_propertyName == b.m_propertyName
919 && a.m_bindingContent == b.m_bindingContent
920 && a.m_sourceLocation == b.m_sourceLocation;
921 }
922
923 friend bool operator!=(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
924 {
925 return !(a == b);
926 }
927
928 friend size_t qHash(const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
929 {
930 // we don't need to care about the actual binding content when hashing
931 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
932 binding.bindingType());
933 }
934};
935
936struct Q_QMLCOMPILER_EXPORT QQmlJSMetaSignalHandler
937{
938 QStringList signalParameters;
939 bool isMultiline;
940};
941
942QT_END_NAMESPACE
943
944#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 setSourceLocation(QQmlJS::SourceLocation location)
QQmlJS::SourceLocation sourceLocation() const
QString methodName() const
QQmlJSMetaMethodType MethodType
void setMethodName(const QString &name)
QDeferredSharedPointer< const QQmlJSScope > returnType() const
void setReturnTypeName(const QString &typeName)
void setReturnType(QDeferredWeakPointer< const QQmlJSScope > type)
QString returnTypeName() const
QQmlJSMetaMethod(QString name, QString returnType=QString())
QList< QQmlJSMetaParameter > parameters() const
void setReturnValue(const QQmlJSMetaReturnType returnValue)
void setIsPointer(bool isPointer)
QQmlJSMetaParameter(QString name=QString(), QString typeName=QString(), Constness typeQualifier=NonConst, QDeferredWeakPointer< const QQmlJSScope > type={ })
QDeferredSharedPointer< const QQmlJSScope > type() const
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)
void setType(QDeferredWeakPointer< const QQmlJSScope > type)
Constness typeQualifier() const
QString typeName() const
friend bool operator==(const QQmlJSMetaParameter &a, const QQmlJSMetaParameter &b)
\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