summaryrefslogtreecommitdiffstats
path: root/generators
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-08-21 18:13:34 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-08-25 16:23:16 -0300
commit55dd77e04a8cef0e14648d6d8fb18cdc18695931 (patch)
treed6533b9b8e741050a6c6ccd9c5abab561767739d /generators
parent9682566c558674609a77540978e36db3dd174303 (diff)
downloadgeneratorrunner-55dd77e04a8cef0e14648d6d8fb18cdc18695931.tar.gz
generatorrunner-55dd77e04a8cef0e14648d6d8fb18cdc18695931.tar.xz
generatorrunner-55dd77e04a8cef0e14648d6d8fb18cdc18695931.zip
- QtDocGenerator is now a GeneratorRunner plugin.
- A lot of methods moved from boostpythongenerator to the generator class.
Diffstat (limited to 'generators')
-rw-r--r--generators/CMakeLists.txt1
-rw-r--r--generators/boostpython/CMakeLists.txt8
-rw-r--r--generators/boostpython/boostpythongenerator.cpp206
-rw-r--r--generators/boostpython/boostpythongenerator.h10
-rw-r--r--generators/qtdoc/CMakeLists.txt10
-rw-r--r--generators/qtdoc/qtdocgenerator.cpp74
-rw-r--r--generators/qtdoc/qtdocgenerator.h24
7 files changed, 49 insertions, 284 deletions
diff --git a/generators/CMakeLists.txt b/generators/CMakeLists.txt
index f0c6537..73b5eea 100644
--- a/generators/CMakeLists.txt
+++ b/generators/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(boostpython)
+add_subdirectory(qtdoc)
diff --git a/generators/boostpython/CMakeLists.txt b/generators/boostpython/CMakeLists.txt
index 1e47cac..c4bb296 100644
--- a/generators/boostpython/CMakeLists.txt
+++ b/generators/boostpython/CMakeLists.txt
@@ -1,6 +1,6 @@
project(boostpython)
-set(boostpython_SRC
+set(boostpython_generator_SRC
boostpythongenerator.cpp
convertergenerator.cpp
cppgenerator.cpp
@@ -8,7 +8,7 @@ hppgenerator.cpp
boostpython.cpp
)
-add_library(boostpython SHARED ${boostpython_SRC})
-target_link_libraries(boostpython ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} generator)
+add_library(boostpython_generator SHARED ${boostpython_generator_SRC})
+target_link_libraries(boostpython_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} generator)
-install(TARGETS boostpython DESTINATION lib)
+install(TARGETS boostpython_generator DESTINATION ${LIB_INSTALL_DIR})
diff --git a/generators/boostpython/boostpythongenerator.cpp b/generators/boostpython/boostpythongenerator.cpp
index d5fd5e6..b799f4d 100644
--- a/generators/boostpython/boostpythongenerator.cpp
+++ b/generators/boostpython/boostpythongenerator.cpp
@@ -36,92 +36,6 @@
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;
- const AbstractMetaClass *cls = metaFunction->implementingClass();
- while (cls) {
- mods += metaFunction->modifications(cls);
-
- if (cls == cls->baseClass())
- break;
- cls = cls->baseClass();
- }
- return mods;
-}
-
QString BoostPythonGenerator::translateType(const AbstractMetaType *cType,
const AbstractMetaClass *context,
int option) const
@@ -343,77 +257,6 @@ void BoostPythonGenerator::writeArgumentNames(QTextStream &s,
}
}
-AbstractMetaFunctionList BoostPythonGenerator::queryGlobalOperators(const AbstractMetaClass *cppClass)
-{
- AbstractMetaFunctionList result;
-
- foreach (AbstractMetaFunction *func, cppClass->functions()) {
- if (func->isInGlobalScope() && func->isOperatorOverload())
- result.append(func);
- }
- return result;
-}
-
-AbstractMetaFunctionList BoostPythonGenerator::sortContructor(AbstractMetaFunctionList list)
-{
- AbstractMetaFunctionList result;
-
- foreach (AbstractMetaFunction *func, list) {
- bool inserted = false;
- foreach (AbstractMetaArgument *arg, func->arguments()) {
- if (arg->type()->isFlags() || arg->type()->isEnum()) {
- result.push_back(func);
- inserted = true;
- break;
- }
- }
- if (!inserted)
- result.push_front(func);
- }
-
- return result;
-}
-
-AbstractMetaFunctionList BoostPythonGenerator::queryFunctions(const AbstractMetaClass *cppClass, bool allFunctions)
-{
- AbstractMetaFunctionList result;
-
- if (allFunctions) {
- int default_flags = AbstractMetaClass::NormalFunctions | AbstractMetaClass::Visible;
- default_flags |= cppClass->isInterface() ? 0 : AbstractMetaClass::ClassImplements;
-
- // Constructors
- result = cppClass->queryFunctions(AbstractMetaClass::Constructors |
- default_flags);
-
- // put enum constructor first to avoid conflict with int contructor
- result = sortContructor(result);
-
- // Final functions
- result += cppClass->queryFunctions(AbstractMetaClass::FinalInTargetLangFunctions |
- AbstractMetaClass::NonStaticFunctions |
- default_flags);
-
- //virtual
- result += cppClass->queryFunctions(AbstractMetaClass::VirtualInTargetLangFunctions |
- AbstractMetaClass::NonStaticFunctions |
- default_flags);
-
- // Static functions
- result += cppClass->queryFunctions(AbstractMetaClass::StaticFunctions | default_flags);
-
- // Empty, private functions, since they aren't caught by the other ones
- result += cppClass->queryFunctions(AbstractMetaClass::Empty |
- AbstractMetaClass::Invisible | default_flags);
- // Signals
- result += cppClass->queryFunctions(AbstractMetaClass::Signals | default_flags);
- } else {
- result = cppClass->functionsInTargetLang();
- }
-
- return result;
-}
-
void BoostPythonGenerator::writeFunctionCall(QTextStream &s,
const AbstractMetaFunction* func,
uint options)
@@ -427,55 +270,6 @@ void BoostPythonGenerator::writeFunctionCall(QTextStream &s,
s << ')';
}
-AbstractMetaFunctionList BoostPythonGenerator::filterFunctions(const AbstractMetaClass *cppClass)
-{
- AbstractMetaFunctionList lst = queryFunctions(cppClass, true);
- foreach (AbstractMetaFunction *func, lst) {
- //skip signals
- if (func->isSignal() ||
- func->isDestructor() ||
- (func->isModifiedRemoved() && !func->isAbstract())) {
- lst.removeOne(func);
- }
- }
-
- //virtual not implemented in current class
- AbstractMetaFunctionList virtual_lst = cppClass->queryFunctions(AbstractMetaClass::VirtualFunctions);
- foreach (AbstractMetaFunction *func, virtual_lst) {
- if ((func->implementingClass() != cppClass) &&
- !lst.contains(func)) {
- lst.append(func);
- }
- }
-
- //append global operators
- foreach (AbstractMetaFunction *func , queryGlobalOperators(cppClass)) {
- if (!lst.contains(func))
- lst.append(func);
- }
-
- return lst;
- //return cpp_class->functions();
-}
-
-CodeSnipList BoostPythonGenerator::getCodeSnips(const AbstractMetaFunction *func)
-{
- CodeSnipList result;
- const AbstractMetaClass *cppClass = func->implementingClass();
- while (cppClass) {
- foreach (FunctionModification mod, func->modifications(cppClass)) {
- if (mod.isCodeInjection())
- result << mod.snips;
- }
-
- if (cppClass == cppClass->baseClass())
- break;
- cppClass = cppClass->baseClass();
- }
-
- return result;
-}
-
void BoostPythonGenerator::writeCodeSnips(QTextStream &s,
const CodeSnipList &codeSnips,
CodeSnip::Position position,
diff --git a/generators/boostpython/boostpythongenerator.h b/generators/boostpython/boostpythongenerator.h
index 709612e..254ea95 100644
--- a/generators/boostpython/boostpythongenerator.h
+++ b/generators/boostpython/boostpythongenerator.h
@@ -29,8 +29,6 @@
class DocParser;
-QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor);
-
/**
* Abstract generator that contains common methods used in CppGenerator and HppGenerator.
*/
@@ -98,8 +96,6 @@ public:
CodeSnip::Position position,
TypeSystem::Language language,
const AbstractMetaFunction *cpp_function = 0);
- /// returns the code snips of a function
- CodeSnipList getCodeSnips(const AbstractMetaFunction *func);
static bool canCreateWrapperFor(const AbstractMetaClass* cppClass);
/**
* Function witch parse the metafunction information
@@ -135,13 +131,7 @@ protected:
// verify if the class is copyalbe
bool isCopyable(const AbstractMetaClass *cpp_class);
- static FunctionModificationList functionModifications(const AbstractMetaFunction *meta_function);
- AbstractMetaFunctionList queryFunctions(const AbstractMetaClass *cpp_class, bool all_function = false);
void writeFunctionCall(QTextStream &s, const AbstractMetaFunction *cpp_func, uint options = 0);
-
- AbstractMetaFunctionList filterFunctions(const AbstractMetaClass *cpp_class);
- AbstractMetaFunctionList queryGlobalOperators(const AbstractMetaClass *cpp_class);
- AbstractMetaFunctionList sortContructor(AbstractMetaFunctionList list);
};
diff --git a/generators/qtdoc/CMakeLists.txt b/generators/qtdoc/CMakeLists.txt
new file mode 100644
index 0000000..68c92b9
--- /dev/null
+++ b/generators/qtdoc/CMakeLists.txt
@@ -0,0 +1,10 @@
+project(qtdoc_generator)
+
+set(qtdoc_generator_SRC
+qtdocgenerator.cpp
+)
+
+add_library(qtdoc_generator SHARED ${qtdoc_generator_SRC})
+target_link_libraries(qtdoc_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} generator)
+
+install(TARGETS qtdoc_generator DESTINATION ${LIB_INSTALL_DIR})
diff --git a/generators/qtdoc/qtdocgenerator.cpp b/generators/qtdoc/qtdocgenerator.cpp
index ac3dbf3..8e8498d 100644
--- a/generators/qtdoc/qtdocgenerator.cpp
+++ b/generators/qtdoc/qtdocgenerator.cpp
@@ -21,7 +21,7 @@
*
*/
-#include "docgenerator.h"
+#include "qtdocgenerator.h"
#include <reporthandler.h>
#include <qtdocparser.h>
#include <algorithm>
@@ -65,7 +65,7 @@ QString escape(const QStringRef& strref)
}
-QtXmlToSphinx::QtXmlToSphinx(DocGenerator* generator, const QString& doc, const QString& context)
+QtXmlToSphinx::QtXmlToSphinx(QtDocGenerator* generator, const QString& doc, const QString& context)
: m_context(context), m_generator(generator), m_insideBold(false), m_insideItalic(false)
{
m_handlerMap.insert("heading", &QtXmlToSphinx::handleHeadingTag);
@@ -803,12 +803,12 @@ static QString getFuncName(const AbstractMetaFunction *cppFunc) {
return result.replace("::", ".");
}
-QString DocGenerator::fileNameForClass(const AbstractMetaClass *cppClass) const
+QString QtDocGenerator::fileNameForClass(const AbstractMetaClass *cppClass) const
{
return QString("%1.rst").arg(getClassName(cppClass));
}
-void DocGenerator::writeFormatedText(QTextStream& s, const Documentation& doc, const AbstractMetaClass* metaClass)
+void QtDocGenerator::writeFormatedText(QTextStream& s, const Documentation& doc, const AbstractMetaClass* metaClass)
{
QString metaClassName;
@@ -825,7 +825,7 @@ void DocGenerator::writeFormatedText(QTextStream& s, const Documentation& doc, c
s << endl;
}
-void DocGenerator::writeFunctionBrief(QTextStream &s,
+void QtDocGenerator::writeFunctionBrief(QTextStream &s,
const AbstractMetaClass *cppClass,
const AbstractMetaFunction *cppFunction)
{
@@ -838,7 +838,7 @@ void DocGenerator::writeFunctionBrief(QTextStream &s,
<< " (" << parseArgDocStyle(cppClass, cppFunction) << "):";
}
-void DocGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppClass)
+void QtDocGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppClass)
{
QString doc;
QTextStream doc_s(&doc);
@@ -858,35 +858,6 @@ void DocGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
AbstractMetaFunctionList functionList = filterFunctions(cppClass);
qSort(functionList.begin(), functionList.end(), functionSort);
-#if 0
- if (functionList.size() > 0)
- {
- QtXmlToSphinx::Table functionTable;
- QtXmlToSphinx::TableRow row;
-
- s << "Functions\n"
- "---------\n\n";
-
-
- foreach (AbstractMetaFunction *func, functionList) {
- if ((func->isConstructor() || func->isModifiedRemoved()) ||
- (func->declaringClass() != cppClass))
- continue;
-
- QString rowString;
- QTextStream rowStream(&rowString);
-
- writeFunctionBrief(rowStream, cppClass, func);
- row << rowString;
- functionTable << row;
- row.clear();
- }
- functionTable.normalize();
- s << functionTable;
- }
-
-#endif
-
doc_s << "Detailed Description\n"
"--------------------\n\n";
@@ -921,7 +892,7 @@ void DocGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
s << doc;
}
-QString DocGenerator::parseFunctionDeclaration(const QString &doc, const AbstractMetaClass *cppClass)
+QString QtDocGenerator::parseFunctionDeclaration(const QString &doc, const AbstractMetaClass *cppClass)
{
//.. method:: QObject.childEvent(arg__1)
//def :meth:`removeEventFilter<QObject.removeEventFilter>` (arg__1):
@@ -952,7 +923,7 @@ QString DocGenerator::parseFunctionDeclaration(const QString &doc, const Abstrac
}
-void DocGenerator::writeFunctionList(QTextStream &s, const QString &content, const AbstractMetaClass *cppClass)
+void QtDocGenerator::writeFunctionList(QTextStream &s, const QString &content, const AbstractMetaClass *cppClass)
{
QStringList functionList;
QStringList staticFunctionList;
@@ -1009,7 +980,7 @@ void DocGenerator::writeFunctionList(QTextStream &s, const QString &content, con
}
}
-void DocGenerator::writeEnums(QTextStream& s, const AbstractMetaClass* cppClass)
+void QtDocGenerator::writeEnums(QTextStream& s, const AbstractMetaClass* cppClass)
{
static const QString section_title(".. attribute:: ");
@@ -1019,7 +990,7 @@ void DocGenerator::writeEnums(QTextStream& s, const AbstractMetaClass* cppClass)
}
}
-void DocGenerator::writeFields(QTextStream &s, const AbstractMetaClass *cppClass)
+void QtDocGenerator::writeFields(QTextStream &s, const AbstractMetaClass *cppClass)
{
static const QString section_title(".. attribute:: ");
@@ -1030,7 +1001,7 @@ void DocGenerator::writeFields(QTextStream &s, const AbstractMetaClass *cppClass
}
}
-void DocGenerator::writeConstructors(QTextStream &s, const AbstractMetaClass *cppClass)
+void QtDocGenerator::writeConstructors(QTextStream &s, const AbstractMetaClass *cppClass)
{
static const QString sectionTitle = ".. class:: ";
static const QString sectionTitleSpace = QString(sectionTitle.size(), ' ');
@@ -1073,7 +1044,7 @@ void DocGenerator::writeConstructors(QTextStream &s, const AbstractMetaClass *cp
}
}
-QString DocGenerator::parseArgDocStyle(const AbstractMetaClass *cppClass, const AbstractMetaFunction *func)
+QString QtDocGenerator::parseArgDocStyle(const AbstractMetaClass *cppClass, const AbstractMetaFunction *func)
{
QString ret;
bool optional = false;
@@ -1103,7 +1074,7 @@ QString DocGenerator::parseArgDocStyle(const AbstractMetaClass *cppClass, const
return ret;
}
-void DocGenerator::writeDocSnips(QTextStream &s,
+void QtDocGenerator::writeDocSnips(QTextStream &s,
const CodeSnipList &codeSnips,
CodeSnip::Position position,
TypeSystem::Language language)
@@ -1166,7 +1137,7 @@ void DocGenerator::writeDocSnips(QTextStream &s,
}
}
-void DocGenerator::writeInjectDocumentation(QTextStream &s,
+void QtDocGenerator::writeInjectDocumentation(QTextStream &s,
DocModification::Mode mode,
const AbstractMetaClass *cppClass,
const AbstractMetaFunction *func)
@@ -1208,14 +1179,14 @@ void DocGenerator::writeInjectDocumentation(QTextStream &s,
}
}
-void DocGenerator::writeFunctionSignature(QTextStream& s, const AbstractMetaClass* cppClass, const AbstractMetaFunction* func)
+void QtDocGenerator::writeFunctionSignature(QTextStream& s, const AbstractMetaClass* cppClass, const AbstractMetaFunction* func)
{
if (!func->isConstructor())
s << getClassName(cppClass) << '.';
s << getFuncName(func) << "(" << parseArgDocStyle(cppClass, func) << ")";
}
-QString DocGenerator::translateToPythonType(const AbstractMetaType *type, const AbstractMetaClass *cppClass)
+QString QtDocGenerator::translateToPythonType(const AbstractMetaType *type, const AbstractMetaClass *cppClass)
{
QString originalType = translateType(type, cppClass, Generator::ExcludeConst | Generator::ExcludeReference);
QString strType = originalType;
@@ -1248,13 +1219,13 @@ QString DocGenerator::translateToPythonType(const AbstractMetaType *type, const
}
}
-void DocGenerator::writeParamerteType(QTextStream &s, const AbstractMetaClass *cppClass, const AbstractMetaArgument *arg)
+void QtDocGenerator::writeParamerteType(QTextStream &s, const AbstractMetaClass *cppClass, const AbstractMetaArgument *arg)
{
s << INDENT << ":param " << arg->argumentName() << ": "
<< translateToPythonType(arg->type(), cppClass) << endl;
}
-void DocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractMetaClass *cppClass, const AbstractMetaFunction* func)
+void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractMetaClass *cppClass, const AbstractMetaFunction* func)
{
Indentation indentation(INDENT);
@@ -1273,7 +1244,7 @@ void DocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractMet
s << endl;
}
-void DocGenerator::writeFunction(QTextStream &s, bool writeDoc, const AbstractMetaClass *cppClass, const AbstractMetaFunction* func)
+void QtDocGenerator::writeFunction(QTextStream &s, bool writeDoc, const AbstractMetaClass *cppClass, const AbstractMetaFunction* func)
{
writeFunctionSignature(s, cppClass, func);
s << endl;
@@ -1288,7 +1259,7 @@ void DocGenerator::writeFunction(QTextStream &s, bool writeDoc, const AbstractMe
}
}
-void DocGenerator::finishGeneration()
+void QtDocGenerator::finishGeneration()
{
if (classes().isEmpty())
return;
@@ -1332,9 +1303,8 @@ void DocGenerator::finishGeneration()
}
}
-bool DocGenerator::prepareGeneration(const QMap<QString, QString>& args)
+bool QtDocGenerator::doSetup(const QMap<QString, QString>& args)
{
- BoostPythonGenerator::prepareGeneration(args);
m_libSourceDir = args.value("library-source-dir");
setOutputDirectory(args.value("documentation-out-dir"));
m_docDataDir = args.value("documentation-data-dir");
@@ -1358,7 +1328,7 @@ bool DocGenerator::prepareGeneration(const QMap<QString, QString>& args)
}
-QMap<QString, QString> DocGenerator::options() const
+QMap<QString, QString> QtDocGenerator::options() const
{
QMap<QString, QString> options;
options.insert("library-source-dir", "Directory where library source code is located");
diff --git a/generators/qtdoc/qtdocgenerator.h b/generators/qtdoc/qtdocgenerator.h
index cef7fa7..1d89819 100644
--- a/generators/qtdoc/qtdocgenerator.h
+++ b/generators/qtdoc/qtdocgenerator.h
@@ -23,11 +23,16 @@
#ifndef DOCGENERATOR_H
#define DOCGENERATOR_H
-#include "boostpythongenerator.h"
#include <QtCore/QStack>
+#include <QtCore/QHash>
+#include <QtCore/QTextStream>
+#include <apiextractor/abstractmetalang.h>
+#include "generator.h"
+class AbstractMetaFunction;
+class AbstractMetaClass;
class QXmlStreamReader;
-class DocGenerator;
+class QtDocGenerator;
class QtXmlToSphinx
{
@@ -77,7 +82,7 @@ public:
bool m_normalized;
};
- QtXmlToSphinx(DocGenerator* generator, const QString& doc, const QString& context = QString());
+ QtXmlToSphinx(QtDocGenerator* generator, const QString& doc, const QString& context = QString());
QString result() const
{
@@ -127,7 +132,7 @@ private:
Table m_currentTable;
bool m_tableHasHeader;
QString m_context;
- DocGenerator* m_generator;
+ QtDocGenerator* m_generator;
bool m_insideBold;
bool m_insideItalic;
QString m_lastTagName;
@@ -149,24 +154,19 @@ QTextStream& operator<<(QTextStream& s, const QtXmlToSphinx::Table &table);
/**
* The DocGenerator generates documentation from library being binded.
*/
-class DocGenerator : public BoostPythonGenerator
+class QtDocGenerator : public Generator
{
public:
- virtual GeneratorType type() const
- {
- return DocumentationType;
- }
-
QString libSourceDir() const
{
return m_libSourceDir;
}
- virtual bool prepareGeneration(const QMap<QString, QString>& args);
+ bool doSetup(const QMap<QString, QString>& args);
const char* name() const
{
- return "DocGenerator";
+ return "QtDocGenerator";
}
QMap<QString, QString> options() const;