-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpars_utils.h
306 lines (262 loc) · 14.6 KB
/
pars_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/**
* \file pars_utils.h
* \brief Parse utilities include file
*/
/*
* Copyright (c) 2024 Lennart BINKOWSKI
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* This file is part of cq_compiler.
*
* Author: Lennart BINKOWSKI <[email protected]>
*/
/*
* =====================================================================================================================
* header guard
* =====================================================================================================================
*/
#ifndef PARSING_H
#define PARSING_H
/*
* =====================================================================================================================
* includes
* =====================================================================================================================
*/
#include <stdbool.h>
#include "ast.h"
#include "symbol_table.h"
/*
* =====================================================================================================================
* C++ check
* =====================================================================================================================
*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* =====================================================================================================================
* type definitions
* =====================================================================================================================
*/
typedef struct stmt_list {
bool is_unitary;
bool is_quantizable;
node_t **stmt_nodes;
unsigned num_of_stmts;
} stmt_list_t;
/**
* \brief Function info struct
* \note This structure defines all characteristics (except return type) of a function
*/
typedef struct func_info {
bool is_unitary; /*!< Whether function is unitary */
bool is_quantizable; /*!< Whether function can be quantized */
type_info_t *pars_type_info; /*!< Type information of function parameters */
unsigned num_of_pars; /*!< Number of function parameters */
} func_info_t;
typedef struct access_info {
entry_t *entry;
bool index_is_const[MAX_ARRAY_DEPTH];
index_t indices[MAX_ARRAY_DEPTH];
unsigned index_depth;
} access_info_t;
typedef struct init_info {
bool is_init_list;
union {
node_t *node;
struct {
q_type_t *qualified_types;
array_value_t *values;
unsigned length;
};
};
} init_info_t;
typedef struct else_if_list {
node_t **else_if_nodes;
unsigned num_of_else_ifs;
} else_if_list_t;
typedef struct case_list {
node_t **case_nodes;
unsigned num_of_cases;
} case_list_t;
typedef struct arg_list {
node_t **args;
unsigned num_of_args;
} arg_list_t;
/*
* =====================================================================================================================
* function declarations
* =====================================================================================================================
*/
/**
* \brief Setup type information at a given address with primitive type
* \param[out] type_info: Address to setup the type information at
* \param[in] type: Primitive type of type information
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the type information was successful
*/
bool setup_type_info(type_info_t *type_info, type_t type, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append size to type information at a given address
* \param[out] type_info: Address of type information
* \param[in] node: Pointer to node carrying the appended size
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending size to type information was successful
*/
bool append_to_type_info(type_info_t *type_info, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup statement list at a given address with node
* \param[out] stmt_list: Address to setup the statement list at
* \param[in] node: Pointer to initial statement node
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the statement list was successful
*/
bool setup_stmt_list(stmt_list_t *stmt_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append statement to statement list at a given address
* \param[out] stmt_list: Address of statement list
* \param[in] node: Pointer to appended statement node
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending statement to statement list was successful
*/
bool append_to_stmt_list(stmt_list_t *stmt_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup empty function information at a given address
* \param[out] func_info: Address to setup the empty function information at
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the empty function information was successful
*/
bool setup_empty_func_info(func_info_t *func_info, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup function information at a given address with return type information
* \param[out] func_info: Address to setup the function information at
* \param[in] type_info: Return type information
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the function information was successful
*/
bool setup_func_info(func_info_t *func_info, type_info_t type_info, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append return type information to function information at a given address
* \param[out] func_info: Address of function information
* \param[in] type_info: Appended return type information
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending return type information to function information was successful
*/
bool append_to_func_info(func_info_t *func_info, type_info_t type_info, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup access information at a given address with symbol table entry
* \param[out] access_info: Address to setup the access information at
* \param[in] entry: Pointer to symbol table entry of variable that is accessed
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the access information was successful
*/
bool setup_access_info(access_info_t *access_info, entry_t *entry, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append index to access information at a given address
* \param[out] access_info: Address of access information
* \param[in] node: Pointer to node representing the access index
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending index to access information was successful
*/
bool append_to_access_info(access_info_t *access_info, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup initialization information at a given address with node
* \param[out] init_info: Address to setup the initialization information at
* \param[in] is_init_list: Whether initialization is given by an initializer list
* \param[in] node: Pointer to node representing first value of initialization
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the initialization information was successful
*/
bool setup_init_info(init_info_t *init_info, bool is_init_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append value to initialization information at a given address
* \param[out] init_info: Address of initialization information
* \param[in] node: Pointer to node representing appended value of initialization
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending value to initialization information was successful
*/
bool append_to_init_info(init_info_t *init_info, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup else-if list at a given address with node
* \param[out] else_if_list: Address to setup the else-if list at
* \param[in] node: Pointer to node representing first else-if
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the else-if list was successful
*/
bool setup_else_if_list(else_if_list_t *else_if_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append else-if to else-if list at a given address
* \param[out] else_if_list: Address to setup the else-if list at
* \param[in] node: Pointer to node representing appended else-if
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending else-if to else-if list was successful
*/
bool append_to_else_if_list(else_if_list_t *else_if_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup case list at a given address with node
* \param[out] case_list: Address to setup the case list at
* \param[in] node: Pointer to node representing first case
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the case list was successful
*/
bool setup_case_list(case_list_t *case_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append case to case list at a given address
* \param[out] case_list: Address of case list
* \param[in] node: Pointer to node representing appended case
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending case to case list was successful
*/
bool append_to_case_list(case_list_t *case_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Setup argument list at a given address with node
* \param[out] arg_list: Address to setup the argument list at
* \param[in] node: Pointer to node representing first argument
* \param[out] error_msg: Message to be written in case of an error
* \return Whether setting up the argument list was successful
*/
bool setup_arg_list(arg_list_t *arg_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Append argument to argument list at a given address
* \param[out] arg_list: Address of argument list
* \param[in] node: Pointer to node representing appended argument
* \param[out] error_msg: Message to be written in case of an error
* \return Whether appending argument to argument list was successful
*/
bool append_to_arg_list(arg_list_t *arg_list, node_t *node, char error_msg[ERROR_MSG_LENGTH]);
/**
* \brief Increase nested-loop counter
*/
void incr_nested_loop_counter();
/**
* \brief Decrease nested-loop counter
*/
void decr_nested_loop_counter();
/*
* =====================================================================================================================
* closing C++ check & header guard
* =====================================================================================================================
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PARSING_H */