Skip to content

Commit 8d8da1b

Browse files
committed
[Localization] Adjust types associated with reader/writer info
Add more usages of `offset_type` where appropriate and change buffer type to `const unsigned char *`.
1 parent 8a1b620 commit 8d8da1b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

include/swift/AST/LocalizationFormat.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class LocalizationWriterInfo {
4545

4646
hash_value_type ComputeHash(key_type_ref key) { return llvm::djbHash(key); }
4747

48-
std::pair<unsigned, unsigned> EmitKeyDataLength(llvm::raw_ostream &out,
49-
key_type_ref key,
50-
data_type_ref data) {
48+
std::pair<offset_type, offset_type> EmitKeyDataLength(llvm::raw_ostream &out,
49+
key_type_ref key,
50+
data_type_ref data) {
5151
offset_type keyLength = static_cast<offset_type>(key.size());
5252
offset_type dataLength = static_cast<offset_type>(data.size());
5353
endian::write<offset_type>(out, keyLength, little);
@@ -85,19 +85,20 @@ class LocalizationReaderInfo {
8585
return llvm::djbHash(key);
8686
}
8787

88-
static std::pair<unsigned, unsigned> ReadKeyDataLength(const uint8_t *&data) {
88+
static std::pair<offset_type, offset_type>
89+
ReadKeyDataLength(const unsigned char *&data) {
8990
offset_type keyLength =
9091
endian::readNext<offset_type, little, unaligned>(data);
9192
offset_type dataLength =
9293
endian::readNext<offset_type, little, unaligned>(data);
9394
return {keyLength, dataLength};
9495
}
9596

96-
internal_key_type ReadKey(const uint8_t *data, offset_type length) {
97+
internal_key_type ReadKey(const unsigned char *data, offset_type length) {
9798
return internal_key_type((const char *)data, length);
9899
}
99100

100-
data_type ReadData(llvm::StringRef Key, const uint8_t *data,
101+
data_type ReadData(llvm::StringRef Key, const unsigned char *data,
101102
offset_type length) {
102103
return data_type((const char *)data, length);
103104
}

lib/AST/LocalizationFormat.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ bool SerializedLocalizationWriter::emit(llvm::StringRef filePath) {
101101
SerializedLocalizationProducer::SerializedLocalizationProducer(
102102
std::unique_ptr<llvm::MemoryBuffer> buffer)
103103
: Buffer(std::move(buffer)) {
104-
auto base = reinterpret_cast<const uint8_t *>(Buffer.get()->getBufferStart());
104+
auto base =
105+
reinterpret_cast<const unsigned char *>(Buffer.get()->getBufferStart());
105106
auto tableOffset = endian::read<offset_type>(base, little);
106107
SerializedTable.reset(SerializedLocalizationTable::Create(
107108
base + tableOffset, base + sizeof(offset_type), base));

localization/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ add_custom_command(
88

99
add_custom_command(
1010
TARGET diagnostic-translation-database
11-
COMMAND swift-serialize-diagnostics --input-file-path="${SWIFT_BINARY_DIR}/share/swift/diagnostics/en.yaml" --output-directory="${SWIFT_BINARY_DIR}/share/swift/diagnostics/")
11+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
12+
COMMAND swift-serialize-diagnostics
13+
--input-file-path diagnostics/en.yaml
14+
--output-directory ${SWIFT_BINARY_DIR}/share/swift/diagnostics)
1215

1316
add_dependencies(swift-frontend diagnostic-translation-database)
1417

0 commit comments

Comments
 (0)