qse/ase/awk/tree.h

381 lines
7.6 KiB
C
Raw Normal View History

2006-01-09 12:51:47 +00:00
/*
2006-10-22 12:39:30 +00:00
* $Id: tree.h,v 1.76 2006-10-22 12:39:30 bacon Exp $
2006-01-09 12:51:47 +00:00
*/
2006-01-02 16:38:23 +00:00
2006-10-22 11:34:53 +00:00
#ifndef _SSE_AWK_TREE_H_
#define _SSE_AWK_TREE_H_
2006-01-09 12:51:47 +00:00
2006-10-22 11:34:53 +00:00
#ifndef _SSE_AWK_AWK_H_
#error Never include this file directly. Include <sse/awk/awk.h> instead
2006-03-03 11:45:45 +00:00
#endif
2006-01-09 12:51:47 +00:00
enum
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_NULL,
2006-03-04 15:54:37 +00:00
2006-04-07 16:52:42 +00:00
/* statement */
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_BLK,
SSE_AWK_NDE_IF,
SSE_AWK_NDE_WHILE,
SSE_AWK_NDE_DOWHILE,
SSE_AWK_NDE_FOR,
SSE_AWK_NDE_FOREACH,
SSE_AWK_NDE_BREAK,
SSE_AWK_NDE_CONTINUE,
SSE_AWK_NDE_RETURN,
SSE_AWK_NDE_EXIT,
SSE_AWK_NDE_NEXT,
SSE_AWK_NDE_NEXTFILE,
SSE_AWK_NDE_DELETE,
SSE_AWK_NDE_PRINT,
2006-10-22 12:39:30 +00:00
/* expression */
2006-04-14 16:26:00 +00:00
/* if you change the following values including their order,
2006-10-22 12:39:30 +00:00
* you should change __eval_func of __eval_expression
2006-04-14 16:26:00 +00:00
* in run.c accordingly */
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_GRP,
SSE_AWK_NDE_ASS,
2006-10-22 12:39:30 +00:00
SSE_AWK_NDE_EXP_BIN,
SSE_AWK_NDE_EXP_UNR,
SSE_AWK_NDE_EXP_INCPRE,
SSE_AWK_NDE_EXP_INCPST,
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_CND,
SSE_AWK_NDE_BFN,
SSE_AWK_NDE_AFN,
SSE_AWK_NDE_INT,
SSE_AWK_NDE_REAL,
SSE_AWK_NDE_STR,
SSE_AWK_NDE_REX,
2006-07-31 04:25:17 +00:00
/* keep this order for the following items otherwise, you may have
2006-08-20 15:49:48 +00:00
* to change __eval_incpre and __eval_incpst in run.c as well as
2006-10-22 11:34:53 +00:00
* SSE_AWK_VAL_REF_XXX in val.h */
SSE_AWK_NDE_NAMED,
SSE_AWK_NDE_GLOBAL,
SSE_AWK_NDE_LOCAL,
SSE_AWK_NDE_ARG,
SSE_AWK_NDE_NAMEDIDX,
SSE_AWK_NDE_GLOBALIDX,
SSE_AWK_NDE_LOCALIDX,
SSE_AWK_NDE_ARGIDX,
SSE_AWK_NDE_POS,
2006-07-31 04:25:17 +00:00
/* ---------------------------------- */
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_GETLINE,
2006-06-13 08:35:53 +00:00
};
2006-06-13 15:11:39 +00:00
enum
{
2006-06-28 10:40:24 +00:00
/* the order of these values match
* __in_type_map and __in_opt_map in extio.c */
2006-10-22 11:34:53 +00:00
SSE_AWK_IN_PIPE,
SSE_AWK_IN_COPROC,
SSE_AWK_IN_FILE,
SSE_AWK_IN_CONSOLE
2006-06-13 15:11:39 +00:00
};
2006-06-13 08:35:53 +00:00
enum
{
2006-06-28 03:44:40 +00:00
/* the order of these values match
* __out_type_map and __out_opt_map in extio.c */
2006-10-22 11:34:53 +00:00
SSE_AWK_OUT_PIPE,
SSE_AWK_OUT_COPROC,
SSE_AWK_OUT_FILE,
SSE_AWK_OUT_FILE_APPEND,
SSE_AWK_OUT_CONSOLE
2006-01-09 12:51:47 +00:00
};
2006-07-13 15:43:39 +00:00
/* afn (awk function defined with the keyword function) */
2006-10-22 11:34:53 +00:00
typedef struct sse_awk_afn_t sse_awk_afn_t;
typedef struct sse_awk_nde_t sse_awk_nde_t;
typedef struct sse_awk_nde_blk_t sse_awk_nde_blk_t;
typedef struct sse_awk_nde_grp_t sse_awk_nde_grp_t;
typedef struct sse_awk_nde_ass_t sse_awk_nde_ass_t;
2006-10-22 12:39:30 +00:00
typedef struct sse_awk_nde_exp_t sse_awk_nde_exp_t;
2006-10-22 11:34:53 +00:00
typedef struct sse_awk_nde_cnd_t sse_awk_nde_cnd_t;
typedef struct sse_awk_nde_pos_t sse_awk_nde_pos_t;
typedef struct sse_awk_nde_int_t sse_awk_nde_int_t;
typedef struct sse_awk_nde_real_t sse_awk_nde_real_t;
typedef struct sse_awk_nde_str_t sse_awk_nde_str_t;
typedef struct sse_awk_nde_rex_t sse_awk_nde_rex_t;
typedef struct sse_awk_nde_var_t sse_awk_nde_var_t;
typedef struct sse_awk_nde_call_t sse_awk_nde_call_t;
typedef struct sse_awk_nde_getline_t sse_awk_nde_getline_t;
typedef struct sse_awk_nde_if_t sse_awk_nde_if_t;
typedef struct sse_awk_nde_while_t sse_awk_nde_while_t;
typedef struct sse_awk_nde_for_t sse_awk_nde_for_t;
typedef struct sse_awk_nde_foreach_t sse_awk_nde_foreach_t;
typedef struct sse_awk_nde_break_t sse_awk_nde_break_t;
typedef struct sse_awk_nde_continue_t sse_awk_nde_continue_t;
typedef struct sse_awk_nde_return_t sse_awk_nde_return_t;
typedef struct sse_awk_nde_exit_t sse_awk_nde_exit_t;
typedef struct sse_awk_nde_next_t sse_awk_nde_next_t;
typedef struct sse_awk_nde_nextfile_t sse_awk_nde_nextfile_t;
typedef struct sse_awk_nde_delete_t sse_awk_nde_delete_t;
typedef struct sse_awk_nde_print_t sse_awk_nde_print_t;
struct sse_awk_afn_t
2006-01-22 15:11:17 +00:00
{
2006-10-22 11:34:53 +00:00
sse_char_t* name;
sse_size_t name_len;
sse_size_t nargs;
sse_awk_nde_t* body;
2006-01-22 15:11:17 +00:00
};
2006-10-22 11:34:53 +00:00
#define SSE_AWK_NDE_HDR \
2006-01-09 12:51:47 +00:00
int type; \
2006-10-22 11:34:53 +00:00
sse_awk_nde_t* next
2006-01-09 12:51:47 +00:00
2006-10-22 11:34:53 +00:00
struct sse_awk_nde_t
2006-01-09 12:51:47 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-01-09 12:51:47 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_BLK - block statement including top-level blocks */
struct sse_awk_nde_blk_t
2006-01-09 12:51:47 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_size_t nlocals;
sse_awk_nde_t* body;
2006-01-09 12:51:47 +00:00
};
2006-10-22 12:39:30 +00:00
/* SSE_AWK_NDE_GRP - expression group */
2006-10-22 11:34:53 +00:00
struct sse_awk_nde_grp_t
2006-04-24 15:36:08 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* body;
2006-04-24 15:36:08 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_ASS - assignment */
struct sse_awk_nde_ass_t
2006-01-11 14:03:17 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-04-14 16:26:00 +00:00
int opcode;
2006-10-22 11:34:53 +00:00
sse_awk_nde_t* left;
sse_awk_nde_t* right;
2006-01-11 14:03:17 +00:00
};
2006-10-22 12:39:30 +00:00
/* SSE_AWK_NDE_EXP_BIN, SSE_AWK_NDE_EXP_UNR,
* SSE_AWK_NDE_EXP_INCPRE, SSE_AW_NDE_EXP_INCPST */
struct sse_awk_nde_exp_t
2006-01-10 13:57:54 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-01-11 14:03:17 +00:00
int opcode;
2006-10-22 11:34:53 +00:00
sse_awk_nde_t* left;
sse_awk_nde_t* right; /* SSE_NULL for UNR, INCPRE, INCPST */
2006-01-10 13:57:54 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_CND */
struct sse_awk_nde_cnd_t
2006-04-11 09:16:20 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* test;
sse_awk_nde_t* left;
sse_awk_nde_t* right;
2006-04-11 09:16:20 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct sse_awk_nde_pos_t
2006-03-05 17:07:33 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* val;
2006-03-05 17:07:33 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_INT */
struct sse_awk_nde_int_t
2006-03-05 17:07:33 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_long_t val;
sse_char_t* str;
sse_size_t len;
2006-03-05 17:07:33 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_REAL */
struct sse_awk_nde_real_t
2006-03-28 16:33:09 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_real_t val;
sse_char_t* str;
sse_size_t len;
2006-03-28 16:33:09 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_STR */
struct sse_awk_nde_str_t
2006-01-10 13:57:54 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_char_t* buf;
sse_size_t len;
2006-01-10 13:57:54 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_REX */
struct sse_awk_nde_rex_t
2006-04-24 11:26:00 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_char_t* buf;
sse_size_t len;
2006-07-26 15:00:01 +00:00
void* code;
2006-04-24 11:26:00 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_NAMED, SSE_AWK_NDE_GLOBAL,
* SSE_AWK_NDE_LOCAL, SSE_AWK_NDE_ARG
* SSE_AWK_NDE_NAMEDIDX, SSE_AWK_NDE_GLOBALIDX,
* SSE_AWK_NDE_LOCALIDX, SSE_AWK_NDE_ARGIDX */
struct sse_awk_nde_var_t
2006-01-24 16:14:28 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-08-03 05:05:48 +00:00
struct
2006-01-24 16:14:28 +00:00
{
2006-10-22 11:34:53 +00:00
sse_char_t* name;
sse_size_t name_len;
sse_size_t idxa;
2006-01-24 16:14:28 +00:00
} id;
2006-10-22 11:34:53 +00:00
sse_awk_nde_t* idx; /* SSE_NULL for non-XXXXIDX */
2006-01-19 16:28:21 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_BFN, SSE_AWK_NDE_AFN */
struct sse_awk_nde_call_t
2006-01-19 16:28:21 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-06-19 15:43:27 +00:00
union
{
2006-08-03 05:05:48 +00:00
struct
{
2006-10-22 11:34:53 +00:00
sse_char_t* name;
sse_size_t name_len;
2006-08-03 05:05:48 +00:00
} afn;
2006-07-14 04:19:22 +00:00
/* minimum information of a built-in function
* needed during run-time. */
struct
{
2006-10-22 11:34:53 +00:00
const sse_char_t* name;
sse_size_t name_len;
sse_size_t min_args;
sse_size_t max_args;
const sse_char_t* arg_spec;
int (*handler) (sse_awk_run_t* awk);
2006-07-14 04:19:22 +00:00
} bfn;
2006-10-22 11:34:53 +00:00
/* sse_awk_bfn_t* bfn; */
2006-06-19 15:43:27 +00:00
} what;
2006-10-22 11:34:53 +00:00
sse_awk_nde_t* args;
sse_size_t nargs;
2006-01-13 11:25:52 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_GETLINE */
struct sse_awk_nde_getline_t
2006-06-12 15:11:02 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* var;
int in_type; /* SSE_AWK_GETLINE_XXX */
sse_awk_nde_t* in;
2006-06-13 08:35:53 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_IF */
struct sse_awk_nde_if_t
2006-01-09 12:51:47 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* test;
sse_awk_nde_t* then_part;
sse_awk_nde_t* else_part; /* optional */
2006-01-09 12:51:47 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_WHILE, SSE_AWK_NDE_DOWHILE */
struct sse_awk_nde_while_t
2006-01-10 13:57:54 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* test;
sse_awk_nde_t* body;
2006-01-10 13:57:54 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_FOR */
struct sse_awk_nde_for_t
2006-01-19 13:28:29 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* init; /* optional */
sse_awk_nde_t* test; /* optional */
sse_awk_nde_t* incr; /* optional */
sse_awk_nde_t* body;
2006-01-19 13:28:29 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_FOREACH */
struct sse_awk_nde_foreach_t
2006-04-29 12:09:29 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* test;
sse_awk_nde_t* body;
2006-04-29 12:09:29 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_BREAK */
struct sse_awk_nde_break_t
2006-03-04 15:54:37 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-03-04 15:54:37 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_CONTINUE */
struct sse_awk_nde_continue_t
2006-03-04 15:54:37 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-03-04 15:54:37 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_RETURN */
struct sse_awk_nde_return_t
2006-03-04 15:54:37 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* val; /* optional (no return code if SSE_NULL) */
2006-03-04 15:54:37 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_EXIT */
struct sse_awk_nde_exit_t
2006-03-04 15:54:37 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* val; /* optional (no exit code if SSE_NULL) */
2006-03-04 15:54:37 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_NEXT */
struct sse_awk_nde_next_t
2006-04-22 16:16:40 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-04-22 16:16:40 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_NEXTFILE */
struct sse_awk_nde_nextfile_t
2006-04-22 16:16:40 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
2006-04-22 16:16:40 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_DELETE */
struct sse_awk_nde_delete_t
2006-06-27 14:18:19 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* var;
2006-06-27 14:18:19 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_NDE_PRINT */
struct sse_awk_nde_print_t
2006-06-27 14:18:19 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_NDE_HDR;
sse_awk_nde_t* args;
int out_type; /* SSE_AWK_OUT_XXX */
sse_awk_nde_t* out;
2006-06-27 14:18:19 +00:00
};
2006-01-14 14:09:52 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-10-22 11:34:53 +00:00
int sse_awk_prnpt (sse_awk_t* awk, sse_awk_nde_t* tree);
int sse_awk_prnptnpt (sse_awk_t* awk, sse_awk_nde_t* tree);
2006-08-06 15:03:42 +00:00
2006-10-22 11:34:53 +00:00
void sse_awk_clrpt (sse_awk_t* awk, sse_awk_nde_t* tree);
2006-01-14 14:09:52 +00:00
#ifdef __cplusplus
}
#endif
2006-01-09 12:51:47 +00:00
#endif