diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2009-11-21 18:00:17 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2009-11-25 13:16:37 -0300 |
commit | 8dcbf2b6ea6c79d0a984a0d87fb598c6d1fc62d8 (patch) | |
tree | 78d1ad81ee6e4e9d8d6ea01f3d0d1a3d99138d8a /overloaddata.cpp | |
parent | 133172661836d496856a190358c0d60ed64dd486 (diff) |
Improve overload sorting
Now adding a new dependency: If the overload type is a
container or template and the contained type is also in the
overload list, the contained type is checked first.
Added due to QList<String> and QString.
WARNING: Not sure yet if this is the best fix :)
Diffstat (limited to 'overloaddata.cpp')
-rw-r--r-- | overloaddata.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/overloaddata.cpp b/overloaddata.cpp index f73592952..dbc8ef496 100644 --- a/overloaddata.cpp +++ b/overloaddata.cpp @@ -34,7 +34,8 @@ * * This avoids using an implicit conversion if there's an explicit * overload for the convertible type. So, if there's an implicit convert - * like TargetType(ConvertibleType foo) and both + * like TargetType(ConvertibleType foo) and both are in the overload list, + * ConvertibleType is checked before TargetType. * * Side effects: Modifies m_nextOverloadData */ @@ -64,8 +65,28 @@ void OverloadData::sortOverloads() if (!map.contains(convertibleType->typeEntry()->name())) continue; - deps << qMakePair(map[targetType->typeEntry()->name()], - map[convertibleType->typeEntry()->name()]); + int target = map[targetType->typeEntry()->name()]; + int convertible = map[convertibleType->typeEntry()->name()]; + + // If a reverse pair already exists, remove it. Probably due to the + // container check (This happened to QVariant and QHash) + QPair<int, int> reversePair = qMakePair(convertible, target); + if (deps.contains(reversePair)) + deps.remove(reversePair); + + deps << qMakePair(target, convertible); + } + + if (targetType->hasInstantiations()) { + foreach(AbstractMetaType *instantiation, targetType->instantiations()) { + if (map.contains(instantiation->typeEntry()->name())) { + int target = map[targetType->typeEntry()->name()]; + int convertible = map[instantiation->typeEntry()->name()]; + + if (!deps.contains(qMakePair(convertible, target))) // Avoid cyclic dependency. + deps << qMakePair(target, convertible); + } + } } } |