]>
Commit | Line | Data |
---|---|---|
e2500fed | 1 | /* Process source files and output type information. |
d9221e01 | 2 | Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. |
e2500fed GK |
3 | |
4 | This file is part of GCC. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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 | |
366ccddb KC |
18 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
19 | 02110-1301, USA. */ | |
e2500fed GK |
20 | |
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; | |
26 | }; | |
27 | ||
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 | |
38 | }; | |
39 | ||
b453c95f GK |
40 | typedef struct pair *pair_p; |
41 | typedef struct type *type_p; | |
42 | typedef unsigned lang_bitmap; | |
43 | ||
44 | /* Option data for the 'nested_ptr' option. */ | |
45 | struct nested_ptr_data { | |
46 | type_p type; | |
47 | const char *convert_to; | |
48 | const char *convert_from; | |
49 | }; | |
50 | ||
e2500fed GK |
51 | /* A way to pass data through to the output end. */ |
52 | typedef struct options { | |
53 | struct options *next; | |
54 | const char *name; | |
9e2878cf | 55 | const char *info; |
e2500fed GK |
56 | } *options_p; |
57 | ||
e2500fed GK |
58 | /* A name and a type. */ |
59 | struct pair { | |
60 | pair_p next; | |
61 | const char *name; | |
62 | type_p type; | |
63 | struct fileloc line; | |
64 | options_p opt; | |
65 | }; | |
66 | ||
36a5eadd GK |
67 | #define NUM_PARAM 10 |
68 | ||
e2500fed | 69 | /* A description of a type. */ |
9e2878cf GDR |
70 | enum gc_used_enum |
71 | { | |
e2500fed GK |
72 | GC_UNUSED = 0, |
73 | GC_USED, | |
74 | GC_MAYBE_POINTED_TO, | |
75 | GC_POINTED_TO | |
9e2878cf GDR |
76 | }; |
77 | ||
78 | struct type { | |
79 | enum typekind kind; | |
80 | type_p next; | |
81 | type_p pointer_to; | |
82 | enum gc_used_enum gc_used; | |
e2500fed GK |
83 | union { |
84 | type_p p; | |
85 | struct { | |
86 | const char *tag; | |
87 | struct fileloc line; | |
88 | pair_p fields; | |
89 | options_p opt; | |
90 | lang_bitmap bitmap; | |
91 | type_p lang_struct; | |
92 | } s; | |
95161faf | 93 | bool scalar_is_char; |
e2500fed GK |
94 | struct { |
95 | type_p p; | |
96 | const char *len; | |
97 | } a; | |
98 | struct { | |
99 | type_p stru; | |
36a5eadd | 100 | type_p param[NUM_PARAM]; |
e2500fed GK |
101 | struct fileloc line; |
102 | } param_struct; | |
103 | } u; | |
104 | }; | |
105 | ||
106 | #define UNION_P(x) \ | |
107 | ((x)->kind == TYPE_UNION || \ | |
108 | ((x)->kind == TYPE_LANG_STRUCT \ | |
109 | && (x)->u.s.lang_struct->kind == TYPE_UNION)) | |
110 | #define UNION_OR_STRUCT_P(x) \ | |
111 | ((x)->kind == TYPE_UNION \ | |
112 | || (x)->kind == TYPE_STRUCT \ | |
113 | || (x)->kind == TYPE_LANG_STRUCT) | |
114 | ||
e2500fed GK |
115 | /* Variables used to communicate between the lexer and the parser. */ |
116 | extern int lexer_toplevel_done; | |
117 | extern struct fileloc lexer_line; | |
118 | ||
119 | /* Print an error message. */ | |
120 | extern void error_at_line | |
3d7aafde | 121 | (struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2; |
e2500fed | 122 | |
e03856fe | 123 | /* Combines xmalloc() and vasprintf(). */ |
3d7aafde | 124 | extern int xvasprintf (char **, const char *, va_list) |
e03856fe GK |
125 | ATTRIBUTE_PRINTF (2, 0); |
126 | /* Like the above, but more convenient for quick coding. */ | |
3d7aafde | 127 | extern char * xasprintf (const char *, ...) |
e03856fe GK |
128 | ATTRIBUTE_PRINTF_1; |
129 | ||
e2500fed | 130 | /* Constructor routines for types. */ |
3d7aafde | 131 | extern void do_typedef (const char *s, type_p t, struct fileloc *pos); |
95161faf | 132 | extern void do_scalar_typedef (const char *s, struct fileloc *pos); |
3d7aafde | 133 | extern type_p resolve_typedef (const char *s, struct fileloc *pos); |
0f01f026 RS |
134 | extern type_p new_structure (const char *name, int isunion, |
135 | struct fileloc *pos, pair_p fields, | |
136 | options_p o); | |
3d7aafde | 137 | extern type_p find_structure (const char *s, int isunion); |
95161faf | 138 | extern type_p create_scalar_type (const char *name); |
3d7aafde AJ |
139 | extern type_p create_pointer (type_p t); |
140 | extern type_p create_array (type_p t, const char *len); | |
0f01f026 | 141 | extern options_p create_option (options_p, const char *name, const void *info); |
17defa6a ZW |
142 | extern options_p create_nested_ptr_option (type_p t, const char *from, |
143 | const char *to); | |
3d7aafde AJ |
144 | extern type_p adjust_field_type (type_p, options_p); |
145 | extern void note_variable (const char *s, type_p t, options_p o, | |
146 | struct fileloc *pos); | |
4a399aef ZW |
147 | extern void note_def_vec (const char *typename, bool is_scalar, |
148 | struct fileloc *pos); | |
149 | extern void note_def_vec_alloc (const char *type, const char *astrat, | |
150 | struct fileloc *pos); | |
e2500fed GK |
151 | |
152 | /* Lexer and parser routines, most automatically generated. */ | |
3d7aafde AJ |
153 | extern int yylex (void); |
154 | extern void yyerror (const char *); | |
155 | extern int yyparse (void); | |
156 | extern void parse_file (const char *name); | |
e2500fed GK |
157 | |
158 | /* Output file handling. */ | |
159 | ||
e03856fe GK |
160 | /* Structure representing an output file. */ |
161 | struct outf | |
162 | { | |
163 | struct outf *next; | |
164 | const char *name; | |
165 | size_t buflength; | |
166 | size_t bufused; | |
167 | char *buf; | |
168 | }; | |
169 | ||
170 | typedef struct outf * outf_p; | |
e2500fed | 171 | |
e2500fed GK |
172 | /* An output file, suitable for definitions, that can see declarations |
173 | made in INPUT_FILE and is linked into every language that uses | |
174 | INPUT_FILE. */ | |
e03856fe | 175 | extern outf_p get_output_file_with_visibility |
3d7aafde AJ |
176 | (const char *input_file); |
177 | const char *get_output_file_name (const char *); | |
e2500fed GK |
178 | |
179 | /* A list of output files suitable for definitions. There is one | |
180 | BASE_FILES entry for each language. */ | |
e03856fe | 181 | extern outf_p base_files[]; |
e2500fed GK |
182 | |
183 | /* A bitmap that specifies which of BASE_FILES should be used to | |
184 | output a definition that is different for each language and must be | |
185 | defined once in each language that uses INPUT_FILE. */ | |
3d7aafde | 186 | extern lang_bitmap get_base_file_bitmap (const char *input_file); |
e03856fe GK |
187 | |
188 | /* Print, like fprintf, to O. */ | |
3d7aafde | 189 | extern void oprintf (outf_p o, const char *S, ...) |
e03856fe | 190 | ATTRIBUTE_PRINTF_2; |