1/* Copyright (C) 2009-2020 Free Software Foundation, Inc.
2   Contributed by Janne Blomqvist
3
4This file is part of the GNU Fortran runtime library (libgfortran).
5
6Libgfortran is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11Libgfortran is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23<http://www.gnu.org/licenses/>.  */
24
25#ifndef GFOR_FORMAT_H
26#define GFOR_FORMAT_H
27
28#include "io.h"
29
30/* Format nodes.  A format string is converted into a tree of these
31   structures, which is traversed as part of a data transfer statement.  */
32
33struct fnode
34{
35  format_token format;
36  int repeat;
37  struct fnode *next;
38  char *source;
39
40  union
41  {
42    struct
43    {
44      int w, d, e;
45    }
46    real;
47
48    struct
49    {
50      int length;
51      char *p;
52    }
53    string;
54
55    struct
56    {
57      int w, m;
58    }
59    integer;
60
61    struct
62    {
63      char *string;
64      int string_len;
65      gfc_full_array_i4 *vlist;
66    }
67    udf;  /* User Defined Format.  */
68
69    int w;
70    int k;
71    int r;
72    int n;
73
74    struct fnode *child;
75  }
76  u;
77
78  /* Members for traversing the tree during data transfer.  */
79
80  int count;
81  struct fnode *current;
82
83};
84
85
86/* A storage structures for format node data.  */
87
88#define FARRAY_SIZE 64
89
90typedef struct fnode_array
91{
92  struct fnode_array *next;
93  fnode array[FARRAY_SIZE];
94}
95fnode_array;
96
97
98typedef struct format_data
99{
100  char *format_string, *string;
101  const char *error;
102  char error_element;
103  format_token saved_token;
104  int value, format_string_len, reversion_ok;
105  fnode *avail;
106  const fnode *saved_format;
107  fnode_array *last;
108  fnode_array array;
109}
110format_data;
111
112extern void parse_format (st_parameter_dt *);
113internal_proto(parse_format);
114
115extern const fnode *next_format (st_parameter_dt *);
116internal_proto(next_format);
117
118extern void unget_format (st_parameter_dt *, const fnode *);
119internal_proto(unget_format);
120
121extern void format_error (st_parameter_dt *, const fnode *, const char *);
122internal_proto(format_error);
123
124extern void free_format_data (struct format_data *);
125internal_proto(free_format_data);
126
127extern void free_format (st_parameter_dt *);
128internal_proto(free_format);
129
130extern void free_format_hash_table (gfc_unit *);
131internal_proto(free_format_hash_table);
132
133extern void init_format_hash (st_parameter_dt *);
134internal_proto(init_format_hash);
135
136extern void free_format_hash (st_parameter_dt *);
137internal_proto(free_format_hash);
138
139#endif
140