return {chars};
}
-std::string QuoteCharacterLiteral(const std::string &str) {
+std::string QuoteCharacterLiteral(
+ const std::string &str, bool doubleDoubleQuotes, bool backslashEscapes) {
std::string result{'"'};
const auto emit{[&](char ch) { result += ch; }};
for (char ch : str) {
- EmitQuotedChar(ch, emit, emit);
+ EmitQuotedChar(ch, emit, emit, doubleDoubleQuotes, backslashEscapes);
}
result += '"';
return result;
}
}
-std::string QuoteCharacterLiteral(const std::string &);
+std::string QuoteCharacterLiteral(const std::string &,
+ bool doubleDoubleQuotes = true, bool backslashEscapes = true);
std::optional<int> UTF8CharacterBytes(const char *);
std::optional<int> EUC_JPCharacterBytes(const char *);
// These features must be explicitly enabled by command line options.
disable_.set(LanguageFeature::OldDebugLines);
disable_.set(LanguageFeature::OpenMP);
- // These features, if enabled, conflict with valid standard usage.
+ // These features, if enabled, conflict with valid standard usage,
+ // so there are disabled here by default.
+ disable_.set(LanguageFeature::BackslashEscapes);
disable_.set(LanguageFeature::LogicalAbbreviations);
disable_.set(LanguageFeature::XOROperator);
}
class UnparseVisitor {
public:
UnparseVisitor(std::ostream &out, int indentationAmount, Encoding encoding,
- bool capitalize, preStatementType *preStatement)
+ bool capitalize, bool backslashEscapes, preStatementType *preStatement)
: out_{out}, indentationAmount_{indentationAmount}, encoding_{encoding},
- capitalizeKeywords_{capitalize}, preStatement_{preStatement} {}
+ capitalizeKeywords_{capitalize}, backslashEscapes_{backslashEscapes},
+ preStatement_{preStatement} {}
// In nearly all cases, this code avoids defining Boolean-valued Pre()
// callbacks for the parse tree walking framework in favor of two void
Walk(*k), Put('_');
}
}
- Put(QuoteCharacterLiteral(std::get<std::string>(x.t)));
+ Put(QuoteCharacterLiteral(
+ std::get<std::string>(x.t), true, backslashEscapes_));
}
void Before(const HollerithLiteralConstant &x) {
std::optional<std::size_t> chars{CountCharacters(x.v.data(), x.v.size(),
Walk(*x.repeatCount);
}
std::visit(common::visitors{[&](const std::string &y) {
- Put(QuoteCharacterLiteral(y));
+ Put(QuoteCharacterLiteral(
+ y, true, backslashEscapes_));
},
[&](const std::list<format::FormatItem> &y) {
Walk("(", y, ",", ")");
std::set<CharBlock> structureComponents_;
Encoding encoding_{Encoding::UTF8};
bool capitalizeKeywords_{true};
+ bool backslashEscapes_{false};
preStatementType *preStatement_{nullptr};
};
void UnparseVisitor::Word(const std::string &str) { Word(str.c_str()); }
void Unparse(std::ostream &out, const Program &program, Encoding encoding,
- bool capitalizeKeywords, preStatementType *preStatement) {
- UnparseVisitor visitor{out, 1, encoding, capitalizeKeywords, preStatement};
+ bool capitalizeKeywords, bool backslashEscapes,
+ preStatementType *preStatement) {
+ UnparseVisitor visitor{
+ out, 1, encoding, capitalizeKeywords, backslashEscapes, preStatement};
Walk(program, visitor);
visitor.Done();
}
/// Convert parsed program to out as Fortran.
void Unparse(std::ostream &out, const Program &program,
Encoding encoding = Encoding::UTF8, bool capitalizeKeywords = true,
- preStatementType *preStatement = nullptr);
+ bool backslashEscapes = true, preStatementType *preStatement = nullptr);
} // namespace Fortran::parser
[&](const parser::CharBlock &location, std::ostream &out, int indent) {
visitor.PrintSymbols(location, out, indent);
}};
- parser::Unparse(out, program, encoding, false, &preStatement);
+ parser::Unparse(out, program, encoding, false, true, &preStatement);
}
} // namespace Fortran::semantics
Fortran::semantics::DumpTree(std::cout, parseTree);
}
if (driver.dumpUnparse) {
- Unparse(std::cout, parseTree, driver.encoding, true /*capitalize*/);
+ Unparse(std::cout, parseTree, driver.encoding, true /*capitalize*/,
+ options.features.IsEnabled(
+ Fortran::parser::LanguageFeature::BackslashEscapes));
return {};
}
if (driver.parseOnly) {
{
std::ofstream tmpSource;
tmpSource.open(tmpSourcePath);
- Unparse(tmpSource, parseTree, driver.encoding);
+ Unparse(tmpSource, parseTree, driver.encoding, true /*capitalize*/,
+ options.features.IsEnabled(
+ Fortran::parser::LanguageFeature::BackslashEscapes));
}
if (ParentProcess()) {
} else if (arg == "-Mbackslash") {
options.features.Enable(
Fortran::parser::LanguageFeature::BackslashEscapes, false);
+ driver.pgf90Args.push_back(arg);
} else if (arg == "-Mnobackslash") {
options.features.Enable(
Fortran::parser::LanguageFeature::BackslashEscapes);
} else if (arg == "-fno-backslash") {
options.features.Enable(
Fortran::parser::LanguageFeature::BackslashEscapes, false);
+ driver.pgf90Args.push_back("-Mbackslash");
} else if (arg == "-fdebug-dump-provenance") {
driver.dumpProvenance = true;
} else if (arg == "-fdebug-dump-parse-tree") {