aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-07 16:04:40 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:09 -0300
commit6bd9d58b31cabedbce5131548d2447341df76e21 (patch)
tree09308a40e9d4a013c6eaba166d165ad7cbf64135 /generator
parent6f46f59f67c0d90fa184d9baf0c7a3f29d9e9865 (diff)
Improved the generation of type indexes written to the generated module header.
Now classes that are typedefs to template class instantiations are written twice with the same index: one with the aliased name, and other with the name composed of template and template arguments.
Diffstat (limited to 'generator')
-rw-r--r--generator/headergenerator.cpp22
-rw-r--r--generator/shibokengenerator.cpp50
-rw-r--r--generator/shibokengenerator.h9
3 files changed, 68 insertions, 13 deletions
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index 6390de557..7cbf6b2ea 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -286,16 +286,28 @@ void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* ty
}
}
+static void _writeTypeIndexDefineLine(QTextStream& s, const QString& variableName, int typeIndex)
+{
+ s << "#define ";
+ s.setFieldWidth(60);
+ s << variableName;
+ s.setFieldWidth(0);
+ s << ' ' << typeIndex << endl;
+}
void HeaderGenerator::writeTypeIndexDefineLine(QTextStream& s, const TypeEntry* typeEntry)
{
if (!typeEntry || !typeEntry->generateCode())
return;
s.setFieldAlignment(QTextStream::AlignLeft);
- s << "#define ";
- s.setFieldWidth(60);
- s << getTypeIndexVariableName(typeEntry);
- s.setFieldWidth(0);
- s << ' ' << getTypeIndex(typeEntry) << endl;
+ int typeIndex = getTypeIndex(typeEntry);
+ _writeTypeIndexDefineLine(s, getTypeIndexVariableName(typeEntry), typeIndex);
+ if (typeEntry->isComplex()) {
+ const ComplexTypeEntry* cType = reinterpret_cast<const ComplexTypeEntry*>(typeEntry);
+ if (cType->baseContainerType()) {
+ const AbstractMetaClass* metaClass = classes().findClass(cType);
+ _writeTypeIndexDefineLine(s, getTypeIndexVariableName(metaClass, true), typeIndex);
+ }
+ }
if (typeEntry->isEnum()) {
const EnumTypeEntry* ete = reinterpret_cast<const EnumTypeEntry*>(typeEntry);
if (ete->flags())
diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp
index 54e5b2a2e..9ec21a42f 100644
--- a/generator/shibokengenerator.cpp
+++ b/generator/shibokengenerator.cpp
@@ -734,6 +734,11 @@ QString ShibokenGenerator::cpythonTypeNameExt(const TypeEntry* type)
return cppApiVariableName(type->targetLangPackage()) + '[' + getTypeIndexVariableName(type) + ']';
}
+QString ShibokenGenerator::cpythonTypeNameExt(const AbstractMetaType* type)
+{
+ return cppApiVariableName(type->typeEntry()->targetLangPackage()) + '[' + getTypeIndexVariableName(type) + ']';
+}
+
QString ShibokenGenerator::cpythonOperatorFunctionName(const AbstractMetaFunction* func)
{
if (!func->isOperatorOverload())
@@ -1868,15 +1873,45 @@ QString ShibokenGenerator::cppApiVariableName(const QString& moduleName) const
return result;
}
+static QString _fixedCppTypeName(QString typeName)
+{
+ return typeName.replace(" ", "")
+ .replace(".", "_")
+ .replace("<", "_")
+ .replace(">", "_")
+ .replace("::", "_")
+ .replace("*", "PTR")
+ .replace("&", "REF");
+}
+
+static QString processInstantiationsVariableName(const AbstractMetaType* type)
+{
+ QString res = QString("_%1").arg(_fixedCppTypeName(type->typeEntry()->qualifiedCppName()).toUpper());
+ foreach (const AbstractMetaType* instantiation, type->instantiations())
+ res += processInstantiationsVariableName(instantiation);
+ return res;
+}
+QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass* metaClass, bool alternativeTemplateName)
+{
+ if (alternativeTemplateName) {
+ const AbstractMetaClass* templateBaseClass = metaClass->templateBaseClass();
+ if (!templateBaseClass)
+ return QString();
+ QString base = _fixedCppTypeName(templateBaseClass->typeEntry()->qualifiedCppName()).toUpper();
+ QString instantiations;
+ foreach (const AbstractMetaType* instantiation, metaClass->templateBaseClassInstantiations())
+ instantiations += processInstantiationsVariableName(instantiation);
+ return QString("SBK_%1%2_IDX").arg(base).arg(instantiations);
+ }
+ return getTypeIndexVariableName(metaClass->typeEntry());
+}
QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry* type)
{
- QString res("SBK_");
- res += type->qualifiedCppName();
- res.replace("::", "_");
- res.replace("<", "_");
- res.replace(">", "_");
- res += "_IDX";
- return res.toUpper();
+ return QString("SBK_%1_IDX").arg(_fixedCppTypeName(type->qualifiedCppName()).toUpper());
+}
+QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaType* type)
+{
+ return QString("SBK%1_IDX").arg(processInstantiationsVariableName(type));
}
bool ShibokenGenerator::verboseErrorMessagesDisabled() const
@@ -1884,7 +1919,6 @@ bool ShibokenGenerator::verboseErrorMessagesDisabled() const
return m_verboseErrorMessagesDisabled;
}
-
bool ShibokenGenerator::pythonFunctionWrapperUsesListOfArguments(const OverloadData& overloadData)
{
if (overloadData.referenceFunction()->isCallOperator())
diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h
index 3139399e3..e103b3f42 100644
--- a/generator/shibokengenerator.h
+++ b/generator/shibokengenerator.h
@@ -297,6 +297,7 @@ public:
QString cpythonTypeName(const AbstractMetaClass* metaClass);
QString cpythonTypeName(const TypeEntry* type);
QString cpythonTypeNameExt(const TypeEntry* type);
+ QString cpythonTypeNameExt(const AbstractMetaType* type);
QString cpythonCheckFunction(const TypeEntry* type, bool genericNumberType = false);
QString cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType = false);
/**
@@ -370,7 +371,15 @@ public:
/// Returns true if the generated code should use the "#define protected public" hack.
bool avoidProtectedHack() const;
QString cppApiVariableName(const QString& moduleName = QString()) const;
+ /**
+ * Returns the type index variable name for a given class. If \p alternativeTemplateName is true
+ * and the class is a typedef for a template class instantiation, it will return an alternative name
+ * made of the template class and the instantiation values, or an empty string if the class isn't
+ * derived from a template class at all.
+ */
+ QString getTypeIndexVariableName(const AbstractMetaClass* metaClass, bool alternativeTemplateName = false);
QString getTypeIndexVariableName(const TypeEntry* type);
+ QString getTypeIndexVariableName(const AbstractMetaType* type);
/// Returns true if the user don't want verbose error messages on the generated bindings.
bool verboseErrorMessagesDisabled() const;