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 PREPROCESSOR_H
5#define PREPROCESSOR_H
6
7#include "parser.h"
8#include <qlist.h>
9#include <qset.h>
10#include <stdio.h>
11
12QT_BEGIN_NAMESPACE
13
14struct Macro
15{
16 Macro() : isFunction(false), isVariadic(false) {}
17 bool isFunction;
18 bool isVariadic;
19 Symbols arguments;
20 Symbols symbols;
21};
22
23#ifdef USE_LEXEM_STORE
24typedef QByteArray MacroName;
25#else
26typedef SubArray MacroName;
27#endif
28typedef QHash<MacroName, Macro> Macros;
29
30class QFile;
31
32class Preprocessor : public Parser
33{
34public:
35 Preprocessor(){}
36 static bool preprocessOnly;
37 QList<QByteArray> frameworks;
38 QSet<QByteArray> preprocessedIncludes;
39 QHash<QByteArray, QByteArray> nonlocalIncludePathResolutionCache;
40 Macros macros;
41 QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo);
42 Symbols preprocessed(const QByteArray &filename, QFile *device);
43
44 void parseDefineArguments(Macro *m);
45
46 void skipUntilEndif();
47 bool skipBranch();
48
49 void substituteUntilNewline(Symbols &substituted);
50 static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName);
51 static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand,
52 qsizetype &index, int lineNum, bool one,
53 const QSet<QByteArray> &excludeSymbols = QSet<QByteArray>());
54
55 int evaluateCondition();
56
57 enum TokenizeMode { TokenizeCpp, TokenizePreprocessor, PreparePreprocessorStatement, TokenizePreprocessorStatement, TokenizeInclude, PrepareDefine, TokenizeDefine };
58 static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode mode = TokenizeCpp);
59
60 void setDebugIncludes(bool value);
61
62private:
63 void until(Token);
64
65 void preprocess(const QByteArray &filename, Symbols &preprocessed);
66 bool debugIncludes = false;
67};
68
69QT_END_NAMESPACE
70
71#endif // PREPROCESSOR_H
72

source code of qtbase/src/tools/moc/preprocessor.h