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