diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 246367d0..66096880 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -3073,8 +3073,6 @@ 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; @@ -3337,296 +3335,6 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line) 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; - ase_size_t name_len; - ase_awk_bfn_t* bfn; - ase_size_t idxa; - ase_char_t name_dup_buf[32]; - - ASE_ASSERT (MATCH(awk,TOKEN_IDENT)); - - if (ASE_STR_LEN(&awk->token.name) < ASE_COUNTOF(name_dup_buf)) - { - ase_strxncpy ( - name_dup_buf, - ASE_COUNTOF(name_dup_buf), - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name)); - name_dup = name_dup_buf; -// TODO: dup on acutal node creationg........ - } - else - { - 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); - - -#define FREE_DUP_NAME(awk) \ - do { \ - if (name_dup != name_dup_buf) \ - ASE_AWK_FREE (awk, name_dup); \ - } while (0) - - if (get_token(awk) == -1) - { - FREE_DUP_NAME(awk); - 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 */ - FREE_DUP_NAME(awk); - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - - nde = parse_fncall (awk, name_dup, name_len, bfn, line); - if (nde == ASE_NULL) FREE_DUP_NAME(awk); - 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) FREE_DUP_NAME(awk); - 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); - FREE_DUP_NAME (awk); - return ASE_NULL; - } - - nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_var_t)); - if (nde == ASE_NULL) - { - FREE_DUP_NAME (awk); - 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); - FREE_DUP_NAME (awk); - return ASE_NULL; - } - - nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_var_t)); - if (nde == ASE_NULL) - { - FREE_DUP_NAME (awk); - 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); - FREE_DUP_NAME (awk); - return ASE_NULL; - } - - nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_var_t)); - if (nde == ASE_NULL) - { - FREE_DUP_NAME (awk); - 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); - FREE_DUP_NAME (awk); - return ASE_NULL; - } - } - - nde = parse_fncall (awk, name_dup, name_len, ASE_NULL, line); - if (nde == ASE_NULL) - { - FREE_DUP_NAME (awk); - } - 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) - { - FREE_DUP_NAME (awk); - 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: - FREE_DUP_NAME (awk); - ASE_AWK_FREE (awk, nde); - - return ASE_NULL; - } - -#undef FREE_DUP_NAME -} static ase_awk_nde_t* parse_hashidx ( ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, ase_size_t line)