diff --git a/icu4c/source/tools/icuexportdata/icuexportdata.cpp b/icu4c/source/tools/icuexportdata/icuexportdata.cpp index b0f9fa4e866c..6d10b5bfc44b 100644 --- a/icu4c/source/tools/icuexportdata/icuexportdata.cpp +++ b/icu4c/source/tools/icuexportdata/icuexportdata.cpp @@ -110,9 +110,9 @@ int32_t scxCodePoints[] = { 2386, 2385, 43059, 43060, 43061, 43056, 43057, 43058, 2404, 2405 }; -void handleError(ErrorCode& status, const char* context) { +void handleError(ErrorCode& status, int line, const char* context) { if (status.isFailure()) { - std::cerr << "Error: " << context << ": " << status.errorName() << std::endl; + std::cerr << "Error[" << line << "]: " << context << ": " << status.errorName() << std::endl; exit(status.reset()); } } @@ -159,7 +159,7 @@ void dumpBinaryProperty(UProperty uproperty, FILE* f) { const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME); const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME); const USet* uset = u_getBinaryPropertySet(uproperty, status); - handleError(status, fullPropName); + handleError(status, __LINE__, fullPropName); fputs("[[binary_property]]\n", f); fprintf(f, "long_name = \"%s\"\n", fullPropName); @@ -212,7 +212,7 @@ void dumpEnumeratedProperty(UProperty uproperty, FILE* f) { const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME); const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME); const UCPMap* umap = u_getIntPropertyMap(uproperty, status); - handleError(status, fullPropName); + handleError(status, __LINE__, fullPropName); fputs("[[enum_property]]\n", f); fprintf(f, "long_name = \"%s\"\n", fullPropName); @@ -248,7 +248,7 @@ void dumpEnumeratedProperty(UProperty uproperty, FILE* f) { trieType, width, status)); - handleError(status, fullPropName); + handleError(status, __LINE__, fullPropName); fputs("[enum_property.code_point_trie]\n", f); usrc_writeUCPTrie(f, shortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML); @@ -265,7 +265,7 @@ void dumpBidiMirroringGlyph(FILE* f) { IcuToolErrorCode status("icuexportdata: dumpBidiMirroringGlyph"); const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME); const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME); - handleError(status, fullPropName); + handleError(status, __LINE__, fullPropName); // Store 21-bit code point as is UCPTrieValueWidth width = UCPTRIE_VALUE_BITS_32; @@ -290,7 +290,7 @@ void dumpBidiMirroringGlyph(FILE* f) { trieType, width, status)); - handleError(status, fullPropName); + handleError(status, __LINE__, fullPropName); // currently a trie and inversion map are the same (as relied upon in characterproperties.cpp) const UCPMap* umap = reinterpret_cast(utrie.getAlias()); @@ -372,9 +372,9 @@ void dumpScriptExtensions(FILE* f) { // Create a mutable UCPTrie builder populated with Script property values data. const UCPMap* scInvMap = u_getIntPropertyMap(UCHAR_SCRIPT, status); - handleError(status, scxFullPropName); + handleError(status, __LINE__, scxFullPropName); LocalUMutableCPTriePointer builder(umutablecptrie_fromUCPMap(scInvMap, status)); - handleError(status, scxFullPropName); + handleError(status, __LINE__, scxFullPropName); // The values for the output scx companion array. // Invariant is that all subvectors are distinct. @@ -389,7 +389,7 @@ void dumpScriptExtensions(FILE* f) { const int32_t SCX_ARRAY_CAPACITY = 32; UScriptCode scxValArray[SCX_ARRAY_CAPACITY]; int32_t numScripts = uscript_getScriptExtensions(cp, scxValArray, SCX_ARRAY_CAPACITY, status); - handleError(status, scxFullPropName); + handleError(status, __LINE__, scxFullPropName); // Convert the scx array into a vector std::vector scxValVec; @@ -444,7 +444,7 @@ void dumpScriptExtensions(FILE* f) { // Update the code point in the mutable trie builder with the trie value umutablecptrie_set(builder.getAlias(), cp, newScVal, status); - handleError(status, scxFullPropName); + handleError(status, __LINE__, scxFullPropName); } fputs("]\n\n", f); // Print the TOML close delimiter for the outer array. @@ -454,7 +454,7 @@ void dumpScriptExtensions(FILE* f) { trieType, scWidth, status)); - handleError(status, scxFullPropName); + handleError(status, __LINE__, scxFullPropName); fputs("[script_extensions.code_point_trie]\n", f); usrc_writeUCPTrie(f, scxShortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML); @@ -468,7 +468,7 @@ FILE* prepareOutputFile(const char* basename) { } outFileName.append(basename, status); outFileName.append(".toml", status); - handleError(status, basename); + handleError(status, __LINE__, basename); FILE* f = fopen(outFileName.data(), "w"); if (f == nullptr) { @@ -527,7 +527,7 @@ void writeCanonicalCompositions(USet* backwardCombiningStarters) { } if (c != composite) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (!u_getCombiningClass(second)) { uset_add(backwardCombiningStarters, second); @@ -547,7 +547,7 @@ void writeCanonicalCompositions(USet* backwardCombiningStarters) { usrc_writeArray(f, "compositions = [\n ", canonicalCompositionTrie.getBuffer(), 16, canonicalCompositionTrie.length(), " ", "\n]\n"); fclose(f); - handleError(status, basename); + handleError(status, __LINE__, basename); } void writeDecompositionTables(const char* basename, const uint16_t* ptr16, size_t len16, const uint32_t* ptr32, size_t len32) { @@ -593,7 +593,7 @@ void writeDecompositionData(const char* basename, uint32_t baseSize16, uint32_t } if (offset + additional > 0xFFF) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } } // It turns out it's better to swap the halves compared to the initial @@ -611,14 +611,14 @@ void writeDecompositionData(const char* basename, uint32_t baseSize16, uint32_t trieType, UCPTRIE_VALUE_BITS_32, status)); - handleError(status, basename); + handleError(status, __LINE__, basename); if (reference) { if (uset_contains(reference, 0xFF9E) || uset_contains(reference, 0xFF9F) || !uset_contains(reference, 0x0345)) { // NFD expectations don't hold. The set must not contain the half-width // kana voicing marks and must contain iota subscript. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } USet* halfWidthVoicing = uset_openEmpty(); @@ -639,7 +639,7 @@ void writeDecompositionData(const char* basename, uint32_t baseSize16, uint32_t // the two half-width voicing marks. The ICU4X // normalizer doesn't know how to deal with this case. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } uset_close(halfWidthCheck); @@ -650,7 +650,7 @@ void writeDecompositionData(const char* basename, uint32_t baseSize16, uint32_t // the iota subscript. The ICU4X normalizer doesn't // know how to deal with this case. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } uset_close(iotaSubscript); @@ -662,7 +662,7 @@ void writeDecompositionData(const char* basename, uint32_t baseSize16, uint32_t fprintf(f, "[trie]\n"); usrc_writeUCPTrie(f, "trie", utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML); fclose(f); - handleError(status, basename); + handleError(status, __LINE__, basename); } // Special marker for the NFKD form of U+FDFA @@ -840,18 +840,18 @@ void computeDecompositions(const char* basename, // normalization step. if (uprv_strcmp(basename, "uts46d") != 0) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } nfdNormalizer->normalize(src, dst, status); len = dst.toUTF32(utf32, DECOMPOSITION_BUFFER_SIZE, status); if (!len || (len == 1 && utf32[0] == 0xFFFD && c != 0xFFFD)) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } } if (len > DECOMPOSITION_BUFFER_SIZE) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } uint8_t firstCombiningClass = u_getCombiningClass(utf32[0]); bool specialNonStarterDecomposition = false; @@ -866,7 +866,7 @@ void computeDecompositions(const char* basename, } else { // A character whose decomposition starts with a non-starter and isn't the same as the character itself and isn't already hard-coded into ICU4X. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } } } else if (uset_contains(backwardCombiningStarters, utf32[0])) { @@ -876,15 +876,15 @@ void computeDecompositions(const char* basename, } if (c != BACKWARD_COMBINING_STARTER_MARKER && len == 1 && utf32[0] == BACKWARD_COMBINING_STARTER_MARKER) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (c != SPECIAL_NON_STARTER_DECOMPOSITION_MARKER && len == 1 && utf32[0] == SPECIAL_NON_STARTER_DECOMPOSITION_MARKER) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (c != FDFA_MARKER && len == 1 && utf32[0] == FDFA_MARKER) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (mainNormalizer != nfdNormalizer) { UnicodeString nfd; @@ -917,7 +917,7 @@ void computeDecompositions(const char* basename, // We're always supposed to have a non-recursive decomposition // if we had a recursive one. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } // In addition to actual difference, put the whole range that contains characters // with oxia into the non-recursive trie in order to catch cases where characters @@ -928,18 +928,18 @@ void computeDecompositions(const char* basename, int32_t rawLen = raw.toUTF32(rawUtf32, RAW_DECOMPOSITION_BUFFER_SIZE, status); if (!rawLen) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (rawLen == 1) { if (c >= 0xFFFF) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } umutablecptrie_set(nonRecursiveBuilder.getAlias(), c, uint32_t(rawUtf32[0]), status); } else if (rawUtf32[0] <= 0xFFFF && rawUtf32[1] <= 0xFFFF) { if (!rawUtf32[0] || !rawUtf32[1]) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } // Swapped for consistency with the primary trie uint32_t bmpPair = uint32_t(rawUtf32[1]) << 16 | uint32_t(rawUtf32[0]); @@ -952,7 +952,7 @@ void computeDecompositions(const char* basename, nonRecursive32.push_back(uint32_t(rawUtf32[1])); if (index > 0xFFFF) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } umutablecptrie_set(nonRecursiveBuilder.getAlias(), c, index << 16, status); } @@ -967,7 +967,7 @@ void computeDecompositions(const char* basename, if (mainNormalizer == nfdNormalizer) { // Not supposed to happen in NFD status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } pendingTrieInsertions.push_back({c, uint32_t(utf32[0]) << 16, false}); } else if (!startsWithBackwardCombiningStarter && len == 1 && utf32[0] <= 0xFFFF) { @@ -984,7 +984,7 @@ void computeDecompositions(const char* basename, // Assert that iota subscript and half-width voicing marks never occur in these // expansions in the normalization forms where they are special. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } } pendingTrieInsertions.push_back({c, (uint32_t(utf32[0]) << 16) | uint32_t(utf32[1]), false}); @@ -996,7 +996,7 @@ void computeDecompositions(const char* basename, // Assert that iota subscript and half-width voicing marks never occur in these // expansions in the normalization forms where they are special. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (utf32[i] > 0xFFFF) { @@ -1004,7 +1004,7 @@ void computeDecompositions(const char* basename, } if (utf32[i] == 0) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } if (i != 0 && !u_getCombiningClass(utf32[i])) { nonInitialStarter = true; @@ -1026,12 +1026,12 @@ void computeDecompositions(const char* basename, continue; } else { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } } } else if (len > LONGEST_ENCODABLE_LENGTH_32 || !len) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } // Complex decomposition // Format for 16-bit value: @@ -1057,7 +1057,7 @@ void computeDecompositions(const char* basename, } if (descriptor & 0xFFF) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } size_t index = 0; if (!supplementary) { @@ -1067,14 +1067,14 @@ void computeDecompositions(const char* basename, } if (index > 0xFFF) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } descriptor |= uint32_t(index); if (!descriptor || descriptor > 0xFFFF) { // > 0xFFFF should never happen if the code above is correct. // == 0 should not happen due to the nature of the data. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, basename); + handleError(status, __LINE__, basename); } uint32_t nonRoundTripMarker = 0; if (!nonNfdOrRoundTrips) { @@ -1098,14 +1098,14 @@ void computeDecompositions(const char* basename, trieType, UCPTRIE_VALUE_BITS_32, status)); - handleError(status, basename); + handleError(status, __LINE__, basename); fprintf(f, "[trie]\n"); usrc_writeUCPTrie(f, "trie", utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML); fclose(f); } - handleError(status, basename); + handleError(status, __LINE__, basename); } #endif // !UCONFIG_NO_NORMALIZATION @@ -1302,7 +1302,7 @@ addRangeToUCPTrie(const void* context, UChar32 start, UChar32 end, uint32_t valu IcuToolErrorCode status("addRangeToUCPTrie"); UMutableCPTrie* ucptrie = ((const AddRangeHelper*) context)->ucptrie; umutablecptrie_setRange(ucptrie, start, end, value, status); - handleError(status, "setRange"); + handleError(status, __LINE__, "setRange"); return true; } @@ -1316,7 +1316,7 @@ int exportCase(int argc, char* argv[]) { IcuToolErrorCode status("icuexportdata"); LocalUMutableCPTriePointer builder(umutablecptrie_open(0, 0, status)); - handleError(status, "exportCase"); + handleError(status, __LINE__, "exportCase"); int32_t exceptionsLength, unfoldLength; const UCaseProps *caseProps = ucase_getSingleton(&exceptionsLength, &unfoldLength); @@ -1331,7 +1331,7 @@ int exportCase(int argc, char* argv[]) { trieType, width, status)); - handleError(status, "exportCase"); + handleError(status, __LINE__, "exportCase"); FILE* f = prepareOutputFile("ucase"); @@ -1395,7 +1395,7 @@ int exportNorm() { if (!(nfdBound == 0xC0 && nfcBound == 0x300)) { // Unexpected bounds for NFD/NFC. status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } uint32_t baseSize16 = storage16.size(); @@ -1417,17 +1417,17 @@ int exportNorm() { nfkcBound); if (!(nfkdBound <= 0xC0 && nfkcBound <= 0x300)) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } if (nfkcBound > 0xC0) { if (nfkdBound != 0xC0) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } } else { if (nfkdBound != nfkcBound) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } } @@ -1447,17 +1447,17 @@ int exportNorm() { uts46Bound); if (!(uts46dBound <= 0xC0 && uts46Bound <= 0x300)) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } if (uts46Bound > 0xC0) { if (uts46dBound != 0xC0) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } } else { if (uts46dBound != uts46Bound) { status.set(U_INTERNAL_PROGRAM_ERROR); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); } } @@ -1480,7 +1480,7 @@ int exportNorm() { uset_close(uts46DecompositionStartsWithBackwardCombiningStarter); uset_close(backwardCombiningStarters); - handleError(status, "exportNorm"); + handleError(status, __LINE__, "exportNorm"); return 0; }