diff options
Diffstat (limited to 'src/qdoc/node.cpp')
-rw-r--r-- | src/qdoc/node.cpp | 238 |
1 files changed, 88 insertions, 150 deletions
diff --git a/src/qdoc/node.cpp b/src/qdoc/node.cpp index 839dd1336..a1df93cb8 100644 --- a/src/qdoc/node.cpp +++ b/src/qdoc/node.cpp @@ -158,49 +158,27 @@ bool Node::changeType(NodeType from, NodeType to) */ bool Node::nodeNameLessThan(const Node *n1, const Node *n2) { +#define LT_RETURN_IF_NOT_EQUAL(a, b) \ + if ((a) != (b)) \ + return (a) < (b); + if (n1->isPageNode() && n2->isPageNode()) { - const PageNode *f1 = static_cast<const PageNode *>(n1); - const PageNode *f2 = static_cast<const PageNode *>(n2); - if (f1->fullTitle() < f2->fullTitle()) - return true; - else if (f1->fullTitle() > f2->fullTitle()) - return false; + LT_RETURN_IF_NOT_EQUAL(n1->fullName(), n2->fullName()); + LT_RETURN_IF_NOT_EQUAL(n1->fullTitle(), n2->fullTitle()); } if (n1->isFunction() && n2->isFunction()) { const FunctionNode *f1 = static_cast<const FunctionNode *>(n1); const FunctionNode *f2 = static_cast<const FunctionNode *>(n2); - if (f1->isConst() < f2->isConst()) - return true; - else if (f1->isConst() > f2->isConst()) - return false; - - if (f1->signature(false, false) < f2->signature(false, false)) - return true; - else if (f1->signature(false, false) > f2->signature(false, false)) - return false; + LT_RETURN_IF_NOT_EQUAL(f1->isConst(), f2->isConst()); + LT_RETURN_IF_NOT_EQUAL(f1->signature(false, false), f2->signature(false, false)); } - if (n1->location().filePath() < n2->location().filePath()) - return true; - else if (n1->location().filePath() > n2->location().filePath()) - return false; - - if (n1->nodeType() < n2->nodeType()) - return true; - else if (n1->nodeType() > n2->nodeType()) - return false; - - if (n1->name() < n2->name()) - return true; - else if (n1->name() > n2->name()) - return false; - - if (n1->access() < n2->access()) - return true; - else if (n1->access() > n2->access()) - return false; + LT_RETURN_IF_NOT_EQUAL(n1->location().filePath(), n2->location().filePath()); + LT_RETURN_IF_NOT_EQUAL(n1->nodeType(), n2->nodeType()); + LT_RETURN_IF_NOT_EQUAL(n1->name(), n2->name()); + LT_RETURN_IF_NOT_EQUAL(n1->access(), n2->access()); return false; } @@ -681,7 +659,7 @@ QString Node::fullName(const Node *relative) const If a match is found, return true. If no match is found, return false. */ -bool Node::match(const QList<int> &types) const +bool Node::match(const QVector<int> &types) const { for (int i=0; i<types.size(); ++i) { if (nodeType() == types.at(i)) @@ -1381,7 +1359,7 @@ QString Node::cleanId(const QString &str) clean += QLatin1Char('a'); } - for (int i = 1; i < (int) name.length(); i++) { + for (int i = 1; i < name.length(); i++) { const QChar c = name[i]; const uint u = c.unicode(); if ((u >= 'a' && u <= 'z') || @@ -2057,16 +2035,16 @@ void Aggregate::findChildren(const QString &name, NodeVector &nodes) const { nodes.clear(); int nonfunctionCount = nonfunctionMap_.count(name); - FunctionMap::const_iterator i = functionMap_.find(name); - if (i != functionMap_.end()) { + auto it = functionMap_.find(name); + if (it != functionMap_.end()) { int functionCount = 0; - FunctionNode *fn = i.value(); + FunctionNode *fn = it.value(); while (fn != nullptr) { ++functionCount; fn = fn->nextOverload(); } nodes.reserve(nonfunctionCount + functionCount); - fn = i.value(); + fn = it.value(); while (fn != nullptr) { nodes.append(fn); fn = fn->nextOverload(); @@ -2075,10 +2053,9 @@ void Aggregate::findChildren(const QString &name, NodeVector &nodes) const nodes.reserve(nonfunctionCount); } if (nonfunctionCount > 0) { - NodeMap::const_iterator i = nonfunctionMap_.find(name); - while (i != nonfunctionMap_.end() && i.key() == name) { - nodes.append(i.value()); - ++i; + for (auto it = nonfunctionMap_.find(name); + it != nonfunctionMap_.end() && it.key() == name; ++it) { + nodes.append(it.value()); } } } @@ -2110,10 +2087,10 @@ Node *Aggregate::findNonfunctionChild(const QString &name, bool (Node::*isMatch) */ FunctionNode *Aggregate::findFunctionChild(const QString &name, const Parameters ¶meters) { - FunctionMap::iterator i = functionMap_.find(name); - if (i == functionMap_.end()) + auto it = functionMap_.find(name); + if (it == functionMap_.end()) return nullptr; - FunctionNode *fn = i.value(); + FunctionNode *fn = it.value(); if (parameters.isEmpty() && fn->parameters().isEmpty() && !fn->isInternal()) return fn; @@ -2136,10 +2113,10 @@ FunctionNode *Aggregate::findFunctionChild(const QString &name, const Parameters } if (parameters.isEmpty()) { - for (fn = i.value(); fn != nullptr; fn = fn->nextOverload()) + for (fn = it.value(); fn != nullptr; fn = fn->nextOverload()) if (!fn->isInternal()) return fn; - return i.value(); + return it.value(); } return nullptr; } @@ -2206,14 +2183,13 @@ void Aggregate::normalizeOverloads() Ensure that none of the primary functions is inactive, private, or marked \e {overload}. */ - FunctionMap::Iterator i = functionMap_.begin(); - while (i != functionMap_.end()) { - FunctionNode *fn = i.value(); + for (auto it = functionMap_.begin(); it != functionMap_.end(); ++it) { + FunctionNode *fn = it.value(); if (fn->isOverload()) { FunctionNode *primary = fn->findPrimaryFunction(); if (primary) { primary->setNextOverload(fn); - i.value() = primary; + it.value() = primary; fn = primary; } else { fn->clearOverloadFlag(); @@ -2244,7 +2220,7 @@ void Aggregate::normalizeOverloads() internalFn->setOverloadNumber(++count); internalFn = internalFn->nextOverload(); } - ++i; // process next function in function map. + // process next function in function map. } /* Recursive part. @@ -2384,11 +2360,11 @@ bool Aggregate::isSameSignature(const FunctionNode *f1, const FunctionNode *f2) */ void Aggregate::addFunction(FunctionNode *fn) { - FunctionMap::iterator i = functionMap_.find(fn->name()); - if (i == functionMap_.end()) + auto it = functionMap_.find(fn->name()); + if (it == functionMap_.end()) functionMap_.insert(fn->name(), fn); else - i.value()->appendOverload(fn); + it.value()->appendOverload(fn); functionCount_++; } @@ -2404,10 +2380,10 @@ void Aggregate::addFunction(FunctionNode *fn) */ void Aggregate::adoptFunction(FunctionNode *fn) { - FunctionMap::iterator i = functionMap_.find(fn->name()); - if (i == functionMap_.end()) + auto it = functionMap_.find(fn->name()); + if (it == functionMap_.end()) functionMap_.insert(fn->name(), fn); - functionCount_++; + ++functionCount_; } /*! @@ -2552,8 +2528,8 @@ QmlPropertyNode *Aggregate::hasQmlProperty(const QString &n, bool attached) cons */ bool Aggregate::hasOverloads(const FunctionNode *fn) const { - FunctionMap::const_iterator i = functionMap_.find(fn->name()); - return (i == functionMap_.end() ? false : (i.value()->nextOverload() != nullptr)); + auto it = functionMap_.find(fn->name()); + return (it == functionMap_.end() ? false : (it.value()->nextOverload() != nullptr)); } /*! @@ -2587,19 +2563,19 @@ void Aggregate::printChildren(const QString &title) */ void Aggregate::removeFunctionNode(FunctionNode *fn) { - FunctionMap::Iterator i = functionMap_.find(fn->name()); - if (i != functionMap_.end()) { - if (i.value() == fn) { + auto it = functionMap_.find(fn->name()); + if (it != functionMap_.end()) { + if (it.value() == fn) { if (fn->nextOverload() != nullptr) { - i.value() = fn->nextOverload(); + it.value() = fn->nextOverload(); fn->setNextOverload(nullptr); fn->setOverloadNumber(0); } else { - functionMap_.erase(i); + functionMap_.erase(it); } } else { - FunctionNode *current = i.value(); + FunctionNode *current = it.value(); while (current != nullptr) { if (current->nextOverload() == fn) { current->setNextOverload(fn->nextOverload()); @@ -2642,9 +2618,8 @@ static bool keep(FunctionNode *fn) */ void Aggregate::findAllFunctions(NodeMapMap &functionIndex) { - FunctionMap::const_iterator i; - for (i = functionMap_.constBegin(); i != functionMap_.constEnd(); ++i) { - FunctionNode *fn = i.value(); + for (auto it = functionMap_.constBegin(); it != functionMap_.constEnd(); ++it) { + FunctionNode *fn = it.value(); if (keep(fn)) functionIndex[fn->name()].insert(fn->parent()->fullDocumentName(), fn); fn = fn->nextOverload(); @@ -2793,15 +2768,15 @@ void Aggregate::findAllSince() QString sinceString = node->since(); // Insert a new entry into each map for each new since string found. if (!node->isPrivate() && !sinceString.isEmpty()) { - NodeMultiMapMap::iterator nsmap = QDocDatabase::newSinceMaps().find(sinceString); + auto nsmap = QDocDatabase::newSinceMaps().find(sinceString); if (nsmap == QDocDatabase::newSinceMaps().end()) nsmap = QDocDatabase::newSinceMaps().insert(sinceString, NodeMultiMap()); - NodeMapMap::iterator ncmap = QDocDatabase::newClassMaps().find(sinceString); + auto ncmap = QDocDatabase::newClassMaps().find(sinceString); if (ncmap == QDocDatabase::newClassMaps().end()) ncmap = QDocDatabase::newClassMaps().insert(sinceString, NodeMap()); - NodeMapMap::iterator nqcmap = QDocDatabase::newQmlTypeMaps().find(sinceString); + auto nqcmap = QDocDatabase::newQmlTypeMaps().find(sinceString); if (nqcmap == QDocDatabase::newQmlTypeMaps().end()) nqcmap = QDocDatabase::newQmlTypeMaps().insert(sinceString, NodeMap()); @@ -2953,7 +2928,7 @@ QString Aggregate::typeWord(bool cap) const is called recursively with the list of base classes from that private or internal class node. */ -void ClassNode::promotePublicBases(const QList<RelatedClass> &bases) +void ClassNode::promotePublicBases(const QVector<RelatedClass> &bases) { if (!bases.isEmpty()) { for (int i = bases.size() - 1; i >= 0; --i) { @@ -3003,7 +2978,7 @@ void ClassNode::removePrivateAndInternalBases() ClassNode *dc = derived_.at(i).node_; if (dc != nullptr && (dc->isPrivate() || dc->isInternal())) { derived_.removeAt(i); - const QList<RelatedClass> &dd = dc->derivedClasses(); + const QVector<RelatedClass> &dd = dc->derivedClasses(); for (int j = dd.size() - 1; j >= 0; --j) derived_.insert(i, dd.at(j)); } @@ -3017,9 +2992,8 @@ void ClassNode::removePrivateAndInternalBases() */ void ClassNode::resolvePropertyOverriddenFromPtrs(PropertyNode *pn) { - QList<RelatedClass>::const_iterator bc = baseClasses().constBegin(); - while (bc != baseClasses().constEnd()) { - ClassNode *cn = bc->node_; + for (const auto &baseClass : qAsConst(baseClasses())) { + ClassNode *cn = baseClass.node_; if (cn) { Node *n = cn->findNonfunctionChild(pn->name(), &Node::isProperty); if (n) { @@ -3030,7 +3004,6 @@ void ClassNode::resolvePropertyOverriddenFromPtrs(PropertyNode *pn) else cn->resolvePropertyOverriddenFromPtrs(pn); } - ++bc; } } @@ -3404,7 +3377,7 @@ PropertyNode *ClassNode::findPropertyNode(const QString &name) PropertyNode *pn = nullptr; - const QList<RelatedClass> &bases = baseClasses(); + const QVector<RelatedClass> &bases = baseClasses(); if (!bases.isEmpty()) { for (int i = 0; i < bases.size(); ++i) { ClassNode *cn = bases[i].node_; @@ -3415,7 +3388,7 @@ PropertyNode *ClassNode::findPropertyNode(const QString &name) } } } - const QList<RelatedClass> &ignoredBases = ignoredBaseClasses(); + const QVector<RelatedClass> &ignoredBases = ignoredBaseClasses(); if (!ignoredBases.isEmpty()) { for (int i = 0; i < ignoredBases.size(); ++i) { ClassNode *cn = ignoredBases[i].node_; @@ -3439,7 +3412,7 @@ PropertyNode *ClassNode::findPropertyNode(const QString &name) QmlTypeNode *ClassNode::findQmlBaseNode() { QmlTypeNode *result = nullptr; - const QList<RelatedClass> &bases = baseClasses(); + const QVector<RelatedClass> &bases = baseClasses(); if (!bases.isEmpty()) { for (int i = 0; i < bases.size(); ++i) { @@ -3473,12 +3446,11 @@ QmlTypeNode *ClassNode::findQmlBaseNode() */ FunctionNode *ClassNode::findOverriddenFunction(const FunctionNode *fn) { - QList<RelatedClass>::Iterator bc = bases_.begin(); - while (bc != bases_.end()) { - ClassNode *cn = bc->node_; + for (auto &bc : bases_) { + ClassNode *cn = bc.node_; if (cn == nullptr) { - cn = QDocDatabase::qdocDB()->findClassNode(bc->path_); - bc->node_ = cn; + cn = QDocDatabase::qdocDB()->findClassNode(bc.path_); + bc.node_ = cn; } if (cn != nullptr) { FunctionNode *result = cn->findFunctionChild(fn); @@ -3488,7 +3460,6 @@ FunctionNode *ClassNode::findOverriddenFunction(const FunctionNode *fn) if (result != nullptr && !result->isNonvirtual()) return result; } - ++bc; } return nullptr; } @@ -3502,31 +3473,27 @@ FunctionNode *ClassNode::findOverriddenFunction(const FunctionNode *fn) */ PropertyNode *ClassNode::findOverriddenProperty(const FunctionNode *fn) { - QList<RelatedClass>::Iterator bc = bases_.begin(); - while (bc != bases_.end()) { - ClassNode *cn = bc->node_; + for (auto &baseClass : bases_) { + ClassNode *cn = baseClass.node_; if (cn == nullptr) { - cn = QDocDatabase::qdocDB()->findClassNode(bc->path_); - bc->node_ = cn; + cn = QDocDatabase::qdocDB()->findClassNode(baseClass.path_); + baseClass.node_ = cn; } if (cn != nullptr) { const NodeList &children = cn->childNodes(); - NodeList::const_iterator i = children.begin(); - while (i != children.end()) { - if ((*i)->isProperty()) { - PropertyNode *pn = static_cast<PropertyNode *>(*i); + for (const auto &child : children) { + if (child->isProperty()) { + PropertyNode *pn = static_cast<PropertyNode *>(child); if (pn->name() == fn->name() || pn->hasAccessFunction(fn->name())) { if (pn->hasDoc()) return pn; } } - i++; } PropertyNode *result = cn->findOverriddenProperty(fn); if (result != nullptr) return result; } - ++bc; } return nullptr; } @@ -3611,17 +3578,7 @@ bool HeaderNode::hasDocumentedChildren() const */ /*! - Returns the node's full title, which is usually whatever - title() returns, but for some cases the full title migth - be different from title(), so this might require changing, - because currently it just returns the title(). - - mws 13/07/2018. This function used to test the node subtype - for File or Image and append text to the title(), but there - are no node subtypes now, so it can't do that. There are no - node type values for File and Image either. Files and images - are used in examples, but the ExampleNode's example files - and example images are stored as lists of path strings. + Returns the node's full title. */ QString PageNode::fullTitle() const { @@ -4263,7 +4220,6 @@ QString FunctionNode::metanessString() const default: return "plain"; } - return QString(); } /*! @@ -4521,29 +4477,21 @@ QString PropertyNode::qualifiedDataType() const */ bool PropertyNode::hasAccessFunction(const QString &name) const { - NodeList::const_iterator i = getters().begin(); - while (i != getters().end()) { - if ((*i)->name() == name) + for (const auto &getter : getters()) { + if (getter->name() == name) return true; - ++i; } - i = setters().begin(); - while (i != setters().end()) { - if ((*i)->name() == name) + for (const auto &setter : setters()) { + if (setter->name() == name) return true; - ++i; } - i = resetters().begin(); - while (i != resetters().end()) { - if ((*i)->name() == name) + for (const auto &resetter : resetters()) { + if (resetter->name() == name) return true; - ++i; } - i = notifiers().begin(); - while (i != notifiers().end()) { - if ((*i)->name() == name) + for (const auto ¬ifier : notifiers()) { + if (notifier->name() == name) return true; - ++i; } return false; } @@ -4866,11 +4814,9 @@ void CollectionNode::addMember(Node *node) bool CollectionNode::hasNamespaces() const { if (!members_.isEmpty()) { - NodeList::const_iterator i = members_.begin(); - while (i != members_.end()) { - if ((*i)->isNamespace()) + for (const auto &member : qAsConst(members_)) { + if (member->isNamespace()) return true; - ++i; } } return false; @@ -4883,11 +4829,9 @@ bool CollectionNode::hasNamespaces() const bool CollectionNode::hasClasses() const { if (!members_.isEmpty()) { - NodeList::const_iterator i = members_.cbegin(); - while (i != members_.cend()) { - if ((*i)->isClassNode()) + for (const auto &member : qAsConst(members_)) { + if (member->isClassNode()) return true; - ++i; } } return false; @@ -4900,11 +4844,9 @@ bool CollectionNode::hasClasses() const void CollectionNode::getMemberNamespaces(NodeMap& out) { out.clear(); - NodeList::const_iterator i = members_.cbegin(); - while (i != members_.cend()) { - if ((*i)->isNamespace()) - out.insert((*i)->name(), (*i)); - ++i; + for (const auto &member : qAsConst(members_)) { + if (member->isNamespace()) + out.insert(member->name(), member); } } @@ -4915,11 +4857,9 @@ void CollectionNode::getMemberNamespaces(NodeMap& out) void CollectionNode::getMemberClasses(NodeMap& out) const { out.clear(); - NodeList::const_iterator i = members_.cbegin(); - while (i != members_.cend()) { - if ((*i)->isClassNode()) - out.insert((*i)->name(), (*i)); - ++i; + for (const auto &i : qAsConst(members_)) { + if (i->isClassNode()) + out.insert(i->name(), i); } } @@ -4931,10 +4871,8 @@ void CollectionNode::printMembers(const QString &title) { qDebug() << title << name() << members_.size(); if (members_.size() > 0) { - for (int i=0; i<members_.size(); ++i) { - Node *n = members_.at(i); - qDebug() << " MEMBER:" << n->name() << n->nodeTypeString(); - } + for (const auto &member : qAsConst(members_)) + qDebug() << " MEMBER:" << member->name() << member->nodeTypeString(); } } |