From ec5e61278c16893aceae27388d619b370be9cd93 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 3 Jan 2020 10:35:45 +0000 Subject: [PATCH] corrected the random max value. some more error information handling improvement in parse.c --- hawk/lib/err.c | 4 ++-- hawk/lib/hawk-cmn.h | 6 +++--- hawk/lib/mod-math.c | 3 ++- hawk/lib/parse.c | 8 ++++---- hawk/lib/run.c | 2 -- hawk/t/test.txt | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hawk/lib/err.c b/hawk/lib/err.c index 9db7f1c3..32bf672f 100644 --- a/hawk/lib/err.c +++ b/hawk/lib/err.c @@ -101,8 +101,8 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum) HAWK_T("global variable redefined"), HAWK_T("parameter redefined"), HAWK_T("variable redefined"), - HAWK_T("duplicate parameter name '${0}'"), - HAWK_T("duplicate global variable '${0}'"), + HAWK_T("duplicate parameter name"), + HAWK_T("duplicate global variable"), HAWK_T("duplicate local variable"), HAWK_T("'${0}' not a valid parameter name"), HAWK_T("'${0}' not a valid variable name"), diff --git a/hawk/lib/hawk-cmn.h b/hawk/lib/hawk-cmn.h index f4c7b7c4..5b86f311 100644 --- a/hawk/lib/hawk-cmn.h +++ b/hawk/lib/hawk-cmn.h @@ -831,9 +831,9 @@ enum hawk_errnum_t HAWK_EGBLRED, /**< global variable redefined */ HAWK_EPARRED, /**< parameter redefined */ HAWK_EVARRED, /**< variable redefined */ - HAWK_EDUPPAR, /**< duplicate parameter name '${0}' */ - HAWK_EDUPGBL, /**< duplicate global variable name '${0}' */ - HAWK_EDUPLCL, /**< duplicate local variable name '${0}' */ + HAWK_EDUPPAR, /**< duplicate parameter name */ + HAWK_EDUPGBL, /**< duplicate global variable name */ + HAWK_EDUPLCL, /**< duplicate local variable name' */ HAWK_EBADPAR, /**< '${0}' not a valid parameter name */ HAWK_EBADVAR, /**< '${0}' not a valid variable name */ HAWK_EVARMS, /**< variable name missing */ diff --git a/hawk/lib/mod-math.c b/hawk/lib/mod-math.c index e62dfc55..f0f5d84c 100644 --- a/hawk/lib/mod-math.c +++ b/hawk/lib/mod-math.c @@ -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) { -#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_int32_t randv; modctx_t* modctx; diff --git a/hawk/lib/parse.c b/hawk/lib/parse.c index 76bfcc25..b570cdad 100644 --- a/hawk/lib/parse.c +++ b/hawk/lib/parse.c @@ -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_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; } @@ -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 */ 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; } @@ -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); 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; } @@ -2272,7 +2272,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop) if (n < awk->tree.ngbls_base) { /* 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; } } diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 987049b4..3ace69b4 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -83,8 +83,6 @@ struct pafv_t (idx) <= HAWK_TYPE_MAX(hawk_int_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 ADJERR_LOC(rtx,l) do { (rtx)->_gem.errloc = *(l); } while (0) diff --git a/hawk/t/test.txt b/hawk/t/test.txt index d7f8b1e9..6ab147aa 100644 --- a/hawk/t/test.txt +++ b/hawk/t/test.txt @@ -112,4 +112,19 @@ $ ~/xxx/bin/hawk 'function test(ax) { @local ax; }' 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 +