diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-22 11:09:18 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-05 14:11:33 +0100 |
| commit | 2a7f16dccfa1986bb79d08c90ed2ef56133994e8 (patch) | |
| tree | c72a427ce7e873e739d059ee7a85c8b2e42a9ca1 /sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp | |
| parent | 8b414806b80683e162133338c4b3ca0816746aaa (diff) | |
shiboken6: Remove ShibokenGenerator::guessScopeForDefaultValue()
Move resolving of class fields and enum values as argument default
values into AbstractMetaBuilder.
Handling of static class field constants was spread between
AbstractMetaBuilderPrivate::fixDefaultValue() and
ShibokenGenerator::guessScopeForDefaultValue().
The former was handling it for arguments of non-primitive type only
and not completely expanding namespaces. The latter was handling it
for arguments of primitive types, too, but also added some code for
non-static fields, which cannot be used as default arguments in C++.
ShibokenGenerator::guessScopeForDefaultValue() was handling enum
values for primitive and values, excluding macros by regex, but
otherwise not checking if the term is really an enum value.
Rewrite the code in AbstractMetaBuilderPrivate::fixDefaultValue()
without regexes for clarity, let it check fields and
enum values correctly via code model and fully expand namespaces.
Add tests.
Adapt the signature module to the now fully qualified signatures.
[ChangeLog][shiboken6] When qualifying function argument default
values for the generated code, shiboken no longer considers each
identifier it cannot otherwise find as an enum value and no longer
adds the class scope to it. This may require manually adding some
replace-default-expression modifications.
Task-number: PYSIDE-1691
Pick-to: 6.2
Change-Id: Id4cd2ca1f91db8c1663d7fc31e4b4ef72a5690f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp')
| -rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp index 33b2cab5f..3db29b6fc 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp @@ -29,6 +29,7 @@ #include "abstractmetabuilder.h" #include "abstractmetabuilder_p.h" #include "abstractmetaenum.h" +#include "abstractmetafield.h" #include "abstractmetalang.h" #include "typesystem.h" @@ -79,7 +80,7 @@ static QString resolveEnumValueScopePrefix(const AbstractMetaEnum &metaEnum, return resolveScopePrefixHelper(parts, value); } -static bool isQualifiedCppIdentifier(QStringView e) +bool AbstractMetaBuilderPrivate::isQualifiedCppIdentifier(QStringView e) { return !e.isEmpty() && e.at(0).isLetter() && std::all_of(e.cbegin() + 1, e.cend(), @@ -197,3 +198,22 @@ bool AbstractMetaBuilder::dontFixDefaultValue(QStringView expr) || expr.startsWith(u"Qt::") // Qt namespace constant || isIntegerConstant(expr) || isFloatConstant(expr); } + +QString AbstractMetaBuilderPrivate::qualifyStaticField(const AbstractMetaClass *c, + QStringView field) +{ + if (!c || c->fields().isEmpty()) + return {}; + // If there is a scope, ensure it matches the class + const auto lastQualifier = field.lastIndexOf(u"::"); + if (lastQualifier != -1 + && !c->qualifiedCppName().endsWith(field.left(lastQualifier))) { + return {}; + } + const auto fieldName = lastQualifier != -1 + ? field.mid(lastQualifier + 2) : field; + const auto fieldOpt = c->findField(fieldName); + if (!fieldOpt.has_value() || !fieldOpt.value().isStatic()) + return {}; + return AbstractMetaBuilder::resolveScopePrefix(c, field) + field.toString(); +} |
