[flang] Another attempt to fix bug flang-compiler/f18#877
Original-commit: flang-compiler/f18@2ad2330cda Reviewed-on: https://github.com/flang-compiler/f18/pull/906
This commit is contained in:
parent
0922083181
commit
39114d503a
|
@ -15,6 +15,8 @@
|
|||
|
||||
namespace Fortran::parser {
|
||||
|
||||
bool useHexadecimalEscapeSequences{false};
|
||||
|
||||
int UTF_8CharacterBytes(const char *p) {
|
||||
if ((*p & 0x80) == 0) {
|
||||
return 1;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
namespace Fortran::parser {
|
||||
|
||||
extern bool useHexadecimalEscapeSequences;
|
||||
|
||||
// We can easily support Fortran program source in any character
|
||||
// set whose first 128 code points correspond to ASCII codes 0-127 (ISO/IEC646).
|
||||
// The specific encodings that we can handle include:
|
||||
|
@ -155,27 +157,37 @@ extern template std::string EncodeString<Encoding::UTF_8, std::u32string>(
|
|||
template<typename NORMAL, typename INSERTED>
|
||||
void EmitQuotedChar(char32_t ch, const NORMAL &emit, const INSERTED &insert,
|
||||
bool backslashEscapes = true, Encoding encoding = Encoding::UTF_8) {
|
||||
auto emitOneChar{[&](std::uint8_t ch) {
|
||||
if (ch < ' ' || (backslashEscapes && (ch == '\\' || ch >= 0x7f))) {
|
||||
insert('\\');
|
||||
auto emitOneByte{[&](std::uint8_t ch) {
|
||||
if (backslashEscapes && (ch < ' ' || ch >= 0x7f || ch == '\\')) {
|
||||
if (std::optional<char> escape{BackslashEscapeChar(ch)}) {
|
||||
insert('\\');
|
||||
emit(*escape);
|
||||
} else if (useHexadecimalEscapeSequences) {
|
||||
insert('\\');
|
||||
insert('x');
|
||||
int top{ch >> 4}, bottom{ch & 0xf};
|
||||
insert(top > 9 ? 'a' + top - 10 : '0' + top);
|
||||
insert(bottom > 9 ? 'a' + bottom - 10 : '0' + bottom);
|
||||
} else {
|
||||
// octal escape sequence; always emit 3 digits to avoid ambiguity
|
||||
insert('\\');
|
||||
insert('0' + (ch >> 6));
|
||||
insert('0' + ((ch >> 3) & 7));
|
||||
insert('0' + (ch & 7));
|
||||
}
|
||||
} else if (ch == '\n') { // always escape newlines
|
||||
insert('\\');
|
||||
insert('n');
|
||||
} else {
|
||||
emit(ch);
|
||||
}
|
||||
}};
|
||||
if (ch <= 0x7f) {
|
||||
emitOneChar(ch);
|
||||
emitOneByte(ch);
|
||||
} else {
|
||||
EncodedCharacter encoded{EncodeCharacter(encoding, ch)};
|
||||
for (int j{0}; j < encoded.bytes; ++j) {
|
||||
emitOneChar(encoded.buffer[j]);
|
||||
emitOneByte(encoded.buffer[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -615,8 +615,13 @@ int main(int argc, char *const argv[]) {
|
|||
driver.pgf90Args.push_back(
|
||||
"-Mbackslash"); // yes, this *disables* them in pgf90
|
||||
}
|
||||
Fortran::parser::useHexadecimalEscapeSequences = false;
|
||||
} else {
|
||||
// TODO: equivalents for other Fortran compilers
|
||||
if (options.features.IsEnabled(
|
||||
Fortran::common::LanguageFeature::BackslashEscapes)) {
|
||||
driver.pgf90Args.push_back("-fbackslash");
|
||||
}
|
||||
Fortran::parser::useHexadecimalEscapeSequences = true;
|
||||
}
|
||||
|
||||
if (!anyFiles) {
|
||||
|
|
Loading…
Reference in a new issue