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;
71namespace QQmlJSUtils {
72/*! \internal
73 Returns escaped version of \a s. This function is mostly useful for code
74 generators.
75*/
76template <typename String, typename CharacterLiteral, typename StringView>
77String escapeString(String s)
78{
79 return s.replace(CharacterLiteral('\\'), StringView("\\\\"))
80 .replace(CharacterLiteral('"'), StringView("\\\""))
81 .replace(CharacterLiteral('\n'), StringView("\\n"))
82 .replace(CharacterLiteral('?'), StringView("\\?"));
83}
84
85/*! \internal
86 Returns \a s wrapped into a literal macro specified by \a ctor. By
87 default, returns a QStringLiteral-wrapped literal. This function is
88 mostly useful for code generators.
89
90 \note This function escapes \a s before wrapping it.
91*/
92template <typename String = QString, typename CharacterLiteral = QLatin1Char,
93 typename StringView = QLatin1StringView>
94String toLiteral(const String &s, StringView ctor = StringView("QStringLiteral"))
95{
96 return ctor % StringView("(\"") % escapeString<String, CharacterLiteral, StringView>(s)
97 % StringView("\")");
98}
99
100/*! \internal
101 Returns \a type string conditionally wrapped into \c{const} and \c{&}.
102 This function is mostly useful for code generators.
103*/
104inline QString constRefify(QString type)
105{
106 if (!type.endsWith(u'*'))
107 type = u"const " % type % u"&";
108 return type;
109}
110
111inline std::optional<QQmlJSMetaProperty> changeHandlerProperty(const QQmlJSScope::ConstPtr &scope,
112 QStringView signalName)
113{
114 if (!signalName.endsWith(QLatin1String("Changed")))
115 return {};
116 constexpr int length = int(sizeof("Changed") / sizeof(char)) - 1;
117 signalName.chop(length);
118 auto p = scope->property(signalName.toString());
119 const bool isBindable = !p.bindable().isEmpty();
120 const bool canNotify = !p.notify().isEmpty();
121 if (p.isValid() && (isBindable || canNotify))
122 return p;
123 return { };
124}
125
126inline std::optional<QQmlJSMetaProperty>
127propertyFromChangedHandler(const QQmlJSScope::ConstPtr &scope, QStringView changedHandler)
128{
129 auto signalName = QQmlSignalNames::changedHandlerNameToPropertyName(changedHandler);
130 if (!signalName)
131 return { };
132
133 auto p = scope->property(*signalName);
134 const bool isBindable = !p.bindable().isEmpty();
135 const bool canNotify = !p.notify().isEmpty();
136 if (p.isValid() && (isBindable || canNotify))
137 return p;
138 return { };
139}
140
141inline bool hasCompositeBase(const QQmlJSScope::ConstPtr &scope)
142{
143 if (!scope)
144 return false;
145 const auto base = scope->baseType();
146 if (!base)
147 return false;
148 return base->isComposite() && base->scopeType() == QQmlSA::ScopeType::QMLScope;
149}
150
155/*! \internal
156
157 Returns \c true if \a p is bindable and property accessor specified by
158 \a accessor is equal to "default". Returns \c false otherwise.
159
160 \note This function follows BINDABLE-only properties logic (e.g. in moc)
161*/
163 PropertyAccessor accessor)
164{
165 if (p.bindable().isEmpty())
166 return false;
167 switch (accessor) {
169 return p.read() == QLatin1String("default");
171 return p.write() == QLatin1String("default");
172 default:
173 break;
174 }
175 return false;
176}
177
190{
191 std::function<void()> reset = []() { };
192 std::function<void(const QQmlJSScope::ConstPtr &)> processResolvedId =
193 [](const QQmlJSScope::ConstPtr &) { };
194 std::function<void(const QQmlJSMetaProperty &, const QQmlJSScope::ConstPtr &)>
197};
200 const QQmlJSScope::ConstPtr &owner,
202ResolvedAlias Q_QMLCOMPILER_EXPORT resolveAlias(const QQmlJSScopesById &idScopes,
204 const QQmlJSScope::ConstPtr &owner,
206
207template <typename QQmlJSScopePtr, typename Action>
208bool searchBaseAndExtensionTypes(const QQmlJSScopePtr &type, const Action &check)
209{
210 if (!type)
211 return false;
212
213 using namespace detail;
214
215 // NB: among other things, getQQmlJSScopeFromSmartPtr() also resolves const
216 // vs non-const pointer issue, so use it's return value as the type
217 using T = decltype(getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(
218 std::declval<QQmlJSScope::ConstPtr>()));
219
220 const auto checkWrapper = [&](const auto &scope, QQmlJSScope::ExtensionKind mode) {
221 if constexpr (std::is_invocable<Action, decltype(scope),
222 QQmlJSScope::ExtensionKind>::value) {
223 return check(scope, mode);
224 } else {
225 static_assert(std::is_invocable<Action, decltype(scope)>::value,
226 "Inferred type Action has unexpected arguments");
227 Q_UNUSED(mode);
228 return check(scope);
229 }
230 };
231
232 const bool isValueOrSequenceType = [type]() {
233 switch (type->accessSemantics()) {
234 case QQmlJSScope::AccessSemantics::Value:
235 case QQmlJSScope::AccessSemantics::Sequence:
236 return true;
237 default:
238 break;
239 }
240 return false;
241 }();
242
243 QDuplicateTracker<T> seen;
244 for (T scope = type; scope && !seen.hasSeen(scope);
245 scope = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(scope->baseType())) {
246 QDuplicateTracker<T> seenExtensions;
247 // Extensions override the types they extend unless they are JavaScript extensions.
248 // However, usually base types of extensions are ignored. The unusual cases are when we
249 // have a value or sequence type or when we have the QObject type, in which
250 // case we also study the extension's base type hierarchy.
251 const bool isQObject = scope->internalName() == QLatin1String("QObject");
252 auto [extensionPtr, extensionKind] = scope->extensionType();
253
254 if (extensionKind == QQmlJSScope::ExtensionJavaScript
255 && checkWrapper(scope, QQmlJSScope::NotExtension)) {
256 return true;
257 }
258
259 auto extension = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(extensionPtr);
260 do {
261 if (!extension || seenExtensions.hasSeen(extension))
262 break;
263
264 if (checkWrapper(extension, extensionKind))
265 return true;
266 extension = getQQmlJSScopeFromSmartPtr<QQmlJSScopePtr>(extension->baseType());
267 } while (isValueOrSequenceType || isQObject);
268
269 if (extensionKind != QQmlJSScope::ExtensionJavaScript
270 && checkWrapper(scope, QQmlJSScope::NotExtension)) {
271 return true;
272 }
273 }
274
275 return false;
276}
277
278template <typename Action>
279void traverseFollowingQmlIrObjectStructure(const QQmlJSScope::Ptr &root, Action act)
280{
281 // We *have* to perform DFS here: QmlIR::Object entries within the
282 // QmlIR::Document are stored in the order they appear during AST traversal
283 // (which does DFS)
284 QStack<QQmlJSScope::Ptr> stack;
285 stack.push(root);
286
287 while (!stack.isEmpty()) {
288 QQmlJSScope::Ptr current = stack.pop();
289
290 act(current);
291
292 auto children = current->childScopes();
293 // arrays are special: they are reverse-processed in QmlIRBuilder
294 if (!current->isArrayScope())
295 std::reverse(children.begin(), children.end()); // left-to-right DFS
296 stack.append(std::move(children));
297 }
298}
299
300/*! \internal
301
302 Traverses the base types and extensions of \a scope in the order aligned
303 with QMetaObjects created at run time for these types and extensions
304 (except that QQmlVMEMetaObject is ignored). \a start is the starting
305 type in the hierarchy where \a act is applied.
306
307 \note To call \a act for every type in the hierarchy, use
308 scope->extensionType().scope as \a start
309*/
310template <typename Action>
311void traverseFollowingMetaObjectHierarchy(const QQmlJSScope::ConstPtr &scope,
312 const QQmlJSScope::ConstPtr &start, Action act)
313{
314 // Meta objects are arranged in the following way:
315 // * static meta objects are chained first
316 // * dynamic meta objects are added on top - they come from extensions.
317 // QQmlVMEMetaObject ignored here
318 //
319 // Example:
320 // ```
321 // class A : public QObject {
322 // QML_EXTENDED(Ext)
323 // };
324 // class B : public A {
325 // QML_EXTENDED(Ext2)
326 // };
327 // ```
328 // gives: Ext2 -> Ext -> B -> A -> QObject
329 // ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
330 // ^^^^^^^^^^^ static meta objects
331 // dynamic meta objects
332
333 using namespace Qt::StringLiterals;
334 // ignore special extensions
335 const QLatin1String ignoredExtensionNames[] = {
336 // QObject extensions: (not related to C++)
337 "Object"_L1,
338 "ObjectPrototype"_L1,
339 };
340
341 QList<QQmlJSScope::AnnotatedScope> types;
342 QList<QQmlJSScope::AnnotatedScope> extensions;
343 const auto collect = [&](const QQmlJSScope::ConstPtr &type, QQmlJSScope::ExtensionKind m) {
344 if (m == QQmlJSScope::NotExtension) {
345 types.append(QQmlJSScope::AnnotatedScope{ type, m });
346 return false;
347 }
348
349 for (const auto &name : ignoredExtensionNames) {
350 if (type->internalName() == name)
351 return false;
352 }
353 extensions.append(QQmlJSScope::AnnotatedScope{ type, m });
354 return false;
355 };
356 searchBaseAndExtensionTypes(scope, collect);
357
358 QList<QQmlJSScope::AnnotatedScope> all;
359 all.reserve(extensions.size() + types.size());
360 // first extensions then types
361 all.append(std::move(extensions));
362 all.append(std::move(types));
363
364 auto begin = all.cbegin();
365 // skip to start
366 while (begin != all.cend() && !begin->scope->isSameType(start))
367 ++begin;
368
369 // iterate over extensions and types starting at a specified point
370 for (; begin != all.cend(); ++begin)
371 act(begin->scope, begin->extensionSpecifier);
372}
373
374std::optional<QQmlJSFixSuggestion>
375 Q_QMLCOMPILER_EXPORT didYouMean(const QString &userInput, QStringList candidates,
376 const QString &filename,
378
379std::variant<QString, QQmlJS::DiagnosticMessage> Q_QMLCOMPILER_EXPORT
381
382template <typename Container>
383inline void deduplicate(Container &container)
384{
385 std::sort(container.begin(), container.end());
386 auto erase = std::unique(container.begin(), container.end());
387 container.erase(erase, container.end());
388}
389
390inline QStringList cleanPaths(QStringList &&paths)
391{
392 for (QString &path : paths)
393 path = QDir::cleanPath(path);
394 return std::move(paths);
395}
396
397QStringList Q_QMLCOMPILER_EXPORT resourceFilesFromBuildFolders(const QStringList &buildFolders);
398QString Q_QMLCOMPILER_EXPORT qmlSourcePathFromBuildPath(const QQmlJSResourceFileMapper *mapper,
400QString Q_QMLCOMPILER_EXPORT qmlBuildPathFromSourcePath(const QQmlJSResourceFileMapper *mapper,
402
403QString Q_QMLCOMPILER_EXPORT getScopeName(const QQmlJSScope::ConstPtr &scope,
405QString Q_QMLCOMPILER_EXPORT fileSelectorFor(const QQmlJSScope::ConstPtr &scope1);
406
407// TODO: use a central list of file extensions that can also be used by qmetatypesjsonprocessor.cpp
408// (that needs header file extensions) and Qt6QmlMacros.cmake.
409constexpr inline std::array cppFileFilters{
410 QLatin1String("*.cpp"), QLatin1String("*.cxx"), QLatin1String("*.cc"), QLatin1String("*.c"),
411 QLatin1String("*.c++"), QLatin1String("*.hpp"), QLatin1String("*.hxx"), QLatin1String("*.hh"),
412 QLatin1String("*.h"), QLatin1String("*.h++"),
413};
414
415bool Q_QMLCOMPILER_EXPORT canStrictlyCompareWithVar(const QQmlJSTypeResolver *typeResolver,
418
419bool Q_QMLCOMPILER_EXPORT canCompareWithQObject(const QQmlJSTypeResolver *typeResolver,
422
423bool Q_QMLCOMPILER_EXPORT canCompareWithQUrl(const QQmlJSTypeResolver *typeResolver,
426}; // namespace QQmlJSUtils
427
428QT_END_NAMESPACE
429
430#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:815
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:826
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
\inmodule QtQmlCompiler
friend bool operator!=(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
QString notify() const
QSharedPointer< const QQmlJSScope > aliasTargetScope() const
QString aliasExpression() const
friend bool operator==(const QQmlJSMetaProperty &a, const QQmlJSMetaProperty &b)
void setIsOverride(bool isOverride)
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 setIsVirtual(bool isVirtual)
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:53
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:107
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:103
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
DocumentEditPrivate(DocumentEdit *, DocumentEditPrivate &&)
Definition qqmlsa.cpp:2153
static QQmlJSDocumentEdit documentEdit(const DocumentEdit &edit)
Definition qqmlsa.cpp:2174
QString replacement() const
Definition qqmlsa.cpp:2169
DocumentEditPrivate(DocumentEdit *, const DocumentEditPrivate &)
Definition qqmlsa.cpp:2147
SourceLocation location() const
Definition qqmlsa.cpp:2164
static QList< QQmlJSDocumentEdit > documentEdits(const QList< DocumentEdit > &edits)
Definition qqmlsa.cpp:2179
QString filename() const
Definition qqmlsa.cpp:2159
static DocumentEdit createQQmlSADocumentEdit(const QQmlJSDocumentEdit &edit)
Definition qqmlsa.cpp:2187
\inmodule QtQmlCompiler
Definition qqmlsa.h:378
QString replacement() const
Returns the replacement string of the edit.
Definition qqmlsa.cpp:2123
QString filename() const
Returns the file this edit applies to.
Definition qqmlsa.cpp:2105
DocumentEdit(const DocumentEdit &)
Creates a copy of other.
Definition qqmlsa.cpp:2058
\inmodule QtQmlCompiler
Definition qqmlsa.h:369
\inmodule QtQmlCompiler
Definition qqmlsa.h:203
QList< DocumentEdit > documentEdits() const
Definition qqmlsa.cpp:1992
SourceLocation location() const
Definition qqmlsa.cpp:1981
QString description() const
Definition qqmlsa.cpp:1976
static FixSuggestion createQQmlSAFixSuggestion(const QQmlJSFixSuggestion &)
Definition qqmlsa.cpp:2030
FixSuggestionPrivate(FixSuggestion *, const QString &description, const SourceLocation &location, const QList< DocumentEdit > &documentEdits={})
Definition qqmlsa.cpp:1956
void setFileName(const QString &)
Definition qqmlsa.cpp:2000
void addDocumentEdit(const DocumentEdit &)
Definition qqmlsa.cpp:1986
FixSuggestionPrivate(FixSuggestion *)
Definition qqmlsa.cpp:1954
void setAutoApplicable(bool autoApplicable=true)
Definition qqmlsa.cpp:2010
static const QQmlJSFixSuggestion & fixSuggestion(const QQmlSA::FixSuggestion &)
Definition qqmlsa.cpp:2025
FixSuggestionPrivate(FixSuggestion *, FixSuggestionPrivate &&)
Definition qqmlsa.cpp:1971
static QQmlJSFixSuggestion & fixSuggestion(QQmlSA::FixSuggestion &)
Definition qqmlsa.cpp:2020
FixSuggestionPrivate(FixSuggestion *, const FixSuggestionPrivate &)
Definition qqmlsa.cpp:1965
\inmodule QtQmlCompiler
Definition qqmlsa.h:406
FixSuggestion(const QString &description, const QQmlSA::SourceLocation &location, const QList< DocumentEdit > &documentEdits={})
Creates a FixSuggestion object.
Definition qqmlsa.cpp:2214
void addDocumentEdit(const DocumentEdit &)
Adds a document edit to the list of edits for this fix.
Definition qqmlsa.cpp:2286
FixSuggestion(const FixSuggestion &)
Creates a copy of other.
Definition qqmlsa.cpp:2223
QString description() const
Returns the description of the fix.
Definition qqmlsa.cpp:2268
bool isAutoApplicable() const
Returns whether this suggested fix can be applied automatically.
Definition qqmlsa.cpp:2330
void setAutoApplicable(bool autoApplicable=true)
Sets autoApplicable to determine whether this suggested fix can be applied automatically.
Definition qqmlsa.cpp:2321
QList< DocumentEdit > documentEdits() const
Returns the list of document edits that applying this fix would make.
Definition qqmlsa.cpp:2295
\inmodule QtQmlCompiler
Definition qqmlsa.h:284
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id)
Emits a warning message diagnostic about an issue of type id.
Definition qqmlsa.cpp:1269
Element resolveLiteralType(const Binding &binding)
Returns the element representing the type of literal in binding.
Definition qqmlsa.cpp:1382
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:1292
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:1278
Element resolveBuiltinType(QAnyStringView typeName) const
Returns the type of the built-in type identified by typeName.
Definition qqmlsa.cpp:1354
Element resolveAttached(QAnyStringView moduleName, QAnyStringView typeName)
Returns the attached type of typeName defined in module moduleName.
Definition qqmlsa.cpp:1372
QString resolveElementToId(const Element &element, const Element &context)
Returns the id of element in a given context.
Definition qqmlsa.cpp:1405
Element resolveTypeInFileScope(QAnyStringView typeName)
Returns the type corresponding to typeName inside the currently analysed file.
Definition qqmlsa.cpp:1307
QString sourceCode(QQmlSA::SourceLocation location)
Returns the source code located within location.
Definition qqmlsa.cpp:1417
Element resolveAttachedInFileScope(QAnyStringView typeName)
Returns the attached type corresponding to typeName used inside the currently analysed file.
Definition qqmlsa.cpp:1319
Element resolveIdToElement(QAnyStringView id, const Element &context)
Returns the element in context that has id id.
Definition qqmlsa.cpp:1393
Element resolveType(QAnyStringView moduleName, QAnyStringView typeName)
Returns the type of typeName defined in module moduleName.
Definition qqmlsa.cpp:1337
\inmodule QtQmlCompiler
Definition qqmlsa.h:341
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:121
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:315
void analyze(const Element &root)
Runs the element passes over root and all its children.
Definition qqmlsa.cpp:1607
bool isCategoryEnabled(LoggerWarningId category) const
Returns true if warnings of category are enabled, false otherwise.
Definition qqmlsa.cpp:1718
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:1509
std::unordered_map< quint32, Binding > bindingsByLocation() const
Returns bindings by their source location.
Definition qqmlsa.cpp:1948
bool hasImportedModule(QAnyStringView name) const
Returns true if the module named module has been imported by the QML to be analyzed,...
Definition qqmlsa.cpp:1710
PropertyPassBuilder(PassManager *passManager)
Definition qqmlsa_p.h:364
\inmodule QtQmlCompiler
Definition qqmlsa.h:352
\inmodule QtQmlCompiler
Definition qqmlsa_p.h:156
\inmodule QtQmlCompiler
Definition qqmlsa.h:170
Property(const Property &)
Creates a copy of other.
Definition qqmlsa.cpp:779
QString typeName() const
Returns the name of the type of this property.
Definition qqmlsa.cpp:824
bool isReadonly() const
Returns true if this property is read-only, false otherwise.
Definition qqmlsa.cpp:842
std::optional< QQmlJSMetaProperty > propertyFromChangedHandler(const QQmlJSScope::ConstPtr &scope, QStringView changedHandler)
void deduplicate(Container &container)
bool searchBaseAndExtensionTypes(const QQmlJSScopePtr &type, const Action &check)
constexpr std::array cppFileFilters
void traverseFollowingQmlIrObjectStructure(const QQmlJSScope::Ptr &root, Action act)
String escapeString(String s)
void traverseFollowingMetaObjectHierarchy(const QQmlJSScope::ConstPtr &scope, const QQmlJSScope::ConstPtr &start, Action act)
QStringList cleanPaths(QStringList &&paths)
bool bindablePropertyHasDefaultAccessor(const QQmlJSMetaProperty &p, PropertyAccessor accessor)
String toLiteral(const String &s, StringView ctor=StringView("QStringLiteral"))
bool hasCompositeBase(const QQmlJSScope::ConstPtr &scope)
QString constRefify(QString type)
std::optional< QQmlJSMetaProperty > changeHandlerProperty(const QQmlJSScope::ConstPtr &scope, QStringView signalName)
void defaultTypeReader(QQmlJSImporter *importer, const QString &filePath, const QSharedPointer< QQmlJSScope > &scope)
\inmodule QtQmlCompiler
MethodType
Definition qqmlsa.h:49
Q_QMLCOMPILER_EXPORT void emitWarningWithOptionalFix(GenericPass &pass, QAnyStringView diagnostic, const LoggerWarningId &id, const QQmlSA::SourceLocation &srcLocation, const std::optional< QQmlJSFixSuggestion > &fixSuggestion)
Definition qqmlsa.cpp:2350
bool isRegularBindingType(BindingType type)
Definition qqmlsa.cpp:2364
constexpr bool isFunctionScope(ScopeType type)
AccessSemantics
Definition qqmlsa.h:50
@ HasBaseTypeError
Definition qqmlsa_p.h:43
@ InlineComponent
Definition qqmlsa_p.h:41
@ HasExtensionNamespace
Definition qqmlsa_p.h:44
@ WrappedInImplicitComponent
Definition qqmlsa_p.h:42
Combined button and popup list for selecting options.
static auto getQQmlJSScopeFromSmartPtr(const From &p) -> From
Q_DECLARE_TYPEINFO(QDateTime::Data, Q_RELOCATABLE_TYPE)
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
static QString toNumericString(double value)
static QString messageTypeForMethod(const QString &method)
static QString derefContentPointer(const QString &contentPointer)
static bool canTypeBeAffectedBySideEffects(const QQmlJSTypeResolver *typeResolver, const QQmlJSRegisterContent &baseType)
#define BYTECODE_UNIMPLEMENTED()
#define INJECT_TRACE_INFO(function)
#define REJECT
static QString registerName(int registerIndex, int offset)
static QString minExpression(int argc)
static QString maxExpression(int argc)
static bool isTypeStorable(const QQmlJSTypeResolver *resolver, const QQmlJSScope::ConstPtr &type)
QQmlSA::MethodType QQmlJSMetaMethodType
QQmlJSMetaParameter QQmlJSMetaReturnType
ScriptBindingValueType
@ ScriptValue_Function
@ ScriptValue_Unknown
@ ScriptValue_Undefined
static void resetFactory(QDeferredSharedPointer< T > &pointer, QQmlJSImporter *importer, const QQmlJS::TypeReader &typeReader, const QString &filePath)
void resetFactoryImpl(QDeferredSharedPointer< T > &pointer, U &&factory)
#define QmlLintPluginInterface_iid
Definition qqmlsa.h:450
std::function< void(const QQmlJSMetaProperty &, const QQmlJSScope::ConstPtr &)> processResolvedProperty
std::function< void(const QQmlJSScope::ConstPtr &)> processResolvedId
QQmlJSScope::ConstPtr owner
QQmlJSMetaProperty property
ResolvedAliasTarget kind
QList< Export > exports
QTypeRevision revision
static void onWriteDefault(PropertyPass *, const Element &, const QString &, const Element &, const Element &, SourceLocation)
Definition qqmlsa_p.h:324
static void onBindingDefault(PropertyPass *, const Element &, const QString &, const Binding &, const Element &, const Element &)
Definition qqmlsa_p.h:312
void onRead(const Element &element, const QString &propertyName, const Element &readScope, SourceLocation location) override
Executes whenever a property is read.
Definition qqmlsa_p.h:339
static void onCallDefault(PropertyPass *, const Element &, const QString &, const Element &, SourceLocation)
Definition qqmlsa_p.h:320
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:334
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:344
static void onReadDefault(PropertyPass *, const Element &, const QString &, const Element &, SourceLocation)
Definition qqmlsa_p.h:316
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:349
std::shared_ptr< QQmlSA::PropertyPass > pass
Definition qqmlsa_p.h:51