fixed a bug in printing a tree node of the HAWK_NDE_POS type

This commit is contained in:
hyung-hwan 2020-03-12 04:26:28 +00:00
parent db77a97119
commit 84c0b37e94
3 changed files with 15 additions and 14 deletions

View File

@ -164,7 +164,7 @@ For this reason, there is no way to get the type name of a regular expressin lit
A pragma item of the file scope can be placed in any source files.
A pragma item of the global scope can appear only once thoughout the all source files.
| | Scope | Values | Description |
| Name | Scope | Values | Description |
|---------------|--------|---------------|--------------------------------------------------------|
| implicit | file | on, off | allow undeclared variables |
| multilinestr | file | on, off | allow a multiline string literal without continuation |
@ -201,7 +201,7 @@ Alternatively, you may form an array before passing it to a function.
There are subtle differences when you put an expression for a position variable. In Hawk, most of the ambiguity issues are resolved if you enclose the expression inside parentheses.
| | HAWK | AWK |
| Expression | HAWK | AWK |
|--------------|---------------|-----------------|
| $++$++i | syntax error | OK |
| $(++$(++i)) | OK | syntax error |

View File

@ -4873,7 +4873,7 @@ static hawk_nde_t* parse_primary_positional (hawk_t* awk, const hawk_loc_t* xloc
hawk_loc_t ploc;
nde = (hawk_nde_pos_t*)hawk_callocmem(awk, HAWK_SIZEOF(*nde));
if (nde == HAWK_NULL)
if (HAWK_UNLIKELY(!nde))
{
ADJERR_LOC (awk, xloc);
goto oops;
@ -4886,7 +4886,7 @@ static hawk_nde_t* parse_primary_positional (hawk_t* awk, const hawk_loc_t* xloc
ploc = awk->tok.loc;
nde->val = parse_primary(awk, &ploc);
if (!nde->val) goto oops;
if (HAWK_UNLIKELY(!nde->val)) goto oops;
return (hawk_nde_t*)nde;
@ -4914,7 +4914,7 @@ static hawk_nde_t* parse_primary_lparen (hawk_t* awk, const hawk_loc_t* xloc)
/* parse the sub-expression inside the parentheses */
eloc = awk->tok.loc;
nde = parse_expr_withdc(awk, &eloc);
if (!nde) return HAWK_NULL;
if (HAWK_UNLIKELY(!nde)) return HAWK_NULL;
/* parse subsequent expressions separated by a comma, if any */
last = nde;
@ -4932,7 +4932,7 @@ static hawk_nde_t* parse_primary_lparen (hawk_t* awk, const hawk_loc_t* xloc)
eloc = awk->tok.loc;
tmp = parse_expr_withdc(awk, &eloc);
if (!tmp) goto oops;
if (HAWK_UNLIKELY(!tmp)) goto oops;
HAWK_ASSERT (tmp->next == HAWK_NULL);
last->next = tmp;
@ -4971,7 +4971,7 @@ static hawk_nde_t* parse_primary_lparen (hawk_t* awk, const hawk_loc_t* xloc)
}
tmp = (hawk_nde_grp_t*)hawk_callocmem(awk, HAWK_SIZEOF(hawk_nde_grp_t));
if (!tmp)
if (HAWK_UNLIKELY(!tmp))
{
ADJERR_LOC (awk, xloc);
goto oops;
@ -5003,7 +5003,7 @@ static hawk_nde_t* parse_primary_getline (hawk_t* awk, const hawk_loc_t* xloc, i
hawk_loc_t ploc;
nde = (hawk_nde_getline_t*)hawk_callocmem(awk, HAWK_SIZEOF(*nde));
if (nde == HAWK_NULL) goto oops;
if (HAWK_UNLIKELY(!nde)) goto oops;
nde->type = HAWK_NDE_GETLINE;
nde->mbs = mbs;
@ -5041,7 +5041,7 @@ static hawk_nde_t* parse_primary_getline (hawk_t* awk, const hawk_loc_t* xloc, i
ploc = awk->tok.loc;
nde->var = parse_primary(awk, &ploc);
if (nde->var == HAWK_NULL) goto oops;
if (HAWK_UNLIKELY(!nde->var)) goto oops;
if (!is_var(nde->var) && nde->var->type != HAWK_NDE_POS)
{
@ -5064,7 +5064,7 @@ novar:
/* TODO: is this correct? */
/*nde->in = parse_expr_withdc (awk, &ploc);*/
nde->in = parse_primary(awk, &ploc);
if (nde->in == HAWK_NULL) goto oops;
if (HAWK_UNLIKELY(!nde->in)) goto oops;
nde->in_type = HAWK_IN_FILE;
}

View File

@ -678,8 +678,9 @@ static int print_expr (hawk_t* awk, hawk_nde_t* nde)
case HAWK_NDE_POS:
{
PUT_SRCSTR (awk, HAWK_T("$"));
PUT_SRCSTR (awk, HAWK_T("$("));
PRINT_EXPR (awk, ((hawk_nde_pos_t*)nde)->val);
PUT_SRCSTR (awk, HAWK_T(")"));
break;
}