2020-02-05 08:55:45 +08:00
|
|
|
//===-- runtime/internal-unit.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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Fortran internal I/O "units"
|
|
|
|
|
|
|
|
#ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
|
|
|
|
#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
|
|
|
|
|
|
|
|
#include "connection.h"
|
2021-09-02 07:00:53 +08:00
|
|
|
#include "flang/Runtime/descriptor.h"
|
2020-02-05 08:55:45 +08:00
|
|
|
#include <cinttypes>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace Fortran::runtime::io {
|
|
|
|
|
|
|
|
class IoErrorHandler;
|
|
|
|
|
|
|
|
// Points to (but does not own) a CHARACTER scalar or array for internal I/O.
|
|
|
|
// Does not buffer.
|
2020-03-29 12:00:16 +08:00
|
|
|
template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
|
2020-02-05 08:55:45 +08:00
|
|
|
public:
|
2020-02-14 06:41:56 +08:00
|
|
|
using Scalar =
|
|
|
|
std::conditional_t<DIR == Direction::Input, const char *, char *>;
|
2020-02-05 08:55:45 +08:00
|
|
|
InternalDescriptorUnit(Scalar, std::size_t);
|
|
|
|
InternalDescriptorUnit(const Descriptor &, const Terminator &);
|
|
|
|
void EndIoStatement();
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
bool Emit(const char *, std::size_t, IoErrorHandler &);
|
2021-11-03 04:01:38 +08:00
|
|
|
std::size_t GetNextInputBytes(const char *&, IoErrorHandler &);
|
2020-02-05 08:55:45 +08:00
|
|
|
bool AdvanceRecord(IoErrorHandler &);
|
2020-02-14 06:41:56 +08:00
|
|
|
void BackspaceRecord(IoErrorHandler &);
|
2020-02-05 08:55:45 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Descriptor &descriptor() { return staticDescriptor_.descriptor(); }
|
2020-02-14 06:41:56 +08:00
|
|
|
const Descriptor &descriptor() const {
|
|
|
|
return staticDescriptor_.descriptor();
|
|
|
|
}
|
|
|
|
Scalar CurrentRecord() const {
|
|
|
|
return descriptor().template ZeroBasedIndexedElement<char>(
|
|
|
|
currentRecordNumber - 1);
|
|
|
|
}
|
2022-01-06 03:42:18 +08:00
|
|
|
void BlankFillOutputRecord();
|
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
StaticDescriptor<maxRank, true /*addendum*/> staticDescriptor_;
|
|
|
|
};
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
extern template class InternalDescriptorUnit<Direction::Output>;
|
|
|
|
extern template class InternalDescriptorUnit<Direction::Input>;
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime::io
|
|
|
|
#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
|