|
11 | 11 |
|
12 | 12 | using namespace llvm; |
13 | 13 |
|
14 | | -llvm::TextEncodingConverter * |
15 | | -LiteralConverter::getConverter(const char *Codepage) { |
16 | | - auto Iter = TextEncodingConverters.find(Codepage); |
17 | | - if (Iter != TextEncodingConverters.end()) |
18 | | - return &Iter->second; |
19 | | - return nullptr; |
20 | | -} |
21 | | - |
22 | 14 | llvm::TextEncodingConverter * |
23 | 15 | LiteralConverter::getConverter(ConversionAction Action) { |
24 | | - StringRef CodePage; |
25 | | - if (Action == ToSystemCharset) |
26 | | - CodePage = SystemCharset; |
27 | | - else if (Action == ToExecCharset) |
28 | | - CodePage = ExecCharset; |
| 16 | + if (Action == ToSystemEncoding) |
| 17 | + return ToSystemEncodingConverter; |
| 18 | + else if (Action == ToExecEncoding) |
| 19 | + return ToExecEncodingConverter; |
29 | 20 | else |
30 | | - CodePage = InternalCharset; |
31 | | - return getConverter(CodePage.data()); |
32 | | -} |
33 | | - |
34 | | -llvm::TextEncodingConverter * |
35 | | -LiteralConverter::createAndInsertCharConverter(const char *To) { |
36 | | - const char *From = InternalCharset.data(); |
37 | | - llvm::TextEncodingConverter *Converter = getConverter(To); |
38 | | - if (Converter) |
39 | | - return Converter; |
40 | | - |
41 | | - ErrorOr<TextEncodingConverter> ErrorOrConverter = |
42 | | - llvm::TextEncodingConverter::create(From, To); |
43 | | - if (!ErrorOrConverter) |
44 | 21 | return nullptr; |
45 | | - TextEncodingConverters.insert_or_assign(StringRef(To), |
46 | | - std::move(*ErrorOrConverter)); |
47 | | - return getConverter(To); |
48 | 22 | } |
49 | 23 |
|
50 | 24 | void LiteralConverter::setConvertersFromOptions( |
51 | 25 | const clang::LangOptions &Opts, const clang::TargetInfo &TInfo, |
52 | 26 | clang::DiagnosticsEngine &Diags) { |
53 | 27 | using namespace llvm; |
54 | | - SystemCharset = TInfo.getTriple().getSystemCharset(); |
55 | | - InternalCharset = "UTF-8"; |
56 | | - ExecCharset = Opts.ExecCharset.empty() ? InternalCharset : Opts.ExecCharset; |
57 | | - // Create converter between internal and system charset |
58 | | - if (InternalCharset != SystemCharset) |
59 | | - createAndInsertCharConverter(SystemCharset.data()); |
| 28 | + InternalEncoding = "UTF-8"; |
| 29 | + SystemEncoding = TInfo.getTriple().getDefaultTextEncoding(); |
| 30 | + ExecEncoding = |
| 31 | + Opts.ExecEncoding.empty() ? InternalEncoding : Opts.ExecEncoding; |
| 32 | + // Create converter between internal and system encoding |
| 33 | + if (InternalEncoding != SystemEncoding) { |
| 34 | + ErrorOr<TextEncodingConverter> ErrorOrConverter = |
| 35 | + llvm::TextEncodingConverter::create(InternalEncoding, SystemEncoding); |
| 36 | + if (!ErrorOrConverter) |
| 37 | + return; |
| 38 | + ToSystemEncodingConverter = |
| 39 | + new TextEncodingConverter(std::move(*ErrorOrConverter)); |
| 40 | + } |
60 | 41 |
|
61 | | - // Create converter between internal and exec charset specified |
| 42 | + // Create converter between internal and exec encoding specified |
62 | 43 | // in fexec-charset option. |
63 | | - if (InternalCharset == ExecCharset) |
| 44 | + if (InternalEncoding == ExecEncoding) |
64 | 45 | return; |
65 | | - if (!createAndInsertCharConverter(ExecCharset.data())) { |
| 46 | + ErrorOr<TextEncodingConverter> ErrorOrConverter = |
| 47 | + llvm::TextEncodingConverter::create(InternalEncoding, ExecEncoding); |
| 48 | + if (!ErrorOrConverter) |
66 | 49 | Diags.Report(clang::diag::err_drv_invalid_value) |
67 | | - << "-fexec-charset" << ExecCharset; |
68 | | - } |
| 50 | + << "-fexec-charset" << ExecEncoding; |
| 51 | + ToExecEncodingConverter = |
| 52 | + new TextEncodingConverter(std::move(*ErrorOrConverter)); |
69 | 53 | } |
0 commit comments