Port tracedef to QRegularExpression

Change-Id: I38bbf36719c99d4fda102eca375011c38792dd4a
Reviewed-by: Rafael Roquetto <rafael@roquetto.com>
This commit is contained in:
Lars Knoll 2020-03-18 12:10:46 +01:00
parent 5b10b57c45
commit e174c2f7d7

View File

@ -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);