Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmljsscope_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
4#ifndef QQMLJSSCOPE_P_H
5#define QQMLJSSCOPE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include <private/qtqmlcompilerexports_p.h>
18
19#include "qqmljsmetatypes_p.h"
20#include "qdeferredpointer_p.h"
21#include "qqmljsannotation_p.h"
22#include "qqmlsaconstants.h"
23#include "qqmlsa_p.h"
24
25#include <QtQml/private/qqmljssourcelocation_p.h>
26
27#include <QtCore/qfileinfo.h>
28#include <QtCore/qhash.h>
29#include <QtCore/qset.h>
30#include <QtCore/qstring.h>
31#include <QtCore/qversionnumber.h>
32#include "qqmlsaconstants.h"
33
34#include <optional>
35
37
38class QQmlJSImporter;
39
40namespace QQmlJS {
41
43{
44public:
47 using iterator_category = std::forward_iterator_tag;
48 using difference_type = std::ptrdiff_t;
52
53 ConstPtrWrapperIterator(QList<Ptr>::const_iterator iterator) : m_iterator(iterator) { }
54
56 {
57 return a.m_iterator == b.m_iterator;
58 }
60 {
61 return a.m_iterator != b.m_iterator;
62 }
63
65 {
66 if (!m_pointer)
67 m_pointer = *m_iterator;
68 return m_pointer;
69 }
71 {
72 if (!m_pointer)
73 m_pointer = *m_iterator;
74 return &m_pointer;
75 }
76
78 {
79 m_iterator++;
80 m_pointer = {};
81 return *this;
82 }
84 {
85 auto before = *this;
86 ++(*this);
87 return before;
88 }
89
90private:
92 ConstPtr m_pointer;
93};
94
95} // namespace QQmlJS
96
97class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSScope
98{
99 friend QQmlSA::Element;
100
101public:
102 explicit QQmlJSScope(const QString &internalName);
105
110
113
115 using RootDocumentNameType = std::monostate; // an empty type that has std::hash
120 std::variant<InlineComponentNameType, RootDocumentNameType>;
121
122 enum Flag {
123 Creatable = 0x1,
124 Composite = 0x2,
126 Script = 0x8,
127 CustomParser = 0x10,
128 Array = 0x20,
129 InlineComponent = 0x40,
130 WrappedInImplicitComponent = 0x80,
131 HasBaseTypeError = 0x100,
132 HasExtensionNamespace = 0x200,
133 IsListProperty = 0x400,
134 Structured = 0x800,
135 };
138
139 class Import
140 {
141 public:
142 Import() = default;
143 Import(QString prefix, QString name, QTypeRevision version, bool isFile, bool isDependency);
144
145 bool isValid() const;
146
147 QString prefix() const { return m_prefix; }
148 QString name() const { return m_name; }
149 QTypeRevision version() const { return m_version; }
150 bool isFile() const { return m_isFile; }
151 bool isDependency() const { return m_isDependency; }
152
153 private:
154 QString m_prefix;
155 QString m_name;
156 QTypeRevision m_version;
157 bool m_isFile = false;
158 bool m_isDependency = false;
159
160 friend inline size_t qHash(const Import &key, size_t seed = 0) noexcept
161 {
162 return qHashMulti(seed, key.m_prefix, key.m_name, key.m_version,
163 key.m_isFile, key.m_isDependency);
164 }
165
166 friend inline bool operator==(const Import &a, const Import &b)
167 {
168 return a.m_prefix == b.m_prefix && a.m_name == b.m_name && a.m_version == b.m_version
169 && a.m_isFile == b.m_isFile && a.m_isDependency == b.m_isDependency;
170 }
171 };
172
173 class Export {
174 public:
175 Export() = default;
176 Export(QString package, QString type, QTypeRevision version, QTypeRevision revision);
177
178 bool isValid() const;
179
180 QString package() const { return m_package; }
181 QString type() const { return m_type; }
182 QTypeRevision version() const { return m_version; }
183 QTypeRevision revision() const { return m_revision; }
184
185 private:
186 QString m_package;
187 QString m_type;
188 QTypeRevision m_version;
189 QTypeRevision m_revision;
190 };
191
192 template<typename Pointer>
194 Pointer scope;
196 };
197
198 template<typename Pointer>
200 Pointer scope;
202 };
203
209 {
210 enum CompileContext { INTERNAL, QML };
211
215 const QQmlJSScope::ConstPtr &arrayType)
216 : m_types(types)
217 , m_context(context)
218 , m_arrayType(arrayType)
219 {}
220
221 CompileContext context() const { return m_context; }
222 ConstPtr arrayType() const { return m_arrayType; }
223
224 bool hasType(const QString &name) const { return m_types.contains(name); }
225 ImportedScope<ConstPtr> type(const QString &name) const { return m_types[name]; }
227 {
228 m_types.insert(name, type);
229 }
230 void clearType(const QString &name)
231 {
232 m_types[name].scope = QQmlJSScope::ConstPtr();
233 }
234
235 bool isNullType(const QString &name) const
236 {
237 const auto it = m_types.constFind(name);
238 return it != m_types.constEnd() && it->scope.isNull();
239 }
240
242 {
243 Q_ASSERT(types.m_context == m_context);
244 m_types.insert(std::move(types.m_types));
245 }
246
248 {
249 Q_ASSERT(types.m_context == m_context);
250 m_types.insert(types.m_types);
251 }
252
253 const QHash<QString, ImportedScope<ConstPtr>> &types() const { return m_types; }
254
255 void clearTypes() { m_types.clear(); }
256
257 private:
259 CompileContext m_context;
260
261 // For resolving enums
262 QQmlJSScope::ConstPtr m_intType;
263
264 // For resolving sequence types
265 QQmlJSScope::ConstPtr m_arrayType;
266 };
267
269 {
270 enum Kind {
274 Injected
275 };
276
277 Kind kind = FunctionScoped;
279 std::optional<QString> typeName;
280 bool isConst = false;
282 };
283
285 SimplePropertyTarget, // e.g. `property int p: 42`
286 ListPropertyTarget, // e.g. `property list<Item> pList: [ Text {} ]`
287 UnnamedPropertyTarget // default property bindings, where property name is unspecified
288 };
289
292 {
294 }
295 static QQmlJSScope::Ptr clone(const QQmlJSScope::ConstPtr &origin);
296 static QQmlJSScope::ConstPtr findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope);
297
299 {
300 return m_parentScope.toStrongRef();
301 }
302
304 {
306#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU < 1400 && Q_CC_GNU >= 1200
307 QT_WARNING_DISABLE_GCC("-Wuse-after-free")
308#endif
309 return QQmlJSScope::WeakConstPtr(m_parentScope).toStrongRef();
311 }
312
313 static void reparent(const QQmlJSScope::Ptr &parentScope, const QQmlJSScope::Ptr &childScope);
314
315 void insertJSIdentifier(const QString &name, const JavaScriptIdentifier &identifier);
316
317 // inserts property as qml identifier as well as the corresponding
318 void insertPropertyIdentifier(const QQmlJSMetaProperty &prop);
319
320 bool isIdInCurrentScope(const QString &id) const;
321
322 ScopeType scopeType() const { return m_scopeType; }
323 void setScopeType(ScopeType type) { m_scopeType = type; }
324
325 void addOwnMethod(const QQmlJSMetaMethod &method) { m_methods.insert(method.methodName(), method); }
327 QList<QQmlJSMetaMethod> ownMethods(const QString &name) const { return m_methods.values(name); }
328 bool hasOwnMethod(const QString &name) const { return m_methods.contains(name); }
329
330 bool hasMethod(const QString &name) const;
334
335 void addOwnEnumeration(const QQmlJSMetaEnum &enumeration) { m_enumerations.insert(enumeration.name(), enumeration); }
336 QHash<QString, QQmlJSMetaEnum> ownEnumerations() const { return m_enumerations; }
337 QQmlJSMetaEnum ownEnumeration(const QString &name) const { return m_enumerations.value(name); }
338 bool hasOwnEnumeration(const QString &name) const { return m_enumerations.contains(name); }
339
340 bool hasEnumeration(const QString &name) const;
341 bool hasEnumerationKey(const QString &name) const;
342 QQmlJSMetaEnum enumeration(const QString &name) const;
343 QHash<QString, QQmlJSMetaEnum> enumerations() const;
344
345 void setAnnotations(const QList<QQmlJSAnnotation> &annotation) { m_annotations = std::move(annotation); }
346 const QList<QQmlJSAnnotation> &annotations() const { return m_annotations; }
347
348 QString filePath() const { return m_filePath; }
349 void setFilePath(const QString &file) { m_filePath = file; }
350
351 // The name the type uses to refer to itself. Either C++ class name or base name of
352 // QML file. isComposite tells us if this is a C++ or a QML name.
353 QString internalName() const { return m_internalName; }
354 void setInternalName(const QString &internalName) { m_internalName = internalName; }
356 {
357 using namespace Qt::StringLiterals;
358
359 switch (m_semantics) {
360 case AccessSemantics::Reference:
361 return m_internalName + " *"_L1;
362 case AccessSemantics::Value:
363 case AccessSemantics::Sequence:
364 break;
365 case AccessSemantics::None:
366 // If we got a namespace, it might still be a regular type, exposed as namespace.
367 // We may need to travel the inheritance chain all the way up to QObject to
368 // figure this out, since all other types may be exposed the same way.
369 for (QQmlJSScope::ConstPtr base = baseType(); base; base = base->baseType()) {
370 switch (base->accessSemantics()) {
371 case AccessSemantics::Reference:
372 return m_internalName + " *"_L1;
373 case AccessSemantics::Value:
374 case AccessSemantics::Sequence:
375 return m_internalName;
376 case AccessSemantics::None:
377 break;
378 }
379 }
380 break;
381 }
382 return m_internalName;
383 }
384
385 // This returns a more user readable version of internalName / baseTypeName
386 static QString prettyName(QAnyStringView name);
387
388 static bool causesImplicitComponentWrapping(const QQmlJSMetaProperty &property,
389 const QQmlJSScope::ConstPtr &assignedType);
390 bool isComponentRootElement() const;
391
392 void setInterfaceNames(const QStringList& interfaces) { m_interfaceNames = interfaces; }
393 QStringList interfaceNames() const { return m_interfaceNames; }
394
395 bool hasInterface(const QString &name) const;
396 bool hasOwnInterface(const QString &name) const { return m_interfaceNames.contains(name); }
397
398 void setOwnDeferredNames(const QStringList &names) { m_ownDeferredNames = names; }
399 QStringList ownDeferredNames() const { return m_ownDeferredNames; }
400 void setOwnImmediateNames(const QStringList &names) { m_ownImmediateNames = names; }
401 QStringList ownImmediateNames() const { return m_ownImmediateNames; }
402
403 bool isNameDeferred(const QString &name) const;
404
405 // If isComposite(), this is the QML/JS name of the prototype. Otherwise it's the
406 // relevant base class (in the hierarchy starting from QObject) of a C++ type.
407 void setBaseTypeName(const QString &baseTypeName);
408 QString baseTypeName() const;
409
410 QQmlJSScope::ConstPtr baseType() const { return m_baseType.scope; }
411 QTypeRevision baseTypeRevision() const { return m_baseType.revision; }
412
413 QString qualifiedName() const { return m_qualifiedName; }
414 void setQualifiedName(const QString &qualifiedName) { m_qualifiedName = qualifiedName; };
415 static QString qualifiedNameFrom(const QString &moduleName, const QString &typeName,
416 const QTypeRevision &firstRevision,
417 const QTypeRevision &lastRevision);
418 QString moduleName() const { return m_moduleName; }
419 void setModuleName(const QString &moduleName) { m_moduleName = moduleName; }
420
421 void clearBaseType() { m_baseType = {}; }
422 void setBaseTypeError(const QString &baseTypeError);
423 QString baseTypeError() const;
424
425 void addOwnProperty(const QQmlJSMetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); }
426 QHash<QString, QQmlJSMetaProperty> ownProperties() const { return m_properties; }
427 QQmlJSMetaProperty ownProperty(const QString &name) const { return m_properties.value(name); }
428 bool hasOwnProperty(const QString &name) const { return m_properties.contains(name); }
429
430 bool hasProperty(const QString &name) const;
433
434 void setPropertyLocallyRequired(const QString &name, bool isRequired);
435 bool isPropertyRequired(const QString &name) const;
436 bool isPropertyLocallyRequired(const QString &name) const;
437
439 const QQmlJSMetaPropertyBinding &binding,
440 BindingTargetSpecifier specifier = BindingTargetSpecifier::SimplePropertyTarget)
441 {
442 Q_ASSERT(binding.sourceLocation().isValid());
443 m_propertyBindings.insert(binding.propertyName(), binding);
444
445 // NB: insert() prepends \a binding to the list of bindings, but we need
446 // append, so rotate
448 QPair<iter, iter> r = m_propertyBindings.equal_range(binding.propertyName());
449 std::rotate(r.first, std::next(r.first), r.second);
450
451 // additionally store bindings in the QmlIR compatible order
452 addOwnPropertyBindingInQmlIROrder(binding, specifier);
453 Q_ASSERT(m_propertyBindings.size() == m_propertyBindingsArray.size());
454 }
456 {
457 return m_propertyBindings;
458 }
462 {
463 return m_propertyBindings.equal_range(name);
464 }
465 QList<QQmlJSMetaPropertyBinding> ownPropertyBindingsInQmlIROrder() const;
467 {
468 return m_propertyBindings.contains(name);
469 }
470
471 bool hasPropertyBindings(const QString &name) const;
472 QList<QQmlJSMetaPropertyBinding> propertyBindings(const QString &name) const;
473
474 struct AnnotatedScope; // defined later
475 static AnnotatedScope ownerOfProperty(const QQmlJSScope::ConstPtr &self, const QString &name);
476
477 bool isResolved() const;
478 bool isFullyResolved() const;
479
480 QString ownDefaultPropertyName() const { return m_defaultPropertyName; }
481 void setOwnDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
482 QString defaultPropertyName() const;
483
484 QString ownParentPropertyName() const { return m_parentPropertyName; }
485 void setOwnParentPropertyName(const QString &name) { m_parentPropertyName = name; }
486 QString parentPropertyName() const;
487
488 QString ownAttachedTypeName() const { return m_attachedTypeName; }
489 void setOwnAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
490 QQmlJSScope::ConstPtr ownAttachedType() const { return m_attachedType; }
491
492 QString attachedTypeName() const;
493 QQmlJSScope::ConstPtr attachedType() const;
494
495 QString extensionTypeName() const { return m_extensionTypeName; }
496 void setExtensionTypeName(const QString &name) { m_extensionTypeName = name; }
501 };
503 {
505 ExtensionKind extensionSpecifier = NotExtension;
506 };
508 {
509 if (!m_extensionType)
510 return { m_extensionType, NotExtension };
511 return { m_extensionType,
512 (m_flags & HasExtensionNamespace) ? ExtensionNamespace : ExtensionType };
513 }
514
515 QString valueTypeName() const { return m_valueTypeName; }
516 void setValueTypeName(const QString &name) { m_valueTypeName = name; }
517 QQmlJSScope::ConstPtr valueType() const { return m_valueType; }
518 QQmlJSScope::ConstPtr listType() const { return m_listType; }
519 QQmlJSScope::Ptr listType() { return m_listType; }
520
522 {
523 m_runtimeFunctionIndices.emplaceBack(index);
524 }
527 {
528 const int i = static_cast<int>(index);
529 Q_ASSERT(i >= 0);
530 Q_ASSERT(i < int(m_runtimeFunctionIndices.size()));
531 return m_runtimeFunctionIndices[i];
532 }
533
534 bool isSingleton() const { return m_flags & Singleton; }
535
536 bool isCreatable() const;
537 bool hasCreatableFlag() const { return m_flags & Creatable; }
538
539 bool isStructured() const;
540 bool hasStructuredFlag() const { return m_flags & Structured; }
541
547 bool isComposite() const { return m_flags & Composite; }
548 bool isScript() const { return m_flags & Script; }
549 bool hasCustomParser() const { return m_flags & CustomParser; }
550 bool isArrayScope() const { return m_flags & Array; }
551 bool isInlineComponent() const { return m_flags & InlineComponent; }
552 bool isWrappedInImplicitComponent() const { return m_flags & WrappedInImplicitComponent; }
553 bool extensionIsNamespace() const { return m_flags & HasExtensionNamespace; }
554 void setIsSingleton(bool v) { m_flags.setFlag(Singleton, v); }
555 void setCreatableFlag(bool v) { m_flags.setFlag(Creatable, v); }
556 void setStructuredFlag(bool v) { m_flags.setFlag(Structured, v); }
557 void setIsComposite(bool v) { m_flags.setFlag(Composite, v); }
558 void setIsScript(bool v) { m_flags.setFlag(Script, v); }
560 {
561 m_flags.setFlag(CustomParser, v);;
562 }
563 void setIsArrayScope(bool v) { m_flags.setFlag(Array, v); }
564 void setIsInlineComponent(bool v) { m_flags.setFlag(InlineComponent, v); }
565 void setIsWrappedInImplicitComponent(bool v) { m_flags.setFlag(WrappedInImplicitComponent, v); }
566 void setExtensionIsNamespace(bool v) { m_flags.setFlag(HasExtensionNamespace, v); }
567
568 bool isListProperty() const { return m_flags.testFlag(IsListProperty); }
569 void setIsListProperty(bool v) { m_flags.setFlag(IsListProperty, v); }
570
571 void setAccessSemantics(AccessSemantics semantics) { m_semantics = semantics; }
572 AccessSemantics accessSemantics() const { return m_semantics; }
573 bool isReferenceType() const { return m_semantics == QQmlJSScope::AccessSemantics::Reference; }
574 bool isValueType() const { return m_semantics == QQmlJSScope::AccessSemantics::Value; }
575
576 bool isIdInCurrentQmlScopes(const QString &id) const;
577 bool isIdInCurrentJSScopes(const QString &id) const;
578 bool isIdInjectedFromSignal(const QString &id) const;
579
580 std::optional<JavaScriptIdentifier> findJSIdentifier(const QString &id) const;
581 std::optional<JavaScriptIdentifier> JSIdentifier(const QString &id) const;
582
583 QQmlJS::ConstPtrWrapperIterator childScopesBegin() const { return m_childScopes.constBegin(); }
584 QQmlJS::ConstPtrWrapperIterator childScopesEnd() const { return m_childScopes.constEnd(); }
585
586 void setInlineComponentName(const QString &inlineComponentName)
587 {
588 Q_ASSERT(isInlineComponent());
589 m_inlineComponentName = inlineComponentName;
590 }
591 std::optional<QString> inlineComponentName() const;
592 InlineComponentOrDocumentRootName enclosingInlineComponentName() const;
593
595 {
596 return m_childScopes;
597 }
598
600 {
602 result.reserve(m_childScopes.size());
603 for (const auto &child : m_childScopes)
604 result.append(child);
605 return result;
606 }
607
608 static QTypeRevision resolveTypes(
609 const Ptr &self, const QQmlJSScope::ContextualTypes &contextualTypes,
610 QSet<QString> *usedTypes = nullptr);
611 static void resolveNonEnumTypes(
612 const QQmlJSScope::Ptr &self, const QQmlJSScope::ContextualTypes &contextualTypes,
613 QSet<QString> *usedTypes = nullptr);
614 static void resolveEnums(
615 const QQmlJSScope::Ptr &self, const QQmlJSScope::ContextualTypes &contextualTypes,
616 QSet<QString> *usedTypes = nullptr);
617 static void resolveList(
618 const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &arrayType);
619 static void resolveGeneralizedGroup(
620 const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &baseType,
621 const QQmlJSScope::ContextualTypes &contextualTypes,
622 QSet<QString> *usedTypes = nullptr);
623
624 void setSourceLocation(const QQmlJS::SourceLocation &sourceLocation)
625 {
626 m_sourceLocation = sourceLocation;
627 }
628
630 {
631 return m_sourceLocation;
632 }
633
635 {
636 for (QQmlJSScope::ConstPtr base = type; base; base = base->baseType()) {
637 if (!base->isComposite())
638 return base;
639 }
640 return {};
641 }
642
644 {
645 for (auto base = scope; base.scope;
646 base = { base.scope->m_baseType.scope, base.scope->m_baseType.revision }) {
647 if (!base.scope->isComposite())
648 return base.revision;
649 }
650 return {};
651 }
652
660 bool isSameType(const QQmlJSScope::ConstPtr &otherScope) const
661 {
662 return this == otherScope.get()
663 || (!this->internalName().isEmpty()
664 && this->internalName() == otherScope->internalName());
665 }
666
668 {
669 for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().get()) {
670 if (scope->isSameType(base))
671 return true;
672 }
673 return false;
674 }
675
685 bool canAssign(const QQmlJSScope::ConstPtr &derived) const;
686
691 bool isInCustomParserParent() const;
692
699 {
702 : propertyName(name), sourceLocationOffset(offset)
703 {
704 }
705 QString propertyName; // bound property name
706 quint32 sourceLocationOffset = 0; // binding's source location offset
707 };
708
718 const ContextualTypes &contextualTypes,
719 QSet<QString> *usedTypes = nullptr);
720
721 static QQmlSA::Element createQQmlSAElement(const ConstPtr &);
722 static QQmlSA::Element createQQmlSAElement(ConstPtr &&);
723 static const QQmlJSScope::ConstPtr &scope(const QQmlSA::Element &);
724 static constexpr qsizetype sizeofQQmlSAElement() { return QQmlSA::Element::sizeofElement; }
725
726private:
727 QQmlJSScope() = default;
728 QQmlJSScope(const QQmlJSScope &) = default;
729 QQmlJSScope &operator=(const QQmlJSScope &) = default;
730 static QTypeRevision resolveType(
731 const QQmlJSScope::Ptr &self, const ContextualTypes &contextualTypes,
732 QSet<QString> *usedTypes);
733 static void updateChildScope(
734 const QQmlJSScope::Ptr &childScope, const QQmlJSScope::Ptr &self,
735 const QQmlJSScope::ContextualTypes &contextualTypes, QSet<QString> *usedTypes);
736
737 void addOwnPropertyBindingInQmlIROrder(const QQmlJSMetaPropertyBinding &binding,
738 BindingTargetSpecifier specifier);
739
741
745
746 // a special QmlIR compatibility bindings array, ordered the same way as
747 // bindings in QmlIR::Object
748 QList<QmlIRCompatibilityBindingData> m_propertyBindingsArray;
749
750 // same as QmlIR::Object::runtimeFunctionIndices
751 QList<QQmlJSMetaMethod::AbsoluteFunctionIndex> m_runtimeFunctionIndices;
752
753 QHash<QString, QQmlJSMetaEnum> m_enumerations;
754
755 QVector<QQmlJSAnnotation> m_annotations;
756 QVector<QQmlJSScope::Ptr> m_childScopes;
757 QQmlJSScope::WeakPtr m_parentScope;
758
759 QString m_filePath;
760 QString m_internalName;
761 QString m_baseTypeNameOrError;
762
763 // We only need the revision for the base type as inheritance is
764 // the only relation between two types where the revisions matter.
765 ImportedScope<QQmlJSScope::WeakConstPtr> m_baseType;
766
767 ScopeType m_scopeType = ScopeType::QMLScope;
768 QStringList m_interfaceNames;
769 QStringList m_ownDeferredNames;
770 QStringList m_ownImmediateNames;
771
772 QString m_defaultPropertyName;
773 QString m_parentPropertyName;
778 QString m_attachedTypeName;
779 QStringList m_requiredPropertyNames;
780 QQmlJSScope::WeakConstPtr m_attachedType;
781
786 QString m_valueTypeName;
787 QQmlJSScope::WeakConstPtr m_valueType;
788 QQmlJSScope::Ptr m_listType;
789
797 QString m_extensionTypeName;
798 QQmlJSScope::WeakConstPtr m_extensionType;
799
800 Flags m_flags = Creatable; // all types are marked as creatable by default.
801 AccessSemantics m_semantics = AccessSemantics::Reference;
802
803 QQmlJS::SourceLocation m_sourceLocation;
804
805 QString m_qualifiedName;
806 QString m_moduleName;
807
808 std::optional<QString> m_inlineComponentName;
809};
811
812template<>
813class Q_QMLCOMPILER_PRIVATE_EXPORT QDeferredFactory<QQmlJSScope>
814{
815public:
816 QDeferredFactory() = default;
817
818 QDeferredFactory(QQmlJSImporter *importer, const QString &filePath) :
819 m_filePath(filePath), m_importer(importer)
820 {}
821
822 bool isValid() const
823 {
824 return !m_filePath.isEmpty() && m_importer != nullptr;
825 }
826
828 {
829 return QFileInfo(m_filePath).baseName();
830 }
831
832 void setIsSingleton(bool isSingleton)
833 {
834 m_isSingleton = isSingleton;
835 }
836
837 void setQualifiedName(const QString &qualifiedName) { m_qualifiedName = qualifiedName; }
838 void setModuleName(const QString &moduleName) { m_moduleName = moduleName; }
839
840private:
842 friend class QDeferredSharedPointer<const QQmlJSScope>;
843 friend class QDeferredWeakPointer<QQmlJSScope>;
844 friend class QDeferredWeakPointer<const QQmlJSScope>;
845
846 // Should only be called when lazy-loading the type in a deferred pointer.
847 void populate(const QSharedPointer<QQmlJSScope> &scope) const;
848
849 QString m_filePath;
850 QQmlJSImporter *m_importer = nullptr;
851 bool m_isSingleton = false;
852 QString m_qualifiedName;
853 QString m_moduleName;
854};
855
858
860
861#endif // QQMLJSSCOPE_P_H
static JNINativeMethod methods[]
\inmodule QtCore
QDeferredFactory(QQmlJSImporter *importer, const QString &filePath)
void setIsSingleton(bool isSingleton)
void setQualifiedName(const QString &qualifiedName)
QSharedPointer< T > toStrongRef() const
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString baseName() const
Returns the base name of the file without the path.
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
\inmodule QtCore
Definition qhash.h:1748
\inmodule QtCore
Definition qhash.h:1696
\inmodule QtCore
Definition qhash.h:1348
int value(const QString &key) const
QString name() const
const QQmlJS::SourceLocation & sourceLocation() const
QString propertyName() const
QString type() const
QTypeRevision revision() const
QString package() const
QTypeRevision version() const
QString name() const
friend bool operator==(const Import &a, const Import &b)
bool isDependency() const
QString prefix() const
friend size_t qHash(const Import &key, size_t seed=0) noexcept
QTypeRevision version() const
Tracks the types for the QmlCompiler.
void setIsInlineComponent(bool v)
QQmlJSMetaProperty ownProperty(const QString &name) const
bool isComposite() const
void setIsComposite(bool v)
bool isWrappedInImplicitComponent() const
QPair< QMultiHash< QString, QQmlJSMetaPropertyBinding >::const_iterator, QMultiHash< QString, QQmlJSMetaPropertyBinding >::const_iterator > ownPropertyBindings(const QString &name) const
bool hasOwnPropertyBindings(const QString &name) const
void setOwnDeferredNames(const QStringList &names)
bool isScript() const
void clearBaseType()
void setIsScript(bool v)
void setExtensionTypeName(const QString &name)
void setAnnotations(const QList< QQmlJSAnnotation > &annotation)
void setInterfaceNames(const QStringList &interfaces)
QQmlJSScope & operator=(QQmlJSScope &&)=default
static QQmlJSScope::Ptr create()
QString filePath() const
QString extensionTypeName() const
bool isSameType(const QQmlJSScope::ConstPtr &otherScope) const
void setStructuredFlag(bool v)
const QList< QQmlJSAnnotation > & annotations() const
void setAccessSemantics(AccessSemantics semantics)
void setModuleName(const QString &moduleName)
std::monostate RootDocumentNameType
QQmlJSMetaEnum ownEnumeration(const QString &name) const
void setOwnParentPropertyName(const QString &name)
QQmlJSScope::Ptr listType()
QQmlJS::ConstPtrWrapperIterator childScopesEnd() const
QQmlJS::ConstPtrWrapperIterator childScopesBegin() const
QHash< QString, QQmlJSMetaEnum > ownEnumerations() const
bool isSingleton() const
QQmlJSScope::Ptr parentScope()
void setOwnAttachedTypeName(const QString &name)
AnnotatedScope extensionType() const
ScopeType scopeType() const
bool hasStructuredFlag() const
void setInternalName(const QString &internalName)
QDeferredWeakPointer< const QQmlJSScope > WeakConstPtr
QString internalName() const
bool hasCreatableFlag() const
void setHasCustomParser(bool v)
void setIsSingleton(bool v)
QList< QQmlJSMetaMethod > ownMethods(const QString &name) const
void setScopeType(ScopeType type)
bool isReferenceType() const
static QQmlJSScope::ConstPtr nonCompositeBaseType(const QQmlJSScope::ConstPtr &type)
void addOwnProperty(const QQmlJSMetaProperty &prop)
QQmlJSMetaMethod::AbsoluteFunctionIndex ownRuntimeFunctionIndex(QQmlJSMetaMethod::RelativeFunctionIndex index) const
QString moduleName() const
bool isInlineComponent() const
AccessSemantics accessSemantics() const
void setExtensionIsNamespace(bool v)
void setIsArrayScope(bool v)
QVector< QQmlJSScope::Ptr > childScopes()
QString ownDefaultPropertyName() const
bool hasCustomParser() const
QString qualifiedName() const
bool isListProperty() const
QStringList ownDeferredNames() const
void setQualifiedName(const QString &qualifiedName)
void setSourceLocation(const QQmlJS::SourceLocation &sourceLocation)
QQmlJSScope(QQmlJSScope &&)=default
void addOwnPropertyBinding(const QQmlJSMetaPropertyBinding &binding, BindingTargetSpecifier specifier=BindingTargetSpecifier::SimplePropertyTarget)
QQmlJSScope::ConstPtr listType() const
static QTypeRevision nonCompositeBaseRevision(const ImportedScope< QQmlJSScope::ConstPtr > &scope)
void setInlineComponentName(const QString &inlineComponentName)
QStringList ownImmediateNames() const
void setValueTypeName(const QString &name)
void setOwnImmediateNames(const QStringList &names)
QString augmentedInternalName() const
bool inherits(const QQmlJSScope::ConstPtr &base) const
QString valueTypeName() const
void addOwnEnumeration(const QQmlJSMetaEnum &enumeration)
bool isArrayScope() const
QStringList interfaceNames() const
QDeferredSharedPointer< const QQmlJSScope > ConstPtr
std::variant< InlineComponentNameType, RootDocumentNameType > InlineComponentOrDocumentRootName
A Hashable type to differentiate document roots from different inline components.
bool hasOwnEnumeration(const QString &name) const
void setIsWrappedInImplicitComponent(bool v)
bool hasOwnProperty(const QString &name) const
bool hasOwnInterface(const QString &name) const
bool isValueType() const
QQmlJSScope::ConstPtr baseType() const
bool extensionIsNamespace() const
void addOwnMethod(const QQmlJSMetaMethod &method)
static QQmlJSScope::Ptr create(const QString &internalName)
QString ownParentPropertyName() const
QQmlJSScope::ConstPtr parentScope() const
void setCreatableFlag(bool v)
static constexpr qsizetype sizeofQQmlSAElement()
QHash< QString, QQmlJSMetaProperty > ownProperties() const
void addOwnRuntimeFunctionIndex(QQmlJSMetaMethod::AbsoluteFunctionIndex index)
void setOwnDefaultPropertyName(const QString &name)
QVector< QQmlJSScope::ConstPtr > childScopes() const
QQmlJSScope::ConstPtr ownAttachedType() const
QMultiHash< QString, QQmlJSMetaPropertyBinding > ownPropertyBindings() const
void setIsListProperty(bool v)
QQmlJS::SourceLocation sourceLocation() const
void setFilePath(const QString &file)
QMultiHash< QString, QQmlJSMetaMethod > ownMethods() const
QTypeRevision baseTypeRevision() const
QQmlJSScope::ConstPtr valueType() const
bool hasOwnMethod(const QString &name) const
QString ownAttachedTypeName() const
ConstPtrWrapperIterator(QList< Ptr >::const_iterator iterator)
QDeferredSharedPointer< const QQmlJSScope > ConstPtr
friend bool operator==(const ConstPtrWrapperIterator &a, const ConstPtrWrapperIterator &b)
ConstPtrWrapperIterator & operator++()
friend bool operator!=(const ConstPtrWrapperIterator &a, const ConstPtrWrapperIterator &b)
std::forward_iterator_tag iterator_category
ConstPtrWrapperIterator operator++(int)
\inmodule QtQmlCompiler
Definition qqmlsa.h:197
Definition qset.h:18
const_iterator constEnd() const noexcept
Definition qset.h:143
const_iterator constFind(const T &value) const
Definition qset.h:161
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
\inmodule QtCore
QSet< QString >::iterator it
MethodType
Definition qqmlsa.h:55
AccessSemantics
Definition qqmlsa_p.h:40
Combined button and popup list for selecting options.
static void * context
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_PUSH
std::pair< T1, T2 > QPair
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
static QDBusError::ErrorType get(const char *name)
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
Flags
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
const char * typeName
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLsizei GLenum GLenum * types
GLenum type
GLenum GLuint GLintptr offset
GLuint name
GLuint GLuint * names
GLuint64EXT * result
[6]
static QString internalName(const QQmlJSScope::ConstPtr &scope)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_FLAGS(x)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned int quint32
Definition qtypes.h:45
ptrdiff_t qsizetype
Definition qtypes.h:70
const char property[13]
Definition qwizard.cpp:101
QFile file
[0]
QExplicitlySharedDataPointer< Derived > derived(base)
QLayoutItem * child
[0]
QQmlJSScope::ConstPtr scope
ContextualTypes(CompileContext context, const QHash< QString, ImportedScope< ConstPtr > > types, const QQmlJSScope::ConstPtr &arrayType)
const QHash< QString, ImportedScope< ConstPtr > > & types() const
bool hasType(const QString &name) const
void addTypes(const ContextualTypes &types)
void addTypes(ContextualTypes &&types)
void clearType(const QString &name)
void setType(const QString &name, const ImportedScope< ConstPtr > &type)
ImportedScope< ConstPtr > type(const QString &name) const
bool isNullType(const QString &name) const
CompileContext context() const
QList< QQmlJSScope::Export > exports
std::optional< QString > typeName
QQmlJS::SourceLocation location
QmlIRCompatibilityBindingData(const QString &name, quint32 offset)