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