llvm/flang/runtime/namelist.h
peter klausler b8452dba28 [flang] Support NAMELIST input of short arrays
NAMELIST array input does not need to fully define an array.
If another input item begins after at least one element,
it ends input into the array and the remaining items are
not modified.

The tricky part of supporting this feature is that it's not
always easy to determine whether the next non-blank thing in
the input is a value or the next item's name, esp. in the case
of logical data where T and F can be names.  E.g.,

  &group logicalArray = t f f t
      = 1 /

should read three elements into "logicalArray" and then read
an integer or real variable named "t".

So the I/O runtime has to do some look-ahead to determine whether
the next thing in the input is a name followed by '=', '(', or '%'.
Since the '=' may be on a later record, possibly with intervening
NAMELIST comments, the runtime has to support a general form of
saving and restoring its current position.  The infrastructure
in the I/O runtime already has to support repositioning for
list-directed repetition, even on non-positionable input sources
like terminals and sockets; this patch adds an internal RAII API
to make it easier to save a position and then do arbitrary
look-ahead.

Differential Revision: https://reviews.llvm.org/D112245
2021-10-22 13:38:11 -07:00

45 lines
1.5 KiB
C++

//===-- runtime/namelist.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
//
//===----------------------------------------------------------------------===//
// Defines the data structure used for NAMELIST I/O
#ifndef FORTRAN_RUNTIME_NAMELIST_H_
#define FORTRAN_RUNTIME_NAMELIST_H_
#include <cstddef>
namespace Fortran::runtime {
class Descriptor;
class IoStatementState;
} // namespace Fortran::runtime
namespace Fortran::runtime::io {
// A NAMELIST group is a named ordered collection of distinct variable names.
// It is packaged by lowering into an instance of this class.
// If all the items are variables with fixed addresses, the NAMELIST group
// description can be in a read-only section.
class NamelistGroup {
public:
struct Item {
const char *name; // NUL-terminated lower-case
const Descriptor &descriptor;
};
const char *groupName; // NUL-terminated lower-case
std::size_t items;
const Item *item; // in original declaration order
};
// Look ahead on input for an identifier followed by a '=', '(', or '%'
// character; for use in disambiguating a name-like value (e.g. F or T) from a
// NAMELIST group item name. Always false when not reading a NAMELIST.
bool IsNamelistName(IoStatementState &);
} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_NAMELIST_H_