2011-08-19 Andrew Stubbs <ams@codesourcery.com>
[official-gcc.git] / gcc / gengtype-state.c
blob5a5939dec85fd7e121e8600264ab36a560133928
1 /* Gengtype persistent state serialization & de-serialization.
2 Useful for gengtype in plugin mode.
4 Copyright (C) 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>.
22 Contributed by Jeremie Salvucci <jeremie.salvucci@free.fr>
23 and Basile Starynkevitch <basile@starynkevitch.net>
26 #ifdef GENERATOR_FILE
27 #include "bconfig.h"
28 #else
29 #include "config.h"
30 #endif
31 #include "system.h"
32 #include "errors.h" /* For fatal. */
33 #include "double-int.h"
34 #include "hashtab.h"
35 #include "version.h" /* For version_string & pkgversion_string. */
36 #include "obstack.h"
37 #include "gengtype.h"
41 /* Gives the file location of a type, if any. */
42 static inline struct fileloc*
43 type_lineloc (const_type_p ty)
45 if (!ty)
46 return NULL;
47 switch (ty->kind)
49 case TYPE_NONE:
50 gcc_unreachable ();
51 case TYPE_STRUCT:
52 case TYPE_UNION:
53 case TYPE_LANG_STRUCT:
54 return CONST_CAST (struct fileloc*, &ty->u.s.line);
55 case TYPE_PARAM_STRUCT:
56 return CONST_CAST (struct fileloc*, &ty->u.param_struct.line);
57 case TYPE_SCALAR:
58 case TYPE_STRING:
59 case TYPE_POINTER:
60 case TYPE_ARRAY:
61 return NULL;
62 default:
63 gcc_unreachable ();
67 /* The state file has simplistic lispy lexical tokens. Its lexer gives
68 a linked list of struct state_token_st, thru the peek_state_token
69 function. Lexical tokens are consumed with next_state_tokens. */
72 /* The lexical kind of each lispy token. */
73 enum state_token_en
75 STOK_NONE, /* Never used. */
76 STOK_INTEGER, /* Integer token. */
77 STOK_STRING, /* String token. */
78 STOK_LEFTPAR, /* Left opening parenthesis. */
79 STOK_RIGHTPAR, /* Right closing parenthesis. */
80 STOK_NAME /* hash-consed name or identifier. */
84 /* Structure and hash-table used to share identifiers or names. */
85 struct state_ident_st
87 /* TODO: We could improve the parser by reserving identifiers for
88 state keywords and adding a keyword number for them. That would
89 mean adding another field in this state_ident_st struct. */
90 char stid_name[1]; /* actually bigger & null terminated */
92 static htab_t state_ident_tab;
95 /* The state_token_st structure is for lexical tokens in the read
96 state file. The stok_kind field discriminates the union. Tokens
97 are allocated by peek_state_token which calls read_a_state_token
98 which allocate them. Tokens are freed by calls to
99 next_state_tokens. Token are organized in a FIFO look-ahead queue
100 filled by peek_state_token. */
101 struct state_token_st
103 enum state_token_en stok_kind; /* the lexical kind
104 discriminates the stok_un
105 union */
106 int stok_line; /* the line number */
107 int stok_col; /* the column number */
108 const char *stok_file; /* the file path */
109 struct state_token_st *stok_next; /* the next token in the
110 queue, when peeked */
111 union /* discriminated by stok_kind! */
113 int stok_num; /* when STOK_INTEGER */
114 char stok_string[1]; /* when STOK_STRING, actual size is
115 bigger and null terminated */
116 struct state_ident_st *stok_ident; /* when STOK_IDENT */
117 void *stok_ptr; /* null otherwise */
119 stok_un;
125 #define NULL_STATE_TOKEN (struct state_token_st*)0
127 /* the state_token pointer contains the leftmost current token. The
128 tokens are organized in a linked queue, using stok_next, for token
129 look-ahead. */
130 struct state_token_st *state_token = NULL_STATE_TOKEN;
132 /* Used by the reading lexer. */
133 static FILE *state_file;
134 static const char *state_path = NULL;
135 static int state_line = 0;
136 static long state_bol = 0; /* offset of beginning of line */
139 /* Counter of written types. */
140 static int state_written_type_count = 0;
143 /* Fatal error messages when reading the state. They are extremely
144 unlikely, and only appear when this gengtype-state.c file is buggy,
145 or when reading a gengtype state which was not generated by the
146 same version of gengtype or GCC. */
149 /* Fatal message while reading state. */
150 static inline void
151 fatal_reading_state (struct state_token_st* tok, const char*msg)
153 if (tok)
154 fatal ("%s:%d:%d: Invalid state file; %s",
155 tok->stok_file, tok->stok_line, tok->stok_col,
156 msg);
157 else
158 fatal ("%s:%d: Invalid state file; %s",
159 state_path, state_line, msg);
163 /* Fatal printf-like message while reading state. This can't be a
164 function, because there is no way to pass a va_arg to a variant of
165 fatal. */
166 #define fatal_reading_state_printf(Tok,Fmt,...) do { \
167 struct state_token_st* badtok = Tok; \
168 if (badtok) \
169 fatal ("%s:%d:%d: Invalid state file; " Fmt, \
170 badtok->stok_file, \
171 badtok->stok_line, \
172 badtok->stok_col, __VA_ARGS__); \
173 else \
174 fatal ("%s:%d: Invalid state file; " Fmt, \
175 state_path, state_line, __VA_ARGS__); \
176 } while(0)
179 /* Find or allocate an identifier in our name hash table. */
180 static struct state_ident_st *
181 state_ident_by_name (const char *name, enum insert_option optins)
183 PTR *slot = NULL;
184 int namlen = 0;
185 struct state_ident_st *stid = NULL;
187 if (!name || !name[0])
188 return NULL;
190 slot = htab_find_slot (state_ident_tab, name, optins);
191 if (!slot)
192 return NULL;
194 namlen = strlen (name);
195 stid =
196 (struct state_ident_st *) xmalloc (sizeof (struct state_ident_st) +
197 namlen);
198 memset (stid, 0, sizeof (struct state_ident_st) + namlen);
199 strcpy (stid->stid_name, name);
200 *slot = stid;
202 return stid;
205 /* Our token lexer is heavily inspired by MELT's lexer, and share some
206 code with the file gcc/melt-runtime.c of the GCC MELT branch! We
207 really want the gengtype state to be easily parsable by MELT. This
208 is a usual lispy lexing routine, dealing with spaces and comments,
209 numbers, parenthesis, names, strings. */
210 static struct state_token_st *
211 read_a_state_token (void)
213 int c = 0;
214 long curoff = 0;
215 struct state_token_st *tk = NULL;
217 again: /* Read again, e.g. after a comment or spaces. */
218 c = getc (state_file);
219 if (c == EOF)
220 return NULL;
222 /* Handle spaces, count lines. */
223 if (c == '\n')
225 state_line++;
226 state_bol = curoff = ftell (state_file);
227 goto again;
229 if (ISSPACE (c))
230 goto again;
231 /* Skip comments starting with semi-colon. */
232 if (c == ';')
236 c = getc (state_file);
238 while (c > 0 && c != '\n');
239 if (c == '\n')
241 state_line++;
242 state_bol = curoff = ftell (state_file);
244 goto again;
246 /* Read signed numbers. */
247 if (ISDIGIT (c) || c == '-' || c == '+')
248 { /* number */
249 int n = 0;
250 ungetc (c, state_file);
251 curoff = ftell (state_file);
252 if (fscanf (state_file, "%d", &n) <= 0)
253 fatal_reading_state (NULL_STATE_TOKEN, "Lexical error in number");
254 tk = XCNEW (struct state_token_st);
255 tk->stok_kind = STOK_INTEGER;
256 tk->stok_line = state_line;
257 tk->stok_col = curoff - state_bol;
258 tk->stok_file = state_path;
259 tk->stok_next = NULL;
260 tk->stok_un.stok_num = n;
262 return tk;
264 /* Read an opening left parenthesis. */
265 else if (c == '(')
267 curoff = ftell (state_file);
268 tk = XCNEW (struct state_token_st);
269 tk->stok_kind = STOK_LEFTPAR;
270 tk->stok_line = state_line;
271 tk->stok_col = curoff - state_bol;
272 tk->stok_file = state_path;
273 tk->stok_next = NULL;
275 return tk;
277 /* Read an closing right parenthesis. */
278 else if (c == ')')
280 curoff = ftell (state_file);
281 tk = XCNEW (struct state_token_st);
282 tk->stok_kind = STOK_RIGHTPAR;
283 tk->stok_line = state_line;
284 tk->stok_col = curoff - state_bol;
285 tk->stok_file = state_path;
286 tk->stok_next = NULL;
288 return tk;
290 /* Read identifiers, using an obstack. */
291 else if (ISALPHA (c) || c == '_' || c == '$' || c == '!' || c == '#')
293 struct obstack id_obstack;
294 struct state_ident_st *sid = NULL;
295 char *ids = NULL;
296 obstack_init (&id_obstack);
297 curoff = ftell (state_file);
298 while (ISALNUM (c) || c == '_' || c == '$' || c == '!' || c == '#')
300 obstack_1grow (&id_obstack, c);
301 c = getc (state_file);
302 if (c < 0)
303 break;
305 if (c >= 0)
306 ungetc (c, state_file);
307 obstack_1grow (&id_obstack, (char) 0);
308 ids = XOBFINISH (&id_obstack, char *);
309 sid = state_ident_by_name (ids, INSERT);
310 obstack_free (&id_obstack, NULL);
311 ids = NULL;
312 tk = XCNEW (struct state_token_st);
313 tk->stok_kind = STOK_NAME;
314 tk->stok_line = state_line;
315 tk->stok_col = curoff - state_bol;
316 tk->stok_file = state_path;
317 tk->stok_next = NULL;
318 tk->stok_un.stok_ident = sid;
320 return tk;
322 /* Read a string, dealing with escape sequences a la C! */
323 else if (c == '"')
325 char *cstr = NULL;
326 int cslen = 0;
327 struct obstack bstring_obstack;
328 obstack_init (&bstring_obstack);
329 curoff = ftell (state_file);
330 while ((c = getc (state_file)) != '"' && c >= 0)
332 if (ISPRINT (c) && c != '\\')
333 obstack_1grow (&bstring_obstack, (char) c);
334 else if (ISSPACE (c) && c != '\n')
335 obstack_1grow (&bstring_obstack, (char) c);
336 else if (c == '\\')
338 c = getc (state_file);
339 switch (c)
341 case 'a':
342 obstack_1grow (&bstring_obstack, '\a');
343 c = getc (state_file);
344 break;
345 case 'b':
346 obstack_1grow (&bstring_obstack, '\b');
347 c = getc (state_file);
348 break;
349 case 't':
350 obstack_1grow (&bstring_obstack, '\t');
351 c = getc (state_file);
352 break;
353 case 'n':
354 obstack_1grow (&bstring_obstack, '\n');
355 c = getc (state_file);
356 break;
357 case 'v':
358 obstack_1grow (&bstring_obstack, '\v');
359 c = getc (state_file);
360 break;
361 case 'f':
362 obstack_1grow (&bstring_obstack, '\f');
363 c = getc (state_file);
364 break;
365 case 'r':
366 obstack_1grow (&bstring_obstack, '\r');
367 c = getc (state_file);
368 break;
369 case '"':
370 obstack_1grow (&bstring_obstack, '\"');
371 c = getc (state_file);
372 break;
373 case '\\':
374 obstack_1grow (&bstring_obstack, '\\');
375 c = getc (state_file);
376 break;
377 case ' ':
378 obstack_1grow (&bstring_obstack, ' ');
379 c = getc (state_file);
380 break;
381 case 'x':
383 unsigned int cx = 0;
384 if (fscanf (state_file, "%02x", &cx) > 0 && cx > 0)
385 obstack_1grow (&bstring_obstack, cx);
386 else
387 fatal_reading_state
388 (NULL_STATE_TOKEN,
389 "Lexical error in string hex escape");
390 c = getc (state_file);
391 break;
393 default:
394 fatal_reading_state
395 (NULL_STATE_TOKEN,
396 "Lexical error - unknown string escape");
399 else
400 fatal_reading_state (NULL_STATE_TOKEN, "Lexical error...");
402 if (c != '"')
403 fatal_reading_state (NULL_STATE_TOKEN, "Unterminated string");
404 obstack_1grow (&bstring_obstack, '\0');
405 cstr = XOBFINISH (&bstring_obstack, char *);
406 cslen = strlen (cstr);
407 tk = (struct state_token_st *)
408 xcalloc (sizeof (struct state_token_st) + cslen, 1);
409 tk->stok_kind = STOK_STRING;
410 tk->stok_line = state_line;
411 tk->stok_col = curoff - state_bol;
412 tk->stok_file = state_path;
413 tk->stok_next = NULL;
414 strcpy (tk->stok_un.stok_string, cstr);
415 obstack_free (&bstring_obstack, NULL);
417 return tk;
419 /* Got an unexpected character. */
420 fatal_reading_state_printf
421 (NULL_STATE_TOKEN,
422 "Lexical error at offset %ld - bad character \\%03o = '%c'",
423 ftell (state_file), c, c);
426 /* Used for lexical look-ahead. Retrieves the lexical token of rank
427 DEPTH, starting with 0 when reading the state file. Gives null on
428 end of file. */
429 static struct state_token_st *
430 peek_state_token (int depth)
432 int remdepth = depth;
433 struct state_token_st **ptoken = &state_token;
434 struct state_token_st *tok = NULL;
436 while (remdepth >= 0)
438 if (*ptoken == NULL)
440 *ptoken = tok = read_a_state_token ();
441 if (tok == NULL)
442 return NULL;
444 tok = *ptoken;
445 ptoken = &((*ptoken)->stok_next);
446 remdepth--;
449 return tok;
452 /* Consume the next DEPTH tokens and free them. */
453 static void
454 next_state_tokens (int depth)
456 struct state_token_st *n;
458 while (depth > 0)
460 if (state_token != NULL)
462 n = state_token->stok_next;
463 free (state_token);
464 state_token = n;
466 else
467 fatal_reading_state (NULL_STATE_TOKEN, "Tokens stack empty");
469 depth--;
473 /* Safely retrieve the lexical kind of a token. */
474 static inline enum state_token_en
475 state_token_kind (struct state_token_st *p)
477 if (p == NULL)
478 return STOK_NONE;
479 else
480 return p->stok_kind;
483 /* Test if a token is a given name i.e. an identifier. */
484 static inline bool
485 state_token_is_name (struct state_token_st *p, const char *name)
487 if (p == NULL)
488 return false;
490 if (p->stok_kind != STOK_NAME)
491 return false;
493 return !strcmp (p->stok_un.stok_ident->stid_name, name);
497 /* Following routines are useful for serializing datas.
499 * We want to serialize :
500 * - typedefs list
501 * - structures list
502 * - param_structs list
503 * - variables list
505 * So, we have one routine for each kind of data. The main writing
506 * routine is write_state. The main reading routine is
507 * read_state. Most writing routines write_state_FOO have a
508 * corresponding reading routine read_state_FOO. Reading is done in a
509 * recursive descending way, and any read error is fatal.
512 /* When reading the state, we need to remember the previously seen
513 types by their state_number, since GTY-ed types are usually
514 shared. */
515 static htab_t state_seen_types;
517 /* Return the length of a linked list made of pairs. */
518 static int pair_list_length (pair_p list);
520 /* Write a pair */
521 static void write_state_pair (pair_p);
523 /* return the number of pairs written. Should match the length given
524 by pair_list_length. */
525 static int write_state_pair_list (pair_p list);
527 /* Write a type. When a type is written, its state_number is updated,
528 to ensure that a "reference" to a seen type is written on next
529 occurrences. */
530 static void write_state_type (type_p);
532 /* Write a null-terminatel string using our Lispy lexical conventions,
533 similar to those of C or MELT. */
534 static void write_state_a_string (const char *s);
536 /* Compute the length of a list of pairs, starting from the first
537 one. */
538 static int
539 pair_list_length (pair_p list)
541 int nbpair = 0;
542 pair_p l = NULL;
543 for (l = list; l; l = l->next)
544 nbpair++;
545 return nbpair;
548 /* Write a file location. Files relative to $(srcdir) are quite
549 frequent and are handled specially. This ensures that two gengtype
550 state file-s produced by gengtype on the same GCC source tree are
551 very similar and can be reasonably compared with diff, even if the
552 two GCC source trees have different absolute paths. */
553 static void
554 write_state_fileloc (struct fileloc *floc)
557 if (floc != NULL && floc->line > 0)
559 const char *srcrelpath = NULL;
560 gcc_assert (floc->file != NULL);
561 /* Most of the files are inside $(srcdir) so it is worth to
562 handle them specially. */
563 srcrelpath = get_file_srcdir_relative_path (floc->file);
564 if (srcrelpath != NULL)
566 fprintf (state_file, "\n(!srcfileloc ");
567 write_state_a_string (srcrelpath);
569 else
571 fprintf (state_file, "\n(!fileloc ");
572 write_state_a_string (get_input_file_name (floc->file));
574 fprintf (state_file, " %d", floc->line);
575 fprintf (state_file, ")\n");
577 else
578 fprintf (state_file, "nil ");
581 /* Write a list of fields. */
582 static void
583 write_state_fields (pair_p fields)
585 int nbfields = pair_list_length (fields);
586 int nbpairs = 0;
587 fprintf (state_file, "\n(!fields %d ", nbfields);
588 nbpairs = write_state_pair_list (fields);
589 gcc_assert (nbpairs == nbfields);
590 fprintf (state_file, ")\n");
593 /* Write a null-terminated string in our lexical convention, very
594 similar to the convention of C. */
595 static void
596 write_state_a_string (const char *s)
598 char c;
600 fputs (" \"", state_file);
601 for (; *s != 0; s++)
603 c = *s;
604 switch (c)
606 case '\a':
607 fputs ("\\a", state_file);
608 break;
609 case '\b':
610 fputs ("\\b", state_file);
611 break;
612 case '\t':
613 fputs ("\\t", state_file);
614 break;
615 case '\n':
616 fputs ("\\n", state_file);
617 break;
618 case '\v':
619 fputs ("\\v", state_file);
620 break;
621 case '\f':
622 fputs ("\\f", state_file);
623 break;
624 case '\r':
625 fputs ("\\r", state_file);
626 break;
627 case '\"':
628 fputs ("\\\"", state_file);
629 break;
630 case '\\':
631 fputs ("\\\\", state_file);
632 break;
633 default:
634 if (ISPRINT (c))
635 putc (c, state_file);
636 else
637 fprintf (state_file, "\\x%02x", (unsigned) c);
640 fputs ("\"", state_file);
643 /* Our option-s have three kinds, each with its writer. */
644 static void
645 write_state_string_option (options_p current)
647 fprintf (state_file, "string ");
648 if (current->info.string != NULL)
649 write_state_a_string (current->info.string);
650 else
651 fprintf (state_file, " nil ");
654 static void
655 write_state_type_option (options_p current)
657 fprintf (state_file, "type ");
658 write_state_type (current->info.type);
661 static void
662 write_state_nested_option (options_p current)
664 fprintf (state_file, "nested ");
665 write_state_type (current->info.nested->type);
666 if (current->info.nested->convert_from != NULL)
667 write_state_a_string (current->info.nested->convert_from);
668 else
669 fprintf (state_file, " nil ");
671 if (current->info.nested->convert_to != NULL)
672 write_state_a_string (current->info.nested->convert_to);
673 else
674 fprintf (state_file, " nil ");
677 static void
678 write_state_option (options_p current)
680 fprintf (state_file, "\n(!option ");
682 if (current->name != NULL)
683 fprintf (state_file, "%s ", current->name);
684 else
685 fprintf (state_file, "nil ");
687 switch (current->kind)
689 case OPTION_STRING:
690 write_state_string_option (current);
691 break;
692 case OPTION_TYPE:
693 write_state_type_option (current);
694 break;
695 case OPTION_NESTED:
696 write_state_nested_option (current);
697 break;
698 default:
699 fatal ("Option tag unknown");
702 fprintf (state_file, ")\n");
707 /* Write a list of GTY options. */
708 static void
709 write_state_options (options_p opt)
711 options_p current;
713 if (opt == NULL)
715 fprintf (state_file, "nil ");
716 return;
719 fprintf (state_file, "\n(!options ");
720 for (current = opt; current != NULL; current = current->next)
721 write_state_option (current);
722 fprintf (state_file, ")\n");
726 /* Write a bitmap representing a set of GCC front-end languages. */
727 static void
728 write_state_lang_bitmap (lang_bitmap bitmap)
730 fprintf (state_file, "%d ", (int) bitmap);
733 /* Write version information. */
734 static void
735 write_state_version (const char *version)
737 fprintf (state_file, "\n(!version ");
738 write_state_a_string (version);
739 fprintf (state_file, ")\n");
742 /* Common routine to write the common content of all types. */
743 static void write_state_common_type_content (type_p current);
745 /* Write a scalar type. We have only two of these. */
746 static void
747 write_state_scalar_type (type_p current)
749 if (current == &scalar_nonchar)
750 fprintf (state_file, "scalar_nonchar ");
751 else if (current == &scalar_char)
752 fprintf (state_file, "scalar_char ");
753 else
754 fatal ("Unexpected type in write_state_scalar_type");
756 write_state_common_type_content (current);
759 /* Write the string type. There is only one such thing! */
760 static void
761 write_state_string_type (type_p current)
763 if (current == &string_type)
765 fprintf (state_file, "string ");
766 write_state_common_type_content (current);
768 else
769 fatal ("Unexpected type in write_state_string_type");
773 /* Common code to write structure like types. */
774 static void
775 write_state_struct_union_type (type_p current, const char *kindstr)
777 DBGPRINTF ("%s type @ %p #%d '%s'", kindstr, (void *) current,
778 current->state_number, current->u.s.tag);
779 fprintf (state_file, "%s ", kindstr);
780 write_state_common_type_content (current);
781 if (current->u.s.tag != NULL)
782 write_state_a_string (current->u.s.tag);
783 else
784 fprintf (state_file, "nil");
786 write_state_fileloc (type_lineloc (current));
787 write_state_fields (current->u.s.fields);
788 write_state_options (current->u.s.opt);
789 write_state_lang_bitmap (current->u.s.bitmap);
793 /* Write a GTY struct type. */
794 static void
795 write_state_struct_type (type_p current)
797 write_state_struct_union_type (current, "struct");
798 write_state_type (current->u.s.lang_struct);
801 /* write a GTY union type. */
802 static void
803 write_state_union_type (type_p current)
805 write_state_struct_union_type (current, "union");
806 write_state_type (current->u.s.lang_struct);
809 /* Write a lang_struct type. This is tricky and was painful to debug,
810 we deal with the next field specifically within their lang_struct
811 subfield, which points to a linked list of homonumous types.
812 Change this function with extreme care, see also
813 read_state_lang_struct_type. */
814 static void
815 write_state_lang_struct_type (type_p current)
817 int nbhomontype = 0;
818 type_p hty = NULL;
819 const char *homoname = 0;
820 write_state_struct_union_type (current, "lang_struct");
821 /* lang_struct-ures are particularily tricky, since their
822 u.s.lang_struct field gives a list of homonymous struct-s or
823 union-s! */
824 DBGPRINTF ("lang_struct @ %p #%d", (void *) current, current->state_number);
825 for (hty = current->u.s.lang_struct; hty != NULL; hty = hty->next)
827 nbhomontype++;
828 DBGPRINTF ("homonymous #%d hty @ %p #%d '%s'", nbhomontype,
829 (void *) hty, hty->state_number, hty->u.s.tag);
830 /* Every member of the homonymous list should have the same tag. */
831 gcc_assert (UNION_OR_STRUCT_P (hty));
832 gcc_assert (hty->u.s.lang_struct == current);
833 if (!homoname)
834 homoname = hty->u.s.tag;
835 gcc_assert (strcmp (homoname, hty->u.s.tag) == 0);
837 fprintf (state_file, "(!homotypes %d\n", nbhomontype);
838 for (hty = current->u.s.lang_struct; hty != NULL; hty = hty->next)
839 write_state_type (hty);
840 fprintf (state_file, ")\n");
843 /* Write a parametrized structure GTY type. */
844 static void
845 write_state_param_struct_type (type_p current)
847 int i;
849 fprintf (state_file, "param_struct ");
850 write_state_common_type_content (current);
851 write_state_type (current->u.param_struct.stru);
852 for (i = 0; i < NUM_PARAM; i++)
854 if (current->u.param_struct.param[i] != NULL)
855 write_state_type (current->u.param_struct.param[i]);
856 else
857 fprintf (state_file, "nil ");
859 write_state_fileloc (&current->u.param_struct.line);
862 /* Write a pointer type. */
863 static void
864 write_state_pointer_type (type_p current)
866 fprintf (state_file, "pointer ");
867 write_state_common_type_content (current);
868 write_state_type (current->u.p);
871 /* Write an array type. */
872 static void
873 write_state_array_type (type_p current)
875 fprintf (state_file, "array ");
876 write_state_common_type_content (current);
877 if (current->u.a.len != NULL)
878 write_state_a_string (current->u.a.len);
879 else
880 fprintf (state_file, " nil");
882 fprintf (state_file, " ");
883 write_state_type (current->u.a.p);
886 /* Write the gc_used information. */
887 static void
888 write_state_gc_used (enum gc_used_enum gus)
890 switch (gus)
892 case GC_UNUSED:
893 fprintf (state_file, " gc_unused");
894 break;
895 case GC_USED:
896 fprintf (state_file, " gc_used");
897 break;
898 case GC_MAYBE_POINTED_TO:
899 fprintf (state_file, " gc_maybe_pointed_to");
900 break;
901 case GC_POINTED_TO:
902 fprintf (state_file, " gc_pointed_to");
903 break;
904 default:
905 gcc_unreachable ();
909 /* Utility routine to write the common content of all types. Notice
910 that the next field is *not* written on purpose. */
911 static void
912 write_state_common_type_content (type_p current)
914 fprintf (state_file, "%d ", current->state_number);
915 /* We do not write the next type, because list of types are
916 explicitly written. However, lang_struct are special in that
917 respect. See function write_state_lang_struct_type for more. */
918 write_state_type (current->pointer_to);
919 write_state_gc_used (current->gc_used);
923 /* The important and recursive routine writing GTY types as understood
924 by gengtype. Types which have a positive state_number have already
925 been seen and written. */
926 static void
927 write_state_type (type_p current)
929 if (current == NULL)
931 fprintf (state_file, "nil ");
932 return;
935 fprintf (state_file, "\n(!type ");
937 if (current->state_number > 0)
938 fprintf (state_file, "already_seen %d", current->state_number);
939 else
941 state_written_type_count++;
942 DBGPRINTF ("writing type #%d @%p old number %d", state_written_type_count,
943 (void *) current, current->state_number);
944 current->state_number = state_written_type_count;
945 switch (current->kind)
947 case TYPE_STRUCT:
948 write_state_struct_type (current);
949 break;
950 case TYPE_UNION:
951 write_state_union_type (current);
952 break;
953 case TYPE_POINTER:
954 write_state_pointer_type (current);
955 break;
956 case TYPE_ARRAY:
957 write_state_array_type (current);
958 break;
959 case TYPE_LANG_STRUCT:
960 write_state_lang_struct_type (current);
961 break;
962 case TYPE_PARAM_STRUCT:
963 write_state_param_struct_type (current);
964 break;
965 case TYPE_SCALAR:
966 write_state_scalar_type (current);
967 break;
968 case TYPE_STRING:
969 write_state_string_type (current);
970 break;
972 default:
973 fatal ("Unexpected type...");
977 fprintf (state_file, ")\n");
981 /* Write a pair. */
982 static void
983 write_state_pair (pair_p current)
985 if (current == NULL)
987 fprintf (state_file, "nil)");
988 return;
991 fprintf (state_file, "\n(!pair ");
993 if (current->name != NULL)
994 write_state_a_string (current->name);
995 else
996 write_state_a_string ("nil");
998 write_state_type (current->type);
999 write_state_fileloc (&(current->line));
1000 write_state_options (current->opt);
1002 fprintf (state_file, ")");
1005 /* Write a pair list and return the number of pairs written. */
1006 static int
1007 write_state_pair_list (pair_p list)
1009 int nbpair = 0;
1010 pair_p current;
1012 for (current = list; current != NULL; current = current->next)
1014 write_state_pair (current);
1015 nbpair++;
1017 return nbpair;
1021 /* When writing imported linked lists, like typedefs, structures,
1022 param_structs, ... we count their length first and write it. These
1023 eases the reading, and enables an extra verification on the number
1024 of actually read items. */
1026 /* Write our typedefs. */
1027 static void
1028 write_state_typedefs (void)
1030 int nbtypedefs = pair_list_length (typedefs);
1031 int nbpairs = 0;
1032 fprintf (state_file, "\n(!typedefs %d\n", nbtypedefs);
1033 nbpairs = write_state_pair_list (typedefs);
1034 gcc_assert (nbpairs == nbtypedefs);
1035 fprintf (state_file, ")\n");
1036 if (verbosity_level >= 2)
1037 printf ("%s wrote %d typedefs\n", progname, nbtypedefs);
1040 /* Write our structures. */
1041 static void
1042 write_state_structures (void)
1044 int nbstruct = 0;
1045 type_p current;
1047 for (current = structures; current != NULL; current = current->next)
1048 nbstruct++;
1050 fprintf (state_file, "\n(!structures %d\n", nbstruct);
1052 for (current = structures; current != NULL; current = current->next)
1053 write_state_type (current);
1055 fprintf (state_file, ")\n");
1056 if (verbosity_level >= 2)
1057 printf ("%s wrote %d structures in state\n", progname, nbstruct);
1060 /* Write our param_struct-s. */
1061 static void
1062 write_state_param_structs (void)
1064 int nbparamstruct = 0;
1065 type_p current;
1067 for (current = param_structs; current != NULL; current = current->next)
1068 nbparamstruct++;
1070 fprintf (state_file, "\n(!param_structs %d\n", nbparamstruct);
1072 for (current = param_structs; current != NULL; current = current->next)
1073 write_state_type (current);
1075 fprintf (state_file, ")\n");
1078 /* Write our variables. */
1079 static void
1080 write_state_variables (void)
1082 int nbvars = pair_list_length (variables);
1083 int nbpairs = 0;
1084 fprintf (state_file, "\n(!variables %d\n", nbvars);
1085 nbpairs = write_state_pair_list (variables);
1086 gcc_assert (nbpairs == nbvars);
1087 fprintf (state_file, ")\n");
1088 if (verbosity_level >= 2)
1089 printf ("%s wrote %d variables.\n", progname, nbvars);
1092 /* Write the source directory. File locations within the source
1093 directory have been written specifically. */
1094 static void
1095 write_state_srcdir (void)
1097 fprintf (state_file, "\n(!srcdir ");
1098 write_state_a_string (srcdir);
1099 fprintf (state_file, ")\n");
1102 /* Count and write the list of our files. */
1103 static void
1104 write_state_files_list (void)
1106 int i = 0;
1107 /* Write the list of files with their lang_bitmap. */
1108 fprintf (state_file, "\n(!fileslist %d\n", (int) num_gt_files);
1109 for (i = 0; i < (int) num_gt_files; i++)
1111 const char *cursrcrelpath = NULL;
1112 const input_file *curfil = gt_files[i];
1113 /* Most of the files are inside $(srcdir) so it is worth to
1114 handle them specially. */
1115 cursrcrelpath = get_file_srcdir_relative_path (curfil);
1116 if (cursrcrelpath)
1118 fprintf (state_file, "(!srcfile %d ", get_lang_bitmap (curfil));
1119 write_state_a_string (cursrcrelpath);
1121 else
1123 fprintf (state_file, "(!file %d ", get_lang_bitmap (curfil));
1124 write_state_a_string (get_input_file_name (curfil));
1126 fprintf (state_file, ")\n");
1128 fprintf (state_file, ")\n");
1131 /* Write the list of GCC front-end languages. */
1132 static void
1133 write_state_languages (void)
1135 int i = 0;
1136 fprintf (state_file, "\n(!languages %d", (int) num_lang_dirs);
1137 for (i = 0; i < (int) num_lang_dirs; i++)
1139 /* Languages names are identifiers, we expect only letters or
1140 underscores or digits in them. In particular, C++ is not a
1141 valid language name, but cp is valid. */
1142 fprintf (state_file, " %s", lang_dir_names[i]);
1144 fprintf (state_file, ")\n");
1147 /* Write the trailer. */
1148 static void
1149 write_state_trailer (void)
1151 /* This test should probably catch IO errors like disk full... */
1152 if (fputs ("\n(!endfile)\n", state_file) == EOF)
1153 fatal ("failed to write state trailer [%s]", xstrerror (errno));
1156 /* The write_state routine is the only writing routine called by main
1157 in gengtype.c. To avoid messing the state if gengtype is
1158 interrupted or aborted, we write a temporary file and rename it
1159 after having written it in totality. */
1160 void
1161 write_state (const char *state_path)
1163 long statelen = 0;
1164 time_t now = 0;
1165 char *temp_state_path = NULL;
1166 char tempsuffix[40];
1167 time (&now);
1169 /* We write a unique temporary file which is renamed when complete
1170 * only. So even if gengtype is interrupted, the written state file
1171 * won't be partially written, since the temporary file is not yet
1172 * renamed in that case. */
1173 memset (tempsuffix, 0, sizeof (tempsuffix));
1174 snprintf (tempsuffix, sizeof (tempsuffix) - 1, "-%ld-%d.tmp", (long) now,
1175 (int) getpid ());
1176 temp_state_path = concat (state_path, tempsuffix, NULL);
1177 state_file = fopen (temp_state_path, "w");
1178 if (state_file == NULL)
1179 fatal ("Failed to open file %s for writing state: %s",
1180 temp_state_path, xstrerror (errno));
1181 if (verbosity_level >= 3)
1182 printf ("%s writing state file %s temporarily in %s\n",
1183 progname, state_path, temp_state_path);
1184 /* This is the first line of the state. Perhaps the file utility
1185 could know about that, so don't change it often. */
1186 fprintf (state_file, ";;;;@@@@ GCC gengtype state\n");
1187 /* Output a few comments for humans. */
1188 fprintf (state_file,
1189 ";;; DON'T EDIT THIS FILE, since generated by GCC's gengtype\n");
1190 fprintf (state_file,
1191 ";;; The format of this file is tied to a particular version of GCC.\n");
1192 fprintf (state_file,
1193 ";;; Don't parse this file wihout knowing GCC gengtype internals.\n");
1194 fprintf (state_file,
1195 ";;; This file should be parsed by the same %s which wrote it.\n",
1196 progname);
1197 fprintf (state_file, ";;; file %s generated on %s\n", state_path,
1198 ctime (&now));
1199 /* The first non-comment significant line gives the version string. */
1200 write_state_version (version_string);
1201 write_state_srcdir ();
1202 write_state_languages ();
1203 write_state_files_list ();
1204 write_state_structures ();
1205 write_state_typedefs ();
1206 write_state_param_structs ();
1207 write_state_variables ();
1208 write_state_trailer ();
1209 statelen = ftell (state_file);
1210 if (ferror (state_file))
1211 fatal ("output error when writing state file %s [%s]",
1212 temp_state_path, xstrerror (errno));
1213 if (fclose (state_file))
1214 fatal ("failed to close state file %s [%s]",
1215 temp_state_path, xstrerror (errno));
1216 if (rename (temp_state_path, state_path))
1217 fatal ("failed to rename %s to state file %s [%s]", temp_state_path,
1218 state_path, xstrerror (errno));
1219 free (temp_state_path);
1221 if (verbosity_level >= 1)
1222 printf ("%s wrote state file %s of %ld bytes with %d GTY-ed types\n",
1223 progname, state_path, statelen, state_written_type_count);
1227 /** End of writing routines! The corresponding reading routines follow. **/
1231 /* Forward declarations, since some read_state_* functions are
1232 recursive! */
1233 static void read_state_fileloc (struct fileloc *line);
1234 static void read_state_options (options_p *opt);
1235 static void read_state_type (type_p *current);
1236 static void read_state_pair (pair_p *pair);
1237 /* Return the number of pairs actually read. */
1238 static int read_state_pair_list (pair_p *list);
1239 static void read_state_fields (pair_p *fields);
1240 static void read_state_common_type_content (type_p current);
1245 /* Record into the state_seen_types hash-table a type which we are
1246 reading, to enable recursive or circular references to it. */
1247 static void
1248 record_type (type_p type)
1250 PTR *slot;
1252 slot = htab_find_slot (state_seen_types, type, INSERT);
1253 gcc_assert (slot);
1255 *slot = type;
1258 /* Read an already seen type. */
1259 static void
1260 read_state_already_seen_type (type_p *type)
1262 struct state_token_st *t0 = peek_state_token (0);
1264 if (state_token_kind (t0) == STOK_INTEGER)
1266 PTR *slot = NULL;
1267 struct type loctype = { TYPE_SCALAR, 0, 0, 0, GC_UNUSED, {0} };
1269 loctype.state_number = t0->stok_un.stok_num;
1270 slot = htab_find_slot (state_seen_types, &loctype, NO_INSERT);
1271 if (slot == NULL)
1273 fatal_reading_state (t0, "Unknown type");
1276 next_state_tokens (1);
1277 *type = (type_p) *slot;
1279 else
1281 fatal_reading_state (t0, "Bad seen type");
1286 /* Read the scalar_nonchar type. */
1287 static void
1288 read_state_scalar_nonchar_type (type_p *type)
1290 *type = &scalar_nonchar;
1291 read_state_common_type_content (*type);
1295 /* Read the scalar_char type. */
1296 static void
1297 read_state_scalar_char_type (type_p *type)
1299 *type = &scalar_char;
1300 read_state_common_type_content (*type);
1304 /* Read the string_type. */
1305 static void
1306 read_state_string_type (type_p *type)
1308 *type = &string_type;
1309 read_state_common_type_content (*type);
1313 /* Read a lang_bitmap representing a set of GCC front-end languages. */
1314 static void
1315 read_state_lang_bitmap (lang_bitmap *bitmap)
1317 struct state_token_st *t;
1319 t = peek_state_token (0);
1320 if (state_token_kind (t) == STOK_INTEGER)
1322 *bitmap = t->stok_un.stok_num;
1323 next_state_tokens (1);
1325 else
1327 fatal_reading_state (t, "Bad syntax for bitmap");
1332 /* Read a GTY-ed struct type. */
1333 static void
1334 read_state_struct_type (type_p type)
1336 struct state_token_st *t0;
1338 type->kind = TYPE_STRUCT;
1339 read_state_common_type_content (type);
1340 t0 = peek_state_token (0);
1341 if (state_token_kind (t0) == STOK_STRING)
1343 if (state_token_is_name (t0, "nil"))
1345 type->u.s.tag = NULL;
1346 DBGPRINTF ("read anonymous struct type @%p #%d",
1347 (void *) type, type->state_number);
1349 else
1351 type->u.s.tag = xstrdup (t0->stok_un.stok_string);
1352 DBGPRINTF ("read struct type @%p #%d '%s'",
1353 (void *) type, type->state_number, type->u.s.tag);
1356 next_state_tokens (1);
1357 read_state_fileloc (&(type->u.s.line));
1358 read_state_fields (&(type->u.s.fields));
1359 read_state_options (&(type->u.s.opt));
1360 read_state_lang_bitmap (&(type->u.s.bitmap));
1361 read_state_type (&(type->u.s.lang_struct));
1363 else
1365 fatal_reading_state (t0, "Bad tag in struct type");
1370 /* Read a GTY-ed union type. */
1371 static void
1372 read_state_union_type (type_p type)
1374 struct state_token_st *t0;
1376 type->kind = TYPE_UNION;
1377 read_state_common_type_content (type);
1378 t0 = peek_state_token (0);
1379 if (state_token_kind (t0) == STOK_STRING)
1381 if (state_token_is_name (t0, "nil"))
1383 type->u.s.tag = NULL;
1384 DBGPRINTF ("read anonymous union type @%p #%d",
1385 (void *) type, type->state_number);
1387 else
1389 type->u.s.tag = xstrdup (t0->stok_un.stok_string);
1390 DBGPRINTF ("read union type @%p #%d '%s'",
1391 (void *) type, type->state_number, type->u.s.tag);
1393 next_state_tokens (1);
1394 read_state_fileloc (&(type->u.s.line));
1395 read_state_fields (&(type->u.s.fields));
1396 read_state_options (&(type->u.s.opt));
1397 read_state_lang_bitmap (&(type->u.s.bitmap));
1398 read_state_type (&(type->u.s.lang_struct));
1400 else
1401 fatal_reading_state (t0, "Bad tag in union type");
1405 /* Read a GTY-ed pointer type. */
1406 static void
1407 read_state_pointer_type (type_p type)
1409 type->kind = TYPE_POINTER;
1410 read_state_common_type_content (type);
1411 DBGPRINTF ("read pointer type @%p #%d", (void *) type, type->state_number);
1412 read_state_type (&(type->u.p));
1416 /* Read a GTY-ed array type. */
1417 static void
1418 read_state_array_type (type_p type)
1420 struct state_token_st *t0;
1422 type->kind = TYPE_ARRAY;
1423 read_state_common_type_content (type);
1424 t0 = peek_state_token (0);
1425 if (state_token_kind (t0) == STOK_STRING)
1427 type->u.a.len = xstrdup (t0->stok_un.stok_string);
1428 DBGPRINTF ("read array type @%p #%d length '%s'",
1429 (void *) type, type->state_number, type->u.a.len);
1430 next_state_tokens (1);
1433 else if (state_token_is_name (t0, "nil"))
1435 type->u.a.len = NULL;
1436 DBGPRINTF ("read array type @%p #%d without length",
1437 (void *) type, type->state_number);
1438 next_state_tokens (1);
1441 else
1442 fatal_reading_state (t0, "Bad array name type");
1443 read_state_type (&(type->u.a.p));
1448 /* Read a lang_struct type for GTY-ed struct-s which depends upon GCC
1449 front-end languages. This is a tricky function and it was painful
1450 to debug. Change it with extreme care. See also
1451 write_state_lang_struct_type. */
1452 static void
1453 read_state_lang_struct_type (type_p type)
1455 struct state_token_st *t0 = NULL;
1456 struct state_token_st *t1 = NULL;
1457 struct state_token_st *t2 = NULL;
1459 type->kind = TYPE_LANG_STRUCT;
1460 read_state_common_type_content (type);
1461 t0 = peek_state_token (0);
1462 if (state_token_kind (t0) == STOK_STRING)
1464 if (state_token_is_name (t0, "nil"))
1466 DBGPRINTF ("read anonymous lang_struct type @%p #%d",
1467 (void *) type, type->state_number);
1468 type->u.s.tag = NULL;
1470 else
1472 type->u.s.tag = xstrdup (t0->stok_un.stok_string);
1473 DBGPRINTF ("read lang_struct type @%p #%d '%s'",
1474 (void *) type, type->state_number, type->u.s.tag);
1476 next_state_tokens (1);
1478 else
1479 fatal_reading_state (t0, "Bad tag in lang struct type");
1480 read_state_fileloc (&(type->u.s.line));
1481 read_state_fields (&(type->u.s.fields));
1482 read_state_options (&(type->u.s.opt));
1483 read_state_lang_bitmap (&(type->u.s.bitmap));
1484 /* Within lang_struct-ures, the lang_struct field is a linked list
1485 of homonymous types! */
1486 t0 = peek_state_token (0);
1487 t1 = peek_state_token (1);
1488 t2 = peek_state_token (2);
1489 /* Parse (!homotypes <number-types> <type-1> .... <type-n>) */
1490 if (state_token_kind (t0) == STOK_LEFTPAR
1491 && state_token_is_name (t1, "!homotypes")
1492 && state_token_kind (t2) == STOK_INTEGER)
1494 type_p *prevty = &type->u.s.lang_struct;
1495 int nbhomotype = t2->stok_un.stok_num;
1496 int i = 0;
1497 t0 = t1 = t2 = NULL;
1498 next_state_tokens (3);
1499 for (i = 0; i < nbhomotype; i++)
1501 read_state_type (prevty);
1502 t0 = peek_state_token (0);
1503 if (*prevty)
1504 prevty = &(*prevty)->next;
1505 else
1506 fatal_reading_state (t0,
1507 "expecting type in homotype list for lang_struct");
1509 if (state_token_kind (t0) != STOK_RIGHTPAR)
1510 fatal_reading_state (t0,
1511 "expecting ) in homotype list for lang_struct");
1512 next_state_tokens (1);
1514 else
1515 fatal_reading_state (t0, "expecting !homotypes for lang_struct");
1519 /* Read a param_struct type for GTY parametrized structures. */
1520 static void
1521 read_state_param_struct_type (type_p type)
1523 int i;
1524 struct state_token_st *t0;
1526 type->kind = TYPE_PARAM_STRUCT;
1527 read_state_common_type_content (type);
1528 DBGPRINTF ("read param_struct type @%p #%d",
1529 (void *) type, type->state_number);
1530 read_state_type (&(type->u.param_struct.stru));
1532 for (i = 0; i < NUM_PARAM; i++)
1534 t0 = peek_state_token (0);
1535 if (state_token_is_name (t0, "nil"))
1537 type->u.param_struct.param[i] = NULL;
1538 next_state_tokens (1);
1540 else
1541 read_state_type (&(type->u.param_struct.param[i]));
1543 read_state_fileloc (&(type->u.param_struct.line));
1547 /* Read the gc used information. */
1548 static void
1549 read_state_gc_used (enum gc_used_enum *pgus)
1551 struct state_token_st *t0 = peek_state_token (0);
1552 if (state_token_is_name (t0, "gc_unused"))
1553 *pgus = GC_UNUSED;
1554 else if (state_token_is_name (t0, "gc_used"))
1555 *pgus = GC_USED;
1556 else if (state_token_is_name (t0, "gc_maybe_pointed_to"))
1557 *pgus = GC_MAYBE_POINTED_TO;
1558 else if (state_token_is_name (t0, "gc_pointed_to"))
1559 *pgus = GC_POINTED_TO;
1560 else
1561 fatal_reading_state (t0, "invalid gc_used information");
1562 next_state_tokens (1);
1566 /* Utility function to read the common content of types. */
1567 static void
1568 read_state_common_type_content (type_p current)
1570 struct state_token_st *t0 = peek_state_token (0);
1572 if (state_token_kind (t0) == STOK_INTEGER)
1574 current->state_number = t0->stok_un.stok_num;
1575 next_state_tokens (1);
1576 record_type (current);
1578 else
1579 fatal_reading_state_printf (t0,
1580 "Expected integer for state_number line %d",
1581 state_line);
1582 /* We don't read the next field of the type. */
1583 read_state_type (&current->pointer_to);
1584 read_state_gc_used (&current->gc_used);
1588 /* Read a GTY-ed type. */
1589 void
1590 read_state_type (type_p *current)
1592 struct state_token_st *t0 = peek_state_token (0);
1593 struct state_token_st *t1 = peek_state_token (1);
1595 if (state_token_kind (t0) == STOK_LEFTPAR &&
1596 state_token_is_name (t1, "!type"))
1598 next_state_tokens (2);
1599 t0 = peek_state_token (0);
1600 if (state_token_is_name (t0, "already_seen"))
1602 next_state_tokens (1);
1603 read_state_already_seen_type (current);
1605 else
1607 t0 = peek_state_token (0);
1609 if (state_token_is_name (t0, "scalar_nonchar"))
1611 next_state_tokens (1);
1612 read_state_scalar_nonchar_type (current);
1614 else if (state_token_is_name (t0, "scalar_char"))
1616 next_state_tokens (1);
1617 read_state_scalar_char_type (current);
1619 else if (state_token_is_name (t0, "string"))
1621 next_state_tokens (1);
1622 read_state_string_type (current);
1624 else if (state_token_is_name (t0, "struct"))
1626 *current = XCNEW (struct type);
1627 next_state_tokens (1);
1628 read_state_struct_type (*current);
1630 else if (state_token_is_name (t0, "union"))
1632 *current = XCNEW (struct type);
1633 next_state_tokens (1);
1634 read_state_union_type (*current);
1636 else if (state_token_is_name (t0, "lang_struct"))
1638 *current = XCNEW (struct type);
1639 next_state_tokens (1);
1640 read_state_lang_struct_type (*current);
1642 else if (state_token_is_name (t0, "param_struct"))
1644 *current = XCNEW (struct type);
1645 next_state_tokens (1);
1646 read_state_param_struct_type (*current);
1648 else if (state_token_is_name (t0, "pointer"))
1650 *current = XCNEW (struct type);
1651 next_state_tokens (1);
1652 read_state_pointer_type (*current);
1654 else if (state_token_is_name (t0, "array"))
1656 *current = XCNEW (struct type);
1657 next_state_tokens (1);
1658 read_state_array_type (*current);
1660 else
1661 fatal_reading_state (t0, "bad type in (!type");
1663 t0 = peek_state_token (0);
1664 if (state_token_kind (t0) != STOK_RIGHTPAR)
1665 fatal_reading_state (t0, "missing ) in type");
1666 next_state_tokens (1);
1668 else if (state_token_is_name (t0, "nil"))
1670 next_state_tokens (1);
1671 *current = NULL;
1673 else
1674 fatal_reading_state (t0, "bad type syntax");
1678 /* Read a file location. Files within the source directory are dealt
1679 with specifically. */
1680 void
1681 read_state_fileloc (struct fileloc *floc)
1683 bool issrcfile = false;
1684 struct state_token_st *t0 = peek_state_token (0);
1685 struct state_token_st *t1 = peek_state_token (1);
1687 gcc_assert (floc != NULL);
1688 gcc_assert (srcdir != NULL);
1690 if (state_token_kind (t0) == STOK_LEFTPAR &&
1691 (state_token_is_name (t1, "!fileloc")
1692 || (issrcfile = state_token_is_name (t1, "!srcfileloc"))))
1694 next_state_tokens (2);
1695 t0 = peek_state_token (0);
1696 t1 = peek_state_token (1);
1697 if (state_token_kind (t0) == STOK_STRING &&
1698 state_token_kind (t1) == STOK_INTEGER)
1700 char *path = t0->stok_un.stok_string;
1701 if (issrcfile)
1703 static const char dirsepstr[2] = { DIR_SEPARATOR, (char) 0 };
1704 char *fullpath = concat (srcdir, dirsepstr, path, NULL);
1705 floc->file = input_file_by_name (fullpath);
1706 free (fullpath);
1708 else
1709 floc->file = input_file_by_name (path);
1710 floc->line = t1->stok_un.stok_num;
1711 next_state_tokens (2);
1713 else
1714 fatal_reading_state (t0,
1715 "Bad fileloc syntax, expected path string and line");
1716 t0 = peek_state_token (0);
1717 if (state_token_kind (t0) != STOK_RIGHTPAR)
1718 fatal_reading_state (t0, "Bad fileloc syntax, expected )");
1719 next_state_tokens (1);
1721 else if (state_token_is_name (t0, "nil"))
1723 next_state_tokens (1);
1724 floc->file = NULL;
1725 floc->line = 0;
1727 else
1728 fatal_reading_state (t0, "Bad fileloc syntax");
1732 /* Read the fields of a GTY-ed type. */
1733 void
1734 read_state_fields (pair_p *fields)
1736 pair_p tmp = NULL;
1737 struct state_token_st *t0 = peek_state_token (0);
1738 struct state_token_st *t1 = peek_state_token (1);
1739 struct state_token_st *t2 = peek_state_token (2);
1741 if (state_token_kind (t0) == STOK_LEFTPAR
1742 && state_token_is_name (t1, "!fields")
1743 && state_token_kind (t2) == STOK_INTEGER)
1745 int nbfields = t2->stok_un.stok_num;
1746 int nbpairs = 0;
1747 next_state_tokens (3);
1748 nbpairs = read_state_pair_list (&tmp);
1749 t0 = peek_state_token (0);
1750 if (nbpairs != nbfields)
1751 fatal_reading_state_printf
1752 (t0,
1753 "Mismatched fields number, expected %d got %d", nbpairs, nbfields);
1754 if (state_token_kind (t0) == STOK_RIGHTPAR)
1755 next_state_tokens (1);
1756 else
1757 fatal_reading_state (t0, "Bad fields expecting )");
1760 *fields = tmp;
1764 /* Read a string option. */
1765 static void
1766 read_state_string_option (options_p opt)
1768 struct state_token_st *t0 = peek_state_token (0);
1769 opt->kind = OPTION_STRING;
1770 if (state_token_kind (t0) == STOK_STRING)
1772 opt->info.string = xstrdup (t0->stok_un.stok_string);
1773 next_state_tokens (1);
1775 else if (state_token_is_name (t0, "nil"))
1777 opt->info.string = NULL;
1778 next_state_tokens (1);
1780 else
1781 fatal_reading_state (t0, "Missing name in string option");
1785 /* Read a type option. */
1786 static void
1787 read_state_type_option (options_p opt)
1789 opt->kind = OPTION_TYPE;
1790 read_state_type (&(opt->info.type));
1794 /* Read a nested option. */
1795 static void
1796 read_state_nested_option (options_p opt)
1798 struct state_token_st *t0;
1800 opt->info.nested = XCNEW (struct nested_ptr_data);
1801 opt->kind = OPTION_NESTED;
1802 read_state_type (&(opt->info.nested->type));
1803 t0 = peek_state_token (0);
1804 if (state_token_kind (t0) == STOK_STRING)
1806 opt->info.nested->convert_from = xstrdup (t0->stok_un.stok_string);
1807 next_state_tokens (1);
1809 else if (state_token_is_name (t0, "nil"))
1811 opt->info.nested->convert_from = NULL;
1812 next_state_tokens (1);
1814 else
1815 fatal_reading_state (t0, "Bad nested convert_from option");
1817 t0 = peek_state_token (0);
1818 if (state_token_kind (t0) == STOK_STRING)
1820 opt->info.nested->convert_to = xstrdup (t0->stok_un.stok_string);
1821 next_state_tokens (1);
1823 else if (state_token_is_name (t0, "nil"))
1825 opt->info.nested->convert_to = NULL;
1826 next_state_tokens (1);
1828 else
1829 fatal_reading_state (t0, "Bad nested convert_from option");
1833 /* Read an GTY option. */
1834 static void
1835 read_state_option (options_p *opt)
1837 struct state_token_st *t0 = peek_state_token (0);
1838 struct state_token_st *t1 = peek_state_token (1);
1840 if (state_token_kind (t0) == STOK_LEFTPAR &&
1841 state_token_is_name (t1, "!option"))
1843 next_state_tokens (2);
1844 t0 = peek_state_token (0);
1845 if (state_token_kind (t0) == STOK_NAME)
1847 *opt = XCNEW (struct options);
1848 if (state_token_is_name (t0, "nil"))
1849 (*opt)->name = NULL;
1850 else
1851 (*opt)->name = t0->stok_un.stok_ident->stid_name;
1852 next_state_tokens (1);
1853 t0 = peek_state_token (0);
1854 if (state_token_kind (t0) == STOK_NAME)
1856 if (state_token_is_name (t0, "string"))
1858 next_state_tokens (1);
1859 read_state_string_option (*opt);
1861 else if (state_token_is_name (t0, "type"))
1863 next_state_tokens (1);
1864 read_state_type_option (*opt);
1866 else if (state_token_is_name (t0, "nested"))
1868 next_state_tokens (1);
1869 read_state_nested_option (*opt);
1871 else
1872 fatal_reading_state (t0, "Bad option type");
1873 t0 = peek_state_token (0);
1874 if (state_token_kind (t0) != STOK_RIGHTPAR)
1875 fatal_reading_state (t0, "Bad syntax in option, expecting )");
1877 next_state_tokens (1);
1879 else
1880 fatal_reading_state (t0, "Missing option type");
1882 else
1883 fatal_reading_state (t0, "Bad name for option");
1885 else
1886 fatal_reading_state (t0, "Bad option, waiting for )");
1889 /* Read a list of options. */
1890 void
1891 read_state_options (options_p *opt)
1893 options_p head = NULL;
1894 options_p previous = NULL;
1895 options_p current_option = NULL;
1896 struct state_token_st *t0 = peek_state_token (0);
1897 struct state_token_st *t1 = peek_state_token (1);
1899 if (state_token_kind (t0) == STOK_LEFTPAR &&
1900 state_token_is_name (t1, "!options"))
1902 next_state_tokens (2);
1903 t0 = peek_state_token (0);
1904 while (state_token_kind (t0) != STOK_RIGHTPAR)
1906 read_state_option (&current_option);
1907 if (head == NULL)
1909 head = current_option;
1910 previous = head;
1912 else
1914 previous->next = current_option;
1915 previous = current_option;
1917 t0 = peek_state_token (0);
1919 next_state_tokens (1);
1921 else if (state_token_is_name (t0, "nil"))
1923 next_state_tokens (1);
1925 else
1926 fatal_reading_state (t0, "Bad options syntax");
1928 *opt = head;
1932 /* Read a version, and check against the version of the gengtype. */
1933 static void
1934 read_state_version (const char *version_string)
1936 struct state_token_st *t0 = peek_state_token (0);
1937 struct state_token_st *t1 = peek_state_token (1);
1939 if (state_token_kind (t0) == STOK_LEFTPAR &&
1940 state_token_is_name (t1, "!version"))
1942 next_state_tokens (2);
1943 t0 = peek_state_token (0);
1944 t1 = peek_state_token (1);
1945 if (state_token_kind (t0) == STOK_STRING &&
1946 state_token_kind (t1) == STOK_RIGHTPAR)
1948 /* Check that the read version string is the same as current
1949 version. */
1950 if (strcmp (version_string, t0->stok_un.stok_string))
1951 fatal_reading_state_printf (t0,
1952 "version string mismatch; expecting %s but got %s",
1953 version_string,
1954 t0->stok_un.stok_string);
1955 next_state_tokens (2);
1957 else
1958 fatal_reading_state (t0, "Missing version or right parenthesis");
1960 else
1961 fatal_reading_state (t0, "Bad version syntax");
1965 /* Read a pair. */
1966 void
1967 read_state_pair (pair_p *current)
1969 struct state_token_st *t0 = peek_state_token (0);
1970 struct state_token_st *t1 = peek_state_token (1);
1971 if (state_token_kind (t0) == STOK_LEFTPAR &&
1972 state_token_is_name (t1, "!pair"))
1974 *current = XCNEW (struct pair);
1975 next_state_tokens (2);
1976 t0 = peek_state_token (0);
1977 if (state_token_kind (t0) == STOK_STRING)
1979 if (strcmp (t0->stok_un.stok_string, "nil") == 0)
1981 (*current)->name = NULL;
1983 else
1985 (*current)->name = xstrdup (t0->stok_un.stok_string);
1987 next_state_tokens (1);
1988 read_state_type (&((*current)->type));
1989 read_state_fileloc (&((*current)->line));
1990 read_state_options (&((*current)->opt));;
1991 t0 = peek_state_token (0);
1992 if (state_token_kind (t0) == STOK_RIGHTPAR)
1994 next_state_tokens (1);
1996 else
1998 fatal_reading_state (t0, "Bad syntax for pair, )");
2001 else
2003 fatal_reading_state (t0, "Bad name for pair");
2006 else if (state_token_kind (t0) == STOK_NAME &&
2007 state_token_is_name (t0, "nil"))
2009 next_state_tokens (1);
2010 *current = NULL;
2012 else
2013 fatal_reading_state_printf (t0, "Bad syntax for pair, (!pair %d",
2014 state_token->stok_kind);
2018 /* Return the number of pairs actually read. */
2020 read_state_pair_list (pair_p *list)
2022 int nbpair = 0;
2023 pair_p head = NULL;
2024 pair_p previous = NULL;
2025 pair_p tmp = NULL;
2026 struct state_token_st *t0 = peek_state_token (0);
2027 while (t0 && state_token_kind (t0) != STOK_RIGHTPAR)
2029 read_state_pair (&tmp);
2030 if (head == NULL)
2032 head = tmp;
2033 previous = head;
2035 else
2037 previous->next = tmp;
2038 previous = tmp;
2040 t0 = peek_state_token (0);
2041 nbpair++;
2044 /* don't consume the ); the caller will eat it. */
2045 *list = head;
2046 return nbpair;
2049 /* Read the typedefs. */
2050 static void
2051 read_state_typedefs (pair_p *typedefs)
2053 int nbtypedefs = 0;
2054 pair_p list = NULL;
2055 struct state_token_st *t0 = peek_state_token (0);
2056 struct state_token_st *t1 = peek_state_token (1);
2057 struct state_token_st *t2 = peek_state_token (2);
2059 if (state_token_kind (t0) == STOK_LEFTPAR
2060 && state_token_is_name (t1, "!typedefs")
2061 && state_token_kind (t2) == STOK_INTEGER)
2063 int nbpairs = 0;
2064 nbtypedefs = t2->stok_un.stok_num;
2065 next_state_tokens (3);
2066 nbpairs = read_state_pair_list (&list);
2067 t0 = peek_state_token (0);
2068 if (nbpairs != nbtypedefs)
2069 fatal_reading_state_printf
2070 (t0,
2071 "invalid number of typedefs, expected %d but got %d",
2072 nbtypedefs, nbpairs);
2073 if (state_token_kind (t0) == STOK_RIGHTPAR)
2074 next_state_tokens (1);
2075 else
2076 fatal_reading_state (t0, "Bad typedefs syntax )");
2078 else
2079 fatal_reading_state (t0, "Bad typedefs syntax (!typedefs");
2081 if (verbosity_level >= 2)
2082 printf ("%s read %d typedefs from state\n", progname, nbtypedefs);
2083 *typedefs = list;
2087 /* Read the structures. */
2088 static void
2089 read_state_structures (type_p *structures)
2091 type_p head = NULL;
2092 type_p previous = NULL;
2093 type_p tmp;
2094 int nbstruct = 0, countstruct = 0;
2095 struct state_token_st *t0 = peek_state_token (0);
2096 struct state_token_st *t1 = peek_state_token (1);
2097 struct state_token_st *t2 = peek_state_token (2);
2099 if (state_token_kind (t0) == STOK_LEFTPAR
2100 && state_token_is_name (t1, "!structures")
2101 && state_token_kind (t2) == STOK_INTEGER)
2103 nbstruct = t2->stok_un.stok_num;
2104 next_state_tokens (3);
2105 t0 = peek_state_token (0);
2106 while (t0 && state_token_kind (t0) != STOK_RIGHTPAR)
2108 tmp = NULL;
2109 read_state_type (&tmp);
2110 countstruct++;
2111 if (head == NULL)
2113 head = tmp;
2114 previous = head;
2116 else
2118 previous->next = tmp;
2119 previous = tmp;
2121 t0 = peek_state_token (0);
2123 next_state_tokens (1);
2125 else
2126 fatal_reading_state (t0, "Bad structures syntax");
2127 if (countstruct != nbstruct)
2128 fatal_reading_state_printf (NULL_STATE_TOKEN,
2129 "expected %d structures but got %d",
2130 nbstruct, countstruct);
2131 if (verbosity_level >= 2)
2132 printf ("%s read %d structures from state\n", progname, nbstruct);
2133 *structures = head;
2137 /* Read the param_struct-s. */
2138 static void
2139 read_state_param_structs (type_p *param_structs)
2141 int nbparamstructs = 0;
2142 int countparamstructs = 0;
2143 type_p head = NULL;
2144 type_p previous = NULL;
2145 type_p tmp;
2146 struct state_token_st *t0 = peek_state_token (0);
2147 struct state_token_st *t1 = peek_state_token (1);
2148 struct state_token_st *t2 = peek_state_token (2);
2150 if (state_token_kind (t0) == STOK_LEFTPAR
2151 && state_token_is_name (t1, "!param_structs")
2152 && state_token_kind (t2) == STOK_INTEGER)
2154 nbparamstructs = t2->stok_un.stok_num;
2155 next_state_tokens (3);
2156 t0 = t1 = t2 = NULL;
2157 t0 = peek_state_token (0);
2158 while (state_token_kind (t0) != STOK_RIGHTPAR)
2160 tmp = NULL;
2161 read_state_type (&tmp);
2162 if (head == NULL)
2164 head = tmp;
2165 previous = head;
2167 else
2169 previous->next = tmp;
2170 previous = tmp;
2172 t0 = peek_state_token (0);
2173 countparamstructs++;
2175 next_state_tokens (1);
2177 else
2178 fatal_reading_state (t0, "Bad param_structs syntax");
2179 t0 = peek_state_token (0);
2180 if (countparamstructs != nbparamstructs)
2181 fatal_reading_state_printf
2182 (t0,
2183 "invalid number of param_structs expected %d got %d",
2184 nbparamstructs, countparamstructs);
2185 *param_structs = head;
2189 /* Read the variables. */
2190 static void
2191 read_state_variables (pair_p *variables)
2193 pair_p list = NULL;
2194 int nbvars = 0;
2195 struct state_token_st *t0 = peek_state_token (0);
2196 struct state_token_st *t1 = peek_state_token (1);
2197 struct state_token_st *t2 = peek_state_token (2);
2199 if (state_token_kind (t0) == STOK_LEFTPAR
2200 && state_token_is_name (t1, "!variables")
2201 && state_token_kind (t2) == STOK_INTEGER)
2203 int nbpairs = 0;
2204 nbvars = t2->stok_un.stok_num;
2205 next_state_tokens (3);
2206 nbpairs = read_state_pair_list (&list);
2207 t0 = peek_state_token (0);
2208 if (nbpairs != nbvars)
2209 fatal_reading_state_printf
2210 (t0, "Invalid number of variables, expected %d but got %d",
2211 nbvars, nbpairs);
2212 if (state_token_kind (t0) == STOK_RIGHTPAR)
2213 next_state_tokens (1);
2214 else
2215 fatal_reading_state (t0, "Waiting for ) in variables");
2217 else
2218 fatal_reading_state (t0, "Bad variables syntax");
2219 *variables = list;
2220 if (verbosity_level >= 2)
2221 printf ("%s read %d variables from state\n", progname, nbvars);
2225 /* Read the source directory. */
2226 static void
2227 read_state_srcdir (void)
2229 struct state_token_st *t0 = peek_state_token (0);
2230 struct state_token_st *t1 = peek_state_token (1);
2231 if (state_token_kind (t0) == STOK_LEFTPAR &&
2232 state_token_is_name (t1, "!srcdir"))
2234 next_state_tokens (2);
2235 t0 = peek_state_token (0);
2236 t1 = peek_state_token (1);
2237 if (state_token_kind (t0) == STOK_STRING &&
2238 state_token_kind (t1) == STOK_RIGHTPAR)
2240 srcdir = xstrdup (t0->stok_un.stok_string);
2241 srcdir_len = strlen (srcdir);
2242 next_state_tokens (2);
2243 return;
2247 fatal_reading_state (t0, "Bad srcdir in state_file");
2251 /* Read the sequence of GCC front-end languages. */
2252 static void
2253 read_state_languages (void)
2255 struct state_token_st *t0 = peek_state_token (0);
2256 struct state_token_st *t1 = peek_state_token (1);
2257 struct state_token_st *t2 = peek_state_token (2);
2258 if (state_token_kind (t0) == STOK_LEFTPAR
2259 && state_token_is_name (t1, "!languages")
2260 && state_token_kind (t2) == STOK_INTEGER)
2262 int i = 0;
2263 num_lang_dirs = t2->stok_un.stok_num;
2264 lang_dir_names = XCNEWVEC (const char *, num_lang_dirs);
2265 next_state_tokens (3);
2266 t0 = t1 = t2 = NULL;
2267 for (i = 0; i < (int) num_lang_dirs; i++)
2269 t0 = peek_state_token (0);
2270 if (state_token_kind (t0) != STOK_NAME)
2271 fatal_reading_state (t0, "expecting language name in state file");
2272 lang_dir_names[i] = t0->stok_un.stok_ident->stid_name;
2273 next_state_tokens (1);
2275 t0 = peek_state_token (0);
2276 if (state_token_kind (t0) != STOK_RIGHTPAR)
2277 fatal_reading_state (t0, "missing ) in languages list of state file");
2278 next_state_tokens (1);
2280 else
2281 fatal_reading_state (t0, "expecting languages list in state file");
2285 /* Read the sequence of files. */
2286 static void
2287 read_state_files_list (void)
2289 struct state_token_st *t0 = peek_state_token (0);
2290 struct state_token_st *t1 = peek_state_token (1);
2291 struct state_token_st *t2 = peek_state_token (2);
2293 if (state_token_kind (t0) == STOK_LEFTPAR
2294 && state_token_is_name (t1, "!fileslist")
2295 && state_token_kind (t2) == STOK_INTEGER)
2297 int i = 0;
2298 num_gt_files = t2->stok_un.stok_num;
2299 next_state_tokens (3);
2300 t0 = t1 = t2 = NULL;
2301 gt_files = XCNEWVEC (const input_file *, num_gt_files);
2302 for (i = 0; i < (int) num_gt_files; i++)
2304 bool issrcfile = FALSE;
2305 t0 = t1 = t2 = NULL;
2306 t0 = peek_state_token (0);
2307 t1 = peek_state_token (1);
2308 t2 = peek_state_token (2);
2309 if (state_token_kind (t0) == STOK_LEFTPAR
2310 && (state_token_is_name (t1, "!file")
2311 || (issrcfile = state_token_is_name (t1, "!srcfile")))
2312 && state_token_kind (t2) == STOK_INTEGER)
2314 lang_bitmap bmap = t2->stok_un.stok_num;
2315 next_state_tokens (3);
2316 t0 = t1 = t2 = NULL;
2317 t0 = peek_state_token (0);
2318 t1 = peek_state_token (1);
2319 if (state_token_kind (t0) == STOK_STRING
2320 && state_token_kind (t1) == STOK_RIGHTPAR)
2322 const char *fnam = t0->stok_un.stok_string;
2323 /* Allocate & fill a gt_file entry with space for the lang_bitmap before! */
2324 input_file *curgt = NULL;
2325 if (issrcfile)
2327 static const char dirsepstr[2] =
2328 { DIR_SEPARATOR, (char) 0 };
2329 char *fullpath = concat (srcdir, dirsepstr, fnam, NULL);
2330 curgt = input_file_by_name (fullpath);
2331 free (fullpath);
2333 else
2334 curgt = input_file_by_name (fnam);
2335 set_lang_bitmap (curgt, bmap);
2336 gt_files[i] = curgt;
2337 next_state_tokens (2);
2339 else
2340 fatal_reading_state (t0,
2341 "bad file in !fileslist of state file");
2343 else
2344 fatal_reading_state (t0,
2345 "expecting file in !fileslist of state file");
2347 t0 = peek_state_token (0);
2348 if (!state_token_kind (t0) == STOK_RIGHTPAR)
2349 fatal_reading_state (t0, "missing ) for !fileslist in state file");
2350 next_state_tokens (1);
2352 else
2353 fatal_reading_state (t0, "missing !fileslist in state file");
2357 /* Read the trailer. */
2358 static void
2359 read_state_trailer (void)
2361 struct state_token_st *t0 = peek_state_token (0);
2362 struct state_token_st *t1 = peek_state_token (1);
2363 struct state_token_st *t2 = peek_state_token (2);
2365 if (state_token_kind (t0) == STOK_LEFTPAR
2366 && state_token_is_name (t1, "!endfile")
2367 && state_token_kind (t2) == STOK_RIGHTPAR)
2368 next_state_tokens (3);
2369 else
2370 fatal_reading_state (t0, "missing !endfile in state file");
2374 /* Utility functions for the state_seen_types hash table. */
2375 static unsigned
2376 hash_type_number (const void *ty)
2378 const struct type *type = (const struct type *) ty;
2380 return type->state_number;
2383 static int
2384 equals_type_number (const void *ty1, const void *ty2)
2386 const struct type *type1 = (const struct type *) ty1;
2387 const struct type *type2 = (const struct type *) ty2;
2389 return type1->state_number == type2->state_number;
2392 static int
2393 string_eq (const void *a, const void *b)
2395 const char *a0 = (const char *)a;
2396 const char *b0 = (const char *)b;
2398 return (strcmp (a0, b0) == 0);
2402 /* The function reading the state, called by main from gengtype.c. */
2403 void
2404 read_state (const char *path)
2406 state_file = fopen (path, "r");
2407 if (state_file == NULL)
2408 fatal ("Failed to open state file %s for reading [%s]", path,
2409 xstrerror (errno));
2410 state_path = path;
2411 state_line = 1;
2413 if (verbosity_level >= 1)
2415 printf ("%s reading state file %s;", progname, state_path);
2416 if (verbosity_level >= 2)
2417 putchar ('\n');
2418 fflush (stdout);
2421 state_seen_types =
2422 htab_create (2017, hash_type_number, equals_type_number, NULL);
2423 state_ident_tab =
2424 htab_create (4027, htab_hash_string, string_eq, NULL);
2425 read_state_version (version_string);
2426 read_state_srcdir ();
2427 read_state_languages ();
2428 read_state_files_list ();
2429 read_state_structures (&structures);
2430 if (ferror (state_file))
2431 fatal_reading_state_printf
2432 (NULL_STATE_TOKEN, "input error while reading state [%s]",
2433 xstrerror (errno));
2434 read_state_typedefs (&typedefs);
2435 read_state_param_structs (&param_structs);
2436 read_state_variables (&variables);
2437 read_state_trailer ();
2439 if (verbosity_level >= 1)
2441 printf ("%s read %ld bytes.\n", progname, ftell (state_file));
2442 fflush (stdout);
2445 if (fclose (state_file))
2446 fatal ("failed to close read state file %s [%s]",
2447 path, xstrerror (errno));
2448 state_file = NULL;
2449 state_path = NULL;
2452 /* End of file gengtype-state.c. */