diff options
Diffstat (limited to 'generators')
-rw-r--r-- | generators/boostpython/CMakeLists.txt | 5 | ||||
-rw-r--r-- | generators/boostpython/boostpythongenerator.cpp | 38 | ||||
-rw-r--r-- | generators/boostpython/boostpythongenerator.h | 16 | ||||
-rw-r--r-- | generators/boostpython/convertergenerator.cpp | 6 | ||||
-rw-r--r-- | generators/boostpython/cppgenerator.cpp | 22 | ||||
-rw-r--r-- | generators/boostpython/hppgenerator.cpp | 4 | ||||
-rw-r--r-- | generators/boostpython/main.cpp | 34 | ||||
-rw-r--r-- | generators/qtdoc/CMakeLists.txt | 5 | ||||
-rw-r--r-- | generators/qtdoc/main.cpp | 34 | ||||
-rw-r--r-- | generators/qtdoc/qtdocgenerator.cpp | 63 | ||||
-rw-r--r-- | generators/qtdoc/qtdocgenerator.h | 5 |
11 files changed, 180 insertions, 52 deletions
diff --git a/generators/boostpython/CMakeLists.txt b/generators/boostpython/CMakeLists.txt index b29b8cf89..00e7915b5 100644 --- a/generators/boostpython/CMakeLists.txt +++ b/generators/boostpython/CMakeLists.txt @@ -8,7 +8,12 @@ hppgenerator.cpp boostpython.cpp ) +add_executable(boostpythongenerator main.cpp) +target_link_libraries(boostpythongenerator ${QT_QTCORE_LIBRARY}) + add_library(boostpython_generator SHARED ${boostpython_generator_SRC}) target_link_libraries(boostpython_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} genrunner) install(TARGETS boostpython_generator DESTINATION ${LIB_INSTALL_DIR}) +install(TARGETS boostpythongenerator DESTINATION bin) + diff --git a/generators/boostpython/boostpythongenerator.cpp b/generators/boostpython/boostpythongenerator.cpp index c62b876d8..c25fc09be 100644 --- a/generators/boostpython/boostpythongenerator.cpp +++ b/generators/boostpython/boostpythongenerator.cpp @@ -36,9 +36,9 @@ static Indentor INDENT; static void dump_function(AbstractMetaFunctionList lst); -QString BoostPythonGenerator::getWrapperName(const AbstractMetaClass* clazz) +QString BoostPythonGenerator::getWrapperName(const AbstractMetaClass* metaClass) { - QString result = clazz->name().toLower(); + QString result = metaClass->typeEntry()->qualifiedCppName().toLower(); result.replace("::", "_"); result += "_wrapper"; return result; @@ -46,13 +46,13 @@ QString BoostPythonGenerator::getWrapperName(const AbstractMetaClass* clazz) QString BoostPythonGenerator::argumentString(const AbstractMetaFunction *cppFunction, const AbstractMetaArgument *cppArgument, - uint options) const + Options options) const { QString modifiedType = cppFunction->typeReplaced(cppArgument->argumentIndex() + 1); QString arg; if (modifiedType.isEmpty()) - arg = translateType(cppArgument->type(), cppFunction->implementingClass(), (Generator::Option) options); + arg = translateType(cppArgument->type(), cppFunction->implementingClass(), options); else arg = modifiedType.replace('$', '.'); @@ -82,14 +82,14 @@ QString BoostPythonGenerator::argumentString(const AbstractMetaFunction *cppFunc void BoostPythonGenerator::writeArgument(QTextStream &s, const AbstractMetaFunction *func, const AbstractMetaArgument *cppArgument, - uint options) const + Options options) const { s << argumentString(func, cppArgument, options); } void BoostPythonGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaFunction *func, - uint options) const + Options options) const { AbstractMetaArgumentList arguments = func->arguments(); @@ -112,19 +112,19 @@ void BoostPythonGenerator::writeFunctionArguments(QTextStream &s, } } -QString BoostPythonGenerator::functionReturnType(const AbstractMetaFunction* func, int option) +QString BoostPythonGenerator::functionReturnType(const AbstractMetaFunction* func, Options options) { QString modifiedReturnType = QString(func->typeReplaced(0)); - if (!modifiedReturnType.isNull() && (!(option & OriginalTypeDescription))) + if (!modifiedReturnType.isNull() && (!(options & OriginalTypeDescription))) return modifiedReturnType; else - return translateType(func->type(), func->implementingClass(), option); + return translateType(func->type(), func->implementingClass(), options); } QString BoostPythonGenerator::functionSignature(const AbstractMetaFunction *func, QString prepend, QString append, - int option, + Options options, int argCount) { AbstractMetaArgumentList arguments = func->arguments(); @@ -137,9 +137,9 @@ QString BoostPythonGenerator::functionSignature(const AbstractMetaFunction *func if (!(func->isEmptyFunction() || func->isNormal() || func->isSignal())) { - option = Option(option | Generator::SkipReturnType); + options |= Generator::SkipReturnType; } else { - s << functionReturnType(func, option) << ' '; + s << functionReturnType(func, options) << ' '; } // name @@ -148,10 +148,10 @@ QString BoostPythonGenerator::functionSignature(const AbstractMetaFunction *func name = getWrapperName(func->ownerClass()); s << prepend << name << append << "("; - writeFunctionArguments(s, func, option); + writeFunctionArguments(s, func, options); s << ")"; - if (func->isConstant() && (!(option & Generator::ExcludeMethodConst))) + if (func->isConstant() && (!(options & Generator::ExcludeMethodConst))) s << " const"; return result; @@ -160,16 +160,16 @@ QString BoostPythonGenerator::functionSignature(const AbstractMetaFunction *func QString BoostPythonGenerator::signatureForDefaultVirtualMethod(const AbstractMetaFunction *cppFunction, QString prepend, QString append, - int option, + Options options, int arg_count) { - QString defaultMethodSignature = functionSignature(cppFunction, prepend, append, option, arg_count); + QString defaultMethodSignature = functionSignature(cppFunction, prepend, append, options, arg_count); QString staticSelf("("); if (cppFunction->isConstant()) staticSelf += "const "; staticSelf += cppFunction->ownerClass()->qualifiedCppName() + "& "; - if (!(option & SkipName)) + if (!(options & SkipName)) staticSelf += " self"; if (cppFunction->arguments().size() > 0) @@ -182,7 +182,7 @@ QString BoostPythonGenerator::signatureForDefaultVirtualMethod(const AbstractMet void BoostPythonGenerator::writeArgumentNames(QTextStream &s, const AbstractMetaFunction *func, - uint options) const + Options options) const { AbstractMetaArgumentList arguments = func->arguments(); int argCount = 0; @@ -210,7 +210,7 @@ void BoostPythonGenerator::writeArgumentNames(QTextStream &s, void BoostPythonGenerator::writeFunctionCall(QTextStream &s, const AbstractMetaFunction* func, - uint options) + Options options) { if (!(options & Generator::SkipName)) diff --git a/generators/boostpython/boostpythongenerator.h b/generators/boostpython/boostpythongenerator.h index 14311b2e0..2f48b1804 100644 --- a/generators/boostpython/boostpythongenerator.h +++ b/generators/boostpython/boostpythongenerator.h @@ -46,7 +46,7 @@ public: void writeArgument(QTextStream &s, const AbstractMetaFunction *boost_function, const AbstractMetaArgument *boost_argument, - uint options = 0) const; + Options options = NoOption) const; /** * Create a QString in the boost::python format to an function argument. * \param boost_fuction the current metafunction. @@ -55,11 +55,11 @@ public: */ QString argumentString(const AbstractMetaFunction *boost_function, const AbstractMetaArgument *boost_argument, - uint options = 0) const; + Options options = NoOption) const; void writeArgumentNames(QTextStream &s, const AbstractMetaFunction *cpp_function, - uint options = 0) const; + Options options = NoOption) const; /** * Function used to write the fucntion arguments on the class buffer. @@ -70,8 +70,8 @@ public: */ void writeFunctionArguments(QTextStream &s, const AbstractMetaFunction *boost_function, - uint options = 0) const; - QString functionReturnType(const AbstractMetaFunction* func, int option = NoOption); + Options options = NoOption) const; + QString functionReturnType(const AbstractMetaFunction* func, Options options = NoOption); /** * Write a code snip into the buffer \p s. * CodeSnip are codes inside inject-code tags. @@ -96,13 +96,13 @@ public: QString functionSignature(const AbstractMetaFunction *boost_function, QString prepend = "", QString append = "", - int option = NoOption, + Options options = NoOption, int arg_count = -1); QString signatureForDefaultVirtualMethod(const AbstractMetaFunction *cpp_function, QString prepend = "", QString append = "_default", - int option = NoOption, + Options = NoOption, int arg_count = -1); virtual QString subDirectoryForClass(const AbstractMetaClass* metaClass) const @@ -121,7 +121,7 @@ protected: // verify if the class is copyalbe bool isCopyable(const AbstractMetaClass *cpp_class); - void writeFunctionCall(QTextStream &s, const AbstractMetaFunction *cpp_func, uint options = 0); + void writeFunctionCall(QTextStream &s, const AbstractMetaFunction *cpp_func, Options options = NoOption); }; diff --git a/generators/boostpython/convertergenerator.cpp b/generators/boostpython/convertergenerator.cpp index ea52b9193..23a5d3601 100644 --- a/generators/boostpython/convertergenerator.cpp +++ b/generators/boostpython/convertergenerator.cpp @@ -134,10 +134,8 @@ void ConverterGenerator::checkFunctionMetaTypes(AbstractMetaFunction* func) checkMetaType(functionReturnType(func)); foreach (AbstractMetaArgument* arg, func->arguments()) { - if (arg->type()) { - checkMetaType(argumentString(func, arg, - (Generator::SkipName | Generator::SkipDefaultValues))); - } + if (arg->type()) + checkMetaType(argumentString(func, arg, Options(SkipName) | SkipDefaultValues)); } } diff --git a/generators/boostpython/cppgenerator.cpp b/generators/boostpython/cppgenerator.cpp index dd90bc9a4..fb68a0e86 100644 --- a/generators/boostpython/cppgenerator.cpp +++ b/generators/boostpython/cppgenerator.cpp @@ -89,8 +89,8 @@ void CppGenerator::writeConstructorInitialization(QTextStream &s, const Abstract QStringList nonOpts; QStringList opts; + Options options = Options(SkipName) | SkipDefaultValues; foreach (AbstractMetaArgument *arg, function->arguments()) { - uint options = SkipName | SkipDefaultValues; QString argType = argumentString(function, arg, options); if (arg->defaultValueExpression().isEmpty()) nonOpts << argType; @@ -142,7 +142,7 @@ void CppGenerator::writeConstructorInitialization(QTextStream &s, const Abstract if (arg->argumentName() == "parent") { parentIndex = arg->argumentIndex(); parentType = translateType(arg->type(), function->ownerClass(), - Generator::ExcludeConst | Generator::ExcludeReference).replace("*", ""); + Options(ExcludeConst) | ExcludeReference).replace("*", ""); break; } } @@ -226,7 +226,7 @@ QString CppGenerator::writeFunctionCast(QTextStream &s, if (func->arguments().size() > 0) s << ", "; } - int options = SkipName | SkipDefaultValues | SkipRemovedArguments; + Options options = Options(SkipName) | SkipDefaultValues | SkipRemovedArguments; if (isWrapped && !func->isStatic()) options |= WriteSelf; @@ -303,11 +303,11 @@ QString CppGenerator::getArgumentType(const AbstractMetaClass *cppClass, const A retval = cppClass->qualifiedCppName(); } else if (idx == 0 && func->type()) { retval = translateType(func->type(), cppClass, - Generator::ExcludeConst | Generator::ExcludeReference); + Options(Generator::ExcludeConst) | Generator::ExcludeReference); } else if (idx > 0) { retval = argumentString(func, func->arguments()[idx-1], - Generator::SkipDefaultValues | Generator::ExcludeConst | - Generator::ExcludeReference | Generator::SkipName); + Options(SkipDefaultValues) | ExcludeConst | + ExcludeReference | SkipName); } retval = retval.trimmed(); @@ -635,7 +635,7 @@ void CppGenerator::writeConstructorImpl(QTextStream& s, const AbstractMetaFuncti { QString wrapperName = getWrapperName(func->ownerClass()); s << wrapperName << "::" << wrapperName << "(PyObject *py_self" << (func->arguments().size() ? ", " : ""); - writeFunctionArguments(s, func, OriginalTypeDescription | SkipDefaultValues); + writeFunctionArguments(s, func, Options(OriginalTypeDescription) | SkipDefaultValues); s << ")" << endl; s << INDENT << " : "; writeFunctionCall(s, func); @@ -717,7 +717,7 @@ void CppGenerator::writeVirtualMethodImpl(QTextStream& s, const AbstractMetaFunc QString prefix = getWrapperName(func->ownerClass()) + "::"; s << functionSignature(func, prefix, "", - Generator::OriginalTypeDescription | Generator::SkipDefaultValues) + Options(Generator::OriginalTypeDescription) | Generator::SkipDefaultValues) << endl << "{" << endl; writeVirtualMethodImplHead(s, func); @@ -804,7 +804,7 @@ void CppGenerator::writeNonVirtualModifiedFunctionImpl(QTextStream& s, const Abs s << "static " << getFunctionReturnType(func) << ' '; s << func->ownerClass()->name() << '_' << func->originalName() << "_modified("; - uint options = SkipRemovedArguments | SkipDefaultValues; + Options options = Options(SkipRemovedArguments) | SkipDefaultValues; if (!func->isStatic()) options |= WriteSelf; @@ -955,7 +955,7 @@ void CppGenerator::writeBoostDeclaration(QTextStream& s, const AbstractMetaClass s << INDENT << "python_cls." << strAccess << "(\"" << field->name() << "\", &" - << field->enclosingClass()->name() << "::" << field->name() << ");" << endl; + << field->enclosingClass()->typeEntry()->qualifiedCppName() << "::" << field->name() << ");" << endl; } } @@ -1192,7 +1192,7 @@ void CppGenerator::writeGlobalOperatorOverloadImpl(QTextStream& s, const Abstrac const AbstractMetaClass *klass = cppFunction->ownerClass(); s << "python::object " << funcName << "("; - writeFunctionArguments(s, cppFunction, SkipDefaultValues | SkipRemovedArguments); + writeFunctionArguments(s, cppFunction, Options(SkipDefaultValues) | SkipRemovedArguments); s << ")" << endl << "{" << endl << INDENT << cppFunction->arguments()[reverse]->argumentName() << operatorStr << cppFunction->arguments()[!reverse]->argumentName() << ";" << endl diff --git a/generators/boostpython/hppgenerator.cpp b/generators/boostpython/hppgenerator.cpp index f6d576d08..2bdfae454 100644 --- a/generators/boostpython/hppgenerator.cpp +++ b/generators/boostpython/hppgenerator.cpp @@ -175,10 +175,10 @@ void HppGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction* fun if (func->isConstructor()) { s << INDENT << getWrapperName(func->ownerClass()) << "(PyObject *py_self" << (func->arguments().size() ? "," : ""); - writeFunctionArguments(s, func, Generator::OriginalTypeDescription | Generator::SkipName); + writeFunctionArguments(s, func, Options(OriginalTypeDescription) | SkipName); s << ")"; } else { - s << INDENT << functionSignature(func, "", "", Generator::OriginalTypeDescription | Generator::SkipName); + s << INDENT << functionSignature(func, "", "", Options(OriginalTypeDescription) | SkipName); } if (func->isModifiedRemoved() && func->isAbstract()) diff --git a/generators/boostpython/main.cpp b/generators/boostpython/main.cpp new file mode 100644 index 000000000..b4e81a878 --- /dev/null +++ b/generators/boostpython/main.cpp @@ -0,0 +1,34 @@ +/* + * This file is part of the Boost Python Generator 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 <QtCore> + +int main(int argc, char *argv[]) +{ + QStringList args; + args.append("--generatorSet=boostpython"); + for (int i = 1; i < argc; i++) + args.append(argv[i]); + return QProcess::execute("generatorrunner", args); +} + diff --git a/generators/qtdoc/CMakeLists.txt b/generators/qtdoc/CMakeLists.txt index fb71784ab..804600e58 100644 --- a/generators/qtdoc/CMakeLists.txt +++ b/generators/qtdoc/CMakeLists.txt @@ -4,7 +4,12 @@ set(qtdoc_generator_SRC qtdocgenerator.cpp ) +add_executable(docgenerator main.cpp) +target_link_libraries(docgenerator ${QT_QTCORE_LIBRARY}) + add_library(qtdoc_generator SHARED ${qtdoc_generator_SRC}) target_link_libraries(qtdoc_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} genrunner) install(TARGETS qtdoc_generator DESTINATION ${LIB_INSTALL_DIR}) +install(TARGETS docgenerator DESTINATION bin) + diff --git a/generators/qtdoc/main.cpp b/generators/qtdoc/main.cpp new file mode 100644 index 000000000..c513147d3 --- /dev/null +++ b/generators/qtdoc/main.cpp @@ -0,0 +1,34 @@ +/* + * This file is part of the Boost Python Generator 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 <QtCore> + +int main(int argc, char *argv[]) +{ + QStringList args; + args.append("--generatorSet=qtdoc"); + for (int i = 1; i < argc; i++) + args.append(argv[i]); + return QProcess::execute("generatorrunner", args); +} + diff --git a/generators/qtdoc/qtdocgenerator.cpp b/generators/qtdoc/qtdocgenerator.cpp index 110003fd9..67e53b187 100644 --- a/generators/qtdoc/qtdocgenerator.cpp +++ b/generators/qtdoc/qtdocgenerator.cpp @@ -131,6 +131,38 @@ QString QtXmlToSphinx::popOutputBuffer() return strcpy; } +QString QtXmlToSphinx::resolveContextForMethod(const QString& methodName) +{ + QString currentClass = m_context.split(".").last(); + + const AbstractMetaClass* metaClass = 0; + foreach (const AbstractMetaClass* cls, m_generator->classes()) { + if (cls->name() == currentClass) { + metaClass = cls; + break; + } + } + + if (metaClass) { + QList<const AbstractMetaFunction*> funcList; + foreach (const AbstractMetaFunction* func, metaClass->queryFunctionsByName(methodName)) { + if (methodName == func->name()) + funcList.append(func); + } + + const AbstractMetaClass* implementingClass = 0; + foreach (const AbstractMetaFunction* func, funcList) { + implementingClass = func->implementingClass(); + if (implementingClass->name() == currentClass) + break; + } + + if (implementingClass) + return implementingClass->name(); + } + + return QLatin1String("~") + m_context; +} QString QtXmlToSphinx::transform(const QString& doc) { @@ -486,12 +518,20 @@ void QtXmlToSphinx::handleLinkTag(QXmlStreamReader& reader) if (l_type == "function" && !m_context.isEmpty()) { l_linktag = " :meth:`"; QStringList rawlinklist = l_linkref.split("."); - if (rawlinklist.size() == 1 || rawlinklist[0] == m_context) - l_linkref.prepend("~" + m_context + '.'); + if (rawlinklist.size() == 1 || rawlinklist.first() == m_context) { + QString context = resolveContextForMethod(rawlinklist.last()); + l_linkref.prepend(context + '.'); + } } else if (l_type == "function" && m_context.isEmpty()) { l_linktag = " :func:`"; } else if (l_type == "class") { l_linktag = " :class:`"; + QStringList rawlinklist = l_linkref.split("."); + QStringList splittedContext = m_context.split("."); + if (rawlinklist.size() == 1 || rawlinklist.first() == splittedContext.last()) { + splittedContext.removeLast(); + l_linkref.prepend('~' + splittedContext.join(".") + '.'); + } } else if (l_type == "enum") { l_linktag = " :attr:`"; } else if (l_type == "page" && l_linkref == m_generator->moduleName()) { @@ -764,7 +804,7 @@ QTextStream& operator<<(QTextStream& s, const QtXmlToSphinx::Table &table) } static QString getClassName(const AbstractMetaClass *cppClass) { - return cppClass->name().replace("::", "."); + return QString(cppClass->typeEntry()->qualifiedCppName()).replace("::", "."); } static QString getFuncName(const AbstractMetaFunction *cppFunc) { @@ -915,9 +955,18 @@ QString QtDocGenerator::parseFunctionDeclaration(const QString &doc, const Abstr QString methName = data.mid(0, data.indexOf("(")); QString methArgs = data.mid(data.indexOf("(")); - data = QString("def :meth:`%1<%2.%3>` %4") + QString scope = cppClass->name(); + QStringList splittedMethName = methName.split("."); + + if (splittedMethName.first() == scope) { + splittedMethName.removeFirst(); + methName = splittedMethName.join("."); + } + scope.append("."); + + data = QString("def :meth:`%1<%2%3>` %4") .arg(methName) - .arg(cppClass->name()) + .arg(scope) .arg(methName) .arg(methArgs); @@ -1185,12 +1234,14 @@ void QtDocGenerator::writeFunctionSignature(QTextStream& s, const AbstractMetaCl { if (!func->isConstructor()) s << getClassName(cppClass) << '.'; + else if (func->implementingClass() && func->implementingClass()->enclosingClass()) + s << func->implementingClass()->enclosingClass()->name() << '.'; s << getFuncName(func) << "(" << parseArgDocStyle(cppClass, func) << ")"; } QString QtDocGenerator::translateToPythonType(const AbstractMetaType *type, const AbstractMetaClass *cppClass) { - QString originalType = translateType(type, cppClass, Generator::ExcludeConst | Generator::ExcludeReference); + QString originalType = translateType(type, cppClass, Options(ExcludeConst) | ExcludeReference); QString strType = originalType; //remove "*" diff --git a/generators/qtdoc/qtdocgenerator.h b/generators/qtdoc/qtdocgenerator.h index c9b411335..8f39e72c8 100644 --- a/generators/qtdoc/qtdocgenerator.h +++ b/generators/qtdoc/qtdocgenerator.h @@ -90,6 +90,7 @@ public: } private: + QString resolveContextForMethod(const QString& methodName); QString transform(const QString& doc); void handleHeadingTag(QXmlStreamReader& reader); @@ -181,8 +182,8 @@ protected: void generateClass(QTextStream& s, const AbstractMetaClass* cppClass); void finishGeneration(); - void writeFunctionArguments(QTextStream&, const AbstractMetaFunction*, uint) const {} - void writeArgumentNames(QTextStream&, const AbstractMetaFunction*, uint) const {} + void writeFunctionArguments(QTextStream&, const AbstractMetaFunction*, Options) const {} + void writeArgumentNames(QTextStream&, const AbstractMetaFunction*, Options) const {} QString subDirectoryForClass(const AbstractMetaClass* clazz) const { Q_ASSERT(false); |