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. --- profile.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 56df9e37..be8977e8 100644 --- a/profile.c +++ b/profile.c @@ -33,6 +33,7 @@ static char *pp_list(int nargs, const char *paren, const char *delim); static char *pp_group3(const char *s1, const char *s2, const char *s3); static char *pp_concat(int nargs); static char *pp_string_or_strong_regex(const char *in_str, size_t len, int delim, bool strong_regex); +static char *pp_strong_regex(const char *in_str, size_t len, int delim); static bool is_binary(int type); static bool is_scalar(int type); static int prec_level(int type); @@ -636,14 +637,17 @@ cleanup: break; case Op_push_re: - if (pc->memory->type != Node_regex) + if (pc->memory->type != Node_regex && pc->memory->type != Node_typedregex) break; /* else fall through */ case Op_match_rec: { NODE *re = pc->memory->re_exp; - str = pp_string(re->stptr, re->stlen, '/'); + if (pc->memory->type == Node_regex) + str = pp_string(re->stptr, re->stlen, '/'); + else + str = pp_strong_regex(re->stptr, re->stlen, '/'); pp_push(pc->opcode, str, CAN_FREE); } break; @@ -665,6 +669,11 @@ cleanup: txt = t2->pp_str; str = pp_group3(txt, op2str(pc->opcode), restr); pp_free(t2); + } else if (m->type == Node_typedregex) { + NODE *re = m->re_exp; + restr = pp_strong_regex(re->stptr, re->stlen, '/'); + str = pp_group3(txt, op2str(pc->opcode), restr); + efree(restr); } else { NODE *re = m->re_exp; restr = pp_string(re->stptr, re->stlen, '/'); @@ -1405,6 +1414,13 @@ pp_string(const char *in_str, size_t len, int delim) return pp_string_or_strong_regex(in_str, len, delim, false); } +/* pp_strong_regex --- pretty format a hard regex constant */ + +static char * +pp_strong_regex(const char *in_str, size_t len, int delim) +{ + return pp_string_or_strong_regex(in_str, len, delim, true); +} /* pp_string_or_strong_regex --- pretty format a string, regex, or hard regex constant */ @@ -1448,6 +1464,9 @@ pp_string_or_strong_regex(const char *in_str, size_t len, int delim, bool strong obufout = obuf; ofre = osiz - 1; + if (strong_regex) + *obufout++ = '@'; + *obufout++ = delim; for (; len > 0; len--, str++) { chksize(2); /* make space for 2 chars */ -- 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. --- profile.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index c60fd296..f27f9dda 100644 --- a/profile.c +++ b/profile.c @@ -32,8 +32,8 @@ static void parenthesize(int type, NODE *left, NODE *right); static char *pp_list(int nargs, const char *paren, const char *delim); static char *pp_group3(const char *s1, const char *s2, const char *s3); static char *pp_concat(int nargs); -static char *pp_string_or_strong_regex(const char *in_str, size_t len, int delim, bool strong_regex); -static char *pp_strong_regex(const char *in_str, size_t len, int delim); +static char *pp_string_or_typed_regex(const char *in_str, size_t len, int delim, bool typed_regex); +static char *pp_typed_regex(const char *in_str, size_t len, int delim); static bool is_binary(int type); static bool is_scalar(int type); static int prec_level(int type); @@ -640,7 +640,7 @@ cleanup: break; case Op_push_re: - if (pc->memory->type != Node_regex && pc->memory->type != Node_typedregex) + if (pc->memory->type != Node_regex && (pc->memory->flags & REGEX) == 0) break; /* else fall through */ @@ -650,7 +650,7 @@ cleanup: if (pc->memory->type == Node_regex) str = pp_string(re->stptr, re->stlen, '/'); else - str = pp_strong_regex(re->stptr, re->stlen, '/'); + str = pp_typed_regex(re->stptr, re->stlen, '/'); pp_push(pc->opcode, str, CAN_FREE); } break; @@ -672,9 +672,9 @@ cleanup: txt = t2->pp_str; str = pp_group3(txt, op2str(pc->opcode), restr); pp_free(t2); - } else if (m->type == Node_typedregex) { + } else if (m->type == Node_val && (m->flags & REGEX) != 0) { NODE *re = m->re_exp; - restr = pp_strong_regex(re->stptr, re->stlen, '/'); + restr = pp_typed_regex(re->stptr, re->stlen, '/'); str = pp_group3(txt, op2str(pc->opcode), restr); efree(restr); } else { @@ -1416,21 +1416,21 @@ parenthesize(int type, NODE *left, NODE *right) char * pp_string(const char *in_str, size_t len, int delim) { - return pp_string_or_strong_regex(in_str, len, delim, false); + return pp_string_or_typed_regex(in_str, len, delim, false); } -/* pp_strong_regex --- pretty format a hard regex constant */ +/* pp_typed_regex --- pretty format a hard regex constant */ static char * -pp_strong_regex(const char *in_str, size_t len, int delim) +pp_typed_regex(const char *in_str, size_t len, int delim) { - return pp_string_or_strong_regex(in_str, len, delim, true); + return pp_string_or_typed_regex(in_str, len, delim, true); } -/* pp_string_or_strong_regex --- pretty format a string, regex, or hard regex constant */ +/* pp_string_or_typed_regex --- pretty format a string, regex, or typed regex constant */ char * -pp_string_or_strong_regex(const char *in_str, size_t len, int delim, bool strong_regex) +pp_string_or_typed_regex(const char *in_str, size_t len, int delim, bool typed_regex) { static char str_escapes[] = "\a\b\f\n\r\t\v\\"; static char str_printables[] = "abfnrtv\\"; @@ -1464,12 +1464,12 @@ pp_string_or_strong_regex(const char *in_str, size_t len, int delim, bool strong } ofre -= (l) /* initial size; 3 for delim + terminating null, 1 for @ */ - osiz = len + 3 + 1 + (strong_regex == true); + osiz = len + 3 + 1 + (typed_regex == true); emalloc(obuf, char *, osiz, "pp_string"); obufout = obuf; ofre = osiz - 1; - if (strong_regex) + if (typed_regex) *obufout++ = '@'; *obufout++ = delim; -- 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! --- profile.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index f27f9dda..ebb7b7e6 100644 --- a/profile.c +++ b/profile.c @@ -646,11 +646,13 @@ cleanup: fall through */ case Op_match_rec: { - NODE *re = pc->memory->re_exp; - if (pc->memory->type == Node_regex) + if (pc->memory->type == Node_regex) { + NODE *re = pc->memory->re_exp; str = pp_string(re->stptr, re->stlen, '/'); - else - str = pp_typed_regex(re->stptr, re->stlen, '/'); + } else { + assert((pc->memory->flags & REGEX) != 0); + str = pp_typed_regex(pc->memory->stptr, pc->memory->stlen, '/'); + } pp_push(pc->opcode, str, CAN_FREE); } break; @@ -673,8 +675,7 @@ cleanup: str = pp_group3(txt, op2str(pc->opcode), restr); pp_free(t2); } else if (m->type == Node_val && (m->flags & REGEX) != 0) { - NODE *re = m->re_exp; - restr = pp_typed_regex(re->stptr, re->stlen, '/'); + restr = pp_typed_regex(m->stptr, m->stlen, '/'); str = pp_group3(txt, op2str(pc->opcode), restr); efree(restr); } else { -- cgit v1.2.3