summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <[email protected]>2013-03-01 15:06:33 +0100
committerThe Qt Project <[email protected]>2013-03-02 12:58:18 +0100
commit7e5d1c1c2fc764d4cacc3e367542e1f42e6b772e (patch)
treeb2d555f840e30f299c7741574e6e93c4e236fcaa
parentb0e58a9008a01cd819d942ddc79534e8dd8ef8bd (diff)
moc: Support the '$' character as an identifier
Both gcc and clang allow the use of '$' in their identifiers as an extension. moc should not throw a parse error if there is one in the file. Instead, consider '$' as valid in identifiers. Task-number: QTBUG-22720 Change-Id: I8be3a52429c0db5b7e8308b8f4fe475d3d3994bf Reviewed-by: Simon Hausmann <[email protected]>
-rw-r--r--src/tools/moc/keywords.cpp2
-rw-r--r--src/tools/moc/ppkeywords.cpp2
-rw-r--r--src/tools/moc/util/generate_keywords.cpp9
-rw-r--r--src/tools/moc/utils.h4
-rw-r--r--tests/auto/tools/moc/dollars.h70
-rw-r--r--tests/auto/tools/moc/moc.pro1
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp1
7 files changed, 81 insertions, 8 deletions
diff --git a/src/tools/moc/keywords.cpp b/src/tools/moc/keywords.cpp
index 558e99c1d60..dc03af3378e 100644
--- a/src/tools/moc/keywords.cpp
+++ b/src/tools/moc/keywords.cpp
@@ -45,7 +45,7 @@
static const short keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,546,543,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 546,252,544,547,0,38,239,545,25,26,236,234,30,235,27,237,
+ 546,252,544,547,8,38,239,545,25,26,236,234,30,235,27,237,
22,22,22,22,22,22,22,22,22,22,34,41,23,39,24,43,
0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,21,8,8,8,8,8,8,8,8,8,31,549,32,238,8,
diff --git a/src/tools/moc/ppkeywords.cpp b/src/tools/moc/ppkeywords.cpp
index e9d199705d8..76387d4b18e 100644
--- a/src/tools/moc/ppkeywords.cpp
+++ b/src/tools/moc/ppkeywords.cpp
@@ -45,7 +45,7 @@
static const short pp_keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,98,12,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 98,76,96,13,0,60,62,97,9,10,58,56,11,57,102,59,
+ 98,76,96,13,1,60,62,97,9,10,58,56,11,57,102,59,
6,6,6,6,6,6,6,6,6,6,92,0,7,81,8,91,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,0,101,0,61,1,
diff --git a/src/tools/moc/util/generate_keywords.cpp b/src/tools/moc/util/generate_keywords.cpp
index 47ff0f9ac80..7ad553608cb 100644
--- a/src/tools/moc/util/generate_keywords.cpp
+++ b/src/tools/moc/util/generate_keywords.cpp
@@ -268,7 +268,7 @@ inline bool is_ident_start(char s)
{
return ((s >= 'a' && s <= 'z')
|| (s >= 'A' && s <= 'Z')
- || s == '_'
+ || s == '_' || s == '$'
);
}
@@ -277,7 +277,7 @@ inline bool is_ident_char(char s)
return ((s >= 'a' && s <= 'z')
|| (s >= 'A' && s <= 'Z')
|| (s >= '0' && s <= '9')
- || s == '_'
+ || s == '_' || s == '$'
);
}
struct State
@@ -360,8 +360,9 @@ void makeTable(const Keyword keywords[])
newState(states, pre?"PP_CHARACTER":"CHARACTER", c);
for (c = 'A'; c <= 'Z'; ++c)
newState(states, pre?"PP_CHARACTER":"CHARACTER", c);
- c = '_';
- newState(states, pre?"PP_CHARACTER":"CHARACTER", c);
+
+ newState(states, pre?"PP_CHARACTER":"CHARACTER", '_');
+ newState(states, pre?"PP_CHARACTER":"CHARACTER", '$');
// add digits
for (c = '0'; c <= '9'; ++c)
diff --git a/src/tools/moc/utils.h b/src/tools/moc/utils.h
index aeb9b745f11..a2c65e4b2a4 100644
--- a/src/tools/moc/utils.h
+++ b/src/tools/moc/utils.h
@@ -60,7 +60,7 @@ inline bool is_ident_start(char s)
{
return ((s >= 'a' && s <= 'z')
|| (s >= 'A' && s <= 'Z')
- || s == '_'
+ || s == '_' || s == '$'
);
}
@@ -69,7 +69,7 @@ inline bool is_ident_char(char s)
return ((s >= 'a' && s <= 'z')
|| (s >= 'A' && s <= 'Z')
|| (s >= '0' && s <= '9')
- || s == '_'
+ || s == '_' || s == '$'
);
}
diff --git a/tests/auto/tools/moc/dollars.h b/tests/auto/tools/moc/dollars.h
new file mode 100644
index 00000000000..8fab45559c2
--- /dev/null
+++ b/tests/auto/tools/moc/dollars.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Olivier Goffart <[email protected]>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/* both GCC and clang allow $ in identifiers
+ * So moc should not throw a parse error if it parses a file that contains such identifiers
+ */
+
+#include <QObject>
+
+#define macro$1 function1
+#define $macro2 function2
+
+namespace $NS {
+ class $CLS : public QObject
+ {
+ Q_PROPERTY(int rich$ MEMBER m_$rich$)
+ Q_PROPERTY(int money$$$ READ $$$money$$$ WRITE $$$setMoney$$$)
+ Q_OBJECT
+
+ int m_$rich$;
+ int m_money;
+ int $$$money$$$() { return m_money; }
+ int $$$setMoney$$$(int m) { return m_money = m; }
+
+ Q_SIGNALS:
+ void macro$1 ();
+ void $macro2 ();
+
+ void function$3 ($CLS * cl$s);
+ };
+}
+
diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro
index 8d08d9a8c07..1600c458b5b 100644
--- a/tests/auto/tools/moc/moc.pro
+++ b/tests/auto/tools/moc/moc.pro
@@ -26,6 +26,7 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n
if(*-g++*|*-icc*|*-clang*|*-llvm):!irix-*:!win32-*: HEADERS += os9-newlines.h win-newlines.h
+if(*-g++*|*-clang*): HEADERS += dollars.h
SOURCES += tst_moc.cpp
QT -= gui
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 195361e007e..382ee36d371 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <[email protected]>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.