In gcc/objc/: 2010-11-01 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / gcc / gengtype.h
blob968288d2ff8006c5135d6dbd706a990c22ba2f41
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
10 version.
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.
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 /* A file position, mostly for error messages.
29 The FILE element may be compared using pointer equality. */
30 struct fileloc
32 const char *file;
33 int line;
36 /* Data types handed around within, but opaque to, the lexer and parser. */
37 typedef struct pair *pair_p;
38 typedef struct type *type_p;
39 typedef const struct type *const_type_p;
40 typedef struct options *options_p;
42 /* Variables used to communicate between the lexer and the parser. */
43 extern int lexer_toplevel_done;
44 extern struct fileloc lexer_line;
46 /* Structure representing an output file. */
47 struct outf
49 struct outf *next;
50 const char *name;
51 size_t buflength;
52 size_t bufused;
53 char *buf;
55 typedef struct outf *outf_p;
57 /* The list of output files. */
58 extern outf_p output_files;
60 /* The output header file that is included into pretty much every
61 source file. */
62 extern outf_p header_file;
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;
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);
74 /* Source directory. */
75 extern const char *srcdir; /* (-S) program argument. */
77 /* Length of srcdir name. */
78 extern size_t srcdir_len;
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. */
84 /* Print an error message. */
85 extern void error_at_line
86 (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;
88 /* Like asprintf, but calls fatal() on out of memory. */
89 extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1;
91 /* Constructor routines for types. */
92 extern void do_typedef (const char *s, type_p t, struct fileloc *pos);
93 extern void do_scalar_typedef (const char *s, struct fileloc *pos);
94 extern type_p resolve_typedef (const char *s, struct fileloc *pos);
95 extern type_p new_structure (const char *name, int isunion,
96 struct fileloc *pos, pair_p fields,
97 options_p o);
98 extern type_p find_structure (const char *s, int isunion);
99 extern type_p create_scalar_type (const char *name);
100 extern type_p create_pointer (type_p t);
101 extern type_p create_array (type_p t, const char *len);
102 extern options_p create_option (options_p, const char *name,
103 const void *info);
104 extern options_p create_nested_ptr_option (options_p, type_p t,
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);
110 extern pair_p nreverse_pairs (pair_p list);
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);
114 extern void note_def_vec (const char *type_name, bool is_scalar,
115 struct fileloc *pos);
116 extern void note_def_vec_alloc (const char *type, const char *astrat,
117 struct fileloc *pos);
119 /* Lexer and parser routines. */
120 extern int yylex (const char **yylval);
121 extern void yybegin (const char *fname);
122 extern void yyend (void);
123 extern void parse_file (const char *name);
124 extern bool hit_error;
126 /* Token codes. */
127 enum
129 EOF_TOKEN = 0,
131 /* Per standard convention, codes in the range (0, UCHAR_MAX]
132 represent single characters with those character codes. */
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,
153 STRING,
154 CHAR,
155 ARRAY,
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
163 /* Level for verbose messages, e.g. output file generation... */
164 extern int verbosity_level; /* (-v) program argument. */
166 /* For debugging purposes we provide two flags. */
168 /* Dump everything to understand gengtype's state. Might be useful to
169 gengtype users. */
170 extern int do_dump; /* (-d) program argument. */
172 /* Trace the execution by many DBGPRINTF (with the position inside
173 gengtype source code). Only useful to debug gengtype itself. */
174 extern int do_debug; /* (-D) program argument. */
176 #if ENABLE_CHECKING
177 #define DBGPRINTF(Fmt,...) do {if (do_debug) \
178 fprintf (stderr, "%s:%d: " Fmt "\n", \
179 lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0)
180 void dbgprint_count_type_at (const char *, int, const char *, type_p);
181 #define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug) \
182 dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0)
183 #else
184 #define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0)
185 #define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0)
186 #endif /*ENABLE_CHECKING */
188 #endif