[flang-commits] [flang] 4e958c1 - [flang] External I/O runtime work, repackaged (part 2)

peter klausler via flang-commits flang-commits at lists.llvm.org
Thu Jul 2 17:45:46 PDT 2020


Author: peter klausler
Date: 2020-07-02T17:44:51-07:00
New Revision: 4e958c1748a98d700def115c034e3a863be269e3

URL: https://github.com/llvm/llvm-project/commit/4e958c1748a98d700def115c034e3a863be269e3
DIFF: https://github.com/llvm/llvm-project/commit/4e958c1748a98d700def115c034e3a863be269e3.diff

LOG: [flang] External I/O runtime work, repackaged (part 2)

Clean up the input editing path so external input works better
when combined with further changes.  List-directed input needed
to allow for advancement to following records.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83104

Added: 
    

Modified: 
    flang/runtime/edit-input.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index 77bf100d2e21..f710c1107ec1 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -13,14 +13,24 @@
 
 namespace Fortran::runtime::io {
 
+static std::optional<char32_t> PrepareInput(
+    IoStatementState &io, const DataEdit &edit, std::optional<int> &remaining) {
+  remaining.reset();
+  if (edit.descriptor == DataEdit::ListDirected) {
+    io.GetNextNonBlank();
+  } else {
+    if (edit.width.value_or(0) > 0) {
+      remaining = *edit.width;
+    }
+    io.SkipSpaces(remaining);
+  }
+  return io.NextInField(remaining);
+}
+
 static bool EditBOZInput(IoStatementState &io, const DataEdit &edit, void *n,
     int base, int totalBitSize) {
   std::optional<int> remaining;
-  if (edit.width) {
-    remaining = std::max(0, *edit.width);
-  }
-  io.SkipSpaces(remaining);
-  std::optional<char32_t> next{io.NextInField(remaining)};
+  std::optional<char32_t> next{PrepareInput(io, edit, remaining)};
   common::UnsignedInt128 value{0};
   for (; next; next = io.NextInField(remaining)) {
     char32_t ch{*next};
@@ -54,14 +64,7 @@ static bool EditBOZInput(IoStatementState &io, const DataEdit &edit, void *n,
 // Returns false if there's a '-' sign
 static bool ScanNumericPrefix(IoStatementState &io, const DataEdit &edit,
     std::optional<char32_t> &next, std::optional<int> &remaining) {
-  if (edit.descriptor != DataEdit::ListDirected && edit.width) {
-    remaining = std::max(0, *edit.width);
-  } else {
-    // list-directed, namelist, or (nonstandard) 0-width input editing
-    remaining.reset();
-  }
-  io.SkipSpaces(remaining);
-  next = io.NextInField(remaining);
+  next = PrepareInput(io, edit, remaining);
   bool negative{false};
   if (next) {
     negative = *next == '-';
@@ -310,11 +313,7 @@ bool EditLogicalInput(IoStatementState &io, const DataEdit &edit, bool &x) {
     return false;
   }
   std::optional<int> remaining;
-  if (edit.width) {
-    remaining = std::max(0, *edit.width);
-  }
-  io.SkipSpaces(remaining);
-  std::optional<char32_t> next{io.NextInField(remaining)};
+  std::optional<char32_t> next{PrepareInput(io, edit, remaining)};
   if (next && *next == '.') { // skip optional period
     next = io.NextInField(remaining);
   }


        


More information about the flang-commits mailing list