aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp76
-rw-r--r--cppgenerator.h1
-rw-r--r--headergenerator.cpp88
-rw-r--r--headergenerator.h1
4 files changed, 83 insertions, 83 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 6612a7e5..458b4ca7 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -156,7 +156,6 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl
if (!metaClass->isNamespace()) {
Indentation indentation(INDENT);
- writeTypeConverterImpl(convImpl, metaClass->typeEntry());
writeSbkCopyCppObjectFunction(copyImpl, metaClass);
}
@@ -334,14 +333,12 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl
foreach (AbstractMetaEnum* cppEnum, metaClass->enums()) {
bool hasFlags = cppEnum->typeEntry()->flags();
if (hasFlags) {
- writeTypeConverterImpl(convImpl, cppEnum->typeEntry()->flags());
writeFlagsMethods(s, cppEnum);
writeFlagsNumberMethodsDefinition(s, cppEnum);
s << endl;
}
writeEnumDefinition(s, cppEnum);
- writeTypeConverterImpl(convImpl, cppEnum->typeEntry());
if (hasFlags) {
// Write Enum as Flags definition (at the moment used only by QFlags<enum>)
@@ -2584,78 +2581,6 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
s << '}' << endl << endl;
}
-void CppGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* type)
-{
- if (type->hasConversionRule())
- return;
-
- QString pyTypeName = cpythonTypeName(type);
-
- AbstractMetaFunctionList implicitConvs;
- foreach (AbstractMetaFunction* func, implicitConversions(type)) {
- if (!func->isUserAdded())
- implicitConvs << func;
- }
-
- bool hasImplicitConversions = !implicitConvs.isEmpty();
-
- if (hasImplicitConversions) {
- // Write Converter<T>::isConvertible
- s << "bool Converter<" << type->name() << " >::isConvertible(PyObject* pyobj)" << endl;
- s << '{' << endl;
- s << INDENT << "return ";
- bool isFirst = true;
- foreach (const AbstractMetaFunction* ctor, implicitConvs) {
- Indentation indent(INDENT);
- if (isFirst)
- isFirst = false;
- else
- s << endl << INDENT << " || ";
- s << cpythonCheckFunction(ctor->arguments().first()->type());
- s << "(pyobj)";
- }
- s << ';' << endl;
- s << '}' << endl << endl;
- }
-
- // A specialized Converter<T>::toCpp method is only need for
- // value-types with implicit conversions.
- if (!type->isValue() || !hasImplicitConversions)
- return;
-
- // Write Converter<T>::toCpp function
- s << type->name() << " Converter<" << type->name() << " >::toCpp(PyObject* pyobj)" << endl;
- s << '{' << endl;
-
- if (!implicitConvs.isEmpty()) {
- s << INDENT << "if (!Shiboken_TypeCheck(pyobj, " << type->name() << ")) {" << endl;
- bool firstImplicitIf = true;
- foreach (const AbstractMetaFunction* ctor, implicitConvs) {
- if (ctor->isModifiedRemoved())
- continue;
-
- Indentation indent(INDENT);
- s << INDENT;
-
- const AbstractMetaType* argType = ctor->arguments().first()->type();
- if (firstImplicitIf)
- firstImplicitIf = false;
- else
- s << "else ";
- s << "if (" << cpythonCheckFunction(argType) << "(pyobj))" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "return " << type->name() << '(';
- writeBaseConversion(s, argType, 0);
- s << "toCpp(pyobj));" << endl;
- }
- }
- s << INDENT << '}' << endl;
- }
-
- s << INDENT << "return *" << cpythonWrapperCPtr(type, "pyobj") << ';' << endl;
- s << '}' << endl << endl;
-}
void CppGenerator::writeTypeNameFunction(QTextStream& s, const AbstractMetaClass* metaClass)
{
Indentation indent(INDENT);
@@ -2815,7 +2740,6 @@ void CppGenerator::finishGeneration()
s << "// Enum definitions ";
s << "------------------------------------------------------------" << endl;
foreach (const AbstractMetaEnum* cppEnum, globalEnums()) {
- writeTypeConverterImpl(convImpl, cppEnum->typeEntry());
writeEnumDefinition(s, cppEnum);
s << endl;
}
diff --git a/cppgenerator.h b/cppgenerator.h
index 7ed0ee5e..a8d45344 100644
--- a/cppgenerator.h
+++ b/cppgenerator.h
@@ -68,7 +68,6 @@ private:
void writeTypeCheck(QTextStream& s, const AbstractMetaType* argType, QString argumentName, bool isNumber = false, QString customType = "");
void writeTypeCheck(QTextStream& s, const OverloadData* overloadData, QString argumentName);
- void writeTypeConverterImpl(QTextStream& s, const TypeEntry* type);
void writeTypeNameFunction(QTextStream& s, const AbstractMetaClass* metaClass);
void writeSbkCopyCppObjectFunction(QTextStream& s, const AbstractMetaClass* metaClass);
diff --git a/headergenerator.cpp b/headergenerator.cpp
index 9d483bed..ea590a1e 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -165,10 +165,7 @@ void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* ty
}
bool isValueTypeWithImplConversions = type->isValue() && !implicitConvs.isEmpty();
- s << "struct ";
- if (isValueTypeWithImplConversions)
- s << getApiExportMacro() << ' ';
- s << "Converter<" << type->name() << (isAbstractOrObjectType ? "*" : "") << " > : ";
+ s << "struct Converter<" << type->name() << (isAbstractOrObjectType ? "*" : "") << " > : ";
if (type->isEnum() || type->isFlags())
s << "Converter_CppEnum";
else
@@ -226,6 +223,8 @@ void HeaderGenerator::finishGeneration()
QTextStream convDecl(&convertersDecl);
QString sbkTypeFunctions;
QTextStream typeFunctions(&sbkTypeFunctions);
+ QString converterImpl;
+ QTextStream convImpl(&converterImpl);
Indentation indent(INDENT);
@@ -282,16 +281,17 @@ void HeaderGenerator::finishGeneration()
if (!metaClass->isNamespace()) {
writeSbkTypeFunction(typeFunctions, metaClass);
- writeSbkCopyCppObjectFunction(typeFunctions, metaClass);
+ writeSbkCopyCppObjectFunction(convDecl, metaClass);
foreach (AbstractMetaClass* innerClass, metaClass->innerClasses()) {
if (shouldGenerate(innerClass)) {
- writeSbkCopyCppObjectFunction(typeFunctions, innerClass);
+ writeSbkCopyCppObjectFunction(convDecl, innerClass);
s_cin << innerClass->typeEntry()->include().toString() << endl;
writeTypeCheckMacro(s_pts, innerClass->typeEntry());
s_pts << "#define " << cpythonWrapperCPtr(innerClass, "pyobj") << " ((";
s_pts << innerClass->qualifiedCppName() << "*)SbkBaseWrapper_cptr(pyobj))" << endl << endl;
writeTypeConverterDecl(convDecl, innerClass->typeEntry());
+ writeTypeConverterImpl(convImpl, innerClass->typeEntry());
convDecl << endl;
writeSbkTypeFunction(typeFunctions, innerClass);
}
@@ -300,6 +300,7 @@ void HeaderGenerator::finishGeneration()
s_pts << "#define " << cpythonWrapperCPtr(metaClass, "pyobj") << " ((";
s_pts << metaClass->qualifiedCppName() << "*)SbkBaseWrapper_cptr(pyobj))" << endl << endl;
writeTypeConverterDecl(convDecl, classType);
+ writeTypeConverterImpl(convImpl, classType);
convDecl << endl;
}
}
@@ -389,6 +390,8 @@ void HeaderGenerator::finishGeneration()
}
s << "} // namespace Shiboken" << endl << endl;
+ s << "// Generated converters implemantations -------------------------------" << endl << endl;
+ s << converterImpl << endl;
s << "#endif // " << includeShield << endl << endl;
}
@@ -445,3 +448,76 @@ void HeaderGenerator::writeSbkCopyCppObjectFunction(QTextStream& s, const Abstra
s << "};" << endl;
}
+void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* type)
+{
+ if (type->hasConversionRule())
+ return;
+
+ QString pyTypeName = cpythonTypeName(type);
+
+ AbstractMetaFunctionList implicitConvs;
+ foreach (AbstractMetaFunction* func, implicitConversions(type)) {
+ if (!func->isUserAdded())
+ implicitConvs << func;
+ }
+
+ bool hasImplicitConversions = !implicitConvs.isEmpty();
+
+ if (hasImplicitConversions) {
+ // Write Converter<T>::isConvertible
+ s << "inline bool Shiboken::Converter<" << type->name() << " >::isConvertible(PyObject* pyobj)" << endl;
+ s << '{' << endl;
+ s << INDENT << "return ";
+ bool isFirst = true;
+ foreach (const AbstractMetaFunction* ctor, implicitConvs) {
+ Indentation indent(INDENT);
+ if (isFirst)
+ isFirst = false;
+ else
+ s << endl << INDENT << " || ";
+ s << cpythonCheckFunction(ctor->arguments().first()->type());
+ s << "(pyobj)";
+ }
+ s << ';' << endl;
+ s << '}' << endl << endl;
+ }
+
+ // A specialized Converter<T>::toCpp method is only need for
+ // value-types with implicit conversions.
+ if (!type->isValue() || !hasImplicitConversions)
+ return;
+
+ // Write Converter<T>::toCpp function
+ s << "inline " << type->name() << " Shiboken::Converter<" << type->name() << " >::toCpp(PyObject* pyobj)" << endl;
+ s << '{' << endl;
+
+ if (!implicitConvs.isEmpty()) {
+ s << INDENT << "if (!Shiboken_TypeCheck(pyobj, " << type->name() << ")) {" << endl;
+ bool firstImplicitIf = true;
+ foreach (const AbstractMetaFunction* ctor, implicitConvs) {
+ if (ctor->isModifiedRemoved())
+ continue;
+
+ Indentation indent(INDENT);
+ s << INDENT;
+
+ const AbstractMetaType* argType = ctor->arguments().first()->type();
+ if (firstImplicitIf)
+ firstImplicitIf = false;
+ else
+ s << "else ";
+ s << "if (" << cpythonCheckFunction(argType) << "(pyobj))" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "return " << type->name() << '(';
+ writeToCppConversion(s, argType, 0, "pyobj");
+ s << ");" << endl;
+ }
+ }
+ s << INDENT << '}' << endl;
+ }
+
+ s << INDENT << "return *" << cpythonWrapperCPtr(type, "pyobj") << ';' << endl;
+ s << '}' << endl << endl;
+}
+
diff --git a/headergenerator.h b/headergenerator.h
index 67791999..0e7fe4eb 100644
--- a/headergenerator.h
+++ b/headergenerator.h
@@ -49,6 +49,7 @@ private:
void writeSbkCopyCppObjectFunction(QTextStream& s, const AbstractMetaClass* metaClass);
void writeTypeIndexDefineLine(QTextStream& s, const TypeEntry* typeEntry, int& idx);
void writeTypeIndexDefine(QTextStream& s, const AbstractMetaClass* metaClass, int& idx);
+ void writeTypeConverterImpl(QTextStream& s, const TypeEntry* type);
};