diff options
Diffstat (limited to 'src/qdoc/generator.cpp')
-rw-r--r-- | src/qdoc/generator.cpp | 530 |
1 files changed, 201 insertions, 329 deletions
diff --git a/src/qdoc/generator.cpp b/src/qdoc/generator.cpp index a65b47333..846db961a 100644 --- a/src/qdoc/generator.cpp +++ b/src/qdoc/generator.cpp @@ -47,7 +47,7 @@ #include <QtCore/qdir.h> #ifndef QT_BOOTSTRAPPED -# include "QtCore/qurl.h" +# include "QtCore/qurl.h" #endif QT_BEGIN_NAMESPACE @@ -55,8 +55,8 @@ QT_BEGIN_NAMESPACE Generator *Generator::currentGenerator_; QStringList Generator::exampleDirs; QStringList Generator::exampleImgExts; -QMap<QString, QMap<QString, QString> > Generator::fmtLeftMaps; -QMap<QString, QMap<QString, QString> > Generator::fmtRightMaps; +QMap<QString, QMap<QString, QString>> Generator::fmtLeftMaps; +QMap<QString, QMap<QString, QString>> Generator::fmtRightMaps; QVector<Generator *> Generator::generators; QStringList Generator::imageDirs; QStringList Generator::imageFiles; @@ -117,9 +117,7 @@ Generator::~Generator() generators.removeAll(this); } -void Generator::appendFullName(Text &text, - const Node *apparentNode, - const Node *relative, +void Generator::appendFullName(Text &text, const Node *apparentNode, const Node *relative, const Node *actualNode) { if (actualNode == nullptr) @@ -130,16 +128,13 @@ void Generator::appendFullName(Text &text, << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); } -void Generator::appendFullName(Text &text, - const Node *apparentNode, - const QString &fullName, +void Generator::appendFullName(Text &text, const Node *apparentNode, const QString &fullName, const Node *actualNode) { if (actualNode == nullptr) actualNode = apparentNode; text << Atom(Atom::LinkNode, CodeMarker::stringForNode(actualNode)) - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << Atom(Atom::String, fullName) + << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << Atom(Atom::String, fullName) << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); } @@ -148,7 +143,7 @@ void Generator::appendFullNames(Text &text, const NodeList &nodes, const Node *r int index = 0; for (const auto &node : nodes) { appendFullName(text, node, relative); - text << comma(index++,nodes.count()); + text << comma(index++, nodes.count()); } } @@ -175,7 +170,7 @@ void Generator::signatureList(const NodeList &nodes, const Node *relative, CodeM Text text; int count = 0; text << Atom(Atom::ListLeft, QString("bullet")); - for (const auto &node: nodes) { + for (const auto &node : nodes) { text << Atom(Atom::ListItemNumber, QString::number(++count)); text << Atom(Atom::ListItemLeft, QString("bullet")); appendSignature(text, node); @@ -187,7 +182,7 @@ void Generator::signatureList(const NodeList &nodes, const Node *relative, CodeM int Generator::appendSortedNames(Text &text, const ClassNode *cn, const QVector<RelatedClass> &rc) { - QMap<QString,Text> classMap; + QMap<QString, Text> classMap; for (const auto &relatedClass : rc) { ClassNode *rcn = relatedClass.node_; if (rcn && rcn->isInAPI()) { @@ -208,12 +203,12 @@ int Generator::appendSortedNames(Text &text, const ClassNode *cn, const QVector< int Generator::appendSortedQmlNames(Text &text, const Node *base, const NodeList &subs) { - QMap<QString,Text> classMap; + QMap<QString, Text> classMap; for (const auto sub : subs) { Text text; - if (!base->isQtQuickNode() || !sub->isQtQuickNode() || - (base->logicalModuleName() == sub->logicalModuleName())) { + if (!base->isQtQuickNode() || !sub->isQtQuickNode() + || (base->logicalModuleName() == sub->logicalModuleName())) { appendFullName(text, sub, base); classMap[text.toString().toLower()] = text; } @@ -254,8 +249,8 @@ void Generator::writeOutFileNames() QFile *Generator::openSubPageFile(const Node *node, const QString &fileName) { QString path = outputDir() + QLatin1Char('/'); - if (Generator::useOutputSubdirs() && !node->outputSubdirectory().isEmpty() && - !outputDir().endsWith(node->outputSubdirectory())) { + if (Generator::useOutputSubdirs() && !node->outputSubdirectory().isEmpty() + && !outputDir().endsWith(node->outputSubdirectory())) { path += node->outputSubdirectory() + QLatin1Char('/'); } path += fileName; @@ -264,11 +259,10 @@ QFile *Generator::openSubPageFile(const Node *node, const QString &fileName) auto outFile = new QFile(outPath); if (!redirectDocumentationToDevNull_ && outFile->exists()) { node->location().error( - tr("Output file already exists; overwriting %1").arg(outFile->fileName())); + tr("Output file already exists; overwriting %1").arg(outFile->fileName())); } if (!outFile->open(QFile::WriteOnly)) { - node->location().fatal( - tr("Cannot open output file '%1'").arg(outFile->fileName())); + node->location().fatal(tr("Cannot open output file '%1'").arg(outFile->fileName())); } qCDebug(lcQdoc, "Writing: %s", qPrintable(path)); outFileNames_ << fileName; @@ -286,7 +280,7 @@ QFile *Generator::openSubPageFile(const Node *node, const QString &fileName) void Generator::beginFilePage(const Node *node, const QString &fileName) { QFile *outFile = openSubPageFile(node, fileName); - QTextStream* out = new QTextStream(outFile); + QTextStream *out = new QTextStream(outFile); #ifndef QT_NO_TEXTCODEC if (outputCodec) out->setCodec(outputCodec); @@ -294,17 +288,17 @@ void Generator::beginFilePage(const Node *node, const QString &fileName) outStreamStack.push(out); } - /*! - Creates the file named \a fileName in the output directory. - Attaches a QTextStream to the created file, which is written - to all over the place using out(). This function calls another - function, \c beginFilePage(), which is really just most of what - this function used to contain. We needed a different version - that doesn't store the \a fileName in the \a node as the output - file name. - - \sa beginFilePage() - */ +/*! + Creates the file named \a fileName in the output directory. + Attaches a QTextStream to the created file, which is written + to all over the place using out(). This function calls another + function, \c beginFilePage(), which is really just most of what + this function used to contain. We needed a different version + that doesn't store the \a fileName in the \a node as the output + file name. + + \sa beginFilePage() +*/ void Generator::beginSubPage(const Node *node, const QString &fileName) { beginFilePage(node, fileName); @@ -342,11 +336,10 @@ static void transmogrify(QString &input, QString &output) uint u = c.unicode(); if (u >= 'A' && u <= 'Z') u += 'a' - 'A'; - if ((u >= 'a' && u <= 'z') || (u >= '0' && u <= '9')) { + if ((u >= 'a' && u <= 'z') || (u >= '0' && u <= '9')) { output += QLatin1Char(u); begun = true; - } - else if (begun) { + } else if (begun) { output += QLatin1Char('-'); begun = false; } @@ -391,8 +384,8 @@ QString Generator::fileBase(const Node *node) const if (node->isExample()) { base.append(QLatin1String("-example")); } - } else if (node->isQmlType() || node->isQmlBasicType() || - node->isJsType() || node->isJsBasicType()) { + } else if (node->isQmlType() || node->isQmlBasicType() || node->isJsType() + || node->isJsBasicType()) { base = node->name(); /* To avoid file name conflicts in the html directory, @@ -401,9 +394,7 @@ QString Generator::fileBase(const Node *node) const module name. */ if (!node->logicalModuleName().isEmpty()) { - base.prepend(node->logicalModuleName() - + outputSuffix(node) - + QLatin1Char('-')); + base.prepend(node->logicalModuleName() + outputSuffix(node) + QLatin1Char('-')); } base.prepend(outputPrefix(node)); } else if (node->isProxyNode()) { @@ -441,8 +432,7 @@ QString Generator::fileBase(const Node *node) const empty (default value), retrieve the file extension from the generator. */ -QString Generator::linkForExampleFile(const QString &path, - const Node *parent, +QString Generator::linkForExampleFile(const QString &path, const Node *parent, const QString &fileExt) { QString link = path; @@ -464,8 +454,7 @@ QString Generator::linkForExampleFile(const QString &path, Helper function to construct a title for a file or image page included in an example. */ -QString Generator::exampleFileTitle(const ExampleNode *relative, - const QString &fileName) +QString Generator::exampleFileTitle(const ExampleNode *relative, const QString &fileName) { QString suffix; if (relative->files().contains(fileName)) @@ -504,9 +493,7 @@ QString Generator::cleanRef(const QString &ref) const QChar c = ref[0]; const uint u = c.unicode(); - if ((u >= 'a' && u <= 'z') || - (u >= 'A' && u <= 'Z') || - (u >= '0' && u <= '9')) { + if ((u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9')) { clean += c; } else if (u == '~') { clean += "dtor."; @@ -519,10 +506,8 @@ QString Generator::cleanRef(const QString &ref) for (int i = 1; i < ref.length(); i++) { const QChar c = ref[i]; const uint u = c.unicode(); - if ((u >= 'a' && u <= 'z') || - (u >= 'A' && u <= 'Z') || - (u >= '0' && u <= '9') || u == '-' || - u == '_' || u == ':' || u == '.') { + if ((u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || u == '-' + || u == '_' || u == ':' || u == '.') { clean += c; } else if (c.isSpace()) { clean += QLatin1Char('-'); @@ -589,26 +574,23 @@ QString Generator::fullDocumentLocation(const Node *node, bool useSubdir) parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension(); else return QString(); - } - else if (node->isQmlType() || node->isQmlBasicType() || - node->isJsType() || node->isJsBasicType()) { + } else if (node->isQmlType() || node->isQmlBasicType() || node->isJsType() + || node->isJsBasicType()) { QString fb = fileBase(node); if (fb.startsWith(outputPrefix(node))) return fb + QLatin1Char('.') + currentGenerator()->fileExtension(); else { QString mq; if (!node->logicalModuleName().isEmpty()) { - mq = node->logicalModuleName().replace(QChar('.'),QChar('-')); + mq = node->logicalModuleName().replace(QChar('.'), QChar('-')); mq = mq.toLower() + QLatin1Char('-'); } - return fdl + outputPrefix(node) + mq + fileBase(node) + - QLatin1Char('.') + currentGenerator()->fileExtension(); + return fdl + outputPrefix(node) + mq + fileBase(node) + QLatin1Char('.') + + currentGenerator()->fileExtension(); } - } - else if (node->isTextPageNode() || node->isCollectionNode()) { + } else if (node->isTextPageNode() || node->isCollectionNode()) { parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension(); - } - else if (fileBase(node).isEmpty()) + } else if (fileBase(node).isEmpty()) return QString(); Node *parentNode = nullptr; @@ -627,8 +609,7 @@ QString Generator::fullDocumentLocation(const Node *node, bool useSubdir) case Node::Proxy: parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension(); break; - case Node::Function: - { + case Node::Function: { const FunctionNode *fn = static_cast<const FunctionNode *>(node); switch (fn->metaness()) { case FunctionNode::JsSignal: @@ -649,8 +630,8 @@ QString Generator::fullDocumentLocation(const Node *node, bool useSubdir) else if (fn->hasOneAssociatedProperty() && fn->doc().isEmpty()) return fullDocumentLocation(fn->firstAssociatedProperty()); else if (fn->overloadNumber() > 0) - anchorRef = QLatin1Char('#') + cleanRef(fn->name()) - + QLatin1Char('-') + QString::number(fn->overloadNumber()); + anchorRef = QLatin1Char('#') + cleanRef(fn->name()) + QLatin1Char('-') + + QString::number(fn->overloadNumber()); else anchorRef = QLatin1Char('#') + cleanRef(fn->name()); break; @@ -665,8 +646,7 @@ QString Generator::fullDocumentLocation(const Node *node, bool useSubdir) case Node::Enum: anchorRef = QLatin1Char('#') + node->name() + "-enum"; break; - case Node::Typedef: - { + case Node::Typedef: { const TypedefNode *tdef = static_cast<const TypedefNode *>(node); if (tdef->associatedEnum()) { return fullDocumentLocation(tdef->associatedEnum()); @@ -694,13 +674,12 @@ QString Generator::fullDocumentLocation(const Node *node, bool useSubdir) case Node::HeaderFile: case Node::Module: case Node::JsModule: - case Node::QmlModule: - { + case Node::QmlModule: { parentName = fileBase(node); - parentName.replace(QLatin1Char('/'), QLatin1Char('-')).replace(QLatin1Char('.'), QLatin1Char('-')); + parentName.replace(QLatin1Char('/'), QLatin1Char('-')) + .replace(QLatin1Char('.'), QLatin1Char('-')); parentName += QLatin1Char('.') + currentGenerator()->fileExtension(); - } - break; + } break; default: break; } @@ -721,10 +700,8 @@ void Generator::generateAlsoList(const Node *node, CodeMarker *marker) if (!alsoList.isEmpty()) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) - << "See also " - << Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD); + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) << "See also " + << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); for (int i = 0; i < alsoList.size(); ++i) text << alsoList.at(i) << separator(i, alsoList.size()); @@ -734,30 +711,21 @@ void Generator::generateAlsoList(const Node *node, CodeMarker *marker) } } -const Atom *Generator::generateAtomList(const Atom *atom, - const Node *relative, - CodeMarker *marker, - bool generate, - int &numAtoms) +const Atom *Generator::generateAtomList(const Atom *atom, const Node *relative, CodeMarker *marker, + bool generate, int &numAtoms) { while (atom != nullptr) { if (atom->type() == Atom::FormatIf) { int numAtoms0 = numAtoms; bool rightFormat = canHandleFormat(atom->string()); - atom = generateAtomList(atom->next(), - relative, - marker, - generate && rightFormat, + atom = generateAtomList(atom->next(), relative, marker, generate && rightFormat, numAtoms); if (atom == nullptr) return nullptr; if (atom->type() == Atom::FormatElse) { ++numAtoms; - atom = generateAtomList(atom->next(), - relative, - marker, - generate && !rightFormat, + atom = generateAtomList(atom->next(), relative, marker, generate && !rightFormat, numAtoms); if (atom == nullptr) return nullptr; @@ -765,23 +733,16 @@ 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 %2") - .arg(format()).arg(outFileName())); + relative->location().warning( + tr("Output format %1 not handled %2").arg(format()).arg(outFileName())); Atom unhandledFormatAtom(Atom::UnhandledFormat, format()); - generateAtomList(&unhandledFormatAtom, - relative, - marker, - generate, - numAtoms); + generateAtomList(&unhandledFormatAtom, relative, marker, generate, numAtoms); } atom = atom->next(); } - } - else if (atom->type() == Atom::FormatElse || - atom->type() == Atom::FormatEndif) { + } else if (atom->type() == Atom::FormatElse || atom->type() == Atom::FormatEndif) { return atom; - } - else { + } else { int n = 1; if (generate) { n += generateAtom(atom, relative, marker); @@ -816,54 +777,49 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (func->isCtor()) { + } else if (func->isCtor()) { Text text; text << "Default constructs an instance of "; text << func->parent()->name() << "."; out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (func->isCCtor()) { + } else if (func->isCCtor()) { Text text; text << "Copy constructor."; out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (func->isMCtor()) { + } else if (func->isMCtor()) { Text text; text << "Move-copy constructor."; out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (func->isCAssign()) { + } else if (func->isCAssign()) { Text text; text << "Copy-assignment operator."; out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (func->isMAssign()) { + } else if (func->isMAssign()) { Text text; text << "Move-assignment operator."; out() << "<p>"; generateText(text, node, marker); out() << "</p>"; - } - else if (!node->isWrapper() && !node->isMarkedReimp()) { + } else if (!node->isWrapper() && !node->isMarkedReimp()) { if (!func->isIgnored()) // undocumented functions added by Q_OBJECT - node->location().warning(tr("No documentation for '%1'").arg(node->plainSignature())); + node->location().warning( + tr("No documentation for '%1'").arg(node->plainSignature())); } } else if (!node->isWrapper() && !node->isMarkedReimp()) { // Don't require documentation of things defined in Q_GADGET if (node->name() != QLatin1String("QtGadgetHelper")) - node->location().warning(tr("No documentation for '%1'").arg(node->plainSignature())); + node->location().warning( + tr("No documentation for '%1'").arg(node->plainSignature())); } - } - else if (!node->isSharingComment()) { + } else if (!node->isSharingComment()) { if (node->isFunction()) { const FunctionNode *fn = static_cast<const FunctionNode *>(node); if (!fn->overridesThis().isEmpty()) @@ -886,8 +842,8 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) const auto &documentedItemList = enume->doc().enumItemNames(); QSet<QString> documentedItems(documentedItemList.cbegin(), documentedItemList.cend()); const QSet<QString> allItems = definedItems + documentedItems; - if (allItems.count() > definedItems.count() || - allItems.count() > documentedItems.count()) { + if (allItems.count() > definedItems.count() + || allItems.count() > documentedItems.count()) { for (const auto &it : allItems) { if (!definedItems.contains(it)) { QString details; @@ -896,10 +852,13 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) details = tr("Maybe you meant '%1'?").arg(best); node->doc().location().warning(tr("No such enum item '%1' in %2") - .arg(it).arg(node->plainFullName()), details); + .arg(it) + .arg(node->plainFullName()), + details); } else if (!documentedItems.contains(it)) { node->doc().location().warning(tr("Undocumented enum item '%1' in %2") - .arg(it).arg(node->plainFullName())); + .arg(it) + .arg(node->plainFullName())); } } } @@ -912,9 +871,9 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) if (!documentedNames.contains(name)) { if (fn->isActive() || fn->isPreliminary()) { if (!fn->isMarkedReimp() && !fn->isOverload()) { - fn->doc().location().warning( - tr("Undocumented parameter '%1' in %2") - .arg(name).arg(node->plainFullName())); + fn->doc().location().warning(tr("Undocumented parameter '%1' in %2") + .arg(name) + .arg(node->plainFullName())); } } } @@ -926,7 +885,8 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) if (!best.isEmpty()) details = tr("Maybe you meant '%1'?").arg(best); fn->doc().location().warning(tr("No such parameter '%1' in %2") - .arg(name).arg(fn->plainFullName()), + .arg(name) + .arg(fn->plainFullName()), details); } } @@ -936,11 +896,12 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) for all functions with a return type. mws 13/12/2018 */ - if (!fn->isObsolete() && fn->returnsBool() && - !fn->isMarkedReimp() && !fn->isOverload()) { + if (!fn->isObsolete() && fn->returnsBool() && !fn->isMarkedReimp() + && !fn->isOverload()) { if (!fn->doc().body().contains("return")) - node->doc().location().warning(tr("Undocumented return value " - "(hint: use 'return' or 'returns' in the text")); + node->doc().location().warning( + tr("Undocumented return value " + "(hint: use 'return' or 'returns' in the text")); } } } @@ -964,7 +925,7 @@ void Generator::generateRequiredLinks(const Node *node, CodeMarker *marker) if (exampleUrl.isEmpty()) { if (!en->noAutoList()) { generateFileList(en, marker, false); // files - generateFileList(en, marker, true); // images + generateFileList(en, marker, true); // images } } else { generateLinkToExample(en, marker, exampleUrl); @@ -978,8 +939,7 @@ void Generator::generateRequiredLinks(const Node *node, CodeMarker *marker) the path is appended to \a baseUrl, after a '/' character if \a baseUrl did not already end in one. */ -void Generator::generateLinkToExample(const ExampleNode *en, - CodeMarker *marker, +void Generator::generateLinkToExample(const ExampleNode *en, CodeMarker *marker, const QString &baseUrl) { QString exampleUrl(baseUrl); @@ -1001,17 +961,14 @@ void Generator::generateLinkToExample(const ExampleNode *en, // Construct a path to the example; <install path>/<example name> QStringList path = QStringList() - << config()->getString(CONFIG_EXAMPLESINSTALLPATH) - << en->name(); + << config()->getString(CONFIG_EXAMPLESINSTALLPATH) << en->name(); path.removeAll({}); Text text; text << Atom::ParaLeft << Atom(Atom::Link, exampleUrl.replace(placeholder, path.join(separator))) - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << Atom(Atom::String, link) - << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) - << Atom::ParaRight; + << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << Atom(Atom::String, link) + << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) << Atom::ParaRight; generateText(text, nullptr, marker); } @@ -1021,12 +978,8 @@ void Generator::addImageToCopy(const ExampleNode *en, const QString &file) QDir dirInfo; QString userFriendlyFilePath; const QString prefix("/images/used-in-examples/"); - QString srcPath = Config::findFile(en->location(), - QStringList(), - exampleDirs, - file, - exampleImgExts, - &userFriendlyFilePath); + QString srcPath = Config::findFile(en->location(), QStringList(), exampleDirs, file, + exampleImgExts, &userFriendlyFilePath); outFileNames_ << prefix.mid(1) + userFriendlyFilePath; userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/')); QString imgOutDir = outDir_ + prefix + userFriendlyFilePath; @@ -1054,7 +1007,7 @@ void Generator::generateFileList(const ExampleNode *en, CodeMarker *marker, bool paths = en->images(); tag = "Images:"; atomType = Atom::ExampleImageLink; - } else { //files + } else { // files paths = en->files(); tag = "Files:"; } @@ -1074,13 +1027,9 @@ void Generator::generateFileList(const ExampleNode *en, CodeMarker *marker, bool openedList.next(); text << Atom(Atom::ListItemNumber, openedList.numberString()) - << Atom(Atom::ListItemLeft, openedList.styleString()) - << Atom::ParaLeft - << Atom(atomType, file) - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << file - << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) - << Atom::ParaRight + << Atom(Atom::ListItemLeft, openedList.styleString()) << Atom::ParaLeft + << Atom(atomType, file) << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << file + << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) << Atom::ParaRight << Atom(Atom::ListItemRight, openedList.styleString()); path = file; } @@ -1093,10 +1042,8 @@ void Generator::generateInheritedBy(const ClassNode *classe, CodeMarker *marker) { if (!classe->derivedClasses().isEmpty()) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) - << "Inherited by: " - << Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD); + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Inherited by: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); appendSortedNames(text, classe, classe->derivedClasses()); text << Atom::ParaRight; @@ -1108,10 +1055,8 @@ void Generator::generateInherits(const ClassNode *classe, CodeMarker *marker) { if (!classe->baseClasses().isEmpty()) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) - << "Inherits: " - << Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD); + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Inherits: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); int index = 0; const QVector<RelatedClass> &baseClasses = classe->baseClasses(); @@ -1121,8 +1066,7 @@ void Generator::generateInherits(const ClassNode *classe, CodeMarker *marker) if (cls.access_ == Node::Protected) { text << " (protected)"; - } - else if (cls.access_ == Node::Private) { + } else if (cls.access_ == Node::Private) { text << " (private)"; } text << separator(index++, classe->baseClasses().count()); @@ -1188,7 +1132,8 @@ void Generator::generateDocumentation(Node *node) // other use cases pop up. QString name = cn->name().toLower(); name.replace(QChar(' '), QString("-")); - QString filename = cn->tree()->physicalModuleName() + "-" + name + "." + fileExtension(); + QString filename = + cn->tree()->physicalModuleName() + "-" + name + "." + fileExtension(); beginSubPage(node, filename); generateGenericCollectionPage(cn, marker); endSubPage(); @@ -1198,8 +1143,8 @@ void Generator::generateDocumentation(Node *node) generatePageNode(static_cast<PageNode *>(node), marker); endSubPage(); } else if (node->isAggregate()) { - if ((node->isClassNode() || node->isHeader() || node->isNamespace()) && - node->docMustBeGenerated()) { + if ((node->isClassNode() || node->isHeader() || node->isNamespace()) + && node->docMustBeGenerated()) { beginSubPage(node, fileName(node)); generateCppReferencePage(static_cast<Aggregate *>(node), marker); endSubPage(); @@ -1240,10 +1185,8 @@ void Generator::generateMaintainerList(const Aggregate *node, CodeMarker *marker if (!sl.isEmpty()) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "Maintained by: " - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Maintained by: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); for (int i = 0; i < sl.size(); ++i) text << sl.at(i) << separator(i, sl.size()); @@ -1257,8 +1200,7 @@ void Generator::generateMaintainerList(const Aggregate *node, CodeMarker *marker Output the "Inherit by" list for the QML element, if it is inherited by any other elements. */ -void Generator::generateQmlInheritedBy(const QmlTypeNode *qcn, - CodeMarker *marker) +void Generator::generateQmlInheritedBy(const QmlTypeNode *qcn, CodeMarker *marker) { if (qcn) { NodeList subs; @@ -1277,10 +1219,8 @@ void Generator::generateQmlInheritedBy(const QmlTypeNode *qcn, Extract sections of markup text surrounded by \e qmltext and \e endqmltext and output them. */ -bool Generator::generateQmlText(const Text &text, - const Node *relative, - CodeMarker *marker, - const QString &/* qmlName */ ) +bool Generator::generateQmlText(const Text &text, const Node *relative, CodeMarker *marker, + const QString & /* qmlName */) { const Atom *atom = text.firstAtom(); bool result = false; @@ -1314,7 +1254,8 @@ void Generator::generateReimplementsClause(const FunctionNode *fn, CodeMarker *m if (overrides->hasDoc()) { Text text; text << Atom::ParaLeft << "Reimplements: "; - QString fullName = overrides->parent()->name() + "::" + overrides->signature(false, true); + QString fullName = + overrides->parent()->name() + "::" + overrides->signature(false, true); appendFullName(text, overrides->parent(), fullName, overrides); text << "." << Atom::ParaRight; generateText(text, fn, marker); @@ -1325,13 +1266,14 @@ void Generator::generateReimplementsClause(const FunctionNode *fn, CodeMarker *m if (sameName && sameName->hasDoc()) { Text text; text << Atom::ParaLeft << "Reimplements an access function for property: "; - QString fullName = sameName->parent()->name() + "::" + sameName->name(); + QString fullName = sameName->parent()->name() + "::" + sameName->name(); appendFullName(text, sameName->parent(), fullName, sameName); text << "." << Atom::ParaRight; generateText(text, fn, marker); } else { - fn->doc().location().warning(tr("Illegal \\reimp; no documented virtual function for %1") - .arg(fn->plainSignature())); + fn->doc().location().warning( + tr("Illegal \\reimp; no documented virtual function for %1") + .arg(fn->plainSignature())); } } } @@ -1353,16 +1295,10 @@ void Generator::generateSince(const Node *node, CodeMarker *marker) { if (!node->since().isEmpty()) { Text text; - text << Atom::ParaLeft - << "This " - << typeString(node) - << " was introduced "; + text << Atom::ParaLeft << "This " << typeString(node) << " was introduced "; if (node->isEnumType()) text << "or modified "; - text << "in " - << formatSince(node) - << "." - << Atom::ParaRight; + text << "in " << formatSince(node) << "." << Atom::ParaRight; generateText(text, node, marker); } } @@ -1376,13 +1312,9 @@ void Generator::generateStatus(const Node *node, CodeMarker *marker) // Do nothing. break; case Node::Preliminary: - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "This " - << typeString(node) - << " is under development and is subject to change." - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) - << Atom::ParaRight; + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) << "This " + << typeString(node) << " is under development and is subject to change." + << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << Atom::ParaRight; break; case Node::Deprecated: text << Atom::ParaLeft; @@ -1418,11 +1350,10 @@ void Generator::generateStatus(const Node *node, CodeMarker *marker) void Generator::generatePrivateSignalNote(const Node *node, CodeMarker *marker) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "Note: " - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) - << "This is a private signal. It can be used in signal connections but cannot be emitted by the user." + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Note: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) + << "This is a private signal. It can be used in signal connections but cannot be emitted " + "by the user." << Atom::ParaRight; generateText(text, node, marker); } @@ -1434,16 +1365,11 @@ void Generator::generatePrivateSignalNote(const Node *node, CodeMarker *marker) void Generator::generateInvokableNote(const Node *node, CodeMarker *marker) { Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "Note: " - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Note: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << "This function can be invoked via the meta-object system and from QML. See " - << Atom(Atom::Link,"Q_INVOKABLE") - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << "Q_INVOKABLE" - << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) - << "." + << Atom(Atom::Link, "Q_INVOKABLE") << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) + << "Q_INVOKABLE" << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) << "." << Atom::ParaRight; generateText(text, node, marker); } @@ -1453,19 +1379,13 @@ void Generator::generateInvokableNote(const Node *node, CodeMarker *marker) is the node that represents the entity where a qdoc comment was found, and \a text represents the qdoc comment. */ -bool Generator::generateText(const Text &text, - const Node *relative, - CodeMarker *marker) +bool Generator::generateText(const Text &text, const Node *relative, CodeMarker *marker) { bool result = false; if (text.firstAtom() != nullptr) { int numAtoms = 0; initializeTextOutput(); - generateAtomList(text.firstAtom(), - relative, - marker, - true, - numAtoms); + generateAtomList(text.firstAtom(), relative, marker, true, numAtoms); result = true; } return result; @@ -1480,16 +1400,14 @@ bool Generator::generateText(const Text &text, nonreentrant, and true is returned. If there are no exceptions, the three node lists remain empty and false is returned. */ -bool Generator::hasExceptions(const Node *node, - NodeList &reentrant, - NodeList &threadsafe, +bool Generator::hasExceptions(const Node *node, NodeList &reentrant, NodeList &threadsafe, NodeList &nonreentrant) { bool result = false; Node::ThreadSafeness ts = node->threadSafeness(); const NodeList &children = static_cast<const Aggregate *>(node)->childNodes(); for (auto child : children) { - if (!child->isObsolete()){ + if (!child->isObsolete()) { switch (child->threadSafeness()) { case Node::Reentrant: reentrant.append(child); @@ -1515,11 +1433,8 @@ bool Generator::hasExceptions(const Node *node, static void startNote(Text &text) { - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "Note:" - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) - << " "; + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Note:" << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << " "; } /*! @@ -1535,30 +1450,19 @@ void Generator::generateThreadSafeness(const Node *node, CodeMarker *marker) Node::ThreadSafeness ts = node->threadSafeness(); bool exceptions = false; - rlink << Atom(Atom::Link,"reentrant") - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << "reentrant" - << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); + rlink << Atom(Atom::Link, "reentrant") << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) + << "reentrant" << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); - tlink << Atom(Atom::Link,"thread-safe") - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << "thread-safe" - << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); + tlink << Atom(Atom::Link, "thread-safe") << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) + << "thread-safe" << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); switch (ts) { case Node::UnspecifiedSafeness: break; case Node::NonReentrant: - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) - << "Warning:" - << Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD) - << " This " - << typeString(node) - << " is not " - << rlink - << "." - << Atom::ParaRight; + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Warning:" << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << " This " + << typeString(node) << " is not " << rlink << "." << Atom::ParaRight; break; case Node::Reentrant: case Node::ThreadSafe: @@ -1575,8 +1479,7 @@ void Generator::generateThreadSafeness(const Node *node, CodeMarker *marker) text << "."; else text << " with the following exceptions:"; - } - else { + } else { text << "This " << typeString(node) << " is "; if (ts == Node::ThreadSafe) text << tlink; @@ -1589,46 +1492,33 @@ void Generator::generateThreadSafeness(const Node *node, CodeMarker *marker) default: break; } - generateText(text,node,marker); + generateText(text, node, marker); if (exceptions) { text.clear(); if (ts == Node::Reentrant) { if (!nonreentrant.isEmpty()) { startNote(text); - text << "These functions are not " - << rlink - << ":" - << Atom::ParaRight; + text << "These functions are not " << rlink << ":" << Atom::ParaRight; signatureList(nonreentrant, node, marker); } if (!threadsafe.isEmpty()) { text.clear(); startNote(text); - text << "These functions are also " - << tlink - << ":" - << Atom::ParaRight; + text << "These functions are also " << tlink << ":" << Atom::ParaRight; generateText(text, node, marker); signatureList(threadsafe, node, marker); } - } - else { // thread-safe + } else { // thread-safe if (!reentrant.isEmpty()) { startNote(text); - text << "These functions are only " - << rlink - << ":" - << Atom::ParaRight; + text << "These functions are only " << rlink << ":" << Atom::ParaRight; signatureList(reentrant, node, marker); } if (!nonreentrant.isEmpty()) { text.clear(); startNote(text); - text << "These functions are not " - << rlink - << ":" - << Atom::ParaRight; + text << "These functions are not " << rlink << ":" << Atom::ParaRight; signatureList(nonreentrant, node, marker); } } @@ -1683,19 +1573,15 @@ void Generator::generateOverloadedSignal(const Node *node, CodeMarker *marker) return; Text text; - text << Atom::ParaLeft - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) - << "Note:" - << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) - << " Signal " - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_ITALIC) - << node->name() + text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) + << "Note:" << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << " Signal " + << Atom(Atom::FormattingLeft, ATOM_FORMATTING_ITALIC) << node->name() << Atom(Atom::FormattingRight, ATOM_FORMATTING_ITALIC) << " is overloaded in this class. " "To connect to this signal by using the function pointer syntax, Qt " "provides a convenient helper for obtaining the function pointer as " "shown in this example:" - << Atom(Atom::Code, marker->markedUpCode(code, node, node->location())); + << Atom(Atom::Code, marker->markedUpCode(code, node, node->location())); generateText(text, node, marker); } @@ -1750,7 +1636,7 @@ QString Generator::getMetadataElement(const Aggregate *inner, const QString &tag QStringList Generator::getMetadataElements(const Aggregate *inner, const QString &t) { QStringList s; - QStringMultiMap& metaTagMap = const_cast<QStringMultiMap&>(inner->doc().metaTagMap()); + QStringMultiMap &metaTagMap = const_cast<QStringMultiMap &>(inner->doc().metaTagMap()); s = metaTagMap.values(t); if (!s.isEmpty()) metaTagMap.remove(t); @@ -1763,19 +1649,13 @@ QStringList Generator::getMetadataElements(const Aggregate *inner, const QString QString Generator::imageFileName(const Node *relative, const QString &fileBase) { QString userFriendlyFilePath; - QString filePath = Config::findFile(relative->doc().location(), - imageFiles, - imageDirs, - fileBase, - imgFileExts[format()], - &userFriendlyFilePath); + QString filePath = Config::findFile(relative->doc().location(), imageFiles, imageDirs, fileBase, + imgFileExts[format()], &userFriendlyFilePath); if (filePath.isEmpty()) return QString(); - QString path = Config::copyFile(relative->doc().location(), - filePath, - userFriendlyFilePath, + QString path = Config::copyFile(relative->doc().location(), filePath, userFriendlyFilePath, outputDir() + QLatin1String("/images")); int images_slash = path.lastIndexOf("images/"); QString relImagePath; @@ -1796,8 +1676,7 @@ QString Generator::indent(int level, const QString &markedCode) while (i < markedCode.length()) { if (markedCode.at(i) == QLatin1Char('\n')) { column = 0; - } - else { + } else { if (column == 0) { for (int j = 0; j < level; j++) t += QLatin1Char(' '); @@ -1809,8 +1688,6 @@ QString Generator::indent(int level, const QString &markedCode) return t; } - - void Generator::initialize(const Config &config) { outputFormats = config.getOutputFormats(); @@ -1847,13 +1724,15 @@ void Generator::initialize(const Config &config) config.lastLocation().warning(tr("Formatting '%1' must " "have exactly one " "parameter (found %2)") - .arg(n).arg(numParams)); + .arg(n) + .arg(numParams)); } else if (numOccs > 1) { config.lastLocation().fatal(tr("Formatting '%1' must " "contain exactly one " "occurrence of '\\1' " "(found %2)") - .arg(n).arg(numOccs)); + .arg(n) + .arg(numOccs)); } else { int paramPos = def.indexOf("\1"); fmtLeftMaps[f].insert(n, def.left(paramPos)); @@ -1889,15 +1768,16 @@ void Generator::initialize(const Config &config) Creates template-specific subdirs (e.g. /styles and /scripts for HTML) and copies the files to them. */ -void Generator::copyTemplateFiles(const Config &config, const QString &configVar, const QString &subDir) +void Generator::copyTemplateFiles(const Config &config, const QString &configVar, + const QString &subDir) { QStringList files = config.getCanonicalPathList(configVar, true); if (!files.isEmpty()) { QDir dirInfo; QString templateDir = outDir_ + QLatin1Char('/') + subDir; if (!dirInfo.exists(templateDir) && !dirInfo.mkdir(templateDir)) { - config.lastLocation().fatal(tr("Cannot create %1 directory '%2'") - .arg(subDir, templateDir)); + config.lastLocation().fatal( + tr("Cannot create %1 directory '%2'").arg(subDir, templateDir)); } else { for (const auto &file : files) { if (!file.isEmpty()) @@ -1945,7 +1825,8 @@ void Generator::initializeFormat(const Config &config) return; if (!dirInfo.exists(outDir_ + "/images") && !dirInfo.mkdir(outDir_ + "/images")) - config.lastLocation().fatal(tr("Cannot create images directory '%1'").arg(outDir_ + "/images")); + config.lastLocation().fatal( + tr("Cannot create images directory '%1'").arg(outDir_ + "/images")); copyTemplateFiles(config, format() + Config::dot + CONFIG_STYLESHEETS, "style"); copyTemplateFiles(config, format() + Config::dot + CONFIG_SCRIPTS, "scripts"); @@ -2021,42 +1902,36 @@ QString Generator::outputSuffix(const Node *node) return QString(); } -bool Generator::parseArg(const QString &src, - const QString &tag, - int *pos, - int n, - QStringRef *contents, - QStringRef *par1, - bool debug) -{ -#define SKIP_CHAR(c) \ - if (debug) \ - qDebug() << "looking for " << c << " at " << QString(src.data() + i, n - i); \ - if (i >= n || src[i] != c) { \ - if (debug) \ - qDebug() << " char '" << c << "' not found"; \ - return false; \ -} \ +bool Generator::parseArg(const QString &src, const QString &tag, int *pos, int n, + QStringRef *contents, QStringRef *par1, bool debug) +{ +#define SKIP_CHAR(c) \ + if (debug) \ + qDebug() << "looking for " << c << " at " << QString(src.data() + i, n - i); \ + if (i >= n || src[i] != c) { \ + if (debug) \ + qDebug() << " char '" << c << "' not found"; \ + return false; \ + } \ ++i; - -#define SKIP_SPACE \ - while (i < n && src[i] == ' ') \ - ++i; +#define SKIP_SPACE \ + while (i < n && src[i] == ' ') \ + ++i; int i = *pos; int j = i; // assume "<@" has been parsed outside - //SKIP_CHAR('<'); - //SKIP_CHAR('@'); + // SKIP_CHAR('<'); + // SKIP_CHAR('@'); if (tag != QStringRef(&src, i, tag.length())) { return false; } if (debug) - qDebug() << "haystack:" << src << "needle:" << tag << "i:" <<i; + qDebug() << "haystack:" << src << "needle:" << tag << "i:" << i; // skip tag i += tag.length(); @@ -2188,8 +2063,7 @@ void Generator::supplementAlsoList(const Node *node, QVector<Text> &alsoList) alternateFunc = fn->parent()->findFunctionChild(alternateName, QString()); } } - } - else if (!fn->name().isEmpty()) { + } else if (!fn->name().isEmpty()) { alternateName = "set"; alternateName += fn->name()[0].toUpper(); alternateName += fn->name().mid(1); @@ -2208,8 +2082,7 @@ void Generator::supplementAlsoList(const Node *node, QVector<Text> &alsoList) Text also; also << Atom(Atom::Link, alternateName) - << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) - << alternateName + << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << alternateName << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); alsoList.prepend(also); } @@ -2221,8 +2094,8 @@ void Generator::supplementAlsoList(const Node *node, QVector<Text> &alsoList) void Generator::terminate() { for (const auto &generator : qAsConst(generators)) { - if (outputFormats.contains(generator->format())) - generator->terminateGenerator(); + if (outputFormats.contains(generator->format())) + generator->terminateGenerator(); } fmtLeftMaps.clear(); @@ -2233,15 +2106,14 @@ void Generator::terminate() outDir_.clear(); } -void Generator::terminateGenerator() -{ -} +void Generator::terminateGenerator() {} /*! Trims trailing whitespace off the \a string and returns the trimmed string. */ -QString Generator::trimmedTrailing(const QString &string, const QString &prefix, const QString &suffix) +QString Generator::trimmedTrailing(const QString &string, const QString &prefix, + const QString &suffix) { QString trimmed = string; while (trimmed.length() > 0 && trimmed[trimmed.length() - 1].isSpace()) @@ -2304,8 +2176,8 @@ QString Generator::typeString(const Node *node) void Generator::unknownAtom(const Atom *atom) { - Location::internalError(tr("unknown atom type '%1' in %2 generator") - .arg(atom->typeString()).arg(format())); + Location::internalError( + tr("unknown atom type '%1' in %2 generator").arg(atom->typeString()).arg(format())); } QT_END_NAMESPACE |