]>
Commit | Line | Data |
---|---|---|
e2500fed | 1 | /* Process source files and output type information. |
f8ed6dc5 JS |
2 | Copyright (C) 2002, 2003, 2004, 2007, 2008, 2010 |
3 | Free Software Foundation, Inc. | |
e2500fed | 4 | |
e1b793e7 | 5 | This file is part of GCC. |
e2500fed | 6 | |
e1b793e7 BS |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
e2500fed | 11 | |
e1b793e7 BS |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
e2500fed | 16 | |
e1b793e7 BS |
17 | You should have received a copy of the GNU General Public License |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
e2500fed | 20 | |
065ae611 ZW |
21 | #ifndef GCC_GENGTYPE_H |
22 | #define GCC_GENGTYPE_H | |
23 | ||
f8ed6dc5 JS |
24 | /* Sets of accepted source languages like C, C++, Ada... are |
25 | represented by a bitmap. */ | |
26 | typedef unsigned lang_bitmap; | |
27 | ||
b8698a0f | 28 | /* A file position, mostly for error messages. |
e2500fed | 29 | The FILE element may be compared using pointer equality. */ |
e1b793e7 BS |
30 | struct fileloc |
31 | { | |
e2500fed GK |
32 | const char *file; |
33 | int line; | |
34 | }; | |
35 | ||
065ae611 | 36 | /* Data types handed around within, but opaque to, the lexer and parser. */ |
b453c95f GK |
37 | typedef struct pair *pair_p; |
38 | typedef struct type *type_p; | |
e5cfc29f | 39 | typedef const struct type *const_type_p; |
065ae611 | 40 | typedef struct options *options_p; |
e2500fed | 41 | |
e2500fed GK |
42 | /* Variables used to communicate between the lexer and the parser. */ |
43 | extern int lexer_toplevel_done; | |
44 | extern struct fileloc lexer_line; | |
45 | ||
f8ed6dc5 JS |
46 | /* Structure representing an output file. */ |
47 | struct outf | |
48 | { | |
49 | struct outf *next; | |
50 | const char *name; | |
51 | size_t buflength; | |
52 | size_t bufused; | |
53 | char *buf; | |
54 | }; | |
55 | typedef struct outf *outf_p; | |
56 | ||
57 | /* The list of output files. */ | |
58 | extern outf_p output_files; | |
59 | ||
60 | /* The output header file that is included into pretty much every | |
61 | source file. */ | |
62 | extern outf_p header_file; | |
63 | ||
64 | /* Print, like fprintf, to O. No-op if O is NULL. */ | |
65 | void | |
66 | oprintf (outf_p o, const char *S, ...) | |
67 | ATTRIBUTE_PRINTF_2; | |
68 | ||
69 | /* An output file, suitable for definitions, that can see declarations | |
70 | made in INPUT_FILE and is linked into every language that uses | |
71 | INPUT_FILE. May return NULL in plugin mode. */ | |
72 | extern outf_p get_output_file_with_visibility (const char *input_file); | |
73 | ||
74 | /* Source directory. */ | |
75 | extern const char *srcdir; /* (-S) program argument. */ | |
76 | ||
77 | /* Length of srcdir name. */ | |
78 | extern size_t srcdir_len; | |
79 | ||
80 | /* Variable used for reading and writing the state. */ | |
81 | extern const char *read_state_filename; /* (-r) program argument. */ | |
82 | extern const char *write_state_filename; /* (-w) program argument. */ | |
83 | ||
e2500fed | 84 | /* Print an error message. */ |
b8698a0f | 85 | extern void error_at_line |
e1b793e7 | 86 | (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2; |
e2500fed | 87 | |
01d419ae | 88 | /* Like asprintf, but calls fatal() on out of memory. */ |
f8ed6dc5 | 89 | extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1; |
01d419ae | 90 | |
e2500fed | 91 | /* Constructor routines for types. */ |
3d7aafde | 92 | extern void do_typedef (const char *s, type_p t, struct fileloc *pos); |
95161faf | 93 | extern void do_scalar_typedef (const char *s, struct fileloc *pos); |
3d7aafde | 94 | extern type_p resolve_typedef (const char *s, struct fileloc *pos); |
0f01f026 RS |
95 | extern type_p new_structure (const char *name, int isunion, |
96 | struct fileloc *pos, pair_p fields, | |
97 | options_p o); | |
3d7aafde | 98 | extern type_p find_structure (const char *s, int isunion); |
95161faf | 99 | extern type_p create_scalar_type (const char *name); |
3d7aafde AJ |
100 | extern type_p create_pointer (type_p t); |
101 | extern type_p create_array (type_p t, const char *len); | |
e1b793e7 BS |
102 | extern options_p create_option (options_p, const char *name, |
103 | const void *info); | |
065ae611 | 104 | extern options_p create_nested_ptr_option (options_p, type_p t, |
e1b793e7 BS |
105 | const char *from, |
106 | const char *to); | |
107 | extern pair_p create_field_at (pair_p next, type_p type, | |
108 | const char *name, options_p opt, | |
109 | struct fileloc *pos); | |
01d419ae | 110 | extern pair_p nreverse_pairs (pair_p list); |
3d7aafde AJ |
111 | extern type_p adjust_field_type (type_p, options_p); |
112 | extern void note_variable (const char *s, type_p t, options_p o, | |
113 | struct fileloc *pos); | |
8ad97cfc | 114 | extern void note_def_vec (const char *type_name, bool is_scalar, |
4a399aef ZW |
115 | struct fileloc *pos); |
116 | extern void note_def_vec_alloc (const char *type, const char *astrat, | |
117 | struct fileloc *pos); | |
e2500fed | 118 | |
01d419ae ZW |
119 | /* Lexer and parser routines. */ |
120 | extern int yylex (const char **yylval); | |
121 | extern void yybegin (const char *fname); | |
122 | extern void yyend (void); | |
3d7aafde | 123 | extern void parse_file (const char *name); |
01d419ae ZW |
124 | extern bool hit_error; |
125 | ||
126 | /* Token codes. */ | |
e1b793e7 BS |
127 | enum |
128 | { | |
129 | EOF_TOKEN = 0, | |
130 | ||
131 | /* Per standard convention, codes in the range (0, UCHAR_MAX] | |
132 | represent single characters with those character codes. */ | |
133 | ||
134 | CHAR_TOKEN_OFFSET = UCHAR_MAX + 1, | |
135 | GTY_TOKEN = CHAR_TOKEN_OFFSET, | |
136 | TYPEDEF, | |
137 | EXTERN, | |
138 | STATIC, | |
139 | UNION, | |
140 | STRUCT, | |
141 | ENUM, | |
142 | VEC_TOKEN, | |
143 | DEFVEC_OP, | |
144 | DEFVEC_I, | |
145 | DEFVEC_ALLOC, | |
146 | ELLIPSIS, | |
147 | PTR_ALIAS, | |
148 | NESTED_PTR, | |
149 | PARAM_IS, | |
150 | NUM, | |
151 | SCALAR, | |
152 | ID, | |
153 | STRING, | |
154 | CHAR, | |
155 | ARRAY, | |
156 | ||
157 | /* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have | |
158 | a meaningful value to be printed. */ | |
159 | FIRST_TOKEN_WITH_VALUE = PARAM_IS | |
160 | }; | |
f8ed6dc5 JS |
161 | |
162 | ||
163 | /* For debugging purposes we provide two flags. */ | |
164 | ||
165 | /* Dump everything to understand gengtype's state. Might be useful to | |
166 | gengtype users. */ | |
167 | extern int do_dump; /* (-d) program argument. */ | |
168 | ||
169 | /* Trace the execution by many DBGPRINTF (with the position inside | |
170 | gengtype source code). Only useful to debug gengtype itself. */ | |
171 | extern int do_debug; /* (-D) program argument. */ | |
172 | ||
173 | #if ENABLE_CHECKING | |
174 | #define DBGPRINTF(Fmt,...) do {if (do_debug) \ | |
175 | fprintf (stderr, "%s:%d: " Fmt "\n", \ | |
176 | lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0) | |
177 | void dbgprint_count_type_at (const char *, int, const char *, type_p); | |
178 | #define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug) \ | |
179 | dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0) | |
180 | #else | |
181 | #define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0) | |
182 | #define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0) | |
183 | #endif /*ENABLE_CHECKING */ | |
184 | ||
065ae611 | 185 | #endif |