diff options
Diffstat (limited to 'tools/qdoc3/generator.cpp')
-rw-r--r-- | tools/qdoc3/generator.cpp | 247 |
1 files changed, 111 insertions, 136 deletions
diff --git a/tools/qdoc3/generator.cpp b/tools/qdoc3/generator.cpp index 7deca2e..b4768db 100644 --- a/tools/qdoc3/generator.cpp +++ b/tools/qdoc3/generator.cpp @@ -43,7 +43,9 @@ generator.cpp */ #include <qdir.h> +#ifdef DEBUG_MULTIPLE_QDOCCONF_FILES #include <qdebug.h> +#endif #include "codemarker.h" #include "config.h" #include "doc.h" @@ -54,6 +56,7 @@ #include "quoter.h" #include "separator.h" #include "tokenizer.h" +#include "ditaxmlgenerator.h" QT_BEGIN_NAMESPACE @@ -72,6 +75,7 @@ QStringList Generator::styleFiles; QStringList Generator::styleDirs; QString Generator::outDir; QString Generator::project; +QHash<QString, QString> Generator::outputPrefixes; static void singularPlural(Text& text, const NodeList& nodes) { @@ -180,45 +184,52 @@ void Generator::initialize(const Config &config) ++e; } - QStringList noExts; - QStringList scripts = - config.getStringList(CONFIG_SCRIPTS+Config::dot+(*g)->format()); - e = scripts.begin(); - while (e != scripts.end()) { - QString userFriendlyFilePath; - QString filePath = Config::findFile(config.lastLocation(), - scriptFiles, - scriptDirs, - *e, - noExts, - userFriendlyFilePath); - if (!filePath.isEmpty()) - Config::copyFile(config.lastLocation(), - filePath, - userFriendlyFilePath, - (*g)->outputDir() + - "/scripts"); - ++e; - } + // Documentation template handling + QString templateDir = config.getString( + (*g)->format() + Config::dot + CONFIG_TEMPLATEDIR); + + if (!templateDir.isEmpty()) { + QStringList noExts; + QStringList searchDirs = QStringList() << templateDir; + QStringList scripts = + config.getStringList((*g)->format()+Config::dot+CONFIG_SCRIPTS); + e = scripts.begin(); + while (e != scripts.end()) { + QString userFriendlyFilePath; + QString filePath = Config::findFile(config.lastLocation(), + scriptFiles, + searchDirs, + *e, + noExts, + userFriendlyFilePath); + if (!filePath.isEmpty()) + Config::copyFile(config.lastLocation(), + filePath, + userFriendlyFilePath, + (*g)->outputDir() + + "/scripts"); + ++e; + } - QStringList styles = - config.getStringList(CONFIG_STYLES+Config::dot+(*g)->format()); - e = styles.begin(); - while (e != styles.end()) { - QString userFriendlyFilePath; - QString filePath = Config::findFile(config.lastLocation(), - styleFiles, - styleDirs, - *e, - noExts, - userFriendlyFilePath); - if (!filePath.isEmpty()) - Config::copyFile(config.lastLocation(), - filePath, - userFriendlyFilePath, - (*g)->outputDir() + - "/style"); - ++e; + QStringList styles = + config.getStringList((*g)->format()+Config::dot+CONFIG_STYLESHEETS); + e = styles.begin(); + while (e != styles.end()) { + QString userFriendlyFilePath; + QString filePath = Config::findFile(config.lastLocation(), + styleFiles, + searchDirs, + *e, + noExts, + userFriendlyFilePath); + if (!filePath.isEmpty()) + Config::copyFile(config.lastLocation(), + filePath, + userFriendlyFilePath, + (*g)->outputDir() + + "/style"); + ++e; + } } } ++g; @@ -264,6 +275,14 @@ void Generator::initialize(const Config &config) } project = config.getString(CONFIG_PROJECT); + + QStringList prefixes = config.getStringList(CONFIG_OUTPUTPREFIXES); + if (!prefixes.isEmpty()) { + foreach (QString prefix, prefixes) + outputPrefixes[prefix] = config.getString( + CONFIG_OUTPUTPREFIXES + Config::dot + prefix); + } else + outputPrefixes[QLatin1String("QML")] = QLatin1String("qml-"); } void Generator::terminate() @@ -326,6 +345,7 @@ bool Generator::generateText(const Text& text, const Node *relative, CodeMarker *marker) { + bool result = false; if (text.firstAtom() != 0) { int numAtoms = 0; startText(relative, marker); @@ -335,9 +355,9 @@ bool Generator::generateText(const Text& text, true, numAtoms); endText(relative, marker); - return true; + result = true; } - return false; + return result; } #ifdef QDOC_QML @@ -351,24 +371,26 @@ bool Generator::generateQmlText(const Text& text, const QString& /* qmlName */ ) { const Atom* atom = text.firstAtom(); - if (atom == 0) - return false; + bool result = false; - startText(relative, marker); - while (atom) { - if (atom->type() != Atom::QmlText) - atom = atom->next(); - else { - atom = atom->next(); - while (atom && (atom->type() != Atom::EndQmlText)) { - int n = 1 + generateAtom(atom, relative, marker); - while (n-- > 0) - atom = atom->next(); + if (atom != 0) { + startText(relative, marker); + while (atom) { + if (atom->type() != Atom::QmlText) + atom = atom->next(); + else { + atom = atom->next(); + while (atom && (atom->type() != Atom::EndQmlText)) { + int n = 1 + generateAtom(atom, relative, marker); + while (n-- > 0) + atom = atom->next(); + } } } + endText(relative, marker); + result = true; } - endText(relative, marker); - return true; + return result; } #endif @@ -376,25 +398,21 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) { bool quiet = false; - if (node->type() == Node::Function) { -#if 0 - const FunctionNode *func = (const FunctionNode *) node; - if (func->isOverload() && func->metaness() != FunctionNode::Ctor) - generateOverload(node, marker); -#endif - } - else if (node->type() == Node::Fake) { + if (node->type() == Node::Fake) { const FakeNode *fake = static_cast<const FakeNode *>(node); - if (fake->subType() == Node::Example) + if (fake->subType() == Node::Example) { generateExampleFiles(fake, marker); - else if ((fake->subType() == Node::File) || (fake->subType() == Node::Image)) + } + else if ((fake->subType() == Node::File) || (fake->subType() == Node::Image)) { quiet = true; + } } if (node->doc().isEmpty()) { - if (!quiet && !node->isReimp()) // ### might be unnecessary + if (!quiet && !node->isReimp()) { // ### might be unnecessary node->location().warning(tr("No documentation for '%1'") .arg(marker->plainFullName(node))); + } } else { if (node->type() == Node::Function) { @@ -403,9 +421,10 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) generateReimplementedFrom(func, marker); } - if (!generateText(node->doc().body(), node, marker)) + if (!generateText(node->doc().body(), node, marker)) { if (node->isReimp()) return; + } if (node->type() == Node::Enum) { const EnumNode *enume = (const EnumNode *) node; @@ -496,18 +515,16 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) ++a; } } -/* Something like this return value check should be implemented at some point. */ + /* + Something like this return value check should + be implemented at some point. + */ if (func->status() > Node::Obsolete && func->returnType() == "bool" && func->reimplementedFrom() == 0 && !func->isOverload()) { QString body = func->doc().body().toString(); if (!body.contains("return", Qt::CaseInsensitive)) node->doc().location().warning(tr("Undocumented return value")); } -#if 0 - // Now we put this at the top, before the other text. - if (func->reimplementedFrom() != 0) - generateReimplementedFrom(func, marker); -#endif } } @@ -518,8 +535,9 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) Quoter quoter; Doc::quoteFromFile(fake->doc().location(), quoter, fake->name()); QString code = quoter.quoteTo(fake->location(), "", ""); - text << Atom(Atom::Code, code); - generateText(text, fake, marker); + CodeMarker *codeMarker = CodeMarker::markerForFileName(fake->name()); + text << Atom(codeMarker->atomType(), code); + generateText(text, fake, codeMarker); } } } @@ -667,35 +685,6 @@ void Generator::generateExampleFiles(const FakeNode *fake, CodeMarker *marker) generateFileList(fake, marker, Node::Image, QString("Images:")); } -#if 0 - QList<Generator *>::ConstIterator g = generators.begin(); - while (g != generators.end()) { - if (outputFormats.contains((*g)->format())) { - (*g)->initializeGenerator(config); - QStringList extraImages = - config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format()); - QStringList::ConstIterator e = extraImages.begin(); - while (e != extraImages.end()) { - QString userFriendlyFilePath; - QString filePath = Config::findFile(config.lastLocation(), - imageFiles, - imageDirs, - *e, - imgFileExts[(*g)->format()], - userFriendlyFilePath); - if (!filePath.isEmpty()) - Config::copyFile(config.lastLocation(), - filePath, - userFriendlyFilePath, - (*g)->outputDir() + - "/images"); - ++e; - } - } - ++g; - } -#endif - QString Generator::indent(int level, const QString& markedCode) { if (level == 0) @@ -706,26 +695,17 @@ QString Generator::indent(int level, const QString& markedCode) int i = 0; while (i < (int) markedCode.length()) { - if (markedCode.at(i) == QLatin1Char('<')) { - while (i < (int) markedCode.length()) { - t += markedCode.at(i++); - if (markedCode.at(i - 1) == QLatin1Char('>')) - break; - } + if (markedCode.at(i) == QLatin1Char('\n')) { + column = 0; } else { - if (markedCode.at(i) == QLatin1Char('\n')) { - column = 0; + if (column == 0) { + for (int j = 0; j < level; j++) + t += QLatin1Char(' '); } - else { - if (column == 0) { - for (int j = 0; j < level; j++) - t += QLatin1Char(' '); - } - column++; - } - t += markedCode.at(i++); + column++; } + t += markedCode.at(i++); } return t; } @@ -855,7 +835,11 @@ QMap<QString, QString>& Generator::formattingRightMap() return fmtRightMaps[format()]; } -QString Generator::trimmedTrailing(const QString &string) +/* + Trims trailimng whitespace off the \a string and returns + the trimmed string. + */ +QString Generator::trimmedTrailing(const QString& string) { QString trimmed = string; while (trimmed.length() > 0 && trimmed[trimmed.length() - 1].isSpace()) @@ -1085,20 +1069,6 @@ void Generator::generateSince(const Node *node, CodeMarker *marker) } } -/*! - No longer in use. - */ -void Generator::generateOverload(const Node *node, CodeMarker *marker) -{ - Text text; - text << Atom::ParaLeft - << "This function overloads "; - QString t = node->name() + "()"; - text << Atom::AutoLink << t - << Atom::ParaRight; - generateText(text, node, marker); -} - void Generator::generateReimplementedFrom(const FunctionNode *func, CodeMarker *marker) { @@ -1147,8 +1117,8 @@ const Atom *Generator::generateAtomList(const Atom *atom, if (atom->type() == Atom::FormatEndif) { if (generate && numAtoms0 == numAtoms) { - relative->location().warning(tr("Output format %1 not handled") - .arg(format())); + relative->location().warning(tr("Output format %1 not handled %2") + .arg(format()).arg(outFileName())); Atom unhandledFormatAtom(Atom::UnhandledFormat, format()); generateAtomList(&unhandledFormatAtom, relative, @@ -1300,4 +1270,9 @@ QString Generator::fullName(const Node *node, return marker->plainFullName(node, relative); } +QString Generator::outputPrefix(const QString &nodeType) +{ + return outputPrefixes[nodeType]; +} + QT_END_NAMESPACE |