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>
44class PassManagerPrivate;
47struct PropertyPassInfo;
90#if QT_DEPRECATED_SINCE(6
, 9
)
103 friend bool operator==(
const Binding &lhs,
const Binding &rhs)
105 return operatorEqualsImpl(lhs, rhs);
107 friend bool operator!=(
const Binding &lhs,
const Binding &rhs)
109 return !operatorEqualsImpl(lhs, rhs);
117 std::unique_ptr<BindingPrivate> d_ptr;
122 Q_DECLARE_PRIVATE(Method)
125 class Q_QMLCOMPILER_EXPORT Methods
127 Q_DECLARE_PRIVATE(Methods)
131 Methods(
const Methods &);
134 QMultiHash<QString, Method>::const_iterator begin()
const {
return constBegin(); }
135 QMultiHash<QString, Method>::const_iterator end()
const {
return constEnd(); }
136 QMultiHash<QString, Method>::const_iterator constBegin()
const;
137 QMultiHash<QString, Method>::const_iterator constEnd()
const;
140 std::unique_ptr<MethodsPrivate> d_ptr;
145 Method(Method &&)
noexcept;
154 friend bool operator==(
const Method &lhs,
const Method &rhs)
156 return operatorEqualsImpl(lhs, rhs);
158 friend bool operator!=(
const Method &lhs,
const Method &rhs)
160 return !operatorEqualsImpl(lhs, rhs);
164 static bool operatorEqualsImpl(
const Method &,
const Method &);
166 std::unique_ptr<MethodPrivate> d_ptr;
171 Q_DECLARE_PRIVATE(Property)
186 friend bool operator==(
const Property &lhs,
const Property &rhs)
188 return operatorEqualsImpl(lhs, rhs);
191 friend bool operator!=(
const Property &lhs,
const Property &rhs)
193 return !operatorEqualsImpl(lhs, rhs);
197 static bool operatorEqualsImpl(
const Property &,
const Property &);
199 std::unique_ptr<PropertyPrivate> d_ptr;
204 friend class QT_PREPEND_NAMESPACE(QQmlJSScope);
208 Element(
const Element &);
209 Element(Element &&other)
noexcept
211 memcpy(m_data, other.m_data, sizeofElement);
212 memset(other.m_data, 0, sizeofElement);
214 Element &operator=(
const Element &);
215 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Element)
218 ScopeType scopeType()
const;
219 Element baseType()
const;
220 QString baseTypeName()
const;
221 Element parentScope()
const;
222 bool inherits(
const Element &)
const;
223 bool isFileRootComponent()
const;
226 QString internalId()
const;
227 AccessSemantics accessSemantics()
const;
228 bool isComposite()
const;
230 bool hasProperty(
const QString &propertyName)
const;
231 bool hasOwnProperty(
const QString &propertyName)
const;
232 Property property(
const QString &propertyName)
const;
233 bool isPropertyRequired(
const QString &propertyName)
const;
234 QString defaultPropertyName()
const;
236 bool hasMethod(
const QString &methodName)
const;
237 Method::Methods ownMethods()
const;
239 QQmlSA::SourceLocation sourceLocation()
const;
240 QQmlSA::SourceLocation idSourceLocation()
const;
241 QString filePath()
const;
243 bool hasPropertyBindings(
const QString &name)
const;
244 bool hasOwnPropertyBindings(
const QString &propertyName)
const;
246 Binding::Bindings ownPropertyBindings()
const;
247 Binding::Bindings ownPropertyBindings(
const QString &propertyName)
const;
248 QList<Binding> propertyBindings(
const QString &propertyName)
const;
250 explicit operator
bool()
const;
251 bool operator!()
const;
253 QString name()
const;
255 friend inline bool operator==(
const QQmlSA::Element &lhs,
const QQmlSA::Element &rhs)
257 return operatorEqualsImpl(lhs, rhs);
259 friend inline bool operator!=(
const Element &lhs,
const Element &rhs) {
return !(lhs == rhs); }
261 friend inline qsizetype qHash(
const Element &key, qsizetype seed = 0)
noexcept
263 return qHashImpl(key, seed);
267 static bool operatorEqualsImpl(
const Element &,
const Element &);
268 static qsizetype qHashImpl(
const Element &key, qsizetype seed)
noexcept;
270 static constexpr qsizetype sizeofElement = 2 *
sizeof(QSharedPointer<
int>);
271 alignas(QSharedPointer<
int>)
char m_data[sizeofElement];
273 void swap(Element &other)
noexcept
275 char t[sizeofElement];
276 memcpy(t, m_data, sizeofElement);
277 memcpy(m_data, other.m_data, sizeofElement);
278 memcpy(other.m_data, t, sizeofElement);
280 friend void swap(Element &lhs, Element &rhs)
noexcept { lhs.swap(rhs); }
285 Q_DECLARE_PRIVATE(GenericPass)
286 Q_DISABLE_COPY_MOVE(GenericPass)
289 GenericPass(PassManager *manager);
290 virtual ~GenericPass();
292 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id);
293 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id,
294 QQmlSA::SourceLocation srcLocation);
295 void emitWarning(QAnyStringView diagnostic, LoggerWarningId id,
296 QQmlSA::SourceLocation srcLocation,
const QQmlSA::FixSuggestion &fix);
311 std::unique_ptr<GenericPassPrivate> d_ptr;
316 Q_DISABLE_COPY_MOVE(PassManager)
317 Q_DECLARE_PRIVATE(PassManager)
320 void registerElementPass(std::unique_ptr<ElementPass> pass);
322 QAnyStringView typeName,
323 QAnyStringView propertyName = QAnyStringView(),
324 bool allowInheritance =
true);
325 void analyze(
const Element &root);
337 std::unique_ptr<PassManagerPrivate> d_ptr;
343 LintPlugin() =
default;
344 virtual ~LintPlugin() =
default;
346 Q_DISABLE_COPY_MOVE(LintPlugin)
348 virtual void registerPasses(PassManager *manager,
const Element &rootElement) = 0;
354 PropertyPass(PassManager *manager);
356 virtual void onBinding(
const QQmlSA::Element &element,
const QString &propertyName,
357 const QQmlSA::Binding &binding,
const QQmlSA::Element &bindingScope,
358 const QQmlSA::Element &value);
359 virtual void onRead(
const QQmlSA::Element &element,
const QString &propertyName,
360 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location);
361 virtual void onCall(
const QQmlSA::Element &element,
const QString &propertyName,
362 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location);
363 virtual void onWrite(
const QQmlSA::Element &element,
const QString &propertyName,
364 const QQmlSA::Element &value,
const QQmlSA::Element &writeScope,
365 QQmlSA::SourceLocation location);
371 ElementPass(PassManager *manager) : GenericPass(manager) { }
373 virtual bool shouldRun(
const Element &element);
374 virtual void run(
const Element &element) = 0;
379 Q_DECLARE_PRIVATE(DocumentEdit)
380 Q_DECLARE_EQUALITY_COMPARABLE(DocumentEdit)
383 DocumentEdit(
const QString &filename,
const SourceLocation &location,
384 const QString &replacement);
396 friend bool comparesEqual(
const DocumentEdit &self,
const DocumentEdit &other)
noexcept
398 return self.filename() == other.filename() && self.location() == other.location()
399 && self.replacement() == other.replacement();
402 std::unique_ptr<DocumentEditPrivate> d_ptr;
407 Q_DECLARE_PRIVATE(FixSuggestion)
410 FixSuggestion(
const QString &description,
const QQmlSA::SourceLocation &location,
411 const DocumentEdit &documentEdit);
412 FixSuggestion(
const QString &description,
const QQmlSA::SourceLocation &location,
413 const QList<DocumentEdit> &documentEdits = {});
432 friend bool operator==(
const FixSuggestion &lhs,
const FixSuggestion &rhs)
434 return operatorEqualsImpl(lhs, rhs);
437 friend bool operator!=(
const FixSuggestion &lhs,
const FixSuggestion &rhs)
439 return !operatorEqualsImpl(lhs, rhs);
443 static bool operatorEqualsImpl(
const FixSuggestion &,
const FixSuggestion &);
445 std::unique_ptr<FixSuggestionPrivate> d_ptr;
450#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...
QString replacement() const
Returns the replacement string of the edit.
QString filename() const
Returns the file this edit applies to.
DocumentEdit(const DocumentEdit &)
Creates a copy of other.
FixSuggestion(const QString &description, const QQmlSA::SourceLocation &location, const QList< DocumentEdit > &documentEdits={})
Creates a FixSuggestion object.
void addDocumentEdit(const DocumentEdit &)
Adds a document edit to the list of edits for this fix.
FixSuggestion(const FixSuggestion &)
Creates a copy of other.
QString description() 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.
QList< DocumentEdit > documentEdits() const
Returns the list of document edits that applying this fix would make.
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.
@ SignalHandlerFunctionScope
Combined button and popup list for selecting options.
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)
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