[flang] WRF preprocessing tweaks
authorpeter klausler <pklausler@nvidia.com>
Thu, 14 Mar 2019 20:53:35 +0000 (13:53 -0700)
committerpeter klausler <pklausler@nvidia.com>
Thu, 14 Mar 2019 21:53:25 +0000 (14:53 -0700)
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
flang/lib/parser/prescan.h
flang/tools/f18/f18.cc

index c311e19..92768fa 100644 (file)
@@ -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)}) {
index 7cc3ddc..e83e377 100644 (file)
@@ -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(' ')};
index 6b773f6..acc423f 100644 (file)
@@ -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();