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 { OutsideParagraph, InSingleLineParagraph, InMultiLineParagraph };
124 ParagraphState m_paragraphState {};
125 bool m_inTableHeader {};
126 bool m_inTableRow {};
127 bool m_inTableItem {};
128 bool m_indexStartedParagraph {}; // ### rename
129 Atom::AtomType m_pendingParagraphLeftType {};
130 Atom::AtomType m_pendingParagraphRightType {};
131 QString m_pendingParagraphString {};
132
133 int m_braceDepth {};
134 Doc::Sections m_currentSection {};
135 QMap<QString, Location> m_targetMap {};
136 QMap<int, QString> m_pendingFormats {};
137 QStack<int> m_openedCommands {};
138 QStack<OpenedList> m_openedLists {};
139 Quoter m_quoter {};
140 Atom *m_lastAtom { nullptr };
141
142 static DocUtilities &s_utilities;
143
144 // KLUDGE: When parsing documentation, there is a need to find
145 // files to resolve quoting commands. Ideally, the system that
146 // takes care of this would be a non-static member that is a
147 // reference that is passed at
148 // construction time.
149 // Nonetheless, with how the current codebase is constructed, this
150 // has proven to be extremely difficult until more changes are
151 // done. In particular, the construction of a DocParser happens in
152 // multiple places at multiple depths and, in particular, happens
153 // in one of Doc's constructor.
154 // Doc itself is built, again, in multiple places at multiple
155 // depths, making it clumsy and sometimes infeasible to pass the
156 // dependency around so that it is available at the required
157 // places. In particular, this stems from the fact that Doc is
158 // holding many responsabilities and is spread troughtout much of
159 // the codebase in different ways. DocParser mostly depends on Doc
160 // and Doc currently depends on DocParser, making the two
161 // difficult to separate.
162 //
163 // In the future, we expect Doc to mostly be removed, such as to
164 // remove this dependencies and the parsing of documentation to
165 // happen near main and atomically from other endevours, producing
166 // an intermediate representation that is consumed by later
167 // phases.
168 // At that point, it should be possible to not have this kind of
169 // indirection while, for now, the only accessible way to pass
170 // this dependency is trough the initialize method which passes
171 // for Doc::initialize.
172 //
173 // Furthemore, as we cannot late-bind a reference, and having a
174 // desire to avoid an unnecessary copy, we are thus forced to use
175 // a different storage method, in this case a pointer.
176 // This too should be removed later on, using reference or move
177 // semantic depending on the required data-flow.
178 static FileResolver* file_resolver;
179};
180
181QT_END_NAMESPACE
182
183#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_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: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:32
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
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
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file, CodeMarker *marker=nullptr)
Definition doc.cpp:462
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:35
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: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: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