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
puredocparser.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
"puredocparser.h"
5
6
#
include
"qdocdatabase.h"
7
#
include
"inclusionfilter.h"
8
#
include
"tokenizer.h"
9
10
#
include
<
cerrno
>
11
12
QT_BEGIN_NAMESPACE
13
14
/*!
15
Parses the source file identified by \a filePath and adds its
16
parsed contents to the database. The \a location is used for
17
reporting errors.
18
*/
19
std
::
vector
<
UntiedDocumentation
>
PureDocParser
::
parse_qdoc_file
(
const
QString &filePath)
20
{
21
QFile in(filePath);
22
if
(!in.open(QIODevice::ReadOnly)) {
23
location.error(
24
QStringLiteral(
"Can't open source file '%1' (%2)"
).arg(filePath, strerror(errno)));
25
return
{};
26
}
27
28
return
processQdocComments(in);
29
}
30
31
/*!
32
This is called by parseSourceFile() to do the actual parsing
33
and tree building. It only processes qdoc comments. It skips
34
everything else.
35
*/
36
std::vector<UntiedDocumentation>
PureDocParser
::processQdocComments(QFile& input_file)
37
{
38
std::vector<UntiedDocumentation> untied{};
39
40
Tokenizer
tokenizer
(
Location
{input_file.fileName()}
,
input_file
)
;
41
42
const
QSet<QString> &commands = CppCodeParser::topic_commands + CppCodeParser::meta_commands;
43
44
int
token = tokenizer
.
getToken
(
)
;
45
while
(token !=
Tok_Eoi
) {
46
if
(token !=
Tok_Doc
) {
47
token = tokenizer
.
getToken
(
)
;
48
continue
;
49
}
50
QString comment = tokenizer.lexeme();
// returns an entire qdoc comment.
51
Location
start_loc
(
tokenizer
.
location
(
)
)
;
52
token = tokenizer
.
getToken
(
)
;
53
54
Doc::trimCStyleComment(start_loc, comment);
55
Location
end_loc
(
tokenizer
.
location
(
)
)
;
56
57
// Doc constructor parses the comment.
58
Doc
doc(start_loc, end_loc, comment, commands, CppCodeParser::topic_commands);
59
if
(doc
.
topicsUsed
(
)
.isEmpty()) {
60
const
auto
policy = Config::instance().createInclusionPolicy();
61
if
(
InclusionFilter
::
processInternalDocs
(
policy
)
|| !doc
.
isInternal
(
)
)
62
doc
.
location
(
)
.warning(QStringLiteral(
"This qdoc comment contains no topic command "
63
"(e.g., '\\%1', '\\%2')."
)
64
.arg(
COMMAND_MODULE
,
COMMAND_PAGE
));
65
continue
;
66
}
67
68
if
(
hasTooManyTopics
(
doc
)
)
69
continue
;
70
71
untied.emplace_back(
UntiedDocumentation
{doc, QStringList()});
72
}
73
74
return
untied;
75
}
76
77
QT_END_NAMESPACE
Doc
Definition
doc.h:32
Doc::location
const Location & location() const
Returns the starting location of a qdoc comment.
Definition
doc.cpp:89
Doc::isInternal
bool isInternal() const
Returns true if the set of metacommands used in the doc comment contains {internal}...
Definition
doc.cpp:226
Doc::topicsUsed
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition
doc.cpp:272
InclusionFilter
Definition
inclusionfilter.h:14
InclusionFilter::processInternalDocs
static bool processInternalDocs(const InclusionPolicy &policy)
Definition
inclusionfilter.h:67
Location
The Location class provides a way to mark a location in a file.
Definition
location.h:20
Location::Location
Location(const Location &other)
The copy constructor copies the contents of other into this Location using the assignment operator.
Definition
location.cpp:69
PureDocParser
Definition
puredocparser.h:16
PureDocParser::parse_qdoc_file
std::vector< UntiedDocumentation > parse_qdoc_file(const QString &filePath)
Parses the source file identified by filePath and adds its parsed contents to the database.
Definition
puredocparser.cpp:19
Tokenizer
Definition
tokenizer.h:80
Tokenizer::getToken
int getToken()
Definition
tokenizer.cpp:140
Tokenizer::location
const Location & location() const
Definition
tokenizer.h:90
Tokenizer::Tokenizer
Tokenizer(const Location &loc, QFile &file)
Definition
tokenizer.cpp:119
COMMAND_MODULE
#define COMMAND_MODULE
Definition
codeparser.h:37
COMMAND_PAGE
#define COMMAND_PAGE
Definition
codeparser.h:45
hasTooManyTopics
bool hasTooManyTopics(const Doc &doc)
Checks if there are too many topic commands in doc.
Definition
cppcodeparser.h:98
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
UntiedDocumentation
Definition
codeparser.h:98
Tok_Eoi
@ Tok_Eoi
Definition
tokenizer.h:24
Tok_Doc
@ Tok_Doc
Definition
tokenizer.h:47
qttools
src
qdoc
qdoc
src
qdoc
puredocparser.cpp
Generated on
for Qt by
1.18.0