2020-02-05 08:55:45 +08:00
|
|
|
//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
// Fortran I/O connection state (abstracted over internal & external units)
|
2020-02-05 08:55:45 +08:00
|
|
|
|
|
|
|
#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
|
|
|
|
#define FORTRAN_RUNTIME_IO_CONNECTION_H_
|
|
|
|
|
|
|
|
#include "format.h"
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
namespace Fortran::runtime::io {
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
enum class Direction { Output, Input };
|
2020-02-05 08:55:45 +08:00
|
|
|
enum class Access { Sequential, Direct, Stream };
|
|
|
|
|
|
|
|
inline bool IsRecordFile(Access a) { return a != Access::Stream; }
|
|
|
|
|
|
|
|
// These characteristics of a connection are immutable after being
|
|
|
|
// established in an OPEN statement.
|
|
|
|
struct ConnectionAttributes {
|
2020-03-29 12:00:16 +08:00
|
|
|
Access access{Access::Sequential}; // ACCESS='SEQUENTIAL', 'DIRECT', 'STREAM'
|
|
|
|
bool isUnformatted{false}; // FORM='UNFORMATTED'
|
|
|
|
bool isUTF8{false}; // ENCODING='UTF-8'
|
2020-07-03 05:11:14 +08:00
|
|
|
bool isFixedRecordLength{false}; // RECL= on OPEN
|
|
|
|
std::optional<std::int64_t> recordLength; // RECL= or current record
|
2020-02-05 08:55:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectionState : public ConnectionAttributes {
|
2020-03-29 12:00:16 +08:00
|
|
|
bool IsAtEOF() const; // true when read has hit EOF or endfile record
|
2020-02-05 08:55:45 +08:00
|
|
|
std::size_t RemainingSpaceInRecord() const;
|
2020-02-14 06:41:56 +08:00
|
|
|
void HandleAbsolutePosition(std::int64_t);
|
|
|
|
void HandleRelativePosition(std::int64_t);
|
|
|
|
|
2020-07-03 05:11:14 +08:00
|
|
|
void BeginRecord() {
|
|
|
|
positionInRecord = 0;
|
|
|
|
furthestPositionInRecord = 0;
|
|
|
|
leftTabLimit.reset();
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
// Positions in a record file (sequential or direct, not stream)
|
2020-03-29 12:00:16 +08:00
|
|
|
std::int64_t currentRecordNumber{1}; // 1 is first
|
|
|
|
std::int64_t positionInRecord{0}; // offset in current record
|
2020-06-19 03:19:49 +08:00
|
|
|
std::int64_t furthestPositionInRecord{0}; // max(position+bytes)
|
2020-03-29 12:00:16 +08:00
|
|
|
bool nonAdvancing{false}; // ADVANCE='NO'
|
2020-02-14 06:41:56 +08:00
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
// Set at end of non-advancing I/O data transfer
|
2020-03-29 12:00:16 +08:00
|
|
|
std::optional<std::int64_t> leftTabLimit; // offset in current record
|
2020-02-14 06:41:56 +08:00
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
// currentRecordNumber value captured after ENDFILE/REWIND/BACKSPACE statement
|
2020-02-14 06:41:56 +08:00
|
|
|
// or an end-of-file READ condition on a sequential access file
|
2020-02-05 08:55:45 +08:00
|
|
|
std::optional<std::int64_t> endfileRecordNumber;
|
2020-02-14 06:41:56 +08:00
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
// Mutable modes set at OPEN() that can be overridden in READ/WRITE & FORMAT
|
2020-03-29 12:00:16 +08:00
|
|
|
MutableModes modes; // BLANK=, DECIMAL=, SIGN=, ROUND=, PAD=, DELIM=, kP
|
2020-02-05 08:55:45 +08:00
|
|
|
};
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime::io
|
|
|
|
#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_
|