summaryrefslogtreecommitdiffstats
path: root/src/tools/tracegen
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-03-18 12:10:46 +0100
committerLars Knoll <lars.knoll@qt.io>2020-04-13 09:40:26 +0200
commite174c2f7d716bb804ad1d0dbe859f8480047f873 (patch)
treef0badafd95387774a5598d80e5dc94647fe2b801 /src/tools/tracegen
parent5b10b57c454b7a18537c04108bd1676ce18ea44d (diff)
Port tracedef to QRegularExpression
Change-Id: I38bbf36719c99d4fda102eca375011c38792dd4a Reviewed-by: Rafael Roquetto <rafael@roquetto.com>
Diffstat (limited to 'src/tools/tracegen')
-rw-r--r--src/tools/tracegen/provider.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/tools/tracegen/provider.cpp b/src/tools/tracegen/provider.cpp
index 7dfa6a86d6..7984fa12a7 100644
--- a/src/tools/tracegen/provider.cpp
+++ b/src/tools/tracegen/provider.cpp
@@ -43,7 +43,7 @@
#include <qfile.h>
#include <qfileinfo.h>
#include <qtextstream.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qstring.h>
#ifdef TRACEGEN_DEBUG
@@ -87,12 +87,13 @@ static inline int arrayLength(const QString &rawType)
/* matches the length of an ordinary array type
* Ex: foo[10] yields '10'
*/
- static const QRegExp rx(QStringLiteral(".*\\[([0-9]+)\\].*"));
+ static const QRegularExpression rx(QStringLiteral("\\[([0-9]+)\\]"));
- if (!rx.exactMatch(rawType.trimmed()))
+ auto match = rx.match(rawType);
+ if (!match.hasMatch())
return 0;
- return rx.cap(1).toInt();
+ return match.captured(1).toInt();
}
static inline QString sequenceLength(const QString &rawType)
@@ -102,12 +103,13 @@ static inline QString sequenceLength(const QString &rawType)
* Ex: in qcoreapplication_foo(const char[len], some_string, unsigned int, * len)
* it will match the 'len' part of 'const char[len]')
*/
- static const QRegExp rx(QStringLiteral(".*\\[([A-Za-z_][A-Za-z_0-9]*)\\].*"));
+ static const QRegularExpression rx(QStringLiteral("\\[([A-Za-z_][A-Za-z_0-9]*)\\]"));
- if (!rx.exactMatch(rawType.trimmed()))
+ auto match = rx.match(rawType);
+ if (!match.hasMatch())
return QString();
- return rx.cap(1);
+ return match.captured(1);
}
static QString decayArrayToPointer(QString type)
@@ -115,15 +117,14 @@ static QString decayArrayToPointer(QString type)
/* decays an array to a pointer, i.e., if 'type' holds int[10],
* this function returns 'int *'
*/
- static QRegExp rx(QStringLiteral("\\[(.+)\\]"));
+ static QRegularExpression rx(QStringLiteral("\\[([^\\]]+)\\]"));
- rx.setMinimal(true);
return type.replace(rx, QStringLiteral("*"));
}
static QString removeBraces(QString type)
{
- static const QRegExp rx(QStringLiteral("\\[.*\\]"));
+ static const QRegularExpression rx(QStringLiteral("\\[.*\\]"));
return type.remove(rx);
}
@@ -187,11 +188,11 @@ static Tracepoint::Field::BackendType backendType(QString rawType)
if (!sequenceLength(rawType).isNull())
return Tracepoint::Field::Sequence;
- static const QRegExp constMatch(QStringLiteral("\\bconst\\b"));
+ static const QRegularExpression constMatch(QStringLiteral("\\bconst\\b"));
rawType.remove(constMatch);
rawType.remove(QLatin1Char('&'));
- static const QRegExp ptrMatch(QStringLiteral("\\s*\\*\\s*"));
+ static const QRegularExpression ptrMatch(QStringLiteral("\\s*\\*\\s*"));
rawType.replace(ptrMatch, QStringLiteral("_ptr"));
rawType = rawType.trimmed();
rawType.replace(QStringLiteral(" "), QStringLiteral("_"));
@@ -218,19 +219,19 @@ static Tracepoint parseTracepoint(const QString &name, const QStringList &args,
auto end = args.constEnd();
int argc = 0;
- static const QRegExp rx(QStringLiteral("(.*)\\b([A-Za-z_][A-Za-z0-9_]*)$"));
+ static const QRegularExpression rx(QStringLiteral("^(.*)\\b([A-Za-z_][A-Za-z0-9_]*)$"));
while (i != end) {
- rx.exactMatch(*i);
+ auto match = rx.match(*i);
- const QString type = rx.cap(1).trimmed();
+ const QString type = match.captured(1).trimmed();
if (type.isNull()) {
panic("Missing parameter type for argument %d of %s (%s:%d)",
argc, qPrintable(name), qPrintable(fileName), lineNumber);
}
- const QString name = rx.cap(2).trimmed();
+ const QString name = match.captured(2).trimmed();
if (name.isNull()) {
panic("Missing parameter name for argument %d of %s (%s:%d)",
@@ -270,7 +271,7 @@ Provider parseProvider(const QString &filename)
QTextStream s(&f);
- static const QRegExp tracedef(QStringLiteral("([A-Za-z][A-Za-z0-9_]*)\\((.*)\\)"));
+ static const QRegularExpression tracedef(QStringLiteral("^([A-Za-z][A-Za-z0-9_]*)\\((.*)\\)$"));
Provider provider;
provider.name = QFileInfo(filename).baseName();
@@ -293,9 +294,10 @@ Provider parseProvider(const QString &filename)
if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
continue;
- if (tracedef.exactMatch(line)) {
- const QString name = tracedef.cap(1);
- const QString argsString = tracedef.cap(2);
+ auto match = tracedef.match(line);
+ if (match.hasMatch()) {
+ const QString name = match.captured(1);
+ const QString argsString = match.captured(2);
const QStringList args = argsString.split(QLatin1Char(','), Qt::SkipEmptyParts);
provider.tracepoints << parseTracepoint(name, args, filename, lineNumber);