aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-01-07 14:34:53 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-11 22:27:02 +0000
commit831286b4fd751ceed5b3abcc1268b9cb46d0a6c7 (patch)
tree30db1b7fde520e0d481ddbde2b046b0353bed3fd
parent31139d5acc369ce225105f81cc02bead8f64f133 (diff)
shiboken6: Remove code for unimplemented elements "custom-constructor", "custom-destructor"
As a drive-by, remove the union from the internal StackElement class. Add an Unimplemented value to the Element type enumeration. which requires making it 64bit. Task-number: PYSIDE-1766 Change-Id: Ib869558a80b362b582427bc7cd1679bcd55d3433 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 18c5fc884ae5a93df197e9ec2abd9e949f0d2300) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/ApiExtractor/modifications.h9
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.cpp22
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.h6
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp94
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.h20
-rw-r--r--sources/shiboken6/doc/typesystem_templates.rst3
6 files changed, 31 insertions, 123 deletions
diff --git a/sources/shiboken6/ApiExtractor/modifications.h b/sources/shiboken6/ApiExtractor/modifications.h
index 291f80545..c8c8579df 100644
--- a/sources/shiboken6/ApiExtractor/modifications.h
+++ b/sources/shiboken6/ApiExtractor/modifications.h
@@ -141,15 +141,6 @@ public:
static QRegularExpression placeHolderRegex(int index);
};
-class CustomFunction : public CodeSnipAbstract
-{
-public:
- explicit CustomFunction(const QString &n = QString()) : name(n) {}
-
- QString name;
- QString paramName;
-};
-
class TemplateEntry : public CodeSnipAbstract
{
public:
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp
index e88022e80..5d1a8c8b5 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystem.cpp
@@ -76,8 +76,6 @@ public:
QString m_targetLangPackage;
mutable QString m_cachedTargetLangName; // "Foo.Bar"
mutable QString m_cachedTargetLangEntryName; // "Bar"
- CustomFunction m_customConstructor;
- CustomFunction m_customDestructor;
CodeSnipList m_codeSnips;
DocModificationList m_docModifications;
IncludeList m_extraIncludes;
@@ -587,26 +585,6 @@ QString TypeEntry::qualifiedTargetLangName() const
return targetLangPackage() + QLatin1Char('.') + targetLangName();
}
-void TypeEntry::setCustomConstructor(const CustomFunction &func)
-{
- m_d->m_customConstructor = func;
-}
-
-CustomFunction TypeEntry::customConstructor() const
-{
- return m_d->m_customConstructor;
-}
-
-void TypeEntry::setCustomDestructor(const CustomFunction &func)
-{
- m_d->m_customDestructor = func;
-}
-
-CustomFunction TypeEntry::customDestructor() const
-{
- return m_d->m_customDestructor;
-}
-
bool TypeEntry::isValue() const
{
return false;
diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h
index f80ff886d..63244f024 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.h
+++ b/sources/shiboken6/ApiExtractor/typesystem.h
@@ -202,12 +202,6 @@ public:
QString qualifiedTargetLangName() const;
- void setCustomConstructor(const CustomFunction &func);
- CustomFunction customConstructor() const;
-
- void setCustomDestructor(const CustomFunction &func);
- CustomFunction customDestructor() const;
-
virtual bool isValue() const;
virtual bool isComplex() const;
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
index efce5ae90..ca5af051d 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
@@ -373,8 +373,8 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
{u"array", StackElement::Array},
{u"container-type", StackElement::ContainerTypeEntry},
{u"conversion-rule", StackElement::ConversionRule},
- {u"custom-constructor", StackElement::CustomMetaConstructor},
- {u"custom-destructor", StackElement::CustomMetaDestructor},
+ {u"custom-constructor", StackElement::Unimplemented},
+ {u"custom-destructor", StackElement::Unimplemented},
{u"custom-type", StackElement::CustomTypeEntry},
{u"declare-function", StackElement::DeclareFunction},
{u"define-ownership", StackElement::DefineOwnership},
@@ -816,6 +816,8 @@ bool TypeSystemParser::endElement(QStringView localName)
return true;
switch (m_current->type) {
+ case StackElement::Unimplemented:
+ return true;
case StackElement::Root:
if (m_generate == TypeEntry::GenerateCode) {
TypeDatabase::instance()->addGlobalUserFunctions(m_contextStack.top()->addedFunctions);
@@ -884,23 +886,13 @@ bool TypeSystemParser::endElement(QStringView localName)
}
}
break;
- case StackElement::CustomMetaConstructor: {
- m_current->entry->setCustomConstructor(*m_current->value.customFunction);
- delete m_current->value.customFunction;
- }
- break;
- case StackElement::CustomMetaDestructor: {
- m_current->entry->setCustomDestructor(*m_current->value.customFunction);
- delete m_current->value.customFunction;
- }
- break;
case StackElement::EnumTypeEntry:
m_current->entry->setDocModification(m_contextStack.top()->docModifications);
m_contextStack.top()->docModifications = DocModificationList();
m_currentEnum = nullptr;
break;
case StackElement::Template:
- m_database->addTemplate(m_current->value.templateEntry);
+ m_database->addTemplate(m_current->templateEntry);
break;
case StackElement::TemplateInstanceEnum:
switch (m_current->parent->type) {
@@ -908,7 +900,7 @@ bool TypeSystemParser::endElement(QStringView localName)
if (m_current->parent->parent->type == StackElement::Root) {
CodeSnipList snips = m_current->parent->entry->codeSnips();
CodeSnip snip = snips.takeLast();
- TemplateInstancePtr ti(m_current->value.templateInstance);
+ TemplateInstancePtr ti(m_current->templateInstance);
snip.addTemplateInstance(ti);
snips.append(snip);
m_current->parent->entry->setCodeSnips(snips);
@@ -917,28 +909,22 @@ bool TypeSystemParser::endElement(QStringView localName)
Q_FALLTHROUGH();
case StackElement::NativeToTarget:
case StackElement::AddConversion: {
- TemplateInstancePtr ti(m_current->value.templateInstance);
+ TemplateInstancePtr ti(m_current->templateInstance);
m_contextStack.top()->codeSnips.last().addTemplateInstance(ti);
}
break;
case StackElement::Template: {
- TemplateInstancePtr ti(m_current->value.templateInstance);
- m_current->parent->value.templateEntry->addTemplateInstance(ti);
- }
- break;
- case StackElement::CustomMetaConstructor:
- case StackElement::CustomMetaDestructor: {
- TemplateInstancePtr ti(m_current->value.templateInstance);
- m_current->parent->value.customFunction->addTemplateInstance(ti);
+ TemplateInstancePtr ti(m_current->templateInstance);
+ m_current->parent->templateEntry->addTemplateInstance(ti);
}
break;
case StackElement::ConversionRule: {
- TemplateInstancePtr ti(m_current->value.templateInstance);
+ TemplateInstancePtr ti(m_current->templateInstance);
m_contextStack.top()->functionMods.last().argument_mods().last().conversionRules().last().addTemplateInstance(ti);
}
break;
case StackElement::InjectCodeInFunction: {
- TemplateInstancePtr ti(m_current->value.templateInstance);
+ TemplateInstancePtr ti(m_current->templateInstance);
m_contextStack.top()->functionMods.last().snips().last().addTemplateInstance(ti);
}
break;
@@ -975,16 +961,11 @@ bool TypeSystemParser::endElement(QStringView localName)
template <class String> // QString/QStringRef
bool TypeSystemParser::characters(const String &ch)
{
- if (m_currentDroppedEntry || m_ignoreDepth)
+ if (m_currentDroppedEntry || m_ignoreDepth || m_current->type == StackElement::Unimplemented)
return true;
if (m_current->type == StackElement::Template) {
- m_current->value.templateEntry->addCode(ch);
- return true;
- }
-
- if (m_current->type == StackElement::CustomMetaConstructor || m_current->type == StackElement::CustomMetaDestructor) {
- m_current->value.customFunction->addCode(ch);
+ m_current->templateEntry->addCode(ch);
return true;
}
@@ -1791,7 +1772,7 @@ bool TypeSystemParser::parseRenameFunction(const ConditionalStreamReader &,
bool TypeSystemParser::parseInjectDocumentation(const ConditionalStreamReader &,
QXmlStreamAttributes *attributes)
{
- const int validParent = StackElement::TypeEntryMask
+ const auto validParent = StackElement::TypeEntryMask
| StackElement::ModifyFunction
| StackElement::ModifyField;
if (!m_current->parent || (m_current->parent->type & validParent) == 0) {
@@ -1834,7 +1815,7 @@ bool TypeSystemParser::parseInjectDocumentation(const ConditionalStreamReader &,
bool TypeSystemParser::parseModifyDocumentation(const ConditionalStreamReader &,
QXmlStreamAttributes *attributes)
{
- const int validParent = StackElement::TypeEntryMask
+ const auto validParent = StackElement::TypeEntryMask
| StackElement::ModifyFunction
| StackElement::ModifyField;
if (!m_current->parent || (m_current->parent->type & validParent) == 0) {
@@ -2574,28 +2555,6 @@ bool TypeSystemParser::parseReplaceDefaultExpression(const ConditionalStreamRead
return true;
}
-CustomFunction *
- TypeSystemParser::parseCustomMetaConstructor(const ConditionalStreamReader &,
- StackElement::ElementType type,
- const StackElement &topElement,
- QXmlStreamAttributes *attributes)
-{
- QString functionName = topElement.entry->name().toLower()
- + (type == StackElement::CustomMetaConstructor
- ? QLatin1String("_create") : QLatin1String("_delete"));
- QString paramName = QLatin1String("copy");
- for (int i = attributes->size() - 1; i >= 0; --i) {
- const auto name = attributes->at(i).qualifiedName();
- if (name == nameAttribute())
- functionName = attributes->takeAt(i).value().toString();
- else if (name == QLatin1String("param-name"))
- paramName = attributes->takeAt(i).value().toString();
- }
- auto *func = new CustomFunction(functionName);
- func->paramName = paramName;
- return func;
-}
-
bool TypeSystemParser::parseReferenceCount(const ConditionalStreamReader &reader,
const StackElement &topElement,
QXmlStreamAttributes *attributes)
@@ -2818,13 +2777,11 @@ TemplateInstance *
{
if (!(topElement.type & StackElement::CodeSnipMask) &&
(topElement.type != StackElement::Template) &&
- (topElement.type != StackElement::CustomMetaConstructor) &&
- (topElement.type != StackElement::CustomMetaDestructor) &&
(topElement.type != StackElement::NativeToTarget) &&
(topElement.type != StackElement::AddConversion) &&
(topElement.type != StackElement::ConversionRule)) {
- m_error = QLatin1String("Can only insert templates into code snippets, templates, custom-constructors, "\
- "custom-destructors, conversion-rule, native-to-target or add-conversion tags.");
+ m_error = QLatin1String("Can only insert templates into code snippets, templates, "\
+ "conversion-rule, native-to-target or add-conversion tags.");
return nullptr;
}
const int nameIndex = indexOfAttribute(*attributes, nameAttribute());
@@ -2852,7 +2809,7 @@ bool TypeSystemParser::parseReplace(const ConditionalStreamReader &,
else if (name == toAttribute())
to = attributes->takeAt(i).value().toString();
}
- element->parent->value.templateInstance->addReplaceRule(from, to);
+ element->parent->templateInstance->addReplaceRule(from, to);
return true;
}
@@ -2946,10 +2903,10 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader)
if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateCode)
customConversionsForReview.clear();
- if (element->type == StackElement::CustomMetaConstructor
- || element->type == StackElement::CustomMetaDestructor) {
+ if (element->type == StackElement::Unimplemented) {
qCWarning(lcShiboken, "%s",
qPrintable(msgUnimplementedElementWarning(reader, tagName)));
+ return true;
}
switch (element->type) {
@@ -3247,11 +3204,6 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader)
case StackElement::RemoveDefaultExpression:
m_contextStack.top()->functionMods.last().argument_mods().last().setRemovedDefaultExpression(true);
break;
- case StackElement::CustomMetaConstructor:
- case StackElement::CustomMetaDestructor:
- element->value.customFunction =
- parseCustomMetaConstructor(reader, element->type, topElement, &attributes);
- break;
case StackElement::ReferenceCount:
if (!parseReferenceCount(reader, topElement, &attributes))
return false;
@@ -3289,14 +3241,14 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader)
m_error = msgMissingAttribute(nameAttribute());
return false;
}
- element->value.templateEntry =
+ element->templateEntry =
new TemplateEntry(attributes.takeAt(nameIndex).value().toString());
}
break;
case StackElement::TemplateInstanceEnum:
- element->value.templateInstance =
+ element->templateInstance =
parseTemplateInstanceEnum(reader, topElement, &attributes);
- if (!element->value.templateInstance)
+ if (!element->templateInstance)
return false;
break;
case StackElement::Replace:
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.h b/sources/shiboken6/ApiExtractor/typesystemparser.h
index 903e84421..a44829d72 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.h
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.h
@@ -43,10 +43,11 @@ class ConditionalStreamReader;
class TypeSystemEntityResolver;
class TypeDatabase;
+
class StackElement
{
public:
- enum ElementType {
+ enum ElementType : uint64_t {
None = 0x0,
// Type tags (0x1, ... , 0xff)
@@ -77,8 +78,6 @@ class StackElement
ModifyFunction = 0x0300,
ModifyField = 0x0400,
Root = 0x0500,
- CustomMetaConstructor = 0x0600,
- CustomMetaDestructor = 0x0700,
SuppressedWarning = 0x0900,
Rejection = 0x0a00,
LoadTypesystem = 0x0b00,
@@ -117,7 +116,9 @@ class StackElement
ReferenceCount = 0x80000000,
ParentOwner = 0x90000000,
Array = 0xA0000000,
- ArgumentModifiers = 0xff000000
+ ArgumentModifiers = 0xff000000,
+
+ Unimplemented = 0x100000000
};
StackElement(StackElement *p) : entry(nullptr), type(None), parent(p) { }
@@ -126,11 +127,8 @@ class StackElement
ElementType type;
StackElement *parent;
- union {
- TemplateInstance* templateInstance;
- TemplateEntry* templateEntry;
- CustomFunction* customFunction;
- } value;
+ TemplateInstance *templateInstance = nullptr;
+ TemplateEntry *templateEntry = nullptr;
};
struct StackElementContext
@@ -240,10 +238,6 @@ private:
QXmlStreamAttributes *);
bool parseReplaceDefaultExpression(const ConditionalStreamReader &,
const StackElement &topElement, QXmlStreamAttributes *);
- static CustomFunction *
- parseCustomMetaConstructor(const ConditionalStreamReader &,
- StackElement::ElementType type,
- const StackElement &topElement, QXmlStreamAttributes *);
bool parseReferenceCount(const ConditionalStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *);
bool parseParentOwner(const ConditionalStreamReader &, const StackElement &topElement,
diff --git a/sources/shiboken6/doc/typesystem_templates.rst b/sources/shiboken6/doc/typesystem_templates.rst
index 795c9d97e..8ae617752 100644
--- a/sources/shiboken6/doc/typesystem_templates.rst
+++ b/sources/shiboken6/doc/typesystem_templates.rst
@@ -30,8 +30,7 @@ insert-template
The ``insert-template`` node includes the code template identified by the
name attribute, and it can be a child of the :ref:`inject-code`,
- :ref:`conversion-rule`, :ref:`template`, ``custom-constructor``
- or ``custom-destructor`` nodes.
+ :ref:`conversion-rule` or :ref:`template` nodes.
.. code-block:: xml