1 //===-- runtime/io-stmt.cpp -------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "io-stmt.h" 10 #include "connection.h" 11 #include "format.h" 12 #include "memory.h" 13 #include "tools.h" 14 #include "unit.h" 15 #include <algorithm> 16 #include <cstdio> 17 #include <cstring> 18 #include <limits> 19 20 namespace Fortran::runtime::io { 21 22 int IoStatementBase::EndIoStatement() { return GetIoStat(); } 23 24 bool IoStatementBase::Emit(const char *, std::size_t, std::size_t) { 25 return false; 26 } 27 28 bool IoStatementBase::Emit(const char *, std::size_t) { 29 return false; 30 } 31 32 bool IoStatementBase::Emit(const char16_t *, std::size_t) { 33 return false; 34 } 35 36 bool IoStatementBase::Emit(const char32_t *, std::size_t) { 37 return false; 38 } 39 40 std::optional<char32_t> IoStatementBase::GetCurrentChar() { 41 return std::nullopt; 42 } 43 44 bool IoStatementBase::AdvanceRecord(int) { return false; } 45 46 void IoStatementBase::BackspaceRecord() {} 47 48 bool IoStatementBase::Receive(char *, std::size_t, std::size_t) { 49 return false; 50 } 51 52 std::optional<DataEdit> IoStatementBase::GetNextDataEdit( 53 IoStatementState &, int) { 54 return std::nullopt; 55 } 56 57 ExternalFileUnit *IoStatementBase::GetExternalFileUnit() const { 58 return nullptr; 59 } 60 61 bool IoStatementBase::BeginReadingRecord() { return true; } 62 63 void IoStatementBase::FinishReadingRecord() {} 64 65 void IoStatementBase::HandleAbsolutePosition(std::int64_t) {} 66 67 void IoStatementBase::HandleRelativePosition(std::int64_t) {} 68 69 bool IoStatementBase::Inquire(InquiryKeywordHash, char *, std::size_t) { 70 return false; 71 } 72 73 bool IoStatementBase::Inquire(InquiryKeywordHash, bool &) { 74 return false; 75 } 76 77 bool IoStatementBase::Inquire(InquiryKeywordHash, std::int64_t, bool &) { 78 return false; 79 } 80 81 bool IoStatementBase::Inquire(InquiryKeywordHash, std::int64_t &) { 82 return false; 83 } 84 85 void IoStatementBase::BadInquiryKeywordHashCrash(InquiryKeywordHash inquiry) { 86 char buffer[16]; 87 const char *decode{InquiryKeywordHashDecode(buffer, sizeof buffer, inquiry)}; 88 Crash("bad InquiryKeywordHash 0x%x (%s)", inquiry, 89 decode ? decode : "(cannot decode)"); 90 } 91 92 template <Direction DIR, typename CHAR> 93 InternalIoStatementState<DIR, CHAR>::InternalIoStatementState( 94 Buffer scalar, std::size_t length, const char *sourceFile, int sourceLine) 95 : IoStatementBase{sourceFile, sourceLine}, unit_{scalar, length} {} 96 97 template <Direction DIR, typename CHAR> 98 InternalIoStatementState<DIR, CHAR>::InternalIoStatementState( 99 const Descriptor &d, const char *sourceFile, int sourceLine) 100 : IoStatementBase{sourceFile, sourceLine}, unit_{d, *this} {} 101 102 template <Direction DIR, typename CHAR> 103 bool InternalIoStatementState<DIR, CHAR>::Emit( 104 const CharType *data, std::size_t chars) { 105 if constexpr (DIR == Direction::Input) { 106 Crash("InternalIoStatementState<Direction::Input>::Emit() called"); 107 return false; 108 } 109 return unit_.Emit(data, chars * sizeof(CharType), *this); 110 } 111 112 template <Direction DIR, typename CHAR> 113 std::optional<char32_t> InternalIoStatementState<DIR, CHAR>::GetCurrentChar() { 114 if constexpr (DIR == Direction::Output) { 115 Crash( 116 "InternalIoStatementState<Direction::Output>::GetCurrentChar() called"); 117 return std::nullopt; 118 } 119 return unit_.GetCurrentChar(*this); 120 } 121 122 template <Direction DIR, typename CHAR> 123 bool InternalIoStatementState<DIR, CHAR>::AdvanceRecord(int n) { 124 while (n-- > 0) { 125 if (!unit_.AdvanceRecord(*this)) { 126 return false; 127 } 128 } 129 return true; 130 } 131 132 template <Direction DIR, typename CHAR> 133 void InternalIoStatementState<DIR, CHAR>::BackspaceRecord() { 134 unit_.BackspaceRecord(*this); 135 } 136 137 template <Direction DIR, typename CHAR> 138 int InternalIoStatementState<DIR, CHAR>::EndIoStatement() { 139 if constexpr (DIR == Direction::Output) { 140 unit_.EndIoStatement(); // fill 141 } 142 auto result{IoStatementBase::EndIoStatement()}; 143 if (free_) { 144 FreeMemory(this); 145 } 146 return result; 147 } 148 149 template <Direction DIR, typename CHAR> 150 void InternalIoStatementState<DIR, CHAR>::HandleAbsolutePosition( 151 std::int64_t n) { 152 return unit_.HandleAbsolutePosition(n); 153 } 154 155 template <Direction DIR, typename CHAR> 156 void InternalIoStatementState<DIR, CHAR>::HandleRelativePosition( 157 std::int64_t n) { 158 return unit_.HandleRelativePosition(n); 159 } 160 161 template <Direction DIR, typename CHAR> 162 InternalFormattedIoStatementState<DIR, CHAR>::InternalFormattedIoStatementState( 163 Buffer buffer, std::size_t length, const CHAR *format, 164 std::size_t formatLength, const char *sourceFile, int sourceLine) 165 : InternalIoStatementState<DIR, CHAR>{buffer, length, sourceFile, 166 sourceLine}, 167 ioStatementState_{*this}, format_{*this, format, formatLength} {} 168 169 template <Direction DIR, typename CHAR> 170 InternalFormattedIoStatementState<DIR, CHAR>::InternalFormattedIoStatementState( 171 const Descriptor &d, const CHAR *format, std::size_t formatLength, 172 const char *sourceFile, int sourceLine) 173 : InternalIoStatementState<DIR, CHAR>{d, sourceFile, sourceLine}, 174 ioStatementState_{*this}, format_{*this, format, formatLength} {} 175 176 template <Direction DIR, typename CHAR> 177 int InternalFormattedIoStatementState<DIR, CHAR>::EndIoStatement() { 178 if constexpr (DIR == Direction::Output) { 179 format_.Finish(*this); // ignore any remaining input positioning actions 180 } 181 return InternalIoStatementState<DIR, CHAR>::EndIoStatement(); 182 } 183 184 template <Direction DIR, typename CHAR> 185 InternalListIoStatementState<DIR, CHAR>::InternalListIoStatementState( 186 Buffer buffer, std::size_t length, const char *sourceFile, int sourceLine) 187 : InternalIoStatementState<DIR, CharType>{buffer, length, sourceFile, 188 sourceLine}, 189 ioStatementState_{*this} {} 190 191 template <Direction DIR, typename CHAR> 192 InternalListIoStatementState<DIR, CHAR>::InternalListIoStatementState( 193 const Descriptor &d, const char *sourceFile, int sourceLine) 194 : InternalIoStatementState<DIR, CharType>{d, sourceFile, sourceLine}, 195 ioStatementState_{*this} {} 196 197 ExternalIoStatementBase::ExternalIoStatementBase( 198 ExternalFileUnit &unit, const char *sourceFile, int sourceLine) 199 : IoStatementBase{sourceFile, sourceLine}, unit_{unit} {} 200 201 MutableModes &ExternalIoStatementBase::mutableModes() { return unit_.modes; } 202 203 ConnectionState &ExternalIoStatementBase::GetConnectionState() { return unit_; } 204 205 int ExternalIoStatementBase::EndIoStatement() { 206 if (mutableModes().nonAdvancing) { 207 unit_.leftTabLimit = unit_.furthestPositionInRecord; 208 } else { 209 unit_.leftTabLimit.reset(); 210 } 211 auto result{IoStatementBase::EndIoStatement()}; 212 unit_.EndIoStatement(); // annihilates *this in unit_.u_ 213 return result; 214 } 215 216 void OpenStatementState::set_path(const char *path, std::size_t length) { 217 pathLength_ = TrimTrailingSpaces(path, length); 218 path_ = SaveDefaultCharacter(path, pathLength_, *this); 219 } 220 221 int OpenStatementState::EndIoStatement() { 222 if (path_.get() || wasExtant_ || 223 (status_ && *status_ == OpenStatus::Scratch)) { 224 unit().OpenUnit(status_, action_, position_, std::move(path_), pathLength_, 225 convert_, *this); 226 } else { 227 unit().OpenAnonymousUnit(status_, action_, position_, convert_, *this); 228 } 229 if (access_) { 230 if (*access_ != unit().access) { 231 if (wasExtant_) { 232 SignalError("ACCESS= may not be changed on an open unit"); 233 } 234 } 235 unit().access = *access_; 236 } 237 if (!unit().isUnformatted) { 238 unit().isUnformatted = isUnformatted_; 239 } 240 if (isUnformatted_ && *isUnformatted_ != *unit().isUnformatted) { 241 if (wasExtant_) { 242 SignalError("FORM= may not be changed on an open unit"); 243 } 244 unit().isUnformatted = *isUnformatted_; 245 } 246 return ExternalIoStatementBase::EndIoStatement(); 247 } 248 249 int CloseStatementState::EndIoStatement() { 250 int result{ExternalIoStatementBase::EndIoStatement()}; 251 unit().CloseUnit(status_, *this); 252 unit().DestroyClosed(); 253 return result; 254 } 255 256 int NoUnitIoStatementState::EndIoStatement() { 257 auto result{IoStatementBase::EndIoStatement()}; 258 FreeMemory(this); 259 return result; 260 } 261 262 template <Direction DIR> 263 ExternalIoStatementState<DIR>::ExternalIoStatementState( 264 ExternalFileUnit &unit, const char *sourceFile, int sourceLine) 265 : ExternalIoStatementBase{unit, sourceFile, sourceLine}, mutableModes_{ 266 unit.modes} {} 267 268 template <Direction DIR> int ExternalIoStatementState<DIR>::EndIoStatement() { 269 if constexpr (DIR == Direction::Input) { 270 BeginReadingRecord(); // in case there were no I/O items 271 if (!mutableModes().nonAdvancing) { 272 FinishReadingRecord(); 273 } 274 } else { 275 if (!mutableModes().nonAdvancing) { 276 unit().AdvanceRecord(*this); 277 } 278 unit().FlushIfTerminal(*this); 279 } 280 return ExternalIoStatementBase::EndIoStatement(); 281 } 282 283 template <Direction DIR> 284 bool ExternalIoStatementState<DIR>::Emit( 285 const char *data, std::size_t bytes, std::size_t elementBytes) { 286 if constexpr (DIR == Direction::Input) { 287 Crash("ExternalIoStatementState::Emit(char) called for input statement"); 288 } 289 return unit().Emit(data, bytes, elementBytes, *this); 290 } 291 292 template <Direction DIR> 293 bool ExternalIoStatementState<DIR>::Emit(const char *data, std::size_t bytes) { 294 if constexpr (DIR == Direction::Input) { 295 Crash("ExternalIoStatementState::Emit(char) called for input statement"); 296 } 297 return unit().Emit(data, bytes, 0, *this); 298 } 299 300 template <Direction DIR> 301 bool ExternalIoStatementState<DIR>::Emit( 302 const char16_t *data, std::size_t chars) { 303 if constexpr (DIR == Direction::Input) { 304 Crash( 305 "ExternalIoStatementState::Emit(char16_t) called for input statement"); 306 } 307 // TODO: UTF-8 encoding 308 return unit().Emit(reinterpret_cast<const char *>(data), chars * sizeof *data, 309 sizeof *data, *this); 310 } 311 312 template <Direction DIR> 313 bool ExternalIoStatementState<DIR>::Emit( 314 const char32_t *data, std::size_t chars) { 315 if constexpr (DIR == Direction::Input) { 316 Crash( 317 "ExternalIoStatementState::Emit(char32_t) called for input statement"); 318 } 319 // TODO: UTF-8 encoding 320 return unit().Emit(reinterpret_cast<const char *>(data), chars * sizeof *data, 321 sizeof *data, *this); 322 } 323 324 template <Direction DIR> 325 std::optional<char32_t> ExternalIoStatementState<DIR>::GetCurrentChar() { 326 if constexpr (DIR == Direction::Output) { 327 Crash( 328 "ExternalIoStatementState<Direction::Output>::GetCurrentChar() called"); 329 } 330 return unit().GetCurrentChar(*this); 331 } 332 333 template <Direction DIR> 334 bool ExternalIoStatementState<DIR>::AdvanceRecord(int n) { 335 while (n-- > 0) { 336 if (!unit().AdvanceRecord(*this)) { 337 return false; 338 } 339 } 340 return true; 341 } 342 343 template <Direction DIR> void ExternalIoStatementState<DIR>::BackspaceRecord() { 344 unit().BackspaceRecord(*this); 345 } 346 347 template <Direction DIR> 348 void ExternalIoStatementState<DIR>::HandleAbsolutePosition(std::int64_t n) { 349 return unit().HandleAbsolutePosition(n); 350 } 351 352 template <Direction DIR> 353 void ExternalIoStatementState<DIR>::HandleRelativePosition(std::int64_t n) { 354 return unit().HandleRelativePosition(n); 355 } 356 357 template <Direction DIR> 358 bool ExternalIoStatementState<DIR>::BeginReadingRecord() { 359 if constexpr (DIR == Direction::Input) { 360 return unit().BeginReadingRecord(*this); 361 } else { 362 Crash("ExternalIoStatementState<Direction::Output>::BeginReadingRecord() " 363 "called"); 364 return false; 365 } 366 } 367 368 template <Direction DIR> 369 void ExternalIoStatementState<DIR>::FinishReadingRecord() { 370 if constexpr (DIR == Direction::Input) { 371 unit().FinishReadingRecord(*this); 372 } else { 373 Crash("ExternalIoStatementState<Direction::Output>::FinishReadingRecord() " 374 "called"); 375 } 376 } 377 378 template <Direction DIR, typename CHAR> 379 ExternalFormattedIoStatementState<DIR, CHAR>::ExternalFormattedIoStatementState( 380 ExternalFileUnit &unit, const CHAR *format, std::size_t formatLength, 381 const char *sourceFile, int sourceLine) 382 : ExternalIoStatementState<DIR>{unit, sourceFile, sourceLine}, 383 format_{*this, format, formatLength} {} 384 385 template <Direction DIR, typename CHAR> 386 int ExternalFormattedIoStatementState<DIR, CHAR>::EndIoStatement() { 387 format_.Finish(*this); 388 return ExternalIoStatementState<DIR>::EndIoStatement(); 389 } 390 391 std::optional<DataEdit> IoStatementState::GetNextDataEdit(int n) { 392 return std::visit( 393 [&](auto &x) { return x.get().GetNextDataEdit(*this, n); }, u_); 394 } 395 396 bool IoStatementState::Emit( 397 const char *data, std::size_t n, std::size_t elementBytes) { 398 return std::visit( 399 [=](auto &x) { return x.get().Emit(data, n, elementBytes); }, u_); 400 } 401 402 bool IoStatementState::Emit(const char *data, std::size_t n) { 403 return std::visit([=](auto &x) { return x.get().Emit(data, n); }, u_); 404 } 405 406 bool IoStatementState::Emit(const char16_t *data, std::size_t chars) { 407 return std::visit([=](auto &x) { return x.get().Emit(data, chars); }, u_); 408 } 409 410 bool IoStatementState::Emit(const char32_t *data, std::size_t chars) { 411 return std::visit([=](auto &x) { return x.get().Emit(data, chars); }, u_); 412 } 413 414 bool IoStatementState::Receive( 415 char *data, std::size_t n, std::size_t elementBytes) { 416 return std::visit( 417 [=](auto &x) { return x.get().Receive(data, n, elementBytes); }, u_); 418 } 419 420 std::optional<char32_t> IoStatementState::GetCurrentChar() { 421 return std::visit([&](auto &x) { return x.get().GetCurrentChar(); }, u_); 422 } 423 424 bool IoStatementState::AdvanceRecord(int n) { 425 return std::visit([=](auto &x) { return x.get().AdvanceRecord(n); }, u_); 426 } 427 428 void IoStatementState::BackspaceRecord() { 429 std::visit([](auto &x) { x.get().BackspaceRecord(); }, u_); 430 } 431 432 void IoStatementState::HandleRelativePosition(std::int64_t n) { 433 std::visit([=](auto &x) { x.get().HandleRelativePosition(n); }, u_); 434 } 435 436 void IoStatementState::HandleAbsolutePosition(std::int64_t n) { 437 std::visit([=](auto &x) { x.get().HandleAbsolutePosition(n); }, u_); 438 } 439 440 int IoStatementState::EndIoStatement() { 441 return std::visit([](auto &x) { return x.get().EndIoStatement(); }, u_); 442 } 443 444 ConnectionState &IoStatementState::GetConnectionState() { 445 return std::visit( 446 [](auto &x) -> ConnectionState & { return x.get().GetConnectionState(); }, 447 u_); 448 } 449 450 MutableModes &IoStatementState::mutableModes() { 451 return std::visit( 452 [](auto &x) -> MutableModes & { return x.get().mutableModes(); }, u_); 453 } 454 455 bool IoStatementState::BeginReadingRecord() { 456 return std::visit([](auto &x) { return x.get().BeginReadingRecord(); }, u_); 457 } 458 459 IoErrorHandler &IoStatementState::GetIoErrorHandler() const { 460 return std::visit( 461 [](auto &x) -> IoErrorHandler & { 462 return static_cast<IoErrorHandler &>(x.get()); 463 }, 464 u_); 465 } 466 467 ExternalFileUnit *IoStatementState::GetExternalFileUnit() const { 468 return std::visit([](auto &x) { return x.get().GetExternalFileUnit(); }, u_); 469 } 470 471 bool IoStatementState::EmitRepeated(char ch, std::size_t n) { 472 return std::visit( 473 [=](auto &x) { 474 for (std::size_t j{0}; j < n; ++j) { 475 if (!x.get().Emit(&ch, 1)) { 476 return false; 477 } 478 } 479 return true; 480 }, 481 u_); 482 } 483 484 bool IoStatementState::EmitField( 485 const char *p, std::size_t length, std::size_t width) { 486 if (width <= 0) { 487 width = static_cast<int>(length); 488 } 489 if (length > static_cast<std::size_t>(width)) { 490 return EmitRepeated('*', width); 491 } else { 492 return EmitRepeated(' ', static_cast<int>(width - length)) && 493 Emit(p, length); 494 } 495 } 496 497 std::optional<char32_t> IoStatementState::PrepareInput( 498 const DataEdit &edit, std::optional<int> &remaining) { 499 remaining.reset(); 500 if (edit.descriptor == DataEdit::ListDirected) { 501 GetNextNonBlank(); 502 } else { 503 if (edit.width.value_or(0) > 0) { 504 remaining = *edit.width; 505 } 506 SkipSpaces(remaining); 507 } 508 return NextInField(remaining); 509 } 510 511 std::optional<char32_t> IoStatementState::SkipSpaces( 512 std::optional<int> &remaining) { 513 while (!remaining || *remaining > 0) { 514 if (auto ch{GetCurrentChar()}) { 515 if (*ch != ' ' && *ch != '\t') { 516 return ch; 517 } 518 HandleRelativePosition(1); 519 if (remaining) { 520 --*remaining; 521 } 522 } else { 523 break; 524 } 525 } 526 return std::nullopt; 527 } 528 529 std::optional<char32_t> IoStatementState::NextInField( 530 std::optional<int> &remaining) { 531 if (!remaining) { // list-directed or NAMELIST: check for separators 532 if (auto next{GetCurrentChar()}) { 533 switch (*next) { 534 case ' ': 535 case '\t': 536 case ',': 537 case ';': 538 case '/': 539 case '(': 540 case ')': 541 case '\'': 542 case '"': 543 case '*': 544 case '\n': // for stream access 545 break; 546 default: 547 HandleRelativePosition(1); 548 return next; 549 } 550 } 551 } else if (*remaining > 0) { 552 if (auto next{GetCurrentChar()}) { 553 --*remaining; 554 HandleRelativePosition(1); 555 return next; 556 } 557 const ConnectionState &connection{GetConnectionState()}; 558 if (!connection.IsAtEOF() && connection.isFixedRecordLength && 559 connection.recordLength && 560 connection.positionInRecord >= *connection.recordLength) { 561 if (connection.modes.pad) { // PAD='YES' 562 --*remaining; 563 return std::optional<char32_t>{' '}; 564 } 565 IoErrorHandler &handler{GetIoErrorHandler()}; 566 if (mutableModes().nonAdvancing) { 567 handler.SignalEor(); 568 } else { 569 handler.SignalError(IostatRecordReadOverrun); 570 } 571 } 572 } 573 return std::nullopt; 574 } 575 576 std::optional<char32_t> IoStatementState::GetNextNonBlank() { 577 auto ch{GetCurrentChar()}; 578 bool inNamelist{GetConnectionState().modes.inNamelist}; 579 while (!ch || *ch == ' ' || *ch == '\t' || (inNamelist && *ch == '!')) { 580 if (ch && (*ch == ' ' || *ch == '\t')) { 581 HandleRelativePosition(1); 582 } else if (!AdvanceRecord()) { 583 return std::nullopt; 584 } 585 ch = GetCurrentChar(); 586 } 587 return ch; 588 } 589 590 bool IoStatementState::Inquire( 591 InquiryKeywordHash inquiry, char *out, std::size_t chars) { 592 return std::visit( 593 [&](auto &x) { return x.get().Inquire(inquiry, out, chars); }, u_); 594 } 595 596 bool IoStatementState::Inquire(InquiryKeywordHash inquiry, bool &out) { 597 return std::visit([&](auto &x) { return x.get().Inquire(inquiry, out); }, u_); 598 } 599 600 bool IoStatementState::Inquire( 601 InquiryKeywordHash inquiry, std::int64_t id, bool &out) { 602 return std::visit( 603 [&](auto &x) { return x.get().Inquire(inquiry, id, out); }, u_); 604 } 605 606 bool IoStatementState::Inquire(InquiryKeywordHash inquiry, std::int64_t &n) { 607 return std::visit([&](auto &x) { return x.get().Inquire(inquiry, n); }, u_); 608 } 609 610 bool ListDirectedStatementState<Direction::Output>::EmitLeadingSpaceOrAdvance( 611 IoStatementState &io, std::size_t length, bool isCharacter) { 612 if (length == 0) { 613 return true; 614 } 615 const ConnectionState &connection{io.GetConnectionState()}; 616 int space{connection.positionInRecord == 0 || 617 !(isCharacter && lastWasUndelimitedCharacter())}; 618 set_lastWasUndelimitedCharacter(false); 619 if (connection.NeedAdvance(space + length)) { 620 return io.AdvanceRecord(); 621 } 622 if (space) { 623 return io.Emit(" ", 1); 624 } 625 return true; 626 } 627 628 std::optional<DataEdit> 629 ListDirectedStatementState<Direction::Output>::GetNextDataEdit( 630 IoStatementState &io, int maxRepeat) { 631 DataEdit edit; 632 edit.descriptor = DataEdit::ListDirected; 633 edit.repeat = maxRepeat; 634 edit.modes = io.mutableModes(); 635 return edit; 636 } 637 638 std::optional<DataEdit> 639 ListDirectedStatementState<Direction::Input>::GetNextDataEdit( 640 IoStatementState &io, int maxRepeat) { 641 // N.B. list-directed transfers cannot be nonadvancing (C1221) 642 ConnectionState &connection{io.GetConnectionState()}; 643 DataEdit edit; 644 edit.descriptor = DataEdit::ListDirected; 645 edit.repeat = 1; // may be overridden below 646 edit.modes = connection.modes; 647 if (hitSlash_) { // everything after '/' is nullified 648 edit.descriptor = DataEdit::ListDirectedNullValue; 649 return edit; 650 } 651 char32_t comma{','}; 652 if (io.mutableModes().editingFlags & decimalComma) { 653 comma = ';'; 654 } 655 if (remaining_ > 0 && !realPart_) { // "r*c" repetition in progress 656 while (connection.currentRecordNumber > initialRecordNumber_) { 657 io.BackspaceRecord(); 658 } 659 connection.HandleAbsolutePosition(initialPositionInRecord_); 660 if (!imaginaryPart_) { 661 edit.repeat = std::min<int>(remaining_, maxRepeat); 662 auto ch{io.GetNextNonBlank()}; 663 if (!ch || *ch == ' ' || *ch == '\t' || *ch == comma) { 664 // "r*" repeated null 665 edit.descriptor = DataEdit::ListDirectedNullValue; 666 } 667 } 668 remaining_ -= edit.repeat; 669 return edit; 670 } 671 // Skip separators, handle a "r*c" repeat count; see 13.10.2 in Fortran 2018 672 auto ch{io.GetNextNonBlank()}; 673 if (imaginaryPart_) { 674 imaginaryPart_ = false; 675 } else if (realPart_) { 676 realPart_ = false; 677 imaginaryPart_ = true; 678 edit.descriptor = DataEdit::ListDirectedImaginaryPart; 679 } 680 if (!ch) { 681 return std::nullopt; 682 } 683 if (*ch == '/') { 684 hitSlash_ = true; 685 edit.descriptor = DataEdit::ListDirectedNullValue; 686 return edit; 687 } 688 bool isFirstItem{isFirstItem_}; 689 isFirstItem_ = false; 690 if (*ch == comma) { 691 if (isFirstItem) { 692 edit.descriptor = DataEdit::ListDirectedNullValue; 693 return edit; 694 } 695 // Consume comma & whitespace after previous item. 696 // This includes the comma between real and imaginary components 697 // in list-directed/NAMELIST complex input. 698 io.HandleRelativePosition(1); 699 ch = io.GetNextNonBlank(); 700 if (!ch) { 701 return std::nullopt; 702 } 703 if (*ch == comma || *ch == '/') { 704 edit.descriptor = DataEdit::ListDirectedNullValue; 705 return edit; 706 } 707 } 708 if (imaginaryPart_) { // can't repeat components 709 return edit; 710 } 711 if (*ch >= '0' && *ch <= '9') { // look for "r*" repetition count 712 auto start{connection.positionInRecord}; 713 int r{0}; 714 do { 715 static auto constexpr clamp{(std::numeric_limits<int>::max() - '9') / 10}; 716 if (r >= clamp) { 717 r = 0; 718 break; 719 } 720 r = 10 * r + (*ch - '0'); 721 io.HandleRelativePosition(1); 722 ch = io.GetCurrentChar(); 723 } while (ch && *ch >= '0' && *ch <= '9'); 724 if (r > 0 && ch && *ch == '*') { // subtle: r must be nonzero 725 io.HandleRelativePosition(1); 726 ch = io.GetCurrentChar(); 727 if (ch && *ch == '/') { // r*/ 728 hitSlash_ = true; 729 edit.descriptor = DataEdit::ListDirectedNullValue; 730 return edit; 731 } 732 if (!ch || *ch == ' ' || *ch == '\t' || *ch == comma) { // "r*" null 733 edit.descriptor = DataEdit::ListDirectedNullValue; 734 } 735 edit.repeat = std::min<int>(r, maxRepeat); 736 remaining_ = r - edit.repeat; 737 initialRecordNumber_ = connection.currentRecordNumber; 738 initialPositionInRecord_ = connection.positionInRecord; 739 } else { // not a repetition count, just an integer value; rewind 740 connection.positionInRecord = start; 741 } 742 } 743 if (!imaginaryPart_ && ch && *ch == '(') { 744 realPart_ = true; 745 io.HandleRelativePosition(1); 746 edit.descriptor = DataEdit::ListDirectedRealPart; 747 } 748 return edit; 749 } 750 751 template <Direction DIR> 752 bool ExternalUnformattedIoStatementState<DIR>::Receive( 753 char *data, std::size_t bytes, std::size_t elementBytes) { 754 if constexpr (DIR == Direction::Output) { 755 this->Crash("ExternalUnformattedIoStatementState::Receive() called for " 756 "output statement"); 757 } 758 return this->unit().Receive(data, bytes, elementBytes, *this); 759 } 760 761 template <Direction DIR> 762 ChildIoStatementState<DIR>::ChildIoStatementState( 763 ChildIo &child, const char *sourceFile, int sourceLine) 764 : IoStatementBase{sourceFile, sourceLine}, child_{child} {} 765 766 template <Direction DIR> 767 MutableModes &ChildIoStatementState<DIR>::mutableModes() { 768 return child_.parent().mutableModes(); 769 } 770 771 template <Direction DIR> 772 ConnectionState &ChildIoStatementState<DIR>::GetConnectionState() { 773 return child_.parent().GetConnectionState(); 774 } 775 776 template <Direction DIR> 777 ExternalFileUnit *ChildIoStatementState<DIR>::GetExternalFileUnit() const { 778 return child_.parent().GetExternalFileUnit(); 779 } 780 781 template <Direction DIR> int ChildIoStatementState<DIR>::EndIoStatement() { 782 auto result{IoStatementBase::EndIoStatement()}; 783 child_.EndIoStatement(); // annihilates *this in child_.u_ 784 return result; 785 } 786 787 template <Direction DIR> 788 bool ChildIoStatementState<DIR>::Emit( 789 const char *data, std::size_t bytes, std::size_t elementBytes) { 790 return child_.parent().Emit(data, bytes, elementBytes); 791 } 792 793 template <Direction DIR> 794 bool ChildIoStatementState<DIR>::Emit(const char *data, std::size_t bytes) { 795 return child_.parent().Emit(data, bytes); 796 } 797 798 template <Direction DIR> 799 bool ChildIoStatementState<DIR>::Emit(const char16_t *data, std::size_t chars) { 800 return child_.parent().Emit(data, chars); 801 } 802 803 template <Direction DIR> 804 bool ChildIoStatementState<DIR>::Emit(const char32_t *data, std::size_t chars) { 805 return child_.parent().Emit(data, chars); 806 } 807 808 template <Direction DIR> 809 std::optional<char32_t> ChildIoStatementState<DIR>::GetCurrentChar() { 810 return child_.parent().GetCurrentChar(); 811 } 812 813 template <Direction DIR> 814 void ChildIoStatementState<DIR>::HandleAbsolutePosition(std::int64_t n) { 815 return child_.parent().HandleAbsolutePosition(n); 816 } 817 818 template <Direction DIR> 819 void ChildIoStatementState<DIR>::HandleRelativePosition(std::int64_t n) { 820 return child_.parent().HandleRelativePosition(n); 821 } 822 823 template <Direction DIR, typename CHAR> 824 ChildFormattedIoStatementState<DIR, CHAR>::ChildFormattedIoStatementState( 825 ChildIo &child, const CHAR *format, std::size_t formatLength, 826 const char *sourceFile, int sourceLine) 827 : ChildIoStatementState<DIR>{child, sourceFile, sourceLine}, 828 mutableModes_{child.parent().mutableModes()}, format_{*this, format, 829 formatLength} {} 830 831 template <Direction DIR, typename CHAR> 832 int ChildFormattedIoStatementState<DIR, CHAR>::EndIoStatement() { 833 format_.Finish(*this); 834 return ChildIoStatementState<DIR>::EndIoStatement(); 835 } 836 837 template <Direction DIR, typename CHAR> 838 bool ChildFormattedIoStatementState<DIR, CHAR>::AdvanceRecord(int) { 839 return false; // no can do in a child I/O 840 } 841 842 template <Direction DIR> 843 bool ChildUnformattedIoStatementState<DIR>::Receive( 844 char *data, std::size_t bytes, std::size_t elementBytes) { 845 return this->child().parent().Receive(data, bytes, elementBytes); 846 } 847 848 template class InternalIoStatementState<Direction::Output>; 849 template class InternalIoStatementState<Direction::Input>; 850 template class InternalFormattedIoStatementState<Direction::Output>; 851 template class InternalFormattedIoStatementState<Direction::Input>; 852 template class InternalListIoStatementState<Direction::Output>; 853 template class InternalListIoStatementState<Direction::Input>; 854 template class ExternalIoStatementState<Direction::Output>; 855 template class ExternalIoStatementState<Direction::Input>; 856 template class ExternalFormattedIoStatementState<Direction::Output>; 857 template class ExternalFormattedIoStatementState<Direction::Input>; 858 template class ExternalListIoStatementState<Direction::Output>; 859 template class ExternalListIoStatementState<Direction::Input>; 860 template class ExternalUnformattedIoStatementState<Direction::Output>; 861 template class ExternalUnformattedIoStatementState<Direction::Input>; 862 template class ChildIoStatementState<Direction::Output>; 863 template class ChildIoStatementState<Direction::Input>; 864 template class ChildFormattedIoStatementState<Direction::Output>; 865 template class ChildFormattedIoStatementState<Direction::Input>; 866 template class ChildListIoStatementState<Direction::Output>; 867 template class ChildListIoStatementState<Direction::Input>; 868 template class ChildUnformattedIoStatementState<Direction::Output>; 869 template class ChildUnformattedIoStatementState<Direction::Input>; 870 871 int ExternalMiscIoStatementState::EndIoStatement() { 872 ExternalFileUnit &ext{unit()}; 873 switch (which_) { 874 case Flush: 875 ext.FlushOutput(*this); 876 std::fflush(nullptr); // flushes C stdio output streams (12.9(2)) 877 break; 878 case Backspace: 879 ext.BackspaceRecord(*this); 880 break; 881 case Endfile: 882 ext.Endfile(*this); 883 break; 884 case Rewind: 885 ext.Rewind(*this); 886 break; 887 } 888 return ExternalIoStatementBase::EndIoStatement(); 889 } 890 891 InquireUnitState::InquireUnitState( 892 ExternalFileUnit &unit, const char *sourceFile, int sourceLine) 893 : ExternalIoStatementBase{unit, sourceFile, sourceLine} {} 894 895 bool InquireUnitState::Inquire( 896 InquiryKeywordHash inquiry, char *result, std::size_t length) { 897 if (unit().createdForInternalChildIo()) { 898 SignalError(IostatInquireInternalUnit, 899 "INQUIRE of unit created for defined derived type I/O of an internal " 900 "unit"); 901 return false; 902 } 903 const char *str{nullptr}; 904 switch (inquiry) { 905 case HashInquiryKeyword("ACCESS"): 906 switch (unit().access) { 907 case Access::Sequential: 908 str = "SEQUENTIAL"; 909 break; 910 case Access::Direct: 911 str = "DIRECT"; 912 break; 913 case Access::Stream: 914 str = "STREAM"; 915 break; 916 } 917 break; 918 case HashInquiryKeyword("ACTION"): 919 str = unit().mayWrite() ? unit().mayRead() ? "READWRITE" : "WRITE" : "READ"; 920 break; 921 case HashInquiryKeyword("ASYNCHRONOUS"): 922 str = unit().mayAsynchronous() ? "YES" : "NO"; 923 break; 924 case HashInquiryKeyword("BLANK"): 925 str = unit().isUnformatted.value_or(true) ? "UNDEFINED" 926 : unit().modes.editingFlags & blankZero ? "ZERO" 927 : "NULL"; 928 break; 929 case HashInquiryKeyword("CARRIAGECONTROL"): 930 str = "LIST"; 931 break; 932 case HashInquiryKeyword("CONVERT"): 933 str = unit().swapEndianness() ? "SWAP" : "NATIVE"; 934 break; 935 case HashInquiryKeyword("DECIMAL"): 936 str = unit().isUnformatted.value_or(true) ? "UNDEFINED" 937 : unit().modes.editingFlags & decimalComma ? "COMMA" 938 : "POINT"; 939 break; 940 case HashInquiryKeyword("DELIM"): 941 if (unit().isUnformatted.value_or(true)) { 942 str = "UNDEFINED"; 943 } else { 944 switch (unit().modes.delim) { 945 case '\'': 946 str = "APOSTROPHE"; 947 break; 948 case '"': 949 str = "QUOTE"; 950 break; 951 default: 952 str = "NONE"; 953 break; 954 } 955 } 956 break; 957 case HashInquiryKeyword("DIRECT"): 958 str = unit().access == Access::Direct || 959 (unit().mayPosition() && unit().isFixedRecordLength) 960 ? "YES" 961 : "NO"; 962 break; 963 case HashInquiryKeyword("ENCODING"): 964 str = unit().isUnformatted.value_or(true) ? "UNDEFINED" 965 : unit().isUTF8 ? "UTF-8" 966 : "ASCII"; 967 break; 968 case HashInquiryKeyword("FORM"): 969 str = !unit().isUnformatted ? "UNKNOWN" 970 : *unit().isUnformatted ? "UNFORMATTED" 971 : "FORMATTED"; 972 break; 973 case HashInquiryKeyword("FORMATTED"): 974 str = !unit().isUnformatted ? "UNKNOWN" 975 : *unit().isUnformatted ? "NO" 976 : "YES"; 977 break; 978 case HashInquiryKeyword("NAME"): 979 str = unit().path(); 980 if (!str) { 981 return true; // result is undefined 982 } 983 break; 984 case HashInquiryKeyword("PAD"): 985 str = unit().isUnformatted.value_or(true) ? "UNDEFINED" 986 : unit().modes.pad ? "YES" 987 : "NO"; 988 break; 989 case HashInquiryKeyword("POSITION"): 990 if (unit().access == Access::Direct) { 991 str = "UNDEFINED"; 992 } else { 993 auto size{unit().knownSize()}; 994 auto pos{unit().position()}; 995 if (pos == size.value_or(pos + 1)) { 996 str = "APPEND"; 997 } else if (pos == 0) { 998 str = "REWIND"; 999 } else { 1000 str = "ASIS"; // processor-dependent & no common behavior 1001 } 1002 } 1003 break; 1004 case HashInquiryKeyword("READ"): 1005 str = unit().mayRead() ? "YES" : "NO"; 1006 break; 1007 case HashInquiryKeyword("READWRITE"): 1008 str = unit().mayRead() && unit().mayWrite() ? "YES" : "NO"; 1009 break; 1010 case HashInquiryKeyword("ROUND"): 1011 if (unit().isUnformatted.value_or(true)) { 1012 str = "UNDEFINED"; 1013 } else { 1014 switch (unit().modes.round) { 1015 case decimal::FortranRounding::RoundNearest: 1016 str = "NEAREST"; 1017 break; 1018 case decimal::FortranRounding::RoundUp: 1019 str = "UP"; 1020 break; 1021 case decimal::FortranRounding::RoundDown: 1022 str = "DOWN"; 1023 break; 1024 case decimal::FortranRounding::RoundToZero: 1025 str = "ZERO"; 1026 break; 1027 case decimal::FortranRounding::RoundCompatible: 1028 str = "COMPATIBLE"; 1029 break; 1030 } 1031 } 1032 break; 1033 case HashInquiryKeyword("SEQUENTIAL"): 1034 // "NO" for Direct, since Sequential would not work if 1035 // the unit were reopened without RECL=. 1036 str = unit().access == Access::Sequential ? "YES" : "NO"; 1037 break; 1038 case HashInquiryKeyword("SIGN"): 1039 str = unit().isUnformatted.value_or(true) ? "UNDEFINED" 1040 : unit().modes.editingFlags & signPlus ? "PLUS" 1041 : "SUPPRESS"; 1042 break; 1043 case HashInquiryKeyword("STREAM"): 1044 str = unit().access == Access::Stream ? "YES" : "NO"; 1045 break; 1046 case HashInquiryKeyword("WRITE"): 1047 str = unit().mayWrite() ? "YES" : "NO"; 1048 break; 1049 case HashInquiryKeyword("UNFORMATTED"): 1050 str = !unit().isUnformatted ? "UNKNOWN" 1051 : *unit().isUnformatted ? "YES" 1052 : "NO"; 1053 break; 1054 } 1055 if (str) { 1056 ToFortranDefaultCharacter(result, length, str); 1057 return true; 1058 } else { 1059 BadInquiryKeywordHashCrash(inquiry); 1060 return false; 1061 } 1062 } 1063 1064 bool InquireUnitState::Inquire(InquiryKeywordHash inquiry, bool &result) { 1065 switch (inquiry) { 1066 case HashInquiryKeyword("EXIST"): 1067 result = true; 1068 return true; 1069 case HashInquiryKeyword("NAMED"): 1070 result = unit().path() != nullptr; 1071 return true; 1072 case HashInquiryKeyword("OPENED"): 1073 result = true; 1074 return true; 1075 case HashInquiryKeyword("PENDING"): 1076 result = false; // asynchronous I/O is not implemented 1077 return true; 1078 default: 1079 BadInquiryKeywordHashCrash(inquiry); 1080 return false; 1081 } 1082 } 1083 1084 bool InquireUnitState::Inquire( 1085 InquiryKeywordHash inquiry, std::int64_t, bool &result) { 1086 switch (inquiry) { 1087 case HashInquiryKeyword("PENDING"): 1088 result = false; // asynchronous I/O is not implemented 1089 return true; 1090 default: 1091 BadInquiryKeywordHashCrash(inquiry); 1092 return false; 1093 } 1094 } 1095 1096 bool InquireUnitState::Inquire( 1097 InquiryKeywordHash inquiry, std::int64_t &result) { 1098 switch (inquiry) { 1099 case HashInquiryKeyword("NEXTREC"): 1100 if (unit().access == Access::Direct) { 1101 result = unit().currentRecordNumber; 1102 } 1103 return true; 1104 case HashInquiryKeyword("NUMBER"): 1105 result = unit().unitNumber(); 1106 return true; 1107 case HashInquiryKeyword("POS"): 1108 result = unit().position(); 1109 return true; 1110 case HashInquiryKeyword("RECL"): 1111 if (unit().access == Access::Stream) { 1112 result = -2; 1113 } else if (unit().isFixedRecordLength && unit().recordLength) { 1114 result = *unit().recordLength; 1115 } else { 1116 result = std::numeric_limits<std::uint32_t>::max(); 1117 } 1118 return true; 1119 case HashInquiryKeyword("SIZE"): 1120 if (auto size{unit().knownSize()}) { 1121 result = *size; 1122 } else { 1123 result = -1; 1124 } 1125 return true; 1126 default: 1127 BadInquiryKeywordHashCrash(inquiry); 1128 return false; 1129 } 1130 } 1131 1132 InquireNoUnitState::InquireNoUnitState(const char *sourceFile, int sourceLine) 1133 : NoUnitIoStatementState{sourceFile, sourceLine, *this} {} 1134 1135 bool InquireNoUnitState::Inquire( 1136 InquiryKeywordHash inquiry, char *result, std::size_t length) { 1137 switch (inquiry) { 1138 case HashInquiryKeyword("ACCESS"): 1139 case HashInquiryKeyword("ACTION"): 1140 case HashInquiryKeyword("ASYNCHRONOUS"): 1141 case HashInquiryKeyword("BLANK"): 1142 case HashInquiryKeyword("CARRIAGECONTROL"): 1143 case HashInquiryKeyword("CONVERT"): 1144 case HashInquiryKeyword("DECIMAL"): 1145 case HashInquiryKeyword("DELIM"): 1146 case HashInquiryKeyword("FORM"): 1147 case HashInquiryKeyword("NAME"): 1148 case HashInquiryKeyword("PAD"): 1149 case HashInquiryKeyword("POSITION"): 1150 case HashInquiryKeyword("ROUND"): 1151 case HashInquiryKeyword("SIGN"): 1152 ToFortranDefaultCharacter(result, length, "UNDEFINED"); 1153 return true; 1154 case HashInquiryKeyword("DIRECT"): 1155 case HashInquiryKeyword("ENCODING"): 1156 case HashInquiryKeyword("FORMATTED"): 1157 case HashInquiryKeyword("READ"): 1158 case HashInquiryKeyword("READWRITE"): 1159 case HashInquiryKeyword("SEQUENTIAL"): 1160 case HashInquiryKeyword("STREAM"): 1161 case HashInquiryKeyword("WRITE"): 1162 case HashInquiryKeyword("UNFORMATTED"): 1163 ToFortranDefaultCharacter(result, length, "UNKNONN"); 1164 return true; 1165 default: 1166 BadInquiryKeywordHashCrash(inquiry); 1167 return false; 1168 } 1169 } 1170 1171 bool InquireNoUnitState::Inquire(InquiryKeywordHash inquiry, bool &result) { 1172 switch (inquiry) { 1173 case HashInquiryKeyword("EXIST"): 1174 result = true; 1175 return true; 1176 case HashInquiryKeyword("NAMED"): 1177 case HashInquiryKeyword("OPENED"): 1178 case HashInquiryKeyword("PENDING"): 1179 result = false; 1180 return true; 1181 default: 1182 BadInquiryKeywordHashCrash(inquiry); 1183 return false; 1184 } 1185 } 1186 1187 bool InquireNoUnitState::Inquire( 1188 InquiryKeywordHash inquiry, std::int64_t, bool &result) { 1189 switch (inquiry) { 1190 case HashInquiryKeyword("PENDING"): 1191 result = false; 1192 return true; 1193 default: 1194 BadInquiryKeywordHashCrash(inquiry); 1195 return false; 1196 } 1197 } 1198 1199 bool InquireNoUnitState::Inquire( 1200 InquiryKeywordHash inquiry, std::int64_t &result) { 1201 switch (inquiry) { 1202 case HashInquiryKeyword("NEXTREC"): 1203 case HashInquiryKeyword("NUMBER"): 1204 case HashInquiryKeyword("POS"): 1205 case HashInquiryKeyword("RECL"): 1206 case HashInquiryKeyword("SIZE"): 1207 result = -1; 1208 return true; 1209 default: 1210 BadInquiryKeywordHashCrash(inquiry); 1211 return false; 1212 } 1213 } 1214 1215 InquireUnconnectedFileState::InquireUnconnectedFileState( 1216 OwningPtr<char> &&path, const char *sourceFile, int sourceLine) 1217 : NoUnitIoStatementState{sourceFile, sourceLine, *this}, path_{std::move( 1218 path)} {} 1219 1220 bool InquireUnconnectedFileState::Inquire( 1221 InquiryKeywordHash inquiry, char *result, std::size_t length) { 1222 const char *str{nullptr}; 1223 switch (inquiry) { 1224 case HashInquiryKeyword("ACCESS"): 1225 case HashInquiryKeyword("ACTION"): 1226 case HashInquiryKeyword("ASYNCHRONOUS"): 1227 case HashInquiryKeyword("BLANK"): 1228 case HashInquiryKeyword("CARRIAGECONTROL"): 1229 case HashInquiryKeyword("CONVERT"): 1230 case HashInquiryKeyword("DECIMAL"): 1231 case HashInquiryKeyword("DELIM"): 1232 case HashInquiryKeyword("FORM"): 1233 case HashInquiryKeyword("PAD"): 1234 case HashInquiryKeyword("POSITION"): 1235 case HashInquiryKeyword("ROUND"): 1236 case HashInquiryKeyword("SIGN"): 1237 str = "UNDEFINED"; 1238 break; 1239 case HashInquiryKeyword("DIRECT"): 1240 case HashInquiryKeyword("ENCODING"): 1241 case HashInquiryKeyword("FORMATTED"): 1242 case HashInquiryKeyword("SEQUENTIAL"): 1243 case HashInquiryKeyword("STREAM"): 1244 case HashInquiryKeyword("UNFORMATTED"): 1245 str = "UNKNONN"; 1246 break; 1247 case HashInquiryKeyword("READ"): 1248 str = MayRead(path_.get()) ? "YES" : "NO"; 1249 break; 1250 case HashInquiryKeyword("READWRITE"): 1251 str = MayReadAndWrite(path_.get()) ? "YES" : "NO"; 1252 break; 1253 case HashInquiryKeyword("WRITE"): 1254 str = MayWrite(path_.get()) ? "YES" : "NO"; 1255 break; 1256 case HashInquiryKeyword("NAME"): 1257 str = path_.get(); 1258 return true; 1259 } 1260 if (str) { 1261 ToFortranDefaultCharacter(result, length, str); 1262 return true; 1263 } else { 1264 BadInquiryKeywordHashCrash(inquiry); 1265 return false; 1266 } 1267 } 1268 1269 bool InquireUnconnectedFileState::Inquire( 1270 InquiryKeywordHash inquiry, bool &result) { 1271 switch (inquiry) { 1272 case HashInquiryKeyword("EXIST"): 1273 result = IsExtant(path_.get()); 1274 return true; 1275 case HashInquiryKeyword("NAMED"): 1276 result = true; 1277 return true; 1278 case HashInquiryKeyword("OPENED"): 1279 result = false; 1280 return true; 1281 case HashInquiryKeyword("PENDING"): 1282 result = false; 1283 return true; 1284 default: 1285 BadInquiryKeywordHashCrash(inquiry); 1286 return false; 1287 } 1288 } 1289 1290 bool InquireUnconnectedFileState::Inquire( 1291 InquiryKeywordHash inquiry, std::int64_t, bool &result) { 1292 switch (inquiry) { 1293 case HashInquiryKeyword("PENDING"): 1294 result = false; 1295 return true; 1296 default: 1297 BadInquiryKeywordHashCrash(inquiry); 1298 return false; 1299 } 1300 } 1301 1302 bool InquireUnconnectedFileState::Inquire( 1303 InquiryKeywordHash inquiry, std::int64_t &result) { 1304 switch (inquiry) { 1305 case HashInquiryKeyword("NEXTREC"): 1306 case HashInquiryKeyword("NUMBER"): 1307 case HashInquiryKeyword("POS"): 1308 case HashInquiryKeyword("RECL"): 1309 case HashInquiryKeyword("SIZE"): 1310 result = -1; 1311 return true; 1312 default: 1313 BadInquiryKeywordHashCrash(inquiry); 1314 return false; 1315 } 1316 } 1317 1318 InquireIOLengthState::InquireIOLengthState( 1319 const char *sourceFile, int sourceLine) 1320 : NoUnitIoStatementState{sourceFile, sourceLine, *this} {} 1321 1322 } // namespace Fortran::runtime::io 1323