1117395Skan/* Process source files and output type information. 2169689Skan Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. 3117395Skan 4117395SkanThis file is part of GCC. 5117395Skan 6117395SkanGCC is free software; you can redistribute it and/or modify it under 7117395Skanthe terms of the GNU General Public License as published by the Free 8117395SkanSoftware Foundation; either version 2, or (at your option) any later 9117395Skanversion. 10117395Skan 11117395SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 12117395SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 13117395SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14117395Skanfor more details. 15117395Skan 16117395SkanYou should have received a copy of the GNU General Public License 17117395Skanalong with GCC; see the file COPYING. If not, write to the Free 18169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 19169689Skan02110-1301, USA. */ 20117395Skan 21117395Skan/* A file position, mostly for error messages. 22117395Skan The FILE element may be compared using pointer equality. */ 23117395Skanstruct fileloc { 24117395Skan const char *file; 25117395Skan int line; 26117395Skan}; 27117395Skan 28117395Skan/* Kinds of types we can understand. */ 29117395Skanenum typekind { 30117395Skan TYPE_SCALAR, 31117395Skan TYPE_STRING, 32117395Skan TYPE_STRUCT, 33117395Skan TYPE_UNION, 34117395Skan TYPE_POINTER, 35117395Skan TYPE_ARRAY, 36117395Skan TYPE_LANG_STRUCT, 37117395Skan TYPE_PARAM_STRUCT 38117395Skan}; 39117395Skan 40169689Skantypedef struct pair *pair_p; 41169689Skantypedef struct type *type_p; 42169689Skantypedef unsigned lang_bitmap; 43169689Skan 44169689Skan/* Option data for the 'nested_ptr' option. */ 45169689Skanstruct nested_ptr_data { 46169689Skan type_p type; 47169689Skan const char *convert_to; 48169689Skan const char *convert_from; 49169689Skan}; 50169689Skan 51117395Skan/* A way to pass data through to the output end. */ 52117395Skantypedef struct options { 53117395Skan struct options *next; 54117395Skan const char *name; 55169689Skan const char *info; 56117395Skan} *options_p; 57117395Skan 58117395Skan/* A name and a type. */ 59117395Skanstruct pair { 60117395Skan pair_p next; 61117395Skan const char *name; 62117395Skan type_p type; 63117395Skan struct fileloc line; 64117395Skan options_p opt; 65117395Skan}; 66117395Skan 67117395Skan#define NUM_PARAM 10 68117395Skan 69117395Skan/* A description of a type. */ 70169689Skanenum gc_used_enum 71169689Skan { 72169689Skan GC_UNUSED = 0, 73169689Skan GC_USED, 74169689Skan GC_MAYBE_POINTED_TO, 75169689Skan GC_POINTED_TO 76169689Skan }; 77169689Skan 78117395Skanstruct type { 79117395Skan enum typekind kind; 80117395Skan type_p next; 81117395Skan type_p pointer_to; 82169689Skan enum gc_used_enum gc_used; 83117395Skan union { 84117395Skan type_p p; 85117395Skan struct { 86117395Skan const char *tag; 87117395Skan struct fileloc line; 88117395Skan pair_p fields; 89117395Skan options_p opt; 90117395Skan lang_bitmap bitmap; 91117395Skan type_p lang_struct; 92117395Skan } s; 93117395Skan char *sc; 94117395Skan struct { 95117395Skan type_p p; 96117395Skan const char *len; 97117395Skan } a; 98117395Skan struct { 99117395Skan type_p stru; 100117395Skan type_p param[NUM_PARAM]; 101117395Skan struct fileloc line; 102117395Skan } param_struct; 103117395Skan } u; 104117395Skan}; 105117395Skan 106117395Skan#define UNION_P(x) \ 107117395Skan ((x)->kind == TYPE_UNION || \ 108117395Skan ((x)->kind == TYPE_LANG_STRUCT \ 109117395Skan && (x)->u.s.lang_struct->kind == TYPE_UNION)) 110117395Skan#define UNION_OR_STRUCT_P(x) \ 111117395Skan ((x)->kind == TYPE_UNION \ 112117395Skan || (x)->kind == TYPE_STRUCT \ 113117395Skan || (x)->kind == TYPE_LANG_STRUCT) 114117395Skan 115117395Skan/* The one and only TYPE_STRING. */ 116117395Skanextern struct type string_type; 117117395Skan 118117395Skan/* Variables used to communicate between the lexer and the parser. */ 119117395Skanextern int lexer_toplevel_done; 120117395Skanextern struct fileloc lexer_line; 121117395Skan 122117395Skan/* Print an error message. */ 123117395Skanextern void error_at_line 124132718Skan (struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2; 125117395Skan 126117395Skan/* Combines xmalloc() and vasprintf(). */ 127132718Skanextern int xvasprintf (char **, const char *, va_list) 128117395Skan ATTRIBUTE_PRINTF (2, 0); 129117395Skan/* Like the above, but more convenient for quick coding. */ 130132718Skanextern char * xasprintf (const char *, ...) 131117395Skan ATTRIBUTE_PRINTF_1; 132117395Skan 133117395Skan/* Constructor routines for types. */ 134132718Skanextern void do_typedef (const char *s, type_p t, struct fileloc *pos); 135132718Skanextern type_p resolve_typedef (const char *s, struct fileloc *pos); 136169689Skanextern type_p new_structure (const char *name, int isunion, 137169689Skan struct fileloc *pos, pair_p fields, 138169689Skan options_p o); 139132718Skanextern type_p find_structure (const char *s, int isunion); 140132718Skanextern type_p create_scalar_type (const char *name, size_t name_len); 141132718Skanextern type_p create_pointer (type_p t); 142132718Skanextern type_p create_array (type_p t, const char *len); 143169689Skanextern options_p create_option (options_p, const char *name, const void *info); 144132718Skanextern type_p adjust_field_type (type_p, options_p); 145132718Skanextern void note_variable (const char *s, type_p t, options_p o, 146132718Skan struct fileloc *pos); 147132718Skanextern void note_yacc_type (options_p o, pair_p fields, 148132718Skan pair_p typeinfo, struct fileloc *pos); 149117395Skan 150117395Skan/* Lexer and parser routines, most automatically generated. */ 151132718Skanextern int yylex (void); 152132718Skanextern void yyerror (const char *); 153132718Skanextern int yyparse (void); 154132718Skanextern void parse_file (const char *name); 155117395Skan 156117395Skan/* Output file handling. */ 157117395Skan 158117395Skan/* Structure representing an output file. */ 159117395Skanstruct outf 160117395Skan{ 161117395Skan struct outf *next; 162117395Skan const char *name; 163117395Skan size_t buflength; 164117395Skan size_t bufused; 165117395Skan char *buf; 166117395Skan}; 167117395Skan 168117395Skantypedef struct outf * outf_p; 169117395Skan 170117395Skan/* An output file, suitable for definitions, that can see declarations 171117395Skan made in INPUT_FILE and is linked into every language that uses 172117395Skan INPUT_FILE. */ 173117395Skanextern outf_p get_output_file_with_visibility 174132718Skan (const char *input_file); 175132718Skanconst char *get_output_file_name (const char *); 176117395Skan 177117395Skan/* A list of output files suitable for definitions. There is one 178117395Skan BASE_FILES entry for each language. */ 179117395Skanextern outf_p base_files[]; 180117395Skan 181117395Skan/* A bitmap that specifies which of BASE_FILES should be used to 182117395Skan output a definition that is different for each language and must be 183117395Skan defined once in each language that uses INPUT_FILE. */ 184132718Skanextern lang_bitmap get_base_file_bitmap (const char *input_file); 185117395Skan 186117395Skan/* Print, like fprintf, to O. */ 187132718Skanextern void oprintf (outf_p o, const char *S, ...) 188117395Skan ATTRIBUTE_PRINTF_2; 189