diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-10-25 15:39:57 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-25 16:15:06 +0100 |
commit | 0ced05f77b88c68c8e2a1c71161cb19b9c890f59 (patch) | |
tree | 572383fc27b857a4a77d6b8a68b28108b9d346ac /sources/shiboken2/ApiExtractor/typesystemparser.cpp | |
parent | 60795a6fc7460b9c5b115270541ef573ba15cde9 (diff) |
shiboken: Store the unqualified entry name in TypeEntry
With the previous change adding a parent pointer, this is working
towards building the target lang name by walking up the hierarchy,
prepending the names, making it possible to exclude namespaces.
Pass the unqualified name from the XML parser and build
the qualified name in the TypeEntry constructor.
For this to work, a new ConstantValueTypeEntry is added replacing the
abuse of EnumValueTypeEntry for nontype-template parameters.
As a side effect, it is no longer possible to nest types
by qualifying with "::" in XML:
<object-type name="Class"/>
<enum-type name="Class::Enum"/>
This needs to be fixed in the type system files.
[ChangeLog][shiboken] As a result of a code cleanup, it is
no longer possible to nest types by by qualifying with "::" in
the type system files. The elements need to be properly nested.
Task-number: PYSIDE-990
Task-number: PYSIDE-1074
Change-Id: I8a2f93c40d59167b0ba205ef3ff3b325d242c3d3
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystemparser.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystemparser.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index 6ecdf1dc9..6d9e409a4 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -1064,34 +1064,34 @@ void TypeSystemParser::applyCommonAttributes(TypeEntry *type, QXmlStreamAttribut FlagsTypeEntry * TypeSystemParser::parseFlagsEntry(const QXmlStreamReader &, - EnumTypeEntry *enumEntry, - const QString &name, QString flagName, + EnumTypeEntry *enumEntry, QString flagName, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto ftype = new FlagsTypeEntry(QLatin1String("QFlags<") + name + QLatin1Char('>'), + auto ftype = new FlagsTypeEntry(QLatin1String("QFlags<") + enumEntry->name() + QLatin1Char('>'), since, currentParentTypeEntry()->typeSystemTypeEntry()); ftype->setOriginator(enumEntry); ftype->setTargetLangPackage(enumEntry->targetLangPackage()); - // Try to get the guess the qualified flag name - const int lastSepPos = name.lastIndexOf(colonColon()); - if (lastSepPos >= 0 && !flagName.contains(colonColon())) - flagName.prepend(name.left(lastSepPos + 2)); + // Try toenumEntry get the guess the qualified flag name + if (!flagName.contains(colonColon())) { + auto eq = enumEntry->qualifier(); + if (!eq.isEmpty()) + flagName.prepend(eq + colonColon()); + } ftype->setOriginalName(flagName); applyCommonAttributes(ftype, attributes); - QString n = ftype->originalName(); - QStringList lst = n.split(colonColon()); + QStringList lst = flagName.split(colonColon()); const QString &targetLangQualifier = enumEntry->targetLangQualifier(); if (QStringList(lst.mid(0, lst.size() - 1)).join(colonColon()) != targetLangQualifier) { qCWarning(lcShiboken).noquote().nospace() - << QStringLiteral("enum %1 and flags %2 differ in qualifiers") - .arg(targetLangQualifier, lst.constFirst()); + << QStringLiteral("enum %1 and flags %2 (%3) differ in qualifiers") + .arg(targetLangQualifier, lst.constFirst(), flagName); } ftype->setFlagsName(lst.constLast()); @@ -1223,19 +1223,12 @@ ContainerTypeEntry * EnumTypeEntry * TypeSystemParser::parseEnumTypeEntry(const QXmlStreamReader &reader, - const QString &fullName, const QVersionNumber &since, + const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - QString scope; - QString name = fullName; - const int sep = fullName.lastIndexOf(colonColon()); - if (sep != -1) { - scope = fullName.left(sep); - name = fullName.right(fullName.size() - sep - 2); - } - auto *entry = new EnumTypeEntry(scope, name, since, currentParentTypeEntry()); + auto *entry = new EnumTypeEntry(name, since, currentParentTypeEntry()); applyCommonAttributes(entry, attributes); entry->setTargetLangPackage(m_defaultPackage); @@ -1263,7 +1256,7 @@ EnumTypeEntry * if (!flagNames.isEmpty()) { const QStringList &flagNameList = flagNames.split(QLatin1Char(',')); for (const QString &flagName : flagNameList) - parseFlagsEntry(reader, entry, fullName, flagName.trimmed(), since, attributes); + parseFlagsEntry(reader, entry, flagName.trimmed(), since, attributes); } return entry; } @@ -2668,6 +2661,12 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) return false; } } + // Allow for primitive and/or std:: types only, else require proper nesting. + if (element->type != StackElement::PrimitiveTypeEntry && name.contains(QLatin1Char(':')) + && !name.contains(QLatin1String("std::"))) { + m_error = msgIncorrectlyNestedName(name); + return false; + } if (m_database->hasDroppedTypeEntries()) { QString identifier = getNamePrefix(element) + QLatin1Char('.'); @@ -2715,13 +2714,6 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) } } - // Fix type entry name using nesting information. - if (element->type & StackElement::TypeEntryMask - && element->parent && element->parent->type != StackElement::Root) { - name = element->parent->entry->name() + colonColon() + name; - } - - if (name.isEmpty()) { m_error = QLatin1String("no 'name' attribute specified"); return false; |