PR c++/3478
[official-gcc.git] / gcc / gengtype.h
blob3a3157ec3771fdbb033c45d52993d687fada6009
1 /* Process source files and output type information.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 /* A file position, mostly for error messages.
22 The FILE element may be compared using pointer equality. */
23 struct fileloc {
24 const char *file;
25 int line;
28 /* Kinds of types we can understand. */
29 enum typekind {
30 TYPE_SCALAR,
31 TYPE_STRING,
32 TYPE_STRUCT,
33 TYPE_UNION,
34 TYPE_POINTER,
35 TYPE_ARRAY,
36 TYPE_LANG_STRUCT,
37 TYPE_PARAM_STRUCT
40 /* A way to pass data through to the output end. */
41 typedef struct options {
42 struct options *next;
43 const char *name;
44 const void *info;
45 } *options_p;
47 typedef struct pair *pair_p;
48 typedef struct type *type_p;
49 typedef unsigned lang_bitmap;
51 /* A name and a type. */
52 struct pair {
53 pair_p next;
54 const char *name;
55 type_p type;
56 struct fileloc line;
57 options_p opt;
60 #define NUM_PARAM 10
62 /* A description of a type. */
63 struct type {
64 enum typekind kind;
65 type_p next;
66 type_p pointer_to;
67 enum gc_used_enum {
68 GC_UNUSED = 0,
69 GC_USED,
70 GC_MAYBE_POINTED_TO,
71 GC_POINTED_TO
72 } gc_used;
73 union {
74 type_p p;
75 struct {
76 const char *tag;
77 struct fileloc line;
78 pair_p fields;
79 options_p opt;
80 lang_bitmap bitmap;
81 type_p lang_struct;
82 } s;
83 char *sc;
84 struct {
85 type_p p;
86 const char *len;
87 } a;
88 struct {
89 type_p stru;
90 type_p param[NUM_PARAM];
91 struct fileloc line;
92 } param_struct;
93 } u;
96 #define UNION_P(x) \
97 ((x)->kind == TYPE_UNION || \
98 ((x)->kind == TYPE_LANG_STRUCT \
99 && (x)->u.s.lang_struct->kind == TYPE_UNION))
100 #define UNION_OR_STRUCT_P(x) \
101 ((x)->kind == TYPE_UNION \
102 || (x)->kind == TYPE_STRUCT \
103 || (x)->kind == TYPE_LANG_STRUCT)
105 /* The one and only TYPE_STRING. */
106 extern struct type string_type;
108 /* Variables used to communicate between the lexer and the parser. */
109 extern int lexer_toplevel_done;
110 extern struct fileloc lexer_line;
112 /* Print an error message. */
113 extern void error_at_line
114 (struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;
116 /* Combines xmalloc() and vasprintf(). */
117 extern int xvasprintf (char **, const char *, va_list)
118 ATTRIBUTE_PRINTF (2, 0);
119 /* Like the above, but more convenient for quick coding. */
120 extern char * xasprintf (const char *, ...)
121 ATTRIBUTE_PRINTF_1;
123 /* Constructor routines for types. */
124 extern void do_typedef (const char *s, type_p t, struct fileloc *pos);
125 extern type_p resolve_typedef (const char *s, struct fileloc *pos);
126 extern void new_structure (const char *name, int isunion,
127 struct fileloc *pos, pair_p fields,
128 options_p o);
129 extern type_p find_structure (const char *s, int isunion);
130 extern type_p create_scalar_type (const char *name, size_t name_len);
131 extern type_p create_pointer (type_p t);
132 extern type_p create_array (type_p t, const char *len);
133 extern type_p adjust_field_type (type_p, options_p);
134 extern void note_variable (const char *s, type_p t, options_p o,
135 struct fileloc *pos);
136 extern void note_yacc_type (options_p o, pair_p fields,
137 pair_p typeinfo, struct fileloc *pos);
139 /* Lexer and parser routines, most automatically generated. */
140 extern int yylex (void);
141 extern void yyerror (const char *);
142 extern int yyparse (void);
143 extern void parse_file (const char *name);
145 /* Output file handling. */
147 /* Structure representing an output file. */
148 struct outf
150 struct outf *next;
151 const char *name;
152 size_t buflength;
153 size_t bufused;
154 char *buf;
157 typedef struct outf * outf_p;
159 /* The output header file that is included into pretty much every
160 source file. */
161 extern outf_p header_file;
163 /* An output file, suitable for definitions, that can see declarations
164 made in INPUT_FILE and is linked into every language that uses
165 INPUT_FILE. */
166 extern outf_p get_output_file_with_visibility
167 (const char *input_file);
168 const char *get_output_file_name (const char *);
170 /* A list of output files suitable for definitions. There is one
171 BASE_FILES entry for each language. */
172 extern outf_p base_files[];
174 /* A bitmap that specifies which of BASE_FILES should be used to
175 output a definition that is different for each language and must be
176 defined once in each language that uses INPUT_FILE. */
177 extern lang_bitmap get_base_file_bitmap (const char *input_file);
179 /* Print, like fprintf, to O. */
180 extern void oprintf (outf_p o, const char *S, ...)
181 ATTRIBUTE_PRINTF_2;