diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2009-08-21 14:21:39 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2009-08-25 16:23:11 -0300 |
commit | 86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a (patch) | |
tree | 1d3f8aef0d325780a382a7a427c12cf5cec53022 | |
parent | 425c1eba27766b4382ace8f10daeaa548c9eb0d6 (diff) | |
download | generatorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.tar.gz generatorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.tar.xz generatorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.zip |
Added boostpython as a generator plugin.
-rw-r--r-- | CMakeLists.txt | 22 | ||||
-rw-r--r-- | generator.h | 13 | ||||
-rw-r--r-- | generators/CMakeLists.txt | 1 | ||||
-rw-r--r-- | generators/boostpython/CMakeLists.txt | 14 | ||||
-rw-r--r-- | generators/boostpython/boostpython.cpp | 29 | ||||
-rw-r--r-- | generators/boostpython/boostpythongenerator.cpp | 76 | ||||
-rw-r--r-- | generators/boostpython/boostpythongenerator.h | 6 | ||||
-rw-r--r-- | generators/boostpython/cppgenerator.cpp | 4 | ||||
-rw-r--r-- | main.cpp | 1 |
9 files changed, 147 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2eeb84c..0d61f43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ cmake_minimum_required(VERSION 2.6) find_package(Qt4 4.5.0 REQUIRED) find_package(ApiExtractor REQUIRED) +# lib generator version +set(generator_VERSION "0.1") + add_definitions(${QT_DEFINITIONS}) set(boostpythongenerator_VERSION 0.2) @@ -13,21 +16,23 @@ set(CMAKE_BUILD_TYPE Debug) set(boostpythongenerator_SRC main.cpp -generator.cpp ) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${APIEXTRACTOR_INCLUDE_DIR} ${APIEXTRACTOR_INCLUDE_DIR}/.. - ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}) +add_library(generator SHARED generator.cpp) +set_target_properties(generator PROPERTIES SOVERSION ${generator_VERSION}) +target_link_libraries(generator ${QT_QTCORE_LIBRARY} ${APIEXTRACTOR_LIBRARY}) + add_executable(boostpythongenerator ${boostpythongenerator_SRC}) target_link_libraries(boostpythongenerator + generator ${APIEXTRACTOR_LIBRARY} - ${QT_QTCORE_LIBRARY} - ${QT_QTXML_LIBRARY}) + ${QT_QTCORE_LIBRARY}) # uninstall target configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake" @@ -37,11 +42,6 @@ add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") -# "make dist", in fact "make package_source" -#set(CPACK_SOURCE_PACKAGE_FILE_NAME "boostpythongenerator-${boostpythongenerator_VERSION}") -#set(CPACK_SOURCE_GENERATOR TGZ) -#set(CPACK_SOURCE_IGNORE_FILES "~$" ".svn" "debian/" "build/" ".swp$" "*.kdev4") -#include(CPack) set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${boostpythongenerator_VERSION}) add_custom_target(dist @@ -50,8 +50,10 @@ add_custom_target(dist WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) install(TARGETS boostpythongenerator DESTINATION bin) +install(TARGETS generator DESTINATION lib) +install(FILES generator.h DESTINATION include) enable_testing() #add_subdirectory(libbindgen) # add_subdirectory(tests) - +add_subdirectory(generators) diff --git a/generator.h b/generator.h index 14526d7..f9e0c71 100644 --- a/generator.h +++ b/generator.h @@ -26,12 +26,19 @@ #include <QtCore/QObject> #include <QtCore/QDir> -#include "abstractmetalang.h" +#include <QtCore/QLinkedList> +#include <apiextractor/abstractmetalang.h> class ApiExtractor; class AbstractMetaBuilder; class QFile; +#define EXPORT_GENERATOR_PLUGIN(X)\ +extern "C" Q_DECL_EXPORT GeneratorList getGenerators()\ +{\ + return GeneratorList() << X;\ +}\ + /** * Base class for all generators. The default implementations does nothing, * you must subclass this to create your own generators. @@ -245,7 +252,7 @@ protected: */ virtual QString fileNameForClass(const AbstractMetaClass* metaClass) const = 0; - virtual bool doSetup(QMap<QString, QString> args) = 0; + virtual bool doSetup(const QMap<QString, QString>& args) = 0; /** * Returns the subdirectory path for a given package @@ -293,6 +300,8 @@ private: QString m_licenseComment; }; +typedef QLinkedList<Generator*> GeneratorList; + /** * Utility class to store the identation level, use it in a QTextStream. */ diff --git a/generators/CMakeLists.txt b/generators/CMakeLists.txt new file mode 100644 index 0000000..f0c6537 --- /dev/null +++ b/generators/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(boostpython) diff --git a/generators/boostpython/CMakeLists.txt b/generators/boostpython/CMakeLists.txt new file mode 100644 index 0000000..1e47cac --- /dev/null +++ b/generators/boostpython/CMakeLists.txt @@ -0,0 +1,14 @@ +project(boostpython) + +set(boostpython_SRC +boostpythongenerator.cpp +convertergenerator.cpp +cppgenerator.cpp +hppgenerator.cpp +boostpython.cpp +) + +add_library(boostpython SHARED ${boostpython_SRC}) +target_link_libraries(boostpython ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} generator) + +install(TARGETS boostpython DESTINATION lib) diff --git a/generators/boostpython/boostpython.cpp b/generators/boostpython/boostpython.cpp new file mode 100644 index 0000000..e165f93 --- /dev/null +++ b/generators/boostpython/boostpython.cpp @@ -0,0 +1,29 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ + +#include "generator.h" +#include "hppgenerator.h" +#include "cppgenerator.h" +#include "convertergenerator.h" + +EXPORT_GENERATOR_PLUGIN(new HppGenerator << new CppGenerator << new ConverterGenerator) diff --git a/generators/boostpython/boostpythongenerator.cpp b/generators/boostpython/boostpythongenerator.cpp index 70ce4a5..d5fd5e6 100644 --- a/generators/boostpython/boostpythongenerator.cpp +++ b/generators/boostpython/boostpythongenerator.cpp @@ -36,6 +36,78 @@ static Indentor INDENT; static void dump_function(AbstractMetaFunctionList lst); +static QString formattedCodeHelper(QTextStream &s, Indentor &indentor, QStringList &lines) +{ + bool multilineComment = false; + bool lastEmpty = true; + QString lastLine; + while (!lines.isEmpty()) { + const QString line = lines.takeFirst().trimmed(); + if (line.isEmpty()) { + if (!lastEmpty) + s << endl; + lastEmpty = true; + continue; + } else + lastEmpty = false; + + if (line.startsWith("/*")) + multilineComment = true; + + if (multilineComment) { + s << indentor; + if (line.startsWith("*")) + s << " "; + s << line << endl; + if (line.endsWith("*/")) + multilineComment = false; + } else if (line.startsWith("}")) + return line; + else if (line.endsWith("")) { + s << indentor << line << endl; + return 0; + } else if (line.endsWith("{")) { + s << indentor << line << endl; + QString tmp; + { + Indentation indent(indentor); + tmp = formattedCodeHelper(s, indentor, lines); + } + if (!tmp.isNull()) + s << indentor << tmp << endl; + + lastLine = tmp; + continue; + } else { + s << indentor; + if (!lastLine.isEmpty() && + !lastLine.endsWith(";") && + !line.startsWith("@") && + !line.startsWith("//") && + !lastLine.startsWith("//") && + !lastLine.endsWith("}") && + !line.startsWith("{")) + s << " "; + s << line << endl; + } + lastLine = line; + } + return 0; +} + +QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor) +{ + QStringList lst(code.split("\n")); + while (!lst.isEmpty()) { + QString tmp = formattedCodeHelper(s, indentor, lst); + if (!tmp.isNull()) + s << indentor << tmp << endl; + + } + s.flush(); + return s; +} + FunctionModificationList BoostPythonGenerator::functionModifications(const AbstractMetaFunction *metaFunction) { FunctionModificationList mods; @@ -419,7 +491,7 @@ void BoostPythonGenerator::writeCodeSnips(QTextStream &s, QString code; QTextStream tmpStream(&code); - snip.formattedCode(tmpStream, INDENT); + formatCode(tmpStream, snip.code(), INDENT); if (func) replaceTemplateVariables(code, func); @@ -488,7 +560,7 @@ static void dump_function(AbstractMetaFunctionList lst) } -bool BoostPythonGenerator::prepareGeneration(const QMap<QString, QString>&) +bool BoostPythonGenerator::doSetup(const QMap<QString, QString>&) { return true; } diff --git a/generators/boostpython/boostpythongenerator.h b/generators/boostpython/boostpythongenerator.h index 4ad191b..709612e 100644 --- a/generators/boostpython/boostpythongenerator.h +++ b/generators/boostpython/boostpythongenerator.h @@ -24,11 +24,13 @@ #ifndef BOOSTPYTHONGENERATOR_H #define BOOSTPYTHONGENERATOR_H -#include <apiextractor/generator.h> #include <QtCore/QTextStream> +#include "generator.h" class DocParser; +QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor); + /** * Abstract generator that contains common methods used in CppGenerator and HppGenerator. */ @@ -127,7 +129,7 @@ public: static QString getWrapperName(const AbstractMetaClass* clazz); - virtual bool prepareGeneration(const QMap<QString, QString>& args); + virtual bool doSetup(const QMap<QString, QString>& args); protected: // verify if the class is copyalbe diff --git a/generators/boostpython/cppgenerator.cpp b/generators/boostpython/cppgenerator.cpp index 36bd067..4a01369 100644 --- a/generators/boostpython/cppgenerator.cpp +++ b/generators/boostpython/cppgenerator.cpp @@ -1405,9 +1405,9 @@ void CppGenerator::writeGlobalFunctions() if (moduleEntry && moduleEntry->codeSnips().size() > 0) { foreach (CodeSnip snip, moduleEntry->codeSnips()) { if (snip.position == CodeSnip().Beginning) - snip.formattedCode(s, INDENT); + formatCode(s, snip.code(), INDENT); else - snip.formattedCode(snipEnd, INDENT); + formatCode(snipEnd, snip.code(), INDENT); } } @@ -49,7 +49,6 @@ static void printOptions(QTextStream& s, const QMap<QString, QString>& options) } typedef QLinkedList<Generator*> (*getGeneratorsFunc)(); -typedef QLinkedList<Generator*> GeneratorList; QMap<QString, QString> getCommandLineArgs(int argc, char** argv) { |