qmltc: Drop half-correct type name collecting procedure
Type resolver can collect (presumably C++) type names which is needed to verify that the QML document we are about to compile is named correctly and does not have name conflicts However, the collection logic gathers everything we can find: C++ names, QML names, names marked with $anonymous$ or under import namespace. At the same time, the way the procedure works involves poking (pretty much) every known QQmlJSScope a.k.a. creates every type (previously some could've been deferred) which usually means that we have a larger than necessary footprint Thus, delete this procedure and simplify the code. We can later revisit the logic and figure the proper way to collect relevant type names. For now this is just overkill though. Note that this change, consequently, should avoid instantiating types imported from implicit import dir, instead of imported from qmldir (there is a difference apparently) Task-number: QTBUG-100103 Pick-to: 6.3 Change-Id: Iaf65e5f3a9bf53286760af0dc39a1d7036d7c474 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
b1bb4c8e5f
commit
25b2645201
|
@ -506,23 +506,16 @@ QHash<QString, qsizetype> makeUniqueCppNames(const Qml2CppContext &context,
|
|||
QHash<QString, qsizetype> typeCounts;
|
||||
for (const QString &str : cppKeywords)
|
||||
typeCounts.insert(str, 1);
|
||||
const auto knownCppNames = context.typeResolver->gatherKnownCppClassNames();
|
||||
for (const QString &str : knownCppNames)
|
||||
typeCounts.insert(str, 1);
|
||||
|
||||
// root is special:
|
||||
QQmlJSScope::Ptr root = context.typeResolver->root();
|
||||
QFileInfo fi(context.documentUrl);
|
||||
auto cppName = fi.baseName();
|
||||
// TODO: root is special and with implicit import directory cppName might be
|
||||
// in typeCounts.
|
||||
#if 0
|
||||
if (typeCounts.contains(cppName)) {
|
||||
context.recordError(root->sourceLocation(),
|
||||
u"Root object name '" + cppName + u"' is reserved");
|
||||
return typeCounts;
|
||||
}
|
||||
#endif
|
||||
if (cppName.isEmpty()) {
|
||||
context.recordError(root->sourceLocation(), u"Root object's name is empty"_qs);
|
||||
return typeCounts;
|
||||
|
|
|
@ -42,30 +42,6 @@ class TypeResolver : public QQmlJSTypeResolver
|
|||
public:
|
||||
TypeResolver(QQmlJSImporter *importer);
|
||||
|
||||
// helper function for code generator
|
||||
QStringList gatherKnownCppClassNames() const
|
||||
{
|
||||
QStringList cppNames;
|
||||
QQmlJSImporter::ImportedTypes builtins = m_importer->builtinInternalNames();
|
||||
cppNames.reserve(builtins.size() + m_imports.size());
|
||||
const auto getInternalName = [](const QQmlJSImportedScope &t) {
|
||||
if (!t.scope)
|
||||
return QString();
|
||||
return t.scope->internalName();
|
||||
};
|
||||
std::transform(builtins.cbegin(), builtins.cend(), std::back_inserter(cppNames),
|
||||
getInternalName);
|
||||
|
||||
// builtins must be valid: all QQmlJSScopes are not nullptr and have
|
||||
// non-empty internal names. m_imports may have nullptrs, due to import
|
||||
// namespaces
|
||||
Q_ASSERT(std::find(cppNames.cbegin(), cppNames.cend(), QString()) == cppNames.cend());
|
||||
|
||||
std::transform(m_imports.cbegin(), m_imports.cend(), std::back_inserter(cppNames),
|
||||
getInternalName);
|
||||
return cppNames;
|
||||
}
|
||||
|
||||
void init(Visitor &visitor, QQmlJS::AST::Node *program);
|
||||
|
||||
// TODO: this shouldn't be exposed. instead, all the custom passes on
|
||||
|
|
Loading…
Reference in New Issue