27
27
#include " llvm/Support/MemoryBuffer.h"
28
28
#include " llvm/Support/OnDiskHashTable.h"
29
29
#include " llvm/Support/StringSaver.h"
30
- #include " llvm/Support/YAMLParser.h"
31
- #include " llvm/Support/YAMLTraits.h"
32
30
#include " llvm/Support/raw_ostream.h"
33
31
#include < cstdint>
34
32
#include < memory>
@@ -50,14 +48,14 @@ enum LocalizationProducerState : uint8_t {
50
48
FailedInitialization
51
49
};
52
50
53
- class DefToYAMLConverter {
51
+ class DefToStringsConverter {
54
52
llvm::ArrayRef<const char *> IDs;
55
53
llvm::ArrayRef<const char *> Messages;
56
54
57
55
public:
58
- DefToYAMLConverter (llvm::ArrayRef<const char *> ids,
59
- llvm::ArrayRef<const char *> messages)
60
- : IDs(ids), Messages(messages) {
56
+ DefToStringsConverter (llvm::ArrayRef<const char *> ids,
57
+ llvm::ArrayRef<const char *> messages)
58
+ : IDs(ids), Messages(messages) {
61
59
assert (IDs.size () == Messages.size ());
62
60
}
63
61
@@ -181,9 +179,9 @@ class LocalizationProducer {
181
179
llvm::StringRef defaultMessage);
182
180
183
181
// / \returns a `SerializedLocalizationProducer` pointer if the serialized
184
- // / diagnostics file available, otherwise returns a `YAMLLocalizationProducer`
185
- // / if the `YAML ` file is available. If both files aren't available returns a
186
- // / `nullptr`.
182
+ // / diagnostics file available, otherwise returns a
183
+ // / `StringsLocalizationProducer` if the `.strings ` file is available. If both
184
+ // / files aren't available returns a `nullptr`.
187
185
static std::unique_ptr<LocalizationProducer>
188
186
producerFor (llvm::StringRef locale, llvm::StringRef path,
189
187
bool printDiagnosticNames);
@@ -204,15 +202,15 @@ class LocalizationProducer {
204
202
virtual llvm::StringRef getMessage (swift::DiagID id) const = 0;
205
203
};
206
204
207
- class YAMLLocalizationProducer final : public LocalizationProducer {
208
- std::vector<std::string> diagnostics;
205
+ class StringsLocalizationProducer final : public LocalizationProducer {
209
206
std::string filePath;
210
207
208
+ std::vector<std::string> diagnostics;
209
+
211
210
public:
212
- // / The diagnostics IDs that are no longer available in `.def`
213
- std::vector<std::string> unknownIDs;
214
- explicit YAMLLocalizationProducer (llvm::StringRef filePath,
215
- bool printDiagnosticNames = false );
211
+ explicit StringsLocalizationProducer (llvm::StringRef filePath,
212
+ bool printDiagnosticNames = false )
213
+ : LocalizationProducer(printDiagnosticNames), filePath(filePath) {}
216
214
217
215
// / Iterate over all of the available (non-empty) translations
218
216
// / maintained by this producer, callback gets each translation
@@ -223,6 +221,10 @@ class YAMLLocalizationProducer final : public LocalizationProducer {
223
221
protected:
224
222
bool initializeImpl () override ;
225
223
llvm::StringRef getMessage (swift::DiagID id) const override ;
224
+
225
+ private:
226
+ static void readStringsFile (llvm::MemoryBuffer *in,
227
+ std::vector<std::string> &diagnostics);
226
228
};
227
229
228
230
class SerializedLocalizationProducer final : public LocalizationProducer {
@@ -242,32 +244,6 @@ class SerializedLocalizationProducer final : public LocalizationProducer {
242
244
llvm::StringRef getMessage (swift::DiagID id) const override ;
243
245
};
244
246
245
- class LocalizationInput : public llvm ::yaml::Input {
246
- using Input::Input;
247
-
248
- // / Read diagnostics in the YAML file iteratively
249
- template <typename T, typename Context>
250
- friend typename std::enable_if<llvm::yaml::has_SequenceTraits<T>::value,
251
- void >::type
252
- readYAML (llvm::yaml::IO &io, T &Seq, T &unknownIDs, bool , Context &Ctx);
253
-
254
- template <typename T>
255
- friend typename std::enable_if<llvm::yaml::has_SequenceTraits<T>::value,
256
- LocalizationInput &>::type
257
- operator >>(LocalizationInput &yin, T &diagnostics);
258
-
259
- public:
260
- // / A vector that keeps track of the diagnostics IDs that are available in
261
- // / YAML and not available in `.def` files.
262
- std::vector<std::string> unknownIDs;
263
-
264
- // / A diagnostic ID might be present in YAML and not in `.def` file, if that's
265
- // / the case the `id` won't have a `DiagID` value.
266
- // / If the `id` is available in `.def` file this method will return the `id`'s
267
- // / value, otherwise this method won't return a value.
268
- static llvm::Optional<uint32_t > readID (llvm::yaml::IO &io);
269
- };
270
-
271
247
} // namespace diag
272
248
} // namespace swift
273
249
0 commit comments