Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
codeparser.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
"codeparser.h"
5
6
#
include
"config.h"
7
#
include
"generator.h"
8
#
include
"inclusionfilter.h"
9
#
include
"inclusionpolicy.h"
10
#
include
"node.h"
11
#
include
"qdocdatabase.h"
12
13
#
include
<
QtCore
/
qregularexpression
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
QList<CodeParser *> CodeParser::s_parsers;
18
19
/*!
20
The constructor adds this code parser to the static
21
list of code parsers.
22
*/
23
CodeParser
::
CodeParser
()
24
{
25
m_qdb
=
QDocDatabase
::
qdocDB
(
)
;
26
s_parsers.prepend(
this
);
27
}
28
29
/*!
30
The destructor removes this code parser from the static
31
list of code parsers.
32
*/
33
CodeParser
::~
CodeParser
()
34
{
35
s_parsers.removeAll(
this
);
36
}
37
38
/*!
39
Terminating a code parser is trivial.
40
*/
41
void
CodeParser
::
terminateParser
()
42
{
43
// nothing.
44
}
45
46
/*!
47
All the code parsers in the static list are initialized here,
48
after the qdoc configuration variables have been set.
49
*/
50
void
CodeParser
::
initialize
()
51
{
52
for
(
const
auto
&parser : std::as_const(s_parsers))
53
parser->initializeParser();
54
}
55
56
/*!
57
All the code parsers in the static list are terminated here.
58
*/
59
void
CodeParser
::
terminate
()
60
{
61
for
(
const
auto
parser : s_parsers)
62
parser->terminateParser();
63
}
64
65
CodeParser
*
CodeParser
::
parserForLanguage
(
const
QString &language)
66
{
67
for
(
const
auto
parser : std::as_const(s_parsers)) {
68
if
(parser->language() == language)
69
return
parser;
70
}
71
return
nullptr
;
72
}
73
74
CodeParser
*
CodeParser
::
parserForSourceFile
(
const
QString &filePath)
75
{
76
QString fileName = QFileInfo(filePath).fileName();
77
78
for
(
const
auto
&parser : s_parsers) {
79
const
QStringList sourcePatterns = parser->sourceFileNameFilter();
80
for
(
const
QString &pattern : sourcePatterns) {
81
auto
re = QRegularExpression::fromWildcard(pattern, Qt::CaseInsensitive);
82
if
(re.match(fileName).hasMatch())
83
return
parser;
84
}
85
}
86
return
nullptr
;
87
}
88
89
/*!
90
\internal
91
*/
92
void
CodeParser
::extractPageLinkAndDesc(QStringView arg, QString *link, QString *desc)
93
{
94
static
const
QRegularExpression bracedRegExp(
95
QRegularExpression::anchoredPattern(QLatin1String(R"(\{([^{}]*)\}(?:\{([^{}]*)\})?)")));
96
auto
match = bracedRegExp.matchView(arg);
97
if
(match.hasMatch()) {
98
*link = match.captured(1);
99
*desc = match.captured(2);
100
if
(desc->isEmpty())
101
*desc = *link;
102
}
else
{
103
qsizetype spaceAt = arg.indexOf(QLatin1Char(
' '
));
104
if
(arg.contains(QLatin1String(
".html"
)) && spaceAt != -1) {
105
*link = arg.left(spaceAt).trimmed().toString();
106
*desc = arg.mid(spaceAt).trimmed().toString();
107
}
else
{
108
*link = arg.toString();
109
*desc = *link;
110
}
111
}
112
}
113
114
/*!
115
\internal
116
*/
117
void
CodeParser
::
setLink
(
Node
*node,
Node
::
LinkType
linkType,
const
QString &arg)
118
{
119
QString link;
120
QString desc;
121
extractPageLinkAndDesc(arg, &link, &desc);
122
node->setLink(linkType, link, desc);
123
}
124
125
/*!
126
\brief Test for whether a doc comment warrants warnings.
127
128
Returns true if qdoc should report that it has found something
129
wrong with the qdoc comment in \a doc. Sometimes, qdoc should
130
not report the warning, for example, when the comment contains
131
the \c internal command, which normally means qdoc will not use
132
the comment in the documentation anyway, so there is no point
133
in reporting warnings about it.
134
135
Auto-generated documentation (such as for explicitly defaulted
136
or deleted special member functions) is never worth warning
137
about, since it's created by QDoc rather than written by an
138
author.
139
*/
140
bool
CodeParser
::
isWorthWarningAbout
(
const
Doc
&doc)
141
{
142
if
(doc
.
isAutoGenerated
(
)
)
143
return
false
;
144
145
const
InclusionPolicy policy = Config::instance().createInclusionPolicy();
146
return
(
InclusionFilter
::
processInternalDocs
(
policy
)
147
|| !doc.metaCommandsUsed().contains(QStringLiteral(
"internal"
)));
148
}
149
150
QT_END_NAMESPACE
CodeParser
Definition
codeparser.h:109
CodeParser::terminateParser
virtual void terminateParser()
Terminating a code parser is trivial.
Definition
codeparser.cpp:41
CodeParser::CodeParser
CodeParser()
The constructor adds this code parser to the static list of code parsers.
Definition
codeparser.cpp:23
CodeParser::setLink
static void setLink(Node *node, Node::LinkType linkType, const QString &arg)
Definition
codeparser.cpp:117
CodeParser::m_qdb
QDocDatabase * m_qdb
Definition
codeparser.h:140
CodeParser::parserForLanguage
static CodeParser * parserForLanguage(const QString &language)
Definition
codeparser.cpp:65
CodeParser::parserForSourceFile
static CodeParser * parserForSourceFile(const QString &filePath)
Definition
codeparser.cpp:74
CodeParser::isWorthWarningAbout
static bool isWorthWarningAbout(const Doc &doc)
Test for whether a doc comment warrants warnings.
Definition
codeparser.cpp:140
CodeParser::~CodeParser
virtual ~CodeParser()
The destructor removes this code parser from the static list of code parsers.
Definition
codeparser.cpp:33
CodeParser::initialize
static void initialize()
All the code parsers in the static list are initialized here, after the qdoc configuration variables ...
Definition
codeparser.cpp:50
CodeParser::terminate
static void terminate()
All the code parsers in the static list are terminated here.
Definition
codeparser.cpp:59
Doc
Definition
doc.h:32
Doc::isAutoGenerated
bool isAutoGenerated() const
Returns true if this documentation was auto-generated by QDoc rather than written by an author.
Definition
doc.cpp:244
InclusionFilter
Definition
inclusionfilter.h:14
InclusionFilter::processInternalDocs
static bool processInternalDocs(const InclusionPolicy &policy)
Definition
inclusionfilter.h:67
QDocDatabase
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
Definition
qdocdatabase.h:214
QDocDatabase::qdocDB
static QDocDatabase * qdocDB()
Creates the singleton.
Definition
qdocdatabase.cpp:373
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
Node
The Node class is the base class for all the nodes in QDoc's parse tree.
Definition
src_corelib_text_qstring.cpp:10
Node::LinkType
LinkType
An unsigned char value that probably should be moved out of the Node base class.
Definition
node.h:73
qttools
src
qdoc
qdoc
src
qdoc
codeparser.cpp
Generated on
for Qt by
1.18.0