From 3348b1691d8ebd54852e5940d907254ab913cf6c Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 14 Mar 2019 13:53:35 -0700 Subject: [PATCH] [flang] WRF preprocessing tweaks Original-commit: flang-compiler/f18@53f76e1c93a9df2afb7ce6689f9abee5cef6793c Reviewed-on: https://github.com/flang-compiler/f18/pull/333 Tree-same-pre-rewrite: false --- flang/lib/parser/prescan.cc | 19 ++++++++++++++++--- flang/lib/parser/prescan.h | 1 + flang/tools/f18/f18.cc | 5 +++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/flang/lib/parser/prescan.cc b/flang/lib/parser/prescan.cc index c311e19..92768fa 100644 --- a/flang/lib/parser/prescan.cc +++ b/flang/lib/parser/prescan.cc @@ -40,6 +40,7 @@ Prescanner::Prescanner(const Prescanner &that) inFixedForm_{that.inFixedForm_}, fixedFormColumnLimit_{that.fixedFormColumnLimit_}, encoding_{that.encoding_}, prescannerNesting_{that.prescannerNesting_ + 1}, + skipLeadingAmpersand_{that.skipLeadingAmpersand_}, compilerDirectiveBloomFilter_{that.compilerDirectiveBloomFilter_}, compilerDirectiveSentinels_{that.compilerDirectiveSentinels_} {} @@ -145,6 +146,13 @@ void Prescanner::Statement() { BeginSourceLineAndAdvance(); if (inFixedForm_) { LabelField(tokens); + } else if (skipLeadingAmpersand_) { + skipLeadingAmpersand_ = false; + const char *p{SkipWhiteSpace(at_)}; + if (p < limit_ && *p == '&') { + column_ += ++p - at_; + at_ = p; + } } else { SkipSpaces(); } @@ -679,7 +687,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) { if (lineStart_ >= limit_) { if (afterAmpersand && prescannerNesting_ > 0) { // 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(); omitNewline_ = true; } @@ -702,6 +710,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) { lineClass.kind == LineClassification::Kind::IncludeLine)) { SkipToEndOfLine(); omitNewline_ = true; + skipLeadingAmpersand_ = true; return false; } else { return false; @@ -841,8 +850,12 @@ bool Prescanner::FreeFormContinuation() { if (ampersand) { p = SkipWhiteSpace(p + 1); } - if (*p != '\n' && (inCharLiteral_ || *p != '!')) { - return false; + if (*p != '\n') { + if (inCharLiteral_) { + return false; + } else if (*p != '!') { + Say(GetProvenance(p), "treated as comment after &"_en_US); + } } do { if (const char *cont{FreeFormContinuationLine(ampersand)}) { diff --git a/flang/lib/parser/prescan.h b/flang/lib/parser/prescan.h index 7cc3ddc..e83e377 100644 --- a/flang/lib/parser/prescan.h +++ b/flang/lib/parser/prescan.h @@ -205,6 +205,7 @@ private: // the line before. Also used when the & appears at the end of the last // line in an include file. bool omitNewline_{false}; + bool skipLeadingAmpersand_{false}; const Provenance spaceProvenance_{ cooked_.allSources().CompilerInsertionProvenance(' ')}; diff --git a/flang/tools/f18/f18.cc b/flang/tools/f18/f18.cc index 6b773f6..acc423f 100644 --- a/flang/tools/f18/f18.cc +++ b/flang/tools/f18/f18.cc @@ -190,6 +190,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options, return {}; } if (driver.dumpCookedChars) { + parsing.messages().Emit(std::cerr, parsing.cooked()); parsing.DumpCookedChars(std::cout); return {}; } @@ -219,8 +220,8 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options, } // TODO: Change this predicate to just "if (!driver.debugNoSemantics)" if (driver.debugSemantics || driver.debugResolveNames || driver.dumpSymbols || - driver.dumpUnparseWithSymbols || - driver.debugLinearFIR || driver.dumpGraph) { + driver.dumpUnparseWithSymbols || driver.debugLinearFIR || + driver.dumpGraph) { Fortran::semantics::Semantics semantics{ semanticsContext, parseTree, parsing.cooked()}; semantics.Perform(); -- 2.7.4