aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/cmake/Macros/PySideModules.cmake5
-rw-r--r--sources/pyside2/pyside_version.py2
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp48
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.cpp118
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.h49
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp27
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h2
-rw-r--r--sources/shiboken2/ApiExtractor/include.cpp2
-rw-r--r--sources/shiboken2/ApiExtractor/messages.cpp6
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp10
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.h4
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel_enums.h7
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp53
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.h8
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp47
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.h49
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem_enums.h7
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp50
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.h2
-rw-r--r--sources/shiboken2/doc/typesystem_specifying_types.rst28
-rw-r--r--sources/shiboken2/generator/generator.cpp60
-rw-r--r--sources/shiboken2/generator/main.cpp8
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp143
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp1954
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.h3
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.cpp135
-rw-r--r--sources/shiboken2/generator/shiboken2/overloaddata.cpp14
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp35
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.h2
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp15
-rw-r--r--sources/shiboken2/shiboken_version.py2
-rw-r--r--sources/shiboken2/tests/helper.py38
-rw-r--r--sources/shiboken2/tests/libother/otherobjecttype.cpp10
-rw-r--r--sources/shiboken2/tests/libother/otherobjecttype.h7
-rw-r--r--sources/shiboken2/tests/libsample/CMakeLists.txt1
-rw-r--r--sources/shiboken2/tests/libsample/renaming.cpp46
-rw-r--r--sources/shiboken2/tests/libsample/renaming.h50
-rw-r--r--sources/shiboken2/tests/libsample/samplenamespace.h9
-rw-r--r--sources/shiboken2/tests/libsmart/smart.cpp25
-rw-r--r--sources/shiboken2/tests/libsmart/smart_integer.h8
-rw-r--r--sources/shiboken2/tests/libsmart/smart_obj.h4
-rw-r--r--sources/shiboken2/tests/otherbinding/signature_test.py48
-rw-r--r--sources/shiboken2/tests/samplebinding/CMakeLists.txt3
-rw-r--r--sources/shiboken2/tests/samplebinding/global.h1
-rw-r--r--sources/shiboken2/tests/samplebinding/namespace_test.py19
-rw-r--r--sources/shiboken2/tests/samplebinding/renaming_test.py57
-rw-r--r--sources/shiboken2/tests/samplebinding/typesystem_sample.xml6
-rw-r--r--sources/shiboken2/tests/smartbinding/smart_pointer_test.py16
48 files changed, 1882 insertions, 1361 deletions
diff --git a/sources/pyside2/cmake/Macros/PySideModules.cmake b/sources/pyside2/cmake/Macros/PySideModules.cmake
index dca00ec11..14707f964 100644
--- a/sources/pyside2/cmake/Macros/PySideModules.cmake
+++ b/sources/pyside2/cmake/Macros/PySideModules.cmake
@@ -91,7 +91,10 @@ macro(create_pyside_module)
list(REMOVE_DUPLICATES total_type_system_files)
# Contains include directories to pass to shiboken's preprocessor.
- set(shiboken_include_dirs ${pyside2_SOURCE_DIR}${PATH_SEP}${QT_INCLUDE_DIR})
+ # Workaround: Added ${QT_INCLUDE_DIR}/QtCore until
+ # qtdeclarative/8d560d1bf0a747bf62f73fad6b6774095442d9d2 has reached qt5.git
+ string(REPLACE ";" ${PATH_SEP} core_includes "${Qt5Core_INCLUDE_DIRS}")
+ set(shiboken_include_dirs ${pyside2_SOURCE_DIR}${PATH_SEP}${QT_INCLUDE_DIR}${PATH_SEP}${core_includes})
set(shiboken_framework_include_dirs_option "")
if(CMAKE_HOST_APPLE)
set(shiboken_framework_include_dirs "${QT_FRAMEWORK_INCLUDE_DIR}")
diff --git a/sources/pyside2/pyside_version.py b/sources/pyside2/pyside_version.py
index 78ea0019d..c022fc803 100644
--- a/sources/pyside2/pyside_version.py
+++ b/sources/pyside2/pyside_version.py
@@ -38,7 +38,7 @@
#############################################################################
major_version = "5"
-minor_version = "14"
+minor_version = "15"
patch_version = "0"
# For example: "a", "b", "rc"
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 4566ed3bc..f6c9e407c 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -410,6 +410,7 @@ FileModelItem AbstractMetaBuilderPrivate::buildDom(QByteArrayList arguments,
unsigned clangFlags)
{
clang::Builder builder;
+ builder.setSystemIncludes(TypeDatabase::instance()->systemIncludes());
if (level == LanguageLevel::Default)
level = clang::emulatedCompilerLanguageLevel();
arguments.prepend(QByteArrayLiteral("-std=")
@@ -549,11 +550,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
if (!entry->isPrimitive()) {
if ((entry->isValue() || entry->isObject())
&& !types->shouldDropTypeEntry(entry->qualifiedCppName())
- && !entry->isString()
- && !entry->isChar()
&& !entry->isContainer()
&& !entry->isCustom()
- && !entry->isVariant()
&& (entry->generateCode() & TypeEntry::GenerateTargetLang)
&& !AbstractMetaClass::findClass(m_metaClasses, entry)) {
qCWarning(lcShiboken).noquote().nospace()
@@ -758,6 +756,11 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel
return nullptr;
}
+ if (namespaceItem->type() == NamespaceType::Inline) {
+ type->setInlineNamespace(true);
+ TypeDatabase::instance()->addInlineNamespaceLookups(type);
+ }
+
// Continue populating namespace?
AbstractMetaClass *metaClass = AbstractMetaClass::findClass(m_metaClasses, type);
if (!metaClass) {
@@ -1215,7 +1218,7 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel
metaField->setType(metaType);
- AbstractMetaAttributes::Attributes attr = nullptr;
+ AbstractMetaAttributes::Attributes attr;
if (field->isStatic())
attr |= AbstractMetaAttributes::Static;
@@ -1292,38 +1295,11 @@ static bool _compareAbstractMetaTypes(const AbstractMetaType *type,
&& (type == nullptr || type->compare(*other, flags));
}
-static bool _compareAbstractMetaFunctions(const AbstractMetaFunction *func,
- const AbstractMetaFunction *other,
- AbstractMetaType::ComparisonFlags argumentFlags = {})
-{
- if (!func && !other)
- return true;
- if (!func || !other)
- return false;
- if (func->name() != other->name())
- return false;
- const int argumentsCount = func->arguments().count();
- if (argumentsCount != other->arguments().count()
- || func->isConstant() != other->isConstant()
- || func->isStatic() != other->isStatic()
- || !_compareAbstractMetaTypes(func->type(), other->type())) {
- return false;
- }
- for (int i = 0; i < argumentsCount; ++i) {
- if (!_compareAbstractMetaTypes(func->arguments().at(i)->type(),
- other->arguments().at(i)->type(),
- argumentFlags)) {
- return false;
- }
- }
- return true;
-}
-
AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem,
AbstractMetaClass::Attributes *constructorAttributes,
AbstractMetaClass *currentClass)
{
- *constructorAttributes = nullptr;
+ *constructorAttributes = {};
AbstractMetaFunctionList result;
const FunctionList &scopeFunctionList = scopeItem->functions();
result.reserve(scopeFunctionList.size());
@@ -2913,7 +2889,7 @@ static void writeRejectLogFile(const QString &name,
for (int reason = 0; reason < AbstractMetaBuilder::NoReason; ++reason) {
- s << QString(72, QLatin1Char('*')) << endl;
+ s << QString(72, QLatin1Char('*')) << Qt::endl;
switch (reason) {
case AbstractMetaBuilder::NotInTypeSystem:
s << "Not in type system";
@@ -2946,16 +2922,16 @@ static void writeRejectLogFile(const QString &name,
break;
}
- s << endl;
+ s << Qt::endl;
for (QMap<QString, AbstractMetaBuilder::RejectReason>::const_iterator it = rejects.constBegin();
it != rejects.constEnd(); ++it) {
if (it.value() != reason)
continue;
- s << " - " << it.key() << endl;
+ s << " - " << it.key() << Qt::endl;
}
- s << QString(72, QLatin1Char('*')) << endl << endl;
+ s << QString(72, QLatin1Char('*')) << Qt::endl << Qt::endl;
}
}
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
index 5ae671d87..b07ea0f0e 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
@@ -531,7 +531,7 @@ bool AbstractMetaFunction::operator<(const AbstractMetaFunction &other) const
*/
AbstractMetaFunction::CompareResult AbstractMetaFunction::compareTo(const AbstractMetaFunction *other) const
{
- CompareResult result = nullptr;
+ CompareResult result;
// Enclosing class...
if (ownerClass() == other->ownerClass())
@@ -1858,6 +1858,14 @@ const AbstractMetaFunction *AbstractMetaField::setter() const
return m_setter;
}
+const AbstractMetaClass *EnclosingClassMixin::targetLangEnclosingClass() const
+{
+ auto result = m_enclosingClass;
+ while (result && !NamespaceTypeEntry::isVisibleScope(result->typeEntry()))
+ result = result->enclosingClass();
+ return result;
+}
+
const AbstractMetaFunction *AbstractMetaField::getter() const
{
if (!m_getter) {
@@ -2676,6 +2684,60 @@ AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &cla
}
#ifndef QT_NO_DEBUG_STREAM
+
+void AbstractMetaClass::format(QDebug &d) const
+{
+ if (d.verbosity() > 2)
+ d << static_cast<const void *>(this) << ", ";
+ d << '"' << qualifiedCppName();
+ if (const int count = m_templateArgs.size()) {
+ for (int i = 0; i < count; ++i)
+ d << (i ? ',' : '<') << m_templateArgs.at(i)->qualifiedCppName();
+ d << '>';
+ }
+ d << '"';
+ if (isNamespace())
+ d << " [namespace]";
+ if (attributes() & AbstractMetaAttributes::FinalCppClass)
+ d << " [final]";
+ if (attributes().testFlag(AbstractMetaAttributes::Deprecated))
+ d << " [deprecated]";
+ if (m_baseClass)
+ d << ", inherits \"" << m_baseClass->name() << '"';
+ if (auto templateBase = templateBaseClass()) {
+ const auto instantiatedTypes = templateBaseClassInstantiations();
+ d << ", instantiates \"" << templateBase->name();
+ for (int i = 0, count = instantiatedTypes.size(); i < count; ++i)
+ d << (i ? ',' : '<') << instantiatedTypes.at(i)->name();
+ d << ">\"";
+ }
+}
+
+void AbstractMetaClass::formatMembers(QDebug &d) const
+{
+ if (!m_enums.isEmpty())
+ d << ", enums[" << m_enums.size() << "]=" << m_enums;
+ if (!m_functions.isEmpty()) {
+ const int count = m_functions.size();
+ d << ", functions=[" << count << "](";
+ for (int i = 0; i < count; ++i) {
+ if (i)
+ d << ", ";
+ formatMetaFunctionBrief(d, m_functions.at(i));
+ }
+ d << ')';
+ }
+ if (const int count = m_fields.size()) {
+ d << ", fields=[" << count << "](";
+ for (int i = 0; i < count; ++i) {
+ if (i)
+ d << ", ";
+ formatMetaField(d, m_fields.at(i));
+ }
+ d << ')';
+ }
+}
+
QDebug operator<<(QDebug d, const AbstractMetaClass *ac)
{
QDebugStateSaver saver(d);
@@ -2683,57 +2745,9 @@ QDebug operator<<(QDebug d, const AbstractMetaClass *ac)
d.nospace();
d << "AbstractMetaClass(";
if (ac) {
- d << '"' << ac->fullName() << '"';
- if (ac->attributes() & AbstractMetaAttributes::FinalCppClass)
- d << " [final]";
- if (ac->attributes().testFlag(AbstractMetaAttributes::Deprecated))
- d << " [deprecated]";
- if (ac->m_baseClass)
- d << ", inherits \"" << ac->m_baseClass->name() << '"';
- if (ac->m_templateBaseClass)
- d << ", inherits template \"" << ac->m_templateBaseClass->name() << '"';
- const AbstractMetaEnumList &enums = ac->enums();
- if (!enums.isEmpty())
- d << ", enums[" << enums.size() << "]=" << enums;
- const AbstractMetaFunctionList &functions = ac->functions();
- if (!functions.isEmpty()) {
- const int count = functions.size();
- d << ", functions=[" << count << "](";
- for (int i = 0; i < count; ++i) {
- if (i)
- d << ", ";
-#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
- if (d.verbosity() > 2)
- d << functions.at(i);
- else
-#endif
- formatMetaFunctionBrief(d, functions.at(i));
- }
- d << ')';
- }
- const AbstractMetaFieldList &fields = ac->fields();
- if (!fields.isEmpty()) {
- const int count = fields.size();
- d << ", fields=[" << count << "](";
- for (int i = 0; i < count; ++i) {
- if (i)
- d << ", ";
- formatMetaField(d, fields.at(i));
- }
- d << ')';
- }
- const auto &templateArguments = ac->templateArguments();
- if (const int count = templateArguments.size()) {
- d << ", templateArguments=[" << count << "](";
- for (int i = 0; i < count; ++i) {
- if (i)
- d << ", ";
- d << templateArguments.at(i);
- }
- d << ')';
- }
-
-
+ ac->format(d);
+ if (d.verbosity() > 2)
+ ac->formatMembers(d);
} else {
d << '0';
}
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h
index 2ae1b6d21..3ef135cf9 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h
@@ -704,25 +704,26 @@ private:
friend class AbstractMetaClass;
};
+class EnclosingClassMixin {
+public:
+ const AbstractMetaClass *enclosingClass() const { return m_enclosingClass; }
+ void setEnclosingClass(const AbstractMetaClass *cls) { m_enclosingClass = cls; }
+ const AbstractMetaClass *targetLangEnclosingClass() const;
+
+private:
+ const AbstractMetaClass *m_enclosingClass = nullptr;
+};
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const AbstractMetaArgument *aa);
#endif
-class AbstractMetaField : public AbstractMetaVariable, public AbstractMetaAttributes
+class AbstractMetaField : public AbstractMetaVariable, public AbstractMetaAttributes, public EnclosingClassMixin
{
public:
AbstractMetaField();
~AbstractMetaField();
- const AbstractMetaClass *enclosingClass() const
- {
- return m_class;
- }
- void setEnclosingClass(const AbstractMetaClass *cls)
- {
- m_class = cls;
- }
-
const AbstractMetaFunction *getter() const;
const AbstractMetaFunction *setter() const;
@@ -741,7 +742,6 @@ public:
private:
mutable AbstractMetaFunction *m_getter = nullptr;
mutable AbstractMetaFunction *m_setter = nullptr;
- const AbstractMetaClass *m_class = nullptr;
};
#ifndef QT_NO_DEBUG_STREAM
@@ -1179,7 +1179,7 @@ private:
Documentation m_doc;
};
-class AbstractMetaEnum : public AbstractMetaAttributes
+class AbstractMetaEnum : public AbstractMetaAttributes, public EnclosingClassMixin
{
public:
AbstractMetaEnum();
@@ -1234,23 +1234,12 @@ public:
m_typeEntry = entry;
}
- AbstractMetaClass *enclosingClass() const
- {
- return m_class;
- }
-
- void setEnclosingClass(AbstractMetaClass *c)
- {
- m_class = c;
- }
-
bool isSigned() const { return m_signed; }
void setSigned(bool s) { m_signed = s; }
private:
AbstractMetaEnumValueList m_enumValues;
EnumTypeEntry *m_typeEntry = nullptr;
- AbstractMetaClass *m_class = nullptr;
EnumKind m_enumKind = CEnum;
uint m_hasQenumsDeclaration : 1;
@@ -1261,7 +1250,7 @@ private:
QDebug operator<<(QDebug d, const AbstractMetaEnum *ae);
#endif
-class AbstractMetaClass : public AbstractMetaAttributes
+class AbstractMetaClass : public AbstractMetaAttributes, public EnclosingClassMixin
{
Q_GADGET
public:
@@ -1477,22 +1466,12 @@ public:
void setBaseClass(AbstractMetaClass *base_class);
- const AbstractMetaClass *enclosingClass() const
- {
- return m_enclosingClass;
- }
-
/**
* \return the namespace from another package which this namespace extends.
*/
AbstractMetaClass *extendedNamespace() const { return m_extendedNamespace; }
void setExtendedNamespace(AbstractMetaClass *e) { m_extendedNamespace = e; }
- void setEnclosingClass(AbstractMetaClass *cl)
- {
- m_enclosingClass = cl;
- }
-
const AbstractMetaClassList& innerClasses() const
{
return m_innerClasses;
@@ -1712,6 +1691,8 @@ public:
private:
#ifndef QT_NO_DEBUG_STREAM
+ void format(QDebug &d) const;
+ void formatMembers(QDebug &d) const;
friend QDebug operator<<(QDebug d, const AbstractMetaClass *ac);
#endif
uint m_hasVirtuals : 1;
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index a5b153499..78f34c87f 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -222,6 +222,7 @@ public:
FunctionModelItem m_currentFunction;
ArgumentModelItem m_currentArgument;
VariableModelItem m_currentField;
+ QByteArrayList m_systemIncludes;
int m_anonymousEnumCount = 0;
CodeModel::FunctionType m_currentFunctionType = CodeModel::Normal;
@@ -720,6 +721,12 @@ bool BuilderPrivate::visitHeader(const char *cFileName) const
return true;
}
#endif // Q_OS_MACOS
+ if (baseName) {
+ for (const auto &systemInclude : m_systemIncludes) {
+ if (systemInclude == baseName)
+ return true;
+ }
+ }
return false;
}
@@ -742,6 +749,11 @@ bool Builder::visitLocation(const CXSourceLocation &location) const
return result;
}
+void Builder::setSystemIncludes(const QByteArrayList &systemIncludes)
+{
+ d->m_systemIncludes = systemIncludes;
+}
+
FileModelItem Builder::dom() const
{
Q_ASSERT(!d->m_scopeStack.isEmpty());
@@ -765,6 +777,17 @@ static CodeModel::ClassType codeModelClassTypeFromCursor(CXCursorKind kind)
return result;
}
+static NamespaceType namespaceType(const CXCursor &cursor)
+{
+ if (clang_Cursor_isAnonymous(cursor))
+ return NamespaceType::Anonymous;
+#if CINDEX_VERSION_MAJOR > 0 || CINDEX_VERSION_MINOR >= 59
+ if (clang_Cursor_isInlineNamespace(cursor))
+ return NamespaceType::Inline;
+#endif
+ return NamespaceType::Default;
+}
+
BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
{
switch (cursor.kind) {
@@ -890,6 +913,9 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
d->m_scopeStack.back()->addFunction(d->m_currentFunction);
break;
case CXCursor_Namespace: {
+ const auto type = namespaceType(cursor);
+ if (type == NamespaceType::Anonymous)
+ return Skip;
const QString name = getCursorSpelling(cursor);
const NamespaceModelItem parentNamespaceItem = qSharedPointerDynamicCast<_NamespaceModelItem>(d->m_scopeStack.back());
if (parentNamespaceItem.isNull()) {
@@ -906,6 +932,7 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
namespaceItem.reset(new _NamespaceModelItem(d->m_model, name));
setFileName(cursor, namespaceItem.data());
namespaceItem->setScope(d->m_scope);
+ namespaceItem->setType(type);
parentNamespaceItem->addNamespace(namespaceItem);
d->pushScope(namespaceItem);
}
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
index fa79acb2a..dc37dff0f 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
@@ -44,6 +44,8 @@ public:
Builder();
~Builder();
+ void setSystemIncludes(const QByteArrayList &systemIncludes);
+
bool visitLocation(const CXSourceLocation &location) const override;
StartTokenResult startToken(const CXCursor &cursor) override;
diff --git a/sources/shiboken2/ApiExtractor/include.cpp b/sources/shiboken2/ApiExtractor/include.cpp
index d6a451992..82cb1d95b 100644
--- a/sources/shiboken2/ApiExtractor/include.cpp
+++ b/sources/shiboken2/ApiExtractor/include.cpp
@@ -49,7 +49,7 @@ uint qHash(const Include& inc)
QTextStream& operator<<(QTextStream& out, const Include& include)
{
if (include.isValid())
- out << include.toString() << endl;
+ out << include.toString() << Qt::endl;
return out;
}
diff --git a/sources/shiboken2/ApiExtractor/messages.cpp b/sources/shiboken2/ApiExtractor/messages.cpp
index 546e9c4ed..d4cf53efe 100644
--- a/sources/shiboken2/ApiExtractor/messages.cpp
+++ b/sources/shiboken2/ApiExtractor/messages.cpp
@@ -334,8 +334,10 @@ QString msgCannotFindSmartPointer(const QString &instantiationType,
QString result;
QTextStream str(&result);
str << "Unable to find smart pointer type for " << instantiationType << " (known types:";
- for (auto t : pointers)
- str << ' ' << t->fullName();
+ for (auto t : pointers) {
+ auto typeEntry = t->typeEntry();
+ str << ' ' << typeEntry->targetLangName() << '/' << typeEntry->qualifiedCppName();
+ }
str << ").";
return result;
}
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
index 099ab8860..892a20bb7 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
@@ -923,6 +923,16 @@ void _NamespaceModelItem::appendNamespace(const _NamespaceModelItem &other)
void _NamespaceModelItem::formatDebug(QDebug &d) const
{
_ScopeModelItem::formatDebug(d);
+ switch (m_type) {
+ case NamespaceType::Default:
+ break;
+ case NamespaceType::Anonymous:
+ d << ", anonymous";
+ break;
+ case NamespaceType::Inline:
+ d << ", inline";
+ break;
+ }
formatScopeList(d, ", namespaces=", m_namespaces);
}
#endif // !QT_NO_DEBUG_STREAM
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
index 80db2cce5..2e33d6cd0 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
@@ -438,6 +438,9 @@ public:
const NamespaceList &namespaces() const { return m_namespaces; }
+ NamespaceType type() const { return m_type; }
+ void setType(NamespaceType t) { m_type = t; }
+
void addNamespace(NamespaceModelItem item);
NamespaceModelItem findNamespace(const QString &name) const;
@@ -450,6 +453,7 @@ public:
private:
NamespaceList m_namespaces;
+ NamespaceType m_type = NamespaceType::Default;
};
class _FileModelItem: public _NamespaceModelItem
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel_enums.h b/sources/shiboken2/ApiExtractor/parser/codemodel_enums.h
index 1713ba42f..aebd59879 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel_enums.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel_enums.h
@@ -54,4 +54,11 @@ enum class ExceptionSpecification
Throws
};
+enum class NamespaceType
+{
+ Default,
+ Anonymous,
+ Inline
+};
+
#endif // CODEMODEL_ENUMS_H
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index 014f4dadc..c952f7b0e 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.cpp
+++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp
@@ -144,6 +144,25 @@ IncludeList TypeDatabase::extraIncludes(const QString& className) const
return typeEntry ? typeEntry->extraIncludes() : IncludeList();
}
+void TypeDatabase::addSystemInclude(const QString &name)
+{
+ m_systemIncludes.append(name.toUtf8());
+}
+
+// Add a lookup for the short name excluding inline namespaces
+// so that "std::shared_ptr" finds "std::__1::shared_ptr" as well.
+// Note: This inserts duplicate TypeEntry * into m_entries.
+void TypeDatabase::addInlineNamespaceLookups(const NamespaceTypeEntry *n)
+{
+ QVector<TypeEntry *> additionalEntries; // Store before modifying the hash
+ for (TypeEntry *entry : m_entries) {
+ if (entry->isChildOf(n))
+ additionalEntries.append(entry);
+ }
+ for (const auto &ae : additionalEntries)
+ m_entries.insert(ae->shortName(), ae);
+}
+
ContainerTypeEntry* TypeDatabase::findContainerType(const QString &name) const
{
QString template_name = name;
@@ -698,6 +717,35 @@ static void _computeTypeIndexes()
computeTypeIndexes = false;
}
+// Build the C++ name excluding any inline namespaces
+// ("std::__1::shared_ptr" -> "std::shared_ptr"
+QString TypeEntry::shortName() const
+{
+ if (m_cachedShortName.isEmpty()) {
+ QVarLengthArray<const TypeEntry *> parents;
+ bool foundInlineNamespace = false;
+ for (auto p = m_parent; p != nullptr && p->type() != TypeEntry::TypeSystemType; p = p->parent()) {
+ if (p->type() == TypeEntry::NamespaceType
+ && static_cast<const NamespaceTypeEntry *>(p)->isInlineNamespace()) {
+ foundInlineNamespace = true;
+ } else {
+ parents.append(p);
+ }
+ }
+ if (foundInlineNamespace) {
+ m_cachedShortName.reserve(m_name.size());
+ for (int i = parents.size() - 1; i >= 0; --i) {
+ m_cachedShortName.append(parents.at(i)->entryName());
+ m_cachedShortName.append(QLatin1String("::"));
+ }
+ m_cachedShortName.append(m_entryName);
+ } else {
+ m_cachedShortName = m_name;
+ }
+ }
+ return m_cachedShortName;
+}
+
void TypeEntry::setRevision(int r)
{
if (m_revision != r) {
@@ -793,7 +841,7 @@ void TypeEntry::formatDebug(QDebug &d) const
if (m_name != cppName)
d << "\", cppName=\"" << cppName << '"';
d << ", type=" << m_type << ", codeGeneration=0x"
- << hex << m_codeGeneration << dec
+ << Qt::hex << m_codeGeneration << Qt::dec
<< ", target=\"" << targetLangName() << '"';
FORMAT_NONEMPTY_STRING("package", m_targetLangPackage)
FORMAT_BOOL("stream", m_stream)
@@ -848,6 +896,9 @@ void NamespaceTypeEntry::formatDebug(QDebug &d) const
ComplexTypeEntry::formatDebug(d);
auto pattern = m_filePattern.pattern();
FORMAT_NONEMPTY_STRING("pattern", pattern)
+ d << ",visibility=" << m_visibility;
+ if (m_inlineNamespace)
+ d << "[inline]";
}
void ContainerTypeEntry::formatDebug(QDebug &d) const
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.h b/sources/shiboken2/ApiExtractor/typedatabase.h
index 334e88a14..f1bd0ac9f 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.h
+++ b/sources/shiboken2/ApiExtractor/typedatabase.h
@@ -84,6 +84,11 @@ public:
IncludeList extraIncludes(const QString &className) const;
+ const QByteArrayList &systemIncludes() const { return m_systemIncludes; }
+ void addSystemInclude(const QString &name);
+
+ void addInlineNamespaceLookups(const NamespaceTypeEntry *n);
+
PrimitiveTypeEntry *findPrimitiveType(const QString &name) const;
ComplexTypeEntry *findComplexType(const QString &name) const;
ObjectTypeEntry *findObjectType(const QString &name) const;
@@ -171,7 +176,7 @@ private:
TypeEntry *resolveTypeDefEntry(TypedefEntry *typedefEntry, QString *errorMessage);
bool m_suppressWarnings = true;
- TypeEntryMultiMap m_entries;
+ TypeEntryMultiMap m_entries; // Contains duplicate entries (cf addInlineNamespaceLookups).
TypeEntryMap m_flagsEntries;
TypedefEntryMap m_typedefEntries;
TemplateEntryMap m_templates;
@@ -189,6 +194,7 @@ private:
QVector<TypeRejection> m_rejections;
QStringList m_dropTypeEntries;
+ QByteArrayList m_systemIncludes;
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index abd2bfb07..f8199622a 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -433,7 +433,7 @@ QDebug operator<<(QDebug d, const CodeSnip &s)
void Modification::formatDebug(QDebug &d) const
{
- d << "modifiers=" << hex << showbase << modifiers << noshowbase << dec;
+ d << "modifiers=" << Qt::hex << Qt::showbase << modifiers << Qt::noshowbase << Qt::dec;
if (removal)
d << ", removal";
if (!renamedToName.isEmpty())
@@ -684,6 +684,15 @@ TypeEntry::~TypeEntry()
delete m_customConversion;
}
+bool TypeEntry::isChildOf(const TypeEntry *p) const
+{
+ for (auto e = m_parent; e; e = e->parent()) {
+ if (e == p)
+ return true;
+ }
+ return false;
+}
+
const TypeSystemTypeEntry *TypeEntry::typeSystemTypeEntry() const
{
for (auto e = this; e; e = e->parent()) {
@@ -693,6 +702,16 @@ const TypeSystemTypeEntry *TypeEntry::typeSystemTypeEntry() const
return nullptr;
}
+const TypeEntry *TypeEntry::targetLangEnclosingEntry() const
+{
+ auto result = m_parent;
+ while (result && result->type() != TypeEntry::TypeSystemType
+ && !NamespaceTypeEntry::isVisibleScope(result)) {
+ result = result->parent();
+ }
+ return result;
+}
+
QString TypeEntry::targetLangName() const
{
if (m_cachedTargetLangName.isEmpty())
@@ -704,11 +723,13 @@ QString TypeEntry::buildTargetLangName() const
{
QString result = m_entryName;
for (auto p = parent(); p && p->type() != TypeEntry::TypeSystemType; p = p->parent()) {
- if (!result.isEmpty())
- result.prepend(QLatin1Char('.'));
- QString n = p->m_entryName;
- n.replace(QLatin1String("::"), QLatin1String(".")); // Primitive types may have "std::"
- result.prepend(n);
+ if (NamespaceTypeEntry::isVisibleScope(p)) {
+ if (!result.isEmpty())
+ result.prepend(QLatin1Char('.'));
+ QString n = p->m_entryName;
+ n.replace(QLatin1String("::"), QLatin1String(".")); // Primitive types may have "std::"
+ result.prepend(n);
+ }
}
return result;
}
@@ -752,6 +773,8 @@ TypeEntry *TypeEntry::clone() const
// Take over parameters relevant for typedefs
void TypeEntry::useAsTypedef(const TypeEntry *source)
{
+ // XML Typedefs are in the global namespace for now.
+ m_parent = source->typeSystemTypeEntry();
m_entryName = source->m_entryName;
m_name = source->m_name;
m_targetLangPackage = source->m_targetLangPackage;
@@ -959,6 +982,18 @@ bool NamespaceTypeEntry::matchesFile(const QString &needle) const
return m_filePattern.match(needle).hasMatch();
}
+bool NamespaceTypeEntry::isVisible() const
+{
+ return m_visibility == TypeSystem::Visibility::Visible
+ || (m_visibility == TypeSystem::Visibility::Auto && !m_inlineNamespace);
+}
+
+bool NamespaceTypeEntry::isVisibleScope(const TypeEntry *e)
+{
+ return e->type() != TypeEntry::NamespaceType
+ || static_cast<const NamespaceTypeEntry *>(e)->isVisible();
+}
+
ValueTypeEntry::ValueTypeEntry(const QString &entryName, const QVersionNumber &vr,
const TypeEntry *parent) :
ComplexTypeEntry(entryName, BasicValueType, vr, parent)
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h
index 4d0a23ca1..d0739c19b 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.h
+++ b/sources/shiboken2/ApiExtractor/typesystem.h
@@ -562,20 +562,14 @@ public:
EnumValue,
ConstantValueType,
TemplateArgumentType,
- ThreadType,
BasicValueType,
- StringType,
ContainerType,
InterfaceType,
ObjectType,
NamespaceType,
- VariantType,
- JObjectWrapperType,
- CharType,
ArrayType,
TypeSystemType,
CustomType,
- TargetLangType,
FunctionType,
SmartPointerType,
TypedefType
@@ -605,7 +599,10 @@ public:
const TypeEntry *parent() const { return m_parent; }
void setParent(const TypeEntry *p) { m_parent = p; }
+ bool isChildOf(const TypeEntry *p) const;
const TypeSystemTypeEntry *typeSystemTypeEntry() const;
+ // cf AbstractMetaClass::targetLangEnclosingClass()
+ const TypeEntry *targetLangEnclosingEntry() const;
bool isPrimitive() const
{
@@ -627,14 +624,6 @@ public:
{
return m_type == ObjectType;
}
- bool isString() const
- {
- return m_type == StringType;
- }
- bool isChar() const
- {
- return m_type == CharType;
- }
bool isNamespace() const
{
return m_type == NamespaceType;
@@ -647,14 +636,6 @@ public:
{
return m_type == SmartPointerType;
}
- bool isVariant() const
- {
- return m_type == VariantType;
- }
- bool isJObjectWrapper() const
- {
- return m_type == JObjectWrapperType;
- }
bool isArray() const
{
return m_type == ArrayType;
@@ -671,18 +652,10 @@ public:
{
return m_type == VarargsType;
}
- bool isThread() const
- {
- return m_type == ThreadType;
- }
bool isCustom() const
{
return m_type == CustomType;
}
- bool isBasicValue() const
- {
- return m_type == BasicValueType;
- }
bool isTypeSystem() const
{
return m_type == TypeSystemType;
@@ -708,6 +681,8 @@ public:
// The type's name in C++, fully qualified
QString name() const { return m_name; }
+ // C++ excluding inline namespaces
+ QString shortName() const;
// Name as specified in XML
QString entryName() const { return m_entryName; }
@@ -896,7 +871,8 @@ protected:
private:
const TypeEntry *m_parent;
- QString m_name; // fully qualified
+ QString m_name; // C++ fully qualified
+ mutable QString m_cachedShortName; // C++ excluding inline namespaces
QString m_entryName;
QString m_targetLangPackage;
mutable QString m_cachedTargetLangName; // "Foo.Bar"
@@ -1535,6 +1511,15 @@ public:
bool matchesFile(const QString &needle) const;
+ bool isVisible() const;
+ void setVisibility(TypeSystem::Visibility v) { m_visibility = v; }
+
+ // C++ 11 inline namespace, from code model
+ bool isInlineNamespace() const { return m_inlineNamespace; }
+ void setInlineNamespace(bool i) { m_inlineNamespace = i; }
+
+ static bool isVisibleScope(const TypeEntry *e);
+
#ifndef QT_NO_DEBUG_STREAM
void formatDebug(QDebug &d) const override;
#endif
@@ -1545,7 +1530,9 @@ protected:
private:
QRegularExpression m_filePattern;
const NamespaceTypeEntry *m_extends = nullptr;
+ TypeSystem::Visibility m_visibility = TypeSystem::Visibility::Auto;
bool m_hasPattern = false;
+ bool m_inlineNamespace = false;
};
class ValueTypeEntry : public ComplexTypeEntry
diff --git a/sources/shiboken2/ApiExtractor/typesystem_enums.h b/sources/shiboken2/ApiExtractor/typesystem_enums.h
index df83429d0..120c9417f 100644
--- a/sources/shiboken2/ApiExtractor/typesystem_enums.h
+++ b/sources/shiboken2/ApiExtractor/typesystem_enums.h
@@ -98,6 +98,13 @@ enum class ExceptionHandling {
On
};
+enum Visibility { // For namespaces
+ Unspecified,
+ Visible,
+ Invisible,
+ Auto
+};
+
} // namespace TypeSystem
#endif // TYPESYSTEM_ENUMS_H
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index 7388b07fc..a5d28c2e2 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -61,6 +61,7 @@ static inline QString deleteInMainThreadAttribute() { return QStringLiteral("del
static inline QString deprecatedAttribute() { return QStringLiteral("deprecated"); }
static inline QString exceptionHandlingAttribute() { return QStringLiteral("exception-handling"); }
static inline QString extensibleAttribute() { return QStringLiteral("extensible"); }
+static inline QString fileNameAttribute() { return QStringLiteral("file-name"); }
static inline QString flagsAttribute() { return QStringLiteral("flags"); }
static inline QString forceAbstractAttribute() { return QStringLiteral("force-abstract"); }
static inline QString forceIntegerAttribute() { return QStringLiteral("force-integer"); }
@@ -93,6 +94,7 @@ static inline QString sourceAttribute() { return QStringLiteral("source"); }
static inline QString streamAttribute() { return QStringLiteral("stream"); }
static inline QString xPathAttribute() { return QStringLiteral("xpath"); }
static inline QString virtualSlotAttribute() { return QStringLiteral("virtual-slot"); }
+static inline QString visibleAttribute() { return QStringLiteral("visible"); }
static inline QString enumIdentifiedByValueAttribute() { return QStringLiteral("identified-by-value"); }
static inline QString noAttributeValue() { return QStringLiteral("no"); }
@@ -381,6 +383,7 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
{u"replace-type", StackElement::ReplaceType},
{u"smart-pointer-type", StackElement::SmartPointerTypeEntry},
{u"suppress-warning", StackElement::SuppressedWarning},
+ {u"system-include", StackElement::SystemInclude},
{u"target-to-native", StackElement::TargetToNative},
{u"template", StackElement::Template},
{u"typedef-type", StackElement::TypedefTypeEntry},
@@ -389,6 +392,17 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
};
ENUM_LOOKUP_BINARY_SEARCH()
+ENUM_LOOKUP_BEGIN(TypeSystem::Visibility, Qt::CaseSensitive,
+ visibilityFromAttribute, TypeSystem::Visibility::Unspecified)
+{
+ {u"no", TypeSystem::Visibility::Invisible},
+ {u"false", TypeSystem::Visibility::Invisible},
+ {u"auto", TypeSystem::Visibility::Auto},
+ {u"yes", TypeSystem::Visibility::Visible},
+ {u"true", TypeSystem::Visibility::Visible},
+};
+ENUM_LOOKUP_LINEAR_SEARCH()
+
static int indexOfAttribute(const QXmlStreamAttributes &atts,
QStringView name)
{
@@ -1304,8 +1318,8 @@ NamespaceTypeEntry *
if (!checkRootElement())
return nullptr;
QScopedPointer<NamespaceTypeEntry> result(new NamespaceTypeEntry(name, since, currentParentTypeEntry()));
+ auto visibility = TypeSystem::Visibility::Unspecified;
applyCommonAttributes(result.data(), attributes);
- applyComplexTypeAttributes(reader, result.data(), attributes);
for (int i = attributes->size() - 1; i >= 0; --i) {
const QStringRef attributeName = attributes->at(i).qualifiedName();
if (attributeName == QLatin1String("files")) {
@@ -1328,9 +1342,24 @@ NamespaceTypeEntry *
return nullptr;
}
result->setExtends(*extendsIt);
+ } else if (attributeName == visibleAttribute()) {
+ const auto attribute = attributes->takeAt(i);
+ visibility = visibilityFromAttribute(attribute.value());
+ if (visibility == TypeSystem::Visibility::Unspecified) {
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgInvalidAttributeValue(attribute)));
+ }
+ } else if (attributeName == generateAttribute()) {
+ if (!convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true))
+ visibility = TypeSystem::Visibility::Invisible;
}
}
+ if (visibility != TypeSystem::Visibility::Unspecified)
+ result->setVisibility(visibility);
+ // Handle legacy "generate" before the common handling
+ applyComplexTypeAttributes(reader, result.data(), attributes);
+
if (result->extends() && !result->hasPattern()) {
m_error = msgExtendingNamespaceRequiresPattern(name);
return nullptr;
@@ -2509,7 +2538,7 @@ bool TypeSystemParser::parseInclude(const QXmlStreamReader &,
QString location;
for (int i = attributes->size() - 1; i >= 0; --i) {
const QStringRef name = attributes->at(i).qualifiedName();
- if (name == QLatin1String("file-name"))
+ if (name == fileNameAttribute())
fileName = attributes->takeAt(i).value().toString();
else if (name == locationAttribute())
location = attributes->takeAt(i).value().toString();
@@ -2537,6 +2566,18 @@ bool TypeSystemParser::parseInclude(const QXmlStreamReader &,
return true;
}
+bool TypeSystemParser::parseSystemInclude(const QXmlStreamReader &,
+ QXmlStreamAttributes *attributes)
+{
+ const int index = indexOfAttribute(*attributes, fileNameAttribute());
+ if (index == -1) {
+ m_error = msgMissingAttribute(fileNameAttribute());
+ return false;
+ }
+ TypeDatabase::instance()->addSystemInclude(attributes->takeAt(index).value().toString());
+ return true;
+}
+
TemplateInstance *
TypeSystemParser::parseTemplateInstanceEnum(const QXmlStreamReader &,
const StackElement &topElement,
@@ -2822,6 +2863,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
|| element->type == StackElement::LoadTypesystem
|| element->type == StackElement::InjectCode
|| element->type == StackElement::ExtraIncludes
+ || element->type == StackElement::SystemInclude
|| element->type == StackElement::ConversionRule
|| element->type == StackElement::AddFunction
|| element->type == StackElement::Template;
@@ -2974,6 +3016,10 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
if (!addRejection(m_database, &attributes, &m_error))
return false;
break;
+ case StackElement::SystemInclude:
+ if (!parseSystemInclude(reader, &attributes))
+ return false;
+ break;
case StackElement::Template: {
const int nameIndex = indexOfAttribute(attributes, nameAttribute());
if (nameIndex == -1) {
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.h b/sources/shiboken2/ApiExtractor/typesystemparser.h
index d3ea54fc6..f56e8e0fc 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.h
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.h
@@ -86,6 +86,7 @@ class StackElement
NativeToTarget = 0x1100,
TargetToNative = 0x1200,
AddConversion = 0x1300,
+ SystemInclude = 0x1400,
SimpleMask = 0x3f00,
// Code snip tags (0x1000, 0x2000, ... , 0xf000)
@@ -247,6 +248,7 @@ private:
StackElement* element, QXmlStreamAttributes *);
bool parseInclude(const QXmlStreamReader &, const StackElement &topElement,
TypeEntry *entry, QXmlStreamAttributes *);
+ bool parseSystemInclude(const QXmlStreamReader &, QXmlStreamAttributes *);
TemplateInstance
*parseTemplateInstanceEnum(const QXmlStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *);
diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst
index ac1121461..fac801cff 100644
--- a/sources/shiboken2/doc/typesystem_specifying_types.rst
+++ b/sources/shiboken2/doc/typesystem_specifying_types.rst
@@ -148,6 +148,7 @@ namespace-type
<typesystem>
<namespace-type name="..."
+ visible="true | auto | false"
generate="yes | no"
package="..."
since="..."
@@ -156,8 +157,16 @@ namespace-type
The **name** attribute is the name of the namespace, e.g., "Qt".
- The *optional* **generate** attribute is used to inform if you need to prepend
- the given namespace into each generated class. Its default value is **yes**.
+ The *optional* **visible** attribute is used specify whether the
+ namespace is visible in the target language name. Its default value is
+ **auto**. It means that normal namespaces are visible, but inline namespaces
+ (as introduced in C++ 11) will not be visible.
+
+ The detection of inline namespaces requires shiboken to be built
+ using LLVM 9.0.
+
+ The *optional* **generate** is a legacy attribute. Specifying
+ **no** is equivalent to **visible="false"**.
The **package** attribute can be used to override the package of the type system.
@@ -462,3 +471,18 @@ function
The function tag has two *optional* attributes: **since**, whose value is used to specify
the API version of this function, and **rename**, to modify the function name.
+.. _system_include:
+
+system-include
+^^^^^^^^^^^^^^
+
+ The optional **system-include** specifies the name of a system include
+ file to be parsed. Normally, include files considered to be system
+ include files are skipped by the C++ code parser. Its primary use case
+ is exposing classes from the STL library.
+
+ .. code-block:: xml
+
+ <typesystem>
+ <system-include file-name="memory"/>
+ </typesystem>
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 484b1f641..585102b01 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -159,7 +159,6 @@ struct Generator::GeneratorPrivate
QString licenseComment;
QString moduleName;
QStringList instantiatedContainersNames;
- QStringList instantiatedSmartPointerNames;
QVector<const AbstractMetaType *> instantiatedContainers;
QVector<const AbstractMetaType *> instantiatedSmartPointers;
@@ -211,6 +210,31 @@ QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType *type)
return typeName;
}
+// Strip a "const QSharedPtr<const Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016/454)
+const AbstractMetaType *canonicalSmartPtrInstantiation(const AbstractMetaType *type)
+{
+ AbstractMetaTypeList instantiations = type->instantiations();
+ Q_ASSERT(instantiations.size() == 1);
+ const bool needsFix = type->isConstant() || type->referenceType() != NoReference;
+ const bool pointeeNeedsFix = instantiations.constFirst()->isConstant();
+ if (!needsFix && !pointeeNeedsFix)
+ return type;
+ auto fixedType = type->copy();
+ fixedType->setReferenceType(NoReference);
+ fixedType->setConstant(false);
+ if (pointeeNeedsFix) {
+ auto fixedPointeeType = instantiations.constFirst()->copy();
+ fixedPointeeType->setConstant(false);
+ fixedType->setInstantiations(AbstractMetaTypeList(1, fixedPointeeType));
+ }
+ return fixedType;
+}
+
+static inline const TypeEntry *pointeeTypeEntry(const AbstractMetaType *smartPtrType)
+{
+ return smartPtrType->instantiations().constFirst()->typeEntry();
+}
+
void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType *type,
const QString &context)
{
@@ -244,18 +268,15 @@ void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType
m_d->instantiatedContainers.append(type);
}
} else {
- // Is smart pointer.
- if (!m_d->instantiatedSmartPointerNames.contains(typeName)) {
- m_d->instantiatedSmartPointerNames.append(typeName);
- if (type->isConstant() || type->referenceType() != NoReference) {
- // Strip a "const QSharedPtr<Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016)
- auto fixedType = type->copy();
- fixedType->setReferenceType(NoReference);
- fixedType->setConstant(false);
- type = fixedType;
- }
- m_d->instantiatedSmartPointers.append(type);
- }
+ // Is smart pointer. Check if the (const?) pointee is already known
+ auto pt = pointeeTypeEntry(type);
+ const bool present =
+ std::any_of(m_d->instantiatedSmartPointers.cbegin(), m_d->instantiatedSmartPointers.cend(),
+ [pt] (const AbstractMetaType *t) {
+ return pointeeTypeEntry(t) == pt;
+ });
+ if (!present)
+ m_d->instantiatedSmartPointers.append(canonicalSmartPtrInstantiation(type));
}
}
@@ -449,7 +470,8 @@ bool Generator::generate()
bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) const
{
- return type->codeGeneration() & TypeEntry::GenerateTargetLang;
+ return (type->codeGeneration() & TypeEntry::GenerateTargetLang)
+ && NamespaceTypeEntry::isVisibleScope(type);
}
bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const
@@ -529,7 +551,7 @@ QTextStream &formatCode(QTextStream &s, const QString &code, Indentor &indentor)
s << indentor << line.remove(0, limit);
}
- s << endl;
+ s << Qt::endl;
}
return s;
}
@@ -893,8 +915,12 @@ static QString getClassTargetFullName_(const T *t, bool includePackageName)
QString name = t->name();
const AbstractMetaClass *context = t->enclosingClass();
while (context) {
- name.prepend(QLatin1Char('.'));
- name.prepend(context->name());
+ // If the type was marked as 'visible=false' we should not use it in
+ // the type name
+ if (NamespaceTypeEntry::isVisibleScope(context->typeEntry())) {
+ name.prepend(QLatin1Char('.'));
+ name.prepend(context->name());
+ }
context = context->enclosingClass();
}
if (includePackageName) {
diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp
index 25daea99e..089ecb48f 100644
--- a/sources/shiboken2/generator/main.cpp
+++ b/sources/shiboken2/generator/main.cpp
@@ -73,11 +73,11 @@ static void printOptions(QTextStream &s, const OptionDescriptions &options)
if (od.second.isEmpty()) {
s << ", ";
} else {
- s << endl;
+ s << Qt::endl;
const auto lines = od.second.splitRef(QLatin1Char('\n'));
for (const auto &line : lines)
- s << " " << line << endl;
- s << endl;
+ s << " " << line << Qt::endl;
+ s << Qt::endl;
}
}
}
@@ -343,7 +343,7 @@ void printUsage()
for (const GeneratorPtr &generator : generators) {
const OptionDescriptions options = generator->options();
if (!options.isEmpty()) {
- s << endl << generator->name() << " options:\n\n";
+ s << Qt::endl << generator->name() << " options:\n\n";
printOptions(s, generator->options());
}
}
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
index 791d9faea..40cc255f0 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
@@ -172,7 +172,7 @@ static QChar lastChar(const QTextStream &str)
static QTextStream &ensureEndl(QTextStream &s)
{
if (lastChar(s) != QLatin1Char('\n'))
- s << endl;
+ s << Qt::endl;
return s;
}
@@ -227,7 +227,7 @@ public:
friend QTextStream &operator<<(QTextStream &str, const rstLabel &a)
{
- str << ".. _" << toRstLabel(a.m_label) << ':' << endl << endl;
+ str << ".. _" << toRstLabel(a.m_label) << ":\n\n";
return str;
}
@@ -502,10 +502,10 @@ QString QtXmlToSphinx::transform(const QString& doc)
if (!m_inlineImages.isEmpty()) {
// Write out inline image definitions stored in handleInlineImageTag().
- m_output << endl;
+ m_output << Qt::endl;
for (const InlineImage &img : qAsConst(m_inlineImages))
- m_output << ".. |" << img.tag << "| image:: " << img.href << endl;
- m_output << endl;
+ m_output << ".. |" << img.tag << "| image:: " << img.href << Qt::endl;
+ m_output << Qt::endl;
m_inlineImages.clear();
}
@@ -608,11 +608,11 @@ void QtXmlToSphinx::handleHeadingTag(QXmlStreamReader& reader)
else
type = types[typeIdx];
} else if (token == QXmlStreamReader::EndElement) {
- m_output << Pad(type, headingSize) << endl << endl;
+ m_output << Pad(type, headingSize) << Qt::endl << Qt::endl;
} else if (token == QXmlStreamReader::Characters) {
- m_output << endl << endl;
+ m_output << Qt::endl << Qt::endl;
headingSize = writeEscapedRstText(m_output, reader.text().trimmed());
- m_output << endl;
+ m_output << Qt::endl;
}
}
@@ -628,7 +628,7 @@ void QtXmlToSphinx::handleParaTag(QXmlStreamReader& reader)
else if (result.startsWith(QLatin1String("**Note:**")))
result.replace(0, 9, QLatin1String(".. note:: "));
- m_output << INDENT << result << endl << endl;
+ m_output << INDENT << result << Qt::endl << Qt::endl;
} else if (token == QXmlStreamReader::Characters) {
const QStringRef text = reader.text();
const QChar end = lastChar(m_output);
@@ -726,7 +726,7 @@ void QtXmlToSphinx::handleSeeAlsoTag(QXmlStreamReader& reader)
handleLinkEnd(m_seeAlsoContext.data());
m_seeAlsoContext.reset();
}
- m_output << endl << endl;
+ m_output << Qt::endl << Qt::endl;
break;
default:
break;
@@ -747,7 +747,7 @@ void formatSnippet(QTextStream &str, Indent indent, const QString &snippet)
for (const QStringRef &line : lines) {
if (!line.trimmed().isEmpty())
str << indent << line;
- str << endl;
+ str << Qt::endl;
}
}
@@ -808,10 +808,10 @@ void QtXmlToSphinx::handleSnippetTag(QXmlStreamReader& reader)
Indentation indentation(INDENT);
const QString code = pythonCode.isEmpty() ? fallbackCode : pythonCode;
if (code.isEmpty())
- m_output << INDENT << "<Code snippet \"" << location << ':' << identifier << "\" not found>" << endl;
+ m_output << INDENT << "<Code snippet \"" << location << ':' << identifier << "\" not found>\n";
else
formatSnippet(m_output, INDENT, code);
- m_output << endl;
+ m_output << Qt::endl;
}
}
void QtXmlToSphinx::handleDotsTag(QXmlStreamReader& reader)
@@ -930,16 +930,16 @@ void QtXmlToSphinx::handleListTag(QXmlStreamReader& reader)
switch (listType) {
case BulletList:
case OrderedList: {
- m_output << endl;
+ m_output << Qt::endl;
const char *separator = listType == BulletList ? "* " : "#. ";
const char *indent = listType == BulletList ? " " : " ";
for (const TableCell &cell : m_currentTable.constFirst()) {
const QVector<QStringRef> itemLines = cell.data.splitRef(QLatin1Char('\n'));
- m_output << INDENT << separator << itemLines.constFirst() << endl;
+ m_output << INDENT << separator << itemLines.constFirst() << Qt::endl;
for (int i = 1, max = itemLines.count(); i < max; ++i)
- m_output << INDENT << indent << itemLines[i] << endl;
+ m_output << INDENT << indent << itemLines[i] << Qt::endl;
}
- m_output << endl;
+ m_output << Qt::endl;
}
break;
case EnumeratedList:
@@ -1144,7 +1144,7 @@ void QtXmlToSphinx::handleImageTag(QXmlStreamReader& reader)
return;
const QString href = reader.attributes().value(QLatin1String("href")).toString();
if (copyImage(href))
- m_output << INDENT << ".. image:: " << href << endl << endl;
+ m_output << INDENT << ".. image:: " << href << Qt::endl << Qt::endl;
}
void QtXmlToSphinx::handleInlineImageTag(QXmlStreamReader& reader)
@@ -1174,13 +1174,13 @@ void QtXmlToSphinx::handleRawTag(QXmlStreamReader& reader)
QXmlStreamReader::TokenType token = reader.tokenType();
if (token == QXmlStreamReader::StartElement) {
QString format = reader.attributes().value(QLatin1String("format")).toString();
- m_output << INDENT << ".. raw:: " << format.toLower() << endl << endl;
+ m_output << INDENT << ".. raw:: " << format.toLower() << Qt::endl << Qt::endl;
} else if (token == QXmlStreamReader::Characters) {
const QVector<QStringRef> lst(reader.text().split(QLatin1Char('\n')));
for (const QStringRef &row : lst)
- m_output << INDENT << INDENT << row << endl;
+ m_output << INDENT << INDENT << row << Qt::endl;
} else if (token == QXmlStreamReader::EndElement) {
- m_output << endl << endl;
+ m_output << Qt::endl << Qt::endl;
}
}
@@ -1188,14 +1188,14 @@ void QtXmlToSphinx::handleCodeTag(QXmlStreamReader& reader)
{
QXmlStreamReader::TokenType token = reader.tokenType();
if (token == QXmlStreamReader::StartElement) {
- m_output << INDENT << "::" << endl << endl;
+ m_output << INDENT << "::\n\n";
INDENT.indent++;
} else if (token == QXmlStreamReader::Characters) {
const QVector<QStringRef> lst(reader.text().split(QLatin1Char('\n')));
for (const QStringRef &row : lst)
- m_output << INDENT << INDENT << row << endl;
+ m_output << INDENT << INDENT << row << Qt::endl;
} else if (token == QXmlStreamReader::EndElement) {
- m_output << endl << endl;
+ m_output << Qt::endl << Qt::endl;
INDENT.indent--;
}
}
@@ -1235,7 +1235,7 @@ void QtXmlToSphinx::handlePageTag(QXmlStreamReader &reader)
? writeEscapedRstText(m_output, title)
: writeEscapedRstText(m_output, fullTitle);
- m_output << endl << Pad('*', size) << endl << endl;
+ m_output << Qt::endl << Pad('*', size) << Qt::endl << Qt::endl;
}
void QtXmlToSphinx::handleTargetTag(QXmlStreamReader &reader)
@@ -1296,10 +1296,10 @@ void QtXmlToSphinx::handleQuoteFileTag(QXmlStreamReader& reader)
m_output << INDENT << "::\n\n";
Indentation indentation(INDENT);
if (code.isEmpty())
- m_output << INDENT << "<Code snippet \"" << location << "\" not found>" << endl;
+ m_output << INDENT << "<Code snippet \"" << location << "\" not found>\n";
else
formatCode(m_output, code, INDENT);
- m_output << endl;
+ m_output << Qt::endl;
}
}
@@ -1435,7 +1435,7 @@ void QtXmlToSphinx::Table::format (QTextStream& s) const
c = '-';
s << Pad(c, colWidths.at(col)) << '+';
}
- s << endl;
+ s << Qt::endl;
// Print the table cells
@@ -1452,17 +1452,16 @@ void QtXmlToSphinx::Table::format (QTextStream& s) const
else
s << ' ';
if (rowLine < rowLines.count())
- s << qSetFieldWidth(colWidths[j]) << left << rowLines.at(rowLine) << qSetFieldWidth(0);
+ s << qSetFieldWidth(colWidths[j]) << Qt::left << rowLines.at(rowLine) << qSetFieldWidth(0);
else
s << Pad(' ', colWidths.at(j));
}
for ( ; j < headerColumnCount; ++j) // pad
s << '|' << Pad(' ', colWidths.at(j));
- s << '|' << endl;
+ s << "|\n";
}
}
- s << INDENT << horizontalLine << endl;
- s << endl;
+ s << INDENT << horizontalLine << Qt::endl << Qt::endl;
}
static QString getFuncName(const AbstractMetaFunction* cppFunc) {
@@ -1563,11 +1562,11 @@ void QtDocGenerator::writeFormattedText(QTextStream &s, const Documentation &doc
s << INDENT
<< (typesystemIndentation > 0 && typesystemIndentation < line.size()
? line.right(line.size() - typesystemIndentation) : line)
- << endl;
+ << Qt::endl;
}
}
- s << endl;
+ s << Qt::endl;
}
static void writeInheritedByList(QTextStream& s, const AbstractMetaClass* metaClass, const AbstractMetaClassList& allClasses)
@@ -1585,7 +1584,7 @@ static void writeInheritedByList(QTextStream& s, const AbstractMetaClass* metaCl
QStringList classes;
for (AbstractMetaClass *c : qAsConst(res))
classes << QLatin1String(":ref:`") + getClassTargetFullName(c, false) + QLatin1Char('`');
- s << classes.join(QLatin1String(", ")) << endl << endl;
+ s << classes.join(QLatin1String(", ")) << Qt::endl << Qt::endl;
}
// Extract the <brief> section from a WebXML (class) documentation and remove it
@@ -1626,16 +1625,16 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex
s << ".. _" << className << ":" << "\n\n";
s << ".. currentmodule:: " << metaClass->package() << "\n\n\n";
- s << className << endl;
- s << Pad('*', className.count()) << endl << endl;
+ s << className << Qt::endl;
+ s << Pad('*', className.count()) << Qt::endl << Qt::endl;
auto documentation = metaClass->documentation();
Documentation brief;
if (extractBrief(&documentation, &brief))
writeFormattedText(s, brief, metaClass);
- s << ".. inheritance-diagram:: " << getClassTargetFullName(metaClass, true) << endl
- << " :parts: 2" << endl << endl; // TODO: This would be a parameter in the future...
+ s << ".. inheritance-diagram:: " << getClassTargetFullName(metaClass, true) << Qt::endl
+ << " :parts: 2\n\n"; // TODO: This would be a parameter in the future...
writeInheritedByList(s, metaClass, classes());
@@ -1652,8 +1651,7 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex
AbstractMetaFunctionList functionList = metaClass->functions();
std::sort(functionList.begin(), functionList.end(), functionSort);
- s << endl
- << "Detailed Description\n"
+ s << "\nDetailed Description\n"
"--------------------\n\n"
<< ".. _More:\n";
@@ -1729,9 +1727,7 @@ void QtDocGenerator::writeFunctionList(QTextStream& s, const AbstractMetaClass*
if (!functionList.isEmpty() || !staticFunctionList.isEmpty()) {
QtXmlToSphinx::Table functionTable;
- s << endl
- << "Synopsis" << endl
- << "--------" << endl << endl;
+ s << "\nSynopsis\n--------\n\n";
writeFunctionBlock(s, QLatin1String("Functions"), functionList);
writeFunctionBlock(s, QLatin1String("Virtual functions"), virtualList);
@@ -1744,17 +1740,17 @@ void QtDocGenerator::writeFunctionList(QTextStream& s, const AbstractMetaClass*
void QtDocGenerator::writeFunctionBlock(QTextStream& s, const QString& title, QStringList& functions)
{
if (!functions.isEmpty()) {
- s << title << endl
- << QString(title.size(), QLatin1Char('^')) << endl;
+ s << title << Qt::endl
+ << QString(title.size(), QLatin1Char('^')) << Qt::endl;
std::sort(functions.begin(), functions.end());
- s << ".. container:: function_list" << endl << endl;
+ s << ".. container:: function_list\n\n";
Indentation indentation(INDENT);
for (const QString &func : qAsConst(functions))
- s << INDENT << '*' << ' ' << func << endl;
+ s << INDENT << '*' << ' ' << func << Qt::endl;
- s << endl << endl;
+ s << Qt::endl << Qt::endl;
}
}
@@ -1764,7 +1760,7 @@ void QtDocGenerator::writeEnums(QTextStream& s, const AbstractMetaClass* cppClas
const AbstractMetaEnumList &enums = cppClass->enums();
for (AbstractMetaEnum *en : enums) {
- s << section_title << getClassTargetFullName(cppClass) << '.' << en->name() << endl << endl;
+ s << section_title << getClassTargetFullName(cppClass) << '.' << en->name() << Qt::endl << Qt::endl;
writeFormattedText(s, en->documentation(), cppClass);
const auto version = versionOf(en->typeEntry());
if (!version.isNull())
@@ -1779,7 +1775,7 @@ void QtDocGenerator::writeFields(QTextStream& s, const AbstractMetaClass* cppCla
const AbstractMetaFieldList &fields = cppClass->fields();
for (AbstractMetaField *field : fields) {
- s << section_title << getClassTargetFullName(cppClass) << "." << field->name() << endl << endl;
+ s << section_title << getClassTargetFullName(cppClass) << "." << field->name() << Qt::endl << Qt::endl;
//TODO: request for member ‘documentation’ is ambiguous
writeFormattedText(s, field->AbstractMetaAttributes::documentation(), cppClass);
}
@@ -1823,14 +1819,14 @@ void QtDocGenerator::writeConstructors(QTextStream& s, const AbstractMetaClass*
}
}
- s << endl;
+ s << Qt::endl;
for (QHash<QString, AbstractMetaArgument*>::const_iterator it = arg_map.cbegin(), end = arg_map.cend(); it != end; ++it) {
Indentation indentation(INDENT, 2);
writeParameterType(s, cppClass, it.value());
}
- s << endl;
+ s << Qt::endl;
for (AbstractMetaFunction *func : qAsConst(lst))
writeFormattedText(s, func->documentation(), cppClass);
@@ -1921,7 +1917,7 @@ void QtDocGenerator::writeDocSnips(QTextStream &s,
if (row.trimmed().size() == 0) {
if (currentRow == 0)
continue;
- s << endl;
+ s << Qt::endl;
}
if (currentRow == 0) {
@@ -1935,7 +1931,7 @@ void QtDocGenerator::writeDocSnips(QTextStream &s,
break;
}
}
- s << row.midRef(offset) << endl;
+ s << row.midRef(offset) << Qt::endl;
currentRow++;
}
@@ -1975,7 +1971,7 @@ bool QtDocGenerator::writeInjectDocumentation(QTextStream& s,
}
}
- s << endl;
+ s << Qt::endl;
// TODO: Deprecate the use of doc string on glue code.
// This is pre "add-function" and "inject-documentation" tags.
@@ -2050,13 +2046,13 @@ QString QtDocGenerator::translateToPythonType(const AbstractMetaType* type, cons
void QtDocGenerator::writeParameterType(QTextStream& s, const AbstractMetaClass* cppClass, const AbstractMetaArgument* arg)
{
s << INDENT << ":param " << arg->name() << ": "
- << translateToPythonType(arg->type(), cppClass) << endl;
+ << translateToPythonType(arg->type(), cppClass) << Qt::endl;
}
void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractMetaClass *cppClass,
const AbstractMetaFunction *func)
{
- s << endl;
+ s << Qt::endl;
const AbstractMetaArgumentList &funcArgs = func->arguments();
for (AbstractMetaArgument *arg : funcArgs) {
@@ -2082,9 +2078,9 @@ void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractM
if (retType.isEmpty())
retType = translateToPythonType(func->type(), cppClass);
- s << INDENT << ":rtype: " << retType << endl;
+ s << INDENT << ":rtype: " << retType << Qt::endl;
}
- s << endl;
+ s << Qt::endl;
}
void QtDocGenerator::writeFunction(QTextStream& s, const AbstractMetaClass* cppClass,
@@ -2138,12 +2134,12 @@ static void writeFancyToc(QTextStream& s, const QStringList& items, int cols = 4
std::sort(it.value().begin(), it.value().end());
if (i)
- ss << endl;
+ ss << Qt::endl;
- ss << "**" << it.key() << "**" << endl << endl;
+ ss << "**" << it.key() << "**\n\n";
i += 2; // a letter title is equivalent to two entries in space
for (const QString &item : qAsConst(it.value())) {
- ss << "* :doc:`" << item << "`" << endl;
+ ss << "* :doc:`" << item << "`\n";
++i;
// end of column detected!
@@ -2165,7 +2161,7 @@ static void writeFancyToc(QTextStream& s, const QStringList& items, int cols = 4
}
table.appendRow(row);
table.normalize();
- s << ".. container:: pysidetoc" << endl << endl;
+ s << ".. container:: pysidetoc\n\n";
s << table;
}
@@ -2188,11 +2184,11 @@ void QtDocGenerator::writeModuleDocumentation()
FileOut output(outputDir + QLatin1String("/index.rst"));
QTextStream& s = output.stream;
- s << ".. module:: " << it.key() << endl << endl;
+ s << ".. module:: " << it.key() << Qt::endl << Qt::endl;
const QString &title = it.key();
- s << title << endl;
- s << Pad('*', title.length()) << endl << endl;
+ s << title << Qt::endl;
+ s << Pad('*', title.length()) << Qt::endl << Qt::endl;
/* Avoid showing "Detailed Description for *every* class in toc tree */
Indentation indentation(INDENT);
@@ -2227,19 +2223,18 @@ void QtDocGenerator::writeModuleDocumentation()
writeFancyToc(s, it.value());
- s << INDENT << ".. container:: hide" << endl << endl;
+ s << INDENT << ".. container:: hide\n\n";
{
Indentation indentation(INDENT);
- s << INDENT << ".. toctree::" << endl;
+ s << INDENT << ".. toctree::\n";
Indentation deeperIndentation(INDENT);
- s << INDENT << ":maxdepth: 1" << endl << endl;
+ s << INDENT << ":maxdepth: 1\n\n";
for (const QString &className : qAsConst(it.value()))
- s << INDENT << className << endl;
- s << endl << endl;
+ s << INDENT << className << Qt::endl;
+ s << Qt::endl << Qt::endl;
}
- s << "Detailed Description" << endl;
- s << "--------------------" << endl << endl;
+ s << "Detailed Description\n--------------------\n\n";
// module doc is always wrong and C++istic, so go straight to the extra directory!
QFile moduleDoc(m_extraSectionDir + QLatin1Char('/') + moduleName.mid(lastIndex + 1) + QLatin1String(".rst"));
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 765657099..eaa9fe8c4 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -300,32 +300,30 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
qCDebug(lcShiboken) << "Generating wrapper implementation for " << metaClass->fullName();
// write license comment
- s << licenseComment() << endl;
+ s << licenseComment() << Qt::endl;
if (!avoidProtectedHack() && !metaClass->isNamespace() && !metaClass->hasPrivateDestructor()) {
- s << "//workaround to access protected functions" << endl;
- s << "#define protected public" << endl << endl;
+ s << "//workaround to access protected functions\n";
+ s << "#define protected public\n\n";
}
// headers
- s << "// default includes" << endl;
- s << "#include <shiboken.h>" << endl;
+ s << "// default includes\n";
+ s << "#include <shiboken.h>\n";
if (usePySideExtensions()) {
s << includeQDebug;
- s << "#include <pysidesignal.h>" << endl;
- s << "#include <pysideproperty.h>" << endl;
- s << "#include <pyside.h>" << endl;
- s << "#include <destroylistener.h>" << endl;
- s << "#include <qapp_macro.h>" << endl;
- s << endl;
- s << "QT_WARNING_DISABLE_DEPRECATED" << endl;
- s << endl;
+ s << "#include <pysidesignal.h>\n"
+ << "#include <pysideproperty.h>\n"
+ << "#include <pyside.h>\n"
+ << "#include <destroylistener.h>\n"
+ << "#include <qapp_macro.h>\n\n"
+ << "QT_WARNING_DISABLE_DEPRECATED\n\n";
}
- s << "#include <typeinfo>" << endl;
+ s << "#include <typeinfo>\n";
if (usePySideExtensions() && metaClass->isQObject()) {
- s << "#include <signalmanager.h>" << endl;
- s << "#include <pysidemetafunction.h>" << endl;
+ s << "#include <signalmanager.h>\n";
+ s << "#include <pysidemetafunction.h>\n";
}
// The multiple inheritance initialization function
@@ -333,22 +331,22 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
if (getMultipleInheritingClass(metaClass) != nullptr)
s << "#include <algorithm>\n#include <set>\n";
if (metaClass->generateExceptionHandling())
- s << "#include <exception>" << endl;
+ s << "#include <exception>\n";
- s << endl << "// module include" << endl << "#include \"" << getModuleHeaderFileName() << '"' << endl;
+ s << "\n// module include\n" << "#include \"" << getModuleHeaderFileName() << "\"\n";
QString headerfile = fileNameForContext(classContext);
headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h"));
- s << endl << "// main header" << endl << "#include \"" << headerfile << '"' << endl;
+ s << "\n// main header\n" << "#include \"" << headerfile << "\"\n";
- s << endl << "// inner classes" << endl;
+ s << Qt::endl << "// inner classes\n";
const AbstractMetaClassList &innerClasses = metaClass->innerClasses();
for (AbstractMetaClass *innerClass : innerClasses) {
GeneratorContext innerClassContext(innerClass);
- if (shouldGenerate(innerClass)) {
+ if (shouldGenerate(innerClass) && !innerClass->typeEntry()->isSmartPointer()) {
QString headerfile = fileNameForContext(innerClassContext);
headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h"));
- s << "#include \"" << headerfile << '"' << endl;
+ s << "#include \"" << headerfile << "\"\n";
}
}
@@ -357,33 +355,33 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
lookForEnumsInClassesNotToBeGenerated(classEnums, innerClass);
//Extra includes
- s << endl << "// Extra includes" << endl;
+ s << "\n// Extra includes\n";
QVector<Include> includes = metaClass->typeEntry()->extraIncludes();
for (AbstractMetaEnum *cppEnum : qAsConst(classEnums))
includes.append(cppEnum->typeEntry()->extraIncludes());
std::sort(includes.begin(), includes.end());
for (const Include &inc : qAsConst(includes))
- s << inc.toString() << endl;
- s << endl;
+ s << inc.toString() << Qt::endl;
+ s << Qt::endl;
s << "\n#include <cctype>\n#include <cstring>\n";
if (metaClass->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated)
- s << "#Deprecated" << endl;
+ s << "#Deprecated\n";
// Use class base namespace
{
const AbstractMetaClass *context = metaClass->enclosingClass();
while (context) {
if (context->isNamespace() && !context->enclosingClass()) {
- s << "using namespace " << context->qualifiedCppName() << ";" << endl;
+ s << "using namespace " << context->qualifiedCppName() << ";\n";
break;
}
context = context->enclosingClass();
}
}
- s << endl << endl << typeNameFunc << endl;
+ s << Qt::endl << Qt::endl << typeNameFunc << Qt::endl;
// Create string literal for smart pointer getter method.
if (classContext.forSmartPointer()) {
@@ -397,18 +395,17 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
// class inject-code native/beginning
if (!metaClass->typeEntry()->codeSnips().isEmpty()) {
writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, metaClass);
- s << endl;
+ s << Qt::endl;
}
// python conversion rules
if (metaClass->typeEntry()->hasTargetConversionRule()) {
- s << "// Python Conversion" << endl;
- s << metaClass->typeEntry()->conversionRule() << endl;
+ s << "// Python Conversion\n";
+ s << metaClass->typeEntry()->conversionRule() << Qt::endl;
}
if (shouldGenerateCppWrapper(metaClass)) {
- s << "// Native ---------------------------------------------------------" << endl;
- s << endl;
+ s << "// Native ---------------------------------------------------------\n\n";
if (avoidProtectedHack() && usePySideExtensions()) {
s << "void " << wrapperName(metaClass) << "::pysideInitQtMetaTypes()\n{\n";
@@ -448,8 +445,8 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
QString signaturesString;
QTextStream signatureStream(&signaturesString);
- s << endl << "// Target ---------------------------------------------------------" << endl << endl;
- s << "extern \"C\" {" << endl;
+ s << "\n// Target ---------------------------------------------------------\n\n"
+ << "extern \"C\" {\n";
const auto &functionGroups = getFunctionGroups(metaClass);
for (auto it = functionGroups.cbegin(), end = functionGroups.cend(); it != end; ++it) {
AbstractMetaFunctionList overloads;
@@ -536,10 +533,10 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
writeSignatureInfo(signatureStream, overloads);
if (OverloadData::hasStaticAndInstanceFunctions(overloads)) {
QString methDefName = cpythonMethodDefinitionName(rfunc);
- smd << "static PyMethodDef " << methDefName << " = {" << endl;
+ smd << "static PyMethodDef " << methDefName << " = {\n";
smd << INDENT;
writeMethodDefinitionEntry(smd, overloads);
- smd << endl << "};" << endl << endl;
+ smd << "\n};\n\n";
}
writeMethodDefinition(md, overloads);
}
@@ -549,54 +546,54 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
if (metaClass->typeEntry()->isValue() || metaClass->typeEntry()->isSmartPointer()) {
writeCopyFunction(s, classContext);
- signatureStream << fullPythonClassName(metaClass) << ".__copy__()" << endl;
+ signatureStream << fullPythonClassName(metaClass) << ".__copy__()\n";
}
// Write single method definitions
s << singleMethodDefinitions;
// Write methods definition
- s << "static PyMethodDef " << className << "_methods[] = {" << endl;
- s << methodsDefinitions << endl;
+ s << "static PyMethodDef " << className << "_methods[] = {\n";
+ s << methodsDefinitions << Qt::endl;
if (metaClass->typeEntry()->isValue() || metaClass->typeEntry()->isSmartPointer()) {
s << INDENT << "{\"__copy__\", reinterpret_cast<PyCFunction>(" << className << "___copy__)"
- << ", METH_NOARGS}," << endl;
+ << ", METH_NOARGS},\n";
}
- s << INDENT << '{' << NULL_PTR << ", " << NULL_PTR << "} // Sentinel" << endl;
- s << "};" << endl << endl;
+ s << INDENT << '{' << NULL_PTR << ", " << NULL_PTR << "} // Sentinel\n";
+ s << "};\n\n";
// Write tp_getattro function
if ((usePySideExtensions() && metaClass->qualifiedCppName() == QLatin1String("QObject"))) {
writeGetattroFunction(s, classContext);
- s << endl;
+ s << Qt::endl;
writeSetattroFunction(s, classContext);
- s << endl;
+ s << Qt::endl;
} else {
if (classNeedsGetattroFunction(metaClass)) {
writeGetattroFunction(s, classContext);
- s << endl;
+ s << Qt::endl;
}
if (classNeedsSetattroFunction(metaClass)) {
writeSetattroFunction(s, classContext);
- s << endl;
+ s << Qt::endl;
}
}
if (const AbstractMetaFunction *f = boolCast(metaClass)) {
ErrorCode errorCode(-1);
- s << "static int " << cpythonBaseName(metaClass) << "___nb_bool(PyObject *self)" << endl;
- s << '{' << endl;
+ s << "static int " << cpythonBaseName(metaClass) << "___nb_bool(PyObject *self)\n"
+ << "{\n";
writeCppSelfDefinition(s, classContext);
if (f->allowThread()) {
- s << INDENT << "int result;" << endl;
- s << INDENT << BEGIN_ALLOW_THREADS << endl;
- s << INDENT << "result = !" << CPP_SELF_VAR << "->isNull();" << endl;
- s << INDENT << END_ALLOW_THREADS << endl;
- s << INDENT << "return result;" << endl;
+ s << INDENT << "int result;\n";
+ s << INDENT << BEGIN_ALLOW_THREADS << Qt::endl;
+ s << INDENT << "result = !" << CPP_SELF_VAR << "->isNull();\n";
+ s << INDENT << END_ALLOW_THREADS << Qt::endl;
+ s << INDENT << "return result;\n";
} else {
- s << INDENT << "return !" << CPP_SELF_VAR << "->isNull();" << endl;
+ s << INDENT << "return !" << CPP_SELF_VAR << "->isNull();\n";
}
- s << '}' << endl << endl;
+ s << "}\n\n";
}
if (supportsNumberProtocol(metaClass) && !metaClass->typeEntry()->isSmartPointer()) {
@@ -632,7 +629,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
}
if (!metaClass->isNamespace() && metaClass->hasComparisonOperatorOverload()) {
- s << "// Rich comparison" << endl;
+ s << "// Rich comparison\n";
writeRichCompareFunction(s, classContext);
}
@@ -644,11 +641,11 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
writeGetterFunction(s, metaField, classContext);
if (canGenerateFieldSetter(metaField))
writeSetterFunction(s, metaField, classContext);
- s << endl;
+ s << Qt::endl;
}
- s << "// Getters and Setters for " << metaClass->name() << endl;
- s << "static PyGetSetDef " << cpythonGettersSettersDefinitionName(metaClass) << "[] = {" << endl;
+ s << "// Getters and Setters for " << metaClass->name() << Qt::endl;
+ s << "static PyGetSetDef " << cpythonGettersSettersDefinitionName(metaClass) << "[] = {\n";
for (const AbstractMetaField *metaField : fields) {
if (metaField->isStatic())
continue;
@@ -659,13 +656,13 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
s << cpythonSetterFunctionName(metaField);
else
s << NULL_PTR;
- s << "}," << endl;
+ s << "},\n";
}
- s << INDENT << '{' << NULL_PTR << "} // Sentinel" << endl;
- s << "};" << endl << endl;
+ s << INDENT << '{' << NULL_PTR << "} // Sentinel\n";
+ s << "};\n\n";
}
- s << "} // extern \"C\"" << endl << endl;
+ s << "} // extern \"C\"\n\n";
if (!metaClass->typeEntry()->hashFunction().isEmpty())
writeHashFunction(s, classContext);
@@ -675,7 +672,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
writeTpClearFunction(s, metaClass);
writeClassDefinition(s, metaClass, classContext);
- s << endl;
+ s << Qt::endl;
if (metaClass->isPolymorphic() && metaClass->baseClass())
writeTypeDiscoveryFunction(s, metaClass);
@@ -689,10 +686,10 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
if (hasFlags) {
writeFlagsMethods(s, cppEnum);
writeFlagsNumberMethodsDefinition(s, cppEnum);
- s << endl;
+ s << Qt::endl;
}
}
- s << endl;
+ s << Qt::endl;
writeConverterFunctions(s, metaClass, classContext);
writeClassRegister(s, metaClass, classContext, signatureStream);
@@ -700,7 +697,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
// class inject-code native/end
if (!metaClass->typeEntry()->codeSnips().isEmpty()) {
writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, metaClass);
- s << endl;
+ s << Qt::endl;
}
}
@@ -711,22 +708,22 @@ void CppGenerator::writeConstructorNative(QTextStream &s, const AbstractMetaFunc
OriginalTypeDescription | SkipDefaultValues);
s << " : ";
writeFunctionCall(s, func);
- s << endl << "{" << endl;
+ s << "\n{\n";
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, func, lastArg);
- s << INDENT << "// ... middle" << endl;
+ s << INDENT << "// ... middle\n";
writeCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, func, lastArg);
- s << '}' << endl << endl;
+ s << "}\n\n";
}
void CppGenerator::writeDestructorNative(QTextStream &s, const AbstractMetaClass *metaClass)
{
Indentation indentation(INDENT);
- s << wrapperName(metaClass) << "::~" << wrapperName(metaClass) << "()" << endl << '{' << endl;
+ s << wrapperName(metaClass) << "::~" << wrapperName(metaClass) << "()\n{\n";
// kill pyobject
- s << INDENT << "SbkObject *wrapper = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
- s << INDENT << "Shiboken::Object::destroy(wrapper, this);" << endl;
- s << '}' << endl;
+ s << INDENT << "SbkObject *wrapper = Shiboken::BindingManager::instance().retrieveWrapper(this);\n";
+ s << INDENT << "Shiboken::Object::destroy(wrapper, this);\n";
+ s << "}\n";
}
static bool allArgumentsRemoved(const AbstractMetaFunction *func)
@@ -780,7 +777,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
QString prefix = wrapperName(func->ownerClass()) + QLatin1String("::");
s << functionSignature(func, prefix, QString(), Generator::SkipDefaultValues|Generator::OriginalTypeDescription)
- << endl << '{' << endl;
+ << "\n{\n";
Indentation indentation(INDENT);
@@ -819,7 +816,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
errorMsg += func->signature();
errorMsg = msgCouldNotFindMinimalConstructor(errorMsg, func->type()->cppSignature());
qCWarning(lcShiboken).noquote().nospace() << errorMsg;
- s << endl << INDENT << "#error " << errorMsg << endl;
+ s << Qt::endl << INDENT << "#error " << errorMsg << Qt::endl;
}
} else {
defaultReturnExpr.setType(DefaultValue::Void);
@@ -830,8 +827,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
<< QString::fromLatin1("Pure virtual method '%1::%2' must be implement but was "\
"completely removed on type system.")
.arg(func->ownerClass()->name(), func->minimalSignature());
- s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl;
- s << '}' << endl << endl;
+ s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl;
+ s << "}\n\n";
return;
}
@@ -840,22 +837,22 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
CodeSnipList snips = func->injectedCodeSnips();
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionDeclaration, TypeSystem::NativeCode, func, lastArg);
- s << endl;
+ s << Qt::endl;
}
- s << INDENT << "Shiboken::GilState gil;" << endl;
+ s << INDENT << "Shiboken::GilState gil;\n";
// Get out of virtual method call if someone already threw an error.
- s << INDENT << "if (PyErr_Occurred())" << endl;
+ s << INDENT << "if (PyErr_Occurred())\n";
{
Indentation indentation(INDENT);
- s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl;
+ s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl;
}
s << INDENT << "Shiboken::AutoDecRef " << PYTHON_OVERRIDE_VAR << "(Shiboken::BindingManager::instance().getOverride(this, \"";
- s << funcName << "\"));" << endl;
+ s << funcName << "\"));\n";
- s << INDENT << "if (" << PYTHON_OVERRIDE_VAR << ".isNull()) {" << endl;
+ s << INDENT << "if (" << PYTHON_OVERRIDE_VAR << ".isNull()) {\n";
{
Indentation indentation(INDENT);
CodeSnipList snips;
@@ -863,18 +860,18 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
snips = func->injectedCodeSnips();
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::ShellCode, func, lastArg);
- s << endl;
+ s << Qt::endl;
}
if (func->isAbstract()) {
s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"pure virtual method '";
s << func->ownerClass()->name() << '.' << funcName;
- s << "()' not implemented.\");" << endl;
+ s << "()' not implemented.\");\n";
s << INDENT << "return";
if (retType)
s << ' ' << defaultReturnExpr.returnValue();
} else {
- s << INDENT << "gil.release();" << endl;
+ s << INDENT << "gil.release();\n";
s << INDENT;
if (retType)
s << "return ";
@@ -884,15 +881,15 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << ";\n" << INDENT << "return";
}
}
- s << ';' << endl;
- s << INDENT << '}' << endl << endl;
+ s << ";\n";
+ s << INDENT<< "}\n\n";
writeConversionRule(s, func, TypeSystem::TargetLangCode);
s << INDENT << "Shiboken::AutoDecRef " << PYTHON_ARGS << "(";
if (func->arguments().isEmpty() || allArgumentsRemoved(func)) {
- s << "PyTuple_New(0));" << endl;
+ s << "PyTuple_New(0));\n";
} else {
QStringList argConversions;
const AbstractMetaArgumentList &arguments = func->arguments();
@@ -934,9 +931,9 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
argConversions << argConv;
}
- s << "Py_BuildValue(\"(" << getFormatUnitString(func, false) << ")\"," << endl;
- s << argConversions.join(QLatin1String(",\n")) << endl;
- s << INDENT << "));" << endl;
+ s << "Py_BuildValue(\"(" << getFormatUnitString(func, false) << ")\",\n";
+ s << argConversions.join(QLatin1String(",\n")) << Qt::endl;
+ s << INDENT << "));\n";
}
bool invalidateReturn = false;
@@ -947,82 +944,82 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
if (argMod.resetAfterUse && !invalidateArgs.contains(argMod.index)) {
invalidateArgs.insert(argMod.index);
s << INDENT << "bool invalidateArg" << argMod.index;
- s << " = PyTuple_GET_ITEM(" << PYTHON_ARGS << ", " << argMod.index - 1 << ")->ob_refcnt == 1;" << endl;
+ s << " = PyTuple_GET_ITEM(" << PYTHON_ARGS << ", " << argMod.index - 1 << ")->ob_refcnt == 1;\n";
} else if (argMod.index == 0 && argMod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::CppOwnership) {
invalidateReturn = true;
}
}
}
- s << endl;
+ s << Qt::endl;
CodeSnipList snips;
if (func->hasInjectedCode()) {
snips = func->injectedCodeSnips();
if (injectedCodeUsesPySelf(func))
- s << INDENT << "PyObject *pySelf = BindingManager::instance().retrieveWrapper(this);" << endl;
+ s << INDENT << "PyObject *pySelf = BindingManager::instance().retrieveWrapper(this);\n";
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, func, lastArg);
- s << endl;
+ s << Qt::endl;
}
if (!injectedCodeCallsPythonOverride(func)) {
s << INDENT;
s << "Shiboken::AutoDecRef " << PYTHON_RETURN_VAR << "(PyObject_Call("
- << PYTHON_OVERRIDE_VAR << ", " << PYTHON_ARGS << ", nullptr));" << endl;
+ << PYTHON_OVERRIDE_VAR << ", " << PYTHON_ARGS << ", nullptr));\n";
- s << INDENT << "// An error happened in python code!" << endl;
- s << INDENT << "if (" << PYTHON_RETURN_VAR << ".isNull()) {" << endl;
+ s << INDENT << "// An error happened in python code!\n";
+ s << INDENT << "if (" << PYTHON_RETURN_VAR << ".isNull()) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_Print();" << endl;
- s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl;
+ s << INDENT << "PyErr_Print();\n";
+ s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
if (retType) {
if (invalidateReturn)
- s << INDENT << "bool invalidateArg0 = " << PYTHON_RETURN_VAR << "->ob_refcnt == 1;" << endl;
+ s << INDENT << "bool invalidateArg0 = " << PYTHON_RETURN_VAR << "->ob_refcnt == 1;\n";
if (func->typeReplaced(0) != QLatin1String("PyObject")) {
- s << INDENT << "// Check return type" << endl;
+ s << INDENT << "// Check return type\n";
s << INDENT;
if (func->typeReplaced(0).isEmpty()) {
s << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << " = " << cpythonIsConvertibleFunction(func->type());
- s << PYTHON_RETURN_VAR << ");" << endl;
- s << INDENT << "if (!" << PYTHON_TO_CPP_VAR << ") {" << endl;
+ s << PYTHON_RETURN_VAR << ");\n";
+ s << INDENT << "if (!" << PYTHON_TO_CPP_VAR << ") {\n";
{
Indentation indent(INDENT);
s << INDENT << "Shiboken::warning(PyExc_RuntimeWarning, 2, "\
"\"Invalid return value in function %s, expected %s, got %s.\", \"";
s << func->ownerClass()->name() << '.' << funcName << "\", " << getVirtualFunctionReturnTypeName(func);
- s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);" << endl;
- s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl;
+ s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n";
+ s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
} else {
- s << INDENT << "// Check return type" << endl;
+ s << INDENT << "// Check return type\n";
s << INDENT << "bool typeIsValid = ";
writeTypeCheck(s, func->type(), QLatin1String(PYTHON_RETURN_VAR),
isNumber(func->type()->typeEntry()), func->typeReplaced(0));
- s << ';' << endl;
+ s << ";\n";
s << INDENT << "if (!typeIsValid";
if (isPointerToWrapperType(func->type()))
s << " && " << PYTHON_RETURN_VAR << " != Py_None";
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
s << INDENT << "Shiboken::warning(PyExc_RuntimeWarning, 2, "\
"\"Invalid return value in function %s, expected %s, got %s.\", \"";
s << func->ownerClass()->name() << '.' << funcName << "\", " << getVirtualFunctionReturnTypeName(func);
- s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);" << endl;
- s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl;
+ s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n";
+ s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
}
@@ -1038,15 +1035,15 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
}
if (invalidateReturn) {
- s << INDENT << "if (invalidateArg0)" << endl;
+ s << INDENT << "if (invalidateArg0)\n";
Indentation indentation(INDENT);
- s << INDENT << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR << ".object());" << endl;
+ s << INDENT << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR << ".object());\n";
}
for (int argIndex : qAsConst(invalidateArgs)) {
- s << INDENT << "if (invalidateArg" << argIndex << ')' << endl;
+ s << INDENT << "if (invalidateArg" << argIndex << ")\n";
Indentation indentation(INDENT);
s << INDENT << "Shiboken::Object::invalidate(PyTuple_GET_ITEM(" << PYTHON_ARGS << ", ";
- s << (argIndex - 1) << "));" << endl;
+ s << (argIndex - 1) << "));\n";
}
@@ -1055,15 +1052,15 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
for (const ArgumentModification &argMod : funcMod.argument_mods) {
if (argMod.ownerships.contains(TypeSystem::NativeCode)
&& argMod.index == 0 && argMod.ownerships[TypeSystem::NativeCode] == TypeSystem::CppOwnership) {
- s << INDENT << "if (Shiboken::Object::checkType(" << PYTHON_RETURN_VAR << "))" << endl;
+ s << INDENT << "if (Shiboken::Object::checkType(" << PYTHON_RETURN_VAR << "))\n";
Indentation indent(INDENT);
- s << INDENT << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR << ");" << endl;
+ s << INDENT << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR << ");\n";
}
}
}
if (func->hasInjectedCode()) {
- s << endl;
+ s << Qt::endl;
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, func, lastArg);
}
@@ -1083,29 +1080,28 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
}
if (func->type()->referenceType() == LValueReference && !isPointer(func->type()))
s << " *";
- s << CPP_RETURN_VAR << ';' << endl;
+ s << CPP_RETURN_VAR << ";\n";
}
- s << '}' << endl << endl;
+ s<< "}\n\n";
}
void CppGenerator::writeMetaObjectMethod(QTextStream &s, const AbstractMetaClass *metaClass)
{
Indentation indentation(INDENT);
QString wrapperClassName = wrapperName(metaClass);
- s << "const QMetaObject *" << wrapperClassName << "::metaObject() const" << endl;
- s << '{' << endl;
- s << INDENT << "if (QObject::d_ptr->metaObject)" << endl
- << INDENT << INDENT << "return QObject::d_ptr->dynamicMetaObject();" << endl;
- s << INDENT << "SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
- s << INDENT << "if (pySelf == nullptr)" << endl;
- s << INDENT << INDENT << "return " << metaClass->qualifiedCppName() << "::metaObject();" << endl;
- s << INDENT << "return PySide::SignalManager::retrieveMetaObject(reinterpret_cast<PyObject *>(pySelf));" << endl;
- s << '}' << endl << endl;
+ s << "const QMetaObject *" << wrapperClassName << "::metaObject() const\n{\n";
+ s << INDENT << "if (QObject::d_ptr->metaObject)\n"
+ << INDENT << INDENT << "return QObject::d_ptr->dynamicMetaObject();\n";
+ s << INDENT << "SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);\n";
+ s << INDENT << "if (pySelf == nullptr)\n";
+ s << INDENT << INDENT << "return " << metaClass->qualifiedCppName() << "::metaObject();\n";
+ s << INDENT << "return PySide::SignalManager::retrieveMetaObject(reinterpret_cast<PyObject *>(pySelf));\n";
+ s<< "}\n\n";
// qt_metacall function
- s << "int " << wrapperClassName << "::qt_metacall(QMetaObject::Call call, int id, void **args)" << endl;
- s << "{" << endl;
+ s << "int " << wrapperClassName << "::qt_metacall(QMetaObject::Call call, int id, void **args)\n";
+ s << "{\n";
AbstractMetaFunction *func = nullptr;
AbstractMetaFunctionList list = metaClass->queryFunctionsByName(QLatin1String("qt_metacall"));
@@ -1121,9 +1117,9 @@ void CppGenerator::writeMetaObjectMethod(QTextStream &s, const AbstractMetaClass
}
}
- s << INDENT << "int result = " << metaClass->qualifiedCppName() << "::qt_metacall(call, id, args);" << endl;
- s << INDENT << "return result < 0 ? result : PySide::SignalManager::qt_metacall(this, call, id, args);" << endl;
- s << "}" << endl << endl;
+ s << INDENT << "int result = " << metaClass->qualifiedCppName() << "::qt_metacall(call, id, args);\n";
+ s << INDENT << "return result < 0 ? result : PySide::SignalManager::qt_metacall(this, call, id, args);\n";
+ s << "}\n\n";
// qt_metacast function
writeMetaCast(s, metaClass);
@@ -1133,14 +1129,13 @@ void CppGenerator::writeMetaCast(QTextStream &s, const AbstractMetaClass *metaCl
{
Indentation indentation(INDENT);
QString wrapperClassName = wrapperName(metaClass);
- s << "void *" << wrapperClassName << "::qt_metacast(const char *_clname)" << endl;
- s << '{' << endl;
- s << INDENT << "if (!_clname) return {};" << endl;
- s << INDENT << "SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
- s << INDENT << "if (pySelf && PySide::inherits(Py_TYPE(pySelf), _clname))" << endl;
- s << INDENT << INDENT << "return static_cast<void *>(const_cast< " << wrapperClassName << " *>(this));" << endl;
- s << INDENT << "return " << metaClass->qualifiedCppName() << "::qt_metacast(_clname);" << endl;
- s << "}" << endl << endl;
+ s << "void *" << wrapperClassName << "::qt_metacast(const char *_clname)\n{\n";
+ s << INDENT << "if (!_clname) return {};\n";
+ s << INDENT << "SbkObject *pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);\n";
+ s << INDENT << "if (pySelf && PySide::inherits(Py_TYPE(pySelf), _clname))\n";
+ s << INDENT << INDENT << "return static_cast<void *>(const_cast< " << wrapperClassName << " *>(this));\n";
+ s << INDENT << "return " << metaClass->qualifiedCppName() << "::qt_metacast(_clname);\n";
+ s << "}\n\n";
}
void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const AbstractMetaEnum *metaEnum)
@@ -1170,7 +1165,7 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry *
c << cppTypeName << "(QFlag(int(PySide::QFlags::getValue(reinterpret_cast<PySideQFlagsObject *>(pyIn)))))";
else
c << "static_cast<" << cppTypeName << ">(Shiboken::Enum::getValue(pyIn))";
- c << ';' << endl;
+ c << ";\n";
writePythonToCppFunction(s, code, typeName, typeName);
QString pyTypeCheck = QStringLiteral("PyObject_TypeCheck(pyIn, %1)").arg(enumPythonType);
@@ -1179,7 +1174,7 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry *
code.clear();
c << INDENT << "const int castCppIn = int(*reinterpret_cast<const "
- << cppTypeName << " *>(cppIn));" << endl;
+ << cppTypeName << " *>(cppIn));\n";
c << INDENT;
c << "return ";
if (enumType->isFlags()) {
@@ -1188,9 +1183,9 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry *
} else {
c << "Shiboken::Enum::newItem(" << enumPythonType << ", castCppIn)";
}
- c << ';' << endl;
+ c << ";\n";
writeCppToPythonFunction(s, code, typeName, typeName);
- s << endl;
+ s << Qt::endl;
if (enumType->isFlags())
return;
@@ -1207,17 +1202,17 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry *
cppTypeName = getFullTypeName(flags).trimmed();
c << INDENT << "*reinterpret_cast<" << cppTypeName << " *>(cppOut) =\n"
<< INDENT << " " << cppTypeName
- << "(QFlag(int(Shiboken::Enum::getValue(pyIn))));" << endl;
+ << "(QFlag(int(Shiboken::Enum::getValue(pyIn))));\n";
QString flagsTypeName = fixedCppTypeName(flags);
writePythonToCppFunction(s, code, typeName, flagsTypeName);
writeIsPythonConvertibleToCppFunction(s, typeName, flagsTypeName, pyTypeCheck);
code.clear();
- c << INDENT << "Shiboken::AutoDecRef pyLong(PyNumber_Long(pyIn));" << endl;
+ c << INDENT << "Shiboken::AutoDecRef pyLong(PyNumber_Long(pyIn));\n";
c << INDENT << "*reinterpret_cast<" << cppTypeName << " *>(cppOut) =\n"
<< INDENT << " " << cppTypeName
- << "(QFlag(int(PyLong_AsLong(pyLong.object()))));" << endl;
+ << "(QFlag(int(PyLong_AsLong(pyLong.object()))));\n";
// PYSIDE-898: Include an additional condition to detect if the type of the
// enum corresponds to the object that is being evaluated.
// Using only `PyNumber_Check(...)` is too permissive,
@@ -1234,14 +1229,14 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry *
void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaClass *metaClass,
GeneratorContext &classContext)
{
- s << "// Type conversion functions." << endl << endl;
+ s << "// Type conversion functions.\n\n";
AbstractMetaEnumList classEnums = metaClass->enums();
const AbstractMetaClassList &innerClasses = metaClass->innerClasses();
for (AbstractMetaClass *innerClass : innerClasses)
lookForEnumsInClassesNotToBeGenerated(classEnums, innerClass);
if (!classEnums.isEmpty())
- s << "// Python to C++ enum conversion." << endl;
+ s << "// Python to C++ enum conversion.\n";
for (const AbstractMetaEnum *metaEnum : qAsConst(classEnums))
writeEnumConverterFunctions(s, metaEnum);
@@ -1257,7 +1252,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
QString cpythonType = cpythonTypeName(metaClass);
// Returns the C++ pointer of the Python wrapper.
- s << "// Python to C++ pointer conversion - returns the C++ object of the Python wrapper (keeps object identity)." << endl;
+ s << "// Python to C++ pointer conversion - returns the C++ object of the Python wrapper (keeps object identity).\n";
QString sourceTypeName = metaClass->name();
QString targetTypeName = metaClass->name() + QLatin1String("_PTR");
@@ -1270,24 +1265,24 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
const QString pyTypeCheck = QLatin1String("PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(")
+ cpythonType + QLatin1String("))");
writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck, QString(), true);
- s << endl;
+ s << Qt::endl;
// C++ pointer to a Python wrapper, keeping identity.
- s << "// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity)." << endl;
+ s << "// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).\n";
code.clear();
if (usePySideExtensions() && metaClass->isQObject())
{
c << INDENT << "return PySide::getWrapperForQObject(reinterpret_cast<"
- << typeName << " *>(const_cast<void *>(cppIn)), " << cpythonType << ");" << endl;
+ << typeName << " *>(const_cast<void *>(cppIn)), " << cpythonType << ");\n";
} else {
- c << INDENT << "auto pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn));" << endl;
- c << INDENT << "if (pyOut) {" << endl;
+ c << INDENT << "auto pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn));\n";
+ c << INDENT << "if (pyOut) {\n";
{
Indentation indent(INDENT);
- c << INDENT << "Py_INCREF(pyOut);" << endl;
- c << INDENT << "return pyOut;" << endl;
+ c << INDENT << "Py_INCREF(pyOut);\n";
+ c << INDENT << "return pyOut;\n";
}
- c << INDENT << '}' << endl;
+ c << INDENT << "}\n";
c << INDENT << "bool changedTypeName = false;\n"
<< INDENT << "auto tCppIn = reinterpret_cast<const " << typeName << " *>(cppIn);\n"
<< INDENT << "const char *typeName = typeid(*tCppIn).name();\n"
@@ -1307,12 +1302,12 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
// The conversions for an Object Type end here.
if (!metaClass->typeEntry()->isValue() && !metaClass->typeEntry()->isSmartPointer()) {
- s << endl;
+ s << Qt::endl;
return;
}
// Always copies C++ value (not pointer, and not reference) to a new Python wrapper.
- s << endl << "// C++ to Python copy conversion." << endl;
+ s << Qt::endl << "// C++ to Python copy conversion.\n";
if (!classContext.forSmartPointer())
targetTypeName = metaClass->name();
else
@@ -1332,10 +1327,10 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
<< ", new ::" << computedWrapperName << "(*reinterpret_cast<const "
<< typeName << " *>(cppIn)), true, true);";
writeCppToPythonFunction(s, code, sourceTypeName, targetTypeName);
- s << endl;
+ s << Qt::endl;
// Python to C++ copy conversion.
- s << "// Python to C++ copy conversion." << endl;
+ s << "// Python to C++ copy conversion.\n";
if (!classContext.forSmartPointer())
sourceTypeName = metaClass->name();
else
@@ -1357,7 +1352,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
// "Is convertible" function for the Python object to C++ value copy conversion.
writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck);
- s << endl;
+ s << Qt::endl;
// User provided implicit conversions.
CustomConversion *customConversion = metaClass->typeEntry()->customConversion();
@@ -1373,7 +1368,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
}
if (!implicitConvs.isEmpty())
- s << "// Implicit conversions." << endl;
+ s << "// Implicit conversions.\n";
AbstractMetaType *targetType = buildAbstractMetaTypeFromAbstractMetaClass(metaClass);
for (const AbstractMetaFunction *conv : qAsConst(implicitConvs)) {
@@ -1422,7 +1417,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla
QTextStream pc(&toCppPreConv);
pc << INDENT << getFullTypeNameWithoutModifiers(sourceType) << " cppIn";
writeMinimalConstructorExpression(pc, sourceType);
- pc << ';' << endl;
+ pc << ";\n";
writeToCppConversion(pc, sourceType, nullptr, QLatin1String("pyIn"), QLatin1String("cppIn"));
pc << ';';
toCppConv.append(QLatin1String("cppIn"));
@@ -1449,10 +1444,10 @@ void CppGenerator::writeCustomConverterFunctions(QTextStream &s, const CustomCon
const CustomConversion::TargetToNativeConversions &toCppConversions = customConversion->targetToNativeConversions();
if (toCppConversions.isEmpty())
return;
- s << "// Python to C++ conversions for type '" << customConversion->ownerType()->qualifiedCppName() << "'." << endl;
+ s << "// Python to C++ conversions for type '" << customConversion->ownerType()->qualifiedCppName() << "'.\n";
for (CustomConversion::TargetToNativeConversion *toNative : toCppConversions)
writePythonToCppConversionFunctions(s, toNative, customConversion->ownerType());
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClass *metaClass,
@@ -1460,26 +1455,26 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas
{
if (metaClass->isNamespace())
return;
- s << INDENT << "// Register Converter" << endl;
+ s << INDENT << "// Register Converter\n";
s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter(";
- s << cpythonTypeName(metaClass) << ',' << endl;
+ s << cpythonTypeName(metaClass) << ',' << Qt::endl;
{
Indentation indent(INDENT);
QString sourceTypeName = metaClass->name();
QString targetTypeName = sourceTypeName + QLatin1String("_PTR");
- s << INDENT << pythonToCppFunctionName(sourceTypeName, targetTypeName) << ',' << endl;
- s << INDENT << convertibleToCppFunctionName(sourceTypeName, targetTypeName) << ',' << endl;
+ s << INDENT << pythonToCppFunctionName(sourceTypeName, targetTypeName) << ',' << Qt::endl;
+ s << INDENT << convertibleToCppFunctionName(sourceTypeName, targetTypeName) << ',' << Qt::endl;
std::swap(targetTypeName, sourceTypeName);
s << INDENT << cppToPythonFunctionName(sourceTypeName, targetTypeName);
if (metaClass->typeEntry()->isValue() || metaClass->typeEntry()->isSmartPointer()) {
- s << ',' << endl;
+ s << ',' << Qt::endl;
sourceTypeName = metaClass->name() + QLatin1String("_COPY");
s << INDENT << cppToPythonFunctionName(sourceTypeName, targetTypeName);
}
}
- s << ");" << endl;
+ s << ");\n";
- s << endl;
+ s << Qt::endl;
QStringList cppSignature;
if (!classContext.forSmartPointer()) {
@@ -1491,9 +1486,9 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas
}
while (!cppSignature.isEmpty()) {
QString signature = cppSignature.join(QLatin1String("::"));
- s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "\");" << endl;
- s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "*\");" << endl;
- s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "&\");" << endl;
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "\");\n";
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "*\");\n";
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "&\");\n";
cppSignature.removeFirst();
}
@@ -1504,20 +1499,20 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas
else
qualifiedCppNameInvocation = classContext.preciseType()->cppSignature();
- s << qualifiedCppNameInvocation << ").name());" << endl;
+ s << qualifiedCppNameInvocation << ").name());\n";
if (shouldGenerateCppWrapper(metaClass)) {
s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::";
- s << wrapperName(metaClass) << ").name());" << endl;
+ s << wrapperName(metaClass) << ").name());\n";
}
- s << endl;
+ s << Qt::endl;
if (!metaClass->typeEntry()->isValue() && !metaClass->typeEntry()->isSmartPointer())
return;
// Python to C++ copy (value, not pointer neither reference) conversion.
- s << INDENT << "// Add Python to C++ copy (value, not pointer neither reference) conversion to type converter." << endl;
+ s << INDENT << "// Add Python to C++ copy (value, not pointer neither reference) conversion to type converter.\n";
QString sourceTypeName = metaClass->name();
QString targetTypeName = sourceTypeName + QLatin1String("_COPY");
QString toCpp = pythonToCppFunctionName(sourceTypeName, targetTypeName);
@@ -1538,7 +1533,7 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas
}
if (!implicitConvs.isEmpty())
- s << INDENT << "// Add implicit conversions to type converter." << endl;
+ s << INDENT << "// Add implicit conversions to type converter.\n";
AbstractMetaType *targetType = buildAbstractMetaTypeFromAbstractMetaClass(metaClass);
for (const AbstractMetaFunction *conv : qAsConst(implicitConvs)) {
@@ -1568,7 +1563,7 @@ void CppGenerator::writeCustomConverterRegister(QTextStream &s, const CustomConv
const CustomConversion::TargetToNativeConversions &toCppConversions = customConversion->targetToNativeConversions();
if (toCppConversions.isEmpty())
return;
- s << INDENT << "// Add user defined implicit conversions to type converter." << endl;
+ s << INDENT << "// Add user defined implicit conversions to type converter.\n";
for (CustomConversion::TargetToNativeConversion *toNative : toCppConversions) {
QString toCpp = pythonToCppFunctionName(toNative, customConversion->ownerType());
QString isConv = convertibleToCppFunctionName(toNative, customConversion->ownerType());
@@ -1604,9 +1599,9 @@ void CppGenerator::writeMethodWrapperPreamble(QTextStream &s, OverloadData &over
else
qualifiedCppName = context.preciseType()->cppSignature();
- s << qualifiedCppName << " >()))" << endl;
+ s << qualifiedCppName << " >()))\n";
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl;
}
// Declare pointer for the underlying C++ object.
s << INDENT << "::";
@@ -1616,7 +1611,7 @@ void CppGenerator::writeMethodWrapperPreamble(QTextStream &s, OverloadData &over
} else {
s << context.preciseType()->cppSignature();
}
- s << " *cptr{};" << endl;
+ s << " *cptr{};\n";
initPythonArguments = maxArgs > 0;
usesNamedArguments = !ownerClass->isQObject() && overloadData.hasArgumentWithDefaultValue();
@@ -1627,33 +1622,33 @@ void CppGenerator::writeMethodWrapperPreamble(QTextStream &s, OverloadData &over
writeCppSelfDefinition(s, rfunc, context, overloadData.hasStaticFunction());
}
if (!rfunc->isInplaceOperator() && overloadData.hasNonVoidReturnType())
- s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << "{};" << endl;
+ s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << "{};\n";
initPythonArguments = minArgs != maxArgs || maxArgs > 1;
usesNamedArguments = rfunc->isCallOperator() || overloadData.hasArgumentWithDefaultValue();
}
if (maxArgs > 0) {
- s << INDENT << "int overloadId = -1;" << endl;
+ s << INDENT << "int overloadId = -1;\n";
s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR;
if (pythonFunctionWrapperUsesListOfArguments(overloadData)) {
s << "[] = { " << NULL_PTR;
for (int i = 1; i < maxArgs; ++i)
s << ", " << NULL_PTR;
- s << " };" << endl;
+ s << " };\n";
} else {
- s << "{};" << endl;
+ s << "{};\n";
}
writeUnusedVariableCast(s, QLatin1String(PYTHON_TO_CPP_VAR));
}
if (usesNamedArguments && !rfunc->isCallOperator())
- s << INDENT << "int numNamedArgs = (kwds ? PyDict_Size(kwds) : 0);" << endl;
+ s << INDENT << "int numNamedArgs = (kwds ? PyDict_Size(kwds) : 0);\n";
if (initPythonArguments) {
s << INDENT << "int numArgs = ";
if (minArgs == 0 && maxArgs == 1 && !rfunc->isConstructor() && !pythonFunctionWrapperUsesListOfArguments(overloadData))
- s << "(" << PYTHON_ARG << " == 0 ? 0 : 1);" << endl;
+ s << "(" << PYTHON_ARG << " == 0 ? 0 : 1);\n";
else
writeArgumentsInitializer(s, overloadData);
}
@@ -1668,9 +1663,8 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun
const AbstractMetaFunction *rfunc = overloadData.referenceFunction();
const AbstractMetaClass *metaClass = rfunc->ownerClass();
- s << "static int" << endl;
- s << cpythonFunctionName(rfunc) << "(PyObject *self, PyObject *args, PyObject *kwds)" << endl;
- s << '{' << endl;
+ s << "static int\n";
+ s << cpythonFunctionName(rfunc) << "(PyObject *self, PyObject *args, PyObject *kwds)\n{\n";
QSet<QString> argNamesSet;
if (usePySideExtensions() && metaClass->isQObject()) {
@@ -1687,96 +1681,96 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun
QStringList argNamesList = argNamesSet.values();
std::sort(argNamesList.begin(), argNamesList.end());
if (argNamesList.isEmpty()) {
- s << INDENT << "const char **argNames{};" << endl;
+ s << INDENT << "const char **argNames{};\n";
} else {
s << INDENT << "const char *argNames[] = {\""
- << argNamesList.join(QLatin1String("\", \"")) << "\"};" << endl;
+ << argNamesList.join(QLatin1String("\", \"")) << "\"};\n";
}
- s << INDENT << "const QMetaObject *metaObject;" << endl;
+ s << INDENT << "const QMetaObject *metaObject;\n";
}
- s << INDENT << "SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self);" << endl;
+ s << INDENT << "SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self);\n";
if (metaClass->isAbstract() || metaClass->baseClassNames().size() > 1) {
- s << INDENT << "SbkObjectType *type = reinterpret_cast<SbkObjectType *>(self->ob_type);" << endl;
- s << INDENT << "SbkObjectType *myType = reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(metaClass->typeEntry()) << ");" << endl;
+ s << INDENT << "SbkObjectType *type = reinterpret_cast<SbkObjectType *>(self->ob_type);\n";
+ s << INDENT << "SbkObjectType *myType = reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(metaClass->typeEntry()) << ");\n";
}
if (metaClass->isAbstract()) {
- s << INDENT << "if (type == myType) {" << endl;
+ s << INDENT << "if (type == myType) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_NotImplementedError," << endl;
+ s << INDENT << "PyErr_SetString(PyExc_NotImplementedError,\n";
{
Indentation indentation(INDENT);
s << INDENT << "\"'" << metaClass->qualifiedCppName();
}
- s << "' represents a C++ abstract class and cannot be instantiated\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << "' represents a C++ abstract class and cannot be instantiated\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << '}' << endl << endl;
+ s << INDENT<< "}\n\n";
}
if (metaClass->baseClassNames().size() > 1) {
if (!metaClass->isAbstract()) {
- s << INDENT << "if (type != myType) {" << endl;
+ s << INDENT << "if (type != myType) {\n";
}
{
Indentation indentation(INDENT);
- s << INDENT << "Shiboken::ObjectType::copyMultipleInheritance(type, myType);" << endl;
+ s << INDENT << "Shiboken::ObjectType::copyMultipleInheritance(type, myType);\n";
}
if (!metaClass->isAbstract())
- s << INDENT << '}' << endl << endl;
+ s << INDENT<< "}\n\n";
}
writeMethodWrapperPreamble(s, overloadData, classContext);
- s << endl;
+ s << Qt::endl;
if (overloadData.maxArgs() > 0)
writeOverloadedFunctionDecisor(s, overloadData);
writeFunctionCalls(s, overloadData, classContext);
- s << endl;
+ s << Qt::endl;
- s << INDENT << "if (PyErr_Occurred() || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< ::" << metaClass->qualifiedCppName() << " >(), cptr)) {" << endl;
+ s << INDENT << "if (PyErr_Occurred() || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< ::" << metaClass->qualifiedCppName() << " >(), cptr)) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "delete cptr;" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << "delete cptr;\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
if (overloadData.maxArgs() > 0) {
- s << INDENT << "if (!cptr) goto " << cpythonFunctionName(rfunc) << "_TypeError;" << endl;
- s << endl;
+ s << INDENT << "if (!cptr) goto " << cpythonFunctionName(rfunc) << "_TypeError;\n";
+ s << Qt::endl;
}
- s << INDENT << "Shiboken::Object::setValidCpp(sbkSelf, true);" << endl;
+ s << INDENT << "Shiboken::Object::setValidCpp(sbkSelf, true);\n";
// If the created C++ object has a C++ wrapper the ownership is assigned to Python
// (first "1") and the flag indicating that the Python wrapper holds an C++ wrapper
// is marked as true (the second "1"). Otherwise the default values apply:
// Python owns it and C++ wrapper is false.
if (shouldGenerateCppWrapper(overloads.constFirst()->ownerClass()))
- s << INDENT << "Shiboken::Object::setHasCppWrapper(sbkSelf, true);" << endl;
+ s << INDENT << "Shiboken::Object::setHasCppWrapper(sbkSelf, true);\n";
// Need to check if a wrapper for same pointer is already registered
// Caused by bug PYSIDE-217, where deleted objects' wrappers are not released
- s << INDENT << "if (Shiboken::BindingManager::instance().hasWrapper(cptr)) {" << endl;
+ s << INDENT << "if (Shiboken::BindingManager::instance().hasWrapper(cptr)) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "Shiboken::BindingManager::instance().releaseWrapper(Shiboken::BindingManager::instance().retrieveWrapper(cptr));" << endl;
+ s << INDENT << "Shiboken::BindingManager::instance().releaseWrapper(Shiboken::BindingManager::instance().retrieveWrapper(cptr));\n";
}
- s << INDENT << "}" << endl;
- s << INDENT << "Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);" << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);\n";
// Create metaObject and register signal/slot
if (metaClass->isQObject() && usePySideExtensions()) {
- s << endl << INDENT << "// QObject setup" << endl;
- s << INDENT << "PySide::Signal::updateSourceObject(self);" << endl;
- s << INDENT << "metaObject = cptr->metaObject(); // <- init python qt properties" << endl;
- s << INDENT << "if (kwds && !PySide::fillQtProperties(self, metaObject, kwds, argNames, " << argNamesSet.count() << "))" << endl;
+ s << Qt::endl << INDENT << "// QObject setup\n";
+ s << INDENT << "PySide::Signal::updateSourceObject(self);\n";
+ s << INDENT << "metaObject = cptr->metaObject(); // <- init python qt properties\n";
+ s << INDENT << "if (kwds && !PySide::fillQtProperties(self, metaObject, kwds, argNames, " << argNamesSet.count() << "))\n";
{
Indentation indentation(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
}
@@ -1793,31 +1787,31 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun
}
if (hasCodeInjectionsAtEnd) {
// FIXME: C++ arguments are not available in code injection on constructor when position = end.
- s << INDENT << "switch(overloadId) {" << endl;
+ s << INDENT << "switch (overloadId) {\n";
for (AbstractMetaFunction *func : overloads) {
Indentation indent(INDENT);
const CodeSnipList &injectedCodeSnips = func->injectedCodeSnips();
for (const CodeSnip &cs : injectedCodeSnips) {
if (cs.position == TypeSystem::CodeSnipPositionEnd) {
- s << INDENT << "case " << metaClass->functions().indexOf(func) << ':' << endl;
- s << INDENT << '{' << endl;
+ s << INDENT << "case " << metaClass->functions().indexOf(func) << ':' << Qt::endl;
+ s << INDENT << "{\n";
{
Indentation indent(INDENT);
writeCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode, func);
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
break;
}
}
}
- s << '}' << endl;
+ s << "}\n";
}
- s << endl;
- s << endl << INDENT << "return 1;" << endl;
+ s << Qt::endl;
+ s << Qt::endl << INDENT << "return 1;\n";
if (overloadData.maxArgs() > 0)
writeErrorSection(s, overloadData);
- s << '}' << endl << endl;
+ s<< "}\n\n";
}
void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunctionList &overloads,
@@ -1835,11 +1829,11 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction
if (overloadData.hasArgumentWithDefaultValue() || rfunc->isCallOperator())
s << ", PyObject *kwds";
}
- s << ')' << endl << '{' << endl;
+ s << ")\n{\n";
writeMethodWrapperPreamble(s, overloadData, classContext);
- s << endl;
+ s << Qt::endl;
/*
* This code is intended for shift operations only:
@@ -1860,40 +1854,40 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction
// For custom classes, operations like __radd__ and __rmul__
// will enter an infinite loop.
if (rfunc->isBinaryOperator() && revOpName.contains(QLatin1String("shift"))) {
- s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"" << revOpName << "\"));" << endl;
- s << INDENT << "if (!isReverse" << endl;
+ s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"" << revOpName << "\"));\n";
+ s << INDENT << "if (!isReverse\n";
{
Indentation indent(INDENT);
- s << INDENT << "&& Shiboken::Object::checkType(" << PYTHON_ARG << ")" << endl;
- s << INDENT << "&& !PyObject_TypeCheck(" << PYTHON_ARG << ", self->ob_type)" << endl;
- s << INDENT << "&& PyObject_HasAttr(" << PYTHON_ARG << ", attrName)) {" << endl;
+ s << INDENT << "&& Shiboken::Object::checkType(" << PYTHON_ARG << ")\n";
+ s << INDENT << "&& !PyObject_TypeCheck(" << PYTHON_ARG << ", self->ob_type)\n";
+ s << INDENT << "&& PyObject_HasAttr(" << PYTHON_ARG << ", attrName)) {\n";
// This PyObject_CallMethod call will emit lots of warnings like
// "deprecated conversion from string constant to char *" during compilation
// due to the method name argument being declared as "char *" instead of "const char *"
// issue 6952 http://bugs.python.org/issue6952
- s << INDENT << "PyObject *revOpMethod = PyObject_GetAttr(" << PYTHON_ARG << ", attrName);" << endl;
- s << INDENT << "if (revOpMethod && PyCallable_Check(revOpMethod)) {" << endl;
+ s << INDENT << "PyObject *revOpMethod = PyObject_GetAttr(" << PYTHON_ARG << ", attrName);\n";
+ s << INDENT << "if (revOpMethod && PyCallable_Check(revOpMethod)) {\n";
{
Indentation indent(INDENT);
- s << INDENT << PYTHON_RETURN_VAR << " = PyObject_CallFunction(revOpMethod, const_cast<char *>(\"O\"), self);" << endl;
+ s << INDENT << PYTHON_RETURN_VAR << " = PyObject_CallFunction(revOpMethod, const_cast<char *>(\"O\"), self);\n";
s << INDENT << "if (PyErr_Occurred() && (PyErr_ExceptionMatches(PyExc_NotImplementedError)";
- s << " || PyErr_ExceptionMatches(PyExc_AttributeError))) {" << endl;
+ s << " || PyErr_ExceptionMatches(PyExc_AttributeError))) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_Clear();" << endl;
- s << INDENT << "Py_XDECREF(" << PYTHON_RETURN_VAR << ");" << endl;
- s << INDENT << PYTHON_RETURN_VAR << " = " << NULL_PTR << ';' << endl;
+ s << INDENT << "PyErr_Clear();\n";
+ s << INDENT << "Py_XDECREF(" << PYTHON_RETURN_VAR << ");\n";
+ s << INDENT << PYTHON_RETURN_VAR << " = " << NULL_PTR << ";\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
- s << INDENT << "}" << endl;
- s << INDENT << "Py_XDECREF(revOpMethod);" << endl << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "Py_XDECREF(revOpMethod);\n\n";
}
- s << INDENT << "}" << endl;
+ s << INDENT << "}\n";
}
- s << INDENT << "// Do not enter here if other object has implemented a reverse operator." << endl;
- s << INDENT << "if (!" << PYTHON_RETURN_VAR << ") {" << endl << endl;
+ s << INDENT << "// Do not enter here if other object has implemented a reverse operator.\n";
+ s << INDENT << "if (!" << PYTHON_RETURN_VAR << ") {\n\n";
}
if (maxArgs > 0)
@@ -1902,9 +1896,9 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction
writeFunctionCalls(s, overloadData, classContext);
if (callExtendedReverseOperator)
- s << endl << INDENT << "} // End of \"if (!" << PYTHON_RETURN_VAR << ")\"" << endl;
+ s << Qt::endl << INDENT << "} // End of \"if (!" << PYTHON_RETURN_VAR << ")\"\n";
- s << endl;
+ s << Qt::endl;
writeFunctionReturnErrorCheckSection(s, hasReturnValue && !rfunc->isInplaceOperator());
@@ -1916,19 +1910,19 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction
s << INDENT << "return " << PYTHON_RETURN_VAR << ";\n";
}
} else {
- s << INDENT << "Py_RETURN_NONE;" << endl;
+ s << INDENT << "Py_RETURN_NONE;\n";
}
if (maxArgs > 0)
writeErrorSection(s, overloadData);
- s << '}' << endl << endl;
+ s<< "}\n\n";
}
void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overloadData)
{
const AbstractMetaFunction *rfunc = overloadData.referenceFunction();
- s << "PyTuple_GET_SIZE(args);" << endl;
+ s << "PyTuple_GET_SIZE(args);\n";
writeUnusedVariableCast(s, QLatin1String("numArgs"));
int minArgs = overloadData.minArgs();
@@ -1937,32 +1931,32 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl
s << INDENT << "PyObject *";
s << PYTHON_ARGS << "[] = {"
<< QString(maxArgs, QLatin1Char('0')).split(QLatin1String(""), QString::SkipEmptyParts).join(QLatin1String(", "))
- << "};" << endl;
- s << endl;
+ << "};\n";
+ s << Qt::endl;
if (overloadData.hasVarargs()) {
maxArgs--;
if (minArgs > maxArgs)
minArgs = maxArgs;
- s << INDENT << "PyObject *nonvarargs = PyTuple_GetSlice(args, 0, " << maxArgs << ");" << endl;
- s << INDENT << "Shiboken::AutoDecRef auto_nonvarargs(nonvarargs);" << endl;
- s << INDENT << PYTHON_ARGS << '[' << maxArgs << "] = PyTuple_GetSlice(args, " << maxArgs << ", numArgs);" << endl;
- s << INDENT << "Shiboken::AutoDecRef auto_varargs(" << PYTHON_ARGS << "[" << maxArgs << "]);" << endl;
- s << endl;
+ s << INDENT << "PyObject *nonvarargs = PyTuple_GetSlice(args, 0, " << maxArgs << ");\n";
+ s << INDENT << "Shiboken::AutoDecRef auto_nonvarargs(nonvarargs);\n";
+ s << INDENT << PYTHON_ARGS << '[' << maxArgs << "] = PyTuple_GetSlice(args, " << maxArgs << ", numArgs);\n";
+ s << INDENT << "Shiboken::AutoDecRef auto_varargs(" << PYTHON_ARGS << "[" << maxArgs << "]);\n";
+ s << Qt::endl;
}
bool usesNamedArguments = overloadData.hasArgumentWithDefaultValue();
- s << INDENT << "// invalid argument lengths" << endl;
+ s << INDENT << "// invalid argument lengths\n";
bool ownerClassIsQObject = rfunc->ownerClass() && rfunc->ownerClass()->isQObject() && rfunc->isConstructor();
if (usesNamedArguments) {
if (!ownerClassIsQObject) {
- s << INDENT << "if (numArgs" << (overloadData.hasArgumentWithDefaultValue() ? " + numNamedArgs" : "") << " > " << maxArgs << ") {" << endl;
+ s << INDENT << "if (numArgs" << (overloadData.hasArgumentWithDefaultValue() ? " + numNamedArgs" : "") << " > " << maxArgs << ") {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): too many arguments\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): too many arguments\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
s << INDENT << '}';
}
@@ -1971,11 +1965,11 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl
s << INDENT;
else
s << " else ";
- s << "if (numArgs < " << minArgs << ") {" << endl;
+ s << "if (numArgs < " << minArgs << ") {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): not enough arguments\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): not enough arguments\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
s << INDENT << '}';
}
@@ -1989,11 +1983,11 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl
s << " else ";
else
s << INDENT;
- s << "if (" << invArgsLen.join(QLatin1String(" || ")) << ")" << endl;
+ s << "if (" << invArgsLen.join(QLatin1String(" || ")) << ")\n";
Indentation indent(INDENT);
s << INDENT << "goto " << cpythonFunctionName(rfunc) << "_TypeError;";
}
- s << endl << endl;
+ s << Qt::endl << Qt::endl;
QString funcName;
if (rfunc->isOperatorOverload())
@@ -2009,12 +2003,12 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl
s << "PyArg_UnpackTuple(" << argsVar << ", \"" << funcName << "\", " << minArgs << ", " << maxArgs;
for (int i = 0; i < maxArgs; i++)
s << ", &(" << PYTHON_ARGS << '[' << i << "])";
- s << "))" << endl;
+ s << "))\n";
{
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writeCppSelfAssigment(QTextStream &s, const GeneratorContext &context,
@@ -2054,28 +2048,28 @@ void CppGenerator::writeCppSelfDefinition(QTextStream &s,
}
if (!cppSelfAsReference) {
- s << INDENT << className << " *" << CPP_SELF_VAR << " = nullptr;" << endl;
+ s << INDENT << className << " *" << CPP_SELF_VAR << " = nullptr;\n";
writeUnusedVariableCast(s, QLatin1String(CPP_SELF_VAR));
}
// Checks if the underlying C++ object is valid.
if (hasStaticOverload && !cppSelfAsReference) {
- s << INDENT << "if (self) {" << endl;
+ s << INDENT << "if (self) {\n";
{
Indentation indent(INDENT);
writeInvalidPyObjectCheck(s, QLatin1String("self"));
s << INDENT;
writeCppSelfAssigment(s, context, className, cppSelfAsReference, useWrapperClass);
- s << ';' << endl;
+ s << ";\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
return;
}
writeInvalidPyObjectCheck(s, QLatin1String("self"));
s << INDENT;
writeCppSelfAssigment(s, context, className, cppSelfAsReference, useWrapperClass);
- s << ';' << endl;
+ s << ";\n";
}
void CppGenerator::writeCppSelfDefinition(QTextStream &s,
@@ -2088,14 +2082,14 @@ void CppGenerator::writeCppSelfDefinition(QTextStream &s,
if (func->isOperatorOverload() && func->isBinaryOperator()) {
QString checkFunc = cpythonCheckFunction(func->ownerClass()->typeEntry());
- s << INDENT << "bool isReverse = " << checkFunc << PYTHON_ARG << ')' << endl;
+ s << INDENT << "bool isReverse = " << checkFunc << PYTHON_ARG << ")\n";
{
Indentation indent1(INDENT, 4);
- s << INDENT << "&& !" << checkFunc << "self);" << endl;
+ s << INDENT << "&& !" << checkFunc << "self);\n";
}
- s << INDENT << "if (isReverse)" << endl;
+ s << INDENT << "if (isReverse)\n";
Indentation indent(INDENT);
- s << INDENT << "std::swap(self, " << PYTHON_ARG << ");" << endl;
+ s << INDENT << "std::swap(self, " << PYTHON_ARG << ");\n";
}
writeCppSelfDefinition(s, context, hasStaticOverload);
@@ -2104,14 +2098,14 @@ void CppGenerator::writeCppSelfDefinition(QTextStream &s,
void CppGenerator::writeErrorSection(QTextStream &s, OverloadData &overloadData)
{
const AbstractMetaFunction *rfunc = overloadData.referenceFunction();
- s << endl << INDENT << cpythonFunctionName(rfunc) << "_TypeError:" << endl;
+ s << Qt::endl << INDENT << cpythonFunctionName(rfunc) << "_TypeError:\n";
Indentation indentation(INDENT);
QString funcName = fullPythonFunctionName(rfunc);
QString argsVar = pythonFunctionWrapperUsesListOfArguments(overloadData)
? QLatin1String("args") : QLatin1String(PYTHON_ARG);
- s << INDENT << "Shiboken::setErrorAboutWrongArguments(" << argsVar << ", \"" << funcName << "\");" << endl;
- s << INDENT << "return " << m_currentErrorCode << ';' << endl;
+ s << INDENT << "Shiboken::setErrorAboutWrongArguments(" << argsVar << ", \"" << funcName << "\");\n";
+ s << INDENT << "return " << m_currentErrorCode << ";\n";
}
void CppGenerator::writeFunctionReturnErrorCheckSection(QTextStream &s, bool hasReturnValue)
@@ -2119,21 +2113,21 @@ void CppGenerator::writeFunctionReturnErrorCheckSection(QTextStream &s, bool has
s << INDENT << "if (PyErr_Occurred()";
if (hasReturnValue)
s << " || !" << PYTHON_RETURN_VAR;
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
if (hasReturnValue)
- s << INDENT << "Py_XDECREF(" << PYTHON_RETURN_VAR << ");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << "Py_XDECREF(" << PYTHON_RETURN_VAR << ");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
void CppGenerator::writeInvalidPyObjectCheck(QTextStream &s, const QString &pyObj)
{
- s << INDENT << "if (!Shiboken::Object::isValid(" << pyObj << "))" << endl;
+ s << INDENT << "if (!Shiboken::Object::isValid(" << pyObj << "))\n";
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
static QString pythonToCppConverterForArgumentName(const QString &argumentName)
@@ -2336,7 +2330,7 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s,
if (mayHaveImplicitConversion) {
s << INDENT << typeName << ' ' << cppOutAux;
writeMinimalConstructorExpression(s, type, defaultValue);
- s << ';' << endl;
+ s << ";\n";
} else if (avoidProtectedHack() && type->typeEntry()->isEnum()) {
const AbstractMetaEnum *metaEnum = findAbstractMetaEnum(type);
if (metaEnum && metaEnum->isProtected()) {
@@ -2368,7 +2362,7 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s,
writeMinimalConstructorExpression(s, type, defaultValue);
}
}
- s << ';' << endl;
+ s << ";\n";
QString pythonToCppFunc = pythonToCppConverterForArgumentName(pyIn);
@@ -2378,28 +2372,28 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s,
QString pythonToCppCall = QString::fromLatin1("%1(%2, &%3)").arg(pythonToCppFunc, pyIn, cppOut);
if (!mayHaveImplicitConversion) {
- s << pythonToCppCall << ';' << endl;
+ s << pythonToCppCall << ";\n";
return;
}
if (!defaultValue.isEmpty())
- s << '{' << endl << INDENT;
+ s << "{\n" << INDENT;
s << "if (Shiboken::Conversions::isImplicitConversion(reinterpret_cast<SbkObjectType *>("
- << cpythonTypeNameExt(type) << "), " << pythonToCppFunc << "))" << endl;
+ << cpythonTypeNameExt(type) << "), " << pythonToCppFunc << "))\n";
{
Indentation indent(INDENT);
- s << INDENT << pythonToCppFunc << '(' << pyIn << ", &" << cppOutAux << ");" << endl;
+ s << INDENT << pythonToCppFunc << '(' << pyIn << ", &" << cppOutAux << ");\n";
}
- s << INDENT << "else" << endl;
+ s << INDENT << "else\n";
{
Indentation indent(INDENT);
- s << INDENT << pythonToCppCall << ';' << endl;
+ s << INDENT << pythonToCppCall << ";\n";
}
if (!defaultValue.isEmpty())
s << INDENT << '}';
- s << endl;
+ s << Qt::endl;
}
static void addConversionRuleCodeSnippet(CodeSnipList &snippetList, QString &rule,
@@ -2445,14 +2439,14 @@ void CppGenerator::writeConversionRule(QTextStream &s, const AbstractMetaFunctio
void CppGenerator::writeNoneReturn(QTextStream &s, const AbstractMetaFunction *func, bool thereIsReturnValue)
{
if (thereIsReturnValue && (!func->type() || func->argumentRemoved(0)) && !injectedCodeHasReturnValueAttribution(func)) {
- s << INDENT << PYTHON_RETURN_VAR << " = Py_None;" << endl;
- s << INDENT << "Py_INCREF(Py_None);" << endl;
+ s << INDENT << PYTHON_RETURN_VAR << " = Py_None;\n";
+ s << INDENT << "Py_INCREF(Py_None);\n";
}
}
void CppGenerator::writeOverloadedFunctionDecisor(QTextStream &s, const OverloadData &overloadData)
{
- s << INDENT << "// Overloaded function decisor" << endl;
+ s << INDENT << "// Overloaded function decisor\n";
const AbstractMetaFunction *rfunc = overloadData.referenceFunction();
const OverloadData::MetaFunctionList &functionOverloads = overloadData.overloadsWithoutRepetition();
for (int i = 0; i < functionOverloads.count(); i++) {
@@ -2462,26 +2456,26 @@ void CppGenerator::writeOverloadedFunctionDecisor(QTextStream &s, const Overload
s << "static ";
if (const auto *decl = func->declaringClass())
s << decl->name() << "::";
- s << func->minimalSignature() << endl;
+ s << func->minimalSignature() << Qt::endl;
}
writeOverloadedFunctionDecisorEngine(s, &overloadData);
- s << endl;
+ s << Qt::endl;
// Ensure that the direct overload that called this reverse
// is called.
if (rfunc->isOperatorOverload() && !rfunc->isCallOperator()) {
- s << INDENT << "if (isReverse && overloadId == -1) {" << endl;
+ s << INDENT << "if (isReverse && overloadId == -1) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"reverse operator not implemented.\");" << endl;
- s << INDENT << "return {};" << endl;
+ s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"reverse operator not implemented.\");\n";
+ s << INDENT << "return {};\n";
}
- s << INDENT << "}" << endl << endl;
+ s << INDENT << "}\n\n";
}
- s << INDENT << "// Function signature not found." << endl;
- s << INDENT << "if (overloadId == -1) goto " << cpythonFunctionName(overloadData.referenceFunction()) << "_TypeError;" << endl;
- s << endl;
+ s << INDENT << "// Function signature not found.\n";
+ s << INDENT << "if (overloadId == -1) goto " << cpythonFunctionName(overloadData.referenceFunction()) << "_TypeError;\n";
+ s << Qt::endl;
}
void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const OverloadData *parentOverloadData)
@@ -2512,7 +2506,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
// Functions without arguments are identified right away.
if (maxArgs == 0) {
s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(referenceFunction);
- s << "; // " << referenceFunction->minimalSignature() << endl;
+ s << "; // " << referenceFunction->minimalSignature() << Qt::endl;
return;
}
@@ -2528,7 +2522,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
if (isLastArgument || (signatureFound && !hasDefaultCall)) {
const AbstractMetaFunction *func = parentOverloadData->referenceFunction();
s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(func);
- s << "; // " << func->minimalSignature() << endl;
+ s << "; // " << func->minimalSignature() << Qt::endl;
return;
}
}
@@ -2542,7 +2536,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
if (hasDefaultCall) {
isFirst = false;
int numArgs = parentOverloadData->argPos() + 1;
- s << INDENT << "if (numArgs == " << numArgs << ") {" << endl;
+ s << INDENT << "if (numArgs == " << numArgs << ") {\n";
{
Indentation indent(INDENT);
const AbstractMetaFunction *func = referenceFunction;
@@ -2554,7 +2548,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
}
}
s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(func);
- s << "; // " << func->minimalSignature() << endl;
+ s << "; // " << func->minimalSignature() << Qt::endl;
}
s << INDENT << '}';
}
@@ -2587,7 +2581,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
const AbstractMetaClass *ownerClass = func->ownerClass();
const ComplexTypeEntry *baseContainerType = ownerClass->typeEntry()->baseContainerType();
if (baseContainerType && baseContainerType == func->arguments().constFirst()->type()->typeEntry() && isCopyable(ownerClass)) {
- tck << '!' << cpythonCheckFunction(ownerClass->typeEntry()) << pyArgName << ')' << endl;
+ tck << '!' << cpythonCheckFunction(ownerClass->typeEntry()) << pyArgName << ")\n";
Indentation indent(INDENT);
tck << INDENT << "&& ";
}
@@ -2633,25 +2627,25 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov
Indentation indent(INDENT);
QString separator;
QTextStream sep(&separator);
- sep << endl << INDENT << "&& ";
+ sep << Qt::endl << INDENT << "&& ";
s << typeChecks.join(separator);
}
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
writeOverloadedFunctionDecisorEngine(s, overloadData);
}
s << INDENT << "}";
}
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writeFunctionCalls(QTextStream &s, const OverloadData &overloadData,
GeneratorContext &context)
{
const OverloadData::MetaFunctionList &overloads = overloadData.overloadsWithoutRepetition();
- s << INDENT << "// Call function/method" << endl;
- s << INDENT << (overloads.count() > 1 ? "switch (overloadId) " : "") << '{' << endl;
+ s << INDENT << "// Call function/method\n";
+ s << INDENT << (overloads.count() > 1 ? "switch (overloadId) " : "") << "{\n";
{
Indentation indent(INDENT);
if (overloads.count() == 1) {
@@ -2659,8 +2653,8 @@ void CppGenerator::writeFunctionCalls(QTextStream &s, const OverloadData &overlo
} else {
for (int i = 0; i < overloads.count(); i++) {
const AbstractMetaFunction *func = overloads.at(i);
- s << INDENT << "case " << i << ": // " << func->signature() << endl;
- s << INDENT << '{' << endl;
+ s << INDENT << "case " << i << ": // " << func->signature() << Qt::endl;
+ s << INDENT << "{\n";
{
Indentation indent(INDENT);
writeSingleFunctionCall(s, overloadData, func, context);
@@ -2670,13 +2664,13 @@ void CppGenerator::writeFunctionCalls(QTextStream &s, const OverloadData &overlo
s << cls->name() << '.';
s << func->signature() << " is deprecated\", 1);\n";
}
- s << INDENT << "break;" << endl;
+ s << INDENT << "break;\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
}
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
void CppGenerator::writeSingleFunctionCall(QTextStream &s,
@@ -2687,14 +2681,14 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s,
if (func->isDeprecated()) {
s << INDENT << "Shiboken::warning(PyExc_DeprecationWarning, 1, \"Function: '"
<< func->signature().replace(QLatin1String("::"), QLatin1String("."))
- << "' is marked as deprecated, please check the documentation for more information.\");" << endl;
+ << "' is marked as deprecated, please check the documentation for more information.\");\n";
}
if (func->functionType() == AbstractMetaFunction::EmptyFunction) {
s << INDENT << "PyErr_Format(PyExc_TypeError, \"%s is a private method.\", \""
<< func->signature().replace(QLatin1String("::"), QLatin1String("."))
- << "\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ << "\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
return;
}
@@ -2714,7 +2708,7 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s,
const QString cppArgRemoved = QLatin1String(CPP_ARG_REMOVED)
+ QString::number(argIdx);
s << INDENT << getFullTypeName(arg->type()) << ' ' << cppArgRemoved;
- s << " = " << guessScopeForDefaultValue(func, arg) << ';' << endl;
+ s << " = " << guessScopeForDefaultValue(func, arg) << ";\n";
writeUnusedVariableCast(s, cppArgRemoved);
} else if (!injectCodeCallsFunc && !func->isUserAdded() && !hasConversionRule) {
// When an argument is removed from a method signature and no other means of calling
@@ -2737,18 +2731,18 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s,
writeArgumentConversion(s, argType, argName, pyArgName, func->implementingClass(), defaultValue, func->isUserAdded());
}
- s << endl;
+ s << Qt::endl;
int numRemovedArgs = OverloadData::numberOfRemovedArguments(func);
- s << INDENT << "if (!PyErr_Occurred()) {" << endl;
+ s << INDENT << "if (!PyErr_Occurred()) {\n";
{
Indentation indentation(INDENT);
writeMethodCall(s, func, context, func->arguments().size() - numRemovedArgs);
if (!func->isConstructor())
writeNoneReturn(s, func, overloadData.hasNonVoidReturnType());
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
QString CppGenerator::cppToPythonFunctionName(const QString &sourceTypeName, QString targetTypeName)
@@ -2794,9 +2788,9 @@ void CppGenerator::writeCppToPythonFunction(QTextStream &s, const QString &code,
processCodeSnip(prettyCode);
s << "static PyObject *" << cppToPythonFunctionName(sourceTypeName, targetTypeName);
- s << "(const void *cppIn) {" << endl;
+ s << "(const void *cppIn) {\n";
s << prettyCode;
- s << '}' << endl;
+ s << "}\n";
}
static void replaceCppToPythonVariables(QString &code, const QString &typeName)
@@ -2846,9 +2840,9 @@ void CppGenerator::writePythonToCppFunction(QTextStream &s, const QString &code,
formatCode(c, code, INDENT);
processCodeSnip(prettyCode);
s << "static void " << pythonToCppFunctionName(sourceTypeName, targetTypeName);
- s << "(PyObject *pyIn, void *cppOut) {" << endl;
+ s << "(PyObject *pyIn, void *cppOut) {\n";
s << prettyCode;
- s << '}' << endl;
+ s << "}\n";
}
void CppGenerator::writeIsPythonConvertibleToCppFunction(QTextStream &s,
@@ -2862,19 +2856,19 @@ void CppGenerator::writeIsPythonConvertibleToCppFunction(QTextStream &s,
pythonToCppFuncName = pythonToCppFunctionName(sourceTypeName, targetTypeName);
s << "static PythonToCppFunc " << convertibleToCppFunctionName(sourceTypeName, targetTypeName);
- s << "(PyObject *pyIn) {" << endl;
+ s << "(PyObject *pyIn) {\n";
if (acceptNoneAsCppNull) {
- s << INDENT << "if (pyIn == Py_None)" << endl;
+ s << INDENT << "if (pyIn == Py_None)\n";
Indentation indent(INDENT);
- s << INDENT << "return Shiboken::Conversions::nonePythonToCppNullPtr;" << endl;
+ s << INDENT << "return Shiboken::Conversions::nonePythonToCppNullPtr;\n";
}
- s << INDENT << "if (" << condition << ')' << endl;
+ s << INDENT << "if (" << condition << ")\n";
{
Indentation indent(INDENT);
- s << INDENT << "return " << pythonToCppFuncName << ';' << endl;
+ s << INDENT << "return " << pythonToCppFuncName << ";\n";
}
- s << INDENT << "return {};" << endl;
- s << '}' << endl;
+ s << INDENT << "return {};\n";
+ s << "}\n";
}
void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s,
@@ -2892,7 +2886,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s,
if (conversion.isEmpty())
conversion = QLatin1Char('*') + cpythonWrapperCPtr(sourceType->typeEntry(), QLatin1String("pyIn"));
if (!preConversion.isEmpty())
- c << INDENT << preConversion << endl;
+ c << INDENT << preConversion << Qt::endl;
const QString fullTypeName = getFullTypeName(targetType->typeEntry());
c << INDENT << "*reinterpret_cast<" << fullTypeName << " *>(cppOut) = "
<< fullTypeName << '(' << conversion << ");";
@@ -2904,7 +2898,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s,
if (typeCheck.isEmpty())
typeCheck = QString::fromLatin1("PyObject_TypeCheck(pyIn, %1)").arg(sourcePyType);
writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, typeCheck);
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s,
@@ -3012,18 +3006,18 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, const Abs
else
typeCheck = QString::fromLatin1("%1pyIn)").arg(typeCheck);
writeIsPythonConvertibleToCppFunction(s, typeName, typeName, typeCheck);
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writeAddPythonToCppConversion(QTextStream &s, const QString &converterVar, const QString &pythonToCppFunc, const QString &isConvertibleFunc)
{
- s << INDENT << "Shiboken::Conversions::addPythonToCppValueConversion(" << converterVar << ',' << endl;
+ s << INDENT << "Shiboken::Conversions::addPythonToCppValueConversion(" << converterVar << ',' << Qt::endl;
{
Indentation indent(INDENT);
- s << INDENT << pythonToCppFunc << ',' << endl;
+ s << INDENT << pythonToCppFunc << ',' << Qt::endl;
s << INDENT << isConvertibleFunc;
}
- s << ");" << endl;
+ s << ");\n";
}
void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMetaFunction *func, bool usePyArgs)
@@ -3035,44 +3029,44 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe
QString pyErrString(QLatin1String("PyErr_SetString(PyExc_TypeError, \"") + fullPythonFunctionName(func)
+ QLatin1String("(): got multiple values for keyword argument '%1'.\");"));
- s << INDENT << "if (kwds) {" << endl;
+ s << INDENT << "if (kwds) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyObject *keyName = nullptr;" << endl;
- s << INDENT << "PyObject *value = nullptr;" << endl;
+ s << INDENT << "PyObject *keyName = nullptr;\n";
+ s << INDENT << "PyObject *value = nullptr;\n";
for (const AbstractMetaArgument *arg : args) {
int pyArgIndex = arg->argumentIndex() - OverloadData::numberOfRemovedArguments(func, arg->argumentIndex());
QString pyArgName = usePyArgs ? pythonArgsAt(pyArgIndex) : QLatin1String(PYTHON_ARG);
- s << INDENT << "keyName = Py_BuildValue(\"s\",\"" << arg->name() << "\");" << endl;
- s << INDENT << "if (PyDict_Contains(kwds, keyName)) {" << endl;
+ s << INDENT << "keyName = Py_BuildValue(\"s\",\"" << arg->name() << "\");\n";
+ s << INDENT << "if (PyDict_Contains(kwds, keyName)) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "value = PyDict_GetItem(kwds, keyName);" << endl;
- s << INDENT << "if (value && " << pyArgName << ") {" << endl;
+ s << INDENT << "value = PyDict_GetItem(kwds, keyName);\n";
+ s << INDENT << "if (value && " << pyArgName << ") {\n";
{
Indentation indent(INDENT);
- s << INDENT << pyErrString.arg(arg->name()) << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << pyErrString.arg(arg->name()) << Qt::endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << '}' << endl;
- s << INDENT << "if (value) {" << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "if (value) {\n";
{
Indentation indent(INDENT);
- s << INDENT << pyArgName << " = value;" << endl;
+ s << INDENT << pyArgName << " = value;\n";
s << INDENT << "if (!";
writeTypeCheck(s, arg->type(), pyArgName, isNumber(arg->type()->typeEntry()), func->typeReplaced(arg->argumentIndex() + 1));
- s << ')' << endl;
+ s << ")\n";
{
Indentation indent(INDENT);
- s << INDENT << "goto " << cpythonFunctionName(func) << "_TypeError;" << endl;
+ s << INDENT << "goto " << cpythonFunctionName(func) << "_TypeError;\n";
}
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
QString CppGenerator::argumentNameFromIndex(const AbstractMetaFunction *func, int argIndex, const AbstractMetaClass **wrappedClass)
@@ -3127,12 +3121,12 @@ static QStringList defaultExceptionHandling()
void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *func,
GeneratorContext &context, int maxArgs)
{
- s << INDENT << "// " << func->minimalSignature() << (func->isReverseOperator() ? " [reverse operator]": "") << endl;
+ s << INDENT << "// " << func->minimalSignature() << (func->isReverseOperator() ? " [reverse operator]": "") << Qt::endl;
if (func->isConstructor()) {
const CodeSnipList &snips = func->injectedCodeSnips();
for (const CodeSnip &cs : snips) {
if (cs.position == TypeSystem::CodeSnipPositionEnd) {
- s << INDENT << "overloadId = " << func->ownerClass()->functions().indexOf(const_cast<AbstractMetaFunction *const>(func)) << ';' << endl;
+ s << INDENT << "overloadId = " << func->ownerClass()->functions().indexOf(const_cast<AbstractMetaFunction *const>(func)) << ";\n";
break;
}
}
@@ -3143,8 +3137,8 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
{
Indentation indent(INDENT);
s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"pure virtual method '";
- s << func->ownerClass()->name() << '.' << func->name() << "()' not implemented.\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << func->ownerClass()->name() << '.' << func->name() << "()' not implemented.\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
s << INDENT << "}\n";
}
@@ -3171,7 +3165,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
}
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode, func, lastArg);
- s << endl;
+ s << Qt::endl;
}
writeConversionRule(s, func, TypeSystem::NativeCode);
@@ -3263,7 +3257,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
std::swap(firstArg, secondArg);
if (((op == QLatin1String("++")) || (op == QLatin1String("--"))) && !func->isReverseOperator()) {
- s << endl << INDENT << "for(int i=0; i < " << secondArg << "; i++, " << firstArg << op << ");" << endl;
+ s << Qt::endl << INDENT << "for (int i=0; i < " << secondArg << "; i++, " << firstArg << op << ");\n";
mc << firstArg;
} else {
mc << firstArg << ' ' << op << ' ' << secondArg;
@@ -3281,25 +3275,25 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
} else {
QString ctorCall = className + QLatin1Char('(') + userArgs.join(QLatin1String(", ")) + QLatin1Char(')');
if (usePySideExtensions() && func->ownerClass()->isQObject()) {
- s << INDENT << "void *addr = PySide::nextQObjectMemoryAddr();" << endl;
- uva << "if (addr) {" << endl;
+ s << INDENT << "void *addr = PySide::nextQObjectMemoryAddr();\n";
+ uva << "if (addr) {\n";
{
Indentation indent(INDENT);
uva << INDENT << "cptr = " << "new (addr) ::"
- << ctorCall << ';' << endl
+ << ctorCall << ";\n"
<< INDENT
<< "PySide::setNextQObjectMemoryAddr(0);"
- << endl;
+ << Qt::endl;
}
- uva << INDENT << "} else {" << endl;
+ uva << INDENT << "} else {\n";
{
Indentation indent(INDENT);
uva << INDENT << "cptr = " << "new ::"
- << ctorCall << ';' << endl;
+ << ctorCall << ";\n";
}
- uva << INDENT << "}" << endl;
+ uva << INDENT << "}\n";
} else {
mc << "new ::" << ctorCall;
}
@@ -3394,12 +3388,12 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
<< INDENT << "threadSaver.save();\n";
}
} else if (allowThread) {
- s << INDENT << BEGIN_ALLOW_THREADS << endl;
+ s << INDENT << BEGIN_ALLOW_THREADS << Qt::endl;
}
s << INDENT;
if (isCtor) {
s << (useVAddr.isEmpty() ?
- QString::fromLatin1("cptr = %1;").arg(methodCall) : useVAddr) << endl;
+ QString::fromLatin1("cptr = %1;").arg(methodCall) : useVAddr) << Qt::endl;
} else if (func->type() && !func->isInplaceOperator()) {
bool writeReturnType = true;
if (avoidProtectedHack()) {
@@ -3425,9 +3419,9 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
}
}
s << " " << CPP_RETURN_VAR << " = ";
- s << methodCall << ';' << endl;
+ s << methodCall << ";\n";
} else {
- s << methodCall << ';' << endl;
+ s << methodCall << ";\n";
}
if (allowThread) {
@@ -3447,7 +3441,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
} else {
writeToPythonConversion(s, func->type(), func->ownerClass(), QLatin1String(CPP_RETURN_VAR));
}
- s << ';' << endl;
+ s << ";\n";
}
if (generateExceptionHandling) { // "catch" code
@@ -3460,7 +3454,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
}
if (func->hasInjectedCode() && !func->isConstructor()) {
- s << endl;
+ s << Qt::endl;
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode, func, lastArg);
}
@@ -3485,12 +3479,12 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
hasReturnPolicy = true;
if (!ownership_mods.isEmpty()) {
- s << endl << INDENT << "// Ownership transferences." << endl;
+ s << Qt::endl << INDENT << "// Ownership transferences.\n";
for (const ArgumentModification &arg_mod : qAsConst(ownership_mods)) {
const AbstractMetaClass *wrappedClass = nullptr;
QString pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass);
if (!wrappedClass) {
- s << "#error Invalid ownership modification for argument " << arg_mod.index << '(' << pyArgName << ')' << endl << endl;
+ s << "#error Invalid ownership modification for argument " << arg_mod.index << '(' << pyArgName << ")\n" << Qt::endl;
break;
}
@@ -3513,7 +3507,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
} else {
s << "invalidate(" << pyArgName << ");";
}
- s << endl;
+ s << Qt::endl;
}
} else if (!refcount_mods.isEmpty()) {
@@ -3533,7 +3527,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
} else {
pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass);
if (pyArgName.isEmpty()) {
- s << "#error Invalid reference count modification for argument " << arg_mod.index << endl << endl;
+ s << "#error Invalid reference count modification for argument " << arg_mod.index << Qt::endl << Qt::endl;
break;
}
}
@@ -3550,7 +3544,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
s << varName << "\", " << pyArgName
<< (refCount.action == ReferenceCount::Add ? ", true" : "")
- << ");" << endl;
+ << ");\n";
if (arg_mod.index == 0)
hasReturnPolicy = true;
@@ -3590,29 +3584,29 @@ void CppGenerator::writeMultipleInheritanceInitializerFunction(QTextStream &s, c
s << "static int mi_offsets[] = { ";
for (int i = 0; i < ancestors.size(); i++)
s << "-1, ";
- s << "-1 };" << endl;
- s << "int *" << endl;
- s << multipleInheritanceInitializerFunctionName(metaClass) << "(const void *cptr)" << endl;
- s << '{' << endl;
- s << INDENT << "if (mi_offsets[0] == -1) {" << endl;
+ s << "-1 };\n";
+ s << "int *\n";
+ s << multipleInheritanceInitializerFunctionName(metaClass) << "(const void *cptr)\n";
+ s << "{\n";
+ s << INDENT << "if (mi_offsets[0] == -1) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "std::set<int> offsets;" << endl;
- s << INDENT << "const auto *class_ptr = reinterpret_cast<const " << className << " *>(cptr);" << endl;
- s << INDENT << "const auto base = reinterpret_cast<uintptr_t>(class_ptr);" << endl;
+ s << INDENT << "std::set<int> offsets;\n";
+ s << INDENT << "const auto *class_ptr = reinterpret_cast<const " << className << " *>(cptr);\n";
+ s << INDENT << "const auto base = reinterpret_cast<uintptr_t>(class_ptr);\n";
for (const QString &ancestor : ancestors)
- s << INDENT << "offsets.insert(int(" << ancestor << "));" << endl;
+ s << INDENT << "offsets.insert(int(" << ancestor << "));\n";
- s << endl;
- s << INDENT << "offsets.erase(0);" << endl;
- s << endl;
+ s << Qt::endl;
+ s << INDENT << "offsets.erase(0);\n";
+ s << Qt::endl;
s << INDENT << "std::copy(offsets.cbegin(), offsets.cend(), mi_offsets);\n";
}
- s << INDENT << '}' << endl;
- s << INDENT << "return mi_offsets;" << endl;
- s << '}' << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "return mi_offsets;\n";
+ s << "}\n";
}
void CppGenerator::writeSpecialCastFunction(QTextStream &s, const AbstractMetaClass *metaClass)
@@ -3637,7 +3631,7 @@ void CppGenerator::writePrimitiveConverterInitialization(QTextStream &s, const C
{
const TypeEntry *type = customConversion->ownerType();
QString converter = converterObject(type);
- s << INDENT << "// Register converter for type '" << type->qualifiedTargetLangName() << "'." << endl;
+ s << INDENT << "// Register converter for type '" << type->qualifiedTargetLangName() << "'.\n";
s << INDENT << converter << " = Shiboken::Conversions::createConverter(";
if (type->targetLangApiName() == type->name())
s << '0';
@@ -3646,8 +3640,8 @@ void CppGenerator::writePrimitiveConverterInitialization(QTextStream &s, const C
else
s << '&' << type->targetLangApiName() << "_Type";
QString typeName = fixedCppTypeName(type);
- s << ", " << cppToPythonFunctionName(typeName, typeName) << ");" << endl;
- s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << type->qualifiedCppName() << "\");" << endl;
+ s << ", " << cppToPythonFunctionName(typeName, typeName) << ");\n";
+ s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << type->qualifiedCppName() << "\");\n";
writeCustomConverterRegister(s, customConversion, converter);
}
@@ -3669,15 +3663,15 @@ void CppGenerator::writeEnumConverterInitialization(QTextStream &s, const TypeEn
if (enumType->isFlags())
flags = static_cast<const FlagsTypeEntry *>(enumType);
- s << INDENT << "// Register converter for " << enumFlagName << " '" << enumType->qualifiedCppName() << "'." << endl;
- s << INDENT << '{' << endl;
+ s << INDENT << "// Register converter for " << enumFlagName << " '" << enumType->qualifiedCppName() << "'.\n";
+ s << INDENT << "{\n";
{
Indentation indent(INDENT);
QString typeName = fixedCppTypeName(enumType);
- s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter(" << enumPythonType << ',' << endl;
+ s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter(" << enumPythonType << ',' << Qt::endl;
{
Indentation indent(INDENT);
- s << INDENT << cppToPythonFunctionName(typeName, typeName) << ");" << endl;
+ s << INDENT << cppToPythonFunctionName(typeName, typeName) << ");\n";
}
if (flags) {
@@ -3697,7 +3691,7 @@ void CppGenerator::writeEnumConverterInitialization(QTextStream &s, const TypeEn
writeAddPythonToCppConversion(s, QLatin1String("converter"), toCpp, isConv);
}
- s << INDENT << "Shiboken::Enum::setTypeConverter(" << enumPythonType << ", converter);" << endl;
+ s << INDENT << "Shiboken::Enum::setTypeConverter(" << enumPythonType << ", converter);\n";
QString signature = enumType->qualifiedCppName();
// Replace "QFlags<Class::Option>" by "Class::Options"
@@ -3723,7 +3717,7 @@ void CppGenerator::writeEnumConverterInitialization(QTextStream &s, const TypeEn
break;
}
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
if (!flags)
writeEnumConverterInitialization(s, static_cast<const EnumTypeEntry *>(enumType)->flags());
@@ -3732,7 +3726,7 @@ void CppGenerator::writeEnumConverterInitialization(QTextStream &s, const TypeEn
void CppGenerator::writeContainerConverterInitialization(QTextStream &s, const AbstractMetaType *type)
{
QByteArray cppSignature = QMetaObject::normalizedSignature(type->cppSignature().toUtf8());
- s << INDENT << "// Register converter for type '" << cppSignature << "'." << endl;
+ s << INDENT << "// Register converter for type '" << cppSignature << "'.\n";
QString converter = converterObject(type);
s << INDENT << converter << " = Shiboken::Conversions::createConverter(";
if (type->typeEntry()->targetLangApiName() == QLatin1String("PyObject")) {
@@ -3744,14 +3738,14 @@ void CppGenerator::writeContainerConverterInitialization(QTextStream &s, const A
s << '&' << baseName << "_Type";
}
QString typeName = fixedCppTypeName(type);
- s << ", " << cppToPythonFunctionName(typeName, typeName) << ");" << endl;
+ s << ", " << cppToPythonFunctionName(typeName, typeName) << ");\n";
QString toCpp = pythonToCppFunctionName(typeName, typeName);
QString isConv = convertibleToCppFunctionName(typeName, typeName);
- s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << cppSignature << "\");" << endl;
+ s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << cppSignature << "\");\n";
if (usePySideExtensions() && cppSignature.startsWith("const ") && cppSignature.endsWith("&")) {
cppSignature.chop(1);
cppSignature.remove(0, sizeof("const ") / sizeof(char) - 1);
- s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << cppSignature << "\");" << endl;
+ s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << cppSignature << "\");\n";
}
writeAddPythonToCppConversion(s, converterObject(type), toCpp, isConv);
}
@@ -3759,7 +3753,7 @@ void CppGenerator::writeContainerConverterInitialization(QTextStream &s, const A
void CppGenerator::writeExtendedConverterInitialization(QTextStream &s, const TypeEntry *externalType,
const QVector<const AbstractMetaClass *>& conversions)
{
- s << INDENT << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << endl;
+ s << INDENT << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << Qt::endl;
for (const AbstractMetaClass *sourceClass : conversions) {
const QString converterVar = QLatin1String("reinterpret_cast<SbkObjectType *>(")
+ cppApiVariableName(externalType->targetLangPackage()) + QLatin1Char('[')
@@ -3953,11 +3947,11 @@ void CppGenerator::writeClassDefinition(QTextStream &s,
if (metaClass == miClass)
writeMultipleInheritanceInitializerFunction(s, metaClass);
writeSpecialCastFunction(s, metaClass);
- s << endl;
+ s << Qt::endl;
}
- s << "// Class Definition -----------------------------------------------" << endl;
- s << "extern \"C\" {" << endl;
+ s << "// Class Definition -----------------------------------------------\n";
+ s << "extern \"C\" {\n";
if (!metaClass->typeEntry()->hashFunction().isEmpty())
tp_hash = QLatin1Char('&') + cpythonBaseName(metaClass) + QLatin1String("_HashFunc");
@@ -3977,14 +3971,14 @@ void CppGenerator::writeClassDefinition(QTextStream &s,
suffix = QLatin1String(" *");
const QString typePtr = QLatin1String("_") + className
+ QLatin1String("_Type");
- s << "static SbkObjectType *" << typePtr << " = nullptr;" << endl;
- s << "static SbkObjectType *" << className << "_TypeF(void)" << endl;
- s << "{" << endl;
- s << INDENT << "return " << typePtr << ";" << endl;
- s << "}" << endl;
- s << endl;
- s << "static PyType_Slot " << className << "_slots[] = {" << endl;
- s << INDENT << "{Py_tp_base, nullptr}, // inserted by introduceWrapperType" << endl;
+ s << "static SbkObjectType *" << typePtr << " = nullptr;\n";
+ s << "static SbkObjectType *" << className << "_TypeF(void)\n";
+ s << "{\n";
+ s << INDENT << "return " << typePtr << ";\n";
+ s << "}\n";
+ s << Qt::endl;
+ s << "static PyType_Slot " << className << "_slots[] = {\n";
+ s << INDENT << "{Py_tp_base, nullptr}, // inserted by introduceWrapperType\n";
s << INDENT << pyTypeSlotEntry("Py_tp_dealloc", tp_dealloc)
<< INDENT << pyTypeSlotEntry("Py_tp_repr", m_tpFuncs.value(QLatin1String("__repr__")))
<< INDENT << pyTypeSlotEntry("Py_tp_hash", tp_hash)
@@ -4002,29 +3996,29 @@ void CppGenerator::writeClassDefinition(QTextStream &s,
<< INDENT << pyTypeSlotEntry("Py_tp_init", tp_init)
<< INDENT << pyTypeSlotEntry("Py_tp_new", tp_new);
if (supportsSequenceProtocol(metaClass)) {
- s << INDENT << "// type supports sequence protocol" << endl;
+ s << INDENT << "// type supports sequence protocol\n";
writeTypeAsSequenceDefinition(s, metaClass);
}
if (supportsMappingProtocol(metaClass)) {
- s << INDENT << "// type supports mapping protocol" << endl;
+ s << INDENT << "// type supports mapping protocol\n";
writeTypeAsMappingDefinition(s, metaClass);
}
if (supportsNumberProtocol(metaClass)) {
// This one must come last. See the function itself.
- s << INDENT << "// type supports number protocol" << endl;
+ s << INDENT << "// type supports number protocol\n";
writeTypeAsNumberDefinition(s, metaClass);
}
- s << INDENT << "{0, " << NULL_PTR << '}' << endl;
- s << "};" << endl;
- s << "static PyType_Spec " << className << "_spec = {" << endl;
- s << INDENT << "\"" << computedClassTargetFullName << "\"," << endl;
- s << INDENT << "sizeof(SbkObject)," << endl;
- s << INDENT << "0," << endl;
- s << INDENT << tp_flags << "," << endl;
- s << INDENT << className << "_slots" << endl;
- s << "};" << endl;
- s << endl;
- s << "} //extern \"C\"" << endl;
+ s << INDENT << "{0, " << NULL_PTR << "}\n";
+ s << "};\n";
+ s << "static PyType_Spec " << className << "_spec = {\n";
+ s << INDENT << "\"" << computedClassTargetFullName << "\",\n";
+ s << INDENT << "sizeof(SbkObject),\n";
+ s << INDENT << "0,\n";
+ s << INDENT << tp_flags << ",\n";
+ s << INDENT << className << "_slots\n";
+ s << "};\n";
+ s << Qt::endl;
+ s << "} //extern \"C\"" << Qt::endl;
}
void CppGenerator::writeMappingMethods(QTextStream &s,
@@ -4040,14 +4034,14 @@ void CppGenerator::writeMappingMethods(QTextStream &s,
QString funcRetVal = it.value().second;
CodeSnipList snips = func->injectedCodeSnips(TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode);
- s << funcRetVal << ' ' << funcName << '(' << funcArgs << ')' << endl << '{' << endl;
+ s << funcRetVal << ' ' << funcName << '(' << funcArgs << ")\n{\n";
writeInvalidPyObjectCheck(s, QLatin1String("self"));
writeCppSelfDefinition(s, func, context);
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode, func, lastArg);
- s << '}' << endl << endl;
+ s<< "}\n\n";
}
}
@@ -4067,14 +4061,14 @@ void CppGenerator::writeSequenceMethods(QTextStream &s,
QString funcRetVal = it.value().second;
CodeSnipList snips = func->injectedCodeSnips(TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode);
- s << funcRetVal << ' ' << funcName << '(' << funcArgs << ')' << endl << '{' << endl;
+ s << funcRetVal << ' ' << funcName << '(' << funcArgs << ")\n{\n";
writeInvalidPyObjectCheck(s, QLatin1String("self"));
writeCppSelfDefinition(s, func, context);
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? 0 : func->arguments().constLast();
writeCodeSnips(s, snips,TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode, func, lastArg);
- s << '}' << endl << endl;
+ s<< "}\n\n";
}
if (!injectedCode)
@@ -4107,10 +4101,10 @@ void CppGenerator::writeTypeAsSequenceDefinition(QTextStream &s, const AbstractM
if (funcs[sqName].isEmpty())
continue;
if (it.value() == QLatin1String("sq_slice"))
- s << "#ifndef IS_PY3K" << endl;
- s << INDENT << "{Py_" << it.value() << ", (void *)" << funcs[sqName] << "}," << endl;
+ s << "#ifndef IS_PY3K\n";
+ s << INDENT << "{Py_" << it.value() << ", (void *)" << funcs[sqName] << "},\n";
if (it.value() == QLatin1String("sq_slice"))
- s << "#endif" << endl;
+ s << "#endif\n";
}
}
@@ -4137,7 +4131,7 @@ void CppGenerator::writeTypeAsMappingDefinition(QTextStream &s, const AbstractMe
const QString &mpName = it.key();
if (funcs[mpName].isEmpty())
continue;
- s << INDENT << "{Py_" << it.value() << ", (void *)" << funcs[mpName] << "}," << endl;
+ s << INDENT << "{Py_" << it.value() << ", (void *)" << funcs[mpName] << "},\n";
}
}
@@ -4194,28 +4188,28 @@ void CppGenerator::writeTypeAsNumberDefinition(QTextStream &s, const AbstractMet
// bool is special because the field name differs on Python 2 and 3 (nb_nonzero vs nb_bool)
// so a shiboken macro is used.
if (nbName == QLatin1String("bool")) {
- s << "#ifdef IS_PY3K" << endl;
- s << INDENT << "{Py_nb_bool, (void *)" << nb[nbName] << "}," << endl;
- s << "#else" << endl;
- s << INDENT << "{Py_nb_nonzero, (void *)" << nb[nbName] << "}," << endl;
- s << "#endif" << endl;
+ s << "#ifdef IS_PY3K\n";
+ s << INDENT << "{Py_nb_bool, (void *)" << nb[nbName] << "},\n";
+ s << "#else\n";
+ s << INDENT << "{Py_nb_nonzero, (void *)" << nb[nbName] << "},\n";
+ s << "#endif\n";
} else {
bool excludeFromPy3K = nbName == QLatin1String("__div__") || nbName == QLatin1String("__idiv__");
if (!excludeFromPy3K)
- s << INDENT << "{Py_" << it.value() << ", (void *)" << nb[nbName] << "}," << endl;
+ s << INDENT << "{Py_" << it.value() << ", (void *)" << nb[nbName] << "},\n";
}
}
if (!nb[QLatin1String("__div__")].isEmpty()) {
- s << INDENT << "{Py_nb_true_divide, (void *)" << nb[QLatin1String("__div__")] << "}," << endl;
- s << "#ifndef IS_PY3K" << endl;
- s << INDENT << "{Py_nb_divide, (void *)" << nb[QLatin1String("__div__")] << "}," << endl;
- s << "#endif" << endl;
+ s << INDENT << "{Py_nb_true_divide, (void *)" << nb[QLatin1String("__div__")] << "},\n";
+ s << "#ifndef IS_PY3K\n";
+ s << INDENT << "{Py_nb_divide, (void *)" << nb[QLatin1String("__div__")] << "},\n";
+ s << "#endif\n";
}
if (!nb[QLatin1String("__idiv__")].isEmpty()) {
- s << INDENT << "// This function is unused in Python 3. We reference it here." << endl;
- s << INDENT << "{0, (void *)" << nb[QLatin1String("__idiv__")] << "}," << endl;
- s << INDENT << "// This list is ending at the first 0 entry." << endl;
- s << INDENT << "// Therefore, we need to put the unused functions at the very end." << endl;
+ s << INDENT << "// This function is unused in Python 3. We reference it here.\n";
+ s << INDENT << "{0, (void *)" << nb[QLatin1String("__idiv__")] << "},\n";
+ s << INDENT << "// This list is ending at the first 0 entry.\n";
+ s << INDENT << "// Therefore, we need to put the unused functions at the very end.\n";
}
}
@@ -4223,28 +4217,28 @@ void CppGenerator::writeTpTraverseFunction(QTextStream &s, const AbstractMetaCla
{
QString baseName = cpythonBaseName(metaClass);
s << "static int ";
- s << baseName << "_traverse(PyObject *self, visitproc visit, void *arg)" << endl;
- s << '{' << endl;
- s << INDENT << "return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_traverse(self, visit, arg);" << endl;
- s << '}' << endl;
+ s << baseName << "_traverse(PyObject *self, visitproc visit, void *arg)\n";
+ s << "{\n";
+ s << INDENT << "return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_traverse(self, visit, arg);\n";
+ s << "}\n";
}
void CppGenerator::writeTpClearFunction(QTextStream &s, const AbstractMetaClass *metaClass)
{
QString baseName = cpythonBaseName(metaClass);
s << "static int ";
- s << baseName << "_clear(PyObject *self)" << endl;
- s << '{' << endl;
- s << INDENT << "return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_clear(self);" << endl;
- s << '}' << endl;
+ s << baseName << "_clear(PyObject *self)\n";
+ s << "{\n";
+ s << INDENT << "return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_clear(self);\n";
+ s << "}\n";
}
void CppGenerator::writeCopyFunction(QTextStream &s, GeneratorContext &context)
{
const AbstractMetaClass *metaClass = context.metaClass();
const QString className = chopType(cpythonTypeName(metaClass));
- s << "static PyObject *" << className << "___copy__(PyObject *self)" << endl;
- s << "{" << endl;
+ s << "static PyObject *" << className << "___copy__(PyObject *self)\n";
+ s << "{\n";
writeCppSelfDefinition(s, context, false, true);
QString conversionCode;
if (!context.forSmartPointer())
@@ -4253,11 +4247,11 @@ void CppGenerator::writeCopyFunction(QTextStream &s, GeneratorContext &context)
conversionCode = cpythonToPythonConversionFunction(context.preciseType());
s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << " = " << conversionCode;
- s << CPP_SELF_VAR << ");" << endl;
+ s << CPP_SELF_VAR << ");\n";
writeFunctionReturnErrorCheckSection(s);
- s << INDENT << "return " << PYTHON_RETURN_VAR << ";" << endl;
- s << "}" << endl;
- s << endl;
+ s << INDENT << "return " << PYTHON_RETURN_VAR << ";\n";
+ s << "}\n";
+ s << Qt::endl;
}
void CppGenerator::writeGetterFunction(QTextStream &s,
@@ -4265,8 +4259,8 @@ void CppGenerator::writeGetterFunction(QTextStream &s,
GeneratorContext &context)
{
ErrorCode errorCode(QString::fromLatin1(NULL_PTR));
- s << "static PyObject *" << cpythonGetterFunctionName(metaField) << "(PyObject *self, void *)" << endl;
- s << '{' << endl;
+ s << "static PyObject *" << cpythonGetterFunctionName(metaField) << "(PyObject *self, void *)\n";
+ s << "{\n";
writeCppSelfDefinition(s, context);
@@ -4287,7 +4281,7 @@ void CppGenerator::writeGetterFunction(QTextStream &s,
}
}
if (isCppIntegralPrimitive(fieldType) || fieldType->isEnum()) {
- s << INDENT << getFullTypeNameWithoutModifiers(fieldType) << " cppOut_local = " << cppField << ';' << endl;
+ s << INDENT << getFullTypeNameWithoutModifiers(fieldType) << " cppOut_local = " << cppField << ";\n";
cppField = QLatin1String("cppOut_local");
} else if (avoidProtectedHack() && metaField->isProtected()) {
s << INDENT << getFullTypeNameWithoutModifiers(fieldType);
@@ -4297,7 +4291,7 @@ void CppGenerator::writeGetterFunction(QTextStream &s,
} else if ((!fieldType->isConstant() && !fieldType->isEnum() && !fieldType->isPrimitive()) || fieldType->indirections() == 1) {
s << " *";
}
- s << " fieldValue = " << cppField << ';' << endl;
+ s << " fieldValue = " << cppField << ";\n";
cppField = QLatin1String("fieldValue");
}
@@ -4330,16 +4324,16 @@ void CppGenerator::writeGetterFunction(QTextStream &s,
// Create and register new wrapper
s << INDENT << "pyOut = ";
s << "Shiboken::Object::newObject(reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(fieldType)
- << "), " << cppField << ", false, true);" << endl;
+ << "), " << cppField << ", false, true);\n";
s << INDENT << "Shiboken::Object::setParent(self, pyOut)";
} else {
s << INDENT << "pyOut = ";
writeToPythonConversion(s, fieldType, metaField->enclosingClass(), cppField);
}
- s << ';' << endl;
+ s << ";\n";
- s << INDENT << "return pyOut;" << endl;
- s << '}' << endl;
+ s << INDENT << "return pyOut;\n";
+ s << "}\n";
}
void CppGenerator::writeSetterFunction(QTextStream &s,
@@ -4347,64 +4341,64 @@ void CppGenerator::writeSetterFunction(QTextStream &s,
GeneratorContext &context)
{
ErrorCode errorCode(0);
- s << "static int " << cpythonSetterFunctionName(metaField) << "(PyObject *self, PyObject *pyIn, void *)" << endl;
- s << '{' << endl;
+ s << "static int " << cpythonSetterFunctionName(metaField) << "(PyObject *self, PyObject *pyIn, void *)\n";
+ s << "{\n";
writeCppSelfDefinition(s, context);
- s << INDENT << "if (pyIn == " << NULL_PTR << ") {" << endl;
+ s << INDENT << "if (pyIn == " << NULL_PTR << ") {\n";
{
Indentation indent(INDENT);
s << INDENT << "PyErr_SetString(PyExc_TypeError, \"'";
- s << metaField->name() << "' may not be deleted\");" << endl;
- s << INDENT << "return -1;" << endl;
+ s << metaField->name() << "' may not be deleted\");\n";
+ s << INDENT << "return -1;\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
AbstractMetaType *fieldType = metaField->type();
- s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << "{nullptr};" << endl;
+ s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << "{nullptr};\n";
s << INDENT << "if (!";
writeTypeCheck(s, fieldType, QLatin1String("pyIn"), isNumber(fieldType->typeEntry()));
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
s << INDENT << "PyErr_SetString(PyExc_TypeError, \"wrong type attributed to '";
- s << metaField->name() << "', '" << fieldType->name() << "' or convertible type expected\");" << endl;
- s << INDENT << "return -1;" << endl;
+ s << metaField->name() << "', '" << fieldType->name() << "' or convertible type expected\");\n";
+ s << INDENT << "return -1;\n";
}
- s << INDENT << '}' << endl << endl;
+ s << INDENT<< "}\n\n";
QString cppField = QString::fromLatin1("%1->%2").arg(QLatin1String(CPP_SELF_VAR), metaField->name());
s << INDENT;
if (avoidProtectedHack() && metaField->isProtected()) {
s << getFullTypeNameWithoutModifiers(fieldType);
- s << (fieldType->indirections() == 1 ? " *" : "") << " cppOut;" << endl;
- s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut);" << endl;
+ s << (fieldType->indirections() == 1 ? " *" : "") << " cppOut;\n";
+ s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut);\n";
s << INDENT << "static_cast<" << wrapperName(metaField->enclosingClass())
<< " *>(" << CPP_SELF_VAR << ")->" << protectedFieldSetterName(metaField)
<< "(cppOut)";
} else if (isCppIntegralPrimitive(fieldType) || fieldType->typeEntry()->isEnum() || fieldType->typeEntry()->isFlags()) {
- s << getFullTypeNameWithoutModifiers(fieldType) << " cppOut_local = " << cppField << ';' << endl;
- s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut_local);" << endl;
+ s << getFullTypeNameWithoutModifiers(fieldType) << " cppOut_local = " << cppField << ";\n";
+ s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut_local);\n";
s << INDENT << cppField << " = cppOut_local";
} else {
if (isPointerToConst(fieldType))
s << "const ";
s << getFullTypeNameWithoutModifiers(fieldType);
s << QString::fromLatin1(" *").repeated(fieldType->indirections()) << "& cppOut_ptr = ";
- s << cppField << ';' << endl;
+ s << cppField << ";\n";
s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut_ptr)";
}
- s << ';' << endl << endl;
+ s << ";\n" << Qt::endl;
if (isPointerToWrapperType(fieldType)) {
s << INDENT << "Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(self), \"";
- s << metaField->name() << "\", pyIn);" << endl;
+ s << metaField->name() << "\", pyIn);\n";
}
- s << INDENT << "return 0;" << endl;
- s << '}' << endl;
+ s << INDENT << "return 0;\n";
+ s << "}\n";
}
void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &context)
@@ -4412,16 +4406,16 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co
const AbstractMetaClass *metaClass = context.metaClass();
QString baseName = cpythonBaseName(metaClass);
s << "static PyObject * ";
- s << baseName << "_richcompare(PyObject *self, PyObject *" << PYTHON_ARG << ", int op)" << endl;
- s << '{' << endl;
+ s << baseName << "_richcompare(PyObject *self, PyObject *" << PYTHON_ARG
+ << ", int op)\n{\n";
writeCppSelfDefinition(s, context, false, true);
writeUnusedVariableCast(s, QLatin1String(CPP_SELF_VAR));
- s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << "{};" << endl;
- s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ';' << endl;
+ s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << "{};\n";
+ s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ";\n";
writeUnusedVariableCast(s, QLatin1String(PYTHON_TO_CPP_VAR));
- s << endl;
+ s << Qt::endl;
- s << INDENT << "switch (op) {" << endl;
+ s << INDENT << "switch (op) {\n";
{
Indentation indent(INDENT);
const QVector<AbstractMetaFunctionList> &groupedFuncs = filterGroupedOperatorFunctions(metaClass, AbstractMetaClass::ComparisonOp);
@@ -4429,7 +4423,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co
const AbstractMetaFunction *rfunc = overloads[0];
QString operatorId = ShibokenGenerator::pythonRichCompareOperatorId(rfunc);
- s << INDENT << "case " << operatorId << ':' << endl;
+ s << INDENT << "case " << operatorId << ':' << Qt::endl;
Indentation indent(INDENT);
@@ -4461,10 +4455,10 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co
}
s << "if (";
writeTypeCheck(s, argType, QLatin1String(PYTHON_ARG), alternativeNumericTypes == 1 || isPyInt(argType));
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
- s << INDENT << "// " << func->signature() << endl;
+ s << INDENT << "// " << func->signature() << Qt::endl;
writeArgumentConversion(s, argType, QLatin1String(CPP_ARG0),
QLatin1String(PYTHON_ARG), metaClass,
QString(), func->isUserAdded());
@@ -4483,49 +4477,49 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co
s << CPP_SELF_VAR << ' ' << op << '(';
if (shouldDereferenceAbstractMetaTypePointer(argType))
s << '*';
- s << CPP_ARG0 << ");" << endl;
+ s << CPP_ARG0 << ");\n";
s << INDENT << PYTHON_RETURN_VAR << " = ";
if (func->type())
writeToPythonConversion(s, func->type(), metaClass, QLatin1String(CPP_RETURN_VAR));
else
- s << "Py_None;" << endl << INDENT << "Py_INCREF(Py_None)";
- s << ';' << endl;
+ s << "Py_None;\n" << INDENT << "Py_INCREF(Py_None)";
+ s << ";\n";
}
}
s << INDENT << '}';
}
- s << " else {" << endl;
+ s << " else {\n";
if (operatorId == QLatin1String("Py_EQ") || operatorId == QLatin1String("Py_NE")) {
Indentation indent(INDENT);
s << INDENT << PYTHON_RETURN_VAR << " = "
- << (operatorId == QLatin1String("Py_EQ") ? "Py_False" : "Py_True") << ';' << endl;
- s << INDENT << "Py_INCREF(" << PYTHON_RETURN_VAR << ");" << endl;
+ << (operatorId == QLatin1String("Py_EQ") ? "Py_False" : "Py_True") << ";\n";
+ s << INDENT << "Py_INCREF(" << PYTHON_RETURN_VAR << ");\n";
} else {
Indentation indent(INDENT);
- s << INDENT << "goto " << baseName << "_RichComparison_TypeError;" << endl;
+ s << INDENT << "goto " << baseName << "_RichComparison_TypeError;\n";
}
- s << INDENT << '}' << endl << endl;
+ s << INDENT<< "}\n\n";
- s << INDENT << "break;" << endl;
+ s << INDENT << "break;\n";
}
- s << INDENT << "default:" << endl;
+ s << INDENT << "default:\n";
{
Indentation indent(INDENT);
- s << INDENT << "goto " << baseName << "_RichComparison_TypeError;" << endl;
+ s << INDENT << "goto " << baseName << "_RichComparison_TypeError;\n";
}
}
- s << INDENT << '}' << endl << endl;
+ s << INDENT<< "}\n\n";
- s << INDENT << "if (" << PYTHON_RETURN_VAR << " && !PyErr_Occurred())" << endl;
+ s << INDENT << "if (" << PYTHON_RETURN_VAR << " && !PyErr_Occurred())\n";
{
Indentation indent(INDENT);
- s << INDENT << "return " << PYTHON_RETURN_VAR << ";" << endl;
+ s << INDENT << "return " << PYTHON_RETURN_VAR << ";\n";
}
- s << INDENT << baseName << "_RichComparison_TypeError:" << endl;
- s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"operator not implemented.\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl << endl;
- s << '}' << endl << endl;
+ s << INDENT << baseName << "_RichComparison_TypeError:\n";
+ s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"operator not implemented.\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl;
+ s<< "}\n\n";
}
void CppGenerator::writeMethodDefinitionEntry(QTextStream &s, const AbstractMetaFunctionList &overloads)
@@ -4568,7 +4562,7 @@ void CppGenerator::writeMethodDefinition(QTextStream &s, const AbstractMetaFunct
writeMethodDefinitionEntry(s, overloads);
s << '}';
}
- s << ',' << endl;
+ s << ',' << Qt::endl;
}
void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunctionList &overloads)
@@ -4601,7 +4595,7 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction
s << funcName << '(' << args.join(QLatin1Char(',')) << ')';
if (f->type())
s << "->" << f->type()->pythonSignature();
- s << endl;
+ s << Qt::endl;
}
}
@@ -4609,7 +4603,7 @@ void CppGenerator::writeEnumsInitialization(QTextStream &s, AbstractMetaEnumList
{
if (enums.isEmpty())
return;
- s << INDENT << "// Initialization of enums." << endl << endl;
+ s << INDENT << "// Initialization of enums.\n\n";
for (const AbstractMetaEnum *cppEnum : qAsConst(enums)) {
if (cppEnum->isPrivate())
continue;
@@ -4628,9 +4622,8 @@ static QString mangleName(QString name)
void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnum *cppEnum)
{
- const AbstractMetaClass *enclosingClass = getProperEnclosingClassForEnum(cppEnum);
- const AbstractMetaClass *upper = enclosingClass ? enclosingClass->enclosingClass() : nullptr;
- bool hasUpperEnclosingClass = upper && upper->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass;
+ const AbstractMetaClass *enclosingClass = cppEnum->targetLangEnclosingClass();
+ bool hasUpperEnclosingClass = enclosingClass && enclosingClass->targetLangEnclosingClass() != nullptr;
const EnumTypeEntry *enumTypeEntry = cppEnum->typeEntry();
QString enclosingObjectVariable;
if (enclosingClass)
@@ -4642,7 +4635,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu
s << INDENT << "// Initialization of ";
s << (cppEnum->isAnonymous() ? "anonymous enum identified by enum value" : "enum");
- s << " '" << cppEnum->name() << "'." << endl;
+ s << " '" << cppEnum->name() << "'.\n";
QString enumVarTypeObj;
if (!cppEnum->isAnonymous()) {
@@ -4654,28 +4647,28 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu
fullPath.truncate(fullPath.lastIndexOf(QLatin1Char('.')) + 1);
s << INDENT << cpythonTypeNameExt(flags) << " = PySide::QFlags::create(\""
<< fullPath << flags->flagsName() << "\", "
- << cpythonEnumName(cppEnum) << "_number_slots);" << endl;
+ << cpythonEnumName(cppEnum) << "_number_slots);\n";
}
enumVarTypeObj = cpythonTypeNameExt(enumTypeEntry);
s << INDENT << enumVarTypeObj << " = Shiboken::Enum::";
s << ((enclosingClass || hasUpperEnclosingClass) ? "createScopedEnum" : "createGlobalEnum");
- s << '(' << enclosingObjectVariable << ',' << endl;
+ s << '(' << enclosingObjectVariable << ',' << Qt::endl;
{
Indentation indent(INDENT);
- s << INDENT << '"' << cppEnum->name() << "\"," << endl;
- s << INDENT << '"' << getClassTargetFullName(cppEnum) << "\"," << endl;
+ s << INDENT << '"' << cppEnum->name() << "\",\n";
+ s << INDENT << '"' << getClassTargetFullName(cppEnum) << "\",\n";
s << INDENT << '"' << (cppEnum->enclosingClass() ? (cppEnum->enclosingClass()->qualifiedCppName() + QLatin1String("::")) : QString());
s << cppEnum->name() << '"';
if (flags)
- s << ',' << endl << INDENT << cpythonTypeNameExt(flags);
- s << ");" << endl;
+ s << ',' << Qt::endl << INDENT << cpythonTypeNameExt(flags);
+ s << ");\n";
}
- s << INDENT << "if (!" << cpythonTypeNameExt(cppEnum->typeEntry()) << ')' << endl;
+ s << INDENT << "if (!" << cpythonTypeNameExt(cppEnum->typeEntry()) << ")\n";
{
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl;
}
}
@@ -4700,45 +4693,45 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu
switch (cppEnum->enumKind()) {
case AnonymousEnum:
if (enclosingClass || hasUpperEnclosingClass) {
- s << INDENT << '{' << endl;
+ s << INDENT << "{\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyObject *anonEnumItem = PyInt_FromLong(" << enumValueText << ");" << endl;
+ s << INDENT << "PyObject *anonEnumItem = PyInt_FromLong(" << enumValueText << ");\n";
s << INDENT << "if (PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(reinterpret_cast<SbkObjectType *>(" << enclosingObjectVariable
- << "))->tp_dict, \"" << mangleName(enumValue->name()) << "\", anonEnumItem) < 0)" << endl;
+ << "))->tp_dict, \"" << mangleName(enumValue->name()) << "\", anonEnumItem) < 0)\n";
{
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << "Py_DECREF(anonEnumItem);" << endl;
+ s << INDENT << "Py_DECREF(anonEnumItem);\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
} else {
s << INDENT << "if (PyModule_AddIntConstant(module, \"" << mangleName(enumValue->name()) << "\", ";
- s << enumValueText << ") < 0)" << endl;
+ s << enumValueText << ") < 0)\n";
{
Indentation indent(INDENT);
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
}
break;
case CEnum: {
s << INDENT << "if (!Shiboken::Enum::";
s << ((enclosingClass || hasUpperEnclosingClass) ? "createScopedEnumItem" : "createGlobalEnumItem");
- s << '(' << enumVarTypeObj << ',' << endl;
+ s << '(' << enumVarTypeObj << ',' << Qt::endl;
Indentation indent(INDENT);
s << INDENT << enclosingObjectVariable << ", \"" << mangleName(enumValue->name()) << "\", ";
- s << enumValueText << "))" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << enumValueText << "))\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
break;
case EnumClass: {
s << INDENT << "if (!Shiboken::Enum::createScopedEnumItem("
- << enumVarTypeObj << ',' << endl;
+ << enumVarTypeObj << ',' << Qt::endl;
Indentation indent(INDENT);
s << INDENT << enumVarTypeObj<< ", \"" << mangleName(enumValue->name()) << "\", "
- << enumValueText << "))" << endl
- << INDENT << returnStatement(m_currentErrorCode) << endl;
+ << enumValueText << "))\n"
+ << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
break;
}
@@ -4749,7 +4742,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu
s << INDENT << "// End of '" << cppEnum->name() << "' enum";
if (cppEnum->typeEntry()->flags())
s << "/flags";
- s << '.' << endl << endl;
+ s << '.' << Qt::endl << Qt::endl;
}
void CppGenerator::writeSignalInitialization(QTextStream &s, const AbstractMetaClass *metaClass)
@@ -4775,7 +4768,7 @@ void CppGenerator::writeSignalInitialization(QTextStream &s, const AbstractMetaC
}
s << INDENT << "PySide::Signal::registerSignals(" << cpythonTypeName(metaClass) << ", &::"
- << metaClass->qualifiedCppName() << "::staticMetaObject);" << endl;
+ << metaClass->qualifiedCppName() << "::staticMetaObject);\n";
}
void CppGenerator::writeFlagsToLong(QTextStream &s, const AbstractMetaEnum *cppEnum)
@@ -4783,13 +4776,13 @@ void CppGenerator::writeFlagsToLong(QTextStream &s, const AbstractMetaEnum *cppE
FlagsTypeEntry *flagsEntry = cppEnum->typeEntry()->flags();
if (!flagsEntry)
return;
- s << "static PyObject *" << cpythonEnumName(cppEnum) << "_long(PyObject *self)" << endl;
- s << "{" << endl;
- s << INDENT << "int val;" << endl;
+ s << "static PyObject *" << cpythonEnumName(cppEnum) << "_long(PyObject *self)\n";
+ s << "{\n";
+ s << INDENT << "int val;\n";
AbstractMetaType *flagsType = buildAbstractMetaTypeFromTypeEntry(flagsEntry);
- s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &val);" << endl;
- s << INDENT << "return Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &val);" << endl;
- s << "}" << endl;
+ s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &val);\n";
+ s << INDENT << "return Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<int>(), &val);\n";
+ s << "}\n";
}
void CppGenerator::writeFlagsNonZero(QTextStream &s, const AbstractMetaEnum *cppEnum)
@@ -4797,14 +4790,14 @@ void CppGenerator::writeFlagsNonZero(QTextStream &s, const AbstractMetaEnum *cpp
FlagsTypeEntry *flagsEntry = cppEnum->typeEntry()->flags();
if (!flagsEntry)
return;
- s << "static int " << cpythonEnumName(cppEnum) << "__nonzero(PyObject *self)" << endl;
- s << "{" << endl;
+ s << "static int " << cpythonEnumName(cppEnum) << "__nonzero(PyObject *self)\n";
+ s << "{\n";
- s << INDENT << "int val;" << endl;
+ s << INDENT << "int val;\n";
AbstractMetaType *flagsType = buildAbstractMetaTypeFromTypeEntry(flagsEntry);
- s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &val);" << endl;
- s << INDENT << "return val != 0;" << endl;
- s << "}" << endl;
+ s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &val);\n";
+ s << INDENT << "return val != 0;\n";
+ s << "}\n";
}
void CppGenerator::writeFlagsMethods(QTextStream &s, const AbstractMetaEnum *cppEnum)
@@ -4817,30 +4810,30 @@ void CppGenerator::writeFlagsMethods(QTextStream &s, const AbstractMetaEnum *cpp
writeFlagsToLong(s, cppEnum);
writeFlagsNonZero(s, cppEnum);
- s << endl;
+ s << Qt::endl;
}
void CppGenerator::writeFlagsNumberMethodsDefinition(QTextStream &s, const AbstractMetaEnum *cppEnum)
{
QString cpythonName = cpythonEnumName(cppEnum);
- s << "static PyType_Slot " << cpythonName << "_number_slots[] = {" << endl;
- s << "#ifdef IS_PY3K" << endl;
- s << INDENT << "{Py_nb_bool, (void *)" << cpythonName << "__nonzero}," << endl;
- s << "#else" << endl;
- s << INDENT << "{Py_nb_nonzero, (void *)" << cpythonName << "__nonzero}," << endl;
- s << INDENT << "{Py_nb_long, (void *)" << cpythonName << "_long}," << endl;
- s << "#endif" << endl;
- s << INDENT << "{Py_nb_invert, (void *)" << cpythonName << "___invert__}," << endl;
- s << INDENT << "{Py_nb_and, (void *)" << cpythonName << "___and__}," << endl;
- s << INDENT << "{Py_nb_xor, (void *)" << cpythonName << "___xor__}," << endl;
- s << INDENT << "{Py_nb_or, (void *)" << cpythonName << "___or__}," << endl;
- s << INDENT << "{Py_nb_int, (void *)" << cpythonName << "_long}," << endl;
- s << "#ifndef IS_PY3K" << endl;
- s << INDENT << "{Py_nb_long, (void *)" << cpythonName << "_long}," << endl;
- s << "#endif" << endl;
- s << INDENT << "{0, " << NULL_PTR << "} // sentinel" << endl;
- s << "};" << endl << endl;
+ s << "static PyType_Slot " << cpythonName << "_number_slots[] = {\n";
+ s << "#ifdef IS_PY3K\n";
+ s << INDENT << "{Py_nb_bool, (void *)" << cpythonName << "__nonzero},\n";
+ s << "#else\n";
+ s << INDENT << "{Py_nb_nonzero, (void *)" << cpythonName << "__nonzero},\n";
+ s << INDENT << "{Py_nb_long, (void *)" << cpythonName << "_long},\n";
+ s << "#endif\n";
+ s << INDENT << "{Py_nb_invert, (void *)" << cpythonName << "___invert__},\n";
+ s << INDENT << "{Py_nb_and, (void *)" << cpythonName << "___and__},\n";
+ s << INDENT << "{Py_nb_xor, (void *)" << cpythonName << "___xor__},\n";
+ s << INDENT << "{Py_nb_or, (void *)" << cpythonName << "___or__},\n";
+ s << INDENT << "{Py_nb_int, (void *)" << cpythonName << "_long},\n";
+ s << "#ifndef IS_PY3K\n";
+ s << INDENT << "{Py_nb_long, (void *)" << cpythonName << "_long},\n";
+ s << "#endif\n";
+ s << INDENT << "{0, " << NULL_PTR << "} // sentinel\n";
+ s << "};\n\n";
}
void CppGenerator::writeFlagsBinaryOperator(QTextStream &s, const AbstractMetaEnum *cppEnum,
@@ -4849,27 +4842,27 @@ void CppGenerator::writeFlagsBinaryOperator(QTextStream &s, const AbstractMetaEn
FlagsTypeEntry *flagsEntry = cppEnum->typeEntry()->flags();
Q_ASSERT(flagsEntry);
- s << "PyObject * " << cpythonEnumName(cppEnum) << "___" << pyOpName << "__(PyObject *self, PyObject *" << PYTHON_ARG << ")" << endl;
- s << '{' << endl;
+ s << "PyObject * " << cpythonEnumName(cppEnum) << "___" << pyOpName
+ << "__(PyObject *self, PyObject *" << PYTHON_ARG << ")\n{\n";
AbstractMetaType *flagsType = buildAbstractMetaTypeFromTypeEntry(flagsEntry);
- s << INDENT << "::" << flagsEntry->originalName() << " cppResult, " << CPP_SELF_VAR << ", cppArg;" << endl;
- s << "#ifdef IS_PY3K" << endl;
+ s << INDENT << "::" << flagsEntry->originalName() << " cppResult, " << CPP_SELF_VAR << ", cppArg;\n";
+ s << "#ifdef IS_PY3K\n";
s << INDENT << CPP_SELF_VAR << " = static_cast<::" << flagsEntry->originalName()
- << ">(int(PyLong_AsLong(self)));" << endl;
+ << ">(int(PyLong_AsLong(self)));\n";
s << INDENT << "cppArg = static_cast<" << flagsEntry->originalName() << ">(int(PyLong_AsLong("
- << PYTHON_ARG << ")));" << endl;
- s << "#else" << endl;
+ << PYTHON_ARG << ")));\n";
+ s << "#else\n";
s << INDENT << CPP_SELF_VAR << " = static_cast<::" << flagsEntry->originalName()
- << ">(int(PyInt_AsLong(self)));" << endl;
+ << ">(int(PyInt_AsLong(self)));\n";
s << INDENT << "cppArg = static_cast<" << flagsEntry->originalName()
- << ">(int(PyInt_AsLong(" << PYTHON_ARG << ")));" << endl;
- s << "#endif" << endl << endl;
- s << INDENT << "cppResult = " << CPP_SELF_VAR << " " << cppOpName << " cppArg;" << endl;
+ << ">(int(PyInt_AsLong(" << PYTHON_ARG << ")));\n";
+ s << "#endif\n\n";
+ s << INDENT << "cppResult = " << CPP_SELF_VAR << " " << cppOpName << " cppArg;\n";
s << INDENT << "return ";
writeToPythonConversion(s, flagsType, nullptr, QLatin1String("cppResult"));
- s << ';' << endl;
- s << '}' << endl << endl;
+ s << ";\n";
+ s<< "}\n\n";
}
void CppGenerator::writeFlagsUnaryOperator(QTextStream &s, const AbstractMetaEnum *cppEnum,
@@ -4879,25 +4872,25 @@ void CppGenerator::writeFlagsUnaryOperator(QTextStream &s, const AbstractMetaEnu
FlagsTypeEntry *flagsEntry = cppEnum->typeEntry()->flags();
Q_ASSERT(flagsEntry);
- s << "PyObject *" << cpythonEnumName(cppEnum) << "___" << pyOpName << "__(PyObject *self, PyObject *" << PYTHON_ARG << ")" << endl;
- s << '{' << endl;
+ s << "PyObject *" << cpythonEnumName(cppEnum) << "___" << pyOpName
+ << "__(PyObject *self, PyObject *" << PYTHON_ARG << ")\n{\n";
AbstractMetaType *flagsType = buildAbstractMetaTypeFromTypeEntry(flagsEntry);
- s << INDENT << "::" << flagsEntry->originalName() << " " << CPP_SELF_VAR << ";" << endl;
- s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &" << CPP_SELF_VAR << ");" << endl;
+ s << INDENT << "::" << flagsEntry->originalName() << " " << CPP_SELF_VAR << ";\n";
+ s << INDENT << cpythonToCppConversionFunction(flagsType) << "self, &" << CPP_SELF_VAR << ");\n";
s << INDENT;
if (boolResult)
s << "bool";
else
s << "::" << flagsEntry->originalName();
- s << " cppResult = " << cppOpName << CPP_SELF_VAR << ';' << endl;
+ s << " cppResult = " << cppOpName << CPP_SELF_VAR << ";\n";
s << INDENT << "return ";
if (boolResult)
s << "PyBool_FromLong(cppResult)";
else
writeToPythonConversion(s, flagsType, nullptr, QLatin1String("cppResult"));
- s << ';' << endl;
- s << '}' << endl << endl;
+ s << ";\n";
+ s<< "}\n\n";
}
QString CppGenerator::getSimpleClassInitFunctionName(const AbstractMetaClass *metaClass) const
@@ -4925,50 +4918,48 @@ void CppGenerator::writeClassRegister(QTextStream &s,
{
const ComplexTypeEntry *classTypeEntry = metaClass->typeEntry();
- const AbstractMetaClass *enc = metaClass->enclosingClass();
- bool hasEnclosingClass = enc && enc->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass;
- QString enclosingObjectVariable = hasEnclosingClass ? QLatin1String("enclosingClass") : QLatin1String("module");
+ const AbstractMetaClass *enc = metaClass->targetLangEnclosingClass();
+ QString enclosingObjectVariable = enc ? QLatin1String("enclosingClass") : QLatin1String("module");
QString pyTypeName = cpythonTypeName(metaClass);
QString initFunctionName = getInitFunctionName(classContext);
// PYSIDE-510: Create a signatures string for the introspection feature.
- s << "// The signatures string for the functions." << endl;
- s << "// Multiple signatures have their index \"n:\" in front." << endl;
- s << "static const char *" << initFunctionName << "_SignatureStrings[] = {" << endl;
+ s << "// The signatures string for the functions.\n";
+ s << "// Multiple signatures have their index \"n:\" in front.\n";
+ s << "static const char *" << initFunctionName << "_SignatureStrings[] = {\n";
QString line;
while (signatureStream.readLineInto(&line))
- s << INDENT << '"' << line << "\"," << endl;
- s << INDENT << NULL_PTR << "}; // Sentinel" << endl << endl;
+ s << INDENT << '"' << line << "\",\n";
+ s << INDENT << NULL_PTR << "}; // Sentinel\n\n";
s << "void init_" << initFunctionName;
- s << "(PyObject *" << enclosingObjectVariable << ")" << endl;
- s << '{' << endl;
+ s << "(PyObject *" << enclosingObjectVariable << ")\n{\n";
// Multiple inheritance
QString pyTypeBasesVariable = chopType(pyTypeName) + QLatin1String("_Type_bases");
const AbstractMetaClassList baseClasses = getBaseClasses(metaClass);
if (metaClass->baseClassNames().size() > 1) {
s << INDENT << "PyObject *" << pyTypeBasesVariable
- << " = PyTuple_Pack(" << baseClasses.size() << ',' << endl;
+ << " = PyTuple_Pack(" << baseClasses.size() << ',' << Qt::endl;
Indentation indent(INDENT);
for (int i = 0, size = baseClasses.size(); i < size; ++i) {
if (i)
- s << "," << endl;
+ s << ",\n";
s << INDENT << "reinterpret_cast<PyObject *>("
<< cpythonTypeNameExt(baseClasses.at(i)->typeEntry()) << ')';
}
- s << ");" << endl << endl;
+ s << ");\n\n";
}
// Create type and insert it in the module or enclosing class.
const QString typePtr = QLatin1String("_") + chopType(pyTypeName)
+ QLatin1String("_Type");
- s << INDENT << typePtr << " = Shiboken::ObjectType::introduceWrapperType(" << endl;
+ s << INDENT << typePtr << " = Shiboken::ObjectType::introduceWrapperType(\n";
{
Indentation indent(INDENT);
// 1:enclosingObject
- s << INDENT << enclosingObjectVariable << "," << endl;
+ s << INDENT << enclosingObjectVariable << ",\n";
QString typeName;
if (!classContext.forSmartPointer())
typeName = metaClass->name();
@@ -4976,7 +4967,7 @@ void CppGenerator::writeClassRegister(QTextStream &s,
typeName = classContext.preciseType()->cppSignature();
// 2:typeName
- s << INDENT << "\"" << typeName << "\"," << endl;
+ s << INDENT << "\"" << typeName << "\",\n";
// 3:originalName
s << INDENT << "\"";
@@ -4988,12 +4979,12 @@ void CppGenerator::writeClassRegister(QTextStream &s,
s << classContext.preciseType()->cppSignature();
}
- s << "\"," << endl;
+ s << "\",\n";
// 4:typeSpec
- s << INDENT << '&' << chopType(pyTypeName) << "_spec," << endl;
+ s << INDENT << '&' << chopType(pyTypeName) << "_spec,\n";
// 5:signatureStrings
- s << INDENT << initFunctionName << "_SignatureStrings," << endl;
+ s << INDENT << initFunctionName << "_SignatureStrings,\n";
// 6:cppObjDtor
s << INDENT;
@@ -5004,9 +4995,9 @@ void CppGenerator::writeClassRegister(QTextStream &s,
if (classContext.forSmartPointer())
dtorClassName = wrapperName(classContext.preciseType());
- s << "&Shiboken::callCppDestructor< ::" << dtorClassName << " >," << endl;
+ s << "&Shiboken::callCppDestructor< ::" << dtorClassName << " >,\n";
} else {
- s << "0," << endl;
+ s << "0,\n";
}
// 7:baseType
@@ -5014,20 +5005,20 @@ void CppGenerator::writeClassRegister(QTextStream &s,
? metaClass->extendedNamespace() : metaClass->baseClass();
if (base) {
s << INDENT << "reinterpret_cast<SbkObjectType *>("
- << cpythonTypeNameExt(base->typeEntry()) << ")," << endl;
+ << cpythonTypeNameExt(base->typeEntry()) << "),\n";
} else {
- s << INDENT << "0," << endl;
+ s << INDENT << "0,\n";
}
// 8:baseTypes
if (metaClass->baseClassNames().size() > 1)
- s << INDENT << pyTypeBasesVariable << ',' << endl;
+ s << INDENT << pyTypeBasesVariable << ',' << Qt::endl;
else
- s << INDENT << "0," << endl;
+ s << INDENT << "0,\n";
// 9:wrapperflags
QByteArrayList wrapperFlags;
- if (hasEnclosingClass)
+ if (enc)
wrapperFlags.append(QByteArrayLiteral("Shiboken::ObjectType::WrapperFlags::InnerClass"));
if (metaClass->deleteInMainThread())
wrapperFlags.append(QByteArrayLiteral("Shiboken::ObjectType::WrapperFlags::DeleteInMainThread"));
@@ -5036,24 +5027,24 @@ void CppGenerator::writeClassRegister(QTextStream &s,
else
s << INDENT << wrapperFlags.join(" | ");
}
- s << INDENT << ");" << endl;
- s << INDENT << endl;
+ s << INDENT << ");\n";
+ s << INDENT << Qt::endl;
if (!classContext.forSmartPointer())
- s << INDENT << cpythonTypeNameExt(classTypeEntry) << endl;
+ s << INDENT << cpythonTypeNameExt(classTypeEntry) << Qt::endl;
else
- s << INDENT << cpythonTypeNameExt(classContext.preciseType()) << endl;
- s << INDENT << " = reinterpret_cast<PyTypeObject *>(" << pyTypeName << ");" << endl;
- s << endl;
+ s << INDENT << cpythonTypeNameExt(classContext.preciseType()) << Qt::endl;
+ s << INDENT << " = reinterpret_cast<PyTypeObject *>(" << pyTypeName << ");\n";
+ s << Qt::endl;
// Register conversions for the type.
writeConverterRegister(s, metaClass, classContext);
- s << endl;
+ s << Qt::endl;
// class inject-code target/beginning
if (!classTypeEntry->codeSnips().isEmpty()) {
writeCodeSnips(s, classTypeEntry->codeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode, metaClass);
- s << endl;
+ s << Qt::endl;
}
// Fill multiple inheritance data, if needed.
@@ -5061,21 +5052,21 @@ void CppGenerator::writeClassRegister(QTextStream &s,
if (miClass) {
s << INDENT << "MultipleInheritanceInitFunction func = ";
if (miClass == metaClass) {
- s << multipleInheritanceInitializerFunctionName(miClass) << ";" << endl;
+ s << multipleInheritanceInitializerFunctionName(miClass) << ";\n";
} else {
s << "Shiboken::ObjectType::getMultipleInheritanceFunction(reinterpret_cast<SbkObjectType *>(";
- s << cpythonTypeNameExt(miClass->typeEntry()) << "));" << endl;
+ s << cpythonTypeNameExt(miClass->typeEntry()) << "));\n";
}
s << INDENT << "Shiboken::ObjectType::setMultipleInheritanceFunction(";
- s << cpythonTypeName(metaClass) << ", func);" << endl;
+ s << cpythonTypeName(metaClass) << ", func);\n";
s << INDENT << "Shiboken::ObjectType::setCastFunction(" << cpythonTypeName(metaClass);
- s << ", &" << cpythonSpecialCastFunctionName(metaClass) << ");" << endl;
+ s << ", &" << cpythonSpecialCastFunctionName(metaClass) << ");\n";
}
// Set typediscovery struct or fill the struct of another one
if (metaClass->isPolymorphic() && metaClass->baseClass()) {
s << INDENT << "Shiboken::ObjectType::setTypeDiscoveryFunctionV2(" << cpythonTypeName(metaClass);
- s << ", &" << cpythonBaseName(metaClass) << "_typeDiscovery);" << endl << endl;
+ s << ", &" << cpythonBaseName(metaClass) << "_typeDiscovery);\n\n";
}
AbstractMetaEnumList classEnums = metaClass->enums();
@@ -5097,13 +5088,13 @@ void CppGenerator::writeClassRegister(QTextStream &s,
s << INDENT << QLatin1String("PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(") + cpythonTypeName(metaClass) + QLatin1String(")->tp_dict, \"");
s << field->name() << "\", ";
writeToPythonConversion(s, field->type(), metaClass, metaClass->qualifiedCppName() + QLatin1String("::") + field->name());
- s << ");" << endl;
+ s << ");\n";
}
- s << endl;
+ s << Qt::endl;
// class inject-code target/end
if (!classTypeEntry->codeSnips().isEmpty()) {
- s << endl;
+ s << Qt::endl;
writeCodeSnips(s, classTypeEntry->codeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode, metaClass);
}
@@ -5115,12 +5106,12 @@ void CppGenerator::writeClassRegister(QTextStream &s,
}
if (usePySideExtensions() && metaClass->isQObject()) {
- s << INDENT << "Shiboken::ObjectType::setSubTypeInitHook(" << pyTypeName << ", &PySide::initQObjectSubType);" << endl;
+ s << INDENT << "Shiboken::ObjectType::setSubTypeInitHook(" << pyTypeName << ", &PySide::initQObjectSubType);\n";
s << INDENT << "PySide::initDynamicMetaObject(" << pyTypeName << ", &::" << metaClass->qualifiedCppName()
- << "::staticMetaObject, sizeof(::" << metaClass->qualifiedCppName() << "));" << endl;
+ << "::staticMetaObject, sizeof(::" << metaClass->qualifiedCppName() << "));\n";
}
- s << '}' << endl;
+ s << "}\n";
}
void CppGenerator::writeInitQtMetaTypeFunctionBody(QTextStream &s, GeneratorContext &context) const
@@ -5170,7 +5161,7 @@ void CppGenerator::writeInitQtMetaTypeFunctionBody(QTextStream &s, GeneratorCont
.arg(QFile::decodeName(__FILE__)).arg(__LINE__);
continue;
}
- s << INDENT << "qRegisterMetaType< ::" << className << " >(\"" << name << "\");" << endl;
+ s << INDENT << "qRegisterMetaType< ::" << className << " >(\"" << name << "\");\n";
}
}
}
@@ -5179,11 +5170,11 @@ void CppGenerator::writeInitQtMetaTypeFunctionBody(QTextStream &s, GeneratorCont
for (AbstractMetaEnum *metaEnum : enums) {
if (!metaEnum->isPrivate() && !metaEnum->isAnonymous()) {
for (const QString &name : qAsConst(nameVariants))
- s << INDENT << "qRegisterMetaType< ::" << metaEnum->typeEntry()->qualifiedCppName() << " >(\"" << name << "::" << metaEnum->name() << "\");" << endl;
+ s << INDENT << "qRegisterMetaType< ::" << metaEnum->typeEntry()->qualifiedCppName() << " >(\"" << name << "::" << metaEnum->name() << "\");\n";
if (metaEnum->typeEntry()->flags()) {
QString n = metaEnum->typeEntry()->flags()->originalName();
- s << INDENT << "qRegisterMetaType< ::" << n << " >(\"" << n << "\");" << endl;
+ s << INDENT << "qRegisterMetaType< ::" << n << " >(\"" << n << "\");\n";
}
}
}
@@ -5193,17 +5184,17 @@ void CppGenerator::writeTypeDiscoveryFunction(QTextStream &s, const AbstractMeta
{
QString polymorphicExpr = metaClass->typeEntry()->polymorphicIdValue();
- s << "static void *" << cpythonBaseName(metaClass) << "_typeDiscovery(void *cptr, SbkObjectType *instanceType)\n{" << endl;
+ s << "static void *" << cpythonBaseName(metaClass) << "_typeDiscovery(void *cptr, SbkObjectType *instanceType)\n{\n";
if (!polymorphicExpr.isEmpty()) {
polymorphicExpr = polymorphicExpr.replace(QLatin1String("%1"),
QLatin1String(" reinterpret_cast< ::")
+ metaClass->qualifiedCppName()
+ QLatin1String(" *>(cptr)"));
- s << INDENT << " if (" << polymorphicExpr << ")" << endl;
+ s << INDENT << " if (" << polymorphicExpr << ")\n";
{
Indentation indent(INDENT);
- s << INDENT << "return cptr;" << endl;
+ s << INDENT << "return cptr;\n";
}
} else if (metaClass->isPolymorphic()) {
const AbstractMetaClassList &ancestors = getAllAncestors(metaClass);
@@ -5212,10 +5203,10 @@ void CppGenerator::writeTypeDiscoveryFunction(QTextStream &s, const AbstractMeta
continue;
if (ancestor->isPolymorphic()) {
s << INDENT << "if (instanceType == reinterpret_cast<SbkObjectType *>(Shiboken::SbkType< ::"
- << ancestor->qualifiedCppName() << " >()))" << endl;
+ << ancestor->qualifiedCppName() << " >()))\n";
Indentation indent(INDENT);
s << INDENT << "return dynamic_cast< ::" << metaClass->qualifiedCppName()
- << " *>(reinterpret_cast< ::"<< ancestor->qualifiedCppName() << " *>(cptr));" << endl;
+ << " *>(reinterpret_cast< ::"<< ancestor->qualifiedCppName() << " *>(cptr));\n";
} else {
qCWarning(lcShiboken).noquote().nospace()
<< metaClass->qualifiedCppName() << " inherits from a non polymorphic type ("
@@ -5225,7 +5216,7 @@ void CppGenerator::writeTypeDiscoveryFunction(QTextStream &s, const AbstractMeta
}
}
- s << INDENT << "return {};" << endl;
+ s << INDENT << "return {};\n";
s << "}\n\n";
}
@@ -5238,37 +5229,37 @@ QString CppGenerator::writeSmartPointerGetterCast()
void CppGenerator::writeSetattroFunction(QTextStream &s, GeneratorContext &context)
{
const AbstractMetaClass *metaClass = context.metaClass();
- s << "static int " << cpythonSetattroFunctionName(metaClass) << "(PyObject *self, PyObject *name, PyObject *value)" << endl;
- s << '{' << endl;
+ s << "static int " << cpythonSetattroFunctionName(metaClass)
+ << "(PyObject *self, PyObject *name, PyObject *value)\n{\n";
if (usePySideExtensions()) {
- s << INDENT << "Shiboken::AutoDecRef pp(reinterpret_cast<PyObject *>(PySide::Property::getObject(self, name)));" << endl;
- s << INDENT << "if (!pp.isNull())" << endl;
+ s << INDENT << "Shiboken::AutoDecRef pp(reinterpret_cast<PyObject *>(PySide::Property::getObject(self, name)));\n";
+ s << INDENT << "if (!pp.isNull())\n";
Indentation indent(INDENT);
- s << INDENT << "return PySide::Property::setValue(reinterpret_cast<PySideProperty *>(pp.object()), self, value);" << endl;
+ s << INDENT << "return PySide::Property::setValue(reinterpret_cast<PySideProperty *>(pp.object()), self, value);\n";
}
if (context.forSmartPointer()) {
- s << INDENT << "// Try to find the 'name' attribute, by retrieving the PyObject for the corresponding C++ object held by the smart pointer." << endl;
+ s << INDENT << "// Try to find the 'name' attribute, by retrieving the PyObject for the corresponding C++ object held by the smart pointer.\n";
s << INDENT << "PyObject *rawObj = PyObject_CallMethod(self, "
- << writeSmartPointerGetterCast() << ", 0);" << endl;
- s << INDENT << "if (rawObj) {" << endl;
+ << writeSmartPointerGetterCast() << ", 0);\n";
+ s << INDENT << "if (rawObj) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "int hasAttribute = PyObject_HasAttr(rawObj, name);" << endl;
- s << INDENT << "if (hasAttribute) {" << endl;
+ s << INDENT << "int hasAttribute = PyObject_HasAttr(rawObj, name);\n";
+ s << INDENT << "if (hasAttribute) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "return PyObject_GenericSetAttr(rawObj, name, value);" << endl;
+ s << INDENT << "return PyObject_GenericSetAttr(rawObj, name, value);\n";
}
- s << INDENT << '}' << endl;
- s << INDENT << "Py_DECREF(rawObj);" << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "Py_DECREF(rawObj);\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
- s << INDENT << "return PyObject_GenericSetAttr(self, name, value);" << endl;
- s << '}' << endl;
+ s << INDENT << "return PyObject_GenericSetAttr(self, name, value);\n";
+ s << "}\n";
}
static inline QString qObjectClassName() { return QStringLiteral("QObject"); }
@@ -5277,8 +5268,9 @@ static inline QString qMetaObjectClassName() { return QStringLiteral("QMetaObjec
void CppGenerator::writeGetattroFunction(QTextStream &s, GeneratorContext &context)
{
const AbstractMetaClass *metaClass = context.metaClass();
- s << "static PyObject *" << cpythonGetattroFunctionName(metaClass) << "(PyObject *self, PyObject *name)" << endl;
- s << '{' << endl;
+ s << "static PyObject *" << cpythonGetattroFunctionName(metaClass)
+ << "(PyObject *self, PyObject *name)\n{\n";
+ s << INDENT << "assert(self);\n";
QString getattrFunc;
if (usePySideExtensions() && metaClass->isQObject()) {
@@ -5287,116 +5279,118 @@ void CppGenerator::writeGetattroFunction(QTextStream &s, GeneratorContext &conte
<< cpythonWrapperCPtr(qobjectClass, QLatin1String("self"))
<< ", self, name)";
} else {
- getattrFunc = QLatin1String("PyObject_GenericGetAttr(") + QLatin1String("self")
- + QLatin1String(", name)");
+ getattrFunc = QLatin1String("PyObject_GenericGetAttr(self, name)");
}
if (classNeedsGetattroFunction(metaClass)) {
- s << INDENT << "if (self) {" << endl;
+ s << INDENT << "// Search the method in the instance dict\n";
+ s << INDENT << "if (auto ob_dict = reinterpret_cast<SbkObject *>(self)->ob_dict) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "// Search the method in the instance dict" << endl;
- s << INDENT << "if (reinterpret_cast<SbkObject *>(self)->ob_dict) {" << endl;
+ s << INDENT << "if (auto meth = PyDict_GetItem(ob_dict, name)) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyObject *meth = PyDict_GetItem(reinterpret_cast<SbkObject *>(self)->ob_dict, name);" << endl;
- s << INDENT << "if (meth) {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "Py_INCREF(meth);" << endl;
- s << INDENT << "return meth;" << endl;
- }
- s << INDENT << '}' << endl;
+ s << INDENT << "Py_INCREF(meth);\n";
+ s << INDENT << "return meth;\n";
}
- s << INDENT << '}' << endl;
- s << INDENT << "// Search the method in the type dict" << endl;
- s << INDENT << "if (Shiboken::Object::isUserType(self)) {" << endl;
+ s << INDENT << "}\n";
+ }
+ s << INDENT << "}\n";
+ s << INDENT << "// Search the method in the type dict\n";
+ s << INDENT << "if (Shiboken::Object::isUserType(self)) {\n";
+ {
+ Indentation indent(INDENT);
+ // PYSIDE-772: Perform optimized name mangling.
+ s << INDENT << "Shiboken::AutoDecRef tmp(_Pep_PrivateMangle(self, name));\n";
+ s << INDENT << "if (auto meth = PyDict_GetItem(Py_TYPE(self)->tp_dict, tmp))\n";
{
Indentation indent(INDENT);
- // PYSIDE-772: Perform optimized name mangling.
- s << INDENT << "Shiboken::AutoDecRef tmp(_Pep_PrivateMangle(self, name));" << endl;
- s << INDENT << "PyObject *meth = PyDict_GetItem(Py_TYPE(self)->tp_dict, tmp);" << endl;
- s << INDENT << "if (meth)" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "return PyFunction_Check(meth) ? SBK_PyMethod_New(meth, self) : " << getattrFunc << ';' << endl;
- }
+ s << INDENT << "return PyFunction_Check(meth) ? SBK_PyMethod_New(meth, self) : " << getattrFunc << ";\n";
}
- s << INDENT << '}' << endl;
+ }
+ s << INDENT << "}\n";
- const AbstractMetaFunctionList &funcs = getMethodsWithBothStaticAndNonStaticMethods(metaClass);
- for (const AbstractMetaFunction *func : funcs) {
- QString defName = cpythonMethodDefinitionName(func);
- s << INDENT << "static PyMethodDef non_static_" << defName << " = {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << defName << ".ml_name," << endl;
- s << INDENT << defName << ".ml_meth," << endl;
- s << INDENT << defName << ".ml_flags & (~METH_STATIC)," << endl;
- s << INDENT << defName << ".ml_doc," << endl;
- }
- s << INDENT << "};" << endl;
- s << INDENT << "if (Shiboken::String::compare(name, \"" << func->name() << "\") == 0)" << endl;
+ const AbstractMetaFunctionList &funcs = getMethodsWithBothStaticAndNonStaticMethods(metaClass);
+ for (const AbstractMetaFunction *func : funcs) {
+ QString defName = cpythonMethodDefinitionName(func);
+ s << INDENT << "static PyMethodDef non_static_" << defName << " = {\n";
+ {
Indentation indent(INDENT);
- s << INDENT << "return PyCFunction_NewEx(&non_static_" << defName << ", self, 0);" << endl;
+ s << INDENT << defName << ".ml_name,\n";
+ s << INDENT << defName << ".ml_meth,\n";
+ s << INDENT << defName << ".ml_flags & (~METH_STATIC),\n";
+ s << INDENT << defName << ".ml_doc,\n";
}
+ s << INDENT << "};\n";
+ s << INDENT << "if (Shiboken::String::compare(name, \"" << func->name() << "\") == 0)\n";
+ Indentation indent(INDENT);
+ s << INDENT << "return PyCFunction_NewEx(&non_static_" << defName << ", self, 0);\n";
}
- s << INDENT << '}' << endl;
}
if (context.forSmartPointer()) {
- s << INDENT << "PyObject *tmp = " << getattrFunc << ';' << endl;
- s << INDENT << "if (tmp) {" << endl;
+ s << INDENT << "PyObject *tmp = " << getattrFunc << ";\n";
+ s << INDENT << "if (tmp)\n";
{
Indentation indent(INDENT);
- s << INDENT << "return tmp;" << endl;
+ s << INDENT << "return tmp;\n";
}
- s << INDENT << "} else {" << endl;
+ s << INDENT << "if (!PyErr_ExceptionMatches(PyExc_AttributeError))\n";
{
Indentation indent(INDENT);
- s << INDENT << "if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return nullptr;" << endl;
- s << INDENT << "PyErr_Clear();" << endl;
-
- s << INDENT << "// Try to find the 'name' attribute, by retrieving the PyObject for "
- "the corresponding C++ object held by the smart pointer." << endl;
- s << INDENT << "PyObject *rawObj = PyObject_CallMethod(self, "
- << writeSmartPointerGetterCast() << ", 0);" << endl;
- s << INDENT << "if (rawObj) {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "PyObject *attribute = PyObject_GetAttr(rawObj, name);" << endl;
- s << INDENT << "if (attribute) {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "tmp = attribute;" << endl;
- }
- s << INDENT << '}' << endl;
- s << INDENT << "Py_DECREF(rawObj);" << endl;
- }
- s << INDENT << '}' << endl;
- s << INDENT << "if (!tmp) {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "PyTypeObject *tp = Py_TYPE(self);" << endl;
- s << INDENT << "PyErr_Format(PyExc_AttributeError," << endl;
- s << INDENT << " \"'%.50s' object has no attribute '%.400s'\"," << endl;
- s << INDENT << " tp->tp_name, Shiboken::String::toCString(name));" << endl;
- s << INDENT << "return nullptr;" << endl;
- }
- s << INDENT << "} else {" << endl;
+ s << INDENT << "return nullptr;\n";
+ }
+ s << INDENT << "PyErr_Clear();\n";
+
+ // This generates the code which dispatches access to member functions
+ // and fields from the smart pointer to its pointee.
+ s << INDENT << "// Try to find the 'name' attribute, by retrieving the PyObject for "
+ "the corresponding C++ object held by the smart pointer.\n";
+ s << INDENT << "if (auto rawObj = PyObject_CallMethod(self, "
+ << writeSmartPointerGetterCast() << ", 0)) {\n";
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "if (auto attribute = PyObject_GetAttr(rawObj, name))\n";
{
Indentation indent(INDENT);
- s << INDENT << "return tmp;" << endl;
+ s << INDENT << "tmp = attribute;\n";
}
- s << INDENT << '}' << endl;
-
+ s << INDENT << "Py_DECREF(rawObj);\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
+ s << INDENT << "if (!tmp) {\n";
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "PyTypeObject *tp = Py_TYPE(self);\n";
+ s << INDENT << "PyErr_Format(PyExc_AttributeError,\n";
+ s << INDENT << " \"'%.50s' object has no attribute '%.400s'\",\n";
+ s << INDENT << " tp->tp_name, Shiboken::String::toCString(name));\n";
+ }
+ s << INDENT << "}\n";
+ s << INDENT << "return tmp;\n";
+ } else {
+ s << INDENT << "return " << getattrFunc << ";\n";
+ }
+ s << "}\n";
+}
+// Write declaration and invocation of the init function for the module init
+// function.
+void CppGenerator::writeInitFunc(QTextStream &declStr, QTextStream &callStr,
+ const Indentor &indent, const QString &initFunctionName,
+ const TypeEntry *enclosingEntry)
+{
+ const bool hasParent =
+ enclosingEntry && enclosingEntry->type() != TypeEntry::TypeSystemType;
+ declStr << "void init_" << initFunctionName << "(PyObject *"
+ << (hasParent ? "enclosingClass" : "module") << ");\n";
+ callStr << indent << "init_" << initFunctionName;
+ if (hasParent) {
+ callStr << "(reinterpret_cast<PyTypeObject *>("
+ << cpythonTypeNameExt(enclosingEntry) << ")->tp_dict);\n";
} else {
- s << INDENT << "return " << getattrFunc << ';' << endl;
+ callStr << "(module);\n";
}
- s << '}' << endl;
}
bool CppGenerator::finishGeneration()
@@ -5453,33 +5447,20 @@ bool CppGenerator::finishGeneration()
const AbstractMetaClassList lst = classesTopologicalSorted(additionalDependencies);
for (const AbstractMetaClass *cls : lst){
- if (!shouldGenerate(cls))
- continue;
-
- const QString initFunctionName = QLatin1String("init_") + getSimpleClassInitFunctionName(cls);
-
- s_classInitDecl << "void " << initFunctionName << "(PyObject *module);" << endl;
-
- s_classPythonDefines << INDENT << initFunctionName;
- if (cls->enclosingClass()
- && (cls->enclosingClass()->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)) {
- s_classPythonDefines << "(reinterpret_cast<PyTypeObject *>("
- << cpythonTypeNameExt(cls->enclosingClass()->typeEntry()) << ")->tp_dict);";
- } else {
- s_classPythonDefines << "(module);";
+ if (shouldGenerate(cls)) {
+ writeInitFunc(s_classInitDecl, s_classPythonDefines, INDENT,
+ getSimpleClassInitFunctionName(cls),
+ cls->typeEntry()->targetLangEnclosingEntry());
}
- s_classPythonDefines << endl;
}
// Initialize smart pointer types.
const QVector<const AbstractMetaType *> &smartPtrs = instantiatedSmartPointers();
for (const AbstractMetaType *metaType : smartPtrs) {
GeneratorContext context(nullptr, metaType, true);
- QString initFunctionName = getInitFunctionName(context);
- s_classInitDecl << "void init_" << initFunctionName << "(PyObject *module);" << endl;
- QString defineStr = QLatin1String("init_") + initFunctionName;
- defineStr += QLatin1String("(module);");
- s_classPythonDefines << INDENT << defineStr << endl;
+ writeInitFunc(s_classInitDecl, s_classPythonDefines, INDENT,
+ getInitFunctionName(context),
+ metaType->typeEntry()->targetLangEnclosingEntry());
}
QString moduleFileName(outputDirectory() + QLatin1Char('/') + subDirectoryForPackage(packageName()));
@@ -5492,31 +5473,30 @@ bool CppGenerator::finishGeneration()
QTextStream &s = file.stream;
// write license comment
- s << licenseComment() << endl;
+ s << licenseComment() << Qt::endl;
- s << "#include <sbkpython.h>" << endl;
- s << "#include <shiboken.h>" << endl;
- s << "#include <algorithm>" << endl;
- s << "#include <signature.h>" << endl;
+ s << "#include <sbkpython.h>\n";
+ s << "#include <shiboken.h>\n";
+ s << "#include <algorithm>\n";
+ s << "#include <signature.h>\n";
if (usePySideExtensions()) {
s << includeQDebug;
- s << "#include <pyside.h>" << endl;
- s << "#include <qapp_macro.h>" << endl;
+ s << "#include <pyside.h>\n";
+ s << "#include <qapp_macro.h>\n";
}
- s << "#include \"" << getModuleHeaderFileName() << '"' << endl << endl;
+ s << "#include \"" << getModuleHeaderFileName() << '"' << Qt::endl << Qt::endl;
for (const Include &include : qAsConst(includes))
s << include;
- s << endl;
+ s << Qt::endl;
// Global enums
AbstractMetaEnumList globalEnums = this->globalEnums();
const AbstractMetaClassList &classList = classes();
for (const AbstractMetaClass *metaClass : classList) {
const AbstractMetaClass *encClass = metaClass->enclosingClass();
- if (encClass && encClass->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)
- continue;
- lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass);
+ if (!encClass || !NamespaceTypeEntry::isVisibleScope(encClass->typeEntry()))
+ lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass);
}
TypeDatabase *typeDb = TypeDatabase::instance();
@@ -5524,103 +5504,103 @@ bool CppGenerator::finishGeneration()
Q_ASSERT(moduleEntry);
//Extra includes
- s << endl << "// Extra includes" << endl;
+ s << Qt::endl << "// Extra includes\n";
QVector<Include> extraIncludes = moduleEntry->extraIncludes();
for (AbstractMetaEnum *cppEnum : qAsConst(globalEnums))
extraIncludes.append(cppEnum->typeEntry()->extraIncludes());
std::sort(extraIncludes.begin(), extraIncludes.end());
for (const Include &inc : qAsConst(extraIncludes))
s << inc;
- s << endl;
+ s << Qt::endl;
- s << "// Current module's type array." << endl;
- s << "PyTypeObject **" << cppApiVariableName() << " = nullptr;" << endl;
+ s << "// Current module's type array.\n";
+ s << "PyTypeObject **" << cppApiVariableName() << " = nullptr;\n";
- s << "// Current module's PyObject pointer." << endl;
- s << "PyObject *" << pythonModuleObjectName() << " = nullptr;" << endl;
+ s << "// Current module's PyObject pointer.\n";
+ s << "PyObject *" << pythonModuleObjectName() << " = nullptr;\n";
- s << "// Current module's converter array." << endl;
- s << "SbkConverter **" << convertersVariableName() << " = nullptr;" << endl;
+ s << "// Current module's converter array.\n";
+ s << "SbkConverter **" << convertersVariableName() << " = nullptr;\n";
const CodeSnipList snips = moduleEntry->codeSnips();
// module inject-code native/beginning
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode);
- s << endl;
+ s << Qt::endl;
}
// cleanup staticMetaObject attribute
if (usePySideExtensions()) {
- s << "void cleanTypesAttributes(void) {" << endl;
- s << INDENT << "if (PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03060000)" << endl;
- s << INDENT << " return; // PYSIDE-953: testbinding crashes in Python 3.5 when hasattr touches types!" << endl;
- s << INDENT << "for (int i = 0, imax = SBK_" << moduleName() << "_IDX_COUNT; i < imax; i++) {" << endl;
+ s << "void cleanTypesAttributes(void) {\n";
+ s << INDENT << "if (PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03060000)\n";
+ s << INDENT << " return; // PYSIDE-953: testbinding crashes in Python 3.5 when hasattr touches types!\n";
+ s << INDENT << "for (int i = 0, imax = SBK_" << moduleName() << "_IDX_COUNT; i < imax; i++) {\n";
{
Indentation indentation(INDENT);
- s << INDENT << "PyObject *pyType = reinterpret_cast<PyObject *>(" << cppApiVariableName() << "[i]);" << endl;
- s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"staticMetaObject\"));" << endl;
- s << INDENT << "if (pyType && PyObject_HasAttr(pyType, attrName))"<< endl;
+ s << INDENT << "PyObject *pyType = reinterpret_cast<PyObject *>(" << cppApiVariableName() << "[i]);\n";
+ s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"staticMetaObject\"));\n";
+ s << INDENT << "if (pyType && PyObject_HasAttr(pyType, attrName))\n";
{
Indentation indentation(INDENT);
- s << INDENT << "PyObject_SetAttr(pyType, attrName, Py_None);" << endl;
+ s << INDENT << "PyObject_SetAttr(pyType, attrName, Py_None);\n";
}
}
- s << INDENT << "}" << endl;
- s << "}" << endl;
+ s << INDENT << "}\n";
+ s << "}\n";
}
s << "// Global functions ";
- s << "------------------------------------------------------------" << endl;
- s << globalFunctionImpl << endl;
+ s << "------------------------------------------------------------\n";
+ s << globalFunctionImpl << Qt::endl;
- s << "static PyMethodDef " << moduleName() << "_methods[] = {" << endl;
+ s << "static PyMethodDef " << moduleName() << "_methods[] = {\n";
s << globalFunctionDecl;
- s << INDENT << "{0} // Sentinel" << endl << "};" << endl << endl;
+ s << INDENT << "{0} // Sentinel\n" << "};\n\n";
s << "// Classes initialization functions ";
- s << "------------------------------------------------------------" << endl;
- s << classInitDecl << endl;
+ s << "------------------------------------------------------------\n";
+ s << classInitDecl << Qt::endl;
if (!globalEnums.isEmpty()) {
QString converterImpl;
QTextStream convImpl(&converterImpl);
s << "// Enum definitions ";
- s << "------------------------------------------------------------" << endl;
+ s << "------------------------------------------------------------\n";
for (const AbstractMetaEnum *cppEnum : qAsConst(globalEnums)) {
if (cppEnum->isAnonymous() || cppEnum->isPrivate())
continue;
writeEnumConverterFunctions(s, cppEnum);
- s << endl;
+ s << Qt::endl;
}
if (!converterImpl.isEmpty()) {
s << "// Enum converters ";
- s << "------------------------------------------------------------" << endl;
- s << "namespace Shiboken" << endl << '{' << endl;
- s << converterImpl << endl;
- s << "} // namespace Shiboken" << endl << endl;
+ s << "------------------------------------------------------------\n";
+ s << "namespace Shiboken\n{\n";
+ s << converterImpl << Qt::endl;
+ s << "} // namespace Shiboken\n\n";
}
}
const QStringList &requiredModules = typeDb->requiredTargetImports();
if (!requiredModules.isEmpty())
- s << "// Required modules' type and converter arrays." << endl;
+ s << "// Required modules' type and converter arrays.\n";
for (const QString &requiredModule : requiredModules) {
- s << "PyTypeObject **" << cppApiVariableName(requiredModule) << ';' << endl;
- s << "SbkConverter **" << convertersVariableName(requiredModule) << ';' << endl;
+ s << "PyTypeObject **" << cppApiVariableName(requiredModule) << ";\n";
+ s << "SbkConverter **" << convertersVariableName(requiredModule) << ";\n";
}
- s << endl;
+ s << Qt::endl;
s << "// Module initialization ";
- s << "------------------------------------------------------------" << endl;
+ s << "------------------------------------------------------------\n";
ExtendedConverterData extendedConverters = getExtendedConverters();
if (!extendedConverters.isEmpty()) {
- s << endl << "// Extended Converters." << endl << endl;
+ s << Qt::endl << "// Extended Converters.\n\n";
for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) {
const TypeEntry *externalType = it.key();
- s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << endl;
+ s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << Qt::endl;
for (const AbstractMetaClass *sourceClass : it.value()) {
AbstractMetaType *sourceType = buildAbstractMetaTypeFromAbstractMetaClass(sourceClass);
AbstractMetaType *targetType = buildAbstractMetaTypeFromTypeEntry(externalType);
@@ -5631,135 +5611,135 @@ bool CppGenerator::finishGeneration()
const QVector<const CustomConversion *> &typeConversions = getPrimitiveCustomConversions();
if (!typeConversions.isEmpty()) {
- s << endl << "// Primitive Type converters." << endl << endl;
+ s << Qt::endl << "// Primitive Type converters.\n\n";
for (const CustomConversion *conversion : typeConversions) {
- s << "// C++ to Python conversion for type '" << conversion->ownerType()->qualifiedCppName() << "'." << endl;
+ s << "// C++ to Python conversion for type '" << conversion->ownerType()->qualifiedCppName() << "'.\n";
writeCppToPythonFunction(s, conversion);
writeCustomConverterFunctions(s, conversion);
}
- s << endl;
+ s << Qt::endl;
}
const QVector<const AbstractMetaType *> &containers = instantiatedContainers();
if (!containers.isEmpty()) {
- s << "// Container Type converters." << endl << endl;
+ s << "// Container Type converters.\n\n";
for (const AbstractMetaType *container : containers) {
- s << "// C++ to Python conversion for type '" << container->cppSignature() << "'." << endl;
+ s << "// C++ to Python conversion for type '" << container->cppSignature() << "'.\n";
writeContainerConverterFunctions(s, container);
}
- s << endl;
- }
-
- s << "#if defined _WIN32 || defined __CYGWIN__" << endl;
- s << " #define SBK_EXPORT_MODULE __declspec(dllexport)" << endl;
- s << "#elif __GNUC__ >= 4" << endl;
- s << " #define SBK_EXPORT_MODULE __attribute__ ((visibility(\"default\")))" << endl;
- s << "#else" << endl;
- s << " #define SBK_EXPORT_MODULE" << endl;
- s << "#endif" << endl << endl;
-
- s << "#ifdef IS_PY3K" << endl;
- s << "static struct PyModuleDef moduledef = {" << endl;
- s << " /* m_base */ PyModuleDef_HEAD_INIT," << endl;
- s << " /* m_name */ \"" << moduleName() << "\"," << endl;
- s << " /* m_doc */ nullptr," << endl;
- s << " /* m_size */ -1," << endl;
- s << " /* m_methods */ " << moduleName() << "_methods," << endl;
- s << " /* m_reload */ nullptr," << endl;
- s << " /* m_traverse */ nullptr," << endl;
- s << " /* m_clear */ nullptr," << endl;
- s << " /* m_free */ nullptr" << endl;
- s << "};" << endl << endl;
- s << "#endif" << endl << endl;
+ s << Qt::endl;
+ }
+
+ s << "#if defined _WIN32 || defined __CYGWIN__\n";
+ s << " #define SBK_EXPORT_MODULE __declspec(dllexport)\n";
+ s << "#elif __GNUC__ >= 4\n";
+ s << " #define SBK_EXPORT_MODULE __attribute__ ((visibility(\"default\")))\n";
+ s << "#else\n";
+ s << " #define SBK_EXPORT_MODULE\n";
+ s << "#endif\n\n";
+
+ s << "#ifdef IS_PY3K\n";
+ s << "static struct PyModuleDef moduledef = {\n";
+ s << " /* m_base */ PyModuleDef_HEAD_INIT,\n";
+ s << " /* m_name */ \"" << moduleName() << "\",\n";
+ s << " /* m_doc */ nullptr,\n";
+ s << " /* m_size */ -1,\n";
+ s << " /* m_methods */ " << moduleName() << "_methods,\n";
+ s << " /* m_reload */ nullptr,\n";
+ s << " /* m_traverse */ nullptr,\n";
+ s << " /* m_clear */ nullptr,\n";
+ s << " /* m_free */ nullptr\n";
+ s << "};\n\n";
+ s << "#endif\n\n";
// PYSIDE-510: Create a signatures string for the introspection feature.
- s << "// The signatures string for the global functions." << endl;
- s << "// Multiple signatures have their index \"n:\" in front." << endl;
- s << "static const char *" << moduleName() << "_SignatureStrings[] = {" << endl;
+ s << "// The signatures string for the global functions.\n";
+ s << "// Multiple signatures have their index \"n:\" in front.\n";
+ s << "static const char *" << moduleName() << "_SignatureStrings[] = {\n";
QString line;
while (signatureStream.readLineInto(&line))
- s << INDENT << '"' << line << "\"," << endl;
- s << INDENT << NULL_PTR << "}; // Sentinel" << endl << endl;
+ s << INDENT << '"' << line << "\",\n";
+ s << INDENT << NULL_PTR << "}; // Sentinel\n\n";
- s << "SBK_MODULE_INIT_FUNCTION_BEGIN(" << moduleName() << ")" << endl;
+ s << "SBK_MODULE_INIT_FUNCTION_BEGIN(" << moduleName() << ")\n";
ErrorCode errorCode(QLatin1String("SBK_MODULE_INIT_ERROR"));
// module inject-code target/beginning
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode);
- s << endl;
+ s << Qt::endl;
}
for (const QString &requiredModule : requiredModules) {
- s << INDENT << "{" << endl;
+ s << INDENT << "{\n";
{
Indentation indentation(INDENT);
- s << INDENT << "Shiboken::AutoDecRef requiredModule(Shiboken::Module::import(\"" << requiredModule << "\"));" << endl;
- s << INDENT << "if (requiredModule.isNull())" << endl;
+ s << INDENT << "Shiboken::AutoDecRef requiredModule(Shiboken::Module::import(\"" << requiredModule << "\"));\n";
+ s << INDENT << "if (requiredModule.isNull())\n";
{
Indentation indentation(INDENT);
- s << INDENT << "return SBK_MODULE_INIT_ERROR;" << endl;
+ s << INDENT << "return SBK_MODULE_INIT_ERROR;\n";
}
- s << INDENT << cppApiVariableName(requiredModule) << " = Shiboken::Module::getTypes(requiredModule);" << endl;
- s << INDENT << convertersVariableName(requiredModule) << " = Shiboken::Module::getTypeConverters(requiredModule);" << endl;
+ s << INDENT << cppApiVariableName(requiredModule) << " = Shiboken::Module::getTypes(requiredModule);\n";
+ s << INDENT << convertersVariableName(requiredModule) << " = Shiboken::Module::getTypeConverters(requiredModule);\n";
}
- s << INDENT << "}" << endl << endl;
+ s << INDENT << "}\n\n";
}
int maxTypeIndex = getMaxTypeIndex() + instantiatedSmartPointers().size();
if (maxTypeIndex) {
- s << INDENT << "// Create an array of wrapper types for the current module." << endl;
- s << INDENT << "static PyTypeObject *cppApi[SBK_" << moduleName() << "_IDX_COUNT];" << endl;
- s << INDENT << cppApiVariableName() << " = cppApi;" << endl << endl;
+ s << INDENT << "// Create an array of wrapper types for the current module.\n";
+ s << INDENT << "static PyTypeObject *cppApi[SBK_" << moduleName() << "_IDX_COUNT];\n";
+ s << INDENT << cppApiVariableName() << " = cppApi;\n\n";
}
- s << INDENT << "// Create an array of primitive type converters for the current module." << endl;
- s << INDENT << "static SbkConverter *sbkConverters[SBK_" << moduleName() << "_CONVERTERS_IDX_COUNT" << "];" << endl;
- s << INDENT << convertersVariableName() << " = sbkConverters;" << endl << endl;
+ s << INDENT << "// Create an array of primitive type converters for the current module.\n";
+ s << INDENT << "static SbkConverter *sbkConverters[SBK_" << moduleName() << "_CONVERTERS_IDX_COUNT" << "];\n";
+ s << INDENT << convertersVariableName() << " = sbkConverters;\n\n";
- s << "#ifdef IS_PY3K" << endl;
- s << INDENT << "PyObject *module = Shiboken::Module::create(\"" << moduleName() << "\", &moduledef);" << endl;
- s << "#else" << endl;
+ s << "#ifdef IS_PY3K\n";
+ s << INDENT << "PyObject *module = Shiboken::Module::create(\"" << moduleName() << "\", &moduledef);\n";
+ s << "#else\n";
s << INDENT << "PyObject *module = Shiboken::Module::create(\"" << moduleName() << "\", ";
- s << moduleName() << "_methods);" << endl;
- s << "#endif" << endl << endl;
+ s << moduleName() << "_methods);\n";
+ s << "#endif\n\n";
- s << INDENT << "// Make module available from global scope" << endl;
- s << INDENT << pythonModuleObjectName() << " = module;" << endl << endl;
+ s << INDENT << "// Make module available from global scope\n";
+ s << INDENT << pythonModuleObjectName() << " = module;\n\n";
- //s << INDENT << "// Initialize converters for primitive types." << endl;
- //s << INDENT << "initConverters();" << endl << endl;
+ //s << INDENT << "// Initialize converters for primitive types.\n";
+ //s << INDENT << "initConverters();\n\n";
- s << INDENT << "// Initialize classes in the type system" << endl;
+ s << INDENT << "// Initialize classes in the type system\n";
s << classPythonDefines;
if (!typeConversions.isEmpty()) {
- s << endl;
+ s << Qt::endl;
for (const CustomConversion *conversion : typeConversions) {
writePrimitiveConverterInitialization(s, conversion);
- s << endl;
+ s << Qt::endl;
}
}
if (!containers.isEmpty()) {
- s << endl;
+ s << Qt::endl;
for (const AbstractMetaType *container : containers) {
writeContainerConverterInitialization(s, container);
- s << endl;
+ s << Qt::endl;
}
}
if (!extendedConverters.isEmpty()) {
- s << endl;
+ s << Qt::endl;
for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) {
writeExtendedConverterInitialization(s, it.key(), it.value());
- s << endl;
+ s << Qt::endl;
}
}
writeEnumsInitialization(s, globalEnums);
- s << INDENT << "// Register primitive types converters." << endl;
+ s << INDENT << "// Register primitive types converters.\n";
const PrimitiveTypeEntryList &primitiveTypeList = primitiveTypes();
for (const PrimitiveTypeEntry *pte : primitiveTypeList) {
if (!pte->generateCode() || !pte->isCppPrimitive())
@@ -5771,56 +5751,56 @@ bool CppGenerator::finishGeneration()
QStringList cppSignature = pte->qualifiedCppName().split(QLatin1String("::"), QString::SkipEmptyParts);
while (!cppSignature.isEmpty()) {
QString signature = cppSignature.join(QLatin1String("::"));
- s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << signature << "\");" << endl;
+ s << INDENT << "Shiboken::Conversions::registerConverterName(" << converter << ", \"" << signature << "\");\n";
cppSignature.removeFirst();
}
}
- s << endl;
+ s << Qt::endl;
if (maxTypeIndex)
- s << INDENT << "Shiboken::Module::registerTypes(module, " << cppApiVariableName() << ");" << endl;
- s << INDENT << "Shiboken::Module::registerTypeConverters(module, " << convertersVariableName() << ");" << endl;
+ s << INDENT << "Shiboken::Module::registerTypes(module, " << cppApiVariableName() << ");\n";
+ s << INDENT << "Shiboken::Module::registerTypeConverters(module, " << convertersVariableName() << ");\n";
- s << endl << INDENT << "if (PyErr_Occurred()) {" << endl;
+ s << Qt::endl << INDENT << "if (PyErr_Occurred()) {\n";
{
Indentation indentation(INDENT);
- s << INDENT << "PyErr_Print();" << endl;
- s << INDENT << "Py_FatalError(\"can't initialize module " << moduleName() << "\");" << endl;
+ s << INDENT << "PyErr_Print();\n";
+ s << INDENT << "Py_FatalError(\"can't initialize module " << moduleName() << "\");\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
// module inject-code target/end
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode);
- s << endl;
+ s << Qt::endl;
}
// module inject-code native/end
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode);
- s << endl;
+ s << Qt::endl;
}
if (usePySideExtensions()) {
for (AbstractMetaEnum *metaEnum : qAsConst(globalEnums))
if (!metaEnum->isAnonymous()) {
- s << INDENT << "qRegisterMetaType< ::" << metaEnum->typeEntry()->qualifiedCppName() << " >(\"" << metaEnum->name() << "\");" << endl;
+ s << INDENT << "qRegisterMetaType< ::" << metaEnum->typeEntry()->qualifiedCppName() << " >(\"" << metaEnum->name() << "\");\n";
}
// cleanup staticMetaObject attribute
- s << INDENT << "PySide::registerCleanupFunction(cleanTypesAttributes);" << endl << endl;
+ s << INDENT << "PySide::registerCleanupFunction(cleanTypesAttributes);\n\n";
}
// finish the rest of __signature__ initialization.
s << INDENT << "FinishSignatureInitialization(module, " << moduleName()
- << "_SignatureStrings);" << endl;
+ << "_SignatureStrings);\n";
if (usePySideExtensions()) {
// initialize the qApp module.
- s << INDENT << "NotifyModuleForQApp(module, qApp);" << endl;
+ s << INDENT << "NotifyModuleForQApp(module, qApp);\n";
}
- s << endl;
- s << "SBK_MODULE_INIT_FUNCTION_END" << endl;
+ s << Qt::endl;
+ s << "SBK_MODULE_INIT_FUNCTION_END\n";
return file.done() != FileOut::Failure;
}
@@ -5921,18 +5901,18 @@ void CppGenerator::writeReturnValueHeuristics(QTextStream &s, const AbstractMeta
ArgumentOwner argOwner = getArgumentOwner(func, ArgumentOwner::ReturnIndex);
if (argOwner.action == ArgumentOwner::Invalid || argOwner.index != ArgumentOwner::ThisIndex) {
if (isPointerToWrapperType(type))
- s << INDENT << "Shiboken::Object::setParent(self, " << PYTHON_RETURN_VAR << ");" << endl;
+ s << INDENT << "Shiboken::Object::setParent(self, " << PYTHON_RETURN_VAR << ");\n";
}
}
void CppGenerator::writeHashFunction(QTextStream &s, GeneratorContext &context)
{
const AbstractMetaClass *metaClass = context.metaClass();
- s << "static Py_hash_t " << cpythonBaseName(metaClass) << "_HashFunc(PyObject *self) {" << endl;
+ s << "static Py_hash_t " << cpythonBaseName(metaClass) << "_HashFunc(PyObject *self) {\n";
writeCppSelfDefinition(s, context);
s << INDENT << "return " << metaClass->typeEntry()->hashFunction() << '(';
- s << (isObjectType(metaClass) ? "" : "*") << CPP_SELF_VAR << ");" << endl;
- s << '}' << endl << endl;
+ s << (isObjectType(metaClass) ? "" : "*") << CPP_SELF_VAR << ");\n";
+ s<< "}\n\n";
}
void CppGenerator::writeStdListWrapperMethods(QTextStream &s, GeneratorContext &context)
@@ -5941,63 +5921,63 @@ void CppGenerator::writeStdListWrapperMethods(QTextStream &s, GeneratorContext &
ErrorCode errorCode(0);
// __len__
- s << "Py_ssize_t " << cpythonBaseName(metaClass->typeEntry()) << "__len__(PyObject *self)" << endl;
- s << '{' << endl;
+ s << "Py_ssize_t " << cpythonBaseName(metaClass->typeEntry())
+ << "__len__(PyObject *self)\n{\n";
writeCppSelfDefinition(s, context);
- s << INDENT << "return " << CPP_SELF_VAR << "->size();" << endl;
- s << '}' << endl;
+ s << INDENT << "return " << CPP_SELF_VAR << "->size();\n";
+ s << "}\n";
// __getitem__
- s << "PyObject *" << cpythonBaseName(metaClass->typeEntry()) << "__getitem__(PyObject *self, Py_ssize_t _i)" << endl;
- s << '{' << endl;
+ s << "PyObject *" << cpythonBaseName(metaClass->typeEntry())
+ << "__getitem__(PyObject *self, Py_ssize_t _i)\n{\n";
writeCppSelfDefinition(s, context);
writeIndexError(s, QLatin1String("index out of bounds"));
- s << INDENT << metaClass->qualifiedCppName() << "::iterator _item = " << CPP_SELF_VAR << "->begin();" << endl;
- s << INDENT << "for (Py_ssize_t pos = 0; pos < _i; pos++) _item++;" << endl;
+ s << INDENT << metaClass->qualifiedCppName() << "::iterator _item = " << CPP_SELF_VAR << "->begin();\n";
+ s << INDENT << "for (Py_ssize_t pos = 0; pos < _i; pos++) _item++;\n";
const AbstractMetaType *itemType = metaClass->templateBaseClassInstantiations().constFirst();
s << INDENT << "return ";
writeToPythonConversion(s, itemType, metaClass, QLatin1String("*_item"));
- s << ';' << endl;
- s << '}' << endl;
+ s << ";\n";
+ s << "}\n";
// __setitem__
ErrorCode errorCode2(-1);
- s << "int " << cpythonBaseName(metaClass->typeEntry()) << "__setitem__(PyObject *self, Py_ssize_t _i, PyObject *pyArg)" << endl;
- s << '{' << endl;
+ s << "int " << cpythonBaseName(metaClass->typeEntry())
+ << "__setitem__(PyObject *self, Py_ssize_t _i, PyObject *pyArg)\n{\n";
writeCppSelfDefinition(s, context);
writeIndexError(s, QLatin1String("list assignment index out of range"));
- s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ';' << endl;
+ s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ";\n";
s << INDENT << "if (!";
writeTypeCheck(s, itemType, QLatin1String("pyArg"), isNumber(itemType->typeEntry()));
- s << ") {" << endl;
+ s << ") {\n";
{
Indentation indent(INDENT);
s << INDENT << "PyErr_SetString(PyExc_TypeError, \"attributed value with wrong type, '";
- s << itemType->name() << "' or other convertible type expected\");" << endl;
- s << INDENT << "return -1;" << endl;
+ s << itemType->name() << "' or other convertible type expected\");\n";
+ s << INDENT << "return -1;\n";
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
writeArgumentConversion(s, itemType, QLatin1String("cppValue"), QLatin1String("pyArg"), metaClass);
- s << INDENT << metaClass->qualifiedCppName() << "::iterator _item = " << CPP_SELF_VAR << "->begin();" << endl;
- s << INDENT << "for (Py_ssize_t pos = 0; pos < _i; pos++) _item++;" << endl;
- s << INDENT << "*_item = cppValue;" << endl;
- s << INDENT << "return {};" << endl;
- s << '}' << endl;
+ s << INDENT << metaClass->qualifiedCppName() << "::iterator _item = " << CPP_SELF_VAR << "->begin();\n";
+ s << INDENT << "for (Py_ssize_t pos = 0; pos < _i; pos++) _item++;\n";
+ s << INDENT << "*_item = cppValue;\n";
+ s << INDENT << "return {};\n";
+ s << "}\n";
}
void CppGenerator::writeIndexError(QTextStream &s, const QString &errorMsg)
{
- s << INDENT << "if (_i < 0 || _i >= (Py_ssize_t) " << CPP_SELF_VAR << "->size()) {" << endl;
+ s << INDENT << "if (_i < 0 || _i >= (Py_ssize_t) " << CPP_SELF_VAR << "->size()) {\n";
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_IndexError, \"" << errorMsg << "\");" << endl;
- s << INDENT << returnStatement(m_currentErrorCode) << endl;
+ s << INDENT << "PyErr_SetString(PyExc_IndexError, \"" << errorMsg << "\");\n";
+ s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl;
}
- s << INDENT << '}' << endl;
+ s << INDENT << "}\n";
}
QString CppGenerator::writeReprFunction(QTextStream &s,
@@ -6006,41 +5986,39 @@ QString CppGenerator::writeReprFunction(QTextStream &s,
{
const AbstractMetaClass *metaClass = context.metaClass();
QString funcName = cpythonBaseName(metaClass) + QLatin1String("__repr__");
- s << "extern \"C\"" << endl;
- s << '{' << endl;
- s << "static PyObject *" << funcName << "(PyObject *self)" << endl;
- s << '{' << endl;
+ s << "extern \"C\"\n{\n";
+ s << "static PyObject *" << funcName << "(PyObject *self)\n{\n";
writeCppSelfDefinition(s, context);
- s << INDENT << "QBuffer buffer;" << endl;
- s << INDENT << "buffer.open(QBuffer::ReadWrite);" << endl;
- s << INDENT << "QDebug dbg(&buffer);" << endl;
+ s << INDENT << "QBuffer buffer;\n";
+ s << INDENT << "buffer.open(QBuffer::ReadWrite);\n";
+ s << INDENT << "QDebug dbg(&buffer);\n";
s << INDENT << "dbg << ";
if (metaClass->typeEntry()->isValue() || indirections == 0)
s << '*';
- s << CPP_SELF_VAR << ';' << endl;
- s << INDENT << "buffer.close();" << endl;
- s << INDENT << "QByteArray str = buffer.data();" << endl;
- s << INDENT << "int idx = str.indexOf('(');" << endl;
- s << INDENT << "if (idx >= 0)" << endl;
+ s << CPP_SELF_VAR << ";\n";
+ s << INDENT << "buffer.close();\n";
+ s << INDENT << "QByteArray str = buffer.data();\n";
+ s << INDENT << "int idx = str.indexOf('(');\n";
+ s << INDENT << "if (idx >= 0)\n";
{
Indentation indent(INDENT);
- s << INDENT << "str.replace(0, idx, Py_TYPE(self)->tp_name);" << endl;
+ s << INDENT << "str.replace(0, idx, Py_TYPE(self)->tp_name);\n";
}
- s << INDENT << "str = str.trimmed();" << endl;
- s << INDENT << "PyObject *mod = PyDict_GetItem(Py_TYPE(self)->tp_dict, Shiboken::PyMagicName::module());" << endl;
+ s << INDENT << "str = str.trimmed();\n";
+ s << INDENT << "PyObject *mod = PyDict_GetItem(Py_TYPE(self)->tp_dict, Shiboken::PyMagicName::module());\n";
// PYSIDE-595: The introduction of heap types has the side effect that the module name
// is always prepended to the type name. Therefore the strchr check:
- s << INDENT << "if (mod && !strchr(str, '.'))" << endl;
+ s << INDENT << "if (mod && !strchr(str, '.'))\n";
{
Indentation indent(INDENT);
- s << INDENT << "return Shiboken::String::fromFormat(\"<%s.%s at %p>\", Shiboken::String::toCString(mod), str.constData(), self);" << endl;
+ s << INDENT << "return Shiboken::String::fromFormat(\"<%s.%s at %p>\", Shiboken::String::toCString(mod), str.constData(), self);\n";
}
- s << INDENT << "else" << endl;
+ s << INDENT << "else\n";
{
Indentation indent(INDENT);
- s << INDENT << "return Shiboken::String::fromFormat(\"<%s at %p>\", str.constData(), self);" << endl;
+ s << INDENT << "return Shiboken::String::fromFormat(\"<%s at %p>\", str.constData(), self);\n";
}
- s << '}' << endl;
- s << "} // extern C" << endl << endl;;
+ s << "}\n";
+ s << "} // extern C\n\n";
return funcName;
}
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h
index 005518f96..fd272eaad 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.h
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h
@@ -50,6 +50,9 @@ protected:
bool finishGeneration() override;
private:
+ void writeInitFunc(QTextStream &declStr, QTextStream &callStr,
+ const Indentor &indent, const QString &initFunctionName,
+ const TypeEntry *enclosingEntry = nullptr);
void writeConstructorNative(QTextStream &s, const AbstractMetaFunction *func);
void writeDestructorNative(QTextStream &s, const AbstractMetaClass *metaClass);
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
index e47c37523..a565659de 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
@@ -61,9 +61,9 @@ QString HeaderGenerator::fileNameForContext(GeneratorContext &context) const
void HeaderGenerator::writeCopyCtor(QTextStream &s, const AbstractMetaClass *metaClass) const
{
s << INDENT << wrapperName(metaClass) << "(const " << metaClass->qualifiedCppName() << "& self)";
- s << " : " << metaClass->qualifiedCppName() << "(self)" << endl;
- s << INDENT << "{" << endl;
- s << INDENT << "}" << endl << endl;
+ s << " : " << metaClass->qualifiedCppName() << "(self)\n";
+ s << INDENT << "{\n";
+ s << INDENT << "}\n\n";
}
void HeaderGenerator::writeProtectedFieldAccessors(QTextStream &s, const AbstractMetaField *field) const
@@ -84,11 +84,11 @@ void HeaderGenerator::writeProtectedFieldAccessors(QTextStream &s, const Abstrac
<< (useReference ? " *" : " ")
<< ' ' << protectedFieldGetterName(field) << "()"
<< " { return "
- << (useReference ? " &" : " ") << "this->" << fieldName << "; }" << endl;
+ << (useReference ? " &" : " ") << "this->" << fieldName << "; }\n";
// Set function
s << INDENT << "inline void " << protectedFieldSetterName(field) << '(' << fieldType << " value)"
- << " { " << fieldName << " = value; }" << endl;
+ << " { " << fieldName << " = value; }\n";
}
void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
@@ -112,14 +112,14 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte
QString innerHeaderGuard;
// Header
- s << "#ifndef SBK_" << outerHeaderGuard << "_H" << endl;
- s << "#define SBK_" << outerHeaderGuard << "_H" << endl << endl;
+ s << "#ifndef SBK_" << outerHeaderGuard << "_H\n";
+ s << "#define SBK_" << outerHeaderGuard << "_H\n\n";
if (!avoidProtectedHack())
- s << "#define protected public" << endl << endl;
+ s << "#define protected public\n\n";
//Includes
- s << metaClass->typeEntry()->include() << endl;
+ s << metaClass->typeEntry()->include() << Qt::endl;
if (shouldGenerateCppWrapper(metaClass) &&
usePySideExtensions() && metaClass->isQObject())
@@ -127,16 +127,16 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte
while (shouldGenerateCppWrapper(metaClass)) {
if (!innerHeaderGuard.isEmpty()) {
- s << "# ifndef SBK_" << innerHeaderGuard << "_H" << endl;
- s << "# define SBK_" << innerHeaderGuard << "_H" << endl << endl;
- s << "// Inherited base class:" << endl;
+ s << "# ifndef SBK_" << innerHeaderGuard << "_H\n";
+ s << "# define SBK_" << innerHeaderGuard << "_H\n\n";
+ s << "// Inherited base class:\n";
}
// Class
s << "class " << wrapperName;
s << " : public " << metaClass->qualifiedCppName();
- s << endl << '{' << endl << "public:" << endl;
+ s << "\n{\npublic:\n";
const AbstractMetaFunctionList &funcs = filterFunctions(metaClass);
for (AbstractMetaFunction *func : funcs) {
@@ -160,8 +160,8 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte
s << INDENT;
if (avoidProtectedHack() && metaClass->hasPrivateDestructor())
s << "// C++11: need to declare (unimplemented) destructor because "
- "the base class destructor is private." << endl;
- s << '~' << wrapperName << "();" << endl;
+ "the base class destructor is private.\n";
+ s << '~' << wrapperName << "();\n";
}
writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), TypeSystem::CodeSnipPositionDeclaration, TypeSystem::NativeCode);
@@ -169,22 +169,22 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte
if ((!avoidProtectedHack() || !metaClass->hasPrivateDestructor())
&& usePySideExtensions() && metaClass->isQObject()) {
s << "public:\n";
- s << INDENT << "int qt_metacall(QMetaObject::Call call, int id, void **args) override;" << endl;
- s << INDENT << "void *qt_metacast(const char *_clname) override;" << endl;
+ s << INDENT << "int qt_metacall(QMetaObject::Call call, int id, void **args) override;\n";
+ s << INDENT << "void *qt_metacast(const char *_clname) override;\n";
}
if (!m_inheritedOverloads.isEmpty()) {
- s << INDENT << "// Inherited overloads, because the using keyword sux" << endl;
+ s << INDENT << "// Inherited overloads, because the using keyword sux\n";
writeInheritedOverloads(s);
m_inheritedOverloads.clear();
}
if (usePySideExtensions())
- s << INDENT << "static void pysideInitQtMetaTypes();" << endl;
+ s << INDENT << "static void pysideInitQtMetaTypes();\n";
- s << "};" << endl << endl;
+ s << "};\n\n";
if (!innerHeaderGuard.isEmpty())
- s << "# endif // SBK_" << innerHeaderGuard << "_H" << endl << endl;
+ s << "# endif // SBK_" << innerHeaderGuard << "_H\n\n";
// PYSIDE-500: Use also includes for inherited wrapper classes, because
// without the protected hack, we sometimes need to cast inherited wrappers.
@@ -202,7 +202,7 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte
innerHeaderGuard = getFilteredCppSignatureString(wrapperName).toUpper();
}
- s << "#endif // SBK_" << outerHeaderGuard << "_H" << endl << endl;
+ s << "#endif // SBK_" << outerHeaderGuard << "_H\n\n";
}
void HeaderGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *func)
@@ -238,7 +238,7 @@ void HeaderGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *
args << argName;
}
s << args.join(QLatin1String(", ")) << ')';
- s << "; }" << endl;
+ s << "; }\n";
}
// pure virtual functions need a default implementation
@@ -263,7 +263,7 @@ void HeaderGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *
if (virtualFunc)
s << " override";
- s << ';' << endl;
+ s << ";\n";
// Check if this method hide other methods in base classes
const AbstractMetaFunctionList &ownerFuncs = func->ownerClass()->functions();
for (const AbstractMetaFunction *f : ownerFuncs) {
@@ -326,7 +326,8 @@ void HeaderGenerator::writeTypeIndexValueLine(QTextStream &s, const TypeEntry *t
void HeaderGenerator::writeTypeIndexValueLines(QTextStream &s, const AbstractMetaClass *metaClass)
{
- if (!metaClass->typeEntry()->generateCode())
+ auto typeEntry = metaClass->typeEntry();
+ if (!typeEntry->generateCode() || !NamespaceTypeEntry::isVisibleScope(typeEntry))
return;
writeTypeIndexValueLine(s, metaClass->typeEntry());
const AbstractMetaEnumList &enums = metaClass->enums();
@@ -400,9 +401,17 @@ bool HeaderGenerator::finishGeneration()
int smartPointerCount = 0;
const QVector<const AbstractMetaType *> &instantiatedSmartPtrs = instantiatedSmartPointers();
for (const AbstractMetaType *metaType : instantiatedSmartPtrs) {
- _writeTypeIndexValue(macrosStream, getTypeIndexVariableName(metaType),
- smartPointerCountIndex);
- macrosStream << ", // " << metaType->cppSignature() << endl;
+ QString indexName = getTypeIndexVariableName(metaType);
+ _writeTypeIndexValue(macrosStream, indexName, smartPointerCountIndex);
+ macrosStream << ", // " << metaType->cppSignature() << Qt::endl;
+ // Add a the same value for const pointees (shared_ptr<const Foo>).
+ const auto ptrName = metaType->typeEntry()->entryName();
+ int pos = indexName.indexOf(ptrName, 0, Qt::CaseInsensitive);
+ if (pos >= 0) {
+ indexName.insert(pos + ptrName.size() + 1, QLatin1String("CONST"));
+ _writeTypeIndexValue(macrosStream, indexName, smartPointerCountIndex);
+ macrosStream << ", // (const)\n";
+ }
++smartPointerCountIndex;
++smartPointerCount;
}
@@ -412,12 +421,12 @@ bool HeaderGenerator::finishGeneration()
getMaxTypeIndex() + smartPointerCount);
macrosStream << "\n};\n";
- macrosStream << "// This variable stores all Python types exported by this module." << endl;
- macrosStream << "extern PyTypeObject **" << cppApiVariableName() << ';' << endl << endl;
- macrosStream << "// This variable stores the Python module object exported by this module." << endl;
- macrosStream << "extern PyObject *" << pythonModuleObjectName() << ';' << endl << endl;
- macrosStream << "// This variable stores all type converters exported by this module." << endl;
- macrosStream << "extern SbkConverter **" << convertersVariableName() << ';' << endl << endl;
+ macrosStream << "// This variable stores all Python types exported by this module.\n";
+ macrosStream << "extern PyTypeObject **" << cppApiVariableName() << ";\n\n";
+ macrosStream << "// This variable stores the Python module object exported by this module.\n";
+ macrosStream << "extern PyObject *" << pythonModuleObjectName() << ";\n\n";
+ macrosStream << "// This variable stores all type converters exported by this module.\n";
+ macrosStream << "extern SbkConverter **" << convertersVariableName() << ";\n\n";
// TODO-CONVERTER ------------------------------------------------------------------------------
// Using a counter would not do, a fix must be made to APIExtractor's getTypeIndex().
@@ -438,7 +447,7 @@ bool HeaderGenerator::finishGeneration()
const QVector<const AbstractMetaType *> &containers = instantiatedContainers();
for (const AbstractMetaType *container : containers) {
_writeTypeIndexValue(macrosStream, getTypeIndexVariableName(container), pCount);
- macrosStream << ", // " << container->cppSignature() << endl;
+ macrosStream << ", // " << container->cppSignature() << Qt::endl;
pCount++;
}
@@ -453,11 +462,11 @@ bool HeaderGenerator::finishGeneration()
// TODO-CONVERTER ------------------------------------------------------------------------------
- macrosStream << "// Macros for type check" << endl;
+ macrosStream << "// Macros for type check\n";
if (usePySideExtensions()) {
- typeFunctions << "QT_WARNING_PUSH" << endl;
- typeFunctions << "QT_WARNING_DISABLE_DEPRECATED" << endl;
+ typeFunctions << "QT_WARNING_PUSH\n";
+ typeFunctions << "QT_WARNING_DISABLE_DEPRECATED\n";
}
for (const AbstractMetaEnum *cppEnum : qAsConst(globalEnums)) {
if (cppEnum->isAnonymous() || cppEnum->isPrivate())
@@ -495,7 +504,7 @@ bool HeaderGenerator::finishGeneration()
writeSbkTypeFunction(typeFunctions, metaType);
}
if (usePySideExtensions())
- typeFunctions << "QT_WARNING_POP" << endl;
+ typeFunctions << "QT_WARNING_POP\n";
QString moduleHeaderFileName(outputDirectory()
+ QDir::separator() + subDirectoryForPackage(packageName())
@@ -506,61 +515,61 @@ bool HeaderGenerator::finishGeneration()
FileOut file(moduleHeaderFileName);
QTextStream &s = file.stream;
// write license comment
- s << licenseComment() << endl << endl;
+ s << licenseComment() << Qt::endl << Qt::endl;
- s << "#ifndef " << includeShield << endl;
- s << "#define " << includeShield << endl<< endl;
+ s << "#ifndef " << includeShield << Qt::endl;
+ s << "#define " << includeShield << Qt::endl << Qt::endl;
if (!avoidProtectedHack()) {
- s << "//workaround to access protected functions" << endl;
- s << "#define protected public" << endl << endl;
+ s << "//workaround to access protected functions\n";
+ s << "#define protected public\n\n";
}
- s << "#include <sbkpython.h>" << endl;
- s << "#include <sbkconverter.h>" << endl;
+ s << "#include <sbkpython.h>\n";
+ s << "#include <sbkconverter.h>\n";
QStringList requiredTargetImports = TypeDatabase::instance()->requiredTargetImports();
if (!requiredTargetImports.isEmpty()) {
- s << "// Module Includes" << endl;
+ s << "// Module Includes\n";
for (const QString &requiredModule : qAsConst(requiredTargetImports))
- s << "#include <" << getModuleHeaderFileName(requiredModule) << ">" << endl;
- s << endl;
+ s << "#include <" << getModuleHeaderFileName(requiredModule) << ">\n";
+ s << Qt::endl;
}
- s << "// Binded library includes" << endl;
+ s << "// Bound library includes\n";
for (const Include &include : qAsConst(includes))
s << include;
if (!primitiveTypes().isEmpty()) {
- s << "// Conversion Includes - Primitive Types" << endl;
+ s << "// Conversion Includes - Primitive Types\n";
const PrimitiveTypeEntryList &primitiveTypeList = primitiveTypes();
for (const PrimitiveTypeEntry *ptype : primitiveTypeList)
s << ptype->include();
- s << endl;
+ s << Qt::endl;
}
if (!containerTypes().isEmpty()) {
- s << "// Conversion Includes - Container Types" << endl;
+ s << "// Conversion Includes - Container Types\n";
const ContainerTypeEntryList &containerTypeList = containerTypes();
for (const ContainerTypeEntry *ctype : containerTypeList)
s << ctype->include();
- s << endl;
+ s << Qt::endl;
}
- s << macros << endl;
+ s << macros << Qt::endl;
if (!protectedEnumSurrogates.isEmpty()) {
- s << "// Protected enum surrogates" << endl;
- s << protectedEnumSurrogates << endl;
+ s << "// Protected enum surrogates\n";
+ s << protectedEnumSurrogates << Qt::endl;
}
- s << "namespace Shiboken" << endl << '{' << endl << endl;
+ s << "namespace Shiboken\n{\n\n";
s << "// PyType functions, to get the PyObjectType for a type T\n";
- s << sbkTypeFunctions << endl;
+ s << sbkTypeFunctions << Qt::endl;
- s << "} // namespace Shiboken" << endl << endl;
+ s << "} // namespace Shiboken\n\n";
- s << "#endif // " << includeShield << endl << endl;
+ s << "#endif // " << includeShield << Qt::endl << Qt::endl;
return file.done() != FileOut::Failure;
}
@@ -568,7 +577,7 @@ bool HeaderGenerator::finishGeneration()
void HeaderGenerator::writeProtectedEnumSurrogate(QTextStream &s, const AbstractMetaEnum *cppEnum)
{
if (avoidProtectedHack() && cppEnum->isProtected())
- s << "enum " << protectedEnumSurrogateName(cppEnum) << " {};" << endl;
+ s << "enum " << protectedEnumSurrogateName(cppEnum) << " {};\n";
}
void HeaderGenerator::writeSbkTypeFunction(QTextStream &s, const AbstractMetaEnum *cppEnum)
@@ -625,6 +634,6 @@ void HeaderGenerator::writeInheritedOverloads(QTextStream &s)
args << argName;
}
s << args.join(QLatin1String(", ")) << ')';
- s << "; }" << endl;
+ s << "; }\n";
}
}
diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp
index 5f74ee64d..56b64bbd5 100644
--- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp
+++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp
@@ -864,8 +864,8 @@ QString OverloadData::dumpGraph() const
QTextStream s(&result);
if (m_argPos == -1) {
const AbstractMetaFunction *rfunc = referenceFunction();
- s << "digraph OverloadedFunction {" << endl;
- s << INDENT << "graph [fontsize=12 fontname=freemono labelloc=t splines=true overlap=false rankdir=LR];" << endl;
+ s << "digraph OverloadedFunction {\n";
+ s << INDENT << "graph [fontsize=12 fontname=freemono labelloc=t splines=true overlap=false rankdir=LR];\n";
// Shows all function signatures
s << "legend [fontsize=9 fontname=freemono shape=rect label=\"";
@@ -877,7 +877,7 @@ QString OverloadData::dumpGraph() const
s << "void";
s << ' ' << toHtml(func->minimalSignature()) << "\\l";
}
- s << "\"];" << endl;
+ s << "\"];\n";
// Function box title
s << INDENT << '"' << rfunc->name() << "\" [shape=plaintext style=\"filled,bold\" margin=0 fontname=freemono fillcolor=white penwidth=1 ";
@@ -930,15 +930,15 @@ QString OverloadData::dumpGraph() const
s << 'f' << functionNumber(func) << ' ';
s << "</td></tr>";
- s << "</table>> ];" << endl;
+ s << "</table>> ];\n";
for (const OverloadData *pd : m_nextOverloadData)
s << INDENT << '"' << rfunc->name() << "\" -> " << pd->dumpGraph();
- s << "}" << endl;
+ s << "}\n";
} else {
QString argId = QLatin1String("arg_") + QString::number(quintptr(this));
- s << argId << ';' << endl;
+ s << argId << ";\n";
s << INDENT << '"' << argId << "\" [shape=\"plaintext\" style=\"filled,bold\" margin=\"0\" fontname=\"freemono\" fillcolor=\"white\" penwidth=1 ";
s << "label=<<table border=\"0\" cellborder=\"0\" cellpadding=\"3\" bgcolor=\"white\">";
@@ -981,7 +981,7 @@ QString OverloadData::dumpGraph() const
}
}
- s << "</table>>];" << endl;
+ s << "</table>>];\n";
for (const OverloadData *pd : m_nextOverloadData)
s << INDENT << argId << " -> " << pd->dumpGraph();
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index fd75c620e..35bd363b5 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -326,7 +326,7 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi
{
Q_ASSERT(metaClass);
// if a scope is not to be generated, collect its enums into the parent scope
- if (metaClass->typeEntry()->codeGeneration() == TypeEntry::GenerateForSubclass) {
+ if (!NamespaceTypeEntry::isVisibleScope(metaClass->typeEntry())) {
const AbstractMetaEnumList &enums = metaClass->enums();
for (AbstractMetaEnum *metaEnum : enums) {
if (!metaEnum->isPrivate() && metaEnum->typeEntry()->generateCode()
@@ -337,22 +337,6 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi
}
}
-static const AbstractMetaClass *getProperEnclosingClass(const AbstractMetaClass *metaClass)
-{
- if (!metaClass)
- return nullptr;
-
- if (metaClass->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)
- return metaClass;
-
- return getProperEnclosingClass(metaClass->enclosingClass());
-}
-
-const AbstractMetaClass *ShibokenGenerator::getProperEnclosingClassForEnum(const AbstractMetaEnum *metaEnum)
-{
- return getProperEnclosingClass(metaEnum->enclosingClass());
-}
-
QString ShibokenGenerator::wrapperName(const AbstractMetaClass *metaClass) const
{
if (shouldGenerateCppWrapper(metaClass)) {
@@ -376,7 +360,8 @@ QString ShibokenGenerator::fullPythonClassName(const AbstractMetaClass *metaClas
QString fullClassName = metaClass->name();
const AbstractMetaClass *enclosing = metaClass->enclosingClass();
while (enclosing) {
- fullClassName.prepend(enclosing->name() + QLatin1Char('.'));
+ if (NamespaceTypeEntry::isVisibleScope(enclosing->typeEntry()))
+ fullClassName.prepend(enclosing->name() + QLatin1Char('.'));
enclosing = enclosing->enclosingClass();
}
fullClassName.prepend(packageName() + QLatin1Char('.'));
@@ -1548,7 +1533,7 @@ void ShibokenGenerator::writeFunctionCall(QTextStream &s,
void ShibokenGenerator::writeUnusedVariableCast(QTextStream &s, const QString &variableName)
{
- s << INDENT << "SBK_UNUSED(" << variableName<< ')' << endl;
+ s << INDENT << "SBK_UNUSED(" << variableName<< ")\n";
}
AbstractMetaFunctionList ShibokenGenerator::filterFunctions(const AbstractMetaClass *metaClass)
@@ -1731,9 +1716,9 @@ void ShibokenGenerator::writeCodeSnips(QTextStream &s,
if (code.isEmpty())
return;
processCodeSnip(code, context);
- s << INDENT << "// Begin code injection" << endl;
+ s << INDENT << "// Begin code injection\n";
s << code;
- s << INDENT << "// End of code injection" << endl;
+ s << INDENT << "// End of code injection\n";
}
void ShibokenGenerator::writeCodeSnips(QTextStream &s,
@@ -1958,9 +1943,9 @@ void ShibokenGenerator::writeCodeSnips(QTextStream &s,
replaceTemplateVariables(code, func);
processCodeSnip(code);
- s << INDENT << "// Begin code injection" << endl;
+ s << INDENT << "// Begin code injection\n";
s << code;
- s << INDENT << "// End of code injection" << endl;
+ s << INDENT << "// End of code injection\n";
}
// Returns true if the string is an expression,
@@ -2054,7 +2039,7 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa
qFatal("%s", qPrintable(msgConversionTypesDiffer(varType, conversionSignature)));
c << getFullTypeName(conversionType) << ' ' << varName;
writeMinimalConstructorExpression(c, conversionType);
- c << ';' << endl;
+ c << ";\n";
Indentation indent(INDENT);
c << INDENT;
}
@@ -2743,7 +2728,7 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream &s, const
} else {
const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->qualifiedCppName());
qCWarning(lcShiboken()).noquote() << message;
- s << ";\n#error " << message << endl;
+ s << ";\n#error " << message << Qt::endl;
}
}
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
index 7970ceb94..4501b902d 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
@@ -206,8 +206,6 @@ protected:
/// Adds enums eligible for generation from classes/namespaces marked not to be generated.
static void lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumList &enumList, const AbstractMetaClass *metaClass);
- /// Returns the enclosing class for an enum, or nullptr if it should be global.
- const AbstractMetaClass *getProperEnclosingClassForEnum(const AbstractMetaEnum *metaEnum);
QString wrapperName(const AbstractMetaClass *metaClass) const;
QString wrapperName(const AbstractMetaType *metaType) const;
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index 3c861c761..71efe12c0 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -58,6 +58,8 @@
#include "qapp_macro.h"
#include "voidptr.h"
+#include <iostream>
+
#if defined(__APPLE__)
#include <dlfcn.h>
#endif
@@ -919,8 +921,11 @@ introduceWrapperType(PyObject *enclosingObject,
}
}
// PYSIDE-510: Here is the single change to support signatures.
- if (SbkSpecial_Type_Ready(enclosingObject, reinterpret_cast<PyTypeObject *>(type), signatureStrings) < 0)
+ if (SbkSpecial_Type_Ready(enclosingObject, reinterpret_cast<PyTypeObject *>(type), signatureStrings) < 0) {
+ std::cerr << "Warning: " << __FUNCTION__ << " returns nullptr for "
+ << typeName << '/' << originalName << " due to SbkSpecial_Type_Ready() failing\n";
return nullptr;
+ }
initPrivateData(type);
auto sotp = PepType_SOTP(type);
@@ -936,7 +941,13 @@ introduceWrapperType(PyObject *enclosingObject,
// PyModule_AddObject steals type's reference.
Py_INCREF(ob_type);
- return PyModule_AddObject(enclosingObject, typeName, ob_type) == 0 ? type : nullptr;
+ if (PyModule_AddObject(enclosingObject, typeName, ob_type) != 0) {
+ std::cerr << "Warning: " << __FUNCTION__ << " returns nullptr for "
+ << typeName << '/' << originalName << " due to PyModule_AddObject(enclosingObject="
+ << enclosingObject << ",ob_type=" << ob_type << ") failing\n";
+ return nullptr;
+ }
+ return type;
}
void setSubTypeInitHook(SbkObjectType *type, SubTypeInitHook func)
diff --git a/sources/shiboken2/shiboken_version.py b/sources/shiboken2/shiboken_version.py
index 78ea0019d..c022fc803 100644
--- a/sources/shiboken2/shiboken_version.py
+++ b/sources/shiboken2/shiboken_version.py
@@ -38,7 +38,7 @@
#############################################################################
major_version = "5"
-minor_version = "14"
+minor_version = "15"
patch_version = "0"
# For example: "a", "b", "rc"
diff --git a/sources/shiboken2/tests/helper.py b/sources/shiboken2/tests/helper.py
new file mode 100644
index 000000000..2564c91d4
--- /dev/null
+++ b/sources/shiboken2/tests/helper.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+#############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+
+def objectFullname(t):
+ module = t.__module__
+ if module is None or module == str.__class__.__module__:
+ return t.__name__
+ else:
+ return module + '.' + t.__name__
diff --git a/sources/shiboken2/tests/libother/otherobjecttype.cpp b/sources/shiboken2/tests/libother/otherobjecttype.cpp
index ca356ce94..1f782ecd8 100644
--- a/sources/shiboken2/tests/libother/otherobjecttype.cpp
+++ b/sources/shiboken2/tests/libother/otherobjecttype.cpp
@@ -34,3 +34,13 @@ operator<<(Collector& collector, const OtherObjectType& obj)
collector << obj.identifier()*2;
return collector;
}
+
+int OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)
+{
+ return static_cast<int>(value);
+}
+
+int OtherObjectType::enumAsIntForInvisibleNamespace(Invisible::EnumOnNamespace value)
+{
+ return static_cast<int>(value);
+}
diff --git a/sources/shiboken2/tests/libother/otherobjecttype.h b/sources/shiboken2/tests/libother/otherobjecttype.h
index 22687c8bd..efd394347 100644
--- a/sources/shiboken2/tests/libother/otherobjecttype.h
+++ b/sources/shiboken2/tests/libother/otherobjecttype.h
@@ -35,11 +35,14 @@
#include "libothermacros.h"
#include "objecttype.h"
#include "collector.h"
+#include "samplenamespace.h"
-class OtherObjectType : public ObjectType
+
+class LIBOTHER_API OtherObjectType : public ObjectType
{
public:
-
+ static int enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value);
+ static int enumAsIntForInvisibleNamespace(Invisible::EnumOnNamespace value);
};
diff --git a/sources/shiboken2/tests/libsample/CMakeLists.txt b/sources/shiboken2/tests/libsample/CMakeLists.txt
index 170829fbc..ae13cd9f2 100644
--- a/sources/shiboken2/tests/libsample/CMakeLists.txt
+++ b/sources/shiboken2/tests/libsample/CMakeLists.txt
@@ -36,6 +36,7 @@ pointf.cpp
polygon.cpp
protected.cpp
reference.cpp
+renaming.cpp
sample.cpp
samplenamespace.cpp
sbkdate.cpp
diff --git a/sources/shiboken2/tests/libsample/renaming.cpp b/sources/shiboken2/tests/libsample/renaming.cpp
new file mode 100644
index 000000000..30586e1db
--- /dev/null
+++ b/sources/shiboken2/tests/libsample/renaming.cpp
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "renaming.h"
+
+#include <iostream>
+
+int ToBeRenamedValue::value() const
+{
+ return m_value;
+}
+
+void ToBeRenamedValue::setValue(int v)
+{
+ m_value = v;
+}
+
+void RenamedUser::useRenamedValue(const ToBeRenamedValue &v)
+{
+ std::cout << __FUNCTION__ << ' ' << v.value() << '\n';
+}
diff --git a/sources/shiboken2/tests/libsample/renaming.h b/sources/shiboken2/tests/libsample/renaming.h
new file mode 100644
index 000000000..cd88b36bf
--- /dev/null
+++ b/sources/shiboken2/tests/libsample/renaming.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENAMING_H
+#define RENAMING_H
+
+#include "libsamplemacros.h"
+
+class LIBSAMPLE_API ToBeRenamedValue
+{
+public:
+ int value() const;
+ void setValue(int v);
+
+private:
+ int m_value = 42;
+};
+
+class LIBSAMPLE_API RenamedUser
+{
+public:
+ void useRenamedValue(const ToBeRenamedValue &v);
+};
+
+#endif // POINT_H
diff --git a/sources/shiboken2/tests/libsample/samplenamespace.h b/sources/shiboken2/tests/libsample/samplenamespace.h
index 6868b5f0a..9e46b2ad6 100644
--- a/sources/shiboken2/tests/libsample/samplenamespace.h
+++ b/sources/shiboken2/tests/libsample/samplenamespace.h
@@ -51,6 +51,13 @@ enum EnumOnNamespace {
Option3 = 3
};
+struct ObjectOnInvisibleNamespace
+{
+ bool exists() const { return true; }
+ static int toInt(EnumOnNamespace e) { return static_cast<int>(e); }
+ static ObjectOnInvisibleNamespace consume(const ObjectOnInvisibleNamespace &other) { return other; }
+};
+
};
namespace SampleNamespace
@@ -137,6 +144,8 @@ protected:
PublicScopedEnum protectedMethodReturningPublicScopedEnum() const;
};
+LIBSAMPLE_API inline int enumAsInt(SomeClass::PublicScopedEnum value) { return static_cast<int>(value); }
+
class DerivedFromNamespace : public SomeClass::SomeInnerClass::OkThisIsRecursiveEnough
{
public:
diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp
index 6a4deb50a..81fa30c7e 100644
--- a/sources/shiboken2/tests/libsmart/smart.cpp
+++ b/sources/shiboken2/tests/libsmart/smart.cpp
@@ -93,7 +93,7 @@ Obj::~Obj()
void Obj::printObj() {
if (shouldPrint()) {
std::cout << "integer value: " << m_integer
- << " internal integer value: " << m_internalInteger->m_int << '\n';
+ << " internal integer value: " << m_internalInteger->value() << '\n';
}
}
@@ -134,6 +134,17 @@ int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj)
int Obj::takeSharedPtrToInteger(SharedPtr<Integer> pInt)
{
pInt->printInteger();
+ return pInt->value();
+}
+
+SharedPtr<const Integer> Obj::giveSharedPtrToConstInteger()
+{
+ SharedPtr<const Integer> co(new Integer);
+ return co;
+}
+
+int Obj::takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt)
+{
return pInt->m_int;
}
@@ -173,7 +184,17 @@ Integer::~Integer()
std::cout << "Integer destructor " << this << '\n';
}
-void Integer::printInteger()
+int Integer::value() const
+{
+ return m_int;
+}
+
+void Integer::setValue(int v)
+{
+ m_int = v;
+}
+
+void Integer::printInteger() const
{
if (shouldPrint())
std::cout << "Integer value for object " << this << " is " << m_int << '\n';
diff --git a/sources/shiboken2/tests/libsmart/smart_integer.h b/sources/shiboken2/tests/libsmart/smart_integer.h
index 3756f68b0..126894120 100644
--- a/sources/shiboken2/tests/libsmart/smart_integer.h
+++ b/sources/shiboken2/tests/libsmart/smart_integer.h
@@ -37,8 +37,12 @@ public:
Integer(const Integer &other);
Integer &operator=(const Integer &other);
~Integer();
- void printInteger();
- int m_int;
+ void printInteger() const;
+
+ int value() const;
+ void setValue(int v);
+
+ int m_int; // public for testing member field access.
};
namespace Smart {
diff --git a/sources/shiboken2/tests/libsmart/smart_obj.h b/sources/shiboken2/tests/libsmart/smart_obj.h
index 12425366e..e5709a071 100644
--- a/sources/shiboken2/tests/libsmart/smart_obj.h
+++ b/sources/shiboken2/tests/libsmart/smart_obj.h
@@ -49,11 +49,13 @@ public:
SharedPtr<Obj> giveSharedPtrToObj();
std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size);
SharedPtr<Integer> giveSharedPtrToInteger();
+ SharedPtr<const Integer> giveSharedPtrToConstInteger();
+ int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt);
SharedPtr<Smart::Integer2> giveSharedPtrToInteger2();
int takeSharedPtrToObj(SharedPtr<Obj> pObj);
int takeSharedPtrToInteger(SharedPtr<Integer> pInt);
- int m_integer;
+ int m_integer; // public for testing member field access.
Integer *m_internalInteger;
};
diff --git a/sources/shiboken2/tests/otherbinding/signature_test.py b/sources/shiboken2/tests/otherbinding/signature_test.py
new file mode 100644
index 000000000..e9fcff860
--- /dev/null
+++ b/sources/shiboken2/tests/otherbinding/signature_test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+#############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+'''Test cases for functions signature'''
+
+import unittest
+
+from other import OtherObjectType
+from helper import objectFullname
+
+class SignatureTest(unittest.TestCase):
+
+ # Check if the argument of 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)'
+ # has the correct representation
+ def testNamespaceFromOtherModule(self):
+ argType = OtherObjectType.enumAsInt.__signature__.parameters['value'].annotation
+ self.assertEqual(objectFullname(argType), 'sample.SampleNamespace.SomeClass.PublicScopedEnum')
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt
index 61090d30e..b65068dc3 100644
--- a/sources/shiboken2/tests/samplebinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/samplebinding/CMakeLists.txt
@@ -94,6 +94,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/rect_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/rectf_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/referentmodelindex_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/toberenamedvalue_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/renameduser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/sample_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/sample_sample_wrapper.cpp
@@ -123,6 +125,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/filter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/data_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/intersection_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/union_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/invisible_objectoninvisiblenamespace_wrapper.cpp
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample-binding.txt.in"
diff --git a/sources/shiboken2/tests/samplebinding/global.h b/sources/shiboken2/tests/samplebinding/global.h
index 3984102a8..f4e20b74f 100644
--- a/sources/shiboken2/tests/samplebinding/global.h
+++ b/sources/shiboken2/tests/samplebinding/global.h
@@ -75,6 +75,7 @@
#include "protected.h"
#include "rect.h"
#include "reference.h"
+#include "renaming.h"
#include "removednamespaces.h"
#include "sample.h"
#include "samplenamespace.h"
diff --git a/sources/shiboken2/tests/samplebinding/namespace_test.py b/sources/shiboken2/tests/samplebinding/namespace_test.py
index 5fcdab974..67f0974a7 100644
--- a/sources/shiboken2/tests/samplebinding/namespace_test.py
+++ b/sources/shiboken2/tests/samplebinding/namespace_test.py
@@ -33,12 +33,17 @@
import unittest
from sample import *
+from helper import objectFullname
class TestEnumUnderNamespace(unittest.TestCase):
def testInvisibleNamespace(self):
o1 = EnumOnNamespace.Option1
self.assertEqual(o1, 1)
+ def testTpNames(self):
+ self.assertEqual(objectFullname(EnumOnNamespace), "sample.EnumOnNamespace")
+ self.assertEqual(str(EnumOnNamespace.Option1),
+ "sample.EnumOnNamespace.Option1")
class TestClassesUnderNamespace(unittest.TestCase):
def testIt(self):
@@ -65,5 +70,19 @@ class TestClassesUnderNamespace(unittest.TestCase):
self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum),
"<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum'>")
+ # Test if enum inside of class is correct represented
+ self.assertEqual(objectFullname(SampleNamespace.enumInEnumOut.__signature__.parameters['in_'].annotation),
+ "sample.SampleNamespace.InValue")
+ self.assertEqual(objectFullname(SampleNamespace.enumAsInt.__signature__.parameters['value'].annotation),
+ "sample.SampleNamespace.SomeClass.PublicScopedEnum")
+ self.assertEqual(objectFullname(ObjectOnInvisibleNamespace.toInt.__signature__.parameters['e'].annotation),
+ "sample.EnumOnNamespace")
+
+ # Test if enum on namespace that was marked as not gerenated does not appear on type name
+ self.assertEqual(objectFullname(ObjectOnInvisibleNamespace),
+ "sample.ObjectOnInvisibleNamespace")
+ self.assertEqual(objectFullname(ObjectOnInvisibleNamespace.consume.__signature__.parameters['other'].annotation),
+ "sample.ObjectOnInvisibleNamespace")
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken2/tests/samplebinding/renaming_test.py b/sources/shiboken2/tests/samplebinding/renaming_test.py
new file mode 100644
index 000000000..1fe42578d
--- /dev/null
+++ b/sources/shiboken2/tests/samplebinding/renaming_test.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+#############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+'''Test cases for renaming using target-lang-name attribute.'''
+
+import re
+import unittest
+
+from sample import RenamedValue, RenamedUser
+
+class RenamingTest(unittest.TestCase):
+ def test(self):
+ '''Tests whether the C++ class ToBeRenamedValue renamed via attribute
+ target-lang-name to RenamedValue shows up in consuming function
+ signature strings correctly.
+ '''
+ renamed_value = RenamedValue()
+ self.assertEqual(str(type(renamed_value)),
+ "<class 'sample.RenamedValue'>")
+ rename_user = RenamedUser()
+ rename_user.useRenamedValue(renamed_value)
+ actual_signature = str(rename_user.useRenamedValue.__signature__)
+ self.assertTrue(re.match(r"^\(self,\s*v:\s*sample.RenamedValue\)$",
+ actual_signature))
+
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
index 30ad5def7..c3db91324 100644
--- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
@@ -543,8 +543,9 @@
<enum-type identified-by-value="AnonymousGlobalEnum_Value0"/>
- <namespace-type name="Invisible" generate="no">
+ <namespace-type name="Invisible" visible="no">
<enum-type name="EnumOnNamespace" />
+ <value-type name="ObjectOnInvisibleNamespace" />
</namespace-type>
<namespace-type name="SampleNamespace">
@@ -2432,6 +2433,9 @@
<modify-function signature="dummy(std::list&lt;std::pair&lt;BlackBox *, BlackBox *&gt; &gt; &amp;)" rename="dummy_method" />
</object-type>
+ <value-type name="ToBeRenamedValue" target-lang-name="RenamedValue"/>
+ <value-type name="RenamedUser"/>
+
<suppress-warning text="horribly broken type '__off64_t'" />
<suppress-warning text="enum '__codecvt_result' does not have a type entry or is not an enum" />
<suppress-warning text="Pure virtual method &quot;Abstract::hideFunction(HideType*)&quot; must be implement but was completely removed on typesystem." />
diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
index e1883c7cc..6c4c2c8e9 100644
--- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
+++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
@@ -116,6 +116,10 @@ class SmartPointerTests(unittest.TestCase):
self.assertEqual(integer.m_int, 50)
# Set and get a member value via shared pointer (like operator->).
+ ptrToInteger.setValue(150)
+ self.assertEqual(ptrToInteger.value(), 150)
+
+ # Set and get a member field via shared pointer (like operator->).
ptrToInteger.m_int = 100
self.assertEqual(ptrToInteger.m_int, 100)
@@ -143,6 +147,18 @@ class SmartPointerTests(unittest.TestCase):
self.assertEqual(objCount(), 0)
self.assertEqual(integerCount(), 0)
+ def testConstIntegerSmartPointer(self):
+ # Uncomment to see more debug info about creation of objects and ref counts.
+ # Registry.getInstance().setShouldPrint(True)
+
+ # Create Obj.
+ o = Obj()
+ ptrToConstInteger = o.giveSharedPtrToConstInteger()
+ self.assertEqual(ptrToConstInteger.m_int, 456)
+ result = o.takeSharedPtrToConstInteger(ptrToConstInteger)
+ self.assertEqual(result, 456)
+ self.assertEqual(ptrToConstInteger.value(), 456)
+
def testSmartPointersWithNamespace(self):
# Create the main object
o = Obj()