aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-12-05 13:22:49 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-12-05 15:55:50 +0000
commite4b83104be7de56ca4a6959f84624c546ea8cd38 (patch)
treee4dce89bcbaba9a77a8b9f8396215b3a9e824e02 /sources/shiboken2
parent998b878f147c4a9e9acb8593b8ad38b25c07fc46 (diff)
Refactor typesystem modification structs
- Use member initialization where possible - Make constructors explicit - Remove unused version attributes, unused comparison operators of FunctionModification and unused struct ExpensePolicy - Rearrange members to minimize Clang warnings about padding Change-Id: I1423f120b2117237c2674cdbb6d06923c842999f Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp2
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp83
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.h171
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp4
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp2
5 files changed, 75 insertions, 187 deletions
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index 0ed016d3d..76953a51e 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.cpp
+++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp
@@ -728,7 +728,7 @@ QDebug operator<<(QDebug d, const TemplateEntry *te)
d.nospace();
d << "TemplateEntry(";
if (te) {
- d << '"' << te->name() << "\", version=" << te->version();
+ d << '"' << te->name() << '"';
} else {
d << '0';
}
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index ed3ba5760..c6f723e4d 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -57,6 +57,7 @@ static inline QString fieldNameAttribute() { return QStringLiteral("field-name")
static inline QString enumNameAttribute() { return QStringLiteral("enum-name"); }
static inline QString argumentTypeAttribute() { return QStringLiteral("argument-type"); }
static inline QString returnTypeAttribute() { return QStringLiteral("return-type"); }
+static inline QString xPathAttribute() { return QStringLiteral("xpath"); }
static QVector<CustomConversion *> customConversionsForReview;
@@ -824,7 +825,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
+ rename + QLatin1String("' is not a valid function name");
return false;
}
- FunctionModification mod(since);
+ FunctionModification mod;
if (!mod.setSignature(signature, &m_error))
return false;
mod.renamedToName = attributes[QLatin1String("rename")];
@@ -1003,16 +1004,6 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
if (!targetLangName.isEmpty())
ctype->setTargetLangName(targetLangName);
- // The expense policy
- QString limit = attributes[QLatin1String("expense-limit")];
- if (!limit.isEmpty() && limit != QLatin1String("none")) {
- ExpensePolicy ep;
- ep.limit = limit.toInt();
- ep.cost = attributes[QLatin1String("expense-cost")];
- ctype->setExpensePolicy(ep);
- }
-
-
ctype->setIsPolymorphicBase(convertBoolean(attributes[QLatin1String("polymorphic-base")], QLatin1String("polymorphic-base"), false));
ctype->setPolymorphicIdValue(attributes[QLatin1String("polymorphic-id-expression")]);
//Copyable
@@ -1096,7 +1087,6 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
attributes.insert(sinceAttribute(), QLatin1String("0"));
fetchAttributeValues(tagName, atts, &attributes);
- double since = attributes[sinceAttribute()].toDouble();
const int validParent = StackElement::TypeEntryMask
| StackElement::ModifyFunction
@@ -1129,8 +1119,8 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
}
QString signature = m_current->type & StackElement::TypeEntryMask ? QString() : m_currentSignature;
- DocModification mod(mode, signature, since);
- mod.format = lang;
+ DocModification mod(mode, signature);
+ mod.setFormat(lang);
m_contextStack.top()->docModifications << mod;
} else {
m_error = QLatin1String("inject-documentation must be inside modify-function, "
@@ -1140,17 +1130,17 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
} else if (element->type == StackElement::ModifyDocumentation) {
// check the XML tag attributes
QHash<QString, QString> attributes;
- attributes.insert(QLatin1String("xpath"), QString());
+ attributes.insert(xPathAttribute(), QString());
attributes.insert(sinceAttribute(), QLatin1String("0"));
fetchAttributeValues(tagName, atts, &attributes);
- double since = attributes[sinceAttribute()].toDouble();
const int validParent = StackElement::TypeEntryMask
| StackElement::ModifyFunction
| StackElement::ModifyField;
if (m_current->parent && m_current->parent->type & validParent) {
QString signature = (m_current->type & StackElement::TypeEntryMask) ? QString() : m_currentSignature;
- m_contextStack.top()->docModifications << DocModification(attributes[QLatin1String("xpath")], signature, since);
+ m_contextStack.top()->docModifications
+ << DocModification(attributes.value(xPathAttribute()), signature);
} else {
m_error = QLatin1String("modify-documentation must be inside modify-function, "
"modify-field or other tags that creates a type");
@@ -1390,7 +1380,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
return false;
}
- CodeSnip snip(since);
+ CodeSnip snip;
snip.language = lang;
m_contextStack.top()->functionMods.last().argument_mods.last().conversion_rules.append(snip);
} else {
@@ -1432,7 +1422,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
m_error = QLatin1String("Native to Target conversion code can only be specified for custom conversion rules.");
return false;
}
- m_contextStack.top()->codeSnips << CodeSnip(0);
+ m_contextStack.top()->codeSnips << CodeSnip();
}
break;
case StackElement::TargetToNative: {
@@ -1456,7 +1446,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
}
QString typeCheck = attributes[QLatin1String("check")];
static_cast<TypeEntry*>(m_current->entry)->customConversion()->addTargetToNativeConversion(sourceTypeName, typeCheck);
- m_contextStack.top()->codeSnips << CodeSnip(0);
+ m_contextStack.top()->codeSnips << CodeSnip();
}
break;
case StackElement::ModifyArgument: {
@@ -1488,7 +1478,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
return false;
}
- ArgumentModification argumentModification = ArgumentModification(idx, since);
+ ArgumentModification argumentModification = ArgumentModification(idx);
argumentModification.replace_value = replace_value;
argumentModification.resetAfterUse = convertBoolean(attributes[QLatin1String("invalidate-after-use")], QLatin1String("invalidate-after-use"), false);
m_contextStack.top()->functionMods.last().argument_mods.append(argumentModification);
@@ -1736,7 +1726,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
m_contextStack.top()->addedFunctions << func;
- FunctionModification mod(since);
+ FunctionModification mod;
if (!mod.setSignature(m_currentSignature, &m_error))
return false;
m_contextStack.top()->functionMods << mod;
@@ -1762,7 +1752,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
return false;
}
- FunctionModification mod(since);
+ FunctionModification mod;
if (!mod.setSignature(signature, &m_error))
return false;
m_currentSignature = signature;
@@ -1949,7 +1939,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
return false;
}
- CodeSnip snip(since);
+ CodeSnip snip;
snip.language = languageNames[className];
snip.position = positionNames[position];
bool in_file = false;
@@ -2048,7 +2038,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
return false;
break;
case StackElement::Template:
- element->value.templateEntry = new TemplateEntry(attributes[nameAttribute()], since);
+ element->value.templateEntry = new TemplateEntry(attributes.value(nameAttribute()));
break;
case StackElement::TemplateInstanceEnum:
if (!(topElement.type & StackElement::CodeSnipMask) &&
@@ -2062,7 +2052,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
"custom-destructors, conversion-rule, native-to-target or add-conversion tags.");
return false;
}
- element->value.templateInstance = new TemplateInstance(attributes[nameAttribute()], since);
+ element->value.templateInstance = new TemplateInstance(attributes.value(nameAttribute()));
break;
case StackElement::Replace:
if (topElement.type != StackElement::TemplateInstanceEnum) {
@@ -2414,43 +2404,6 @@ QString FunctionModification::toString() const
return str;
}
-bool FunctionModification::operator!=(const FunctionModification& other) const
-{
- return !(*this == other);
-}
-
-bool FunctionModification::operator==(const FunctionModification& other) const
-{
- if (m_signature.isEmpty() != other.m_signature.isEmpty())
- return false;
-
- if (m_signature.isEmpty()
- ? m_signaturePattern != other.m_signaturePattern
- : m_signature != other.m_signature) {
- return false;
- }
-
- if (association != other.association)
- return false;
-
- if (modifiers != other.modifiers)
- return false;
-
- if (removal != other.removal)
- return false;
-
- if (m_thread != other.m_thread)
- return false;
-
- if (m_allowThread != other.m_allowThread)
- return false;
-
- if (m_version != other.m_version)
- return false;
-
- return true;
-}
-
static AddedFunction::TypeInfo parseType(const QString& signature, int startPos = 0, int* endPos = 0)
{
AddedFunction::TypeInfo result;
@@ -2519,7 +2472,9 @@ static AddedFunction::TypeInfo parseType(const QString& signature, int startPos
return result;
}
-AddedFunction::AddedFunction(QString signature, QString returnType, double vr) : m_access(Public), m_version(vr)
+AddedFunction::AddedFunction(QString signature, QString returnType, double vr) :
+ m_version(vr),
+ m_access(Public)
{
Q_ASSERT(!returnType.isEmpty());
m_returnType = parseType(returnType);
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h
index eddf087b9..c8a1c88fa 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.h
+++ b/sources/shiboken2/ApiExtractor/typesystem.h
@@ -62,7 +62,6 @@ class TemplateInstance;
struct ReferenceCount
{
- ReferenceCount() {}
enum Action { // 0x01 - 0xff
Invalid = 0x00,
Add = 0x01,
@@ -76,8 +75,8 @@ struct ReferenceCount
Padding = 0xffffffff
};
- Action action;
QString varName;
+ Action action = Invalid;
};
struct ArgumentOwner
@@ -93,28 +92,23 @@ struct ArgumentOwner
ReturnIndex = 0,
FirstArgumentIndex = 1
};
- ArgumentOwner() : action(ArgumentOwner::Invalid), index(ArgumentOwner::InvalidIndex) {}
- Action action;
- int index;
+ Action action = Invalid;
+ int index = InvalidIndex;
};
class CodeSnipFragment
{
-private:
- QString m_code;
- TemplateInstance *m_instance;
-
public:
- CodeSnipFragment() : m_instance(0) {}
- CodeSnipFragment(const QString &code)
- : m_code(code),
- m_instance(0) {}
-
- CodeSnipFragment(TemplateInstance *instance)
- : m_instance(instance) {}
+ CodeSnipFragment() = default;
+ explicit CodeSnipFragment(const QString &code) : m_code(code) {}
+ explicit CodeSnipFragment(TemplateInstance *instance) : m_instance(instance) {}
QString code() const;
+
+private:
+ QString m_code;
+ TemplateInstance *m_instance = nullptr;
};
class CodeSnipAbstract
@@ -136,7 +130,7 @@ public:
class CustomFunction : public CodeSnipAbstract
{
public:
- CustomFunction(const QString &n = QString()) : name(n) { }
+ explicit CustomFunction(const QString &n = QString()) : name(n) {}
QString name;
QString paramName;
@@ -145,31 +139,21 @@ public:
class TemplateEntry : public CodeSnipAbstract
{
public:
- TemplateEntry(const QString &name, double vr)
- : m_name(name), m_version(vr)
- {
- };
+ explicit TemplateEntry(const QString &name) : m_name(name) {}
QString name() const
{
return m_name;
- };
-
- double version() const
- {
- return m_version;
}
private:
QString m_name;
- double m_version;
};
class TemplateInstance
{
public:
- TemplateInstance(const QString &name, double vr)
- : m_name(name), m_version(vr) {}
+ explicit TemplateInstance(const QString &name) : m_name(name) {}
void addReplaceRule(const QString &name, const QString &value)
{
@@ -183,14 +167,8 @@ public:
return m_name;
}
- double version() const
- {
- return m_version;
- }
-
private:
const QString m_name;
- double m_version;
QHash<QString, QString> replaceRules;
};
@@ -198,33 +176,23 @@ private:
class CodeSnip : public CodeSnipAbstract
{
public:
- CodeSnip() : language(TypeSystem::TargetLangCode), version(0) {}
- CodeSnip(double vr) : language(TypeSystem::TargetLangCode), version(vr) { }
- CodeSnip(double vr, TypeSystem::Language lang) : language(lang), version(vr) { }
+ CodeSnip() = default;
+ explicit CodeSnip(TypeSystem::Language lang) : language(lang) {}
- TypeSystem::Language language;
- TypeSystem::CodeSnipPosition position;
+ TypeSystem::Language language = TypeSystem::TargetLangCode;
+ TypeSystem::CodeSnipPosition position = TypeSystem::CodeSnipPositionAny;
ArgumentMap argumentMap;
- double version;
};
struct ArgumentModification
{
ArgumentModification() : removedDefaultExpression(false), removed(false),
- noNullPointers(false), array(false), index(-1), version(0) {}
- ArgumentModification(int idx, double vr)
- : removedDefaultExpression(false), removed(false),
- noNullPointers(false), array(false), index(idx), version(vr) {}
+ noNullPointers(false), array(false) {}
+ explicit ArgumentModification(int idx) : index(idx), removedDefaultExpression(false), removed(false),
+ noNullPointers(false), array(false) {}
// Should the default expression be removed?
- uint removedDefaultExpression : 1;
- uint removed : 1;
- uint noNullPointers : 1;
- uint resetAfterUse : 1;
- uint array : 1; // consider "int*" to be "int[]"
- // The index of this argument
- int index;
// Reference count flags for this argument
QVector<ReferenceCount> referenceCounts;
@@ -252,11 +220,17 @@ struct ArgumentModification
//QObject parent(owner) of this argument
ArgumentOwner owner;
- //Api version
- double version;
-
//New name
QString renamed_to;
+
+ // The index of this argument
+ int index = -1;
+
+ uint removedDefaultExpression : 1;
+ uint removed : 1;
+ uint noNullPointers : 1;
+ uint resetAfterUse : 1;
+ uint array : 1; // consider "int*" to be "int[]"
};
struct Modification
@@ -282,8 +256,6 @@ struct Modification
VirtualSlot = 0x10000 | NonFinal
};
- Modification() : modifiers(0), removal(TypeSystem::NoLanguage) { }
-
bool isAccessModifier() const
{
return modifiers & AccessModifierMask;
@@ -345,16 +317,13 @@ struct Modification
return removal != TypeSystem::NoLanguage;
}
- uint modifiers;
QString renamedToName;
- TypeSystem::Language removal;
+ uint modifiers = 0;
+ TypeSystem::Language removal = TypeSystem::NoLanguage;
};
struct FunctionModification: public Modification
{
- FunctionModification() : m_thread(false), m_allowThread(false), m_version(0) {}
- FunctionModification(double vr) : m_thread(false), m_allowThread(false), m_version(vr) {}
-
bool isCodeInjection() const
{
return modifiers & CodeInjection;
@@ -375,13 +344,6 @@ struct FunctionModification: public Modification
{
m_allowThread = allow;
}
- double version() const
- {
- return m_version;
- }
-
- bool operator!=(const FunctionModification& other) const;
- bool operator==(const FunctionModification& other) const;
bool matches(const QString &functionSignature) const
{
@@ -403,11 +365,8 @@ struct FunctionModification: public Modification
private:
QString m_signature;
QRegularExpression m_signaturePattern;
- bool m_thread;
- bool m_allowThread;
- double m_version;
-
-
+ bool m_thread = false;
+ bool m_allowThread = false;
};
struct FieldModification: public Modification
@@ -445,19 +404,19 @@ struct AddedFunction
* AbstractMetaType and AbstractMetaArgument for the AbstractMetaFunctions.
*/
struct TypeInfo {
- TypeInfo() : isConstant(false), indirections(0), isReference(false) {}
+ TypeInfo() = default;
static TypeInfo fromSignature(const QString& signature);
QString name;
- bool isConstant;
- int indirections;
- bool isReference;
QString defaultValue;
+ int indirections = 0;
+ bool isConstant = false;
+ bool isReference = false;
};
/// Creates a new AddedFunction with a signature and a return type.
- AddedFunction(QString signature, QString returnType, double vr);
- AddedFunction() : m_access(Protected), m_isConst(false), m_isStatic(false), m_version(0) {}
+ explicit AddedFunction(QString signature, QString returnType, double vr);
+ AddedFunction() = default;
/// Returns the function name.
QString name() const
@@ -513,12 +472,12 @@ struct AddedFunction
}
private:
QString m_name;
- Access m_access;
QVector<TypeInfo> m_arguments;
TypeInfo m_returnType;
- bool m_isConst;
- bool m_isStatic;
- double m_version;
+ double m_version = 0;
+ Access m_access = Protected;
+ bool m_isConst = false;
+ bool m_isStatic = false;
};
#ifndef QT_NO_DEBUG_STREAM
@@ -526,29 +485,17 @@ QDebug operator<<(QDebug d, const AddedFunction::TypeInfo &ti);
QDebug operator<<(QDebug d, const AddedFunction &af);
#endif
-struct ExpensePolicy
-{
- ExpensePolicy() : limit(-1) {}
- int limit;
- QString cost;
- bool isValid() const
- {
- return limit >= 0;
- }
-};
-
class InterfaceTypeEntry;
class ObjectTypeEntry;
class DocModification
{
public:
- DocModification() : format(TypeSystem::NativeCode), m_mode(TypeSystem::DocModificationXPathReplace), m_version(0) {}
- DocModification(const QString& xpath, const QString& signature, double vr)
- : format(TypeSystem::NativeCode), m_mode(TypeSystem::DocModificationXPathReplace),
- m_xpath(xpath), m_signature(signature), m_version(vr) {}
- DocModification(TypeSystem::DocModificationMode mode, const QString& signature, double vr)
- : m_mode(mode), m_signature(signature), m_version(vr) {}
+ DocModification() = default;
+ explicit DocModification(const QString& xpath, const QString& signature) :
+ m_xpath(xpath), m_signature(signature) {}
+ explicit DocModification(TypeSystem::DocModificationMode mode, const QString& signature) :
+ m_signature(signature), m_mode(mode) {}
void setCode(const QString& code) { m_code = code; }
void setCode(const QStringRef& code) { m_code = code.toString(); }
@@ -569,19 +516,16 @@ public:
{
return m_mode;
}
- double version() const
- {
- return m_version;
- }
- TypeSystem::Language format;
+ TypeSystem::Language format() const { return m_format; }
+ void setFormat(TypeSystem::Language f) { m_format = f; }
private:
- TypeSystem::DocModificationMode m_mode;
QString m_code;
QString m_xpath;
QString m_signature;
- double m_version;
+ TypeSystem::DocModificationMode m_mode = TypeSystem::DocModificationXPathReplace;
+ TypeSystem::Language m_format = TypeSystem::NativeCode;
};
class CustomConversion;
@@ -1424,16 +1368,6 @@ public:
return m_heldTypeValue;
}
-
- void setExpensePolicy(const ExpensePolicy &policy)
- {
- m_expensePolicy = policy;
- }
- const ExpensePolicy &expensePolicy() const
- {
- return m_expensePolicy;
- }
-
QString targetType() const
{
return m_targetType;
@@ -1507,7 +1441,6 @@ private:
QString m_heldTypeValue;
QString m_lookupName;
QString m_targetType;
- ExpensePolicy m_expensePolicy;
TypeFlags m_typeFlags;
CopyableFlag m_copyableFlag = Unknown;
QString m_hashFunction;
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
index 014b44476..5b58e7e8a 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
@@ -1387,9 +1387,9 @@ bool QtDocGenerator::writeInjectDocumentation(QTextStream& s,
Documentation doc;
Documentation::Format fmt;
- if (mod.format == TypeSystem::NativeCode)
+ if (mod.format() == TypeSystem::NativeCode)
fmt = Documentation::Native;
- else if (mod.format == TypeSystem::TargetLangCode)
+ else if (mod.format() == TypeSystem::TargetLangCode)
fmt = Documentation::Target;
else
continue;
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 35d896333..0a07964a5 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -2354,7 +2354,7 @@ static void addConversionRuleCodeSnippet(CodeSnipList& snippetList, QString& rul
} else {
rule.replace(QLatin1String("%out"), outputName);
}
- CodeSnip snip(0, snippetLanguage);
+ CodeSnip snip(snippetLanguage);
snip.position = (snippetLanguage == TypeSystem::NativeCode) ? TypeSystem::CodeSnipPositionAny : TypeSystem::CodeSnipPositionBeginning;
snip.addCode(rule);
snippetList << snip;