This commit is contained in:
hyung-hwan 2007-12-21 01:41:52 +00:00
parent f5a2f5d70f
commit 730e8cc9c5
2 changed files with 253 additions and 130 deletions

View File

@ -139,7 +139,8 @@ static ase_size_t find_global (
static int add_global ( static int add_global (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len, ase_awk_t* awk, const ase_char_t* name, ase_size_t len,
ase_size_t line, int force); ase_size_t line, int force);
static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals); static ase_awk_t* collect_locals (
ase_awk_t* awk, ase_size_t nlocals, ase_bool_t istop);
static ase_awk_nde_t* parse_function (ase_awk_t* awk); static ase_awk_nde_t* parse_function (ase_awk_t* awk);
static ase_awk_nde_t* parse_begin (ase_awk_t* awk); static ase_awk_nde_t* parse_begin (ase_awk_t* awk);
@ -147,8 +148,8 @@ static ase_awk_nde_t* parse_end (ase_awk_t* awk);
static ase_awk_chain_t* parse_pattern_block ( static ase_awk_chain_t* parse_pattern_block (
ase_awk_t* awk, ase_awk_nde_t* ptn, ase_bool_t blockless); ase_awk_t* awk, ase_awk_nde_t* ptn, ase_bool_t blockless);
static ase_awk_nde_t* parse_block (ase_awk_t* awk, ase_size_t line, ase_bool_t is_top); static ase_awk_nde_t* parse_block (ase_awk_t* awk, ase_size_t line, ase_bool_t istop);
static ase_awk_nde_t* parse_block_dc (ase_awk_t* awk, ase_size_t line, ase_bool_t is_top); static ase_awk_nde_t* parse_block_dc (ase_awk_t* awk, ase_size_t line, ase_bool_t istop);
static ase_awk_nde_t* parse_statement (ase_awk_t* awk, ase_size_t line); static ase_awk_nde_t* parse_statement (ase_awk_t* awk, ase_size_t line);
static ase_awk_nde_t* parse_statement_nb (ase_awk_t* awk, ase_size_t line); static ase_awk_nde_t* parse_statement_nb (ase_awk_t* awk, ase_size_t line);
@ -804,7 +805,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
ase_size_t name_len; ase_size_t name_len;
ase_awk_nde_t* body; ase_awk_nde_t* body;
ase_awk_afn_t* afn; ase_awk_afn_t* afn;
ase_size_t nargs; ase_size_t nargs, g;
ase_awk_pair_t* pair; ase_awk_pair_t* pair;
int n; int n;
@ -839,10 +840,12 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
return ASE_NULL; return ASE_NULL;
} }
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
#endif
/* check if it coincides to be a global variable name */ /* check if it coincides to be a global variable name */
ase_size_t g = find_global (awk, name, name_len); g = find_global (awk, name, name_len);
if (g != (ase_size_t)-1) if (g != (ase_size_t)-1)
{ {
SETERRARG ( SETERRARG (
@ -850,7 +853,9 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
name, name_len); name, name_len);
return ASE_NULL; return ASE_NULL;
} }
#if 0
} }
#endif
/* clone the function name before it is overwritten */ /* clone the function name before it is overwritten */
name_dup = ase_awk_strxdup (awk, name, name_len); name_dup = ase_awk_strxdup (awk, name, name_len);
@ -915,9 +920,11 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
param = ASE_STR_BUF(&awk->token.name); param = ASE_STR_BUF(&awk->token.name);
param_len = ASE_STR_LEN(&awk->token.name); param_len = ASE_STR_LEN(&awk->token.name);
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
/* check if a parameter conflicts with a function */ /* check if a parameter conflicts with a function
* function f (f) { print f; } */
if (ase_strxncmp (name_dup, name_len, param, param_len) == 0 || if (ase_strxncmp (name_dup, name_len, param, param_len) == 0 ||
ase_awk_map_get (awk->tree.afns, param, param_len) != ASE_NULL) ase_awk_map_get (awk->tree.afns, param, param_len) != ASE_NULL)
{ {
@ -937,6 +944,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
* x in print x is a parameter * x in print x is a parameter
*/ */
} }
#endif
/* check if a parameter conflicts with other parameters */ /* check if a parameter conflicts with other parameters */
if (ase_awk_tab_find ( if (ase_awk_tab_find (
@ -1180,7 +1188,7 @@ static ase_awk_chain_t* parse_pattern_block (
} }
static ase_awk_nde_t* parse_block ( static ase_awk_nde_t* parse_block (
ase_awk_t* awk, ase_size_t line, ase_bool_t is_top) ase_awk_t* awk, ase_size_t line, ase_bool_t istop)
{ {
ase_awk_nde_t* head, * curr, * nde; ase_awk_nde_t* head, * curr, * nde;
ase_awk_nde_blk_t* block; ase_awk_nde_blk_t* block;
@ -1204,7 +1212,7 @@ static ase_awk_nde_t* parse_block (
return ASE_NULL; return ASE_NULL;
} }
if (collect_locals (awk, nlocals) == ASE_NULL) if (collect_locals (awk, nlocals, istop) == ASE_NULL)
{ {
ase_awk_tab_remove ( ase_awk_tab_remove (
&awk->parse.locals, nlocals, &awk->parse.locals, nlocals,
@ -1303,7 +1311,7 @@ static ase_awk_nde_t* parse_block (
and merged to top-level block */ and merged to top-level block */
/* migrate all block-local variables to a top-level block */ /* migrate all block-local variables to a top-level block */
if (is_top) if (istop)
{ {
block->nlocals = awk->parse.nlocals_max - nlocals; block->nlocals = awk->parse.nlocals_max - nlocals;
awk->parse.nlocals_max = nlocals_max; awk->parse.nlocals_max = nlocals_max;
@ -1318,7 +1326,7 @@ static ase_awk_nde_t* parse_block (
} }
static ase_awk_nde_t* parse_block_dc ( static ase_awk_nde_t* parse_block_dc (
ase_awk_t* awk, ase_size_t line, ase_bool_t is_top) ase_awk_t* awk, ase_size_t line, ase_bool_t istop)
{ {
ase_awk_nde_t* nde; ase_awk_nde_t* nde;
@ -1331,7 +1339,7 @@ static ase_awk_nde_t* parse_block_dc (
} }
awk->parse.depth.cur.block++; awk->parse.depth.cur.block++;
nde = parse_block (awk, line, is_top); nde = parse_block (awk, line, istop);
awk->parse.depth.cur.block--; awk->parse.depth.cur.block--;
return nde; return nde;
@ -1433,8 +1441,10 @@ static int add_global (
{ {
ase_size_t nglobals; ase_size_t nglobals;
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
#endif
/* check if it conflict with a builtin function name */ /* check if it conflict with a builtin function name */
if (ase_awk_getbfn (awk, name, len) != ASE_NULL) if (ase_awk_getbfn (awk, name, len) != ASE_NULL)
{ {
@ -1462,7 +1472,9 @@ static int add_global (
name, len); name, len);
return -1; return -1;
} }
#if 0
} }
#endif
/* check if it conflicts with other global variable names */ /* check if it conflicts with other global variable names */
if (find_global (awk, name, len) != (ase_size_t)-1) if (find_global (awk, name, len) != (ase_size_t)-1)
@ -1590,7 +1602,8 @@ static ase_awk_t* collect_globals (ase_awk_t* awk)
return awk; return awk;
} }
static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals) static ase_awk_t* collect_locals (
ase_awk_t* awk, ase_size_t nlocals, ase_bool_t istop)
{ {
ase_char_t* local; ase_char_t* local;
ase_size_t local_len; ase_size_t local_len;
@ -1607,11 +1620,14 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
local = ASE_STR_BUF(&awk->token.name); local = ASE_STR_BUF(&awk->token.name);
local_len = ASE_STR_LEN(&awk->token.name); local_len = ASE_STR_LEN(&awk->token.name);
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
ase_bool_t iscur = ase_false; ase_bool_t iscur = ase_false;
#endif
/* check if it conflict with a builtin function name */ /* check if it conflict with a builtin function name
* function f() { local length; } */
if (ase_awk_getbfn (awk, local, local_len) != ASE_NULL) if (ase_awk_getbfn (awk, local, local_len) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
@ -1620,6 +1636,7 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
return ASE_NULL; return ASE_NULL;
} }
#if 0
/* check if it conflict with a function name */ /* check if it conflict with a function name */
if (awk->tree.cur_afn.ptr != ASE_NULL) if (awk->tree.cur_afn.ptr != ASE_NULL)
{ {
@ -1646,15 +1663,19 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
return ASE_NULL; return ASE_NULL;
} }
} }
#endif
/* check if it conflicts with a paremeter name */ if (istop)
n = ase_awk_tab_find (&awk->parse.params, 0, local, local_len);
if (n != (ase_size_t)-1)
{ {
SETERRARG ( /* check if it conflicts with a paremeter name */
awk, ASE_AWK_EPARRED, awk->token.line, n = ase_awk_tab_find (&awk->parse.params, 0, local, local_len);
local, local_len); if (n != (ase_size_t)-1)
return ASE_NULL; {
SETERRARG (
awk, ASE_AWK_EPARRED, awk->token.line,
local, local_len);
return ASE_NULL;
}
} }
/* check if it conflicts with other local variable names */ /* check if it conflicts with other local variable names */
@ -1682,7 +1703,8 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
local, local_len); local, local_len);
return ASE_NULL; return ASE_NULL;
} }
if ((awk->option & ASE_AWK_SHADING) == 0)
if (!(awk->option & ASE_AWK_SHADING))
{ {
/* conflicting with a normal global variable */ /* conflicting with a normal global variable */
SETERRARG ( SETERRARG (
@ -3043,6 +3065,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
ase_char_t* name_dup; ase_char_t* name_dup;
ase_size_t name_len; ase_size_t name_len;
ase_awk_bfn_t* bfn; ase_awk_bfn_t* bfn;
ase_size_t idxa;
ASE_ASSERT (MATCH(awk,TOKEN_IDENT)); ASE_ASSERT (MATCH(awk,TOKEN_IDENT));
@ -3073,7 +3096,6 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
/* an intrinsic function should be in the form /* an intrinsic function should be in the form
* of the function call */ * of the function call */
ASE_AWK_FREE (awk, name_dup); ASE_AWK_FREE (awk, name_dup);
SETERRTOK (awk, ASE_AWK_ELPAREN); SETERRTOK (awk, ASE_AWK_ELPAREN);
return ASE_NULL; return ASE_NULL;
} }
@ -3091,19 +3113,20 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup); if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup);
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
} }
else if (MATCH(awk,TOKEN_LPAREN)) else if ((idxa = ase_awk_tab_rrfind (
&awk->parse.locals, 0, name_dup, name_len)) != (ase_size_t)-1)
{ {
/* function call */ /* local variable */
ase_awk_nde_t* nde;
nde = parse_fncall (awk, name_dup, name_len, ASE_NULL, line);
if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup);
return (ase_awk_nde_t*)nde;
}
else
{
/* normal variable */
ase_awk_nde_var_t* nde; ase_awk_nde_var_t* nde;
ase_size_t idxa;
if (MATCH(awk,TOKEN_LPAREN))
{
/* a local variable is not a function */
SETERRARG (awk, ASE_AWK_EFNNAME, line, name_dup, name_len);
ASE_AWK_FREE (awk, name_dup);
return ASE_NULL;
}
nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC ( nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_nde_var_t)); awk, ASE_SIZEOF(ase_awk_nde_var_t));
@ -3114,60 +3137,121 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
return ASE_NULL; return ASE_NULL;
} }
/* search the parameter name list */ nde->type = ASE_AWK_NDE_LOCAL;
idxa = ase_awk_tab_find ( nde->line = line;
&awk->parse.params, 0, name_dup, name_len); nde->next = ASE_NULL;
if (idxa != (ase_size_t)-1) /*nde->id.name = ASE_NULL;*/
{ nde->id.name = name_dup;
nde->type = ASE_AWK_NDE_ARG; nde->id.name_len = name_len;
nde->line = line; nde->id.idxa = idxa;
nde->next = ASE_NULL; nde->idx = ASE_NULL;
/*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup;
nde->id.name_len = name_len;
nde->id.idxa = idxa;
nde->idx = ASE_NULL;
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
}
else if ((idxa = ase_awk_tab_find (
&awk->parse.params, 0, name_dup, name_len)) != (ase_size_t)-1)
{
/* parameter */
ase_awk_nde_var_t* nde;
if (MATCH(awk,TOKEN_LPAREN))
{
/* a parameter is not a function */
SETERRARG (awk, ASE_AWK_EFNNAME, line, name_dup, name_len);
ASE_AWK_FREE (awk, name_dup);
return ASE_NULL;
} }
/* search the local variable list */ nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC (
idxa = ase_awk_tab_rrfind ( awk, ASE_SIZEOF(ase_awk_nde_var_t));
&awk->parse.locals, 0, name_dup, name_len); if (nde == ASE_NULL)
if (idxa != (ase_size_t)-1)
{ {
nde->type = ASE_AWK_NDE_LOCAL; ASE_AWK_FREE (awk, name_dup);
nde->line = line; SETERRLIN (awk, ASE_AWK_ENOMEM, line);
nde->next = ASE_NULL; return ASE_NULL;
/*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup;
nde->id.name_len = name_len;
nde->id.idxa = idxa;
nde->idx = ASE_NULL;
return (ase_awk_nde_t*)nde;
} }
/* gets the global variable index */ nde->type = ASE_AWK_NDE_ARG;
idxa = get_global (awk, name_dup, name_len); nde->line = line;
if (idxa != (ase_size_t)-1) nde->next = ASE_NULL;
{ /*nde->id.name = ASE_NULL;*/
nde->type = ASE_AWK_NDE_GLOBAL; nde->id.name = name_dup;
nde->line = line; nde->id.name_len = name_len;
nde->next = ASE_NULL; nde->id.idxa = idxa;
/*nde->id.name = ASE_NULL;*/ nde->idx = ASE_NULL;
nde->id.name = name_dup;
nde->id.name_len = name_len;
nde->id.idxa = idxa;
nde->idx = ASE_NULL;
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
}
else if ((idxa = get_global (
awk, name_dup, name_len)) != (ase_size_t)-1)
{
/* global variable */
ase_awk_nde_var_t* nde;
if (MATCH(awk,TOKEN_LPAREN))
{
/* a global variable is not a function */
SETERRARG (awk, ASE_AWK_EFNNAME, line, name_dup, name_len);
ASE_AWK_FREE (awk, name_dup);
return ASE_NULL;
}
nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_nde_var_t));
if (nde == ASE_NULL)
{
ASE_AWK_FREE (awk, name_dup);
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL;
}
nde->type = ASE_AWK_NDE_GLOBAL;
nde->line = line;
nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup;
nde->id.name_len = name_len;
nde->id.idxa = idxa;
nde->idx = ASE_NULL;
return (ase_awk_nde_t*)nde;
}
else if (MATCH(awk,TOKEN_LPAREN))
{
/* function call */
ase_awk_nde_t* nde;
if (awk->option & ASE_AWK_IMPLICIT)
{
/*TODO: check if it conflicts any named variables collected so far.... XXXX */
}
nde = parse_fncall (awk, name_dup, name_len, ASE_NULL, line);
if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup);
return (ase_awk_nde_t*)nde;
}
else
{
/* named variable */
ase_awk_nde_var_t* nde;
nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_nde_var_t));
if (nde == ASE_NULL)
{
ASE_AWK_FREE (awk, name_dup);
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL;
} }
if (awk->option & ASE_AWK_IMPLICIT) if (awk->option & ASE_AWK_IMPLICIT)
{ {
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
#endif
ase_bool_t iscur = ase_false; ase_bool_t iscur = ase_false;
/* the name should not conflict with a function name */ /* the name should not conflict with a function name */
@ -3195,10 +3279,13 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
if (ase_awk_tab_find (&awk->parse.afns, 0, name_dup, name_len) != (ase_size_t)-1) if (ase_awk_tab_find (&awk->parse.afns, 0, name_dup, name_len) != (ase_size_t)-1)
{ {
/* is it one of the function calls found so far? */
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len); SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
goto exit_func; goto exit_func;
} }
#if 0
} }
#endif
nde->type = ASE_AWK_NDE_NAMED; nde->type = ASE_AWK_NDE_NAMED;
nde->line = line; nde->line = line;
@ -3208,6 +3295,8 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
nde->id.idxa = (ase_size_t)-1; nde->id.idxa = (ase_size_t)-1;
nde->idx = ASE_NULL; nde->idx = ASE_NULL;
/* TODO: add this named variable to the parse.named map... XXXX */
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
} }
@ -3285,11 +3374,11 @@ static ase_awk_nde_t* parse_hashidx (
return ASE_NULL; return ASE_NULL;
} }
/* search the parameter name list */ /* search the local variable list */
idxa = ase_awk_tab_find (&awk->parse.params, 0, name, name_len); idxa = ase_awk_tab_rrfind(&awk->parse.locals, 0, name, name_len);
if (idxa != (ase_size_t)-1) if (idxa != (ase_size_t)-1)
{ {
nde->type = ASE_AWK_NDE_ARGIDX; nde->type = ASE_AWK_NDE_LOCALIDX;
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL; */ /*nde->id.name = ASE_NULL; */
@ -3301,11 +3390,11 @@ static ase_awk_nde_t* parse_hashidx (
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
} }
/* search the local variable list */ /* search the parameter name list */
idxa = ase_awk_tab_rrfind(&awk->parse.locals, 0, name, name_len); idxa = ase_awk_tab_find (&awk->parse.params, 0, name, name_len);
if (idxa != (ase_size_t)-1) if (idxa != (ase_size_t)-1)
{ {
nde->type = ASE_AWK_NDE_LOCALIDX; nde->type = ASE_AWK_NDE_ARGIDX;
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL; */ /*nde->id.name = ASE_NULL; */
@ -3335,8 +3424,10 @@ static ase_awk_nde_t* parse_hashidx (
if (awk->option & ASE_AWK_IMPLICIT) if (awk->option & ASE_AWK_IMPLICIT)
{ {
#if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
{ {
#endif
ase_bool_t iscur = ase_false; ase_bool_t iscur = ase_false;
/* check if it is a builtin function */ /* check if it is a builtin function */
@ -3363,10 +3454,13 @@ static ase_awk_nde_t* parse_hashidx (
if (ase_awk_tab_find (&awk->parse.afns, 0, name, name_len) != (ase_size_t)-1) if (ase_awk_tab_find (&awk->parse.afns, 0, name, name_len) != (ase_size_t)-1)
{ {
/* is it one of the function calls found so far? */
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len); SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
goto exit_func; goto exit_func;
} }
#if 0
} }
#endif
nde->type = ASE_AWK_NDE_NAMEDIDX; nde->type = ASE_AWK_NDE_NAMEDIDX;
nde->line = line; nde->line = line;
@ -3501,10 +3595,12 @@ static ase_awk_nde_t* parse_fncall (
call->args = head; call->args = head;
call->nargs = nargs; call->nargs = nargs;
#if 0
if (((awk->option & ASE_AWK_EXPLICIT) && if (((awk->option & ASE_AWK_EXPLICIT) &&
!(awk->option & ASE_AWK_IMPLICIT)) || !(awk->option & ASE_AWK_IMPLICIT)) /*||
(awk->option & ASE_AWK_UNIQUEFN)) (awk->option & ASE_AWK_UNIQUEFN)*/)
{ {
#endif
if (ase_awk_tab_adduniq ( if (ase_awk_tab_adduniq (
&awk->parse.afns, name, name_len) == (ase_size_t)-1) &awk->parse.afns, name, name_len) == (ase_size_t)-1)
{ {
@ -3513,7 +3609,9 @@ static ase_awk_nde_t* parse_fncall (
SETERRLIN (awk, ASE_AWK_ENOMEM, line); SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL; return ASE_NULL;
} }
#if 0
} }
#endif
} }
return (ase_awk_nde_t*)call; return (ase_awk_nde_t*)call;
@ -5341,7 +5439,7 @@ static int deparse (ase_awk_t* awk)
if (awk->tree.nglobals > awk->tree.nbglobals) if (awk->tree.nglobals > awk->tree.nbglobals)
{ {
ase_size_t i/*, len*/; ase_size_t i, len;
ASE_ASSERT (awk->tree.nglobals > 0); ASE_ASSERT (awk->tree.nglobals > 0);
if (ase_awk_putsrcstr(awk,ase_awk_getkw(awk,ASE_T("global"))) == -1) if (ase_awk_putsrcstr(awk,ase_awk_getkw(awk,ASE_T("global"))) == -1)
@ -5355,7 +5453,45 @@ static int deparse (ase_awk_t* awk)
for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++) for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++)
{ {
/* if ((awk->option & ASE_AWK_EXPLICIT) &&
!(awk->option & ASE_AWK_IMPLICIT))
{
/* use the actual name if no name variable
* is allowed */
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
{
EXIT_DEPARSE ();
}
}
else
{
len = ase_awk_longtostr ((ase_long_t)i,
10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp));
ASE_ASSERT (len != (ase_size_t)-1);
if (ase_awk_putsrcstrx (awk, tmp, len) == -1)
{
EXIT_DEPARSE ();
}
}
if (ase_awk_putsrcstr (awk, ASE_T(", ")) == -1)
EXIT_DEPARSE ();
}
if ((awk->option & ASE_AWK_EXPLICIT) &&
!(awk->option & ASE_AWK_IMPLICIT))
{
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
{
EXIT_DEPARSE ();
}
}
else
{
len = ase_awk_longtostr ((ase_long_t)i, len = ase_awk_longtostr ((ase_long_t)i,
10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp)); 10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp));
ASE_ASSERT (len != (ase_size_t)-1); ASE_ASSERT (len != (ase_size_t)-1);
@ -5363,32 +5499,6 @@ static int deparse (ase_awk_t* awk)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
*/
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
{
EXIT_DEPARSE ();
}
if (ase_awk_putsrcstr (awk, ASE_T(", ")) == -1)
EXIT_DEPARSE ();
}
/*
len = ase_awk_longtostr ((ase_long_t)i,
10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp));
ASE_ASSERT (len != (ase_size_t)-1);
if (ase_awk_putsrcstrx (awk, tmp, len) == -1)
{
EXIT_DEPARSE ();
}
*/
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
{
EXIT_DEPARSE ();
} }
if (awk->option & ASE_AWK_CRLF) if (awk->option & ASE_AWK_CRLF)

View File

@ -384,20 +384,27 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
case ASE_AWK_NDE_GLOBAL: case ASE_AWK_NDE_GLOBAL:
{ {
/*ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2];
ase_size_t n;*/
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
if (px->id.idxa != (ase_size_t)-1) if (px->id.idxa != (ase_size_t)-1)
{ {
/*
PUT_SRCSTR (awk, ASE_T("__global")); if ((awk->option & ASE_AWK_EXPLICIT) &&
n = ase_awk_longtostr ( !(awk->option & ASE_AWK_IMPLICIT))
px->id.idxa, 10, {
ASE_NULL, tmp, ASE_COUNTOF(tmp)); PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
PUT_SRCSTRX (awk, tmp, n); }
*/ else
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); {
ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2];
ase_size_t n;
PUT_SRCSTR (awk, ASE_T("__global"));
n = ase_awk_longtostr (
px->id.idxa, 10,
ASE_NULL, tmp, ASE_COUNTOF(tmp));
PUT_SRCSTRX (awk, tmp, n);
}
} }
else else
{ {
@ -409,20 +416,26 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
case ASE_AWK_NDE_GLOBALIDX: case ASE_AWK_NDE_GLOBALIDX:
{ {
/*ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2];
ase_size_t n;*/
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde;
if (px->id.idxa != (ase_size_t)-1) if (px->id.idxa != (ase_size_t)-1)
{ {
/* if ((awk->option & ASE_AWK_EXPLICIT) &&
PUT_SRCSTR (awk, ASE_T("__global")); !(awk->option & ASE_AWK_IMPLICIT))
n = ase_awk_longtostr ( {
px->id.idxa, 10, PUT_SRCSTRX (awk, px->id.name, px->id.name_len);
ASE_NULL, tmp, ASE_COUNTOF(tmp)); }
PUT_SRCSTRX (awk, tmp, n); else
*/ {
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2];
ase_size_t n;
PUT_SRCSTR (awk, ASE_T("__global"));
n = ase_awk_longtostr (
px->id.idxa, 10,
ASE_NULL, tmp, ASE_COUNTOF(tmp));
PUT_SRCSTRX (awk, tmp, n);
}
PUT_SRCSTR (awk, ASE_T("[")); PUT_SRCSTR (awk, ASE_T("["));
} }
else else