llvm/flang/runtime/internal-unit.h
Peter Klausler bafbae238a [flang] Initial UTF-8 support in runtime I/O
Implements UTF-8 encoding and decoding for external units
with OPEN(ENCODING='UTF-8').  This encoding applies to default
CHARACTER values that are not 7-bit ASCII as well as to
the wide CHARACTER kinds 2 and 4.  Basic testing is in place
via direct calls to the runtime I/O APIs, but serious checkout
awaits lowering support of the wide CHARACTER kinds.

Differential Revision: https://reviews.llvm.org/D122038
2022-03-22 11:48:14 -07:00

56 lines
1.9 KiB
C++

//===-- 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"
#include "flang/Runtime/descriptor.h"
#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.
template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
public:
using Scalar =
std::conditional_t<DIR == Direction::Input, const char *, char *>;
InternalDescriptorUnit(Scalar, std::size_t);
InternalDescriptorUnit(const Descriptor &, const Terminator &);
void EndIoStatement();
bool Emit(const char *, std::size_t, IoErrorHandler &);
std::size_t GetNextInputBytes(const char *&, IoErrorHandler &);
bool AdvanceRecord(IoErrorHandler &);
void BackspaceRecord(IoErrorHandler &);
private:
Descriptor &descriptor() { return staticDescriptor_.descriptor(); }
const Descriptor &descriptor() const {
return staticDescriptor_.descriptor();
}
Scalar CurrentRecord() const {
return descriptor().template ZeroBasedIndexedElement<char>(
currentRecordNumber - 1);
}
void BlankFillOutputRecord();
StaticDescriptor<maxRank, true /*addendum*/> staticDescriptor_;
};
extern template class InternalDescriptorUnit<Direction::Output>;
extern template class InternalDescriptorUnit<Direction::Input>;
} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_