qse/ase/awk/tree.h

383 lines
7.7 KiB
C
Raw Normal View History

2006-01-09 12:51:47 +00:00
/*
2006-11-23 03:31:58 +00:00
* $Id: tree.h,v 1.81 2006-11-23 03:31:36 bacon Exp $
2006-01-09 12:51:47 +00:00
*/
2006-01-02 16:38:23 +00:00
2006-10-24 04:10:12 +00:00
#ifndef _ASE_AWK_TREE_H_
#define _ASE_AWK_TREE_H_
2006-01-09 12:51:47 +00:00
2006-10-24 04:10:12 +00:00
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
2006-03-03 11:45:45 +00:00
#endif
2006-11-19 11:55:17 +00:00
enum ase_awk_nde_type_t
2006-01-09 12:51:47 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_NULL,
2006-03-04 15:54:37 +00:00
2006-04-07 16:52:42 +00:00
/* statement */
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_BLK,
ASE_AWK_NDE_IF,
ASE_AWK_NDE_WHILE,
ASE_AWK_NDE_DOWHILE,
ASE_AWK_NDE_FOR,
ASE_AWK_NDE_FOREACH,
ASE_AWK_NDE_BREAK,
ASE_AWK_NDE_CONTINUE,
ASE_AWK_NDE_RETURN,
ASE_AWK_NDE_EXIT,
ASE_AWK_NDE_NEXT,
ASE_AWK_NDE_NEXTFILE,
ASE_AWK_NDE_DELETE,
ASE_AWK_NDE_PRINT,
2006-10-31 10:13:15 +00:00
ASE_AWK_NDE_PRINTF,
2006-10-22 11:34:53 +00:00
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-24 04:10:12 +00:00
ASE_AWK_NDE_GRP,
ASE_AWK_NDE_ASS,
ASE_AWK_NDE_EXP_BIN,
ASE_AWK_NDE_EXP_UNR,
ASE_AWK_NDE_EXP_INCPRE,
ASE_AWK_NDE_EXP_INCPST,
ASE_AWK_NDE_CND,
ASE_AWK_NDE_BFN,
ASE_AWK_NDE_AFN,
ASE_AWK_NDE_INT,
ASE_AWK_NDE_REAL,
ASE_AWK_NDE_STR,
ASE_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-24 04:10:12 +00:00
* ASE_AWK_VAL_REF_XXX in val.h */
ASE_AWK_NDE_NAMED,
ASE_AWK_NDE_GLOBAL,
ASE_AWK_NDE_LOCAL,
ASE_AWK_NDE_ARG,
ASE_AWK_NDE_NAMEDIDX,
ASE_AWK_NDE_GLOBALIDX,
ASE_AWK_NDE_LOCALIDX,
ASE_AWK_NDE_ARGIDX,
ASE_AWK_NDE_POS,
2006-07-31 04:25:17 +00:00
/* ---------------------------------- */
2006-11-19 14:55:20 +00:00
ASE_AWK_NDE_GETLINE
2006-06-13 08:35:53 +00:00
};
2006-11-19 11:55:17 +00:00
enum ase_awk_in_type_t
2006-06-13 15:11:39 +00:00
{
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-24 04:10:12 +00:00
ASE_AWK_IN_PIPE,
ASE_AWK_IN_COPROC,
ASE_AWK_IN_FILE,
ASE_AWK_IN_CONSOLE
2006-06-13 15:11:39 +00:00
};
2006-11-19 11:55:17 +00:00
enum ase_awk_out_type_t
2006-06-13 08:35:53 +00:00
{
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-24 04:10:12 +00:00
ASE_AWK_OUT_PIPE,
ASE_AWK_OUT_COPROC,
ASE_AWK_OUT_FILE,
ASE_AWK_OUT_FILE_APPEND,
ASE_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-24 04:10:12 +00:00
typedef struct ase_awk_afn_t ase_awk_afn_t;
typedef struct ase_awk_nde_t ase_awk_nde_t;
typedef struct ase_awk_nde_blk_t ase_awk_nde_blk_t;
typedef struct ase_awk_nde_grp_t ase_awk_nde_grp_t;
typedef struct ase_awk_nde_ass_t ase_awk_nde_ass_t;
typedef struct ase_awk_nde_exp_t ase_awk_nde_exp_t;
typedef struct ase_awk_nde_cnd_t ase_awk_nde_cnd_t;
typedef struct ase_awk_nde_pos_t ase_awk_nde_pos_t;
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
typedef struct ase_awk_nde_str_t ase_awk_nde_str_t;
typedef struct ase_awk_nde_rex_t ase_awk_nde_rex_t;
typedef struct ase_awk_nde_var_t ase_awk_nde_var_t;
typedef struct ase_awk_nde_call_t ase_awk_nde_call_t;
typedef struct ase_awk_nde_getline_t ase_awk_nde_getline_t;
typedef struct ase_awk_nde_if_t ase_awk_nde_if_t;
typedef struct ase_awk_nde_while_t ase_awk_nde_while_t;
typedef struct ase_awk_nde_for_t ase_awk_nde_for_t;
typedef struct ase_awk_nde_foreach_t ase_awk_nde_foreach_t;
typedef struct ase_awk_nde_break_t ase_awk_nde_break_t;
typedef struct ase_awk_nde_continue_t ase_awk_nde_continue_t;
typedef struct ase_awk_nde_return_t ase_awk_nde_return_t;
typedef struct ase_awk_nde_exit_t ase_awk_nde_exit_t;
typedef struct ase_awk_nde_next_t ase_awk_nde_next_t;
typedef struct ase_awk_nde_nextfile_t ase_awk_nde_nextfile_t;
typedef struct ase_awk_nde_delete_t ase_awk_nde_delete_t;
typedef struct ase_awk_nde_print_t ase_awk_nde_print_t;
struct ase_awk_afn_t
2006-01-22 15:11:17 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t* name;
ase_size_t name_len;
ase_size_t nargs;
ase_awk_nde_t* body;
2006-01-22 15:11:17 +00:00
};
2006-10-24 04:10:12 +00:00
#define ASE_AWK_NDE_HDR \
2006-01-09 12:51:47 +00:00
int type; \
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* next
2006-01-09 12:51:47 +00:00
2006-10-24 04:10:12 +00:00
struct ase_awk_nde_t
2006-01-09 12:51:47 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-01-09 12:51:47 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_BLK - block statement including top-level blocks */
struct ase_awk_nde_blk_t
2006-01-09 12:51:47 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_size_t nlocals;
ase_awk_nde_t* body;
2006-01-09 12:51:47 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_GRP - expression group */
struct ase_awk_nde_grp_t
2006-04-24 15:36:08 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* body;
2006-04-24 15:36:08 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_ASS - assignment */
struct ase_awk_nde_ass_t
2006-01-11 14:03:17 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-04-14 16:26:00 +00:00
int opcode;
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* left;
ase_awk_nde_t* right;
2006-01-11 14:03:17 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_EXP_BIN, ASE_AWK_NDE_EXP_UNR,
* ASE_AWK_NDE_EXP_INCPRE, ASE_AW_NDE_EXP_INCPST */
struct ase_awk_nde_exp_t
2006-01-10 13:57:54 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-01-11 14:03:17 +00:00
int opcode;
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* left;
ase_awk_nde_t* right; /* ASE_NULL for UNR, INCPRE, INCPST */
2006-01-10 13:57:54 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_CND */
struct ase_awk_nde_cnd_t
2006-04-11 09:16:20 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* left;
ase_awk_nde_t* right;
2006-04-11 09:16:20 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct ase_awk_nde_pos_t
2006-03-05 17:07:33 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val;
2006-03-05 17:07:33 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_INT */
struct ase_awk_nde_int_t
2006-03-05 17:07:33 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_long_t val;
ase_char_t* str;
ase_size_t len;
2006-03-05 17:07:33 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_REAL */
struct ase_awk_nde_real_t
2006-03-28 16:33:09 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_real_t val;
ase_char_t* str;
ase_size_t len;
2006-03-28 16:33:09 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_STR */
struct ase_awk_nde_str_t
2006-01-10 13:57:54 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
2006-01-10 13:57:54 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_REX */
struct ase_awk_nde_rex_t
2006-04-24 11:26:00 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
2006-07-26 15:00:01 +00:00
void* code;
2006-04-24 11:26:00 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_NAMED, ASE_AWK_NDE_GLOBAL,
* ASE_AWK_NDE_LOCAL, ASE_AWK_NDE_ARG
* ASE_AWK_NDE_NAMEDIDX, ASE_AWK_NDE_GLOBALIDX,
* ASE_AWK_NDE_LOCALIDX, ASE_AWK_NDE_ARGIDX */
struct ase_awk_nde_var_t
2006-01-24 16:14:28 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-08-03 05:05:48 +00:00
struct
2006-01-24 16:14:28 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t* name;
ase_size_t name_len;
ase_size_t idxa;
2006-01-24 16:14:28 +00:00
} id;
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */
2006-01-19 16:28:21 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_BFN, ASE_AWK_NDE_AFN */
struct ase_awk_nde_call_t
2006-01-19 16:28:21 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-06-19 15:43:27 +00:00
union
{
2006-08-03 05:05:48 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t* name;
ase_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-24 04:10:12 +00:00
const ase_char_t* name;
ase_size_t name_len;
ase_size_t min_args;
ase_size_t max_args;
const ase_char_t* arg_spec;
int (*handler) (ase_awk_run_t* awk);
2006-07-14 04:19:22 +00:00
} bfn;
2006-10-24 04:10:12 +00:00
/* ase_awk_bfn_t* bfn; */
2006-06-19 15:43:27 +00:00
} what;
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* args;
ase_size_t nargs;
2006-01-13 11:25:52 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_GETLINE */
struct ase_awk_nde_getline_t
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
int in_type; /* ASE_AWK_GETLINE_XXX */
ase_awk_nde_t* in;
2006-06-13 08:35:53 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_IF */
struct ase_awk_nde_if_t
2006-01-09 12:51:47 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* then_part;
ase_awk_nde_t* else_part; /* optional */
2006-01-09 12:51:47 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_WHILE, ASE_AWK_NDE_DOWHILE */
struct ase_awk_nde_while_t
2006-01-10 13:57:54 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
2006-01-10 13:57:54 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_FOR */
struct ase_awk_nde_for_t
2006-01-19 13:28:29 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* init; /* optional */
ase_awk_nde_t* test; /* optional */
ase_awk_nde_t* incr; /* optional */
ase_awk_nde_t* body;
2006-01-19 13:28:29 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_FOREACH */
struct ase_awk_nde_foreach_t
2006-04-29 12:09:29 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
2006-04-29 12:09:29 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_BREAK */
struct ase_awk_nde_break_t
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-03-04 15:54:37 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_CONTINUE */
struct ase_awk_nde_continue_t
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-03-04 15:54:37 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_RETURN */
struct ase_awk_nde_return_t
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no return code if ASE_NULL) */
2006-03-04 15:54:37 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_EXIT */
struct ase_awk_nde_exit_t
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no exit code if ASE_NULL) */
2006-03-04 15:54:37 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_NEXT */
struct ase_awk_nde_next_t
2006-04-22 16:16:40 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-04-22 16:16:40 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_NEXTFILE */
struct ase_awk_nde_nextfile_t
2006-04-22 16:16:40 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
2006-11-23 03:31:58 +00:00
int out;
2006-04-22 16:16:40 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_DELETE */
struct ase_awk_nde_delete_t
2006-06-27 14:18:19 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
2006-06-27 14:18:19 +00:00
};
2006-10-24 04:10:12 +00:00
/* ASE_AWK_NDE_PRINT */
struct ase_awk_nde_print_t
2006-06-27 14:18:19 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_NDE_HDR;
ase_awk_nde_t* args;
int out_type; /* ASE_AWK_OUT_XXX */
ase_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-24 04:10:12 +00:00
int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree);
2006-01-14 14:09:52 +00:00
#ifdef __cplusplus
}
#endif
2006-01-09 12:51:47 +00:00
#endif