1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef PARSE_DEFINES_H
30#define PARSE_DEFINES_H
31
32#include <qobject.h>
33
34// this is intentionally ugly to test moc's preprocessing capabilities
35#define PD_NAMESPACE PD
36#define PD_BEGIN_NAMESPACE namespace PD_NAMESPACE {
37#define PD_END_NAMESPACE }
38#define PD_VOIDFUNCTION() voidFunction()
39#define PD_CLASSNAME ParseDefine
40
41#define PD_STRINGIFY(a) #a
42#define PD_XSTRINGIFY(a) PD_STRINGIFY(a)
43#define PD_SCOPED_STRING(a, b) PD_STRINGIFY(a) "::" PD_STRINGIFY(b)
44#define PD_DEFINE1(a,b) a##b
45#define PD_DEFINE2(a,b) a comb##b
46#define PD_DEFINE3(a,b) a b##ined3()
47#define PD_COMBINE(a,b) a b
48#define PD_TEST_IDENTIFIER_ARG(if, while) if while
49
50#define QString() error_type
51
52#define PD_CLASSINFO Q_CLASSINFO
53
54#define PD_VARARG(x, ...) x(__VA_ARGS__)
55
56#if defined(Q_CC_GNU) || defined(Q_MOC_RUN)
57//GCC extension for variadic macros
58#define PD_VARARGEXT(x, y...) x(y)
59#else
60#define PD_VARARGEXT(x, ...) x(__VA_ARGS__)
61#endif
62
63
64#define PD_ADD_SUFFIX(x) PD_DEFINE1(x,_SUFFIX)
65#define PD_DEFINE_ITSELF PD_ADD_SUFFIX(PD_DEFINE_ITSELF)
66
67#ifndef Q_MOC_RUN
68// macro defined on the command line (in tst_moc.pro)
69#define DEFINE_CMDLINE_EMPTY
70#define DEFINE_CMDLINE_SIGNAL void cmdlineSignal(const QMap<int, int> &i)
71#endif
72
73#define HASH_SIGN #
74
75PD_BEGIN_NAMESPACE
76
77class DEFINE_CMDLINE_EMPTY PD_CLASSNAME DEFINE_CMDLINE_EMPTY
78 : public DEFINE_CMDLINE_EMPTY QObject DEFINE_CMDLINE_EMPTY
79{
80 Q_OBJECT
81 Q_CLASSINFO("TestString", PD_STRINGIFY(PD_CLASSNAME))
82 Q_CLASSINFO("TestString2", PD_XSTRINGIFY(PD_CLASSNAME))
83 PD_CLASSINFO("TestString3", "TestValue")
84public:
85 PD_CLASSNAME() {}
86
87public slots:
88 void PD_VOIDFUNCTION() {}
89
90 QString stringMethod() { return QString::fromLatin1(str: ""); }
91
92 void PD_DEFINE1(comb, ined1()) {}
93 PD_DEFINE2(void, ined2()) {}
94 PD_DEFINE3(void, comb) {}
95 PD_COMBINE(void combined4(int, int), {})
96
97 PD_COMBINE(void combined5() {, })
98
99 PD_TEST_IDENTIFIER_ARG(void, combined6()) {}
100
101 PD_VARARG(void vararg1) {}
102 PD_VARARG(void vararg2, int) {}
103 PD_VARARG(void vararg3, int, int) {}
104
105 PD_VARARGEXT(void vararg4) {}
106 PD_VARARGEXT(void vararg5, int) {}
107 PD_VARARGEXT(void vararg6, int, int) {}
108
109#define OUTERFUNCTION(x) x
110#define INNERFUNCTION(x) OUTERFUNCTION(x)
111#define INNER INNERFUNCTION
112
113 void INNERFUNCTION(INNERFUNCTION)(int) {}
114 void OUTERFUNCTION(INNERFUNCTION)(inner_expanded(int)) {}
115 void expanded_method OUTERFUNCTION(INNER)((int)) {}
116
117#undef INNERFUNCTION
118
119#define cond1() 0x1
120#define cond2() 0x2
121
122#if !(cond1() & cond2())
123 void conditionSlot() {}
124#endif
125
126 void PD_DEFINE_ITSELF(int) {}
127
128signals:
129 DEFINE_CMDLINE_SIGNAL;
130
131#define QTBUG55853(X) PD_DEFINE1(X, signalQTBUG55853)
132#define PD_EMPTY /* empty */
133 void QTBUG55853(PD_EMPTY)();
134};
135
136#undef QString
137
138#ifdef Q_MOC_RUN
139// Normaly, redefining keywords is forbidden, but we should not abort parsing
140#define and &&
141#define and_eq &=
142#define bitand &
143#define true 1
144#undef true
145#endif
146
147PD_END_NAMESPACE
148
149#endif
150

source code of qtbase/tests/auto/tools/moc/parse-defines.h