2019-12-13 04:29:58 +00:00
|
|
|
/*
|
2020-04-16 03:42:30 +00:00
|
|
|
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
|
2019-12-13 04:29:58 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hawk-prv.h"
|
|
|
|
|
|
|
|
static const hawk_ooch_t* assop_str[] =
|
|
|
|
{
|
|
|
|
/* this table must match hawk_assop_type_t in run.h */
|
|
|
|
HAWK_T("="),
|
|
|
|
HAWK_T("+="),
|
|
|
|
HAWK_T("-="),
|
|
|
|
HAWK_T("*="),
|
|
|
|
HAWK_T("/="),
|
|
|
|
HAWK_T("\\="),
|
|
|
|
HAWK_T("%="),
|
|
|
|
HAWK_T("**="), /* exponentation, also ^= */
|
|
|
|
HAWK_T("%%="),
|
|
|
|
HAWK_T(">>="),
|
|
|
|
HAWK_T("<<="),
|
|
|
|
HAWK_T("&="),
|
|
|
|
HAWK_T("^^="),
|
|
|
|
HAWK_T("|=")
|
|
|
|
};
|
|
|
|
|
|
|
|
static const hawk_ooch_t* binop_str[][2] =
|
|
|
|
{
|
|
|
|
{ HAWK_T("||"), HAWK_T("||") },
|
|
|
|
{ HAWK_T("&&"), HAWK_T("&&") },
|
|
|
|
{ HAWK_T("in"), HAWK_T("in") },
|
|
|
|
|
|
|
|
{ HAWK_T("|"), HAWK_T("|") },
|
|
|
|
{ HAWK_T("^^"), HAWK_T("^^") },
|
|
|
|
{ HAWK_T("&"), HAWK_T("&") },
|
|
|
|
|
|
|
|
{ HAWK_T("==="), HAWK_T("===") },
|
|
|
|
{ HAWK_T("!=="), HAWK_T("!==") },
|
|
|
|
{ HAWK_T("=="), HAWK_T("==") },
|
|
|
|
{ HAWK_T("!="), HAWK_T("!=") },
|
|
|
|
{ HAWK_T(">"), HAWK_T(">") },
|
|
|
|
{ HAWK_T(">="), HAWK_T(">=") },
|
|
|
|
{ HAWK_T("<"), HAWK_T("<") },
|
|
|
|
{ HAWK_T("<="), HAWK_T("<=") },
|
|
|
|
|
|
|
|
{ HAWK_T("<<"), HAWK_T("<<") },
|
|
|
|
{ HAWK_T(">>"), HAWK_T(">>") },
|
|
|
|
|
|
|
|
{ HAWK_T("+"), HAWK_T("+") },
|
|
|
|
{ HAWK_T("-"), HAWK_T("-") },
|
|
|
|
{ HAWK_T("*"), HAWK_T("*") },
|
|
|
|
{ HAWK_T("/"), HAWK_T("/") },
|
|
|
|
{ HAWK_T("\\"), HAWK_T("\\") },
|
|
|
|
{ HAWK_T("%"), HAWK_T("%") },
|
|
|
|
{ HAWK_T("**"), HAWK_T("**") }, /* exponentation, also ^ */
|
|
|
|
|
|
|
|
{ HAWK_T(" "), HAWK_T("%%") }, /* take note of this entry */
|
|
|
|
{ HAWK_T("~"), HAWK_T("~") },
|
|
|
|
{ HAWK_T("!~"), HAWK_T("!~") }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const hawk_ooch_t* unrop_str[] =
|
|
|
|
{
|
|
|
|
HAWK_T("+"),
|
|
|
|
HAWK_T("-"),
|
|
|
|
HAWK_T("!"),
|
2020-03-04 09:54:38 +00:00
|
|
|
HAWK_T("~")
|
2019-12-13 04:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const hawk_ooch_t* incop_str[] =
|
|
|
|
{
|
|
|
|
HAWK_T("++"),
|
|
|
|
HAWK_T("--"),
|
|
|
|
HAWK_T("++"),
|
|
|
|
HAWK_T("--")
|
|
|
|
};
|
|
|
|
|
|
|
|
static const hawk_ooch_t* getline_inop_str[] =
|
|
|
|
{
|
|
|
|
HAWK_T("|"),
|
|
|
|
HAWK_T("||"),
|
|
|
|
HAWK_T("<"),
|
|
|
|
HAWK_T("")
|
|
|
|
};
|
|
|
|
|
|
|
|
static const hawk_ooch_t* print_outop_str[] =
|
|
|
|
{
|
|
|
|
HAWK_T("|"),
|
|
|
|
HAWK_T("||"),
|
|
|
|
HAWK_T(">"),
|
|
|
|
HAWK_T(">>"),
|
|
|
|
HAWK_T("")
|
|
|
|
};
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PUT_SRCSTR(hawk,str) do { if (hawk_putsrcoocstr (hawk, str) == -1) return -1; } while(0)
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PUT_NL(hawk) do { \
|
|
|
|
if (hawk->opt.trait & HAWK_CRLF) PUT_SRCSTR (hawk, HAWK_T("\r")); \
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\n")); \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PUT_SRCSTRN(hawk,str,len) do { \
|
|
|
|
if (hawk_putsrcoochars (hawk, str, len) == -1) return -1; \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PRINT_TABS(hawk,depth) do { \
|
|
|
|
if (print_tabs(hawk,depth) == -1) return -1; \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PRINT_EXPR(hawk,nde) do { \
|
|
|
|
if (print_expr(hawk,nde) == -1) return -1; \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PRINT_EXPR_LIST(hawk,nde) do { \
|
|
|
|
if (print_expr_list(hawk,nde) == -1) return -1; \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PRINT_EXPR_LIST_FOR_IDX(hawk,nde) do { \
|
|
|
|
if (print_expr_list_for_idx(hawk,nde) == -1) return -1; \
|
2020-03-30 08:54:37 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
#define PRINT_STMTS(hawk,nde,depth) do { \
|
|
|
|
if (print_stmts(hawk,nde,depth) == -1) return -1; \
|
2019-12-13 04:29:58 +00:00
|
|
|
} while(0)
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_tabs (hawk_t* hawk, int depth);
|
|
|
|
static int print_expr (hawk_t* hawk, hawk_nde_t* nde);
|
|
|
|
static int print_expr_list (hawk_t* hawk, hawk_nde_t* tree);
|
|
|
|
static int print_expr_list_for_idx (hawk_t* hawk, hawk_nde_t* tree);
|
|
|
|
static int print_stmts (hawk_t* hawk, hawk_nde_t* tree, int depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_tabs (hawk_t* hawk, int depth)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
while (depth > 0)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\t"));
|
2019-12-13 04:29:58 +00:00
|
|
|
depth--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_printx (hawk_t* hawk, hawk_nde_print_t* px)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_oocs_t kw;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->type == HAWK_NDE_PRINT)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_PRINT, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_PRINTF, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (px->args != HAWK_NULL)
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR_LIST (hawk, px->args);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (px->out != HAWK_NULL)
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PUT_SRCSTR (hawk, print_outop_str[px->out_type]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR (hawk, px->out);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_expr (hawk_t* hawk, hawk_nde_t* nde)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_oocs_t kw;
|
2024-05-02 13:47:30 +00:00
|
|
|
|
|
|
|
switch (nde->type)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
case HAWK_NDE_GRP:
|
2024-05-02 13:47:30 +00:00
|
|
|
{
|
2019-12-13 04:29:58 +00:00
|
|
|
hawk_nde_t* p = ((hawk_nde_grp_t*)nde)->body;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
2024-05-02 13:47:30 +00:00
|
|
|
while (p != HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, p);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (p->next != HAWK_NULL)
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(","));
|
2019-12-13 04:29:58 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_ASS:
|
|
|
|
{
|
|
|
|
hawk_nde_ass_t* px = (hawk_nde_ass_t*)nde;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->left);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PUT_SRCSTR (hawk, assop_str[px->opcode]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR (hawk, px->right);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->right->next == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_BIN:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)nde;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->left);
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->left->next == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PUT_SRCSTR (hawk, binop_str[px->opcode][(hawk->opt.trait & HAWK_BLANKCONCAT)? 0: 1]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->right->type == HAWK_NDE_ASS)
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->right);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->right->type == HAWK_NDE_ASS)
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2024-05-02 13:47:30 +00:00
|
|
|
HAWK_ASSERT (px->right->next == HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_UNR:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->right == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PUT_SRCSTR (hawk, unrop_str[px->opcode]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->left);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_INCPRE:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->right == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, incop_str[px->opcode]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->left);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_INCPST:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->right == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->left);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
PUT_SRCSTR (hawk, incop_str[px->opcode]);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_CND:
|
|
|
|
{
|
|
|
|
hawk_nde_cnd_t* px = (hawk_nde_cnd_t*)nde;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR (hawk, px->test);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")?"));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->left);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(":"));
|
|
|
|
PRINT_EXPR (hawk, px->right);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-04 16:19:01 +00:00
|
|
|
case HAWK_NDE_CHAR:
|
|
|
|
{
|
|
|
|
hawk_ooch_t tmp = ((hawk_nde_char_t*)nde)->val;
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t buf[16];
|
2020-12-04 16:19:01 +00:00
|
|
|
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\'"));
|
|
|
|
if (tmp == '\0')
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\0"));
|
|
|
|
else if (tmp == '\'')
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\'"));
|
|
|
|
else if (hawk_is_ooch_print(tmp))
|
|
|
|
PUT_SRCSTRN (hawk, &tmp, 1);
|
|
|
|
#if defined(HAWK_OOCH_IS_UCH)
|
|
|
|
else if (tmp <= 0xFFFF)
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("\\u%04x"), (hawk_oochu_t)tmp);
|
2020-12-04 16:19:01 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("\\U%08x"), (hawk_oochu_t)tmp);
|
2020-12-04 16:19:01 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
else
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("\\x%02x"), (hawk_oochu_t)tmp);
|
2020-12-04 16:19:01 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\'"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-09 18:07:20 +00:00
|
|
|
case HAWK_NDE_BCHR:
|
|
|
|
{
|
2020-12-18 17:16:58 +00:00
|
|
|
hawk_bch_t tmp = ((hawk_nde_bchr_t*)nde)->val;
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t buf[16];
|
2020-12-09 18:07:20 +00:00
|
|
|
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("@b\'"));
|
|
|
|
if (tmp == '\0')
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\0"));
|
|
|
|
else if (tmp == '\'')
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\'"));
|
|
|
|
else if (hawk_is_bch_print(tmp))
|
2020-12-10 16:55:47 +00:00
|
|
|
{
|
|
|
|
hawk_ooch_t oc = (hawk_bchu_t)tmp;
|
|
|
|
PUT_SRCSTRN (hawk, &oc, 1);
|
|
|
|
}
|
2020-12-09 18:07:20 +00:00
|
|
|
else
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("\\x%02x"), (hawk_bchu_t)tmp);
|
2020-12-09 18:07:20 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\'"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:29:58 +00:00
|
|
|
case HAWK_NDE_INT:
|
|
|
|
{
|
|
|
|
if (((hawk_nde_int_t*)nde)->str)
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
PUT_SRCSTRN (hawk, ((hawk_nde_int_t*)nde)->str, ((hawk_nde_int_t*)nde)->len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
/* Note that the array sizing fomula is not accurate
|
2019-12-13 04:29:58 +00:00
|
|
|
* but should be good enoug consiering the followings.
|
|
|
|
*
|
|
|
|
* size minval digits sign
|
|
|
|
* 1 -128 3 1
|
|
|
|
* 2 -32768 5 1
|
|
|
|
* 4 -2147483648 10 1
|
|
|
|
* 8 -9223372036854775808 19 1
|
|
|
|
* 16 -170141183460469231731687303715884105728 39 1
|
|
|
|
*/
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t buf[HAWK_SIZEOF(hawk_int_t) * 3 + 2];
|
2019-12-13 04:29:58 +00:00
|
|
|
|
|
|
|
hawk_fmt_intmax_to_oocstr (
|
|
|
|
buf, HAWK_COUNTOF(buf),
|
|
|
|
((hawk_nde_int_t*)nde)->val,
|
2024-05-02 13:47:30 +00:00
|
|
|
10,
|
2019-12-13 04:29:58 +00:00
|
|
|
-1,
|
|
|
|
HAWK_T('\0'),
|
|
|
|
HAWK_NULL
|
|
|
|
);
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FLT:
|
|
|
|
{
|
|
|
|
if (((hawk_nde_flt_t*)nde)->str)
|
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
PUT_SRCSTRN (hawk, ((hawk_nde_flt_t*)nde)->str, ((hawk_nde_flt_t*)nde)->len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hawk_ooch_t buf[96];
|
|
|
|
|
2020-12-03 07:28:53 +00:00
|
|
|
#if defined(HAWK_USE_FLTMAX)
|
|
|
|
/*hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("%jf"), ((hawk_nde_flt_t*)nde)->val);*/
|
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("%jjf"), &((hawk_nde_flt_t*)nde)->val);
|
|
|
|
#else
|
|
|
|
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("%zf"), ((hawk_nde_flt_t*)nde)->val);
|
|
|
|
#endif
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, buf);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_STR:
|
|
|
|
{
|
|
|
|
hawk_ooch_t* ptr;
|
|
|
|
hawk_oow_t len, i;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
|
|
|
ptr = ((hawk_nde_str_t*)nde)->ptr;
|
|
|
|
len = ((hawk_nde_str_t*)nde)->len;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
/* TODO: maybe more de-escaping?? */
|
|
|
|
switch (ptr[i])
|
|
|
|
{
|
|
|
|
case HAWK_T('\n'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\n"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\r'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\r"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\t'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\t"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\f'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\f"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\b'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\b"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\v'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\v"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\a'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\a"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\0'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\0"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\"'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_T('\\'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\\\"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, &ptr[i], 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_MBS:
|
|
|
|
{
|
|
|
|
hawk_bch_t* ptr;
|
|
|
|
hawk_oow_t len, i;
|
|
|
|
|
2020-11-08 17:23:25 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("@b\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
ptr = ((hawk_nde_mbs_t*)nde)->ptr;
|
|
|
|
len = ((hawk_nde_mbs_t*)nde)->len;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
/* TODO: maybe more de-escaping?? */
|
|
|
|
switch (ptr[i])
|
|
|
|
{
|
|
|
|
case HAWK_BT('\n'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\n"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\r'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\r"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\t'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\t"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\f'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\f"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\b'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\b"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\v'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\v"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\a'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\a"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\0'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\0"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\"'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
case HAWK_BT('\\'):
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\\\"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
#if defined(HAWK_OOCH_IS_BCH)
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, &ptr[i], 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
#else
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_ooch_t oc = (hawk_bchu_t)ptr[i];
|
|
|
|
if (HAWK_BYTE_PRINTABLE(oc))
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-12-10 16:55:47 +00:00
|
|
|
PUT_SRCSTRN (hawk, &oc, 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hawk_bch_t xbuf[3];
|
2020-12-10 16:55:47 +00:00
|
|
|
hawk_byte_to_bcstr (oc, xbuf, HAWK_COUNTOF(xbuf), 16, '0');
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\\x"));
|
2020-12-10 16:55:47 +00:00
|
|
|
oc = (hawk_bchu_t)xbuf[0]; PUT_SRCSTRN (hawk, &oc, 1);
|
|
|
|
oc = (hawk_bchu_t)xbuf[1]; PUT_SRCSTRN (hawk, &oc, 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("\""));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_REX:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("/"));
|
|
|
|
PUT_SRCSTRN (hawk,
|
2024-05-02 13:47:30 +00:00
|
|
|
((hawk_nde_rex_t*)nde)->str.ptr,
|
2019-12-13 04:29:58 +00:00
|
|
|
((hawk_nde_rex_t*)nde)->str.len);
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("/"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-10 02:56:29 +00:00
|
|
|
case HAWK_NDE_XNIL:
|
|
|
|
{
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("@nil"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:36:50 +00:00
|
|
|
case HAWK_NDE_XARG:
|
|
|
|
{
|
|
|
|
static hawk_ooch_t* xarg_str[] =
|
|
|
|
{
|
|
|
|
HAWK_T("@argv("),
|
|
|
|
HAWK_T("@argc("),
|
|
|
|
};
|
|
|
|
PUT_SRCSTR (hawk, xarg_str[((hawk_nde_xarg_t*)nde)->opcode % 2]);
|
|
|
|
if (((hawk_nde_xarg_t*)nde)->pos) PRINT_EXPR (hawk, ((hawk_nde_xarg_t*)nde)->pos);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:29:58 +00:00
|
|
|
case HAWK_NDE_FUN:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk,
|
2024-05-02 13:47:30 +00:00
|
|
|
((hawk_nde_fun_t*)nde)->name.ptr,
|
2019-12-13 04:29:58 +00:00
|
|
|
((hawk_nde_fun_t*)nde)->name.len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_ARG:
|
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2];
|
2019-12-13 04:29:58 +00:00
|
|
|
hawk_oow_t n;
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->id.idxa != (hawk_oow_t)-1);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp));
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__p"));
|
|
|
|
PUT_SRCSTRN (hawk, tmp, n);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_ARGIDX:
|
|
|
|
{
|
|
|
|
hawk_oow_t n;
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->id.idxa != (hawk_oow_t)-1);
|
|
|
|
HAWK_ASSERT (px->idx != HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__p"));
|
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt));
|
|
|
|
PUT_SRCSTRN (hawk, hawk->tmp.fmt, n);
|
|
|
|
PRINT_EXPR_LIST_FOR_IDX (hawk, px->idx);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NAMED:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->id.idxa == (hawk_oow_t)-1);
|
|
|
|
HAWK_ASSERT (px->idx == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NAMEDIDX:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->id.idxa == (hawk_oow_t)-1);
|
|
|
|
HAWK_ASSERT (px->idx != HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
|
|
|
PRINT_EXPR_LIST_FOR_IDX (hawk, px->idx);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_GBL:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->id.idxa != (hawk_oow_t)-1)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
/* deparsing is global. so i can't honor hawk->parse.pragma.trait
|
2020-04-16 03:42:30 +00:00
|
|
|
* which can change in each input file. let me just check hawk->opt.trait */
|
2024-05-02 13:47:30 +00:00
|
|
|
if (!(hawk->opt.trait & HAWK_IMPLICIT))
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
/* no implicit(named) variable is allowed.
|
|
|
|
* use the actual name */
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
else if (px->id.idxa < hawk->tree.ngbls_base)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
/* static global variables */
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2];
|
2019-12-13 04:29:58 +00:00
|
|
|
hawk_oow_t n;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__g"));
|
2019-12-13 04:29:58 +00:00
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp));
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, tmp, n);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_GBLIDX:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->id.idxa != (hawk_oow_t)-1)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
/* deparsing is global. so i can't honor hawk->parse.pragma.trait
|
2020-04-16 03:42:30 +00:00
|
|
|
* which can change in each input file. let me just check hawk->opt.trait */
|
|
|
|
if (!(hawk->opt.trait & HAWK_IMPLICIT))
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
/* no implicit(named) variable is allowed.
|
|
|
|
* use the actual name */
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
else if (px->id.idxa < hawk->tree.ngbls_base)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
/* static global variables */
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2];
|
2019-12-13 04:29:58 +00:00
|
|
|
hawk_oow_t n;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__g"));
|
2019-12-13 04:29:58 +00:00
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp));
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, tmp, n);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx != HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR_LIST_FOR_IDX (hawk, px->idx);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-12 08:02:36 +00:00
|
|
|
|
2019-12-13 04:29:58 +00:00
|
|
|
case HAWK_NDE_LCL:
|
|
|
|
{
|
|
|
|
hawk_oow_t n;
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->id.idxa != (hawk_oow_t)-1)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__l"));
|
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt));
|
|
|
|
PUT_SRCSTRN (hawk, hawk->tmp.fmt, n);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_LCLIDX:
|
|
|
|
{
|
|
|
|
hawk_oow_t n;
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)nde;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->id.idxa != (hawk_oow_t)-1)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__l"));
|
|
|
|
n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt));
|
|
|
|
PUT_SRCSTRN (hawk, hawk->tmp.fmt, n);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx != HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR_LIST_FOR_IDX (hawk, px->idx);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_POS:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("$("));
|
|
|
|
PRINT_EXPR (hawk, ((hawk_nde_pos_t*)nde)->val);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_FNC:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)nde;
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->u.fnc.info.name.ptr, px->u.fnc.info.name.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR_LIST (hawk, px->args);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_FUN:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)nde;
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, px->u.fun.name.ptr, px->u.fun.name.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR_LIST (hawk, px->args);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_VAR:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)nde;
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, (hawk_nde_t*)px->u.var.var);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
|
|
|
PRINT_EXPR_LIST (hawk, px->args);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_GETLINE:
|
|
|
|
{
|
|
|
|
hawk_nde_getline_t* px = (hawk_nde_getline_t*)nde;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-11-10 02:56:29 +00:00
|
|
|
if (px->in && (px->in_type == HAWK_IN_PIPE || px->in_type == HAWK_IN_RWPIPE))
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->in);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PUT_SRCSTR (hawk, getline_inop_str[px->in_type]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, (px->mbs? HAWK_KWID_GETBLINE: HAWK_KWID_GETLINE), &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2020-11-10 02:56:29 +00:00
|
|
|
if (px->var)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR (hawk, px->var);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 02:56:29 +00:00
|
|
|
if (px->in && px->in_type == HAWK_IN_FILE)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PUT_SRCSTR (hawk, getline_inop_str[px->in_type]);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR (hawk, px->in);
|
2024-05-02 13:47:30 +00:00
|
|
|
}
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_PRINT:
|
|
|
|
case HAWK_NDE_PRINTF:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("("));
|
2020-11-10 02:56:29 +00:00
|
|
|
if (print_printx(hawk, (hawk_nde_print_t*)nde) <= -1) return -1;
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINTERN);
|
2019-12-13 04:29:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_expr_list (hawk_t* hawk, hawk_nde_t* tree)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_t* p = tree;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
while (p)
|
2020-03-30 08:54:37 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, p);
|
2020-03-30 08:54:37 +00:00
|
|
|
p = p->next;
|
2020-04-16 03:42:30 +00:00
|
|
|
if (p) PUT_SRCSTR (hawk, HAWK_T(","));
|
2020-03-30 08:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_expr_list_for_idx (hawk_t* hawk, hawk_nde_t* tree)
|
2020-03-30 08:54:37 +00:00
|
|
|
{
|
|
|
|
hawk_nde_t* p = tree;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("["));
|
2024-05-02 13:47:30 +00:00
|
|
|
while (p)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
p = p->next;
|
2024-05-02 13:47:30 +00:00
|
|
|
if (p)
|
2020-03-30 08:54:37 +00:00
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
if (p->type == HAWK_NDE_NULL)
|
2020-03-30 08:54:37 +00:00
|
|
|
{
|
|
|
|
/* the parser injects a HAWK_NDE_NULL node between the true multi-dimensional indices
|
|
|
|
* if the true multi-dimensional indices are enabled(i.e. HAWK_ENABLE_GC is defined)
|
|
|
|
* e.g. a[x][y][z]
|
|
|
|
* let me print this regardless of */
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("]["));
|
2020-03-30 08:54:37 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
else PUT_SRCSTR (hawk, HAWK_T(","));
|
2020-03-30 08:54:37 +00:00
|
|
|
}
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("]"));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_oow_t i;
|
|
|
|
hawk_oocs_t kw;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
switch (p->type)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
case HAWK_NDE_NULL:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_BLK:
|
|
|
|
{
|
|
|
|
hawk_oow_t n;
|
|
|
|
hawk_nde_blk_t* px = (hawk_nde_blk_t*)p;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("{"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->org_nlcls > 0)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_XLOCAL, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-11-12 08:02:36 +00:00
|
|
|
/* though the parser pushed up all local variables to the outer-most level,
|
|
|
|
* the code here restores the original declarations with org_nlcls and prv_nlcls */
|
2024-05-02 13:47:30 +00:00
|
|
|
for (i = 0; i < px->org_nlcls - 1; i++)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__l"));
|
2020-11-12 08:02:36 +00:00
|
|
|
n = hawk_int_to_oocstr(px->outer_nlcls + i, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt));
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, hawk->tmp.fmt, n);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(", "));
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("__l"));
|
2020-11-12 08:02:36 +00:00
|
|
|
n = hawk_int_to_oocstr(px->outer_nlcls + i, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt));
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTRN (hawk, hawk->tmp.fmt, n);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth + 1);
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T("}"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
case HAWK_NDE_IF:
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_if_t* px = (hawk_nde_if_t*)p;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_IF, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2024-05-02 13:47:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" ("));
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->test);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->then_part != HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
if (px->then_part->type == HAWK_NDE_BLK)
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->then_part, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
else
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->then_part, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->else_part != HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_ELSE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
if (px->else_part->type == HAWK_NDE_BLK)
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->else_part, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
else
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->else_part, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
case HAWK_NDE_WHILE:
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_while_t* px = (hawk_nde_while_t*)p;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_WHILE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" ("));
|
|
|
|
PRINT_EXPR (hawk, px->test);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
PUT_NL (hawk);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->body->type == HAWK_NDE_BLK)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
case HAWK_NDE_DOWHILE:
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_while_t* px = (hawk_nde_while_t*)p;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_DO, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_NL (hawk);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->body->type == HAWK_NDE_BLK)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_WHILE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" ("));
|
|
|
|
PRINT_EXPR (hawk, px->test);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(");"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FOR:
|
|
|
|
{
|
|
|
|
hawk_nde_for_t* px = (hawk_nde_for_t*)p;
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_FOR, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" ("));
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->init != HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->init);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("; "));
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->test != HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->test);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T("; "));
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->incr != HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->incr);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(")"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->body->type == HAWK_NDE_BLK)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:01:05 +00:00
|
|
|
case HAWK_NDE_FORIN:
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-03-22 18:01:05 +00:00
|
|
|
hawk_nde_forin_t* px = (hawk_nde_forin_t*)p;
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_FOR, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
PRINT_EXPR (hawk, px->test);
|
|
|
|
PUT_NL (hawk);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->body->type == HAWK_NDE_BLK)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_STMTS (hawk, px->body, depth + 1);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_BREAK:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_BREAK, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_CONTINUE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_CONTINUE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_RETURN:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
2024-05-02 13:47:30 +00:00
|
|
|
if (((hawk_nde_return_t*)p)->val == HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_RETURN, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_RETURN, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (((hawk_nde_return_t*)p)->val->next == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, ((hawk_nde_return_t*)p)->val);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXIT:
|
|
|
|
{
|
|
|
|
hawk_nde_exit_t* px = (hawk_nde_exit_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
if (px->val == HAWK_NULL)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, (px->abort? HAWK_KWID_XABORT: HAWK_KWID_EXIT), &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2024-05-02 13:47:30 +00:00
|
|
|
else
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, (px->abort? HAWK_KWID_XABORT: HAWK_KWID_EXIT), &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->val->next == HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_EXPR (hawk, px->val);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NEXT:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_NEXT, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NEXTFILE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
2019-12-13 04:29:58 +00:00
|
|
|
if (((hawk_nde_nextfile_t*)p)->out)
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_NEXTOFILE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_getkwname (hawk, HAWK_KWID_NEXTFILE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_DELETE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_DELETE, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
hawk_prnpt (hawk, ((hawk_nde_delete_t*)p)->var);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_RESET:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
hawk_getkwname (hawk, HAWK_KWID_XRESET, &kw);
|
|
|
|
PUT_SRCSTRN (hawk, kw.ptr, kw.len);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(" "));
|
|
|
|
hawk_prnpt (hawk, ((hawk_nde_reset_t*)p)->var);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_PRINT:
|
|
|
|
case HAWK_NDE_PRINTF:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
if (print_printx (hawk, (hawk_nde_print_t*)p) <= -1) return -1;
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
PRINT_TABS (hawk, depth);
|
|
|
|
PRINT_EXPR (hawk, p);
|
|
|
|
PUT_SRCSTR (hawk, HAWK_T(";"));
|
|
|
|
PUT_NL (hawk);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
static int print_stmts (hawk_t* hawk, hawk_nde_t* tree, int depth)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_t* p = tree;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
while (p)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-11-12 08:02:36 +00:00
|
|
|
if (print_stmt(hawk, p, depth) <= -1) return -1;
|
2019-12-13 04:29:58 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
int hawk_prnpt (hawk_t* hawk, hawk_nde_t* tree)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-11-08 17:23:25 +00:00
|
|
|
return print_stmts(hawk, tree, 0);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
int hawk_prnnde (hawk_t* hawk, hawk_nde_t* tree)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-11-08 17:23:25 +00:00
|
|
|
return print_stmt(hawk, tree, 0);
|
2019-12-13 04:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
int hawk_prnptnpt (hawk_t* hawk, hawk_nde_t* tree)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_t* nde = tree;
|
|
|
|
|
2020-11-08 17:23:25 +00:00
|
|
|
while (nde)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-11-12 08:02:36 +00:00
|
|
|
if (print_expr(hawk, nde) <= -1) return -1;
|
|
|
|
if (!nde->next) break;
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
PUT_SRCSTR (hawk, HAWK_T(","));
|
2019-12-13 04:29:58 +00:00
|
|
|
nde = nde->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
hawk_nde_t* p = tree;
|
|
|
|
hawk_nde_t* next;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
while (p)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
next = p->next;
|
|
|
|
|
2024-05-02 13:47:30 +00:00
|
|
|
switch (p->type)
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
|
|
|
case HAWK_NDE_NULL:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_BLK:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_blk_t*)p)->body);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_IF:
|
|
|
|
{
|
|
|
|
hawk_nde_if_t* px = (hawk_nde_if_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, px->test);
|
|
|
|
hawk_clrpt (hawk, px->then_part);
|
|
|
|
if (px->else_part) hawk_clrpt (hawk, px->else_part);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_WHILE:
|
|
|
|
case HAWK_NDE_DOWHILE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_while_t*)p)->test);
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_while_t*)p)->body);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FOR:
|
|
|
|
{
|
|
|
|
hawk_nde_for_t* px = (hawk_nde_for_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
if (px->init) hawk_clrpt (hawk, px->init);
|
|
|
|
if (px->test) hawk_clrpt (hawk, px->test);
|
|
|
|
if (px->incr) hawk_clrpt (hawk, px->incr);
|
|
|
|
hawk_clrpt (hawk, px->body);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:01:05 +00:00
|
|
|
case HAWK_NDE_FORIN:
|
2019-12-13 04:29:58 +00:00
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_forin_t*)p)->test);
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_forin_t*)p)->body);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_BREAK:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_CONTINUE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_RETURN:
|
|
|
|
{
|
|
|
|
hawk_nde_return_t* px = (hawk_nde_return_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
if (px->val) hawk_clrpt (hawk, px->val);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXIT:
|
|
|
|
{
|
2024-05-02 13:47:30 +00:00
|
|
|
if (((hawk_nde_exit_t*)p)->val != HAWK_NULL)
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_exit_t*)p)->val);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NEXT:
|
|
|
|
case HAWK_NDE_NEXTFILE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_DELETE:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_delete_t*)p)->var);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_RESET:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_reset_t*)p)->var);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_PRINT:
|
|
|
|
case HAWK_NDE_PRINTF:
|
|
|
|
{
|
|
|
|
hawk_nde_print_t* px = (hawk_nde_print_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
if (px->args) hawk_clrpt (hawk, px->args);
|
|
|
|
if (px->out) hawk_clrpt (hawk, px->out);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_GRP:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_grp_t*)p)->body);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_ASS:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_ass_t*)p)->left);
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_ass_t*)p)->right);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_BIN:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)p;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->left->next == HAWK_NULL);
|
|
|
|
HAWK_ASSERT (px->right->next == HAWK_NULL);
|
2019-12-13 04:29:58 +00:00
|
|
|
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, px->left);
|
|
|
|
hawk_clrpt (hawk, px->right);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_EXP_UNR:
|
|
|
|
case HAWK_NDE_EXP_INCPRE:
|
|
|
|
case HAWK_NDE_EXP_INCPST:
|
|
|
|
{
|
|
|
|
hawk_nde_exp_t* px = (hawk_nde_exp_t*)p;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->right == HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, px->left);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_CND:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_cnd_t*)p)->test);
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_cnd_t*)p)->left);
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_cnd_t*)p)->right);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-05 18:55:05 +00:00
|
|
|
case HAWK_NDE_CHAR:
|
2020-12-09 18:07:20 +00:00
|
|
|
case HAWK_NDE_BCHR:
|
2020-12-05 18:55:05 +00:00
|
|
|
{
|
|
|
|
hawk_freemem (hawk, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:29:58 +00:00
|
|
|
case HAWK_NDE_INT:
|
|
|
|
{
|
|
|
|
if (((hawk_nde_int_t*)p)->str)
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, ((hawk_nde_int_t*)p)->str);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FLT:
|
|
|
|
{
|
|
|
|
if (((hawk_nde_flt_t*)p)->str)
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, ((hawk_nde_flt_t*)p)->str);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_STR:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, ((hawk_nde_str_t*)p)->ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_MBS:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, ((hawk_nde_mbs_t*)p)->ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_REX:
|
|
|
|
{
|
|
|
|
hawk_nde_rex_t* rex = (hawk_nde_rex_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freerex (hawk, rex->code[0], rex->code[1]);
|
|
|
|
hawk_freemem (hawk, ((hawk_nde_rex_t*)p)->str.ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-10 02:56:29 +00:00
|
|
|
case HAWK_NDE_XNIL:
|
|
|
|
{
|
|
|
|
hawk_freemem (hawk, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:36:50 +00:00
|
|
|
case HAWK_NDE_XARG:
|
|
|
|
{
|
|
|
|
if (((hawk_nde_xarg_t*)p)->pos) /* pos is null for @argc */
|
|
|
|
hawk_clrpt (hawk, ((hawk_nde_xarg_t*)p)->pos);
|
|
|
|
hawk_freemem (hawk, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:29:58 +00:00
|
|
|
case HAWK_NDE_FUN:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, ((hawk_nde_fun_t*)p)->name.ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NAMED:
|
|
|
|
case HAWK_NDE_GBL:
|
|
|
|
case HAWK_NDE_LCL:
|
|
|
|
case HAWK_NDE_ARG:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)p;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx == HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
if (px->id.name.ptr) hawk_freemem (hawk, px->id.name.ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_NAMEDIDX:
|
|
|
|
case HAWK_NDE_GBLIDX:
|
|
|
|
case HAWK_NDE_LCLIDX:
|
|
|
|
case HAWK_NDE_ARGIDX:
|
|
|
|
{
|
|
|
|
hawk_nde_var_t* px = (hawk_nde_var_t*)p;
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (px->idx != HAWK_NULL);
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, px->idx);
|
|
|
|
if (px->id.name.ptr) hawk_freemem (hawk, px->id.name.ptr);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_POS:
|
|
|
|
{
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, ((hawk_nde_pos_t*)p)->val);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_FNC:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
/* hawk_freemem (hawk, px->u.fnc); */
|
|
|
|
hawk_freemem (hawk, px->u.fnc.info.name.ptr);
|
|
|
|
hawk_clrpt (hawk, px->args);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_FUN:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, px->u.fun.name.ptr);
|
|
|
|
hawk_clrpt (hawk, px->args);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_FNCALL_VAR:
|
|
|
|
{
|
|
|
|
hawk_nde_fncall_t* px = (hawk_nde_fncall_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_clrpt (hawk, (hawk_nde_t*)px->u.var.var);
|
|
|
|
hawk_clrpt (hawk, px->args);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HAWK_NDE_GETLINE:
|
|
|
|
{
|
|
|
|
hawk_nde_getline_t* px = (hawk_nde_getline_t*)p;
|
2020-04-16 03:42:30 +00:00
|
|
|
if (px->var) hawk_clrpt (hawk, px->var);
|
|
|
|
if (px->in) hawk_clrpt (hawk, px->in);
|
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-12-21 16:59:00 +00:00
|
|
|
HAWK_ASSERT (!"should never happen - invalid node type");
|
2020-04-16 03:42:30 +00:00
|
|
|
hawk_freemem (hawk, p);
|
2019-12-13 04:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = next;
|
|
|
|
}
|
|
|
|
}
|