llvm-capstone/flang/runtime/non-tbp-dio.cpp
Peter Klausler 7cf1608b4d
[flang] Rework handling of non-type-bound user-defined I/O
A fairly recent introduction of runtime I/O APIs called OutputDerivedType()
and InputDerivedType() didn't cover NAMELIST I/O's need to access
non-type-bound generic interfaces for user-defined derived type I/O
when those generic interfaces are defined in some scope other than the
one that defines the derived type.

The patch adds a new data structure shared between lowering
and the runtime that can represent all of the cases that can
arise with non-type-bound defined I/O.  It can represent
scopes in which non-type-bound defined I/O generic interfaces
are inaccessible, too, due to IMPORT statements.

The data structure is now an operand to OutputDerivedType() and
InputDerivedType() as well as a data member in the NamelistGroup
structure.

Differential Revision: https://reviews.llvm.org/D148257
2023-04-13 15:35:01 -07:00

33 lines
1.0 KiB
C++

//===-- flang/runtime/non-tbp-dio.cpp ---------------------------*- 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
//
//===----------------------------------------------------------------------===//
#include "non-tbp-dio.h"
#include "type-info.h"
namespace Fortran::runtime::io {
const NonTbpDefinedIo *NonTbpDefinedIoTable::Find(
const typeInfo::DerivedType &type, common::DefinedIo definedIo) const {
std::size_t j{items};
for (const auto *p{item}; j-- > 0; ++p) {
if (&p->derivedType == &type && p->definedIo == definedIo) {
return p;
} else if (p->isDtvArgPolymorphic) {
for (const typeInfo::DerivedType *t{type.GetParentType()}; t;
t = t->GetParentType()) {
if (&p->derivedType == t && p->definedIo == definedIo) {
return p;
}
}
}
}
return nullptr;
}
} // namespace Fortran::runtime::io