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. 30extern FILE* yyin; 31 32// Name of the file we're currently parsing. 33extern char lexfile[]; 34 35// The line we're currently parsing. 36extern int yylineno; 37 38struct field_t; 39 40// Describes a data type. 41struct type_t { 42 type_code code; // type code 43 const char* name; // name of this type 44 int32 count; // how many fields 45 field_t* fields; // field definitions 46 int32 def_id; // default resource ID 47 const char* def_name; // default resource name 48}; 49 50// Used by the lexer and parser to pass around resource data. The rdef 51// format allows string literals to contain embedded '\0' chars, so we 52// can't use strlen() to find their length; instead we look at the size 53// field for that (size includes the final '\0' too). 54struct data_t { 55 type_t type; // data type 56 char* name; // name (only if this is a field) 57 size_t size; // byte size of data 58 void* ptr; // the actual data 59}; 60 61// Describes a data field in a user-defined type. 62struct field_t { 63 type_t type; // data type 64 const char* name; // name of this field 65 size_t resize; // if not 0, data will be resized 66 data_t data; // default value 67}; 68 69// Describes an array of data_t or field_t objects. 70struct list_t { 71 int32 count; 72 void* items; // cast to data_t* or field_t* 73}; 74 75// Used by the parser to pass around resource IDs. 76struct res_id_t { 77 bool has_id; 78 bool has_name; 79 int32 id; 80 char* name; 81}; 82 83// Describes a symbolic constant. 84struct define_t { 85 const char* name; 86 int32 value; 87}; 88 89// The output file we add resources to. 90extern BResources rsrc; 91extern const char* rsrc_file; 92 93int yylex(); 94int yyparse(); 95 96void init_lexer(); 97void clean_up_lexer(); 98 99void init_parser(); 100void clean_up_parser(); 101 102void* alloc_mem(size_t size); 103void free_mem(void* ptr); 104 105// Returns the data type with the specified name. 106type_t get_type(const char* name); 107 108void abort_compile(status_t err, const char* format, ...); 109void abort_compile(); 110 111#endif // COMPILE_H 112