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
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
5
6#include "qdocdatabase.h"
8#include "tokenizer.h"
9
10#include <cerrno>
11
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 */
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 */
36std::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();
62 doc.location().warning(QStringLiteral("This qdoc comment contains no topic command "
63 "(e.g., '\\%1', '\\%2').")
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
77QT_END_NAMESPACE
Definition doc.h:32
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:89
bool isInternal() const
Returns true if the set of metacommands used in the doc comment contains {internal}...
Definition doc.cpp:226
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition doc.cpp:272
static bool processInternalDocs(const InclusionPolicy &policy)
The Location class provides a way to mark a location in a file.
Definition location.h:20
Location(const Location &other)
The copy constructor copies the contents of other into this Location using the assignment operator.
Definition location.cpp:67
std::vector< UntiedDocumentation > parse_qdoc_file(const QString &filePath)
Parses the source file identified by filePath and adds its parsed contents to the database.
int getToken()
const Location & location() const
Definition tokenizer.h:90
Tokenizer(const Location &loc, QFile &file)
#define COMMAND_MODULE
Definition codeparser.h:37
#define COMMAND_PAGE
Definition codeparser.h:45
bool hasTooManyTopics(const Doc &doc)
Checks if there are too many topic commands in doc.
Combined button and popup list for selecting options.
@ Tok_Eoi
Definition tokenizer.h:24
@ Tok_Doc
Definition tokenizer.h:47