aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-07 14:12:37 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-08 11:39:42 +0200
commit4761ea81d1789d153ae986be6f749853f5a68332 (patch)
tree91594cb22e0adcb3d6a62ce3dccb6ad3c2400c1e
parent9498d127aaf1a7888e46763ed7b8e39ee76e76da (diff)
shiboken2: Rearrange values of enum TypeEntry::CodeGeneration
TypeEntry::CodeGeneration::GenerateCpp was unused. Consequently, the GenerateAll mask is not needed, either. Replace GenerateCpp and GenerateTargetLang by a generic GenerateCode value. Introduce a new GenerationDisabled value to be able to distinguish a generate='no' XML attribute from a plain rejection. Fix many invalid usages of bool generateCode() testing against the flag value. Use the enum instead of uint for the code generation field. Task-number: PYSIDE-1202 Change-Id: I0aec5bd1ebfb9a50b80d5a187372c4271490e1b3 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp19
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp2
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.h20
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp10
-rw-r--r--sources/shiboken2/generator/generator.cpp3
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp5
6 files changed, 25 insertions, 34 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index b46ed5092..6b72d6b71 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -175,12 +175,12 @@ void AbstractMetaBuilderPrivate::checkFunctionModifications()
const TypeEntry *entry = it.value();
if (!entry)
continue;
- if (!entry->isComplex() || entry->codeGeneration() == TypeEntry::GenerateNothing)
+ if (!entry->isComplex() || !entry->generateCode())
continue;
auto centry = static_cast<const ComplexTypeEntry *>(entry);
- if (!(centry->codeGeneration() & TypeEntry::GenerateTargetLang))
+ if (!centry->generateCode())
continue;
FunctionModificationList modifications = centry->functionModifications();
@@ -290,7 +290,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte
if (arguments.size() == 1) {
unaryOperator = true;
} else if (!baseoperandClass
- || !(baseoperandClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang)) {
+ || !baseoperandClass->typeEntry()->generateCode()) {
baseoperandClass = argumentToClass(arguments.at(1), currentClass);
firstArgumentIsSelf = false;
} else {
@@ -551,7 +551,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
&& !types->shouldDropTypeEntry(entry->qualifiedCppName())
&& !entry->isContainer()
&& !entry->isCustom()
- && (entry->generateCode() & TypeEntry::GenerateTargetLang)
+ && entry->generateCode()
&& !AbstractMetaClass::findClass(m_metaClasses, entry)) {
qCWarning(lcShiboken, "%s", qPrintable(msgTypeNotDefined(entry)));
} else if (entry->generateCode() && entry->type() == TypeEntry::FunctionType) {
@@ -570,7 +570,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
qPrintable(msgGlobalFunctionNotDefined(fte, signature)));
}
}
- } else if (entry->isEnum() && (entry->generateCode() & TypeEntry::GenerateTargetLang)) {
+ } else if (entry->isEnum() && entry->generateCode()) {
auto enumEntry = static_cast<const EnumTypeEntry *>(entry);
const QString name = enumEntry->targetLangQualifier();
AbstractMetaClass *cls = AbstractMetaClass::findClass(m_metaClasses, name);
@@ -855,8 +855,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem &
return nullptr;
}
- const bool rejectionWarning = !enclosing
- || (enclosing->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang);
+ const bool rejectionWarning = !enclosing || enclosing->typeEntry()->generateCode();
if (!typeEntry) {
if (rejectionWarning)
@@ -1185,7 +1184,7 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel
if (!metaType) {
const QString type = TypeInfo::resolveType(fieldType, currentScope()).qualifiedName().join(colonColon());
- if (cls->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang) {
+ if (cls->typeEntry()->generateCode()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgSkippingField(field, cls->name(), type)));
}
@@ -1869,9 +1868,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
// unless the function is virtual (since the override in the
// wrapper can then not correctly be generated).
if (arg->defaultValue() && !functionItem->isVirtual()) {
- if (!currentClass
- || (currentClass->typeEntry()->codeGeneration()
- & TypeEntry::GenerateTargetLang)) {
+ if (!currentClass || currentClass->typeEntry()->generateCode()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgStrippingArgument(functionItem, i, originalQualifiedSignatureWithReturn, arg)));
}
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index 0cfde1c66..c9b3fcd91 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.cpp
+++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp
@@ -432,7 +432,7 @@ ConstantValueTypeEntry *
const TypeEntry *parent)
{
auto result = new ConstantValueTypeEntry(value, parent);
- result->setCodeGeneration(0);
+ result->setCodeGeneration(TypeEntry::GenerateNothing);
addType(result);
return result;
}
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h
index a68231f36..6635b501e 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.h
+++ b/sources/shiboken2/ApiExtractor/typesystem.h
@@ -598,13 +598,10 @@ public:
Q_ENUM(Type)
enum CodeGeneration {
- GenerateTargetLang = 0x0001,
- GenerateCpp = 0x0002,
- GenerateForSubclass = 0x0004,
-
- GenerateNothing = 0,
- GenerateAll = 0xffff,
- GenerateCode = GenerateTargetLang | GenerateCpp
+ GenerateNothing, // Rejection, private type, ConstantValueTypeEntry or similar
+ GenerationDisabled, // generate='no' in type system
+ GenerateCode, // Generate code
+ GenerateForSubclass, // Inherited from a loaded dependent type system.
};
Q_ENUM(CodeGeneration)
@@ -703,11 +700,11 @@ public:
// Name as specified in XML
QString entryName() const { return m_entryName; }
- uint codeGeneration() const
+ CodeGeneration codeGeneration() const
{
return m_codeGeneration;
}
- void setCodeGeneration(uint cg)
+ void setCodeGeneration(CodeGeneration cg)
{
m_codeGeneration = cg;
}
@@ -719,8 +716,7 @@ public:
// on 'load-typesystem' tag
inline bool generateCode() const
{
- return m_codeGeneration != TypeEntry::GenerateForSubclass
- && m_codeGeneration != TypeEntry::GenerateNothing;
+ return m_codeGeneration == GenerateCode;
}
int revision() const { return m_revision; }
@@ -897,7 +893,7 @@ private:
QVersionNumber m_version;
CustomConversion *m_customConversion = nullptr;
SourceLocation m_sourceLocation; // XML file
- uint m_codeGeneration = GenerateAll;
+ CodeGeneration m_codeGeneration = GenerateCode;
int m_revision = 0;
int m_sbkIndex = 0;
Type m_type;
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index 6352ce2be..d2648d0b4 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -505,7 +505,7 @@ QString TypeSystemEntityResolver::resolveUndeclaredEntity(const QString &name)
TypeSystemParser::TypeSystemParser(TypeDatabase *database, bool generate) :
m_database(database),
- m_generate(generate ? TypeEntry::GenerateAll : TypeEntry::GenerateForSubclass)
+ m_generate(generate ? TypeEntry::GenerateCode : TypeEntry::GenerateForSubclass)
{
}
@@ -773,7 +773,7 @@ bool TypeSystemParser::endElement(const QStringRef &localName)
switch (m_current->type) {
case StackElement::Root:
- if (m_generate == TypeEntry::GenerateAll) {
+ if (m_generate == TypeEntry::GenerateCode) {
TypeDatabase::instance()->addGlobalUserFunctions(m_contextStack.top()->addedFunctions);
TypeDatabase::instance()->addGlobalUserFunctionModifications(m_contextStack.top()->functionMods);
for (CustomConversion *customConversion : qAsConst(customConversionsForReview)) {
@@ -1555,7 +1555,7 @@ void TypeSystemParser::applyComplexTypeAttributes(const QXmlStreamReader &reader
if (generate)
ctype->setCodeGeneration(m_generate);
else
- ctype->setCodeGeneration(TypeEntry::GenerateForSubclass);
+ ctype->setCodeGeneration(TypeEntry::GenerationDisabled);
}
bool TypeSystemParser::parseRenameFunction(const QXmlStreamReader &,
@@ -1738,7 +1738,7 @@ bool TypeSystemParser::loadTypesystem(const QXmlStreamReader &,
}
const bool result =
m_database->parseFile(typeSystemName, m_currentPath, generateChild
- && m_generate == TypeEntry::GenerateAll);
+ && m_generate == TypeEntry::GenerateCode);
if (!result)
m_error = QStringLiteral("Failed to parse: '%1'").arg(typeSystemName);
return result;
@@ -2754,7 +2754,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
auto *element = new StackElement(m_current);
element->type = elementType;
- if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateAll)
+ if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateCode)
customConversionsForReview.clear();
if (element->type == StackElement::CustomMetaConstructor
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index e39ead258..c0a2af2ee 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -502,8 +502,7 @@ bool Generator::generate()
bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) const
{
- return (type->codeGeneration() & TypeEntry::GenerateTargetLang)
- && NamespaceTypeEntry::isVisibleScope(type);
+ return type->generateCode() && NamespaceTypeEntry::isVisibleScope(type);
}
bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 4f3ca20c1..8cea5aeda 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -929,7 +929,7 @@ QString ShibokenGenerator::fixedCppTypeName(const TypeEntry *type, QString typeN
{
if (typeName.isEmpty())
typeName = type->qualifiedCppName();
- if (!(type->codeGeneration() & TypeEntry::GenerateTargetLang)) {
+ if (!type->generateCode()) {
typeName.prepend(QLatin1Char('_'));
typeName.prepend(type->targetLangPackage());
}
@@ -1609,8 +1609,7 @@ ShibokenGenerator::ExtendedConverterData ShibokenGenerator::getExtendedConverter
// Get only the conversion operators that return a type from another module,
// that are value-types and were not removed in the type system.
const TypeEntry *convType = convOp->type()->typeEntry();
- if ((convType->codeGeneration() & TypeEntry::GenerateTargetLang)
- || !convType->isValue()
+ if (convType->generateCode() || !convType->isValue()
|| convOp->isModifiedRemoved())
continue;
extConvs[convType].append(convOp->ownerClass());