better error information handling in parse.c

This commit is contained in:
hyung-hwan 2020-01-03 10:22:23 +00:00
parent c64364ecb1
commit 01464d1fb1
9 changed files with 102 additions and 73 deletions

View File

@ -167,8 +167,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \ $(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \ $(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing ac/ar-lib \ $(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing ac/ar-lib \
ac/compile ac/config.guess ac/config.sub ac/install-sh \ ac/compile ac/config.guess ac/config.sub ac/depcomp \
ac/ltmain.sh ac/missing ac/install-sh ac/ltmain.sh ac/missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION) distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir) top_distdir = $(distdir)

2
hawk/configure vendored
View File

@ -18841,7 +18841,7 @@ _ACEOF
fi fi
done done
for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r random_r random for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r initstate_r srandom_r random_r random
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@ -205,7 +205,7 @@ AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep select]) AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep select])
AC_CHECK_FUNCS([sigaction signal getpgid getpgrp]) AC_CHECK_FUNCS([sigaction signal getpgid getpgrp])
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r random_r random]) AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r initstate_r srandom_r random_r random])
AC_CHECK_FUNCS([accept4 pipe2 epoll_create epoll_create1 kqueue kqueue1]) AC_CHECK_FUNCS([accept4 pipe2 epoll_create epoll_create1 kqueue kqueue1])
AC_CHECK_FUNCS([isatty mmap munmap]) AC_CHECK_FUNCS([isatty mmap munmap])
AC_CHECK_FUNCS([readdir64 dirfd faccessat]) AC_CHECK_FUNCS([readdir64 dirfd faccessat])

View File

@ -82,25 +82,25 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("comma expected in place of '${0}'"), HAWK_T("comma expected in place of '${0}'"),
HAWK_T("semicolon expected in place of '${0}'"), HAWK_T("semicolon expected in place of '${0}'"),
HAWK_T("colon expected in place of '${0}'"), HAWK_T("colon expected in place of '${0}'"),
HAWK_T("integer literal expected in place of '${0}'"), HAWK_T("integer literal expected"),
HAWK_T("statement not ending with a semicolon"), HAWK_T("statement not ending with a semicolon"),
HAWK_T("keyword 'in' expected in place of '${0}'"), HAWK_T("keyword 'in' expected in place of '${0}'"),
HAWK_T("right-hand side of 'in' not a variable"), HAWK_T("right-hand side of 'in' not a variable"),
HAWK_T("expression not recognized around"), HAWK_T("expression not recognized"),
HAWK_T("keyword 'function' expected in place of '${0}'"), HAWK_T("keyword 'function' expected"),
HAWK_T("keyword 'while' expected in place of '${0}'"), HAWK_T("keyword 'while' expected in place of '${0}'"),
HAWK_T("invalid assignment statement"), HAWK_T("invalid assignment statement"),
HAWK_T("identifier expected in place of '${0}'"), HAWK_T("identifier expected in place of '${0}'"),
HAWK_T("'${0}' not a valid function name"), HAWK_T("'${0}' not a valid function name"),
HAWK_T("BEGIN not followed by left bracket on the same line"), HAWK_T("BEGIN not followed by left bracket on the same line"),
HAWK_T("END not followed by left bracket on the same line"), HAWK_T("END not followed by left bracket on the same line"),
HAWK_T("keyword '${0}' redefined"), HAWK_T("keyword redefined"),
HAWK_T("intrinsic function '${0}' redefined"), HAWK_T("intrinsic function redefined"),
HAWK_T("function '${0}' redefined"), HAWK_T("function redefined"),
HAWK_T("global variable '${0}' redefined"), HAWK_T("global variable redefined"),
HAWK_T("parameter '${0}' redefined"), HAWK_T("parameter redefined"),
HAWK_T("variable '${0}' redefined"), HAWK_T("variable redefined"),
HAWK_T("duplicate parameter name '${0}'"), HAWK_T("duplicate parameter name '${0}'"),
HAWK_T("duplicate global variable '${0}'"), HAWK_T("duplicate global variable '${0}'"),
HAWK_T("duplicate local variable"), HAWK_T("duplicate local variable"),

View File

@ -226,6 +226,9 @@
/* Define to 1 if you have the `gmtime_r' function. */ /* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R #undef HAVE_GMTIME_R
/* Define to 1 if you have the `initstate_r' function. */
#undef HAVE_INITSTATE_R
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H #undef HAVE_INTTYPES_H
@ -442,6 +445,9 @@
/* Define to 1 if you have the `sqrtq' function. */ /* Define to 1 if you have the `sqrtq' function. */
#undef HAVE_SQRTQ #undef HAVE_SQRTQ
/* Define to 1 if you have the `srandom_r' function. */
#undef HAVE_SRANDOM_R
/* Define to 1 if you have the `stat64' function. */ /* Define to 1 if you have the `stat64' function. */
#undef HAVE_STAT64 #undef HAVE_STAT64

View File

@ -812,9 +812,9 @@ enum hawk_errnum_t
HAWK_ECOMMA, /**< comma expected in place of '${0}' */ HAWK_ECOMMA, /**< comma expected in place of '${0}' */
HAWK_ESCOLON, /**< semicolon expected in place of '${0}' */ HAWK_ESCOLON, /**< semicolon expected in place of '${0}' */
HAWK_ECOLON, /**< colon expected in place of '${0}' */ HAWK_ECOLON, /**< colon expected in place of '${0}' */
HAWK_EINTLIT, /**< integer literal expected in place of '${0}' */ HAWK_EINTLIT, /**< integer literal expected */
HAWK_ESTMEND, /**< statement not ending with a semicolon */ HAWK_ESTMEND, /**< statement not ending with a semicolon */
HAWK_EKWIN, /**< keyword 'in' expected in place of '${0}' */ HAWK_EKWIN, /**< keyword 'in' expected */
HAWK_ENOTVAR, /**< right-hand side of 'in' not a variable */ HAWK_ENOTVAR, /**< right-hand side of 'in' not a variable */
HAWK_EEXPRNR, /**< expression not recognized */ HAWK_EEXPRNR, /**< expression not recognized */
@ -825,12 +825,12 @@ enum hawk_errnum_t
HAWK_EFUNNAM, /**< '${0}' not a valid function name */ HAWK_EFUNNAM, /**< '${0}' not a valid function name */
HAWK_EBLKBEG, /**< BEGIN not followed by left bracket on the same line */ HAWK_EBLKBEG, /**< BEGIN not followed by left bracket on the same line */
HAWK_EBLKEND, /**< END not followed by left bracket on the same line */ HAWK_EBLKEND, /**< END not followed by left bracket on the same line */
HAWK_EKWRED, /**< keyword '${0}' redefined */ HAWK_EKWRED, /**< keyword redefined */
HAWK_EFNCRED, /**< intrinsic function '${0}' redefined */ HAWK_EFNCRED, /**< intrinsic function redefined */
HAWK_EFUNRED, /**< function '${0}' redefined */ HAWK_EFUNRED, /**< function redefined */
HAWK_EGBLRED, /**< global variable '${0}' redefined */ HAWK_EGBLRED, /**< global variable redefined */
HAWK_EPARRED, /**< parameter '${0}' redefined */ HAWK_EPARRED, /**< parameter redefined */
HAWK_EVARRED, /**< variable '${0}' redefined */ HAWK_EVARRED, /**< variable redefined */
HAWK_EDUPPAR, /**< duplicate parameter name '${0}' */ HAWK_EDUPPAR, /**< duplicate parameter name '${0}' */
HAWK_EDUPGBL, /**< duplicate global variable name '${0}' */ HAWK_EDUPGBL, /**< duplicate global variable name '${0}' */
HAWK_EDUPLCL, /**< duplicate local variable name '${0}' */ HAWK_EDUPLCL, /**< duplicate local variable name '${0}' */

View File

@ -60,12 +60,12 @@
# define HAVE_SQRT # define HAVE_SQRT
# endif # endif
#endif #endif
typedef struct modctx_t typedef struct modctx_t
{ {
unsigned int seed; unsigned int seed;
#if defined(HAVE_RANDOM_R) #if defined(HAVE_INITSTATE_R) && defined(HAVE_SRANDOM_R) && defined(HAVE_RANDOM_R)
struct random_data prand; struct random_data prand;
hawk_uint8_t prand_bin[256];
#endif #endif
} modctx_t; } modctx_t;
@ -536,7 +536,7 @@ static int fnc_rand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
modctx_t* modctx; modctx_t* modctx;
modctx = (modctx_t*)fi->mod->ctx; modctx = (modctx_t*)fi->mod->ctx;
#if defined(HAVE_RANDOM_R) #if defined(HAVE_INITSTATE_R) && defined(HAVE_SRANDOM_R) && defined(HAVE_RANDOM_R)
random_r (&modctx->prand, &randv); random_r (&modctx->prand, &randv);
#elif defined(HAVE_RANDOM) #elif defined(HAVE_RANDOM)
randv = random(); randv = random();
@ -573,7 +573,7 @@ static int fnc_srand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
hawk_ntime_t tv; hawk_ntime_t tv;
hawk_get_time (&tv); hawk_get_time (&tv);
modctx->seed = tv.sec + tv.nsec; modctx->seed = tv.sec + tv.nsec;
#if defined(HAVE_RANDOM_R) #if defined(HAVE_INITSTATE_R) && defined(HAVE_SRANDOM_R) && defined(HAVE_RANDOM_R)
srandom_r (modctx->seed, &modctx->prand); srandom_r (modctx->seed, &modctx->prand);
#elif defined(HAVE_RANDOM) #elif defined(HAVE_RANDOM)
srandom (modctx->seed); srandom (modctx->seed);
@ -586,7 +586,7 @@ static int fnc_srand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
a0 = hawk_rtx_getarg(rtx, 0); a0 = hawk_rtx_getarg(rtx, 0);
n = hawk_rtx_valtoint(rtx, a0, &lv); n = hawk_rtx_valtoint(rtx, a0, &lv);
if (n <= -1) return -1; if (n <= -1) return -1;
#if defined(HAVE_RANDOM_R) #if defined(HAVE_INITSTATE_R) && defined(HAVE_SRANDOM_R) && defined(HAVE_RANDOM_R)
srandom_r (lv, &modctx->prand); srandom_r (lv, &modctx->prand);
#elif defined(HAVE_RANDOM) #elif defined(HAVE_RANDOM)
srandom (lv); srandom (lv);
@ -714,7 +714,8 @@ int hawk_mod_math (hawk_mod_t* mod, hawk_t* awk)
hawk_get_time (&tv); hawk_get_time (&tv);
modctx->seed = tv.sec + tv.nsec; modctx->seed = tv.sec + tv.nsec;
#if defined(HAVE_RANDOM_R) #if defined(HAVE_INITSTATE_R) && defined(HAVE_SRANDOM_R) && defined(HAVE_RANDOM_R)
initstate_r (0, &modctx->prand_bin, HAWK_SIZEOF(&modctx->prand_bin), &modctx->prand);
srandom_r (modctx->seed, &modctx->prand); srandom_r (modctx->seed, &modctx->prand);
#elif defined(HAVE_RANDOM) #elif defined(HAVE_RANDOM)
srandom (modctx->seed); srandom (modctx->seed);

View File

@ -796,20 +796,13 @@ static int record_ever_included (hawk_t* awk, hawk_sio_arg_t* arg)
static int begin_include (hawk_t* awk, int once) static int begin_include (hawk_t* awk, int once)
{ {
hawk_sio_arg_t* arg = HAWK_NULL; hawk_sio_arg_t* arg = HAWK_NULL;
hawk_link_t* link;
hawk_ooch_t* sio_name; hawk_ooch_t* sio_name;
if (hawk_count_oocstr(HAWK_OOECS_PTR(awk->tok.name)) != HAWK_OOECS_LEN(awk->tok.name)) if (hawk_count_oocstr(HAWK_OOECS_PTR(awk->tok.name)) != HAWK_OOECS_LEN(awk->tok.name))
{ {
/* a '\0' character included in the include file name. /* a '\0' character included in the include file name.
* we don't support such a file name */ * we don't support such a file name */
SETERR_ARG_LOC ( hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EIONMNL, HAWK_T("invalid I/O name of length %zu containing '\\0'"), HAWK_OOECS_LEN(awk->tok.name));
awk,
HAWK_EIONMNL,
HAWK_OOECS_PTR(awk->tok.name),
hawk_count_oocstr(HAWK_OOECS_PTR(awk->tok.name)),
&awk->tok.loc
);
return -1; return -1;
} }
@ -1000,7 +993,7 @@ static int parse_progunit (hawk_t* awk)
if (get_token(awk) <= -1) return -1; if (get_token(awk) <= -1) return -1;
if (!MATCH(awk, TOK_INT)) if (!MATCH(awk, TOK_INT))
{ {
SETERR_TOK (awk, HAWK_EINTLIT); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EINTLIT, HAWK_T("integer literal expected in place of '%.*js'"), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return -1; return -1;
} }
@ -1027,9 +1020,9 @@ static int parse_progunit (hawk_t* awk)
} }
else if (MATCH(awk, TOK_BEGIN)) else if (MATCH(awk, TOK_BEGIN))
{ {
if ((awk->opt.trait & HAWK_PABLOCK) == 0) if (!(awk->opt.trait & HAWK_PABLOCK)) /* pattern action block not allowed */
{ {
SETERR_TOK (awk, HAWK_EKWFNC); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EKWFNC, HAWK_T("keyword 'function' expected in place of '%.*js'"), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return -1; return -1;
} }
@ -1058,9 +1051,9 @@ static int parse_progunit (hawk_t* awk)
} }
else if (MATCH(awk, TOK_END)) else if (MATCH(awk, TOK_END))
{ {
if ((awk->opt.trait & HAWK_PABLOCK) == 0) if (!(awk->opt.trait & HAWK_PABLOCK))
{ {
SETERR_TOK (awk, HAWK_EKWFNC); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EKWFNC, HAWK_T("keyword 'function' expected in place of '%.*js'"), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return -1; return -1;
} }
@ -1090,9 +1083,9 @@ static int parse_progunit (hawk_t* awk)
else if (MATCH(awk, TOK_LBRACE)) else if (MATCH(awk, TOK_LBRACE))
{ {
/* patternless block */ /* patternless block */
if ((awk->opt.trait & HAWK_PABLOCK) == 0) if (!(awk->opt.trait & HAWK_PABLOCK))
{ {
SETERR_TOK (awk, HAWK_EKWFNC); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EKWFNC, HAWK_T("keyword 'function' expected in place of '%.*js'"), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return -1; return -1;
} }
@ -1116,9 +1109,9 @@ static int parse_progunit (hawk_t* awk)
hawk_nde_t* ptn; hawk_nde_t* ptn;
hawk_loc_t eloc; hawk_loc_t eloc;
if ((awk->opt.trait & HAWK_PABLOCK) == 0) if (!(awk->opt.trait & HAWK_PABLOCK))
{ {
SETERR_TOK (awk, HAWK_EKWFNC); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EKWFNC, HAWK_T("keyword 'function' expected in place of '%.*js'"), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return -1; return -1;
} }
@ -1222,6 +1215,7 @@ static hawk_nde_t* parse_function (hawk_t* awk)
hawk_htb_pair_t* pair; hawk_htb_pair_t* pair;
hawk_loc_t xloc; hawk_loc_t xloc;
int rederr; int rederr;
const hawk_ooch_t* redobj;
/* eat up the keyword 'function' and get the next token */ /* eat up the keyword 'function' and get the next token */
HAWK_ASSERT (MATCH(awk,TOK_FUNCTION)); HAWK_ASSERT (MATCH(awk,TOK_FUNCTION));
@ -1241,15 +1235,15 @@ static hawk_nde_t* parse_function (hawk_t* awk)
/* note that i'm assigning to rederr in the 'if' conditions below. /* note that i'm assigning to rederr in the 'if' conditions below.
* i'm not checking equality */ * i'm not checking equality */
/* check if it is a builtin function */ /* check if it is a builtin function */
if ((hawk_findfncwithoocs(awk, &name) != HAWK_NULL && (rederr = HAWK_EFNCRED)) || if ((hawk_findfncwithoocs(awk, &name) != HAWK_NULL && (rederr = HAWK_EFNCRED, redobj = HAWK_T("intrinsic function"))) ||
/* check if it has already been defined as a function */ /* check if it has already been defined as a function */
(hawk_htb_search(awk->tree.funs, name.ptr, name.len) != HAWK_NULL && (rederr = HAWK_EFUNRED)) || (hawk_htb_search(awk->tree.funs, name.ptr, name.len) != HAWK_NULL && (rederr = HAWK_EFUNRED, redobj = HAWK_T("function"))) ||
/* check if it conflicts with a named variable */ /* check if it conflicts with a named variable */
(hawk_htb_search(awk->parse.named, name.ptr, name.len) != HAWK_NULL && (rederr = HAWK_EVARRED)) || (hawk_htb_search(awk->parse.named, name.ptr, name.len) != HAWK_NULL && (rederr = HAWK_EVARRED, redobj = HAWK_T("variable"))) ||
/* check if it coincides to be a global variable name */ /* check if it coincides to be a global variable name */
(((g = find_global (awk, &name)) != HAWK_ARR_NIL) && (rederr = HAWK_EGBLRED))) (((g = find_global (awk, &name)) != HAWK_ARR_NIL) && (rederr = HAWK_EGBLRED, redobj = HAWK_T("global variable"))))
{ {
hawk_seterror (awk, rederr, &name, &awk->tok.loc); hawk_seterrfmt (awk, &awk->tok.loc, rederr, HAWK_T("%js '%.*js' redefined"), redobj, HAWK_OOECS_LEN(awk->tok.name), HAWK_OOECS_PTR(awk->tok.name));
return HAWK_NULL; return HAWK_NULL;
} }
@ -1839,29 +1833,23 @@ static int add_global (hawk_t* awk, const hawk_oocs_t* name, hawk_loc_t* xloc, i
/* check if it is a keyword */ /* check if it is a keyword */
if (classify_ident(awk, name) != TOK_IDENT) if (classify_ident(awk, name) != TOK_IDENT)
{ {
SETERR_ARG_LOC (awk, HAWK_EKWRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EKWRED, HAWK_T("keyword '%.*js' redefined"), name->len, name->ptr);
return -1; return -1;
} }
/* check if it conflicts with a builtin function name */ /* check if it conflicts with a builtin function name */
if (hawk_findfncwithoocs(awk, name) != HAWK_NULL) if (hawk_findfncwithoocs(awk, name) != HAWK_NULL)
{ {
SETERR_ARG_LOC (awk, HAWK_EFNCRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EFNCRED, HAWK_T("intrinsic function '%.*js' redefined"), name->len, name->ptr);
return -1; return -1;
} }
/* check if it conflicts with a function name */ /* check if it conflicts with a function name */
if (hawk_htb_search(awk->tree.funs, name->ptr, name->len) != HAWK_NULL) if (hawk_htb_search(awk->tree.funs, name->ptr, name->len) != HAWK_NULL ||
/* check if it conflicts with a function name caught in the function call table */
hawk_htb_search(awk->parse.funs, name->ptr, name->len) != HAWK_NULL)
{ {
SETERR_ARG_LOC (awk, HAWK_EFUNRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EFUNRED, HAWK_T("function '%.*js' redefined"), name->len, name->ptr);
return -1;
}
/* check if it conflicts with a function name
* caught in the function call table */
if (hawk_htb_search(awk->parse.funs, name->ptr, name->len) != HAWK_NULL)
{
SETERR_ARG_LOC (awk, HAWK_EFUNRED, name->ptr, name->len, xloc);
return -1; return -1;
} }
@ -1876,12 +1864,12 @@ static int add_global (hawk_t* awk, const hawk_oocs_t* name, hawk_loc_t* xloc, i
/* TODO: need to check if it conflicts with a named variable to /* TODO: need to check if it conflicts with a named variable to
* disallow such a program shown below (IMPLICIT & EXPLICIT on) * disallow such a program shown below (IMPLICIT & EXPLICIT on)
* BEGIN {X=20; x(); x(); x(); print X} * BEGIN {X=20; x(); x(); x(); print X}
* global X; * @global X;
* function x() { print X++; } * function x() { print X++; }
*/ */
if (hawk_htb_search(awk->parse.named, name, len) != HAWK_NULL) if (hawk_htb_search(awk->parse.named, name, len) != HAWK_NULL)
{ {
SETERR_ARG_LOC (awk, HAWK_EVARRED, name, len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EVARRED, HAWK_T("variable '%.*js' redefined"), len, name);
return -1; return -1;
} }
#endif #endif
@ -2239,7 +2227,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
* function f() { local length; } */ * function f() { local length; } */
if (hawk_findfncwithoocs(awk, &lcl) != HAWK_NULL) if (hawk_findfncwithoocs(awk, &lcl) != HAWK_NULL)
{ {
SETERR_ARG_LOC (awk, HAWK_EFNCRED, lcl.ptr, lcl.len, &awk->tok.loc); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EFNCRED, HAWK_T("intrinsic function '%.*js' redefined"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
@ -2251,7 +2239,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
n = hawk_arr_search(awk->parse.params, 0, lcl.ptr, lcl.len); n = hawk_arr_search(awk->parse.params, 0, lcl.ptr, lcl.len);
if (n != HAWK_ARR_NIL) if (n != HAWK_ARR_NIL)
{ {
SETERR_ARG_LOC (awk, HAWK_EPARRED, lcl.ptr, lcl.len, &awk->tok.loc); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EPARRED, HAWK_T("parameter '%.*js' redefined"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
} }
@ -2263,7 +2251,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
{ {
if (hawk_comp_oochars(lcl.ptr, lcl.len, awk->tree.cur_fun.ptr, awk->tree.cur_fun.len, 0) == 0) if (hawk_comp_oochars(lcl.ptr, lcl.len, awk->tree.cur_fun.ptr, awk->tree.cur_fun.len, 0) == 0)
{ {
SETERR_ARG_LOC (awk, HAWK_EFUNRED, lcl.ptr, lcl.len, &awk->tok.loc); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EFUNRED, HAWK_T("function '%.*js' redefined"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
} }
@ -2283,8 +2271,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
{ {
if (n < awk->tree.ngbls_base) if (n < awk->tree.ngbls_base)
{ {
/* 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 */
hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, HAWK_T("duplicate local variable - %.*js"), lcl.len, lcl.ptr); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, HAWK_T("duplicate local variable - %.*js"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
@ -5295,11 +5282,11 @@ static hawk_nde_t* parse_primary_ident_noseg (hawk_t* awk, const hawk_loc_t* xlo
} }
else else
{ {
/* function name appeared without () */ /* function name appeared without (). used as a value without invocation */
#if defined(ENABLE_FEATURE_FUN_AS_VALUE) #if defined(ENABLE_FEATURE_FUN_AS_VALUE)
nde = parse_fun_as_value(awk, name, xloc, funptr); nde = parse_fun_as_value(awk, name, xloc, funptr);
#else #else
SETERR_ARG_LOC (awk, HAWK_EFUNRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EFUNRED, HAWK_T("function '%.*js' redefined"), name->len, name->ptr);
#endif #endif
} }
} }
@ -5329,7 +5316,7 @@ static hawk_nde_t* parse_primary_ident_noseg (hawk_t* awk, const hawk_loc_t* xlo
is_fncall_var = 1; is_fncall_var = 1;
goto named_var; goto named_var;
#else #else
SETERR_ARG_LOC (awk, HAWK_EVARRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EVARRED, HAWK_T("variable '%.*js' redefined"), name->len, name->ptr);
#endif #endif
} }
else else
@ -5630,11 +5617,11 @@ static hawk_nde_t* parse_hashidx (hawk_t* awk, const hawk_oocs_t* name, const ha
switch (fnname) switch (fnname)
{ {
case FNTYPE_FNC: case FNTYPE_FNC:
SETERR_ARG_LOC (awk, HAWK_EFNCRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EFNCRED, HAWK_T("intrinsic function '%.*js' redefined"), name->len, name->ptr);
goto exit_func; goto exit_func;
case FNTYPE_FUN: case FNTYPE_FUN:
SETERR_ARG_LOC (awk, HAWK_EFUNRED, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EFUNRED, HAWK_T("function '%.*js' redefined"), name->len, name->ptr);
goto exit_func; goto exit_func;
} }

View File

@ -78,3 +78,38 @@ HAWK_ELXDIG -> ERROR: CODE 32 LINE 1 COLUMN 15 - invalid digit '9'
$ hawk 'BEGIN { + $ hawk 'BEGIN { +
> }' > }'
HAWK_EEXPRNR -> ERROR: CODE 49 LINE 1 COLUMN 9 - expression not recognized around '+' HAWK_EEXPRNR -> ERROR: CODE 49 LINE 1 COLUMN 9 - expression not recognized around '+'
$ ~/xxx/bin/hawk '@pragma stack_limit "99"; BEGIN { }'
HAWK_EINTLIT -> ERROR: CODE 45 LINE 1 COLUMN 21 - integer literal expected in place of '99'
$ ~/xxx/bin/hawk --pablock=off '{ print $0; }'
HAWK_EKWFNC -> ERROR: CODE 50 LINE 1 COLUMN 1 - keyword 'function' expected in place of '{'
$ ~/xxx/bin/hawk --pablock=off 'BEGIN { print $0; }'
HAWK_EKWFNC -> ERROR: CODE 50 LINE 1 COLUMN 1 - keyword 'function' expected in place of 'BEGIN'
$ ~/xxx/bin/hawk '@include "a\0b"; function; BEGIN { function=10; }'
HAWK_EIONMNL -> ERROR: CODE 122 LINE 1 COLUMN 10 - invalid I/O name of length 3 containing '\0'
$ ~/xxx/bin/hawk 'function add(a,b) { return a + b; } @global add; BEGIN { add = 10; }'
HAWK_EFUNRED -> ERROR: CODE 59 LINE 1 COLUMN 45 - function 'add' redefined
$ ~/xxx/bin/hawk '@global add; function add(a,b) { return a + b; } BEGIN { add = 10; }'
HAWK_EGBLRED -> ERROR: CODE 60 LINE 1 COLUMN 23 - global variable 'add' redefined
$ ~/xxx/bin/hawk 'BEGIN { @local length; }'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 16 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk '@global length;'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 9 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk 'function length(x) { return 10; }'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 10 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk 'function test(ax) { @local ax; }'
HAWK_EPARRED -> ERROR: CODE 61 LINE 1 COLUMN 28 - parameter 'ax' redefined