DEADSOFTWARE

Добавлена проверка базы записи на рекурсивное расширение
[dsw-obn.git] / src / oberon-internals.h
1 #ifndef OBERON_INTERNALS_H
2 #define OBERON_INTERNALS_H
4 #include <stdint.h>
5 #include <stdbool.h>
7 typedef struct gen_module_t gen_module_t;
8 typedef struct gen_proc_t gen_proc_t;
9 typedef struct gen_type_t gen_type_t;
10 typedef struct gen_var_t gen_var_t;
11 typedef struct gen_label_t gen_label_t;
12 typedef struct gen_context_t gen_context_t;
14 typedef struct oberon_type_t oberon_type_t;
15 typedef struct oberon_object_t oberon_object_t;
16 typedef struct oberon_module_t oberon_module_t;
17 typedef struct oberon_context_t oberon_context_t;
18 typedef struct oberon_scope_t oberon_scope_t;
20 typedef struct oberon_item_t oberon_item_t;
21 typedef struct oberon_oper_t oberon_oper_t;
22 typedef union oberon_expr_t oberon_expr_t;
24 struct oberon_scope_t
25 {
26 oberon_context_t * ctx;
27 oberon_object_t * list;
28 oberon_scope_t * up;
30 int local;
31 oberon_object_t * parent;
32 oberon_type_t * parent_type;
34 gen_label_t * exit_label;
35 };
37 enum oberon_type_kind
38 {
39 OBERON_TYPE_VOID,
40 OBERON_TYPE_INTEGER,
41 OBERON_TYPE_BOOLEAN,
42 OBERON_TYPE_PROCEDURE,
43 OBERON_TYPE_ARRAY,
44 OBERON_TYPE_RECORD,
45 OBERON_TYPE_POINTER,
46 OBERON_TYPE_REAL,
47 OBERON_TYPE_CHAR,
48 OBERON_TYPE_STRING,
49 OBERON_TYPE_SET
50 };
52 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
53 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
55 struct oberon_type_t
56 {
57 enum oberon_type_kind class;
58 int size;
60 int num_decl;
61 oberon_type_t * base;
62 oberon_object_t * decl;
63 oberon_scope_t * scope;
65 bool sysproc;
66 GenerateFuncCallback genfunc;
67 GenerateProcCallback genproc;
69 oberon_module_t * module;
71 int recursive;
72 int initialized;
73 gen_type_t * gen_type;
74 };
76 enum oberon_object_kind
77 {
78 OBERON_CLASS_VAR,
79 OBERON_CLASS_TYPE,
80 OBERON_CLASS_PROC,
81 OBERON_CLASS_PARAM,
82 OBERON_CLASS_VAR_PARAM,
83 OBERON_CLASS_CONST,
84 OBERON_CLASS_FIELD,
85 OBERON_CLASS_MODULE
86 };
88 struct oberon_object_t
89 {
90 char * name;
91 enum oberon_object_kind class;
92 int export;
93 int read_only;
95 int local;
96 int linked;
97 int initialized;
99 oberon_object_t * parent;
100 oberon_type_t * parent_type;
102 oberon_scope_t * scope; // for proc
103 int has_return; // for proc
105 oberon_type_t * type;
106 oberon_item_t * value;
107 oberon_object_t * next;
109 oberon_module_t * module;
111 gen_var_t * gen_var;
112 gen_proc_t * gen_proc;
113 };
115 struct oberon_module_t
117 char * name;
118 int ready;
120 oberon_scope_t * decl;
122 oberon_module_t * next;
124 gen_module_t * gen_mod;
125 };
127 typedef const char * (*ModuleImportCallback)(const char * name);
129 struct oberon_context_t
131 /*** SCANER DATA ***/
132 const char * code;
133 int code_index;
135 char c;
136 int token;
137 char * string;
138 int64_t integer;
139 double real;
140 bool longmode;
141 /*** END SCANER DATA ***/
143 /*** PARSER DATA ***/
144 oberon_scope_t * decl;
145 oberon_module_t * mod;
146 /*** END PARSER DATA ***/
148 oberon_type_t * void_type;
149 oberon_type_t * void_ptr_type;
150 oberon_type_t * bool_type;
151 oberon_type_t * byte_type;
152 oberon_type_t * shortint_type;
153 oberon_type_t * int_type;
154 oberon_type_t * longint_type;
155 oberon_type_t * real_type;
156 oberon_type_t * longreal_type;
157 oberon_type_t * char_type;
158 oberon_type_t * string_type;
159 oberon_type_t * set_type;
161 oberon_scope_t * world_scope;
162 oberon_module_t * module_list;
163 ModuleImportCallback import_module;
164 gen_context_t * gen_context;
165 };
167 enum oberon_mode_kind
169 MODE_VAR,
170 MODE_INTEGER,
171 MODE_BOOLEAN,
172 MODE_CALL,
173 MODE_INDEX,
174 MODE_FIELD,
175 MODE_DEREF,
176 MODE_NIL,
177 MODE_NEW,
178 MODE_REAL,
179 MODE_CHAR,
180 MODE_STRING,
181 MODE_TYPE,
182 MODE_SET
183 };
185 enum oberon_operator_kind
187 OP_UNARY_MINUS,
188 OP_LOGIC_NOT,
189 OP_ABS,
191 OP_ADD,
192 OP_SUB,
193 OP_MUL,
194 OP_DIV,
195 OP_MOD,
196 OP_LOGIC_AND,
197 OP_LOGIC_OR,
199 OP_EQ,
200 OP_NEQ,
201 OP_LSS,
202 OP_LEQ,
203 OP_GRT,
204 OP_GEQ,
206 OP_CAST,
207 OP_IS,
209 OP_RANGE,
210 OP_UNION,
211 OP_INTERSECTION,
212 OP_DIFFERENCE,
213 OP_SYM_DIFFERENCE,
214 OP_COMPLEMENTATION,
215 OP_IN
216 };
218 struct oberon_item_t
220 bool is_item; // == 1
221 oberon_type_t * result;
222 oberon_expr_t * next;
223 bool read_only;
225 enum oberon_mode_kind mode;
226 long integer;
227 double real;
228 char * string;
229 oberon_object_t * var;
231 oberon_item_t * parent;
233 int num_args;
234 oberon_expr_t * args;
235 };
237 struct oberon_oper_t
239 bool is_item; // == 0
240 oberon_type_t * result;
241 oberon_expr_t * next;
242 bool read_only;
244 enum oberon_operator_kind op;
245 oberon_expr_t * left;
246 oberon_expr_t * right;
247 };
249 union oberon_expr_t
251 struct {
252 bool is_item;
253 oberon_type_t * result;
254 oberon_expr_t * next;
255 bool read_only;
256 };
258 oberon_item_t item;
259 oberon_oper_t oper;
260 };
262 #endif // OBERON_INTERNALS_H