From b5c463bfa07770ee5ee8e34807ee8f002374a2ef Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 13 Feb 2008 02:56:21 +0000 Subject: [PATCH] --- ase/awk/parse.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 490e32a0..246367d0 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -3073,6 +3073,271 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line) return ASE_NULL; } +#if 0 +ORIGINAL... +static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line) +{ + ase_char_t* name_dup; + ase_size_t name_len; + ase_awk_bfn_t* bfn; + ase_size_t idxa; + + ASE_ASSERT (MATCH(awk,TOKEN_IDENT)); + + name_dup = ase_awk_strxdup (awk, + ASE_STR_BUF(&awk->token.name), + ASE_STR_LEN(&awk->token.name)); + if (name_dup == ASE_NULL) + { + SETERRLIN (awk, ASE_AWK_ENOMEM, line); + return ASE_NULL; + } + name_len = ASE_STR_LEN(&awk->token.name); + + if (get_token(awk) == -1) + { + ASE_AWK_FREE (awk, name_dup); + return ASE_NULL; + } + + /* check if name_dup is an intrinsic function name */ + bfn = ase_awk_getbfn (awk, name_dup, name_len); + if (bfn != ASE_NULL) + { + ase_awk_nde_t* nde; + + if (!MATCH(awk,TOKEN_LPAREN)) + { + /* an intrinsic function should be in the form + * of the function call */ + ASE_AWK_FREE (awk, name_dup); + SETERRTOK (awk, ASE_AWK_ELPAREN); + return ASE_NULL; + } + + nde = parse_fncall (awk, name_dup, name_len, bfn, line); + if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup); + return (ase_awk_nde_t*)nde; + } + + /* now we know that name_dup is a normal identifier. */ + if (MATCH(awk,TOKEN_LBRACK)) + { + ase_awk_nde_t* nde; + nde = parse_hashidx (awk, name_dup, name_len, line); + if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup); + return (ase_awk_nde_t*)nde; + } + else if ((idxa = ase_awk_tab_rrfind ( + &awk->parse.locals, 0, name_dup, name_len)) != (ase_size_t)-1) + { + /* local variable */ + + ase_awk_nde_var_t* nde; + + 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 ( + 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_LOCAL; + 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 ((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; + } + + 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_ARG; + 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 ((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) + { + if (ase_map_get (awk->parse.named, name_dup, name_len) != ASE_NULL) + { + /* a function call conflicts with a named variable */ + SETERRARG (awk, ASE_AWK_EVARRED, line, name_dup, name_len); + ASE_AWK_FREE (awk, name_dup); + return ASE_NULL; + } + } + + 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 0 + if (awk->option & ASE_AWK_UNIQUEFN) + { + #endif + ase_bool_t iscur = ase_false; + + /* the name should not conflict with a function name */ + /* check if it is a builtin function */ + if (ase_awk_getbfn (awk, name_dup, name_len) != ASE_NULL) + { + SETERRARG (awk, ASE_AWK_EBFNRED, line, name_dup, name_len); + goto exit_func; + } + + /* check if it is an AWK function */ + if (awk->tree.cur_afn.ptr != ASE_NULL) + { + iscur = (ase_strxncmp ( + awk->tree.cur_afn.ptr, awk->tree.cur_afn.len, + name_dup, name_len) == 0); + } + + if (iscur || ase_map_get (awk->tree.afns, name_dup, name_len) != ASE_NULL) + { + /* the function is defined previously */ + SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len); + goto exit_func; + } + + if (ase_map_get (awk->parse.afns, name_dup, name_len) != ASE_NULL) + { + /* is it one of the function calls found so far? */ + SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len); + goto exit_func; + } + #if 0 + } + #endif + + nde->type = ASE_AWK_NDE_NAMED; + nde->line = line; + nde->next = ASE_NULL; + nde->id.name = name_dup; + nde->id.name_len = name_len; + nde->id.idxa = (ase_size_t)-1; + nde->idx = ASE_NULL; + + /* collect unique instances of a named variables for reference */ + if (ase_map_put (awk->parse.named, + name_dup, name_len, (void*)line) == ASE_NULL) + { + SETERRLIN (awk, ASE_AWK_ENOMEM, line); + goto exit_func; + } + + return (ase_awk_nde_t*)nde; + } + + /* undefined variable */ + SETERRARG (awk, ASE_AWK_EUNDEF, line, name_dup, name_len); + + exit_func: + ASE_AWK_FREE (awk, name_dup); + ASE_AWK_FREE (awk, nde); + + return ASE_NULL; + } +} +#endif static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line) { ase_char_t* name_dup;