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 appendAtom(const LinkAtom&);
68 void appendChar(QChar ch);
69 void appendWord(const QString &word);
70 void appendEscapedIdentifier();
71 void appendToCode(const QString &code);
72 void appendToCode(const QString &code, Atom::AtomType defaultType, const QString &language);
73 void enterPara(Atom::AtomType leftType = Atom::ParaLeft,
74 Atom::AtomType rightType = Atom::ParaRight, const QString &string = QString());
75 void leavePara();
76 void leaveValue();
77 void leaveValueList();
78 void leaveTableRow();
79 void quoteFromFile(const QString& filename, CodeMarker *marker = nullptr);
80 bool expandMacro(ArgumentParsingOptions options);
81 void expandMacro(const QString &def, const QStringList &args);
82 QString expandMacroToString(const QString &name, const Macro &macro);
83 Doc::Sections getSectioningUnit();
84 QString getArgument(ArgumentParsingOptions options = ArgumentParsingOptions::Default);
85 QString getBracedArgument(ArgumentParsingOptions options);
86 QString getBracketedArgument();
87 QString getLanguageArgument(CodeMarker **marker);
88 QStringList getMacroArguments(const QString &name, const Macro &macro);
89 QString getOptionalArgument();
90 QString getRestOfLine();
91 QString getMetaCommandArgument(const QString &cmdStr);
92 QString getUntilEnd(int cmd);
93 QString getCode(int cmd, CodeMarker *marker, const QString &argStr = QString());
94
95 CodeMarker *markerForLanguage(const QString &language);
96
97 inline bool isAutoLinkString(const QString &word);
98 bool isAutoLinkString(const QString &word, qsizetype &curPos);
99 bool isBlankLine();
100 bool isLeftBraceAhead();
101 bool isLeftBracketAhead(int maxNewlines = 1);
102 void skipSpacesOnLine();
103 void skipSpacesOrOneEndl();
104 void skipAllSpaces();
105 void skipToNextPreprocessorCommand();
106 static bool isCode(const Atom *atom);
107 static bool isQuote(const Atom *atom);
108 static void expandArgumentsInString(QString &str, const QStringList &args);
109 void cmd_image(int cmd);
110 void cmd_overload();
111
112 QStack<qsizetype> m_openedInputs {};
113
114 QString m_input {};
115 qsizetype m_position {};
116 qsizetype m_backslashPosition {};
117 qsizetype m_endPosition {};
118 qsizetype m_inputLength {};
119 Location m_cachedLocation {};
120 qsizetype m_cachedPosition {};
121
122 DocPrivate *m_private { nullptr };
123 enum ParagraphState {
124 OutsideParagraph,
125 InSingleLineParagraph,
126 InMultiLineParagraph,
127 InBraceDelimitedParagraph
128 };
129 ParagraphState m_paragraphState {};
130 bool m_inTableHeader {};
131 bool m_inTableRow {};
132 bool m_inTableItem {};
133 bool m_indexStartedParagraph {}; // ### rename
134 Atom::AtomType m_pendingParagraphLeftType {};
135 Atom::AtomType m_pendingParagraphRightType {};
136 QString m_pendingParagraphString {};
137
138 int m_braceDepth {};
139 Doc::Sections m_currentSection {};
140 QMap<QString, Location> m_targetMap {};
141 QMap<int, QString> m_pendingFormats {};
142 QStack<int> m_openedCommands {};
143 QStack<OpenedList> m_openedLists {};
144 Quoter m_quoter {};
145 Atom *m_lastAtom { nullptr };
146
147 static DocUtilities &s_utilities;
148
149 // KLUDGE: When parsing documentation, there is a need to find
150 // files to resolve quoting commands. Ideally, the system that
151 // takes care of this would be a non-static member that is a
152 // reference that is passed at
153 // construction time.
154 // Nonetheless, with how the current codebase is constructed, this
155 // has proven to be extremely difficult until more changes are
156 // done. In particular, the construction of a DocParser happens in
157 // multiple places at multiple depths and, in particular, happens
158 // in one of Doc's constructor.
159 // Doc itself is built, again, in multiple places at multiple
160 // depths, making it clumsy and sometimes infeasible to pass the
161 // dependency around so that it is available at the required
162 // places. In particular, this stems from the fact that Doc is
163 // holding many responsabilities and is spread troughtout much of
164 // the codebase in different ways. DocParser mostly depends on Doc
165 // and Doc currently depends on DocParser, making the two
166 // difficult to separate.
167 //
168 // In the future, we expect Doc to mostly be removed, such as to
169 // remove this dependencies and the parsing of documentation to
170 // happen near main and atomically from other endevours, producing
171 // an intermediate representation that is consumed by later
172 // phases.
173 // At that point, it should be possible to not have this kind of
174 // indirection while, for now, the only accessible way to pass
175 // this dependency is trough the initialize method which passes
176 // for Doc::initialize.
177 //
178 // Furthemore, as we cannot late-bind a reference, and having a
179 // desire to avoid an unnecessary copy, we are thus forced to use
180 // a different storage method, in this case a pointer.
181 // This too should be removed later on, using reference or move
182 // semantic depending on the required data-flow.
183 static FileResolver* file_resolver;
184};
185
186QT_END_NAMESPACE
187
188#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:155
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:152
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:85
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:200
Text legaleseText() const
Definition doc.cpp:192
QList< Text > alsoList() const
Definition doc.cpp:280
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:300
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:224
bool hasTableOfContents() const
Definition doc.cpp:285
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file, CodeMarker *marker=nullptr)
Definition doc.cpp:461
const QList< Atom * > & keywords() const
Definition doc.cpp:320
~Doc()
Definition doc.cpp:68
const Text & body() const
Definition doc.cpp:114
static void initialize(FileResolver &file_resolver)
Definition doc.cpp:356
bool hasKeywords() const
Definition doc.cpp:290
QStringList omitEnumItemNames() const
Definition doc.cpp:210
const QList< Atom * > & targets() const
Definition doc.cpp:330
QMultiMap< ComparisonCategory, Text > * comparesWithMap() const
Definition doc.cpp:345
const QList< int > & tableOfContentsLevels() const
Definition doc.cpp:310
bool hasTargets() const
Definition doc.cpp:295
Text trimmedBriefText(const QString &className) const
Definition doc.cpp:131
Sections
Definition doc.h:35
ArgList metaCommandArgs(const QString &metaCommand) const
Definition doc.cpp:275
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:233
void markAutoGenerated()
Marks this documentation as auto-generated by QDoc.
Definition doc.cpp:250
bool isAutoGenerated() const
Returns true if this documentation was auto-generated by QDoc rather than written by an author.
Definition doc.cpp:242
static void terminate()
All the heap allocated variables are deleted.
Definition doc.cpp:409
QList< ArgPair > overloadList() const
Returns the list of arguments passed to the {\overload} command.
Definition doc.cpp:260
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition doc.cpp:270
QStringMultiMap * metaTagMap() const
Definition doc.cpp:340
QSet< QString > metaCommandsUsed() const
Definition doc.cpp:215
bool isEmpty() const
Definition doc.cpp:109
Doc(const Doc &doc)
Definition doc.cpp:63
void constructExtra() const
Definition doc.cpp:350
const QString & source() const
Definition doc.cpp:103
QStringList enumItemNames() const
Definition doc.cpp:205
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:225
Text subText(Atom::AtomType left, Atom::AtomType right, const Atom *from=nullptr, bool inclusive=false) const
Definition text.cpp:153
Atom * firstAtom()
Definition text.h:21
Text()
Definition text.cpp:12
#define CONFIG_MACRO
Definition config.h:413
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