summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generator.cpp59
-rw-r--r--generator.h7
2 files changed, 65 insertions, 1 deletions
diff --git a/generator.cpp b/generator.cpp
index ee15d2f..df8c721 100644
--- a/generator.cpp
+++ b/generator.cpp
@@ -40,12 +40,16 @@ struct Generator::GeneratorPrivate {
QString packageName;
int numGenerated;
int numGeneratedWritten;
+ QStringList instantiatedContainersNames;
+ QList<const AbstractMetaType*> instantiatedContainers;
};
Generator::Generator() : m_d(new GeneratorPrivate)
{
m_d->numGenerated = 0;
m_d->numGeneratedWritten = 0;
+ m_d->instantiatedContainers = QList<const AbstractMetaType*>();
+ m_d->instantiatedContainersNames = QStringList();
}
Generator::~Generator()
@@ -68,14 +72,67 @@ bool Generator::setup(const ApiExtractor& extractor, const QMap< QString, QStrin
if (entryFound)
break;
}
-
if (entryFound)
m_d->packageName = entryFound->name();
else
ReportHandler::warning("Couldn't find the package name!!");
+
+ collectInstantiatedContainers();
+
return doSetup(args);
}
+QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType* type)
+{
+ if (!type->isContainer())
+ return type->cppSignature();
+ QString typeName = type->cppSignature();
+ if (type->isConstant())
+ typeName.remove(0, sizeof("const ") / sizeof(char) - 1);
+ if (type->isReference())
+ typeName.chop(1);
+ while (typeName.endsWith('*') || typeName.endsWith(' '))
+ typeName.chop(1);
+ return typeName;
+}
+
+void Generator::addInstantiatedContainers(const AbstractMetaType* type)
+{
+ if (!type)
+ return;
+ foreach (const AbstractMetaType* t, type->instantiations())
+ addInstantiatedContainers(t);
+ if (!type->typeEntry()->isContainer())
+ return;
+ QString typeName = getSimplifiedContainerTypeName(type);
+ if (!m_d->instantiatedContainersNames.contains(typeName)) {
+ m_d->instantiatedContainersNames.append(typeName);
+ m_d->instantiatedContainers.append(type);
+ }
+}
+
+void Generator::collectInstantiatedContainers(const AbstractMetaFunction* func)
+{
+ addInstantiatedContainers(func->type());
+ foreach (const AbstractMetaArgument* arg, func->arguments())
+ addInstantiatedContainers(arg->type());
+}
+
+void Generator::collectInstantiatedContainers()
+{
+ foreach (const AbstractMetaFunction* func, globalFunctions())
+ collectInstantiatedContainers(func);
+ foreach (const AbstractMetaClass* metaClass, classes()) {
+ foreach (const AbstractMetaFunction* func, metaClass->functions())
+ collectInstantiatedContainers(func);
+ }
+}
+
+QList<const AbstractMetaType*> Generator::instantiatedContainers() const
+{
+ return m_d->instantiatedContainers;
+}
+
QMap< QString, QString > Generator::options() const
{
return QMap<QString, QString>();
diff --git a/generator.h b/generator.h
index 4c20268..59cef78 100644
--- a/generator.h
+++ b/generator.h
@@ -277,9 +277,16 @@ protected:
*/
virtual QString subDirectoryForPackage(QString packageName = QString()) const;
+ QList<const AbstractMetaType*> instantiatedContainers() const;
+
+ static QString getSimplifiedContainerTypeName(const AbstractMetaType* type);
+ void addInstantiatedContainers(const AbstractMetaType* type);
+
private:
struct GeneratorPrivate;
GeneratorPrivate* m_d;
+ void collectInstantiatedContainers(const AbstractMetaFunction* func);
+ void collectInstantiatedContainers();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Generator::Options)