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
parser.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef PARSER_H
5#define PARSER_H
6
7#include "symbols.h"
8#include <QtCore/qbytearrayview.h>
9
10#include <stack>
11
12QT_BEGIN_NAMESPACE
13
14class Parser
15{
16public:
17 Symbols symbols;
18 qsizetype index = 0;
19 bool displayWarnings = true;
20 bool displayNotes = true;
21 bool activeQtMode = false;
22 bool qmlMacroWarningIsFatal = false;
23
24 struct IncludePath
25 {
26 inline explicit IncludePath(const QByteArray &_path)
27 : path(_path), isFrameworkPath(false) {}
28 QByteArray path;
29 bool isFrameworkPath;
30 };
31 QList<IncludePath> includes;
32
33 std::stack<QByteArray, QByteArrayList> currentFilenames;
34
35 inline bool hasNext() const { return (index < symbols.size()); }
36 inline Token next() { if (index >= symbols.size()) return NOTOKEN; return symbols.at(index++).token; }
37 inline Token peek() { if (index >= symbols.size()) return NOTOKEN; return symbols.at(index).token; }
38 bool test(Token);
39 void next(Token);
40 void next(Token, const char *msg);
41 inline void prev() {--index;}
42 inline Token lookup(int k = 1);
43 inline const Symbol &symbol_lookup(int k = 1) { return symbols.at(index-1+k);}
44 inline Token token() { return symbols.at(index-1).token;}
45 inline QByteArray lexem() { return symbols.at(index-1).lexem();}
46 inline QByteArray unquotedLexem() { return symbols.at(index-1).unquotedLexem();}
47 inline QByteArrayView lexemView() { return symbols.at(index-1).lexemView();}
48 inline QByteArrayView unquotedLexemView() { return symbols.at(index-1).unquotedLexemView();}
49 inline const Symbol &symbol() { return symbols.at(index-1);}
50 inline const Symbol &symbolAt(qsizetype idx) { return symbols.at(idx); }
51
52 Q_NORETURN void error(const Symbol &symbol);
53 Q_NORETURN void error(const char *msg = nullptr);
54 Q_NORETURN void error(const Symbol &symbol, const char *msg);
55 void warning(const char * = nullptr);
56 void warning(const Symbol &sym, QByteArrayView msg);
57 void note(const char * = nullptr);
58 void defaultErrorMsg(const Symbol &sym);
59 void printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg, const Symbol &sym);
60
61};
62
63inline bool Parser::test(Token token)
64{
65 if (index < symbols.size() && symbols.at(index).token == token) {
66 ++index;
67 return true;
68 }
69 return false;
70}
71
72inline Token Parser::lookup(int k)
73{
74 const qsizetype l = index - 1 + k;
75 return l < symbols.size() ? symbols.at(l).token : NOTOKEN;
76}
77
78inline void Parser::next(Token token)
79{
80 if (!test(token))
81 error();
82}
83
84inline void Parser::next(Token token, const char *msg)
85{
86 if (!test(token))
87 error(msg);
88}
89
90QT_END_NAMESPACE
91
92#endif
Definition moc.h:223
void parse()
Definition moc.cpp:677
bool requireCompleteTypes
Definition moc.h:235
void generate(FILE *out, FILE *jsonOutput)
Definition moc.cpp:1190
bool noInclude
Definition moc.h:233
int evaluateCondition()
void setDebugIncludes(bool value)
void parseDefineArguments(Macro *m)
void skipUntilEndif()
QHash< QByteArray, QByteArray > nonlocalIncludePathResolutionCache
Symbols preprocessed(const QByteArray &filename, QFile *device)
void substituteUntilNewline(Symbols &substituted)
QList< QByteArray > frameworks
static bool preprocessOnly
static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName)
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, qsizetype &index, int lineNum, bool one, const QSet< QByteArray > &excludeSymbols=QSet< QByteArray >())
@ PreparePreprocessorStatement
@ TokenizePreprocessorStatement
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
QHash< MacroName, Macro > Macros
SubArray MacroName
#define qPrintable(string)
Definition qstring.h:1685
#define QStringLiteral(str)
Definition qstring.h:1826
static QByteArray combinePath(const QString &infile, const QString &outfile)
Definition main.cpp:40
static bool hasNext(const Symbols &symbols, int i)
Definition main.cpp:78
static const Symbol & next(const Symbols &symbols, int &i)
Definition main.cpp:81
int runMoc(int argc, char **argv)
Definition main.cpp:170
static auto openFileForWriting(const QString &name)
Definition main.cpp:62
void error(const char *msg="Invalid argument")
Definition main.cpp:56
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
Definition main.cpp:138
QByteArray composePreprocessorOutput(const Symbols &symbols)
Definition main.cpp:85
int main(int argc, char *argv[])
[ctor_close]
Simple structure used by the Doc and DocParser classes.
Symbols symbols
bool isVariadic
bool isFunction
Symbols arguments
Token token
Definition symbols.h:58
int lineNum
Definition symbols.h:57
QList< Symbol > Symbols
Definition symbols.h:75