From dfd0bc442d5f3c04d03ee23606b399ed18d304f7 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Wed, 24 Aug 2011 17:54:56 -0300 Subject: Implement getTypeIndex function for types no generated types and primitive types. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Marcelo Lira Renato Araújo --- typedatabase.cpp | 60 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 17 deletions(-) (limited to 'typedatabase.cpp') diff --git a/typedatabase.cpp b/typedatabase.cpp index d5c1eb6ce..25933501f 100644 --- a/typedatabase.cpp +++ b/typedatabase.cpp @@ -430,8 +430,12 @@ void TypeDatabase::setDropTypeEntries(QStringList dropTypeEntries) // This global variable exists only because we can't break the ABI typedef QHash > TypeRevisionMap; Q_GLOBAL_STATIC(TypeRevisionMap, typeEntryFields); +// Hash of: packageName -> (max type index found, max primitive type index found) +typedef QMap > MaxTypeIndexes; +Q_GLOBAL_STATIC(MaxTypeIndexes, maxTypeIndexes); static bool computeTypeIndexes = true; -static int maxTypeIndex; +// This is kept for API compatibility issues with previous versions +int oldMaxTypeIndex; int getTypeRevision(const TypeEntry* typeEntry) { @@ -453,39 +457,51 @@ static void _computeTypeIndexes() { TypeDatabase* tdb = TypeDatabase::instance(); typedef QMap > GroupedTypeEntries; - GroupedTypeEntries groupedEntries; + typedef QHash GroupedPerPackageGroups; + GroupedPerPackageGroups groupsPerPackage; // Group type entries by revision numbers TypeEntryHash allEntries = tdb->allEntries(); + QString pkgName; + oldMaxTypeIndex = 0; foreach (QList entryList, allEntries) { foreach (TypeEntry* entry, entryList) { - if (entry->isPrimitive() + if (entry->isCppPrimitive() || entry->isContainer() || entry->isFunction() - || !entry->generateCode() || entry->isEnumValue() || entry->isVarargs() || entry->isTypeSystem() || entry->isVoid() || entry->isCustom()) continue; - groupedEntries[getTypeRevision(entry)] << entry; + + if (entry->generateCode() && !entry->isPrimitive()) + oldMaxTypeIndex++; + pkgName = entry->targetLangPackage(); + groupsPerPackage[pkgName][getTypeRevision(entry)] << entry; } } - maxTypeIndex = 0; - GroupedTypeEntries::iterator it = groupedEntries.begin(); - for (; it != groupedEntries.end(); ++it) { - // Remove duplicates - QList::iterator newEnd = std::unique(it.value().begin(), it.value().end()); - it.value().erase(newEnd, it.value().end()); - // Sort the type entries by name - qSort(it.value().begin(), newEnd, compareTypeEntriesByName); - - foreach (TypeEntry* entry, it.value()) { - (*typeEntryFields())[entry].second = maxTypeIndex++; + + GroupedPerPackageGroups::iterator pkg = groupsPerPackage.begin(); + for (; pkg != groupsPerPackage.end() ; ++pkg) { + GroupedTypeEntries::iterator it = pkg.value().begin(); + for (; it != pkg.value().end(); ++it) { + // Remove duplicates + QList::iterator newEnd = std::unique(it.value().begin(), it.value().end()); + it.value().erase(newEnd, it.value().end()); + // Sort the type entries by name + qSort(it.value().begin(), newEnd, compareTypeEntriesByName); + + foreach (TypeEntry* entry, it.value()) { + QPair& pair = (*maxTypeIndexes())[pkg.key()]; + int value = entry->isPrimitive() ? pair.second++ : pair.first++; + (*typeEntryFields())[entry].second = value; + } } } + computeTypeIndexes = false; } @@ -500,7 +516,17 @@ int getMaxTypeIndex() { if (computeTypeIndexes) _computeTypeIndexes(); - return maxTypeIndex; + return oldMaxTypeIndex; +} + +int getMaxTypeIndex(const QString& packageName) +{ + return maxTypeIndexes()->value(packageName).first - 1; +} + +int getMaxPrimitiveTypeIndex(const QString& packageName) +{ + return maxTypeIndexes()->value(packageName).second - 1; } void TypeDatabase::setApiVersion(const QString& package, const QByteArray& version) -- cgit v1.2.3