fixed some issues in the awk tester
This commit is contained in:
parent
ad3e78f386
commit
f22b4894fd
@ -1685,9 +1685,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
|
|||||||
block = (qse_awk_nde_blk_t*)qse_awk_callocmem(awk, QSE_SIZEOF(*block));
|
block = (qse_awk_nde_blk_t*)qse_awk_callocmem(awk, QSE_SIZEOF(*block));
|
||||||
if (block == QSE_NULL)
|
if (block == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_arr_delete (
|
qse_arr_delete (awk->parse.lcls, nlcls, QSE_ARR_SIZE(awk->parse.lcls) - nlcls);
|
||||||
awk->parse.lcls, nlcls,
|
|
||||||
QSE_ARR_SIZE(awk->parse.lcls)-nlcls);
|
|
||||||
qse_awk_clrpt (awk, head);
|
qse_awk_clrpt (awk, head);
|
||||||
ADJERR_LOC (awk, xloc);
|
ADJERR_LOC (awk, xloc);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
@ -1725,8 +1723,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
|
|||||||
return (qse_awk_nde_t*)block;
|
return (qse_awk_nde_t*)block;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_awk_nde_t* parse_block_dc (
|
static qse_awk_nde_t* parse_block_dc (qse_awk_t* awk, const qse_awk_loc_t* xloc, int istop)
|
||||||
qse_awk_t* awk, const qse_awk_loc_t* xloc, int istop)
|
|
||||||
{
|
{
|
||||||
qse_awk_nde_t* nde;
|
qse_awk_nde_t* nde;
|
||||||
|
|
||||||
@ -1805,10 +1802,7 @@ static qse_size_t get_global (qse_awk_t* awk, const qse_cstr_t* name)
|
|||||||
for (i = QSE_ARR_SIZE(gbls); i > 0; )
|
for (i = QSE_ARR_SIZE(gbls); i > 0; )
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
|
if (qse_strxncmp(QSE_ARR_DPTR(gbls,i), QSE_ARR_DLEN(gbls,i), name->ptr, name->len) == 0) return i;
|
||||||
if (qse_strxncmp (
|
|
||||||
QSE_ARR_DPTR(gbls,i), QSE_ARR_DLEN(gbls,i),
|
|
||||||
name->ptr, name->len) == 0) return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSE_ARR_NIL;
|
return QSE_ARR_NIL;
|
||||||
@ -1821,17 +1815,13 @@ static qse_size_t find_global (qse_awk_t* awk, const qse_cstr_t* name)
|
|||||||
|
|
||||||
for (i = 0; i < QSE_ARR_SIZE(gbls); i++)
|
for (i = 0; i < QSE_ARR_SIZE(gbls); i++)
|
||||||
{
|
{
|
||||||
if (qse_strxncmp (
|
if (qse_strxncmp (QSE_ARR_DPTR(gbls,i), QSE_ARR_DLEN(gbls,i), name->ptr, name->len) == 0) return i;
|
||||||
QSE_ARR_DPTR(gbls,i), QSE_ARR_DLEN(gbls,i),
|
|
||||||
name->ptr, name->len) == 0) return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSE_ARR_NIL;
|
return QSE_ARR_NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_global (
|
static int add_global (qse_awk_t* awk, const qse_cstr_t* name, qse_awk_loc_t* xloc, int disabled)
|
||||||
qse_awk_t* awk, const qse_cstr_t* name,
|
|
||||||
qse_awk_loc_t* xloc, int disabled)
|
|
||||||
{
|
{
|
||||||
qse_size_t ngbls;
|
qse_size_t ngbls;
|
||||||
|
|
||||||
@ -1960,8 +1950,7 @@ int qse_awk_delgbl (qse_awk_t* awk, const qse_char_t* name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = qse_arr_search (awk->parse.gbls,
|
n = qse_arr_search(awk->parse.gbls, QSE_AWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
|
||||||
QSE_AWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
|
|
||||||
if (n == QSE_ARR_NIL)
|
if (n == QSE_ARR_NIL)
|
||||||
{
|
{
|
||||||
qse_awk_seterrnum (awk, QSE_AWK_ENOENT, &ncs);
|
qse_awk_seterrnum (awk, QSE_AWK_ENOENT, &ncs);
|
||||||
@ -1991,8 +1980,7 @@ int qse_awk_findgbl (qse_awk_t* awk, const qse_char_t* name)
|
|||||||
ncs.ptr = (qse_char_t*)name;
|
ncs.ptr = (qse_char_t*)name;
|
||||||
ncs.len = qse_strlen (name);
|
ncs.len = qse_strlen (name);
|
||||||
|
|
||||||
n = qse_arr_search (awk->parse.gbls,
|
n = qse_arr_search(awk->parse.gbls, QSE_AWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
|
||||||
QSE_AWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
|
|
||||||
if (n == QSE_ARR_NIL)
|
if (n == QSE_ARR_NIL)
|
||||||
{
|
{
|
||||||
qse_awk_seterrnum (awk, QSE_AWK_ENOENT, &ncs);
|
qse_awk_seterrnum (awk, QSE_AWK_ENOENT, &ncs);
|
||||||
@ -2020,9 +2008,7 @@ static qse_awk_t* collect_globals (qse_awk_t* awk)
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_global (
|
if (add_global(awk, QSE_STR_XSTR(awk->tok.name), &awk->tok.loc, 0) <= -1) return QSE_NULL;
|
||||||
awk, QSE_STR_XSTR(awk->tok.name),
|
|
||||||
&awk->tok.loc, 0) <= -1) return QSE_NULL;
|
|
||||||
|
|
||||||
if (get_token(awk) <= -1) return QSE_NULL;
|
if (get_token(awk) <= -1) return QSE_NULL;
|
||||||
|
|
||||||
@ -2056,8 +2042,7 @@ static qse_awk_t* collect_globals (qse_awk_t* awk)
|
|||||||
return awk;
|
return awk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_awk_t* collect_locals (
|
static qse_awk_t* collect_locals (qse_awk_t* awk, qse_size_t nlcls, int istop)
|
||||||
qse_awk_t* awk, qse_size_t nlcls, int istop)
|
|
||||||
{
|
{
|
||||||
if (MATCH(awk,TOK_NEWLINE))
|
if (MATCH(awk,TOK_NEWLINE))
|
||||||
{
|
{
|
||||||
@ -2084,9 +2069,7 @@ static qse_awk_t* collect_locals (
|
|||||||
* function f() { local length; } */
|
* function f() { local length; } */
|
||||||
if (qse_awk_findfnc (awk, &lcl) != QSE_NULL)
|
if (qse_awk_findfnc (awk, &lcl) != QSE_NULL)
|
||||||
{
|
{
|
||||||
SETERR_ARG_LOC (
|
SETERR_ARG_LOC (awk, QSE_AWK_EFNCRED, lcl.ptr, lcl.len, &awk->tok.loc);
|
||||||
awk, QSE_AWK_EFNCRED,
|
|
||||||
lcl.ptr, lcl.len, &awk->tok.loc);
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2095,13 +2078,10 @@ static qse_awk_t* collect_locals (
|
|||||||
/* check if it conflicts with a parameter name.
|
/* check if it conflicts with a parameter name.
|
||||||
* the first level declaration is treated as the same
|
* the first level declaration is treated as the same
|
||||||
* scope as the parameter list */
|
* scope as the parameter list */
|
||||||
n = qse_arr_search (
|
n = qse_arr_search(awk->parse.params, 0, lcl.ptr, lcl.len);
|
||||||
awk->parse.params, 0, lcl.ptr, lcl.len);
|
|
||||||
if (n != QSE_ARR_NIL)
|
if (n != QSE_ARR_NIL)
|
||||||
{
|
{
|
||||||
SETERR_ARG_LOC (
|
SETERR_ARG_LOC (awk, QSE_AWK_EPARRED, lcl.ptr, lcl.len, &awk->tok.loc);
|
||||||
awk, QSE_AWK_EPARRED,
|
|
||||||
lcl.ptr, lcl.len, &awk->tok.loc);
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2111,14 +2091,9 @@ static qse_awk_t* collect_locals (
|
|||||||
/* check if it conflicts with the owning function */
|
/* check if it conflicts with the owning function */
|
||||||
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
||||||
{
|
{
|
||||||
if (qse_strxncmp (
|
if (qse_strxncmp (lcl.ptr, lcl.len, awk->tree.cur_fun.ptr, awk->tree.cur_fun.len) == 0)
|
||||||
lcl.ptr, lcl.len,
|
|
||||||
awk->tree.cur_fun.ptr,
|
|
||||||
awk->tree.cur_fun.len) == 0)
|
|
||||||
{
|
{
|
||||||
SETERR_ARG_LOC (
|
SETERR_ARG_LOC (awk, QSE_AWK_EFUNRED, lcl.ptr, lcl.len, &awk->tok.loc);
|
||||||
awk, QSE_AWK_EFUNRED,
|
|
||||||
lcl.ptr, lcl.len, &awk->tok.loc);
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2128,9 +2103,7 @@ static qse_awk_t* collect_locals (
|
|||||||
n = qse_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len);
|
n = qse_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len);
|
||||||
if (n != QSE_ARR_NIL)
|
if (n != QSE_ARR_NIL)
|
||||||
{
|
{
|
||||||
SETERR_ARG_LOC (
|
SETERR_ARG_LOC (awk, QSE_AWK_EDUPLCL, lcl.ptr, lcl.len, &awk->tok.loc);
|
||||||
awk, QSE_AWK_EDUPLCL,
|
|
||||||
lcl.ptr, lcl.len, &awk->tok.loc);
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2142,9 +2115,7 @@ static qse_awk_t* collect_locals (
|
|||||||
{
|
{
|
||||||
/* it is a conflict only if it is one of a
|
/* it is a conflict only if it is one of a
|
||||||
* static global variable */
|
* static global variable */
|
||||||
SETERR_ARG_LOC (
|
SETERR_ARG_LOC (awk, QSE_AWK_EDUPLCL, lcl.ptr, lcl.len, &awk->tok.loc);
|
||||||
awk, QSE_AWK_EDUPLCL,
|
|
||||||
lcl.ptr, lcl.len, &awk->tok.loc);
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2155,10 +2126,7 @@ static qse_awk_t* collect_locals (
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qse_arr_insert (
|
if (qse_arr_insert (awk->parse.lcls, QSE_ARR_SIZE(awk->parse.lcls), lcl.ptr, lcl.len) == QSE_ARR_NIL)
|
||||||
awk->parse.lcls,
|
|
||||||
QSE_ARR_SIZE(awk->parse.lcls),
|
|
||||||
lcl.ptr, lcl.len) == QSE_ARR_NIL)
|
|
||||||
{
|
{
|
||||||
SETERR_LOC (awk, QSE_AWK_ENOMEM, &awk->tok.loc);
|
SETERR_LOC (awk, QSE_AWK_ENOMEM, &awk->tok.loc);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
@ -2242,7 +2210,6 @@ static qse_awk_nde_t* parse_if (qse_awk_t* awk, const qse_awk_loc_t* xloc)
|
|||||||
|
|
||||||
{
|
{
|
||||||
qse_awk_loc_t eloc;
|
qse_awk_loc_t eloc;
|
||||||
|
|
||||||
eloc = awk->tok.loc;
|
eloc = awk->tok.loc;
|
||||||
else_part = parse_statement(awk, &eloc);
|
else_part = parse_statement(awk, &eloc);
|
||||||
if (else_part == QSE_NULL) goto oops;
|
if (else_part == QSE_NULL) goto oops;
|
||||||
|
@ -123,7 +123,6 @@ static int run_pblocks (qse_awk_rtx_t* rtx);
|
|||||||
static int run_pblock_chain (qse_awk_rtx_t* rtx, qse_awk_chain_t* cha);
|
static int run_pblock_chain (qse_awk_rtx_t* rtx, qse_awk_chain_t* cha);
|
||||||
static int run_pblock (qse_awk_rtx_t* rtx, qse_awk_chain_t* cha, qse_size_t bno);
|
static int run_pblock (qse_awk_rtx_t* rtx, qse_awk_chain_t* cha, qse_size_t bno);
|
||||||
static int run_block (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde);
|
static int run_block (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde);
|
||||||
static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde);
|
|
||||||
static int run_statement (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde);
|
static int run_statement (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde);
|
||||||
static int run_if (qse_awk_rtx_t* rtx, qse_awk_nde_if_t* nde);
|
static int run_if (qse_awk_rtx_t* rtx, qse_awk_nde_if_t* nde);
|
||||||
static int run_while (qse_awk_rtx_t* rtx, qse_awk_nde_while_t* nde);
|
static int run_while (qse_awk_rtx_t* rtx, qse_awk_nde_while_t* nde);
|
||||||
@ -1808,25 +1807,7 @@ static int run_pblock (qse_awk_rtx_t* rtx, qse_awk_chain_t* cha, qse_size_t bno)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_block (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
static QSE_INLINE int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (rtx->awk->opt.depth.s.block_run > 0 &&
|
|
||||||
rtx->depth.block >= rtx->awk->opt.depth.s.block_run)
|
|
||||||
{
|
|
||||||
SETERR_LOC (rtx, QSE_AWK_EBLKNST, &nde->loc);
|
|
||||||
return -1;;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtx->depth.block++;
|
|
||||||
n = run_block0(rtx, nde);
|
|
||||||
rtx->depth.block--;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
|
||||||
{
|
{
|
||||||
qse_awk_nde_t* p;
|
qse_awk_nde_t* p;
|
||||||
qse_size_t nlcls;
|
qse_size_t nlcls;
|
||||||
@ -1914,6 +1895,24 @@ static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int run_block (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (rtx->awk->opt.depth.s.block_run > 0 &&
|
||||||
|
rtx->depth.block >= rtx->awk->opt.depth.s.block_run)
|
||||||
|
{
|
||||||
|
SETERR_LOC (rtx, QSE_AWK_EBLKNST, &nde->loc);
|
||||||
|
return -1;;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtx->depth.block++;
|
||||||
|
n = run_block0(rtx, nde);
|
||||||
|
rtx->depth.block--;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
#define ON_STATEMENT(rtx,nde) QSE_BLOCK ( \
|
#define ON_STATEMENT(rtx,nde) QSE_BLOCK ( \
|
||||||
qse_awk_rtx_ecb_t* ecb; \
|
qse_awk_rtx_ecb_t* ecb; \
|
||||||
if ((rtx)->awk->stopall) (rtx)->exit_level = EXIT_ABORT; \
|
if ((rtx)->awk->stopall) (rtx)->exit_level = EXIT_ABORT; \
|
||||||
|
@ -574,7 +574,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
|
|
||||||
if (px->id.idxa != (qse_size_t)-1)
|
if (px->id.idxa != (qse_size_t)-1)
|
||||||
{
|
{
|
||||||
/* deparsing is global. so i can't honor awk->parse.pragmas
|
/* deparsing is global. so i can't honor awk->parse.pragma.trait
|
||||||
* which can change in each input file. let me just check awk->opt.trait */
|
* which can change in each input file. let me just check awk->opt.trait */
|
||||||
if (!(awk->opt.trait & QSE_AWK_IMPLICIT))
|
if (!(awk->opt.trait & QSE_AWK_IMPLICIT))
|
||||||
{
|
{
|
||||||
@ -617,7 +617,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
|
|
||||||
if (px->id.idxa != (qse_size_t)-1)
|
if (px->id.idxa != (qse_size_t)-1)
|
||||||
{
|
{
|
||||||
/* deparsing is global. so i can't honor awk->parse.pragmas
|
/* deparsing is global. so i can't honor awk->parse.pragma.trait
|
||||||
* which can change in each input file. let me just check awk->opt.trait */
|
* which can change in each input file. let me just check awk->opt.trait */
|
||||||
if (!(awk->opt.trait & QSE_AWK_IMPLICIT))
|
if (!(awk->opt.trait & QSE_AWK_IMPLICIT))
|
||||||
{
|
{
|
||||||
|
@ -220,6 +220,8 @@ run_scripts()
|
|||||||
extraopts="${2}"
|
extraopts="${2}"
|
||||||
echo "${PROGS}" > "${TMPFILE}"
|
echo "${PROGS}" > "${TMPFILE}"
|
||||||
|
|
||||||
|
curdir="`pwd`"
|
||||||
|
|
||||||
while read prog
|
while read prog
|
||||||
do
|
do
|
||||||
[ -z "${prog}" ] && continue
|
[ -z "${prog}" ] && continue
|
||||||
@ -233,27 +235,40 @@ run_scripts()
|
|||||||
[ -z "${script}" ] && continue
|
[ -z "${script}" ] && continue
|
||||||
|
|
||||||
script_path="@abs_srcdir@/${script}"
|
script_path="@abs_srcdir@/${script}"
|
||||||
datafile_path="@abs_srcdir@/${datafile}"
|
script_dp_path="@abs_builddir@/${script}.dp"
|
||||||
readinfile_path="@abs_srcdir@/${readinfile}"
|
readinfile_path="@abs_srcdir@/${readinfile}"
|
||||||
|
datafile_path=""
|
||||||
|
[ -n "${datafile}" ] && {
|
||||||
|
for i in ${datafile}
|
||||||
|
do
|
||||||
|
[ -f "@abs_srcdir@/${i}" ] && datafile_path="${datafile_path} @abs_srcdir@/${i}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
[ -f "${script}".dp ] && script="${script}.dp"
|
[ -f "${script_path}" ] || {
|
||||||
[ -f "${script_path}" ] ||
|
|
||||||
{
|
|
||||||
echo_so "${script} not found"
|
echo_so "${script} not found"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -z "${readinfile}" ] &&
|
[ -z "${readinfile}" ] && {
|
||||||
{
|
|
||||||
readinfile="/dev/stdin"
|
readinfile="/dev/stdin"
|
||||||
readinfile_path="/dev/stdin"
|
readinfile_path="/dev/stdin"
|
||||||
}
|
}
|
||||||
|
|
||||||
# if the datafile does not exist, let's not use the original name
|
|
||||||
[ -f "${datafile_path}" ] || datafile_path="$datafile"
|
|
||||||
|
|
||||||
echo_title "${valgrind} ${QSEAWK_BASENAME} ${extraopts} ${awkopts} -f ${orgscript} ${datafile} <${readinfile} 2>&1"
|
echo_title "${valgrind} ${QSEAWK_BASENAME} ${extraopts} ${awkopts} -f ${orgscript} ${datafile} <${readinfile} 2>&1"
|
||||||
${valgrind} ${QSEAWK} ${extraopts} -d "${script}.dp" ${awkopts} -f ${script_path} ${datafile_path} <${readinfile_path} 2>&1
|
|
||||||
|
if [ -f "${script_dp_path}" ]
|
||||||
|
then
|
||||||
|
# run the deparsed script
|
||||||
|
cd "`dirname ${script_dp_path}`"
|
||||||
|
${valgrind} ${QSEAWK} ${extraopts} ${awkopts} -f "`basename ${script_dp_path}`" ${datafile_path} <${readinfile_path} 2>&1
|
||||||
|
cd "$curdir"
|
||||||
|
else
|
||||||
|
# run the orignal script
|
||||||
|
cd "`dirname ${script_path}`"
|
||||||
|
${valgrind} ${QSEAWK} ${extraopts} -d "${script_dp_path}" ${awkopts} -f "`basename ${script_path}`" ${datafile_path} <${readinfile_path} 2>&1
|
||||||
|
cd "$curdir"
|
||||||
|
fi
|
||||||
|
|
||||||
done < "${TMPFILE}"
|
done < "${TMPFILE}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user