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
qqmljsutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QQMLJSUTILS_P_H
6#define QQMLJSUTILS_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 "qqmljslogger_p.h"
22#include "qqmljsscope_p.h"
24
25#include <QtCore/qdir.h>
26#include <QtCore/qstack.h>
27#include <QtCore/qstring.h>
28#include <QtCore/qstringbuilder.h>
29#include <QtCore/qstringview.h>
30
31#include <QtQml/private/qqmlsignalnames_p.h>
32#include <private/qduplicatetracker_p.h>
33
34#include <optional>
35#include <functional>
36#include <type_traits>
37#include <variant>
38
39QT_BEGIN_NAMESPACE
40
41namespace detail {
42/*! \internal
43
44 Utility method that returns proper value according to the type To. This
45 version returns From.
46*/
47template<typename To, typename From, typename std::enable_if_t<!std::is_pointer_v<To>, int> = 0>
48static auto getQQmlJSScopeFromSmartPtr(const From &p) -> From
49{
50 static_assert(!std::is_pointer_v<From>, "From has to be a smart pointer holding QQmlJSScope");
51 return p;
52}
53
54/*! \internal
55
56 Utility method that returns proper value according to the type To. This
57 version returns From::get(), which is a raw pointer. The returned type
58 is not necessarily equal to To (e.g. To might be `QQmlJSScope *` while
59 returned is `const QQmlJSScope *`).
60*/
61template<typename To, typename From, typename std::enable_if_t<std::is_pointer_v<To>, int> = 0>
62static auto getQQmlJSScopeFromSmartPtr(const From &p) -> decltype(p.get())
63{
64 static_assert(!std::is_pointer_v<From>, "From has to be a smart pointer holding QQmlJSScope");
65 return p.get();
66}
67}
68
69class QQmlJSTypeResolver;
71struct Q_QMLCOMPILER_EXPORT QQmlJSUtils
72{
73 /*! \internal
74 Returns escaped version of \a s. This function is mostly useful for code
75 generators.
76 */
77 template<typename String, typename CharacterLiteral, typename StringView>
78 static String escapeString(String s)
79 {
80 return s.replace(CharacterLiteral('\\'), StringView("\\\\"))
81 .replace(CharacterLiteral('"'), StringView("\\\""))
82 .replace(CharacterLiteral('\n'), StringView("\\n"))
83 .replace(CharacterLiteral('?'), StringView("\\?"));
84 }
85
86 /*! \internal
87 Returns \a s wrapped into a literal macro specified by \a ctor. By
88 default, returns a QStringLiteral-wrapped literal. This function is
89 mostly useful for code generators.
90
91 \note This function escapes \a s before wrapping it.
92 */
93 template<
94 typename String = QString,
95 typename CharacterLiteral = QLatin1Char,
96 typename StringView = QLatin1StringView>
97 static String toLiteral(const String &s, StringView ctor = StringView("QStringLiteral"))
98 {
99 return ctor % StringView("(\"")
100 % escapeString<String, CharacterLiteral, StringView>(s) % StringView("\")");
101 }
102
103 /*! \internal
104 Returns \a type string conditionally wrapped into \c{const} and \c{&}.
105 This function is mostly useful for code generators.
106 */
107 static QString constRefify(QString type)
108 {
109 if (!type.endsWith(u'*'))
110 type = u"const " % type % u"&";
111 return type;
112 }
113
114 static std::optional<QQmlJSMetaProperty>
115 changeHandlerProperty(const QQmlJSScope::ConstPtr &scope, QStringView signalName)
116 {
117 if (!signalName.endsWith(QLatin1String("Changed")))
118 return {};
119 constexpr int length = int(sizeof("Changed") / sizeof(char)) - 1;
120 signalName.chop(length);
121 auto p = scope->property(signalName.toString());
122 const bool isBindable = !p.bindable().isEmpty();
123 const bool canNotify = !p.notify().isEmpty();
124 if (p.isValid() && (isBindable || canNotify))
125 return p;
126 return {};
127 }
128
129 static std::optional<QQmlJSMetaProperty>
130 propertyFromChangedHandler(const QQmlJSScope::ConstPtr &scope, QStringView changedHandler)
131 {
132 auto signalName = QQmlSignalNames::changedHandlerNameToPropertyName(changedHandler);
133 if (!signalName)
134 return {};
135
136 auto p = scope->property(*signalName);
137 const bool isBindable = !p.bindable().isEmpty();
138 const bool canNotify = !p.notify().isEmpty();
139 if (p.isValid() && (isBindable || canNotify))
140 return p;
141 return {};
142 }
143
144 static bool hasCompositeBase(const QQmlJSScope::ConstPtr &scope)
145 {
146 if (!scope)
147 return false;
148 const auto base = scope->baseType();
149 if (!base)
150 return false;
151 return base->isComposite() && base->scopeType() == QQmlSA::ScopeType::QMLScope;
152 }
153
154 enum PropertyAccessor {
155 PropertyAccessor_Read,
156 PropertyAccessor_Write,
157 };
158 /*! \internal
159
160 Returns \c true if \a p is bindable and property accessor specified by
161 \a accessor is equal to "default". Returns \c false otherwise.
162
163 \note This function follows BINDABLE-only properties logic (e.g. in moc)
164 */
165 static bool bindablePropertyHasDefaultAccessor(const QQmlJSMetaProperty &p,
166 PropertyAccessor accessor)
167 {
168 if (p.bindable().isEmpty())
169 return false;
170 switch (accessor) {
171 case PropertyAccessor::PropertyAccessor_Read:
172 return p.read() == QLatin1String("default");
173 case PropertyAccessor::PropertyAccessor_Write:
174 return p.write() == QLatin1String("default");
175 default:
176 break;
177 }
178 return false;
179 }
180
181 enum ResolvedAliasTarget {
182 AliasTarget_Invalid,
183 AliasTarget_Property,
184 AliasTarget_Object,
185 };
186 struct ResolvedAlias
187 {
188 QQmlJSMetaProperty property;
189 QQmlJSScope::ConstPtr owner;
190 ResolvedAliasTarget kind = ResolvedAliasTarget::AliasTarget_Invalid;
191 };
192 struct AliasResolutionVisitor
193 {
194 std::function<void()> reset = []() {};
195 std::function<void(const QQmlJSScope::ConstPtr &)> processResolvedId =
196 [](const QQmlJSScope::ConstPtr &) {};
197 std::function<void(const QQmlJSMetaProperty &, const QQmlJSScope::ConstPtr &)>
198 processResolvedProperty =
199 [](const QQmlJSMetaProperty &, const QQmlJSScope::ConstPtr &) {};
200 };
201 static ResolvedAlias resolveAlias(const QQmlJSTypeResolver *typeResolver,
202 const QQmlJSMetaProperty &property,
203 const QQmlJSScope::ConstPtr &owner,
204 const AliasResolutionVisitor &visitor);
205 static ResolvedAlias resolveAlias(const QQmlJSScopesById &idScopes,
206 const QQmlJSMetaProperty &property,
207 const QQmlJSScope::ConstPtr &owner,
208 const AliasResolutionVisitor &visitor);
209
210 template<typename QQmlJSScopePtr, typename Action>
211 static bool searchBaseAndExtensionTypes(const QQmlJSScopePtr &type, const Action &check)
212 {
213 if (!type)
214 return false;
215
216 using namespace detail;
217
218 // NB: among other things, getQQmlJSScopeFromSmartPtr() also resolves const
219 // vs non-const pointer issue, so use it's return value as the type
220 using T = decltype(getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(
221 std::declval<QQmlJSScope::ConstPtr>()));
222
223 const auto checkWrapper = [&](const auto &scope, QQmlJSScope::ExtensionKind mode) {
224 if constexpr (std::is_invocable<Action, decltype(scope),
225 QQmlJSScope::ExtensionKind>::value) {
226 return check(scope, mode);
227 } else {
228 static_assert(std::is_invocable<Action, decltype(scope)>::value,
229 "Inferred type Action has unexpected arguments");
230 Q_UNUSED(mode);
231 return check(scope);
232 }
233 };
234
235 const bool isValueOrSequenceType = [type]() {
236 switch (type->accessSemantics()) {
237 case QQmlJSScope::AccessSemantics::Value:
238 case QQmlJSScope::AccessSemantics::Sequence:
239 return true;
240 default:
241 break;
242 }
243 return false;
244 }();
245
246 QDuplicateTracker<T> seen;
247 for (T scope = type; scope && !seen.hasSeen(scope);
248 scope = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(scope->baseType())) {
249 QDuplicateTracker<T> seenExtensions;
250 // Extensions override the types they extend unless they are JavaScript extensions.
251 // However, usually base types of extensions are ignored. The unusual cases are when we
252 // have a value or sequence type or when we have the QObject type, in which
253 // case we also study the extension's base type hierarchy.
254 const bool isQObject = scope->internalName() == QLatin1String("QObject");
255 auto [extensionPtr, extensionKind] = scope->extensionType();
256
257 if (extensionKind == QQmlJSScope::ExtensionJavaScript
258 && checkWrapper(scope, QQmlJSScope::NotExtension)) {
259 return true;
260 }
261
262 auto extension = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(extensionPtr);
263 do {
264 if (!extension || seenExtensions.hasSeen(extension))
265 break;
266
267 if (checkWrapper(extension, extensionKind))
268 return true;
269 extension = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(extension->baseType());
270 } while (isValueOrSequenceType || isQObject);
271
272 if (extensionKind != QQmlJSScope::ExtensionJavaScript
273 && checkWrapper(scope, QQmlJSScope::NotExtension)) {
274 return true;
275 }
276 }
277
278 return false;
279 }
280
281 template<typename Action>
282 static void traverseFollowingQmlIrObjectStructure(const QQmlJSScope::Ptr &root, Action act)
283 {
284 // We *have* to perform DFS here: QmlIR::Object entries within the
285 // QmlIR::Document are stored in the order they appear during AST traversal
286 // (which does DFS)
287 QStack<QQmlJSScope::Ptr> stack;
288 stack.push(root);
289
290 while (!stack.isEmpty()) {
291 QQmlJSScope::Ptr current = stack.pop();
292
293 act(current);
294
295 auto children = current->childScopes();
296 // arrays are special: they are reverse-processed in QmlIRBuilder
297 if (!current->isArrayScope())
298 std::reverse(children.begin(), children.end()); // left-to-right DFS
299 stack.append(std::move(children));
300 }
301 }
302
303 /*! \internal
304
305 Traverses the base types and extensions of \a scope in the order aligned
306 with QMetaObjects created at run time for these types and extensions
307 (except that QQmlVMEMetaObject is ignored). \a start is the starting
308 type in the hierarchy where \a act is applied.
309
310 \note To call \a act for every type in the hierarchy, use
311 scope->extensionType().scope as \a start
312 */
313 template<typename Action>
314 static void traverseFollowingMetaObjectHierarchy(const QQmlJSScope::ConstPtr &scope,
315 const QQmlJSScope::ConstPtr &start, Action act)
316 {
317 // Meta objects are arranged in the following way:
318 // * static meta objects are chained first
319 // * dynamic meta objects are added on top - they come from extensions.
320 // QQmlVMEMetaObject ignored here
321 //
322 // Example:
323 // ```
324 // class A : public QObject {
325 // QML_EXTENDED(Ext)
326 // };
327 // class B : public A {
328 // QML_EXTENDED(Ext2)
329 // };
330 // ```
331 // gives: Ext2 -> Ext -> B -> A -> QObject
332 // ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
333 // ^^^^^^^^^^^ static meta objects
334 // dynamic meta objects
335
336 using namespace Qt::StringLiterals;
337 // ignore special extensions
338 const QLatin1String ignoredExtensionNames[] = {
339 // QObject extensions: (not related to C++)
340 "Object"_L1,
341 "ObjectPrototype"_L1,
342 };
343
344 QList<QQmlJSScope::AnnotatedScope> types;
345 QList<QQmlJSScope::AnnotatedScope> extensions;
346 const auto collect = [&](const QQmlJSScope::ConstPtr &type, QQmlJSScope::ExtensionKind m) {
347 if (m == QQmlJSScope::NotExtension) {
348 types.append(QQmlJSScope::AnnotatedScope { type, m });
349 return false;
350 }
351
352 for (const auto &name : ignoredExtensionNames) {
353 if (type->internalName() == name)
354 return false;
355 }
356 extensions.append(QQmlJSScope::AnnotatedScope { type, m });
357 return false;
358 };
359 searchBaseAndExtensionTypes(scope, collect);
360
361 QList<QQmlJSScope::AnnotatedScope> all;
362 all.reserve(extensions.size() + types.size());
363 // first extensions then types
364 all.append(std::move(extensions));
365 all.append(std::move(types));
366
367 auto begin = all.cbegin();
368 // skip to start
369 while (begin != all.cend() && !begin->scope->isSameType(start))
370 ++begin;
371
372 // iterate over extensions and types starting at a specified point
373 for (; begin != all.cend(); ++begin)
374 act(begin->scope, begin->extensionSpecifier);
375 }
376
377 static std::optional<QQmlJSFixSuggestion> didYouMean(const QString &userInput,
378 QStringList candidates,
379 QQmlJS::SourceLocation location);
380
381 static std::variant<QString, QQmlJS::DiagnosticMessage>
382 sourceDirectoryPath(const QQmlJSImporter *importer, const QString &buildDirectoryPath);
383
384 template <typename Container>
385 static void deduplicate(Container &container)
386 {
387 std::sort(container.begin(), container.end());
388 auto erase = std::unique(container.begin(), container.end());
389 container.erase(erase, container.end());
390 }
391
392 static QStringList cleanPaths(QStringList &&paths)
393 {
394 for (QString &path : paths)
395 path = QDir::cleanPath(path);
396 return std::move(paths);
397 }
398
399 static QStringList resourceFilesFromBuildFolders(const QStringList &buildFolders);
400 static QString qmlSourcePathFromBuildPath(const QQmlJSResourceFileMapper *mapper,
401 const QString &pathInBuildFolder);
402 static QString qmlBuildPathFromSourcePath(const QQmlJSResourceFileMapper *mapper,
403 const QString &pathInBuildFolder);
404};
405
406bool Q_QMLCOMPILER_EXPORT canStrictlyCompareWithVar(
407 const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
408 const QQmlJSScope::ConstPtr &rhsType);
409
410bool Q_QMLCOMPILER_EXPORT canCompareWithQObject(
411 const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
412 const QQmlJSScope::ConstPtr &rhsType);
413
414bool Q_QMLCOMPILER_EXPORT canCompareWithQUrl(
415 const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
416 const QQmlJSScope::ConstPtr &rhsType);
417
418QT_END_NAMESPACE
419
420#endif // QQMLJSUTILS_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
bool isValid() const
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
static BindingPrivate * get(Binding *binding)
Definition qqmlsa_p.h:89
static QQmlJSMetaPropertyBinding binding(QQmlSA::Binding &binding)
Definition qqmlsa.cpp:320
Element bindingScope() const
Definition qqmlsa_p.h:98
void setPropertyName(QString name)
Definition qqmlsa_p.h:96
static QQmlSA::Binding createBinding(const QQmlJSMetaPropertyBinding &)
Definition qqmlsa.cpp:313
static const QQmlJSMetaPropertyBinding binding(const QQmlSA::Binding &binding)
Definition qqmlsa.cpp:325
bool isAttached() const
Definition qqmlsa_p.h:101
void setIsAttached(bool isAttached)
Definition qqmlsa_p.h:102
BindingPrivate(Binding *, const BindingPrivate &)
Definition qqmlsa.cpp:307
void setBindingScope(Element bindingScope)
Definition qqmlsa_p.h:99
static const BindingPrivate * get(const Binding *binding)
Definition qqmlsa_p.h:90
\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
QMultiHash< QString, Binding >::const_iterator constBegin() const
Definition qqmlsa.cpp:213
BindingsPrivate(QQmlSA::Binding::Bindings *, const BindingsPrivate &)
Definition qqmlsa.cpp:189
friend class QT_PREPEND_NAMESPACE(QQmlJSMetaPropertyBinding)
QMultiHash< QString, Binding >::const_iterator constEnd() const
Definition qqmlsa.cpp:232
\inmodule QtQmlCompiler
Definition qqmlsa.h:368
\inmodule QtQmlCompiler
Definition qqmlsa.h:202
QQmlSA::SourceLocation location() const
Definition qqmlsa.cpp:2037
FixSuggestionPrivate(FixSuggestion *, const QString &fixDescription, const QQmlSA::SourceLocation &location, const QString &replacement)
Definition qqmlsa.cpp:2012
void setHint(const QString &)
Definition qqmlsa.cpp:2057
void setFileName(const QString &)
Definition qqmlsa.cpp:2047
QString fixDescription() const
Definition qqmlsa.cpp:2032
FixSuggestionPrivate(FixSuggestion *)
Definition qqmlsa.cpp:2010
void setAutoApplicable(bool autoApplicable=true)
Definition qqmlsa.cpp:2067
static const QQmlJSFixSuggestion & fixSuggestion(const QQmlSA::FixSuggestion &)
Definition qqmlsa.cpp:2082
FixSuggestionPrivate(FixSuggestion *, FixSuggestionPrivate &&)
Definition qqmlsa.cpp:2027
QString replacement() const
Definition qqmlsa.cpp:2042
static QQmlJSFixSuggestion & fixSuggestion(QQmlSA::FixSuggestion &)
Definition qqmlsa.cpp:2077
FixSuggestionPrivate(FixSuggestion *, const FixSuggestionPrivate &)
Definition qqmlsa.cpp:2021
\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
MethodPrivate(Method *, const MethodPrivate &)
Definition qqmlsa.cpp:563
QQmlSA::SourceLocation sourceLocation() const
Definition qqmlsa.cpp:573
static QQmlSA::Method createMethod(const QQmlJSMetaMethod &)
Definition qqmlsa.cpp:680
MethodType methodType() const
Definition qqmlsa.cpp:578
static QQmlJSMetaMethod method(const QQmlSA::Method &)
Definition qqmlsa.cpp:701
QString methodName() const
Definition qqmlsa.cpp:568
\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
MethodsPrivate(QQmlSA::Method::Methods *, MethodsPrivate &&)
Definition qqmlsa.cpp:556
static QQmlSA::Method::Methods createMethods(const QMultiHash< QString, QQmlJSMetaMethod > &)
Definition qqmlsa.cpp:689
QMultiHash< QString, Method >::const_iterator constEnd() const
Definition qqmlsa.cpp:544
MethodsPrivate(QQmlSA::Method::Methods *, const MethodsPrivate &)
Definition qqmlsa.cpp:551
QMultiHash< QString, Method >::const_iterator constBegin() const
Definition qqmlsa.cpp:525
\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
PropertyPassBuilder(PassManager *passManager)
Definition qqmlsa_p.h:339
\inmodule QtQmlCompiler
Definition qqmlsa.h:351
static QQmlSA::Property createProperty(const QQmlJSMetaProperty &)
Definition qqmlsa.cpp:751
PropertyPrivate(Property *, const PropertyPrivate &)
Definition qqmlsa.cpp:708
PropertyPrivate(Property *, PropertyPrivate &&)
Definition qqmlsa.cpp:713
static QQmlJSMetaProperty property(const QQmlSA::Property &property)
Definition qqmlsa.cpp:746
QQmlSA::Element type() const
Returns the type that this property was defined with.
Definition qqmlsa.cpp:741
bool isValid() const
Definition qqmlsa.cpp:723
QString typeName() const
Definition qqmlsa.cpp:718
bool isReadonly() const
Returns whether this property is readonly.
Definition qqmlsa.cpp:733
\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
Q_QMLCOMPILER_EXPORT void emitWarningWithOptionalFix(GenericPass &pass, QAnyStringView diagnostic, const LoggerWarningId &id, const QQmlSA::SourceLocation &srcLocation, const std::optional< QQmlJSFixSuggestion > &fix)
Definition qqmlsa.cpp:2237
bool isRegularBindingType(BindingType type)
Definition qqmlsa.cpp:2253
constexpr bool isFunctionScope(ScopeType type)
AccessSemantics
Definition qqmlsa.h:49
@ HasBaseTypeError
Definition qqmlsa_p.h:43
@ InlineComponent
Definition qqmlsa_p.h:41
@ HasExtensionNamespace
Definition qqmlsa_p.h:44
@ WrappedInImplicitComponent
Definition qqmlsa_p.h:42
static auto getQQmlJSScopeFromSmartPtr(const From &p) -> From
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
static void onWriteDefault(PropertyPass *, const Element &, const QString &, const Element &, const Element &, SourceLocation)
Definition qqmlsa_p.h:299
static void onBindingDefault(PropertyPass *, const Element &, const QString &, const Binding &, const Element &, const Element &)
Definition qqmlsa_p.h:287
void onRead(const Element &element, const QString &propertyName, const Element &readScope, SourceLocation location) override
Executes whenever a property is read.
Definition qqmlsa_p.h:314
static void onCallDefault(PropertyPass *, const Element &, const QString &, const Element &, SourceLocation)
Definition qqmlsa_p.h:295
void onBinding(const Element &element, const QString &propertyName, const Binding &binding, const Element &bindingScope, const Element &value) override
Executes whenever a property gets bound to a value.
Definition qqmlsa_p.h:309
void onCall(const Element &element, const QString &propertyName, const Element &readScope, SourceLocation location) override
Executes whenever a property or method is called.
Definition qqmlsa_p.h:319
static void onReadDefault(PropertyPass *, const Element &, const QString &, const Element &, SourceLocation)
Definition qqmlsa_p.h:291
void onWrite(const Element &element, const QString &propertyName, const Element &value, const Element &writeScope, SourceLocation location) override
Executes whenever a property is written to.
Definition qqmlsa_p.h:324
std::shared_ptr< QQmlSA::PropertyPass > pass
Definition qqmlsa_p.h:51