OSDN Git Service

2002-09-10 Matthias Klose <doko@debian.org>
[pf3gnuchains/gcc-fork.git] / gcc / gengtype.h
1 /* Process source files and output type information.
2    Copyright (C) 2002 Free Software Foundation, Inc.
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
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.  */
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
40 /* A way to pass data through to the output end.  */
41 typedef struct options {
42   struct options *next;
43   const char *name;
44   void *info;
45 } *options_p;
46
47 typedef struct pair *pair_p;
48 typedef struct type *type_p;
49 typedef unsigned lang_bitmap;
50
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;
58 };
59
60 /* A description of a type.  */
61 struct type {
62   enum typekind kind;
63   type_p next;
64   type_p pointer_to;
65   enum gc_used_enum {
66     GC_UNUSED = 0,
67     GC_USED,
68     GC_MAYBE_POINTED_TO,
69     GC_POINTED_TO
70   } gc_used;
71   union {
72     type_p p;
73     struct {
74       const char *tag;
75       struct fileloc line;
76       pair_p fields;
77       options_p opt;
78       lang_bitmap bitmap;
79       type_p lang_struct;
80     } s;
81     char *sc;
82     struct {
83       type_p p;
84       const char *len;
85     } a;
86     struct {
87       type_p stru;
88       type_p param;
89       struct fileloc line;
90     } param_struct;
91   } u;
92 };
93
94 #define UNION_P(x)                                      \
95  ((x)->kind == TYPE_UNION ||                            \
96   ((x)->kind == TYPE_LANG_STRUCT                        \
97    && (x)->u.s.lang_struct->kind == TYPE_UNION))
98 #define UNION_OR_STRUCT_P(x)                    \
99  ((x)->kind == TYPE_UNION                       \
100   || (x)->kind == TYPE_STRUCT                   \
101   || (x)->kind == TYPE_LANG_STRUCT)
102
103 /* The one and only TYPE_STRING.  */
104 extern struct type string_type;
105
106 /* Variables used to communicate between the lexer and the parser.  */
107 extern int lexer_toplevel_done;
108 extern struct fileloc lexer_line;
109
110 /* Print an error message.  */
111 extern void error_at_line 
112   PARAMS ((struct fileloc *pos, const char *msg, ...)) ATTRIBUTE_PRINTF_2;
113
114 /* Combines xmalloc() and vasprintf().  */
115 extern int xvasprintf PARAMS ((char **, const char *, va_list))
116      ATTRIBUTE_PRINTF (2, 0);
117 /* Like the above, but more convenient for quick coding.  */
118 extern char * xasprintf PARAMS ((const char *, ...))
119      ATTRIBUTE_PRINTF_1;
120
121 /* Constructor routines for types.  */
122 extern void do_typedef PARAMS ((const char *s, type_p t, struct fileloc *pos));
123 extern type_p resolve_typedef PARAMS ((const char *s, struct fileloc *pos));
124 extern void new_structure PARAMS ((const char *name, int isunion, 
125                                    struct fileloc *pos, pair_p fields, 
126                                    options_p o));
127 extern type_p find_structure PARAMS ((const char *s, int isunion));
128 extern type_p create_scalar_type PARAMS ((const char *name, size_t name_len));
129 extern type_p create_pointer PARAMS ((type_p t));
130 extern type_p create_array PARAMS ((type_p t, const char *len));
131 extern type_p adjust_field_type PARAMS ((type_p, options_p));
132 extern void note_variable PARAMS ((const char *s, type_p t, options_p o,
133                                    struct fileloc *pos));
134 extern void note_yacc_type PARAMS ((options_p o, pair_p fields,
135                                     pair_p typeinfo, struct fileloc *pos));
136
137 /* Lexer and parser routines, most automatically generated.  */
138 extern int yylex PARAMS((void));
139 extern void yyerror PARAMS ((const char *));
140 extern int yyparse PARAMS ((void));
141 extern void parse_file PARAMS ((const char *name));
142
143 /* Output file handling.  */
144
145 /* Structure representing an output file.  */
146 struct outf 
147 {
148   struct outf *next;
149   const char *name;
150   size_t buflength;
151   size_t bufused;
152   char *buf;
153 };
154
155 typedef struct outf * outf_p;
156
157 /* The output header file that is included into pretty much every
158    source file.  */
159 extern outf_p header_file;
160
161 /* An output file, suitable for definitions, that can see declarations
162    made in INPUT_FILE and is linked into every language that uses
163    INPUT_FILE.  */
164 extern outf_p get_output_file_with_visibility 
165    PARAMS ((const char *input_file));
166 const char *get_output_file_name PARAMS ((const char *));
167
168 /* A list of output files suitable for definitions.  There is one
169    BASE_FILES entry for each language.  */
170 extern outf_p base_files[];
171
172 /* A bitmap that specifies which of BASE_FILES should be used to
173    output a definition that is different for each language and must be
174    defined once in each language that uses INPUT_FILE.  */
175 extern lang_bitmap get_base_file_bitmap PARAMS ((const char *input_file));
176
177 /* Print, like fprintf, to O.  */
178 extern void oprintf PARAMS ((outf_p o, const char *S, ...))
179      ATTRIBUTE_PRINTF_2;