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
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// Qt-Security score:significant
4
5#ifndef QQMLJSSCOPE_P_H
6#define QQMLJSSCOPE_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
24#include "qqmlsa_p.h"
25
26#include <QtQml/private/qqmljssourcelocation_p.h>
27
28#include <QtCore/qfileinfo.h>
29#include <QtCore/qhash.h>
30#include <QtCore/qset.h>
31#include <QtCore/qstring.h>
32#include <QtCore/qversionnumber.h>
34
35#include <optional>
36
37QT_BEGIN_NAMESPACE
38
39class QQmlJSImporter;
40
41namespace QQmlJS {
42
44
45class Export {
46public:
47 Export() = default;
48 Export(QString package, QString type, QTypeRevision version, QTypeRevision revision);
49
50 bool isValid() const;
51
52 QString package() const { return m_package; }
53 QString type() const { return m_type; }
54 QTypeRevision version() const { return m_version; }
55 QTypeRevision revision() const { return m_revision; }
56
57private:
58 QString m_package;
59 QString m_type;
60 QTypeRevision m_version;
61 QTypeRevision m_revision;
62};
63
64template<typename Pointer>
66 Pointer scope;
68};
69
70template<typename Pointer>
75
76struct ContextualTypes;
77
78} // namespace QQmlJS
79
80class Q_QMLCOMPILER_EXPORT QQmlJSScope
81{
82 friend QQmlSA::Element;
83
84public:
85 using Ptr = QDeferredSharedPointer<QQmlJSScope>;
86 using WeakPtr = QDeferredWeakPointer<QQmlJSScope>;
87 using ConstPtr = QDeferredSharedPointer<const QQmlJSScope>;
88 using WeakConstPtr = QDeferredWeakPointer<const QQmlJSScope>;
89
90 using AccessSemantics = QQmlSA::AccessSemantics;
91 using ScopeType = QQmlSA::ScopeType;
92
93 using InlineComponentNameType = QString;
94 using RootDocumentNameType = std::monostate; // an empty type that has std::hash
95 /*!
96 * A Hashable type to differentiate document roots from different inline components.
97 */
98 using InlineComponentOrDocumentRootName =
99 std::variant<InlineComponentNameType, RootDocumentNameType>;
100
101 enum Flag {
102 Creatable = 0x1,
103 Composite = 0x2,
104 JavaScriptBuiltin = 0x4,
105 Singleton = 0x8,
106 Script = 0x10,
107 CustomParser = 0x20,
108 Array = 0x40,
109 InlineComponent = 0x80,
110 WrappedInImplicitComponent = 0x100,
111 HasBaseTypeError = 0x200,
112 ExtensionIsNamespace = 0x400,
113 IsListProperty = 0x800,
114 Structured = 0x1000,
115 ExtensionIsJavaScript = 0x2000,
116 EnforcesScopedEnums = 0x4000,
117 FileRootComponent = 0x8000,
118 AssignedToUnknownProperty = 0x10000,
119 };
120 Q_DECLARE_FLAGS(Flags, Flag)
121 Q_FLAGS(Flags);
122
123 using Export = QQmlJS::Export;
124 template <typename Pointer>
125 using ImportedScope = QQmlJS::ImportedScope<Pointer>;
126 template <typename Pointer>
127 using ExportedScope = QQmlJS::ExportedScope<Pointer>;
128
129 struct JavaScriptIdentifier
130 {
131 enum Kind {
132 Parameter,
133 FunctionScoped,
134 LexicalScoped,
135 Injected
136 };
137
138 Kind kind = FunctionScoped;
139 QQmlJS::SourceLocation location;
140 std::optional<QString> typeName;
141 bool isConst = false;
142 QQmlJSScope::WeakConstPtr scope = {};
143 };
144
145 enum BindingTargetSpecifier {
146 SimplePropertyTarget, // e.g. `property int p: 42`
147 ListPropertyTarget, // e.g. `property list<Item> pList: [ Text {} ]`
148 UnnamedPropertyTarget // default property bindings, where property name is unspecified
149 };
150
151 template <typename Key, typename Value>
152 using QMultiHashRange = std::pair<typename QMultiHash<Key, Value>::iterator,
153 typename QMultiHash<Key, Value>::iterator>;
154
155 static QQmlJSScope::Ptr create() { return QSharedPointer<QQmlJSScope>(new QQmlJSScope); }
156 static QQmlJSScope::Ptr clone(const QQmlJSScope::ConstPtr &origin);
157
158 static void cloneInto(QQmlJSScope::Ptr &origin,
159 const QQmlJSScope::Ptr &target)
160 {
161 *target = std::move(*clone(origin));
162 }
163
164 //! \internal This should probably restricted, only needed in prepareTargetForVisit
165 void resetForReparse() {
166 const QString moduleName = this->moduleName();
167 *this = QQmlJSScope { this->internalName() };
168 setOwnModuleName(moduleName);
169 }
170
171 static QQmlJSScope::ConstPtr findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope);
172
173 QQmlJSScope::Ptr parentScope();
174 QQmlJSScope::ConstPtr parentScope() const;
175 static void reparent(const QQmlJSScope::Ptr &parentScope, const QQmlJSScope::Ptr &childScope);
176
177 void insertJSIdentifier(const QString &name, const JavaScriptIdentifier &identifier);
178 QHash<QString, JavaScriptIdentifier> ownJSIdentifiers() const;
179 void insertPropertyIdentifier(const QQmlJSMetaProperty &prop);
180
181 ScopeType scopeType() const { return m_scopeType; }
182 void setScopeType(ScopeType type) { m_scopeType = type; }
183
184 void addOwnMethod(const QQmlJSMetaMethod &method) { m_methods.insert(method.methodName(), method); }
185 QMultiHashRange<QString, QQmlJSMetaMethod> mutableOwnMethodsRange(const QString &name)
186 {
187 return m_methods.equal_range(name);
188 }
189 QMultiHash<QString, QQmlJSMetaMethod> ownMethods() const { return m_methods; }
190 QList<QQmlJSMetaMethod> ownMethods(const QString &name) const { return m_methods.values(name); }
191 bool hasOwnMethod(const QString &name) const { return m_methods.contains(name); }
192
193 bool hasMethod(const QString &name) const;
194 QHash<QString, QQmlJSMetaMethod> methods() const;
195 QList<QQmlJSMetaMethod> methods(const QString &name) const;
196 QList<QQmlJSMetaMethod> methods(const QString &name, QQmlJSMetaMethodType type) const;
197
198 void addOwnEnumeration(const QQmlJSMetaEnum &enumeration) { m_enumerations.insert(enumeration.name(), enumeration); }
199 QHash<QString, QQmlJSMetaEnum> ownEnumerations() const { return m_enumerations; }
200 QQmlJSMetaEnum ownEnumeration(const QString &name) const { return m_enumerations.value(name); }
201 bool hasOwnEnumeration(const QString &name) const { return m_enumerations.contains(name); }
202
203 bool hasEnumeration(const QString &name) const;
204 bool hasEnumerationKey(const QString &name) const;
205 bool hasOwnEnumerationKey(const QString &name) const;
206 QQmlJSMetaEnum enumeration(const QString &name) const;
207 QHash<QString, QQmlJSMetaEnum> enumerations() const;
208
209 void setAnnotations(const QList<QQmlJSAnnotation> &annotation) { m_annotations = std::move(annotation); }
210 const QList<QQmlJSAnnotation> &annotations() const { return m_annotations; }
211
212 QString filePath() const { return m_filePath; }
213 void setFilePath(const QString &file) { m_filePath = file; }
214
215 quint32 lineNumber() const { return m_sourceLocation.startLine; }
216 void setLineNumber(quint32 lineNumber);
217
218 // The name the type uses to refer to itself. Either C++ class name or base name of
219 // QML file. isComposite tells us if this is a C++ or a QML name.
220 QString internalName() const { return m_internalName; }
221 void setInternalName(const QString &internalName) { m_internalName = internalName; }
222 QString augmentedInternalName() const;
223
224 // This returns a more user readable version of internalName / baseTypeName
225 static QString prettyName(QAnyStringView name);
226
227 enum class IsComponentRoot : quint8 { No = 0, Yes, Maybe };
228 IsComponentRoot componentRootStatus() const;
229
230 void setAliases(const QStringList &aliases) { m_aliases = aliases; }
231 QStringList aliases() const { return m_aliases; }
232
233 void setInterfaceNames(const QStringList& interfaces) { m_interfaceNames = interfaces; }
234 QStringList interfaceNames() const { return m_interfaceNames; }
235
236 bool hasInterface(const QString &name) const;
237 bool hasOwnInterface(const QString &name) const { return m_interfaceNames.contains(name); }
238
239 void setOwnDeferredNames(const QStringList &names) { m_ownDeferredNames = names; }
240 QStringList ownDeferredNames() const { return m_ownDeferredNames; }
241 void setOwnImmediateNames(const QStringList &names) { m_ownImmediateNames = names; }
242 QStringList ownImmediateNames() const { return m_ownImmediateNames; }
243
244 bool isNameDeferred(const QString &name) const;
245
246 // If isComposite(), this is the QML/JS name of the prototype. Otherwise it's the
247 // relevant base class (in the hierarchy starting from QObject) of a C++ type.
248 void setBaseTypeName(const QString &baseTypeName);
249 QString baseTypeName() const;
250
251 QQmlJSScope::ConstPtr baseType() const { return m_baseType.scope; }
252 QTypeRevision baseTypeRevision() const { return m_baseType.revision; }
253
254 QString moduleName() const;
255 QString ownModuleName() const { return m_moduleName; }
256 void setOwnModuleName(const QString &moduleName) { m_moduleName = moduleName; }
257
258 void clearBaseType() { m_baseType = {}; }
259 void setBaseTypeError(const QString &baseTypeError);
260 QString baseTypeError() const;
261
262 void addOwnProperty(const QQmlJSMetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); }
263 QHash<QString, QQmlJSMetaProperty> ownProperties() const { return m_properties; }
264 QQmlJSMetaProperty ownProperty(const QString &name) const { return m_properties.value(name); }
265 bool hasOwnProperty(const QString &name) const { return m_properties.contains(name); }
266
267 bool hasProperty(const QString &name) const;
268 QQmlJSMetaProperty property(const QString &name) const;
269 QHash<QString, QQmlJSMetaProperty> properties() const;
270
271 void setPropertyLocallyRequired(const QString &name, bool isRequired);
272 bool isPropertyRequired(const QString &name) const;
273 bool isPropertyLocallyRequired(const QString &name) const;
274
275 void addOwnPropertyBinding(
276 const QQmlJSMetaPropertyBinding &binding,
277 BindingTargetSpecifier specifier = BindingTargetSpecifier::SimplePropertyTarget);
278 QMultiHash<QString, QQmlJSMetaPropertyBinding> ownPropertyBindings() const;
279 std::pair<QMultiHash<QString, QQmlJSMetaPropertyBinding>::const_iterator,
280 QMultiHash<QString, QQmlJSMetaPropertyBinding>::const_iterator>
281 ownPropertyBindings(const QString &name) const;
282 QList<QQmlJSMetaPropertyBinding> ownPropertyBindingsInQmlIROrder() const;
283 bool hasOwnPropertyBindings(const QString &name) const;
284
285 bool hasPropertyBindings(const QString &name) const;
286 QList<QQmlJSMetaPropertyBinding> propertyBindings(const QString &name) const;
287
288 struct AnnotatedScope; // defined later
289 static AnnotatedScope ownerOfProperty(const QQmlJSScope::ConstPtr &self, const QString &name);
290
291 bool isResolved() const;
292 bool isFullyResolved() const;
293
294 QString ownDefaultPropertyName() const { return m_defaultPropertyName; }
295 void setOwnDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
296 QString defaultPropertyName() const;
297
298 QString ownParentPropertyName() const { return m_parentPropertyName; }
299 void setOwnParentPropertyName(const QString &name) { m_parentPropertyName = name; }
300 QString parentPropertyName() const;
301
302 QString ownAttachedTypeName() const { return m_attachedTypeName; }
303 void setOwnAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
304 QQmlJSScope::ConstPtr ownAttachedType() const { return m_attachedType; }
305
306 QString attachedTypeName() const;
307 QQmlJSScope::ConstPtr attachedType() const;
308
309 QString extensionTypeName() const { return m_extensionTypeName; }
310 void setExtensionTypeName(const QString &name) { m_extensionTypeName = name; }
311 enum ExtensionKind {
312 NotExtension,
313 ExtensionType,
314 ExtensionJavaScript,
315 ExtensionNamespace,
316 };
317 struct AnnotatedScope
318 {
319 QQmlJSScope::ConstPtr scope;
320 ExtensionKind extensionSpecifier = NotExtension;
321 };
322 AnnotatedScope extensionType() const;
323
324 QString elementTypeName() const { return m_elementTypeName; }
325 void setElementTypeName(const QString &name) { m_elementTypeName = name; }
326 QQmlJSScope::ConstPtr elementType() const { return m_elementType; }
327 QQmlJSScope::ConstPtr listType() const { return m_listType; }
328 QQmlJSScope::Ptr listType() { return m_listType; }
329
330 void addOwnRuntimeFunctionIndex(QQmlJSMetaMethod::AbsoluteFunctionIndex index);
331 QQmlJSMetaMethod::AbsoluteFunctionIndex
332 ownRuntimeFunctionIndex(QQmlJSMetaMethod::RelativeFunctionIndex index) const;
333
334
335 /*!
336 * \internal
337 *
338 * Returns true for objects defined from Qml, and false for objects declared from C++.
339 */
340 bool isComposite() const { return m_flags.testFlag(Composite); }
341 void setIsComposite(bool v) { m_flags.setFlag(Composite, v); }
342
343 /*!
344 * \internal
345 *
346 * Returns true for JavaScript types, false for QML and C++ types.
347 */
348 bool isJavaScriptBuiltin() const { return m_flags.testFlag(JavaScriptBuiltin); }
349 void setIsJavaScriptBuiltin(bool v) { m_flags.setFlag(JavaScriptBuiltin, v); }
350
351 bool isScript() const { return m_flags.testFlag(Script); }
352 void setIsScript(bool v) { m_flags.setFlag(Script, v); }
353
354 bool hasCustomParser() const { return m_flags.testFlag(CustomParser); }
355 void setHasCustomParser(bool v) { m_flags.setFlag(CustomParser, v); }
356
357 bool isArrayScope() const { return m_flags.testFlag(Array); }
358 void setIsArrayScope(bool v) { m_flags.setFlag(Array, v); }
359
360 bool isInlineComponent() const { return m_flags.testFlag(InlineComponent); }
361 void setIsInlineComponent(bool v) { m_flags.setFlag(InlineComponent, v); }
362
363 bool isWrappedInImplicitComponent() const { return m_flags.testFlag(WrappedInImplicitComponent); }
364 void setIsWrappedInImplicitComponent(bool v) { m_flags.setFlag(WrappedInImplicitComponent, v); }
365
366 bool isAssignedToUnknownProperty() const { return m_flags.testFlag(AssignedToUnknownProperty); }
367 void setAssignedToUnknownProperty(bool v) { m_flags.setFlag(AssignedToUnknownProperty, v); }
368
369 bool extensionIsJavaScript() const { return m_flags.testFlag(ExtensionIsJavaScript); }
370 void setExtensionIsJavaScript(bool v) { m_flags.setFlag(ExtensionIsJavaScript, v); }
371
372 bool extensionIsNamespace() const { return m_flags.testFlag(ExtensionIsNamespace); }
373 void setExtensionIsNamespace(bool v) { m_flags.setFlag(ExtensionIsNamespace, v); }
374
375 bool isListProperty() const { return m_flags.testFlag(IsListProperty); }
376 void setIsListProperty(bool v) { m_flags.setFlag(IsListProperty, v); }
377
378 bool isSingleton() const { return m_flags.testFlag(Singleton); }
379 void setIsSingleton(bool v) { m_flags.setFlag(Singleton, v); }
380
381 bool enforcesScopedEnums() const;
382 void setEnforcesScopedEnumsFlag(bool v) { m_flags.setFlag(EnforcesScopedEnums, v); }
383
384 bool isCreatable() const;
385 void setCreatableFlag(bool v) { m_flags.setFlag(Creatable, v); }
386
387 bool isStructured() const;
388 void setStructuredFlag(bool v) { m_flags.setFlag(Structured, v); }
389
390 bool isFileRootComponent() const { return m_flags.testFlag(FileRootComponent); }
391 void setIsRootFileComponentFlag(bool v) { m_flags.setFlag(FileRootComponent, v); }
392
393 void setAccessSemantics(AccessSemantics semantics) { m_semantics = semantics; }
394 AccessSemantics accessSemantics() const { return m_semantics; }
395 bool isReferenceType() const { return m_semantics == QQmlJSScope::AccessSemantics::Reference; }
396 bool isValueType() const { return m_semantics == QQmlJSScope::AccessSemantics::Value; }
397
398 std::optional<JavaScriptIdentifier> jsIdentifier(const QString &id) const;
399 std::optional<JavaScriptIdentifier> ownJSIdentifier(const QString &id) const;
400
401 QQmlJS::ChildScopesIterator childScopesBegin() const { return m_childScopes.constBegin(); }
402 QQmlJS::ChildScopesIterator childScopesEnd() const { return m_childScopes.constEnd(); }
403
404 void setInlineComponentName(const QString &inlineComponentName);
405 std::optional<QString> inlineComponentName() const;
406 InlineComponentOrDocumentRootName enclosingInlineComponentName() const;
407
408 QList<QQmlJSScope::Ptr> childScopes();
409
410 QList<QQmlJSScope::ConstPtr> childScopes() const;
411
412 static QTypeRevision resolveTypes(
413 const Ptr &self, const QQmlJS::ContextualTypes &contextualTypes,
414 QSet<QString> *usedTypes = nullptr);
415 static void resolveNonEnumTypes(
416 const QQmlJSScope::Ptr &self, const QQmlJS::ContextualTypes &contextualTypes,
417 QSet<QString> *usedTypes = nullptr);
418 static void resolveEnums(
419 const QQmlJSScope::Ptr &self, const QQmlJS::ContextualTypes &contextualTypes,
420 QSet<QString> *usedTypes = nullptr);
421 static void resolveList(
422 const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &arrayType);
423 static void resolveGroup(
424 const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &baseType,
425 const QQmlJS::ContextualTypes &contextualTypes,
426 QSet<QString> *usedTypes = nullptr);
427
428 void setSourceLocation(const QQmlJS::SourceLocation &sourceLocation);
429 QQmlJS::SourceLocation sourceLocation() const;
430
431 void setIdSourceLocation(const QQmlJS::SourceLocation &sourceLocation);
432 QQmlJS::SourceLocation idSourceLocation() const;
433
434 static QQmlJSScope::ConstPtr nonCompositeBaseType(const QQmlJSScope::ConstPtr &type);
435
436 static QTypeRevision
437 nonCompositeBaseRevision(const ImportedScope<QQmlJSScope::ConstPtr> &scope);
438
439 bool isSameType(const QQmlJSScope::ConstPtr &otherScope) const;
440 bool inherits(const QQmlJSScope::ConstPtr &base) const;
441 bool canAssign(const QQmlJSScope::ConstPtr &derived) const;
442
443 bool isInCustomParserParent() const;
444
445
446 static ImportedScope<QQmlJSScope::ConstPtr> findType(const QString &name,
447 const QQmlJS::ContextualTypes &contextualTypes,
448 QSet<QString> *usedTypes = nullptr);
449
450 static QQmlSA::Element createQQmlSAElement(const ConstPtr &);
451 static QQmlSA::Element createQQmlSAElement(ConstPtr &&);
452 static const QQmlJSScope::ConstPtr &scope(const QQmlSA::Element &);
453 static constexpr qsizetype sizeofQQmlSAElement() { return QQmlSA::Element::sizeofElement; }
454
455private:
456 // the way to construct a QQmlJSScope is via create
457 explicit QQmlJSScope(const QString &internalName);
458 QQmlJSScope(QQmlJSScope &&) = default;
459 QQmlJSScope &operator=(QQmlJSScope &&) = default;
460 /*! \internal
461
462 Minimal information about a QQmlJSMetaPropertyBinding that allows it to
463 be manipulated similarly to QmlIR::Binding.
464 */
465 template <typename T>
466 friend class QTypeInfo; // so that we can Q_DECLARE_TYPEINFO QmlIRCompatibilityBindingData
467 struct QmlIRCompatibilityBindingData
468 {
469 QmlIRCompatibilityBindingData() = default;
470 QmlIRCompatibilityBindingData(const QString &name, quint32 offset)
471 : propertyName(name), sourceLocationOffset(offset)
472 {
473 }
474 QString propertyName; // bound property name
475 quint32 sourceLocationOffset = 0; // binding's source location offset
476 };
477
478 QQmlJSScope() = default;
479 QQmlJSScope(const QQmlJSScope &) = default;
480 QQmlJSScope &operator=(const QQmlJSScope &) = default;
481 static QTypeRevision resolveType(
482 const QQmlJSScope::Ptr &self, const QQmlJS::ContextualTypes &contextualTypes,
483 QSet<QString> *usedTypes);
484 static void updateChildScope(
485 const QQmlJSScope::Ptr &childScope, const QQmlJSScope::Ptr &self,
486 const QQmlJS::ContextualTypes &contextualTypes, QSet<QString> *usedTypes);
487
488 void addOwnPropertyBindingInQmlIROrder(const QQmlJSMetaPropertyBinding &binding,
489 BindingTargetSpecifier specifier);
490 bool hasEnforcesScopedEnumsFlag() const { return m_flags & EnforcesScopedEnums; }
491 bool hasCreatableFlag() const { return m_flags & Creatable; }
492 bool hasStructuredFlag() const { return m_flags & Structured; }
493
494 QHash<QString, JavaScriptIdentifier> m_jsIdentifiers;
495
496 QMultiHash<QString, QQmlJSMetaMethod> m_methods;
497 QHash<QString, QQmlJSMetaProperty> m_properties;
498 QMultiHash<QString, QQmlJSMetaPropertyBinding> m_propertyBindings;
499
500 // a special QmlIR compatibility bindings array, ordered the same way as
501 // bindings in QmlIR::Object
502 QList<QmlIRCompatibilityBindingData> m_propertyBindingsArray;
503
504 // same as QmlIR::Object::runtimeFunctionIndices
505 QList<QQmlJSMetaMethod::AbsoluteFunctionIndex> m_runtimeFunctionIndices;
506
507 QHash<QString, QQmlJSMetaEnum> m_enumerations;
508
509 QList<QQmlJSAnnotation> m_annotations;
510 QList<QQmlJSScope::Ptr> m_childScopes;
511 QQmlJSScope::WeakPtr m_parentScope;
512
513 QString m_filePath;
514 QString m_internalName;
515 QString m_baseTypeNameOrError;
516
517 // We only need the revision for the base type as inheritance is
518 // the only relation between two types where the revisions matter.
519 ImportedScope<QQmlJSScope::WeakConstPtr> m_baseType;
520
521 ScopeType m_scopeType = ScopeType::QMLScope;
522 QStringList m_aliases;
523 QStringList m_interfaceNames;
524 QStringList m_ownDeferredNames;
525 QStringList m_ownImmediateNames;
526
527 QString m_defaultPropertyName;
528 QString m_parentPropertyName;
529 /*! \internal
530 * The attached type name.
531 * This is an internal name, from a c++ type or a synthetic jsrootgen.
532 */
533 QString m_attachedTypeName;
534 QStringList m_requiredPropertyNames;
535 QQmlJSScope::WeakConstPtr m_attachedType;
536
537 /*! \internal
538 * The type name of the list element in case this is a sequence type.
539 * This is an internal name, from a c++ type or a synthetic jsrootgen.
540 */
541 QString m_elementTypeName;
542 QQmlJSScope::WeakConstPtr m_elementType;
543 QQmlJSScope::Ptr m_listType;
544
545 /*!
546 The extension is provided as either a type (QML_{NAMESPACE_}EXTENDED) or as a
547 namespace (QML_EXTENDED_NAMESPACE).
548 The bool HasExtensionNamespace helps differentiating both cases, as namespaces
549 have a more limited lookup capaility.
550 This is an internal name, from a c++ type or a synthetic jsrootgen.
551 */
552 QString m_extensionTypeName;
553 QQmlJSScope::WeakConstPtr m_extensionType;
554
555 Flags m_flags = Creatable; // all types are marked as creatable by default.
556 AccessSemantics m_semantics = AccessSemantics::Reference;
557
558 QQmlJS::SourceLocation m_sourceLocation;
559 QQmlJS::SourceLocation m_idSourceLocation;
560
561 QString m_moduleName;
562
563 std::optional<QString> m_inlineComponentName;
564};
565
566inline QQmlJSScope::Ptr QQmlJSScope::parentScope()
567{
568 return m_parentScope.toStrongRef();
569}
570
571inline QQmlJSScope::ConstPtr QQmlJSScope::parentScope() const
572{
573 QT_WARNING_PUSH
574#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU < 1400 && Q_CC_GNU >= 1200
575 QT_WARNING_DISABLE_GCC("-Wuse-after-free")
576#endif
577 return QQmlJSScope::WeakConstPtr(m_parentScope).toStrongRef();
578 QT_WARNING_POP
579}
580
581inline QMultiHash<QString, QQmlJSMetaPropertyBinding> QQmlJSScope::ownPropertyBindings() const
582{
583 return m_propertyBindings;
584}
585
586inline std::pair<QMultiHash<QString, QQmlJSMetaPropertyBinding>::const_iterator, QMultiHash<QString, QQmlJSMetaPropertyBinding>::const_iterator> QQmlJSScope::ownPropertyBindings(const QString &name) const
587{
588 return m_propertyBindings.equal_range(name);
589}
590
591inline bool QQmlJSScope::hasOwnPropertyBindings(const QString &name) const
592{
593 return m_propertyBindings.contains(name);
594}
595
596inline QQmlJSMetaMethod::AbsoluteFunctionIndex QQmlJSScope::ownRuntimeFunctionIndex(QQmlJSMetaMethod::RelativeFunctionIndex index) const
597{
598 const int i = static_cast<int>(index);
599 Q_ASSERT(i >= 0);
600 Q_ASSERT(i < int(m_runtimeFunctionIndices.size()));
601 return m_runtimeFunctionIndices[i];
602}
603
604inline void QQmlJSScope::setInlineComponentName(const QString &inlineComponentName)
605{
606 Q_ASSERT(isInlineComponent());
607 m_inlineComponentName = inlineComponentName;
608}
609
610inline QList<QQmlJSScope::Ptr> QQmlJSScope::childScopes()
611{
612 return m_childScopes;
613}
614
615inline void QQmlJSScope::setSourceLocation(const QQmlJS::SourceLocation &sourceLocation)
616{
617 m_sourceLocation = sourceLocation;
618}
619
620inline QQmlJS::SourceLocation QQmlJSScope::sourceLocation() const
621{
622 return m_sourceLocation;
623}
624
625inline void QQmlJSScope::setIdSourceLocation(const QQmlJS::SourceLocation &sourceLocation)
626{
627 Q_ASSERT(m_scopeType == QQmlSA::ScopeType::QMLScope);
628 m_idSourceLocation = sourceLocation;
629}
630
631inline QQmlJS::SourceLocation QQmlJSScope::idSourceLocation() const
632{
633 Q_ASSERT(m_scopeType == QQmlSA::ScopeType::QMLScope);
634 return m_idSourceLocation;
635}
636
637inline QQmlJSScope::ConstPtr QQmlJSScope::nonCompositeBaseType(const ConstPtr &type)
638{
639 for (QQmlJSScope::ConstPtr base = type; base; base = base->baseType()) {
640 if (!base->isComposite())
641 return base;
642 }
643 return {};
644}
645
647
648template<>
649class Q_QMLCOMPILER_EXPORT QDeferredFactory<QQmlJSScope>
650{
651public:
652 using TypeReader = std::function<QList<QQmlJS::DiagnosticMessage>(
653 QQmlJSImporter *importer, const QString &filePath,
654 const QSharedPointer<QQmlJSScope> &scopeToPopulate)>;
655 QDeferredFactory() = default;
656
657 QDeferredFactory(QQmlJSImporter *importer, const QString &filePath,
658 const TypeReader &typeReader = {});
659
660 bool isValid() const
661 {
662 return !m_filePath.isEmpty() && m_importer != nullptr;
663 }
664
665 QString internalName() const
666 {
667 return QFileInfo(m_filePath).baseName();
668 }
669
670 QString filePath() const { return m_filePath; }
671
672 QQmlJSImporter* importer() const { return m_importer; }
673
674 void setIsSingleton(bool isSingleton)
675 {
676 m_isSingleton = isSingleton;
677 }
678
679 void setModuleName(const QString &moduleName) { m_moduleName = moduleName; }
680
681private:
682 friend class QDeferredSharedPointer<QQmlJSScope>;
683 friend class QDeferredSharedPointer<const QQmlJSScope>;
684 friend class QDeferredWeakPointer<QQmlJSScope>;
685 friend class QDeferredWeakPointer<const QQmlJSScope>;
686
687 // Should only be called when lazy-loading the type in a deferred pointer.
688 void populate(const QSharedPointer<QQmlJSScope> &scope) const;
689
690 QString m_filePath;
691 QQmlJSImporter *m_importer = nullptr;
692 bool m_isSingleton = false;
693 QString m_moduleName;
694 TypeReader m_typeReader;
695};
696
697using QQmlJSExportedScope = QQmlJSScope::ExportedScope<QQmlJSScope::Ptr>;
698using QQmlJSImportedScope = QQmlJSScope::ImportedScope<QQmlJSScope::ConstPtr>;
699
700namespace QQmlSA {
701constexpr inline bool isFunctionScope(ScopeType type)
702{
703 switch (type) {
707 return true;
708 default:
709 return false;
710 }
711}
712
713}
714
715QT_END_NAMESPACE
716
717#endif // QQMLJSSCOPE_P_H
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:801
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
Definition qbytearray.h:812
QString fileName() const
If the currently assigned device is a QFile, or if setFileName() has been called, this function retur...
void setFileName(const QString &fileName)
Sets the file name of QImageReader to fileName.
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual bool isValid() const
virtual QString location() const
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)
QQmlJSRegisterContent createMethod(const QList< QQmlJSMetaMethod > &methods, const QQmlJSScope::ConstPtr &methodType, ContentVariant variant, QQmlJSRegisterContent scope)
QQmlJSRegisterContent createImportNamespace(uint importNamespaceStringId, const QQmlJSScope::ConstPtr &importNamespaceType, ContentVariant variant, QQmlJSRegisterContent scope)
QQmlJSRegisterContent createProperty(const QQmlJSMetaProperty &property, int baseLookupIndex, int resultLookupIndex, ContentVariant variant, QQmlJSRegisterContent scope)
void adjustType(QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &adjusted)
void generalizeType(QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &generalized)
void storeType(QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &stored)
QQmlJSRegisterContent castTo(QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &newContainedType)
QQmlJSRegisterContent createEnumeration(const QQmlJSMetaEnum &enumeration, const QString &enumMember, ContentVariant variant, QQmlJSRegisterContent scope)
void setAllocationMode(AllocationMode mode)
QQmlJSRegisterContent storedIn(QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &newStoredType)
QQmlJSRegisterContent clone(QQmlJSRegisterContent from)
QQmlJSRegisterContent createType(const QQmlJSScope::ConstPtr &type, int resultLookupIndex, ContentVariant variant, QQmlJSRegisterContent scope={})
QQmlJSRegisterContent createConversion(const QList< QQmlJSRegisterContent > &origins, const QQmlJSScope::ConstPtr &conversion, QQmlJSRegisterContent conversionScope, ContentVariant variant, QQmlJSRegisterContent scope)
QQmlJSRegisterContent createMethodCall(const QQmlJSMetaMethod &method, const QQmlJSScope::ConstPtr &returnType, QQmlJSRegisterContent scope)
Tracks the types for the QmlCompiler.
QTypeRevision revision() const
QString type() const
QTypeRevision version() const
bool isValid() const
QString package() const
Export()=default
Export(QString package, QString type, QTypeRevision version, QTypeRevision revision)
virtual QQmlSourceLocation sourceLocation() const
\inmodule QtQmlCompiler
Definition qqmlsa.h:52
Element attachedType() const
Returns the attached type if the content type of this binding is AttachedProperty,...
Definition qqmlsa.cpp:384
BindingType bindingType() const
Returns the type of this binding.
Definition qqmlsa.cpp:350
Element bindingScope() const
Returns the Element scope in which the binding is defined.
Definition qqmlsa.cpp:342
friend bool operator!=(const Binding &lhs, const Binding &rhs)
Returns true if lhs and rhs are not equal, and false otherwise.
Definition qqmlsa.h:106
bool hasUndefinedScriptValue() const
Returns whether this binding has script value type undefined like when it is assigned undefined.
Definition qqmlsa.cpp:451
Binding(const Binding &)
Creates a copy of other.
Definition qqmlsa.cpp:254
Binding & operator=(const Binding &)
Assigns other to this Binding instance.
Definition qqmlsa.cpp:266
bool isAttached() const
Returns true if this type is attached to another one, false otherwise.
Definition qqmlsa.cpp:375
bool hasObject() const
Returns true if this binding has an objects, otherwise returns false.
Definition qqmlsa.cpp:432
friend bool operator==(const Binding &lhs, const Binding &rhs)
Returns true if lhs and rhs are equal, and false otherwise.
Definition qqmlsa.h:102
static bool isLiteralBinding(BindingType)
Returns true if bindingType is a literal type, and false otherwise.
Definition qqmlsa.cpp:475
QString propertyName() const
Returns the name of the property bound with this binding.
Definition qqmlsa.cpp:367
Binding()
Constructs a new Binding object.
Definition qqmlsa.cpp:247
QString stringValue() const
Returns the associated string literal if the content type of this binding is StringLiteral,...
Definition qqmlsa.cpp:359
Element objectType() const
Returns the type of the associated object if the content type of this binding is Object,...
Definition qqmlsa.cpp:441
Binding & operator=(Binding &&) noexcept
Move-assigns other to this Binding instance.
Definition qqmlsa.cpp:282
QQmlSA::SourceLocation sourceLocation() const
Returns the location in the QML code where this binding is defined.
Definition qqmlsa.cpp:405
ScriptBindingKind scriptKind() const
Returns the kind of the associated script if the content type of this binding is Script,...
Definition qqmlsa.cpp:424
double numberValue() const
Returns the associated number if the content type of this binding is NumberLiteral,...
Definition qqmlsa.cpp:415
Element groupType() const
Returns the type of the property of this binding if it is a group property, otherwise returns an inva...
Definition qqmlsa.cpp:334
bool hasFunctionScriptValue() const
Returns whether this binding has script value type function like when it is assigned a (lambda) metho...
Definition qqmlsa.cpp:464
\inmodule QtQmlCompiler
Definition qqmlsa.h:368
\inmodule QtQmlCompiler
Definition qqmlsa.h:202
\inmodule QtQmlCompiler
Definition qqmlsa.h:397
void setHint(const QString &)
Sets hint as the hint for this fix suggestion.
Definition qqmlsa.cpp:2193
FixSuggestion(const FixSuggestion &)
Creates a copy of other.
Definition qqmlsa.cpp:2107
QString hint() const
Returns the hint for this fix suggestion.
Definition qqmlsa.cpp:2201
QString replacement() const
Returns the fix that will replace the problematic source code.
Definition qqmlsa.cpp:2169
QString fixDescription() const
Returns the description of the fix.
Definition qqmlsa.cpp:2152
bool isAutoApplicable() const
Returns whether this suggested fix can be applied automatically.
Definition qqmlsa.cpp:2218
void setAutoApplicable(bool autoApplicable=true)
Sets autoApplicable to determine whether this suggested fix can be applied automatically.
Definition qqmlsa.cpp:2210
\inmodule QtQmlCompiler
Definition qqmlsa.h:283
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id)
Emits a warning message diagnostic about an issue of type id.
Definition qqmlsa.cpp:1264
Element resolveLiteralType(const Binding &binding)
Returns the element representing the type of literal in binding.
Definition qqmlsa.cpp:1376
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id, QQmlSA::SourceLocation srcLocation, const QQmlSA::FixSuggestion &fix)
Emits a warning message diagnostic about an issue of type id located at srcLocation and with suggeste...
Definition qqmlsa.cpp:1287
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id, QQmlSA::SourceLocation srcLocation)
Emits warning message diagnostic about an issue of type id located at srcLocation.
Definition qqmlsa.cpp:1273
Element resolveBuiltinType(QAnyStringView typeName) const
Returns the type of the built-in type identified by typeName.
Definition qqmlsa.cpp:1348
Element resolveAttached(QAnyStringView moduleName, QAnyStringView typeName)
Returns the attached type of typeName defined in module moduleName.
Definition qqmlsa.cpp:1366
QString resolveElementToId(const Element &element, const Element &context)
Returns the id of element in a given context.
Definition qqmlsa.cpp:1399
Element resolveTypeInFileScope(QAnyStringView typeName)
Returns the type corresponding to typeName inside the currently analysed file.
Definition qqmlsa.cpp:1302
QString sourceCode(QQmlSA::SourceLocation location)
Returns the source code located within location.
Definition qqmlsa.cpp:1411
Element resolveAttachedInFileScope(QAnyStringView typeName)
Returns the attached type corresponding to typeName used inside the currently analysed file.
Definition qqmlsa.cpp:1314
Element resolveIdToElement(QAnyStringView id, const Element &context)
Returns the element in context that has id id.
Definition qqmlsa.cpp:1387
Element resolveType(QAnyStringView moduleName, QAnyStringView typeName)
Returns the type of typeName defined in module moduleName.
Definition qqmlsa.cpp:1332
\inmodule QtQmlCompiler
Definition qqmlsa.h:340
\inmodule QtQmlCompiler
Definition qqmlsa.h:120
Method & operator=(Method &&) noexcept
Move-assigns other to this Method instance.
Definition qqmlsa.cpp:624
MethodType methodType() const
Returns the type of this method.
Definition qqmlsa.cpp:651
Method(const Method &)
Creates a copy of other.
Definition qqmlsa.cpp:598
Method()
Constructs a new Method object.
Definition qqmlsa.cpp:593
Method & operator=(const Method &)
Assigns other to this Method instance.
Definition qqmlsa.cpp:611
QString methodName() const
Returns the name of the this method.
Definition qqmlsa.cpp:642
\inmodule QtQmlCompiler
Definition qqmlsa.h:314
void analyze(const Element &root)
Runs the element passes over root and all its children.
Definition qqmlsa.cpp:1600
bool isCategoryEnabled(LoggerWarningId category) const
Returns true if warnings of category are enabled, false otherwise.
Definition qqmlsa.cpp:1711
bool registerPropertyPass(std::shared_ptr< PropertyPass > pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName=QAnyStringView(), bool allowInheritance=true)
Registers a static analysis pass for properties.
Definition qqmlsa.cpp:1503
std::unordered_map< quint32, Binding > bindingsByLocation() const
Returns bindings by their source location.
Definition qqmlsa.cpp:2004
bool hasImportedModule(QAnyStringView name) const
Returns true if the module named module has been imported by the QML to be analyzed,...
Definition qqmlsa.cpp:1703
\inmodule QtQmlCompiler
Definition qqmlsa.h:351
\inmodule QtQmlCompiler
Definition qqmlsa.h:169
Property(const Property &)
Creates a copy of other.
Definition qqmlsa.cpp:774
QString typeName() const
Returns the name of the type of this property.
Definition qqmlsa.cpp:819
bool isReadonly() const
Returns true if this property is read-only, false otherwise.
Definition qqmlsa.cpp:837
\inmodule QtQmlCompiler
MethodType
Definition qqmlsa.h:48
constexpr bool isFunctionScope(ScopeType type)
AccessSemantics
Definition qqmlsa.h:49
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
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
#define QmlLintPluginInterface_iid
Definition qqmlsa.h:440
QList< Export > exports
QTypeRevision revision