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