17#include <QtQmlCompiler/qqmlsaconstants.h>
18#include <QtQmlCompiler/qqmljsloggingutils.h>
20#include <QtQmlCompiler/qtqmlcompilerexports.h>
22#include <QtCore/qhash.h>
23#include <QtCore/qsharedpointer.h>
24#include <QtCore/qplugin.h>
25#include <QtQmlCompiler/qqmlsasourcelocation.h>
27#include <unordered_map>
43class PassManagerPrivate;
46struct PropertyPassInfo;
89#if QT_DEPRECATED_SINCE(6
, 9
)
102 friend bool operator==(
const Binding &lhs,
const Binding &rhs)
104 return operatorEqualsImpl(lhs, rhs);
106 friend bool operator!=(
const Binding &lhs,
const Binding &rhs)
108 return !operatorEqualsImpl(lhs, rhs);
116 std::unique_ptr<BindingPrivate> d_ptr;
121 Q_DECLARE_PRIVATE(Method)
124 class Q_QMLCOMPILER_EXPORT Methods
126 Q_DECLARE_PRIVATE(Methods)
130 Methods(
const Methods &);
133 QMultiHash<QString, Method>::const_iterator begin()
const {
return constBegin(); }
134 QMultiHash<QString, Method>::const_iterator end()
const {
return constEnd(); }
135 QMultiHash<QString, Method>::const_iterator constBegin()
const;
136 QMultiHash<QString, Method>::const_iterator constEnd()
const;
139 std::unique_ptr<MethodsPrivate> d_ptr;
144 Method(Method &&)
noexcept;
153 friend bool operator==(
const Method &lhs,
const Method &rhs)
155 return operatorEqualsImpl(lhs, rhs);
157 friend bool operator!=(
const Method &lhs,
const Method &rhs)
159 return !operatorEqualsImpl(lhs, rhs);
163 static bool operatorEqualsImpl(
const Method &,
const Method &);
165 std::unique_ptr<MethodPrivate> d_ptr;
170 Q_DECLARE_PRIVATE(Property)
185 friend bool operator==(
const Property &lhs,
const Property &rhs)
187 return operatorEqualsImpl(lhs, rhs);
190 friend bool operator!=(
const Property &lhs,
const Property &rhs)
192 return !operatorEqualsImpl(lhs, rhs);
196 static bool operatorEqualsImpl(
const Property &,
const Property &);
198 std::unique_ptr<PropertyPrivate> d_ptr;
203 friend class QT_PREPEND_NAMESPACE(QQmlJSScope);
207 Element(
const Element &);
208 Element(Element &&other)
noexcept
210 memcpy(m_data, other.m_data, sizeofElement);
211 memset(other.m_data, 0, sizeofElement);
213 Element &operator=(
const Element &);
214 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Element)
217 ScopeType scopeType()
const;
218 Element baseType()
const;
219 QString baseTypeName()
const;
220 Element parentScope()
const;
221 bool inherits(
const Element &)
const;
222 bool isFileRootComponent()
const;
225 QString internalId()
const;
226 AccessSemantics accessSemantics()
const;
227 bool isComposite()
const;
229 bool hasProperty(
const QString &propertyName)
const;
230 bool hasOwnProperty(
const QString &propertyName)
const;
231 Property property(
const QString &propertyName)
const;
232 bool isPropertyRequired(
const QString &propertyName)
const;
233 QString defaultPropertyName()
const;
235 bool hasMethod(
const QString &methodName)
const;
236 Method::Methods ownMethods()
const;
238 QQmlSA::SourceLocation sourceLocation()
const;
239 QQmlSA::SourceLocation idSourceLocation()
const;
240 QString filePath()
const;
242 bool hasPropertyBindings(
const QString &name)
const;
243 bool hasOwnPropertyBindings(
const QString &propertyName)
const;
245 Binding::Bindings ownPropertyBindings()
const;
246 Binding::Bindings ownPropertyBindings(
const QString &propertyName)
const;
247 QList<Binding> propertyBindings(
const QString &propertyName)
const;
249 explicit operator
bool()
const;
250 bool operator!()
const;
252 QString name()
const;
254 friend inline bool operator==(
const QQmlSA::Element &lhs,
const QQmlSA::Element &rhs)
256 return operatorEqualsImpl(lhs, rhs);
258 friend inline bool operator!=(
const Element &lhs,
const Element &rhs) {
return !(lhs == rhs); }
260 friend inline qsizetype qHash(
const Element &key, qsizetype seed = 0)
noexcept
262 return qHashImpl(key, seed);
266 static bool operatorEqualsImpl(
const Element &,
const Element &);
267 static qsizetype qHashImpl(
const Element &key, qsizetype seed)
noexcept;
269 static constexpr qsizetype sizeofElement = 2 *
sizeof(QSharedPointer<
int>);
270 alignas(QSharedPointer<
int>)
char m_data[sizeofElement];
272 void swap(Element &other)
noexcept
274 char t[sizeofElement];
275 memcpy(t, m_data, sizeofElement);
276 memcpy(m_data, other.m_data, sizeofElement);
277 memcpy(other.m_data, t, sizeofElement);
279 friend void swap(Element &lhs, Element &rhs)
noexcept { lhs.swap(rhs); }
284 Q_DECLARE_PRIVATE(GenericPass)
285 Q_DISABLE_COPY_MOVE(GenericPass)
288 GenericPass(PassManager *manager);
289 virtual ~GenericPass();
291 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id);
292 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id,
293 QQmlSA::SourceLocation srcLocation);
294 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id,
295 QQmlSA::SourceLocation srcLocation,
const QQmlSA::FixSuggestion &fix);
310 std::unique_ptr<GenericPassPrivate> d_ptr;
315 Q_DISABLE_COPY_MOVE(PassManager)
316 Q_DECLARE_PRIVATE(PassManager)
319 void registerElementPass(std::unique_ptr<ElementPass> pass);
321 QAnyStringView typeName,
322 QAnyStringView propertyName = QAnyStringView(),
323 bool allowInheritance =
true);
324 void analyze(
const Element &root);
336 std::unique_ptr<PassManagerPrivate> d_ptr;
342 LintPlugin() =
default;
343 virtual ~LintPlugin() =
default;
345 Q_DISABLE_COPY_MOVE(LintPlugin)
347 virtual void registerPasses(PassManager *manager,
const Element &rootElement) = 0;
353 PropertyPass(PassManager *manager);
355 virtual void onBinding(
const QQmlSA::Element &element,
const QString &propertyName,
356 const QQmlSA::Binding &binding,
const QQmlSA::Element &bindingScope,
357 const QQmlSA::Element &value);
358 virtual void onRead(
const QQmlSA::Element &element,
const QString &propertyName,
359 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location);
360 virtual void onCall(
const QQmlSA::Element &element,
const QString &propertyName,
361 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location);
362 virtual void onWrite(
const QQmlSA::Element &element,
const QString &propertyName,
363 const QQmlSA::Element &value,
const QQmlSA::Element &writeScope,
364 QQmlSA::SourceLocation location);
370 ElementPass(PassManager *manager) : GenericPass(manager) { }
372 virtual bool shouldRun(
const Element &element);
373 virtual void run(
const Element &element) = 0;
378 void run(
const Element &element) override;
384 DebugPropertyPass(QQmlSA::PassManager *manager);
386 void onRead(
const QQmlSA::Element &element,
const QString &propertyName,
387 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override;
388 void onBinding(
const QQmlSA::Element &element,
const QString &propertyName,
389 const QQmlSA::Binding &binding,
const QQmlSA::Element &bindingScope,
390 const QQmlSA::Element &value) override;
391 void onWrite(
const QQmlSA::Element &element,
const QString &propertyName,
392 const QQmlSA::Element &value,
const QQmlSA::Element &writeScope,
393 QQmlSA::SourceLocation location) override;
398 Q_DECLARE_PRIVATE(FixSuggestion)
401 FixSuggestion(
const QString &fixDescription,
const QQmlSA::SourceLocation &location,
402 const QString &replacement = QString());
422 friend bool operator==(
const FixSuggestion &lhs,
const FixSuggestion &rhs)
424 return operatorEqualsImpl(lhs, rhs);
427 friend bool operator!=(
const FixSuggestion &lhs,
const FixSuggestion &rhs)
429 return !operatorEqualsImpl(lhs, rhs);
433 static bool operatorEqualsImpl(
const FixSuggestion &,
const FixSuggestion &);
435 std::unique_ptr<FixSuggestionPrivate> d_ptr;
440#define QmlLintPluginInterface_iid "org.qt-project.Qt.Qml.SA.LintPlugin/1.0"
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
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 QQmlSourceLocation sourceLocation() const
Element attachedType() const
Returns the attached type if the content type of this binding is AttachedProperty,...
BindingType bindingType() const
Returns the type of this binding.
Element bindingScope() const
Returns the Element scope in which the binding is defined.
friend bool operator!=(const Binding &lhs, const Binding &rhs)
Returns true if lhs and rhs are not equal, and false otherwise.
bool hasUndefinedScriptValue() const
Returns whether this binding has script value type undefined like when it is assigned undefined.
Binding(const Binding &)
Creates a copy of other.
Binding & operator=(const Binding &)
Assigns other to this Binding instance.
bool isAttached() const
Returns true if this type is attached to another one, false otherwise.
bool hasObject() const
Returns true if this binding has an objects, otherwise returns false.
friend bool operator==(const Binding &lhs, const Binding &rhs)
Returns true if lhs and rhs are equal, and false otherwise.
static bool isLiteralBinding(BindingType)
Returns true if bindingType is a literal type, and false otherwise.
QString propertyName() const
Returns the name of the property bound with this binding.
Binding()
Constructs a new Binding object.
QString stringValue() const
Returns the associated string literal if the content type of this binding is StringLiteral,...
Element objectType() const
Returns the type of the associated object if the content type of this binding is Object,...
Binding & operator=(Binding &&) noexcept
Move-assigns other to this Binding instance.
QQmlSA::SourceLocation sourceLocation() const
Returns the location in the QML code where this binding is defined.
ScriptBindingKind scriptKind() const
Returns the kind of the associated script if the content type of this binding is Script,...
double numberValue() const
Returns the associated number if the content type of this binding is NumberLiteral,...
Element groupType() const
Returns the type of the property of this binding if it is a group property, otherwise returns an inva...
bool hasFunctionScriptValue() const
Returns whether this binding has script value type function like when it is assigned a (lambda) metho...
void setHint(const QString &)
Sets hint as the hint for this fix suggestion.
FixSuggestion(const FixSuggestion &)
Creates a copy of other.
QString hint() const
Returns the hint for this fix suggestion.
QString replacement() const
Returns the fix that will replace the problematic source code.
QString fixDescription() const
Returns the description of the fix.
bool isAutoApplicable() const
Returns whether this suggested fix can be applied automatically.
void setAutoApplicable(bool autoApplicable=true)
Sets autoApplicable to determine whether this suggested fix can be applied automatically.
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id)
Emits a warning message diagnostic about an issue of type id.
Element resolveLiteralType(const Binding &binding)
Returns the element representing the type of literal in binding.
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...
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id, QQmlSA::SourceLocation srcLocation)
Emits warning message diagnostic about an issue of type id located at srcLocation.
Element resolveBuiltinType(QAnyStringView typeName) const
Returns the type of the built-in type identified by typeName.
Element resolveAttached(QAnyStringView moduleName, QAnyStringView typeName)
Returns the attached type of typeName defined in module moduleName.
QString resolveElementToId(const Element &element, const Element &context)
Returns the id of element in a given context.
Element resolveTypeInFileScope(QAnyStringView typeName)
Returns the type corresponding to typeName inside the currently analysed file.
QString sourceCode(QQmlSA::SourceLocation location)
Returns the source code located within location.
Element resolveAttachedInFileScope(QAnyStringView typeName)
Returns the attached type corresponding to typeName used inside the currently analysed file.
Element resolveIdToElement(QAnyStringView id, const Element &context)
Returns the element in context that has id id.
Element resolveType(QAnyStringView moduleName, QAnyStringView typeName)
Returns the type of typeName defined in module moduleName.
Method & operator=(Method &&) noexcept
Move-assigns other to this Method instance.
MethodType methodType() const
Returns the type of this method.
Method(const Method &)
Creates a copy of other.
Method()
Constructs a new Method object.
Method & operator=(const Method &)
Assigns other to this Method instance.
QString methodName() const
Returns the name of the this method.
void analyze(const Element &root)
Runs the element passes over root and all its children.
bool isCategoryEnabled(LoggerWarningId category) const
Returns true if warnings of category are enabled, false otherwise.
bool registerPropertyPass(std::shared_ptr< PropertyPass > pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName=QAnyStringView(), bool allowInheritance=true)
Registers a static analysis pass for properties.
std::unordered_map< quint32, Binding > bindingsByLocation() const
Returns bindings by their source location.
bool hasImportedModule(QAnyStringView name) const
Returns true if the module named module has been imported by the QML to be analyzed,...
Property(const Property &)
Creates a copy of other.
QString typeName() const
Returns the name of the type of this property.
bool isReadonly() const
Returns true if this property is read-only, false otherwise.
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
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)
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)
#define QmlLintPluginInterface_iid