aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-11-07 14:18:01 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-11-08 12:37:47 +0100
commitde1101c3abe85426b47cfdcff82212f26003264e (patch)
treee8baac2a850e981f6c0ac596815f775c14e0e282 /tools
parent21cd756a401afddb8839d3daa62e62e969dfe24e (diff)
qmltc: Fix usage of namespaced attached types
We can't have a '.' in the variable name. Use '_' instead. In addition, disambiguate the names by always prepending a number to the part extracted from QML. This is safe because QML names can't start with numbers. Pick-to: 6.8 Fixes: QTBUG-130838 Change-Id: I1243070a3cb901bc4c2c108ecbec0c9cbbc57a55 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmltc/qmltccompiler.cpp7
-rw-r--r--tools/qmltc/qmltccompiler.h8
2 files changed, 12 insertions, 3 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp
index e2f9af44d7..0682d72720 100644
--- a/tools/qmltc/qmltccompiler.cpp
+++ b/tools/qmltc/qmltccompiler.cpp
@@ -1477,7 +1477,8 @@ void QmltcCompiler::compileAttachedPropertyBinding(QmltcType &current,
auto &attachedMemberName =
m_uniques[UniqueStringId(current, propertyName)].attachedVariableName;
if (attachedMemberName.isEmpty()) {
- attachedMemberName = u"m_" + attachingTypeName;
+ attachedMemberName = uniqueVariableName(attachingTypeName);
+
// add attached type as a member variable to allow noop lookup
current.variables.emplaceBack(attachedTypeName + u" *", attachedMemberName, u"nullptr"_s);
@@ -1775,8 +1776,8 @@ void QmltcCompiler::compileBindingByType(QmltcType &current,
break;
}
case QQmlSA::BindingType::Script: {
- QString bindingSymbolName = type->internalName() + u'_' + propertyName + u"_binding";
- bindingSymbolName.replace(u'.', u'_'); // can happen with group properties
+ QString bindingSymbolName
+ = uniqueVariableName(type->internalName() + u'_' + propertyName + u"_binding");
compileScriptBinding(current, binding, bindingSymbolName, type, propertyName, propertyType,
accessor);
break;
diff --git a/tools/qmltc/qmltccompiler.h b/tools/qmltc/qmltccompiler.h
index 3deab6d44e..a8254dc315 100644
--- a/tools/qmltc/qmltccompiler.h
+++ b/tools/qmltc/qmltccompiler.h
@@ -60,6 +60,7 @@ private:
QQmlJSLogger *m_logger = nullptr;
QmltcCompilerInfo m_info {}; // miscellaneous input/output information
QString m_urlMethodName;
+ uint m_currentVariableNumber = 0;
struct UniqueStringId;
struct QmltcTypeLocalData;
@@ -80,6 +81,13 @@ private:
const QQmlJSScope::ConstPtr &owner);
void compileExtraListMethods(QmltcType &current, const QQmlJSMetaProperty &p);
+ QString uniqueVariableName(const QString &qmlName)
+ {
+ QString result = u"m_"_s + QString::number(++m_currentVariableNumber) + qmlName;
+ result.replace(u'.', u'_');
+ return result;
+ }
+
/*!
\internal