aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generator.cpp97
-rw-r--r--generator.h152
-rw-r--r--generatorrunnermacros.h1
3 files changed, 137 insertions, 113 deletions
diff --git a/generator.cpp b/generator.cpp
index 58e1a0e13..cc7ef6f45 100644
--- a/generator.cpp
+++ b/generator.cpp
@@ -31,32 +31,39 @@
#include <QtCore/QFileInfo>
#include <QDebug>
-Generator::Generator() : m_numGenerated(0), m_numGeneratedWritten(0)
-{}
+struct Generator::GeneratorPrivate {
+ const ApiExtractor* apiextractor;
+ QString outDir;
+ // License comment
+ QString licenseComment;
+ QString packageName;
+ int numGenerated;
+ int numGeneratedWritten;
+};
+
+Generator::Generator() : m_d(new GeneratorPrivate)
+{
+ m_d->numGenerated = 0;
+ m_d->numGeneratedWritten = 0;
+}
Generator::~Generator()
{
+ delete m_d;
}
bool Generator::setup(const ApiExtractor& extractor, const QMap< QString, QString > args)
{
- m_globalEnums = extractor.globalEnums();
- m_globalFunctions = extractor.globalFunctions();
- m_classes = extractor.classes();
- m_primitiveTypes = extractor.primitiveTypes();
- m_containerTypes = extractor.containerTypes();
-
+ m_d->apiextractor = &extractor;
// FIXME: Avoid this ugly hack to get the package name.. and... why the name "package"!?
- foreach (const AbstractMetaClass* cppClass, m_classes) {
- if (m_packageName.isEmpty()
+ foreach (const AbstractMetaClass* cppClass, m_d->apiextractor->classes()) {
+ if (m_d->packageName.isEmpty()
&& cppClass->typeEntry()->generateCode()
&& !cppClass->package().isEmpty()) {
- m_packageName = cppClass->package();
+ m_d->packageName = cppClass->package();
break;
}
}
- // does anyone use this?
- m_qmetatypeDeclaredTypenames = extractor.qtMetaTypeDeclaredTypeNames();
return doSetup(args);
}
@@ -67,42 +74,78 @@ QMap< QString, QString > Generator::options() const
AbstractMetaClassList Generator::classes() const
{
- return m_classes;
+ return m_d->apiextractor->classes();
}
AbstractMetaFunctionList Generator::globalFunctions() const
{
- return m_globalFunctions;
+ return m_d->apiextractor->globalFunctions();
}
AbstractMetaEnumList Generator::globalEnums() const
{
- return m_globalEnums;
+ return m_d->apiextractor->globalEnums();
}
QList<const PrimitiveTypeEntry*> Generator::primitiveTypes() const
{
- return m_primitiveTypes;
+ return m_d->apiextractor->primitiveTypes();
}
QList<const ContainerTypeEntry*> Generator::containerTypes() const
{
- return m_containerTypes;
+ return m_d->apiextractor->containerTypes();
+}
+
+QSet< QString > Generator::qtMetaTypeDeclaredTypeNames() const
+{
+ return m_d->apiextractor->qtMetaTypeDeclaredTypeNames();
+}
+
+QString Generator::licenseComment() const
+{
+ return m_d->licenseComment;
+}
+
+void Generator::setLicenseComment(const QString& licenseComment)
+{
+ m_d->licenseComment = licenseComment;
+}
+
+QString Generator::packageName() const
+{
+ return m_d->packageName;
+}
+
+QString Generator::moduleName() const
+{
+ QString& pkgName = m_d->packageName;
+ return QString(pkgName).remove(0, pkgName.lastIndexOf('.') + 1);
}
QString Generator::outputDirectory() const
{
- return m_outDir;
+ return m_d->outDir;
}
void Generator::setOutputDirectory(const QString &outDir)
{
- m_outDir = outDir;
+ m_d->outDir = outDir;
+}
+
+int Generator::numGenerated() const
+{
+ return m_d->numGenerated;
+}
+
+int Generator::numGeneratedAndWritten() const
+{
+ return m_d->numGeneratedWritten;
}
void Generator::generate()
{
- foreach (AbstractMetaClass *cls, m_classes) {
+ foreach (AbstractMetaClass *cls, m_d->apiextractor->classes()) {
if (!shouldGenerate(cls))
continue;
@@ -115,8 +158,8 @@ void Generator::generate()
generateClass(fileOut.stream, cls);
if (fileOut.done())
- ++m_numGeneratedWritten;
- ++m_numGenerated;
+ ++m_d->numGeneratedWritten;
+ ++m_d->numGenerated;
}
finishGeneration();
}
@@ -126,7 +169,7 @@ bool Generator::shouldGenerate(const AbstractMetaClass* metaClass) const
return metaClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang;
}
-void Generator::verifyDirectoryFor(const QFile &file)
+void verifyDirectoryFor(const QFile &file)
{
QDir dir = QFileInfo(file).dir();
if (!dir.exists()) {
@@ -141,7 +184,7 @@ bool Generator::hasDefaultConstructor(const AbstractMetaType *type)
QString full_name = type->typeEntry()->qualifiedTargetLangName();
QString class_name = type->typeEntry()->targetLangName();
- foreach (const AbstractMetaClass *cls, m_classes) {
+ foreach (const AbstractMetaClass *cls, m_d->apiextractor->classes()) {
if (cls->typeEntry()->qualifiedTargetLangName() == full_name) {
AbstractMetaFunctionList functions = cls->functions();
foreach (const AbstractMetaFunction *function, functions) {
@@ -369,7 +412,7 @@ QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor)
return s;
}
-CodeSnipList Generator::getCodeSnips(const AbstractMetaFunction *func)
+CodeSnipList Generator::getCodeSnips(const AbstractMetaFunction *func) const
{
CodeSnipList result;
const AbstractMetaClass *cppClass = func->implementingClass();
@@ -444,7 +487,7 @@ QString Generator::subDirectoryForClass(const AbstractMetaClass* clazz) const
QString Generator::subDirectoryForPackage(QString packageName) const
{
if (packageName.isEmpty())
- packageName = m_packageName;
+ packageName = m_d->packageName;
return QString(packageName).replace(".", QDir::separator());
}
diff --git a/generator.h b/generator.h
index b16694de0..ee51cb87a 100644
--- a/generator.h
+++ b/generator.h
@@ -40,7 +40,10 @@ extern "C" GENRUNNER_API GeneratorList getGenerators()\
return GeneratorList() << X;\
}\
+GENRUNNER_API
QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor);
+GENRUNNER_API
+void verifyDirectoryFor(const QFile &file);
/**
* Base class for all generators. The default implementations does nothing,
@@ -98,12 +101,16 @@ public:
/// Returns the classes used to generate the binding code.
AbstractMetaClassList classes() const;
+ /// Returns all global functions found by APIExtractor
AbstractMetaFunctionList globalFunctions() const;
+ /// Returns all global enums found by APIExtractor
AbstractMetaEnumList globalEnums() const;
+ /// Returns all primitive types found by APIExtractor
QList<const PrimitiveTypeEntry*> primitiveTypes() const;
+ /// Returns all container types found by APIExtractor
QList<const ContainerTypeEntry*> containerTypes() const;
/// Returns the output directory
@@ -121,17 +128,12 @@ public:
void generate();
/// Returns the number of generated items
- int numGenerated()
- {
- return m_numGenerated;
- }
+ int numGenerated() const;
/// Returns the number of generated items written
- int numGeneratedAndWritten()
- {
- return m_numGeneratedWritten;
- }
+ int numGeneratedAndWritten() const;
+ /// Returns the generator's name. Used for cosmetic purposes.
virtual const char* name() const = 0;
/// Returns true if the generator should generate any code for the AbstractMetaClass
@@ -168,61 +170,33 @@ public:
void replaceTemplateVariables(QString &code, const AbstractMetaFunction *func);
- bool hasDefaultConstructor(const AbstractMetaType *type);
-
// QtScript
- QSet<QString> qtMetaTypeDeclaredTypeNames() const
- {
- return m_qmetatypeDeclaredTypenames;
- }
+ QSet<QString> qtMetaTypeDeclaredTypeNames() const;
/**
* Returns the license comment to be prepended to each source file generated.
*/
- QString licenseComment()
- {
- return m_licenseComment;
- }
+ QString licenseComment() const;
/**
* Sets the license comment to be prepended to each source file generated.
*/
- void setLicenseComment(const QString &licenseComment)
- {
- m_licenseComment = licenseComment;
- }
+ void setLicenseComment(const QString &licenseComment);
/**
* Returns the package name.
*/
- QString packageName()
- {
- return m_packageName;
- }
-
- /**
- * Sets the package name.
- */
- void setPackageName(const QString &packageName)
- {
- m_packageName = packageName;
- }
+ QString packageName() const;
/**
- * Retrieves the name of the currently processed module. While package name
- * is a complete package idetification, e.g. 'PySide.QtCore', a module name
- * represents the last part of the package, e.g. 'QtCore'.
- * If the target language separates the modules with characters other than
- * dots ('.') the generator subclass must overload this method.
- * /return a string representing the last part of a package name
+ * Retrieves the name of the currently processed module.
+ * While package name is a complete package idetification, e.g. 'PySide.QtCore',
+ * a module name represents the last part of the package, e.g. 'QtCore'.
+ * If the target language separates the modules with characters other than
+ * dots ('.') the generator subclass must overload this method.
+ * \return a string representing the last part of a package name
*/
- virtual QString moduleName() const
- {
- return QString(m_packageName).remove(0, m_packageName.lastIndexOf('.') + 1);
- }
-
- /// returns the code snips of a function
- CodeSnipList getCodeSnips(const AbstractMetaFunction *func);
+ virtual QString moduleName() const;
/**
* Retrieves a list of constructors used in implicit conversions
@@ -237,63 +211,70 @@ public:
AbstractMetaFunctionList implicitConversions(const AbstractMetaType* metaType) const;
protected:
- QString m_packageName;
-
/**
* Returns the file name used to write the binding code of an AbstractMetaClass.
- * /param metaClass the AbstractMetaClass for which the file name must be
+ * \param metaClass the AbstractMetaClass for which the file name must be
* returned
- * /return the file name used to write the binding code for the class
+ * \return the file name used to write the binding code for the class
*/
virtual QString fileNameForClass(const AbstractMetaClass* metaClass) const = 0;
- static FunctionModificationList functionModifications(const AbstractMetaFunction *meta_function);
- AbstractMetaFunctionList filterFunctions(const AbstractMetaClass *cppClass);
- AbstractMetaFunctionList queryFunctions(const AbstractMetaClass *cpp_class, bool all_function = false);
- AbstractMetaFunctionList queryGlobalOperators(const AbstractMetaClass *cpp_class);
- AbstractMetaFunctionList sortConstructor(AbstractMetaFunctionList list);
virtual bool doSetup(const QMap<QString, QString>& args) = 0;
/**
- * Returns the subdirectory path for a given package
- * (aka module, aka library) name.
- * If the target language separates the package modules with characters other
- * than dots ('.') the generator subclass must overload this method.
- * /param packageName complete package name for which to return the subdirectory path
- * or nothing the use the name of the currently processed package
- * /return a string representing the subdirectory path for the given package
- */
- virtual QString subDirectoryForPackage(QString packageName = QString()) const;
-
- /**
* Write the bindding code for an AbstractMetaClass.
- * This is called by the default implementation of generate method.
+ * This is called by generate method.
* \param s text stream to write the generated output
* \param metaClass the class that should be generated
*/
virtual void generateClass(QTextStream& s, const AbstractMetaClass* metaClass) = 0;
virtual void finishGeneration() = 0;
- void verifyDirectoryFor(const QFile &file);
+ /**
+ * Returns the subdirectory path for a given package
+ * (aka module, aka library) name.
+ * If the target language separates the package modules with characters other
+ * than dots ('.') the generator subclass must overload this method.
+ * /param packageName complete package name for which to return the subdirectory path
+ * or nothing the use the name of the currently processed package
+ * /return a string representing the subdirectory path for the given package
+ */
+ virtual QString subDirectoryForPackage(QString packageName = QString()) const;
- int m_numGenerated;
- int m_numGeneratedWritten;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ static FunctionModificationList functionModifications(const AbstractMetaFunction *meta_function) GENRUNNER_DEPRECATED;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ AbstractMetaFunctionList filterFunctions(const AbstractMetaClass *cppClass) GENRUNNER_DEPRECATED;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ AbstractMetaFunctionList queryFunctions(const AbstractMetaClass *cpp_class, bool all_function = false) GENRUNNER_DEPRECATED;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ AbstractMetaFunctionList queryGlobalOperators(const AbstractMetaClass *cpp_class) GENRUNNER_DEPRECATED;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ AbstractMetaFunctionList sortConstructor(AbstractMetaFunctionList list) GENRUNNER_DEPRECATED;
+ /**
+ * Returns the code snips of a function
+ * \deprecated Use AbstractMetaFunction::injectedCodeSnips() instead.
+ */
+ CodeSnipList getCodeSnips(const AbstractMetaFunction *func) const GENRUNNER_DEPRECATED;
+ /**
+ * @deprecated This function doesn't belongs to the generator world and will sooner be moved to APIExtractor
+ */
+ bool hasDefaultConstructor(const AbstractMetaType *type) GENRUNNER_DEPRECATED;
private:
- AbstractMetaClassList m_classes;
- AbstractMetaFunctionList m_globalFunctions;
- AbstractMetaEnumList m_globalEnums;
- QString m_outDir;
-
- QList<const PrimitiveTypeEntry*> m_primitiveTypes;
- QList<const ContainerTypeEntry*> m_containerTypes;
-
- // QtScript
- QSet<QString> m_qmetatypeDeclaredTypenames;
-
- // License comment
- QString m_licenseComment;
+ struct GeneratorPrivate;
+ GeneratorPrivate* m_d;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Generator::Options)
@@ -305,8 +286,7 @@ typedef QLinkedList<Generator*> GeneratorList;
class GENRUNNER_API Indentor
{
public:
- Indentor():
- indent(0) {}
+ Indentor() : indent(0) {}
int indent;
};
diff --git a/generatorrunnermacros.h b/generatorrunnermacros.h
index f7095f18f..8f801f06d 100644
--- a/generatorrunnermacros.h
+++ b/generatorrunnermacros.h
@@ -39,4 +39,5 @@
#endif
#endif
+#define GENRUNNER_DEPRECATED __attribute__ ((deprecated))
#endif