From f591d307d9af95bfa0ccda4d5eb76a674447ba39 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 3 Aug 2016 21:38:50 +0300 Subject: Restore typed regexp code in a new branch. --- builtin.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index b295cd24..87f7fb23 100644 --- a/builtin.c +++ b/builtin.c @@ -532,7 +532,7 @@ do_length(int nargs) return make_number(size); } - assert(tmp->type == Node_val); + assert(tmp->type == Node_val || tmp->type == Node_typedregex); if (do_lint && (fixtype(tmp)->flags & STRING) == 0) lintwarn(_("length: received non-string argument")); @@ -2191,10 +2191,12 @@ do_print(int nargs, int redirtype) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(tmp)); } - if ( (tmp->flags & STRCUR) == 0 - || ( tmp->stfmt != STFMT_UNUSED - && tmp->stfmt != OFMTidx)) - args_array[i] = format_val(OFMT, OFMTidx, tmp); + if (tmp->type == Node_typedregex) + args_array[i] = force_string(tmp); + else if ( (tmp->flags & STRCUR) == 0 + || ( tmp->stfmt != STFMT_UNUSED + && tmp->stfmt != OFMTidx)) + args_array[i] = format_val(OFMT, OFMTidx, tmp); } if (redir_exp != NULL) { @@ -3197,7 +3199,8 @@ call_sub(const char *name, int nargs) * push replace * push $0 */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_typedregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); lhs = r_get_field(zero, (Func_ptr *) 0, true); @@ -3221,7 +3224,8 @@ call_sub(const char *name, int nargs) * nargs++ * } */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_typedregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); PUSH(glob_flag); @@ -3258,7 +3262,8 @@ call_match(int nargs) /* Don't need to pop the string just to push it back ... */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_typedregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); if (array) @@ -3286,7 +3291,8 @@ call_split_func(const char *name, int nargs) if (nargs >= 3) { regex = POP_STRING(); - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_typedregex) + regex = make_regnode(Node_regex, regex); } else { if (name[0] == 's') { regex = make_regnode(Node_regex, FS_node->var_value); @@ -3942,6 +3948,9 @@ do_typeof(int nargs) res = "array"; deref = false; break; + case Node_typedregex: + res = "regexp"; + break; case Node_val: case Node_var: switch (arg->flags & (STRING|NUMBER|MAYBE_NUM)) { -- cgit v1.2.3 From b37675aa79213f2665abb2bbb4db90560642bdee Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 15 Nov 2016 21:03:57 +0200 Subject: First steps reworking code away from node type. --- builtin.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index a7fe6312..001dd6e2 100644 --- a/builtin.c +++ b/builtin.c @@ -536,7 +536,7 @@ do_length(int nargs) return make_number(size); } - assert(tmp->type == Node_val || tmp->type == Node_typedregex); + assert(tmp->type == Node_val); if (do_lint && (fixtype(tmp)->flags & STRING) == 0) lintwarn(_("length: received non-string argument")); @@ -2195,11 +2195,9 @@ do_print(int nargs, int redirtype) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(tmp)); } - if (tmp->type == Node_typedregex) - args_array[i] = force_string(tmp); - else if ( (tmp->flags & STRCUR) == 0 - || ( tmp->stfmt != STFMT_UNUSED - && tmp->stfmt != OFMTidx)) + if ( (tmp->flags & STRCUR) == 0 + || ( tmp->stfmt != STFMT_UNUSED + && tmp->stfmt != OFMTidx)) args_array[i] = format_val(OFMT, OFMTidx, tmp); } @@ -3203,7 +3201,7 @@ call_sub(const char *name, int nargs) * push replace * push $0 */ - if (regex->type != Node_typedregex) + if ((regex->flags & REGEX) == 0) regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); @@ -3228,7 +3226,7 @@ call_sub(const char *name, int nargs) * nargs++ * } */ - if (regex->type != Node_typedregex) + if ((regex->flags & REGEX) == 0) regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); @@ -3266,7 +3264,7 @@ call_match(int nargs) /* Don't need to pop the string just to push it back ... */ - if (regex->type != Node_typedregex) + if ((regex->flags & REGEX) == 0) regex = make_regnode(Node_regex, regex); PUSH(regex); @@ -3295,7 +3293,7 @@ call_split_func(const char *name, int nargs) if (nargs >= 3) { regex = POP_STRING(); - if (regex->type != Node_typedregex) + if ((regex->flags & REGEX) == 0) regex = make_regnode(Node_regex, regex); } else { if (name[0] == 's') { @@ -3955,12 +3953,9 @@ do_typeof(int nargs) res = "array"; deref = false; break; - case Node_typedregex: - res = "regexp"; - break; case Node_val: case Node_var: - switch (arg->flags & (STRING|NUMBER|MAYBE_NUM)) { + switch (arg->flags & (STRING|NUMBER|MAYBE_NUM|REGEX)) { case STRING: res = "string"; break; @@ -3970,6 +3965,9 @@ do_typeof(int nargs) case STRING|MAYBE_NUM: res = "strnum"; break; + case REGEX: + res = "regexp"; + break; case NUMBER|STRING: if (arg == Nnull_string) { res = "unassigned"; -- cgit v1.2.3 From 4f1eec385831018980e4c7424e1a544c5313b52a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 15 Nov 2016 21:45:58 +0200 Subject: Finish reworking typed regexes. Tests pass! --- builtin.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 001dd6e2..d51eafe2 100644 --- a/builtin.c +++ b/builtin.c @@ -3201,7 +3201,9 @@ call_sub(const char *name, int nargs) * push replace * push $0 */ - if ((regex->flags & REGEX) == 0) + if ((regex->flags & REGEX) != 0) + regex = regex->typed_re; + else regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); @@ -3226,7 +3228,9 @@ call_sub(const char *name, int nargs) * nargs++ * } */ - if ((regex->flags & REGEX) == 0) + if ((regex->flags & REGEX) != 0) + regex = regex->typed_re; + else regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); @@ -3264,8 +3268,11 @@ call_match(int nargs) /* Don't need to pop the string just to push it back ... */ - if ((regex->flags & REGEX) == 0) + if ((regex->flags & REGEX) != 0) + regex = regex->typed_re; + else regex = make_regnode(Node_regex, regex); + PUSH(regex); if (array) @@ -3293,7 +3300,9 @@ call_split_func(const char *name, int nargs) if (nargs >= 3) { regex = POP_STRING(); - if ((regex->flags & REGEX) == 0) + if ((regex->flags & REGEX) != 0) + regex = regex->typed_re; + else regex = make_regnode(Node_regex, regex); } else { if (name[0] == 's') { -- cgit v1.2.3