aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-11-30 18:39:25 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-12-07 12:31:15 +0000
commited87e710dd14bc9612dcfdba2e09143201768556 (patch)
tree0c7dd4b49e4a891c57d514fca39642abfaad91f6 /sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
parenteb16797b9a54970dbc0c461ebeddda57b060af22 (diff)
shiboken6: Add support for a snake case typesystem attribute
Add a snake case attribute to type system, complex type entry, function type entry as well as to function and field modifications. Add a function definitionNames() to AbstractMetaFunction/Field returning the names under which the function/field will be registered. Change the code writing the registration accordingly. Fixes: PYSIDE-1441 Change-Id: I178390bb80fa25aad9f8a56e99e4cc70064178eb Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
index a3c2d3731..41e42ac2a 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
@@ -451,13 +451,11 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
if (!funcEntry->hasSignature(metaFunc->minimalSignature()))
continue;
+ metaFunc->setTypeEntry(funcEntry);
applyFunctionModifications(metaFunc);
setInclude(funcEntry, func->fileName());
- if (metaFunc->typeEntry())
- delete metaFunc->typeEntry();
- metaFunc->setTypeEntry(funcEntry);
m_globalFunctions << metaFuncPtr;
}
@@ -1368,6 +1366,51 @@ void AbstractMetaBuilderPrivate::fillAddedFunctions(AbstractMetaClass *metaClass
}
}
+QString AbstractMetaBuilder::getSnakeCaseName(const QString &name)
+{
+ const int size = name.size();
+ if (size < 3)
+ return name;
+ QString result;
+ result.reserve(size + 4);
+ for (int i = 0; i < size; ++i) {
+ const QChar c = name.at(i);
+ if (c.isUpper()) {
+ if (i > 0) {
+ if (name.at(i - 1).isUpper())
+ return name; // Give up at consecutive upper chars
+ result.append(u'_');
+ }
+ result.append(c.toLower());
+ } else {
+ result.append(c);
+ }
+ }
+ return result;
+}
+
+// Names under which an item will be registered to Python depending on snakeCase
+QStringList AbstractMetaBuilder::definitionNames(const QString &name,
+ TypeSystem::SnakeCase snakeCase)
+{
+ QStringList result;
+ switch (snakeCase) {
+ case TypeSystem::SnakeCase::Unspecified:
+ case TypeSystem::SnakeCase::Disabled:
+ result.append(name);
+ break;
+ case TypeSystem::SnakeCase::Enabled:
+ result.append(AbstractMetaBuilder::getSnakeCaseName(name));
+ break;
+ case TypeSystem::SnakeCase::Both:
+ result.append(AbstractMetaBuilder::getSnakeCaseName(name));
+ if (name != result.constFirst())
+ result.append(name);
+ break;
+ }
+ return result;
+}
+
void AbstractMetaBuilderPrivate::applyFunctionModifications(AbstractMetaFunction *func)
{
AbstractMetaFunction& funcRef = *func;