1 /* 2 * Copyright (c) 2003 Matthijs Hollemans 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef COMPILE_H 24 #define COMPILE_H 25 26 #include <Resources.h> 27 #include <TypeConstants.h> 28 29 // Handle of file we're currently parsing. 30 extern FILE* yyin; 31 32 // Name of the file we're currently parsing. 33 extern char lexfile[]; 34 35 // The line we're currently parsing. 36 extern int yylineno; 37 38 struct field_t; 39 40 // Describes a data type. 41 struct type_t 42 { 43 type_code code; // type code 44 char* name; // name of this type 45 int32 count; // how many fields 46 field_t* fields; // field definitions 47 int32 def_id; // default resource ID 48 char* def_name; // default resource name 49 }; 50 51 // Used by the lexer and parser to pass around resource data. The rdef 52 // format allows string literals to contain embedded '\0' chars, so we 53 // can't use strlen() to find their length; instead we look at the size 54 // field for that (size includes the final '\0' too). 55 struct data_t 56 { 57 type_t type; // data type 58 char* name; // name (only if this is a field) 59 size_t size; // byte size of data 60 void* ptr; // the actual data 61 }; 62 63 // Describes a data field in a user-defined type. 64 struct field_t 65 { 66 type_t type; // data type 67 char* name; // name of this field 68 size_t resize; // if not 0, data will be resized 69 data_t data; // default value 70 }; 71 72 // Describes an array of data_t or field_t objects. 73 struct list_t 74 { 75 int32 count; 76 void* items; // cast to data_t* or field_t* 77 }; 78 79 // Used by the parser to pass around resource IDs. 80 struct res_id_t 81 { 82 bool has_id; 83 bool has_name; 84 int32 id; 85 char* name; 86 }; 87 88 // Describes a symbolic constant. 89 struct define_t 90 { 91 char* name; 92 int32 value; 93 }; 94 95 // The output file we add resources to. 96 extern BResources rsrc; 97 extern const char* rsrc_file; 98 99 int yylex(); 100 int yyparse(); 101 102 void init_lexer(); 103 void clean_up_lexer(); 104 105 void init_parser(); 106 void clean_up_parser(); 107 108 void* alloc_mem(size_t size); 109 void free_mem(void* ptr); 110 111 // Returns the data type with the specified name. 112 type_t get_type(char* name); 113 114 void abort_compile(status_t err, const char* format, ...); 115 void abort_compile(); 116 117 #endif // COMPILE_H 118