2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2021-06-29 11:19:21 +00:00
|
|
|
|
|
|
|
#include "qqmljsregistercontent_p.h"
|
|
|
|
#include "qqmljstyperesolver_p.h"
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2022-03-21 09:21:18 +00:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2021-06-29 11:19:21 +00:00
|
|
|
QString QQmlJSRegisterContent::descriptiveName() const
|
|
|
|
{
|
2022-04-06 09:52:25 +00:00
|
|
|
if (m_storedType.isNull())
|
2022-03-21 09:21:18 +00:00
|
|
|
return u"(invalid type)"_s;
|
2022-04-06 09:52:25 +00:00
|
|
|
|
2022-03-21 09:21:18 +00:00
|
|
|
QString result = m_storedType->internalName() + u" of "_s;
|
2021-06-29 11:19:21 +00:00
|
|
|
const auto scope = [this]() -> QString {
|
2022-04-06 09:52:25 +00:00
|
|
|
if (m_scope.isNull())
|
2022-03-21 09:21:18 +00:00
|
|
|
return u"(invalid type)::"_s;
|
2021-06-29 11:19:21 +00:00
|
|
|
return (m_scope->internalName().isEmpty()
|
2022-02-24 09:37:01 +00:00
|
|
|
? (m_scope->filePath().isEmpty()
|
2022-03-21 09:21:18 +00:00
|
|
|
? u"??"_s
|
|
|
|
: (u"(component in "_s + m_scope->filePath() + u")"_s))
|
2021-06-29 11:19:21 +00:00
|
|
|
: m_scope->internalName())
|
2022-03-21 09:21:18 +00:00
|
|
|
+ u"::"_s;
|
2021-06-29 11:19:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Type:
|
|
|
|
return result + std::get<QQmlJSScope::ConstPtr>(m_content)->internalName();
|
|
|
|
case Property: {
|
|
|
|
const QQmlJSMetaProperty prop = std::get<QQmlJSMetaProperty>(m_content);
|
2022-03-21 09:21:18 +00:00
|
|
|
return result + scope() + prop.propertyName() + u" with type "_s + prop.typeName();
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
|
|
|
case Method: {
|
|
|
|
const auto methods = std::get<QList<QQmlJSMetaMethod>>(m_content);
|
|
|
|
if (methods.isEmpty())
|
2022-03-21 09:21:18 +00:00
|
|
|
return result + scope() + u"(unknown method)"_s;
|
2021-06-29 11:19:21 +00:00
|
|
|
else
|
2022-03-21 09:21:18 +00:00
|
|
|
return result + scope() + methods[0].methodName() + u"(...)"_s;
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
|
|
|
case Enum: {
|
|
|
|
const auto e = std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content);
|
|
|
|
if (e.second.isEmpty())
|
|
|
|
return result + scope() + e.first.name();
|
|
|
|
else
|
2022-03-21 09:21:18 +00:00
|
|
|
return result + scope() + e.first.name() + u"::"_s + e.second;
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
2021-08-16 06:53:39 +00:00
|
|
|
case ImportNamespace: {
|
2022-03-21 09:21:18 +00:00
|
|
|
return u"import namespace %1"_s.arg(std::get<uint>(m_content));
|
2021-08-16 06:53:39 +00:00
|
|
|
}
|
2022-02-04 20:46:07 +00:00
|
|
|
case Conversion: {
|
2022-03-21 09:21:18 +00:00
|
|
|
return u"conversion to %1"_s.arg(
|
2022-02-04 20:46:07 +00:00
|
|
|
std::get<ConvertedTypes>(m_content).result->internalName());
|
|
|
|
}
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
Port to new Q_UNREACHABLE_RETURN()
This is a semantic patch using ClangTidyTransformator to convert
sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(),
newly added to qtbase.
const std::string unr = "unr", val = "val", ret = "ret";
auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(",
ifBound(val, cat(node(val)), cat("")),
")");
auto ignoringSwitchCases = [](auto stmt) {
return anyOf(stmt, switchCase(subStmt(stmt)));
};
makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)),
nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))),
{changeTo(node(unr), cat(makeUnreachableReturn,
";")), // TODO: why is the ; lost w/o this?
changeTo(node(ret), cat(""))},
cat("use ", makeUnreachableReturn));
a.k.a qt-use-unreachable-return.
subStmt() and nextStmt() are non-standard matchers.
There was one false positive, suppressed it with NOLINTNEXTLINE.
It's not really a false positiive, it's just that Clang sees the world
in one way and if conditonal compilation (#if) differs for other
compilers, Clang doesn't know better. This is an artifact of matching
two consecutive statements.
Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-13 21:18:06 +00:00
|
|
|
Q_UNREACHABLE_RETURN(result + u"wat?"_s);
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlJSRegisterContent::isList() const
|
|
|
|
{
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Type:
|
|
|
|
return std::get<QQmlJSScope::ConstPtr>(m_content)->accessSemantics()
|
|
|
|
== QQmlJSScope::AccessSemantics::Sequence;
|
|
|
|
case Property: {
|
|
|
|
const auto prop = std::get<QQmlJSMetaProperty>(m_content);
|
|
|
|
return prop.isList()
|
|
|
|
|| prop.type()->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
|
|
|
|
}
|
2022-02-04 20:46:07 +00:00
|
|
|
case Conversion:
|
|
|
|
return std::get<ConvertedTypes>(m_content).result->accessSemantics()
|
|
|
|
== QQmlJSScope::AccessSemantics::Sequence;
|
2021-06-29 11:19:21 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlJSRegisterContent::isWritable() const
|
|
|
|
{
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Property:
|
|
|
|
return std::get<QQmlJSMetaProperty>(m_content).isWritable();
|
|
|
|
|
|
|
|
// TODO: What can we actually write?
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSScope::ConstPtr &type,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = type;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSMetaProperty &property,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = property;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSMetaEnum &enumeration,
|
|
|
|
const QString &enumMember,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = std::make_pair(enumeration, enumMember);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QList<QQmlJSMetaMethod> &methods,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = methods;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-16 06:53:39 +00:00
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
uint importNamespaceStringId,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = importNamespaceStringId;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-04 20:46:07 +00:00
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QList<QQmlJSScope::ConstPtr> origins,
|
|
|
|
const QQmlJSScope::ConstPtr &conversion,
|
|
|
|
ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = ConvertedTypes { origins, conversion };
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-29 11:19:21 +00:00
|
|
|
QT_END_NAMESPACE
|