[clangd] Fix erroneous qualification of template type parameters (#116821)
[llvm-project.git] / flang / runtime / connection.cpp
blobf24f0e832eb484c36af17ca93d63e7130b9683bc
1 //===-- runtime/connection.cpp --------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "connection.h"
10 #include "environment.h"
11 #include "io-stmt.h"
12 #include <algorithm>
14 namespace Fortran::runtime::io {
15 RT_OFFLOAD_API_GROUP_BEGIN
17 RT_API_ATTRS std::size_t ConnectionState::RemainingSpaceInRecord() const {
18 auto recl{recordLength.value_or(openRecl.value_or(
19 executionEnvironment.listDirectedOutputLineLengthLimit))};
20 return positionInRecord >= recl ? 0 : recl - positionInRecord;
23 RT_API_ATTRS bool ConnectionState::NeedAdvance(std::size_t width) const {
24 return positionInRecord > 0 && width > RemainingSpaceInRecord();
27 RT_API_ATTRS bool ConnectionState::IsAtEOF() const {
28 return endfileRecordNumber && currentRecordNumber >= *endfileRecordNumber;
31 RT_API_ATTRS bool ConnectionState::IsAfterEndfile() const {
32 return endfileRecordNumber && currentRecordNumber > *endfileRecordNumber;
35 RT_API_ATTRS void ConnectionState::HandleAbsolutePosition(std::int64_t n) {
36 positionInRecord = std::max(n, std::int64_t{0}) + leftTabLimit.value_or(0);
39 RT_API_ATTRS void ConnectionState::HandleRelativePosition(std::int64_t n) {
40 positionInRecord = std::max(leftTabLimit.value_or(0), positionInRecord + n);
43 SavedPosition::SavedPosition(IoStatementState &io) : io_{io} {
44 ConnectionState &conn{io_.GetConnectionState()};
45 saved_ = conn;
46 conn.pinnedFrame = true;
49 SavedPosition::~SavedPosition() {
50 if (!cancelled_) {
51 ConnectionState &conn{io_.GetConnectionState()};
52 while (conn.currentRecordNumber > saved_.currentRecordNumber) {
53 io_.BackspaceRecord();
55 conn.leftTabLimit = saved_.leftTabLimit;
56 conn.furthestPositionInRecord = saved_.furthestPositionInRecord;
57 conn.positionInRecord = saved_.positionInRecord;
58 conn.pinnedFrame = saved_.pinnedFrame;
62 RT_OFFLOAD_API_GROUP_END
63 } // namespace Fortran::runtime::io