[flang-commits] [PATCH] D83104: [flang] External I/O runtime work, repackaged (part 2)

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jul 2 16:13:21 PDT 2020


klausler created this revision.
klausler added reviewers: tskeith, sscalpone.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83104

Files:
  flang/runtime/edit-input.cpp


Index: flang/runtime/edit-input.cpp
===================================================================
--- flang/runtime/edit-input.cpp
+++ 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 @@
 // 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 @@
     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);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83104.275257.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200702/a381e071/attachment-0001.bin>


More information about the flang-commits mailing list