From d46739294d04c72af1e434e414e1c012d7e78a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Tue, 4 Feb 2020 16:03:52 +0100 Subject: Add an isImmutable to know if a property is immutable Summary: Add a utility function isImmutable to access immutability quickly. Generated classes uses them internally to avoid code redundance. Sample: ``` /** Set blocked-by-default */ void setBlockedByDefault( bool v ) { if (v != mBlockedByDefault && !isBlockedByDefaultImmutable() ) { mBlockedByDefault = v; Q_EMIT blockedByDefaultChanged(); } } /** Is blocked-by-default Immutable */ bool isBlockedByDefaultImmutable() { return isImmutable( QStringLiteral( "blockedByDefault" ) ); } ``` ``` /** Set org.kde.ActivityManager.ResourceScoringEnabled */ void setResourceScoringEnabled( bool v ) { if (!isResourceScoringEnabledImmutable() ) mResourceScoringEnabled = v; } /** Is org.kde.ActivityManager.ResourceScoringEnabled Immutable */ bool isResourceScoringEnabledImmutable() { return isImmutable( QStringLiteral( "resourceScoringEnabled" ) ); } ``` Reviewers: ervin, #frameworks, dfaure Reviewed By: ervin Subscribers: dfaure, tcanabrava, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D26368 --- src/kconfig_compiler/KConfigCodeGeneratorBase.cpp | 54 ++++++++++++++--------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'src/kconfig_compiler/KConfigCodeGeneratorBase.cpp') diff --git a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp index 5a110b2e..239c906c 100644 --- a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp +++ b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp @@ -184,39 +184,51 @@ QString KConfigCodeGeneratorBase::memberAccessorBody(const CfgEntry *e, bool glo return result; } -void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression) +void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globalEnums) { - const QString n = e->name; - const QString t = e->type; - const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties; + QString n = e->name; + QString t = e->type; - m_stream << whitespace() << "if ("; - if (hasBody) { - m_stream << "v != " << varExpression << " && "; - } - m_stream << "!" << m_this << "isImmutable( QStringLiteral( \""; + stream() << whitespace() << "return " << m_this << "isImmutable( QStringLiteral( \""; if (!e->param.isEmpty()) { - QString paramName = e->paramName; - - m_stream << paramName.replace(QStringLiteral("$(") + e->param + QStringLiteral(")"), QLatin1String("%1")) << "\" ).arg( "; + stream() << QString(e->paramName).replace(QLatin1String("$(") + e->param + QLatin1Char(')'), QLatin1String("%1")) << "\" ).arg( "; if (e->paramType == QLatin1String("Enum")) { - m_stream << "QLatin1String( "; + stream() << "QLatin1String( "; - if (m_cfg.globalEnums) { - m_stream << enumName(e->param) << "ToString[i]"; + if (globalEnums) { + stream() << enumName(e->param) << "ToString[i]"; } else { - m_stream << enumName(e->param) << "::enumToString[i]"; + stream() << enumName(e->param) << "::enumToString[i]"; } - m_stream << " )"; + stream() << " )"; } else { - m_stream << "i"; + stream() << "i"; } - m_stream << " )"; + stream() << " )"; } else { - m_stream << n << "\" )"; + stream() << n << "\" )"; + } + stream() << " );" << endl; +} + +void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression) +{ + const QString n = e->name; + const QString t = e->type; + const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties; + + m_stream << whitespace() << "if ("; + if (hasBody) { + m_stream << "v != " << varExpression << " && "; + } + + const auto immutablefunction = immutableFunction(n, m_cfg.dpointer ? m_cfg.className : QString()); + m_stream << "!" << m_this << immutablefunction << "("; + if (!e->param.isEmpty()) { + m_stream << " i "; } - m_stream << " ))"; + m_stream << "))"; } void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e) -- cgit v1.2.1