qse/ase/awk/tree.c

1123 lines
24 KiB
C
Raw Normal View History

2006-01-14 14:09:52 +00:00
/*
2006-11-01 04:41:20 +00:00
* $Id: tree.c,v 1.86 2006-11-01 04:41:01 bacon Exp $
2006-01-14 14:09:52 +00:00
*/
2006-10-24 04:10:12 +00:00
#include <ase/awk/awk_i.h>
2006-01-18 15:16:01 +00:00
2006-10-24 04:10:12 +00:00
static const ase_char_t* __assop_str[] =
2006-04-14 16:26:00 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("="),
ASE_T("+="),
ASE_T("-="),
ASE_T("*="),
ASE_T("/="),
ASE_T("%="),
ASE_T("**=")
2006-04-14 16:26:00 +00:00
};
2006-10-24 04:10:12 +00:00
static const ase_char_t* __binop_str[] =
2006-01-14 14:09:52 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("||"),
ASE_T("&&"),
ASE_T("in"),
ASE_T("|"),
ASE_T("^"),
ASE_T("&"),
ASE_T("=="),
ASE_T("!="),
ASE_T(">"),
ASE_T(">="),
ASE_T("<"),
ASE_T("<="),
ASE_T("<<"),
ASE_T(">>"),
ASE_T("+"),
ASE_T("-"),
ASE_T("*"),
ASE_T("/"),
ASE_T("%"),
ASE_T("**"),
ASE_T(" "),
ASE_T("~"),
ASE_T("!~")
2006-03-31 12:04:14 +00:00
};
2006-10-24 04:10:12 +00:00
static const ase_char_t* __unrop_str[] =
2006-03-31 12:04:14 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("+"),
ASE_T("-"),
ASE_T("!"),
ASE_T("~")
2006-01-14 14:09:52 +00:00
};
2006-10-24 04:10:12 +00:00
static const ase_char_t* __incop_str[] =
2006-04-02 12:45:04 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("++"),
ASE_T("--"),
ASE_T("++"),
ASE_T("--")
2006-04-02 12:45:04 +00:00
};
2006-10-24 04:10:12 +00:00
static const ase_char_t* __getline_inop_str[] =
2006-06-13 15:11:39 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("|"),
ASE_T("|&"),
ASE_T("<"),
ASE_T("")
2006-06-13 15:11:39 +00:00
};
2006-10-24 04:10:12 +00:00
static const ase_char_t* __print_outop_str[] =
2006-06-13 08:35:53 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_T("|"),
ASE_T("|&"),
ASE_T(">"),
ASE_T(">>"),
ASE_T("")
2006-06-13 08:35:53 +00:00
};
2006-08-06 15:03:42 +00:00
#define PUT_SRCSTR(awk,str) \
2006-10-24 04:10:12 +00:00
do { if (ase_awk_putsrcstr (awk, str) == -1) return -1; } while (0)
2006-01-14 14:09:52 +00:00
2006-08-06 15:03:42 +00:00
#define PUT_SRCSTRX(awk,str,len) \
2006-10-24 04:10:12 +00:00
do { if (ase_awk_putsrcstrx (awk, str, len) == -1) return -1; } while (0)
2006-08-06 15:03:42 +00:00
#define PRINT_TABS(awk,depth) \
do { if (__print_tabs(awk,depth) == -1) return -1; } while (0)
2006-10-22 12:39:30 +00:00
#define PRINT_EXPRESSION(awk,nde) \
do { if (__print_expression(awk,nde) == -1) return -1; } while (0)
2006-08-06 15:03:42 +00:00
2006-10-22 12:39:30 +00:00
#define PRINT_EXPRESSION_LIST(awk,nde) \
do { if (__print_expression_list(awk,nde) == -1) return -1; } while (0)
2006-08-06 15:03:42 +00:00
#define PRINT_STATEMENTS(awk,nde,depth) \
do { if (__print_statements(awk,nde,depth) == -1) return -1; } while (0)
2006-10-24 04:10:12 +00:00
static int __print_tabs (ase_awk_t* awk, int depth);
static int __print_expression (ase_awk_t* awk, ase_awk_nde_t* nde);
static int __print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree);
static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth);
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
static int __print_tabs (ase_awk_t* awk, int depth)
2006-01-14 14:09:52 +00:00
{
2006-07-01 07:57:10 +00:00
while (depth > 0)
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("\t"));
2006-07-01 07:57:10 +00:00
depth--;
}
2006-08-06 15:03:42 +00:00
return 0;
2006-01-14 14:09:52 +00:00
}
2006-10-24 04:10:12 +00:00
static int __print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
2006-01-14 14:09:52 +00:00
{
2006-04-24 14:38:46 +00:00
switch (nde->type)
{
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GRP:
2006-04-26 15:53:17 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* p = ((ase_awk_nde_grp_t*)nde)->body;
2006-04-26 15:53:17 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
while (p != ASE_NULL)
2006-07-01 07:57:10 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, p);
2006-10-24 04:10:12 +00:00
if (p->next != ASE_NULL)
PUT_SRCSTR (awk, ASE_T(","));
2006-04-26 15:53:17 +00:00
p = p->next;
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-12 15:11:02 +00:00
break;
2006-04-26 15:53:17 +00:00
}
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_ASS:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_ass_t* px = (ase_awk_nde_ass_t*)nde;
2006-06-12 15:11:02 +00:00
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __assop_str[px->opcode]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->right);
2006-08-06 15:03:42 +00:00
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right->next == ASE_NULL);
2006-06-12 15:11:02 +00:00
break;
2006-02-05 16:00:33 +00:00
}
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_BIN:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde;
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->left->next == ASE_NULL);
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __binop_str[px->opcode]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 11:34:53 +00:00
2006-10-24 04:10:12 +00:00
if (px->right->type == ASE_AWK_NDE_ASS)
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->right);
2006-10-24 04:10:12 +00:00
if (px->right->type == ASE_AWK_NDE_ASS)
PUT_SRCSTR (awk, ASE_T(")"));
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right->next == ASE_NULL);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-12 15:11:02 +00:00
break;
2006-02-05 16:00:33 +00:00
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_UNR:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right == ASE_NULL);
2006-06-12 15:11:02 +00:00
2006-11-01 04:41:20 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __unrop_str[px->opcode]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-11-01 04:41:20 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-12 15:11:02 +00:00
break;
2006-02-05 16:00:33 +00:00
}
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_INCPRE:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right == ASE_NULL);
2006-06-12 15:11:02 +00:00
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __incop_str[px->opcode]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-12 15:11:02 +00:00
break;
2006-02-05 16:00:33 +00:00
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_INCPST:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right == ASE_NULL);
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __incop_str[px->opcode]);
2006-06-12 15:11:02 +00:00
break;
2006-02-05 13:45:59 +00:00
}
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_CND:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_cnd_t* px = (ase_awk_nde_cnd_t*)nde;
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")?"));
2006-06-12 15:11:02 +00:00
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->left);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(":"));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->right);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_INT:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_int_t*)nde)->str == ASE_NULL)
2006-10-06 03:37:40 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
n = ase_awk_longtostr (
((ase_awk_nde_int_t*)nde)->val,
10, ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
2006-10-06 03:37:40 +00:00
PUT_SRCSTRX (awk, tmp, n);
}
else
{
PUT_SRCSTRX (awk,
2006-10-24 04:10:12 +00:00
((ase_awk_nde_int_t*)nde)->str,
((ase_awk_nde_int_t*)nde)->len);
2006-10-06 03:37:40 +00:00
}
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_REAL:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_real_t*)nde)->str == ASE_NULL)
2006-10-06 03:37:40 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[128];
#if (ASE_SIZEOF_LONG_DOUBLE != 0)
2006-10-12 14:36:25 +00:00
awk->syscas.sprintf (
2006-10-24 04:10:12 +00:00
tmp, ase_countof(tmp), ASE_T("%Lf"),
(long double)((ase_awk_nde_real_t*)nde)->val);
#elif (ASE_SIZEOF_DOUBLE != 0)
2006-10-12 14:36:25 +00:00
awk->syscas.sprintf (
2006-10-24 04:10:12 +00:00
tmp, ase_countof(tmp), ASE_T("%f"),
(double)((ase_awk_nde_real_t*)nde)->val);
2006-10-06 03:37:40 +00:00
#else
#error unsupported floating-point data type
#endif
PUT_SRCSTR (awk, tmp);
}
else
{
PUT_SRCSTRX (awk,
2006-10-24 04:10:12 +00:00
((ase_awk_nde_real_t*)nde)->str,
((ase_awk_nde_real_t*)nde)->len);
2006-10-06 03:37:40 +00:00
}
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_STR:
2006-06-12 15:11:02 +00:00
{
2006-08-06 15:03:42 +00:00
/* TODO: ESCAPING */
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("\""));
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk,
2006-10-24 04:10:12 +00:00
((ase_awk_nde_str_t*)nde)->buf,
((ase_awk_nde_str_t*)nde)->len);
PUT_SRCSTR (awk, ASE_T("\""));
2006-06-12 15:11:02 +00:00
break;
2006-02-05 13:45:59 +00:00
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_REX:
2006-03-04 15:54:37 +00:00
{
2006-07-26 15:00:01 +00:00
/* TODO: buf, len */
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("/"));
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk,
2006-10-24 04:10:12 +00:00
((ase_awk_nde_rex_t*)nde)->buf,
((ase_awk_nde_rex_t*)nde)->len);
PUT_SRCSTR (awk, ASE_T("/"));
2006-06-12 15:11:02 +00:00
break;
2006-02-05 13:45:59 +00:00
}
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_ARG:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->id.idxa != (ase_size_t)-1);
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
n = ase_awk_longtostr (
px->id.idxa, 10, ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__param"));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-08-06 15:03:42 +00:00
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx == ASE_NULL);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_ARGIDX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->id.idxa != (ase_size_t)-1);
ASE_AWK_ASSERT (awk, px->idx != ASE_NULL);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__param"));
n = ase_awk_longtostr (
px->id.idxa, 10, ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->idx);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("]"));
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NAMED:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->id.idxa == (ase_size_t)-1);
ASE_AWK_ASSERT (awk, px->idx == ASE_NULL);
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NAMEDIDX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->id.idxa == (ase_size_t)-1);
ASE_AWK_ASSERT (awk, px->idx != ASE_NULL);
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->idx);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("]"));
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GLOBAL:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-09-02 14:59:15 +00:00
2006-10-24 04:10:12 +00:00
if (px->id.idxa != (ase_size_t)-1)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__global"));
n = ase_awk_longtostr (
2006-09-02 14:59:15 +00:00
px->id.idxa, 10,
2006-10-24 04:10:12 +00:00
ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-06-12 15:11:02 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-06-12 15:11:02 +00:00
}
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx == ASE_NULL);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GLOBALIDX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-09-02 14:59:15 +00:00
2006-10-24 04:10:12 +00:00
if (px->id.idxa != (ase_size_t)-1)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__global"));
n = ase_awk_longtostr (
2006-09-02 14:59:15 +00:00
px->id.idxa, 10,
2006-10-24 04:10:12 +00:00
ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-06-12 15:11:02 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-06-12 15:11:02 +00:00
}
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx != ASE_NULL);
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->idx);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("]"));
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_LOCAL:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-09-02 14:59:15 +00:00
2006-10-24 04:10:12 +00:00
if (px->id.idxa != (ase_size_t)-1)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__local"));
n = ase_awk_longtostr (
2006-09-02 14:59:15 +00:00
px->id.idxa, 10,
2006-10-24 04:10:12 +00:00
ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-06-12 15:11:02 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-06-12 15:11:02 +00:00
}
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx == ASE_NULL);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_LOCALIDX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
2006-09-02 14:59:15 +00:00
2006-10-24 04:10:12 +00:00
if (px->id.idxa != (ase_size_t)-1)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__local"));
n = ase_awk_longtostr (
2006-09-02 14:59:15 +00:00
px->id.idxa, 10,
2006-10-24 04:10:12 +00:00
ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-06-12 15:11:02 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("["));
2006-06-12 15:11:02 +00:00
}
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx != ASE_NULL);
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->idx);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("]"));
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_POS:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("$"));
PRINT_EXPRESSION (awk, ((ase_awk_nde_pos_t*)nde)->val);
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BFN:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)nde;
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk,
px->what.bfn.name, px->what.bfn.name_len);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" ("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->args);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-19 15:43:27 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_AFN:
2006-06-19 15:43:27 +00:00
{
2006-08-03 05:05:48 +00:00
/* TODO: use px->what.afn.name_len */
2006-10-24 04:10:12 +00:00
ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)nde;
2006-08-06 15:03:42 +00:00
PUT_SRCSTRX (awk,
px->what.afn.name, px->what.afn.name_len);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" ("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->args);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")"));
2006-06-12 15:11:02 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GETLINE:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_getline_t* px = (ase_awk_nde_getline_t*)nde;
if (px->in != ASE_NULL &&
(px->in_type == ASE_AWK_IN_PIPE ||
px->in_type == ASE_AWK_IN_COPROC))
2006-06-13 15:11:39 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->in);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __getline_inop_str[px->in_type]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-06-12 15:11:02 +00:00
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("getline"));
if (px->var != ASE_NULL)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->var);
2006-06-12 15:11:02 +00:00
}
2006-10-24 04:10:12 +00:00
if (px->in != ASE_NULL &&
px->in_type == ASE_AWK_IN_FILE)
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __getline_inop_str[px->in_type]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->in);
2006-06-12 15:11:02 +00:00
}
break;
}
default:
{
return -1;
2006-02-05 13:45:59 +00:00
}
2006-01-14 14:09:52 +00:00
}
return 0;
}
2006-10-24 04:10:12 +00:00
static int __print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree)
2006-01-14 14:09:52 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* p = tree;
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
while (p != ASE_NULL)
2006-03-04 15:54:37 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, p);
2006-01-14 14:09:52 +00:00
p = p->next;
2006-10-24 04:10:12 +00:00
if (p != ASE_NULL) PUT_SRCSTR (awk, ASE_T(","));
2006-01-14 14:09:52 +00:00
}
return 0;
}
2006-10-24 04:10:12 +00:00
static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
2006-01-14 14:09:52 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* p = tree;
ase_size_t i;
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
while (p != ASE_NULL)
2006-03-04 15:54:37 +00:00
{
2006-01-14 14:09:52 +00:00
2006-03-04 15:54:37 +00:00
switch (p->type)
{
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NULL:
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-06-13 08:35:53 +00:00
break;
}
2006-02-05 06:10:43 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BLK:
2006-04-24 14:38:46 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t tmp[ase_sizeof(ase_long_t)*8+2];
ase_size_t n;
ase_awk_nde_blk_t* px = (ase_awk_nde_blk_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("{\n"));
2006-02-05 06:10:43 +00:00
2006-06-13 08:35:53 +00:00
if (px->nlocals > 0)
2006-04-24 14:38:46 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth + 1);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("local "));
2006-06-13 08:35:53 +00:00
for (i = 0; i < px->nlocals - 1; i++)
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__local"));
n = ase_awk_longtostr (
i, 10, ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(", "));
2006-06-13 08:35:53 +00:00
}
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("__local"));
n = ase_awk_longtostr (
i, 10, ASE_NULL, tmp, ase_countof(tmp));
2006-09-02 14:59:15 +00:00
PUT_SRCSTRX (awk, tmp, n);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-02-05 06:10:43 +00:00
}
2006-01-14 14:09:52 +00:00
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth + 1);
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("}\n"));
2006-06-13 08:35:53 +00:00
break;
}
2006-01-14 16:09:58 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_IF:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("if ("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")\n"));
2006-06-13 08:35:53 +00:00
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->then_part != ASE_NULL);
2006-10-24 04:10:12 +00:00
if (px->then_part->type == ASE_AWK_NDE_BLK)
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->then_part, depth);
2006-01-19 10:56:35 +00:00
else
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->then_part, depth + 1);
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
if (px->else_part != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("else\n"));
if (px->else_part->type == ASE_AWK_NDE_BLK)
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->else_part, depth);
2006-06-13 08:35:53 +00:00
else
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->else_part, depth + 1);
2006-06-13 08:35:53 +00:00
}
break;
2006-01-19 10:56:35 +00:00
}
2006-01-18 16:12:59 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_WHILE:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("while ("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")\n"));
if (px->body->type == ASE_AWK_NDE_BLK)
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth);
2006-06-13 08:35:53 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth + 1);
2006-06-13 08:35:53 +00:00
}
break;
2006-01-19 10:56:35 +00:00
}
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_DOWHILE:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p;
2006-01-19 10:56:35 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("do\n"));
if (px->body->type == ASE_AWK_NDE_BLK)
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth);
2006-06-13 08:35:53 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth + 1);
2006-06-13 08:35:53 +00:00
}
2006-01-14 16:09:58 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("while ("));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(");\n"));
2006-06-13 08:35:53 +00:00
break;
2006-01-19 13:28:29 +00:00
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_FOR:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("for ("));
if (px->init != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->init);
2006-06-13 08:35:53 +00:00
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("; "));
if (px->test != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-06-13 08:35:53 +00:00
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("; "));
if (px->incr != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->incr);
2006-06-13 08:35:53 +00:00
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(")\n"));
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
if (px->body->type == ASE_AWK_NDE_BLK)
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth);
2006-06-13 08:35:53 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth + 1);
2006-06-13 08:35:53 +00:00
}
break;
2006-01-19 13:28:29 +00:00
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_FOREACH:
2006-04-30 17:12:51 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("for "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->test);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("\n"));
if (px->body->type == ASE_AWK_NDE_BLK)
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth);
2006-06-13 08:35:53 +00:00
}
else
{
2006-08-06 15:03:42 +00:00
PRINT_STATEMENTS (awk, px->body, depth + 1);
2006-06-13 08:35:53 +00:00
}
break;
2006-04-30 17:12:51 +00:00
}
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BREAK:
2006-04-30 17:12:51 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("break;\n"));
2006-06-13 08:35:53 +00:00
break;
2006-04-30 17:12:51 +00:00
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_CONTINUE:
2006-03-04 15:54:37 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("continue;\n"));
2006-06-13 08:35:53 +00:00
break;
2006-01-14 14:09:52 +00:00
}
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_RETURN:
2006-03-04 15:54:37 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_return_t*)p)->val == ASE_NULL)
2006-04-24 14:38:46 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("return;\n"));
2006-01-28 06:38:01 +00:00
}
2006-03-04 15:54:37 +00:00
else
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("return "));
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, ((ase_awk_nde_return_t*)p)->val->next == ASE_NULL);
2006-08-06 15:03:42 +00:00
2006-10-24 04:10:12 +00:00
PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val);
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-01-28 06:38:01 +00:00
}
2006-06-13 08:35:53 +00:00
break;
2006-01-14 14:09:52 +00:00
}
2006-01-28 06:38:01 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXIT:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exit_t* px = (ase_awk_nde_exit_t*)p;
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-06-13 08:35:53 +00:00
2006-10-24 04:10:12 +00:00
if (px->val == ASE_NULL)
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("exit;\n"));
2006-01-28 06:38:01 +00:00
}
2006-03-04 15:54:37 +00:00
else
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("exit "));
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->val->next == ASE_NULL);
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->val);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-01-28 06:38:01 +00:00
}
2006-06-13 08:35:53 +00:00
break;
2006-01-14 14:09:52 +00:00
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NEXT:
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("next;\n"));
2006-06-13 08:35:53 +00:00
break;
}
2006-01-20 07:33:46 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NEXTFILE:
2006-06-13 08:35:53 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("nextfile;\n"));
2006-06-13 08:35:53 +00:00
break;
}
2006-01-20 07:33:46 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_DELETE:
2006-06-27 14:18:19 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T("delete "));
2006-10-22 12:39:30 +00:00
/* TODO: can't use __print_expression??? */
2006-10-24 04:10:12 +00:00
ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var);
2006-06-27 14:18:19 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_PRINT:
2006-10-31 10:13:15 +00:00
case ASE_AWK_NDE_PRINTF:
2006-03-04 15:54:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_print_t* px = (ase_awk_nde_print_t*)p;
2006-06-13 08:35:53 +00:00
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-06-13 08:35:53 +00:00
2006-10-31 10:13:15 +00:00
if (p->type == ASE_AWK_NDE_PRINT)
PUT_SRCSTR (awk, ASE_T("print"));
else PUT_SRCSTR (awk, ASE_T("printf"));
2006-10-24 04:10:12 +00:00
if (px->args != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION_LIST (awk, px->args);
2006-06-13 08:35:53 +00:00
}
2006-10-24 04:10:12 +00:00
if (px->out != ASE_NULL)
2006-06-13 08:35:53 +00:00
{
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-08-06 15:03:42 +00:00
PUT_SRCSTR (awk, __print_outop_str[px->out_type]);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(" "));
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, px->out);
2006-06-13 08:35:53 +00:00
}
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-06-13 08:35:53 +00:00
break;
2006-01-14 14:09:52 +00:00
}
2006-06-13 08:35:53 +00:00
default:
2006-03-04 15:54:37 +00:00
{
2006-08-06 15:03:42 +00:00
PRINT_TABS (awk, depth);
2006-10-22 12:39:30 +00:00
PRINT_EXPRESSION (awk, p);
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(";\n"));
2006-01-14 14:09:52 +00:00
}
}
p = p->next;
}
2006-08-06 15:03:42 +00:00
return 0;
2006-01-14 14:09:52 +00:00
}
2006-10-24 04:10:12 +00:00
int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree)
2006-01-14 14:09:52 +00:00
{
2006-08-06 15:03:42 +00:00
return __print_statements (awk, tree, 0);
2006-01-14 14:09:52 +00:00
}
2006-10-24 04:10:12 +00:00
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree)
2006-05-07 17:45:08 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* nde = tree;
2006-05-07 17:45:08 +00:00
2006-10-24 04:10:12 +00:00
while (nde != ASE_NULL)
2006-05-07 17:45:08 +00:00
{
2006-10-22 12:39:30 +00:00
if (__print_expression (awk, nde) == -1) return -1;
2006-10-24 04:10:12 +00:00
if (nde->next == ASE_NULL) break;
2006-05-07 17:45:08 +00:00
2006-10-24 04:10:12 +00:00
PUT_SRCSTR (awk, ASE_T(","));
2006-05-07 17:45:08 +00:00
nde = nde->next;
}
2006-08-06 15:03:42 +00:00
return 0;
2006-05-07 17:45:08 +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
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* p = tree;
ase_awk_nde_t* next;
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
while (p != ASE_NULL)
2006-03-04 15:54:37 +00:00
{
2006-01-14 14:09:52 +00:00
next = p->next;
2006-03-04 15:54:37 +00:00
switch (p->type)
{
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NULL:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-18 16:12:59 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BLK:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_blk_t*)p)->body);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_IF:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p;
ase_awk_clrpt (awk, px->test);
ase_awk_clrpt (awk, px->then_part);
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
if (px->else_part != ASE_NULL)
ase_awk_clrpt (awk, px->else_part);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-19 13:28:29 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_WHILE:
case ASE_AWK_NDE_DOWHILE:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_while_t*)p)->test);
ase_awk_clrpt (awk, ((ase_awk_nde_while_t*)p)->body);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 16:09:58 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_FOR:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p;
if (px->init != ASE_NULL)
ase_awk_clrpt (awk, px->init);
if (px->test != ASE_NULL)
ase_awk_clrpt (awk, px->test);
if (px->incr != ASE_NULL)
ase_awk_clrpt (awk, px->incr);
ase_awk_clrpt (awk, px->body);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-19 13:28:29 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_FOREACH:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_foreach_t*)p)->test);
ase_awk_clrpt (awk, ((ase_awk_nde_foreach_t*)p)->body);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-18 16:12:59 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BREAK:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-04-29 12:09:29 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_CONTINUE:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-03-04 15:54:37 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_RETURN:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_return_t* px =
(ase_awk_nde_return_t*)p;
if (px->val != ASE_NULL)
ase_awk_clrpt (awk, px->val);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-03-04 15:54:37 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXIT:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_exit_t*)p)->val != ASE_NULL)
ase_awk_clrpt (awk, ((ase_awk_nde_exit_t*)p)->val);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NEXT:
case ASE_AWK_NDE_NEXTFILE:
2006-06-27 14:18:19 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-06-27 14:18:19 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_DELETE:
2006-06-27 14:18:19 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_delete_t*)p)->var);
ASE_AWK_FREE (awk, p);
2006-06-27 14:18:19 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_PRINT:
2006-10-31 10:13:15 +00:00
case ASE_AWK_NDE_PRINTF:
2006-06-27 14:18:19 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_print_t* px =
(ase_awk_nde_print_t*)p;
if (px->args != ASE_NULL)
ase_awk_clrpt (awk, px->args);
if (px->out != ASE_NULL)
ase_awk_clrpt (awk, px->out);
ASE_AWK_FREE (awk, p);
2006-06-27 14:18:19 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GRP:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_grp_t*)p)->body);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-04-26 15:53:17 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_ASS:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_ass_t*)p)->left);
ase_awk_clrpt (awk, ((ase_awk_nde_ass_t*)p)->right);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_BIN:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)p;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->left->next == ASE_NULL);
ASE_AWK_ASSERT (awk, px->right->next == ASE_NULL);
2006-06-12 15:11:02 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, px->left);
ase_awk_clrpt (awk, px->right);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_EXP_UNR:
case ASE_AWK_NDE_EXP_INCPRE:
case ASE_AWK_NDE_EXP_INCPST:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)p;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->right == ASE_NULL);
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, px->left);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_CND:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->test);
ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->left);
ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->right);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_INT:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_int_t*)p)->str != ASE_NULL)
ASE_AWK_FREE (awk, ((ase_awk_nde_int_t*)p)->str);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-04-11 09:16:20 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_REAL:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
if (((ase_awk_nde_real_t*)p)->str != ASE_NULL)
ASE_AWK_FREE (awk, ((ase_awk_nde_real_t*)p)->str);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-03-05 17:07:33 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_STR:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, ((ase_awk_nde_str_t*)p)->buf);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-03-28 16:33:09 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_REX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, ((ase_awk_nde_rex_t*)p)->buf);
ASE_AWK_FREE (awk, ((ase_awk_nde_rex_t*)p)->code);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NAMED:
case ASE_AWK_NDE_GLOBAL:
case ASE_AWK_NDE_LOCAL:
case ASE_AWK_NDE_ARG:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx == ASE_NULL);
2006-10-24 04:10:12 +00:00
if (px->id.name != ASE_NULL)
ASE_AWK_FREE (awk, px->id.name);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-04-24 11:26:00 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_NAMEDIDX:
case ASE_AWK_NDE_GLOBALIDX:
case ASE_AWK_NDE_LOCALIDX:
case ASE_AWK_NDE_ARGIDX:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p;
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, px->idx != ASE_NULL);
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, px->idx);
if (px->id.name != ASE_NULL)
ASE_AWK_FREE (awk, px->id.name);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-31 16:57:45 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_POS:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_clrpt (awk, ((ase_awk_nde_pos_t*)p)->val);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-31 16:57:45 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_BFN:
2006-06-19 15:43:27 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)p;
/* ASE_AWK_FREE (awk, px->what.bfn); */
ase_awk_clrpt (awk, px->args);
ASE_AWK_FREE (awk, p);
2006-06-19 15:43:27 +00:00
break;
}
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_AFN:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)p;
ASE_AWK_FREE (awk, px->what.afn.name);
ase_awk_clrpt (awk, px->args);
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-25 14:50:57 +00:00
2006-10-24 04:10:12 +00:00
case ASE_AWK_NDE_GETLINE:
2006-06-12 15:11:02 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_getline_t* px =
(ase_awk_nde_getline_t*)p;
if (px->var != ASE_NULL)
ase_awk_clrpt (awk, px->var);
if (px->in != ASE_NULL)
ase_awk_clrpt (awk, px->in);
ASE_AWK_FREE (awk, p);
2006-06-13 08:35:53 +00:00
break;
}
2006-06-12 15:11:02 +00:00
default:
{
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (awk, !"should never happen - invalid node type");
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-06-12 15:11:02 +00:00
break;
}
2006-01-14 14:09:52 +00:00
}
p = next;
}
}