diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | generator.cpp | 91 | ||||
-rw-r--r-- | generator.h | 46 | ||||
-rw-r--r-- | generators/boostpython/boostpythongenerator.cpp | 49 | ||||
-rw-r--r-- | generators/qtdoc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | generators/qtdoc/qtdocgenerator.h | 9 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/sphinxtabletest.cpp | 4 | ||||
-rw-r--r-- | tests/sphinxtabletest.h | 4 |
9 files changed, 120 insertions, 93 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 20047c54d..46dc75100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,6 @@ install(TARGETS generatorrunner DESTINATION bin) install(FILES generator.h DESTINATION include) enable_testing() -#add_subdirectory(libbindgen) -# add_subdirectory(tests) + add_subdirectory(generators) +add_subdirectory(tests) diff --git a/generator.cpp b/generator.cpp index 300406356..80610c401 100644 --- a/generator.cpp +++ b/generator.cpp @@ -60,6 +60,48 @@ bool Generator::setup(const ApiExtractor& extractor, const QMap< QString, QStrin return doSetup(args); } +QMap< QString, QString > Generator::options() const +{ + return QMap<QString, QString>(); +} + +AbstractMetaClassList Generator::classes() const +{ + return m_classes; +} + +AbstractMetaFunctionList Generator::globalFunctions() const +{ + return m_globalFunctions; +} + +AbstractMetaEnumList Generator::globalEnums() const +{ + return m_globalEnums; +} + +QList<const PrimitiveTypeEntry*> Generator::primitiveTypes() const +{ + return m_primitiveTypes; +} + +QList<const ContainerTypeEntry*> Generator::containerTypes() const +{ + return m_containerTypes; +} + +/// Returns the output directory +QString Generator::outputDirectory() const +{ + return m_outDir; +} + +/// Set the output directory +void Generator::setOutputDirectory(const QString &outDir) +{ + m_outDir = outDir; +} + void Generator::generate() { foreach (AbstractMetaClass *cls, m_classes) { @@ -346,3 +388,52 @@ CodeSnipList Generator::getCodeSnips(const AbstractMetaFunction *func) return result; } + +QString Generator::translateType(const AbstractMetaType *cType, + const AbstractMetaClass *context, + int option) const +{ + QString s; + + if (context && cType && + context->typeEntry()->isGenericClass() && + cType->originalTemplateType()) { + qDebug() << "set original templateType" << cType->name(); + cType = cType->originalTemplateType(); + } + + if (!cType) { + s = "void"; + } else if (cType->isArray()) { + s = translateType(cType->arrayElementType(), context) + "[]"; + } else if (cType->isEnum() || cType->isFlags()) { + if (option & Generator::EnumAsInts) + s = "int"; + else + s = cType->cppSignature(); +#if 0 + } else if (c_type->isContainer()) { + qDebug() << "is container" << c_type->cppSignature(); + s = c_type->name(); + if (!(option & SkipTemplateParameters)) { + s += " < "; + QList<AbstractMetaType *> args = c_type->instantiations(); + for (int i = 0; i < args.size(); ++i) { + if (i) + s += ", "; + qDebug() << "container type: " << args.at(i)->cppSignature() << " / " << args.at(i)->instantiations().count(); + s += translateType(args.at(i), context, option); + } + s += " > "; + } +#endif + } else { + s = cType->cppSignature(); + if (cType->isConstant() && (option & Generator::ExcludeConst)) + s.replace("const", ""); + if (cType->isReference() && (option & Generator::ExcludeReference)) + s.replace("&", ""); + } + + return s; +} diff --git a/generator.h b/generator.h index 529d9b249..8040072aa 100644 --- a/generator.h +++ b/generator.h @@ -91,48 +91,24 @@ public: bool setup(const ApiExtractor& extractor, const QMap<QString, QString> args); - virtual QMap<QString, QString> options() const - { - return QMap<QString, QString>(); - } + virtual QMap<QString, QString> options() const; /// Returns the classes used to generate the binding code. - AbstractMetaClassList classes() const - { - return m_classes; - } + AbstractMetaClassList classes() const; - AbstractMetaFunctionList globalFunctions() const - { - return m_globalFunctions; - } + AbstractMetaFunctionList globalFunctions() const; - AbstractMetaEnumList globalEnums() const - { - return m_globalEnums; - } + AbstractMetaEnumList globalEnums() const; - QList<const PrimitiveTypeEntry*> primitiveTypes() const - { - return m_primitiveTypes; - } + QList<const PrimitiveTypeEntry*> primitiveTypes() const; - QList<const ContainerTypeEntry*> containerTypes() const - { - return m_containerTypes; - } + QList<const ContainerTypeEntry*> containerTypes() const; /// Returns the output directory - QString outputDirectory() const - { - return m_outDir; - } + QString outputDirectory() const; /// Set the output directory - void setOutputDirectory(const QString &outDir) - { - m_outDir = outDir; - } + void setOutputDirectory(const QString &outDir); /** * Start the code generation, be sure to call setClasses before callign this method. @@ -169,9 +145,9 @@ public: * \param option some extra options * \return the metatype translated to binding source format */ - virtual QString translateType(const AbstractMetaType *metatype, - const AbstractMetaClass *context, - int option = NoOption) const = 0; + QString translateType(const AbstractMetaType *metatype, + const AbstractMetaClass *context, + int option = NoOption) const; /** * Function used to write the fucntion arguments on the class buffer. diff --git a/generators/boostpython/boostpythongenerator.cpp b/generators/boostpython/boostpythongenerator.cpp index b799f4d2f..c62b876d8 100644 --- a/generators/boostpython/boostpythongenerator.cpp +++ b/generators/boostpython/boostpythongenerator.cpp @@ -36,55 +36,6 @@ static Indentor INDENT; static void dump_function(AbstractMetaFunctionList lst); -QString BoostPythonGenerator::translateType(const AbstractMetaType *cType, - const AbstractMetaClass *context, - int option) const -{ - QString s; - - if (context && cType && - context->typeEntry()->isGenericClass() && - cType->originalTemplateType()) { - qDebug() << "set original templateType" << cType->name(); - cType = cType->originalTemplateType(); - } - - if (!cType) { - s = "void"; - } else if (cType->isArray()) { - s = translateType(cType->arrayElementType(), context) + "[]"; - } else if (cType->isEnum() || cType->isFlags()) { - if (option & Generator::EnumAsInts) - s = "int"; - else - s = cType->cppSignature(); -#if 0 - } else if (c_type->isContainer()) { - qDebug() << "is container" << c_type->cppSignature(); - s = c_type->name(); - if (!(option & SkipTemplateParameters)) { - s += " < "; - QList<AbstractMetaType *> args = c_type->instantiations(); - for (int i = 0; i < args.size(); ++i) { - if (i) - s += ", "; - qDebug() << "container type: " << args.at(i)->cppSignature() << " / " << args.at(i)->instantiations().count(); - s += translateType(args.at(i), context, option); - } - s += " > "; - } -#endif - } else { - s = cType->cppSignature(); - if (cType->isConstant() && (option & Generator::ExcludeConst)) - s.replace("const", ""); - if (cType->isReference() && (option & Generator::ExcludeReference)) - s.replace("&", ""); - } - - return s; -} - QString BoostPythonGenerator::getWrapperName(const AbstractMetaClass* clazz) { QString result = clazz->name().toLower(); diff --git a/generators/qtdoc/CMakeLists.txt b/generators/qtdoc/CMakeLists.txt index 68c92b950..fb71784ab 100644 --- a/generators/qtdoc/CMakeLists.txt +++ b/generators/qtdoc/CMakeLists.txt @@ -5,6 +5,6 @@ qtdocgenerator.cpp ) add_library(qtdoc_generator SHARED ${qtdoc_generator_SRC}) -target_link_libraries(qtdoc_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} generator) +target_link_libraries(qtdoc_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} genrunner) install(TARGETS qtdoc_generator DESTINATION ${LIB_INSTALL_DIR}) diff --git a/generators/qtdoc/qtdocgenerator.h b/generators/qtdoc/qtdocgenerator.h index 1d898197e..c9b411335 100644 --- a/generators/qtdoc/qtdocgenerator.h +++ b/generators/qtdoc/qtdocgenerator.h @@ -180,6 +180,15 @@ protected: QString fileNameForClass(const AbstractMetaClass* cppClass) const; void generateClass(QTextStream& s, const AbstractMetaClass* cppClass); void finishGeneration(); + + void writeFunctionArguments(QTextStream&, const AbstractMetaFunction*, uint) const {} + void writeArgumentNames(QTextStream&, const AbstractMetaFunction*, uint) const {} + QString subDirectoryForClass(const AbstractMetaClass* clazz) const + { + Q_ASSERT(false); + return QString(); + } + private: void writeEnums(QTextStream& s, const AbstractMetaClass* cppClass); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9099adff8..89cf34fc2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,7 @@ project(sphinxtabletest) # TODO set(sphinxtabletest_SRC sphinxtabletest.cpp) qt4_automoc(${sphinxtabletest_SRC}) -include_directories(${QT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${boostpythongenerator_SOURCE_DIR}) +include_directories(${QT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${qtdoc_generator_SOURCE_DIR}) add_executable(sphinxtabletest ${sphinxtabletest_SRC}) -target_link_libraries(sphinxtabletest ${QT_QTTEST_LIBRARY} ${APIEXTRACTOR_LIBRARY} libboostpythongenerator) +target_link_libraries(sphinxtabletest ${QT_QTTEST_LIBRARY} ${APIEXTRACTOR_LIBRARY} qtdoc_generator generator) add_test("sphinxtable" sphinxtabletest) diff --git a/tests/sphinxtabletest.cpp b/tests/sphinxtabletest.cpp index 058a3b522..a35d11926 100644 --- a/tests/sphinxtabletest.cpp +++ b/tests/sphinxtabletest.cpp @@ -22,7 +22,7 @@ */ #include "sphinxtabletest.h" -#include "docgenerator.h" +#include "qtdocgenerator.h" #include <QtTest/QTest> #include <QDebug> @@ -33,7 +33,7 @@ QString SphinxTableTest::transformXml(const char* xml) void SphinxTableTest::setUp() { - m_generator = new DocGenerator; + m_generator = new QtDocGenerator; } void SphinxTableTest::tearDown() diff --git a/tests/sphinxtabletest.h b/tests/sphinxtabletest.h index 163cc5337..57d8937d0 100644 --- a/tests/sphinxtabletest.h +++ b/tests/sphinxtabletest.h @@ -26,7 +26,7 @@ #include <QObject> -class DocGenerator; +class QtDocGenerator; class SphinxTableTest : public QObject { Q_OBJECT @@ -40,7 +40,7 @@ private slots: void testComplexTable(); void testRowSpan2(); private: - DocGenerator* m_generator; + QtDocGenerator* m_generator; QString transformXml(const char* xml); }; |