summaryrefslogtreecommitdiffstats
path: root/src/qtwaylandscanner
diff options
context:
space:
mode:
authorJorgen Lind <jorgen.lind@digia.com>2013-11-25 10:44:29 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-27 21:39:45 +0100
commitdcef544fb24f810b21fa38cc0e9e77f3a4f86ba8 (patch)
treecdb0ae8dbb7cec87885beaeab9449c6a9d3e970a /src/qtwaylandscanner
parent645dc7c8528ef05e8f1cb040a5350c631eaa0162 (diff)
Add a preprocessor protocol name variable
We should convert - to _ in the preprocessor protocol name since - will lead to a new token, but we don't since it is better to fail early here and the official wayland-scanner doesn't do this either. The generated c++ header will give a compiler error when being used which gives the user a chance to change the protocol name. Change-Id: I049bdecacc8ed9a70c0879494d4d358ce53f3320 Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Diffstat (limited to 'src/qtwaylandscanner')
-rw-r--r--src/qtwaylandscanner/qtwaylandscanner.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp
index 85cca90b9..bd8471e0a 100644
--- a/src/qtwaylandscanner/qtwaylandscanner.cpp
+++ b/src/qtwaylandscanner/qtwaylandscanner.cpp
@@ -344,6 +344,11 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
return;
}
+ //We should convert - to _ so that the preprocessor wont generate code which will lead to unexpected behavior
+ //However, the wayland-scanner doesn't do so we will do the same for now
+ //QByteArray preProcessorProtocolName = QByteArray(protocolName).replace('-', '_').toUpper();
+ QByteArray preProcessorProtocolName = QByteArray(protocolName).toUpper();
+
QList<WaylandInterface> interfaces;
while (xml.readNextStartElement()) {
@@ -357,7 +362,7 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
return;
if (option == ServerHeader) {
- QByteArray inclusionGuard = "QT_WAYLAND_SERVER_" + protocolName.toUpper();
+ QByteArray inclusionGuard = QByteArray("QT_WAYLAND_SERVER_") + preProcessorProtocolName.constData();
printf("#ifndef %s\n", inclusionGuard.constData());
printf("#define %s\n", inclusionGuard.constData());
printf("\n");
@@ -381,13 +386,15 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
printf("\n");
printf("QT_BEGIN_NAMESPACE\n");
+ QByteArray serverExport;
if (headerPath.size()) {
+ serverExport = QByteArray("Q_WAYLAND_SERVER_") + preProcessorProtocolName + "_EXPORT";
printf("\n");
- printf("#if !defined(Q_WAYLAND_SERVER_%s_EXPORT)\n", protocolName.toUpper().constData());
+ printf("#if !defined(%s)\n", serverExport.constData());
printf("# if defined(QT_SHARED)\n");
- printf("# define Q_WAYLAND_SERVER_%s_EXPORT Q_DECL_EXPORT\n", protocolName.toUpper().constData());
+ printf("# define %s Q_DECL_EXPORT\n", serverExport.constData());
printf("# else\n");
- printf("# define Q_WAYLAND_SERVER_%s_EXPORT\n", protocolName.toUpper().constData());
+ printf("# define %s\n", serverExport.constData());
printf("# endif\n");
printf("#endif\n");
}
@@ -405,10 +412,7 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
QByteArray stripped = stripInterfaceName(interface.name);
const char *interfaceNameStripped = stripped.constData();
- if (headerPath.isEmpty())
- printf(" class %s\n {\n", interfaceName);
- else
- printf(" class Q_WAYLAND_SERVER_%s_EXPORT %s\n {\n",protocolName.toUpper().constData(), interfaceName);
+ printf(" class %s %s\n {\n", serverExport.constData(), interfaceName);
printf(" public:\n");
printf(" %s(struct ::wl_client *client, int id);\n", interfaceName);
printf(" %s(struct ::wl_display *display);\n", interfaceName);
@@ -764,7 +768,7 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
}
if (option == ClientHeader) {
- QByteArray inclusionGuard = "QT_WAYLAND_" + protocolName.toUpper();
+ QByteArray inclusionGuard = QByteArray("QT_WAYLAND_") + preProcessorProtocolName.constData();
printf("#ifndef %s\n", inclusionGuard.constData());
printf("#define %s\n", inclusionGuard.constData());
printf("\n");
@@ -777,13 +781,16 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
printf("\n");
printf("QT_BEGIN_NAMESPACE\n");
+ QByteArray clientExport;
+
if (headerPath.size()) {
+ clientExport = QByteArray("Q_WAYLAND_CLIENT_") + preProcessorProtocolName + "_EXPORT";
printf("\n");
- printf("#if !defined(Q_WAYLAND_CLIENT_%s_EXPORT)\n", protocolName.toUpper().constData());
+ printf("#if !defined(%s)\n", clientExport.constData());
printf("# if defined(QT_SHARED)\n");
- printf("# define Q_WAYLAND_CLIENT_%s_EXPORT Q_DECL_EXPORT\n", protocolName.toUpper().constData());
+ printf("# define %s Q_DECL_EXPORT\n", clientExport.constData());
printf("# else\n");
- printf("# define Q_WAYLAND_CLIENT_%s_EXPORT\n", protocolName.toUpper().constData());
+ printf("# define %s\n", clientExport.constData());
printf("# endif\n");
printf("#endif\n");
}
@@ -800,10 +807,7 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath)
QByteArray stripped = stripInterfaceName(interface.name);
const char *interfaceNameStripped = stripped.constData();
- if (headerPath.isEmpty())
- printf(" class %s\n {\n", interfaceName);
- else
- printf(" class Q_WAYLAND_CLIENT_%s_EXPORT %s\n {\n",protocolName.toUpper().constData(), interfaceName);
+ printf(" class %s %s\n {\n", clientExport.constData(), interfaceName);
printf(" public:\n");
printf(" %s(struct ::wl_registry *registry, int id);\n", interfaceName);
printf(" %s(struct ::%s *object);\n", interfaceName, interfaceName);