QUnicodeTables generator: Minor clean-up & stricter checks

Use static_cast instead of C-style cast;
ushort -> unsigned short;
Avoid a lvalue in qGetProp();
Minor styling fixes.

Change-Id: Ic6412e28ac9316a587d32d0e674d21f672967fd6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Konstantin Ritt 2015-11-07 00:31:43 +04:00
parent 0f336e8565
commit 3a3e2193d7
2 changed files with 66 additions and 71 deletions

View File

@ -40,7 +40,7 @@ QT_BEGIN_NAMESPACE
namespace QUnicodeTables {
static const unsigned short uc_property_trie[] = {
// 0 - 0x11000
// [0x0..0x11000)
6256, 6288, 6320, 6352, 6384, 6416, 6448, 6480,
6512, 6544, 6576, 6608, 6640, 6672, 6704, 6736,
@ -331,7 +331,7 @@ static const unsigned short uc_property_trie[] = {
8400, 8400, 8400, 23088, 8400, 8400, 8400, 8400,
8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400,
// 0x11000 - 0x110000
// [0x11000..0x110000)
23120, 23376, 23632, 23888, 24144, 24400, 24656, 24912,
25168, 25424, 25680, 25424, 25424, 25424, 25424, 25424,
@ -5738,7 +5738,7 @@ static const unsigned short uc_property_trie[] = {
2494, 2494, 2494, 2494, 2494, 2494, 2494, 2494,
2494, 2494, 2494, 2494, 2494, 2494, 2494, 2494,
2494, 2494, 2494, 2494, 2494, 2494, 2494, 2494,
2494, 2494, 2494, 2494, 2494, 2494, 2489, 2489,
2494, 2494, 2494, 2494, 2494, 2494, 2489, 2489
};
#define GET_PROP_INDEX(ucs4) \
@ -8249,14 +8249,12 @@ static const Properties uc_properties[] = {
Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX(ucs4);
return uc_properties + index;
return uc_properties + GET_PROP_INDEX(ucs4);
}
Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX_UCS2(ucs2);
return uc_properties + index;
return uc_properties + GET_PROP_INDEX_UCS2(ucs2);
}
Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW
@ -8271,26 +8269,26 @@ Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(us
Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (GraphemeBreakClass)qGetProp(ucs4)->graphemeBreakClass;
return static_cast<GraphemeBreakClass>(qGetProp(ucs4)->graphemeBreakClass);
}
Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (WordBreakClass)qGetProp(ucs4)->wordBreakClass;
return static_cast<WordBreakClass>(qGetProp(ucs4)->wordBreakClass);
}
Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (SentenceBreakClass)qGetProp(ucs4)->sentenceBreakClass;
return static_cast<SentenceBreakClass>(qGetProp(ucs4)->sentenceBreakClass);
}
Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (LineBreakClass)qGetProp(ucs4)->lineBreakClass;
return static_cast<LineBreakClass>(qGetProp(ucs4)->lineBreakClass);
}
static const ushort specialCaseMap[] = {
static const unsigned short specialCaseMap[] = {
0x0, // placeholder
0x1, 0x2c65,
0x1, 0x2c66,
@ -10407,8 +10405,8 @@ static const unsigned short uc_decomposition_trie[] = {
#define GET_DECOMPOSITION_INDEX(ucs4) \
(ucs4 < 0x3400 \
? (uc_decomposition_trie[uc_decomposition_trie[ucs4>>4] + (ucs4 & 0xf)]) \
: (ucs4 < 0x30000\
? uc_decomposition_trie[uc_decomposition_trie[((ucs4 - 0x3400)>>8) + 0x340] + (ucs4 & 0xff)]\
: (ucs4 < 0x30000 \
? uc_decomposition_trie[uc_decomposition_trie[((ucs4 - 0x3400)>>8) + 0x340] + (ucs4 & 0xff)] \
: 0xffff))
static const unsigned short uc_decomposition_map[] = {
@ -12608,8 +12606,8 @@ static const unsigned short uc_ligature_trie[] = {
#define GET_LIGATURE_INDEX(ucs4) \
(ucs4 < 0x3100 \
? (uc_ligature_trie[uc_ligature_trie[ucs4>>5] + (ucs4 & 0x1f)]) \
: (ucs4 < 0x12000\
? uc_ligature_trie[uc_ligature_trie[((ucs4 - 0x3100)>>8) + 0x188] + (ucs4 & 0xff)]\
: (ucs4 < 0x12000 \
? uc_ligature_trie[uc_ligature_trie[((ucs4 - 0x3100)>>8) + 0x188] + (ucs4 & 0xff)] \
: 0xffff))
static const unsigned short uc_ligature_map[] = {
@ -12874,7 +12872,7 @@ static const NormalizationCorrection uc_normalization_corrections[] = {
{ 0x2f874, 0x5f33, 7 },
{ 0x2f91f, 0x43ab, 7 },
{ 0x2f95f, 0x7aae, 7 },
{ 0x2f9bf, 0x4d57, 7 },
{ 0x2f9bf, 0x4d57, 7 }
};
enum { NumNormalizationCorrections = 6 };

View File

@ -848,12 +848,14 @@ static int appendToSpecialCaseMap(const QList<int> &map)
{
QList<int> utf16map;
for (int i = 0; i < map.size(); ++i) {
int val = map.at(i);
if (QChar::requiresSurrogates(val)) {
utf16map << QChar::highSurrogate(val);
utf16map << QChar::lowSurrogate(val);
uint codepoint = map.at(i);
// if the condition below doesn't hold anymore we need to modify our special case mapping code
Q_ASSERT(!QChar::requiresSurrogates(codepoint));
if (QChar::requiresSurrogates(codepoint)) {
utf16map << QChar::highSurrogate(codepoint);
utf16map << QChar::lowSurrogate(codepoint);
} else {
utf16map << val;
utf16map << codepoint;
}
}
int length = utf16map.size();
@ -1133,41 +1135,39 @@ static void readUnicodeData()
int upperCase = properties[UD_UpperCase].toInt(&ok, 16);
Q_ASSERT(ok);
int diff = upperCase - codepoint;
// if the conditions below doesn't hold anymore we need to modify our upper casing code
Q_ASSERT(QChar::requiresSurrogates(codepoint) == QChar::requiresSurrogates(upperCase));
if (QChar::requiresSurrogates(codepoint)) {
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(upperCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(upperCase));
}
if (qAbs(diff) >= (1<<13)) {
qWarning() << "upperCaseDiff exceeded (" << hex << codepoint << "->" << upperCase << "); map it for special case";
// if the condition below doesn't hold anymore we need to modify our special upper casing code in qchar.cpp
Q_ASSERT(!QChar::requiresSurrogates(codepoint) && !QChar::requiresSurrogates(upperCase));
data.p.upperCaseSpecial = true;
data.p.upperCaseDiff = appendToSpecialCaseMap(QList<int>() << upperCase);
} else {
data.p.upperCaseDiff = diff;
maxUpperCaseDiff = qMax(maxUpperCaseDiff, qAbs(diff));
}
if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(upperCase)) {
// if the conditions below doesn't hold anymore we need to modify our upper casing code
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(upperCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(upperCase));
}
}
if (!properties[UD_LowerCase].isEmpty()) {
int lowerCase = properties[UD_LowerCase].toInt(&ok, 16);
Q_ASSERT(ok);
int diff = lowerCase - codepoint;
// if the conditions below doesn't hold anymore we need to modify our lower casing code
Q_ASSERT(QChar::requiresSurrogates(codepoint) == QChar::requiresSurrogates(lowerCase));
if (QChar::requiresSurrogates(codepoint)) {
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(lowerCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(lowerCase));
}
if (qAbs(diff) >= (1<<13)) {
qWarning() << "lowerCaseDiff exceeded (" << hex << codepoint << "->" << lowerCase << "); map it for special case";
// if the condition below doesn't hold anymore we need to modify our special lower casing code in qchar.cpp
Q_ASSERT(!QChar::requiresSurrogates(codepoint) && !QChar::requiresSurrogates(lowerCase));
data.p.lowerCaseSpecial = true;
data.p.lowerCaseDiff = appendToSpecialCaseMap(QList<int>() << lowerCase);
} else {
data.p.lowerCaseDiff = diff;
maxLowerCaseDiff = qMax(maxLowerCaseDiff, qAbs(diff));
}
if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(lowerCase)) {
// if the conditions below doesn't hold anymore we need to modify our lower casing code
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(lowerCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(lowerCase));
}
}
// we want toTitleCase to map to ToUpper in case we don't have any titlecase.
if (properties[UD_TitleCase].isEmpty())
@ -1176,21 +1176,20 @@ static void readUnicodeData()
int titleCase = properties[UD_TitleCase].toInt(&ok, 16);
Q_ASSERT(ok);
int diff = titleCase - codepoint;
// if the conditions below doesn't hold anymore we need to modify our title casing code
Q_ASSERT(QChar::requiresSurrogates(codepoint) == QChar::requiresSurrogates(titleCase));
if (QChar::requiresSurrogates(codepoint)) {
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(titleCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(titleCase));
}
if (qAbs(diff) >= (1<<13)) {
qWarning() << "titleCaseDiff exceeded (" << hex << codepoint << "->" << titleCase << "); map it for special case";
// if the condition below doesn't hold anymore we need to modify our special title casing code in qchar.cpp
Q_ASSERT(!QChar::requiresSurrogates(codepoint) && !QChar::requiresSurrogates(titleCase));
data.p.titleCaseSpecial = true;
data.p.titleCaseDiff = appendToSpecialCaseMap(QList<int>() << titleCase);
} else {
data.p.titleCaseDiff = diff;
maxTitleCaseDiff = qMax(maxTitleCaseDiff, qAbs(diff));
}
if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(titleCase)) {
// if the conditions below doesn't hold anymore we need to modify our title casing code
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(titleCase));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(titleCase));
}
}
if (!properties[UD_DigitValue].isEmpty())
@ -1546,8 +1545,10 @@ static QByteArray createNormalizationCorrections()
++numCorrections;
maxVersion = qMax(c.version, maxVersion);
}
if (out.endsWith(",\n"))
out.chop(2);
out += "};\n\n"
out += "\n};\n\n"
"enum { NumNormalizationCorrections = " + QByteArray::number(numCorrections) + " };\n"
"enum { NormalizationCorrectionsVersionMax = " + QByteArray::number(maxVersion) + " };\n\n";
@ -1742,23 +1743,20 @@ static void readCaseFolding()
if (foldMap.size() == 1) {
int caseFolded = foldMap.at(0);
int diff = caseFolded - codepoint;
// if the conditions below doesn't hold anymore we need to modify our case folding code
Q_ASSERT(QChar::requiresSurrogates(codepoint) == QChar::requiresSurrogates(caseFolded));
if (QChar::requiresSurrogates(codepoint)) {
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(caseFolded));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(caseFolded));
}
if (qAbs(diff) >= (1<<13)) {
qWarning() << "caseFoldDiff exceeded (" << hex << codepoint << "->" << caseFolded << "); map it for special case";
// if the condition below doesn't hold anymore we need to modify our special case folding code in qchar.cpp
Q_ASSERT(!QChar::requiresSurrogates(codepoint) && !QChar::requiresSurrogates(caseFolded));
ud.p.caseFoldSpecial = true;
ud.p.caseFoldDiff = appendToSpecialCaseMap(foldMap);
} else {
ud.p.caseFoldDiff = diff;
maxCaseFoldDiff = qMax(maxCaseFoldDiff, qAbs(diff));
}
if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(caseFolded)) {
// if the conditions below doesn't hold anymore we need to modify our case folding code
Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(caseFolded));
Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(caseFolded));
}
// if (caseFolded != codepoint + ud.p.lowerCaseDiff)
// qDebug() << hex << codepoint;
} else {
qFatal("we currently don't support full case foldings");
// qDebug() << "special" << hex << foldMap;
@ -2301,7 +2299,7 @@ static QByteArray createPropertyInfo()
out += "static const unsigned short uc_property_trie[] = {\n";
// first write the map
out += " // 0 - 0x" + QByteArray::number(BMP_END, 16);
out += " // [0x0..0x" + QByteArray::number(BMP_END, 16) + ")";
for (int i = 0; i < BMP_END/BMP_BLOCKSIZE; ++i) {
if (!(i % 8)) {
if (out.endsWith(' '))
@ -2315,7 +2313,7 @@ static QByteArray createPropertyInfo()
}
if (out.endsWith(' '))
out.chop(1);
out += "\n\n // 0x" + QByteArray::number(BMP_END, 16) + " - 0x" + QByteArray::number(SMP_END, 16) + "\n";
out += "\n\n // [0x" + QByteArray::number(BMP_END, 16) + "..0x" + QByteArray::number(SMP_END, 16) + ")\n";
for (int i = BMP_END/BMP_BLOCKSIZE; i < blockMap.size(); ++i) {
if (!(i % 8)) {
if (out.endsWith(' '))
@ -2346,8 +2344,8 @@ static QByteArray createPropertyInfo()
out += ", ";
}
}
if (out.endsWith(' '))
out.chop(1);
if (out.endsWith(", "))
out.chop(2);
out += "\n};\n\n";
out += "#define GET_PROP_INDEX(ucs4) \\\n"
@ -2430,20 +2428,19 @@ static QByteArray createPropertyInfo()
out += QByteArray::number( p.script );
out += " },";
}
out.chop(1);
if (out.endsWith(','))
out.chop(1);
out += "\n};\n\n";
out += "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) Q_DECL_NOTHROW\n"
"{\n"
" const int index = GET_PROP_INDEX(ucs4);\n"
" return uc_properties + index;\n"
" return uc_properties + GET_PROP_INDEX(ucs4);\n"
"}\n"
"\n"
"Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) Q_DECL_NOTHROW\n"
"{\n"
" const int index = GET_PROP_INDEX_UCS2(ucs2);\n"
" return uc_properties + index;\n"
" return uc_properties + GET_PROP_INDEX_UCS2(ucs2);\n"
"}\n"
"\n"
"Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW\n"
@ -2458,22 +2455,22 @@ static QByteArray createPropertyInfo()
out += "Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW\n"
"{\n"
" return (GraphemeBreakClass)qGetProp(ucs4)->graphemeBreakClass;\n"
" return static_cast<GraphemeBreakClass>(qGetProp(ucs4)->graphemeBreakClass);\n"
"}\n"
"\n"
"Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW\n"
"{\n"
" return (WordBreakClass)qGetProp(ucs4)->wordBreakClass;\n"
" return static_cast<WordBreakClass>(qGetProp(ucs4)->wordBreakClass);\n"
"}\n"
"\n"
"Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW\n"
"{\n"
" return (SentenceBreakClass)qGetProp(ucs4)->sentenceBreakClass;\n"
" return static_cast<SentenceBreakClass>(qGetProp(ucs4)->sentenceBreakClass);\n"
"}\n"
"\n"
"Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW\n"
"{\n"
" return (LineBreakClass)qGetProp(ucs4)->lineBreakClass;\n"
" return static_cast<LineBreakClass>(qGetProp(ucs4)->lineBreakClass);\n"
"}\n"
"\n";
@ -2486,7 +2483,7 @@ static QByteArray createSpecialCaseMap()
QByteArray out;
out += "static const ushort specialCaseMap[] = {\n"
out += "static const unsigned short specialCaseMap[] = {\n"
" 0x0, // placeholder";
int i = 1;
while (i < specialCaseMap.size()) {
@ -2686,10 +2683,10 @@ static QByteArray createCompositionInfo()
" (ucs4 < 0x" + QByteArray::number(BMP_END, 16) + " \\\n"
" ? (uc_decomposition_trie[uc_decomposition_trie[ucs4>>" + QByteArray::number(BMP_SHIFT) +
"] + (ucs4 & 0x" + QByteArray::number(BMP_BLOCKSIZE-1, 16)+ ")]) \\\n"
" : (ucs4 < 0x" + QByteArray::number(SMP_END, 16) + "\\\n"
" : (ucs4 < 0x" + QByteArray::number(SMP_END, 16) + " \\\n"
" ? uc_decomposition_trie[uc_decomposition_trie[((ucs4 - 0x" + QByteArray::number(BMP_END, 16) +
")>>" + QByteArray::number(SMP_SHIFT) + ") + 0x" + QByteArray::number(BMP_END/BMP_BLOCKSIZE, 16) + "]"
" + (ucs4 & 0x" + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")]\\\n"
" + (ucs4 & 0x" + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")] \\\n"
" : 0xffff))\n\n";
out += "static const unsigned short uc_decomposition_map[] = {";
@ -2885,10 +2882,10 @@ static QByteArray createLigatureInfo()
" (ucs4 < 0x" + QByteArray::number(BMP_END, 16) + " \\\n"
" ? (uc_ligature_trie[uc_ligature_trie[ucs4>>" + QByteArray::number(BMP_SHIFT) +
"] + (ucs4 & 0x" + QByteArray::number(BMP_BLOCKSIZE-1, 16)+ ")]) \\\n"
" : (ucs4 < 0x" + QByteArray::number(SMP_END, 16) + "\\\n"
" : (ucs4 < 0x" + QByteArray::number(SMP_END, 16) + " \\\n"
" ? uc_ligature_trie[uc_ligature_trie[((ucs4 - 0x" + QByteArray::number(BMP_END, 16) +
")>>" + QByteArray::number(SMP_SHIFT) + ") + 0x" + QByteArray::number(BMP_END/BMP_BLOCKSIZE, 16) + "]"
" + (ucs4 & 0x" + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")]\\\n"
" + (ucs4 & 0x" + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")] \\\n"
" : 0xffff))\n\n";
out += "static const unsigned short uc_ligature_map[] = {";