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 "docutilities.h"
9#include "location.h"
10#include "openedlist.h"
11#include "quoter.h"
12
13#include "filesystem/fileresolver.h"
14
15#include <QtCore/QCoreApplication>
16#include <QtCore/qglobalstatic.h>
17#include <QtCore/qhash.h>
18#include <QtCore/qstack.h>
19#include <QtCore/qstring.h>
20
22
23class Doc;
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 appendToCode(const QString &code);
70 void appendToCode(const QString &code, Atom::AtomType defaultType);
71 void enterPara(Atom::AtomType leftType = Atom::ParaLeft,
72 Atom::AtomType rightType = Atom::ParaRight, const QString &string = QString());
73 void leavePara();
74 void leaveValue();
75 void leaveValueList();
76 void leaveTableRow();
77 void quoteFromFile(const QString& filename);
78 bool expandMacro(ArgumentParsingOptions options);
79 void expandMacro(const QString &def, const QStringList &args);
80 QString expandMacroToString(const QString &name, const Macro &macro);
81 Doc::Sections getSectioningUnit();
82 QString getArgument(ArgumentParsingOptions options = ArgumentParsingOptions::Default);
83 QString getBracedArgument(ArgumentParsingOptions options);
84 QString getBracketedArgument();
85 QStringList getMacroArguments(const QString &name, const Macro &macro);
86 QString getOptionalArgument();
87 QString getRestOfLine();
88 QString getMetaCommandArgument(const QString &cmdStr);
89 QString getUntilEnd(int cmd);
90 QString getCode(int cmd, CodeMarker *marker, const QString &argStr = QString());
91
92 inline bool isAutoLinkString(const QString &word);
93 bool isAutoLinkString(const QString &word, qsizetype &curPos);
94 bool isBlankLine();
95 bool isLeftBraceAhead();
96 bool isLeftBracketAhead();
97 void skipSpacesOnLine();
98 void skipSpacesOrOneEndl();
99 void skipAllSpaces();
100 void skipToNextPreprocessorCommand();
101 static bool isCode(const Atom *atom);
102 static bool isQuote(const Atom *atom);
103 static void expandArgumentsInString(QString &str, const QStringList &args);
104
105 QStack<qsizetype> m_openedInputs {};
106
107 QString m_input {};
108 qsizetype m_position {};
109 qsizetype m_backslashPosition {};
110 qsizetype m_endPosition {};
111 qsizetype m_inputLength {};
112 Location m_cachedLocation {};
113 qsizetype m_cachedPosition {};
114
115 DocPrivate *m_private { nullptr };
116 enum ParagraphState { OutsideParagraph, InSingleLineParagraph, InMultiLineParagraph };
117 ParagraphState m_paragraphState {};
118 bool m_inTableHeader {};
119 bool m_inTableRow {};
120 bool m_inTableItem {};
121 bool m_indexStartedParagraph {}; // ### rename
122 Atom::AtomType m_pendingParagraphLeftType {};
123 Atom::AtomType m_pendingParagraphRightType {};
124 QString m_pendingParagraphString {};
125
126 int m_braceDepth {};
127 Doc::Sections m_currentSection {};
128 QMap<QString, Location> m_targetMap {};
129 QMap<int, QString> m_pendingFormats {};
130 QStack<int> m_openedCommands {};
131 QStack<OpenedList> m_openedLists {};
132 Quoter m_quoter {};
133 Atom *m_lastAtom { nullptr };
134
135 static DocUtilities &s_utilities;
136
137 // KLUDGE: When parsing documentation, there is a need to find
138 // files to resolve quoting commands. Ideally, the system that
139 // takes care of this would be a non-static member that is a
140 // reference that is passed at
141 // construction time.
142 // Nonetheless, with how the current codebase is constructed, this
143 // has proven to be extremely difficult until more changes are
144 // done. In particular, the construction of a DocParser happens in
145 // multiple places at multiple depths and, in particular, happens
146 // in one of Doc's constructor.
147 // Doc itself is built, again, in multiple places at multiple
148 // depths, making it clumsy and sometimes infeasible to pass the
149 // dependency around so that it is available at the required
150 // places. In particular, this stems from the fact that Doc is
151 // holding many responsabilities and is spread troughtout much of
152 // the codebase in different ways. DocParser mostly depends on Doc
153 // and Doc currently depends on DocParser, making the two
154 // difficult to separate.
155 //
156 // In the future, we expect Doc to mostly be removed, such as to
157 // remove this dependencies and the parsing of documentation to
158 // happen near main and atomically from other endevours, producing
159 // an intermediate representation that is consumed by later
160 // phases.
161 // At that point, it should be possible to not have this kind of
162 // indirection while, for now, the only accessible way to pass
163 // this dependency is trough the initialize method which passes
164 // for Doc::initialize.
165 //
166 // Furthemore, as we cannot late-bind a reference, and having a
167 // desire to avoid an unnecessary copy, we are thus forced to use
168 // a different storage method, in this case a pointer.
169 // This too should be removed later on, using reference or move
170 // semantic depending on the required data-flow.
171 static FileResolver* file_resolver;
172};
173
174QT_END_NAMESPACE
175
176#endif // DOCPARSER_H
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:18
AtomType type() const
Return the type of this atom.
Definition atom.h:149
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
Definition atom.h:20
@ BriefRight
Definition atom.h:26
@ LegaleseRight
Definition atom.h:58
@ String
Definition atom.h:92
@ BriefLeft
Definition atom.h:25
@ LegaleseLeft
Definition atom.h:57
@ C
Definition atom.h:27
@ ParaRight
Definition atom.h:75
@ AutoLink
Definition atom.h:22
@ ParaLeft
Definition atom.h:74
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:146
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:84
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
DocPrivateExtra * extra
Definition docprivate.h:68
void constructExtra()
Text m_text
Definition docprivate.h:61
bool m_hasLegalese
Definition docprivate.h:71
bool deref()
Definition docprivate.h:54
TopicList m_topics
Definition docprivate.h:69
Definition doc.h:31
QSet< QString > parameterNames() const
Definition doc.cpp:195
Text legaleseText() const
Definition doc.cpp:187
QList< Text > alsoList() const
Definition doc.cpp:248
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:268
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file)
Definition doc.cpp:403
bool isInternal() const
Returns true if the set of metacommands used in the doc comment contains {internal}...
Definition doc.cpp:219
bool hasTableOfContents() const
Definition doc.cpp:253
const QList< Atom * > & keywords() const
Definition doc.cpp:280
~Doc()
Definition doc.cpp:69
const Text & body() const
Definition doc.cpp:115
static void initialize(FileResolver &file_resolver)
Definition doc.cpp:308
bool hasKeywords() const
Definition doc.cpp:258
QStringList omitEnumItemNames() const
Definition doc.cpp:205
const QList< Atom * > & targets() const
Definition doc.cpp:286
QMultiMap< ComparisonCategory, Text > * comparesWithMap() const
Definition doc.cpp:297
const QList< int > & tableOfContentsLevels() const
Definition doc.cpp:274
bool hasTargets() const
Definition doc.cpp:263
Text trimmedBriefText(const QString &className) const
Definition doc.cpp:126
Sections
Definition doc.h:34
ArgList metaCommandArgs(const QString &metaCommand) const
Definition doc.cpp:243
Text briefText(bool inclusive=false) const
Definition doc.cpp:121
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:228
static void terminate()
All the heap allocated variables are deleted.
Definition doc.cpp:361
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
Definition doc.cpp:238
QStringMultiMap * metaTagMap() const
Definition doc.cpp:292
QSet< QString > metaCommandsUsed() const
Definition doc.cpp:210
bool isEmpty() const
Definition doc.cpp:110
Doc(const Doc &doc)
Definition doc.cpp:64
void constructExtra() const
Definition doc.cpp:302
const QString & source() const
Definition doc.cpp:104
QStringList enumItemNames() const
Definition doc.cpp:200
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:15
int columnNo() const
Returns the current column number.
Definition location.h:44
void reset()
Definition quoter.cpp:106
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:364
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