xref: /dragonfly/contrib/gcc-4.7/gcc/gengtype.h (revision e4b17023)
1*e4b17023SJohn Marino /* Process source files and output type information.
2*e4b17023SJohn Marino    Copyright (C) 2002, 2003, 2004, 2007, 2008, 2010, 2011
3*e4b17023SJohn Marino    Free Software Foundation, Inc.
4*e4b17023SJohn Marino 
5*e4b17023SJohn Marino    This file is part of GCC.
6*e4b17023SJohn Marino 
7*e4b17023SJohn Marino    GCC is free software; you can redistribute it and/or modify it under
8*e4b17023SJohn Marino    the terms of the GNU General Public License as published by the Free
9*e4b17023SJohn Marino    Software Foundation; either version 3, or (at your option) any later
10*e4b17023SJohn Marino    version.
11*e4b17023SJohn Marino 
12*e4b17023SJohn Marino    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*e4b17023SJohn Marino    WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*e4b17023SJohn Marino    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*e4b17023SJohn Marino    for more details.
16*e4b17023SJohn Marino 
17*e4b17023SJohn Marino    You should have received a copy of the GNU General Public License
18*e4b17023SJohn Marino    along with GCC; see the file COPYING3.  If not see
19*e4b17023SJohn Marino    <http://www.gnu.org/licenses/>.  */
20*e4b17023SJohn Marino 
21*e4b17023SJohn Marino #ifndef GCC_GENGTYPE_H
22*e4b17023SJohn Marino #define GCC_GENGTYPE_H
23*e4b17023SJohn Marino 
24*e4b17023SJohn Marino /* Sets of accepted source languages like C, C++, Ada... are
25*e4b17023SJohn Marino    represented by a bitmap.  */
26*e4b17023SJohn Marino typedef unsigned lang_bitmap;
27*e4b17023SJohn Marino 
28*e4b17023SJohn Marino /* Variable length structure representing an input file.  A hash table
29*e4b17023SJohn Marino    ensure uniqueness for a given input file name.  The only function
30*e4b17023SJohn Marino    allocating input_file-s is input_file_by_name.  */
31*e4b17023SJohn Marino struct input_file_st
32*e4b17023SJohn Marino {
33*e4b17023SJohn Marino   struct outf* inpoutf;  /* Cached corresponding output file, computed
34*e4b17023SJohn Marino                             in get_output_file_with_visibility.  */
35*e4b17023SJohn Marino   lang_bitmap inpbitmap; /* The set of languages using this file.  */
36*e4b17023SJohn Marino   bool inpisplugin;      /* Flag set for plugin input files.  */
37*e4b17023SJohn Marino   char inpname[1];       /* A variable-length array, ended by a null
38*e4b17023SJohn Marino                             char.  */
39*e4b17023SJohn Marino };
40*e4b17023SJohn Marino typedef struct input_file_st input_file;
41*e4b17023SJohn Marino 
42*e4b17023SJohn Marino /* A file position, mostly for error messages.
43*e4b17023SJohn Marino    The FILE element may be compared using pointer equality.  */
44*e4b17023SJohn Marino struct fileloc
45*e4b17023SJohn Marino {
46*e4b17023SJohn Marino   const input_file *file;
47*e4b17023SJohn Marino   int line;
48*e4b17023SJohn Marino };
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino 
51*e4b17023SJohn Marino /* Table of all input files and its size.  */
52*e4b17023SJohn Marino extern const input_file** gt_files;
53*e4b17023SJohn Marino extern size_t num_gt_files;
54*e4b17023SJohn Marino 
55*e4b17023SJohn Marino /* A number of places use the name of this "gengtype.c" file for a
56*e4b17023SJohn Marino    location for things that we can't rely on the source to define.  We
57*e4b17023SJohn Marino    also need to refer to the "system.h" file specifically.  These two
58*e4b17023SJohn Marino    pointers are initialized early in main.  */
59*e4b17023SJohn Marino extern input_file* this_file;
60*e4b17023SJohn Marino extern input_file* system_h_file;
61*e4b17023SJohn Marino 
62*e4b17023SJohn Marino /* Retrieve or create the input_file for a given name, which is a file
63*e4b17023SJohn Marino    path.  This is the only function allocating input_file-s and it is
64*e4b17023SJohn Marino    hash-consing them.  */
65*e4b17023SJohn Marino input_file* input_file_by_name (const char* name);
66*e4b17023SJohn Marino 
67*e4b17023SJohn Marino /* For F an input_file, return the relative path to F from $(srcdir)
68*e4b17023SJohn Marino    if the latter is a prefix in F, NULL otherwise.  */
69*e4b17023SJohn Marino const char *get_file_srcdir_relative_path (const input_file *inpf);
70*e4b17023SJohn Marino 
71*e4b17023SJohn Marino /* Get the name of an input file.  */
72*e4b17023SJohn Marino static inline const char*
get_input_file_name(const input_file * inpf)73*e4b17023SJohn Marino get_input_file_name (const input_file *inpf)
74*e4b17023SJohn Marino {
75*e4b17023SJohn Marino   if (inpf)
76*e4b17023SJohn Marino       return inpf->inpname;
77*e4b17023SJohn Marino   return NULL;
78*e4b17023SJohn Marino }
79*e4b17023SJohn Marino 
80*e4b17023SJohn Marino /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
81*e4b17023SJohn Marino    INPUT_FILE is used by <lang>.
82*e4b17023SJohn Marino 
83*e4b17023SJohn Marino    This function should be written to assume that a file _is_ used
84*e4b17023SJohn Marino    if the situation is unclear.  If it wrongly assumes a file _is_ used,
85*e4b17023SJohn Marino    a linker error will result.  If it wrongly assumes a file _is not_ used,
86*e4b17023SJohn Marino    some GC roots may be missed, which is a much harder-to-debug problem.
87*e4b17023SJohn Marino   */
88*e4b17023SJohn Marino 
89*e4b17023SJohn Marino static inline lang_bitmap
get_lang_bitmap(const input_file * inpf)90*e4b17023SJohn Marino get_lang_bitmap (const input_file* inpf)
91*e4b17023SJohn Marino {
92*e4b17023SJohn Marino   if (inpf == NULL)
93*e4b17023SJohn Marino     return 0;
94*e4b17023SJohn Marino   return inpf->inpbitmap;
95*e4b17023SJohn Marino }
96*e4b17023SJohn Marino 
97*e4b17023SJohn Marino /* Set the bitmap returned by get_lang_bitmap.  The only legitimate
98*e4b17023SJohn Marino    callers of this function are read_input_list & read_state_*.  */
99*e4b17023SJohn Marino static inline void
set_lang_bitmap(input_file * inpf,lang_bitmap n)100*e4b17023SJohn Marino set_lang_bitmap (input_file* inpf, lang_bitmap n)
101*e4b17023SJohn Marino {
102*e4b17023SJohn Marino   gcc_assert (inpf);
103*e4b17023SJohn Marino   inpf->inpbitmap = n;
104*e4b17023SJohn Marino }
105*e4b17023SJohn Marino 
106*e4b17023SJohn Marino /* Vector of per-language directories.  */
107*e4b17023SJohn Marino extern const char **lang_dir_names;
108*e4b17023SJohn Marino extern size_t num_lang_dirs;
109*e4b17023SJohn Marino 
110*e4b17023SJohn Marino /* Data types handed around within, but opaque to, the lexer and parser.  */
111*e4b17023SJohn Marino typedef struct pair *pair_p;
112*e4b17023SJohn Marino typedef struct type *type_p;
113*e4b17023SJohn Marino typedef const struct type *const_type_p;
114*e4b17023SJohn Marino typedef struct options *options_p;
115*e4b17023SJohn Marino 
116*e4b17023SJohn Marino /* Variables used to communicate between the lexer and the parser.  */
117*e4b17023SJohn Marino extern int lexer_toplevel_done;
118*e4b17023SJohn Marino extern struct fileloc lexer_line;
119*e4b17023SJohn Marino 
120*e4b17023SJohn Marino /* Various things, organized as linked lists, needed both in
121*e4b17023SJohn Marino    gengtype.c & in gengtype-state.c files.  */
122*e4b17023SJohn Marino extern pair_p typedefs;
123*e4b17023SJohn Marino extern type_p structures;
124*e4b17023SJohn Marino extern type_p param_structs;
125*e4b17023SJohn Marino extern pair_p variables;
126*e4b17023SJohn Marino 
127*e4b17023SJohn Marino 
128*e4b17023SJohn Marino 
129*e4b17023SJohn Marino /* Discrimating kind of types we can understand.  */
130*e4b17023SJohn Marino 
131*e4b17023SJohn Marino enum typekind {
132*e4b17023SJohn Marino   TYPE_NONE=0,          /* Never used, so zeroed memory is invalid.  */
133*e4b17023SJohn Marino   TYPE_SCALAR,          /* Scalar types like char.  */
134*e4b17023SJohn Marino   TYPE_STRING,          /* The string type.  */
135*e4b17023SJohn Marino   TYPE_STRUCT,          /* Type for GTY-ed structs.  */
136*e4b17023SJohn Marino   TYPE_UNION,           /* Type for GTY-ed discriminated unions.  */
137*e4b17023SJohn Marino   TYPE_POINTER,         /* Pointer type to GTY-ed type.  */
138*e4b17023SJohn Marino   TYPE_ARRAY,           /* Array of GTY-ed types.  */
139*e4b17023SJohn Marino   TYPE_LANG_STRUCT,     /* GCC front-end language specific structs.
140*e4b17023SJohn Marino                            Various languages may have homonymous but
141*e4b17023SJohn Marino                            different structs.  */
142*e4b17023SJohn Marino   TYPE_PARAM_STRUCT     /* Type for parametrized structs, e.g. hash_t
143*e4b17023SJohn Marino                            hash-tables, ...  See (param_is, use_param,
144*e4b17023SJohn Marino                            param1_is, param2_is,... use_param1,
145*e4b17023SJohn Marino                            use_param_2,... use_params) GTY
146*e4b17023SJohn Marino                            options.  */
147*e4b17023SJohn Marino };
148*e4b17023SJohn Marino 
149*e4b17023SJohn Marino /* Discriminating kind for options.  */
150*e4b17023SJohn Marino enum option_kind {
151*e4b17023SJohn Marino   OPTION_NONE=0,        /* Never used, so zeroed memory is invalid.  */
152*e4b17023SJohn Marino   OPTION_STRING,        /* A string-valued option.  Most options are
153*e4b17023SJohn Marino                            strings.  */
154*e4b17023SJohn Marino   OPTION_TYPE,          /* A type-valued option.  */
155*e4b17023SJohn Marino   OPTION_NESTED         /* Option data for 'nested_ptr'.  */
156*e4b17023SJohn Marino };
157*e4b17023SJohn Marino 
158*e4b17023SJohn Marino 
159*e4b17023SJohn Marino /* A way to pass data through to the output end.  */
160*e4b17023SJohn Marino struct options {
161*e4b17023SJohn Marino   struct options *next;         /* next option of the same pair.  */
162*e4b17023SJohn Marino   const char *name;             /* GTY option name.  */
163*e4b17023SJohn Marino   enum option_kind kind;        /* discriminating option kind.  */
164*e4b17023SJohn Marino   union {
165*e4b17023SJohn Marino     const char* string;                    /* When OPTION_STRING.  */
166*e4b17023SJohn Marino     type_p type;                           /* When OPTION_TYPE.  */
167*e4b17023SJohn Marino     struct nested_ptr_data* nested;        /* when OPTION_NESTED.  */
168*e4b17023SJohn Marino   } info;
169*e4b17023SJohn Marino };
170*e4b17023SJohn Marino 
171*e4b17023SJohn Marino 
172*e4b17023SJohn Marino /* Option data for the 'nested_ptr' option.  */
173*e4b17023SJohn Marino struct nested_ptr_data {
174*e4b17023SJohn Marino   type_p type;
175*e4b17023SJohn Marino   const char *convert_to;
176*e4b17023SJohn Marino   const char *convert_from;
177*e4b17023SJohn Marino };
178*e4b17023SJohn Marino 
179*e4b17023SJohn Marino /* Some functions to create various options structures with name NAME
180*e4b17023SJohn Marino    and info INFO.  NEXT is the next option in the chain.  */
181*e4b17023SJohn Marino 
182*e4b17023SJohn Marino /* Create a string option.  */
183*e4b17023SJohn Marino options_p create_string_option (options_p next, const char* name,
184*e4b17023SJohn Marino                                 const char* info);
185*e4b17023SJohn Marino 
186*e4b17023SJohn Marino /* Create a type option.  */
187*e4b17023SJohn Marino options_p create_type_option (options_p next, const char* name,
188*e4b17023SJohn Marino                               type_p info);
189*e4b17023SJohn Marino 
190*e4b17023SJohn Marino /* Create a nested option.  */
191*e4b17023SJohn Marino options_p create_nested_option (options_p next, const char* name,
192*e4b17023SJohn Marino 				struct nested_ptr_data* info);
193*e4b17023SJohn Marino 
194*e4b17023SJohn Marino /* Create a nested pointer option.  */
195*e4b17023SJohn Marino options_p create_nested_ptr_option (options_p, type_p t,
196*e4b17023SJohn Marino 			 	     const char *from, const char *to);
197*e4b17023SJohn Marino 
198*e4b17023SJohn Marino /* A name and a type.  */
199*e4b17023SJohn Marino struct pair {
200*e4b17023SJohn Marino   pair_p next;                  /* The next pair in the linked list.  */
201*e4b17023SJohn Marino   const char *name;             /* The defined name.  */
202*e4b17023SJohn Marino   type_p type;                  /* Its GTY-ed type.  */
203*e4b17023SJohn Marino   struct fileloc line;          /* The file location.  */
204*e4b17023SJohn Marino   options_p opt;                /* GTY options, as a linked list.  */
205*e4b17023SJohn Marino };
206*e4b17023SJohn Marino 
207*e4b17023SJohn Marino /* Usage information for GTY-ed types.  Gengtype has to care only of
208*e4b17023SJohn Marino    used GTY-ed types.  Types are initially unused, and their usage is
209*e4b17023SJohn Marino    computed by set_gc_used_type and set_gc_used functions.  */
210*e4b17023SJohn Marino 
211*e4b17023SJohn Marino enum gc_used_enum {
212*e4b17023SJohn Marino 
213*e4b17023SJohn Marino   /* We need that zeroed types are initially unused.  */
214*e4b17023SJohn Marino   GC_UNUSED=0,
215*e4b17023SJohn Marino 
216*e4b17023SJohn Marino   /* The GTY-ed type is used, e.g by a GTY-ed variable or a field
217*e4b17023SJohn Marino      inside a GTY-ed used type.  */
218*e4b17023SJohn Marino   GC_USED,
219*e4b17023SJohn Marino 
220*e4b17023SJohn Marino   /* For GTY-ed structures whose definitions we haven't seen so far
221*e4b17023SJohn Marino      when we encounter a pointer to it that is annotated with
222*e4b17023SJohn Marino      ``maybe_undef''.  If after reading in everything we don't have
223*e4b17023SJohn Marino      source file information for it, we assume that it never has been
224*e4b17023SJohn Marino      defined.  */
225*e4b17023SJohn Marino   GC_MAYBE_POINTED_TO,
226*e4b17023SJohn Marino 
227*e4b17023SJohn Marino   /* For known GTY-ed structures which are pointed to by GTY-ed
228*e4b17023SJohn Marino      variables or fields.  */
229*e4b17023SJohn Marino   GC_POINTED_TO
230*e4b17023SJohn Marino };
231*e4b17023SJohn Marino 
232*e4b17023SJohn Marino /* We can have at most ten type parameters in parameterized structures.  */
233*e4b17023SJohn Marino #define NUM_PARAM 10
234*e4b17023SJohn Marino 
235*e4b17023SJohn Marino /* Our type structure describes all types handled by gengtype.  */
236*e4b17023SJohn Marino struct type {
237*e4b17023SJohn Marino   /* Discriminating kind, cannot be TYPE_NONE.  */
238*e4b17023SJohn Marino   enum typekind kind;
239*e4b17023SJohn Marino 
240*e4b17023SJohn Marino   /* For top-level structs or unions, the 'next' field links the
241*e4b17023SJohn Marino      global list 'structures' or 'param_structs'; for lang_structs,
242*e4b17023SJohn Marino      their homonymous structs are linked using this 'next' field.  The
243*e4b17023SJohn Marino      homonymous list starts at the s.lang_struct field of the
244*e4b17023SJohn Marino      lang_struct.  See the new_structure function for details.  This is
245*e4b17023SJohn Marino      tricky!  */
246*e4b17023SJohn Marino   type_p next;
247*e4b17023SJohn Marino 
248*e4b17023SJohn Marino   /* State number used when writing & reading the persistent state.  A
249*e4b17023SJohn Marino      type with a positive number has already been written.  For ease
250*e4b17023SJohn Marino      of debugging, newly allocated types have a unique negative
251*e4b17023SJohn Marino      number.  */
252*e4b17023SJohn Marino   int state_number;
253*e4b17023SJohn Marino 
254*e4b17023SJohn Marino   /* Each GTY-ed type which is pointed to by some GTY-ed type knows
255*e4b17023SJohn Marino      the GTY pointer type pointing to it.  See create_pointer
256*e4b17023SJohn Marino      function.  */
257*e4b17023SJohn Marino   type_p pointer_to;
258*e4b17023SJohn Marino 
259*e4b17023SJohn Marino   /* Type usage information, computed by set_gc_used_type and
260*e4b17023SJohn Marino      set_gc_used functions.  */
261*e4b17023SJohn Marino   enum gc_used_enum gc_used;
262*e4b17023SJohn Marino 
263*e4b17023SJohn Marino   /* The following union is discriminated by the 'kind' field above.  */
264*e4b17023SJohn Marino   union {
265*e4b17023SJohn Marino     /* TYPE__NONE is impossible.  */
266*e4b17023SJohn Marino 
267*e4b17023SJohn Marino     /* when TYPE_POINTER:  */
268*e4b17023SJohn Marino     type_p p;
269*e4b17023SJohn Marino 
270*e4b17023SJohn Marino     /* when TYPE_STRUCT or TYPE_UNION or TYPE_LANG_STRUCT, we have an
271*e4b17023SJohn Marino        aggregate type containing fields: */
272*e4b17023SJohn Marino     struct {
273*e4b17023SJohn Marino       const char *tag;          /* the aggragate tag, if any.  */
274*e4b17023SJohn Marino       struct fileloc line;      /* the source location.  */
275*e4b17023SJohn Marino       pair_p fields;            /* the linked list of fields.  */
276*e4b17023SJohn Marino       options_p opt;            /* the GTY options if any.  */
277*e4b17023SJohn Marino       lang_bitmap bitmap;       /* the set of front-end languages
278*e4b17023SJohn Marino                                    using that GTY-ed aggregate.  */
279*e4b17023SJohn Marino       /* For TYPE_LANG_STRUCT, the lang_struct field gives the first
280*e4b17023SJohn Marino          element of a linked list of homonymous struct or union types.
281*e4b17023SJohn Marino          Within this list, each homonymous type has as its lang_struct
282*e4b17023SJohn Marino          field the original TYPE_LANG_STRUCT type.  This is a dirty
283*e4b17023SJohn Marino          trick, see the new_structure function for details.  */
284*e4b17023SJohn Marino       type_p lang_struct;
285*e4b17023SJohn Marino     } s;
286*e4b17023SJohn Marino 
287*e4b17023SJohn Marino     /* when TYPE_SCALAR: */
288*e4b17023SJohn Marino     bool scalar_is_char;
289*e4b17023SJohn Marino 
290*e4b17023SJohn Marino     /* when TYPE_ARRAY: */
291*e4b17023SJohn Marino     struct {
292*e4b17023SJohn Marino       type_p p;                 /* The array component type.  */
293*e4b17023SJohn Marino       const char *len;          /* The string if any giving its length.  */
294*e4b17023SJohn Marino     } a;
295*e4b17023SJohn Marino 
296*e4b17023SJohn Marino     /* When TYPE_PARAM_STRUCT for (param_is, use_param, param1_is,
297*e4b17023SJohn Marino        param2_is, ... use_param1, use_param_2, ... use_params) GTY
298*e4b17023SJohn Marino        options.  */
299*e4b17023SJohn Marino     struct {
300*e4b17023SJohn Marino       type_p stru;              /* The generic GTY-ed type.  */
301*e4b17023SJohn Marino       type_p param[NUM_PARAM];  /* The actual parameter types.  */
302*e4b17023SJohn Marino       struct fileloc line;      /* The source location.  */
303*e4b17023SJohn Marino     } param_struct;
304*e4b17023SJohn Marino 
305*e4b17023SJohn Marino   } u;
306*e4b17023SJohn Marino };
307*e4b17023SJohn Marino 
308*e4b17023SJohn Marino /* The one and only TYPE_STRING.  */
309*e4b17023SJohn Marino extern struct type string_type;
310*e4b17023SJohn Marino 
311*e4b17023SJohn Marino /* The two and only TYPE_SCALARs.  Their u.scalar_is_char flags are
312*e4b17023SJohn Marino    set early in main.  */
313*e4b17023SJohn Marino extern struct type scalar_nonchar;
314*e4b17023SJohn Marino extern struct type scalar_char;
315*e4b17023SJohn Marino 
316*e4b17023SJohn Marino /* Test if a type is a union, either a plain one or a language
317*e4b17023SJohn Marino    specific one.  */
318*e4b17023SJohn Marino #define UNION_P(x)                                      \
319*e4b17023SJohn Marino     ((x)->kind == TYPE_UNION ||                         \
320*e4b17023SJohn Marino      ((x)->kind == TYPE_LANG_STRUCT                     \
321*e4b17023SJohn Marino       && (x)->u.s.lang_struct->kind == TYPE_UNION))
322*e4b17023SJohn Marino 
323*e4b17023SJohn Marino /* Test if a type is a union or a structure, perhaps a language
324*e4b17023SJohn Marino    specific one.  */
325*e4b17023SJohn Marino #define UNION_OR_STRUCT_P(x)			\
326*e4b17023SJohn Marino     ((x)->kind == TYPE_UNION 			\
327*e4b17023SJohn Marino      || (x)->kind == TYPE_STRUCT		\
328*e4b17023SJohn Marino      || (x)->kind == TYPE_LANG_STRUCT)
329*e4b17023SJohn Marino 
330*e4b17023SJohn Marino 
331*e4b17023SJohn Marino 
332*e4b17023SJohn Marino /* Give the file location of a type, if any. */
333*e4b17023SJohn Marino static inline struct fileloc*
type_fileloc(type_p t)334*e4b17023SJohn Marino type_fileloc (type_p t)
335*e4b17023SJohn Marino {
336*e4b17023SJohn Marino   if (!t)
337*e4b17023SJohn Marino     return NULL;
338*e4b17023SJohn Marino   if (UNION_OR_STRUCT_P(t))
339*e4b17023SJohn Marino     return &t->u.s.line;
340*e4b17023SJohn Marino   if  (t->kind == TYPE_PARAM_STRUCT)
341*e4b17023SJohn Marino     return &t->u.param_struct.line;
342*e4b17023SJohn Marino   return NULL;
343*e4b17023SJohn Marino }
344*e4b17023SJohn Marino 
345*e4b17023SJohn Marino /* Structure representing an output file.  */
346*e4b17023SJohn Marino struct outf
347*e4b17023SJohn Marino {
348*e4b17023SJohn Marino   struct outf *next;
349*e4b17023SJohn Marino   const char *name;
350*e4b17023SJohn Marino   size_t buflength;
351*e4b17023SJohn Marino   size_t bufused;
352*e4b17023SJohn Marino   char *buf;
353*e4b17023SJohn Marino };
354*e4b17023SJohn Marino typedef struct outf *outf_p;
355*e4b17023SJohn Marino 
356*e4b17023SJohn Marino /* The list of output files.  */
357*e4b17023SJohn Marino extern outf_p output_files;
358*e4b17023SJohn Marino 
359*e4b17023SJohn Marino /* The output header file that is included into pretty much every
360*e4b17023SJohn Marino    source file.  */
361*e4b17023SJohn Marino extern outf_p header_file;
362*e4b17023SJohn Marino 
363*e4b17023SJohn Marino /* Print, like fprintf, to O.  No-op if O is NULL.  */
364*e4b17023SJohn Marino void
365*e4b17023SJohn Marino oprintf (outf_p o, const char *S, ...)
366*e4b17023SJohn Marino   ATTRIBUTE_PRINTF_2;
367*e4b17023SJohn Marino 
368*e4b17023SJohn Marino /* An output file, suitable for definitions, that can see declarations
369*e4b17023SJohn Marino    made in INPF and is linked into every language that uses INPF.  May
370*e4b17023SJohn Marino    return NULL in plugin mode.  The INPF argument is almost const, but
371*e4b17023SJohn Marino    since the result is cached in its inpoutf field it cannot be
372*e4b17023SJohn Marino    declared const.  */
373*e4b17023SJohn Marino outf_p get_output_file_with_visibility (input_file* inpf);
374*e4b17023SJohn Marino 
375*e4b17023SJohn Marino /* The name of an output file, suitable for definitions, that can see
376*e4b17023SJohn Marino    declarations made in INPF and is linked into every language that
377*e4b17023SJohn Marino    uses INPF.  May return NULL.  */
378*e4b17023SJohn Marino const char *get_output_file_name (input_file *inpf);
379*e4b17023SJohn Marino 
380*e4b17023SJohn Marino 
381*e4b17023SJohn Marino /* Source directory.  */
382*e4b17023SJohn Marino extern const char *srcdir;	/* (-S) program argument. */
383*e4b17023SJohn Marino 
384*e4b17023SJohn Marino /* Length of srcdir name.  */
385*e4b17023SJohn Marino extern size_t srcdir_len;
386*e4b17023SJohn Marino 
387*e4b17023SJohn Marino /* Variable used for reading and writing the state.  */
388*e4b17023SJohn Marino extern const char *read_state_filename; /* (-r) program argument. */
389*e4b17023SJohn Marino extern const char *write_state_filename; /* (-w) program argument. */
390*e4b17023SJohn Marino 
391*e4b17023SJohn Marino /* Functions reading and writing the entire gengtype state, called from
392*e4b17023SJohn Marino    main, and implemented in file gengtype-state.c.  */
393*e4b17023SJohn Marino void read_state (const char* path);
394*e4b17023SJohn Marino /* Write the state, and update the state_number field in types.  */
395*e4b17023SJohn Marino void write_state (const char* path);
396*e4b17023SJohn Marino 
397*e4b17023SJohn Marino 
398*e4b17023SJohn Marino /* Print an error message.  */
399*e4b17023SJohn Marino extern void error_at_line
400*e4b17023SJohn Marino (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;
401*e4b17023SJohn Marino 
402*e4b17023SJohn Marino /* Like asprintf, but calls fatal() on out of memory.  */
403*e4b17023SJohn Marino extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1;
404*e4b17023SJohn Marino 
405*e4b17023SJohn Marino /* Constructor routines for types.  */
406*e4b17023SJohn Marino extern void do_typedef (const char *s, type_p t, struct fileloc *pos);
407*e4b17023SJohn Marino extern void do_scalar_typedef (const char *s, struct fileloc *pos);
408*e4b17023SJohn Marino extern type_p resolve_typedef (const char *s, struct fileloc *pos);
409*e4b17023SJohn Marino extern type_p new_structure (const char *name, int isunion,
410*e4b17023SJohn Marino 			     struct fileloc *pos, pair_p fields,
411*e4b17023SJohn Marino 			     options_p o);
412*e4b17023SJohn Marino extern type_p find_structure (const char *s, int isunion);
413*e4b17023SJohn Marino extern type_p create_scalar_type (const char *name);
414*e4b17023SJohn Marino extern type_p create_pointer (type_p t);
415*e4b17023SJohn Marino extern type_p create_array (type_p t, const char *len);
416*e4b17023SJohn Marino extern pair_p create_field_at (pair_p next, type_p type,
417*e4b17023SJohn Marino 			       const char *name, options_p opt,
418*e4b17023SJohn Marino 			       struct fileloc *pos);
419*e4b17023SJohn Marino extern pair_p nreverse_pairs (pair_p list);
420*e4b17023SJohn Marino extern type_p adjust_field_type (type_p, options_p);
421*e4b17023SJohn Marino extern void note_variable (const char *s, type_p t, options_p o,
422*e4b17023SJohn Marino 			   struct fileloc *pos);
423*e4b17023SJohn Marino extern void note_def_vec (const char *type_name, bool is_scalar,
424*e4b17023SJohn Marino 			  struct fileloc *pos);
425*e4b17023SJohn Marino extern void note_def_vec_alloc (const char *type, const char *astrat,
426*e4b17023SJohn Marino 				struct fileloc *pos);
427*e4b17023SJohn Marino 
428*e4b17023SJohn Marino /* Lexer and parser routines.  */
429*e4b17023SJohn Marino extern int yylex (const char **yylval);
430*e4b17023SJohn Marino extern void yybegin (const char *fname);
431*e4b17023SJohn Marino extern void yyend (void);
432*e4b17023SJohn Marino extern void parse_file (const char *name);
433*e4b17023SJohn Marino extern bool hit_error;
434*e4b17023SJohn Marino 
435*e4b17023SJohn Marino /* Token codes.  */
436*e4b17023SJohn Marino enum
437*e4b17023SJohn Marino   {
438*e4b17023SJohn Marino     EOF_TOKEN = 0,
439*e4b17023SJohn Marino 
440*e4b17023SJohn Marino     /* Per standard convention, codes in the range (0, UCHAR_MAX]
441*e4b17023SJohn Marino        represent single characters with those character codes.  */
442*e4b17023SJohn Marino 
443*e4b17023SJohn Marino     CHAR_TOKEN_OFFSET = UCHAR_MAX + 1,
444*e4b17023SJohn Marino     GTY_TOKEN = CHAR_TOKEN_OFFSET,
445*e4b17023SJohn Marino     TYPEDEF,
446*e4b17023SJohn Marino     EXTERN,
447*e4b17023SJohn Marino     STATIC,
448*e4b17023SJohn Marino     UNION,
449*e4b17023SJohn Marino     STRUCT,
450*e4b17023SJohn Marino     ENUM,
451*e4b17023SJohn Marino     VEC_TOKEN,
452*e4b17023SJohn Marino     DEFVEC_OP,
453*e4b17023SJohn Marino     DEFVEC_I,
454*e4b17023SJohn Marino     DEFVEC_ALLOC,
455*e4b17023SJohn Marino     ELLIPSIS,
456*e4b17023SJohn Marino     PTR_ALIAS,
457*e4b17023SJohn Marino     NESTED_PTR,
458*e4b17023SJohn Marino     PARAM_IS,
459*e4b17023SJohn Marino     NUM,
460*e4b17023SJohn Marino     SCALAR,
461*e4b17023SJohn Marino     ID,
462*e4b17023SJohn Marino     STRING,
463*e4b17023SJohn Marino     CHAR,
464*e4b17023SJohn Marino     ARRAY,
465*e4b17023SJohn Marino 
466*e4b17023SJohn Marino     /* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
467*e4b17023SJohn Marino        a meaningful value to be printed.  */
468*e4b17023SJohn Marino     FIRST_TOKEN_WITH_VALUE = PARAM_IS
469*e4b17023SJohn Marino   };
470*e4b17023SJohn Marino 
471*e4b17023SJohn Marino 
472*e4b17023SJohn Marino /* Level for verbose messages, e.g. output file generation...  */
473*e4b17023SJohn Marino extern int verbosity_level;	/* (-v) program argument.  */
474*e4b17023SJohn Marino 
475*e4b17023SJohn Marino /* For debugging purposes we provide two flags.  */
476*e4b17023SJohn Marino 
477*e4b17023SJohn Marino /* Dump everything to understand gengtype's state. Might be useful to
478*e4b17023SJohn Marino    gengtype users.  */
479*e4b17023SJohn Marino extern int do_dump;		/* (-d) program argument. */
480*e4b17023SJohn Marino 
481*e4b17023SJohn Marino /* Trace the execution by many DBGPRINTF (with the position inside
482*e4b17023SJohn Marino    gengtype source code).  Only useful to debug gengtype itself.  */
483*e4b17023SJohn Marino extern int do_debug;		/* (-D) program argument. */
484*e4b17023SJohn Marino 
485*e4b17023SJohn Marino #if ENABLE_CHECKING
486*e4b17023SJohn Marino #define DBGPRINTF(Fmt,...) do {if (do_debug)				\
487*e4b17023SJohn Marino       fprintf (stderr, "%s:%d: " Fmt "\n",				\
488*e4b17023SJohn Marino 	       lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0)
489*e4b17023SJohn Marino void dbgprint_count_type_at (const char *, int, const char *, type_p);
490*e4b17023SJohn Marino #define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug)			\
491*e4b17023SJohn Marino       dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0)
492*e4b17023SJohn Marino #else
493*e4b17023SJohn Marino #define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0)
494*e4b17023SJohn Marino #define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0)
495*e4b17023SJohn Marino #endif /*ENABLE_CHECKING */
496*e4b17023SJohn Marino 
497*e4b17023SJohn Marino #endif
498