[flang] WRF preprocessing tweaks

Original-commit: flang-compiler/f18@53f76e1c93
Reviewed-on: https://github.com/flang-compiler/f18/pull/333
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-03-14 13:53:35 -07:00
parent 3204a1c1b9
commit 3348b1691d
3 changed files with 20 additions and 5 deletions

View File

@ -40,6 +40,7 @@ Prescanner::Prescanner(const Prescanner &that)
inFixedForm_{that.inFixedForm_}, inFixedForm_{that.inFixedForm_},
fixedFormColumnLimit_{that.fixedFormColumnLimit_}, fixedFormColumnLimit_{that.fixedFormColumnLimit_},
encoding_{that.encoding_}, prescannerNesting_{that.prescannerNesting_ + 1}, encoding_{that.encoding_}, prescannerNesting_{that.prescannerNesting_ + 1},
skipLeadingAmpersand_{that.skipLeadingAmpersand_},
compilerDirectiveBloomFilter_{that.compilerDirectiveBloomFilter_}, compilerDirectiveBloomFilter_{that.compilerDirectiveBloomFilter_},
compilerDirectiveSentinels_{that.compilerDirectiveSentinels_} {} compilerDirectiveSentinels_{that.compilerDirectiveSentinels_} {}
@ -145,6 +146,13 @@ void Prescanner::Statement() {
BeginSourceLineAndAdvance(); BeginSourceLineAndAdvance();
if (inFixedForm_) { if (inFixedForm_) {
LabelField(tokens); LabelField(tokens);
} else if (skipLeadingAmpersand_) {
skipLeadingAmpersand_ = false;
const char *p{SkipWhiteSpace(at_)};
if (p < limit_ && *p == '&') {
column_ += ++p - at_;
at_ = p;
}
} else { } else {
SkipSpaces(); SkipSpaces();
} }
@ -679,7 +687,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) {
if (lineStart_ >= limit_) { if (lineStart_ >= limit_) {
if (afterAmpersand && prescannerNesting_ > 0) { if (afterAmpersand && prescannerNesting_ > 0) {
// A continuation marker at the end of the last line in an // A continuation marker at the end of the last line in an
// include file inhibits the newline. // include file inhibits the newline for that line.
SkipToEndOfLine(); SkipToEndOfLine();
omitNewline_ = true; omitNewline_ = true;
} }
@ -702,6 +710,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) {
lineClass.kind == LineClassification::Kind::IncludeLine)) { lineClass.kind == LineClassification::Kind::IncludeLine)) {
SkipToEndOfLine(); SkipToEndOfLine();
omitNewline_ = true; omitNewline_ = true;
skipLeadingAmpersand_ = true;
return false; return false;
} else { } else {
return false; return false;
@ -841,8 +850,12 @@ bool Prescanner::FreeFormContinuation() {
if (ampersand) { if (ampersand) {
p = SkipWhiteSpace(p + 1); p = SkipWhiteSpace(p + 1);
} }
if (*p != '\n' && (inCharLiteral_ || *p != '!')) { if (*p != '\n') {
return false; if (inCharLiteral_) {
return false;
} else if (*p != '!') {
Say(GetProvenance(p), "treated as comment after &"_en_US);
}
} }
do { do {
if (const char *cont{FreeFormContinuationLine(ampersand)}) { if (const char *cont{FreeFormContinuationLine(ampersand)}) {

View File

@ -205,6 +205,7 @@ private:
// the line before. Also used when the & appears at the end of the last // the line before. Also used when the & appears at the end of the last
// line in an include file. // line in an include file.
bool omitNewline_{false}; bool omitNewline_{false};
bool skipLeadingAmpersand_{false};
const Provenance spaceProvenance_{ const Provenance spaceProvenance_{
cooked_.allSources().CompilerInsertionProvenance(' ')}; cooked_.allSources().CompilerInsertionProvenance(' ')};

View File

@ -190,6 +190,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
return {}; return {};
} }
if (driver.dumpCookedChars) { if (driver.dumpCookedChars) {
parsing.messages().Emit(std::cerr, parsing.cooked());
parsing.DumpCookedChars(std::cout); parsing.DumpCookedChars(std::cout);
return {}; return {};
} }
@ -219,8 +220,8 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
} }
// TODO: Change this predicate to just "if (!driver.debugNoSemantics)" // TODO: Change this predicate to just "if (!driver.debugNoSemantics)"
if (driver.debugSemantics || driver.debugResolveNames || driver.dumpSymbols || if (driver.debugSemantics || driver.debugResolveNames || driver.dumpSymbols ||
driver.dumpUnparseWithSymbols || driver.dumpUnparseWithSymbols || driver.debugLinearFIR ||
driver.debugLinearFIR || driver.dumpGraph) { driver.dumpGraph) {
Fortran::semantics::Semantics semantics{ Fortran::semantics::Semantics semantics{
semanticsContext, parseTree, parsing.cooked()}; semanticsContext, parseTree, parsing.cooked()};
semantics.Perform(); semantics.Perform();