blob: 7f4f11e976f6a13e7204cb167b1809db668b5ec5 [file] [log] [blame]
peter klausler95696d52020-02-05 00:55:451//===-- runtime/internal-unit.h ---------------------------------*- 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// Fortran internal I/O "units"
10
11#ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
12#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
13
14#include "connection.h"
15#include "descriptor.h"
16#include <cinttypes>
17#include <type_traits>
18
19namespace Fortran::runtime::io {
20
21class IoErrorHandler;
22
23// Points to (but does not own) a CHARACTER scalar or array for internal I/O.
24// Does not buffer.
peter klausler3b635712020-02-13 22:41:5625template<Direction DIR> class InternalDescriptorUnit : public ConnectionState {
peter klausler95696d52020-02-05 00:55:4526public:
peter klausler3b635712020-02-13 22:41:5627 using Scalar =
28 std::conditional_t<DIR == Direction::Input, const char *, char *>;
peter klausler95696d52020-02-05 00:55:4529 InternalDescriptorUnit(Scalar, std::size_t);
30 InternalDescriptorUnit(const Descriptor &, const Terminator &);
31 void EndIoStatement();
32
peter klausler3b635712020-02-13 22:41:5633 bool Emit(const char *, std::size_t, IoErrorHandler &);
34 std::optional<char32_t> GetCurrentChar(IoErrorHandler &);
peter klausler95696d52020-02-05 00:55:4535 bool AdvanceRecord(IoErrorHandler &);
peter klausler3b635712020-02-13 22:41:5636 void BackspaceRecord(IoErrorHandler &);
peter klausler95696d52020-02-05 00:55:4537
38private:
39 Descriptor &descriptor() { return staticDescriptor_.descriptor(); }
peter klausler3b635712020-02-13 22:41:5640 const Descriptor &descriptor() const {
41 return staticDescriptor_.descriptor();
42 }
43 Scalar CurrentRecord() const {
44 return descriptor().template ZeroBasedIndexedElement<char>(
45 currentRecordNumber - 1);
46 }
peter klausler95696d52020-02-05 00:55:4547 StaticDescriptor<maxRank, true /*addendum*/> staticDescriptor_;
peter klausler95696d52020-02-05 00:55:4548};
49
peter klausler3b635712020-02-13 22:41:5650extern template class InternalDescriptorUnit<Direction::Output>;
51extern template class InternalDescriptorUnit<Direction::Input>;
peter klausler95696d52020-02-05 00:55:4552}
53#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_