aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-05-05 10:39:03 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-05-05 10:39:03 +0300
commitecf875a23050b7e3b64805674e9ce3cac4199cb8 (patch)
tree4bd2293e71b990c9715d601a50fcb1f0350d1cf7 /profile.c
parent8f79856a02dd3e3ba8fc00a6e3086a367ca0cdf4 (diff)
downloadegawk-ecf875a23050b7e3b64805674e9ce3cac4199cb8.tar.gz
egawk-ecf875a23050b7e3b64805674e9ce3cac4199cb8.tar.bz2
egawk-ecf875a23050b7e3b64805674e9ce3cac4199cb8.zip
Make profiling work for hard regexes.
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/profile.c b/profile.c
index dcc2946c..a5c24b77 100644
--- a/profile.c
+++ b/profile.c
@@ -32,6 +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_hard_regex(const char *in_str, size_t len, int delim, bool hard_regex);
+static char *pp_hard_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);
@@ -624,14 +626,17 @@ cleanup:
break;
case Op_push_re:
- if (pc->memory->type != Node_regex)
+ if (pc->memory->type != Node_regex && pc->memory->type != Node_hardregex)
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_hard_regex(re->stptr, re->stlen, '/');
pp_push(pc->opcode, str, CAN_FREE);
}
break;
@@ -653,6 +658,11 @@ cleanup:
txt = t2->pp_str;
str = pp_group3(txt, op2str(pc->opcode), restr);
pp_free(t2);
+ } else if (m->type == Node_hardregex) {
+ NODE *re = m->re_exp;
+ restr = pp_hard_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, '/');
@@ -1323,11 +1333,27 @@ parenthesize(int type, NODE *left, NODE *right)
pp_parenthesize(right);
}
-/* pp_string --- pretty format a string or regex constant */
+/* pp_string --- pretty format a string or regular regex constant */
char *
pp_string(const char *in_str, size_t len, int delim)
{
+ return pp_string_or_hard_regex(in_str, len, delim, false);
+}
+
+/* pp_hard_regex --- pretty format a hard regex constant */
+
+static char *
+pp_hard_regex(const char *in_str, size_t len, int delim)
+{
+ return pp_string_or_hard_regex(in_str, len, delim, true);
+}
+
+/* pp_string_or_hard_regex --- pretty format a string, regex, or hard regex constant */
+
+char *
+pp_string_or_hard_regex(const char *in_str, size_t len, int delim, bool hard_regex)
+{
static char str_escapes[] = "\a\b\f\n\r\t\v\\";
static char str_printables[] = "abfnrtv\\";
static char re_escapes[] = "\a\b\f\n\r\t\v";
@@ -1359,11 +1385,15 @@ pp_string(const char *in_str, size_t len, int delim)
osiz *= 2; \
} ofre -= (l)
- osiz = len + 3 + 1; /* initial size; 3 for delim + terminating null */
+ /* initial size; 3 for delim + terminating null, 1 for @ */
+ osiz = len + 3 + 1 + (hard_regex == true);
emalloc(obuf, char *, osiz, "pp_string");
obufout = obuf;
ofre = osiz - 1;
+ if (hard_regex)
+ *obufout++ = '@';
+
*obufout++ = delim;
for (; len > 0; len--, str++) {
chksize(2); /* make space for 2 chars */