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
519class Q_QMLCOMPILER_EXPORT QQmlJSMetaPropertyBinding
520{
521 using BindingType = QQmlSA::BindingType;
522 using ScriptBindingKind = QQmlSA::ScriptBindingKind;
523
524 // needs to be kept in sync with the BindingType enum
525 struct Content {
526 using Invalid = std::monostate;
527 struct BoolLiteral {
528 bool value;
529 friend bool operator==(BoolLiteral a, BoolLiteral b) { return a.value == b.value; }
530 friend bool operator!=(BoolLiteral a, BoolLiteral b) { return !(a == b); }
531 };
532 struct NumberLiteral {
533 QT_WARNING_PUSH
534 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
535 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
536 friend bool operator==(NumberLiteral a, NumberLiteral b) { return a.value == b.value; }
537 friend bool operator!=(NumberLiteral a, NumberLiteral b) { return !(a == b); }
538 QT_WARNING_POP
539
540 double value; // ### TODO: int?
541 };
542 struct StringLiteral {
543 friend bool operator==(StringLiteral a, StringLiteral b) { return a.value == b.value; }
544 friend bool operator!=(StringLiteral a, StringLiteral b) { return !(a == b); }
545 QString value;
546 };
547 struct RegexpLiteral {
548 friend bool operator==(RegexpLiteral a, RegexpLiteral b) { return a.value == b.value; }
549 friend bool operator!=(RegexpLiteral a, RegexpLiteral b) { return !(a == b); }
550 QString value;
551 };
552 struct Null {
553 friend bool operator==(Null , Null ) { return true; }
554 friend bool operator!=(Null a, Null b) { return !(a == b); }
555 };
556 struct TranslationString {
557 friend bool operator==(TranslationString a, TranslationString b)
558 {
559 return a.text == b.text && a.comment == b.comment && a.number == b.number && a.context == b.context;
560 }
561 friend bool operator!=(TranslationString a, TranslationString b) { return !(a == b); }
562 QString text;
563 QString comment;
564 QString context;
565 int number;
566 };
567 struct TranslationById {
568 friend bool operator==(TranslationById a, TranslationById b)
569 {
570 return a.id == b.id && a.number == b.number;
571 }
572 friend bool operator!=(TranslationById a, TranslationById b) { return !(a == b); }
573 QString id;
574 int number;
575 };
576 struct Script {
577 friend bool operator==(Script a, Script b)
578 {
579 return a.index == b.index && a.kind == b.kind;
580 }
581 friend bool operator!=(Script a, Script b) { return !(a == b); }
582 QQmlJSMetaMethod::RelativeFunctionIndex index =
583 QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
584 ScriptBindingKind kind = ScriptBindingKind::Invalid;
585 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown;
586 };
587 struct Object {
588 friend bool operator==(Object a, Object b) { return a.value.owner_equal(b.value) && a.typeName == b.typeName; }
589 friend bool operator!=(Object a, Object b) { return !(a == b); }
590 QString typeName;
591 QWeakPointer<const QQmlJSScope> value;
592 };
593 struct Interceptor {
594 friend bool operator==(Interceptor a, Interceptor b)
595 {
596 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
597 }
598 friend bool operator!=(Interceptor a, Interceptor b) { return !(a == b); }
599 QString typeName;
600 QWeakPointer<const QQmlJSScope> value;
601 };
602 struct ValueSource {
603 friend bool operator==(ValueSource a, ValueSource b)
604 {
605 return a.value.owner_equal(b.value) && a.typeName == b.typeName;
606 }
607 friend bool operator!=(ValueSource a, ValueSource b) { return !(a == b); }
608 QString typeName;
609 QWeakPointer<const QQmlJSScope> value;
610 };
611 struct AttachedProperty {
612 /*
613 AttachedProperty binding is a grouping for a series of bindings
614 belonging to the same scope(QQmlJSScope::AttachedPropertyScope).
615 Thus, the attached property binding itself only exposes the
616 attaching type object. Such object is unique per the enclosing
617 scope, so attaching types attached to different QML scopes are
618 different (think of them as objects in C++ terms).
619
620 An attaching type object, being a QQmlJSScope, has bindings
621 itself. For instance:
622 ```
623 Type {
624 Keys.enabled: true
625 }
626 ```
627 tells us that "Type" has an AttachedProperty binding with
628 property name "Keys". The attaching object of that binding
629 (binding.attachedType()) has type "Keys" and a BoolLiteral
630 binding with property name "enabled".
631 */
632 friend bool operator==(AttachedProperty a, AttachedProperty b)
633 {
634 return a.value.owner_equal(b.value);
635 }
636 friend bool operator!=(AttachedProperty a, AttachedProperty b) { return !(a == b); }
637 QWeakPointer<const QQmlJSScope> value;
638 };
639 struct GroupProperty {
640 /* Given a group property declaration like
641 anchors.left: root.left
642 the QQmlJSMetaPropertyBinding will have name "anchors", and a m_bindingContent
643 of type GroupProperty, with groupScope pointing to the scope introudced by anchors
644 In that scope, there will be another QQmlJSMetaPropertyBinding, with name "left" and
645 m_bindingContent Script (for root.left).
646 There should never be more than one GroupProperty for the same name in the same
647 scope, though: If the scope also contains anchors.top: root.top that should reuse the
648 GroupProperty content (and add a top: root.top binding in it). There might however
649 still be an additional object or script binding ( anchors: {left: foo, right: bar };
650 anchors: root.someFunction() ) or another binding to the property in a "derived"
651 type.
652
653 ### TODO: Obtaining the effective binding result requires some resolving function
654 */
655 QWeakPointer<const QQmlJSScope> groupScope;
656 friend bool operator==(GroupProperty a, GroupProperty b) { return a.groupScope.owner_equal(b.groupScope); }
657 friend bool operator!=(GroupProperty a, GroupProperty b) { return !(a == b); }
658 };
659 using type = std::variant<Invalid, BoolLiteral, NumberLiteral, StringLiteral,
660 RegexpLiteral, Null, TranslationString,
661 TranslationById, Script, Object, Interceptor,
662 ValueSource, AttachedProperty, GroupProperty
663 >;
664 };
665 using BindingContent = Content::type;
666
667 QQmlJS::SourceLocation m_sourceLocation;
668 QString m_propertyName; // TODO: this is a debug-only information
669 BindingContent m_bindingContent;
670
671 void ensureSetBindingTypeOnce()
672 {
673 Q_ASSERT(bindingType() == BindingType::Invalid);
674 }
675
676 bool isLiteralBinding() const { return isLiteralBinding(bindingType()); }
677
678
679public:
680 static bool isLiteralBinding(BindingType type)
681 {
682 return type == BindingType::BoolLiteral || type == BindingType::NumberLiteral
683 || type == BindingType::StringLiteral || type == BindingType::RegExpLiteral
684 || type == BindingType::Null; // special. we record it as literal
685 }
686
687 QQmlJSMetaPropertyBinding();
688 QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location) : m_sourceLocation(location) { }
689 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location, const QString &propName)
690 : m_sourceLocation(location), m_propertyName(propName)
691 {
692 }
693 explicit QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation location,
694 const QQmlJSMetaProperty &prop)
695 : QQmlJSMetaPropertyBinding(location, prop.propertyName())
696 {
697 }
698
699 void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
700 QString propertyName() const { return m_propertyName; }
701
702 const QQmlJS::SourceLocation &sourceLocation() const { return m_sourceLocation; }
703
704 BindingType bindingType() const { return BindingType(m_bindingContent.index()); }
705
706 bool isValid() const;
707
708 void setStringLiteral(QAnyStringView value)
709 {
710 ensureSetBindingTypeOnce();
711 m_bindingContent = Content::StringLiteral { value.toString() };
712 }
713
714 void
715 setScriptBinding(QQmlJSMetaMethod::RelativeFunctionIndex value, ScriptBindingKind kind,
716 ScriptBindingValueType valueType = ScriptBindingValueType::ScriptValue_Unknown)
717 {
718 ensureSetBindingTypeOnce();
719 m_bindingContent = Content::Script { value, kind, valueType };
720 }
721
722 void setGroupBinding(const QSharedPointer<const QQmlJSScope> &groupScope)
723 {
724 ensureSetBindingTypeOnce();
725 m_bindingContent = Content::GroupProperty { groupScope };
726 }
727
728 void setAttachedBinding(const QSharedPointer<const QQmlJSScope> &attachingScope)
729 {
730 ensureSetBindingTypeOnce();
731 m_bindingContent = Content::AttachedProperty { attachingScope };
732 }
733
734 void setBoolLiteral(bool value)
735 {
736 ensureSetBindingTypeOnce();
737 m_bindingContent = Content::BoolLiteral { value };
738 }
739
740 void setNullLiteral()
741 {
742 ensureSetBindingTypeOnce();
743 m_bindingContent = Content::Null {};
744 }
745
746 void setNumberLiteral(double value)
747 {
748 ensureSetBindingTypeOnce();
749 m_bindingContent = Content::NumberLiteral { value };
750 }
751
752 void setRegexpLiteral(QAnyStringView value)
753 {
754 ensureSetBindingTypeOnce();
755 m_bindingContent = Content::RegexpLiteral { value.toString() };
756 }
757
758 void setTranslation(QStringView text, QStringView comment, QStringView context, int number)
759 {
760 ensureSetBindingTypeOnce();
761 m_bindingContent =
762 Content::TranslationString{ text.toString(), comment.toString(), context.toString(), number };
763 }
764
765 void setTranslationId(QStringView id, int number)
766 {
767 ensureSetBindingTypeOnce();
768 m_bindingContent = Content::TranslationById{ id.toString(), number };
769 }
770
771 void setObject(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
772 {
773 ensureSetBindingTypeOnce();
774 m_bindingContent = Content::Object { typeName, type };
775 }
776
777 void setInterceptor(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
778 {
779 ensureSetBindingTypeOnce();
780 m_bindingContent = Content::Interceptor { typeName, type };
781 }
782
783 void setValueSource(const QString &typeName, const QSharedPointer<const QQmlJSScope> &type)
784 {
785 ensureSetBindingTypeOnce();
786 m_bindingContent = Content::ValueSource { typeName, type };
787 }
788
789 // ### TODO: here and below: Introduce an allowConversion parameter, if yes, enable conversions e.g. bool -> number?
790 bool boolValue() const;
791
792 double numberValue() const;
793
794 QString stringValue() const;
795
796 QString regExpValue() const;
797
798 QQmlTranslation translationDataValue(QString qmlFileNameForContext = QString()) const;
799
800 QSharedPointer<const QQmlJSScope> literalType(const QQmlJSTypeResolver *resolver) const;
801
802 QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex() const
803 {
804 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
805 return script->index;
806 // warn
807 return QQmlJSMetaMethod::RelativeFunctionIndex::Invalid;
808 }
809
810 ScriptBindingKind scriptKind() const
811 {
812 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
813 return script->kind;
814 // warn
815 return ScriptBindingKind::Invalid;
816 }
817
818 ScriptBindingValueType scriptValueType() const
819 {
820 if (auto *script = std::get_if<Content::Script>(&m_bindingContent))
821 return script->valueType;
822 // warn
823 return ScriptBindingValueType::ScriptValue_Unknown;
824 }
825
826 QString objectTypeName() const
827 {
828 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
829 return object->typeName;
830 // warn
831 return {};
832 }
833 QSharedPointer<const QQmlJSScope> objectType() const
834 {
835 if (auto *object = std::get_if<Content::Object>(&m_bindingContent))
836 return object->value.lock();
837 // warn
838 return {};
839 }
840
841 QString interceptorTypeName() const
842 {
843 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
844 return interceptor->typeName;
845 // warn
846 return {};
847 }
848 QSharedPointer<const QQmlJSScope> interceptorType() const
849 {
850 if (auto *interceptor = std::get_if<Content::Interceptor>(&m_bindingContent))
851 return interceptor->value.lock();
852 // warn
853 return {};
854 }
855
856 QString valueSourceTypeName() const
857 {
858 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
859 return valueSource->typeName;
860 // warn
861 return {};
862 }
863 QSharedPointer<const QQmlJSScope> valueSourceType() const
864 {
865 if (auto *valueSource = std::get_if<Content::ValueSource>(&m_bindingContent))
866 return valueSource->value.lock();
867 // warn
868 return {};
869 }
870
871 QSharedPointer<const QQmlJSScope> groupType() const
872 {
873 if (auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
874 return group->groupScope.lock();
875 // warn
876 return {};
877 }
878
879 QSharedPointer<const QQmlJSScope> attachedType() const
880 {
881 if (auto *attached = std::get_if<Content::AttachedProperty>(&m_bindingContent))
882 return attached->value.lock();
883 // warn
884 return {};
885 }
886
887 bool hasLiteral() const
888 {
889 // TODO: Assumption: if the type is literal, we must have one
890 return isLiteralBinding();
891 }
892 bool hasObject() const { return bindingType() == BindingType::Object; }
893 bool hasInterceptor() const
894 {
895 return bindingType() == BindingType::Interceptor;
896 }
897 bool hasValueSource() const
898 {
899 return bindingType() == BindingType::ValueSource;
900 }
901
902 friend bool operator==(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
903 {
904 return a.m_propertyName == b.m_propertyName
905 && a.m_bindingContent == b.m_bindingContent
906 && a.m_sourceLocation == b.m_sourceLocation;
907 }
908
909 friend bool operator!=(const QQmlJSMetaPropertyBinding &a, const QQmlJSMetaPropertyBinding &b)
910 {
911 return !(a == b);
912 }
913
914 friend size_t qHash(const QQmlJSMetaPropertyBinding &binding, size_t seed = 0)
915 {
916 // we don't need to care about the actual binding content when hashing
917 return qHashMulti(seed, binding.m_propertyName, binding.m_sourceLocation,
918 binding.bindingType());
919 }
920};
921
922struct Q_QMLCOMPILER_EXPORT QQmlJSMetaSignalHandler
923{
924 QStringList signalParameters;
925 bool isMultiline;
926};
927
928QT_END_NAMESPACE
929
930#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 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
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