2019-06-14 12:21:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
#include "findwarnings.h"
|
2019-11-11 16:35:09 +00:00
|
|
|
#include "importedmembersvisitor.h"
|
2019-06-14 12:21:25 +00:00
|
|
|
#include "scopetree.h"
|
2019-11-11 17:18:04 +00:00
|
|
|
#include "typedescriptionreader.h"
|
2020-03-30 15:42:48 +00:00
|
|
|
#include "checkidentifiers.h"
|
2020-08-12 10:36:15 +00:00
|
|
|
#include "qmljstypereader.h"
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
#include <QtQml/private/qqmljsast_p.h>
|
|
|
|
#include <QtQml/private/qqmljslexer_p.h>
|
|
|
|
#include <QtQml/private/qqmljsparser_p.h>
|
|
|
|
#include <QtQml/private/qv4codegen_p.h>
|
2020-06-10 14:25:16 +00:00
|
|
|
#include <QtQml/private/qqmlimportresolver_p.h>
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
#include <QtCore/qfile.h>
|
|
|
|
#include <QtCore/qdiriterator.h>
|
|
|
|
#include <QtCore/qscopedvaluerollback.h>
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::enterEnvironment(ScopeType type, const QString &name)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-09-25 08:13:26 +00:00
|
|
|
m_currentScope = ScopeTree::create(type, m_currentScope);
|
2020-09-25 10:39:17 +00:00
|
|
|
m_currentScope->setBaseTypeName(name);
|
|
|
|
m_currentScope->setIsComposite(true);
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::leaveEnvironment()
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
m_currentScope = m_currentScope->parentScope();
|
|
|
|
}
|
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
void FindWarningVisitor::importExportedNames(ScopeTree::ConstPtr scope)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-03-16 13:50:24 +00:00
|
|
|
QList<ScopeTree::ConstPtr> scopes;
|
2020-09-25 14:14:53 +00:00
|
|
|
while (!scope.isNull()) {
|
|
|
|
if (scopes.contains(scope)) {
|
|
|
|
QString inheritenceCycle;
|
|
|
|
for (const auto &seen: qAsConst(scopes)) {
|
|
|
|
if (!inheritenceCycle.isEmpty())
|
2020-03-16 13:50:24 +00:00
|
|
|
inheritenceCycle.append(QLatin1String(" -> "));
|
2020-09-25 14:14:53 +00:00
|
|
|
inheritenceCycle.append(seen->baseTypeName());
|
|
|
|
}
|
2020-03-16 13:50:24 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
if (m_warnInheritanceCycle) {
|
|
|
|
m_colorOut.write(QLatin1String("Warning: "), Warning);
|
|
|
|
m_colorOut.write(QString::fromLatin1("%1 is part of an inheritance cycle: %2\n")
|
|
|
|
.arg(scope->internalName())
|
|
|
|
.arg(inheritenceCycle));
|
|
|
|
}
|
2020-04-24 13:10:53 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
m_unknownImports.insert(scope->internalName());
|
|
|
|
m_visitFailed = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-24 13:10:53 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
scopes.append(scope);
|
|
|
|
|
|
|
|
const auto properties = scope->properties();
|
|
|
|
for (auto property : properties)
|
|
|
|
m_currentScope->insertPropertyIdentifier(property);
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
m_currentScope->addMethods(scope->methods());
|
2020-09-24 13:09:38 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
if (scope->baseTypeName().isEmpty()) {
|
|
|
|
break;
|
|
|
|
} else if (auto newScope = scope->baseType()) {
|
|
|
|
scope = newScope;
|
2019-06-14 12:21:25 +00:00
|
|
|
} else {
|
2020-09-28 10:40:33 +00:00
|
|
|
m_colorOut.write(QLatin1String("Warning: "), Warning);
|
2020-09-25 14:14:53 +00:00
|
|
|
m_colorOut.write(scope->baseTypeName()
|
|
|
|
+ QLatin1String(" was not found."
|
|
|
|
" Did you add all import paths?\n"));
|
|
|
|
m_unknownImports.insert(scope->baseTypeName());
|
2019-11-14 15:31:48 +00:00
|
|
|
m_visitFailed = true;
|
2019-06-14 12:21:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 12:44:24 +00:00
|
|
|
void FindWarningVisitor::flushPendingSignalParameters()
|
|
|
|
{
|
|
|
|
const SignalHandler handler = m_signalHandlers[m_pendingSingalHandler];
|
|
|
|
for (const QString ¶meter : handler.signal.parameterNames()) {
|
|
|
|
m_currentScope->insertJSIdentifier(
|
|
|
|
parameter, { JavaScriptIdentifier::Injected, m_pendingSingalHandler});
|
|
|
|
}
|
|
|
|
m_pendingSingalHandler = QQmlJS::SourceLocation();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::throwRecursionDepthError()
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-08-16 08:14:49 +00:00
|
|
|
m_colorOut.write(QStringLiteral("Error"), Error);
|
|
|
|
m_colorOut.write(QStringLiteral("Maximum statement or expression depth exceeded"), Error);
|
|
|
|
m_visitFailed = true;
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiProgram *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::QMLScope, "program");
|
2020-09-29 14:55:15 +00:00
|
|
|
m_rootScopeImports = m_importer.importBuiltins();
|
|
|
|
|
|
|
|
if (!m_qmltypesFiles.isEmpty()) {
|
|
|
|
const auto baseTypes = m_importer.importQmltypes(m_qmltypesFiles);
|
2020-09-29 15:56:46 +00:00
|
|
|
m_rootScopeImports.insert(baseTypes);
|
2020-09-29 14:55:15 +00:00
|
|
|
}
|
2020-03-26 09:57:12 +00:00
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
// add "self" (as we only ever check the first part of a qualified identifier, we get away with
|
2019-11-11 17:18:04 +00:00
|
|
|
// using an empty ScopeTree
|
2020-09-29 15:56:46 +00:00
|
|
|
m_rootScopeImports.insert(QFileInfo { m_filePath }.baseName(), {});
|
2020-09-24 13:09:38 +00:00
|
|
|
|
2020-09-29 14:26:07 +00:00
|
|
|
const auto imported = m_importer.importFileOrDirectory(QFileInfo(m_filePath).path());
|
2020-09-29 15:56:46 +00:00
|
|
|
m_rootScopeImports.insert(imported);
|
2020-09-24 08:45:58 +00:00
|
|
|
|
|
|
|
const QStringList warnings = m_importer.takeWarnings();
|
|
|
|
for (const QString &warning : warnings) {
|
|
|
|
m_colorOut.write(QStringLiteral("warning: "), Warning);
|
|
|
|
m_colorOut.writeUncolored(warning);
|
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::UiProgram *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::ClassExpression *ast)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSFunctionScope, ast->name.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::ClassExpression *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::ClassDeclaration *ast)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSFunctionScope, ast->name.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::ClassDeclaration *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::ForStatement *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "forloop");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::ForStatement *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::ForEachStatement *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "foreachloop");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::ForEachStatement *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-09-30 12:44:24 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::ExpressionStatement *)
|
|
|
|
{
|
|
|
|
if (m_pendingSingalHandler.isValid()) {
|
|
|
|
enterEnvironment(ScopeType::JSFunctionScope, "signalhandler");
|
|
|
|
flushPendingSignalParameters();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::ExpressionStatement *)
|
|
|
|
{
|
|
|
|
if (m_currentScope->scopeType() == ScopeType::JSFunctionScope
|
|
|
|
&& m_currentScope->baseTypeName() == "signalhandler") {
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::Block *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "block");
|
2020-09-30 12:44:24 +00:00
|
|
|
if (m_pendingSingalHandler.isValid())
|
|
|
|
flushPendingSignalParameters();
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::Block *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::CaseBlock *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "case");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::CaseBlock *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::Catch *catchStatement)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "catch");
|
2020-09-30 12:44:24 +00:00
|
|
|
m_currentScope->insertJSIdentifier(
|
|
|
|
catchStatement->patternElement->bindingIdentifier.toString(), {
|
|
|
|
JavaScriptIdentifier::LexicalScoped,
|
|
|
|
catchStatement->patternElement->firstSourceLocation()
|
|
|
|
});
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::Catch *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::WithStatement *withStatement)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-04-24 13:10:53 +00:00
|
|
|
if (m_warnWithStatement) {
|
|
|
|
m_colorOut.write(QString::fromLatin1("Warning: "), Warning);
|
|
|
|
m_colorOut.write(QString::fromLatin1(
|
|
|
|
"%1:%2: with statements are strongly discouraged in QML "
|
|
|
|
"and might cause false positives when analysing unqalified identifiers\n")
|
|
|
|
.arg(withStatement->firstSourceLocation().startLine)
|
|
|
|
.arg(withStatement->firstSourceLocation().startColumn),
|
|
|
|
Normal);
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
enterEnvironment(ScopeType::JSLexicalScope, "with");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::WithStatement *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2019-12-17 08:29:31 +00:00
|
|
|
static QString signalName(QStringView handlerName)
|
2019-08-16 09:31:51 +00:00
|
|
|
{
|
2019-12-17 08:29:31 +00:00
|
|
|
if (handlerName.startsWith(u"on") && handlerName.size() > 2) {
|
2019-08-16 09:31:51 +00:00
|
|
|
QString signal = handlerName.mid(2).toString();
|
|
|
|
for (int i = 0; i < signal.length(); ++i) {
|
2019-12-17 08:29:31 +00:00
|
|
|
QChar &ch = signal[i];
|
2019-08-16 09:31:51 +00:00
|
|
|
if (ch.isLower())
|
|
|
|
return QString();
|
|
|
|
if (ch.isUpper()) {
|
|
|
|
ch = ch.toLower();
|
|
|
|
return signal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiScriptBinding *uisb)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
using namespace QQmlJS::AST;
|
|
|
|
auto name = uisb->qualifiedId->name;
|
|
|
|
if (name == QLatin1String("id")) {
|
|
|
|
// found id
|
2019-11-11 17:18:04 +00:00
|
|
|
auto expstat = cast<ExpressionStatement *>(uisb->statement);
|
|
|
|
auto identexp = cast<IdentifierExpression *>(expstat->expression);
|
2019-11-08 13:48:32 +00:00
|
|
|
m_qmlid2scope.insert(identexp->name.toString(), m_currentScope);
|
2020-09-30 08:50:11 +00:00
|
|
|
|
|
|
|
// Figure out whether the current scope is the root scope.
|
|
|
|
if (auto parentScope = m_currentScope->parentScope()) {
|
|
|
|
if (auto grandParentScope = parentScope->parentScope()) {
|
|
|
|
if (!grandParentScope->parentScope())
|
|
|
|
m_rootId = identexp->name.toString();
|
|
|
|
}
|
|
|
|
}
|
2019-08-16 09:31:51 +00:00
|
|
|
} else {
|
|
|
|
const QString signal = signalName(name);
|
|
|
|
if (signal.isEmpty())
|
|
|
|
return true;
|
|
|
|
|
2020-09-30 13:03:04 +00:00
|
|
|
if (!m_currentScope->methods().contains(signal) && m_warnUnqualified) {
|
|
|
|
const auto location = uisb->firstSourceLocation();
|
|
|
|
m_colorOut.write(QLatin1String("Warning: "), Warning);
|
|
|
|
m_colorOut.write(QString::fromLatin1(
|
|
|
|
"no matching signal found for handler \"%1\" at %2:%3:%4\n")
|
|
|
|
.arg(name.toString()).arg(m_filePath).arg(location.startLine)
|
|
|
|
.arg(location.startColumn), Normal);
|
|
|
|
CheckIdentifiers::printContext(m_code, &m_colorOut, location);
|
2019-08-16 09:31:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto statement = uisb->statement;
|
2019-06-14 12:21:25 +00:00
|
|
|
if (statement->kind == Node::Kind::Kind_ExpressionStatement) {
|
2019-11-11 17:18:04 +00:00
|
|
|
if (cast<ExpressionStatement *>(statement)->expression->asFunctionDefinition()) {
|
2019-06-14 12:21:25 +00:00
|
|
|
// functions are already handled
|
|
|
|
// they do not get names inserted according to the signal, but access their formal
|
|
|
|
// parameters
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-08-16 09:31:51 +00:00
|
|
|
|
2020-04-09 16:43:43 +00:00
|
|
|
const auto methods = m_currentScope->methods();
|
|
|
|
const auto methodsRange = methods.equal_range(signal);
|
|
|
|
for (auto method = methodsRange.first; method != methodsRange.second; ++method) {
|
|
|
|
if (method->methodType() != MetaMethod::Signal)
|
|
|
|
continue;
|
2020-09-30 12:44:24 +00:00
|
|
|
|
|
|
|
const auto firstSourceLocation = statement->firstSourceLocation();
|
|
|
|
bool hasMultilineStatementBody
|
|
|
|
= statement->lastSourceLocation().startLine > firstSourceLocation.startLine;
|
|
|
|
m_pendingSingalHandler = firstSourceLocation;
|
|
|
|
m_signalHandlers.insert(firstSourceLocation, {*method, hasMultilineStatementBody});
|
|
|
|
break; // If there are multiple candidates for the signal, it's a mess anyway.
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiPublicMember *uipm)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-08-18 19:22:10 +00:00
|
|
|
if (uipm->type == QQmlJS::AST::UiPublicMember::Signal) {
|
|
|
|
MetaMethod method;
|
|
|
|
method.setMethodType(MetaMethod::Signal);
|
|
|
|
method.setMethodName(uipm->name.toString());
|
|
|
|
QQmlJS::AST::UiParameterList *param = uipm->parameters;
|
|
|
|
while (param) {
|
|
|
|
method.addParameter(param->name.toString(), param->type->name.toString());
|
|
|
|
param = param->next;
|
|
|
|
}
|
|
|
|
m_currentScope->addMethod(method);
|
|
|
|
} else {
|
|
|
|
// property bool inactive: !active
|
|
|
|
// extract name inactive
|
|
|
|
MetaProperty property(
|
2019-11-11 17:18:04 +00:00
|
|
|
uipm->name.toString(),
|
2020-08-18 19:22:10 +00:00
|
|
|
// TODO: complex types etc.
|
2019-11-11 17:18:04 +00:00
|
|
|
uipm->memberType ? uipm->memberType->name.toString() : QString(),
|
2020-08-18 19:22:10 +00:00
|
|
|
uipm->typeModifier == QLatin1String("list"), !uipm->isReadonlyMember, false,
|
|
|
|
uipm->memberType ? (uipm->memberType->name == QLatin1String("alias")) : false, 0);
|
2020-09-29 15:56:46 +00:00
|
|
|
property.setType(m_rootScopeImports.value(property.typeName()));
|
2020-08-18 19:22:10 +00:00
|
|
|
m_currentScope->insertPropertyIdentifier(property);
|
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::IdentifierExpression *idexp)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-09-30 13:31:43 +00:00
|
|
|
m_memberAccessChains[m_currentScope].append(
|
|
|
|
{{idexp->name.toString(), QString(), idexp->firstSourceLocation()}});
|
2019-11-08 13:48:32 +00:00
|
|
|
m_fieldMemberBase = idexp;
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-22 16:38:43 +00:00
|
|
|
FindWarningVisitor::FindWarningVisitor(
|
2020-09-29 14:55:15 +00:00
|
|
|
QStringList qmlImportPaths, QStringList qmltypesFiles, QString code, QString fileName,
|
2020-06-22 16:38:43 +00:00
|
|
|
bool silent, bool warnUnqualified, bool warnWithStatement, bool warnInheritanceCycle)
|
2020-09-25 08:13:26 +00:00
|
|
|
: m_rootScope(ScopeTree::create(ScopeType::JSFunctionScope)),
|
2020-06-22 16:38:43 +00:00
|
|
|
m_qmltypesFiles(std::move(qmltypesFiles)),
|
2019-11-11 17:18:04 +00:00
|
|
|
m_code(std::move(code)),
|
2019-06-14 12:21:25 +00:00
|
|
|
m_rootId(QLatin1String("<id>")),
|
2019-11-11 17:18:04 +00:00
|
|
|
m_filePath(std::move(fileName)),
|
2020-04-24 13:10:53 +00:00
|
|
|
m_colorOut(silent),
|
|
|
|
m_warnUnqualified(warnUnqualified),
|
|
|
|
m_warnWithStatement(warnWithStatement),
|
2020-09-24 08:45:58 +00:00
|
|
|
m_warnInheritanceCycle(warnInheritanceCycle),
|
2020-09-29 14:55:15 +00:00
|
|
|
m_importer(qmlImportPaths)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-09-25 08:13:26 +00:00
|
|
|
m_rootScope->setInternalName("global");
|
2020-03-31 13:46:20 +00:00
|
|
|
m_currentScope = m_rootScope;
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
// setup color output
|
2019-11-11 17:18:04 +00:00
|
|
|
m_colorOut.insertMapping(Error, ColorOutput::RedForeground);
|
|
|
|
m_colorOut.insertMapping(Warning, ColorOutput::PurpleForeground);
|
|
|
|
m_colorOut.insertMapping(Info, ColorOutput::BlueForeground);
|
|
|
|
m_colorOut.insertMapping(Normal, ColorOutput::DefaultColor);
|
|
|
|
m_colorOut.insertMapping(Hint, ColorOutput::GreenForeground);
|
2019-06-14 12:21:25 +00:00
|
|
|
QLatin1String jsGlobVars[] = {
|
2019-07-24 06:42:17 +00:00
|
|
|
/* Not listed on the MDN page; browser and QML extensions: */
|
|
|
|
// console/debug api
|
|
|
|
QLatin1String("console"), QLatin1String("print"),
|
|
|
|
// garbage collector
|
|
|
|
QLatin1String("gc"),
|
|
|
|
// i18n
|
2019-11-11 17:18:04 +00:00
|
|
|
QLatin1String("qsTr"), QLatin1String("qsTrId"), QLatin1String("QT_TR_NOOP"),
|
|
|
|
QLatin1String("QT_TRANSLATE_NOOP"), QLatin1String("QT_TRID_NOOP"),
|
2019-07-24 06:42:17 +00:00
|
|
|
// XMLHttpRequest
|
|
|
|
QLatin1String("XMLHttpRequest")
|
2019-06-14 12:21:25 +00:00
|
|
|
};
|
2020-09-30 12:44:24 +00:00
|
|
|
|
|
|
|
JavaScriptIdentifier globalJavaScript = {
|
|
|
|
JavaScriptIdentifier::LexicalScoped,
|
|
|
|
QQmlJS::SourceLocation()
|
|
|
|
};
|
2019-11-11 17:18:04 +00:00
|
|
|
for (const char **globalName = QV4::Compiler::Codegen::s_globalNames;
|
|
|
|
*globalName != nullptr;
|
|
|
|
++globalName) {
|
2020-09-30 12:44:24 +00:00
|
|
|
m_currentScope->insertJSIdentifier(QString::fromLatin1(*globalName), globalJavaScript);
|
2019-07-24 06:42:17 +00:00
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
for (const auto& jsGlobVar: jsGlobVars)
|
2020-09-30 12:44:24 +00:00
|
|
|
m_currentScope->insertJSIdentifier(jsGlobVar, globalJavaScript);
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::check()
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-08-16 08:14:49 +00:00
|
|
|
if (m_visitFailed)
|
|
|
|
return false;
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
// now that all ids are known, revisit any Connections whose target were perviously unknown
|
2019-11-11 17:18:04 +00:00
|
|
|
for (auto const &outstandingConnection: m_outstandingConnections) {
|
|
|
|
auto targetScope = m_qmlid2scope[outstandingConnection.targetName];
|
2020-05-06 11:21:21 +00:00
|
|
|
if (outstandingConnection.scope && targetScope != nullptr)
|
2019-11-11 17:18:04 +00:00
|
|
|
outstandingConnection.scope->addMethods(targetScope->methods());
|
2020-03-31 13:46:20 +00:00
|
|
|
QScopedValueRollback<ScopeTree::Ptr> rollback(m_currentScope, outstandingConnection.scope);
|
2019-06-14 12:21:25 +00:00
|
|
|
outstandingConnection.uiod->initializer->accept(this);
|
|
|
|
}
|
2020-03-30 15:42:48 +00:00
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
if (!m_warnUnqualified)
|
|
|
|
return true;
|
|
|
|
|
2020-09-25 10:39:17 +00:00
|
|
|
CheckIdentifiers check(&m_colorOut, m_code, m_rootScopeImports, m_filePath);
|
2020-09-30 13:31:43 +00:00
|
|
|
return check(m_qmlid2scope, m_signalHandlers, m_memberAccessChains, m_rootScope, m_rootId);
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::VariableDeclarationList *vdl)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
while (vdl) {
|
2020-03-30 15:42:48 +00:00
|
|
|
m_currentScope->insertJSIdentifier(
|
|
|
|
vdl->declaration->bindingIdentifier.toString(),
|
2020-09-30 12:44:24 +00:00
|
|
|
{
|
|
|
|
(vdl->declaration->scope == QQmlJS::AST::VariableScope::Var)
|
|
|
|
? JavaScriptIdentifier::FunctionScoped
|
|
|
|
: JavaScriptIdentifier::LexicalScoped,
|
|
|
|
vdl->declaration->firstSourceLocation()
|
|
|
|
});
|
2019-06-14 12:21:25 +00:00
|
|
|
vdl = vdl->next;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::visitFunctionExpressionHelper(QQmlJS::AST::FunctionExpression *fexpr)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
using namespace QQmlJS::AST;
|
2019-11-11 17:18:04 +00:00
|
|
|
auto name = fexpr->name.toString();
|
|
|
|
if (!name.isEmpty()) {
|
2020-09-30 12:44:24 +00:00
|
|
|
if (m_currentScope->scopeType() == ScopeType::QMLScope) {
|
2019-11-11 17:18:04 +00:00
|
|
|
m_currentScope->addMethod(MetaMethod(name, QLatin1String("void")));
|
2020-09-30 12:44:24 +00:00
|
|
|
} else {
|
|
|
|
m_currentScope->insertJSIdentifier(
|
|
|
|
name,
|
|
|
|
{ JavaScriptIdentifier::LexicalScoped, fexpr->firstSourceLocation() });
|
|
|
|
}
|
2019-11-11 17:18:04 +00:00
|
|
|
enterEnvironment(ScopeType::JSFunctionScope, name);
|
|
|
|
} else {
|
|
|
|
enterEnvironment(ScopeType::JSFunctionScope, QLatin1String("<anon>"));
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::FunctionExpression *fexpr)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
visitFunctionExpressionHelper(fexpr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::FunctionExpression *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::FunctionDeclaration *fdecl)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
visitFunctionExpressionHelper(fdecl);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::FunctionDeclaration *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
leaveEnvironment();
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::FormalParameterList *fpl)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2020-09-30 12:44:24 +00:00
|
|
|
for (auto const &boundName : fpl->boundNames()) {
|
|
|
|
m_currentScope->insertJSIdentifier(
|
|
|
|
boundName.id,
|
|
|
|
{JavaScriptIdentifier::Parameter, fpl->firstSourceLocation() });
|
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
// construct path
|
|
|
|
QString prefix = QLatin1String("");
|
|
|
|
if (import->asToken.isValid()) {
|
2019-11-08 17:43:31 +00:00
|
|
|
prefix += import->importId;
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
2020-09-29 14:26:07 +00:00
|
|
|
auto filename = import->fileName.toString();
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
const QFileInfo file(filename);
|
|
|
|
const auto imported = m_importer.importFileOrDirectory(
|
|
|
|
file.isRelative() ? QFileInfo(m_filePath).dir().filePath(filename) : filename,
|
|
|
|
prefix);
|
2020-09-29 15:56:46 +00:00
|
|
|
m_rootScopeImports.insert(imported);
|
2020-09-24 13:09:38 +00:00
|
|
|
}
|
2019-08-16 15:03:30 +00:00
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
QString path {};
|
|
|
|
if (!import->importId.isEmpty()) {
|
2019-11-11 17:18:04 +00:00
|
|
|
// TODO: do not put imported ids into the same space as qml IDs
|
2019-11-08 13:48:32 +00:00
|
|
|
const QString importId = import->importId.toString();
|
2020-09-29 15:56:46 +00:00
|
|
|
m_qmlid2scope.insert(importId, m_rootScopeImports.value(importId));
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
2020-06-22 16:38:43 +00:00
|
|
|
auto uri = import->importUri;
|
|
|
|
while (uri) {
|
|
|
|
path.append(uri->name);
|
|
|
|
path.append("/");
|
|
|
|
uri = uri->next;
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
2020-06-22 16:38:43 +00:00
|
|
|
path.chop(1);
|
|
|
|
|
2020-09-24 13:09:38 +00:00
|
|
|
const auto imported = m_importer.importModule(
|
|
|
|
path, prefix, import->version ? import->version->version : QTypeRevision());
|
|
|
|
|
2020-09-29 15:56:46 +00:00
|
|
|
m_rootScopeImports.insert(imported);
|
2020-09-24 08:45:58 +00:00
|
|
|
|
|
|
|
const QStringList warnings = m_importer.takeWarnings();
|
|
|
|
for (const QString &warning : warnings) {
|
|
|
|
m_colorOut.write(QStringLiteral("warning: "), Warning);
|
|
|
|
m_colorOut.writeUncolored(warning);
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiEnumDeclaration *uied)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-11-11 17:18:04 +00:00
|
|
|
MetaEnum qmlEnum(uied->name.toString());
|
|
|
|
for (const auto *member = uied->members; member; member = member->next)
|
|
|
|
qmlEnum.addKey(member->member.toString());
|
|
|
|
m_currentScope->addEnum(qmlEnum);
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
|
|
|
// property QtObject __styleData: QtObject {...}
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
QString name;
|
|
|
|
for (auto id = uiob->qualifiedTypeNameId; id; id = id->next)
|
2019-06-14 12:21:25 +00:00
|
|
|
name += id->name.toString() + QLatin1Char('.');
|
2020-09-25 14:14:53 +00:00
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
name.chop(1);
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2019-11-11 16:35:09 +00:00
|
|
|
MetaProperty prop(uiob->qualifiedId->name.toString(), name, false, true, true,
|
|
|
|
name == QLatin1String("alias"), 0);
|
2020-09-29 15:56:46 +00:00
|
|
|
prop.setType(m_rootScopeImports.value(uiob->qualifiedTypeNameId->name.toString()));
|
2019-11-11 17:18:04 +00:00
|
|
|
m_currentScope->addProperty(prop);
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
enterEnvironment(ScopeType::QMLScope, name);
|
2020-09-29 15:56:46 +00:00
|
|
|
m_currentScope->resolveTypes(m_rootScopeImports);
|
2020-09-25 14:14:53 +00:00
|
|
|
importExportedNames(m_currentScope);
|
2019-06-14 12:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::UiObjectBinding *uiob)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-11-08 13:48:32 +00:00
|
|
|
const auto childScope = m_currentScope;
|
2019-06-14 12:21:25 +00:00
|
|
|
leaveEnvironment();
|
2019-11-08 13:48:32 +00:00
|
|
|
MetaProperty property(uiob->qualifiedId->name.toString(),
|
|
|
|
uiob->qualifiedTypeNameId->name.toString(),
|
2019-11-11 16:35:09 +00:00
|
|
|
false, true, true,
|
|
|
|
uiob->qualifiedTypeNameId->name == QLatin1String("alias"),
|
|
|
|
0);
|
2019-11-08 13:48:32 +00:00
|
|
|
property.setType(childScope);
|
|
|
|
m_currentScope->addProperty(property);
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-11-11 17:18:04 +00:00
|
|
|
using namespace QQmlJS::AST;
|
|
|
|
|
2020-09-25 14:14:53 +00:00
|
|
|
QString name;
|
|
|
|
for (auto id = uiod->qualifiedTypeNameId; id; id = id->next)
|
2019-06-14 12:21:25 +00:00
|
|
|
name += id->name.toString() + QLatin1Char('.');
|
2020-09-25 14:14:53 +00:00
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
name.chop(1);
|
|
|
|
enterEnvironment(ScopeType::QMLScope, name);
|
|
|
|
if (name.isLower())
|
|
|
|
return false; // Ignore grouped properties for now
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2020-09-29 15:56:46 +00:00
|
|
|
m_currentScope->resolveTypes(m_rootScopeImports);
|
2020-10-02 08:27:38 +00:00
|
|
|
importExportedNames(m_currentScope);
|
|
|
|
|
2019-06-14 12:21:25 +00:00
|
|
|
if (name.endsWith("Connections")) {
|
|
|
|
QString target;
|
|
|
|
auto member = uiod->initializer->members;
|
|
|
|
while (member) {
|
|
|
|
if (member->member->kind == QQmlJS::AST::Node::Kind_UiScriptBinding) {
|
|
|
|
auto asBinding = static_cast<QQmlJS::AST::UiScriptBinding*>(member->member);
|
|
|
|
if (asBinding->qualifiedId->name == QLatin1String("target")) {
|
|
|
|
if (asBinding->statement->kind == QQmlJS::AST::Node::Kind_ExpressionStatement) {
|
|
|
|
auto expr = static_cast<QQmlJS::AST::ExpressionStatement*>(asBinding->statement)->expression;
|
|
|
|
if (auto idexpr = QQmlJS::AST::cast<QQmlJS::AST::IdentifierExpression*>(expr)) {
|
|
|
|
target = idexpr->name.toString();
|
|
|
|
} else {
|
|
|
|
// more complex expressions are not supported
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
member = member->next;
|
|
|
|
}
|
2020-03-31 13:46:20 +00:00
|
|
|
ScopeTree::ConstPtr targetScope;
|
2019-06-14 12:21:25 +00:00
|
|
|
if (target.isEmpty()) {
|
|
|
|
// no target set, connection comes from parentF
|
2020-03-31 13:46:20 +00:00
|
|
|
ScopeTree::Ptr scope = m_currentScope;
|
2019-06-14 12:21:25 +00:00
|
|
|
do {
|
|
|
|
scope = scope->parentScope(); // TODO: rename method
|
|
|
|
} while (scope->scopeType() != ScopeType::QMLScope);
|
2020-09-29 15:56:46 +00:00
|
|
|
targetScope = m_rootScopeImports.value(scope->baseTypeName());
|
2019-06-14 12:21:25 +00:00
|
|
|
} else {
|
|
|
|
// there was a target, check if we already can find it
|
2019-11-11 17:18:04 +00:00
|
|
|
auto scopeIt = m_qmlid2scope.find(target);
|
|
|
|
if (scopeIt != m_qmlid2scope.end()) {
|
|
|
|
targetScope = *scopeIt;
|
2019-06-14 12:21:25 +00:00
|
|
|
} else {
|
|
|
|
m_outstandingConnections.push_back({target, m_currentScope, uiod});
|
|
|
|
return false; // visit children later once target is known
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 17:18:04 +00:00
|
|
|
if (targetScope)
|
|
|
|
m_currentScope->addMethods(targetScope->methods());
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::PatternElement *element)
|
2019-09-17 15:13:18 +00:00
|
|
|
{
|
|
|
|
if (element->isVariableDeclaration()) {
|
|
|
|
QQmlJS::AST::BoundNames names;
|
|
|
|
element->boundNames(&names);
|
2020-03-30 15:42:48 +00:00
|
|
|
for (const auto &name : names) {
|
|
|
|
m_currentScope->insertJSIdentifier(
|
2020-09-30 12:44:24 +00:00
|
|
|
name.id, {
|
|
|
|
(element->scope == QQmlJS::AST::VariableScope::Var)
|
|
|
|
? JavaScriptIdentifier::FunctionScoped
|
|
|
|
: JavaScriptIdentifier::LexicalScoped,
|
|
|
|
element->firstSourceLocation()
|
|
|
|
});
|
2020-03-30 15:42:48 +00:00
|
|
|
}
|
2019-09-17 15:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::UiObjectDefinition *)
|
2019-06-14 12:21:25 +00:00
|
|
|
{
|
2019-11-14 14:59:56 +00:00
|
|
|
auto childScope = m_currentScope;
|
2019-06-14 12:21:25 +00:00
|
|
|
leaveEnvironment();
|
2020-10-02 09:17:29 +00:00
|
|
|
|
|
|
|
if (m_currentScope->baseTypeName() == QStringLiteral("Component")
|
|
|
|
|| m_currentScope->baseTypeName() == QStringLiteral("program")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto properties = childScope->properties();
|
|
|
|
const auto it = properties.find(QStringLiteral("parent"));
|
|
|
|
if (it != properties.end()) {
|
|
|
|
auto property = *it;
|
|
|
|
property.setType(m_currentScope);
|
|
|
|
childScope->addProperty(property);
|
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
2019-11-08 13:48:32 +00:00
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::FieldMemberExpression *)
|
2019-11-08 13:48:32 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::FieldMemberExpression *fieldMember)
|
2019-11-08 13:48:32 +00:00
|
|
|
{
|
2019-11-15 15:59:46 +00:00
|
|
|
using namespace QQmlJS::AST;
|
|
|
|
ExpressionNode *base = fieldMember->base;
|
|
|
|
while (auto *nested = cast<NestedExpression *>(base))
|
|
|
|
base = nested->expression;
|
|
|
|
|
|
|
|
if (m_fieldMemberBase == base) {
|
|
|
|
QString type;
|
|
|
|
if (auto *binary = cast<BinaryExpression *>(base)) {
|
|
|
|
if (binary->op == QSOperator::As) {
|
2020-05-18 14:47:34 +00:00
|
|
|
if (auto *right = cast<TypeExpression *>(binary->right))
|
|
|
|
type = right->m_type->toString();
|
2019-11-15 15:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-30 13:31:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
auto &chain = m_memberAccessChains[m_currentScope];
|
|
|
|
Q_ASSERT(!chain.last().isEmpty());
|
|
|
|
chain.last().append(FieldMember {
|
|
|
|
fieldMember->name.toString(), type, fieldMember->identifierToken
|
|
|
|
});
|
2019-11-08 13:48:32 +00:00
|
|
|
m_fieldMemberBase = fieldMember;
|
|
|
|
} else {
|
|
|
|
m_fieldMemberBase = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 15:59:46 +00:00
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
bool FindWarningVisitor::visit(QQmlJS::AST::BinaryExpression *)
|
2019-11-15 15:59:46 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
void FindWarningVisitor::endVisit(QQmlJS::AST::BinaryExpression *binExp)
|
2019-11-15 15:59:46 +00:00
|
|
|
{
|
|
|
|
if (binExp->op == QSOperator::As && m_fieldMemberBase == binExp->left)
|
|
|
|
m_fieldMemberBase = binExp;
|
|
|
|
else
|
|
|
|
m_fieldMemberBase = nullptr;
|
|
|
|
}
|