1 //===-- runtime/internal-unit.h ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Fortran internal I/O "units"
11 #ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
12 #define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
14 #include "connection.h"
15 #include "flang/Runtime/descriptor.h"
17 #include <type_traits>
19 namespace Fortran::runtime::io
{
23 // Points to (but does not own) a CHARACTER scalar or array for internal I/O.
25 template <Direction
DIR> class InternalDescriptorUnit
: public ConnectionState
{
28 std::conditional_t
<DIR == Direction::Input
, const char *, char *>;
29 InternalDescriptorUnit(Scalar
, std::size_t chars
, int kind
);
30 InternalDescriptorUnit(const Descriptor
&, const Terminator
&);
31 void EndIoStatement();
33 bool Emit(const char *, std::size_t, IoErrorHandler
&);
34 std::size_t GetNextInputBytes(const char *&, IoErrorHandler
&);
35 bool AdvanceRecord(IoErrorHandler
&);
36 void BackspaceRecord(IoErrorHandler
&);
37 std::int64_t InquirePos();
40 Descriptor
&descriptor() { return staticDescriptor_
.descriptor(); }
41 const Descriptor
&descriptor() const {
42 return staticDescriptor_
.descriptor();
44 Scalar
CurrentRecord() const {
45 return descriptor().template ZeroBasedIndexedElement
<char>(
46 currentRecordNumber
- 1);
48 void BlankFill(char *, std::size_t);
49 void BlankFillOutputRecord();
51 StaticDescriptor
<maxRank
, true /*addendum*/> staticDescriptor_
;
54 extern template class InternalDescriptorUnit
<Direction::Output
>;
55 extern template class InternalDescriptorUnit
<Direction::Input
>;
56 } // namespace Fortran::runtime::io
57 #endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_