xref: /haiku/src/bin/rc/compile.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
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 	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).
54 struct 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.
62 struct 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.
70 struct 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.
76 struct res_id_t {
77 	bool			has_id;
78 	bool			has_name;
79 	int32			id;
80 	char*			name;
81 };
82 
83 // Describes a symbolic constant.
84 struct define_t {
85 	const char*		name;
86 	int32			value;
87 };
88 
89 // The output file we add resources to.
90 extern BResources rsrc;
91 extern const char* rsrc_file;
92 
93 int yylex();
94 int yyparse();
95 
96 void init_lexer();
97 void clean_up_lexer();
98 
99 void init_parser();
100 void clean_up_parser();
101 
102 void* alloc_mem(size_t size);
103 void free_mem(void* ptr);
104 
105 // Returns the data type with the specified name.
106 type_t get_type(const char* name);
107 
108 void abort_compile(status_t err, const char* format, ...);
109 void abort_compile();
110 
111 #endif // COMPILE_H
112