summaryrefslogtreecommitdiffstats
path: root/generators
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-08-21 14:21:39 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-08-25 16:23:11 -0300
commit86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a (patch)
tree1d3f8aef0d325780a382a7a427c12cf5cec53022 /generators
parent425c1eba27766b4382ace8f10daeaa548c9eb0d6 (diff)
downloadgeneratorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.tar.gz
generatorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.tar.xz
generatorrunner-86c00c1d694cfc69b58ac2fbd0d7744c7f95e39a.zip
Added boostpython as a generator plugin.
Diffstat (limited to 'generators')
-rw-r--r--generators/CMakeLists.txt1
-rw-r--r--generators/boostpython/CMakeLists.txt14
-rw-r--r--generators/boostpython/boostpython.cpp29
-rw-r--r--generators/boostpython/boostpythongenerator.cpp76
-rw-r--r--generators/boostpython/boostpythongenerator.h6
-rw-r--r--generators/boostpython/cppgenerator.cpp4
6 files changed, 124 insertions, 6 deletions
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);
}
}