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
docparser.h
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#ifndef DOCPARSER_H
4#define DOCPARSER_H
5
6#include "atom.h"
7#include "config.h"
8#include "doc.h"
9#include "docutilities.h"
10#include "location.h"
11#include "openedlist.h"
12#include "quoter.h"
13
14#include "filesystem/fileresolver.h"
15
16#include <QtCore/QCoreApplication>
17#include <QtCore/qglobalstatic.h>
18#include <QtCore/qhash.h>
19#include <QtCore/qstack.h>
20#include <QtCore/qstring.h>
21
23
24class DocPrivate;
25class CodeMarker;
26struct Macro;
27
29{
30public:
31 void parse(const QString &source, DocPrivate *docPrivate, const QSet<QString> &metaCommandSet,
32 const QSet<QString> &possibleTopics);
33
34 static void initialize(const Config &config, FileResolver& file_resolver);
35 static int endCmdFor(int cmd);
36 static QString cmdName(int cmd);
37 static QString endCmdName(int cmd);
38 static QString untabifyEtc(const QString &str);
39 static int indentLevel(const QString &str);
40 static QString dedent(int level, const QString &str);
41
42 static int s_tabSize;
45 static bool s_quoting;
46
47private:
48
49 enum class ArgumentParsingOptions {
50 Default,
51 Verbatim,
52 MacroArguments
53 };
54
55 Location &location();
56 QString detailsUnknownCommand(const QSet<QString> &metaCommandSet, const QString &str);
57 void insertTarget(const QString &target);
58 void insertKeyword(const QString &keyword);
59 void include(const QString &fileName, const QString &identifier, const QStringList &parameters);
60 void startFormat(const QString &format, int cmd);
61 bool openCommand(int cmd);
62 bool closeCommand(int endCmd);
63 void startSection(Doc::Sections unit, int cmd);
64 void endSection(int unit, int endCmd);
65 void parseAlso();
66 void appendAtom(const Atom&);
67 void appendChar(QChar ch);
68 void appendWord(const QString &word);
69 void appendEscapedIdentifier();
70 void appendToCode(const QString &code);
71 void appendToCode(const QString &code, Atom::AtomType defaultType, const QString &language);
72 void enterPara(Atom::AtomType leftType = Atom::ParaLeft,
73 Atom::AtomType rightType = Atom::ParaRight, const QString &string = QString());
74 void leavePara();
75 void leaveValue();
76 void leaveValueList();
77 void leaveTableRow();
78 void quoteFromFile(const QString& filename, CodeMarker *marker = nullptr);
79 bool expandMacro(ArgumentParsingOptions options);
80 void expandMacro(const QString &def, const QStringList &args);
81 QString expandMacroToString(const QString &name, const Macro &macro);
82 Doc::Sections getSectioningUnit();
83 QString getArgument(ArgumentParsingOptions options = ArgumentParsingOptions::Default);
84 QString getBracedArgument(ArgumentParsingOptions options);
85 QString getBracketedArgument();
86 QString getLanguageArgument(CodeMarker **marker);
87 QStringList getMacroArguments(const QString &name, const Macro &macro);
88 QString getOptionalArgument();
89 QString getRestOfLine();
90 QString getMetaCommandArgument(const QString &cmdStr);
91 QString getUntilEnd(int cmd);
92 QString getCode(int cmd, CodeMarker *marker, const QString &argStr = QString());
93
94 CodeMarker *markerForLanguage(const QString &language);
95
96 inline bool isAutoLinkString(const QString &word);
97 bool isAutoLinkString(const QString &word, qsizetype &curPos);
98 bool isBlankLine();
99 bool isLeftBraceAhead();
100 bool isLeftBracketAhead(int maxNewlines = 1);
101 void skipSpacesOnLine();
102 void skipSpacesOrOneEndl();
103 void skipAllSpaces();
104 void skipToNextPreprocessorCommand();
105 static bool isCode(const Atom *atom);
106 static bool isQuote(const Atom *atom);
107 static void expandArgumentsInString(QString &str, const QStringList &args);
108 void cmd_image(int cmd);
109 void cmd_overload();
110
111 QStack<qsizetype> m_openedInputs {};
112
113 QString m_input {};
114 qsizetype m_position {};
115 qsizetype m_backslashPosition {};
116 qsizetype m_endPosition {};
117 qsizetype m_inputLength {};
118 Location m_cachedLocation {};
119 qsizetype m_cachedPosition {};
120
121 DocPrivate *m_private { nullptr };
122 enum ParagraphState {
123 OutsideParagraph,
124 InSingleLineParagraph,
125 InMultiLineParagraph,
126 InBraceDelimitedParagraph
127 };
128 ParagraphState m_paragraphState {};
129 bool m_inTableHeader {};
130 bool m_inTableRow {};
131 bool m_inTableItem {};
132 bool m_indexStartedParagraph {}; // ### rename
133 Atom::AtomType m_pendingParagraphLeftType {};
134 Atom::AtomType m_pendingParagraphRightType {};
135 QString m_pendingParagraphString {};
136
137 int m_braceDepth {};
138 Doc::Sections m_currentSection {};
139 QMap<QString, Location> m_targetMap {};
140 QMap<int, QString> m_pendingFormats {};
141 QStack<int> m_openedCommands {};
142 QStack<OpenedList> m_openedLists {};
143 Quoter m_quoter {};
144 Atom *m_lastAtom { nullptr };
145
146 static DocUtilities &s_utilities;
147
148 // KLUDGE: When parsing documentation, there is a need to find
149 // files to resolve quoting commands. Ideally, the system that
150 // takes care of this would be a non-static member that is a
151 // reference that is passed at
152 // construction time.
153 // Nonetheless, with how the current codebase is constructed, this
154 // has proven to be extremely difficult until more changes are
155 // done. In particular, the construction of a DocParser happens in
156 // multiple places at multiple depths and, in particular, happens
157 // in one of Doc's constructor.
158 // Doc itself is built, again, in multiple places at multiple
159 // depths, making it clumsy and sometimes infeasible to pass the
160 // dependency around so that it is available at the required
161 // places. In particular, this stems from the fact that Doc is
162 // holding many responsabilities and is spread troughtout much of
163 // the codebase in different ways. DocParser mostly depends on Doc
164 // and Doc currently depends on DocParser, making the two
165 // difficult to separate.
166 //
167 // In the future, we expect Doc to mostly be removed, such as to
168 // remove this dependencies and the parsing of documentation to
169 // happen near main and atomically from other endevours, producing
170 // an intermediate representation that is consumed by later
171 // phases.
172 // At that point, it should be possible to not have this kind of
173 // indirection while, for now, the only accessible way to pass
174 // this dependency is trough the initialize method which passes
175 // for Doc::initialize.
176 //
177 // Furthemore, as we cannot late-bind a reference, and having a
178 // desire to avoid an unnecessary copy, we are thus forced to use
179 // a different storage method, in this case a pointer.
180 // This too should be removed later on, using reference or move
181 // semantic depending on the required data-flow.
182 static FileResolver* file_resolver;
183};
184
185QT_END_NAMESPACE
186
187#endif // DOCPARSER_H
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:19
AtomType type() const
Return the type of this atom.
Definition atom.h:144
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
Definition atom.h:21
@ BriefRight
Definition atom.h:27
@ LegaleseRight
Definition atom.h:61
@ String
Definition atom.h:95
@ BriefLeft
Definition atom.h:26
@ LegaleseLeft
Definition atom.h:60
@ C
Definition atom.h:28
@ ParaRight
Definition atom.h:78
@ AutoLink
Definition atom.h:23
@ ParaLeft
Definition atom.h:77
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:141
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:95
static QString untabifyEtc(const QString &str)
static QStringList s_allowedLanguages
Definition docparser.h:43
static QStringList s_ignoreWords
Definition docparser.h:44
void parse(const QString &source, DocPrivate *docPrivate, const QSet< QString > &metaCommandSet, const QSet< QString > &possibleTopics)
Parse the source string to build a Text data structure in docPrivate.
static QString dedent(int level, const QString &str)
static QString cmdName(int cmd)
static bool s_quoting
Definition docparser.h:45
static int endCmdFor(int cmd)
static int indentLevel(const QString &str)
static void initialize(const Config &config, FileResolver &file_resolver)
static QString endCmdName(int cmd)
static int s_tabSize
Definition docparser.h:42
void ref()
Definition docprivate.h:52
bool m_autoGenerated
Definition docprivate.h:72
Text m_title
Definition docprivate.h:61
DocPrivateExtra * extra
Definition docprivate.h:68
void constructExtra()
Text m_text
Definition docprivate.h:60
bool m_hasLegalese
Definition docprivate.h:71
bool deref()
Definition docprivate.h:53
TopicList m_topics
Definition docprivate.h:69
CommandMap m_metaCommandMap
Definition docprivate.h:67
Definition doc.h:32
QSet< QString > parameterNames() const
Definition doc.cpp:202
Text legaleseText() const
Definition doc.cpp:194
QList< Text > alsoList() const
Definition doc.cpp:282
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:89
Doc & operator=(const Doc &doc)
Definition doc.cpp:74
Doc(const Location &start_loc, const Location &end_loc, const QString &source, const QSet< QString > &metaCommandSet, const QSet< QString > &topics)
Parse the qdoc comment source.
Definition doc.cpp:46
const QList< Atom * > & tableOfContents() const
Definition doc.cpp:302
const Text & title() const
Definition doc.cpp:120
bool isInternal() const
Returns true if the set of metacommands used in the doc comment contains {internal}...
Definition doc.cpp:226
bool hasTableOfContents() const
Definition doc.cpp:287
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file, CodeMarker *marker=nullptr)
Definition doc.cpp:463
const QList< Atom * > & keywords() const
Definition doc.cpp:322
~Doc()
Definition doc.cpp:68
const Text & body() const
Definition doc.cpp:114
static void initialize(FileResolver &file_resolver)
Definition doc.cpp:358
bool hasKeywords() const
Definition doc.cpp:292
QStringList omitEnumItemNames() const
Definition doc.cpp:212
const QList< Atom * > & targets() const
Definition doc.cpp:332
QMultiMap< ComparisonCategory, Text > * comparesWithMap() const
Definition doc.cpp:347
const QList< int > & tableOfContentsLevels() const
Definition doc.cpp:312
bool hasTargets() const
Definition doc.cpp:297
Text trimmedBriefText(const QString &className) const
Definition doc.cpp:131
Sections
Definition doc.h:35
ArgList metaCommandArgs(const QString &metaCommand) const
Definition doc.cpp:277
Text briefText(bool inclusive=false) const
Definition doc.cpp:126
const Location & startLocation() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:98
bool isMarkedReimp() const
Returns true if the set of metacommands used in the doc comment contains {reimp}.
Definition doc.cpp:235
void markAutoGenerated()
Marks this documentation as auto-generated by QDoc.
Definition doc.cpp:252
bool isAutoGenerated() const
Returns true if this documentation was auto-generated by QDoc rather than written by an author.
Definition doc.cpp:244
static void terminate()
All the heap allocated variables are deleted.
Definition doc.cpp:411
QList< ArgPair > overloadList() const
Returns the list of arguments passed to the {\overload} command.
Definition doc.cpp:262
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition doc.cpp:272
QStringMultiMap * metaTagMap() const
Definition doc.cpp:342
QSet< QString > metaCommandsUsed() const
Definition doc.cpp:217
bool isEmpty() const
Definition doc.cpp:109
Doc(const Doc &doc)
Definition doc.cpp:63
void constructExtra() const
Definition doc.cpp:352
const QString & source() const
Definition doc.cpp:103
QStringList enumItemNames() const
Definition doc.cpp:207
Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are re...
The Location class provides a way to mark a location in a file.
Definition location.h:20
int columnNo() const
Returns the current column number.
Definition location.h:51
Definition text.h:12
void dump() const
Prints a human-readable version of the contained atoms to stderr.
Definition text.cpp:206
Text subText(Atom::AtomType left, Atom::AtomType right, const Atom *from=nullptr, bool inclusive=false) const
Definition text.cpp:134
Atom * firstAtom()
Definition text.h:21
Text()
Definition text.cpp:12
#define CONFIG_MACRO
Definition config.h:425
QList< ArgPair > ArgList
Definition doc.h:28
QMultiMap< QString, QString > QStringMultiMap
Definition doc.h:29
Combined button and popup list for selecting options.
QStringMultiMap m_metaMap
Definition docprivate.h:38
QHash_QString_Macro macroHash
QHash_QString_int cmdHash
Simple structure used by the Doc and DocParser classes.
Represents a file that is reachable by QDoc based on its current configuration.
QList< Topic > TopicList
Definition topic.h:25