1 /* Process source files and output type information.
2 Copyright (C) 2002, 2003, 2004, 2007, 2008, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
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
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
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/>. */
21 #ifndef GCC_GENGTYPE_H
22 #define GCC_GENGTYPE_H
24 /* Sets of accepted source languages like C, C++, Ada... are
25 represented by a bitmap. */
26 typedef unsigned lang_bitmap
;
28 /* Variable length structure representing an input file. A hash table
29 ensure uniqueness for a given input file name. The only function
30 allocating input_file-s is input_file_by_name. */
33 struct outf
* inpoutf
; /* Cached corresponding output file, computed
34 in get_output_file_with_visibility. */
35 lang_bitmap inpbitmap
; /* The set of languages using this file. */
36 char inpname
[1]; /* A variable-length array, ended by a null
39 typedef struct input_file_st input_file
;
41 /* A file position, mostly for error messages.
42 The FILE element may be compared using pointer equality. */
45 const input_file
*file
;
50 /* Table of all input files and its size. */
51 extern const input_file
** gt_files
;
52 extern size_t num_gt_files
;
54 /* A number of places use the name of this "gengtype.c" file for a
55 location for things that we can't rely on the source to define. We
56 also need to refer to the "system.h" file specifically. These two
57 pointers are initialized early in main. */
58 extern input_file
* this_file
;
59 extern input_file
* system_h_file
;
61 /* Retrieve or create the input_file for a given name, which is a file
62 path. This is the only function allocating input_file-s and it is
64 input_file
* input_file_by_name (const char* name
);
66 /* For F an input_file, return the relative path to F from $(srcdir)
67 if the latter is a prefix in F, NULL otherwise. */
68 const char *get_file_srcdir_relative_path (const input_file
*inpf
);
70 /* Get the name of an input file. */
71 static inline const char*
72 get_input_file_name (const input_file
*inpf
)
79 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
80 INPUT_FILE is used by <lang>.
82 This function should be written to assume that a file _is_ used
83 if the situation is unclear. If it wrongly assumes a file _is_ used,
84 a linker error will result. If it wrongly assumes a file _is not_ used,
85 some GC roots may be missed, which is a much harder-to-debug problem.
88 static inline lang_bitmap
89 get_lang_bitmap (const input_file
* inpf
)
93 return inpf
->inpbitmap
;
96 /* Set the bitmap returned by get_lang_bitmap. The only legitimate
97 callers of this function are read_input_list & read_state_*. */
99 set_lang_bitmap (input_file
* inpf
, lang_bitmap n
)
105 /* Vector of per-language directories. */
106 extern const char **lang_dir_names
;
107 extern size_t num_lang_dirs
;
109 /* Data types handed around within, but opaque to, the lexer and parser. */
110 typedef struct pair
*pair_p
;
111 typedef struct type
*type_p
;
112 typedef const struct type
*const_type_p
;
113 typedef struct options
*options_p
;
115 /* Variables used to communicate between the lexer and the parser. */
116 extern int lexer_toplevel_done
;
117 extern struct fileloc lexer_line
;
119 /* Structure representing an output file. */
128 typedef struct outf
*outf_p
;
130 /* The list of output files. */
131 extern outf_p output_files
;
133 /* The output header file that is included into pretty much every
135 extern outf_p header_file
;
137 /* Print, like fprintf, to O. No-op if O is NULL. */
139 oprintf (outf_p o
, const char *S
, ...)
142 /* An output file, suitable for definitions, that can see declarations
143 made in INPF and is linked into every language that uses INPF. May
144 return NULL in plugin mode. The INPF argument is almost const, but
145 since the result is cached in its inpoutf field it cannot be
147 outf_p
get_output_file_with_visibility (input_file
* inpf
);
149 /* The name of an output file, suitable for definitions, that can see
150 declarations made in INPF and is linked into every language that
151 uses INPF. May return NULL. */
152 const char *get_output_file_name (input_file
*inpf
);
155 /* Source directory. */
156 extern const char *srcdir
; /* (-S) program argument. */
158 /* Length of srcdir name. */
159 extern size_t srcdir_len
;
161 /* Variable used for reading and writing the state. */
162 extern const char *read_state_filename
; /* (-r) program argument. */
163 extern const char *write_state_filename
; /* (-w) program argument. */
165 /* Print an error message. */
166 extern void error_at_line
167 (const struct fileloc
*pos
, const char *msg
, ...) ATTRIBUTE_PRINTF_2
;
169 /* Like asprintf, but calls fatal() on out of memory. */
170 extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1
;
172 /* Constructor routines for types. */
173 extern void do_typedef (const char *s
, type_p t
, struct fileloc
*pos
);
174 extern void do_scalar_typedef (const char *s
, struct fileloc
*pos
);
175 extern type_p
resolve_typedef (const char *s
, struct fileloc
*pos
);
176 extern type_p
new_structure (const char *name
, int isunion
,
177 struct fileloc
*pos
, pair_p fields
,
179 extern type_p
find_structure (const char *s
, int isunion
);
180 extern type_p
create_scalar_type (const char *name
);
181 extern type_p
create_pointer (type_p t
);
182 extern type_p
create_array (type_p t
, const char *len
);
183 extern options_p
create_option (options_p
, const char *name
,
185 extern options_p
create_nested_ptr_option (options_p
, type_p t
,
188 extern pair_p
create_field_at (pair_p next
, type_p type
,
189 const char *name
, options_p opt
,
190 struct fileloc
*pos
);
191 extern pair_p
nreverse_pairs (pair_p list
);
192 extern type_p
adjust_field_type (type_p
, options_p
);
193 extern void note_variable (const char *s
, type_p t
, options_p o
,
194 struct fileloc
*pos
);
195 extern void note_def_vec (const char *type_name
, bool is_scalar
,
196 struct fileloc
*pos
);
197 extern void note_def_vec_alloc (const char *type
, const char *astrat
,
198 struct fileloc
*pos
);
200 /* Lexer and parser routines. */
201 extern int yylex (const char **yylval
);
202 extern void yybegin (const char *fname
);
203 extern void yyend (void);
204 extern void parse_file (const char *name
);
205 extern bool hit_error
;
212 /* Per standard convention, codes in the range (0, UCHAR_MAX]
213 represent single characters with those character codes. */
215 CHAR_TOKEN_OFFSET
= UCHAR_MAX
+ 1,
216 GTY_TOKEN
= CHAR_TOKEN_OFFSET
,
238 /* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
239 a meaningful value to be printed. */
240 FIRST_TOKEN_WITH_VALUE
= PARAM_IS
244 /* Level for verbose messages, e.g. output file generation... */
245 extern int verbosity_level
; /* (-v) program argument. */
247 /* For debugging purposes we provide two flags. */
249 /* Dump everything to understand gengtype's state. Might be useful to
251 extern int do_dump
; /* (-d) program argument. */
253 /* Trace the execution by many DBGPRINTF (with the position inside
254 gengtype source code). Only useful to debug gengtype itself. */
255 extern int do_debug
; /* (-D) program argument. */
258 #define DBGPRINTF(Fmt,...) do {if (do_debug) \
259 fprintf (stderr, "%s:%d: " Fmt "\n", \
260 lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0)
261 void dbgprint_count_type_at (const char *, int, const char *, type_p
);
262 #define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug) \
263 dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0)
265 #define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0)
266 #define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0)
267 #endif /*ENABLE_CHECKING */