diff options
author | Luca Di Sera <luca.disera@qt.io> | 2023-04-11 14:38:38 +0200 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2023-04-12 15:06:56 +0200 |
commit | 846c860b89ee5fbef4f1db583bd951f8a33e196a (patch) | |
tree | f29b0f8ae9c1ab4d796e11e7b72cc56347e8a5e5 /src/qdoc/qmlcodemarker.cpp | |
parent | 2ba87cd00e6527dbd64f5884f29081bd535605bb (diff) | |
download | qttools-846c860b89ee5fbef4f1db583bd951f8a33e196a.tar.gz |
QDoc: Move QDoc source files under a further "qdoc" directory
QDoc development under the "qttools" repository is currently performed
under the "src/qdoc" directory, which contains all source files and
directories relevant to QDoc as direct children.
Due to a slow restructuring of how QDoc works, what its dependencies are
and certain possible architectural changes, the infrastructure that is
expected to be required for the development of QDoc might increase.
Some of that infrastructure, which might require some custom effort, is
expected to be developed as "independent" "library-like" sub-projects,
which QDoc depends on.
Albeit developed "independently", such infrastructure would be developed
specifically for QDoc and thus should live "adjacent" to it.
To allow such a structure a new "qdoc" directory was added under the
"src/qdoc" directory. All source files and directory that were
previously children of the "src/qdoc" directory were moved under the new
"qdoc" directory.
This preserves the space for QDoc-related elements and the relative
project structure while allowing some space for "adjacent" projects that
are intended for QDoc specifically.
To support the change, a new "CMakeLists.txt" file was introduced under
"src/qdoc", which dispatches to the "CMakeLists.txt" file in the new
"src/qdoc/qdoc" directory.
QDoc is only built when certain dependencies are found. This is
supported through the use of Qt features at the CMake level.
The "CMakeLists.txt" file in "src", thus dispatched to the "src/qdoc"
directory only when the required features were found.
As "independent", "library-like", entities might not have the same
requirements as QDoc, the "CMakeLists.txt" file in "src" was modified to
always dispatch to the "src/qdoc" directory while the features-check was
moved to the new "CMakeLists.txt" files in "src/qdoc", so as to allow
non-QDoc but QDoc-specific project to have an independent configuration
for building.
Certain test projects in "test/auto/qdoc/" depends on QDoc-specific
source-files to generate their CMake targets.
Those dependencies were generally specified as relative paths.
The additional level in the directory structure invalidated the paths
and, hence, the relevant "CMakeLists.txt" files for those projects were
modified to correctly refer to the new directory structure.
Change-Id: I50c7106614428753544eaba5091e1e44d48fd31d
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/qmlcodemarker.cpp')
-rw-r--r-- | src/qdoc/qmlcodemarker.cpp | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/src/qdoc/qmlcodemarker.cpp b/src/qdoc/qmlcodemarker.cpp deleted file mode 100644 index 30dec979e..000000000 --- a/src/qdoc/qmlcodemarker.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "qmlcodemarker.h" - -#include <QtCore/qregularexpression.h> - -#include "atom.h" -#include "node.h" -#include "qmlmarkupvisitor.h" -#include "text.h" - -#include <private/qqmljsast_p.h> -#include <private/qqmljsastfwd_p.h> -#include <private/qqmljsengine_p.h> -#include <private/qqmljslexer_p.h> -#include <private/qqmljsparser_p.h> - -QT_BEGIN_NAMESPACE - -/*! - Returns \c true if the \a code is recognized by the parser. - */ -bool QmlCodeMarker::recognizeCode(const QString &code) -{ - // Naive pre-check; starts with an import statement or 'CamelCase {' - static const QRegularExpression regExp(QStringLiteral("^\\s*(import |([A-Z][a-z0-9]*)+\\s?{)")); - if (!regExp.match(code).hasMatch()) - return false; - - QQmlJS::Engine engine; - QQmlJS::Lexer lexer(&engine); - QQmlJS::Parser parser(&engine); - - QString newCode = code; - extractPragmas(newCode); - lexer.setCode(newCode, 1); - - return parser.parse(); -} - -/*! - Returns \c true if \a ext is any of a list of file extensions - for the QML language. - */ -bool QmlCodeMarker::recognizeExtension(const QString &ext) -{ - return ext == "qml"; -} - -/*! - Returns \c true if the \a language is recognized. Only "QML" is - recognized by this marker. - */ -bool QmlCodeMarker::recognizeLanguage(const QString &language) -{ - return language == "QML"; -} - -/*! - Returns the type of atom used to represent QML code in the documentation. -*/ -Atom::AtomType QmlCodeMarker::atomType() const -{ - return Atom::Qml; -} - -QString QmlCodeMarker::markedUpCode(const QString &code, const Node *relative, - const Location &location) -{ - return addMarkUp(code, relative, location); -} - -/*! - Constructs and returns the marked up name for the \a node. - If the node is any kind of QML function (a method, - signal, or handler), "()" is appended to the marked up name. - */ -QString QmlCodeMarker::markedUpName(const Node *node) -{ - QString name = linkTag(node, taggedNode(node)); - if (node->isFunction()) - name += "()"; - return name; -} - -QString QmlCodeMarker::markedUpInclude(const QString &include) -{ - return addMarkUp("import " + include, nullptr, Location{}); -} - -QString QmlCodeMarker::addMarkUp(const QString &code, const Node * /* relative */, - const Location &location) -{ - QQmlJS::Engine engine; - QQmlJS::Lexer lexer(&engine); - - QString newCode = code; - QList<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode); - lexer.setCode(newCode, 1); - - QQmlJS::Parser parser(&engine); - QString output; - - if (parser.parse()) { - QQmlJS::AST::UiProgram *ast = parser.ast(); - // Pass the unmodified code to the visitor so that pragmas and other - // unhandled source text can be output. - QmlMarkupVisitor visitor(code, pragmas, &engine); - QQmlJS::AST::Node::accept(ast, &visitor); - if (visitor.hasError()) { - location.warning( - location.fileName() - + QStringLiteral("Unable to analyze QML snippet. The output is incomplete.")); - } - output = visitor.markedUpCode(); - } else { - location.warning(QStringLiteral("Unable to parse QML snippet: \"%1\" at line %2, column %3") - .arg(parser.errorMessage()) - .arg(parser.errorLineNumber()) - .arg(parser.errorColumnNumber())); - output = protect(code); - } - - return output; -} - -/* - Copied and pasted from - src/declarative/qml/qqmlscriptparser.cpp. -*/ -void replaceWithSpace(QString &str, int idx, int n); // qmlcodeparser.cpp - -/* - Copied and pasted from - src/declarative/qml/qqmlscriptparser.cpp then modified to - return a list of removed pragmas. - - Searches for ".pragma <value>" or ".import <stuff>" declarations - in \a script. Currently supported pragmas are: library -*/ -QList<QQmlJS::SourceLocation> QmlCodeMarker::extractPragmas(QString &script) -{ - QList<QQmlJS::SourceLocation> removed; - - QQmlJS::Lexer l(nullptr); - l.setCode(script, 0); - - int token = l.lex(); - - while (true) { - if (token != QQmlJSGrammar::T_DOT) - break; - - int startOffset = l.tokenOffset(); - int startLine = l.tokenStartLine(); - int startColumn = l.tokenStartColumn(); - - token = l.lex(); - - if (token != QQmlJSGrammar::T_PRAGMA && token != QQmlJSGrammar::T_IMPORT) - break; - int endOffset = 0; - while (startLine == l.tokenStartLine()) { - endOffset = l.tokenLength() + l.tokenOffset(); - token = l.lex(); - } - replaceWithSpace(script, startOffset, endOffset - startOffset); - removed.append(QQmlJS::SourceLocation(startOffset, endOffset - startOffset, startLine, - startColumn)); - } - return removed; -} - -QT_END_NAMESPACE |