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;
44 static bool s_quoting;
45
46private:
47
48 enum class ArgumentParsingOptions {
49 Default,
50 Verbatim,
51 MacroArguments
52 };
53
54 Location &location();
55 QString detailsUnknownCommand(const QSet<QString> &metaCommandSet, const QString &str);
56 void insertTarget(const QString &target);
57 void insertKeyword(const QString &keyword);
58 void include(const QString &fileName, const QString &identifier, const QStringList &parameters);
59 void startFormat(const QString &format, int cmd);
60 bool openCommand(int cmd);
61 bool closeCommand(int endCmd);
62 void startSection(Doc::Sections unit, int cmd);
63 void endSection(int unit, int endCmd);
64 void parseAlso();
65 void appendAtom(const Atom&);
66 void appendAtom(const LinkAtom&);
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);
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);
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 QStringList getMacroArguments(const QString &name, const Macro &macro);
87 QString getOptionalArgument();
88 QString getRestOfLine();
89 QString getMetaCommandArgument(const QString &cmdStr);
90 QString getUntilEnd(int cmd);
91 QString getCode(int cmd, CodeMarker *marker, const QString &argStr = QString());
92
93 inline bool isAutoLinkString(const QString &word);
94 bool isAutoLinkString(const QString &word, qsizetype &curPos);
95 bool isBlankLine();
96 bool isLeftBraceAhead();
97 bool isLeftBracketAhead(int maxNewlines = 1);
98 void skipSpacesOnLine();
99 void skipSpacesOrOneEndl();
100 void skipAllSpaces();
101 void skipToNextPreprocessorCommand();
102 static bool isCode(const Atom *atom);
103 static bool isQuote(const Atom *atom);
104 static void expandArgumentsInString(QString &str, const QStringList &args);
105 void cmd_image(int cmd);
106 void cmd_overload();
107
108 QStack<qsizetype> m_openedInputs {};
109
110 QString m_input {};
111 qsizetype m_position {};
112 qsizetype m_backslashPosition {};
113 qsizetype m_endPosition {};
114 qsizetype m_inputLength {};
115 Location m_cachedLocation {};
116 qsizetype m_cachedPosition {};
117
118 DocPrivate *m_private { nullptr };
119 enum ParagraphState { OutsideParagraph, InSingleLineParagraph, InMultiLineParagraph };
120 ParagraphState m_paragraphState {};
121 bool m_inTableHeader {};
122 bool m_inTableRow {};
123 bool m_inTableItem {};
124 bool m_indexStartedParagraph {}; // ### rename
125 Atom::AtomType m_pendingParagraphLeftType {};
126 Atom::AtomType m_pendingParagraphRightType {};
127 QString m_pendingParagraphString {};
128
129 int m_braceDepth {};
130 Doc::Sections m_currentSection {};
131 QMap<QString, Location> m_targetMap {};
132 QMap<int, QString> m_pendingFormats {};
133 QStack<int> m_openedCommands {};
134 QStack<OpenedList> m_openedLists {};
135 Quoter m_quoter {};
136 Atom *m_lastAtom { nullptr };
137
138 static DocUtilities &s_utilities;
139
140 // KLUDGE: When parsing documentation, there is a need to find
141 // files to resolve quoting commands. Ideally, the system that
142 // takes care of this would be a non-static member that is a
143 // reference that is passed at
144 // construction time.
145 // Nonetheless, with how the current codebase is constructed, this
146 // has proven to be extremely difficult until more changes are
147 // done. In particular, the construction of a DocParser happens in
148 // multiple places at multiple depths and, in particular, happens
149 // in one of Doc's constructor.
150 // Doc itself is built, again, in multiple places at multiple
151 // depths, making it clumsy and sometimes infeasible to pass the
152 // dependency around so that it is available at the required
153 // places. In particular, this stems from the fact that Doc is
154 // holding many responsabilities and is spread troughtout much of
155 // the codebase in different ways. DocParser mostly depends on Doc
156 // and Doc currently depends on DocParser, making the two
157 // difficult to separate.
158 //
159 // In the future, we expect Doc to mostly be removed, such as to
160 // remove this dependencies and the parsing of documentation to
161 // happen near main and atomically from other endevours, producing
162 // an intermediate representation that is consumed by later
163 // phases.
164 // At that point, it should be possible to not have this kind of
165 // indirection while, for now, the only accessible way to pass
166 // this dependency is trough the initialize method which passes
167 // for Doc::initialize.
168 //
169 // Furthemore, as we cannot late-bind a reference, and having a
170 // desire to avoid an unnecessary copy, we are thus forced to use
171 // a different storage method, in this case a pointer.
172 // This too should be removed later on, using reference or move
173 // semantic depending on the required data-flow.
174 static FileResolver* file_resolver;
175};
176
177QT_END_NAMESPACE
178
179#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:153
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:59
@ String
Definition atom.h:93
@ BriefLeft
Definition atom.h:26
@ LegaleseLeft
Definition atom.h:58
@ C
Definition atom.h:28
@ ParaRight
Definition atom.h:76
@ AutoLink
Definition atom.h:23
@ ParaLeft
Definition atom.h:75
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:150
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_ignoreWords
Definition docparser.h:43
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:44
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:53
bool m_autoGenerated
Definition docprivate.h:73
Text m_title
Definition docprivate.h:62
DocPrivateExtra * extra
Definition docprivate.h:69
void constructExtra()
Text m_text
Definition docprivate.h:61
bool m_hasLegalese
Definition docprivate.h:72
bool deref()
Definition docprivate.h:54
TopicList m_topics
Definition docprivate.h:70
CommandMap m_metaCommandMap
Definition docprivate.h:68
Definition doc.h:31
QSet< QString > parameterNames() const
Definition doc.cpp:201
Text legaleseText() const
Definition doc.cpp:193
QList< Text > alsoList() const
Definition doc.cpp:281
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:90
Doc & operator=(const Doc &doc)
Definition doc.cpp:75
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:47
const QList< Atom * > & tableOfContents() const
Definition doc.cpp:301
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file)
Definition doc.cpp:462
const Text & title() const
Definition doc.cpp:121
bool isInternal() const
Returns true if the set of metacommands used in the doc comment contains {internal}...
Definition doc.cpp:225
bool hasTableOfContents() const
Definition doc.cpp:286
const QList< Atom * > & keywords() const
Definition doc.cpp:321
~Doc()
Definition doc.cpp:69
const Text & body() const
Definition doc.cpp:115
static void initialize(FileResolver &file_resolver)
Definition doc.cpp:357
bool hasKeywords() const
Definition doc.cpp:291
QStringList omitEnumItemNames() const
Definition doc.cpp:211
const QList< Atom * > & targets() const
Definition doc.cpp:331
QMultiMap< ComparisonCategory, Text > * comparesWithMap() const
Definition doc.cpp:346
const QList< int > & tableOfContentsLevels() const
Definition doc.cpp:311
bool hasTargets() const
Definition doc.cpp:296
Text trimmedBriefText(const QString &className) const
Definition doc.cpp:132
Sections
Definition doc.h:34
ArgList metaCommandArgs(const QString &metaCommand) const
Definition doc.cpp:276
Text briefText(bool inclusive=false) const
Definition doc.cpp:127
const Location & startLocation() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:99
bool isMarkedReimp() const
Returns true if the set of metacommands used in the doc comment contains {reimp}.
Definition doc.cpp:234
void markAutoGenerated()
Marks this documentation as auto-generated by QDoc.
Definition doc.cpp:251
bool isAutoGenerated() const
Returns true if this documentation was auto-generated by QDoc rather than written by an author.
Definition doc.cpp:243
static void terminate()
All the heap allocated variables are deleted.
Definition doc.cpp:410
QList< ArgPair > overloadList() const
Returns the list of arguments passed to the {\overload} command.
Definition doc.cpp:261
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition doc.cpp:271
QStringMultiMap * metaTagMap() const
Definition doc.cpp:341
QSet< QString > metaCommandsUsed() const
Definition doc.cpp:216
bool isEmpty() const
Definition doc.cpp:110
Doc(const Doc &doc)
Definition doc.cpp:64
void constructExtra() const
Definition doc.cpp:351
const QString & source() const
Definition doc.cpp:104
QStringList enumItemNames() const
Definition doc.cpp:206
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:411
QList< ArgPair > ArgList
Definition doc.h:27
QMultiMap< QString, QString > QStringMultiMap
Definition doc.h:28
Combined button and popup list for selecting options.
QStringMultiMap m_metaMap
Definition docprivate.h:39
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