summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-02-10 12:47:19 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-02-10 14:07:17 -0300
commitb1b32623845a15e6c20ac229c3f9fef7c7b2124a (patch)
treee1f184d9b0c1fddc98dd0f31f66462ccb0dcebd8
parente5fc9e22416603a976873f22f99af365bf5bd928 (diff)
downloadshiboken-b1b32623845a15e6c20ac229c3f9fef7c7b2124a.tar.gz
shiboken-b1b32623845a15e6c20ac229c3f9fef7c7b2124a.tar.xz
shiboken-b1b32623845a15e6c20ac229c3f9fef7c7b2124a.zip
Overloaded call decision now consider inheritance: inheritor is checked before ancestor.
A couple of ShibokenGenerator methods were made "const" to allow them to be called from OverloadDecisor. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--generator/overloaddata.cpp39
-rw-r--r--generator/shibokengenerator.cpp4
-rw-r--r--generator/shibokengenerator.h4
3 files changed, 29 insertions, 18 deletions
diff --git a/generator/overloaddata.cpp b/generator/overloaddata.cpp
index f8fd831f..3a32c94d 100644
--- a/generator/overloaddata.cpp
+++ b/generator/overloaddata.cpp
@@ -238,6 +238,7 @@ void OverloadData::sortNextOverloads()
foreach(OverloadData* ov, m_nextOverloadData) {
const AbstractMetaType* targetType = ov->argType();
const QString targetTypeEntryName(getTypeName(ov));
+ int targetTypeId = sortData.map[targetTypeEntryName];
// Process implicit conversions
foreach(AbstractMetaFunction* function, m_generator->implicitConversions(targetType)) {
@@ -253,7 +254,6 @@ void OverloadData::sortNextOverloads()
if (!sortData.map.contains(convertibleType))
continue;
- int targetTypeId = sortData.map[targetTypeEntryName];
int convertibleTypeId = sortData.map[convertibleType];
// If a reverse pair already exists, remove it. Probably due to the
@@ -262,28 +262,39 @@ void OverloadData::sortNextOverloads()
graph.addEdge(convertibleTypeId, targetTypeId);
}
+ // Process inheritance relationships
+ if (targetType->isValue() || targetType->isObject()) {
+ const AbstractMetaClass* metaClass = m_generator->classes().findClass(targetType->typeEntry());
+ foreach (const AbstractMetaClass* ancestor, m_generator->getAllAncestors(metaClass)) {
+ QString ancestorTypeName = ancestor->typeEntry()->name();
+ if (!sortData.map.contains(ancestorTypeName))
+ continue;
+ int ancestorTypeId = sortData.map[ancestorTypeName];
+ graph.removeEdge(ancestorTypeId, targetTypeId);
+ graph.addEdge(targetTypeId, ancestorTypeId);
+ }
+ }
// Process template instantiations
foreach (const AbstractMetaType* instantiation, targetType->instantiations()) {
if (sortData.map.contains(getTypeName(instantiation))) {
- int target = sortData.map[targetTypeEntryName];
int convertible = sortData.map[getTypeName(instantiation)];
- if (!graph.containsEdge(target, convertible)) // Avoid cyclic dependency.
- graph.addEdge(convertible, target);
+ if (!graph.containsEdge(targetTypeId, convertible)) // Avoid cyclic dependency.
+ graph.addEdge(convertible, targetTypeId);
if (instantiation->isPrimitive() && (signedIntegerPrimitives.contains(instantiation->name()))) {
foreach (const QString& primitive, nonIntegerPrimitives) {
QString convertibleTypeName = getImplicitConversionTypeName(ov->argType(), instantiation, 0, primitive);
- if (!graph.containsEdge(target, sortData.map[convertibleTypeName])) // Avoid cyclic dependency.
- graph.addEdge(sortData.map[convertibleTypeName], target);
+ if (!graph.containsEdge(targetTypeId, sortData.map[convertibleTypeName])) // Avoid cyclic dependency.
+ graph.addEdge(sortData.map[convertibleTypeName], targetTypeId);
}
} else {
foreach (const AbstractMetaFunction* function, m_generator->implicitConversions(instantiation)) {
QString convertibleTypeName = getImplicitConversionTypeName(ov->argType(), instantiation, function);
- if (!graph.containsEdge(target, sortData.map[convertibleTypeName])) // Avoid cyclic dependency.
- graph.addEdge(sortData.map[convertibleTypeName], target);
+ if (!graph.containsEdge(targetTypeId, sortData.map[convertibleTypeName])) // Avoid cyclic dependency.
+ graph.addEdge(sortData.map[convertibleTypeName], targetTypeId);
}
}
}
@@ -291,20 +302,20 @@ void OverloadData::sortNextOverloads()
/* Add dependency on PyObject, so its check is the last one (too generic) */
if (checkPyObject && !targetTypeEntryName.contains("PyObject")) {
- graph.addEdge(sortData.map[targetTypeEntryName], pyobjectIndex);
+ graph.addEdge(targetTypeId, pyobjectIndex);
} else if (checkQVariant && targetTypeEntryName != "QVariant") {
- if (!graph.containsEdge(qvariantIndex, sortData.map[targetTypeEntryName])) // Avoid cyclic dependency.
- graph.addEdge(sortData.map[targetTypeEntryName], qvariantIndex);
+ if (!graph.containsEdge(qvariantIndex, targetTypeId)) // Avoid cyclic dependency.
+ graph.addEdge(targetTypeId, qvariantIndex);
} else if (checkQString && ov->argType()->indirections() > 0 && targetTypeEntryName != "QString" && targetTypeEntryName != "QByteArray") {
- if (!graph.containsEdge(qstringIndex, sortData.map[targetTypeEntryName])) // Avoid cyclic dependency.
- graph.addEdge(sortData.map[targetTypeEntryName], qstringIndex);
+ if (!graph.containsEdge(qstringIndex, targetTypeId)) // Avoid cyclic dependency.
+ graph.addEdge(targetTypeId, qstringIndex);
}
if (targetType->isEnum()) {
// Enum values must precede primitive types.
for (int i = 0; i < numPrimitives; ++i) {
if (hasPrimitive[i])
- graph.addEdge(sortData.map[targetTypeEntryName], sortData.map[primitiveTypes[i]]);
+ graph.addEdge(targetTypeId, sortData.map[primitiveTypes[i]]);
}
}
}
diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp
index 381e99e0..79b19bce 100644
--- a/generator/shibokengenerator.cpp
+++ b/generator/shibokengenerator.cpp
@@ -1462,7 +1462,7 @@ AbstractMetaFunctionList ShibokenGenerator::getMethodsWithBothStaticAndNonStatic
return methods;
}
-AbstractMetaClassList ShibokenGenerator::getBaseClasses(const AbstractMetaClass* metaClass)
+AbstractMetaClassList ShibokenGenerator::getBaseClasses(const AbstractMetaClass* metaClass) const
{
AbstractMetaClassList baseClasses;
foreach (QString parent, metaClass->baseClassNames()) {
@@ -1482,7 +1482,7 @@ const AbstractMetaClass* ShibokenGenerator::getMultipleInheritingClass(const Abs
return getMultipleInheritingClass(metaClass->baseClass());
}
-AbstractMetaClassList ShibokenGenerator::getAllAncestors(const AbstractMetaClass* metaClass)
+AbstractMetaClassList ShibokenGenerator::getAllAncestors(const AbstractMetaClass* metaClass) const
{
AbstractMetaClassList result;
AbstractMetaClassList baseClasses = getBaseClasses(metaClass);
diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h
index 218bc461..a238b2c0 100644
--- a/generator/shibokengenerator.h
+++ b/generator/shibokengenerator.h
@@ -189,10 +189,10 @@ public:
AbstractMetaFunctionList getMethodsWithBothStaticAndNonStaticMethods(const AbstractMetaClass* metaClass);
/// Returns a list of parent classes for a given class.
- AbstractMetaClassList getBaseClasses(const AbstractMetaClass* metaClass);
+ AbstractMetaClassList getBaseClasses(const AbstractMetaClass* metaClass) const;
/// Returns a list of all ancestor classes for the given class.
- AbstractMetaClassList getAllAncestors(const AbstractMetaClass* metaClass);
+ AbstractMetaClassList getAllAncestors(const AbstractMetaClass* metaClass) const;
const AbstractMetaClass* getMultipleInheritingClass(const AbstractMetaClass* metaClass);