aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/typesystem.h
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystem.h')
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.h381
1 files changed, 200 insertions, 181 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h
index 186c4b24d..b0144923a 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.h
+++ b/sources/shiboken2/ApiExtractor/typesystem.h
@@ -43,8 +43,8 @@
#include <QtCore/QVersionNumber>
//Used to identify the conversion rule to avoid break API
-#define TARGET_CONVERSION_RULE_FLAG "0"
-#define NATIVE_CONVERSION_RULE_FLAG "1"
+extern const char *TARGET_CONVERSION_RULE_FLAG;
+extern const char *NATIVE_CONVERSION_RULE_FLAG;
class Indentor;
@@ -203,12 +203,6 @@ struct ArgumentModification
QString replace_value;
- // The code to be used to construct a return value when noNullPointers is true and
- // the returned value is null. If noNullPointers is true and this string is
- // empty, then the base class implementation will be used (or a default construction
- // if there is no implementation)
- QString nullPointerDefaultValue;
-
// The text of the new default expression of the argument
QString replacedDefaultExpression;
@@ -237,6 +231,7 @@ struct ArgumentModification
struct Modification
{
enum Modifiers {
+ InvalidModifier = 0x0000,
Private = 0x0001,
Protected = 0x0002,
Public = 0x0003,
@@ -253,8 +248,7 @@ struct Modification
CodeInjection = 0x1000,
Rename = 0x2000,
Deprecated = 0x4000,
- ReplaceExpression = 0x8000,
- VirtualSlot = 0x10000 | NonFinal
+ ReplaceExpression = 0x8000
};
bool isAccessModifier() const
@@ -289,10 +283,6 @@ struct Modification
{
return modifiers & NonFinal;
}
- bool isVirtualSlot() const
- {
- return (modifiers & VirtualSlot) == VirtualSlot;
- }
QString accessModifierString() const;
bool isDeprecated() const
@@ -318,6 +308,10 @@ struct Modification
return removal != TypeSystem::NoLanguage;
}
+#ifndef QT_NO_DEBUG_STREAM
+ void formatDebug(QDebug &d) const;
+#endif
+
QString renamedToName;
uint modifiers = 0;
TypeSystem::Language removal = TypeSystem::NoLanguage;
@@ -325,6 +319,8 @@ struct Modification
struct FunctionModification: public Modification
{
+ using AllowThread = TypeSystem::AllowThread;
+
bool isCodeInjection() const
{
return modifiers & CodeInjection;
@@ -337,14 +333,9 @@ struct FunctionModification: public Modification
{
return m_thread;
}
- bool allowThread() const
- {
- return m_allowThread;
- }
- void setAllowThread(bool allow)
- {
- m_allowThread = allow;
- }
+
+ AllowThread allowThread() const { return m_allowThread; }
+ void setAllowThread(AllowThread allow) { m_allowThread = allow; }
bool matches(const QString &functionSignature) const
{
@@ -359,8 +350,15 @@ struct FunctionModification: public Modification
void setOriginalSignature(const QString &s) { m_originalSignature = s; }
QString originalSignature() const { return m_originalSignature; }
+ TypeSystem::ExceptionHandling exceptionHandling() const { return m_exceptionHandling; }
+ void setExceptionHandling(TypeSystem::ExceptionHandling e) { m_exceptionHandling = e; }
+
QString toString() const;
+#ifndef QT_NO_DEBUG_STREAM
+ void formatDebug(QDebug &d) const;
+#endif
+
QString association;
CodeSnipList snips;
@@ -371,9 +369,17 @@ private:
QString m_originalSignature;
QRegularExpression m_signaturePattern;
bool m_thread = false;
- bool m_allowThread = false;
+ AllowThread m_allowThread = AllowThread::Unspecified;
+ TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified;
};
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug d, const ReferenceCount &);
+QDebug operator<<(QDebug d, const ArgumentOwner &a);
+QDebug operator<<(QDebug d, const ArgumentModification &a);
+QDebug operator<<(QDebug d, const FunctionModification &fm);
+#endif
+
struct FieldModification: public Modification
{
bool isReadable() const
@@ -398,6 +404,7 @@ struct AddedFunction
{
/// Function access types.
enum Access {
+ InvalidAccess = 0,
Protected = 0x1,
Public = 0x2
};
@@ -532,7 +539,6 @@ class CustomConversion;
class TypeEntry
{
- Q_DISABLE_COPY(TypeEntry)
Q_GADGET
public:
enum Type {
@@ -558,7 +564,8 @@ public:
CustomType,
TargetLangType,
FunctionType,
- SmartPointerType
+ SmartPointerType,
+ TypedefType
};
Q_ENUM(Type)
@@ -670,15 +677,6 @@ public:
return m_type == EnumValue;
}
- virtual bool preferredConversion() const
- {
- return m_preferredConversion;
- }
- virtual void setPreferredConversion(bool b)
- {
- m_preferredConversion = b;
- }
-
bool stream() const
{
return m_stream;
@@ -715,6 +713,11 @@ public:
&& m_codeGeneration != TypeEntry::GenerateNothing;
}
+ int revision() const { return m_revision; }
+ void setRevision(int r); // see typedatabase.cpp
+ int sbkIndex() const;
+ void setSbkIndex(int i) { m_sbkIndex = i; }
+
virtual QString qualifiedCppName() const
{
return m_name;
@@ -747,10 +750,8 @@ public:
}
// The package
- virtual QString targetLangPackage() const
- {
- return QString();
- }
+ QString targetLangPackage() const { return m_targetLangPackage; }
+ void setTargetLangPackage(const QString &p) { m_targetLangPackage = p; }
virtual QString qualifiedTargetLangName() const
{
@@ -889,13 +890,29 @@ public:
bool hasCustomConversion() const;
void setCustomConversion(CustomConversion* customConversion);
CustomConversion* customConversion() const;
+
+ virtual TypeEntry *clone() const;
+
+ void useAsTypedef(const TypeEntry *source);
+
+#ifndef QT_NO_DEBUG_STREAM
+ virtual void formatDebug(QDebug &d) const;
+#endif
+
+protected:
+ TypeEntry(const TypeEntry &);
+
private:
+ TypeEntry &operator=(const TypeEntry &) = delete;
+ TypeEntry &operator=(TypeEntry &&) = delete;
+ TypeEntry(TypeEntry &&) = delete;
+
QString m_name;
+ QString m_targetLangPackage;
Type m_type;
uint m_codeGeneration = GenerateAll;
CustomFunction m_customConstructor;
CustomFunction m_customDestructor;
- bool m_preferredConversion = true;
CodeSnipList m_codeSnips;
DocModificationList m_docModifications;
IncludeList m_extraIncludes;
@@ -904,24 +921,42 @@ private:
QString m_conversionRule;
bool m_stream = false;
QVersionNumber m_version;
+ CustomConversion *m_customConversion = nullptr;
+ int m_revision = 0;
+ int m_sbkIndex = 0;
};
class TypeSystemTypeEntry : public TypeEntry
{
public:
explicit TypeSystemTypeEntry(const QString &name, const QVersionNumber &vr);
+
+ TypeEntry *clone() const override;
+
+protected:
+ TypeSystemTypeEntry(const TypeSystemTypeEntry &);
};
class VoidTypeEntry : public TypeEntry
{
public:
VoidTypeEntry();
+
+ TypeEntry *clone() const override;
+
+protected:
+ VoidTypeEntry(const VoidTypeEntry &);
};
class VarargsTypeEntry : public TypeEntry
{
public:
VarargsTypeEntry();
+
+ TypeEntry *clone() const override;
+
+protected:
+ VarargsTypeEntry(const VarargsTypeEntry &);
};
class TemplateArgumentEntry : public TypeEntry
@@ -938,6 +973,11 @@ public:
m_ordinal = o;
}
+ TypeEntry *clone() const override;
+
+protected:
+ TemplateArgumentEntry(const TemplateArgumentEntry &);
+
private:
int m_ordinal = 0;
};
@@ -959,6 +999,11 @@ public:
QString targetLangName() const override;
QString targetLangApiName() const override;
+ TypeEntry *clone() const override;
+
+protected:
+ ArrayTypeEntry(const ArrayTypeEntry &);
+
private:
const TypeEntry *m_nestedType;
};
@@ -1019,9 +1064,6 @@ public:
*/
PrimitiveTypeEntry* basicReferencedTypeEntry() const;
- bool preferredConversion() const override;
- void setPreferredConversion(bool b) override;
-
bool preferredTargetLangType() const
{
return m_preferredTargetLangType;
@@ -1031,26 +1073,27 @@ public:
m_preferredTargetLangType = b;
}
- void setTargetLangPackage(const QString& package);
- QString targetLangPackage() const override;
+ TypeEntry *clone() const override;
+
+protected:
+ PrimitiveTypeEntry(const PrimitiveTypeEntry &);
+
private:
QString m_targetLangName;
QString m_targetLangApiName;
QString m_defaultConstructor;
- uint m_preferredConversion : 1;
uint m_preferredTargetLangType : 1;
PrimitiveTypeEntry* m_referencedTypeEntry = nullptr;
};
+class EnumValueTypeEntry;
+
class EnumTypeEntry : public TypeEntry
{
public:
explicit EnumTypeEntry(const QString &nspace, const QString &enumName,
const QVersionNumber &vr);
- QString targetLangPackage() const override;
- void setTargetLangPackage(const QString &package);
-
QString targetLangName() const override;
QString targetLangQualifier() const;
QString qualifiedTargetLangName() const override;
@@ -1066,30 +1109,8 @@ public:
m_qualifier = q;
}
- bool preferredConversion() const override;
-
- bool isBoundsChecked() const
- {
- return m_lowerBound.isEmpty() && m_upperBound.isEmpty();
- }
-
- QString upperBound() const
- {
- return m_upperBound;
- }
- void setUpperBound(const QString &bound)
- {
- m_upperBound = bound;
- }
-
- QString lowerBound() const
- {
- return m_lowerBound;
- }
- void setLowerBound(const QString &bound)
- {
- m_lowerBound = bound;
- }
+ const EnumValueTypeEntry *nullValue() const { return m_nullValue; }
+ void setNullValue(const EnumValueTypeEntry *n) { m_nullValue = n; }
void setFlags(FlagsTypeEntry *flags)
{
@@ -1100,15 +1121,6 @@ public:
return m_flags;
}
- bool isExtensible() const
- {
- return m_extensible;
- }
- void setExtensible(bool is)
- {
- m_extensible = is;
- }
-
bool isEnumValueRejected(const QString &name) const
{
return m_rejectedEnums.contains(name);
@@ -1122,33 +1134,27 @@ public:
return m_rejectedEnums;
}
- bool forceInteger() const
- {
- return m_forceInteger;
- }
- void setForceInteger(bool force)
- {
- m_forceInteger = force;
- }
+ TypeEntry *clone() const override;
+#ifndef QT_NO_DEBUG_STREAM
+ void formatDebug(QDebug &d) const override;
+#endif
+protected:
+ EnumTypeEntry(const EnumTypeEntry &);
private:
QString m_packageName;
QString m_qualifier;
QString m_targetLangName;
-
- QString m_lowerBound;
- QString m_upperBound;
+ const EnumValueTypeEntry *m_nullValue = nullptr;
QStringList m_rejectedEnums;
FlagsTypeEntry *m_flags = nullptr;
-
- bool m_extensible = false;
- bool m_forceInteger = false;
};
// EnumValueTypeEntry is used for resolving integer type templates
-// like array<EnumValue>.
+// like array<EnumValue>. Note: Dummy entries for integer values will
+// be created for non-type template parameters, where m_enclosingEnum==nullptr.
class EnumValueTypeEntry : public TypeEntry
{
public:
@@ -1156,6 +1162,12 @@ public:
QString value() const { return m_value; }
const EnumTypeEntry* enclosingEnum() const { return m_enclosingEnum; }
+
+ TypeEntry *clone() const override;
+
+protected:
+ EnumValueTypeEntry(const EnumValueTypeEntry &);
+
private:
QString m_value;
const EnumTypeEntry* m_enclosingEnum;
@@ -1169,7 +1181,6 @@ public:
QString qualifiedTargetLangName() const override;
QString targetLangName() const override;
QString targetLangApiName() const override;
- bool preferredConversion() const override;
QString originalName() const
{
@@ -1189,11 +1200,6 @@ public:
m_targetLangName = name;
}
- bool forceInteger() const
- {
- return m_enum->forceInteger();
- }
-
EnumTypeEntry *originator() const
{
return m_enum;
@@ -1203,7 +1209,10 @@ public:
m_enum = e;
}
- QString targetLangPackage() const override;
+ TypeEntry *clone() const override;
+
+protected:
+ FlagsTypeEntry(const FlagsTypeEntry &);
private:
QString m_originalName;
@@ -1216,8 +1225,6 @@ class ComplexTypeEntry : public TypeEntry
{
public:
enum TypeFlag {
- ForceAbstract = 0x1,
- DeleteInMainThread = 0x2,
Deprecated = 0x4
};
typedef QFlags<TypeFlag> TypeFlags;
@@ -1288,12 +1295,6 @@ public:
return m_fieldMods;
}
- QString targetLangPackage() const override;
- void setTargetLangPackage(const QString &package)
- {
- m_package = package;
- }
-
bool isQObject() const
{
return m_qobject;
@@ -1336,15 +1337,6 @@ public:
return m_polymorphicIdValue;
}
- void setHeldType(const QString &value)
- {
- m_heldTypeValue = value;
- }
- QString heldTypeValue() const
- {
- return m_heldTypeValue;
- }
-
QString targetType() const
{
return m_targetType;
@@ -1369,6 +1361,9 @@ public:
m_genericClass = isGeneric;
}
+ bool deleteInMainThread() const { return m_deleteInMainThread; }
+ void setDeleteInMainThread(bool d) { m_deleteInMainThread = d; }
+
CopyableFlag copyable() const
{
return m_copyableFlag;
@@ -1397,15 +1392,28 @@ public:
return m_baseContainerType;
}
+ TypeSystem::ExceptionHandling exceptionHandling() const { return m_exceptionHandling; }
+ void setExceptionHandling(TypeSystem::ExceptionHandling e) { m_exceptionHandling = e; }
+
QString defaultConstructor() const;
void setDefaultConstructor(const QString& defaultConstructor);
bool hasDefaultConstructor() const;
+ TypeEntry *clone() const override;
+
+ void useAsTypedef(const ComplexTypeEntry *source);
+
+#ifndef QT_NO_DEBUG_STREAM
+ void formatDebug(QDebug &d) const override;
+#endif
+protected:
+ ComplexTypeEntry(const ComplexTypeEntry &);
+
private:
AddedFunctionList m_addedFunctions;
FunctionModificationList m_functionMods;
FieldModificationList m_fieldMods;
- QString m_package;
+ QString m_defaultConstructor;
QString m_defaultSuperclass;
QString m_qualifiedCppName;
QString m_targetLangName;
@@ -1413,9 +1421,9 @@ private:
uint m_qobject : 1;
uint m_polymorphicBase : 1;
uint m_genericClass : 1;
+ uint m_deleteInMainThread : 1;
QString m_polymorphicIdValue;
- QString m_heldTypeValue;
QString m_lookupName;
QString m_targetType;
TypeFlags m_typeFlags;
@@ -1423,6 +1431,38 @@ private:
QString m_hashFunction;
const ComplexTypeEntry* m_baseContainerType = nullptr;
+ // For class functions
+ TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified;
+};
+
+class TypedefEntry : public ComplexTypeEntry
+{
+public:
+ explicit TypedefEntry(const QString &name,
+ const QString &sourceType,
+ const QVersionNumber &vr);
+
+ QString sourceType() const { return m_sourceType; }
+ void setSourceType(const QString &s) { m_sourceType =s; }
+
+ TypeEntry *clone() const override;
+
+ ComplexTypeEntry *source() const { return m_source; }
+ void setSource(ComplexTypeEntry *source) { m_source = source; }
+
+ ComplexTypeEntry *target() const { return m_target; }
+ void setTarget(ComplexTypeEntry *target) { m_target = target; }
+
+#ifndef QT_NO_DEBUG_STREAM
+ virtual void formatDebug(QDebug &d) const override;
+#endif
+protected:
+ TypedefEntry(const TypedefEntry &);
+
+private:
+ QString m_sourceType;
+ ComplexTypeEntry *m_source = nullptr;
+ ComplexTypeEntry *m_target = nullptr;
};
class ContainerTypeEntry : public ComplexTypeEntry
@@ -1455,28 +1495,15 @@ public:
QString typeName() const;
QString targetLangName() const override;
- QString targetLangPackage() const override;
QString qualifiedCppName() const override;
- static Type containerTypeFromString(QString typeName)
- {
- static QHash<QString, Type> m_stringToContainerType;
- if (m_stringToContainerType.isEmpty()) {
- m_stringToContainerType.insert(QLatin1String("list"), ListContainer);
- m_stringToContainerType.insert(QLatin1String("string-list"), StringListContainer);
- m_stringToContainerType.insert(QLatin1String("linked-list"), LinkedListContainer);
- m_stringToContainerType.insert(QLatin1String("vector"), VectorContainer);
- m_stringToContainerType.insert(QLatin1String("stack"), StackContainer);
- m_stringToContainerType.insert(QLatin1String("queue"), QueueContainer);
- m_stringToContainerType.insert(QLatin1String("set"), SetContainer);
- m_stringToContainerType.insert(QLatin1String("map"), MapContainer);
- m_stringToContainerType.insert(QLatin1String("multi-map"), MultiMapContainer);
- m_stringToContainerType.insert(QLatin1String("hash"), HashContainer);
- m_stringToContainerType.insert(QLatin1String("multi-hash"), MultiHashContainer);
- m_stringToContainerType.insert(QLatin1String("pair"), PairContainer);
- }
- return m_stringToContainerType.value(typeName, NoContainer);
- }
+ TypeEntry *clone() const override;
+
+#ifndef QT_NO_DEBUG_STREAM
+ void formatDebug(QDebug &d) const override;
+#endif
+protected:
+ ContainerTypeEntry(const ContainerTypeEntry &);
private:
Type m_type;
@@ -1501,6 +1528,11 @@ public:
return m_refCountMethodName;
}
+ TypeEntry *clone() const override;
+
+protected:
+ SmartPointerTypeEntry(const SmartPointerTypeEntry &);
+
private:
QString m_getterName;
QString m_smartPointerType;
@@ -1511,6 +1543,11 @@ class NamespaceTypeEntry : public ComplexTypeEntry
{
public:
explicit NamespaceTypeEntry(const QString &name, const QVersionNumber &vr);
+
+ TypeEntry *clone() const override;
+
+protected:
+ NamespaceTypeEntry(const NamespaceTypeEntry &);
};
@@ -1523,48 +1560,13 @@ public:
bool isNativeIdBased() const override;
+ TypeEntry *clone() const override;
+
protected:
explicit ValueTypeEntry(const QString &name, Type t, const QVersionNumber &vr);
+ ValueTypeEntry(const ValueTypeEntry &);
};
-
-class StringTypeEntry : public ValueTypeEntry
-{
-public:
- explicit StringTypeEntry(const QString &name, const QVersionNumber &vr);
-
- QString targetLangApiName() const override;
- QString targetLangName() const override;
- QString targetLangPackage() const override;
-
- bool isNativeIdBased() const override;
-};
-
-class CharTypeEntry : public ValueTypeEntry
-{
-public:
- explicit CharTypeEntry(const QString &name, const QVersionNumber &vr);
-
- QString targetLangApiName() const override;
- QString targetLangName() const override;
- QString targetLangPackage() const override;
-
- bool isNativeIdBased() const override;
-};
-
-class VariantTypeEntry: public ValueTypeEntry
-{
-public:
- explicit VariantTypeEntry(const QString &name, const QVersionNumber &vr);
-
- QString targetLangApiName() const override;
- QString targetLangName() const override;
- QString targetLangPackage() const override;
-
- bool isNativeIdBased() const override;
-};
-
-
class InterfaceTypeEntry : public ComplexTypeEntry
{
public:
@@ -1587,6 +1589,11 @@ public:
bool isNativeIdBased() const override;
QString qualifiedCppName() const override;
+ TypeEntry *clone() const override;
+
+protected:
+ InterfaceTypeEntry(const InterfaceTypeEntry &);
+
private:
ObjectTypeEntry *m_origin;
};
@@ -1611,6 +1618,12 @@ public:
{
return m_signatures.contains(signature);
}
+
+ TypeEntry *clone() const override;
+
+protected:
+ FunctionTypeEntry(const FunctionTypeEntry &);
+
private:
QStringList m_signatures;
};
@@ -1628,6 +1641,11 @@ public:
bool isNativeIdBased() const override;
+ TypeEntry *clone() const override;
+
+protected:
+ ObjectTypeEntry(const ObjectTypeEntry &);
+
private:
InterfaceTypeEntry *m_interface = nullptr;
};
@@ -1641,7 +1659,8 @@ struct TypeRejection
Field, // Match className and field name
Enum, // Match className and enum name
ArgumentType, // Match className and argument type
- ReturnType // Match className and return type
+ ReturnType, // Match className and return type
+ Invalid
};
QRegularExpression className;