format.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Janne Blomqvist
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgfortran is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef GFOR_FORMAT_H
  20. #define GFOR_FORMAT_H
  21. #include "io.h"
  22. /* Format tokens. Only about half of these can be stored in the
  23. format nodes. */
  24. typedef enum
  25. {
  26. FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
  27. FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL,
  28. FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING,
  29. FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F,
  30. FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END, FMT_DC,
  31. FMT_DP, FMT_STAR, FMT_RC, FMT_RD, FMT_RN, FMT_RP, FMT_RU, FMT_RZ
  32. }
  33. format_token;
  34. /* Format nodes. A format string is converted into a tree of these
  35. structures, which is traversed as part of a data transfer statement. */
  36. struct fnode
  37. {
  38. format_token format;
  39. int repeat;
  40. struct fnode *next;
  41. char *source;
  42. union
  43. {
  44. struct
  45. {
  46. int w, d, e;
  47. }
  48. real;
  49. struct
  50. {
  51. int length;
  52. char *p;
  53. }
  54. string;
  55. struct
  56. {
  57. int w, m;
  58. }
  59. integer;
  60. int w;
  61. int k;
  62. int r;
  63. int n;
  64. struct fnode *child;
  65. }
  66. u;
  67. /* Members for traversing the tree during data transfer. */
  68. int count;
  69. struct fnode *current;
  70. };
  71. /* A storage structures for format node data. */
  72. #define FARRAY_SIZE 64
  73. typedef struct fnode_array
  74. {
  75. struct fnode_array *next;
  76. fnode array[FARRAY_SIZE];
  77. }
  78. fnode_array;
  79. typedef struct format_data
  80. {
  81. char *format_string, *string;
  82. const char *error;
  83. char error_element;
  84. format_token saved_token;
  85. int value, format_string_len, reversion_ok;
  86. fnode *avail;
  87. const fnode *saved_format;
  88. fnode_array *last;
  89. fnode_array array;
  90. }
  91. format_data;
  92. extern void parse_format (st_parameter_dt *);
  93. internal_proto(parse_format);
  94. extern const fnode *next_format (st_parameter_dt *);
  95. internal_proto(next_format);
  96. extern void unget_format (st_parameter_dt *, const fnode *);
  97. internal_proto(unget_format);
  98. extern void format_error (st_parameter_dt *, const fnode *, const char *);
  99. internal_proto(format_error);
  100. extern void free_format_data (struct format_data *);
  101. internal_proto(free_format_data);
  102. extern void free_format_hash_table (gfc_unit *);
  103. internal_proto(free_format_hash_table);
  104. extern void init_format_hash (st_parameter_dt *);
  105. internal_proto(init_format_hash);
  106. extern void free_format_hash (st_parameter_dt *);
  107. internal_proto(free_format_hash);
  108. #endif