2006-01-14 14:09:52 +00:00
|
|
|
/*
|
2006-07-01 07:57:10 +00:00
|
|
|
* $Id: tree.c,v 1.62 2006-07-01 07:57:10 bacon Exp $
|
2006-01-14 14:09:52 +00:00
|
|
|
*/
|
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
#include <xp/awk/awk_i.h>
|
2006-01-18 15:16:01 +00:00
|
|
|
|
2006-04-16 04:31:38 +00:00
|
|
|
#ifndef XP_AWK_STAND_ALONE
|
2006-01-14 14:09:52 +00:00
|
|
|
#include <xp/bas/memory.h>
|
|
|
|
#include <xp/bas/assert.h>
|
|
|
|
#include <xp/bas/stdio.h>
|
2006-01-18 15:16:01 +00:00
|
|
|
#endif
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-04-14 16:26:00 +00:00
|
|
|
static const xp_char_t* __assop_str[] =
|
|
|
|
{
|
2006-05-06 12:52:36 +00:00
|
|
|
XP_T("="),
|
|
|
|
XP_T("+="),
|
|
|
|
XP_T("-="),
|
|
|
|
XP_T("*="),
|
|
|
|
XP_T("/="),
|
|
|
|
XP_T("%="),
|
|
|
|
XP_T("**=")
|
2006-04-14 16:26:00 +00:00
|
|
|
};
|
|
|
|
|
2006-02-08 16:14:31 +00:00
|
|
|
static const xp_char_t* __binop_str[] =
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
2006-05-06 12:52:36 +00:00
|
|
|
XP_T("||"),
|
|
|
|
XP_T("&&"),
|
|
|
|
XP_T("in"),
|
|
|
|
|
|
|
|
XP_T("|"),
|
|
|
|
XP_T("^"),
|
|
|
|
XP_T("&"),
|
|
|
|
|
|
|
|
XP_T("=="),
|
|
|
|
XP_T("!="),
|
|
|
|
XP_T(">"),
|
|
|
|
XP_T(">="),
|
|
|
|
XP_T("<"),
|
|
|
|
XP_T("<="),
|
|
|
|
|
|
|
|
XP_T("<<"),
|
|
|
|
XP_T(">>"),
|
|
|
|
|
|
|
|
XP_T("+"),
|
|
|
|
XP_T("-"),
|
|
|
|
XP_T("*"),
|
|
|
|
XP_T("/"),
|
|
|
|
XP_T("%"),
|
|
|
|
XP_T("**"),
|
|
|
|
|
2006-06-29 15:40:30 +00:00
|
|
|
XP_T(" "),
|
2006-05-06 12:52:36 +00:00
|
|
|
XP_T("~"),
|
|
|
|
XP_T("!~")
|
2006-03-31 12:04:14 +00:00
|
|
|
};
|
|
|
|
|
2006-04-02 12:45:04 +00:00
|
|
|
static const xp_char_t* __unrop_str[] =
|
2006-03-31 12:04:14 +00:00
|
|
|
{
|
2006-05-06 12:52:36 +00:00
|
|
|
XP_T("+"),
|
|
|
|
XP_T("-"),
|
|
|
|
XP_T("!"),
|
|
|
|
XP_T("~")
|
2006-01-14 14:09:52 +00:00
|
|
|
};
|
|
|
|
|
2006-04-02 12:45:04 +00:00
|
|
|
static const xp_char_t* __incop_str[] =
|
|
|
|
{
|
2006-05-06 12:52:36 +00:00
|
|
|
XP_T("++"),
|
|
|
|
XP_T("--"),
|
|
|
|
XP_T("++"),
|
|
|
|
XP_T("--")
|
2006-04-02 12:45:04 +00:00
|
|
|
};
|
|
|
|
|
2006-06-13 15:11:39 +00:00
|
|
|
static const xp_char_t* __getline_inop_str[] =
|
|
|
|
{
|
|
|
|
XP_T("|"),
|
2006-06-18 10:53:06 +00:00
|
|
|
XP_T("|&"),
|
2006-06-29 14:38:01 +00:00
|
|
|
XP_T("<"),
|
|
|
|
XP_T("")
|
2006-06-13 15:11:39 +00:00
|
|
|
};
|
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
static const xp_char_t* __print_outop_str[] =
|
|
|
|
{
|
|
|
|
XP_T("|"),
|
2006-06-18 10:53:06 +00:00
|
|
|
XP_T("|&"),
|
2006-06-22 14:15:02 +00:00
|
|
|
XP_T(">"),
|
2006-06-25 15:26:57 +00:00
|
|
|
XP_T(">>"),
|
|
|
|
XP_T("")
|
2006-06-13 08:35:53 +00:00
|
|
|
};
|
|
|
|
|
2006-01-14 14:09:52 +00:00
|
|
|
static void __print_tabs (int depth);
|
2006-03-04 15:54:37 +00:00
|
|
|
static int __print_expression (xp_awk_nde_t* nde);
|
|
|
|
static int __print_expression_list (xp_awk_nde_t* tree);
|
2006-03-03 11:45:45 +00:00
|
|
|
static void __print_statements (xp_awk_nde_t* tree, int depth);
|
2006-01-14 14:09:52 +00:00
|
|
|
|
|
|
|
static void __print_tabs (int depth)
|
|
|
|
{
|
2006-07-01 07:57:10 +00:00
|
|
|
while (depth > 0)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("\t"));
|
|
|
|
depth--;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
static int __print_expression (xp_awk_nde_t* nde)
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
2006-04-24 14:38:46 +00:00
|
|
|
switch (nde->type)
|
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_GRP:
|
2006-04-26 15:53:17 +00:00
|
|
|
{
|
|
|
|
xp_awk_nde_t* p = ((xp_awk_nde_grp_t*)nde)->body;
|
|
|
|
|
2006-05-06 12:52:36 +00:00
|
|
|
xp_printf (XP_T("("));
|
2006-07-01 07:57:10 +00:00
|
|
|
while (p != XP_NULL)
|
|
|
|
{
|
2006-04-26 15:53:17 +00:00
|
|
|
__print_expression (p);
|
2006-05-06 12:52:36 +00:00
|
|
|
if (p->next != XP_NULL) xp_printf (XP_T(","));
|
2006-04-26 15:53:17 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
2006-05-06 12:52:36 +00:00
|
|
|
xp_printf (XP_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
|
|
|
|
|
|
|
case XP_AWK_NDE_ASS:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_ass_t* px = (xp_awk_nde_ass_t*)nde;
|
|
|
|
|
|
|
|
if (__print_expression (px->left) == -1) return -1;
|
|
|
|
xp_printf (XP_T(" %s "), __assop_str[px->opcode]);
|
|
|
|
if (__print_expression (px->right) == -1) return -1;
|
|
|
|
xp_assert (px->right->next == XP_NULL);
|
|
|
|
break;
|
2006-02-05 16:00:33 +00:00
|
|
|
}
|
2006-06-12 15:11:02 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_EXP_BIN:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde;
|
|
|
|
|
|
|
|
xp_printf (XP_T("("));
|
|
|
|
if (__print_expression(px->left) == -1) return -1;
|
|
|
|
xp_assert (px->left->next == XP_NULL);
|
|
|
|
xp_printf (XP_T(" %s "), __binop_str[px->opcode]);
|
|
|
|
if (px->right->type == XP_AWK_NDE_ASS) xp_printf (XP_T("("));
|
|
|
|
if (__print_expression (px->right) == -1) return -1;
|
|
|
|
if (px->right->type == XP_AWK_NDE_ASS) xp_printf (XP_T(")"));
|
|
|
|
xp_assert (px->right->next == XP_NULL);
|
|
|
|
xp_printf (XP_T(")"));
|
|
|
|
break;
|
2006-02-05 16:00:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_EXP_UNR:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde;
|
|
|
|
xp_assert (px->right == XP_NULL);
|
|
|
|
|
|
|
|
xp_printf (XP_T("%s("), __unrop_str[px->opcode]);
|
|
|
|
if (__print_expression (px->left) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")"));
|
|
|
|
break;
|
2006-02-05 16:00:33 +00:00
|
|
|
}
|
2006-06-12 15:11:02 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_EXP_INCPRE:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde;
|
|
|
|
xp_assert (px->right == XP_NULL);
|
|
|
|
|
|
|
|
xp_printf (XP_T("%s("), __incop_str[px->opcode]);
|
|
|
|
if (__print_expression (px->left) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")"));
|
|
|
|
break;
|
2006-02-05 16:00:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_EXP_INCPST:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde;
|
|
|
|
xp_assert (px->right == XP_NULL);
|
|
|
|
|
|
|
|
xp_printf (XP_T("("));
|
|
|
|
if (__print_expression (px->left) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")%s"), __incop_str[px->opcode]);
|
|
|
|
break;
|
2006-02-05 13:45:59 +00:00
|
|
|
}
|
2006-06-12 15:11:02 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_CND:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_cnd_t* px = (xp_awk_nde_cnd_t*)nde;
|
|
|
|
|
|
|
|
xp_printf (XP_T("("));
|
|
|
|
if (__print_expression(px->test) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")?"));
|
|
|
|
|
|
|
|
if (__print_expression(px->left) == -1) return -1;
|
|
|
|
xp_printf (XP_T(":"));
|
|
|
|
if (__print_expression(px->right) == -1) return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_INT:
|
|
|
|
{
|
|
|
|
#if defined(__LCC__)
|
|
|
|
xp_printf (XP_T("%lld"),
|
|
|
|
(long long)((xp_awk_nde_int_t*)nde)->val);
|
|
|
|
#elif defined(__BORLANDC__) || defined(_MSC_VER)
|
|
|
|
xp_printf (XP_T("%I64d"),
|
|
|
|
(__int64)((xp_awk_nde_int_t*)nde)->val);
|
|
|
|
#elif defined(vax) || defined(__vax) || defined(_SCO_DS)
|
|
|
|
xp_printf (XP_T("%ld"),
|
|
|
|
(long)((xp_awk_nde_int_t*)nde)->val);
|
|
|
|
#else
|
|
|
|
xp_printf (XP_T("%lld"),
|
|
|
|
(long long)((xp_awk_nde_int_t*)nde)->val);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_REAL:
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("%Lf"),
|
|
|
|
(long double)((xp_awk_nde_real_t*)nde)->val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_STR:
|
|
|
|
{
|
|
|
|
/* TODO: buf, len */
|
|
|
|
xp_printf (XP_T("\"%s\""), ((xp_awk_nde_str_t*)nde)->buf);
|
|
|
|
break;
|
2006-02-05 13:45:59 +00:00
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_REX:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
/* TODO: buf, len */
|
|
|
|
xp_printf (XP_T("/%s/"), ((xp_awk_nde_rex_t*)nde)->buf);
|
|
|
|
break;
|
2006-02-05 13:45:59 +00:00
|
|
|
}
|
2006-06-12 15:11:02 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_ARG:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
xp_assert (px->id.idxa != (xp_size_t)-1);
|
|
|
|
xp_printf (XP_T("__arg%lu"), (unsigned long)px->id.idxa);
|
|
|
|
xp_assert (px->idx == XP_NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_ARGIDX:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
xp_assert (px->id.idxa != (xp_size_t)-1);
|
|
|
|
xp_printf (XP_T("__arg%lu["), (unsigned long)px->id.idxa);
|
|
|
|
xp_assert (px->idx != XP_NULL);
|
|
|
|
__print_expression_list (px->idx);
|
|
|
|
xp_printf (XP_T("]"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_NAMED:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
xp_assert (px->id.idxa == (xp_size_t)-1);
|
|
|
|
xp_printf (XP_T("%s"), px->id.name);
|
|
|
|
xp_assert (px->idx == XP_NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_NAMEDIDX:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
xp_assert (px->id.idxa == (xp_size_t)-1);
|
|
|
|
xp_printf (XP_T("%s["), px->id.name);
|
|
|
|
xp_assert (px->idx != XP_NULL);
|
|
|
|
__print_expression_list (px->idx);
|
|
|
|
xp_printf (XP_T("]"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_GLOBAL:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
if (px->id.idxa != (xp_size_t)-1)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("__global%lu"),
|
|
|
|
(unsigned long)px->id.idxa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("%s"), px->id.name);
|
|
|
|
}
|
|
|
|
xp_assert (px->idx == XP_NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_GLOBALIDX:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
if (px->id.idxa != (xp_size_t)-1)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("__global%lu["),
|
|
|
|
(unsigned long)px->id.idxa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("%s["), px->id.name);
|
|
|
|
}
|
|
|
|
xp_assert (px->idx != XP_NULL);
|
|
|
|
__print_expression_list (px->idx);
|
|
|
|
xp_printf (XP_T("]"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_LOCAL:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
if (px->id.idxa != (xp_size_t)-1)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("__local%lu"),
|
|
|
|
(unsigned long)px->id.idxa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("%s"), px->id.name);
|
|
|
|
}
|
|
|
|
xp_assert (px->idx == XP_NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_LOCALIDX:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde;
|
|
|
|
if (px->id.idxa != (xp_size_t)-1)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("__local%lu["),
|
|
|
|
(unsigned long)px->id.idxa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("%s["), px->id.name);
|
|
|
|
}
|
|
|
|
xp_assert (px->idx != XP_NULL);
|
|
|
|
__print_expression_list (px->idx);
|
|
|
|
xp_printf (XP_T("]"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_POS:
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("$"));
|
|
|
|
__print_expression (((xp_awk_nde_pos_t*)nde)->val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-19 15:43:27 +00:00
|
|
|
case XP_AWK_NDE_BFN:
|
2006-06-12 15:11:02 +00:00
|
|
|
{
|
|
|
|
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
|
2006-06-19 15:43:27 +00:00
|
|
|
xp_printf (XP_T("%s ("), px->what.bfn->name);
|
|
|
|
if (__print_expression_list (px->args) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_UFN:
|
|
|
|
{
|
|
|
|
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
|
|
|
|
xp_printf (XP_T("%s ("), px->what.name);
|
2006-06-12 15:11:02 +00:00
|
|
|
if (__print_expression_list (px->args) == -1) return -1;
|
|
|
|
xp_printf (XP_T(")"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_GETLINE:
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
xp_awk_nde_getline_t* px = (xp_awk_nde_getline_t*)nde;
|
2006-06-13 15:11:39 +00:00
|
|
|
if (px->in != XP_NULL &&
|
2006-06-28 10:40:24 +00:00
|
|
|
(px->in_type == XP_AWK_IN_PIPE ||
|
|
|
|
px->in_type == XP_AWK_IN_COPROC))
|
2006-06-13 15:11:39 +00:00
|
|
|
{
|
|
|
|
__print_expression (px->in);
|
|
|
|
xp_printf (XP_T(" %s "),
|
|
|
|
__getline_inop_str[px->in_type]);
|
2006-06-12 15:11:02 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("getline"));
|
2006-06-12 15:11:02 +00:00
|
|
|
if (px->var != XP_NULL)
|
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T(" "));
|
2006-06-12 15:11:02 +00:00
|
|
|
__print_expression (px->var);
|
|
|
|
}
|
|
|
|
|
2006-06-13 15:11:39 +00:00
|
|
|
if (px->in != XP_NULL &&
|
2006-06-28 10:40:24 +00:00
|
|
|
px->in_type == XP_AWK_IN_FILE)
|
2006-06-12 15:11:02 +00:00
|
|
|
{
|
2006-06-13 15:11:39 +00:00
|
|
|
xp_printf (XP_T(" %s "),
|
|
|
|
__getline_inop_str[px->in_type]);
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_expression (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-03-04 15:54:37 +00:00
|
|
|
static int __print_expression_list (xp_awk_nde_t* tree)
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
2006-03-03 11:45:45 +00:00
|
|
|
xp_awk_nde_t* p = tree;
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
while (p != XP_NULL)
|
|
|
|
{
|
|
|
|
if (__print_expression(p) == -1) return -1;
|
2006-01-14 14:09:52 +00:00
|
|
|
p = p->next;
|
2006-05-06 12:52:36 +00:00
|
|
|
if (p != XP_NULL) xp_printf (XP_T(","));
|
2006-01-14 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-03 11:45:45 +00:00
|
|
|
static void __print_statements (xp_awk_nde_t* tree, int depth)
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
2006-03-03 11:45:45 +00:00
|
|
|
xp_awk_nde_t* p = tree;
|
2006-02-05 06:10:43 +00:00
|
|
|
xp_size_t i;
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
while (p != XP_NULL)
|
|
|
|
{
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
switch (p->type)
|
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_NULL:
|
|
|
|
{
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T(";\n"));
|
|
|
|
break;
|
|
|
|
}
|
2006-02-05 06:10:43 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_BLK:
|
2006-04-24 14:38:46 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_blk_t* px = (xp_awk_nde_blk_t*)p;
|
|
|
|
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_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-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth + 1);
|
|
|
|
xp_printf (XP_T("local "));
|
|
|
|
|
|
|
|
for (i = 0; i < px->nlocals - 1; i++)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("__local%lu, "), (unsigned long)i);
|
|
|
|
}
|
|
|
|
xp_printf (XP_T("__local%lu;\n"), (unsigned long)i);
|
2006-02-05 06:10:43 +00:00
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_statements (px->body, depth + 1);
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("}\n"));
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 16:09:58 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_IF:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_if_t* px = (xp_awk_nde_if_t*)p;
|
|
|
|
|
2006-01-14 16:09:58 +00:00
|
|
|
__print_tabs (depth);
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("if ("));
|
|
|
|
__print_expression (px->test);
|
|
|
|
xp_printf (XP_T(")\n"));
|
|
|
|
|
|
|
|
xp_assert (px->then_part != XP_NULL);
|
|
|
|
if (px->then_part->type == XP_AWK_NDE_BLK)
|
|
|
|
__print_statements (px->then_part, depth);
|
2006-01-19 10:56:35 +00:00
|
|
|
else
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_statements (px->then_part, depth + 1);
|
|
|
|
|
|
|
|
if (px->else_part != XP_NULL)
|
|
|
|
{
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("else\n"));
|
|
|
|
if (px->else_part->type == XP_AWK_NDE_BLK)
|
|
|
|
__print_statements (px->else_part, depth);
|
|
|
|
else
|
|
|
|
__print_statements (px->else_part, depth + 1);
|
|
|
|
}
|
|
|
|
break;
|
2006-01-19 10:56:35 +00:00
|
|
|
}
|
2006-01-18 16:12:59 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_WHILE:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_while_t* px = (xp_awk_nde_while_t*)p;
|
|
|
|
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("while ("));
|
|
|
|
__print_expression (px->test);
|
|
|
|
xp_printf (XP_T(")\n"));
|
|
|
|
if (px->body->type == XP_AWK_NDE_BLK)
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth + 1);
|
|
|
|
}
|
|
|
|
break;
|
2006-01-19 10:56:35 +00:00
|
|
|
}
|
2006-06-13 08:35:53 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_DOWHILE:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_while_t* px = (xp_awk_nde_while_t*)p;
|
2006-01-19 10:56:35 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("do\n"));
|
|
|
|
if (px->body->type == XP_AWK_NDE_BLK)
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth + 1);
|
|
|
|
}
|
2006-01-14 16:09:58 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("while ("));
|
|
|
|
__print_expression (px->test);
|
|
|
|
xp_printf (XP_T(");\n"));
|
|
|
|
break;
|
2006-01-19 13:28:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_FOR:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_for_t* px = (xp_awk_nde_for_t*)p;
|
|
|
|
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("for ("));
|
|
|
|
if (px->init != XP_NULL)
|
|
|
|
{
|
|
|
|
__print_expression (px->init);
|
|
|
|
}
|
|
|
|
xp_printf (XP_T("; "));
|
|
|
|
if (px->test != XP_NULL)
|
|
|
|
{
|
|
|
|
__print_expression (px->test);
|
|
|
|
}
|
|
|
|
xp_printf (XP_T("; "));
|
|
|
|
if (px->incr != XP_NULL)
|
|
|
|
{
|
|
|
|
__print_expression (px->incr);
|
|
|
|
}
|
|
|
|
xp_printf (XP_T(")\n"));
|
|
|
|
|
|
|
|
if (px->body->type == XP_AWK_NDE_BLK)
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth + 1);
|
|
|
|
}
|
|
|
|
break;
|
2006-01-19 13:28:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_FOREACH:
|
2006-04-30 17:12:51 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_foreach_t* px = (xp_awk_nde_foreach_t*)p;
|
|
|
|
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("for "));
|
|
|
|
__print_expression (px->test);
|
|
|
|
xp_printf (XP_T("\n"));
|
|
|
|
if (px->body->type == XP_AWK_NDE_BLK)
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__print_statements (px->body, depth + 1);
|
|
|
|
}
|
|
|
|
break;
|
2006-04-30 17:12:51 +00:00
|
|
|
}
|
2006-06-13 08:35:53 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_BREAK:
|
2006-04-30 17:12:51 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("break;\n"));
|
|
|
|
break;
|
2006-04-30 17:12:51 +00:00
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_CONTINUE:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("continue;\n"));
|
|
|
|
break;
|
2006-01-14 14:09:52 +00:00
|
|
|
}
|
2006-06-13 08:35:53 +00:00
|
|
|
|
|
|
|
case XP_AWK_NDE_RETURN:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
if (((xp_awk_nde_return_t*)p)->val == XP_NULL)
|
2006-04-24 14:38:46 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("return;\n"));
|
2006-01-28 06:38:01 +00:00
|
|
|
}
|
2006-03-04 15:54:37 +00:00
|
|
|
else
|
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("return "));
|
|
|
|
xp_assert (((xp_awk_nde_return_t*)p)->val->next == XP_NULL);
|
|
|
|
if (__print_expression(((xp_awk_nde_return_t*)p)->val) == 0)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T(";\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_awk_nde_return_t* x = (xp_awk_nde_return_t*)p;
|
|
|
|
xp_printf (XP_T("***INTERNAL ERROR: unknown nde type - %d\n"), x->type);
|
|
|
|
}
|
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-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_EXIT:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_exit_t* px = (xp_awk_nde_exit_t*)p;
|
|
|
|
__print_tabs (depth);
|
|
|
|
|
|
|
|
if (px->val == XP_NULL)
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("exit;\n"));
|
2006-01-28 06:38:01 +00:00
|
|
|
}
|
2006-03-04 15:54:37 +00:00
|
|
|
else
|
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_printf (XP_T("exit "));
|
|
|
|
xp_assert (px->val->next == XP_NULL);
|
|
|
|
if (__print_expression(px->val) == 0)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T(";\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("***INTERNAL ERROR: unknown nde type - %d\n"), px->type);
|
|
|
|
}
|
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-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_NEXT:
|
|
|
|
{
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("next;\n"));
|
|
|
|
break;
|
|
|
|
}
|
2006-01-20 07:33:46 +00:00
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_NEXTFILE:
|
|
|
|
{
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("nextfile;\n"));
|
|
|
|
break;
|
|
|
|
}
|
2006-01-20 07:33:46 +00:00
|
|
|
|
2006-06-27 14:18:19 +00:00
|
|
|
case XP_AWK_NDE_DELETE:
|
|
|
|
{
|
|
|
|
__print_tabs (depth);
|
|
|
|
xp_printf (XP_T("delete "));
|
|
|
|
xp_awk_prnpt (((xp_awk_nde_delete_t*)p)->var);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-13 08:35:53 +00:00
|
|
|
case XP_AWK_NDE_PRINT:
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-06-13 08:35:53 +00:00
|
|
|
xp_awk_nde_print_t* px = (xp_awk_nde_print_t*)p;
|
|
|
|
|
|
|
|
__print_tabs (depth);
|
|
|
|
|
|
|
|
xp_printf (XP_T("print"));
|
|
|
|
if (px->args != XP_NULL)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T(" "));
|
|
|
|
__print_expression_list (px->args);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (px->out != XP_NULL)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T(" %s "),
|
|
|
|
__print_outop_str[px->out_type]);
|
|
|
|
__print_expression (px->out);
|
|
|
|
}
|
|
|
|
|
2006-05-06 12:52:36 +00:00
|
|
|
xp_printf (XP_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-06-13 08:35:53 +00:00
|
|
|
__print_tabs (depth);
|
|
|
|
if (__print_expression(p) == 0)
|
|
|
|
{
|
|
|
|
xp_printf (XP_T(";\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xp_printf (XP_T("***INTERNAL ERROR: unknown type - %d\n"), p->type);
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-03 11:45:45 +00:00
|
|
|
void xp_awk_prnpt (xp_awk_nde_t* tree)
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
|
|
|
__print_statements (tree, 0);
|
|
|
|
}
|
|
|
|
|
2006-05-07 17:45:08 +00:00
|
|
|
void xp_awk_prnptnpt (xp_awk_nde_t* tree)
|
|
|
|
{
|
|
|
|
xp_awk_nde_t* nde = tree;
|
|
|
|
|
|
|
|
while (nde != XP_NULL)
|
|
|
|
{
|
2006-05-09 15:58:16 +00:00
|
|
|
__print_expression (nde);
|
2006-05-07 17:45:08 +00:00
|
|
|
if (nde->next == XP_NULL) break;
|
|
|
|
|
|
|
|
xp_printf (XP_T(","));
|
|
|
|
nde = nde->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-03 11:45:45 +00:00
|
|
|
void xp_awk_clrpt (xp_awk_nde_t* tree)
|
2006-01-14 14:09:52 +00:00
|
|
|
{
|
2006-03-03 11:45:45 +00:00
|
|
|
xp_awk_nde_t* p = tree;
|
|
|
|
xp_awk_nde_t* next;
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
while (p != XP_NULL)
|
|
|
|
{
|
2006-01-14 14:09:52 +00:00
|
|
|
next = p->next;
|
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
switch (p->type)
|
|
|
|
{
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_NULL:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-18 16:12:59 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_BLK:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_blk_t*)p)->body);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_IF:
|
|
|
|
{
|
|
|
|
xp_awk_nde_if_t* px = (xp_awk_nde_if_t*)p;
|
|
|
|
xp_awk_clrpt (px->test);
|
|
|
|
xp_awk_clrpt (px->then_part);
|
|
|
|
|
|
|
|
if (px->else_part != XP_NULL)
|
|
|
|
xp_awk_clrpt (px->else_part);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-19 13:28:29 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_WHILE:
|
|
|
|
case XP_AWK_NDE_DOWHILE:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_while_t*)p)->test);
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_while_t*)p)->body);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 16:09:58 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_FOR:
|
|
|
|
{
|
|
|
|
xp_awk_nde_for_t* px = (xp_awk_nde_for_t*)p;
|
|
|
|
|
|
|
|
if (px->init != XP_NULL)
|
|
|
|
xp_awk_clrpt (px->init);
|
|
|
|
if (px->test != XP_NULL)
|
|
|
|
xp_awk_clrpt (px->test);
|
|
|
|
if (px->incr != XP_NULL)
|
|
|
|
xp_awk_clrpt (px->incr);
|
|
|
|
xp_awk_clrpt (px->body);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-19 13:28:29 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_FOREACH:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_foreach_t*)p)->test);
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_foreach_t*)p)->body);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-18 16:12:59 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_BREAK:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-29 12:09:29 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_CONTINUE:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-04 15:54:37 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_RETURN:
|
|
|
|
{
|
|
|
|
xp_awk_nde_return_t* px =
|
|
|
|
(xp_awk_nde_return_t*)p;
|
|
|
|
if (px->val != XP_NULL) xp_awk_clrpt (px->val);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-04 15:54:37 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_EXIT:
|
|
|
|
{
|
|
|
|
if (((xp_awk_nde_exit_t*)p)->val != XP_NULL)
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_exit_t*)p)->val);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-27 14:18:19 +00:00
|
|
|
case XP_AWK_NDE_NEXT:
|
|
|
|
case XP_AWK_NDE_NEXTFILE:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_DELETE:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_delete_t*)p)->var);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_PRINT:
|
|
|
|
{
|
|
|
|
xp_awk_nde_print_t* px =
|
|
|
|
(xp_awk_nde_print_t*)p;
|
|
|
|
if (px->args != XP_NULL) xp_awk_clrpt (px->args);
|
|
|
|
if (px->out != XP_NULL) xp_awk_clrpt (px->out);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_GRP:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_grp_t*)p)->body);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-26 15:53:17 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_ASS:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->left);
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->right);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_EXP_BIN:
|
|
|
|
{
|
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)p;
|
|
|
|
xp_assert (px->left->next == XP_NULL);
|
|
|
|
xp_assert (px->right->next == XP_NULL);
|
|
|
|
|
|
|
|
xp_awk_clrpt (px->left);
|
|
|
|
xp_awk_clrpt (px->right);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_EXP_UNR:
|
|
|
|
case XP_AWK_NDE_EXP_INCPRE:
|
|
|
|
case XP_AWK_NDE_EXP_INCPST:
|
|
|
|
{
|
|
|
|
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)p;
|
|
|
|
xp_assert (px->right == XP_NULL);
|
|
|
|
xp_awk_clrpt (px->left);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_CND:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->test);
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->left);
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->right);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_INT:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-11 09:16:20 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_REAL:
|
|
|
|
{
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-05 17:07:33 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_STR:
|
|
|
|
{
|
|
|
|
xp_free (((xp_awk_nde_str_t*)p)->buf);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-28 16:33:09 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_REX:
|
|
|
|
{
|
|
|
|
xp_free (((xp_awk_nde_rex_t*)p)->buf);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_NAMED:
|
|
|
|
case XP_AWK_NDE_GLOBAL:
|
|
|
|
case XP_AWK_NDE_LOCAL:
|
|
|
|
case XP_AWK_NDE_ARG:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p;
|
|
|
|
xp_assert (px->idx == XP_NULL);
|
|
|
|
if (px->id.name != XP_NULL)
|
|
|
|
xp_free (px->id.name);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-24 11:26:00 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_NAMEDIDX:
|
|
|
|
case XP_AWK_NDE_GLOBALIDX:
|
|
|
|
case XP_AWK_NDE_LOCALIDX:
|
|
|
|
case XP_AWK_NDE_ARGIDX:
|
|
|
|
{
|
|
|
|
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p;
|
|
|
|
xp_assert (px->idx != XP_NULL);
|
|
|
|
xp_awk_clrpt (px->idx);
|
|
|
|
if (px->id.name != XP_NULL)
|
|
|
|
xp_free (px->id.name);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-31 16:57:45 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_POS:
|
|
|
|
{
|
|
|
|
xp_awk_clrpt (((xp_awk_nde_pos_t*)p)->val);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-31 16:57:45 +00:00
|
|
|
|
2006-06-19 15:43:27 +00:00
|
|
|
case XP_AWK_NDE_BFN:
|
|
|
|
{
|
|
|
|
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
|
|
|
|
/* xp_free (px->what.bfn); */
|
|
|
|
xp_awk_clrpt (px->args);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XP_AWK_NDE_UFN:
|
2006-06-12 15:11:02 +00:00
|
|
|
{
|
|
|
|
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
|
2006-06-19 15:43:27 +00:00
|
|
|
xp_free (px->what.name);
|
2006-06-12 15:11:02 +00:00
|
|
|
xp_awk_clrpt (px->args);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-25 14:50:57 +00:00
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
case XP_AWK_NDE_GETLINE:
|
|
|
|
{
|
|
|
|
xp_awk_nde_getline_t* px =
|
|
|
|
(xp_awk_nde_getline_t*)p;
|
|
|
|
if (px->var != XP_NULL) xp_awk_clrpt (px->var);
|
2006-06-13 08:35:53 +00:00
|
|
|
if (px->in != XP_NULL) xp_awk_clrpt (px->in);
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-12 15:11:02 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
xp_assert (!"should never happen - invalid node type");
|
|
|
|
xp_free (p);
|
|
|
|
break;
|
|
|
|
}
|
2006-01-14 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = next;
|
|
|
|
}
|
|
|
|
}
|