[flang] Fix INQUIRE of access and formatting possibilities

Don't give false positives from INQUIRE about possible
access mode changes on connected units.  DIRECT and SEQUENTIAL
cannot be intermixed, apart from allowing DIRECT on a SEQUENTIAL
file with fixed-size records and positioning.  Nor can
FORMATTED and UNFORMATTED be interchanged.  On unconnected
files, the best that we can do is "UNKNOWN".

Differential revision: https://reviews.llvm.org/D88673
This commit is contained in:
peter klausler 2020-10-01 09:44:09 -07:00
parent 9d40fb808f
commit df6de2222c
1 changed files with 14 additions and 11 deletions

View File

@ -820,7 +820,10 @@ bool InquireUnitState::Inquire(
} }
break; break;
case HashInquiryKeyword("DIRECT"): case HashInquiryKeyword("DIRECT"):
str = unit().mayPosition() ? "YES" : "NO"; str = unit().access == Access::Direct ||
(unit().mayPosition() && unit().isFixedRecordLength)
? "YES"
: "NO";
break; break;
case HashInquiryKeyword("ENCODING"): case HashInquiryKeyword("ENCODING"):
str = unit().isUnformatted ? "UNDEFINED" str = unit().isUnformatted ? "UNDEFINED"
@ -831,7 +834,7 @@ bool InquireUnitState::Inquire(
str = unit().isUnformatted ? "UNFORMATTED" : "FORMATTED"; str = unit().isUnformatted ? "UNFORMATTED" : "FORMATTED";
break; break;
case HashInquiryKeyword("FORMATTED"): case HashInquiryKeyword("FORMATTED"):
str = "YES"; str = !unit().isUnformatted ? "YES" : "NO";
break; break;
case HashInquiryKeyword("NAME"): case HashInquiryKeyword("NAME"):
str = unit().path(); str = unit().path();
@ -887,7 +890,9 @@ bool InquireUnitState::Inquire(
} }
break; break;
case HashInquiryKeyword("SEQUENTIAL"): case HashInquiryKeyword("SEQUENTIAL"):
str = "YES"; // "NO" for Direct, since Sequential would not work if
// the unit were reopened without RECL=.
str = unit().access == Access::Sequential ? "YES" : "NO";
break; break;
case HashInquiryKeyword("SIGN"): case HashInquiryKeyword("SIGN"):
str = unit().isUnformatted ? "UNDEFINED" str = unit().isUnformatted ? "UNDEFINED"
@ -895,13 +900,13 @@ bool InquireUnitState::Inquire(
: "SUPPRESS"; : "SUPPRESS";
break; break;
case HashInquiryKeyword("STREAM"): case HashInquiryKeyword("STREAM"):
str = "YES"; str = unit().access == Access::Stream ? "YES" : "NO";
break; break;
case HashInquiryKeyword("WRITE"): case HashInquiryKeyword("WRITE"):
str = unit().mayWrite() ? "YES" : "NO"; str = unit().mayWrite() ? "YES" : "NO";
break; break;
case HashInquiryKeyword("UNFORMATTED"): case HashInquiryKeyword("UNFORMATTED"):
str = "YES"; str = unit().isUnformatted ? "YES" : "NO";
break; break;
} }
if (str) { if (str) {
@ -1090,6 +1095,10 @@ bool InquireUnconnectedFileState::Inquire(
break; break;
case HashInquiryKeyword("DIRECT"): case HashInquiryKeyword("DIRECT"):
case HashInquiryKeyword("ENCODING"): case HashInquiryKeyword("ENCODING"):
case HashInquiryKeyword("FORMATTED"):
case HashInquiryKeyword("SEQUENTIAL"):
case HashInquiryKeyword("STREAM"):
case HashInquiryKeyword("UNFORMATTED"):
str = "UNKNONN"; str = "UNKNONN";
break; break;
case HashInquiryKeyword("READ"): case HashInquiryKeyword("READ"):
@ -1101,12 +1110,6 @@ bool InquireUnconnectedFileState::Inquire(
case HashInquiryKeyword("WRITE"): case HashInquiryKeyword("WRITE"):
str = MayWrite(path_.get()) ? "YES" : "NO"; str = MayWrite(path_.get()) ? "YES" : "NO";
break; break;
case HashInquiryKeyword("FORMATTED"):
case HashInquiryKeyword("SEQUENTIAL"):
case HashInquiryKeyword("STREAM"):
case HashInquiryKeyword("UNFORMATTED"):
str = "YES";
break;
case HashInquiryKeyword("NAME"): case HashInquiryKeyword("NAME"):
str = path_.get(); str = path_.get();
return true; return true;