summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2024-02-12 21:03:13 +0100
committerLuca Di Sera <luca.disera@qt.io>2024-02-21 13:21:53 +0100
commita907cef7c7d0261ede0c5352010ac2ff6597f638 (patch)
tree1ff6daaf2d8e506364bdd80ae5f0513e38f46854
parent70279ae7255f0c1125d1d3dd1f297c935f800298 (diff)
QDoc: Remove open namespaces
When QDoc obtains the user-provided documentation, it tries to "tie" it to an internal representation of a documentable-element based on the "topic commands" of the specific documentation. For example, a "\class" command, a "\property" command and so on. When performing this process, while encountering a documentation that "ties" to certain documentable elements that can be container for other elements, such as a C++ class or namespace, QDoc stores that documentable element as an "open namespace". "open namespaces" are later used when QDoc tries to "tie" a documentation to an element that might be contained by another element. For example, if QDoc is trying to "tie" a documentation that has a "\property" "topic", and it has previously tied a "\class" "topic" to some C++ class, it will consider the namespace that class provides when looking for the element that the "\property" refers to. This allows users to elide fully qualifying certain elements. For example, if the documentation was trying to refer to a "\property" `foo` under a class `Bar` that was previously added as an "open namespace", the user could write a "\property" topic as "\property foo", with QDoc filling in the `Bar` part of the qualified path `Bar::foo`. "open namespaces" are currently granular at the file-level, so that all "open namespaces" that are found by "tying" the documentation block in a file will be valid only for other documentation blocks in that file. QDoc performs otherwise shallow searches, currently, so that non-qualified "topics" would not be found without an "open namespace" available. While this allows for a bit more lazyness on the part of the documentation writer and possibly some minor amount of reducing repetition, it disables certain properties that are desirable for optmization changes that are expected to be performed for QDoc. For example, it reduces the atomicity of a single documentation-block, creating an ordering between different blocks that prevents parallelization efforts. For this same reason, it prevents certain blocks from being freely moved, for example, as they cannot be resolved in a file that does not document a suitable "open namespace". Thus, "open namespaces" are now removed from QDoc. "open namespaces" are generally stored in `QDocDatabase`, a singleton class that manages and stores most of the shared mutable state in QDoc. `QDocDatabase::m_openNamespace`, the member storing the available "open namespaces" was removed. `QDocDatabase::clearOpenNamespaces` which was used by consumers of the "open namespaces" to reset the available "open namespaces" was removed. `QDoc::insertOpenNamespace` which was used by consumers of the "open namespaces" to make an "open namespace" available was removed. `QDocDatabase::findNodeInOpenNamespace` which was used by consumers of "open namespaces" to "tie" a "topic command" to a documentable entity while taking into consideration the available "open namespaces" was removed. All usages of the above methods were removed. QDoc regression test suites were updated to take the changes into account. Task-number: QTBUG-111686 Change-Id: Id0df9a147b581dadf1fb6a4cf50cd1b5ae71b563 Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp5
-rw-r--r--src/qdoc/qdoc/src/qdoc/cppcodeparser.cpp15
-rw-r--r--src/qdoc/qdoc/src/qdoc/puredocparser.cpp6
-rw-r--r--src/qdoc/qdoc/src/qdoc/qdocdatabase.cpp33
-rw-r--r--src/qdoc/qdoc/src/qdoc/qdocdatabase.h4
-rw-r--r--src/qdoc/qdoc/tests/generatedoutput/testdata/testcpp/testcpp.cpp8
-rw-r--r--src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/comprehensiveproject/testcpp.cpp6
-rw-r--r--src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/scopedenum/testcpp.cpp6
-rw-r--r--src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/testtemplate/testcpp.cpp6
9 files changed, 14 insertions, 75 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp b/src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp
index 9c32d0e21..9f1818e91 100644
--- a/src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp
@@ -1719,11 +1719,6 @@ static float getUnpatchedVersion(QString t)
*/
void ClangCodeParser::parseSourceFile(const Location & /*location*/, const QString &filePath, CppCodeParser& cpp_code_parser)
{
- /*
- The set of open namespaces is cleared before parsing
- each source file. The word "source" here means cpp file.
- */
- m_qdb->clearOpenNamespaces();
flags_ = static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete
| CXTranslationUnit_SkipFunctionBodies
| CXTranslationUnit_KeepGoing);
diff --git a/src/qdoc/qdoc/src/qdoc/cppcodeparser.cpp b/src/qdoc/qdoc/src/qdoc/cppcodeparser.cpp
index 2432c7cf9..c864febb4 100644
--- a/src/qdoc/qdoc/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/qdoc/src/qdoc/cppcodeparser.cpp
@@ -123,9 +123,7 @@ Node *CppCodeParser::processTopicCommand(const Doc &doc, const QString &command,
idx = words.size() - 1;
path = words[idx].split("::");
- node = database->findNodeInOpenNamespace(path, s_nodeTypeTestFuncMap[command]);
- if (node == nullptr)
- node = database->findNodeByNameAndType(path, s_nodeTypeTestFuncMap[command]);
+ node = database->findNodeByNameAndType(path, s_nodeTypeTestFuncMap[command]);
// Allow representing a type alias as a class
if (node == nullptr && command == COMMAND_CLASS) {
node = database->findNodeByNameAndType(path, &Node::isTypeAlias);
@@ -151,17 +149,6 @@ Node *CppCodeParser::processTopicCommand(const Doc &doc, const QString &command,
ns->markSeen();
ns->setWhereDocumented(ns->tree()->camelCaseModuleName());
}
- /*
- This treats a class as a namespace.
- */
- if ((type == Node::Class) || (type == Node::Namespace) || (type == Node::Struct)
- || (type == Node::Union)) {
- if (path.size() > 1) {
- path.pop_back();
- QString ns = path.join(QLatin1String("::"));
- database->insertOpenNamespace(ns);
- }
- }
}
return node;
} else if (command == COMMAND_EXAMPLE) {
diff --git a/src/qdoc/qdoc/src/qdoc/puredocparser.cpp b/src/qdoc/qdoc/src/qdoc/puredocparser.cpp
index d220e0c2f..0565d01b6 100644
--- a/src/qdoc/qdoc/src/qdoc/puredocparser.cpp
+++ b/src/qdoc/qdoc/src/qdoc/puredocparser.cpp
@@ -37,12 +37,6 @@ void PureDocParser::parseSourceFile(const Location &location, const QString &fil
return;
}
- /*
- The set of open namespaces is cleared before parsing
- each source file. The word "source" here means cpp file.
- */
- m_qdb->clearOpenNamespaces();
-
processQdocComments(in, cpp_code_parser);
in.close();
}
diff --git a/src/qdoc/qdoc/src/qdoc/qdocdatabase.cpp b/src/qdoc/qdoc/src/qdoc/qdocdatabase.cpp
index eda5f23d5..9d811a881 100644
--- a/src/qdoc/qdoc/src/qdoc/qdocdatabase.cpp
+++ b/src/qdoc/qdoc/src/qdoc/qdocdatabase.cpp
@@ -1193,39 +1193,6 @@ void QDocDatabase::generateIndex(const QString &fileName, const QString &url, co
}
/*!
- Find a node of the specified \a type that is reached with
- the specified \a path qualified with the name of one of the
- open namespaces (might not be any open ones). If the node
- is found in an open namespace, prefix \a path with the name
- of the open namespace and "::" and return a pointer to the
- node. Otherwise return \c nullptr.
-
- This function only searches in the current primary tree.
- */
-Node *QDocDatabase::findNodeInOpenNamespace(QStringList &path, bool (Node::*isMatch)() const)
-{
- if (path.isEmpty())
- return nullptr;
- Node *n = nullptr;
- if (!m_openNamespaces.isEmpty()) {
- const auto &openNamespaces = m_openNamespaces;
- for (const QString &t : openNamespaces) {
- QStringList p;
- if (t != path[0])
- p = t.split("::") + path;
- else
- p = path;
- n = primaryTree()->findNodeByNameAndType(p, isMatch);
- if (n) {
- path = p;
- break;
- }
- }
- }
- return n;
-}
-
-/*!
Returns the collection node representing the module that \a relative
node belongs to, or \c nullptr if there is no such module in the
primary tree.
diff --git a/src/qdoc/qdoc/src/qdoc/qdocdatabase.h b/src/qdoc/qdoc/src/qdoc/qdocdatabase.h
index d779a161e..df2b4135c 100644
--- a/src/qdoc/qdoc/src/qdoc/qdocdatabase.h
+++ b/src/qdoc/qdoc/src/qdoc/qdocdatabase.h
@@ -263,7 +263,6 @@ public:
{
return primaryTree()->findRelatesNode(path);
}
- Node *findNodeInOpenNamespace(QStringList &path, bool (Node::*)() const);
/*******************************************************************/
/*****************************************************************************
@@ -331,8 +330,6 @@ public:
void generateIndex(const QString &fileName, const QString &url, const QString &title,
Generator *g);
- void clearOpenNamespaces() { m_openNamespaces.clear(); }
- void insertOpenNamespace(const QString &path) { m_openNamespaces.insert(path); }
void processForest();
NamespaceNode *primaryTreeRoot() { return m_forest.primaryTreeRoot(); }
@@ -390,7 +387,6 @@ private:
NodeMultiMap m_attributions {};
NodeMapMap m_functionIndex {};
TextToNodeMap m_legaleseTexts {};
- QSet<QString> m_openNamespaces {};
QMultiHash<Tree*, FindFunctionPtr> m_completedFindFunctions {};
};
diff --git a/src/qdoc/qdoc/tests/generatedoutput/testdata/testcpp/testcpp.cpp b/src/qdoc/qdoc/tests/generatedoutput/testdata/testcpp/testcpp.cpp
index b51f0291b..2693e8216 100644
--- a/src/qdoc/qdoc/tests/generatedoutput/testdata/testcpp/testcpp.cpp
+++ b/src/qdoc/qdoc/tests/generatedoutput/testdata/testcpp/testcpp.cpp
@@ -111,7 +111,7 @@ namespace TestQDoc {
/*!
\if defined(test_properties)
- \property Test::id
+ \property TestQDoc::Test::id
\else
\nothing
\endif
@@ -263,7 +263,7 @@ void Test::virtualFun()
*/
/*!
- \typedef Test::SomeType
+ \typedef TestQDoc::Test::SomeType
\brief A typedef.
*/
@@ -290,12 +290,12 @@ void TestDerived::virtualFun()
*/
/*!
- \typealias TestDerived::DerivedType
+ \typealias TestQDoc::TestDerived::DerivedType
An aliased typedef.
*/
/*!
- \typedef TestDerived::NotTypedef
+ \typedef TestQDoc::TestDerived::NotTypedef
I'm an alias, not a typedef.
*/
diff --git a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/comprehensiveproject/testcpp.cpp b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/comprehensiveproject/testcpp.cpp
index b51f0291b..d31167efb 100644
--- a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/comprehensiveproject/testcpp.cpp
+++ b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/comprehensiveproject/testcpp.cpp
@@ -263,7 +263,7 @@ void Test::virtualFun()
*/
/*!
- \typedef Test::SomeType
+ \typedef TestQDoc::Test::SomeType
\brief A typedef.
*/
@@ -290,12 +290,12 @@ void TestDerived::virtualFun()
*/
/*!
- \typealias TestDerived::DerivedType
+ \typealias TestQDoc::TestDerived::DerivedType
An aliased typedef.
*/
/*!
- \typedef TestDerived::NotTypedef
+ \typedef TestQDoc::TestDerived::NotTypedef
I'm an alias, not a typedef.
*/
diff --git a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/scopedenum/testcpp.cpp b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/scopedenum/testcpp.cpp
index b51f0291b..d31167efb 100644
--- a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/scopedenum/testcpp.cpp
+++ b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/scopedenum/testcpp.cpp
@@ -263,7 +263,7 @@ void Test::virtualFun()
*/
/*!
- \typedef Test::SomeType
+ \typedef TestQDoc::Test::SomeType
\brief A typedef.
*/
@@ -290,12 +290,12 @@ void TestDerived::virtualFun()
*/
/*!
- \typealias TestDerived::DerivedType
+ \typealias TestQDoc::TestDerived::DerivedType
An aliased typedef.
*/
/*!
- \typedef TestDerived::NotTypedef
+ \typedef TestQDoc::TestDerived::NotTypedef
I'm an alias, not a typedef.
*/
diff --git a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/testtemplate/testcpp.cpp b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/testtemplate/testcpp.cpp
index b51f0291b..d31167efb 100644
--- a/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/testtemplate/testcpp.cpp
+++ b/src/qdoc/qdoc/tests/validateqdocoutputfiles/testdata/testtemplate/testcpp.cpp
@@ -263,7 +263,7 @@ void Test::virtualFun()
*/
/*!
- \typedef Test::SomeType
+ \typedef TestQDoc::Test::SomeType
\brief A typedef.
*/
@@ -290,12 +290,12 @@ void TestDerived::virtualFun()
*/
/*!
- \typealias TestDerived::DerivedType
+ \typealias TestQDoc::TestDerived::DerivedType
An aliased typedef.
*/
/*!
- \typedef TestDerived::NotTypedef
+ \typedef TestQDoc::TestDerived::NotTypedef
I'm an alias, not a typedef.
*/