Newer
Older
/*
** ast.h for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Sun Jul 30 04:40:03 2006 Seblu
*/
#ifndef AST_H_
# define AST_H_
# include <sys/types.h>
# include <errno.h>
# include <stdlib.h>
# include <assert.h>
{
ts_ast_node *cond;
ts_ast_node *cond_true;
ts_ast_node *cond_false;
} ts_if_node;
/*
** For ast node
*/
/*
** Case item (not an ast node)
*/
typedef struct s_case_item ts_case_item;
struct s_case_item
{
char **pattern;
ts_ast_node *list;
ts_case_item *next;
};
} ts_case_node;
/*
** While ast node
*/
{
ts_ast_node *cond;
ts_ast_node *exec;
} ts_while_node;
/*
** Enumerate different type of redirection
*/
{
R_LESS, /* < */
R_LESSAND, /* <& */
R_GREAT, /* > */
R_GREATAND, /* >& */
R_DGREAT, /* >> */
R_LESSGREAT, /* <> */
R_CLOBBER, /* >| */
R_DLESS, /* << */
R_DLESSDASH /* <<- */
} te_redir_type;
/*
** Redirection ast node
*/
{
te_redir_type type;
int fd;
char *string;
} ts_redir_node;
/*
** Command ast node
*/
char **prefix;
} ts_cmd_node;
/*
** Binary ast node
** Generic type, it's a contener !
** T_PIPE, T_SEP_* , T_AND, T_OR : binary operator
** T_BANG : unary operator but ts_bin_op with right pointer is always NULL
*/
} ts_bin_node;
/*
** Funcdec node
*/
{
char *name;
ts_ast_node *body;
} ts_funcdec_node;
/*
** Enumerate all node type
*/
{
T_IF,
T_FOR,
T_WHILE,
T_UNTIL,
T_CMD,
T_AND,
T_OR,
T_SUBSHELL,
T_FUNCDEC,
T_BANG,
T_PIPE,
T_CASE,
} te_node_type;
/*
** This is a type for a node item
*/
ts_while_node child_while;
ts_while_node child_until;
ts_funcdec_node child_funcdec;
ts_bin_node child_bang;
ts_bin_node child_pipe;
ts_bin_node child_sep;
} tu_node_item;
/*
** Generic ast node type
*/
/*!
** Destroy node and all its childs
**
** @param ast mother node to destroy
**
*/
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*!
** Create an if ast node
**
** @param cond if condition
** @param cond_true tree if condition is true
** @param cond_false tree if condition is false
**
** @return the node
*/
ts_ast_node *ast_create_if(ts_ast_node *cond,
ts_ast_node *cond_true,
ts_ast_node *cond_false);
/*!
** Destruct an if ast node
**
** @param node node to destroy
*/
void ast_destruct_if(ts_ast_node *node);
/*!
** Create a for ast node
**
** @param varname variable name
** @param values word list that var @value varname will take.
** @warning values is a NULL termined list of string
** @param exec tree to execute with @value varname correctly set
**
** @return the node
*/
ts_ast_node *ast_create_for(char *varname,
char **values,
ts_ast_node *exec);
/*!
** Destruct a for ast node
**
** @param node node to destroy
*/
void ast_destruct_for(ts_ast_node *node);
/*!
** Create a while ast node
**
** @param cond poursuit condition
** @param exec tree to execute if cond is true
**
** @return the node
*/
ts_ast_node *ast_create_while(ts_ast_node *cond, ts_ast_node *exec);
/*!
** Destruct a while ast node
**
** @param node node to destroy
*/
void ast_destruct_while(ts_ast_node *node);
/*!
** Create a until ast node
**
** @param cond poursuit condition
** @param exec tree to execute if cond is false
**
** @return the node
*/
ts_ast_node *ast_create_until(ts_ast_node *cond, ts_ast_node *exec);
/*!
** Destruct a until ast node
**
** @param node node to destroy
*/
void ast_destruct_until(ts_ast_node *node);
/*!
** Create an and (&&) ast node
**
** @param lhs left child
** @param rhs right child
**
** @return the node
*/
ts_ast_node *ast_create_and(ts_ast_node *lhs, ts_ast_node *rhs);
/*!
** Destruct an and (&&) node
**
** @param node node to destroy
*/
void ast_destruct_and(ts_ast_node *node);
/*!
** Create an or (||) ast node
**
** @param lhs left child
** @param rhs right child
**
** @return the node
*/
ts_ast_node *ast_create_or(ts_ast_node *lhs, ts_ast_node *rhs);
/*!
** Destruct an or (||) node
**
** @param node node to destroy
*/
void ast_destruct_or(ts_ast_node *node);
/*!
** Create a subshell ($()) ast node
**
** @param child subshell tree
**
** @return the node
*/
ts_ast_node *ast_create_subshell(ts_ast_node *child);
/*!
** Destruct a subshell ($()) node
**
** @param node node to destroy
*/
void ast_destruct_subshell(ts_ast_node *node);
/*!
** Create a funcdec (function declaration) ast node
**
** @param name function name
** @param body function body
**
** @return the node
*/
ts_ast_node *ast_create_funcdec(char *name, ts_ast_node *body);
/*!
** Destruct a funcdec ast node
**
** @param node node to destroy
*/
void ast_destruct_funcdec(ts_ast_node *node);
/*!
** Create a bang (!) ast node
**
** @param child under bang tree
**
** @return the node
*/
ts_ast_node *ast_create_bang(ts_ast_node *child);
/*!
** Destruct a bang (!) node
**
** @param node node to destroy
*/
void ast_destruct_bang(ts_ast_node *node);
/*!
** Create a pipe (|) ast node
**
** @param lhs left child
** @param rhs right child
**
** @return the node
*/
ts_ast_node *ast_create_pipe(ts_ast_node *lhs, ts_ast_node *rhs);
/*!
** Destruct a pipe (|) node
**
** @param node node to destroy
*/
void ast_destruct_pipe(ts_ast_node *node);
/*!
** Create a separtor (;) ast node
**
** @param lhs left child
** @param rhs right child
**
** @return the node
*/
ts_ast_node *ast_create_sep(ts_ast_node *lhs, ts_ast_node *rhs);
/*!
** Destruct a sep (;) node
**
** @param node node to destroy
*/
/*!
** Create a sepand (&) ast node
**
** @param lhs left child
** @param rhs right child
**
** @return the node
*/
ts_ast_node *ast_create_sepand(ts_ast_node *lhs, ts_ast_node *rhs);
/*!
** Destruct a sepand (&) node
**
** @param node node to destroy
*/
void ast_destruct_sep(ts_ast_node *node);