tracegen: Fix handling enumerators with duplicate values
Aggregate the names of the same value enumerators. The values can also be hexadecimal so handle them also. Change-Id: I89693d7e3b8f6c051b298401dcbe8a9f5c0a38aa Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> (cherry picked from commit 83effb3a3f6bf73e682f7a9ccedebf4073ade776)
This commit is contained in:
parent
1f23ed3c85
commit
b3f77d25aa
@ -305,11 +305,20 @@ static void writeEnums(QTextStream &stream, const Provider &provider)
|
|||||||
name.replace(QStringLiteral("::"), QStringLiteral("_"));
|
name.replace(QStringLiteral("::"), QStringLiteral("_"));
|
||||||
stream << "TRACEPOINT_METADATA(" << provider.name << ", " << name << ", \n";
|
stream << "TRACEPOINT_METADATA(" << provider.name << ", " << name << ", \n";
|
||||||
stream << "QStringLiteral(\"typealias enum : integer { size = " << e.valueSize << "; } {\\n\\\n";
|
stream << "QStringLiteral(\"typealias enum : integer { size = " << e.valueSize << "; } {\\n\\\n";
|
||||||
for (const auto &v : e.values) {
|
|
||||||
if (v.range)
|
const auto values = e.values;
|
||||||
|
QList<int> handledValues;
|
||||||
|
|
||||||
|
for (const auto &v : values) {
|
||||||
|
if (handledValues.contains(v.value))
|
||||||
|
continue;
|
||||||
|
if (v.range) {
|
||||||
stream << v.name << " = " << v.value << " ... " << v.range << ", \\n\\\n";
|
stream << v.name << " = " << v.value << " ... " << v.range << ", \\n\\\n";
|
||||||
else
|
} else {
|
||||||
stream << v.name << " = " << v.value << ", \\n\\\n";
|
const QString names = aggregateListValues(v.value, values);
|
||||||
|
stream << names << " = " << v.value << ", \\n\\\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stream << "} := " << name << ";\\n\\n\"));\n\n";
|
stream << "} := " << name << ";\\n\\n\"));\n\n";
|
||||||
}
|
}
|
||||||
@ -323,8 +332,16 @@ static void writeFlags(QTextStream &stream, const Provider &provider)
|
|||||||
name.replace(QStringLiteral("::"), QStringLiteral("_"));
|
name.replace(QStringLiteral("::"), QStringLiteral("_"));
|
||||||
stream << "TRACEPOINT_METADATA(" << provider.name << ", " << name << ", \n";
|
stream << "TRACEPOINT_METADATA(" << provider.name << ", " << name << ", \n";
|
||||||
stream << "QStringLiteral(\"typealias enum : integer { size = 8; } {\\n\\\n";
|
stream << "QStringLiteral(\"typealias enum : integer { size = 8; } {\\n\\\n";
|
||||||
for (const auto &v : e.values) {
|
|
||||||
stream << v.name << " = " << v.value << ", \\n\\\n";
|
const auto values = e.values;
|
||||||
|
QList<int> handledValues;
|
||||||
|
|
||||||
|
for (const auto &v : values) {
|
||||||
|
if (handledValues.contains(v.value))
|
||||||
|
continue;
|
||||||
|
const QString names = aggregateListValues(v.value, values);
|
||||||
|
stream << names << " = " << v.value << ", \\n\\\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
}
|
}
|
||||||
stream << "} := " << name << ";\\n\\n\"));\n\n";
|
stream << "} := " << name << ";\\n\\n\"));\n\n";
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,14 @@ static void writeEnumConverter(QTextStream &stream, const TraceEnum &enumeration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream << "\n QString ret;\n switch (val) {\n";
|
stream << "\n QString ret;\n switch (val) {\n";
|
||||||
|
|
||||||
|
QList<int> handledValues;
|
||||||
for (const auto &v : enumeration.values) {
|
for (const auto &v : enumeration.values) {
|
||||||
if (v.range == 0)
|
if (v.range == 0 && !handledValues.contains(v.value)) {
|
||||||
stream << " case " << v.value << ": ret = QStringLiteral(\"" << v.name << "\"); break;\n";
|
stream << " case " << v.value << ": ret = QStringLiteral(\""
|
||||||
|
<< aggregateListValues(v.value, enumeration.values) << "\"); break;\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << " }\n return ret;\n}\n";
|
stream << " }\n return ret;\n}\n";
|
||||||
@ -229,13 +234,18 @@ static void writeFlagConverter(QTextStream &stream, const TraceFlags &flag)
|
|||||||
stream << "{\n QString ret;\n";
|
stream << "{\n QString ret;\n";
|
||||||
for (const auto &v : flag.values) {
|
for (const auto &v : flag.values) {
|
||||||
if (v.value == 0) {
|
if (v.value == 0) {
|
||||||
stream << " if (val == 0)\n return QStringLiteral(\"" << v.name << "\");\n";
|
stream << " if (val == 0)\n return QStringLiteral(\""
|
||||||
|
<< aggregateListValues(v.value, flag.values) << "\");\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QList<int> handledValues;
|
||||||
for (const auto &v : flag.values) {
|
for (const auto &v : flag.values) {
|
||||||
if (v.value != 0)
|
if (v.value != 0 && !handledValues.contains(v.value)) {
|
||||||
stream << " if (val & " << (1 << (v.value - 1)) << ") { if (ret.length()) ret += QLatin1Char(\'|\'); ret += QStringLiteral(\"" << v.name << "\"); }\n";
|
stream << " if (val & " << (1 << (v.value - 1))
|
||||||
|
<< ") { if (ret.length()) ret += QLatin1Char(\'|\'); ret += QStringLiteral(\"" << v.name << "\"); }\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stream << " return ret;\n}\n";
|
stream << " return ret;\n}\n";
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,15 @@ QString includeGuard(const QString &filename);
|
|||||||
QString formatFunctionSignature(const QList<Tracepoint::Argument> &args);
|
QString formatFunctionSignature(const QList<Tracepoint::Argument> &args);
|
||||||
QString formatParameterList(const Provider &provider, const QList<Tracepoint::Argument> &args, const QList<Tracepoint::Field> &fields, ParamType type);
|
QString formatParameterList(const Provider &provider, const QList<Tracepoint::Argument> &args, const QList<Tracepoint::Field> &fields, ParamType type);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static QString aggregateListValues(int value, const QList<T> &list)
|
||||||
|
{
|
||||||
|
QStringList values;
|
||||||
|
for (auto l : list) {
|
||||||
|
if (l.value == value)
|
||||||
|
values << l.name;
|
||||||
|
}
|
||||||
|
return values.join(QLatin1Char('_'));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HELPERS_H
|
#endif // HELPERS_H
|
||||||
|
@ -198,11 +198,14 @@ static void writeEnums(QTextStream &stream, const Provider &provider)
|
|||||||
<< " " << provider.name << ",\n"
|
<< " " << provider.name << ",\n"
|
||||||
<< " " << typeToTypeName(e.name) << ",\n"
|
<< " " << typeToTypeName(e.name) << ",\n"
|
||||||
<< " TP_ENUM_VALUES(\n";
|
<< " TP_ENUM_VALUES(\n";
|
||||||
|
QList<int> handledValues;
|
||||||
for (const auto &v : e.values) {
|
for (const auto &v : e.values) {
|
||||||
if (v.range > 0)
|
if (v.range > 0) {
|
||||||
stream << " ctf_enum_range(\"" << v.name << "\", " << v.value << ", " << v.range << ")\n";
|
stream << " ctf_enum_range(\"" << v.name << "\", " << v.value << ", " << v.range << ")\n";
|
||||||
else
|
} else if (!handledValues.contains(v.value)) {
|
||||||
stream << " ctf_enum_value(\"" << v.name << "\", " << v.value << ")\n";
|
stream << " ctf_enum_value(\"" << aggregateListValues(v.value, e.values) << "\", " << v.value << ")\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stream << " )\n)\n\n";
|
stream << " )\n)\n\n";
|
||||||
}
|
}
|
||||||
@ -215,8 +218,13 @@ static void writeFlags(QTextStream &stream, const Provider &provider)
|
|||||||
<< " " << provider.name << ",\n"
|
<< " " << provider.name << ",\n"
|
||||||
<< " " << typeToTypeName(f.name) << ",\n"
|
<< " " << typeToTypeName(f.name) << ",\n"
|
||||||
<< " TP_ENUM_VALUES(\n";
|
<< " TP_ENUM_VALUES(\n";
|
||||||
for (const auto &v : f.values)
|
QList<int> handledValues;
|
||||||
stream << " ctf_enum_value(\"" << v.name << "\", " << v.value << ")\n";
|
for (const auto &v : f.values) {
|
||||||
|
if (!handledValues.contains(v.value)) {
|
||||||
|
stream << " ctf_enum_value(\"" << aggregateListValues(v.value, f.values) << "\", " << v.value << ")\n";
|
||||||
|
handledValues.append(v.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
stream << " )\n)\n\n";
|
stream << " )\n)\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ Provider parseProvider(const QString &filename)
|
|||||||
|
|
||||||
static const QRegularExpression tracedef(QStringLiteral("^([A-Za-z][A-Za-z0-9_]*)\\((.*)\\)$"));
|
static const QRegularExpression tracedef(QStringLiteral("^([A-Za-z][A-Za-z0-9_]*)\\((.*)\\)$"));
|
||||||
static const QRegularExpression enumenddef(QStringLiteral("^} ?([A-Za-z][A-Za-z0-9_:]*);"));
|
static const QRegularExpression enumenddef(QStringLiteral("^} ?([A-Za-z][A-Za-z0-9_:]*);"));
|
||||||
static const QRegularExpression enumdef(QStringLiteral("^([A-Za-z][A-Za-z0-9_]*)( ?= ?([0-9]*))?"));
|
static const QRegularExpression enumdef(QStringLiteral("^([A-Za-z][A-Za-z0-9_]*)( *= *([xabcdef0-9]*))?"));
|
||||||
static const QRegularExpression rangedef(QStringLiteral("^RANGE\\(([A-Za-z][A-Za-z0-9_]*) ?, ?([0-9]*) ?... ?([0-9]*) ?\\)"));
|
static const QRegularExpression rangedef(QStringLiteral("^RANGE\\(([A-Za-z][A-Za-z0-9_]*) ?, ?([0-9]*) ?... ?([0-9]*) ?\\)"));
|
||||||
|
|
||||||
Provider provider;
|
Provider provider;
|
||||||
@ -370,7 +370,7 @@ Provider parseProvider(const QString &filename)
|
|||||||
value.name = m.captured(1);
|
value.name = m.captured(1);
|
||||||
value.value = m.captured(2).toInt();
|
value.value = m.captured(2).toInt();
|
||||||
value.range = m.captured(3).toInt();
|
value.range = m.captured(3).toInt();
|
||||||
currentEnumValue = value.range;
|
currentEnumValue = value.range + 1;
|
||||||
currentEnum.values.push_back(value);
|
currentEnum.values.push_back(value);
|
||||||
maxEnumValue = qMax(maxEnumValue, value.range);
|
maxEnumValue = qMax(maxEnumValue, value.range);
|
||||||
minEnumValue = qMin(minEnumValue, value.value);
|
minEnumValue = qMin(minEnumValue, value.value);
|
||||||
@ -382,22 +382,26 @@ Provider parseProvider(const QString &filename)
|
|||||||
value.name = m.captured(1);
|
value.name = m.captured(1);
|
||||||
value.value = m.captured(3).toInt();
|
value.value = m.captured(3).toInt();
|
||||||
value.range = 0;
|
value.range = 0;
|
||||||
currentEnumValue = value.value;
|
currentEnumValue = value.value + 1;
|
||||||
currentEnum.values.push_back(value);
|
currentEnum.values.push_back(value);
|
||||||
maxEnumValue = qMax(maxEnumValue, value.value);
|
maxEnumValue = qMax(maxEnumValue, value.value);
|
||||||
minEnumValue = qMin(minEnumValue, value.value);
|
minEnumValue = qMin(minEnumValue, value.value);
|
||||||
} else {
|
} else {
|
||||||
TraceFlags::FlagValue value;
|
TraceFlags::FlagValue value;
|
||||||
value.name = m.captured(1);
|
value.name = m.captured(1);
|
||||||
value.value = m.captured(3).toInt();
|
if (m.captured(3).startsWith(QStringLiteral("0x")))
|
||||||
|
value.value = m.captured(3).toInt(nullptr, 16);
|
||||||
|
else
|
||||||
|
value.value = m.captured(3).toInt();
|
||||||
if (!isPow2OrZero(value.value)) {
|
if (!isPow2OrZero(value.value)) {
|
||||||
printf("Warning: '%s' line %d:\n"
|
printf("Warning: '%s' line %d:\n"
|
||||||
" '%s' flag value is not power of two.\n",
|
" '%s' flag value is not power of two.\n",
|
||||||
qPrintable(filename), lineNumber,
|
qPrintable(filename), lineNumber,
|
||||||
qPrintable(line));
|
qPrintable(line));
|
||||||
|
} else {
|
||||||
|
value.value = pow2Log2(value.value);
|
||||||
|
currentFlags.values.push_back(value);
|
||||||
}
|
}
|
||||||
value.value = pow2Log2(value.value);
|
|
||||||
currentFlags.values.push_back(value);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
maxEnumValue = qMax(maxEnumValue, currentEnumValue);
|
maxEnumValue = qMax(maxEnumValue, currentEnumValue);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user