xref: /llvm-project/flang/runtime/namelist.h (revision 8ebf741136c66f51053315bf4f0ef828c6f66094)
1 //===-- runtime/namelist.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 // Defines the data structure used for NAMELIST I/O
10 
11 #ifndef FORTRAN_RUNTIME_NAMELIST_H_
12 #define FORTRAN_RUNTIME_NAMELIST_H_
13 
14 #include "non-tbp-dio.h"
15 #include "flang/Common/api-attrs.h"
16 
17 #include <cstddef>
18 
19 namespace Fortran::runtime {
20 class Descriptor;
21 class IoStatementState;
22 } // namespace Fortran::runtime
23 
24 namespace Fortran::runtime::io {
25 
26 // A NAMELIST group is a named ordered collection of distinct variable names.
27 // It is packaged by lowering into an instance of this class.
28 // If all the items are variables with fixed addresses, the NAMELIST group
29 // description can be in a read-only section.
30 class NamelistGroup {
31 public:
32   struct Item {
33     const char *name; // NUL-terminated lower-case
34     const Descriptor &descriptor;
35   };
36   const char *groupName{nullptr}; // NUL-terminated lower-case
37   std::size_t items{0};
38   const Item *item{nullptr}; // in original declaration order
39 
40   // When the uses of a namelist group appear in scopes with distinct sets
41   // of non-type-bound defined formatted I/O interfaces, they require the
42   // use of distinct NamelistGroups pointing to distinct NonTbpDefinedIoTables.
43   // Multiple NamelistGroup instances may share a NonTbpDefinedIoTable..
44   const NonTbpDefinedIoTable *nonTbpDefinedIo{nullptr};
45 };
46 
47 // Look ahead on input for a '/' or an identifier followed by a '=', '(', or '%'
48 // character; for use in disambiguating a name-like value (e.g. F or T) from a
49 // NAMELIST group item name and for coping with short arrays.  Always false
50 // when not reading a NAMELIST.
51 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
52 
53 } // namespace Fortran::runtime::io
54 #endif // FORTRAN_RUNTIME_NAMELIST_H_
55