Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
parsererror.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "parsererror.h"
5#include "node.h"
6#include "qdocdatabase.h"
7#include "config.h"
8#include "utilities.h"
9
10#include <QtCore/qregularexpression.h>
11
12using namespace Qt::Literals::StringLiterals;
13
15
16/*!
17 \class FnMatchError
18 \brief Encapsulates information about \fn match error during parsing.
19*/
20
21/*!
22 \variable FnMatchError::signature
23
24 Signature for the \fn topic that failed to match.
25*/
26
27/*!
28 \relates FnMatchError
29
30 Returns \c true if any parent of a C++ function represented by
31 \a signature is documented as \\internal.
32*/
33bool isParentInternal(const QString &signature)
34{
35 const QRegularExpression scoped_fn{R"((?:\w+(?:<[^>]+>)?::)+~?\w\S*\‍()"};
36 auto match = scoped_fn.match(signature);
37 if (!match.isValid())
38 return false;
39
40 auto scope = match.captured().split("::"_L1);
41 scope.removeLast(); // Drop function name
42
43 for (auto &s : scope)
44 if (qsizetype pos = s.indexOf('<'); pos >= 0)
45 s.truncate(pos);
46
47 auto parent = QDocDatabase::qdocDB()->findNodeByNameAndType(scope, &Node::isCppNode);
48 if (parent && !(parent->isClassNode() || parent->isNamespace())) {
49 qCDebug(lcQdoc).noquote()
50 << "Invalid scope:" << qPrintable(parent->nodeTypeString())
51 << qPrintable(parent->fullName())
52 << "for \\fn" << qPrintable(signature);
53 return false;
54 }
55
56 while (parent) {
57 if (parent->isInternal())
58 return true;
59 parent = parent->parent();
60 }
61
62 return false;
63}
64
65/*!
66 \class ParserErrorHandler
67 \brief Processes parser errors and outputs warnings for them.
68*/
69
70/*!
71 Generates a warning specific to FnMatchError.
72
73 Warnings for internal documentation are omitted. Specifically, this
74 (omission) happens if:
75
76 \list
77 \li \c {--showinternal} command line option is \b not
78 used, and
79 \li The warning is for an \\fn that is declared
80 under a namespace/class that is documented as
81 \\internal.
82 \endlist
83*/
85{
86 if (Config::instance().showInternal() || !isParentInternal(e.signature))
87 e.location.warning("Failed to find function when parsing \\fn %1"_L1.arg(e.signature));
88}
89
90QT_END_NAMESPACE
LinkType
An unsigned char value that probably should be moved out of the Node base class.
Definition node.h:112
bool isCppNode() const
Returns true if this node's Genus value is CPP.
Definition node.h:130
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
Encapsulates information about.
Definition parsererror.h:13
bool isParentInternal(const QString &signature)
Returns true if any parent of a C++ function represented by signature is documented as \internal.
Processes parser errors and outputs warnings for them.
Definition parsererror.h:20
void operator()(const FnMatchError &e) const
Generates a warning specific to FnMatchError.