1285c7c73Smahlzeit/*
2285c7c73Smahlzeit * Copyright (c) 2003 Matthijs Hollemans
3a5079edcSAxel Dörfler *
4a5079edcSAxel Dörfler * Permission is hereby granted, free of charge, to any person obtaining a
5a5079edcSAxel Dörfler * copy of this software and associated documentation files (the "Software"),
6a5079edcSAxel Dörfler * to deal in the Software without restriction, including without limitation
7a5079edcSAxel Dörfler * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8a5079edcSAxel Dörfler * and/or sell copies of the Software, and to permit persons to whom the
9285c7c73Smahlzeit * Software is furnished to do so, subject to the following conditions:
10a5079edcSAxel Dörfler *
11a5079edcSAxel Dörfler * The above copyright notice and this permission notice shall be included in
12285c7c73Smahlzeit * all copies or substantial portions of the Software.
13a5079edcSAxel Dörfler *
14a5079edcSAxel Dörfler * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15a5079edcSAxel Dörfler * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16a5079edcSAxel Dörfler * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17a5079edcSAxel Dörfler * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18a5079edcSAxel Dörfler * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19a5079edcSAxel Dörfler * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20285c7c73Smahlzeit * DEALINGS IN THE SOFTWARE.
21285c7c73Smahlzeit */
22285c7c73Smahlzeit
23285c7c73Smahlzeit#ifndef COMPILE_H
24285c7c73Smahlzeit#define COMPILE_H
25285c7c73Smahlzeit
26285c7c73Smahlzeit#include <Resources.h>
27285c7c73Smahlzeit#include <TypeConstants.h>
28285c7c73Smahlzeit
29285c7c73Smahlzeit// Handle of file we're currently parsing.
30285c7c73Smahlzeitextern FILE* yyin;
31285c7c73Smahlzeit
32285c7c73Smahlzeit// Name of the file we're currently parsing.
33285c7c73Smahlzeitextern char lexfile[];
34285c7c73Smahlzeit
35285c7c73Smahlzeit// The line we're currently parsing.
36285c7c73Smahlzeitextern int yylineno;
37285c7c73Smahlzeit
38285c7c73Smahlzeitstruct field_t;
39285c7c73Smahlzeit
40285c7c73Smahlzeit// Describes a data type.
41a5079edcSAxel Dörflerstruct type_t {
42a5079edcSAxel Dörfler	type_code		code;			// type code
43a5079edcSAxel Dörfler	const char*		name;			// name of this type
44a5079edcSAxel Dörfler	int32			count;			// how many fields
45a5079edcSAxel Dörfler	field_t*		fields;			// field definitions
46a5079edcSAxel Dörfler	int32			def_id;			// default resource ID
47a5079edcSAxel Dörfler	const char*		def_name;		// default resource name
48285c7c73Smahlzeit};
49285c7c73Smahlzeit
50285c7c73Smahlzeit// Used by the lexer and parser to pass around resource data. The rdef
51285c7c73Smahlzeit// format allows string literals to contain embedded '\0' chars, so we
52285c7c73Smahlzeit// can't use strlen() to find their length; instead we look at the size
53285c7c73Smahlzeit// field for that (size includes the final '\0' too).
54a5079edcSAxel Dörflerstruct data_t {
55a5079edcSAxel Dörfler	type_t			type;			// data type
56a5079edcSAxel Dörfler	char*			name;			// name (only if this is a field)
57a5079edcSAxel Dörfler	size_t			size;			// byte size of data
58a5079edcSAxel Dörfler	void*			ptr;			// the actual data
59285c7c73Smahlzeit};
60285c7c73Smahlzeit
61285c7c73Smahlzeit// Describes a data field in a user-defined type.
62a5079edcSAxel Dörflerstruct field_t {
63a5079edcSAxel Dörfler	type_t			type;			// data type
64a5079edcSAxel Dörfler	const char*		name;			// name of this field
65a5079edcSAxel Dörfler	size_t			resize;			// if not 0, data will be resized
66a5079edcSAxel Dörfler	data_t			data;			// default value
67285c7c73Smahlzeit};
68285c7c73Smahlzeit
69285c7c73Smahlzeit// Describes an array of data_t or field_t objects.
70a5079edcSAxel Dörflerstruct list_t {
71a5079edcSAxel Dörfler	int32			count;
72a5079edcSAxel Dörfler	void*			items;			// cast to data_t* or field_t*
73285c7c73Smahlzeit};
74285c7c73Smahlzeit
75285c7c73Smahlzeit// Used by the parser to pass around resource IDs.
76a5079edcSAxel Dörflerstruct res_id_t {
77a5079edcSAxel Dörfler	bool			has_id;
78a5079edcSAxel Dörfler	bool			has_name;
79a5079edcSAxel Dörfler	int32			id;
80a5079edcSAxel Dörfler	char*			name;
81285c7c73Smahlzeit};
82285c7c73Smahlzeit
83eed2e48eSmahlzeit// Describes a symbolic constant.
84a5079edcSAxel Dörflerstruct define_t {
85a5079edcSAxel Dörfler	const char*		name;
86a5079edcSAxel Dörfler	int32			value;
87eed2e48eSmahlzeit};
88eed2e48eSmahlzeit
89285c7c73Smahlzeit// The output file we add resources to.
90285c7c73Smahlzeitextern BResources rsrc;
91285c7c73Smahlzeitextern const char* rsrc_file;
92285c7c73Smahlzeit
93285c7c73Smahlzeitint yylex();
94285c7c73Smahlzeitint yyparse();
95285c7c73Smahlzeit
96285c7c73Smahlzeitvoid init_lexer();
97285c7c73Smahlzeitvoid clean_up_lexer();
98285c7c73Smahlzeit
99285c7c73Smahlzeitvoid init_parser();
100285c7c73Smahlzeitvoid clean_up_parser();
101285c7c73Smahlzeit
102285c7c73Smahlzeitvoid* alloc_mem(size_t size);
103285c7c73Smahlzeitvoid free_mem(void* ptr);
104285c7c73Smahlzeit
105285c7c73Smahlzeit// Returns the data type with the specified name.
106a5079edcSAxel Dörflertype_t get_type(const char* name);
107285c7c73Smahlzeit
108285c7c73Smahlzeitvoid abort_compile(status_t err, const char* format, ...);
109285c7c73Smahlzeitvoid abort_compile();
110285c7c73Smahlzeit
111285c7c73Smahlzeit#endif // COMPILE_H
112