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