corrected the random max value.

some more error information handling improvement in parse.c
This commit is contained in:
hyung-hwan 2020-01-03 10:35:45 +00:00
parent 01464d1fb1
commit ec5e61278c
6 changed files with 26 additions and 12 deletions

View File

@ -101,8 +101,8 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("global variable redefined"), HAWK_T("global variable redefined"),
HAWK_T("parameter redefined"), HAWK_T("parameter redefined"),
HAWK_T("variable redefined"), HAWK_T("variable redefined"),
HAWK_T("duplicate parameter name '${0}'"), HAWK_T("duplicate parameter name"),
HAWK_T("duplicate global variable '${0}'"), HAWK_T("duplicate global variable"),
HAWK_T("duplicate local variable"), HAWK_T("duplicate local variable"),
HAWK_T("'${0}' not a valid parameter name"), HAWK_T("'${0}' not a valid parameter name"),
HAWK_T("'${0}' not a valid variable name"), HAWK_T("'${0}' not a valid variable name"),

View File

@ -831,9 +831,9 @@ enum hawk_errnum_t
HAWK_EGBLRED, /**< global variable redefined */ HAWK_EGBLRED, /**< global variable redefined */
HAWK_EPARRED, /**< parameter redefined */ HAWK_EPARRED, /**< parameter redefined */
HAWK_EVARRED, /**< variable redefined */ HAWK_EVARRED, /**< variable redefined */
HAWK_EDUPPAR, /**< duplicate parameter name '${0}' */ HAWK_EDUPPAR, /**< duplicate parameter name */
HAWK_EDUPGBL, /**< duplicate global variable name '${0}' */ HAWK_EDUPGBL, /**< duplicate global variable name */
HAWK_EDUPLCL, /**< duplicate local variable name '${0}' */ HAWK_EDUPLCL, /**< duplicate local variable name' */
HAWK_EBADPAR, /**< '${0}' not a valid parameter name */ HAWK_EBADPAR, /**< '${0}' not a valid parameter name */
HAWK_EBADVAR, /**< '${0}' not a valid variable name */ HAWK_EBADVAR, /**< '${0}' not a valid variable name */
HAWK_EVARMS, /**< variable name missing */ HAWK_EVARMS, /**< variable name missing */

View File

@ -530,7 +530,8 @@ static int fnc_sqrt (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
static int fnc_rand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) static int fnc_rand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
#define RANDV_MAX HAWK_TYPE_MAX(hawk_int_t) /*#define RANDV_MAX HAWK_TYPE_MAX(hawk_int_t)*/
#define RANDV_MAX RAND_MAX
hawk_val_t* r; hawk_val_t* r;
hawk_int32_t randv; hawk_int32_t randv;
modctx_t* modctx; modctx_t* modctx;

View File

@ -1324,7 +1324,7 @@ static hawk_nde_t* parse_function (hawk_t* awk)
hawk_comp_oochars(pa, pal, name.ptr, name.len, 0) == 0) || hawk_comp_oochars(pa, pal, name.ptr, name.len, 0) == 0) ||
hawk_arr_search(awk->parse.params, 0, pa, pal) != HAWK_ARR_NIL) hawk_arr_search(awk->parse.params, 0, pa, pal) != HAWK_ARR_NIL)
{ {
SETERR_ARG_LOC (awk, HAWK_EDUPPAR, pa, pal, &awk->tok.loc); hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EDUPPAR, HAWK_T("duplicate parameter name '%.*js'"), pal, pa);
goto oops; goto oops;
} }
@ -1856,7 +1856,7 @@ static int add_global (hawk_t* awk, const hawk_oocs_t* name, hawk_loc_t* xloc, i
/* check if it conflicts with other global variable names */ /* check if it conflicts with other global variable names */
if (find_global(awk, name) != HAWK_ARR_NIL) if (find_global(awk, name) != HAWK_ARR_NIL)
{ {
SETERR_ARG_LOC (awk, HAWK_EDUPGBL, name->ptr, name->len, xloc); hawk_seterrfmt (awk, xloc, HAWK_EDUPGBL, HAWK_T("duplicate global variable name '%.*js'"), name->len, name->ptr);
return -1; return -1;
} }
@ -2261,7 +2261,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
n = hawk_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len); n = hawk_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len);
if (n != HAWK_ARR_NIL) if (n != HAWK_ARR_NIL)
{ {
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 name - %.*js"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
@ -2272,7 +2272,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 static global variable */ /* it is a conflict only if it is one of a 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 name - %.*js"), lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
} }

View File

@ -83,8 +83,6 @@ struct pafv_t
(idx) <= HAWK_TYPE_MAX(hawk_int_t) && \ (idx) <= HAWK_TYPE_MAX(hawk_int_t) && \
(idx) <= HAWK_TYPE_MAX(hawk_oow_t)) (idx) <= HAWK_TYPE_MAX(hawk_oow_t))
#define SETERR_ARGX_LOC(rtx,code,ea,loc) hawk_rtx_seterror ((rtx), (code), (ea), (loc))
#define CLRERR(rtx) hawk_rtx_seterrnum(rtx, HAWK_NULL, HAWK_ENOERR) #define CLRERR(rtx) hawk_rtx_seterrnum(rtx, HAWK_NULL, HAWK_ENOERR)
#define ADJERR_LOC(rtx,l) do { (rtx)->_gem.errloc = *(l); } while (0) #define ADJERR_LOC(rtx,l) do { (rtx)->_gem.errloc = *(l); } while (0)

View File

@ -112,4 +112,19 @@ $ ~/xxx/bin/hawk 'function test(ax) { @local ax; }'
HAWK_EPARRED -> ERROR: CODE 61 LINE 1 COLUMN 28 - parameter 'ax' redefined HAWK_EPARRED -> ERROR: CODE 61 LINE 1 COLUMN 28 - parameter 'ax' redefined
$ ~/xxx/bin/hawk 'function test(ax, bx, ax) { return ax * bx; }'
HAWK_EDUPPAR -> ERROR: CODE 63 LINE 1 COLUMN 23 - duplicate parameter name 'ax'
$ ~/xxx/bin/hawk '@global x, y, x; '
HAWK_EDUPGBL -> ERROR: CODE 64 LINE 1 COLUMN 15 - duplicate global variable name 'x'
$ ~/xxx/bin/hawk 'function test(ax, bx) { @local x, y, x; }'
HAWK_EDUPLCL -> ERROR: CODE 65 LINE 1 COLUMN 38 - duplicate local variable name - x
$ ~/xxx/bin/hawk 'function test(ax, bx) { @local ARGC; }'
ERROR: CODE 65 LINE 1 COLUMN 32 - duplicate local variable name - ARGC